@quickbuilder.io/rich-text 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +122 -2
- package/adapters.d.ts +1 -0
- package/adapters.js +1 -0
- package/collaboration.d.ts +1 -0
- package/collaboration.js +1 -0
- package/commands.d.ts +1 -0
- package/commands.js +1 -0
- package/content.d.ts +1 -0
- package/content.js +1 -0
- package/contracts.d.ts +1 -0
- package/contracts.js +1 -0
- package/dist/adapters.d.mts +11 -0
- package/dist/adapters.d.ts +11 -0
- package/dist/adapters.js +564 -0
- package/dist/adapters.js.map +1 -0
- package/dist/adapters.mjs +557 -0
- package/dist/adapters.mjs.map +1 -0
- package/dist/collaboration.d.mts +29 -0
- package/dist/collaboration.d.ts +29 -0
- package/dist/collaboration.js +758 -0
- package/dist/collaboration.js.map +1 -0
- package/dist/collaboration.mjs +733 -0
- package/dist/collaboration.mjs.map +1 -0
- package/dist/commands.d.mts +8 -0
- package/dist/commands.d.ts +8 -0
- package/dist/commands.js +42 -0
- package/dist/commands.js.map +1 -0
- package/dist/commands.mjs +38 -0
- package/dist/commands.mjs.map +1 -0
- package/dist/content-types-CYHsrMrs.d.mts +27 -0
- package/dist/content-types-CYHsrMrs.d.ts +27 -0
- package/dist/content.d.mts +19 -0
- package/dist/content.d.ts +19 -0
- package/dist/content.js +785 -0
- package/dist/content.js.map +1 -0
- package/dist/content.mjs +775 -0
- package/dist/content.mjs.map +1 -0
- package/dist/contracts.d.mts +199 -0
- package/dist/contracts.d.ts +199 -0
- package/dist/contracts.js +4 -0
- package/dist/contracts.js.map +1 -0
- package/dist/contracts.mjs +3 -0
- package/dist/contracts.mjs.map +1 -0
- package/dist/extensions.d.mts +363 -0
- package/dist/extensions.d.ts +363 -0
- package/dist/extensions.js +153 -0
- package/dist/extensions.js.map +1 -0
- package/dist/extensions.mjs +142 -0
- package/dist/extensions.mjs.map +1 -0
- package/dist/history.d.mts +12 -0
- package/dist/history.d.ts +12 -0
- package/dist/history.js +464 -0
- package/dist/history.js.map +1 -0
- package/dist/history.mjs +459 -0
- package/dist/history.mjs.map +1 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1438 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1372 -0
- package/dist/index.mjs.map +1 -0
- package/dist/markdown.d.mts +32 -0
- package/dist/markdown.d.ts +32 -0
- package/dist/markdown.js +739 -0
- package/dist/markdown.js.map +1 -0
- package/dist/markdown.mjs +735 -0
- package/dist/markdown.mjs.map +1 -0
- package/dist/runtime/dom.d.mts +148 -0
- package/dist/runtime/dom.d.ts +148 -0
- package/dist/runtime/dom.js +2145 -0
- package/dist/runtime/dom.js.map +1 -0
- package/dist/runtime/dom.mjs +2084 -0
- package/dist/runtime/dom.mjs.map +1 -0
- package/dist/schema.d.mts +23 -0
- package/dist/schema.d.ts +23 -0
- package/dist/schema.js +157 -0
- package/dist/schema.js.map +1 -0
- package/dist/schema.mjs +137 -0
- package/dist/schema.mjs.map +1 -0
- package/dist/serializer.d.mts +38 -0
- package/dist/serializer.d.ts +38 -0
- package/dist/serializer.js +504 -0
- package/dist/serializer.js.map +1 -0
- package/dist/serializer.mjs +491 -0
- package/dist/serializer.mjs.map +1 -0
- package/dist/svg-export-BtI8x_mG.d.mts +15 -0
- package/dist/svg-export-BtI8x_mG.d.ts +15 -0
- package/dist/transactions.d.mts +16 -0
- package/dist/transactions.d.ts +16 -0
- package/dist/transactions.js +637 -0
- package/dist/transactions.js.map +1 -0
- package/dist/transactions.mjs +631 -0
- package/dist/transactions.mjs.map +1 -0
- package/extensions.d.ts +1 -0
- package/extensions.js +1 -0
- package/history.d.ts +1 -0
- package/history.js +1 -0
- package/package.json +352 -4
- package/schema.d.ts +1 -0
- package/schema.js +1 -0
- package/serializer.d.ts +1 -0
- package/serializer.js +1 -0
- package/transactions.d.ts +1 -0
- package/transactions.js +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Quick Builder contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,123 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @quickbuilder.io/rich-text
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Framework-neutral Quick Builder rich text contracts, schema, sanitizer, serializers, transaction runtime, history helpers, command metadata, DOM runtime bridge, and framework adapters.
|
|
4
|
+
|
|
5
|
+
The package owns editor-domain behavior only. Visual editor components live in `@quickbuilder.io/rich-text-editor`, while `@quickbuilder.io/design-system` remains focused on reusable UI primitives and styling tokens.
|
|
6
|
+
|
|
7
|
+
## Quick start
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @quickbuilder.io/rich-text
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Use the `/content` entry to convert and sanitize content in browsers and Node.js
|
|
14
|
+
18 or newer. It has no required runtime dependencies.
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import {
|
|
18
|
+
markdownToRichTextHtml,
|
|
19
|
+
richTextHtmlToPlainText,
|
|
20
|
+
sanitizeRichTextMarkup,
|
|
21
|
+
} from '@quickbuilder.io/rich-text/content';
|
|
22
|
+
|
|
23
|
+
const html = markdownToRichTextHtml('## Release notes\n\nReady to ship.');
|
|
24
|
+
const plainText = richTextHtmlToPlainText(html);
|
|
25
|
+
const safeImportedHtml = sanitizeRichTextMarkup('<p>Imported article</p>');
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Install `yjs` alongside Rich Text when using the optional `/collaboration` entry.
|
|
29
|
+
|
|
30
|
+
## Runtime Boundary
|
|
31
|
+
|
|
32
|
+
- `contracts` defines the serializable document, selection, transaction, and editor-state contracts.
|
|
33
|
+
- `transactions` owns normalized document snapshots, undo/redo history, transaction metadata, and selection sync.
|
|
34
|
+
- Configure `maxHistoryEntries` when creating a runtime state to bound stored snapshots, including the current document. A limit of one keeps the current snapshot and disables undo.
|
|
35
|
+
- `extensions` owns headless extension definitions, including the registered table, slash-command, mention, collaboration, and AI assistant contracts used by Pro packages.
|
|
36
|
+
- `runtime/dom` owns the browser `contenteditable` command bridge.
|
|
37
|
+
- `createRichTextEditingHtml` projects canonical HTML into an editing surface with eagerly loaded images. Image insertion and document replacement use this projection. Canonical serialization supplies the saved document and its image loading attributes.
|
|
38
|
+
- `runtime/dom` includes table commands for insert/delete table, row insertion/deletion, and column insertion/deletion.
|
|
39
|
+
- `runtime/dom` includes slash-command query detection, command filtering, and command execution against the active editor selection.
|
|
40
|
+
- `runtime/dom` includes mention query detection, item filtering, and sanitized mention insertion against the active editor selection.
|
|
41
|
+
- `runtime/dom` includes collaboration presence validation, snapshot resolution, and local selection capture.
|
|
42
|
+
- `runtime/dom` includes AI assistant request creation and explicit sanitized suggestion application.
|
|
43
|
+
- `@quickbuilder.io/rich-text-editor` composes these headless primitives with design-system chrome.
|
|
44
|
+
|
|
45
|
+
### Markdown content
|
|
46
|
+
|
|
47
|
+
`@quickbuilder.io/rich-text/markdown` exposes `markdownToRichTextHtml`, `markdownToRichTextBlocks`, and `createRichTextDocumentFromMarkdown`. The owned parser supports headings, paragraphs, hard breaks, nested lists and quotes, task lists, fenced code, tables, links, images, autolinks, emphasis, strike, and inline code. Raw HTML is inert text; links and images use the shared schema policy.
|
|
48
|
+
|
|
49
|
+
`markdownToRichTextBlocks` preserves top-level fences as `{ type: 'code', value, language }` and other blocks as sanitized `{ type: 'html', html }`. An unfinished fence remains a code block through streaming and completion. Input limits default to one million UTF-16 code units; nesting is limited to 48 levels. This is the supported Quick Builder Markdown contract, not a claim of complete CommonMark/GFM syntax conformance.
|
|
50
|
+
|
|
51
|
+
Inline code preserves literal backslashes. Escape a pipe as `\|` to keep it in a table cell.
|
|
52
|
+
|
|
53
|
+
`plainTextToRichTextHtml(text)` explicitly converts plain text to sanitized HTML-compatible content, preserving line breaks and literal markup. Use it at ingestion or offline migration boundaries; stored HTML uses `sanitizeRichTextMarkup` and is never format-guessed.
|
|
54
|
+
|
|
55
|
+
`richTextHtmlToPlainText(html)` is the same DOM-free serializer on servers and browsers. It sanitizes active markup, decodes supported named/numeric entities exactly once, preserves block/line boundaries and separates table cells with tabs. It shares the view-tree entity policy and rejects unsupported entities and inputs over one million characters explicitly. It is available through the root, `/serializer`, and portable `/content` entries.
|
|
56
|
+
|
|
57
|
+
## Native adapter and contract
|
|
58
|
+
|
|
59
|
+
richTextHtmlToViewTree produces a bounded transient rendering tree from the
|
|
60
|
+
existing schema-sanitized HTML. The limits are one million input characters,
|
|
61
|
+
20,000 tokens and 64 nested elements. It rejects unbalanced content and unsupported
|
|
62
|
+
named entities; common named and numeric entities are decoded once. Canonical HTML
|
|
63
|
+
remains the durable document. This helper has no DOM or native runtime dependency.
|
|
64
|
+
|
|
65
|
+
`@quickbuilder.io/rich-text/content` exposes the canonical sanitizer, HTML/Markdown/plain-text conversion, transient view tree and content types without DOM selection/editor contracts. Native read-only renderers consume this entry; storage remains the existing canonical HTML.
|
|
66
|
+
|
|
67
|
+
`sanitizeRichTextMarkup(html, options)` accepts a host media policy. Set
|
|
68
|
+
`allowVideos: false` to remove video blocks. `resolveImageSource(source)` receives
|
|
69
|
+
each untrusted image source and returns an approved URL or `null` to remove that
|
|
70
|
+
image. Returned URLs still pass the canonical image URL policy. This lets a host
|
|
71
|
+
resolve authorized inline attachments and remove remote tracking images while
|
|
72
|
+
preserving text, links and image descriptions. Defaults retain the existing
|
|
73
|
+
schema policy. The resolver is synchronous and performs no media fetching.
|
|
74
|
+
Set `imageCrossOrigin: 'anonymous'` when approved image URLs can redirect across
|
|
75
|
+
origins. Canonical markup retains that attribute through repeated sanitization.
|
|
76
|
+
It uses same-origin credentials for the image request. [HTML fetch policy](https://html.spec.whatwg.org/multipage/urls-and-fetching.html#cors-settings-attributes)
|
|
77
|
+
|
|
78
|
+
The same option accepts `(approvedSource) => 'anonymous' | undefined` for
|
|
79
|
+
mixed documents. It runs after source resolution and URL validation. Returning
|
|
80
|
+
`undefined` retains the image's existing request policy. Hosts can govern private
|
|
81
|
+
attachment redirects while preserving ordinary web images that use their
|
|
82
|
+
default request mode. Unsupported callback results are rejected.
|
|
83
|
+
|
|
84
|
+
Image insertion through `RichTextImage` accepts `crossOrigin: 'anonymous'` with
|
|
85
|
+
the same policy. The runtime applies it before the image source and retains it
|
|
86
|
+
in canonical output. Unsupported explicit credentials policies are rejected.
|
|
87
|
+
|
|
88
|
+
Set `allowContentIdImages: true` when serializing email HTML that references
|
|
89
|
+
authorized MIME parts. It permits `cid:` URLs whose decoded identity contains
|
|
90
|
+
one to 200 printable ASCII characters without whitespace, angle brackets or
|
|
91
|
+
quotes. Malformed percent escapes and other unsafe URL schemes remain rejected.
|
|
92
|
+
The host owns attachment authorization, identity matching and MIME delivery.
|
|
93
|
+
Default browser and document sanitization keeps its existing web-image policy.
|
|
94
|
+
|
|
95
|
+
Set `videoPresentation: 'link'` for destinations that need a readable link in
|
|
96
|
+
place of an embedded player. The canonical governed source and title become a
|
|
97
|
+
sanitized link, retaining block identity and plain-text content. The default
|
|
98
|
+
`'embed'` preserves video blocks. `allowVideos: false` removes videos with either
|
|
99
|
+
presentation setting.
|
|
100
|
+
|
|
101
|
+
## Collaborative rich text
|
|
102
|
+
|
|
103
|
+
`@quickbuilder.io/rich-text/collaboration` binds schema-governed HTML to the named `quickbuilder.rich-text` Yjs XML fragment. Yjs is an optional peer required only for this entry. `writeRichTextCollaboration` seeds an empty document once; `readRichTextCollaboration` derives sanitized HTML. Persist the original Yjs binary state. Inline formatting is stored as Y.XmlText marks so text and formatting edits retain text identities. Editable `snapshot()` HTML carries validated inert UUID block identities that the owned sanitizer preserves; display HTML omits this metadata. This keeps a surviving block attached to its concurrent edits when a preceding sibling is removed. UTF-16 reconciliation preserves surrogate pairs. Structural edits use bounded reconciliation; concurrently deleting an edited block has Yjs deletion semantics.
|
|
104
|
+
|
|
105
|
+
`createRichTextCollaborationBinding(doc)` exposes `getHtml`, `setHtml`, `subscribe`, local-origin `undo`/`redo`, capability checks, `stopCapturing`, and idempotent `dispose`. Dispose each binding before switching document or access scope. Providers own authenticated transport, durable acknowledgement, revocation, presence and reconnect. `readRichTextBlockSignatures(doc)` lets an authorized persistence service associate changed top-level blocks with verified authors. Set `topLevelParagraphs` on an annotated binding to keep bare typed text inside attributable paragraphs. This entry does not claim that a controlled HTML editor automatically preserves its DOM selection on remote replacement.
|
|
106
|
+
|
|
107
|
+
### Portable rich-text reports
|
|
108
|
+
|
|
109
|
+
`exportRichTextSvgPages(html, { title })` projects normalized rich text into
|
|
110
|
+
standalone SVG pages. It retains text, headings and inline emphasis. An image
|
|
111
|
+
with a description contributes its description to the report. Use the
|
|
112
|
+
canonical HTML serializer when you need the full editable document.
|
|
113
|
+
|
|
114
|
+
`exportRichTextSvgPages` keeps raster images together across page breaks and
|
|
115
|
+
requires resolved image bytes. Browser callers can use
|
|
116
|
+
`resolveRichTextExportImages` from `/runtime/dom` to load and embed those bytes.
|
|
117
|
+
Unreadable images fail the export explicitly. Hosts that copy documents to a
|
|
118
|
+
new media scope can use `rewriteRichTextImageSources` to rebind image URLs
|
|
119
|
+
without changing links or collaborative block identities.
|
|
120
|
+
|
|
121
|
+
Canonical `qb-video` blocks persist only a governed source and title. The
|
|
122
|
+
serializer strips runtime player markup, and collaboration preserves the media
|
|
123
|
+
block alongside text and images. Static exports include its title.
|
package/adapters.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/adapters';
|
package/adapters.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/adapters.js');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/collaboration';
|
package/collaboration.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/collaboration.js');
|
package/commands.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/commands';
|
package/commands.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/commands.js');
|
package/content.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/content';
|
package/content.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/content.js');
|
package/contracts.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/contracts';
|
package/contracts.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/contracts.js');
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RichTextBindingOptions, RichTextBinding, RichTextFramework } from './contracts.mjs';
|
|
2
|
+
import './content-types-CYHsrMrs.mjs';
|
|
3
|
+
|
|
4
|
+
declare const QUICK_BUILDER_RICH_TEXT_FRAMEWORKS: readonly ["react", "next", "vue", "nuxt", "angular", "astro", "svelte", "solid", "qwik", "preact", "react-native", "webcomponents"];
|
|
5
|
+
declare function createRichTextBinding(target: RichTextFramework, options?: RichTextBindingOptions): RichTextBinding;
|
|
6
|
+
declare function createReactRichTextBinding(options?: RichTextBindingOptions): RichTextBinding;
|
|
7
|
+
declare function createVueRichTextBinding(options?: RichTextBindingOptions): RichTextBinding;
|
|
8
|
+
declare function createSvelteRichTextBinding(options?: RichTextBindingOptions): RichTextBinding;
|
|
9
|
+
declare function createWebcomponentsRichTextBinding(options?: RichTextBindingOptions): RichTextBinding;
|
|
10
|
+
|
|
11
|
+
export { QUICK_BUILDER_RICH_TEXT_FRAMEWORKS, createReactRichTextBinding, createRichTextBinding, createSvelteRichTextBinding, createVueRichTextBinding, createWebcomponentsRichTextBinding };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RichTextBindingOptions, RichTextBinding, RichTextFramework } from './contracts.js';
|
|
2
|
+
import './content-types-CYHsrMrs.js';
|
|
3
|
+
|
|
4
|
+
declare const QUICK_BUILDER_RICH_TEXT_FRAMEWORKS: readonly ["react", "next", "vue", "nuxt", "angular", "astro", "svelte", "solid", "qwik", "preact", "react-native", "webcomponents"];
|
|
5
|
+
declare function createRichTextBinding(target: RichTextFramework, options?: RichTextBindingOptions): RichTextBinding;
|
|
6
|
+
declare function createReactRichTextBinding(options?: RichTextBindingOptions): RichTextBinding;
|
|
7
|
+
declare function createVueRichTextBinding(options?: RichTextBindingOptions): RichTextBinding;
|
|
8
|
+
declare function createSvelteRichTextBinding(options?: RichTextBindingOptions): RichTextBinding;
|
|
9
|
+
declare function createWebcomponentsRichTextBinding(options?: RichTextBindingOptions): RichTextBinding;
|
|
10
|
+
|
|
11
|
+
export { QUICK_BUILDER_RICH_TEXT_FRAMEWORKS, createReactRichTextBinding, createRichTextBinding, createSvelteRichTextBinding, createVueRichTextBinding, createWebcomponentsRichTextBinding };
|