@astryxdesign/richtext 0.6.5-canary.fcd44d1 → 0.6.6-canary.0e97faa
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/CodeBlockHeaderPlugin.d.ts +7 -0
- package/dist/CodeBlockHeaderPlugin.d.ts.map +1 -0
- package/dist/CodeBlockHeaderPlugin.js +196 -0
- package/dist/CodeSyntaxPlugin.d.ts +12 -0
- package/dist/CodeSyntaxPlugin.d.ts.map +1 -0
- package/dist/CodeSyntaxPlugin.js +154 -0
- package/dist/MarkdownExtensionsPlugin.d.ts +17 -0
- package/dist/MarkdownExtensionsPlugin.d.ts.map +1 -0
- package/dist/MarkdownExtensionsPlugin.js +185 -0
- package/dist/RichTextEditor.d.ts +17 -4
- package/dist/RichTextEditor.d.ts.map +1 -1
- package/dist/RichTextEditor.js +32 -9
- package/dist/RichTextEditorToolbar.d.ts.map +1 -1
- package/dist/RichTextEditorToolbar.js +11 -3
- package/dist/RichTextView.d.ts +16 -3
- package/dist/RichTextView.d.ts.map +1 -1
- package/dist/RichTextView.js +55 -15
- 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/TaskCheckboxPlugin.d.ts +7 -0
- package/dist/TaskCheckboxPlugin.d.ts.map +1 -0
- package/dist/TaskCheckboxPlugin.js +193 -0
- package/dist/editorNodes.d.ts +2 -2
- package/dist/editorNodes.d.ts.map +1 -1
- package/dist/editorNodes.js +10 -3
- package/dist/editorTheme.d.ts.map +1 -1
- package/dist/editorTheme.js +257 -53
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/markdown.d.ts +17 -0
- package/dist/markdown.d.ts.map +1 -0
- package/dist/markdown.js +17 -0
- package/dist/markdownCharacterReferences.d.ts +112 -0
- package/dist/markdownCharacterReferences.d.ts.map +1 -0
- package/dist/markdownCharacterReferences.js +975 -0
- package/dist/markdownCodeFence.d.ts +4 -0
- package/dist/markdownCodeFence.d.ts.map +1 -0
- package/dist/markdownCodeFence.js +167 -0
- package/dist/markdownExtensionNode.d.ts +88 -0
- package/dist/markdownExtensionNode.d.ts.map +1 -0
- package/dist/markdownExtensionNode.js +244 -0
- package/dist/markdownExtensions.d.ts +115 -0
- package/dist/markdownExtensions.d.ts.map +1 -0
- package/dist/markdownExtensions.js +392 -0
- package/dist/markdownHardLineBreak.d.ts +22 -0
- package/dist/markdownHardLineBreak.d.ts.map +1 -0
- package/dist/markdownHardLineBreak.js +38 -0
- package/dist/markdownHeading.d.ts +20 -0
- package/dist/markdownHeading.d.ts.map +1 -0
- package/dist/markdownHeading.js +30 -0
- package/dist/markdownLink.d.ts +5 -0
- package/dist/markdownLink.d.ts.map +1 -0
- package/dist/markdownLink.js +88 -0
- package/dist/markdownListExport.d.ts +3 -0
- package/dist/markdownListExport.d.ts.map +1 -0
- package/dist/markdownListExport.js +65 -0
- package/dist/markdownListIndentation.d.ts +8 -0
- package/dist/markdownListIndentation.d.ts.map +1 -0
- package/dist/markdownListIndentation.js +101 -0
- package/dist/markdownOrderedList.d.ts +3 -0
- package/dist/markdownOrderedList.d.ts.map +1 -0
- package/dist/markdownOrderedList.js +51 -0
- package/dist/markdownQuote.d.ts +22 -0
- package/dist/markdownQuote.d.ts.map +1 -0
- package/dist/markdownQuote.js +32 -0
- package/dist/markdownSerializers.d.ts +12 -3
- package/dist/markdownSerializers.d.ts.map +1 -1
- package/dist/markdownSerializers.js +14 -14
- package/dist/markdownSource.d.ts +71 -0
- package/dist/markdownSource.d.ts.map +1 -0
- package/dist/markdownSource.js +769 -0
- package/dist/markdownSpaceRuns.d.ts +24 -0
- package/dist/markdownSpaceRuns.d.ts.map +1 -0
- package/dist/markdownSpaceRuns.js +147 -0
- package/dist/markdownTable.d.ts +35 -0
- package/dist/markdownTable.d.ts.map +1 -0
- package/dist/markdownTable.js +227 -0
- package/dist/markdownTaskList.d.ts +48 -0
- package/dist/markdownTaskList.d.ts.map +1 -0
- package/dist/markdownTaskList.js +166 -0
- 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 +95 -18
- package/dist/textSemantics.d.ts +3 -0
- package/dist/textSemantics.d.ts.map +1 -0
- package/dist/textSemantics.js +87 -0
- package/package.json +19 -4
- package/src/CodeBlockHeaderPlugin.test.tsx +100 -0
- package/src/CodeBlockHeaderPlugin.tsx +262 -0
- package/src/CodeSyntaxPlugin.test.tsx +40 -0
- package/src/CodeSyntaxPlugin.tsx +193 -0
- package/src/MarkdownExtensionsPlugin.test.tsx +279 -0
- package/src/MarkdownExtensionsPlugin.tsx +289 -0
- package/src/RichTextEditor.doc.mjs +35 -5
- package/src/RichTextEditor.test.tsx +122 -3
- package/src/RichTextEditor.tsx +66 -16
- package/src/RichTextEditorToolbar.tsx +15 -2
- package/src/RichTextView.tsx +77 -24
- 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/TaskCheckboxPlugin.tsx +246 -0
- package/src/__tests__/MarkdownParitySandbox.a11y.chromium.spec.ts +1486 -2
- package/src/__tests__/MarkdownPlugins.a11y.chromium.spec.ts +482 -0
- package/src/__tests__/MarkdownPluginsImportExport.a11y.chromium.spec.ts +117 -0
- package/src/doc-mjs.d.ts +23 -0
- package/src/editorNodes.ts +12 -2
- package/src/editorTheme.ts +373 -88
- package/src/index.ts +5 -0
- package/src/markdown.ts +25 -0
- package/src/markdownAngleCodeSpans.test.ts +92 -0
- package/src/markdownAngleDestinations.test.ts +303 -0
- package/src/markdownCharacterReferences.test.ts +202 -0
- package/src/markdownCharacterReferences.ts +990 -0
- package/src/markdownCodeFence.test.ts +195 -0
- package/src/markdownCodeFence.ts +216 -0
- package/src/markdownCodeSpans.test.ts +399 -0
- package/src/markdownEscapes.test.ts +234 -0
- package/src/markdownExtensionNode.ts +332 -0
- package/src/markdownExtensionSelection.test.ts +102 -0
- package/src/markdownExtensions.test.ts +765 -0
- package/src/markdownExtensions.ts +496 -0
- package/src/markdownHardLineBreak.ts +47 -0
- package/src/markdownHeading.ts +33 -0
- package/src/markdownHeadingMarkers.test.ts +132 -0
- package/src/markdownIndentedFences.test.ts +43 -0
- package/src/markdownIndentedTables.test.ts +43 -0
- package/src/markdownLink.ts +92 -0
- package/src/markdownListContinuation.test.ts +34 -0
- package/src/markdownListExport.ts +80 -0
- package/src/markdownListIndentation.test.ts +235 -0
- package/src/markdownListIndentation.ts +105 -0
- package/src/markdownListThematicBreak.test.ts +31 -0
- package/src/markdownListThematicBreakInside.test.ts +64 -0
- package/src/markdownOpenFence.test.ts +35 -0
- package/src/markdownOrderedList.test.ts +62 -0
- package/src/markdownOrderedList.ts +60 -0
- package/src/markdownQuote.ts +35 -0
- package/src/markdownQuoteMarkers.test.ts +206 -0
- package/src/markdownRefusedLinks.test.tsx +193 -0
- package/src/markdownSerializers.ts +27 -22
- package/src/markdownSource.test.tsx +750 -0
- package/src/markdownSource.ts +995 -0
- package/src/markdownSpaceRuns.test.ts +204 -0
- package/src/markdownSpaceRuns.ts +164 -0
- package/src/markdownSpacedBlockStarts.test.ts +96 -0
- package/src/markdownTabRuns.test.ts +75 -0
- package/src/markdownTable.test.tsx +214 -0
- package/src/markdownTable.ts +309 -0
- package/src/markdownTableLinks.test.ts +69 -0
- package/src/markdownTaskList.test.tsx +445 -0
- package/src/markdownTaskList.ts +222 -0
- package/src/markdownThematicBreak.test.tsx +185 -0
- package/src/markdownThematicBreak.ts +66 -0
- package/src/textSemantics.test.tsx +368 -0
- package/src/textSemantics.ts +104 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type JSX } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Draws a header over each top-level code block and keeps it there as the
|
|
4
|
+
* document, the editor's size, or the window changes.
|
|
5
|
+
*/
|
|
6
|
+
export declare function CodeBlockHeaderPlugin(): JSX.Element;
|
|
7
|
+
//# sourceMappingURL=CodeBlockHeaderPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodeBlockHeaderPlugin.d.ts","sourceRoot":"","sources":["../src/CodeBlockHeaderPlugin.tsx"],"names":[],"mappings":"AAmBA,OAAO,EAAsB,KAAK,GAAG,EAAC,MAAM,OAAO,CAAC;AA+JpD;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,GAAG,CAAC,OAAO,CA+EnD"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @file CodeBlockHeaderPlugin.tsx
|
|
7
|
+
* @input Uses @lexical/react (composer context), @lexical/code (CodeNode),
|
|
8
|
+
* lexical, and core IconButton, Icon, useClipboard, and useTranslator.
|
|
9
|
+
* @output Exports CodeBlockHeaderPlugin, which draws core CodeBlock's header
|
|
10
|
+
* over every fenced code block: the language label and a copy button, or
|
|
11
|
+
* just the copy button in the corner when the block names no language.
|
|
12
|
+
* @position Rendered by RichTextEditor and RichTextView inside the positioned
|
|
13
|
+
* element that holds the content editable. The headers are siblings of the
|
|
14
|
+
* editable text, never inside it, so they are not part of the document and
|
|
15
|
+
* cannot be edited (spec:AST-061 FR8, DEC-4). The code block's theme class
|
|
16
|
+
* reserves the header's height, so the code sits where core Markdown's does.
|
|
17
|
+
*/
|
|
18
|
+
import * as stylex from '@stylexjs/stylex';
|
|
19
|
+
import { useEffect, useState } from 'react';
|
|
20
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
21
|
+
import { $isCodeNode } from '@lexical/code';
|
|
22
|
+
import { $getNodeByKey, $getRoot } from 'lexical';
|
|
23
|
+
import { Icon } from '@astryxdesign/core/Icon';
|
|
24
|
+
import { IconButton } from '@astryxdesign/core/IconButton';
|
|
25
|
+
import { useClipboard } from '@astryxdesign/core/hooks';
|
|
26
|
+
import { useTranslator } from '@astryxdesign/core/i18n';
|
|
27
|
+
import '@astryxdesign/core/theme/tokens.stylex';
|
|
28
|
+
import { fontWeightVars, spacingVars, typeScaleVars, typographyVars } from '@astryxdesign/core/theme/tokens.stylex';
|
|
29
|
+
|
|
30
|
+
/** Where one code block's header goes, in the container's coordinates. */
|
|
31
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
32
|
+
const styles = {
|
|
33
|
+
header: {
|
|
34
|
+
kVAEAm: "x10l6tqk",
|
|
35
|
+
k1xSpc: "x78zum5",
|
|
36
|
+
kGNEyG: "x6s0dn4",
|
|
37
|
+
kjj79g: "x1qughib",
|
|
38
|
+
k8WAf4: "xce4md1",
|
|
39
|
+
kg3NbH: "x1pzlopt",
|
|
40
|
+
kB7OPa: "x9f619",
|
|
41
|
+
$$css: true
|
|
42
|
+
},
|
|
43
|
+
corner: {
|
|
44
|
+
kVAEAm: "x10l6tqk",
|
|
45
|
+
k1xSpc: "x78zum5",
|
|
46
|
+
kjj79g: "x13a6bvl",
|
|
47
|
+
kmVPX3: "xlsj2fj",
|
|
48
|
+
kB7OPa: "x9f619",
|
|
49
|
+
kfzvcC: "x47corl",
|
|
50
|
+
$$css: true
|
|
51
|
+
},
|
|
52
|
+
cornerButton: {
|
|
53
|
+
kfzvcC: "x67bb7w",
|
|
54
|
+
$$css: true
|
|
55
|
+
},
|
|
56
|
+
copyButton: {
|
|
57
|
+
kMwMTN: "x1mjzq1q",
|
|
58
|
+
$$css: true
|
|
59
|
+
},
|
|
60
|
+
placement: (top, left, width) => [{
|
|
61
|
+
k87sOh: top != null ? "xjbys53" : top,
|
|
62
|
+
kbCHJM: left != null ? "xgq9j65" : left,
|
|
63
|
+
kzqmXN: width != null ? "x5lhr3w" : width,
|
|
64
|
+
$$css: true
|
|
65
|
+
}, {
|
|
66
|
+
"--x-top": (val => typeof val === "number" ? val + "px" : val != null ? val : undefined)(top),
|
|
67
|
+
"--x-left": (val => typeof val === "number" ? val + "px" : val != null ? val : undefined)(left),
|
|
68
|
+
"--x-width": (val => typeof val === "number" ? val + "px" : val != null ? val : undefined)(width)
|
|
69
|
+
}]
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The language a header names, as core CodeBlock decides it: none for a fence
|
|
74
|
+
* without one, and none for exactly `plaintext`, which core Markdown gives a
|
|
75
|
+
* fence with no info string.
|
|
76
|
+
*/
|
|
77
|
+
function displayLanguageOf(language) {
|
|
78
|
+
return language == null || language === '' || language === PLAIN_TEXT ? null : language;
|
|
79
|
+
}
|
|
80
|
+
const PLAIN_TEXT = 'plaintext';
|
|
81
|
+
function samePlacements(a, b) {
|
|
82
|
+
return a.length === b.length && a.every((placement, index) => placement.key === b[index].key && placement.language === b[index].language && placement.top === b[index].top && placement.left === b[index].left && placement.width === b[index].width);
|
|
83
|
+
}
|
|
84
|
+
function CodeBlockHeader({
|
|
85
|
+
placement
|
|
86
|
+
}) {
|
|
87
|
+
const [editor] = useLexicalComposerContext();
|
|
88
|
+
const t = useTranslator();
|
|
89
|
+
const {
|
|
90
|
+
copy,
|
|
91
|
+
isCopied
|
|
92
|
+
} = useClipboard({
|
|
93
|
+
announce: t('@astryx.codeBlock.copied')
|
|
94
|
+
});
|
|
95
|
+
const copyButton = /*#__PURE__*/_jsx(IconButton, {
|
|
96
|
+
variant: "ghost",
|
|
97
|
+
size: "sm",
|
|
98
|
+
icon: /*#__PURE__*/_jsx(Icon, {
|
|
99
|
+
icon: isCopied ? 'check' : 'copy',
|
|
100
|
+
size: "sm",
|
|
101
|
+
color: "inherit"
|
|
102
|
+
}),
|
|
103
|
+
tooltip: t('@astryx.codeBlock.copyCode'),
|
|
104
|
+
label: isCopied ? t('@astryx.codeBlock.copied') : t('@astryx.codeBlock.copyCode'),
|
|
105
|
+
onClick: () => {
|
|
106
|
+
const code = editor.getEditorState().read(() => $getNodeByKey(placement.key)?.getTextContent() ?? '');
|
|
107
|
+
void copy(code);
|
|
108
|
+
},
|
|
109
|
+
xstyle: [styles.copyButton, placement.language == null && styles.cornerButton]
|
|
110
|
+
});
|
|
111
|
+
const position = styles.placement(placement.top, placement.left, placement.width);
|
|
112
|
+
if (placement.language == null) {
|
|
113
|
+
return /*#__PURE__*/_jsx("div", {
|
|
114
|
+
"data-richtext-code-header": "",
|
|
115
|
+
...stylex.props(styles.corner, position),
|
|
116
|
+
children: copyButton
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
120
|
+
"data-richtext-code-header": "",
|
|
121
|
+
...stylex.props(styles.header, position),
|
|
122
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
123
|
+
...{
|
|
124
|
+
className: "x141an7d x9m5x89 x1e4wzip x1ltkj2j x1mjzq1q xeuugli xb3r6kr xlyipyv xuxw1ft"
|
|
125
|
+
},
|
|
126
|
+
children: placement.language
|
|
127
|
+
}), copyButton]
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Draws a header over each top-level code block and keeps it there as the
|
|
133
|
+
* document, the editor's size, or the window changes.
|
|
134
|
+
*/
|
|
135
|
+
export function CodeBlockHeaderPlugin() {
|
|
136
|
+
const [editor] = useLexicalComposerContext();
|
|
137
|
+
const [placements, setPlacements] = useState([]);
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
let frame = 0;
|
|
140
|
+
const measure = () => {
|
|
141
|
+
frame = 0;
|
|
142
|
+
const root = editor.getRootElement();
|
|
143
|
+
const container = root?.parentElement;
|
|
144
|
+
if (root == null || container == null) {
|
|
145
|
+
setPlacements(current => current.length === 0 ? current : []);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const origin = container.getBoundingClientRect();
|
|
149
|
+
const next = editor.getEditorState().read(() => $getRoot().getChildren().filter($isCodeNode).flatMap(node => {
|
|
150
|
+
const element = editor.getElementByKey(node.getKey());
|
|
151
|
+
if (element == null) {
|
|
152
|
+
return [];
|
|
153
|
+
}
|
|
154
|
+
const box = element.getBoundingClientRect();
|
|
155
|
+
// Inside the block's border, so the header lines up with the
|
|
156
|
+
// padding the theme reserves for it.
|
|
157
|
+
return [{
|
|
158
|
+
key: node.getKey(),
|
|
159
|
+
language: displayLanguageOf(node.getLanguage()),
|
|
160
|
+
top: box.top - origin.top + element.clientTop,
|
|
161
|
+
left: box.left - origin.left + element.clientLeft,
|
|
162
|
+
width: element.clientWidth
|
|
163
|
+
}];
|
|
164
|
+
}));
|
|
165
|
+
setPlacements(current => samePlacements(current, next) ? current : next);
|
|
166
|
+
};
|
|
167
|
+
const schedule = () => {
|
|
168
|
+
if (frame === 0) {
|
|
169
|
+
frame = requestAnimationFrame(measure);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
const observer = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(schedule);
|
|
173
|
+
const unregisterRoot = editor.registerRootListener(root => {
|
|
174
|
+
observer?.disconnect();
|
|
175
|
+
if (root != null) {
|
|
176
|
+
observer?.observe(root);
|
|
177
|
+
}
|
|
178
|
+
schedule();
|
|
179
|
+
});
|
|
180
|
+
const unregisterUpdate = editor.registerUpdateListener(schedule);
|
|
181
|
+
window.addEventListener('resize', schedule);
|
|
182
|
+
schedule();
|
|
183
|
+
return () => {
|
|
184
|
+
cancelAnimationFrame(frame);
|
|
185
|
+
observer?.disconnect();
|
|
186
|
+
unregisterRoot();
|
|
187
|
+
unregisterUpdate();
|
|
188
|
+
window.removeEventListener('resize', schedule);
|
|
189
|
+
};
|
|
190
|
+
}, [editor]);
|
|
191
|
+
return /*#__PURE__*/_jsx(_Fragment, {
|
|
192
|
+
children: placements.map(placement => /*#__PURE__*/_jsx(CodeBlockHeader, {
|
|
193
|
+
placement: placement
|
|
194
|
+
}, placement.key))
|
|
195
|
+
});
|
|
196
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type TokenLine } from '@astryxdesign/core/CodeBlock';
|
|
2
|
+
/** The class the theme adds to every code block (editorTheme.ts). */
|
|
3
|
+
export declare const CODE_SYNTAX_CLASS = "astryx-richtext-code";
|
|
4
|
+
/**
|
|
5
|
+
* The tokens of `code`, laid out for the rendered text of its block: line by
|
|
6
|
+
* line when the text keeps the line breaks, or as one line of offsets when
|
|
7
|
+
* each line break is an element with no text. Null when the rendered text is
|
|
8
|
+
* not the code (it is mid-update), so nothing is colored out of place.
|
|
9
|
+
*/
|
|
10
|
+
export declare function renderedTokens(code: string, language: string, rendered: string): TokenLine[] | null;
|
|
11
|
+
export declare function CodeSyntaxPlugin(): null;
|
|
12
|
+
//# sourceMappingURL=CodeSyntaxPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodeSyntaxPlugin.d.ts","sourceRoot":"","sources":["../src/CodeSyntaxPlugin.tsx"],"names":[],"mappings":"AA2BA,OAAO,EAIL,KAAK,SAAS,EACf,MAAM,8BAA8B,CAAC;AAEtC,qEAAqE;AACrE,eAAO,MAAM,iBAAiB,yBAAyB,CAAC;AA8BxD;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,SAAS,EAAE,GAAG,IAAI,CAqBpB;AASD,wBAAgB,gBAAgB,IAAI,IAAI,CAuFvC"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @file CodeSyntaxPlugin.tsx
|
|
7
|
+
* @input Uses @lexical/react (composer context), @lexical/code (CodeNode),
|
|
8
|
+
* lexical, and core CodeBlock's tokenizer, highlight ranges, and token
|
|
9
|
+
* types.
|
|
10
|
+
* @output Exports CodeSyntaxPlugin, which colors the code in every fenced code
|
|
11
|
+
* block with core CodeBlock's tokenizer and syntax color tokens;
|
|
12
|
+
* CODE_SYNTAX_CLASS, the class the theme gives code blocks for it; and
|
|
13
|
+
* renderedTokens, which lays tokens out over a block's rendered text.
|
|
14
|
+
* @position Rendered by RichTextEditor and RichTextView. A fenced code block
|
|
15
|
+
* with a language core CodeBlock knows is colored as core Markdown colors
|
|
16
|
+
* it: the same tokenizer finds the same tokens, and each token type takes
|
|
17
|
+
* its `--color-syntax-*` token (spec:AST-061 FR1) — no palette of its own.
|
|
18
|
+
* The colors are CSS Custom Highlight ranges over the text Lexical renders,
|
|
19
|
+
* the way core CodeBlock colors editable code, so the document and its DOM
|
|
20
|
+
* are untouched; the ranges are rebuilt when a block's code or language
|
|
21
|
+
* changes. Browsers without the Highlight API show plain code.
|
|
22
|
+
*/
|
|
23
|
+
import { useEffect } from 'react';
|
|
24
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
25
|
+
import { $isCodeNode, CodeNode } from '@lexical/code';
|
|
26
|
+
import { $getNodeByKey } from 'lexical';
|
|
27
|
+
import { applyHighlightRangesFlat, TOKEN_TYPES, tokenize } from '@astryxdesign/core/CodeBlock';
|
|
28
|
+
|
|
29
|
+
/** The class the theme adds to every code block (editorTheme.ts). */
|
|
30
|
+
export const CODE_SYNTAX_CLASS = 'astryx-richtext-code';
|
|
31
|
+
let hasInjectedRules = false;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The highlight rules for code blocks, injected once: each token type takes
|
|
35
|
+
* the same syntax color token core CodeBlock's rules use.
|
|
36
|
+
*/
|
|
37
|
+
function ensureRules() {
|
|
38
|
+
if (hasInjectedRules || typeof document === 'undefined') {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
hasInjectedRules = true;
|
|
42
|
+
const style = document.createElement('style');
|
|
43
|
+
style.setAttribute('data-astryx-richtext-code-syntax', '');
|
|
44
|
+
style.textContent = TOKEN_TYPES.map(type => `.${CODE_SYNTAX_CLASS}::highlight(astryx-${type}) { color: var(--color-syntax-${type}); }`).join('\n');
|
|
45
|
+
document.head.append(style);
|
|
46
|
+
}
|
|
47
|
+
function supportsHighlights() {
|
|
48
|
+
return typeof CSS !== 'undefined' && 'highlights' in CSS && typeof Highlight !== 'undefined';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The tokens of `code`, laid out for the rendered text of its block: line by
|
|
53
|
+
* line when the text keeps the line breaks, or as one line of offsets when
|
|
54
|
+
* each line break is an element with no text. Null when the rendered text is
|
|
55
|
+
* not the code (it is mid-update), so nothing is colored out of place.
|
|
56
|
+
*/
|
|
57
|
+
export function renderedTokens(code, language, rendered) {
|
|
58
|
+
const lines = tokenize(code, language);
|
|
59
|
+
if (rendered === code) {
|
|
60
|
+
return lines;
|
|
61
|
+
}
|
|
62
|
+
if (rendered !== code.replaceAll('\n', '')) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
const flat = [];
|
|
66
|
+
let offset = 0;
|
|
67
|
+
code.split('\n').forEach((line, index) => {
|
|
68
|
+
for (const token of lines[index] ?? []) {
|
|
69
|
+
flat.push({
|
|
70
|
+
type: token.type,
|
|
71
|
+
start: offset + token.start,
|
|
72
|
+
end: offset + token.end
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
offset += line.length;
|
|
76
|
+
});
|
|
77
|
+
return [flat];
|
|
78
|
+
}
|
|
79
|
+
export function CodeSyntaxPlugin() {
|
|
80
|
+
const [editor] = useLexicalComposerContext();
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
if (!supportsHighlights()) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
ensureRules();
|
|
86
|
+
// Every code block in the editor, and the ones colored, by node key.
|
|
87
|
+
const blocks = new Set();
|
|
88
|
+
const colored = new Map();
|
|
89
|
+
const uncolor = key => {
|
|
90
|
+
colored.get(key)?.cleanup();
|
|
91
|
+
colored.delete(key);
|
|
92
|
+
};
|
|
93
|
+
const color = key => {
|
|
94
|
+
const block = editor.getEditorState().read(() => {
|
|
95
|
+
const node = $getNodeByKey(key);
|
|
96
|
+
return $isCodeNode(node) ? {
|
|
97
|
+
code: node.getTextContent(),
|
|
98
|
+
language: node.getLanguage() ?? ''
|
|
99
|
+
} : null;
|
|
100
|
+
});
|
|
101
|
+
const element = editor.getElementByKey(key);
|
|
102
|
+
if (block == null || element == null) {
|
|
103
|
+
uncolor(key);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const previous = colored.get(key);
|
|
107
|
+
if (previous != null && previous.element === element && previous.code === block.code && previous.language === block.language) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
previous?.cleanup();
|
|
111
|
+
const tokens = renderedTokens(block.code, block.language, element.textContent ?? '');
|
|
112
|
+
if (tokens == null) {
|
|
113
|
+
// Not rendered yet; the next update tries again.
|
|
114
|
+
colored.delete(key);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
colored.set(key, {
|
|
118
|
+
element,
|
|
119
|
+
...block,
|
|
120
|
+
cleanup: applyHighlightRangesFlat(element, tokens)
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
const unregisterMutations = editor.registerMutationListener(CodeNode, mutations => {
|
|
124
|
+
for (const [key, mutation] of mutations) {
|
|
125
|
+
if (mutation === 'destroyed') {
|
|
126
|
+
blocks.delete(key);
|
|
127
|
+
uncolor(key);
|
|
128
|
+
} else {
|
|
129
|
+
blocks.add(key);
|
|
130
|
+
color(key);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}, {
|
|
134
|
+
skipInitialization: false
|
|
135
|
+
});
|
|
136
|
+
// Typing in a block changes its text nodes, not always the block itself:
|
|
137
|
+
// recheck every block after each update (unchanged ones stop at the
|
|
138
|
+
// comparison above).
|
|
139
|
+
const unregisterUpdates = editor.registerUpdateListener(() => {
|
|
140
|
+
for (const key of blocks) {
|
|
141
|
+
color(key);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
return () => {
|
|
145
|
+
unregisterMutations();
|
|
146
|
+
unregisterUpdates();
|
|
147
|
+
for (const key of [...colored.keys()]) {
|
|
148
|
+
uncolor(key);
|
|
149
|
+
}
|
|
150
|
+
blocks.clear();
|
|
151
|
+
};
|
|
152
|
+
}, [editor]);
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Transformer } from '@lexical/markdown';
|
|
2
|
+
import type { MarkdownExtensionNode, MarkdownPluginEntry } from '@astryxdesign/core/Markdown/plugins';
|
|
3
|
+
import { type RichTextMarkdownExtension } from './markdownExtensions';
|
|
4
|
+
import { type RichTextExtensionNodeFacts } from './markdownExtensionNode';
|
|
5
|
+
/**
|
|
6
|
+
* The node core derives from a stored node's source with `plugins`, or null
|
|
7
|
+
* when no adopted plugin of the same protocol version reads that exact source
|
|
8
|
+
* as that node.
|
|
9
|
+
*/
|
|
10
|
+
export declare function deriveExtensionNode(facts: RichTextExtensionNodeFacts, plugins: ReadonlyArray<MarkdownPluginEntry>): MarkdownExtensionNode | null;
|
|
11
|
+
export interface MarkdownExtensionsPluginProps {
|
|
12
|
+
extensions: ReadonlyArray<RichTextMarkdownExtension>;
|
|
13
|
+
/** The surface's Markdown transformers, checked against the extensions. */
|
|
14
|
+
transformers: ReadonlyArray<Transformer>;
|
|
15
|
+
}
|
|
16
|
+
export declare function MarkdownExtensionsPlugin({ extensions, transformers, }: MarkdownExtensionsPluginProps): null;
|
|
17
|
+
//# sourceMappingURL=MarkdownExtensionsPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MarkdownExtensionsPlugin.d.ts","sourceRoot":"","sources":["../src/MarkdownExtensionsPlugin.tsx"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAwBnD,OAAO,KAAK,EACV,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAY,KAAK,yBAAyB,EAAC,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAKL,KAAK,0BAA0B,EAChC,MAAM,yBAAyB,CAAC;AAEjC;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,0BAA0B,EACjC,OAAO,EAAE,aAAa,CAAC,mBAAmB,CAAC,GAC1C,qBAAqB,GAAG,IAAI,CAoB9B;AAyHD,MAAM,WAAW,6BAA6B;IAC5C,UAAU,EAAE,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACrD,2EAA2E;IAC3E,YAAY,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;CAC1C;AAED,wBAAgB,wBAAwB,CAAC,EACvC,UAAU,EACV,YAAY,GACb,EAAE,6BAA6B,GAAG,IAAI,CAoEtC"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @file MarkdownExtensionsPlugin.tsx
|
|
7
|
+
* @input Uses @lexical/react (composer context), @lexical/utils ($dfs),
|
|
8
|
+
* lexical, core's client-only MarkdownPluginNodeRenderer and server-safe
|
|
9
|
+
* parser, and the RichText adapter and extension node.
|
|
10
|
+
* @output Exports MarkdownExtensionsPlugin, which draws every Markdown plugin
|
|
11
|
+
* node in an editor with its plugin's renderer, and deriveExtensionNode.
|
|
12
|
+
* @position Rendered by RichTextEditor and RichTextView when they are given
|
|
13
|
+
* `markdownExtensions` (spec:AST-064 FR2). It checks the configuration
|
|
14
|
+
* first (FR6), so a conflicting one throws a RichTextExtensionError while
|
|
15
|
+
* the surface renders. Each node is derived again from its source with the
|
|
16
|
+
* adopted plugins and drawn by core's MarkdownPluginNodeRenderer, so it
|
|
17
|
+
* renders, falls back, and reports failures exactly as Markdown does (FR8,
|
|
18
|
+
* FR9); stored data is never drawn on its own, and a node its plugin no
|
|
19
|
+
* longer recognizes — or whose plugin is not adopted — shows its source
|
|
20
|
+
* (FR11). Without this plugin a node shows its source.
|
|
21
|
+
*/
|
|
22
|
+
import { useEffect, useMemo } from 'react';
|
|
23
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
24
|
+
import { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection';
|
|
25
|
+
import { $dfs, addClassNamesToElement, removeClassNamesFromElement } from '@lexical/utils';
|
|
26
|
+
import { $getSelection, $isRangeSelection, CLICK_COMMAND, COMMAND_PRIORITY_LOW, FORMAT_TEXT_COMMAND, HISTORY_MERGE_TAG, TEXT_TYPE_TO_FORMAT } from 'lexical';
|
|
27
|
+
import { MarkdownPluginNodeRenderer } from '@astryxdesign/core/Markdown/plugin-renderer';
|
|
28
|
+
import { parseInlineAst, parseMarkdownAst } from '@astryxdesign/core/Markdown/parser';
|
|
29
|
+
import { pluginsOf } from "./markdownExtensions.js";
|
|
30
|
+
import { $firstSelectedText, $isRichTextExtensionNode, setRichTextExtensionNodeDecorator } from "./markdownExtensionNode.js";
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The node core derives from a stored node's source with `plugins`, or null
|
|
34
|
+
* when no adopted plugin of the same protocol version reads that exact source
|
|
35
|
+
* as that node.
|
|
36
|
+
*/
|
|
37
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
38
|
+
export function deriveExtensionNode(facts, plugins) {
|
|
39
|
+
const plugin = plugins.find(entry => entry.name === facts.plugin);
|
|
40
|
+
if (plugin == null || plugin.apiVersion !== facts.apiVersion) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const nodes = facts.display === 'inline' ? parseInlineAst(facts.source, {
|
|
44
|
+
plugins: [plugin]
|
|
45
|
+
}) : parseMarkdownAst(facts.source, {
|
|
46
|
+
plugins: [plugin]
|
|
47
|
+
}).children;
|
|
48
|
+
const [node] = nodes;
|
|
49
|
+
if (nodes.length !== 1 || node?.type !== 'extension') {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
const extension = node;
|
|
53
|
+
return extension.plugin === facts.plugin && extension.name === facts.name && extension.display === facts.display && extension.source === facts.source ? extension : null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The formats a plugin node can sit inside, outermost first, as RichText draws
|
|
58
|
+
* them around text (textSemantics.ts): a deletion, then emphasis, then strong.
|
|
59
|
+
*/
|
|
60
|
+
const MARKS = [['strikethrough', 'del'], ['italic', 'em'], ['bold', 'strong']];
|
|
61
|
+
|
|
62
|
+
/** The formats a toggle can put a plugin node inside. */
|
|
63
|
+
const NODE_FORMATS = new Set(MARKS.map(([format]) => format));
|
|
64
|
+
function ExtensionNodeView({
|
|
65
|
+
facts,
|
|
66
|
+
format,
|
|
67
|
+
nodeKey,
|
|
68
|
+
plugins
|
|
69
|
+
}) {
|
|
70
|
+
const [editor] = useLexicalComposerContext();
|
|
71
|
+
const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey);
|
|
72
|
+
// A click on the node selects it whole, as a click on a rule does, so a
|
|
73
|
+
// pointer user can format or delete it like a keyboard user.
|
|
74
|
+
useEffect(() => editor.registerCommand(CLICK_COMMAND, event => {
|
|
75
|
+
const element = editor.getElementByKey(nodeKey);
|
|
76
|
+
if (!editor.isEditable() || element == null || !(event.target instanceof Node) || !element.contains(event.target)) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
clearSelection();
|
|
80
|
+
setSelected(true);
|
|
81
|
+
return true;
|
|
82
|
+
}, COMMAND_PRIORITY_LOW), [clearSelection, editor, nodeKey, setSelected]);
|
|
83
|
+
// A selected node shows the focus ring a selected rule shows.
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
const element = editor.getElementByKey(nodeKey);
|
|
86
|
+
const className = editor._config.theme.markdownExtensionSelected;
|
|
87
|
+
if (element == null || typeof className !== 'string' || className === '') {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (isSelected) {
|
|
91
|
+
addClassNamesToElement(element, className);
|
|
92
|
+
} else {
|
|
93
|
+
removeClassNamesFromElement(element, className);
|
|
94
|
+
}
|
|
95
|
+
}, [editor, isSelected, nodeKey]);
|
|
96
|
+
const node = useMemo(() => deriveExtensionNode(facts, plugins), [facts, plugins]);
|
|
97
|
+
let content = node == null ? facts.source : /*#__PURE__*/_jsx(MarkdownPluginNodeRenderer, {
|
|
98
|
+
plugins: plugins,
|
|
99
|
+
node: node
|
|
100
|
+
});
|
|
101
|
+
// Inside emphasis, strong, or strikethrough, the node is drawn inside the
|
|
102
|
+
// same elements, as core Markdown draws it inside the text's.
|
|
103
|
+
for (const [type, Tag] of [...MARKS].reverse()) {
|
|
104
|
+
if ((format & TEXT_TYPE_TO_FORMAT[type]) !== 0) {
|
|
105
|
+
content = /*#__PURE__*/_jsx(Tag, {
|
|
106
|
+
children: content
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return content;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Marks every plugin node so Lexical draws it again with the decorator the
|
|
115
|
+
* editor has now. Not an edit, so it adds nothing to undo history.
|
|
116
|
+
*/
|
|
117
|
+
function redrawExtensionNodes(editor) {
|
|
118
|
+
editor.update(() => {
|
|
119
|
+
for (const {
|
|
120
|
+
node
|
|
121
|
+
} of $dfs()) {
|
|
122
|
+
if ($isRichTextExtensionNode(node)) {
|
|
123
|
+
node.markDirty();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}, {
|
|
127
|
+
tag: HISTORY_MERGE_TAG
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Whether `format` will be on for the text a range selects once it is
|
|
133
|
+
* toggled, as Lexical's formatText decides it from the first selected
|
|
134
|
+
* character; null when the range selects no text, only nodes.
|
|
135
|
+
*/
|
|
136
|
+
function $nextTextFormat(selection, format) {
|
|
137
|
+
const first = $firstSelectedText(selection);
|
|
138
|
+
return first == null ? null : (first.getFormatFlags(format, null) & TEXT_TYPE_TO_FORMAT[format]) !== 0;
|
|
139
|
+
}
|
|
140
|
+
export function MarkdownExtensionsPlugin({
|
|
141
|
+
extensions,
|
|
142
|
+
transformers
|
|
143
|
+
}) {
|
|
144
|
+
const [editor] = useLexicalComposerContext();
|
|
145
|
+
const plugins = useMemo(() => pluginsOf(extensions, transformers), [extensions, transformers]);
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
const unset = setRichTextExtensionNodeDecorator(editor, (facts, format, nodeKey) => /*#__PURE__*/_jsx(ExtensionNodeView, {
|
|
148
|
+
facts: facts,
|
|
149
|
+
format: format,
|
|
150
|
+
nodeKey: nodeKey,
|
|
151
|
+
plugins: plugins
|
|
152
|
+
}));
|
|
153
|
+
redrawExtensionNodes(editor);
|
|
154
|
+
return () => {
|
|
155
|
+
unset();
|
|
156
|
+
redrawExtensionNodes(editor);
|
|
157
|
+
};
|
|
158
|
+
}, [editor, plugins]);
|
|
159
|
+
|
|
160
|
+
// Bold, italic, or strikethrough toggled on a selection takes the plugin
|
|
161
|
+
// nodes in it along, so they stay inside the marks the text around them
|
|
162
|
+
// gets — and a selection of nodes alone toggles them by themselves.
|
|
163
|
+
useEffect(() => editor.registerCommand(FORMAT_TEXT_COMMAND, format => {
|
|
164
|
+
const selection = $getSelection();
|
|
165
|
+
if (!NODE_FORMATS.has(format) || selection == null) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
const nodes = selection.getNodes().filter(node => $isRichTextExtensionNode(node) && node.isInline());
|
|
169
|
+
if (nodes.length === 0) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
// The state Lexical gives the selected text, read before it does;
|
|
173
|
+
// null when no text is selected, only nodes.
|
|
174
|
+
const textState = $isRangeSelection(selection) ? $nextTextFormat(selection, format) : null;
|
|
175
|
+
if ($isRangeSelection(selection)) {
|
|
176
|
+
selection.formatText(format);
|
|
177
|
+
}
|
|
178
|
+
const isOn = textState ?? !nodes.every(node => node.hasFormat(format));
|
|
179
|
+
for (const node of nodes) {
|
|
180
|
+
node.setFormatFlag(format, isOn);
|
|
181
|
+
}
|
|
182
|
+
return true;
|
|
183
|
+
}, COMMAND_PRIORITY_LOW), [editor]);
|
|
184
|
+
return null;
|
|
185
|
+
}
|
package/dist/RichTextEditor.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ import { type ReactNode } from 'react';
|
|
|
26
26
|
import { type FieldStatusVariant } from '@astryxdesign/core/Field';
|
|
27
27
|
import type { BaseProps } from '@astryxdesign/core';
|
|
28
28
|
import { type SizeValue } from '@astryxdesign/core/utils';
|
|
29
|
+
import type { RichTextMarkdownExtension } from './markdownExtensions';
|
|
29
30
|
import { type Transformer } from '@lexical/markdown';
|
|
30
31
|
export type { Transformer } from '@lexical/markdown';
|
|
31
32
|
import { type EditorState, type Klass, type LexicalEditor, type LexicalNode } from 'lexical';
|
|
@@ -57,8 +58,10 @@ export interface RichTextEditorRef {
|
|
|
57
58
|
/**
|
|
58
59
|
* Serialize the current content to a Markdown string, using the same
|
|
59
60
|
* `transformers` the editor is configured with (so custom transformers
|
|
60
|
-
* layered in via the `transformers` prop are honored).
|
|
61
|
-
*
|
|
61
|
+
* layered in via the `transformers` prop are honored). Content imported
|
|
62
|
+
* with `markdownToEditorStateJSON` comes back as written: blocks nobody
|
|
63
|
+
* changed byte for byte, and only edited or added blocks in canonical
|
|
64
|
+
* Markdown.
|
|
62
65
|
*/
|
|
63
66
|
getMarkdown: () => string;
|
|
64
67
|
/**
|
|
@@ -176,13 +179,14 @@ export interface RichTextEditorProps extends Omit<BaseProps, 'onChange' | 'defau
|
|
|
176
179
|
/**
|
|
177
180
|
* Whether to enable Markdown shortcut typing (e.g. `# ` for a heading,
|
|
178
181
|
* `- ` for a list). Uses the `transformers` prop (defaults to the standard
|
|
179
|
-
* `@lexical/markdown` transformers).
|
|
182
|
+
* `@lexical/markdown` transformers plus GFM tables).
|
|
180
183
|
* @default true
|
|
181
184
|
*/
|
|
182
185
|
hasMarkdownShortcuts?: boolean;
|
|
183
186
|
/**
|
|
184
187
|
* Markdown transformers — the single source of truth for markdown behaviour.
|
|
185
|
-
* Defaults to the standard `@lexical/markdown` `TRANSFORMERS
|
|
188
|
+
* Defaults to the standard `@lexical/markdown` `TRANSFORMERS` plus GFM
|
|
189
|
+
* tables. A custom array replaces the default, tables included.
|
|
186
190
|
*
|
|
187
191
|
* The same array drives all three markdown operations in Lexical (see the
|
|
188
192
|
* lexical-playground reference, where one `PLAYGROUND_TRANSFORMERS` array
|
|
@@ -198,6 +202,15 @@ export interface RichTextEditorProps extends Omit<BaseProps, 'onChange' | 'defau
|
|
|
198
202
|
* the serialization APIs added in later phases.
|
|
199
203
|
*/
|
|
200
204
|
transformers?: ReadonlyArray<Transformer>;
|
|
205
|
+
/**
|
|
206
|
+
* Markdown plugins whose nodes this surface draws, each adopted with
|
|
207
|
+
* `createRichTextExtension` (spec:AST-064). A plugin node renders exactly as
|
|
208
|
+
* core `Markdown` renders it, and one whose plugin is not given here shows
|
|
209
|
+
* its source. Pass the extensions the content was converted with. Create
|
|
210
|
+
* them in a client module: they hold the plugins' functions, so they are not
|
|
211
|
+
* serializable props.
|
|
212
|
+
*/
|
|
213
|
+
markdownExtensions?: ReadonlyArray<RichTextMarkdownExtension>;
|
|
201
214
|
/** Whether to automatically focus the editor on mount. @default false */
|
|
202
215
|
hasAutoFocus?: boolean;
|
|
203
216
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextEditor.d.ts","sourceRoot":"","sources":["../src/RichTextEditor.tsx"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