@astryxdesign/richtext 0.6.5-canary.c8d8a1d → 0.6.5-canary.ca77025
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/dist/RichTextEditor.d.ts +4 -2
- package/dist/RichTextEditor.d.ts.map +1 -1
- package/dist/RichTextEditor.js +11 -7
- package/dist/RichTextView.d.ts +5 -2
- package/dist/RichTextView.d.ts.map +1 -1
- package/dist/RichTextView.js +10 -9
- package/dist/TableColumnFloorPlugin.d.ts +12 -0
- package/dist/TableColumnFloorPlugin.d.ts.map +1 -0
- package/dist/TableColumnFloorPlugin.js +84 -0
- package/dist/TableScrollRegionPlugin.d.ts +9 -0
- package/dist/TableScrollRegionPlugin.d.ts.map +1 -0
- package/dist/TableScrollRegionPlugin.js +95 -0
- package/dist/editorNodes.d.ts.map +1 -1
- package/dist/editorNodes.js +2 -1
- package/dist/editorTheme.d.ts.map +1 -1
- package/dist/editorTheme.js +239 -59
- package/dist/markdownHardLineBreak.d.ts +22 -0
- package/dist/markdownHardLineBreak.d.ts.map +1 -0
- package/dist/markdownHardLineBreak.js +38 -0
- package/dist/markdownListExport.d.ts +3 -0
- package/dist/markdownListExport.d.ts.map +1 -0
- package/dist/markdownListExport.js +60 -0
- package/dist/markdownListIndentation.d.ts +8 -0
- package/dist/markdownListIndentation.d.ts.map +1 -0
- package/dist/markdownListIndentation.js +85 -0
- package/dist/markdownSerializers.d.ts.map +1 -1
- package/dist/markdownSerializers.js +5 -9
- package/dist/markdownSource.d.ts +79 -0
- package/dist/markdownSource.d.ts.map +1 -0
- package/dist/markdownSource.js +570 -0
- package/dist/markdownTable.d.ts +4 -2
- package/dist/markdownTable.d.ts.map +1 -1
- package/dist/markdownTable.js +9 -3
- package/dist/markdownThematicBreak.d.ts +3 -0
- package/dist/markdownThematicBreak.d.ts.map +1 -0
- package/dist/markdownThematicBreak.js +55 -0
- package/dist/richtext.css +53 -15
- package/package.json +9 -4
- package/src/RichTextEditor.doc.mjs +9 -4
- package/src/RichTextEditor.tsx +16 -8
- package/src/RichTextView.tsx +11 -21
- package/src/TableColumnFloorPlugin.test.tsx +49 -0
- package/src/TableColumnFloorPlugin.tsx +99 -0
- package/src/TableScrollRegionPlugin.test.tsx +138 -0
- package/src/TableScrollRegionPlugin.tsx +107 -0
- package/src/__tests__/MarkdownParitySandbox.a11y.chromium.spec.ts +456 -1
- package/src/editorNodes.ts +2 -0
- package/src/editorTheme.ts +281 -56
- package/src/markdownHardLineBreak.ts +47 -0
- package/src/markdownListExport.ts +77 -0
- package/src/markdownListIndentation.test.ts +235 -0
- package/src/markdownListIndentation.ts +89 -0
- package/src/markdownSerializers.ts +9 -14
- package/src/markdownSource.test.tsx +638 -0
- package/src/markdownSource.ts +738 -0
- package/src/markdownTable.test.tsx +20 -3
- package/src/markdownTable.ts +10 -2
- package/src/markdownThematicBreak.test.tsx +185 -0
- package/src/markdownThematicBreak.ts +66 -0
package/dist/RichTextEditor.d.ts
CHANGED
|
@@ -57,8 +57,10 @@ export interface RichTextEditorRef {
|
|
|
57
57
|
/**
|
|
58
58
|
* Serialize the current content to a Markdown string, using the same
|
|
59
59
|
* `transformers` the editor is configured with (so custom transformers
|
|
60
|
-
* layered in via the `transformers` prop are honored).
|
|
61
|
-
*
|
|
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.
|
|
62
64
|
*/
|
|
63
65
|
getMarkdown: () => string;
|
|
64
66
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextEditor.d.ts","sourceRoot":"","sources":["../src/RichTextEditor.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAQL,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;AASf,OAAO,EAML,KAAK,kBAAkB,E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AAS,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,mHAuQzB,CAAC"}
|
package/dist/RichTextEditor.js
CHANGED
|
@@ -48,9 +48,11 @@ import { TabIndentationPlugin } from '@lexical/react/LexicalTabIndentationPlugin
|
|
|
48
48
|
import { MarkdownShortcutPlugin } from '@lexical/react/LexicalMarkdownShortcutPlugin';
|
|
49
49
|
import { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin';
|
|
50
50
|
import { TablePlugin } from '@lexical/react/LexicalTablePlugin';
|
|
51
|
-
import {
|
|
51
|
+
import { HorizontalRuleExtension } from '@lexical/extension';
|
|
52
|
+
import { TableColumnFloorPlugin } from "./TableColumnFloorPlugin.js";
|
|
52
53
|
import { $generateHtmlFromNodes } from '@lexical/html';
|
|
53
54
|
import { DEFAULT_NODES } from "./editorNodes.js";
|
|
55
|
+
import { $exportMarkdownKeepingSource } from "./markdownSource.js";
|
|
54
56
|
import { DEFAULT_TRANSFORMERS } from "./markdownTable.js";
|
|
55
57
|
import { BLUR_COMMAND, COMMAND_PRIORITY_LOW, defineExtension, KEY_DOWN_COMMAND, KEY_ESCAPE_COMMAND, KEY_TAB_COMMAND, mergeRegister } from 'lexical';
|
|
56
58
|
|
|
@@ -271,6 +273,8 @@ export const RichTextEditor = /*#__PURE__*/forwardRef(function RichTextEditor({
|
|
|
271
273
|
theme: themeRef.current,
|
|
272
274
|
editable,
|
|
273
275
|
nodes: nodes ? [...DEFAULT_NODES, ...nodes] : [...DEFAULT_NODES],
|
|
276
|
+
// Horizontal rules select on click and show their selection.
|
|
277
|
+
dependencies: [HorizontalRuleExtension],
|
|
274
278
|
// `undefined` (not `null`) leaves Lexical's default initializer in place,
|
|
275
279
|
// which seeds the empty document with one paragraph — what
|
|
276
280
|
// LexicalComposer did when no `editorState` was given. `null` would mean
|
|
@@ -352,7 +356,7 @@ export const RichTextEditor = /*#__PURE__*/forwardRef(function RichTextEditor({
|
|
|
352
356
|
hasCellBackgroundColor: false,
|
|
353
357
|
hasTabHandler: false,
|
|
354
358
|
hasHorizontalScroll: true
|
|
355
|
-
}), /*#__PURE__*/_jsx(TabIndentationPlugin, {}), /*#__PURE__*/_jsx(TabFocusEscapePlugin, {}), hasMarkdownShortcuts && /*#__PURE__*/_jsx(MarkdownShortcutPlugin, {
|
|
359
|
+
}), /*#__PURE__*/_jsx(TableColumnFloorPlugin, {}), /*#__PURE__*/_jsx(TabIndentationPlugin, {}), /*#__PURE__*/_jsx(TabFocusEscapePlugin, {}), hasMarkdownShortcuts && /*#__PURE__*/_jsx(MarkdownShortcutPlugin, {
|
|
356
360
|
transformers: markdownTransformers
|
|
357
361
|
}), hasAutoFocus && /*#__PURE__*/_jsx(AutoFocusOnMount, {}), onChange && /*#__PURE__*/_jsx(OnChangePlugin, {
|
|
358
362
|
onChange: onChange,
|
|
@@ -516,11 +520,11 @@ function EditorRefBridge({
|
|
|
516
520
|
},
|
|
517
521
|
getEditorState: () => editor.getEditorState(),
|
|
518
522
|
getMarkdown: () =>
|
|
519
|
-
//
|
|
520
|
-
//
|
|
521
|
-
// transformers round-trip
|
|
522
|
-
//
|
|
523
|
-
editor.getEditorState().read(() => $
|
|
523
|
+
// Untouched blocks export exactly as imported and changed blocks in
|
|
524
|
+
// canonical form (spec:AST-062). Honors the same transformers the
|
|
525
|
+
// editor uses for shortcuts, so custom transformers round-trip. Reads
|
|
526
|
+
// the state without changing it.
|
|
527
|
+
editor.getEditorState().read(() => $exportMarkdownKeepingSource(transformers)),
|
|
524
528
|
getHTML: () =>
|
|
525
529
|
// $generateHtmlFromNodes serializes the whole document (null selection)
|
|
526
530
|
// to HTML; must run in a read context and requires a DOM.
|
package/dist/RichTextView.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file RichTextView.tsx
|
|
3
3
|
* @input Uses React, Lexical (lexical + @lexical/react, composed through
|
|
4
|
-
* LexicalExtensionComposer), mergeProps from core utils, design tokens
|
|
4
|
+
* LexicalExtensionComposer), mergeProps from core utils, design tokens,
|
|
5
|
+
* TableScrollRegionPlugin
|
|
5
6
|
* @output Exports RichTextView component and RichTextViewProps
|
|
6
7
|
* @position Read-only renderer for serialized Lexical editor state, exposed to
|
|
7
8
|
* assistive technology as document content rather than a form field;
|
|
@@ -55,7 +56,9 @@ export interface RichTextViewProps extends BaseProps {
|
|
|
55
56
|
*
|
|
56
57
|
* The output is document content, not a form field: headings, lists and links
|
|
57
58
|
* keep their own roles for assistive technology, and the view takes no label.
|
|
58
|
-
* For a labelled, read-only field, use `<RichTextEditor isReadOnly />`.
|
|
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.
|
|
59
62
|
*
|
|
60
63
|
* @example
|
|
61
64
|
* ```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextView.d.ts","sourceRoot":"","sources":["../src/RichTextView.tsx"],"names":[],"mappings":"AAIA
|
|
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;AAWlD,OAAO,KAAK,EAEV,KAAK,EACL,WAAW,EAEZ,MAAM,SAAS,CAAC;AAsCjB,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,+BAiHnB;yBA5He,YAAY"}
|
package/dist/RichTextView.js
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @file RichTextView.tsx
|
|
7
7
|
* @input Uses React, Lexical (lexical + @lexical/react, composed through
|
|
8
|
-
* LexicalExtensionComposer), mergeProps from core utils, design tokens
|
|
8
|
+
* LexicalExtensionComposer), mergeProps from core utils, design tokens,
|
|
9
|
+
* TableScrollRegionPlugin
|
|
9
10
|
* @output Exports RichTextView component and RichTextViewProps
|
|
10
11
|
* @position Read-only renderer for serialized Lexical editor state, exposed to
|
|
11
12
|
* assistive technology as document content rather than a form field;
|
|
@@ -26,12 +27,11 @@ import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
|
|
|
26
27
|
import { ContentEditable } from '@lexical/react/LexicalContentEditable';
|
|
27
28
|
import { LexicalErrorBoundary } from '@lexical/react/LexicalErrorBoundary';
|
|
28
29
|
import { TablePlugin } from '@lexical/react/LexicalTablePlugin';
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import { LinkNode, AutoLinkNode } from '@lexical/link';
|
|
32
|
-
import { CodeNode, CodeHighlightNode } from '@lexical/code';
|
|
33
|
-
import { TableNode, TableRowNode, TableCellNode } from '@lexical/table';
|
|
30
|
+
import { TableScrollRegionPlugin } from "./TableScrollRegionPlugin.js";
|
|
31
|
+
import { TableColumnFloorPlugin } from "./TableColumnFloorPlugin.js";
|
|
34
32
|
import { defineExtension } from 'lexical';
|
|
33
|
+
// The same node set as the editor, so anything it writes renders here.
|
|
34
|
+
import { DEFAULT_NODES } from "./editorNodes.js";
|
|
35
35
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
36
36
|
const styles = {
|
|
37
37
|
root: {
|
|
@@ -39,7 +39,6 @@ const styles = {
|
|
|
39
39
|
$$css: true
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
|
-
const DEFAULT_NODES = [HeadingNode, QuoteNode, ListNode, ListItemNode, LinkNode, AutoLinkNode, CodeNode, CodeHighlightNode, TableNode, TableRowNode, TableCellNode];
|
|
43
42
|
|
|
44
43
|
/**
|
|
45
44
|
* Lexical's `ContentEditable` renders `role="textbox"` and widget-only ARIA
|
|
@@ -114,7 +113,9 @@ function SyncValuePlugin({
|
|
|
114
113
|
*
|
|
115
114
|
* The output is document content, not a form field: headings, lists and links
|
|
116
115
|
* keep their own roles for assistive technology, and the view takes no label.
|
|
117
|
-
* For a labelled, read-only field, use `<RichTextEditor isReadOnly />`.
|
|
116
|
+
* For a labelled, read-only field, use `<RichTextEditor isReadOnly />`. A
|
|
117
|
+
* table wider than the view scrolls inside a region named "Table" that takes a
|
|
118
|
+
* tab stop while it overflows, as core `Table` does.
|
|
118
119
|
*
|
|
119
120
|
* @example
|
|
120
121
|
* ```
|
|
@@ -225,7 +226,7 @@ export function RichTextView({
|
|
|
225
226
|
hasCellBackgroundColor: false,
|
|
226
227
|
hasTabHandler: false,
|
|
227
228
|
hasHorizontalScroll: true
|
|
228
|
-
}), /*#__PURE__*/_jsx(RichTextPlugin, {
|
|
229
|
+
}), /*#__PURE__*/_jsx(TableScrollRegionPlugin, {}), /*#__PURE__*/_jsx(TableColumnFloorPlugin, {}), /*#__PURE__*/_jsx(RichTextPlugin, {
|
|
229
230
|
contentEditable: /*#__PURE__*/_jsx(ContentEditable, {
|
|
230
231
|
...VIEW_CONTENT_EDITABLE_PROPS
|
|
231
232
|
}),
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Each column's floor in `ch`, from the text length of every cell, header row
|
|
3
|
+
* first: the longest cell wraps to about two lines, the header reads on one
|
|
4
|
+
* line up to its cap, and every floor stays between the bounds.
|
|
5
|
+
*/
|
|
6
|
+
export declare function tableColumnFloors(rows: ReadonlyArray<ReadonlyArray<number>>): Array<number>;
|
|
7
|
+
/**
|
|
8
|
+
* Sets each top-level table's header cells to their column's floor after
|
|
9
|
+
* every update, so the floors follow edits.
|
|
10
|
+
*/
|
|
11
|
+
export declare function TableColumnFloorPlugin(): null;
|
|
12
|
+
//# sourceMappingURL=TableColumnFloorPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableColumnFloorPlugin.d.ts","sourceRoot":"","sources":["../src/TableColumnFloorPlugin.tsx"],"names":[],"mappings":"AA8BA;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,GACzC,KAAK,CAAC,MAAM,CAAC,CAiBf;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,IAAI,CAsC7C"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @file TableColumnFloorPlugin.tsx
|
|
7
|
+
* @input Uses @lexical/react (composer context), @lexical/table, and lexical.
|
|
8
|
+
* @output Exports TableColumnFloorPlugin, which gives each table column core
|
|
9
|
+
* Markdown's readable width floor, and tableColumnFloors, the rule itself.
|
|
10
|
+
* @position Rendered by RichTextEditor and RichTextView. Matches core
|
|
11
|
+
* Markdown's table column floors (spec:AST-061 FR4): automatic table layout
|
|
12
|
+
* already keeps every column at least as wide as its longest word, but a
|
|
13
|
+
* prose column's longest word is short, so a narrow table still wraps one
|
|
14
|
+
* word per line. The floor lets a column's longest cell wrap to about two
|
|
15
|
+
* lines instead, keeps a header label on one line up to a cap, and stays
|
|
16
|
+
* bounded so a table of short columns still fits; a wider table scrolls
|
|
17
|
+
* inside its wrapper. The floors are `ch` on content-box cells, so they
|
|
18
|
+
* follow the reader's font size and cell padding does not eat into them.
|
|
19
|
+
*/
|
|
20
|
+
import { useEffect } from 'react';
|
|
21
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
22
|
+
import { $isTableCellNode, $isTableNode, $isTableRowNode } from '@lexical/table';
|
|
23
|
+
import { $getRoot } from 'lexical';
|
|
24
|
+
const TABLE_COLUMN_MIN_CH = 4;
|
|
25
|
+
const TABLE_COLUMN_MAX_CH = 24;
|
|
26
|
+
const TABLE_COLUMN_TARGET_LINES = 2;
|
|
27
|
+
const TABLE_HEADER_ONE_LINE_MAX_CH = 20;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Each column's floor in `ch`, from the text length of every cell, header row
|
|
31
|
+
* first: the longest cell wraps to about two lines, the header reads on one
|
|
32
|
+
* line up to its cap, and every floor stays between the bounds.
|
|
33
|
+
*/
|
|
34
|
+
export function tableColumnFloors(rows) {
|
|
35
|
+
const [header, ...body] = rows;
|
|
36
|
+
if (header == null) {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
return header.map((headerLength, column) => {
|
|
40
|
+
const longest = Math.max(headerLength, ...body.map(row => row[column] ?? 0));
|
|
41
|
+
const bodyFloor = Math.ceil(longest / TABLE_COLUMN_TARGET_LINES);
|
|
42
|
+
const headerFloor = Math.min(headerLength, TABLE_HEADER_ONE_LINE_MAX_CH);
|
|
43
|
+
return Math.min(TABLE_COLUMN_MAX_CH, Math.max(TABLE_COLUMN_MIN_CH, bodyFloor, headerFloor));
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Sets each top-level table's header cells to their column's floor after
|
|
49
|
+
* every update, so the floors follow edits.
|
|
50
|
+
*/
|
|
51
|
+
export function TableColumnFloorPlugin() {
|
|
52
|
+
const [editor] = useLexicalComposerContext();
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
let frame = 0;
|
|
55
|
+
const apply = () => {
|
|
56
|
+
frame = 0;
|
|
57
|
+
editor.getEditorState().read(() => {
|
|
58
|
+
for (const table of $getRoot().getChildren().filter($isTableNode)) {
|
|
59
|
+
const rows = table.getChildren().filter($isTableRowNode).map(row => row.getChildren().filter($isTableCellNode));
|
|
60
|
+
const floors = tableColumnFloors(rows.map(cells => cells.map(cell => cell.getTextContentSize())));
|
|
61
|
+
rows[0]?.forEach((cell, column) => {
|
|
62
|
+
const element = editor.getElementByKey(cell.getKey());
|
|
63
|
+
const floor = `${floors[column]}ch`;
|
|
64
|
+
if (element != null && element.style.minWidth !== floor) {
|
|
65
|
+
element.style.minWidth = floor;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
const schedule = () => {
|
|
72
|
+
if (frame === 0) {
|
|
73
|
+
frame = requestAnimationFrame(apply);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const unregister = editor.registerUpdateListener(schedule);
|
|
77
|
+
schedule();
|
|
78
|
+
return () => {
|
|
79
|
+
cancelAnimationFrame(frame);
|
|
80
|
+
unregister();
|
|
81
|
+
};
|
|
82
|
+
}, [editor]);
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editorNodes.d.ts","sourceRoot":"","sources":["../src/editorNodes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"editorNodes.d.ts","sourceRoot":"","sources":["../src/editorNodes.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAC,KAAK,EAAE,WAAW,EAAC,MAAM,SAAS,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,CAa3D,CAAC"}
|
package/dist/editorNodes.js
CHANGED
|
@@ -16,9 +16,10 @@ import { HeadingNode, QuoteNode } from '@lexical/rich-text';
|
|
|
16
16
|
import { LinkNode, AutoLinkNode } from '@lexical/link';
|
|
17
17
|
import { CodeNode, CodeHighlightNode } from '@lexical/code';
|
|
18
18
|
import { TableNode, TableRowNode, TableCellNode } from '@lexical/table';
|
|
19
|
+
import { HorizontalRuleNode } from '@lexical/extension';
|
|
19
20
|
/**
|
|
20
21
|
* The default OSS node set registered with the editor: headings, quotes,
|
|
21
22
|
* lists, links, code, and tables. Extend via the `nodes` prop / option rather
|
|
22
23
|
* than editing this list.
|
|
23
24
|
*/
|
|
24
|
-
export const DEFAULT_NODES = [HeadingNode, QuoteNode, ListNode, ListItemNode, LinkNode, AutoLinkNode, CodeNode, CodeHighlightNode, TableNode, TableRowNode, TableCellNode];
|
|
25
|
+
export const DEFAULT_NODES = [HeadingNode, QuoteNode, ListNode, ListItemNode, LinkNode, AutoLinkNode, CodeNode, CodeHighlightNode, TableNode, TableRowNode, TableCellNode, HorizontalRuleNode];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editorTheme.d.ts","sourceRoot":"","sources":["../src/editorTheme.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"editorTheme.d.ts","sourceRoot":"","sources":["../src/editorTheme.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,SAAS,CAAC;AA4VhD;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,kBAAkB,CAqEtD"}
|