@astryxdesign/richtext 0.7.11 → 0.7.12-canary.0840fcc
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 +9 -0
- package/dist/CodePastePlugin.d.ts +2 -0
- package/dist/CodePastePlugin.d.ts.map +1 -0
- package/dist/CodePastePlugin.js +103 -0
- package/dist/CodeTabPlugin.d.ts +2 -0
- package/dist/CodeTabPlugin.d.ts.map +1 -0
- package/dist/CodeTabPlugin.js +256 -0
- package/dist/DisabledLinkGuardPlugin.d.ts +4 -0
- package/dist/DisabledLinkGuardPlugin.d.ts.map +1 -0
- package/dist/DisabledLinkGuardPlugin.js +93 -0
- package/dist/RichTextEditor.d.ts +3 -2
- package/dist/RichTextEditor.d.ts.map +1 -1
- package/dist/RichTextEditor.js +17 -7
- package/dist/RichTextEditorAutoLinkPlugin.d.ts +5 -5
- package/dist/RichTextEditorAutoLinkPlugin.d.ts.map +1 -1
- package/dist/RichTextEditorAutoLinkPlugin.js +12 -6
- 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/CodeTabPlugin.tsx +298 -0
- package/src/DisabledLinkGuardPlugin.tsx +93 -0
- package/src/RichTextEditor.doc.mjs +16 -1
- package/src/RichTextEditor.tsx +18 -4
- package/src/RichTextEditorAutoLinkPlugin.doc.mjs +43 -0
- package/src/RichTextEditorAutoLinkPlugin.tsx +18 -6
- 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
|
@@ -85,7 +85,7 @@ export const docs = {
|
|
|
85
85
|
name: 'isDisabled',
|
|
86
86
|
type: 'boolean',
|
|
87
87
|
description:
|
|
88
|
-
'Whether the editor is disabled: non-editable, dimmed, out of the tab order, and announced as disabled. Wins when isReadOnly is also set. Takes effect when changed after mount.',
|
|
88
|
+
'Whether the editor is disabled: non-editable, dimmed, out of the tab order, and announced as disabled. Its links do not navigate and are not tab stops. Wins when isReadOnly is also set. Takes effect when changed after mount.',
|
|
89
89
|
default: 'false',
|
|
90
90
|
},
|
|
91
91
|
{
|
|
@@ -238,11 +238,21 @@ export const docs = {
|
|
|
238
238
|
description:
|
|
239
239
|
'GFM pipe tables import, edit, and export by default. The first row renders as header cells, delimiter-row colons set each column alignment, rows shorter than the widest row gain empty cells, and a wide table scrolls inside its own wrapper. Arrow keys move between cells; Tab keeps its editor meaning, so Escape then Tab still leaves the editor. Tables export in the canonical form: outer pipes and three-dash delimiters. RichTextView renders the same tables. Install @lexical/table with the other lexical peers.',
|
|
240
240
|
},
|
|
241
|
+
{
|
|
242
|
+
guidance: true,
|
|
243
|
+
description:
|
|
244
|
+
'In a code block, Tab and Shift+Tab indent and outdent every line the selection touches, by the indent the block already uses: a tab when one of its lines starts with a tab, otherwise the fewest spaces an indented line starts with (2 to 8), otherwise 2 spaces. The selection stays on the same characters, and each press is one undo step. Escape then Tab still moves focus out of the editor.',
|
|
245
|
+
},
|
|
241
246
|
{
|
|
242
247
|
guidance: true,
|
|
243
248
|
description:
|
|
244
249
|
'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
250
|
},
|
|
251
|
+
{
|
|
252
|
+
guidance: true,
|
|
253
|
+
description:
|
|
254
|
+
'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.',
|
|
255
|
+
},
|
|
246
256
|
{
|
|
247
257
|
guidance: true,
|
|
248
258
|
description:
|
|
@@ -283,6 +293,11 @@ export const docs = {
|
|
|
283
293
|
description:
|
|
284
294
|
"The toolbar's glyphs are themeable. Each control resolves its icon from the core icon registry under a stable richtext:* key (see RICHTEXT_ICON_KEYS), falling back to a bundled inline SVG. A theme restyles any glyph without forking the toolbar by naming its key: defineTheme({icons: {'richtext:bold': <MyBoldIcon />}}). Undo and redo mirror under right-to-left direction, whichever glyph draws them.",
|
|
285
295
|
},
|
|
296
|
+
{
|
|
297
|
+
guidance: true,
|
|
298
|
+
description:
|
|
299
|
+
"To switch between reading (Markdown or RichTextView) and editing the same document in place, give the editor's field its inset and border outside the reading width, so every paragraph keeps its line count across the switch. Define the frame with stylex.create, for example const inPlace = stylex.create({editorFrame: {marginInline: `calc(-1 * (${spacingVars['--spacing-2']} + ${borderVars['--border-width']}))`}}), with spacingVars and borderVars from @astryxdesign/core/theme/tokens.stylex, and pass xstyle={inPlace.editorFrame} to the RichTextEditor. The recipe assumes no status: a status icon reserves another spacing-6 at the inline end. The field then extends past the column on both sides; leave room for it in the surrounding padding. A standalone editor in a form keeps its default width, so its border lines up with the fields around it.",
|
|
300
|
+
},
|
|
286
301
|
{
|
|
287
302
|
guidance: false,
|
|
288
303
|
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,11 +79,14 @@ 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';
|
|
84
|
+
import {CodeTabPlugin} from './CodeTabPlugin';
|
|
83
85
|
import {MarkdownExtensionsPlugin} from './MarkdownExtensionsPlugin';
|
|
84
86
|
import type {RichTextMarkdownExtension} from './markdownExtensions';
|
|
85
87
|
import type {CodeLanguage} from '@astryxdesign/core/CodeBlock';
|
|
86
88
|
import {TaskCheckboxPlugin} from './TaskCheckboxPlugin';
|
|
89
|
+
import {DisabledLinkGuardPlugin} from './DisabledLinkGuardPlugin';
|
|
87
90
|
import {SelectAllScopePlugin} from './SelectAllScopePlugin';
|
|
88
91
|
import {ImageSourceCaretPlugin} from './ImageSourceCaretPlugin';
|
|
89
92
|
import {type Transformer} from '@lexical/markdown';
|
|
@@ -106,6 +109,7 @@ import {
|
|
|
106
109
|
type LexicalNode,
|
|
107
110
|
type EditorThemeClasses,
|
|
108
111
|
} from 'lexical';
|
|
112
|
+
import {rendererManagedRootProps} from './privateAttributes/layerPortalBoundary.stylex';
|
|
109
113
|
|
|
110
114
|
/**
|
|
111
115
|
* Serialized state for an empty editor: a root containing a single empty
|
|
@@ -359,7 +363,8 @@ export interface RichTextEditorProps extends Omit<
|
|
|
359
363
|
isReadOnly?: boolean;
|
|
360
364
|
/**
|
|
361
365
|
* Whether the editor is disabled: non-editable, dimmed, out of the tab
|
|
362
|
-
* order, and announced as disabled.
|
|
366
|
+
* order, and announced as disabled. Its links do not navigate and are not
|
|
367
|
+
* tab stops. Wins when `isReadOnly` is also set.
|
|
363
368
|
* Takes effect when changed after mount.
|
|
364
369
|
* @default false
|
|
365
370
|
*/
|
|
@@ -660,6 +665,7 @@ export const RichTextEditor = function RichTextEditor({
|
|
|
660
665
|
}),
|
|
661
666
|
stylex.props(
|
|
662
667
|
inputWrapperStyles.base,
|
|
668
|
+
inputWrapperStyles.textField,
|
|
663
669
|
styles.wrapper,
|
|
664
670
|
// Only disabled is dimmed, matching TextArea: a read-only editor
|
|
665
671
|
// keeps full-opacity text and stays keyboard-reachable.
|
|
@@ -687,7 +693,7 @@ export const RichTextEditor = function RichTextEditor({
|
|
|
687
693
|
!!statusIcon && styles.editorBodyWithStatus,
|
|
688
694
|
size === 'lg' && editorBodySizeStyles.lg,
|
|
689
695
|
)}>
|
|
690
|
-
<div {...stylex.props(styles.editorRoot)}>
|
|
696
|
+
<div {...stylex.props(styles.editorRoot)} dir={rest.dir}>
|
|
691
697
|
<RichTextPlugin
|
|
692
698
|
contentEditable={
|
|
693
699
|
<EditorContentEditable
|
|
@@ -712,6 +718,7 @@ export const RichTextEditor = function RichTextEditor({
|
|
|
712
718
|
<ListPlugin />
|
|
713
719
|
<TaskCheckboxPlugin isReadOnly={isReadOnly || isDisabled} />
|
|
714
720
|
<LinkPlugin />
|
|
721
|
+
<DisabledLinkGuardPlugin isDisabled={isDisabled} />
|
|
715
722
|
{/* Tab keeps its editor meaning inside a table (indent, and
|
|
716
723
|
Escape then Tab to leave the editor); arrow keys move
|
|
717
724
|
between cells. GFM tables have no merged cells or cell
|
|
@@ -728,12 +735,16 @@ export const RichTextEditor = function RichTextEditor({
|
|
|
728
735
|
{/* Backspace at the very start of a code block makes it a
|
|
729
736
|
paragraph, instead of merging it into the block above. */}
|
|
730
737
|
<CodeBackspacePlugin />
|
|
738
|
+
<CodePastePlugin />
|
|
731
739
|
{markdownExtensions != null && markdownExtensions.length > 0 ? (
|
|
732
740
|
<MarkdownExtensionsPlugin
|
|
733
741
|
extensions={markdownExtensions}
|
|
734
742
|
transformers={markdownTransformers}
|
|
735
743
|
/>
|
|
736
744
|
) : null}
|
|
745
|
+
{/* In a code block, Tab indents the lines the selection
|
|
746
|
+
touches instead of inserting a tab character. */}
|
|
747
|
+
<CodeTabPlugin />
|
|
737
748
|
<TabIndentationPlugin />
|
|
738
749
|
<TabFocusEscapePlugin />
|
|
739
750
|
<SelectAllScopePlugin />
|
|
@@ -828,7 +839,8 @@ const ESCAPE_REARM_EXEMPT_KEYS = new Set([
|
|
|
828
839
|
* listeners from the highest priority down, stopping at the first one that
|
|
829
840
|
* returns true. Registering at COMMAND_PRIORITY_LOW (1) therefore runs first;
|
|
830
841
|
* when the escape is armed we return true WITHOUT calling
|
|
831
|
-
* `event.preventDefault()`, so the indentation
|
|
842
|
+
* `event.preventDefault()`, so the indentation handlers (TabIndentationPlugin,
|
|
843
|
+
* and CodeTabPlugin at the front of the same priority) never see the event
|
|
832
844
|
* and the browser performs its default Tab focus navigation.
|
|
833
845
|
*/
|
|
834
846
|
function TabFocusEscapePlugin(): null {
|
|
@@ -1065,6 +1077,8 @@ function EditorContentEditable({
|
|
|
1065
1077
|
dynamicStyles.contentEditableMinHeight(minHeight),
|
|
1066
1078
|
),
|
|
1067
1079
|
...rest,
|
|
1080
|
+
// Lexical reconciles this DOM, so Layer keeps corrective portals out.
|
|
1081
|
+
...rendererManagedRootProps,
|
|
1068
1082
|
};
|
|
1069
1083
|
if (placeholderText) {
|
|
1070
1084
|
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. Text inside a code block stays code and is never linked. 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
|
+
};
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
* @output Exports `RichTextEditorAutoLinkPlugin` and its props type, plus the
|
|
11
11
|
* default `DEFAULT_LINK_MATCHERS`.
|
|
12
12
|
* @position @astryxdesign/richtext. Drop into RichTextEditor's `plugins` slot to
|
|
13
|
-
* auto-linkify URLs and emails as they are typed or pasted
|
|
14
|
-
* `AutoLinkNode` to be registered (it is, by
|
|
13
|
+
* auto-linkify URLs and emails as they are typed or pasted, except inside
|
|
14
|
+
* a code block. Requires `AutoLinkNode` to be registered (it is, by
|
|
15
|
+
* default).
|
|
15
16
|
*
|
|
16
17
|
* SYNC: When modified, update:
|
|
17
18
|
* - /packages/richtext/src/index.ts (exports / barrel)
|
|
@@ -28,9 +29,8 @@
|
|
|
28
29
|
* and new-tab defaults, so a consumer supplies a richer matcher set — an
|
|
29
30
|
* application-specific identifier or ticket syntax, say — through the
|
|
30
31
|
* `matchers` prop without changing the contract. An application needing a
|
|
31
|
-
* hardened transform (expanded separators,
|
|
32
|
-
*
|
|
33
|
-
* `AutoLinkPlugin`.
|
|
32
|
+
* hardened transform (expanded separators, say) substitutes its own plugin in
|
|
33
|
+
* the same slot; astryx stays on the upstream `AutoLinkPlugin`.
|
|
34
34
|
*/
|
|
35
35
|
|
|
36
36
|
import {
|
|
@@ -38,6 +38,8 @@ import {
|
|
|
38
38
|
createLinkMatcherWithRegExp,
|
|
39
39
|
type LinkMatcher,
|
|
40
40
|
} from '@lexical/react/LexicalAutoLinkPlugin';
|
|
41
|
+
import {$isCodeNode} from '@lexical/code';
|
|
42
|
+
import type {ElementNode} from 'lexical';
|
|
41
43
|
import {URL_MATCHER, EMAIL_MATCHER, sanitizeUrl} from './linkUtils';
|
|
42
44
|
|
|
43
45
|
/**
|
|
@@ -72,6 +74,10 @@ export const DEFAULT_LINK_MATCHERS: LinkMatcher[] = [
|
|
|
72
74
|
},
|
|
73
75
|
];
|
|
74
76
|
|
|
77
|
+
// Text in a code block is never linked. The upstream plugin registers again
|
|
78
|
+
// when this array changes. Keep it a module constant.
|
|
79
|
+
const EXCLUDE_PARENTS: ((parent: ElementNode) => boolean)[] = [$isCodeNode];
|
|
80
|
+
|
|
75
81
|
export interface RichTextEditorAutoLinkPluginProps {
|
|
76
82
|
/**
|
|
77
83
|
* Link matchers to use. Defaults to {@link DEFAULT_LINK_MATCHERS} (URLs +
|
|
@@ -108,7 +114,13 @@ export function RichTextEditorAutoLinkPlugin({
|
|
|
108
114
|
matchers = DEFAULT_LINK_MATCHERS,
|
|
109
115
|
onChange,
|
|
110
116
|
}: RichTextEditorAutoLinkPluginProps) {
|
|
111
|
-
return
|
|
117
|
+
return (
|
|
118
|
+
<AutoLinkPlugin
|
|
119
|
+
matchers={matchers}
|
|
120
|
+
onChange={onChange}
|
|
121
|
+
excludeParents={EXCLUDE_PARENTS}
|
|
122
|
+
/>
|
|
123
|
+
);
|
|
112
124
|
}
|
|
113
125
|
|
|
114
126
|
RichTextEditorAutoLinkPlugin.displayName = 'RichTextEditorAutoLinkPlugin';
|
|
@@ -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
|
+
};
|