@reactloom/editor 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/README.md +41 -2
- package/dist/LICENSE +21 -0
- package/dist/_internal/primitives/visually-hidden.js +29 -0
- package/dist/_internal/primitives/visually-hidden.js.map +1 -0
- package/dist/_internal/utils/cx.js +10 -0
- package/dist/_internal/utils/cx.js.map +1 -0
- package/dist/_internal/utils/data-attr.js +8 -0
- package/dist/_internal/utils/data-attr.js.map +1 -0
- package/dist/document.d.ts +50 -0
- package/dist/document.d.ts.map +1 -0
- package/dist/document.js +228 -0
- package/dist/document.js.map +1 -0
- package/dist/editor.module.js +26 -0
- package/dist/editor.module.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/messages.d.ts +42 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +42 -0
- package/dist/messages.js.map +1 -0
- package/dist/rich-text-editor.d.ts +42 -0
- package/dist/rich-text-editor.d.ts.map +1 -0
- package/dist/rich-text-editor.js +791 -0
- package/dist/rich-text-editor.js.map +1 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +1 -0
- package/dist/styles.css +3 -0
- package/package.json +86 -3
package/README.md
CHANGED
|
@@ -1,3 +1,42 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @reactloom/editor
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An accessible rich-text editor for ReactLoom, built on Tiptap (ProseMirror): a labelled field, a
|
|
4
|
+
toolbar with roving focus, a link dialog, and JSON values you can validate and render to safe HTML
|
|
5
|
+
on the server.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @reactloom/editor @reactloom/ui @reactloom/theme
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import '@reactloom/editor/styles.css';
|
|
13
|
+
import { RichTextEditor, type RichTextDocument } from '@reactloom/editor';
|
|
14
|
+
|
|
15
|
+
const [doc, setDoc] = useState<RichTextDocument | null>(null);
|
|
16
|
+
|
|
17
|
+
<RichTextEditor
|
|
18
|
+
label="Release notes"
|
|
19
|
+
value={doc}
|
|
20
|
+
onValueChange={setDoc}
|
|
21
|
+
formats={['bold', 'italic', 'link', 'heading', 'bulletList', 'orderedList']}
|
|
22
|
+
headingLevels={[2, 3]}
|
|
23
|
+
/>;
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
- **Only the formats you allow:** `formats` sets both the toolbar and what the document may
|
|
27
|
+
contain; pasted content outside it is dropped.
|
|
28
|
+
- **Safe on the server:** import from `@reactloom/editor/server` (no React, no DOM) to check what a
|
|
29
|
+
client sent and to render stored documents:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { validateDocument, renderHtml } from '@reactloom/editor/server';
|
|
33
|
+
|
|
34
|
+
const result = validateDocument(body.notes, { formats, maxLength: 10_000 });
|
|
35
|
+
if (!result.valid) return error(result.errors);
|
|
36
|
+
const html = renderHtml(result.doc, { formats });
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`renderHtml` escapes text and only writes safe link URLs (no `javascript:`), so never render
|
|
40
|
+
editor HTML that came from the browser.
|
|
41
|
+
|
|
42
|
+
Documentation and live examples: <https://reactloom.dev/components/rich-text-editor>
|
package/dist/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ReactLoom UI 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.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { forwardRef } from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
// ../primitives/src/visually-hidden.tsx
|
|
4
|
+
var hidden = {
|
|
5
|
+
position: "absolute",
|
|
6
|
+
width: 1,
|
|
7
|
+
height: 1,
|
|
8
|
+
padding: 0,
|
|
9
|
+
margin: -1,
|
|
10
|
+
overflow: "hidden",
|
|
11
|
+
clip: "rect(0 0 0 0)",
|
|
12
|
+
clipPath: "inset(50%)",
|
|
13
|
+
whiteSpace: "nowrap",
|
|
14
|
+
border: 0
|
|
15
|
+
};
|
|
16
|
+
/** Content available to assistive technology but not rendered visually. */
|
|
17
|
+
var VisuallyHidden = /*#__PURE__*/ forwardRef(function VisuallyHidden({ style, ...props }, ref) {
|
|
18
|
+
return /* @__PURE__ */ jsx("span", {
|
|
19
|
+
ref,
|
|
20
|
+
...props,
|
|
21
|
+
style: {
|
|
22
|
+
...hidden,
|
|
23
|
+
...style
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
export { VisuallyHidden };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=visually-hidden.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visually-hidden.js","names":[],"sources":["../../../../primitives/src/visually-hidden.tsx"],"sourcesContent":["import { forwardRef, type CSSProperties, type HTMLAttributes } from 'react';\n\nconst hidden: CSSProperties = {\n position: 'absolute',\n width: 1,\n height: 1,\n padding: 0,\n margin: -1,\n overflow: 'hidden',\n clip: 'rect(0 0 0 0)',\n clipPath: 'inset(50%)',\n whiteSpace: 'nowrap',\n border: 0,\n};\n\nexport type VisuallyHiddenProps = HTMLAttributes<HTMLSpanElement>;\n\n/** Content available to assistive technology but not rendered visually. */\nexport const VisuallyHidden = /*#__PURE__*/ forwardRef<HTMLSpanElement, VisuallyHiddenProps>(function VisuallyHidden(\n { style, ...props },\n ref,\n) {\n return <span ref={ref} {...props} style={{ ...hidden, ...style }} />;\n});\n"],"mappings":";;;AAEA,IAAM,SAAwB;CAC5B,UAAU;CACV,OAAO;CACP,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,UAAU;CACV,MAAM;CACN,UAAU;CACV,YAAY;CACZ,QAAQ;AACV;;AAKA,IAAa,iBAA+B,yBAAiD,SAAS,eACpG,EAAE,OAAO,GAAG,SACZ,KACA;CACA,OAAO,oBAAC,QAAD;EAAW;EAAK,GAAI;EAAO,OAAO;GAAE,GAAG;GAAQ,GAAG;EAAM;CAAI,CAAA;AACrE,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// ../utils/src/cx.ts
|
|
2
|
+
/** Joins truthy class names with a single space. */
|
|
3
|
+
function cx(...values) {
|
|
4
|
+
let out = "";
|
|
5
|
+
for (const v of values) if (v) out = out ? `${out} ${v}` : v;
|
|
6
|
+
return out || void 0;
|
|
7
|
+
}
|
|
8
|
+
export { cx };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=cx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cx.js","names":[],"sources":["../../../../utils/src/cx.ts"],"sourcesContent":["type ClassValue = string | false | null | undefined;\n\n/** Joins truthy class names with a single space. */\nexport function cx(...values: ClassValue[]): string | undefined {\n let out = '';\n for (const v of values) if (v) out = out ? `${out} ${v}` : v;\n return out || undefined;\n}\n"],"mappings":";;AAGA,SAAgB,GAAG,GAAG,QAA0C;CAC9D,IAAI,MAAM;CACV,KAAK,MAAM,KAAK,QAAQ,IAAI,GAAG,MAAM,MAAM,GAAG,IAAI,GAAG,MAAM;CAC3D,OAAO,OAAO,KAAA;AAChB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-attr.js","names":[],"sources":["../../../../utils/src/data-attr.ts"],"sourcesContent":["/** `true` → `\"\"` (attribute present), falsy → `undefined` (attribute absent). */\nexport function dataAttr(condition: boolean | undefined): '' | undefined {\n return condition ? '' : undefined;\n}\n"],"mappings":";;AACA,SAAgB,SAAS,WAAgD;CACvE,OAAO,YAAY,KAAK,KAAA;AAC1B"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type AnyExtension, type JSONContent } from '@tiptap/core';
|
|
2
|
+
import { type Schema } from '@tiptap/pm/model';
|
|
3
|
+
/** A rich-text document as stored: ProseMirror/Tiptap JSON. Store this, not HTML. */
|
|
4
|
+
export type RichTextDocument = JSONContent;
|
|
5
|
+
/** Formatting a field allows. Anything else is dropped on paste and rejected by validation. */
|
|
6
|
+
export type RichTextFormat = 'bold' | 'italic' | 'strike' | 'code' | 'link' | 'heading' | 'bulletList' | 'orderedList' | 'blockquote' | 'codeBlock' | 'image' | 'table';
|
|
7
|
+
export declare const defaultFormats: readonly RichTextFormat[];
|
|
8
|
+
export interface DocumentOptions {
|
|
9
|
+
/** @default ['bold', 'italic', 'link', 'bulletList', 'orderedList'] */
|
|
10
|
+
formats?: readonly RichTextFormat[];
|
|
11
|
+
/** Heading levels when `heading` is allowed. @default [2, 3] */
|
|
12
|
+
headingLevels?: ReadonlyArray<1 | 2 | 3 | 4 | 5 | 6>;
|
|
13
|
+
/** Accept links without a scheme (`/help`, `#top`). @default false */
|
|
14
|
+
allowRelativeLinks?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** `http`, `https` and `mailto` URLs (and relative ones when allowed). Never `javascript:` or `data:`. */
|
|
17
|
+
export declare function isSafeUrl(url: string, allowRelative?: boolean): boolean;
|
|
18
|
+
/** Image sources: `https` and `http` only (and relative paths when allowed) — never `data:`, `blob:` or `javascript:`. */
|
|
19
|
+
export declare function isSafeImageUrl(url: string, allowRelative?: boolean): boolean;
|
|
20
|
+
/** Completes what people type in a link field: `example.com` → `https://example.com`, `a@b.co` → `mailto:a@b.co`. */
|
|
21
|
+
export declare function normalizeUrl(input: string): string;
|
|
22
|
+
/** The Tiptap extensions for a set of formats (also defines the schema used for validation). */
|
|
23
|
+
export declare function extensionsFor(options?: DocumentOptions): AnyExtension[];
|
|
24
|
+
/** Schemas are built once per option set. */
|
|
25
|
+
export declare function schemaFor(options?: DocumentOptions): Schema;
|
|
26
|
+
export type ValidationResult = {
|
|
27
|
+
valid: true;
|
|
28
|
+
doc: RichTextDocument;
|
|
29
|
+
text: string;
|
|
30
|
+
} | {
|
|
31
|
+
valid: false;
|
|
32
|
+
errors: string[];
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Checks a document received from a client before you store it (ADR-0011): only the allowed
|
|
36
|
+
* nodes and marks, structurally valid, and every link a safe URL — the schema alone accepts any
|
|
37
|
+
* `href`, including `javascript:`. Optionally limits the text length. Rejects rather than repairs.
|
|
38
|
+
*/
|
|
39
|
+
export declare function validateDocument(json: unknown, options?: DocumentOptions & {
|
|
40
|
+
maxLength?: number;
|
|
41
|
+
}): ValidationResult;
|
|
42
|
+
/** True for a document with no text (an empty paragraph), e.g. for `required` checks. */
|
|
43
|
+
export declare function isEmptyDocument(json: RichTextDocument | null | undefined): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Renders a stored document to HTML without a DOM (Node, edge runtimes, browsers). Invalid
|
|
46
|
+
* documents throw; unsafe links are dropped. Run the result through your HTML sanitiser too
|
|
47
|
+
* (DOMPurify or sanitize-html) before showing it to other users — defence in depth.
|
|
48
|
+
*/
|
|
49
|
+
export declare function renderHtml(json: RichTextDocument, options?: DocumentOptions): string;
|
|
50
|
+
//# sourceMappingURL=document.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAEA,OAAO,EAA8B,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAC/F,OAAO,EAAiD,KAAK,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAK9F,qFAAqF;AACrF,MAAM,MAAM,gBAAgB,GAAG,WAAW,CAAC;AAE3C,+FAA+F;AAC/F,MAAM,MAAM,cAAc,GACtB,MAAM,GACN,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,MAAM,GACN,SAAS,GACT,YAAY,GACZ,aAAa,GACb,YAAY,GACZ,WAAW,GACX,OAAO,GACP,OAAO,CAAC;AAEZ,eAAO,MAAM,cAAc,EAAE,SAAS,cAAc,EAA4D,CAAC;AAEjH,MAAM,WAAW,eAAe;IAC9B,uEAAuE;IACvE,OAAO,CAAC,EAAE,SAAS,cAAc,EAAE,CAAC;IACpC,gEAAgE;IAChE,aAAa,CAAC,EAAE,aAAa,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IACrD,sEAAsE;IACtE,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAID,0GAA0G;AAC1G,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,UAAQ,GAAG,OAAO,CAerE;AAED,0HAA0H;AAC1H,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,UAAQ,GAAG,OAAO,CAG1E;AAyBD,qHAAqH;AACrH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKlD;AAED,gGAAgG;AAChG,wBAAgB,aAAa,CAAC,OAAO,GAAE,eAAoB,GAAG,YAAY,EAAE,CAmC3E;AAGD,6CAA6C;AAC7C,wBAAgB,SAAS,CAAC,OAAO,GAAE,eAAoB,GAAG,MAAM,CAQ/D;AAED,MAAM,MAAM,gBAAgB,GAAG;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,GAAG,EAAE,gBAAgB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAEzH;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,GAAE,eAAe,GAAG;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,gBAAgB,CAyBxH;AAED,yFAAyF;AACzF,wBAAgB,eAAe,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAIlF;AA+CD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,gBAAgB,EAAE,OAAO,GAAE,eAAoB,GAAG,MAAM,CAIxF"}
|
package/dist/document.js
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { getSchema, mergeAttributes } from "@tiptap/core";
|
|
2
|
+
import { Node } from "@tiptap/pm/model";
|
|
3
|
+
import StarterKit from "@tiptap/starter-kit";
|
|
4
|
+
import Image from "@tiptap/extension-image";
|
|
5
|
+
import { Table, TableCell, TableHeader, TableRow } from "@tiptap/extension-table";
|
|
6
|
+
// src/document.ts
|
|
7
|
+
var defaultFormats = [
|
|
8
|
+
"bold",
|
|
9
|
+
"italic",
|
|
10
|
+
"link",
|
|
11
|
+
"bulletList",
|
|
12
|
+
"orderedList"
|
|
13
|
+
];
|
|
14
|
+
var SAFE_PROTOCOLS = /* @__PURE__ */ new Set([
|
|
15
|
+
"http:",
|
|
16
|
+
"https:",
|
|
17
|
+
"mailto:"
|
|
18
|
+
]);
|
|
19
|
+
/** `http`, `https` and `mailto` URLs (and relative ones when allowed). Never `javascript:` or `data:`. */
|
|
20
|
+
function isSafeUrl(url, allowRelative = false) {
|
|
21
|
+
const value = url.trim();
|
|
22
|
+
if (!value) return false;
|
|
23
|
+
for (const ch of value) {
|
|
24
|
+
const code = ch.charCodeAt(0);
|
|
25
|
+
if (code < 32 || code === 127) return false;
|
|
26
|
+
}
|
|
27
|
+
if (!/^([a-z][a-z\d+\-.]*):/i.exec(value)) return allowRelative && !value.startsWith("//");
|
|
28
|
+
try {
|
|
29
|
+
return SAFE_PROTOCOLS.has(new URL(value).protocol);
|
|
30
|
+
} catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** Image sources: `https` and `http` only (and relative paths when allowed) — never `data:`, `blob:` or `javascript:`. */
|
|
35
|
+
function isSafeImageUrl(url, allowRelative = false) {
|
|
36
|
+
if (!isSafeUrl(url, allowRelative)) return false;
|
|
37
|
+
return !/^mailto:/i.test(url.trim());
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Tables without Tab bindings: Tiptap moves between cells with Tab, which would trap keyboard
|
|
41
|
+
* users inside the editor whenever the caret is in a table. Arrow keys move between cells
|
|
42
|
+
* instead, and Tab keeps leaving the field as everywhere else.
|
|
43
|
+
*/
|
|
44
|
+
var AccessibleTable = /*#__PURE__*/ Table.extend({ addKeyboardShortcuts() {
|
|
45
|
+
const shortcuts = { ...this.parent?.() };
|
|
46
|
+
delete shortcuts.Tab;
|
|
47
|
+
delete shortcuts["Shift-Tab"];
|
|
48
|
+
return shortcuts;
|
|
49
|
+
} });
|
|
50
|
+
/** Header cells are column headers (the editor inserts tables with a header row). */
|
|
51
|
+
var ColumnHeader = /*#__PURE__*/ TableHeader.extend({ renderHTML({ HTMLAttributes }) {
|
|
52
|
+
const { colspan, rowspan, ...rest } = HTMLAttributes;
|
|
53
|
+
const spans = {
|
|
54
|
+
...Number(colspan) > 1 ? { colspan } : {},
|
|
55
|
+
...Number(rowspan) > 1 ? { rowspan } : {}
|
|
56
|
+
};
|
|
57
|
+
return [
|
|
58
|
+
"th",
|
|
59
|
+
mergeAttributes(this.options.HTMLAttributes, rest, spans, { scope: "col" }),
|
|
60
|
+
0
|
|
61
|
+
];
|
|
62
|
+
} });
|
|
63
|
+
/** Completes what people type in a link field: `example.com` → `https://example.com`, `a@b.co` → `mailto:a@b.co`. */
|
|
64
|
+
function normalizeUrl(input) {
|
|
65
|
+
const value = input.trim();
|
|
66
|
+
if (!value || /^[a-z][a-z\d+\-.]*:/i.test(value) || value.startsWith("/") || value.startsWith("#")) return value;
|
|
67
|
+
if (/^[^\s@/]+@[^\s@/]+\.[^\s@/]+$/.test(value)) return `mailto:${value}`;
|
|
68
|
+
return `https://${value}`;
|
|
69
|
+
}
|
|
70
|
+
/** The Tiptap extensions for a set of formats (also defines the schema used for validation). */
|
|
71
|
+
function extensionsFor(options = {}) {
|
|
72
|
+
const formats = new Set(options.formats ?? defaultFormats);
|
|
73
|
+
const on = (f) => formats.has(f);
|
|
74
|
+
const lists = on("bulletList") || on("orderedList");
|
|
75
|
+
return [
|
|
76
|
+
StarterKit.configure({
|
|
77
|
+
bold: on("bold") ? {} : false,
|
|
78
|
+
italic: on("italic") ? {} : false,
|
|
79
|
+
strike: on("strike") ? {} : false,
|
|
80
|
+
code: on("code") ? {} : false,
|
|
81
|
+
heading: on("heading") ? { levels: [...options.headingLevels ?? [2, 3]] } : false,
|
|
82
|
+
bulletList: on("bulletList") ? {} : false,
|
|
83
|
+
orderedList: on("orderedList") ? {} : false,
|
|
84
|
+
listItem: lists ? {} : false,
|
|
85
|
+
listKeymap: lists ? {} : false,
|
|
86
|
+
blockquote: on("blockquote") ? {} : false,
|
|
87
|
+
codeBlock: on("codeBlock") ? {} : false,
|
|
88
|
+
link: on("link") ? {
|
|
89
|
+
openOnClick: false,
|
|
90
|
+
autolink: true,
|
|
91
|
+
linkOnPaste: true,
|
|
92
|
+
defaultProtocol: "https",
|
|
93
|
+
isAllowedUri: (url) => isSafeUrl(url, options.allowRelativeLinks),
|
|
94
|
+
HTMLAttributes: {
|
|
95
|
+
rel: "noopener noreferrer nofollow",
|
|
96
|
+
target: null
|
|
97
|
+
}
|
|
98
|
+
} : false,
|
|
99
|
+
underline: false,
|
|
100
|
+
horizontalRule: false,
|
|
101
|
+
trailingNode: false
|
|
102
|
+
}),
|
|
103
|
+
...on("image") ? [Image.configure({
|
|
104
|
+
inline: false,
|
|
105
|
+
allowBase64: false,
|
|
106
|
+
HTMLAttributes: { loading: "lazy" }
|
|
107
|
+
})] : [],
|
|
108
|
+
...on("table") ? [
|
|
109
|
+
AccessibleTable.configure({ resizable: false }),
|
|
110
|
+
TableRow,
|
|
111
|
+
ColumnHeader,
|
|
112
|
+
TableCell
|
|
113
|
+
] : []
|
|
114
|
+
];
|
|
115
|
+
}
|
|
116
|
+
var schemas = /* @__PURE__ */ new Map();
|
|
117
|
+
/** Schemas are built once per option set. */
|
|
118
|
+
function schemaFor(options = {}) {
|
|
119
|
+
const key = JSON.stringify([
|
|
120
|
+
[...options.formats ?? defaultFormats].sort(),
|
|
121
|
+
options.headingLevels ?? [2, 3],
|
|
122
|
+
Boolean(options.allowRelativeLinks)
|
|
123
|
+
]);
|
|
124
|
+
let schema = schemas.get(key);
|
|
125
|
+
if (!schema) {
|
|
126
|
+
schema = getSchema(extensionsFor(options));
|
|
127
|
+
schemas.set(key, schema);
|
|
128
|
+
}
|
|
129
|
+
return schema;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Checks a document received from a client before you store it (ADR-0011): only the allowed
|
|
133
|
+
* nodes and marks, structurally valid, and every link a safe URL — the schema alone accepts any
|
|
134
|
+
* `href`, including `javascript:`. Optionally limits the text length. Rejects rather than repairs.
|
|
135
|
+
*/
|
|
136
|
+
function validateDocument(json, options = {}) {
|
|
137
|
+
const errors = [];
|
|
138
|
+
let node;
|
|
139
|
+
try {
|
|
140
|
+
node = Node.fromJSON(schemaFor(options), json);
|
|
141
|
+
node.check();
|
|
142
|
+
} catch (error) {
|
|
143
|
+
return {
|
|
144
|
+
valid: false,
|
|
145
|
+
errors: [`Invalid document: ${error.message}`]
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
node.descendants((child) => {
|
|
149
|
+
if (child.type.name === "image") {
|
|
150
|
+
const src = String(child.attrs.src ?? "");
|
|
151
|
+
if (!isSafeImageUrl(src, options.allowRelativeLinks)) errors.push(`Unsafe image source: ${src.slice(0, 80)}`);
|
|
152
|
+
if (typeof child.attrs.alt !== "string") errors.push(`Image without alt text: ${src.slice(0, 80)}`);
|
|
153
|
+
}
|
|
154
|
+
for (const mark of child.marks) if (mark.type.name === "link" && !isSafeUrl(String(mark.attrs.href ?? ""), options.allowRelativeLinks)) errors.push(`Unsafe link: ${String(mark.attrs.href).slice(0, 80)}`);
|
|
155
|
+
});
|
|
156
|
+
const text = node.textBetween(0, node.content.size, "\n", "\n");
|
|
157
|
+
if (options.maxLength !== void 0 && text.length > options.maxLength) errors.push(`Text is ${text.length} characters (limit ${options.maxLength})`);
|
|
158
|
+
return errors.length ? {
|
|
159
|
+
valid: false,
|
|
160
|
+
errors
|
|
161
|
+
} : {
|
|
162
|
+
valid: true,
|
|
163
|
+
doc: node.toJSON(),
|
|
164
|
+
text
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/** True for a document with no text (an empty paragraph), e.g. for `required` checks. */
|
|
168
|
+
function isEmptyDocument(json) {
|
|
169
|
+
if (!json) return true;
|
|
170
|
+
const walk = (n) => n.text ? n.text.trim() === "" : (n.content ?? []).every(walk);
|
|
171
|
+
return walk(json);
|
|
172
|
+
}
|
|
173
|
+
var escapeText = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
174
|
+
var escapeAttr = (s) => escapeText(s).replace(/"/g, """);
|
|
175
|
+
var VOID = /* @__PURE__ */ new Set([
|
|
176
|
+
"br",
|
|
177
|
+
"hr",
|
|
178
|
+
"img",
|
|
179
|
+
"col"
|
|
180
|
+
]);
|
|
181
|
+
var ATTR_NAME = /^[a-z][a-z0-9-]*$/;
|
|
182
|
+
/** Renders a schema's DOMOutputSpec (`['p', attrs, 0]`) to a string; `hole` is the content. */
|
|
183
|
+
function specToHtml(spec, hole) {
|
|
184
|
+
if (typeof spec === "string") return escapeText(spec);
|
|
185
|
+
if (!Array.isArray(spec)) throw new Error("Unsupported output spec (DOM node): rendering stays DOM-free");
|
|
186
|
+
const [tag, ...rest] = spec;
|
|
187
|
+
const name = String(tag).toLowerCase();
|
|
188
|
+
if (!ATTR_NAME.test(name)) throw new Error(`Invalid tag ${name}`);
|
|
189
|
+
let attrs = "";
|
|
190
|
+
let children = rest;
|
|
191
|
+
const first = rest[0];
|
|
192
|
+
if (first && typeof first === "object" && !Array.isArray(first)) {
|
|
193
|
+
children = rest.slice(1);
|
|
194
|
+
for (const [key, value] of Object.entries(first)) {
|
|
195
|
+
if (value === null || value === void 0 || value === false || !ATTR_NAME.test(key) || /^on/i.test(key)) continue;
|
|
196
|
+
attrs += ` ${key}="${escapeAttr(String(value))}"`;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (VOID.has(name)) return `<${name}${attrs}>`;
|
|
200
|
+
const inner = children.map((c) => c === 0 ? hole : specToHtml(c, hole)).join("");
|
|
201
|
+
return `<${name}${attrs}>${inner}</${name}>`;
|
|
202
|
+
}
|
|
203
|
+
function nodeToHtml(node, allowRelative) {
|
|
204
|
+
if (node.isText) return node.marks.reduceRight((html, mark) => {
|
|
205
|
+
if (mark.type.name === "link" && !isSafeUrl(String(mark.attrs.href ?? ""), allowRelative)) return html;
|
|
206
|
+
const toDOM = mark.type.spec.toDOM;
|
|
207
|
+
return toDOM ? specToHtml(toDOM(mark, true), html) : html;
|
|
208
|
+
}, escapeText(node.text ?? ""));
|
|
209
|
+
if (node.type.name === "image" && !isSafeImageUrl(String(node.attrs.src ?? ""), allowRelative)) return "";
|
|
210
|
+
let inner = "";
|
|
211
|
+
node.forEach((child) => inner += nodeToHtml(child, allowRelative));
|
|
212
|
+
if (node.type.name === "doc") return inner;
|
|
213
|
+
const toDOM = node.type.spec.toDOM;
|
|
214
|
+
return toDOM ? specToHtml(toDOM(node), inner) : inner;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Renders a stored document to HTML without a DOM (Node, edge runtimes, browsers). Invalid
|
|
218
|
+
* documents throw; unsafe links are dropped. Run the result through your HTML sanitiser too
|
|
219
|
+
* (DOMPurify or sanitize-html) before showing it to other users — defence in depth.
|
|
220
|
+
*/
|
|
221
|
+
function renderHtml(json, options = {}) {
|
|
222
|
+
const node = Node.fromJSON(schemaFor(options), json);
|
|
223
|
+
node.check();
|
|
224
|
+
return nodeToHtml(node, Boolean(options.allowRelativeLinks));
|
|
225
|
+
}
|
|
226
|
+
export { defaultFormats, extensionsFor, isEmptyDocument, isSafeImageUrl, isSafeUrl, normalizeUrl, renderHtml, schemaFor, validateDocument };
|
|
227
|
+
|
|
228
|
+
//# sourceMappingURL=document.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.js","names":["PMNode"],"sources":["../src/document.ts"],"sourcesContent":["// Shared by the editor (browser) and `@reactloom/editor/server`: which formats exist, the Tiptap\n// extensions for them, URL rules, validation, and DOM-free HTML rendering.\nimport { getSchema, mergeAttributes, type AnyExtension, type JSONContent } from '@tiptap/core';\nimport { Node as PMNode, type DOMOutputSpec, type Mark, type Schema } from '@tiptap/pm/model';\nimport StarterKit from '@tiptap/starter-kit';\nimport Image from '@tiptap/extension-image';\nimport { Table, TableCell, TableHeader, TableRow } from '@tiptap/extension-table';\n\n/** A rich-text document as stored: ProseMirror/Tiptap JSON. Store this, not HTML. */\nexport type RichTextDocument = JSONContent;\n\n/** Formatting a field allows. Anything else is dropped on paste and rejected by validation. */\nexport type RichTextFormat =\n | 'bold'\n | 'italic'\n | 'strike'\n | 'code'\n | 'link'\n | 'heading'\n | 'bulletList'\n | 'orderedList'\n | 'blockquote'\n | 'codeBlock'\n | 'image'\n | 'table';\n\nexport const defaultFormats: readonly RichTextFormat[] = ['bold', 'italic', 'link', 'bulletList', 'orderedList'];\n\nexport interface DocumentOptions {\n /** @default ['bold', 'italic', 'link', 'bulletList', 'orderedList'] */\n formats?: readonly RichTextFormat[];\n /** Heading levels when `heading` is allowed. @default [2, 3] */\n headingLevels?: ReadonlyArray<1 | 2 | 3 | 4 | 5 | 6>;\n /** Accept links without a scheme (`/help`, `#top`). @default false */\n allowRelativeLinks?: boolean;\n}\n\nconst SAFE_PROTOCOLS = new Set(['http:', 'https:', 'mailto:']);\n\n/** `http`, `https` and `mailto` URLs (and relative ones when allowed). Never `javascript:` or `data:`. */\nexport function isSafeUrl(url: string, allowRelative = false): boolean {\n const value = url.trim();\n if (!value) return false;\n // Control characters and whitespace inside a scheme are used to smuggle `java\\tscript:`.\n for (const ch of value) {\n const code = ch.charCodeAt(0);\n if (code < 0x20 || code === 0x7f) return false;\n }\n const scheme = /^([a-z][a-z\\d+\\-.]*):/i.exec(value);\n if (!scheme) return allowRelative && !value.startsWith('//');\n try {\n return SAFE_PROTOCOLS.has(new URL(value).protocol);\n } catch {\n return false;\n }\n}\n\n/** Image sources: `https` and `http` only (and relative paths when allowed) — never `data:`, `blob:` or `javascript:`. */\nexport function isSafeImageUrl(url: string, allowRelative = false): boolean {\n if (!isSafeUrl(url, allowRelative)) return false;\n return !/^mailto:/i.test(url.trim());\n}\n\n/**\n * Tables without Tab bindings: Tiptap moves between cells with Tab, which would trap keyboard\n * users inside the editor whenever the caret is in a table. Arrow keys move between cells\n * instead, and Tab keeps leaving the field as everywhere else.\n */\nconst AccessibleTable = /*#__PURE__*/ Table.extend({\n addKeyboardShortcuts() {\n const shortcuts = { ...this.parent?.() };\n delete shortcuts.Tab;\n delete shortcuts['Shift-Tab'];\n return shortcuts;\n },\n});\n\n/** Header cells are column headers (the editor inserts tables with a header row). */\nconst ColumnHeader = /*#__PURE__*/ TableHeader.extend({\n renderHTML({ HTMLAttributes }) {\n const { colspan, rowspan, ...rest } = HTMLAttributes as Record<string, unknown>;\n const spans = { ...(Number(colspan) > 1 ? { colspan } : {}), ...(Number(rowspan) > 1 ? { rowspan } : {}) };\n return ['th', mergeAttributes(this.options.HTMLAttributes, rest, spans, { scope: 'col' }), 0];\n },\n});\n\n/** Completes what people type in a link field: `example.com` → `https://example.com`, `a@b.co` → `mailto:a@b.co`. */\nexport function normalizeUrl(input: string): string {\n const value = input.trim();\n if (!value || /^[a-z][a-z\\d+\\-.]*:/i.test(value) || value.startsWith('/') || value.startsWith('#')) return value;\n if (/^[^\\s@/]+@[^\\s@/]+\\.[^\\s@/]+$/.test(value)) return `mailto:${value}`;\n return `https://${value}`;\n}\n\n/** The Tiptap extensions for a set of formats (also defines the schema used for validation). */\nexport function extensionsFor(options: DocumentOptions = {}): AnyExtension[] {\n const formats = new Set(options.formats ?? defaultFormats);\n const on = (f: RichTextFormat) => formats.has(f);\n const lists = on('bulletList') || on('orderedList');\n return [\n StarterKit.configure({\n bold: on('bold') ? {} : false,\n italic: on('italic') ? {} : false,\n strike: on('strike') ? {} : false,\n code: on('code') ? {} : false,\n heading: on('heading') ? { levels: [...(options.headingLevels ?? [2, 3])] } : false,\n bulletList: on('bulletList') ? {} : false,\n orderedList: on('orderedList') ? {} : false,\n listItem: lists ? {} : false,\n listKeymap: lists ? {} : false,\n blockquote: on('blockquote') ? {} : false,\n codeBlock: on('codeBlock') ? {} : false,\n link: on('link')\n ? {\n openOnClick: false,\n autolink: true,\n linkOnPaste: true,\n defaultProtocol: 'https',\n isAllowedUri: (url) => isSafeUrl(url, options.allowRelativeLinks),\n HTMLAttributes: { rel: 'noopener noreferrer nofollow', target: null },\n }\n : false,\n underline: false,\n horizontalRule: false,\n // Stored documents end where the author stopped (no automatic empty paragraph).\n trailingNode: false,\n }),\n ...(on('image') ? [Image.configure({ inline: false, allowBase64: false, HTMLAttributes: { loading: 'lazy' } })] : []),\n ...(on('table') ? [AccessibleTable.configure({ resizable: false }), TableRow, ColumnHeader, TableCell] : []),\n ];\n}\n\nconst schemas = new Map<string, Schema>();\n/** Schemas are built once per option set. */\nexport function schemaFor(options: DocumentOptions = {}): Schema {\n const key = JSON.stringify([[...(options.formats ?? defaultFormats)].sort(), options.headingLevels ?? [2, 3], Boolean(options.allowRelativeLinks)]);\n let schema = schemas.get(key);\n if (!schema) {\n schema = getSchema(extensionsFor(options));\n schemas.set(key, schema);\n }\n return schema;\n}\n\nexport type ValidationResult = { valid: true; doc: RichTextDocument; text: string } | { valid: false; errors: string[] };\n\n/**\n * Checks a document received from a client before you store it (ADR-0011): only the allowed\n * nodes and marks, structurally valid, and every link a safe URL — the schema alone accepts any\n * `href`, including `javascript:`. Optionally limits the text length. Rejects rather than repairs.\n */\nexport function validateDocument(json: unknown, options: DocumentOptions & { maxLength?: number } = {}): ValidationResult {\n const errors: string[] = [];\n let node: PMNode;\n try {\n node = PMNode.fromJSON(schemaFor(options), json as Record<string, unknown>);\n node.check();\n } catch (error) {\n return { valid: false, errors: [`Invalid document: ${(error as Error).message}`] };\n }\n node.descendants((child) => {\n if (child.type.name === 'image') {\n const src = String(child.attrs.src ?? '');\n if (!isSafeImageUrl(src, options.allowRelativeLinks)) errors.push(`Unsafe image source: ${src.slice(0, 80)}`);\n // Alt text is required; an empty string marks a decorative image deliberately.\n if (typeof child.attrs.alt !== 'string') errors.push(`Image without alt text: ${src.slice(0, 80)}`);\n }\n for (const mark of child.marks) {\n if (mark.type.name === 'link' && !isSafeUrl(String(mark.attrs.href ?? ''), options.allowRelativeLinks)) {\n errors.push(`Unsafe link: ${String(mark.attrs.href).slice(0, 80)}`);\n }\n }\n });\n const text = node.textBetween(0, node.content.size, '\\n', '\\n');\n if (options.maxLength !== undefined && text.length > options.maxLength) errors.push(`Text is ${text.length} characters (limit ${options.maxLength})`);\n return errors.length ? { valid: false, errors } : { valid: true, doc: node.toJSON() as RichTextDocument, text };\n}\n\n/** True for a document with no text (an empty paragraph), e.g. for `required` checks. */\nexport function isEmptyDocument(json: RichTextDocument | null | undefined): boolean {\n if (!json) return true;\n const walk = (n: JSONContent): boolean => (n.text ? n.text.trim() === '' : (n.content ?? []).every(walk));\n return walk(json);\n}\n\n// ----- DOM-free HTML -----\n\nconst escapeText = (s: string) => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');\nconst escapeAttr = (s: string) => escapeText(s).replace(/\"/g, '"');\nconst VOID = new Set(['br', 'hr', 'img', 'col']);\nconst ATTR_NAME = /^[a-z][a-z0-9-]*$/;\n\n/** Renders a schema's DOMOutputSpec (`['p', attrs, 0]`) to a string; `hole` is the content. */\nfunction specToHtml(spec: DOMOutputSpec, hole: string): string {\n if (typeof spec === 'string') return escapeText(spec);\n if (!Array.isArray(spec)) throw new Error('Unsupported output spec (DOM node): rendering stays DOM-free');\n const [tag, ...rest] = spec as [string, ...unknown[]];\n const name = String(tag).toLowerCase();\n if (!ATTR_NAME.test(name)) throw new Error(`Invalid tag ${name}`);\n let attrs = '';\n let children = rest;\n const first = rest[0];\n if (first && typeof first === 'object' && !Array.isArray(first)) {\n children = rest.slice(1);\n for (const [key, value] of Object.entries(first as Record<string, unknown>)) {\n if (value === null || value === undefined || value === false || !ATTR_NAME.test(key) || /^on/i.test(key)) continue;\n attrs += ` ${key}=\"${escapeAttr(String(value))}\"`;\n }\n }\n if (VOID.has(name)) return `<${name}${attrs}>`;\n const inner = children.map((c) => (c === 0 ? hole : specToHtml(c as DOMOutputSpec, hole))).join('');\n return `<${name}${attrs}>${inner}</${name}>`;\n}\n\nfunction nodeToHtml(node: PMNode, allowRelative: boolean): string {\n if (node.isText) {\n return node.marks.reduceRight((html, mark: Mark) => {\n if (mark.type.name === 'link' && !isSafeUrl(String(mark.attrs.href ?? ''), allowRelative)) return html;\n const toDOM = mark.type.spec.toDOM;\n return toDOM ? specToHtml(toDOM(mark, true), html) : html;\n }, escapeText(node.text ?? ''));\n }\n if (node.type.name === 'image' && !isSafeImageUrl(String(node.attrs.src ?? ''), allowRelative)) return '';\n let inner = '';\n node.forEach((child) => (inner += nodeToHtml(child, allowRelative)));\n if (node.type.name === 'doc') return inner;\n const toDOM = node.type.spec.toDOM;\n return toDOM ? specToHtml(toDOM(node), inner) : inner;\n}\n\n/**\n * Renders a stored document to HTML without a DOM (Node, edge runtimes, browsers). Invalid\n * documents throw; unsafe links are dropped. Run the result through your HTML sanitiser too\n * (DOMPurify or sanitize-html) before showing it to other users — defence in depth.\n */\nexport function renderHtml(json: RichTextDocument, options: DocumentOptions = {}): string {\n const node = PMNode.fromJSON(schemaFor(options), json);\n node.check();\n return nodeToHtml(node, Boolean(options.allowRelativeLinks));\n}\n"],"mappings":";;;;;;AA0BA,IAAa,iBAA4C;CAAC;CAAQ;CAAU;CAAQ;CAAc;AAAa;AAW/G,IAAM,iCAAiB,IAAI,IAAI;CAAC;CAAS;CAAU;AAAS,CAAC;;AAG7D,SAAgB,UAAU,KAAa,gBAAgB,OAAgB;CACrE,MAAM,QAAQ,IAAI,KAAK;CACvB,IAAI,CAAC,OAAO,OAAO;CAEnB,KAAK,MAAM,MAAM,OAAO;EACtB,MAAM,OAAO,GAAG,WAAW,CAAC;EAC5B,IAAI,OAAO,MAAQ,SAAS,KAAM,OAAO;CAC3C;CAEA,IAAI,CADW,yBAAyB,KAAK,KACxC,GAAQ,OAAO,iBAAiB,CAAC,MAAM,WAAW,IAAI;CAC3D,IAAI;EACF,OAAO,eAAe,IAAI,IAAI,IAAI,KAAK,CAAC,CAAC,QAAQ;CACnD,QAAQ;EACN,OAAO;CACT;AACF;;AAGA,SAAgB,eAAe,KAAa,gBAAgB,OAAgB;CAC1E,IAAI,CAAC,UAAU,KAAK,aAAa,GAAG,OAAO;CAC3C,OAAO,CAAC,YAAY,KAAK,IAAI,KAAK,CAAC;AACrC;;;;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AgC;CAChE,IAAI,KAAK,QACP,OAAO,KAAK,MAAM,aAAa,MAAM,SAAe;EAClD,IAAI,KAAK,KAAK,SAAS,UAAU,CAAC,UAAU,OAAO,KAAK,MAAM,QAAQ,EAAE,GAAG,aAAa,GAAG,OAAO;EAClG,MAAM,QAAQ,KAAK,KAAK,KAAK;EAC7B,OAAO,QAAQ,WAAW,MAAM,MAAM,IAAI,GAAG,IAAI,IAAI;CACvD,GAAG,WAAW,KAAK,QAAQ,EAAE,CAAC;CAEhC,IAAI,KAAK,KAAK,SAAS,WAAW,CAAC,eAAe,OAAO,KAAK,MAAM,OAAO,EAAE,GAAG,aAAa,GAAG,OAAO;CACvG,IAAI,QAAQ;CACZ,KAAK,SAAS,UAAW,SAAS,WAAW,OAAO,aAAa,CAAE;CACnE,IAAI,KAAK,KAAK,SAAS,OAAO,OAAO;CACrC,MAAM,QAAQ,KAAK,KAAK,KAAK;CAC7B,OAAO,QAAQ,WAAW,MAAM,IAAI,GAAG,KAAK,IAAI;AAClD;;;;;;AAOA,SAAgB,WAAW,MAAwB,UAA2B,CAAC,GAAW;CACxF,MAAM,OAAOA,KAAO,SAAS,UAAU,OAAO,GAAG,IAAI;CACrD,KAAK,MAAM;CACX,OAAO,WAAW,MAAM,QAAQ,QAAQ,kBAAkB,CAAC;AAC7D"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// src/editor.module.css
|
|
2
|
+
var root = "pl-editor-root-0noQBA";
|
|
3
|
+
var frame = "pl-editor-frame-0noQBA";
|
|
4
|
+
var toolbar = "pl-editor-toolbar-0noQBA";
|
|
5
|
+
var toolSlot = "pl-editor-toolSlot-0noQBA";
|
|
6
|
+
var tool = "pl-editor-tool-0noQBA";
|
|
7
|
+
var level = "pl-editor-level-0noQBA";
|
|
8
|
+
var editorHost = "pl-editor-editorHost-0noQBA";
|
|
9
|
+
var content = "pl-editor-content-0noQBA";
|
|
10
|
+
var linkDialog = "pl-editor-linkDialog-0noQBA";
|
|
11
|
+
var linkTitle = "pl-editor-linkTitle-0noQBA";
|
|
12
|
+
var editor_module_default = {
|
|
13
|
+
root,
|
|
14
|
+
frame,
|
|
15
|
+
toolbar,
|
|
16
|
+
toolSlot,
|
|
17
|
+
tool,
|
|
18
|
+
level,
|
|
19
|
+
editorHost,
|
|
20
|
+
content,
|
|
21
|
+
linkDialog,
|
|
22
|
+
linkTitle
|
|
23
|
+
};
|
|
24
|
+
export { content, editor_module_default as default, editorHost, frame, level, linkDialog, linkTitle, root, tool, toolSlot, toolbar };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=editor.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editor.module.js","names":[],"sources":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { RichTextEditor, type RichTextEditorProps } from './rich-text-editor.js';
|
|
2
|
+
export { defaultMessages, type EditorMessages } from './messages.js';
|
|
3
|
+
export { validateDocument, renderHtml, isEmptyDocument, isSafeUrl, isSafeImageUrl, normalizeUrl, defaultFormats, type DocumentOptions, type RichTextDocument, type RichTextFormat, type ValidationResult, } from './document.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,eAAe,EACf,SAAS,EACT,cAAc,EACd,YAAY,EACZ,cAAc,EACd,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,gBAAgB,GACtB,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { RichTextEditor } from "./rich-text-editor.js";
|
|
2
|
+
import { defaultMessages } from "./messages.js";
|
|
3
|
+
import { defaultFormats, isEmptyDocument, isSafeImageUrl, isSafeUrl, normalizeUrl, renderHtml, validateDocument } from "./document.js";
|
|
4
|
+
export { RichTextEditor, defaultFormats, defaultMessages, isEmptyDocument, isSafeImageUrl, isSafeUrl, normalizeUrl, renderHtml, validateDocument };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** Every built-in string, for translation (`messages` prop). */
|
|
2
|
+
export interface EditorMessages {
|
|
3
|
+
toolbar: string;
|
|
4
|
+
bold: string;
|
|
5
|
+
italic: string;
|
|
6
|
+
strike: string;
|
|
7
|
+
code: string;
|
|
8
|
+
heading: (level: number) => string;
|
|
9
|
+
bulletList: string;
|
|
10
|
+
orderedList: string;
|
|
11
|
+
blockquote: string;
|
|
12
|
+
codeBlock: string;
|
|
13
|
+
link: string;
|
|
14
|
+
undo: string;
|
|
15
|
+
redo: string;
|
|
16
|
+
linkDialogTitle: string;
|
|
17
|
+
linkAddress: string;
|
|
18
|
+
linkHint: string;
|
|
19
|
+
linkInvalid: string;
|
|
20
|
+
applyLink: string;
|
|
21
|
+
removeLink: string;
|
|
22
|
+
cancel: string;
|
|
23
|
+
image: string;
|
|
24
|
+
imageDialogTitle: string;
|
|
25
|
+
imageAddress: string;
|
|
26
|
+
imageAlt: string;
|
|
27
|
+
imageAltHint: string;
|
|
28
|
+
imageDecorative: string;
|
|
29
|
+
imageInvalid: string;
|
|
30
|
+
imageAltRequired: string;
|
|
31
|
+
insertImage: string;
|
|
32
|
+
table: string;
|
|
33
|
+
addRow: string;
|
|
34
|
+
addColumn: string;
|
|
35
|
+
deleteRow: string;
|
|
36
|
+
deleteColumn: string;
|
|
37
|
+
deleteTable: string;
|
|
38
|
+
/** Visually hidden instructions for the editable area. */
|
|
39
|
+
keyboardHint: string;
|
|
40
|
+
}
|
|
41
|
+
export declare const defaultMessages: EditorMessages;
|
|
42
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,0DAA0D;IAC1D,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,eAAe,EAAE,cAqC7B,CAAC"}
|
package/dist/messages.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// src/messages.ts
|
|
2
|
+
var defaultMessages = {
|
|
3
|
+
toolbar: "Formatting",
|
|
4
|
+
bold: "Bold",
|
|
5
|
+
italic: "Italic",
|
|
6
|
+
strike: "Strikethrough",
|
|
7
|
+
code: "Inline code",
|
|
8
|
+
heading: (level) => `Heading ${level}`,
|
|
9
|
+
bulletList: "Bulleted list",
|
|
10
|
+
orderedList: "Numbered list",
|
|
11
|
+
blockquote: "Quote",
|
|
12
|
+
codeBlock: "Code block",
|
|
13
|
+
link: "Link",
|
|
14
|
+
undo: "Undo",
|
|
15
|
+
redo: "Redo",
|
|
16
|
+
linkDialogTitle: "Link",
|
|
17
|
+
linkAddress: "Address",
|
|
18
|
+
linkHint: "A web address or an email address.",
|
|
19
|
+
linkInvalid: "Enter a web address (https://…) or an email address.",
|
|
20
|
+
applyLink: "Apply",
|
|
21
|
+
removeLink: "Remove link",
|
|
22
|
+
cancel: "Cancel",
|
|
23
|
+
image: "Image",
|
|
24
|
+
imageDialogTitle: "Image",
|
|
25
|
+
imageAddress: "Image address",
|
|
26
|
+
imageAlt: "Alternative text",
|
|
27
|
+
imageAltHint: "What the image shows, for people who cannot see it.",
|
|
28
|
+
imageDecorative: "Decorative image (no alternative text)",
|
|
29
|
+
imageInvalid: "Enter a web address that starts with https://.",
|
|
30
|
+
imageAltRequired: "Describe the image, or mark it as decorative.",
|
|
31
|
+
insertImage: "Insert image",
|
|
32
|
+
table: "Insert table",
|
|
33
|
+
addRow: "Add row below",
|
|
34
|
+
addColumn: "Add column after",
|
|
35
|
+
deleteRow: "Delete row",
|
|
36
|
+
deleteColumn: "Delete column",
|
|
37
|
+
deleteTable: "Delete table",
|
|
38
|
+
keyboardHint: "Alt+F10 moves to the formatting toolbar."
|
|
39
|
+
};
|
|
40
|
+
export { defaultMessages };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","names":[],"sources":["../src/messages.ts"],"sourcesContent":["/** Every built-in string, for translation (`messages` prop). */\nexport interface EditorMessages {\n toolbar: string;\n bold: string;\n italic: string;\n strike: string;\n code: string;\n heading: (level: number) => string;\n bulletList: string;\n orderedList: string;\n blockquote: string;\n codeBlock: string;\n link: string;\n undo: string;\n redo: string;\n linkDialogTitle: string;\n linkAddress: string;\n linkHint: string;\n linkInvalid: string;\n applyLink: string;\n removeLink: string;\n cancel: string;\n image: string;\n imageDialogTitle: string;\n imageAddress: string;\n imageAlt: string;\n imageAltHint: string;\n imageDecorative: string;\n imageInvalid: string;\n imageAltRequired: string;\n insertImage: string;\n table: string;\n addRow: string;\n addColumn: string;\n deleteRow: string;\n deleteColumn: string;\n deleteTable: string;\n /** Visually hidden instructions for the editable area. */\n keyboardHint: string;\n}\n\nexport const defaultMessages: EditorMessages = {\n toolbar: 'Formatting',\n bold: 'Bold',\n italic: 'Italic',\n strike: 'Strikethrough',\n code: 'Inline code',\n heading: (level) => `Heading ${level}`,\n bulletList: 'Bulleted list',\n orderedList: 'Numbered list',\n blockquote: 'Quote',\n codeBlock: 'Code block',\n link: 'Link',\n undo: 'Undo',\n redo: 'Redo',\n linkDialogTitle: 'Link',\n linkAddress: 'Address',\n linkHint: 'A web address or an email address.',\n linkInvalid: 'Enter a web address (https://…) or an email address.',\n applyLink: 'Apply',\n removeLink: 'Remove link',\n cancel: 'Cancel',\n image: 'Image',\n imageDialogTitle: 'Image',\n imageAddress: 'Image address',\n imageAlt: 'Alternative text',\n imageAltHint: 'What the image shows, for people who cannot see it.',\n imageDecorative: 'Decorative image (no alternative text)',\n imageInvalid: 'Enter a web address that starts with https://.',\n imageAltRequired: 'Describe the image, or mark it as decorative.',\n insertImage: 'Insert image',\n table: 'Insert table',\n addRow: 'Add row below',\n addColumn: 'Add column after',\n deleteRow: 'Delete row',\n deleteColumn: 'Delete column',\n deleteTable: 'Delete table',\n keyboardHint: 'Alt+F10 moves to the formatting toolbar.',\n};\n"],"mappings":";AAyCA,IAAa,kBAAkC;CAC7C,SAAS;CACT,MAAM;CACN,QAAQ;CACR,QAAQ;CACR,MAAM;CACN,UAAU,UAAU,WAAW;CAC/B,YAAY;CACZ,aAAa;CACb,YAAY;CACZ,WAAW;CACX,MAAM;CACN,MAAM;CACN,MAAM;CACN,iBAAiB;CACjB,aAAa;CACb,UAAU;CACV,aAAa;CACb,WAAW;CACX,YAAY;CACZ,QAAQ;CACR,OAAO;CACP,kBAAkB;CAClB,cAAc;CACd,UAAU;CACV,cAAc;CACd,iBAAiB;CACjB,cAAc;CACd,kBAAkB;CAClB,aAAa;CACb,OAAO;CACP,QAAQ;CACR,WAAW;CACX,WAAW;CACX,cAAc;CACd,aAAa;CACb,cAAc;AAChB"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type DocumentOptions, type RichTextDocument } from './document.js';
|
|
3
|
+
import { type EditorMessages } from './messages.js';
|
|
4
|
+
export interface RichTextEditorProps extends DocumentOptions {
|
|
5
|
+
/** Visible label; it names the editable area. */
|
|
6
|
+
label: ReactNode;
|
|
7
|
+
hideLabel?: boolean;
|
|
8
|
+
description?: ReactNode;
|
|
9
|
+
error?: ReactNode;
|
|
10
|
+
invalid?: boolean;
|
|
11
|
+
required?: boolean;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
/** Shows the content without the toolbar; text can be selected and copied. */
|
|
14
|
+
readOnly?: boolean;
|
|
15
|
+
/** The document (Tiptap/ProseMirror JSON). Store this, not HTML. */
|
|
16
|
+
value?: RichTextDocument | null;
|
|
17
|
+
defaultValue?: RichTextDocument | null;
|
|
18
|
+
onValueChange?: (value: RichTextDocument) => void;
|
|
19
|
+
/** Shown while the document is empty. */
|
|
20
|
+
placeholder?: string;
|
|
21
|
+
/** Submits the document as JSON in a hidden input with this name. */
|
|
22
|
+
name?: string;
|
|
23
|
+
/** Minimum height of the editable area (CSS length or px). @default 120 */
|
|
24
|
+
minHeight?: number | string;
|
|
25
|
+
/** Scroll inside the field beyond this height (CSS length or px). */
|
|
26
|
+
maxHeight?: number | string;
|
|
27
|
+
/** Show the formatting toolbar. @default true */
|
|
28
|
+
toolbar?: boolean;
|
|
29
|
+
messages?: Partial<EditorMessages>;
|
|
30
|
+
onFocus?: () => void;
|
|
31
|
+
onBlur?: () => void;
|
|
32
|
+
autoFocus?: boolean;
|
|
33
|
+
className?: string;
|
|
34
|
+
id?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A labelled rich-text field (ADR-0011): Tiptap/ProseMirror editing with a roving-focus toolbar,
|
|
38
|
+
* a link dialog that only accepts safe URLs, and a JSON value. The schema follows `formats`, so
|
|
39
|
+
* pasted formatting that a field does not allow is dropped.
|
|
40
|
+
*/
|
|
41
|
+
export declare const RichTextEditor: import("react").ForwardRefExoticComponent<RichTextEditorProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
42
|
+
//# sourceMappingURL=rich-text-editor.d.ts.map
|