@astryxdesign/richtext 0.6.4-canary.fdc76dc → 0.6.5-canary.01972bc

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.
Files changed (52) hide show
  1. package/README.md +3 -2
  2. package/dist/RichTextEditor.d.ts +15 -7
  3. package/dist/RichTextEditor.d.ts.map +1 -1
  4. package/dist/RichTextEditor.js +55 -10
  5. package/dist/RichTextEditorAutoLinkPlugin.d.ts +10 -11
  6. package/dist/RichTextEditorAutoLinkPlugin.d.ts.map +1 -1
  7. package/dist/RichTextEditorAutoLinkPlugin.js +10 -11
  8. package/dist/RichTextEditorToolbar.d.ts.map +1 -1
  9. package/dist/RichTextEditorToolbar.js +2 -3
  10. package/dist/RichTextView.d.ts +12 -4
  11. package/dist/RichTextView.d.ts.map +1 -1
  12. package/dist/RichTextView.js +74 -14
  13. package/dist/TableScrollRegionPlugin.d.ts +9 -0
  14. package/dist/TableScrollRegionPlugin.d.ts.map +1 -0
  15. package/dist/TableScrollRegionPlugin.js +95 -0
  16. package/dist/editorNodes.d.ts +2 -2
  17. package/dist/editorNodes.d.ts.map +1 -1
  18. package/dist/editorNodes.js +4 -3
  19. package/dist/editorTheme.d.ts.map +1 -1
  20. package/dist/editorTheme.js +63 -19
  21. package/dist/markdownHardLineBreak.d.ts +22 -0
  22. package/dist/markdownHardLineBreak.d.ts.map +1 -0
  23. package/dist/markdownHardLineBreak.js +38 -0
  24. package/dist/markdownSerializers.d.ts +4 -3
  25. package/dist/markdownSerializers.d.ts.map +1 -1
  26. package/dist/markdownSerializers.js +8 -11
  27. package/dist/markdownSource.d.ts +71 -0
  28. package/dist/markdownSource.d.ts.map +1 -0
  29. package/dist/markdownSource.js +538 -0
  30. package/dist/markdownTable.d.ts +28 -0
  31. package/dist/markdownTable.d.ts.map +1 -0
  32. package/dist/markdownTable.js +184 -0
  33. package/dist/richtext.css +53 -14
  34. package/package.json +9 -3
  35. package/src/RichTextEditor.doc.mjs +23 -7
  36. package/src/RichTextEditor.test.tsx +420 -18
  37. package/src/RichTextEditor.tsx +73 -19
  38. package/src/RichTextEditorAutoLinkPlugin.tsx +10 -11
  39. package/src/RichTextEditorToolbar.tsx +2 -3
  40. package/src/RichTextView.tsx +77 -12
  41. package/src/TableScrollRegionPlugin.test.tsx +138 -0
  42. package/src/TableScrollRegionPlugin.tsx +107 -0
  43. package/src/__tests__/MarkdownParitySandbox.a11y.chromium.spec.ts +763 -0
  44. package/src/doc-mjs.d.ts +23 -0
  45. package/src/editorNodes.ts +6 -2
  46. package/src/editorTheme.ts +238 -28
  47. package/src/markdownHardLineBreak.ts +47 -0
  48. package/src/markdownSerializers.ts +16 -20
  49. package/src/markdownSource.test.tsx +632 -0
  50. package/src/markdownSource.ts +702 -0
  51. package/src/markdownTable.test.tsx +214 -0
  52. package/src/markdownTable.ts +245 -0
package/README.md CHANGED
@@ -7,7 +7,7 @@ with Astryx design tokens.
7
7
  import {RichTextEditor, RichTextView} from '@astryxdesign/richtext';
8
8
 
9
9
  <RichTextEditor label="Notes" onChange={setState} />;
10
- <RichTextView label="Notes" value={serializedState} />;
10
+ <RichTextView value={serializedState} />;
11
11
  ```
12
12
 
13
13
  The editor is deliberately minimal and extensible: pass `nodes` and `plugins` to
@@ -27,7 +27,8 @@ It ships to npm **only under the `@canary` dist-tag** — there is never a stabl
27
27
 
28
28
  > Note: this package is the successor to the experimental `RichTextEditor` that
29
29
  > used to live in `@astryxdesign/lab`; that code has moved here so it can be
30
- > canaried independently (e.g. into EPS/Nest) without a fresh package rollout.
30
+ > canaried independently by an adopting application without a fresh package
31
+ > rollout.
31
32
 
32
33
  ## Status
33
34
 
@@ -4,7 +4,8 @@
4
4
  * LexicalExtensionComposer), Field, VisuallyHidden, useInputStatusIcon,
5
5
  * mergeProps, design tokens
6
6
  * @output Exports an accessibly labelled RichTextEditor component with a flush
7
- * top toolbar slot and configurable editable-surface minimum height, RichTextEditorProps,
7
+ * top toolbar slot, configurable editable-surface minimum height, and distinct
8
+ * read-only and disabled states that follow prop changes, RichTextEditorProps,
8
9
  * RichTextEditorStatus, RichTextEditorStatusType, RichTextEditorSize
9
10
  * @position Experimental (richtext) implementation; consumed by the package index.ts and
10
11
  * re-exported from @astryxdesign/richtext. Tested by RichTextEditor.test.tsx.
@@ -56,8 +57,10 @@ export interface RichTextEditorRef {
56
57
  /**
57
58
  * Serialize the current content to a Markdown string, using the same
58
59
  * `transformers` the editor is configured with (so custom transformers
59
- * layered in via the `transformers` prop are honored). Equivalent to
60
- * `$convertToMarkdownString` run in a read context.
60
+ * layered in via the `transformers` prop are honored). Content imported
61
+ * with `markdownToEditorStateJSON` comes back as written: blocks nobody
62
+ * changed byte for byte, and only edited or added blocks in canonical
63
+ * Markdown.
61
64
  */
62
65
  getMarkdown: () => string;
63
66
  /**
@@ -107,12 +110,16 @@ export interface RichTextEditorProps extends Omit<BaseProps, 'onChange' | 'defau
107
110
  /** Placeholder text shown when the editor is empty. */
108
111
  placeholder?: string;
109
112
  /**
110
- * Whether the editor is read-only (non-editable).
113
+ * Whether the editor is read-only (non-editable). The content stays at full
114
+ * opacity, in the tab order, and announced as read-only, so people can still
115
+ * reach, read, and copy it. Takes effect when changed after mount.
111
116
  * @default false
112
117
  */
113
118
  isReadOnly?: boolean;
114
119
  /**
115
- * Whether the editor is disabled (non-editable, dimmed).
120
+ * Whether the editor is disabled: non-editable, dimmed, out of the tab
121
+ * order, and announced as disabled. Wins when `isReadOnly` is also set.
122
+ * Takes effect when changed after mount.
116
123
  * @default false
117
124
  */
118
125
  isDisabled?: boolean;
@@ -171,13 +178,14 @@ export interface RichTextEditorProps extends Omit<BaseProps, 'onChange' | 'defau
171
178
  /**
172
179
  * Whether to enable Markdown shortcut typing (e.g. `# ` for a heading,
173
180
  * `- ` for a list). Uses the `transformers` prop (defaults to the standard
174
- * `@lexical/markdown` transformers).
181
+ * `@lexical/markdown` transformers plus GFM tables).
175
182
  * @default true
176
183
  */
177
184
  hasMarkdownShortcuts?: boolean;
178
185
  /**
179
186
  * Markdown transformers — the single source of truth for markdown behaviour.
180
- * Defaults to the standard `@lexical/markdown` `TRANSFORMERS`.
187
+ * Defaults to the standard `@lexical/markdown` `TRANSFORMERS` plus GFM
188
+ * tables. A custom array replaces the default, tables included.
181
189
  *
182
190
  * The same array drives all three markdown operations in Lexical (see the
183
191
  * lexical-playground reference, where one `PLAYGROUND_TRANSFORMERS` array
@@ -1 +1 @@
1
- {"version":3,"file":"RichTextEditor.d.ts","sourceRoot":"","sources":["../src/RichTextEditor.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAQL,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;AASf,OAAO,EAML,KAAK,kBAAkB,EACxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAGlD,OAAO,EAAyB,KAAK,SAAS,EAAC,MAAM,0BAA0B,CAAC;AAchF,OAAO,EAGL,KAAK,WAAW,EACjB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAGnD,OAAO,EASL,KAAK,WAAW,EAChB,KAAK,KAAK,EACV,KAAK,aAAa,EAClB,KAAK,WAAW,EAEjB,MAAM,SAAS,CAAC;AAwJjB,MAAM,MAAM,wBAAwB,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;AAEvE,MAAM,MAAM,kBAAkB,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAEpD,MAAM,WAAW,oBAAoB;IACnC,qCAAqC;IACrC,IAAI,EAAE,wBAAwB,CAAC;IAC/B,oDAAoD;IACpD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB;;;OAGG;IACH,KAAK,EAAE,MAAM,IAAI,C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E,kBAAkB,CAAC;IACnC;;;OAGG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB;;;;OAIG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,uEAAuE;IACvE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,IAAI,CAAC,EAAE,kBAAkB,CAAC;IAC1B;;;;OAIG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;IAC1C;;;;;OAKG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB;;;;OAIG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB;;;;;OAKG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B;;;;;;;;;;;;;;;;;OAiBG;IACH,YAAY,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;IAC1C,yEAAyE;IACzE,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;;;;OAOG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,cAAc,mHAoQzB,CAAC"}
@@ -8,7 +8,8 @@
8
8
  * LexicalExtensionComposer), Field, VisuallyHidden, useInputStatusIcon,
9
9
  * mergeProps, design tokens
10
10
  * @output Exports an accessibly labelled RichTextEditor component with a flush
11
- * top toolbar slot and configurable editable-surface minimum height, RichTextEditorProps,
11
+ * top toolbar slot, configurable editable-surface minimum height, and distinct
12
+ * read-only and disabled states that follow prop changes, RichTextEditorProps,
12
13
  * RichTextEditorStatus, RichTextEditorStatusType, RichTextEditorSize
13
14
  * @position Experimental (richtext) implementation; consumed by the package index.ts and
14
15
  * re-exported from @astryxdesign/richtext. Tested by RichTextEditor.test.tsx.
@@ -46,9 +47,11 @@ import { LinkPlugin } from '@lexical/react/LexicalLinkPlugin';
46
47
  import { TabIndentationPlugin } from '@lexical/react/LexicalTabIndentationPlugin';
47
48
  import { MarkdownShortcutPlugin } from '@lexical/react/LexicalMarkdownShortcutPlugin';
48
49
  import { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin';
49
- import { TRANSFORMERS, $convertToMarkdownString } from '@lexical/markdown';
50
+ import { TablePlugin } from '@lexical/react/LexicalTablePlugin';
50
51
  import { $generateHtmlFromNodes } from '@lexical/html';
51
52
  import { DEFAULT_NODES } from "./editorNodes.js";
53
+ import { $exportMarkdownKeepingSource } from "./markdownSource.js";
54
+ import { DEFAULT_TRANSFORMERS } from "./markdownTable.js";
52
55
  import { BLUR_COMMAND, COMMAND_PRIORITY_LOW, defineExtension, KEY_DOWN_COMMAND, KEY_ESCAPE_COMMAND, KEY_TAB_COMMAND, mergeRegister } from 'lexical';
53
56
 
54
57
  /**
@@ -214,7 +217,7 @@ export const RichTextEditor = /*#__PURE__*/forwardRef(function RichTextEditor({
214
217
  toolbar,
215
218
  plugins,
216
219
  hasMarkdownShortcuts = true,
217
- transformers = TRANSFORMERS,
220
+ transformers = DEFAULT_TRANSFORMERS,
218
221
  hasAutoFocus = false,
219
222
  tabEscapeHint = DEFAULT_TAB_ESCAPE_HINT,
220
223
  maxLength,
@@ -314,7 +317,10 @@ export const RichTextEditor = /*#__PURE__*/forwardRef(function RichTextEditor({
314
317
  ...mergeProps(themeProps('rich-text-editor', {
315
318
  size,
316
319
  status: status?.type ?? null
317
- }), stylex.props(inputWrapperStyles.base, styles.wrapper, (isDisabled || isReadOnly) && inputWrapperStyles.disabled, isDisabled && styles.disabled, status && inputStatusBorderStyles[status.type], status && !isDisabled && !isReadOnly && inputStatusHoverShadowStyles[status.type], status && inputStatusFocusWithinStyles[status.type], xstyle), className, style),
320
+ }), stylex.props(inputWrapperStyles.base, styles.wrapper,
321
+ // Only disabled is dimmed, matching TextArea: a read-only editor
322
+ // keeps full-opacity text and stays keyboard-reachable.
323
+ isDisabled && inputWrapperStyles.disabled, isDisabled && styles.disabled, status && inputStatusBorderStyles[status.type], status && !isDisabled && !isReadOnly && inputStatusHoverShadowStyles[status.type], status && inputStatusFocusWithinStyles[status.type], xstyle), className, style),
318
324
  children: [/*#__PURE__*/_jsxs(LexicalExtensionComposer, {
319
325
  extension: extensionRef.current,
320
326
  contentEditable: null,
@@ -332,6 +338,8 @@ export const RichTextEditor = /*#__PURE__*/forwardRef(function RichTextEditor({
332
338
  ariaDescribedBy: ariaDescribedBy,
333
339
  ariaRequired: isRequired && !isOptional,
334
340
  ariaInvalid: status?.type === 'error',
341
+ isReadOnly: isReadOnly,
342
+ isDisabled: isDisabled,
335
343
  placeholderText: placeholder,
336
344
  placeholderID: placeholderID,
337
345
  minHeight: minHeight,
@@ -339,7 +347,12 @@ export const RichTextEditor = /*#__PURE__*/forwardRef(function RichTextEditor({
339
347
  }),
340
348
  placeholder: null,
341
349
  ErrorBoundary: LexicalErrorBoundary
342
- }), /*#__PURE__*/_jsx(HistoryPlugin, {}), /*#__PURE__*/_jsx(ListPlugin, {}), /*#__PURE__*/_jsx(LinkPlugin, {}), /*#__PURE__*/_jsx(TabIndentationPlugin, {}), /*#__PURE__*/_jsx(TabFocusEscapePlugin, {}), hasMarkdownShortcuts && /*#__PURE__*/_jsx(MarkdownShortcutPlugin, {
350
+ }), /*#__PURE__*/_jsx(HistoryPlugin, {}), /*#__PURE__*/_jsx(ListPlugin, {}), /*#__PURE__*/_jsx(LinkPlugin, {}), /*#__PURE__*/_jsx(TablePlugin, {
351
+ hasCellMerge: false,
352
+ hasCellBackgroundColor: false,
353
+ hasTabHandler: false,
354
+ hasHorizontalScroll: true
355
+ }), /*#__PURE__*/_jsx(TabIndentationPlugin, {}), /*#__PURE__*/_jsx(TabFocusEscapePlugin, {}), hasMarkdownShortcuts && /*#__PURE__*/_jsx(MarkdownShortcutPlugin, {
343
356
  transformers: markdownTransformers
344
357
  }), hasAutoFocus && /*#__PURE__*/_jsx(AutoFocusOnMount, {}), onChange && /*#__PURE__*/_jsx(OnChangePlugin, {
345
358
  onChange: onChange,
@@ -468,6 +481,22 @@ function EditorRefBridge({
468
481
  transformers
469
482
  }) {
470
483
  const [editor] = useLexicalComposerContext();
484
+
485
+ // The extension applies `editable` once, when the composer builds the
486
+ // editor, so a later isReadOnly/isDisabled change would leave
487
+ // contenteditable at its mount value while the wrapper styling and ARIA
488
+ // follow the props. Sync the editor on a prop change only: the mount value
489
+ // is already applied, and this bridge renders after `plugins`, so
490
+ // re-asserting it on mount would undo a plugin that set editability during
491
+ // its own mount.
492
+ const syncedEditableRef = useRef(editable);
493
+ useEffect(() => {
494
+ if (syncedEditableRef.current === editable) {
495
+ return;
496
+ }
497
+ syncedEditableRef.current = editable;
498
+ editor.setEditable(editable);
499
+ }, [editor, editable]);
471
500
  useImperativeHandle(editorRef, () => ({
472
501
  focus: () => {
473
502
  if (!editable) {
@@ -487,11 +516,11 @@ function EditorRefBridge({
487
516
  },
488
517
  getEditorState: () => editor.getEditorState(),
489
518
  getMarkdown: () =>
490
- // $convertToMarkdownString must run inside a read context. Honors the
491
- // same transformers the editor uses for shortcuts, so custom
492
- // transformers round-trip to Markdown. `@lexical/markdown` is a
493
- // subpackage (built dist) — safe, unlike a top-level `lexical` import.
494
- editor.getEditorState().read(() => $convertToMarkdownString(transformers)),
519
+ // Untouched blocks export exactly as imported and changed blocks in
520
+ // canonical form (spec:AST-062). Honors the same transformers the
521
+ // editor uses for shortcuts, so custom transformers round-trip. Reads
522
+ // the state without changing it.
523
+ editor.getEditorState().read(() => $exportMarkdownKeepingSource(transformers)),
495
524
  getHTML: () =>
496
525
  // $generateHtmlFromNodes serializes the whole document (null selection)
497
526
  // to HTML; must run in a read context and requires a DOM.
@@ -541,6 +570,8 @@ function EditorContentEditable({
541
570
  ariaDescribedBy,
542
571
  ariaRequired,
543
572
  ariaInvalid,
573
+ isReadOnly,
574
+ isDisabled,
544
575
  placeholderText,
545
576
  placeholderID,
546
577
  minHeight,
@@ -555,6 +586,20 @@ function EditorContentEditable({
555
586
  'aria-describedby': ariaDescribedBy,
556
587
  'aria-required': ariaRequired ? 'true' : undefined,
557
588
  'aria-invalid': ariaInvalid ? 'true' : undefined,
589
+ // Lexical announces every non-editable surface as aria-readonly and
590
+ // leaves it out of the tab order. Split the two states: read-only stays
591
+ // reachable and is announced read-only; disabled is announced disabled
592
+ // instead. These keys land after Lexical's computed attributes, so the
593
+ // disabled branch's explicit `undefined` removes the wrong read-only
594
+ // announcement. With neither prop set no keys are passed, so a plugin
595
+ // that drives editor.setEditable keeps Lexical's own aria-readonly.
596
+ ...(isDisabled ? {
597
+ 'aria-disabled': 'true',
598
+ 'aria-readonly': undefined
599
+ } : isReadOnly ? {
600
+ tabIndex: 0,
601
+ 'aria-readonly': 'true'
602
+ } : null),
558
603
  ...stylex.props(styles.contentEditable, dynamicStyles.contentEditableMinHeight(minHeight)),
559
604
  ...rest
560
605
  };
@@ -18,22 +18,21 @@
18
18
  * NOTE: Experimental `@astryxdesign/richtext` component (canary). `lexical` and
19
19
  * `@lexical/*` are OPTIONAL peer dependencies — install them to use this.
20
20
  *
21
- * COMPATIBILITY: astryx aims for its RichTextEditor internals to eventually
22
- * back Meta's EPS `EPSRichTextArea` (nest/libs/eps-lexical). EPS's auto-link is
23
- * matcher-driven and applies `target="_blank"` + `rel="noopener noreferrer"` to
24
- * created links (its `NEW_TAB_LINK_ATTRIBUTES`). This plugin uses the same
25
- * matcher shape (`createLinkMatcherWithRegExp` + `attributes`) and the same
26
- * new-tab defaults, so EPS can pass its own richer matcher set (e.g. shortform
27
- * `D123` / `T456` / `S789` intern URLs) through the `matchers` prop without
28
- * changing the contract. EPS ships a hardened fork of the transform itself
29
- * (expanded separators, code-block exclusion) — astryx stays on the OSS
30
- * `AutoLinkPlugin`, and EPS can substitute its own plugin in the same slot.
21
+ * COMPATIBILITY: the plugin is deliberately a thin pass-through so an
22
+ * application with its own link conventions can adopt it without forking. It
23
+ * uses the stock matcher shape (`createLinkMatcherWithRegExp` + `attributes`)
24
+ * and new-tab defaults, so a consumer supplies a richer matcher set — an
25
+ * application-specific identifier or ticket syntax, say — through the
26
+ * `matchers` prop without changing the contract. An application needing a
27
+ * hardened transform (expanded separators, code-block exclusion) substitutes
28
+ * its own plugin in the same slot; astryx stays on the upstream
29
+ * `AutoLinkPlugin`.
31
30
  */
32
31
  import { type LinkMatcher } from '@lexical/react/LexicalAutoLinkPlugin';
33
32
  /**
34
33
  * Attributes written onto every auto-created link so it opens in a new tab.
35
34
  * `rel="noopener noreferrer"` is required whenever `target="_blank"` is set, to
36
- * prevent reverse-tabnabbing. Matches EPS eps-lexical's `NEW_TAB_LINK_ATTRIBUTES`.
35
+ * prevent reverse-tabnabbing.
37
36
  */
38
37
  export declare const NEW_TAB_LINK_ATTRIBUTES: {
39
38
  readonly target: "_blank";
@@ -1 +1 @@
1
- {"version":3,"file":"RichTextEditorAutoLinkPlugin.d.ts","sourceRoot":"","sources":["../src/RichTextEditorAutoLinkPlugin.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAGL,KAAK,WAAW,EACjB,MAAM,sCAAsC,CAAC;AAG9C;;;;GAIG;AACH,eAAO,MAAM,uBAAuB;;;CAG1B,CAAC;AAEX;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,EAAE,WAAW,EAc9C,CAAC;AAEF,MAAM,WAAW,iCAAiC;IAChD;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;CACjE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,4BAA4B,CAAC,EAC3C,QAAgC,EAChC,QAAQ,GACT,EAAE,iCAAiC,+BAEnC;yBALe,4BAA4B"}
1
+ {"version":3,"file":"RichTextEditorAutoLinkPlugin.d.ts","sourceRoot":"","sources":["../src/RichTextEditorAutoLinkPlugin.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAGL,KAAK,WAAW,EACjB,MAAM,sCAAsC,CAAC;AAG9C;;;;GAIG;AACH,eAAO,MAAM,uBAAuB;;;CAG1B,CAAC;AAEX;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,EAAE,WAAW,EAc9C,CAAC;AAEF,MAAM,WAAW,iCAAiC;IAChD;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;CACjE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,4BAA4B,CAAC,EAC3C,QAAgC,EAChC,QAAQ,GACT,EAAE,iCAAiC,+BAEnC;yBALe,4BAA4B"}
@@ -22,16 +22,15 @@
22
22
  * NOTE: Experimental `@astryxdesign/richtext` component (canary). `lexical` and
23
23
  * `@lexical/*` are OPTIONAL peer dependencies — install them to use this.
24
24
  *
25
- * COMPATIBILITY: astryx aims for its RichTextEditor internals to eventually
26
- * back Meta's EPS `EPSRichTextArea` (nest/libs/eps-lexical). EPS's auto-link is
27
- * matcher-driven and applies `target="_blank"` + `rel="noopener noreferrer"` to
28
- * created links (its `NEW_TAB_LINK_ATTRIBUTES`). This plugin uses the same
29
- * matcher shape (`createLinkMatcherWithRegExp` + `attributes`) and the same
30
- * new-tab defaults, so EPS can pass its own richer matcher set (e.g. shortform
31
- * `D123` / `T456` / `S789` intern URLs) through the `matchers` prop without
32
- * changing the contract. EPS ships a hardened fork of the transform itself
33
- * (expanded separators, code-block exclusion) — astryx stays on the OSS
34
- * `AutoLinkPlugin`, and EPS can substitute its own plugin in the same slot.
25
+ * COMPATIBILITY: the plugin is deliberately a thin pass-through so an
26
+ * application with its own link conventions can adopt it without forking. It
27
+ * uses the stock matcher shape (`createLinkMatcherWithRegExp` + `attributes`)
28
+ * and new-tab defaults, so a consumer supplies a richer matcher set — an
29
+ * application-specific identifier or ticket syntax, say — through the
30
+ * `matchers` prop without changing the contract. An application needing a
31
+ * hardened transform (expanded separators, code-block exclusion) substitutes
32
+ * its own plugin in the same slot; astryx stays on the upstream
33
+ * `AutoLinkPlugin`.
35
34
  */
36
35
  import { AutoLinkPlugin, createLinkMatcherWithRegExp } from '@lexical/react/LexicalAutoLinkPlugin';
37
36
  import { URL_MATCHER, EMAIL_MATCHER, sanitizeUrl } from "./linkUtils.js";
@@ -39,7 +38,7 @@ import { URL_MATCHER, EMAIL_MATCHER, sanitizeUrl } from "./linkUtils.js";
39
38
  /**
40
39
  * Attributes written onto every auto-created link so it opens in a new tab.
41
40
  * `rel="noopener noreferrer"` is required whenever `target="_blank"` is set, to
42
- * prevent reverse-tabnabbing. Matches EPS eps-lexical's `NEW_TAB_LINK_ATTRIBUTES`.
41
+ * prevent reverse-tabnabbing.
43
42
  */
44
43
  import { jsx as _jsx } from "react/jsx-runtime";
45
44
  export const NEW_TAB_LINK_ATTRIBUTES = {
@@ -1 +1 @@
1
- {"version":3,"file":"RichTextEditorToolbar.d.ts","sourceRoot":"","sources":["../src/RichTextEditorToolbar.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAML,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAgHf;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;CAgBrB,CAAC;AAwOX,MAAM,WAAW,0BAA0B;IACzC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC,IAAI,GAAG,IAAI,GAAG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AAC;IACnE;;;;;;;OAOG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;;OAIG;IACH,UAAU,CAAC,EAAE,SAAS,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,KAAyB,EACzB,aAAkC,EAClC,IAAW,EACX,OAAc,EACd,YAAY,EACZ,iBAAwB,EACxB,UAAU,GACX,EAAE,0BAA0B,+BA6d5B;yBAree,qBAAqB"}
@@ -431,9 +431,8 @@ export function RichTextEditorToolbar({
431
431
  setActiveFormats(formats);
432
432
 
433
433
  // Link active state — a link is "active" when the caret/selection anchor
434
- // sits inside a LinkNode (or its immediate parent is one). Mirrors the EPS
435
- // eps-lexical toolbar (`$isLinkNode(parent) || $isLinkNode(node)`), which is
436
- // the implementation astryx aims to be swappable with.
434
+ // sits inside a LinkNode (or its immediate parent is one):
435
+ // `$isLinkNode(parent) || $isLinkNode(node)`.
437
436
  const node = selection.anchor.getNode();
438
437
  const parent = node.getParent();
439
438
  const linkNode = $isLinkNode(node) ? node : $isLinkNode(parent) ? parent : null;
@@ -1,13 +1,15 @@
1
1
  /**
2
2
  * @file RichTextView.tsx
3
3
  * @input Uses React, Lexical (lexical + @lexical/react, composed through
4
- * LexicalExtensionComposer), design tokens
4
+ * LexicalExtensionComposer), mergeProps from core utils, design tokens,
5
+ * TableScrollRegionPlugin
5
6
  * @output Exports RichTextView component and RichTextViewProps
6
- * @position Read-only renderer for serialized Lexical editor state; experimental
7
- * (richtext), exported from @astryxdesign/richtext
7
+ * @position Read-only renderer for serialized Lexical editor state, exposed to
8
+ * assistive technology as document content rather than a form field;
9
+ * experimental (richtext), exported from @astryxdesign/richtext
8
10
  *
9
11
  * SYNC: When modified, update these files to stay in sync:
10
- * - /packages/richtext/src/RichTextView.test.tsx
12
+ * - /packages/richtext/src/RichTextEditor.test.tsx
11
13
  * - /packages/richtext/src/index.ts
12
14
  * - /apps/storybook/stories/RichTextEditor.stories.tsx
13
15
  */
@@ -52,6 +54,12 @@ export interface RichTextViewProps extends BaseProps {
52
54
  * A read-only renderer for serialized Lexical content. Renders the same styled
53
55
  * output as {@link RichTextEditor} without any editing affordances.
54
56
  *
57
+ * The output is document content, not a form field: headings, lists and links
58
+ * keep their own roles for assistive technology, and the view takes no label.
59
+ * For a labelled, read-only field, use `<RichTextEditor isReadOnly />`. A
60
+ * table wider than the view scrolls inside a region named "Table" that takes a
61
+ * tab stop while it overflows, as core `Table` does.
62
+ *
55
63
  * @example
56
64
  * ```
57
65
  * import {RichTextView} from '@astryxdesign/richtext';
@@ -1 +1 @@
1
- {"version":3,"file":"RichTextView.d.ts","sourceRoot":"","sources":["../src/RichTextView.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAA8B,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAGlE,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAWlD,OAAO,KAAK,EAEV,KAAK,EACL,WAAW,EAEZ,MAAM,SAAS,CAAC;AAoBjB,MAAM,WAAW,iBAAkB,SAAQ,SAAS;IAClD;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;IAC1C;;;OAGG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACtC;;;;OAIG;IACH,aAAa,CAAC,EAAE,SAAS,CAAC;CAC3B;AAyCD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,KAAK,EACL,OAAO,EACP,SAAyB,EACzB,YAAY,EACZ,aAAoB,EACpB,MAAM,EACN,SAAS,EACT,KAAK,EACL,GAAG,IAAI,EACR,EAAE,iBAAiB,+BAyFnB;yBApGe,YAAY"}
1
+ {"version":3,"file":"RichTextView.d.ts","sourceRoot":"","sources":["../src/RichTextView.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAA8B,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAGlE,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAelD,OAAO,KAAK,EAEV,KAAK,EACL,WAAW,EAEZ,MAAM,SAAS,CAAC;AAkDjB,MAAM,WAAW,iBAAkB,SAAQ,SAAS;IAClD;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;IAC1C;;;OAGG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACtC;;;;OAIG;IACH,aAAa,CAAC,EAAE,SAAS,CAAC;CAC3B;AAyCD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,KAAK,EACL,OAAO,EACP,SAAyB,EACzB,YAAY,EACZ,aAAoB,EACpB,MAAM,EACN,SAAS,EACT,KAAK,EACL,GAAG,IAAI,EACR,EAAE,iBAAiB,+BAgHnB;yBA3He,YAAY"}
@@ -5,28 +5,34 @@
5
5
  /**
6
6
  * @file RichTextView.tsx
7
7
  * @input Uses React, Lexical (lexical + @lexical/react, composed through
8
- * LexicalExtensionComposer), design tokens
8
+ * LexicalExtensionComposer), mergeProps from core utils, design tokens,
9
+ * TableScrollRegionPlugin
9
10
  * @output Exports RichTextView component and RichTextViewProps
10
- * @position Read-only renderer for serialized Lexical editor state; experimental
11
- * (richtext), exported from @astryxdesign/richtext
11
+ * @position Read-only renderer for serialized Lexical editor state, exposed to
12
+ * assistive technology as document content rather than a form field;
13
+ * experimental (richtext), exported from @astryxdesign/richtext
12
14
  *
13
15
  * SYNC: When modified, update these files to stay in sync:
14
- * - /packages/richtext/src/RichTextView.test.tsx
16
+ * - /packages/richtext/src/RichTextEditor.test.tsx
15
17
  * - /packages/richtext/src/index.ts
16
18
  * - /apps/storybook/stories/RichTextEditor.stories.tsx
17
19
  */
18
20
  import { useEffect, useRef, useState } from 'react';
19
21
  import * as stylex from '@stylexjs/stylex';
20
22
  import { sharedEditorTheme } from "./editorTheme.js";
23
+ import { mergeProps } from '@astryxdesign/core/utils';
21
24
  import { LexicalExtensionComposer } from '@lexical/react/LexicalExtensionComposer';
22
25
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
23
26
  import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
24
27
  import { ContentEditable } from '@lexical/react/LexicalContentEditable';
25
28
  import { LexicalErrorBoundary } from '@lexical/react/LexicalErrorBoundary';
29
+ import { TablePlugin } from '@lexical/react/LexicalTablePlugin';
26
30
  import { ListNode, ListItemNode } from '@lexical/list';
27
31
  import { HeadingNode, QuoteNode } from '@lexical/rich-text';
28
32
  import { LinkNode, AutoLinkNode } from '@lexical/link';
29
33
  import { CodeNode, CodeHighlightNode } from '@lexical/code';
34
+ import { TableNode, TableRowNode, TableCellNode } from '@lexical/table';
35
+ import { TableScrollRegionPlugin } from "./TableScrollRegionPlugin.js";
30
36
  import { defineExtension } from 'lexical';
31
37
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
32
38
  const styles = {
@@ -35,7 +41,34 @@ const styles = {
35
41
  $$css: true
36
42
  }
37
43
  };
38
- const DEFAULT_NODES = [HeadingNode, QuoteNode, ListNode, ListItemNode, LinkNode, AutoLinkNode, CodeNode, CodeHighlightNode];
44
+ const DEFAULT_NODES = [HeadingNode, QuoteNode, ListNode, ListItemNode, LinkNode, AutoLinkNode, CodeNode, CodeHighlightNode, TableNode, TableRowNode, TableCellNode];
45
+
46
+ /**
47
+ * Lexical's `ContentEditable` renders `role="textbox"` and widget-only ARIA
48
+ * (`aria-autocomplete`, `aria-readonly`) even when the editor is not editable.
49
+ * A view renders document content, not a form field, so all three are cleared:
50
+ *
51
+ * - A textbox is a widget, so an unnamed one fails axe
52
+ * `aria-input-field-name` — and a view has no name to give, because it is
53
+ * content rather than a labelled input.
54
+ * - The widget role exposes the rendered document to assistive technology
55
+ * as a form field rather than as the content it is.
56
+ * - Widget-only ARIA is invalid without a widget role, so clearing only the
57
+ * role would trade `aria-input-field-name` for `aria-allowed-attr`.
58
+ *
59
+ * `role` must be `null`, not `undefined`: Lexical substitutes its `textbox`
60
+ * default for `undefined`. The ARIA keys reach the element through Lexical's
61
+ * trailing prop spread, which is why `undefined` clears them. A proposed
62
+ * upstream fix (facebook/lexical#9270) would make these overrides no-ops.
63
+ *
64
+ * A caller who wants read-only form-field semantics instead wants
65
+ * `<RichTextEditor isReadOnly />`, which is a labelled field by construction.
66
+ */
67
+ const VIEW_CONTENT_EDITABLE_PROPS = {
68
+ 'aria-autocomplete': undefined,
69
+ 'aria-readonly': undefined,
70
+ role: null
71
+ };
39
72
  /**
40
73
  * Keeps the rendered content in sync with the `value` prop after mount.
41
74
  *
@@ -81,6 +114,12 @@ function SyncValuePlugin({
81
114
  * A read-only renderer for serialized Lexical content. Renders the same styled
82
115
  * output as {@link RichTextEditor} without any editing affordances.
83
116
  *
117
+ * The output is document content, not a form field: headings, lists and links
118
+ * keep their own roles for assistive technology, and the view takes no label.
119
+ * For a labelled, read-only field, use `<RichTextEditor isReadOnly />`. A
120
+ * table wider than the view scrolls inside a region named "Table" that takes a
121
+ * tab stop while it overflows, as core `Table` does.
122
+ *
84
123
  * @example
85
124
  * ```
86
125
  * import {RichTextView} from '@astryxdesign/richtext';
@@ -119,8 +158,26 @@ export function RichTextView({
119
158
  } else {
120
159
  lastValueRef.current = value;
121
160
  }
161
+
162
+ // A parse failure is recorded during render (below, or from Lexical's
163
+ // `onError` while the composer builds the editor) but reported to the
164
+ // consumer only after commit. Updating this component's own state during
165
+ // render is allowed; running a consumer's callback is not — a callback that
166
+ // updates its own component would do so during another component's render,
167
+ // and StrictMode or a discarded concurrent render would repeat it or run it
168
+ // for output that never commits. This Effect synchronizes the consumer's
169
+ // `onParseError`, reporting each distinct failure exactly once.
170
+ const pendingErrorRef = useRef(null);
171
+ const reportedErrorRef = useRef(null);
172
+ useEffect(() => {
173
+ const error = pendingErrorRef.current;
174
+ if (error !== null && error !== reportedErrorRef.current) {
175
+ reportedErrorRef.current = error;
176
+ onParseError?.(error);
177
+ }
178
+ });
122
179
  const handleError = error => {
123
- onParseError?.(error);
180
+ pendingErrorRef.current = error;
124
181
  setHasError(true);
125
182
  };
126
183
 
@@ -141,9 +198,7 @@ export function RichTextView({
141
198
  // with the corrected `value`.
142
199
  extensionRef.current = null;
143
200
  return /*#__PURE__*/_jsx("div", {
144
- ...stylex.props(styles.root, xstyle),
145
- className: className,
146
- style: style,
201
+ ...mergeProps(stylex.props(styles.root, xstyle), className, style),
147
202
  ...rest,
148
203
  children: errorFallback
149
204
  });
@@ -162,17 +217,22 @@ export function RichTextView({
162
217
  });
163
218
  }
164
219
  return /*#__PURE__*/_jsx("div", {
165
- ...stylex.props(styles.root, xstyle),
166
- className: className,
167
- style: style,
220
+ ...mergeProps(stylex.props(styles.root, xstyle), className, style),
168
221
  ...rest,
169
222
  children: /*#__PURE__*/_jsxs(LexicalExtensionComposer, {
170
223
  extension: extensionRef.current,
171
224
  contentEditable: null,
172
225
  children: [/*#__PURE__*/_jsx(SyncValuePlugin, {
173
226
  value: value
174
- }), /*#__PURE__*/_jsx(RichTextPlugin, {
175
- contentEditable: /*#__PURE__*/_jsx(ContentEditable, {}),
227
+ }), /*#__PURE__*/_jsx(TablePlugin, {
228
+ hasCellMerge: false,
229
+ hasCellBackgroundColor: false,
230
+ hasTabHandler: false,
231
+ hasHorizontalScroll: true
232
+ }), /*#__PURE__*/_jsx(TableScrollRegionPlugin, {}), /*#__PURE__*/_jsx(RichTextPlugin, {
233
+ contentEditable: /*#__PURE__*/_jsx(ContentEditable, {
234
+ ...VIEW_CONTENT_EDITABLE_PROPS
235
+ }),
176
236
  placeholder: null,
177
237
  ErrorBoundary: LexicalErrorBoundary
178
238
  }), plugins]
@@ -0,0 +1,9 @@
1
+ /**
2
+ * A read-only view has no caret, so nothing inside a wide table can scroll it
3
+ * from the keyboard. Like core Table's scroll region, each table's wrapper is
4
+ * a group named "Table" that takes a tab stop only while the table overflows
5
+ * it; a table that fits adds no stop. The tab stop is explicit, so browsers
6
+ * that do not make scroll containers focusable on their own still reach it.
7
+ */
8
+ export declare function TableScrollRegionPlugin(): null;
9
+ //# sourceMappingURL=TableScrollRegionPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TableScrollRegionPlugin.d.ts","sourceRoot":"","sources":["../src/TableScrollRegionPlugin.tsx"],"names":[],"mappings":"AAmCA;;;;;;GAMG;AACH,wBAAgB,uBAAuB,IAAI,IAAI,CAgE9C"}
@@ -0,0 +1,95 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ /**
6
+ * @file TableScrollRegionPlugin.tsx
7
+ * @input Lexical's TableNode mutations, the scroll wrapper that TablePlugin's
8
+ * horizontal-scroll mode renders around each table, and core's translator
9
+ * for the region's name.
10
+ * @output TableScrollRegionPlugin: gives each table's scroll wrapper the
11
+ * semantics of core Table's scroll region.
12
+ * @position Internal to @astryxdesign/richtext; rendered by RichTextView only.
13
+ * The editor needs none of this: its caret scrolls a wide table, and a tab
14
+ * stop inside the editable surface would break Escape-then-Tab.
15
+ */
16
+ import { useEffect } from 'react';
17
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
18
+ import { TableNode } from '@lexical/table';
19
+ import { useTranslator } from '@astryxdesign/core/i18n';
20
+ /** A tab stop only while the table is wider than its wrapper. */
21
+ function syncTabStop(wrapper) {
22
+ if (wrapper.scrollWidth > wrapper.clientWidth) {
23
+ wrapper.tabIndex = 0;
24
+ } else {
25
+ wrapper.removeAttribute('tabindex');
26
+ }
27
+ }
28
+
29
+ /**
30
+ * A read-only view has no caret, so nothing inside a wide table can scroll it
31
+ * from the keyboard. Like core Table's scroll region, each table's wrapper is
32
+ * a group named "Table" that takes a tab stop only while the table overflows
33
+ * it; a table that fits adds no stop. The tab stop is explicit, so browsers
34
+ * that do not make scroll containers focusable on their own still reach it.
35
+ */
36
+ export function TableScrollRegionPlugin() {
37
+ const [editor] = useLexicalComposerContext();
38
+ const t = useTranslator();
39
+ const label = t('@astryx.table.label');
40
+ useEffect(() => {
41
+ const regions = new Map();
42
+ const release = key => {
43
+ regions.get(key)?.observer?.disconnect();
44
+ regions.delete(key);
45
+ };
46
+ const track = key => {
47
+ // With horizontal scroll active, a table node's DOM is its wrapper.
48
+ const wrapper = editor.getElementByKey(key);
49
+ if (!(wrapper instanceof HTMLDivElement)) {
50
+ release(key);
51
+ return;
52
+ }
53
+ if (regions.get(key)?.wrapper === wrapper) {
54
+ syncTabStop(wrapper);
55
+ return;
56
+ }
57
+ release(key);
58
+ wrapper.setAttribute('role', 'group');
59
+ wrapper.setAttribute('aria-label', label);
60
+ let observer = null;
61
+ if (typeof ResizeObserver !== 'undefined') {
62
+ observer = new ResizeObserver(() => syncTabStop(wrapper));
63
+ // The wrapper resizes with its container, the table with its content.
64
+ observer.observe(wrapper);
65
+ const table = wrapper.querySelector(':scope > table');
66
+ if (table != null) {
67
+ observer.observe(table);
68
+ }
69
+ }
70
+ regions.set(key, {
71
+ wrapper,
72
+ observer
73
+ });
74
+ syncTabStop(wrapper);
75
+ };
76
+ const unregister = editor.registerMutationListener(TableNode, mutations => {
77
+ for (const [key, mutation] of mutations) {
78
+ if (mutation === 'destroyed') {
79
+ release(key);
80
+ } else {
81
+ track(key);
82
+ }
83
+ }
84
+ }, {
85
+ skipInitialization: false
86
+ });
87
+ return () => {
88
+ unregister();
89
+ for (const key of [...regions.keys()]) {
90
+ release(key);
91
+ }
92
+ };
93
+ }, [editor, label]);
94
+ return null;
95
+ }