@astryxdesign/richtext 0.7.11 → 0.7.12-canary.0f28099
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 +3 -0
- package/dist/CodePastePlugin.d.ts +2 -0
- package/dist/CodePastePlugin.d.ts.map +1 -0
- package/dist/CodePastePlugin.js +103 -0
- package/dist/RichTextEditor.d.ts +1 -1
- package/dist/RichTextEditor.d.ts.map +1 -1
- package/dist/RichTextEditor.js +9 -4
- package/dist/editorTheme.d.ts.map +1 -1
- package/dist/privateAttributes/layerPortalBoundary.stylex.d.ts +12 -0
- package/dist/privateAttributes/layerPortalBoundary.stylex.d.ts.map +1 -0
- package/dist/privateAttributes/layerPortalBoundary.stylex.js +16 -0
- package/package.json +5 -5
- package/src/CodePastePlugin.tsx +143 -0
- package/src/RichTextEditor.doc.mjs +5 -0
- package/src/RichTextEditor.tsx +8 -2
- package/src/RichTextEditorAutoLinkPlugin.doc.mjs +43 -0
- package/src/RichTextEditorToolbar.doc.mjs +92 -0
- package/src/RichTextView.doc.mjs +101 -0
- package/src/editorTheme.ts +4 -3
- package/src/privateAttributes/layerPortalBoundary.stylex.ts +18 -0
package/README.md
CHANGED
|
@@ -74,6 +74,9 @@ if your app has its own reset) loads first.
|
|
|
74
74
|
Backspace at the very start of a code block turns it into a paragraph of its
|
|
75
75
|
lines, instead of merging the code into the block above.
|
|
76
76
|
|
|
77
|
+
Pasting rich content into a code block inserts its plain text, one line per
|
|
78
|
+
block: headings, lists, tables, and formatting never land inside the code.
|
|
79
|
+
|
|
77
80
|
## Examples
|
|
78
81
|
|
|
79
82
|
Interactive examples live in Storybook under **RichText/RichTextEditor**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodePastePlugin.d.ts","sourceRoot":"","sources":["../src/CodePastePlugin.tsx"],"names":[],"mappings":"AAuFA,wBAAgB,eAAe,IAAI,IAAI,CAuDtC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @file CodePastePlugin.tsx
|
|
7
|
+
* @input Uses @lexical/react (composer context), @lexical/code (CodeNode), and
|
|
8
|
+
* lexical.
|
|
9
|
+
* @output Exports CodePastePlugin, which makes rich content pasted or dropped
|
|
10
|
+
* into a code block go in as plain lines of code.
|
|
11
|
+
* @position Rendered by RichTextEditor; always on; not exported. A paste
|
|
12
|
+
* whose selection starts in a code block goes in as plain text: the
|
|
13
|
+
* clipboard's plain text, or else one line per pasted block.
|
|
14
|
+
*/
|
|
15
|
+
import { useEffect } from 'react';
|
|
16
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
17
|
+
import { $isCodeNode } from '@lexical/code';
|
|
18
|
+
import { $addUpdateTag, $findMatchingParent, $getSelection, $isElementNode, $isRangeSelection, $isSelectionCapturedInDecoratorInput, COMMAND_PRIORITY_LOW, isDOMNode, mergeRegister, PASTE_COMMAND, PASTE_TAG, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND } from 'lexical';
|
|
19
|
+
|
|
20
|
+
/** Clipboard types that carry more than plain text. */
|
|
21
|
+
const RICH_TYPES = ['text/html', 'application/x-lexical-editor'];
|
|
22
|
+
|
|
23
|
+
/** Whether content inserted at the selection lands in a code block. */
|
|
24
|
+
function $startsInCodeBlock(selection) {
|
|
25
|
+
if (!$isRangeSelection(selection)) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const start = selection.isBackward() ? selection.focus : selection.anchor;
|
|
29
|
+
const node = start.getNode();
|
|
30
|
+
// A link (an autolinked URL) can sit between the text and its code block.
|
|
31
|
+
return $findMatchingParent(node, $isCodeNode) !== null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Clipboard nodes as plain lines: each block's text on a line of its own (a
|
|
36
|
+
* paragraph, a heading, a list item, a table cell), and inline content
|
|
37
|
+
* between blocks on one line.
|
|
38
|
+
*/
|
|
39
|
+
function $plainLinesOf(nodes) {
|
|
40
|
+
const lines = [];
|
|
41
|
+
let inline = null;
|
|
42
|
+
const endInline = () => {
|
|
43
|
+
if (inline != null) {
|
|
44
|
+
lines.push(inline);
|
|
45
|
+
inline = null;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const visit = node => {
|
|
49
|
+
if (node.isInline()) {
|
|
50
|
+
inline = (inline ?? '') + node.getTextContent();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
endInline();
|
|
54
|
+
if ($isElementNode(node) && node.getChildren().some(child => !child.isInline())) {
|
|
55
|
+
node.getChildren().forEach(visit);
|
|
56
|
+
endInline();
|
|
57
|
+
} else {
|
|
58
|
+
lines.push(node.getTextContent());
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
nodes.forEach(visit);
|
|
62
|
+
endInline();
|
|
63
|
+
return lines.join('\n');
|
|
64
|
+
}
|
|
65
|
+
export function CodePastePlugin() {
|
|
66
|
+
const [editor] = useLexicalComposerContext();
|
|
67
|
+
useEffect(() => mergeRegister(
|
|
68
|
+
// Ahead of the rich-text paste, which inserts the clipboard's rich
|
|
69
|
+
// content when there is any.
|
|
70
|
+
editor.registerCommand(PASTE_COMMAND, event => {
|
|
71
|
+
// A paste into an input a decorator node renders is that input's.
|
|
72
|
+
if (isDOMNode(event.target) && $isSelectionCapturedInDecoratorInput(event.target)) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
const data = 'clipboardData' in event ? event.clipboardData : null;
|
|
76
|
+
if (!editor.isEditable() || data == null || !RICH_TYPES.some(type => data.types.includes(type))) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
const text = data.getData('text/plain');
|
|
80
|
+
const selection = $getSelection();
|
|
81
|
+
if (text === '' || !$startsInCodeBlock(selection)) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
event.preventDefault();
|
|
85
|
+
// Its own undo step, as every paste is.
|
|
86
|
+
$addUpdateTag(PASTE_TAG);
|
|
87
|
+
selection.insertRawText(text);
|
|
88
|
+
return true;
|
|
89
|
+
}, COMMAND_PRIORITY_LOW),
|
|
90
|
+
// Every insertion of clipboard nodes, a paste with no plain text or a
|
|
91
|
+
// drop, comes through here; ahead of the table's own handler.
|
|
92
|
+
editor.registerCommand(SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, ({
|
|
93
|
+
nodes,
|
|
94
|
+
selection
|
|
95
|
+
}) => {
|
|
96
|
+
if (!$startsInCodeBlock(selection)) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
selection.insertRawText($plainLinesOf(nodes));
|
|
100
|
+
return true;
|
|
101
|
+
}, COMMAND_PRIORITY_LOW)), [editor]);
|
|
102
|
+
return null;
|
|
103
|
+
}
|
package/dist/RichTextEditor.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file RichTextEditor.tsx
|
|
3
|
-
* @input Uses React, useId, Lexical (lexical + @lexical/react, composed through
|
|
3
|
+
* @input Uses React, useId, a declared DOM boundary, Lexical (lexical + @lexical/react, composed through
|
|
4
4
|
* LexicalExtensionComposer), Field, VisuallyHidden, useInputStatusIcon,
|
|
5
5
|
* mergeProps, design tokens
|
|
6
6
|
* @output Exports an accessibly labelled RichTextEditor component with a flush
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextEditor.d.ts","sourceRoot":"","sources":["../src/RichTextEditor.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAOL,KAAK,SAAS,EACd,KAAK,GAAG,EACT,MAAM,OAAO,CAAC;AASf,OAAO,EAML,KAAK,kBAAkB,EACxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAIlD,OAAO,EAIL,KAAK,SAAS,EACf,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"RichTextEditor.d.ts","sourceRoot":"","sources":["../src/RichTextEditor.tsx"],"names":[],"mappings":"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"}
|
package/dist/RichTextEditor.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @file RichTextEditor.tsx
|
|
7
|
-
* @input Uses React, useId, Lexical (lexical + @lexical/react, composed through
|
|
7
|
+
* @input Uses React, useId, a declared DOM boundary, Lexical (lexical + @lexical/react, composed through
|
|
8
8
|
* LexicalExtensionComposer), Field, VisuallyHidden, useInputStatusIcon,
|
|
9
9
|
* mergeProps, design tokens
|
|
10
10
|
* @output Exports an accessibly labelled RichTextEditor component with a flush
|
|
@@ -51,6 +51,7 @@ import { TextSemanticsExtension } from "./textSemantics.js";
|
|
|
51
51
|
import { TableColumnFloorPlugin } from "./TableColumnFloorPlugin.js";
|
|
52
52
|
import { CodeBackspacePlugin } from "./CodeBackspacePlugin.js";
|
|
53
53
|
import { CodeBlockHeaderPlugin } from "./CodeBlockHeaderPlugin.js";
|
|
54
|
+
import { CodePastePlugin } from "./CodePastePlugin.js";
|
|
54
55
|
import { CodeSyntaxPlugin } from "./CodeSyntaxPlugin.js";
|
|
55
56
|
import { MarkdownExtensionsPlugin } from "./MarkdownExtensionsPlugin.js";
|
|
56
57
|
import { TaskCheckboxPlugin } from "./TaskCheckboxPlugin.js";
|
|
@@ -61,6 +62,7 @@ import { DEFAULT_NODES } from "./editorNodes.js";
|
|
|
61
62
|
import { $exportMarkdownKeepingSource } from "./markdownSource.js";
|
|
62
63
|
import { DEFAULT_TRANSFORMERS } from "./markdownTable.js";
|
|
63
64
|
import { BLUR_COMMAND, COMMAND_PRIORITY_LOW, defineExtension, KEY_DOWN_COMMAND, KEY_ESCAPE_COMMAND, KEY_TAB_COMMAND, mergeRegister } from 'lexical';
|
|
65
|
+
import { rendererManagedRootProps } from "./privateAttributes/layerPortalBoundary.stylex.js";
|
|
64
66
|
|
|
65
67
|
/**
|
|
66
68
|
* Serialized state for an empty editor: a root containing a single empty
|
|
@@ -295,7 +297,7 @@ export const RichTextEditor = function RichTextEditor({
|
|
|
295
297
|
...mergeProps(themeProps('rich-text-editor', {
|
|
296
298
|
size,
|
|
297
299
|
status: status?.type ?? null
|
|
298
|
-
}), stylex.props(inputWrapperStyles.base, styles.wrapper,
|
|
300
|
+
}), stylex.props(inputWrapperStyles.base, inputWrapperStyles.textField, styles.wrapper,
|
|
299
301
|
// Only disabled is dimmed, matching TextArea: a read-only editor
|
|
300
302
|
// keeps full-opacity text and stays keyboard-reachable.
|
|
301
303
|
isDisabled && inputWrapperStyles.disabled, isDisabled && styles.disabled, status && inputStatusBorderStyles[status.type], status && !isDisabled && !isReadOnly && inputStatusHoverShadowStyles[status.type], status && inputStatusFocusWithinStyles[status.type], xstyle), className, style),
|
|
@@ -333,6 +335,7 @@ export const RichTextEditor = function RichTextEditor({
|
|
|
333
335
|
...{
|
|
334
336
|
className: "x1n2onr6 xh8yej3 x9ynric xjm74w1 xf9zqsd xw6l6zx"
|
|
335
337
|
},
|
|
338
|
+
dir: rest.dir,
|
|
336
339
|
children: [/*#__PURE__*/_jsx(RichTextPlugin, {
|
|
337
340
|
contentEditable: /*#__PURE__*/_jsx(EditorContentEditable, {
|
|
338
341
|
id: inputID,
|
|
@@ -361,7 +364,7 @@ export const RichTextEditor = function RichTextEditor({
|
|
|
361
364
|
codeLanguages: codeLanguages
|
|
362
365
|
}), /*#__PURE__*/_jsx(CodeSyntaxPlugin, {
|
|
363
366
|
codeLanguages: codeLanguages
|
|
364
|
-
}), /*#__PURE__*/_jsx(CodeBackspacePlugin, {}), markdownExtensions != null && markdownExtensions.length > 0 ? /*#__PURE__*/_jsx(MarkdownExtensionsPlugin, {
|
|
367
|
+
}), /*#__PURE__*/_jsx(CodeBackspacePlugin, {}), /*#__PURE__*/_jsx(CodePastePlugin, {}), markdownExtensions != null && markdownExtensions.length > 0 ? /*#__PURE__*/_jsx(MarkdownExtensionsPlugin, {
|
|
365
368
|
extensions: markdownExtensions,
|
|
366
369
|
transformers: markdownTransformers
|
|
367
370
|
}) : null, /*#__PURE__*/_jsx(TabIndentationPlugin, {}), /*#__PURE__*/_jsx(TabFocusEscapePlugin, {}), /*#__PURE__*/_jsx(SelectAllScopePlugin, {}), /*#__PURE__*/_jsx(ImageSourceCaretPlugin, {}), hasMarkdownShortcuts && /*#__PURE__*/_jsx(MarkdownShortcutPlugin, {
|
|
@@ -621,7 +624,9 @@ function EditorContentEditable({
|
|
|
621
624
|
'aria-readonly': 'true'
|
|
622
625
|
} : null),
|
|
623
626
|
...stylex.props(styles.contentEditable, dynamicStyles.contentEditableMinHeight(minHeight)),
|
|
624
|
-
...rest
|
|
627
|
+
...rest,
|
|
628
|
+
// Lexical reconciles this DOM, so Layer keeps corrective portals out.
|
|
629
|
+
...rendererManagedRootProps
|
|
625
630
|
};
|
|
626
631
|
if (placeholderText) {
|
|
627
632
|
return /*#__PURE__*/_jsx(ContentEditable, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editorTheme.d.ts","sourceRoot":"","sources":["../src/editorTheme.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"editorTheme.d.ts","sourceRoot":"","sources":["../src/editorTheme.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,SAAS,CAAC;AAschD;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,kBAAkB,CAgEtD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file privateAttributes/layerPortalBoundary.stylex.ts
|
|
3
|
+
* @input The editable root Lexical reconciles
|
|
4
|
+
* @output rendererManagedRootProps, which marks that root
|
|
5
|
+
* @position Owner module of the private layer-portal-boundary attribute in
|
|
6
|
+
* RichText: the only RichText file that writes its name. Core's Layer reads
|
|
7
|
+
* the mark through its own owner module of the same name. No package entry
|
|
8
|
+
* exports it.
|
|
9
|
+
*/
|
|
10
|
+
/** Spread on the editable root, whose DOM Lexical reconciles. */
|
|
11
|
+
export declare const rendererManagedRootProps: Readonly<Record<`data-${string}`, string>>;
|
|
12
|
+
//# sourceMappingURL=layerPortalBoundary.stylex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layerPortalBoundary.stylex.d.ts","sourceRoot":"","sources":["../../src/privateAttributes/layerPortalBoundary.stylex.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH,iEAAiE;AACjE,eAAO,MAAM,wBAAwB,EAAE,QAAQ,CAC7C,MAAM,CAAC,QAAQ,MAAM,EAAE,EAAE,MAAM,CAAC,CAGjC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file privateAttributes/layerPortalBoundary.stylex.ts
|
|
5
|
+
* @input The editable root Lexical reconciles
|
|
6
|
+
* @output rendererManagedRootProps, which marks that root
|
|
7
|
+
* @position Owner module of the private layer-portal-boundary attribute in
|
|
8
|
+
* RichText: the only RichText file that writes its name. Core's Layer reads
|
|
9
|
+
* the mark through its own owner module of the same name. No package entry
|
|
10
|
+
* exports it.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** Spread on the editable root, whose DOM Lexical reconciles. */
|
|
14
|
+
export const rendererManagedRootProps = {
|
|
15
|
+
'data-astryx-layer-portal-boundary': 'external'
|
|
16
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/richtext",
|
|
3
3
|
"displayName": "Rich Text",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.12-canary.0f28099",
|
|
5
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",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
68
|
"@stylexjs/stylex": ">=0.10.0",
|
|
69
|
-
"@astryxdesign/core": "0.7.
|
|
69
|
+
"@astryxdesign/core": "0.7.12-canary.0f28099",
|
|
70
70
|
"react": ">=19.0.0",
|
|
71
71
|
"react-dom": ">=19.0.0",
|
|
72
72
|
"lexical": "^0.52.0",
|
|
@@ -125,6 +125,8 @@
|
|
|
125
125
|
}
|
|
126
126
|
},
|
|
127
127
|
"devDependencies": {
|
|
128
|
+
"@astryxdesign/a11y-spec": "0.7.12-canary.0f28099",
|
|
129
|
+
"@astryxdesign/cli": "0.7.12-canary.0f28099",
|
|
128
130
|
"@babel/cli": "^7.29.7",
|
|
129
131
|
"@babel/core": "^7.29.7",
|
|
130
132
|
"@babel/preset-react": "^7.29.7",
|
|
@@ -143,9 +145,7 @@
|
|
|
143
145
|
"@lexical/utils": "^0.52.0",
|
|
144
146
|
"@stylexjs/babel-plugin": "^0.19.0",
|
|
145
147
|
"@testing-library/react": "^16.3.2",
|
|
146
|
-
"lexical": "^0.52.0"
|
|
147
|
-
"@astryxdesign/a11y-spec": "0.0.0",
|
|
148
|
-
"@astryxdesign/cli": "0.7.11"
|
|
148
|
+
"lexical": "^0.52.0"
|
|
149
149
|
},
|
|
150
150
|
"scripts": {
|
|
151
151
|
"api:report": "node ../../scripts/api-report/cli.mjs --package .",
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @file CodePastePlugin.tsx
|
|
7
|
+
* @input Uses @lexical/react (composer context), @lexical/code (CodeNode), and
|
|
8
|
+
* lexical.
|
|
9
|
+
* @output Exports CodePastePlugin, which makes rich content pasted or dropped
|
|
10
|
+
* into a code block go in as plain lines of code.
|
|
11
|
+
* @position Rendered by RichTextEditor; always on; not exported. A paste
|
|
12
|
+
* whose selection starts in a code block goes in as plain text: the
|
|
13
|
+
* clipboard's plain text, or else one line per pasted block.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import {useEffect} from 'react';
|
|
17
|
+
import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
|
|
18
|
+
import {$isCodeNode} from '@lexical/code';
|
|
19
|
+
import {
|
|
20
|
+
$addUpdateTag,
|
|
21
|
+
$findMatchingParent,
|
|
22
|
+
$getSelection,
|
|
23
|
+
$isElementNode,
|
|
24
|
+
$isRangeSelection,
|
|
25
|
+
$isSelectionCapturedInDecoratorInput,
|
|
26
|
+
COMMAND_PRIORITY_LOW,
|
|
27
|
+
isDOMNode,
|
|
28
|
+
mergeRegister,
|
|
29
|
+
PASTE_COMMAND,
|
|
30
|
+
PASTE_TAG,
|
|
31
|
+
SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,
|
|
32
|
+
type BaseSelection,
|
|
33
|
+
type LexicalNode,
|
|
34
|
+
type RangeSelection,
|
|
35
|
+
} from 'lexical';
|
|
36
|
+
|
|
37
|
+
/** Clipboard types that carry more than plain text. */
|
|
38
|
+
const RICH_TYPES = ['text/html', 'application/x-lexical-editor'];
|
|
39
|
+
|
|
40
|
+
/** Whether content inserted at the selection lands in a code block. */
|
|
41
|
+
function $startsInCodeBlock(
|
|
42
|
+
selection: BaseSelection | null,
|
|
43
|
+
): selection is RangeSelection {
|
|
44
|
+
if (!$isRangeSelection(selection)) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
const start = selection.isBackward() ? selection.focus : selection.anchor;
|
|
48
|
+
const node = start.getNode();
|
|
49
|
+
// A link (an autolinked URL) can sit between the text and its code block.
|
|
50
|
+
return $findMatchingParent(node, $isCodeNode) !== null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Clipboard nodes as plain lines: each block's text on a line of its own (a
|
|
55
|
+
* paragraph, a heading, a list item, a table cell), and inline content
|
|
56
|
+
* between blocks on one line.
|
|
57
|
+
*/
|
|
58
|
+
function $plainLinesOf(nodes: ReadonlyArray<LexicalNode>): string {
|
|
59
|
+
const lines: string[] = [];
|
|
60
|
+
let inline: string | null = null;
|
|
61
|
+
const endInline = () => {
|
|
62
|
+
if (inline != null) {
|
|
63
|
+
lines.push(inline);
|
|
64
|
+
inline = null;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const visit = (node: LexicalNode) => {
|
|
68
|
+
if (node.isInline()) {
|
|
69
|
+
inline = (inline ?? '') + node.getTextContent();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
endInline();
|
|
73
|
+
if (
|
|
74
|
+
$isElementNode(node) &&
|
|
75
|
+
node.getChildren().some(child => !child.isInline())
|
|
76
|
+
) {
|
|
77
|
+
node.getChildren().forEach(visit);
|
|
78
|
+
endInline();
|
|
79
|
+
} else {
|
|
80
|
+
lines.push(node.getTextContent());
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
nodes.forEach(visit);
|
|
84
|
+
endInline();
|
|
85
|
+
return lines.join('\n');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function CodePastePlugin(): null {
|
|
89
|
+
const [editor] = useLexicalComposerContext();
|
|
90
|
+
useEffect(
|
|
91
|
+
() =>
|
|
92
|
+
mergeRegister(
|
|
93
|
+
// Ahead of the rich-text paste, which inserts the clipboard's rich
|
|
94
|
+
// content when there is any.
|
|
95
|
+
editor.registerCommand(
|
|
96
|
+
PASTE_COMMAND,
|
|
97
|
+
event => {
|
|
98
|
+
// A paste into an input a decorator node renders is that input's.
|
|
99
|
+
if (
|
|
100
|
+
isDOMNode(event.target) &&
|
|
101
|
+
$isSelectionCapturedInDecoratorInput(event.target)
|
|
102
|
+
) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
const data = 'clipboardData' in event ? event.clipboardData : null;
|
|
106
|
+
if (
|
|
107
|
+
!editor.isEditable() ||
|
|
108
|
+
data == null ||
|
|
109
|
+
!RICH_TYPES.some(type => data.types.includes(type))
|
|
110
|
+
) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
const text = data.getData('text/plain');
|
|
114
|
+
const selection = $getSelection();
|
|
115
|
+
if (text === '' || !$startsInCodeBlock(selection)) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
event.preventDefault();
|
|
119
|
+
// Its own undo step, as every paste is.
|
|
120
|
+
$addUpdateTag(PASTE_TAG);
|
|
121
|
+
selection.insertRawText(text);
|
|
122
|
+
return true;
|
|
123
|
+
},
|
|
124
|
+
COMMAND_PRIORITY_LOW,
|
|
125
|
+
),
|
|
126
|
+
// Every insertion of clipboard nodes, a paste with no plain text or a
|
|
127
|
+
// drop, comes through here; ahead of the table's own handler.
|
|
128
|
+
editor.registerCommand(
|
|
129
|
+
SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,
|
|
130
|
+
({nodes, selection}) => {
|
|
131
|
+
if (!$startsInCodeBlock(selection)) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
selection.insertRawText($plainLinesOf(nodes));
|
|
135
|
+
return true;
|
|
136
|
+
},
|
|
137
|
+
COMMAND_PRIORITY_LOW,
|
|
138
|
+
),
|
|
139
|
+
),
|
|
140
|
+
[editor],
|
|
141
|
+
);
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
@@ -243,6 +243,11 @@ export const docs = {
|
|
|
243
243
|
description:
|
|
244
244
|
'Backspace at the very start of a code block turns it into a paragraph holding its lines, each on its own line, with the caret at its start. The code never merges into the block above, so a heading above keeps its own text. Backspace anywhere else in a code block deletes as usual.',
|
|
245
245
|
},
|
|
246
|
+
{
|
|
247
|
+
guidance: true,
|
|
248
|
+
description:
|
|
249
|
+
'Pasting into a code block inserts plain code. Rich content, such as a web page, a word processor document, or blocks copied from another editor, goes in as the plain text on the clipboard; when the clipboard has no plain text, each pasted block goes in as one line of its text. Headings, lists, tables, and formatting never land inside a code block.',
|
|
250
|
+
},
|
|
246
251
|
{
|
|
247
252
|
guidance: true,
|
|
248
253
|
description:
|
package/src/RichTextEditor.tsx
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @file RichTextEditor.tsx
|
|
7
|
-
* @input Uses React, useId, Lexical (lexical + @lexical/react, composed through
|
|
7
|
+
* @input Uses React, useId, a declared DOM boundary, Lexical (lexical + @lexical/react, composed through
|
|
8
8
|
* LexicalExtensionComposer), Field, VisuallyHidden, useInputStatusIcon,
|
|
9
9
|
* mergeProps, design tokens
|
|
10
10
|
* @output Exports an accessibly labelled RichTextEditor component with a flush
|
|
@@ -79,6 +79,7 @@ import {TextSemanticsExtension} from './textSemantics';
|
|
|
79
79
|
import {TableColumnFloorPlugin} from './TableColumnFloorPlugin';
|
|
80
80
|
import {CodeBackspacePlugin} from './CodeBackspacePlugin';
|
|
81
81
|
import {CodeBlockHeaderPlugin} from './CodeBlockHeaderPlugin';
|
|
82
|
+
import {CodePastePlugin} from './CodePastePlugin';
|
|
82
83
|
import {CodeSyntaxPlugin} from './CodeSyntaxPlugin';
|
|
83
84
|
import {MarkdownExtensionsPlugin} from './MarkdownExtensionsPlugin';
|
|
84
85
|
import type {RichTextMarkdownExtension} from './markdownExtensions';
|
|
@@ -106,6 +107,7 @@ import {
|
|
|
106
107
|
type LexicalNode,
|
|
107
108
|
type EditorThemeClasses,
|
|
108
109
|
} from 'lexical';
|
|
110
|
+
import {rendererManagedRootProps} from './privateAttributes/layerPortalBoundary.stylex';
|
|
109
111
|
|
|
110
112
|
/**
|
|
111
113
|
* Serialized state for an empty editor: a root containing a single empty
|
|
@@ -660,6 +662,7 @@ export const RichTextEditor = function RichTextEditor({
|
|
|
660
662
|
}),
|
|
661
663
|
stylex.props(
|
|
662
664
|
inputWrapperStyles.base,
|
|
665
|
+
inputWrapperStyles.textField,
|
|
663
666
|
styles.wrapper,
|
|
664
667
|
// Only disabled is dimmed, matching TextArea: a read-only editor
|
|
665
668
|
// keeps full-opacity text and stays keyboard-reachable.
|
|
@@ -687,7 +690,7 @@ export const RichTextEditor = function RichTextEditor({
|
|
|
687
690
|
!!statusIcon && styles.editorBodyWithStatus,
|
|
688
691
|
size === 'lg' && editorBodySizeStyles.lg,
|
|
689
692
|
)}>
|
|
690
|
-
<div {...stylex.props(styles.editorRoot)}>
|
|
693
|
+
<div {...stylex.props(styles.editorRoot)} dir={rest.dir}>
|
|
691
694
|
<RichTextPlugin
|
|
692
695
|
contentEditable={
|
|
693
696
|
<EditorContentEditable
|
|
@@ -728,6 +731,7 @@ export const RichTextEditor = function RichTextEditor({
|
|
|
728
731
|
{/* Backspace at the very start of a code block makes it a
|
|
729
732
|
paragraph, instead of merging it into the block above. */}
|
|
730
733
|
<CodeBackspacePlugin />
|
|
734
|
+
<CodePastePlugin />
|
|
731
735
|
{markdownExtensions != null && markdownExtensions.length > 0 ? (
|
|
732
736
|
<MarkdownExtensionsPlugin
|
|
733
737
|
extensions={markdownExtensions}
|
|
@@ -1065,6 +1069,8 @@ function EditorContentEditable({
|
|
|
1065
1069
|
dynamicStyles.contentEditableMinHeight(minHeight),
|
|
1066
1070
|
),
|
|
1067
1071
|
...rest,
|
|
1072
|
+
// Lexical reconciles this DOM, so Layer keeps corrective portals out.
|
|
1073
|
+
...rendererManagedRootProps,
|
|
1068
1074
|
};
|
|
1069
1075
|
if (placeholderText) {
|
|
1070
1076
|
return (
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/** @type {import('@astryxdesign/cli/authoring').ComponentDoc} */
|
|
4
|
+
|
|
5
|
+
export const docs = {
|
|
6
|
+
name: 'RichTextEditorAutoLinkPlugin',
|
|
7
|
+
subComponentOf: 'RichTextEditor',
|
|
8
|
+
description:
|
|
9
|
+
'Turns typed and pasted URLs and email addresses into links, in the plugins slot of RichTextEditor.',
|
|
10
|
+
displayName: 'Rich Text Editor Auto-Link Plugin',
|
|
11
|
+
keywords: ['richtext', 'autolink', 'link', 'url', 'email', 'plugin'],
|
|
12
|
+
props: [
|
|
13
|
+
{
|
|
14
|
+
name: 'matchers',
|
|
15
|
+
type: 'LinkMatcher[]',
|
|
16
|
+
description:
|
|
17
|
+
'Link matchers to use. The default recognizes URLs and email addresses and opens the links in a new tab. Build extra matchers with createLinkMatcherWithRegExp from @lexical/react/LexicalAutoLinkPlugin.',
|
|
18
|
+
default: 'DEFAULT_LINK_MATCHERS',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: 'onChange',
|
|
22
|
+
type: '(url: string | null, prevUrl: string | null) => void',
|
|
23
|
+
description:
|
|
24
|
+
'Called when auto-linking creates, updates or removes a link. It gets the new URL, or null when the link is removed, and the previous URL.',
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
usage: {
|
|
28
|
+
description:
|
|
29
|
+
"Turns typed and pasted URLs and email addresses into links. Render it in RichTextEditor's plugins slot; it reaches the editor through the editor's Lexical composer and uses AutoLinkNode, which the editor registers by default.",
|
|
30
|
+
bestPractices: [
|
|
31
|
+
{
|
|
32
|
+
guidance: true,
|
|
33
|
+
description:
|
|
34
|
+
'Pass it as plugins={<RichTextEditorAutoLinkPlugin />}. Its links open in a new tab, with target="_blank" and rel="noopener noreferrer" in the node.',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
guidance: false,
|
|
38
|
+
description:
|
|
39
|
+
"Render it outside RichTextEditor's plugins slot: it needs the editor's Lexical composer.",
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/** @type {import('@astryxdesign/cli/authoring').ComponentDoc} */
|
|
4
|
+
|
|
5
|
+
export const docs = {
|
|
6
|
+
name: 'RichTextEditorToolbar',
|
|
7
|
+
subComponentOf: 'RichTextEditor',
|
|
8
|
+
description: 'Formatting toolbar for the toolbar slot of RichTextEditor.',
|
|
9
|
+
displayName: 'Rich Text Editor Toolbar',
|
|
10
|
+
keywords: ['richtext', 'toolbar', 'formatting', 'bold', 'link', 'heading'],
|
|
11
|
+
props: [
|
|
12
|
+
{
|
|
13
|
+
name: 'ref',
|
|
14
|
+
type: 'Ref<HTMLDivElement>',
|
|
15
|
+
description:
|
|
16
|
+
'Ref to the toolbar\'s root element. The ref, className, style and xstyle reach the root of the Astryx Toolbar it renders; data-*, other aria-* attributes and DOM handlers reach its role="toolbar" element.',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: 'label',
|
|
20
|
+
type: 'string',
|
|
21
|
+
description:
|
|
22
|
+
'Accessible label for the toolbar element. Pass label rather than aria-label.',
|
|
23
|
+
default: "'Text formatting' (translated)",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: 'headingLevels',
|
|
27
|
+
type: "ReadonlyArray<'h1' | 'h2' | 'h3'>",
|
|
28
|
+
description:
|
|
29
|
+
'Which heading levels the block-format selector offers, in order.',
|
|
30
|
+
default: "['h1', 'h2', 'h3']",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: 'size',
|
|
34
|
+
type: "'sm' | 'md' | 'lg'",
|
|
35
|
+
description:
|
|
36
|
+
"Size of the toolbar's controls; it also sets the toolbar's padding.",
|
|
37
|
+
default: "'sm'",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'hasLink',
|
|
41
|
+
type: 'boolean',
|
|
42
|
+
description:
|
|
43
|
+
'Whether to show the link button. It opens an Astryx Dialog that adds, updates or removes a link and keeps the editor selection. With a collapsed selection the URL is inserted as link text; otherwise the selected text is linked. Only http, https, mailto and tel URLs are written.',
|
|
44
|
+
default: 'true',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'promptForUrl',
|
|
48
|
+
type: '(selectedText: string) => string | null | undefined',
|
|
49
|
+
description:
|
|
50
|
+
'A synchronous URL prompt that replaces the built-in Dialog when the link button is pressed on a selection that is not a link. It gets the selected text; return the URL, or null or an empty string to cancel.',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'hasNewTabLinks',
|
|
54
|
+
type: 'boolean',
|
|
55
|
+
description:
|
|
56
|
+
'Whether links made with the toolbar open in a new tab. When true, target="_blank" and rel="noopener noreferrer" are written into the link node, so they serialize.',
|
|
57
|
+
default: 'true',
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: 'endContent',
|
|
61
|
+
type: 'ReactNode',
|
|
62
|
+
description:
|
|
63
|
+
'Extra items at the end of the toolbar, after a divider, such as mention or AI controls.',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: 'xstyle',
|
|
67
|
+
type: 'StyleXStyles',
|
|
68
|
+
description: "StyleX styles for the toolbar's root.",
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
usage: {
|
|
72
|
+
description:
|
|
73
|
+
"A formatting toolbar for RichTextEditor, built from Astryx Toolbar, Selector and ToggleButton controls: undo and redo, a block-format selector for paragraphs, headings, lists and quotes, inline bold, italic, underline, strikethrough and code, and links. Render it in the editor's toolbar slot; it reaches the editor through the editor's Lexical composer, so it must live inside it.",
|
|
74
|
+
bestPractices: [
|
|
75
|
+
{
|
|
76
|
+
guidance: true,
|
|
77
|
+
description:
|
|
78
|
+
'Pass it as toolbar={<RichTextEditorToolbar />}. The slot places it at the top of the field, before the editing surface, in the right keyboard order.',
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
guidance: true,
|
|
82
|
+
description:
|
|
83
|
+
"Restyle a glyph from a theme by its richtext:* icon key (see RICHTEXT_ICON_KEYS), for example defineTheme({icons: {'richtext:bold': <MyBoldIcon />}}).",
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
guidance: false,
|
|
87
|
+
description:
|
|
88
|
+
"Render it outside RichTextEditor's toolbar slot: it needs the editor's Lexical composer.",
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/** @type {import('@astryxdesign/cli/authoring').ComponentDoc} */
|
|
4
|
+
|
|
5
|
+
export const docs = {
|
|
6
|
+
name: 'RichTextView',
|
|
7
|
+
displayName: 'Rich Text View',
|
|
8
|
+
category: 'Content',
|
|
9
|
+
keywords: [
|
|
10
|
+
'richtext',
|
|
11
|
+
'rich text',
|
|
12
|
+
'viewer',
|
|
13
|
+
'read-only',
|
|
14
|
+
'lexical',
|
|
15
|
+
'render',
|
|
16
|
+
'serialized',
|
|
17
|
+
],
|
|
18
|
+
props: [
|
|
19
|
+
{
|
|
20
|
+
name: 'value',
|
|
21
|
+
type: 'string',
|
|
22
|
+
description:
|
|
23
|
+
'Serialized editor state to render: the JSON string from JSON.stringify(editorState.toJSON()). The view updates when value changes.',
|
|
24
|
+
required: true,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'nodes',
|
|
28
|
+
type: 'ReadonlyArray<Klass<LexicalNode>>',
|
|
29
|
+
description:
|
|
30
|
+
'Lexical nodes to register beyond the default set. Pass the same nodes the content was authored with, so custom node types deserialize.',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: 'markdownExtensions',
|
|
34
|
+
type: 'ReadonlyArray<RichTextMarkdownExtension>',
|
|
35
|
+
description:
|
|
36
|
+
'Markdown plugins whose nodes this view draws, each adopted with createRichTextExtension. A plugin node renders as core Markdown renders it; a node whose plugin is not passed shows its source. Pass the extensions the content was converted with, created in a client module.',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'codeLanguages',
|
|
40
|
+
type: 'ReadonlyArray<CodeLanguage>',
|
|
41
|
+
description:
|
|
42
|
+
"CodeBlock languages a fence may name, such as graphql from @astryxdesign/core/CodeBlock/languages/graphql. Pass the same list as Markdown's codeLanguages, so reading and editing label and paint the same languages.",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'plugins',
|
|
46
|
+
type: 'ReactNode',
|
|
47
|
+
description:
|
|
48
|
+
'Read-only Lexical plugins to render inside the view, such as hover cards or decorators.',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: 'namespace',
|
|
52
|
+
type: 'string',
|
|
53
|
+
description: 'The Lexical composer namespace.',
|
|
54
|
+
default: "'astryx-view'",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'onParseError',
|
|
58
|
+
type: '(error: Error) => void',
|
|
59
|
+
description:
|
|
60
|
+
'Called when value cannot be parsed or rendered, for example malformed JSON or a node type that is not registered through nodes. Use it to log or report the failure.',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: 'errorFallback',
|
|
64
|
+
type: 'ReactNode',
|
|
65
|
+
description:
|
|
66
|
+
'What to render when value cannot be parsed or rendered. The view renders it instead of throwing.',
|
|
67
|
+
default: 'null',
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: 'xstyle',
|
|
71
|
+
type: 'StyleXStyles',
|
|
72
|
+
description: 'StyleX styles for the view root.',
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
usage: {
|
|
76
|
+
description:
|
|
77
|
+
'Renders serialized RichTextEditor content read-only, with the same nodes, tables, code blocks and Markdown plugin nodes the editor draws. Ships from @astryxdesign/richtext, with lexical and @lexical/* as optional peer dependencies.',
|
|
78
|
+
bestPractices: [
|
|
79
|
+
{
|
|
80
|
+
guidance: true,
|
|
81
|
+
description:
|
|
82
|
+
'Store editorState.toJSON() from RichTextEditor onChange, and pass the stringified JSON as value.',
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
guidance: true,
|
|
86
|
+
description:
|
|
87
|
+
'Register the same custom nodes and markdownExtensions on the editor and the view, so stored content round-trips.',
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
guidance: true,
|
|
91
|
+
description:
|
|
92
|
+
'Pass onParseError and an errorFallback when the stored content can come from an older or a foreign schema. By default a parse failure renders nothing instead of throwing.',
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
guidance: false,
|
|
96
|
+
description:
|
|
97
|
+
'Use RichTextView to render Markdown source; use core Markdown for that.',
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
},
|
|
101
|
+
};
|
package/src/editorTheme.ts
CHANGED
|
@@ -62,9 +62,10 @@ const editorTheme = stylex.create({
|
|
|
62
62
|
// Lexical marks every top-level block `dir="auto"`, which picks each
|
|
63
63
|
// block's direction from its first strong character: a Hebrew paragraph in
|
|
64
64
|
// an English document flips to the right, an English one in an Arabic
|
|
65
|
-
// document to the left.
|
|
66
|
-
// them
|
|
67
|
-
//
|
|
65
|
+
// document to the left. Here blocks take the direction of the surface
|
|
66
|
+
// around them, and bidi inside a block still follows the Unicode
|
|
67
|
+
// algorithm. Core Markdown differs: it gives each block the direction of
|
|
68
|
+
// its own text.
|
|
68
69
|
providerDirection: {
|
|
69
70
|
direction: 'inherit',
|
|
70
71
|
},
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file privateAttributes/layerPortalBoundary.stylex.ts
|
|
5
|
+
* @input The editable root Lexical reconciles
|
|
6
|
+
* @output rendererManagedRootProps, which marks that root
|
|
7
|
+
* @position Owner module of the private layer-portal-boundary attribute in
|
|
8
|
+
* RichText: the only RichText file that writes its name. Core's Layer reads
|
|
9
|
+
* the mark through its own owner module of the same name. No package entry
|
|
10
|
+
* exports it.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** Spread on the editable root, whose DOM Lexical reconciles. */
|
|
14
|
+
export const rendererManagedRootProps: Readonly<
|
|
15
|
+
Record<`data-${string}`, string>
|
|
16
|
+
> = {
|
|
17
|
+
'data-astryx-layer-portal-boundary': 'external',
|
|
18
|
+
};
|