@astryxdesign/richtext 0.7.1-canary.bc0261a → 0.7.1-canary.bffff80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -4
- package/dist/RichTextEditor.d.ts +11 -3
- package/dist/RichTextEditor.d.ts.map +1 -1
- package/dist/RichTextEditor.js +35 -36
- package/dist/RichTextEditorAutoLinkPlugin.d.ts +1 -1
- package/dist/RichTextEditorAutoLinkPlugin.js +1 -1
- package/dist/index.d.ts +10 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -4
- package/dist/linkUtils.js +1 -1
- package/package.json +4 -4
- package/src/RichTextEditor.doc.mjs +1 -1
- package/src/RichTextEditor.tsx +49 -45
- package/src/RichTextEditorAutoLinkPlugin.tsx +1 -1
- package/src/index.ts +9 -11
- package/src/linkUtils.ts +1 -1
- package/src/publicSurface.test.ts +42 -0
package/README.md
CHANGED
|
@@ -18,8 +18,20 @@ editor's `plugins` slot, and `markdownToEditorStateJSON` /
|
|
|
18
18
|
headlessly (no mounted editor required). It consumes `@astryxdesign/core` theme
|
|
19
19
|
tokens directly (StyleX build mirrors `@astryxdesign/lab` / `@astryxdesign/charts`).
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
## Built on Lexical
|
|
22
|
+
|
|
23
|
+
RichText is built on [Lexical](https://lexical.dev) and does not hide it:
|
|
24
|
+
`nodes` and `transformers` take Lexical types, `plugins` takes Lexical React
|
|
25
|
+
plugins, and `onChange(editorState, editor)` and the editor ref's
|
|
26
|
+
`getEditorState()` report Lexical types, so you extend the editor with Lexical
|
|
27
|
+
directly. The value you store is serialized Lexical editor state;
|
|
28
|
+
`markdownToEditorStateJSON` and `editorStateJSONToMarkdown` convert it to and
|
|
29
|
+
from Markdown.
|
|
30
|
+
|
|
31
|
+
RichText supports one Lexical minor at a time, named by its `lexical` and
|
|
32
|
+
`@lexical/*` peer ranges. Those are **optional** peer dependencies, so your
|
|
33
|
+
package manager does not add them: install them at that minor alongside
|
|
34
|
+
richtext. See the RFC:
|
|
23
35
|
[facebook/astryx#3899](https://github.com/facebook/astryx/issues/3899).
|
|
24
36
|
|
|
25
37
|
It ships to npm **only under the `@canary` dist-tag** — there is never a stable
|
|
@@ -56,10 +68,12 @@ you must request that tag explicitly. There is no `latest` version to install.
|
|
|
56
68
|
|
|
57
69
|
```bash
|
|
58
70
|
npm install @astryxdesign/richtext@canary @astryxdesign/core@canary
|
|
59
|
-
# plus the optional lexical peers you use:
|
|
60
|
-
npm install lexical @lexical/react @lexical/markdown @lexical/rich-text
|
|
61
71
|
```
|
|
62
72
|
|
|
73
|
+
Then install every `lexical` and `@lexical/*` package listed in richtext's
|
|
74
|
+
`peerDependencies`, at the range shown there (`npm view
|
|
75
|
+
@astryxdesign/richtext@canary peerDependencies` prints them).
|
|
76
|
+
|
|
63
77
|
> Canary builds track the latest commit on `main` (`0.x.y-canary.<sha>`). They
|
|
64
78
|
> can break between any two versions — pin an exact version if you need
|
|
65
79
|
> stability.
|
package/dist/RichTextEditor.d.ts
CHANGED
|
@@ -22,13 +22,12 @@
|
|
|
22
22
|
* Component Specification Protocol. `lexical` and `@lexical/*` are OPTIONAL peer
|
|
23
23
|
* dependencies — install them to use this component.
|
|
24
24
|
*/
|
|
25
|
-
import { type ReactNode } from 'react';
|
|
25
|
+
import { type ReactNode, type Ref } 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
29
|
import type { RichTextMarkdownExtension } from './markdownExtensions';
|
|
30
30
|
import { type Transformer } from '@lexical/markdown';
|
|
31
|
-
export type { Transformer } from '@lexical/markdown';
|
|
32
31
|
import { type EditorState, type Klass, type LexicalEditor, type LexicalNode } from 'lexical';
|
|
33
32
|
export type RichTextEditorStatusType = 'warning' | 'error' | 'success';
|
|
34
33
|
export type RichTextEditorSize = 'sm' | 'md' | 'lg';
|
|
@@ -77,6 +76,12 @@ export interface RichTextEditorRef {
|
|
|
77
76
|
getEditor: () => LexicalEditor;
|
|
78
77
|
}
|
|
79
78
|
export interface RichTextEditorProps extends Omit<BaseProps, 'onChange' | 'defaultValue'> {
|
|
79
|
+
/**
|
|
80
|
+
* Imperative handle for callers that manage the editor from outside. In
|
|
81
|
+
* React 19 `ref` is an ordinary prop, so it is declared here rather than
|
|
82
|
+
* supplied by a `forwardRef` wrapper.
|
|
83
|
+
*/
|
|
84
|
+
ref?: Ref<RichTextEditorRef>;
|
|
80
85
|
/** Label text for the editor (always rendered for accessibility). */
|
|
81
86
|
label: string;
|
|
82
87
|
/**
|
|
@@ -261,5 +266,8 @@ export interface RichTextEditorProps extends Omit<BaseProps, 'onChange' | 'defau
|
|
|
261
266
|
* />
|
|
262
267
|
* ```
|
|
263
268
|
*/
|
|
264
|
-
export declare const RichTextEditor:
|
|
269
|
+
export declare const RichTextEditor: {
|
|
270
|
+
({ label, isLabelHidden, description, isOptional, isRequired, defaultValue, onChange, placeholder, isReadOnly, isDisabled, status, statusVariant, width, minHeight, labelTooltip, size: sizeProp, nodes, toolbar, plugins, hasMarkdownShortcuts, transformers, markdownExtensions, hasAutoFocus, tabEscapeHint: tabEscapeHintFromProps, maxLength, namespace, xstyle, className, style, ref, ...rest }: RichTextEditorProps): import("react").JSX.Element;
|
|
271
|
+
displayName: string;
|
|
272
|
+
};
|
|
265
273
|
//# sourceMappingURL=RichTextEditor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextEditor.d.ts","sourceRoot":"","sources":["../src/RichTextEditor.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"RichTextEditor.d.ts","sourceRoot":"","sources":["../src/RichTextEditor.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;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;;OAOG;IACH,kBAAkB,CAAC,EAAE,aAAa,CAAC,yBAAyB,CAAC,CAAC;IAC9D,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;4YAgCxB,mBAAmB;;CAoPrB,CAAC"}
|
package/dist/RichTextEditor.js
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* Component Specification Protocol. `lexical` and `@lexical/*` are OPTIONAL peer
|
|
27
27
|
* dependencies — install them to use this component.
|
|
28
28
|
*/
|
|
29
|
-
import { useEffect, useId, useImperativeHandle, useMemo, useRef, useState
|
|
29
|
+
import { useEffect, useId, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
30
30
|
import * as stylex from '@stylexjs/stylex';
|
|
31
31
|
import '@astryxdesign/core/theme/tokens.stylex';
|
|
32
32
|
import { colorVars, spacingVars, typographyVars, typeScaleVars } from '@astryxdesign/core/theme/tokens.stylex';
|
|
@@ -108,24 +108,6 @@ const styles = {
|
|
|
108
108
|
kAzted: "x65nank",
|
|
109
109
|
$$css: true
|
|
110
110
|
},
|
|
111
|
-
editorBody: {
|
|
112
|
-
kVAEAm: "x1n2onr6",
|
|
113
|
-
kB7OPa: "x9f619",
|
|
114
|
-
kzqmXN: "xh8yej3",
|
|
115
|
-
k8WAf4: "xu0wf1k",
|
|
116
|
-
kg3NbH: "xf314gf",
|
|
117
|
-
$$css: true
|
|
118
|
-
},
|
|
119
|
-
editorBodyWithToolbar: {
|
|
120
|
-
kEafiO: "x178xt8z",
|
|
121
|
-
kPef9Z: "x13fuv20",
|
|
122
|
-
kLZC3w: "x1pc3f07",
|
|
123
|
-
$$css: true
|
|
124
|
-
},
|
|
125
|
-
editorBodyWithStatus: {
|
|
126
|
-
kwRFfy: "xp74n0j",
|
|
127
|
-
$$css: true
|
|
128
|
-
},
|
|
129
111
|
contentEditable: {
|
|
130
112
|
k1xSpc: "x1lliihq",
|
|
131
113
|
kzqmXN: "xh8yej3",
|
|
@@ -149,19 +131,6 @@ const dynamicStyles = {
|
|
|
149
131
|
"--x-minHeight": (val => typeof val === "number" ? val + "px" : val != null ? val : undefined)(minHeight)
|
|
150
132
|
}]
|
|
151
133
|
};
|
|
152
|
-
const editorBodySizeStyles = {
|
|
153
|
-
sm: {
|
|
154
|
-
$$css: true
|
|
155
|
-
},
|
|
156
|
-
md: {
|
|
157
|
-
$$css: true
|
|
158
|
-
},
|
|
159
|
-
lg: {
|
|
160
|
-
k8WAf4: "xce4md1",
|
|
161
|
-
$$css: true
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
|
|
165
134
|
/**
|
|
166
135
|
* Fraction of `maxLength` at which the character counter begins announcing
|
|
167
136
|
* remaining/over-limit characters to screen readers. Matches TextArea.
|
|
@@ -198,7 +167,7 @@ const COUNTER_WARNING_THRESHOLD = 0.8;
|
|
|
198
167
|
* />
|
|
199
168
|
* ```
|
|
200
169
|
*/
|
|
201
|
-
export const RichTextEditor =
|
|
170
|
+
export const RichTextEditor = function RichTextEditor({
|
|
202
171
|
label,
|
|
203
172
|
isLabelHidden = false,
|
|
204
173
|
description,
|
|
@@ -228,8 +197,9 @@ export const RichTextEditor = /*#__PURE__*/forwardRef(function RichTextEditor({
|
|
|
228
197
|
xstyle,
|
|
229
198
|
className,
|
|
230
199
|
style,
|
|
200
|
+
ref,
|
|
231
201
|
...rest
|
|
232
|
-
}
|
|
202
|
+
}) {
|
|
233
203
|
const size = useSize(sizeProp, 'md');
|
|
234
204
|
const t = useTranslator();
|
|
235
205
|
const tabEscapeHint = tabEscapeHintFromProps ?? t('@astryx.richTextEditor.tabEscapeHint');
|
|
@@ -333,7 +303,32 @@ export const RichTextEditor = /*#__PURE__*/forwardRef(function RichTextEditor({
|
|
|
333
303
|
extension: extensionRef.current,
|
|
334
304
|
contentEditable: null,
|
|
335
305
|
children: [hasToolbar ? toolbar : null, /*#__PURE__*/_jsxs("div", {
|
|
336
|
-
...
|
|
306
|
+
...{
|
|
307
|
+
0: {
|
|
308
|
+
className: "x1n2onr6 x9f619 xh8yej3 xu0wf1k xf314gf"
|
|
309
|
+
},
|
|
310
|
+
4: {
|
|
311
|
+
className: "x1n2onr6 x9f619 xh8yej3 xu0wf1k xf314gf x178xt8z x13fuv20 x1pc3f07"
|
|
312
|
+
},
|
|
313
|
+
2: {
|
|
314
|
+
className: "x1n2onr6 x9f619 xh8yej3 xu0wf1k xf314gf xp74n0j"
|
|
315
|
+
},
|
|
316
|
+
6: {
|
|
317
|
+
className: "x1n2onr6 x9f619 xh8yej3 xu0wf1k xf314gf x178xt8z x13fuv20 x1pc3f07 xp74n0j"
|
|
318
|
+
},
|
|
319
|
+
1: {
|
|
320
|
+
className: "x1n2onr6 x9f619 xh8yej3 xf314gf xce4md1"
|
|
321
|
+
},
|
|
322
|
+
5: {
|
|
323
|
+
className: "x1n2onr6 x9f619 xh8yej3 xf314gf x178xt8z x13fuv20 x1pc3f07 xce4md1"
|
|
324
|
+
},
|
|
325
|
+
3: {
|
|
326
|
+
className: "x1n2onr6 x9f619 xh8yej3 xf314gf xp74n0j xce4md1"
|
|
327
|
+
},
|
|
328
|
+
7: {
|
|
329
|
+
className: "x1n2onr6 x9f619 xh8yej3 xf314gf x178xt8z x13fuv20 x1pc3f07 xp74n0j xce4md1"
|
|
330
|
+
}
|
|
331
|
+
}[!!hasToolbar << 2 | !!!!statusIcon << 1 | !!(size === 'lg') << 0],
|
|
337
332
|
children: [/*#__PURE__*/_jsxs("div", {
|
|
338
333
|
...{
|
|
339
334
|
className: "x1n2onr6 xh8yej3 x9ynric xjm74w1 xf9zqsd xw6l6zx"
|
|
@@ -409,7 +404,11 @@ export const RichTextEditor = /*#__PURE__*/forwardRef(function RichTextEditor({
|
|
|
409
404
|
})]
|
|
410
405
|
})]
|
|
411
406
|
});
|
|
412
|
-
}
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
// Keeps the editor inside `@astryx/require-baseprops-passthrough`, which only
|
|
410
|
+
// checks components that assign a top-level `displayName`. Without it, a
|
|
411
|
+
// dropped `className`, `style` or `xstyle` on the root stops warning.
|
|
413
412
|
RichTextEditor.displayName = 'RichTextEditor';
|
|
414
413
|
|
|
415
414
|
/**
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* `linkUtils`.
|
|
6
6
|
* @output Exports `RichTextEditorAutoLinkPlugin` and its props type, plus the
|
|
7
7
|
* default `DEFAULT_LINK_MATCHERS`.
|
|
8
|
-
* @position Experimental (
|
|
8
|
+
* @position Experimental (richtext). Drop into RichTextEditor's `plugins` slot to
|
|
9
9
|
* auto-linkify URLs and emails as they are typed or pasted. Requires
|
|
10
10
|
* `AutoLinkNode` to be registered (it is, by default).
|
|
11
11
|
*
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* `linkUtils`.
|
|
10
10
|
* @output Exports `RichTextEditorAutoLinkPlugin` and its props type, plus the
|
|
11
11
|
* default `DEFAULT_LINK_MATCHERS`.
|
|
12
|
-
* @position Experimental (
|
|
12
|
+
* @position Experimental (richtext). Drop into RichTextEditor's `plugins` slot to
|
|
13
13
|
* auto-linkify URLs and emails as they are typed or pasted. Requires
|
|
14
14
|
* `AutoLinkNode` to be registered (it is, by default).
|
|
15
15
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -6,14 +6,19 @@
|
|
|
6
6
|
* Lexical-based rich text editor and viewer, promoted out of
|
|
7
7
|
* @astryxdesign/lab so it can be canaried independently.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* Exports only what a caller builds with (spec:AST-061/DEC-8): the generated
|
|
10
|
+
* editor theme classes and the autolink regular expressions stay internal,
|
|
11
|
+
* and Lexical's `Transformer` type comes from `@lexical/markdown`.
|
|
12
|
+
* `publicSurface.test.ts` holds the runtime list.
|
|
13
|
+
*
|
|
14
|
+
* SYNC: When modified, update this header, /packages/richtext/README.md,
|
|
15
|
+
* /packages/richtext/src/publicSurface.test.ts, and the editor component doc
|
|
16
|
+
* files.
|
|
11
17
|
*/
|
|
12
18
|
export { RichTextEditor } from './RichTextEditor';
|
|
13
|
-
export type { RichTextEditorProps, RichTextEditorRef, RichTextEditorStatus, RichTextEditorStatusType, RichTextEditorSize,
|
|
19
|
+
export type { RichTextEditorProps, RichTextEditorRef, RichTextEditorStatus, RichTextEditorStatusType, RichTextEditorSize, } from './RichTextEditor';
|
|
14
20
|
export { RichTextView } from './RichTextView';
|
|
15
21
|
export type { RichTextViewProps } from './RichTextView';
|
|
16
|
-
export { sharedEditorTheme } from './editorTheme';
|
|
17
22
|
export { markdownToEditorStateJSON, editorStateJSONToMarkdown, } from './markdownSerializers';
|
|
18
23
|
export type { MarkdownSerializerOptions } from './markdownSerializers';
|
|
19
24
|
export { createRichTextExtension, RichTextExtensionError, } from './markdownExtensions';
|
|
@@ -22,5 +27,5 @@ export { RichTextEditorToolbar, RICHTEXT_ICON_KEYS, } from './RichTextEditorTool
|
|
|
22
27
|
export type { RichTextEditorToolbarProps } from './RichTextEditorToolbar';
|
|
23
28
|
export { RichTextEditorAutoLinkPlugin, DEFAULT_LINK_MATCHERS, NEW_TAB_LINK_ATTRIBUTES, } from './RichTextEditorAutoLinkPlugin';
|
|
24
29
|
export type { RichTextEditorAutoLinkPluginProps } from './RichTextEditorAutoLinkPlugin';
|
|
25
|
-
export { sanitizeUrl, validateUrl
|
|
30
|
+
export { sanitizeUrl, validateUrl } from './linkUtils';
|
|
26
31
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,YAAY,EACV,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAC5C,YAAY,EAAC,iBAAiB,EAAC,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EACL,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAC,yBAAyB,EAAC,MAAM,uBAAuB,CAAC;AACrE,OAAO,EACL,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAC,yBAAyB,EAAC,MAAM,sBAAsB,CAAC;AAEpE,OAAO,EACL,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,yBAAyB,CAAC;AACjC,YAAY,EAAC,0BAA0B,EAAC,MAAM,yBAAyB,CAAC;AAExE,OAAO,EACL,4BAA4B,EAC5B,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,gCAAgC,CAAC;AACxC,YAAY,EAAC,iCAAiC,EAAC,MAAM,gCAAgC,CAAC;AAEtF,OAAO,EAAC,WAAW,EAAE,WAAW,EAAC,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -10,14 +10,19 @@
|
|
|
10
10
|
* Lexical-based rich text editor and viewer, promoted out of
|
|
11
11
|
* @astryxdesign/lab so it can be canaried independently.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* Exports only what a caller builds with (spec:AST-061/DEC-8): the generated
|
|
14
|
+
* editor theme classes and the autolink regular expressions stay internal,
|
|
15
|
+
* and Lexical's `Transformer` type comes from `@lexical/markdown`.
|
|
16
|
+
* `publicSurface.test.ts` holds the runtime list.
|
|
17
|
+
*
|
|
18
|
+
* SYNC: When modified, update this header, /packages/richtext/README.md,
|
|
19
|
+
* /packages/richtext/src/publicSurface.test.ts, and the editor component doc
|
|
20
|
+
* files.
|
|
15
21
|
*/
|
|
16
22
|
export { RichTextEditor } from "./RichTextEditor.js";
|
|
17
23
|
export { RichTextView } from "./RichTextView.js";
|
|
18
|
-
export { sharedEditorTheme } from "./editorTheme.js";
|
|
19
24
|
export { markdownToEditorStateJSON, editorStateJSONToMarkdown } from "./markdownSerializers.js";
|
|
20
25
|
export { createRichTextExtension, RichTextExtensionError } from "./markdownExtensions.js";
|
|
21
26
|
export { RichTextEditorToolbar, RICHTEXT_ICON_KEYS } from "./RichTextEditorToolbar.js";
|
|
22
27
|
export { RichTextEditorAutoLinkPlugin, DEFAULT_LINK_MATCHERS, NEW_TAB_LINK_ATTRIBUTES } from "./RichTextEditorAutoLinkPlugin.js";
|
|
23
|
-
export { sanitizeUrl, validateUrl
|
|
28
|
+
export { sanitizeUrl, validateUrl } from "./linkUtils.js";
|
package/dist/linkUtils.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @input Uses only the DOM URL constructor (guarded via try/catch for SSR/edge).
|
|
6
6
|
* @output Exports `sanitizeUrl`, `validateUrl`, and the URL/email matcher regexes
|
|
7
7
|
* used by the AutoLink wiring.
|
|
8
|
-
* @position Experimental (
|
|
8
|
+
* @position Experimental (richtext) helper shared by RichTextEditorToolbar (link
|
|
9
9
|
* button) and the AutoLink matchers in RichTextEditor. Kept dependency-free so
|
|
10
10
|
* both can import it without pulling in extra `@lexical/*` surface.
|
|
11
11
|
*
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/richtext",
|
|
3
3
|
"displayName": "Rich Text",
|
|
4
|
-
"version": "0.7.1-canary.
|
|
4
|
+
"version": "0.7.1-canary.bffff80",
|
|
5
5
|
"description": "Astryx rich text — a Lexical-based rich text editor and viewer. Published to npm only under the @canary dist-tag for early testing; never released as a stable (latest) version.",
|
|
6
6
|
"author": "Meta Open Source",
|
|
7
7
|
"license": "MIT",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"@stylexjs/stylex": ">=0.10.0",
|
|
58
|
-
"@astryxdesign/core": "0.7.1-canary.
|
|
58
|
+
"@astryxdesign/core": "0.7.1-canary.bffff80",
|
|
59
59
|
"react": ">=19.0.0",
|
|
60
60
|
"react-dom": ">=19.0.0",
|
|
61
61
|
"lexical": "^0.46.0",
|
|
@@ -114,8 +114,8 @@
|
|
|
114
114
|
}
|
|
115
115
|
},
|
|
116
116
|
"devDependencies": {
|
|
117
|
-
"@astryxdesign/a11y-spec": "0.7.1-canary.
|
|
118
|
-
"@astryxdesign/cli": "0.7.1-canary.
|
|
117
|
+
"@astryxdesign/a11y-spec": "0.7.1-canary.bffff80",
|
|
118
|
+
"@astryxdesign/cli": "0.7.1-canary.bffff80",
|
|
119
119
|
"@babel/cli": "^7.29.7",
|
|
120
120
|
"@babel/core": "^7.29.7",
|
|
121
121
|
"@babel/preset-react": "^7.29.7",
|
|
@@ -184,7 +184,7 @@ export const docs = {
|
|
|
184
184
|
{
|
|
185
185
|
guidance: true,
|
|
186
186
|
description:
|
|
187
|
-
'Install lexical and @lexical
|
|
187
|
+
'RichText is built on Lexical and exposes it: nodes and transformers take Lexical types, plugins takes Lexical React plugins, and onChange and getEditorState() report Lexical types. Install the lexical and @lexical/* peers (optional peers) at the Lexical minor named in the package peer ranges before importing from @astryxdesign/richtext.',
|
|
188
188
|
},
|
|
189
189
|
{
|
|
190
190
|
guidance: true,
|
package/src/RichTextEditor.tsx
CHANGED
|
@@ -34,7 +34,6 @@ import {
|
|
|
34
34
|
useMemo,
|
|
35
35
|
useRef,
|
|
36
36
|
useState,
|
|
37
|
-
forwardRef,
|
|
38
37
|
type ReactNode,
|
|
39
38
|
type Ref,
|
|
40
39
|
} from 'react';
|
|
@@ -82,7 +81,6 @@ import {MarkdownExtensionsPlugin} from './MarkdownExtensionsPlugin';
|
|
|
82
81
|
import type {RichTextMarkdownExtension} from './markdownExtensions';
|
|
83
82
|
import {TaskCheckboxPlugin} from './TaskCheckboxPlugin';
|
|
84
83
|
import {type Transformer} from '@lexical/markdown';
|
|
85
|
-
export type {Transformer} from '@lexical/markdown';
|
|
86
84
|
import {$generateHtmlFromNodes} from '@lexical/html';
|
|
87
85
|
import {DEFAULT_NODES} from './editorNodes';
|
|
88
86
|
import {$exportMarkdownKeepingSource} from './markdownSource';
|
|
@@ -240,8 +238,8 @@ const dynamicStyles = stylex.create({
|
|
|
240
238
|
});
|
|
241
239
|
|
|
242
240
|
const editorBodySizeStyles = stylex.create({
|
|
243
|
-
sm
|
|
244
|
-
|
|
241
|
+
// Only `lg` adds block padding; `sm` and `md` take the base body spacing.
|
|
242
|
+
// An empty entry each would read as deliberate size-specific styling.
|
|
245
243
|
lg: {
|
|
246
244
|
paddingBlock: spacingVars['--spacing-2'],
|
|
247
245
|
},
|
|
@@ -307,6 +305,12 @@ export interface RichTextEditorProps extends Omit<
|
|
|
307
305
|
BaseProps,
|
|
308
306
|
'onChange' | 'defaultValue'
|
|
309
307
|
> {
|
|
308
|
+
/**
|
|
309
|
+
* Imperative handle for callers that manage the editor from outside. In
|
|
310
|
+
* React 19 `ref` is an ordinary prop, so it is declared here rather than
|
|
311
|
+
* supplied by a `forwardRef` wrapper.
|
|
312
|
+
*/
|
|
313
|
+
ref?: Ref<RichTextEditorRef>;
|
|
310
314
|
/** Label text for the editor (always rendered for accessibility). */
|
|
311
315
|
label: string;
|
|
312
316
|
/**
|
|
@@ -492,44 +496,39 @@ export interface RichTextEditorProps extends Omit<
|
|
|
492
496
|
* />
|
|
493
497
|
* ```
|
|
494
498
|
*/
|
|
495
|
-
export const RichTextEditor =
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
style,
|
|
529
|
-
...rest
|
|
530
|
-
}: RichTextEditorProps,
|
|
531
|
-
ref: Ref<RichTextEditorRef>,
|
|
532
|
-
) {
|
|
499
|
+
export const RichTextEditor = function RichTextEditor({
|
|
500
|
+
label,
|
|
501
|
+
isLabelHidden = false,
|
|
502
|
+
description,
|
|
503
|
+
isOptional = false,
|
|
504
|
+
isRequired = false,
|
|
505
|
+
defaultValue,
|
|
506
|
+
onChange,
|
|
507
|
+
placeholder,
|
|
508
|
+
isReadOnly = false,
|
|
509
|
+
isDisabled = false,
|
|
510
|
+
status,
|
|
511
|
+
statusVariant = 'attached',
|
|
512
|
+
width,
|
|
513
|
+
minHeight = '4.5rem',
|
|
514
|
+
labelTooltip,
|
|
515
|
+
size: sizeProp,
|
|
516
|
+
nodes,
|
|
517
|
+
toolbar,
|
|
518
|
+
plugins,
|
|
519
|
+
hasMarkdownShortcuts = true,
|
|
520
|
+
transformers = DEFAULT_TRANSFORMERS,
|
|
521
|
+
markdownExtensions,
|
|
522
|
+
hasAutoFocus = false,
|
|
523
|
+
tabEscapeHint: tabEscapeHintFromProps,
|
|
524
|
+
maxLength,
|
|
525
|
+
namespace = 'astryx-editor',
|
|
526
|
+
xstyle,
|
|
527
|
+
className,
|
|
528
|
+
style,
|
|
529
|
+
ref,
|
|
530
|
+
...rest
|
|
531
|
+
}: RichTextEditorProps) {
|
|
533
532
|
const size = useSize(sizeProp, 'md');
|
|
534
533
|
const t = useTranslator();
|
|
535
534
|
const tabEscapeHint =
|
|
@@ -672,7 +671,7 @@ export const RichTextEditor = forwardRef<
|
|
|
672
671
|
styles.editorBody,
|
|
673
672
|
hasToolbar && styles.editorBodyWithToolbar,
|
|
674
673
|
!!statusIcon && styles.editorBodyWithStatus,
|
|
675
|
-
editorBodySizeStyles
|
|
674
|
+
size === 'lg' && editorBodySizeStyles.lg,
|
|
676
675
|
)}>
|
|
677
676
|
<div {...stylex.props(styles.editorRoot)}>
|
|
678
677
|
<RichTextPlugin
|
|
@@ -773,8 +772,11 @@ export const RichTextEditor = forwardRef<
|
|
|
773
772
|
)}
|
|
774
773
|
</Field>
|
|
775
774
|
);
|
|
776
|
-
}
|
|
775
|
+
};
|
|
777
776
|
|
|
777
|
+
// Keeps the editor inside `@astryx/require-baseprops-passthrough`, which only
|
|
778
|
+
// checks components that assign a top-level `displayName`. Without it, a
|
|
779
|
+
// dropped `className`, `style` or `xstyle` on the root stops warning.
|
|
778
780
|
RichTextEditor.displayName = 'RichTextEditor';
|
|
779
781
|
|
|
780
782
|
/**
|
|
@@ -890,7 +892,9 @@ function EditorRefBridge({
|
|
|
890
892
|
editable,
|
|
891
893
|
transformers,
|
|
892
894
|
}: {
|
|
893
|
-
|
|
895
|
+
// Optional, matching the public `ref` prop: with `forwardRef` gone, React
|
|
896
|
+
// no longer supplies `null` when the caller passes nothing.
|
|
897
|
+
editorRef: Ref<RichTextEditorRef> | undefined;
|
|
894
898
|
editable: boolean;
|
|
895
899
|
transformers: Array<Transformer>;
|
|
896
900
|
}): null {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* `linkUtils`.
|
|
10
10
|
* @output Exports `RichTextEditorAutoLinkPlugin` and its props type, plus the
|
|
11
11
|
* default `DEFAULT_LINK_MATCHERS`.
|
|
12
|
-
* @position Experimental (
|
|
12
|
+
* @position Experimental (richtext). Drop into RichTextEditor's `plugins` slot to
|
|
13
13
|
* auto-linkify URLs and emails as they are typed or pasted. Requires
|
|
14
14
|
* `AutoLinkNode` to be registered (it is, by default).
|
|
15
15
|
*
|
package/src/index.ts
CHANGED
|
@@ -10,8 +10,14 @@
|
|
|
10
10
|
* Lexical-based rich text editor and viewer, promoted out of
|
|
11
11
|
* @astryxdesign/lab so it can be canaried independently.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* Exports only what a caller builds with (spec:AST-061/DEC-8): the generated
|
|
14
|
+
* editor theme classes and the autolink regular expressions stay internal,
|
|
15
|
+
* and Lexical's `Transformer` type comes from `@lexical/markdown`.
|
|
16
|
+
* `publicSurface.test.ts` holds the runtime list.
|
|
17
|
+
*
|
|
18
|
+
* SYNC: When modified, update this header, /packages/richtext/README.md,
|
|
19
|
+
* /packages/richtext/src/publicSurface.test.ts, and the editor component doc
|
|
20
|
+
* files.
|
|
15
21
|
*/
|
|
16
22
|
|
|
17
23
|
export {RichTextEditor} from './RichTextEditor';
|
|
@@ -21,14 +27,11 @@ export type {
|
|
|
21
27
|
RichTextEditorStatus,
|
|
22
28
|
RichTextEditorStatusType,
|
|
23
29
|
RichTextEditorSize,
|
|
24
|
-
Transformer,
|
|
25
30
|
} from './RichTextEditor';
|
|
26
31
|
|
|
27
32
|
export {RichTextView} from './RichTextView';
|
|
28
33
|
export type {RichTextViewProps} from './RichTextView';
|
|
29
34
|
|
|
30
|
-
export {sharedEditorTheme} from './editorTheme';
|
|
31
|
-
|
|
32
35
|
export {
|
|
33
36
|
markdownToEditorStateJSON,
|
|
34
37
|
editorStateJSONToMarkdown,
|
|
@@ -53,9 +56,4 @@ export {
|
|
|
53
56
|
} from './RichTextEditorAutoLinkPlugin';
|
|
54
57
|
export type {RichTextEditorAutoLinkPluginProps} from './RichTextEditorAutoLinkPlugin';
|
|
55
58
|
|
|
56
|
-
export {
|
|
57
|
-
sanitizeUrl,
|
|
58
|
-
validateUrl,
|
|
59
|
-
URL_MATCHER,
|
|
60
|
-
EMAIL_MATCHER,
|
|
61
|
-
} from './linkUtils';
|
|
59
|
+
export {sanitizeUrl, validateUrl} from './linkUtils';
|
package/src/linkUtils.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @input Uses only the DOM URL constructor (guarded via try/catch for SSR/edge).
|
|
6
6
|
* @output Exports `sanitizeUrl`, `validateUrl`, and the URL/email matcher regexes
|
|
7
7
|
* used by the AutoLink wiring.
|
|
8
|
-
* @position Experimental (
|
|
8
|
+
* @position Experimental (richtext) helper shared by RichTextEditorToolbar (link
|
|
9
9
|
* button) and the AutoLink matchers in RichTextEditor. Kept dependency-free so
|
|
10
10
|
* both can import it without pulling in extra `@lexical/*` surface.
|
|
11
11
|
*
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file publicSurface.test.ts
|
|
5
|
+
* @input The package entry, packages/richtext/src/index.ts
|
|
6
|
+
* @output Pins the runtime exports of @astryxdesign/richtext to the list
|
|
7
|
+
* spec:AST-061/DEC-8 admits, and the internals it keeps out of the entry.
|
|
8
|
+
* @position Package-level contract test.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {describe, expect, it} from 'vitest';
|
|
12
|
+
// @ts-expect-error Transformer is Lexical's type; import it from @lexical/markdown.
|
|
13
|
+
import type {Transformer as _NotReExported} from './index';
|
|
14
|
+
import * as richtext from './index';
|
|
15
|
+
|
|
16
|
+
describe('@astryxdesign/richtext public surface', () => {
|
|
17
|
+
it('exports exactly what a caller builds with', () => {
|
|
18
|
+
expect(Object.keys(richtext).sort()).toEqual(
|
|
19
|
+
[
|
|
20
|
+
'DEFAULT_LINK_MATCHERS',
|
|
21
|
+
'NEW_TAB_LINK_ATTRIBUTES',
|
|
22
|
+
'RICHTEXT_ICON_KEYS',
|
|
23
|
+
'RichTextEditor',
|
|
24
|
+
'RichTextEditorAutoLinkPlugin',
|
|
25
|
+
'RichTextEditorToolbar',
|
|
26
|
+
'RichTextExtensionError',
|
|
27
|
+
'RichTextView',
|
|
28
|
+
'createRichTextExtension',
|
|
29
|
+
'editorStateJSONToMarkdown',
|
|
30
|
+
'markdownToEditorStateJSON',
|
|
31
|
+
'sanitizeUrl',
|
|
32
|
+
'validateUrl',
|
|
33
|
+
].sort(),
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('keeps the editor theme classes and autolink patterns internal', () => {
|
|
38
|
+
for (const name of ['sharedEditorTheme', 'URL_MATCHER', 'EMAIL_MATCHER']) {
|
|
39
|
+
expect(richtext).not.toHaveProperty(name);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
});
|