@astryxdesign/richtext 0.7.1-canary.ff40b78 → 0.7.1
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/CHANGELOG.md +23 -0
- package/README.md +47 -57
- package/astryx.integration.mjs +1 -1
- package/dist/RichTextEditor.d.ts +16 -12
- package/dist/RichTextEditor.d.ts.map +1 -1
- package/dist/RichTextEditor.js +40 -45
- package/dist/RichTextEditorAutoLinkPlugin.d.ts +3 -3
- package/dist/RichTextEditorAutoLinkPlugin.js +3 -3
- package/dist/RichTextEditorToolbar.d.ts +19 -8
- package/dist/RichTextEditorToolbar.d.ts.map +1 -1
- package/dist/RichTextEditorToolbar.js +16 -9
- package/dist/RichTextView.d.ts +1 -1
- package/dist/RichTextView.js +1 -1
- package/dist/editorTheme.d.ts.map +1 -1
- package/dist/editorTheme.js +15 -4
- package/dist/index.d.ts +10 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -4
- package/dist/linkUtils.js +1 -1
- package/dist/markdownLink.d.ts.map +1 -1
- package/dist/markdownLink.js +25 -33
- package/dist/markdownListExport.d.ts.map +1 -1
- package/dist/markdownListExport.js +4 -1
- package/dist/markdownSerializers.d.ts.map +1 -1
- package/dist/markdownSerializers.js +2 -3
- package/dist/richtext.css +6 -1
- package/package.json +34 -36
- package/src/RichTextEditor.doc.mjs +3 -3
- package/src/RichTextEditor.test.tsx +36 -2
- package/src/RichTextEditor.tsx +54 -54
- package/src/RichTextEditorAutoLinkPlugin.tsx +3 -3
- package/src/RichTextEditorToolbar.tsx +27 -10
- package/src/RichTextView.tsx +1 -1
- package/src/__tests__/MarkdownParitySandbox.a11y.chromium.spec.ts +40 -23
- package/src/__tests__/MarkdownPlugins.a11y.chromium.spec.ts +2 -2
- package/src/__tests__/MarkdownPluginsImportExport.a11y.chromium.spec.ts +35 -1
- package/src/__tests__/Playground.a11y.chromium.spec.ts +298 -0
- package/src/__tests__/RichTextEditorToolbar.a11y.chromium.spec.ts +1 -1
- package/src/__tests__/RichTextView.a11y.chromium.spec.ts +1 -1
- package/src/__tests__/TableCellSelection.a11y.chromium.spec.ts +379 -0
- package/src/editorTheme.ts +53 -3
- package/src/index.ts +9 -11
- package/src/linkUtils.ts +1 -1
- package/src/markdownAngleDestinations.test.ts +29 -0
- package/src/markdownLink.ts +29 -35
- package/src/markdownListExport.ts +6 -1
- package/src/markdownSerializers.ts +2 -3
- package/src/publicSurface.test.ts +42 -0
package/dist/editorTheme.js
CHANGED
|
@@ -48,8 +48,8 @@ const editorTheme = {
|
|
|
48
48
|
$$css: true
|
|
49
49
|
},
|
|
50
50
|
paragraph: {
|
|
51
|
-
keoZOQ: "x1ftnraw xnhvf09",
|
|
52
|
-
k1K539: "x18pneqc xfo59cc",
|
|
51
|
+
keoZOQ: "x1ftnraw xnhvf09 xe66n16",
|
|
52
|
+
k1K539: "x18pneqc xfo59cc x1vugyqv",
|
|
53
53
|
ks0D6T: "x7ep2pv",
|
|
54
54
|
k63SB2: "x1pd3egz",
|
|
55
55
|
kMwMTN: "x1heor9g",
|
|
@@ -201,6 +201,13 @@ const editorTheme = {
|
|
|
201
201
|
kMwMTN: "xv1l7n4",
|
|
202
202
|
$$css: true
|
|
203
203
|
},
|
|
204
|
+
tableCellSelected: {
|
|
205
|
+
kMeerF: "xak0ai5",
|
|
206
|
+
k3XXqK: "x9ssot5",
|
|
207
|
+
kjBf7l: "x19bwoy8",
|
|
208
|
+
kInvED: "x1c097ug",
|
|
209
|
+
$$css: true
|
|
210
|
+
},
|
|
204
211
|
code: {
|
|
205
212
|
k1xSpc: "x1lliihq",
|
|
206
213
|
kMv6JI: "x9m5x89",
|
|
@@ -221,7 +228,8 @@ const editorTheme = {
|
|
|
221
228
|
keoZOQ: "x1w2a574 xnhvf09",
|
|
222
229
|
k1K539: "x1u2y747 xfo59cc",
|
|
223
230
|
khDVqt: "x126k92a",
|
|
224
|
-
|
|
231
|
+
kTgw9: "x1yn0g08",
|
|
232
|
+
kHjlTd: "x1mzt3pk",
|
|
225
233
|
$$css: true
|
|
226
234
|
}
|
|
227
235
|
};
|
|
@@ -286,7 +294,7 @@ export function sharedEditorTheme() {
|
|
|
286
294
|
// The plain class lets CodeSyntaxPlugin's highlight rules find code blocks.
|
|
287
295
|
code: `${block(editorTheme.code)} ${CODE_SYNTAX_CLASS}`,
|
|
288
296
|
hr: {
|
|
289
|
-
className: "xc342km x11xkdxz x13fuv20 x1pc3f07 x13xmvwt xnhvf09 x1qaki06 xfo59cc"
|
|
297
|
+
className: "xc342km x11xkdxz x13fuv20 x1pc3f07 x13xmvwt xnhvf09 xe66n16 x1qaki06 xfo59cc x1vugyqv"
|
|
290
298
|
}.className,
|
|
291
299
|
hrSelected: {
|
|
292
300
|
className: "xak0ai5 x9ssot5 x19bwoy8 x1eqjuhu"
|
|
@@ -301,6 +309,9 @@ export function sharedEditorTheme() {
|
|
|
301
309
|
tableRow: block(editorTheme.tableRow),
|
|
302
310
|
tableCell: block(editorTheme.tableCell),
|
|
303
311
|
tableCellHeader: block(editorTheme.tableCellHeader),
|
|
312
|
+
// Added on top of the cell's own class by Lexical while the cell is in a
|
|
313
|
+
// table selection, so it carries no direction of its own.
|
|
314
|
+
tableCellSelected: className(editorTheme.tableCellSelected),
|
|
304
315
|
tableScrollableWrapper: block(editorTheme.tableScrollableWrapper)
|
|
305
316
|
};
|
|
306
317
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,14 +6,19 @@
|
|
|
6
6
|
* Lexical-based rich text editor and viewer, promoted out of
|
|
7
7
|
* @astryxdesign/lab so it can be canaried independently.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* Exports only what a caller builds with (spec:AST-061/DEC-8): the generated
|
|
10
|
+
* editor theme classes and the autolink regular expressions stay internal,
|
|
11
|
+
* and Lexical's `Transformer` type comes from `@lexical/markdown`.
|
|
12
|
+
* `publicSurface.test.ts` holds the runtime list.
|
|
13
|
+
*
|
|
14
|
+
* SYNC: When modified, update this header, /packages/richtext/README.md,
|
|
15
|
+
* /packages/richtext/src/publicSurface.test.ts, and the editor component doc
|
|
16
|
+
* files.
|
|
11
17
|
*/
|
|
12
18
|
export { RichTextEditor } from './RichTextEditor';
|
|
13
|
-
export type { RichTextEditorProps, RichTextEditorRef, RichTextEditorStatus, RichTextEditorStatusType, RichTextEditorSize,
|
|
19
|
+
export type { RichTextEditorProps, RichTextEditorRef, RichTextEditorStatus, RichTextEditorStatusType, RichTextEditorSize, } from './RichTextEditor';
|
|
14
20
|
export { RichTextView } from './RichTextView';
|
|
15
21
|
export type { RichTextViewProps } from './RichTextView';
|
|
16
|
-
export { sharedEditorTheme } from './editorTheme';
|
|
17
22
|
export { markdownToEditorStateJSON, editorStateJSONToMarkdown, } from './markdownSerializers';
|
|
18
23
|
export type { MarkdownSerializerOptions } from './markdownSerializers';
|
|
19
24
|
export { createRichTextExtension, RichTextExtensionError, } from './markdownExtensions';
|
|
@@ -22,5 +27,5 @@ export { RichTextEditorToolbar, RICHTEXT_ICON_KEYS, } from './RichTextEditorTool
|
|
|
22
27
|
export type { RichTextEditorToolbarProps } from './RichTextEditorToolbar';
|
|
23
28
|
export { RichTextEditorAutoLinkPlugin, DEFAULT_LINK_MATCHERS, NEW_TAB_LINK_ATTRIBUTES, } from './RichTextEditorAutoLinkPlugin';
|
|
24
29
|
export type { RichTextEditorAutoLinkPluginProps } from './RichTextEditorAutoLinkPlugin';
|
|
25
|
-
export { sanitizeUrl, validateUrl
|
|
30
|
+
export { sanitizeUrl, validateUrl } from './linkUtils';
|
|
26
31
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,YAAY,EACV,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAC5C,YAAY,EAAC,iBAAiB,EAAC,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EACL,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAC,yBAAyB,EAAC,MAAM,uBAAuB,CAAC;AACrE,OAAO,EACL,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAC,yBAAyB,EAAC,MAAM,sBAAsB,CAAC;AAEpE,OAAO,EACL,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,yBAAyB,CAAC;AACjC,YAAY,EAAC,0BAA0B,EAAC,MAAM,yBAAyB,CAAC;AAExE,OAAO,EACL,4BAA4B,EAC5B,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,gCAAgC,CAAC;AACxC,YAAY,EAAC,iCAAiC,EAAC,MAAM,gCAAgC,CAAC;AAEtF,OAAO,EAAC,WAAW,EAAE,WAAW,EAAC,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -10,14 +10,19 @@
|
|
|
10
10
|
* Lexical-based rich text editor and viewer, promoted out of
|
|
11
11
|
* @astryxdesign/lab so it can be canaried independently.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* Exports only what a caller builds with (spec:AST-061/DEC-8): the generated
|
|
14
|
+
* editor theme classes and the autolink regular expressions stay internal,
|
|
15
|
+
* and Lexical's `Transformer` type comes from `@lexical/markdown`.
|
|
16
|
+
* `publicSurface.test.ts` holds the runtime list.
|
|
17
|
+
*
|
|
18
|
+
* SYNC: When modified, update this header, /packages/richtext/README.md,
|
|
19
|
+
* /packages/richtext/src/publicSurface.test.ts, and the editor component doc
|
|
20
|
+
* files.
|
|
15
21
|
*/
|
|
16
22
|
export { RichTextEditor } from "./RichTextEditor.js";
|
|
17
23
|
export { RichTextView } from "./RichTextView.js";
|
|
18
|
-
export { sharedEditorTheme } from "./editorTheme.js";
|
|
19
24
|
export { markdownToEditorStateJSON, editorStateJSONToMarkdown } from "./markdownSerializers.js";
|
|
20
25
|
export { createRichTextExtension, RichTextExtensionError } from "./markdownExtensions.js";
|
|
21
26
|
export { RichTextEditorToolbar, RICHTEXT_ICON_KEYS } from "./RichTextEditorToolbar.js";
|
|
22
27
|
export { RichTextEditorAutoLinkPlugin, DEFAULT_LINK_MATCHERS, NEW_TAB_LINK_ATTRIBUTES } from "./RichTextEditorAutoLinkPlugin.js";
|
|
23
|
-
export { sanitizeUrl, validateUrl
|
|
28
|
+
export { sanitizeUrl, validateUrl } from "./linkUtils.js";
|
package/dist/linkUtils.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @input Uses only the DOM URL constructor (guarded via try/catch for SSR/edge).
|
|
6
6
|
* @output Exports `sanitizeUrl`, `validateUrl`, and the URL/email matcher regexes
|
|
7
7
|
* used by the AutoLink wiring.
|
|
8
|
-
* @position
|
|
8
|
+
* @position @astryxdesign/richtext helper shared by RichTextEditorToolbar (link
|
|
9
9
|
* button) and the AutoLink matchers in RichTextEditor. Kept dependency-free so
|
|
10
10
|
* both can import it without pulling in extra `@lexical/*` surface.
|
|
11
11
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdownLink.d.ts","sourceRoot":"","sources":["../src/markdownLink.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"markdownLink.d.ts","sourceRoot":"","sources":["../src/markdownLink.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAO,KAAK,oBAAoB,EAAC,MAAM,mBAAmB,CAAC;AA6BlE,gEAAgE;AAChE,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAUvD;AAED,eAAO,MAAM,yBAAyB,EAAE,oBAoBvC,CAAC"}
|
package/dist/markdownLink.js
CHANGED
|
@@ -4,17 +4,20 @@
|
|
|
4
4
|
* @file markdownLink.ts
|
|
5
5
|
* @input Uses @lexical/link and @lexical/markdown (LINK).
|
|
6
6
|
* @output Exports LINK_KEEPING_DESTINATIONS, Lexical's link transformer with
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* one change on export. Import is Lexical's own, which reads every
|
|
8
|
+
* CommonMark destination and title shape, an angle-bracket destination
|
|
9
|
+
* (`<https://e.com/a b>`) included, and decodes backslash escapes and
|
|
10
|
+
* character references in both. A destination that needs no escape is
|
|
11
|
+
* written by Lexical's export too, which escapes parentheses and an `&`
|
|
12
|
+
* that starts a character reference (`https://e.com/a_(b)` as
|
|
13
|
+
* `https://e.com/a_\(b\)`). One that holds whitespace or opens with `<`
|
|
14
|
+
* is written here in angle brackets, and one with a backslash or
|
|
15
|
+
* unbalanced parentheses with those escaped; both escape a
|
|
16
|
+
* reference-starting `&` as Lexical does, so every link reads back as
|
|
17
|
+
* the same link, whether it was imported or made in the editor
|
|
18
|
+
* (spec:AST-062 FR3).
|
|
11
19
|
* @position Replaces Lexical's LINK in DEFAULT_TRANSFORMERS and in table
|
|
12
|
-
* cells (markdownTable.ts).
|
|
13
|
-
* destination and backslash escapes (markdownCharacterReferences.ts), so a
|
|
14
|
-
* destination written this way — `https://e.com/a(b` as
|
|
15
|
-
* `https://e.com/a\(b` — reads back as the same link, whether it was
|
|
16
|
-
* imported or made in the editor (spec:AST-062 FR3). A balanced
|
|
17
|
-
* destination is written as it is.
|
|
20
|
+
* cells (markdownTable.ts).
|
|
18
21
|
*/
|
|
19
22
|
|
|
20
23
|
import { $isAutoLinkNode, $isLinkNode } from '@lexical/link';
|
|
@@ -36,6 +39,14 @@ function isBalanced(url) {
|
|
|
36
39
|
return depth === 0;
|
|
37
40
|
}
|
|
38
41
|
|
|
42
|
+
/**
|
|
43
|
+
* `value` with every `&` that would start a character reference written as
|
|
44
|
+
* `&`, since import decodes references in a destination and a title.
|
|
45
|
+
*/
|
|
46
|
+
function escapeCharacterReferences(value) {
|
|
47
|
+
return value.replace(/&(?=#\d+;|#[Xx][\dA-Fa-f]+;|[A-Za-z][\dA-Za-z]*;)/g, '&');
|
|
48
|
+
}
|
|
49
|
+
|
|
39
50
|
/** `url` as a Markdown destination that reads back as `url`. */
|
|
40
51
|
export function markdownDestination(url) {
|
|
41
52
|
if (/\s/.test(url) || url.startsWith('<')) {
|
|
@@ -48,30 +59,10 @@ export function markdownDestination(url) {
|
|
|
48
59
|
// balance.
|
|
49
60
|
return url.replace(isBalanced(url) ? /\\/g : /[\\()]/g, '\\$&');
|
|
50
61
|
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Lexical's link pattern, with a destination in angle brackets too: any
|
|
54
|
-
* characters but brackets and line endings, spaces included. A destination
|
|
55
|
-
* that opens with `<` is an angle-bracket one or no destination at all
|
|
56
|
-
* (CommonMark §6.3), so `[a](<b>c>)` stays text, as core reads it.
|
|
57
|
-
*/
|
|
58
|
-
const LINK_WITH_ANGLE_DESTINATION = /(?:\[(.+?)\])(?:\((?:(<[^<>\n]*>|[^()\s<][^()\s]*)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))/;
|
|
59
62
|
export const LINK_KEEPING_DESTINATIONS = {
|
|
63
|
+
// Lexical's own import reads every CommonMark destination and title shape,
|
|
64
|
+
// an angle-bracket destination included.
|
|
60
65
|
...LINK,
|
|
61
|
-
importRegExp: LINK_WITH_ANGLE_DESTINATION,
|
|
62
|
-
replace: (textNode, match) => {
|
|
63
|
-
const destination = match[2];
|
|
64
|
-
if (destination == null || !destination.startsWith('<')) {
|
|
65
|
-
return LINK.replace?.(textNode, match);
|
|
66
|
-
}
|
|
67
|
-
// The link's address is what the angle brackets hold.
|
|
68
|
-
const withoutBrackets = Object.assign([...match], {
|
|
69
|
-
index: match.index,
|
|
70
|
-
input: match.input
|
|
71
|
-
});
|
|
72
|
-
withoutBrackets[2] = destination.slice(1, -1);
|
|
73
|
-
return LINK.replace?.(textNode, withoutBrackets);
|
|
74
|
-
},
|
|
75
66
|
export: (node, exportChildren, exportFormat) => {
|
|
76
67
|
if (!$isLinkNode(node) || $isAutoLinkNode(node)) {
|
|
77
68
|
return null;
|
|
@@ -82,7 +73,8 @@ export const LINK_KEEPING_DESTINATIONS = {
|
|
|
82
73
|
return LINK.export?.(node, exportChildren, exportFormat) ?? null;
|
|
83
74
|
}
|
|
84
75
|
const text = exportChildren(node);
|
|
76
|
+
const written = escapeCharacterReferences(destination);
|
|
85
77
|
const title = node.getTitle();
|
|
86
|
-
return title == null || title === '' ? `[${text}](${
|
|
78
|
+
return title == null || title === '' ? `[${text}](${written})` : `[${text}](${written} "${escapeCharacterReferences(title).replace(/([\\"])/g, '\\$1')}")`;
|
|
87
79
|
}
|
|
88
80
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdownListExport.d.ts","sourceRoot":"","sources":["../src/markdownListExport.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"markdownListExport.d.ts","sourceRoot":"","sources":["../src/markdownListExport.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,mBAAmB,CAAC;AAoD1D,eAAO,MAAM,WAAW,EAAE,kBAQzB,CAAC"}
|
|
@@ -21,7 +21,10 @@ import { $getTaskState } from "./markdownTaskList.js";
|
|
|
21
21
|
|
|
22
22
|
/** The bullet Lexical recorded for a list on import (`-`, `*`, or `+`). */
|
|
23
23
|
function bulletOf(list) {
|
|
24
|
-
|
|
24
|
+
// The export may hand over a view of the list (an object inheriting from
|
|
25
|
+
// the node, see markdownSource.ts); Lexical validates the fields of the
|
|
26
|
+
// node it serializes, so read the recorded state from the node itself.
|
|
27
|
+
const serialized = list.getLatest().exportJSON();
|
|
25
28
|
const marker = serialized.$?.mdListMarker;
|
|
26
29
|
return marker === '*' || marker === '+' ? marker : '-';
|
|
27
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdownSerializers.d.ts","sourceRoot":"","sources":["../src/markdownSerializers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"markdownSerializers.d.ts","sourceRoot":"","sources":["../src/markdownSerializers.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAC,KAAK,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAOnD,OAAO,EAAY,KAAK,yBAAyB,EAAC,MAAM,sBAAsB,CAAC;AAC/E,OAAO,KAAK,EAAC,KAAK,EAAE,WAAW,EAAC,MAAM,SAAS,CAAC;AAEhD,yDAAyD;AACzD,MAAM,WAAW,yBAAyB;IACxC;;;;;OAKG;IACH,YAAY,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;IAC1C;;;OAGG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;IAC1C;;;;;OAKG;IACH,UAAU,CAAC,EAAE,aAAa,CAAC,yBAAyB,CAAC,CAAC;CACvD;AAYD;;;;;;;;;;GAUG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,yBAA8B,GACtC,MAAM,CAMR;AAED;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CACvC,eAAe,EAAE,MAAM,EACvB,OAAO,GAAE,yBAA8B,GACtC,MAAM,CAKR"}
|
|
@@ -17,9 +17,8 @@
|
|
|
17
17
|
* - /packages/richtext/src/RichTextEditor.test.tsx (tests)
|
|
18
18
|
*
|
|
19
19
|
* NOTE: `@lexical/headless`, `@lexical/markdown`, and `lexical` are OPTIONAL
|
|
20
|
-
* peer dependencies
|
|
21
|
-
*
|
|
22
|
-
* Node / SSR contexts.
|
|
20
|
+
* peer dependencies. Install them to use these helpers. `@lexical/headless`
|
|
21
|
+
* runs Lexical without a DOM, so these work in Node / SSR contexts.
|
|
23
22
|
*/
|
|
24
23
|
|
|
25
24
|
import { createHeadlessEditor } from '@lexical/headless';
|
package/dist/richtext.css
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/* Astryx Rich Text Pre-compiled StyleX CSS — Lexical editor and viewer */
|
|
2
2
|
/* Auto-generated. Do not edit manually. */
|
|
3
3
|
|
|
4
|
+
@layer reset, astryx-base, astryx-theme;
|
|
5
|
+
|
|
4
6
|
@layer astryx-base {
|
|
5
7
|
@property --x-left { syntax: "*"; inherits: false;}
|
|
6
8
|
@property --x-minHeight { syntax: "*"; inherits: false;}
|
|
@@ -109,10 +111,10 @@
|
|
|
109
111
|
.x152237o:not(#\#):not(#\#):not(#\#){list-style-type:square}
|
|
110
112
|
.x8yim9t:not(#\#):not(#\#):not(#\#){margin-inline-start:calc(var(--spacing-0))}
|
|
111
113
|
.x19bwoy8:not(#\#):not(#\#):not(#\#){outline-color:var(--focus-outline-color)}
|
|
114
|
+
.x1c097ug:not(#\#):not(#\#):not(#\#){outline-offset:calc(-1 * var(--focus-outline-width))}
|
|
112
115
|
.x1eqjuhu:not(#\#):not(#\#):not(#\#){outline-offset:var(--focus-outline-offset)}
|
|
113
116
|
.x9ssot5:not(#\#):not(#\#):not(#\#){outline-style:var(--focus-outline-style)}
|
|
114
117
|
.xak0ai5:not(#\#):not(#\#):not(#\#){outline-width:var(--focus-outline-width)}
|
|
115
|
-
.xj0a0fe:not(#\#):not(#\#):not(#\#){overflow-wrap:anywhere}
|
|
116
118
|
.x1mzt3pk:not(#\#):not(#\#):not(#\#){overflow-wrap:break-word}
|
|
117
119
|
.xp74n0j:not(#\#):not(#\#):not(#\#){padding-inline-end:calc(var(--spacing-2) + var(--spacing-6))}
|
|
118
120
|
.xbj1ybn:not(#\#):not(#\#):not(#\#){padding-inline-start:calc(var(--spacing-0))}
|
|
@@ -129,6 +131,7 @@
|
|
|
129
131
|
.xxymvpz:not(#\#):not(#\#):not(#\#){vertical-align:middle}
|
|
130
132
|
.xuxw1ft:not(#\#):not(#\#):not(#\#){white-space:nowrap}
|
|
131
133
|
.x126k92a:not(#\#):not(#\#):not(#\#){white-space:pre-wrap}
|
|
134
|
+
.x1yn0g08:not(#\#):not(#\#):not(#\#){word-break:break-all}
|
|
132
135
|
.x1vjfegm:not(#\#):not(#\#):not(#\#){z-index:1}
|
|
133
136
|
.x16khyan:is(:disabled,[aria-disabled="true"]):not(#\#):not(#\#):not(#\#){cursor:default}
|
|
134
137
|
.x2i8j16:is([data-richtext-task]):not(#\#):not(#\#):not(#\#){list-style-type:none}
|
|
@@ -178,7 +181,9 @@
|
|
|
178
181
|
.xh8yej3:not(#\#):not(#\#):not(#\#):not(#\#){width:100%}
|
|
179
182
|
.xeq5yr9:not(#\#):not(#\#):not(#\#):not(#\#){width:fit-content}
|
|
180
183
|
.x5lhr3w:not(#\#):not(#\#):not(#\#):not(#\#){width:var(--x-width)}
|
|
184
|
+
.xe66n16:is([data-lexical-decorator-boundary]:first-child + *):not(#\#):not(#\#):not(#\#):not(#\#){margin-top:var(--spacing-0)}
|
|
181
185
|
.x2w4pp4:is([data-language]:not([data-language="plaintext"])):not(#\#):not(#\#):not(#\#):not(#\#){padding-top:calc(var(--spacing-2) + var(--size-element-sm) + var(--spacing-3))}
|
|
186
|
+
.x1vugyqv:has(+ [data-lexical-decorator-boundary]:last-child):not(#\#):not(#\#):not(#\#):not(#\#){margin-bottom:var(--spacing-0)}
|
|
182
187
|
.xkuhcwz:has(ul):not(#\#):not(#\#):not(#\#):not(#\#){margin-top:calc(var(--spacing-2))}
|
|
183
188
|
.xsgnyjk:has(ol):not(#\#):not(#\#):not(#\#):not(#\#){margin-top:calc(var(--spacing-2))}
|
|
184
189
|
.x1uerj9w:has(ol):not(#\#):not(#\#):not(#\#):not(#\#){padding-top:var(--spacing-0)}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/richtext",
|
|
3
3
|
"displayName": "Rich Text",
|
|
4
|
-
"version": "0.7.1
|
|
5
|
-
"description": "Astryx rich text — a Lexical-based rich text editor and viewer
|
|
4
|
+
"version": "0.7.1",
|
|
5
|
+
"description": "Astryx rich text — a Lexical-based rich text editor and viewer, styled with Astryx design tokens.",
|
|
6
6
|
"author": "Meta Open Source",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"homepage": "https://github.com/facebook/astryx#readme",
|
|
@@ -22,14 +22,12 @@
|
|
|
22
22
|
"lexical",
|
|
23
23
|
"design-system"
|
|
24
24
|
],
|
|
25
|
-
"astryx": {
|
|
26
|
-
"canaryOnly": true,
|
|
27
|
-
"_comment": "Published ONLY to the @canary dist-tag (see .github/workflows/release.yml). Never released as a stable `latest` release. `private: true` is intentional and must stay — it is npm\"s hard guarantee against an accidental stable publish."
|
|
28
|
-
},
|
|
29
25
|
"type": "module",
|
|
30
26
|
"main": "./dist/index.js",
|
|
31
27
|
"types": "./dist/index.d.ts",
|
|
32
|
-
"sideEffects":
|
|
28
|
+
"sideEffects": [
|
|
29
|
+
"**/*.css"
|
|
30
|
+
],
|
|
33
31
|
"files": [
|
|
34
32
|
"astryx.integration.mjs",
|
|
35
33
|
"blocks",
|
|
@@ -55,22 +53,22 @@
|
|
|
55
53
|
},
|
|
56
54
|
"peerDependencies": {
|
|
57
55
|
"@stylexjs/stylex": ">=0.10.0",
|
|
58
|
-
"@astryxdesign/core": "0.7.1
|
|
56
|
+
"@astryxdesign/core": "0.7.1",
|
|
59
57
|
"react": ">=19.0.0",
|
|
60
58
|
"react-dom": ">=19.0.0",
|
|
61
|
-
"lexical": "^0.
|
|
62
|
-
"@lexical/react": "^0.
|
|
63
|
-
"@lexical/markdown": "^0.
|
|
64
|
-
"@lexical/headless": "^0.
|
|
65
|
-
"@lexical/html": "^0.
|
|
66
|
-
"@lexical/link": "^0.
|
|
67
|
-
"@lexical/list": "^0.
|
|
68
|
-
"@lexical/rich-text": "^0.
|
|
69
|
-
"@lexical/selection": "^0.
|
|
70
|
-
"@lexical/code": "^0.
|
|
71
|
-
"@lexical/extension": "^0.
|
|
72
|
-
"@lexical/table": "^0.
|
|
73
|
-
"@lexical/utils": "^0.
|
|
59
|
+
"lexical": "^0.52.0",
|
|
60
|
+
"@lexical/react": "^0.52.0",
|
|
61
|
+
"@lexical/markdown": "^0.52.0",
|
|
62
|
+
"@lexical/headless": "^0.52.0",
|
|
63
|
+
"@lexical/html": "^0.52.0",
|
|
64
|
+
"@lexical/link": "^0.52.0",
|
|
65
|
+
"@lexical/list": "^0.52.0",
|
|
66
|
+
"@lexical/rich-text": "^0.52.0",
|
|
67
|
+
"@lexical/selection": "^0.52.0",
|
|
68
|
+
"@lexical/code": "^0.52.0",
|
|
69
|
+
"@lexical/extension": "^0.52.0",
|
|
70
|
+
"@lexical/table": "^0.52.0",
|
|
71
|
+
"@lexical/utils": "^0.52.0"
|
|
74
72
|
},
|
|
75
73
|
"peerDependenciesMeta": {
|
|
76
74
|
"lexical": {
|
|
@@ -114,27 +112,27 @@
|
|
|
114
112
|
}
|
|
115
113
|
},
|
|
116
114
|
"devDependencies": {
|
|
117
|
-
"@astryxdesign/a11y-spec": "0.7.1-canary.ff40b78",
|
|
118
|
-
"@astryxdesign/cli": "0.7.1-canary.ff40b78",
|
|
119
115
|
"@babel/cli": "^7.29.7",
|
|
120
116
|
"@babel/core": "^7.29.7",
|
|
121
117
|
"@babel/preset-react": "^7.29.7",
|
|
122
118
|
"@babel/preset-typescript": "^7.29.7",
|
|
123
|
-
"@lexical/code": "^0.
|
|
124
|
-
"@lexical/extension": "^0.
|
|
125
|
-
"@lexical/headless": "^0.
|
|
126
|
-
"@lexical/html": "^0.
|
|
127
|
-
"@lexical/link": "^0.
|
|
128
|
-
"@lexical/list": "^0.
|
|
129
|
-
"@lexical/markdown": "^0.
|
|
130
|
-
"@lexical/react": "^0.
|
|
131
|
-
"@lexical/rich-text": "^0.
|
|
132
|
-
"@lexical/selection": "^0.
|
|
133
|
-
"@lexical/table": "^0.
|
|
134
|
-
"@lexical/utils": "^0.
|
|
119
|
+
"@lexical/code": "^0.52.0",
|
|
120
|
+
"@lexical/extension": "^0.52.0",
|
|
121
|
+
"@lexical/headless": "^0.52.0",
|
|
122
|
+
"@lexical/html": "^0.52.0",
|
|
123
|
+
"@lexical/link": "^0.52.0",
|
|
124
|
+
"@lexical/list": "^0.52.0",
|
|
125
|
+
"@lexical/markdown": "^0.52.0",
|
|
126
|
+
"@lexical/react": "^0.52.0",
|
|
127
|
+
"@lexical/rich-text": "^0.52.0",
|
|
128
|
+
"@lexical/selection": "^0.52.0",
|
|
129
|
+
"@lexical/table": "^0.52.0",
|
|
130
|
+
"@lexical/utils": "^0.52.0",
|
|
135
131
|
"@stylexjs/babel-plugin": "^0.19.0",
|
|
136
132
|
"@testing-library/react": "^16.3.2",
|
|
137
|
-
"lexical": "^0.
|
|
133
|
+
"lexical": "^0.52.0",
|
|
134
|
+
"@astryxdesign/a11y-spec": "0.0.0",
|
|
135
|
+
"@astryxdesign/cli": "0.7.1"
|
|
138
136
|
},
|
|
139
137
|
"scripts": {
|
|
140
138
|
"build": "node ../../scripts/clean-dist.mjs && pnpm build:esm && tsc --project tsconfig.build.json && pnpm build:css && node ../../scripts/check-no-dev-jsx.mjs && node ../../scripts/check-fully-specified.mjs",
|
|
@@ -179,12 +179,12 @@ export const docs = {
|
|
|
179
179
|
},
|
|
180
180
|
usage: {
|
|
181
181
|
description:
|
|
182
|
-
'A WYSIWYG rich-text editor built on Lexical, styled with Astryx design tokens. Its field container shares TextArea input visuals for the resting border, hover ring, focus-within ring, disabled state, and status colors.
|
|
182
|
+
'A WYSIWYG rich-text editor built on Lexical, styled with Astryx design tokens. Its field container shares TextArea input visuals for the resting border, hover ring, focus-within ring, disabled state, and status colors. Ships from @astryxdesign/richtext; lexical and @lexical/* are optional peer dependencies. The editor is deliberately minimal and extensible: pass toolbar, nodes, and plugins to layer richer behaviour (formatting, mentions, hover cards) on top without forking. Use RichTextView to render serialized content read-only.',
|
|
183
183
|
bestPractices: [
|
|
184
184
|
{
|
|
185
185
|
guidance: true,
|
|
186
186
|
description:
|
|
187
|
-
'Install lexical and @lexical
|
|
187
|
+
'RichText is built on Lexical and exposes it: nodes and transformers take Lexical types, plugins takes Lexical React plugins, and onChange and getEditorState() report Lexical types. Install the lexical and @lexical/* peers (optional peers) at the Lexical minor named in the package peer ranges before importing from @astryxdesign/richtext.',
|
|
188
188
|
},
|
|
189
189
|
{
|
|
190
190
|
guidance: true,
|
|
@@ -229,7 +229,7 @@ export const docs = {
|
|
|
229
229
|
{
|
|
230
230
|
guidance: true,
|
|
231
231
|
description:
|
|
232
|
-
'Links: the toolbar Link button (on by default; disable with hasLink={false}) and Cmd/Ctrl+K open an Astryx Dialog. The form preserves the Lexical selection while focus moves into the URL input and supports add, update, remove, Escape, and focus return. Pass promptForUrl only when integrating an existing synchronous URL flow. Entered URLs are sanitized (only http/https/mailto/tel are written; javascript:/data: are rejected). Links open in a new tab by default: target=_blank and rel=noopener noreferrer are written into the link node data; set
|
|
232
|
+
'Links: the toolbar Link button (on by default; disable with hasLink={false}) and Cmd/Ctrl+K open an Astryx Dialog. The form preserves the Lexical selection while focus moves into the URL input and supports add, update, remove, Escape, and focus return. Pass promptForUrl only when integrating an existing synchronous URL flow. Entered URLs are sanitized (only http/https/mailto/tel are written; javascript:/data: are rejected). Links open in a new tab by default: target=_blank and rel=noopener noreferrer are written into the link node data; set hasNewTabLinks={false} for same-tab links. The toolbar takes base props and passes them to the Astryx Toolbar it renders: ref, className, style and xstyle on its root; data-*, other aria-* attributes and DOM handlers on the toolbar element (name it with label, not aria-label).',
|
|
233
233
|
},
|
|
234
234
|
{
|
|
235
235
|
guidance: true,
|
|
@@ -1845,7 +1845,41 @@ describe('RichTextEditorToolbar — new-tab links', () => {
|
|
|
1845
1845
|
});
|
|
1846
1846
|
});
|
|
1847
1847
|
|
|
1848
|
-
it('
|
|
1848
|
+
it('passes base props and the ref through to the Astryx Toolbar', () => {
|
|
1849
|
+
const ref = createRef<HTMLDivElement>();
|
|
1850
|
+
const onKeyDown = vi.fn();
|
|
1851
|
+
render(
|
|
1852
|
+
<RichTextEditor
|
|
1853
|
+
label="Notes"
|
|
1854
|
+
toolbar={
|
|
1855
|
+
<RichTextEditorToolbar
|
|
1856
|
+
ref={ref}
|
|
1857
|
+
className="product-toolbar"
|
|
1858
|
+
style={{marginBlockEnd: 3}}
|
|
1859
|
+
data-testid="toolbar-root"
|
|
1860
|
+
aria-describedby="toolbar-help"
|
|
1861
|
+
onKeyDown={onKeyDown}
|
|
1862
|
+
/>
|
|
1863
|
+
}
|
|
1864
|
+
/>,
|
|
1865
|
+
);
|
|
1866
|
+
// Base props land where core Toolbar puts them: the ref and styling on
|
|
1867
|
+
// its root, every other base prop on the role="toolbar" element inside.
|
|
1868
|
+
const toolbar = screen.getByRole('toolbar');
|
|
1869
|
+
const root = ref.current;
|
|
1870
|
+
expect(root).not.toBeNull();
|
|
1871
|
+
expect(root?.contains(toolbar)).toBe(true);
|
|
1872
|
+
expect(root).toHaveClass('product-toolbar');
|
|
1873
|
+
expect(root?.style.marginBlockEnd).toBe('3px');
|
|
1874
|
+
expect(screen.getByTestId('toolbar-root')).toBe(toolbar);
|
|
1875
|
+
expect(toolbar).toHaveAttribute('aria-describedby', 'toolbar-help');
|
|
1876
|
+
// The toolbar's own label and role survive the spread.
|
|
1877
|
+
expect(toolbar).toHaveAccessibleName('Text formatting');
|
|
1878
|
+
fireEvent.keyDown(toolbar, {key: 'x'});
|
|
1879
|
+
expect(onKeyDown).toHaveBeenCalledTimes(1);
|
|
1880
|
+
});
|
|
1881
|
+
|
|
1882
|
+
it('omits new-tab attributes when hasNewTabLinks is false', async () => {
|
|
1849
1883
|
let editor!: LexicalEditor;
|
|
1850
1884
|
const promptForUrl = vi.fn(() => 'example.com');
|
|
1851
1885
|
render(
|
|
@@ -1854,7 +1888,7 @@ describe('RichTextEditorToolbar — new-tab links', () => {
|
|
|
1854
1888
|
toolbar={
|
|
1855
1889
|
<RichTextEditorToolbar
|
|
1856
1890
|
promptForUrl={promptForUrl}
|
|
1857
|
-
|
|
1891
|
+
hasNewTabLinks={false}
|
|
1858
1892
|
/>
|
|
1859
1893
|
}
|
|
1860
1894
|
plugins={<CaptureEditor onReady={e => (editor = e)} />}
|