# TSRichTextEditor

`TSRichTextEditor` is a TypeScript-first package built around the existing RichTextEditor browser runtime.

This repository focuses on four things:

- keeping the shipping editor runtime intact and synced from the JavaScript project
- exposing a typed browser API for initialization and common editor methods
- giving the repo a clean TypeScript build and demo flow
- producing publishable package outputs for npm, GitHub Packages, and NuGet

## Project layout

- `src/`: typed wrapper and public API
- `public/richtexteditor/`: synced runtime assets copied from the JavaScript project
- `dist/`: compiled package output plus runtime files
- `demo/`: plain browser demo written in TypeScript
- `nuget/TSRichTextEditor.AspNetCore/`: ASP.NET Core static web assets package project
- `scripts/`: runtime sync, build, and packaging helpers

## Commands

```bash
npm install
npm run build
npm run demo:serve
```

Then open:

- `http://127.0.0.1:4174/demo/index.html`

## Runtime sync source

Runtime assets are copied from the sibling JavaScript repo at:

- `../JSRichTextEditor/RichTextEditorJS/Demos/AspNetCoreRazor/wwwroot/richtexteditor`

Run `npm run sync:runtime` any time the JavaScript editor runtime changes.

## Package outputs

### Standard npm package

Build the normal package output and create the local tarball:

```bash
npm run build
npm pack
```

### GitHub Packages

GitHub's npm registry requires a scoped package name, so this repo keeps the standard package name for local/npm use and generates a scoped publish variant only for GitHub Packages.

Create the GitHub-ready tarball:

```bash
npm run pack:github
```

Optional environment variables:

- `GITHUB_PACKAGE_SCOPE`: package scope to use, without the leading `@`
- `GITHUB_REPOSITORY`: repository in `owner/repo` form, used for metadata
- `GITHUB_REPOSITORY_OWNER`: fallback scope source

If no scope is provided, the scripts default to `richscripts`.

Publish to GitHub Packages:

```bash
npm run publish:github
```

Authentication can come from either a local `.npmrc` or `NODE_AUTH_TOKEN`.

### NuGet package

Build the ASP.NET Core static web assets package:

```bash
npm run pack:nuget
```

That produces a `.nupkg` in `artifacts/nuget/`.

The NuGet package exposes the editor files through ASP.NET Core static web assets under:

- `/_content/TSRichTextEditor.AspNetCore/ts-rich-text-editor/dist/index.js`
- `/_content/TSRichTextEditor.AspNetCore/ts-rich-text-editor/dist/richtexteditor`

## CI publishing

This repo also includes `.github/workflows/publish-packages.yml` for:

- publishing the scoped npm variant to GitHub Packages
- building the NuGet package
- pushing the NuGet package to nuget.org when `NUGET_API_KEY` is configured

## Current scope

The editor core is still the existing browser runtime, but the package surface is now TypeScript:

- typed `createRichTextEditor(...)`
- typed runtime loader
- typed option and instance interfaces
- typed browser globals for `window.RichTextEditor`

That keeps the package practical for immediate use while the underlying runtime remains aligned with the shipping editor.
