@astryxdesign/richtext 0.7.1-canary.3235ec9 → 0.7.1-canary.366aafa
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 +23 -58
- package/dist/RichTextEditor.d.ts +5 -9
- package/dist/RichTextEditor.d.ts.map +1 -1
- package/dist/RichTextEditor.js +5 -9
- package/dist/RichTextEditorAutoLinkPlugin.d.ts +3 -3
- package/dist/RichTextEditorAutoLinkPlugin.js +3 -3
- package/dist/RichTextEditorToolbar.d.ts +3 -3
- package/dist/RichTextEditorToolbar.js +3 -3
- package/dist/RichTextView.d.ts +1 -1
- package/dist/RichTextView.js +1 -1
- package/dist/editorTheme.d.ts.map +1 -1
- package/dist/editorTheme.js +10 -0
- package/dist/linkUtils.js +1 -1
- package/dist/markdownSerializers.d.ts.map +1 -1
- package/dist/markdownSerializers.js +2 -3
- package/dist/richtext.css +1 -0
- package/package.json +5 -9
- package/src/RichTextEditor.doc.mjs +1 -1
- package/src/RichTextEditor.tsx +5 -9
- package/src/RichTextEditorAutoLinkPlugin.tsx +3 -3
- package/src/RichTextEditorToolbar.tsx +3 -3
- package/src/RichTextView.tsx +1 -1
- package/src/__tests__/MarkdownParitySandbox.a11y.chromium.spec.ts +14 -14
- package/src/__tests__/MarkdownPlugins.a11y.chromium.spec.ts +2 -2
- package/src/__tests__/MarkdownPluginsImportExport.a11y.chromium.spec.ts +1 -1
- package/src/__tests__/Playground.a11y.chromium.spec.ts +2 -2
- package/src/__tests__/RichTextEditorToolbar.a11y.chromium.spec.ts +1 -1
- package/src/__tests__/RichTextView.a11y.chromium.spec.ts +1 -1
- package/src/__tests__/TableCellSelection.a11y.chromium.spec.ts +379 -0
- package/src/editorTheme.ts +34 -0
- package/src/linkUtils.ts +1 -1
- package/src/markdownSerializers.ts +2 -3
package/README.md
CHANGED
|
@@ -12,11 +12,15 @@ import {RichTextEditor, RichTextView} from '@astryxdesign/richtext';
|
|
|
12
12
|
|
|
13
13
|
The editor is deliberately minimal and extensible: pass `nodes` and `plugins` to
|
|
14
14
|
layer richer behaviour (toolbars, mentions, hover cards) on top without forking.
|
|
15
|
-
`RichTextEditorToolbar` is a composable formatting toolbar
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
`RichTextEditorToolbar` is a composable formatting toolbar for the editor's
|
|
16
|
+
`toolbar` slot, and `markdownToEditorStateJSON` / `editorStateJSONToMarkdown`
|
|
17
|
+
convert Markdown to and from serialized editor state headlessly (no mounted
|
|
18
|
+
editor required). The server-safe serializers are also available from
|
|
19
|
+
`@astryxdesign/richtext/markdown`.
|
|
20
|
+
|
|
21
|
+
`RichTextView` and core `Markdown` render the same document the same way, and
|
|
22
|
+
Markdown imported into the editor exports back byte for byte when nothing was
|
|
23
|
+
edited.
|
|
20
24
|
|
|
21
25
|
## Built on Lexical
|
|
22
26
|
|
|
@@ -34,66 +38,27 @@ package manager does not add them: install them at that minor alongside
|
|
|
34
38
|
richtext. See the RFC:
|
|
35
39
|
[facebook/astryx#3899](https://github.com/facebook/astryx/issues/3899).
|
|
36
40
|
|
|
37
|
-
|
|
38
|
-
(`latest`) release yet.
|
|
39
|
-
|
|
40
|
-
> Note: this package is the successor to the experimental `RichTextEditor` that
|
|
41
|
-
> used to live in `@astryxdesign/lab`; that code has moved here so it can be
|
|
42
|
-
> canaried independently by an adopting application without a fresh package
|
|
43
|
-
> rollout.
|
|
44
|
-
|
|
45
|
-
## Status
|
|
41
|
+
## Install
|
|
46
42
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
```bash
|
|
44
|
+
npm install @astryxdesign/richtext @astryxdesign/core
|
|
45
|
+
```
|
|
50
46
|
|
|
51
|
-
|
|
47
|
+
Then install every `lexical` and `@lexical/*` package listed in richtext's
|
|
48
|
+
`peerDependencies`, at the range shown there (`npm view @astryxdesign/richtext
|
|
49
|
+
peerDependencies` prints them).
|
|
52
50
|
|
|
53
|
-
|
|
51
|
+
`@astryxdesign/richtext` is released together with `@astryxdesign/core` at the
|
|
52
|
+
same version; install matching versions. `lexical` and the `@lexical/*` packages
|
|
53
|
+
are optional peer dependencies, so a project that only uses the headless
|
|
54
|
+
Markdown serializers installs just those.
|
|
54
55
|
|
|
55
56
|
```tsx
|
|
56
|
-
import {RichTextEditor, RichTextView} from '@astryxdesign/richtext';
|
|
57
57
|
import '@astryxdesign/core/astryx.css';
|
|
58
58
|
import '@astryxdesign/richtext/richtext.css';
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
(`apps/storybook/stories/RichTextEditor.stories.tsx`).
|
|
63
|
-
|
|
64
|
-
### Trying richtext in your own project (canary)
|
|
61
|
+
## Examples
|
|
65
62
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
```bash
|
|
70
|
-
npm install @astryxdesign/richtext@canary @astryxdesign/core@canary
|
|
71
|
-
```
|
|
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
|
-
|
|
77
|
-
> Canary builds track the latest commit on `main` (`0.x.y-canary.<sha>`). They
|
|
78
|
-
> can break between any two versions — pin an exact version if you need
|
|
79
|
-
> stability.
|
|
80
|
-
|
|
81
|
-
## Why no stable release?
|
|
82
|
-
|
|
83
|
-
`package.json` keeps `"private": true` plus an `"astryx": { "canaryOnly": true }`
|
|
84
|
-
marker. The release workflow's stable (`latest`) job skips both private and
|
|
85
|
-
`canaryOnly` packages, while the canary job strips `private` in its ephemeral CI
|
|
86
|
-
checkout only (never in git) to publish the `@canary` tag. The committed
|
|
87
|
-
`private: true` is npm's hard guarantee that no stable publish can ever happen —
|
|
88
|
-
**do not remove it.**
|
|
89
|
-
|
|
90
|
-
## Publishing publicly (when the editor/view are ready)
|
|
91
|
-
|
|
92
|
-
When maintainers are ready to promote richtext to a stable public release:
|
|
93
|
-
|
|
94
|
-
1. Remove `"private": true` **and** the `"astryx": { "canaryOnly": true }`
|
|
95
|
-
marker from `package.json`.
|
|
96
|
-
2. Add a changeset (`pnpm changeset`) selecting `@astryxdesign/richtext` so the
|
|
97
|
-
release workflow versions and publishes it to the `latest` dist-tag.
|
|
98
|
-
3. The stable (`latest`) release job (`.github/workflows/release.yml`) will then
|
|
99
|
-
include richtext on the next release.
|
|
63
|
+
Interactive examples live in Storybook under **RichText/RichTextEditor**
|
|
64
|
+
(`apps/storybook/stories/RichTextEditor.stories.tsx`).
|
package/dist/RichTextEditor.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* top toolbar slot, configurable editable-surface minimum height, and distinct
|
|
8
8
|
* read-only and disabled states that follow prop changes, RichTextEditorProps,
|
|
9
9
|
* RichTextEditorStatus, RichTextEditorStatusType, RichTextEditorSize
|
|
10
|
-
* @position
|
|
10
|
+
* @position @astryxdesign/richtext implementation; consumed by the package index.ts and
|
|
11
11
|
* re-exported from @astryxdesign/richtext. Tested by RichTextEditor.test.tsx.
|
|
12
12
|
*
|
|
13
13
|
* SYNC: When modified, update these files to stay in sync:
|
|
@@ -16,11 +16,8 @@
|
|
|
16
16
|
* - /packages/richtext/src/index.ts (exports if types change)
|
|
17
17
|
* - /apps/storybook/stories/RichTextEditor.stories.tsx (storybook stories)
|
|
18
18
|
*
|
|
19
|
-
* NOTE:
|
|
20
|
-
*
|
|
21
|
-
* OSS Lexical editor RFC; the goal is graduation to @astryxdesign/core after the
|
|
22
|
-
* Component Specification Protocol. `lexical` and `@lexical/*` are OPTIONAL peer
|
|
23
|
-
* dependencies — install them to use this component.
|
|
19
|
+
* NOTE: `lexical` and `@lexical/*` are OPTIONAL peer dependencies — install them to
|
|
20
|
+
* use this component.
|
|
24
21
|
*/
|
|
25
22
|
import { type ReactNode, type Ref } from 'react';
|
|
26
23
|
import { type FieldStatusVariant } from '@astryxdesign/core/Field';
|
|
@@ -243,9 +240,8 @@ export interface RichTextEditorProps extends Omit<BaseProps, 'onChange' | 'defau
|
|
|
243
240
|
}
|
|
244
241
|
/**
|
|
245
242
|
* A WYSIWYG rich-text editor built on Lexical, styled with Astryx design
|
|
246
|
-
* tokens.
|
|
247
|
-
*
|
|
248
|
-
* component.
|
|
243
|
+
* tokens. Ships from `@astryxdesign/richtext`. `lexical` and `@lexical/*` are
|
|
244
|
+
* optional peer dependencies — install them to use this component.
|
|
249
245
|
*
|
|
250
246
|
* The editor is intentionally minimal and extensible: pass `toolbar`, `nodes`,
|
|
251
247
|
* and `plugins` to layer richer behaviour (formatting, mentions, hover cards)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextEditor.d.ts","sourceRoot":"","sources":["../src/RichTextEditor.tsx"],"names":[],"mappings":"AAIA
|
|
1
|
+
{"version":3,"file":"RichTextEditor.d.ts","sourceRoot":"","sources":["../src/RichTextEditor.tsx"],"names":[],"mappings":"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"}
|
package/dist/RichTextEditor.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* top toolbar slot, configurable editable-surface minimum height, and distinct
|
|
12
12
|
* read-only and disabled states that follow prop changes, RichTextEditorProps,
|
|
13
13
|
* RichTextEditorStatus, RichTextEditorStatusType, RichTextEditorSize
|
|
14
|
-
* @position
|
|
14
|
+
* @position @astryxdesign/richtext implementation; consumed by the package index.ts and
|
|
15
15
|
* re-exported from @astryxdesign/richtext. Tested by RichTextEditor.test.tsx.
|
|
16
16
|
*
|
|
17
17
|
* SYNC: When modified, update these files to stay in sync:
|
|
@@ -20,11 +20,8 @@
|
|
|
20
20
|
* - /packages/richtext/src/index.ts (exports if types change)
|
|
21
21
|
* - /apps/storybook/stories/RichTextEditor.stories.tsx (storybook stories)
|
|
22
22
|
*
|
|
23
|
-
* NOTE:
|
|
24
|
-
*
|
|
25
|
-
* OSS Lexical editor RFC; the goal is graduation to @astryxdesign/core after the
|
|
26
|
-
* Component Specification Protocol. `lexical` and `@lexical/*` are OPTIONAL peer
|
|
27
|
-
* dependencies — install them to use this component.
|
|
23
|
+
* NOTE: `lexical` and `@lexical/*` are OPTIONAL peer dependencies — install them to
|
|
24
|
+
* use this component.
|
|
28
25
|
*/
|
|
29
26
|
import { useEffect, useId, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
30
27
|
import * as stylex from '@stylexjs/stylex';
|
|
@@ -144,9 +141,8 @@ const COUNTER_WARNING_THRESHOLD = 0.8;
|
|
|
144
141
|
|
|
145
142
|
/**
|
|
146
143
|
* A WYSIWYG rich-text editor built on Lexical, styled with Astryx design
|
|
147
|
-
* tokens.
|
|
148
|
-
*
|
|
149
|
-
* component.
|
|
144
|
+
* tokens. Ships from `@astryxdesign/richtext`. `lexical` and `@lexical/*` are
|
|
145
|
+
* optional peer dependencies — install them to use this component.
|
|
150
146
|
*
|
|
151
147
|
* The editor is intentionally minimal and extensible: pass `toolbar`, `nodes`,
|
|
152
148
|
* and `plugins` to layer richer behaviour (formatting, mentions, hover cards)
|
|
@@ -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
|
|
8
|
+
* @position @astryxdesign/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
|
*
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
* - /packages/richtext/src/RichTextEditor.test.tsx (tests)
|
|
16
16
|
* - /apps/storybook/stories/RichTextEditor.stories.tsx (story)
|
|
17
17
|
*
|
|
18
|
-
* NOTE:
|
|
19
|
-
*
|
|
18
|
+
* NOTE: `lexical` and `@lexical/*` are OPTIONAL peer dependencies — install them
|
|
19
|
+
* to use this.
|
|
20
20
|
*
|
|
21
21
|
* COMPATIBILITY: the plugin is deliberately a thin pass-through so an
|
|
22
22
|
* application with its own link conventions can adopt it without forking. It
|
|
@@ -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
|
|
12
|
+
* @position @astryxdesign/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
|
*
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
* - /packages/richtext/src/RichTextEditor.test.tsx (tests)
|
|
20
20
|
* - /apps/storybook/stories/RichTextEditor.stories.tsx (story)
|
|
21
21
|
*
|
|
22
|
-
* NOTE:
|
|
23
|
-
*
|
|
22
|
+
* NOTE: `lexical` and `@lexical/*` are OPTIONAL peer dependencies — install them
|
|
23
|
+
* to use this.
|
|
24
24
|
*
|
|
25
25
|
* COMPATIBILITY: the plugin is deliberately a thin pass-through so an
|
|
26
26
|
* application with its own link conventions can adopt it without forking. It
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @output Exports RichTextEditorToolbar (a compact formatting toolbar with a
|
|
8
8
|
* RichText-owned 4px control gutter and horizontally scrollable action row)
|
|
9
9
|
* and RichTextEditorToolbarProps.
|
|
10
|
-
* @position
|
|
10
|
+
* @position @astryxdesign/richtext. Drop into RichTextEditor's `toolbar` slot to
|
|
11
11
|
* add a flush top formatting toolbar. Themed via Astryx Toolbar, Selector,
|
|
12
12
|
* IconButton, and ToggleButton, so it inherits the active theme. Base props
|
|
13
13
|
* pass through to the Astryx Toolbar exactly as Toolbar places them
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
* - /packages/richtext/src/RichTextEditor.test.tsx (tests)
|
|
20
20
|
* - /apps/storybook/stories/RichTextEditor.stories.tsx (WithToolbar story)
|
|
21
21
|
*
|
|
22
|
-
* NOTE:
|
|
23
|
-
*
|
|
22
|
+
* NOTE: `lexical` and `@lexical/*` are OPTIONAL peer dependencies — install them
|
|
23
|
+
* to use this.
|
|
24
24
|
* Behavior mirrors the Lexical playground toolbar (selection sync + format
|
|
25
25
|
* commands); the UI is built from Astryx primitives so it matches the theme.
|
|
26
26
|
*
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* @output Exports RichTextEditorToolbar (a compact formatting toolbar with a
|
|
12
12
|
* RichText-owned 4px control gutter and horizontally scrollable action row)
|
|
13
13
|
* and RichTextEditorToolbarProps.
|
|
14
|
-
* @position
|
|
14
|
+
* @position @astryxdesign/richtext. Drop into RichTextEditor's `toolbar` slot to
|
|
15
15
|
* add a flush top formatting toolbar. Themed via Astryx Toolbar, Selector,
|
|
16
16
|
* IconButton, and ToggleButton, so it inherits the active theme. Base props
|
|
17
17
|
* pass through to the Astryx Toolbar exactly as Toolbar places them
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
* - /packages/richtext/src/RichTextEditor.test.tsx (tests)
|
|
24
24
|
* - /apps/storybook/stories/RichTextEditor.stories.tsx (WithToolbar story)
|
|
25
25
|
*
|
|
26
|
-
* NOTE:
|
|
27
|
-
*
|
|
26
|
+
* NOTE: `lexical` and `@lexical/*` are OPTIONAL peer dependencies — install them
|
|
27
|
+
* to use this.
|
|
28
28
|
* Behavior mirrors the Lexical playground toolbar (selection sync + format
|
|
29
29
|
* commands); the UI is built from Astryx primitives so it matches the theme.
|
|
30
30
|
*
|
package/dist/RichTextView.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @output Exports RichTextView component and RichTextViewProps
|
|
7
7
|
* @position Read-only renderer for serialized Lexical editor state, exposed to
|
|
8
8
|
* assistive technology as document content rather than a form field;
|
|
9
|
-
*
|
|
9
|
+
* exported from @astryxdesign/richtext
|
|
10
10
|
*
|
|
11
11
|
* SYNC: When modified, update these files to stay in sync:
|
|
12
12
|
* - /packages/richtext/src/RichTextEditor.test.tsx
|
package/dist/RichTextView.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* @output Exports RichTextView component and RichTextViewProps
|
|
11
11
|
* @position Read-only renderer for serialized Lexical editor state, exposed to
|
|
12
12
|
* assistive technology as document content rather than a form field;
|
|
13
|
-
*
|
|
13
|
+
* exported from @astryxdesign/richtext
|
|
14
14
|
*
|
|
15
15
|
* SYNC: When modified, update these files to stay in sync:
|
|
16
16
|
* - /packages/richtext/src/RichTextEditor.test.tsx
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editorTheme.d.ts","sourceRoot":"","sources":["../src/editorTheme.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"editorTheme.d.ts","sourceRoot":"","sources":["../src/editorTheme.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,SAAS,CAAC;AAwahD;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,kBAAkB,CAgEtD"}
|
package/dist/editorTheme.js
CHANGED
|
@@ -201,6 +201,13 @@ const editorTheme = {
|
|
|
201
201
|
kMwMTN: "xv1l7n4",
|
|
202
202
|
$$css: true
|
|
203
203
|
},
|
|
204
|
+
tableCellSelected: {
|
|
205
|
+
kMeerF: "xak0ai5",
|
|
206
|
+
k3XXqK: "x9ssot5",
|
|
207
|
+
kjBf7l: "x19bwoy8",
|
|
208
|
+
kInvED: "x1c097ug",
|
|
209
|
+
$$css: true
|
|
210
|
+
},
|
|
204
211
|
code: {
|
|
205
212
|
k1xSpc: "x1lliihq",
|
|
206
213
|
kMv6JI: "x9m5x89",
|
|
@@ -302,6 +309,9 @@ export function sharedEditorTheme() {
|
|
|
302
309
|
tableRow: block(editorTheme.tableRow),
|
|
303
310
|
tableCell: block(editorTheme.tableCell),
|
|
304
311
|
tableCellHeader: block(editorTheme.tableCellHeader),
|
|
312
|
+
// Added on top of the cell's own class by Lexical while the cell is in a
|
|
313
|
+
// table selection, so it carries no direction of its own.
|
|
314
|
+
tableCellSelected: className(editorTheme.tableCellSelected),
|
|
305
315
|
tableScrollableWrapper: block(editorTheme.tableScrollableWrapper)
|
|
306
316
|
};
|
|
307
317
|
}
|
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
|
|
8
|
+
* @position @astryxdesign/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
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdownSerializers.d.ts","sourceRoot":"","sources":["../src/markdownSerializers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"markdownSerializers.d.ts","sourceRoot":"","sources":["../src/markdownSerializers.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAC,KAAK,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAOnD,OAAO,EAAY,KAAK,yBAAyB,EAAC,MAAM,sBAAsB,CAAC;AAC/E,OAAO,KAAK,EAAC,KAAK,EAAE,WAAW,EAAC,MAAM,SAAS,CAAC;AAEhD,yDAAyD;AACzD,MAAM,WAAW,yBAAyB;IACxC;;;;;OAKG;IACH,YAAY,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;IAC1C;;;OAGG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;IAC1C;;;;;OAKG;IACH,UAAU,CAAC,EAAE,aAAa,CAAC,yBAAyB,CAAC,CAAC;CACvD;AAYD;;;;;;;;;;GAUG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,yBAA8B,GACtC,MAAM,CAMR;AAED;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CACvC,eAAe,EAAE,MAAM,EACvB,OAAO,GAAE,yBAA8B,GACtC,MAAM,CAKR"}
|
|
@@ -17,9 +17,8 @@
|
|
|
17
17
|
* - /packages/richtext/src/RichTextEditor.test.tsx (tests)
|
|
18
18
|
*
|
|
19
19
|
* NOTE: `@lexical/headless`, `@lexical/markdown`, and `lexical` are OPTIONAL
|
|
20
|
-
* peer dependencies
|
|
21
|
-
*
|
|
22
|
-
* Node / SSR contexts.
|
|
20
|
+
* peer dependencies. Install them to use these helpers. `@lexical/headless`
|
|
21
|
+
* runs Lexical without a DOM, so these work in Node / SSR contexts.
|
|
23
22
|
*/
|
|
24
23
|
|
|
25
24
|
import { createHeadlessEditor } from '@lexical/headless';
|
package/dist/richtext.css
CHANGED
|
@@ -109,6 +109,7 @@
|
|
|
109
109
|
.x152237o:not(#\#):not(#\#):not(#\#){list-style-type:square}
|
|
110
110
|
.x8yim9t:not(#\#):not(#\#):not(#\#){margin-inline-start:calc(var(--spacing-0))}
|
|
111
111
|
.x19bwoy8:not(#\#):not(#\#):not(#\#){outline-color:var(--focus-outline-color)}
|
|
112
|
+
.x1c097ug:not(#\#):not(#\#):not(#\#){outline-offset:calc(-1 * var(--focus-outline-width))}
|
|
112
113
|
.x1eqjuhu:not(#\#):not(#\#):not(#\#){outline-offset:var(--focus-outline-offset)}
|
|
113
114
|
.x9ssot5:not(#\#):not(#\#):not(#\#){outline-style:var(--focus-outline-style)}
|
|
114
115
|
.xak0ai5:not(#\#):not(#\#):not(#\#){outline-width:var(--focus-outline-width)}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/richtext",
|
|
3
3
|
"displayName": "Rich Text",
|
|
4
|
-
"version": "0.7.1-canary.
|
|
5
|
-
"description": "Astryx rich text — a Lexical-based rich text editor and viewer
|
|
4
|
+
"version": "0.7.1-canary.366aafa",
|
|
5
|
+
"description": "Astryx rich text — a Lexical-based rich text editor and viewer, styled with Astryx design tokens.",
|
|
6
6
|
"author": "Meta Open Source",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"homepage": "https://github.com/facebook/astryx#readme",
|
|
@@ -22,10 +22,6 @@
|
|
|
22
22
|
"lexical",
|
|
23
23
|
"design-system"
|
|
24
24
|
],
|
|
25
|
-
"astryx": {
|
|
26
|
-
"canaryOnly": true,
|
|
27
|
-
"_comment": "Published ONLY to the @canary dist-tag (see .github/workflows/release.yml). Never released as a stable `latest` release. `private: true` is intentional and must stay — it is npm\"s hard guarantee against an accidental stable publish."
|
|
28
|
-
},
|
|
29
25
|
"type": "module",
|
|
30
26
|
"main": "./dist/index.js",
|
|
31
27
|
"types": "./dist/index.d.ts",
|
|
@@ -55,7 +51,7 @@
|
|
|
55
51
|
},
|
|
56
52
|
"peerDependencies": {
|
|
57
53
|
"@stylexjs/stylex": ">=0.10.0",
|
|
58
|
-
"@astryxdesign/core": "0.7.1-canary.
|
|
54
|
+
"@astryxdesign/core": "0.7.1-canary.366aafa",
|
|
59
55
|
"react": ">=19.0.0",
|
|
60
56
|
"react-dom": ">=19.0.0",
|
|
61
57
|
"lexical": "^0.52.0",
|
|
@@ -114,8 +110,8 @@
|
|
|
114
110
|
}
|
|
115
111
|
},
|
|
116
112
|
"devDependencies": {
|
|
117
|
-
"@astryxdesign/a11y-spec": "0.7.1-canary.
|
|
118
|
-
"@astryxdesign/cli": "0.7.1-canary.
|
|
113
|
+
"@astryxdesign/a11y-spec": "0.7.1-canary.366aafa",
|
|
114
|
+
"@astryxdesign/cli": "0.7.1-canary.366aafa",
|
|
119
115
|
"@babel/cli": "^7.29.7",
|
|
120
116
|
"@babel/core": "^7.29.7",
|
|
121
117
|
"@babel/preset-react": "^7.29.7",
|
|
@@ -179,7 +179,7 @@ export const docs = {
|
|
|
179
179
|
},
|
|
180
180
|
usage: {
|
|
181
181
|
description:
|
|
182
|
-
'A WYSIWYG rich-text editor built on Lexical, styled with Astryx design tokens. Its field container shares TextArea input visuals for the resting border, hover ring, focus-within ring, disabled state, and status colors.
|
|
182
|
+
'A WYSIWYG rich-text editor built on Lexical, styled with Astryx design tokens. Its field container shares TextArea input visuals for the resting border, hover ring, focus-within ring, disabled state, and status colors. Ships from @astryxdesign/richtext; lexical and @lexical/* are optional peer dependencies. The editor is deliberately minimal and extensible: pass toolbar, nodes, and plugins to layer richer behaviour (formatting, mentions, hover cards) on top without forking. Use RichTextView to render serialized content read-only.',
|
|
183
183
|
bestPractices: [
|
|
184
184
|
{
|
|
185
185
|
guidance: true,
|
package/src/RichTextEditor.tsx
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* top toolbar slot, configurable editable-surface minimum height, and distinct
|
|
12
12
|
* read-only and disabled states that follow prop changes, RichTextEditorProps,
|
|
13
13
|
* RichTextEditorStatus, RichTextEditorStatusType, RichTextEditorSize
|
|
14
|
-
* @position
|
|
14
|
+
* @position @astryxdesign/richtext implementation; consumed by the package index.ts and
|
|
15
15
|
* re-exported from @astryxdesign/richtext. Tested by RichTextEditor.test.tsx.
|
|
16
16
|
*
|
|
17
17
|
* SYNC: When modified, update these files to stay in sync:
|
|
@@ -20,11 +20,8 @@
|
|
|
20
20
|
* - /packages/richtext/src/index.ts (exports if types change)
|
|
21
21
|
* - /apps/storybook/stories/RichTextEditor.stories.tsx (storybook stories)
|
|
22
22
|
*
|
|
23
|
-
* NOTE:
|
|
24
|
-
*
|
|
25
|
-
* OSS Lexical editor RFC; the goal is graduation to @astryxdesign/core after the
|
|
26
|
-
* Component Specification Protocol. `lexical` and `@lexical/*` are OPTIONAL peer
|
|
27
|
-
* dependencies — install them to use this component.
|
|
23
|
+
* NOTE: `lexical` and `@lexical/*` are OPTIONAL peer dependencies — install them to
|
|
24
|
+
* use this component.
|
|
28
25
|
*/
|
|
29
26
|
|
|
30
27
|
import {
|
|
@@ -473,9 +470,8 @@ export interface RichTextEditorProps extends Omit<
|
|
|
473
470
|
|
|
474
471
|
/**
|
|
475
472
|
* A WYSIWYG rich-text editor built on Lexical, styled with Astryx design
|
|
476
|
-
* tokens.
|
|
477
|
-
*
|
|
478
|
-
* component.
|
|
473
|
+
* tokens. Ships from `@astryxdesign/richtext`. `lexical` and `@lexical/*` are
|
|
474
|
+
* optional peer dependencies — install them to use this component.
|
|
479
475
|
*
|
|
480
476
|
* The editor is intentionally minimal and extensible: pass `toolbar`, `nodes`,
|
|
481
477
|
* and `plugins` to layer richer behaviour (formatting, mentions, hover cards)
|
|
@@ -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
|
|
12
|
+
* @position @astryxdesign/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
|
*
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
* - /packages/richtext/src/RichTextEditor.test.tsx (tests)
|
|
20
20
|
* - /apps/storybook/stories/RichTextEditor.stories.tsx (story)
|
|
21
21
|
*
|
|
22
|
-
* NOTE:
|
|
23
|
-
*
|
|
22
|
+
* NOTE: `lexical` and `@lexical/*` are OPTIONAL peer dependencies — install them
|
|
23
|
+
* to use this.
|
|
24
24
|
*
|
|
25
25
|
* COMPATIBILITY: the plugin is deliberately a thin pass-through so an
|
|
26
26
|
* application with its own link conventions can adopt it without forking. It
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* @output Exports RichTextEditorToolbar (a compact formatting toolbar with a
|
|
12
12
|
* RichText-owned 4px control gutter and horizontally scrollable action row)
|
|
13
13
|
* and RichTextEditorToolbarProps.
|
|
14
|
-
* @position
|
|
14
|
+
* @position @astryxdesign/richtext. Drop into RichTextEditor's `toolbar` slot to
|
|
15
15
|
* add a flush top formatting toolbar. Themed via Astryx Toolbar, Selector,
|
|
16
16
|
* IconButton, and ToggleButton, so it inherits the active theme. Base props
|
|
17
17
|
* pass through to the Astryx Toolbar exactly as Toolbar places them
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
* - /packages/richtext/src/RichTextEditor.test.tsx (tests)
|
|
24
24
|
* - /apps/storybook/stories/RichTextEditor.stories.tsx (WithToolbar story)
|
|
25
25
|
*
|
|
26
|
-
* NOTE:
|
|
27
|
-
*
|
|
26
|
+
* NOTE: `lexical` and `@lexical/*` are OPTIONAL peer dependencies — install them
|
|
27
|
+
* to use this.
|
|
28
28
|
* Behavior mirrors the Lexical playground toolbar (selection sync + format
|
|
29
29
|
* commands); the UI is built from Astryx primitives so it matches the theme.
|
|
30
30
|
*
|
package/src/RichTextView.tsx
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* @output Exports RichTextView component and RichTextViewProps
|
|
11
11
|
* @position Read-only renderer for serialized Lexical editor state, exposed to
|
|
12
12
|
* assistive technology as document content rather than a form field;
|
|
13
|
-
*
|
|
13
|
+
* exported from @astryxdesign/richtext
|
|
14
14
|
*
|
|
15
15
|
* SYNC: When modified, update these files to stay in sync:
|
|
16
16
|
* - /packages/richtext/src/RichTextEditor.test.tsx
|
|
@@ -34,10 +34,10 @@ import {
|
|
|
34
34
|
const OUTPUT = path.resolve('test-results/richtext-markdown-parity');
|
|
35
35
|
|
|
36
36
|
const STORY = {
|
|
37
|
-
sideBySide: '
|
|
38
|
-
toggle: '
|
|
39
|
-
overlay: '
|
|
40
|
-
longDocument: '
|
|
37
|
+
sideBySide: 'richtext-richtexteditor--markdown-parity',
|
|
38
|
+
toggle: 'richtext-richtexteditor--markdown-parity-toggle',
|
|
39
|
+
overlay: 'richtext-richtexteditor--markdown-parity-overlay',
|
|
40
|
+
longDocument: 'richtext-richtexteditor--markdown-parity-long-document',
|
|
41
41
|
} as const;
|
|
42
42
|
|
|
43
43
|
/** The exemptions the repository's Storybook axe audit already makes. */
|
|
@@ -315,7 +315,7 @@ test('a rule at either edge of the document adds no outer margin', async ({
|
|
|
315
315
|
}) => {
|
|
316
316
|
await page.setViewportSize(DESKTOP);
|
|
317
317
|
await page.goto(
|
|
318
|
-
`${storybook.origin}/iframe.html?id=
|
|
318
|
+
`${storybook.origin}/iframe.html?id=richtext-richtexteditor--markdown-serializers&viewMode=story&globals=astryxTheme:neutral;colorMode:light;direction:ltr`,
|
|
319
319
|
{waitUntil: 'load'},
|
|
320
320
|
);
|
|
321
321
|
await page.locator('textarea').fill('---\n\nBetween the rules.\n\n---');
|
|
@@ -542,7 +542,7 @@ test('task items own their checkboxes, keep link tab order, and toggle by keyboa
|
|
|
542
542
|
}) => {
|
|
543
543
|
await page.setViewportSize(DESKTOP);
|
|
544
544
|
await page.goto(
|
|
545
|
-
`${storybook.origin}/iframe.html?id=
|
|
545
|
+
`${storybook.origin}/iframe.html?id=richtext-richtexteditor--markdown-serializers&viewMode=story&globals=astryxTheme:neutral;colorMode:light;direction:ltr`,
|
|
546
546
|
{waitUntil: 'load'},
|
|
547
547
|
);
|
|
548
548
|
await page
|
|
@@ -842,7 +842,7 @@ test('code blocks wrap long lines at phone width and copy from the keyboard', as
|
|
|
842
842
|
await context.grantPermissions(['clipboard-read', 'clipboard-write']);
|
|
843
843
|
await page.setViewportSize(PHONE);
|
|
844
844
|
await page.goto(
|
|
845
|
-
`${storybook.origin}/iframe.html?id=
|
|
845
|
+
`${storybook.origin}/iframe.html?id=richtext-richtexteditor--markdown-serializers&viewMode=story&globals=astryxTheme:neutral;colorMode:light;direction:ltr`,
|
|
846
846
|
{waitUntil: 'load'},
|
|
847
847
|
);
|
|
848
848
|
const token = 'x'.repeat(160);
|
|
@@ -955,7 +955,7 @@ for (const globals of [
|
|
|
955
955
|
test(`list markers cycle by depth (${globals})`, async ({page}) => {
|
|
956
956
|
await page.setViewportSize(DESKTOP);
|
|
957
957
|
await page.goto(
|
|
958
|
-
`${storybook.origin}/iframe.html?id=
|
|
958
|
+
`${storybook.origin}/iframe.html?id=richtext-richtexteditor--markdown-serializers&viewMode=story&globals=astryxTheme:neutral;${globals}`,
|
|
959
959
|
{waitUntil: 'load'},
|
|
960
960
|
);
|
|
961
961
|
const depths = Array.from({length: 9}, (_, depth) => depth);
|
|
@@ -1061,7 +1061,7 @@ test('struck text is a deletion around its other marks, and stays one while edit
|
|
|
1061
1061
|
}) => {
|
|
1062
1062
|
await page.setViewportSize(DESKTOP);
|
|
1063
1063
|
await page.goto(
|
|
1064
|
-
`${storybook.origin}/iframe.html?id=
|
|
1064
|
+
`${storybook.origin}/iframe.html?id=richtext-richtexteditor--markdown-serializers&viewMode=story&globals=astryxTheme:neutral;colorMode:light;direction:ltr`,
|
|
1065
1065
|
{waitUntil: 'load'},
|
|
1066
1066
|
);
|
|
1067
1067
|
await page
|
|
@@ -1292,7 +1292,7 @@ for (const globals of [
|
|
|
1292
1292
|
test('edited code is colored again as it changes', async ({page}) => {
|
|
1293
1293
|
await page.setViewportSize(DESKTOP);
|
|
1294
1294
|
await page.goto(
|
|
1295
|
-
`${storybook.origin}/iframe.html?id=
|
|
1295
|
+
`${storybook.origin}/iframe.html?id=richtext-richtexteditor--markdown-serializers&viewMode=story&globals=astryxTheme:neutral;colorMode:light;direction:ltr`,
|
|
1296
1296
|
{waitUntil: 'load'},
|
|
1297
1297
|
);
|
|
1298
1298
|
await page.locator('textarea').fill('```ts\nlet value = 1;\n```');
|
|
@@ -1330,7 +1330,7 @@ test('bold italic text is emphasis and strong in the editor and the view', async
|
|
|
1330
1330
|
}) => {
|
|
1331
1331
|
await page.setViewportSize(DESKTOP);
|
|
1332
1332
|
await page.goto(
|
|
1333
|
-
`${storybook.origin}/iframe.html?id=
|
|
1333
|
+
`${storybook.origin}/iframe.html?id=richtext-richtexteditor--markdown-serializers&viewMode=story&globals=astryxTheme:neutral;colorMode:light;direction:ltr`,
|
|
1334
1334
|
{waitUntil: 'load'},
|
|
1335
1335
|
);
|
|
1336
1336
|
await page.locator('textarea').fill('Keep ***both*** and **bold** here.');
|
|
@@ -1351,7 +1351,7 @@ test('nested numbered lists keep their start in the editor and the view', async
|
|
|
1351
1351
|
}) => {
|
|
1352
1352
|
await page.setViewportSize(DESKTOP);
|
|
1353
1353
|
await page.goto(
|
|
1354
|
-
`${storybook.origin}/iframe.html?id=
|
|
1354
|
+
`${storybook.origin}/iframe.html?id=richtext-richtexteditor--markdown-serializers&viewMode=story&globals=astryxTheme:neutral;colorMode:light;direction:ltr`,
|
|
1355
1355
|
{waitUntil: 'load'},
|
|
1356
1356
|
);
|
|
1357
1357
|
await page
|
|
@@ -1398,7 +1398,7 @@ for (const viewport of [PHONE, {width: 1280, height: 900}] as const) {
|
|
|
1398
1398
|
}) => {
|
|
1399
1399
|
await page.setViewportSize(viewport);
|
|
1400
1400
|
await page.goto(
|
|
1401
|
-
`${storybook.origin}/iframe.html?id=
|
|
1401
|
+
`${storybook.origin}/iframe.html?id=richtext-richtexteditor--markdown-serializers&viewMode=story&globals=astryxTheme:neutral;${globals}`,
|
|
1402
1402
|
{waitUntil: 'load'},
|
|
1403
1403
|
);
|
|
1404
1404
|
for (const columnCount of [2, 20]) {
|
|
@@ -1870,7 +1870,7 @@ for (const direction of ['ltr', 'rtl'] as const) {
|
|
|
1870
1870
|
}) => {
|
|
1871
1871
|
await page.setViewportSize(DESKTOP);
|
|
1872
1872
|
await page.goto(
|
|
1873
|
-
`${storybook.origin}/iframe.html?id=
|
|
1873
|
+
`${storybook.origin}/iframe.html?id=richtext-richtexteditor--markdown-serializers&viewMode=story&globals=astryxTheme:neutral;colorMode:light;direction:${direction}`,
|
|
1874
1874
|
{waitUntil: 'load'},
|
|
1875
1875
|
);
|
|
1876
1876
|
await page
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @file MarkdownPlugins.a11y.chromium.spec.ts
|
|
5
|
-
* @input The built Storybook's
|
|
5
|
+
* @input The built Storybook's RichText/RichTextEditor "Markdown plugins" story.
|
|
6
6
|
* @output Real-browser proof for spec:AST-064 FR7 and FR8: a plugin node
|
|
7
7
|
* renders the same DOM and accessibility in core Markdown, RichTextView, and
|
|
8
8
|
* RichTextEditor, and the editor moves over, selects, deletes, restores,
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
} from '@astryxdesign/a11y-spec/storybook';
|
|
23
23
|
|
|
24
24
|
const STORYBOOK_DIR = process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR;
|
|
25
|
-
const STORY = '
|
|
25
|
+
const STORY = 'richtext-richtexteditor--markdown-plugins';
|
|
26
26
|
|
|
27
27
|
let storybook: StaticServer;
|
|
28
28
|
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
} from '@astryxdesign/a11y-spec/storybook';
|
|
24
24
|
|
|
25
25
|
const STORYBOOK_DIR = process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR;
|
|
26
|
-
const STORY = '
|
|
26
|
+
const STORY = 'richtext-richtexteditor--markdown-plugins-import-export';
|
|
27
27
|
|
|
28
28
|
let storybook: StaticServer;
|
|
29
29
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @file Playground.a11y.chromium.spec.ts
|
|
5
|
-
* @input The built Storybook's
|
|
5
|
+
* @input The built Storybook's RichText/RichTextEditor "Playground" story.
|
|
6
6
|
* @output Real-browser proof that the playground is ONE editor carrying every
|
|
7
7
|
* feature at once: the seeded document brings every block type, each
|
|
8
8
|
* readout reports that same editor, switching a feature on or off leaves a
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
} from '@astryxdesign/a11y-spec/storybook';
|
|
28
28
|
|
|
29
29
|
const STORYBOOK_DIR = process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR;
|
|
30
|
-
const STORY = '
|
|
30
|
+
const STORY = 'richtext-richtexteditor--playground';
|
|
31
31
|
|
|
32
32
|
/** The one editable surface the whole page is about. */
|
|
33
33
|
const EDITOR = '[data-playground-editor] [role="textbox"]';
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
} from '@astryxdesign/a11y-spec/storybook';
|
|
23
23
|
|
|
24
24
|
const STORYBOOK_DIR = process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR;
|
|
25
|
-
const STORY = '
|
|
25
|
+
const STORY = 'richtext-richtexteditor--with-toolbar';
|
|
26
26
|
|
|
27
27
|
let storybook: StaticServer;
|
|
28
28
|
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
} from '@astryxdesign/a11y-spec/storybook';
|
|
22
22
|
|
|
23
23
|
const STORYBOOK_DIR = process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR;
|
|
24
|
-
const STORY = '
|
|
24
|
+
const STORY = 'richtext-richtexteditor--markdown-serializers';
|
|
25
25
|
const DOCUMENT = [
|
|
26
26
|
'Paragraph text',
|
|
27
27
|
'',
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file TableCellSelection.a11y.chromium.spec.ts
|
|
5
|
+
* @input The built Storybook's Lab/RichTextEditor "Playground" story, whose
|
|
6
|
+
* editor takes a table from the toolbar's insert control.
|
|
7
|
+
* @output Real-browser proof that a table selection is visible: the cells a
|
|
8
|
+
* drag covers are marked and the cells it does not are not, the mark clears
|
|
9
|
+
* the surface it is drawn on in every shipped theme and mode, it costs the
|
|
10
|
+
* cell's own text no contrast, it marks exactly the cells the next keystroke
|
|
11
|
+
* replaces, and it goes when the selection goes.
|
|
12
|
+
*
|
|
13
|
+
* A table selection is made of DOM the engine owns and a class name the theme
|
|
14
|
+
* supplies. Nothing in a unit test can see whether that class was ever named:
|
|
15
|
+
* `addClassNamesToElement(element, theme.tableCellSelected)` is a silent
|
|
16
|
+
* no-op when the slot is undefined, which is how cells in a selection came to
|
|
17
|
+
* be painted exactly like cells outside one. Only a real engine, dragging
|
|
18
|
+
* across real cells, can tell the two apart.
|
|
19
|
+
*
|
|
20
|
+
* The theme sweep is not ceremony. A mark is only visible against the surface
|
|
21
|
+
* it lands on, and a token that clears the surface under one theme can equal
|
|
22
|
+
* it under another: `--color-accent-muted` resolves to the editor field's own
|
|
23
|
+
* colour under Neutral dark, where a background wash would be invisible while
|
|
24
|
+
* every computed-value assertion still passed.
|
|
25
|
+
*
|
|
26
|
+
* Run after building Storybook:
|
|
27
|
+
* pnpm storybook:build
|
|
28
|
+
* pnpm exec playwright test packages/richtext --project chromium
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import {expect, test, type Page} from '@playwright/test';
|
|
32
|
+
import {
|
|
33
|
+
DEFAULT_STORYBOOK_DIR,
|
|
34
|
+
serveStorybook,
|
|
35
|
+
type StaticServer,
|
|
36
|
+
} from '@astryxdesign/a11y-spec/storybook';
|
|
37
|
+
|
|
38
|
+
const STORYBOOK_DIR = process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR;
|
|
39
|
+
const STORY = 'richtext-richtexteditor--playground';
|
|
40
|
+
const EDITOR = '[data-playground-editor] [role="textbox"]';
|
|
41
|
+
const CELLS = `${EDITOR} table th, ${EDITOR} table td`;
|
|
42
|
+
|
|
43
|
+
/** Every shipped theme, in both modes: a mark has to land on all of them. */
|
|
44
|
+
const THEMES = [
|
|
45
|
+
'neutral',
|
|
46
|
+
'stone',
|
|
47
|
+
'butter',
|
|
48
|
+
'chocolate',
|
|
49
|
+
'gothic',
|
|
50
|
+
'matcha',
|
|
51
|
+
'y2k',
|
|
52
|
+
] as const;
|
|
53
|
+
const MODES = ['light', 'dark'] as const;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* WCAG 1.4.11's bar for a non-text indicator. The mark has to clear the
|
|
57
|
+
* surface it is drawn on by at least this much to be a mark at all.
|
|
58
|
+
*/
|
|
59
|
+
const NON_TEXT_CONTRAST = 3;
|
|
60
|
+
|
|
61
|
+
let storybook: StaticServer;
|
|
62
|
+
|
|
63
|
+
test.beforeAll(async () => {
|
|
64
|
+
storybook = await serveStorybook(STORYBOOK_DIR);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test.afterAll(async () => {
|
|
68
|
+
await storybook?.close();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* How a cell is marked, and what its text has to read against: enough to say
|
|
73
|
+
* whether two cells look different, without naming the treatment. A future
|
|
74
|
+
* mark that is a wash rather than a ring is described here just as well.
|
|
75
|
+
*/
|
|
76
|
+
interface CellPaint {
|
|
77
|
+
readonly outline: string;
|
|
78
|
+
readonly background: string;
|
|
79
|
+
/** Contrast of the cell's own text against its own background. */
|
|
80
|
+
readonly textContrast: number;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Opens the story under one theme and mode, with a filled 3×3 table. */
|
|
84
|
+
async function openWithTable(
|
|
85
|
+
page: Page,
|
|
86
|
+
theme: string = 'neutral',
|
|
87
|
+
mode: string = 'light',
|
|
88
|
+
): Promise<string[]> {
|
|
89
|
+
const errors: string[] = [];
|
|
90
|
+
page.on('pageerror', error => errors.push(String(error)));
|
|
91
|
+
page.on('console', message => {
|
|
92
|
+
if (message.type() === 'error' && !message.text().includes('404')) {
|
|
93
|
+
errors.push(message.text());
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
await page.setViewportSize({width: 1440, height: 900});
|
|
97
|
+
await page.goto(
|
|
98
|
+
`${storybook.origin}/iframe.html?id=${STORY}&viewMode=story&globals=astryxTheme:${theme};colorMode:${mode};direction:ltr`,
|
|
99
|
+
{waitUntil: 'load'},
|
|
100
|
+
);
|
|
101
|
+
await expect(page.locator(EDITOR)).toBeVisible();
|
|
102
|
+
|
|
103
|
+
// A table of its own, away from the seeded document, so the cell indices
|
|
104
|
+
// below mean what they say.
|
|
105
|
+
await page.getByRole('button', {name: 'Clear', exact: true}).click();
|
|
106
|
+
await page.locator(EDITOR).click();
|
|
107
|
+
await page.getByRole('button', {name: 'Table', exact: true}).click();
|
|
108
|
+
await expect(page.locator(CELLS)).toHaveCount(9);
|
|
109
|
+
for (const [index, word] of [
|
|
110
|
+
[0, 'Area'],
|
|
111
|
+
[1, 'Owner'],
|
|
112
|
+
[3, 'Sync'],
|
|
113
|
+
[4, 'Platform'],
|
|
114
|
+
] as const) {
|
|
115
|
+
await page.locator(CELLS).nth(index).click();
|
|
116
|
+
await page.keyboard.type(word);
|
|
117
|
+
}
|
|
118
|
+
return errors;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Reads each cell's mark and its text contrast, compositing translucent
|
|
123
|
+
* colours over the first opaque surface behind the table so a measurement is
|
|
124
|
+
* of what a person actually sees, not of a token's nominal value.
|
|
125
|
+
*/
|
|
126
|
+
const paints = (page: Page): Promise<CellPaint[]> =>
|
|
127
|
+
page.$$eval(CELLS, cells => {
|
|
128
|
+
const parse = (value: string): number[] => {
|
|
129
|
+
const parts = (value.match(/[\d.]+/g) ?? []).map(Number);
|
|
130
|
+
return parts.length === 3 ? [...parts, 1] : parts;
|
|
131
|
+
};
|
|
132
|
+
const over = (fg: number[], bg: number[]): number[] =>
|
|
133
|
+
[0, 1, 2].map(i => fg[i] * fg[3] + bg[i] * (1 - fg[3]));
|
|
134
|
+
const channel = (c: number): number => {
|
|
135
|
+
const v = c / 255;
|
|
136
|
+
return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
|
|
137
|
+
};
|
|
138
|
+
const luminance = (c: number[]): number =>
|
|
139
|
+
0.2126 * channel(c[0]) + 0.7152 * channel(c[1]) + 0.0722 * channel(c[2]);
|
|
140
|
+
const contrast = (a: number[], b: number[]): number => {
|
|
141
|
+
const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x);
|
|
142
|
+
return (hi + 0.05) / (lo + 0.05);
|
|
143
|
+
};
|
|
144
|
+
/** The first opaque background behind an element. */
|
|
145
|
+
const backdrop = (el: Element): number[] => {
|
|
146
|
+
let node: Element | null = el.parentElement;
|
|
147
|
+
while (node != null) {
|
|
148
|
+
const parsed = parse(getComputedStyle(node).backgroundColor);
|
|
149
|
+
if (parsed[3] === 1) {
|
|
150
|
+
return parsed;
|
|
151
|
+
}
|
|
152
|
+
node = node.parentElement;
|
|
153
|
+
}
|
|
154
|
+
return [255, 255, 255, 1];
|
|
155
|
+
};
|
|
156
|
+
return cells.map(cell => {
|
|
157
|
+
const style = getComputedStyle(cell);
|
|
158
|
+
const behind = backdrop(cell);
|
|
159
|
+
const own = over(parse(style.backgroundColor), behind);
|
|
160
|
+
return {
|
|
161
|
+
outline: `${style.outlineStyle} ${style.outlineWidth} ${style.outlineColor}`,
|
|
162
|
+
background: style.backgroundColor,
|
|
163
|
+
textContrast: contrast(parse(style.color), own),
|
|
164
|
+
};
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
/** The mark's own contrast against the surface the table sits on. */
|
|
169
|
+
const markContrast = (page: Page): Promise<number> =>
|
|
170
|
+
page.$$eval(CELLS, cells => {
|
|
171
|
+
const parse = (value: string): number[] => {
|
|
172
|
+
const parts = (value.match(/[\d.]+/g) ?? []).map(Number);
|
|
173
|
+
return parts.length === 3 ? [...parts, 1] : parts;
|
|
174
|
+
};
|
|
175
|
+
const over = (fg: number[], bg: number[]): number[] =>
|
|
176
|
+
[0, 1, 2].map(i => fg[i] * fg[3] + bg[i] * (1 - fg[3]));
|
|
177
|
+
const channel = (c: number): number => {
|
|
178
|
+
const v = c / 255;
|
|
179
|
+
return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
|
|
180
|
+
};
|
|
181
|
+
const luminance = (c: number[]): number =>
|
|
182
|
+
0.2126 * channel(c[0]) + 0.7152 * channel(c[1]) + 0.0722 * channel(c[2]);
|
|
183
|
+
const contrast = (a: number[], b: number[]): number => {
|
|
184
|
+
const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x);
|
|
185
|
+
return (hi + 0.05) / (lo + 0.05);
|
|
186
|
+
};
|
|
187
|
+
const backdrop = (el: Element): number[] => {
|
|
188
|
+
let node: Element | null = el.parentElement;
|
|
189
|
+
while (node != null) {
|
|
190
|
+
const parsed = parse(getComputedStyle(node).backgroundColor);
|
|
191
|
+
if (parsed[3] === 1) {
|
|
192
|
+
return parsed;
|
|
193
|
+
}
|
|
194
|
+
node = node.parentElement;
|
|
195
|
+
}
|
|
196
|
+
return [255, 255, 255, 1];
|
|
197
|
+
};
|
|
198
|
+
const selected = cells[0];
|
|
199
|
+
const style = getComputedStyle(selected);
|
|
200
|
+
const behind = backdrop(selected);
|
|
201
|
+
// Whichever way the cell is marked, measure that mark against the
|
|
202
|
+
// surface: the ring if it is ringed, the background if it is washed.
|
|
203
|
+
const mark =
|
|
204
|
+
style.outlineStyle !== 'none' && parseFloat(style.outlineWidth) > 0
|
|
205
|
+
? parse(style.outlineColor)
|
|
206
|
+
: parse(style.backgroundColor);
|
|
207
|
+
return contrast(over(mark, behind), behind);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
const texts = (page: Page): Promise<string[]> =>
|
|
211
|
+
page.$$eval(CELLS, cells =>
|
|
212
|
+
cells.map(cell => cell.textContent?.trim() ?? ''),
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
/** Drags from one cell to another, the gesture that selects a cell range. */
|
|
216
|
+
async function dragAcross(page: Page, from: number, to: number) {
|
|
217
|
+
const start = await page.locator(CELLS).nth(from).boundingBox();
|
|
218
|
+
const end = await page.locator(CELLS).nth(to).boundingBox();
|
|
219
|
+
if (start == null || end == null) {
|
|
220
|
+
throw new Error('a cell has no box');
|
|
221
|
+
}
|
|
222
|
+
await page.mouse.move(start.x + 15, start.y + start.height / 2);
|
|
223
|
+
await page.mouse.down();
|
|
224
|
+
// Past the anchor cell's edge first: the engine starts highlighting once
|
|
225
|
+
// the pointer leaves the cell it went down in.
|
|
226
|
+
await page.mouse.move(start.x + 40, start.y + start.height / 2, {steps: 4});
|
|
227
|
+
await page.mouse.move(end.x + end.width / 2, end.y + end.height / 2, {
|
|
228
|
+
steps: 20,
|
|
229
|
+
});
|
|
230
|
+
await page.mouse.up();
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** Did the selection change how this cell looks? */
|
|
234
|
+
const looksDifferent = (before: CellPaint, after: CellPaint): boolean =>
|
|
235
|
+
before.outline !== after.outline || before.background !== after.background;
|
|
236
|
+
|
|
237
|
+
test('the cells a selection covers are marked, and the rest are not', async ({
|
|
238
|
+
page,
|
|
239
|
+
}) => {
|
|
240
|
+
const errors = await openWithTable(page);
|
|
241
|
+
const before = await paints(page);
|
|
242
|
+
|
|
243
|
+
// The top-left 2×2 block of a 3-column table: cells 0, 1, 3 and 4.
|
|
244
|
+
await dragAcross(page, 0, 4);
|
|
245
|
+
const after = await paints(page);
|
|
246
|
+
|
|
247
|
+
const marked = after
|
|
248
|
+
.map((paint, index) => (looksDifferent(before[index], paint) ? index : -1))
|
|
249
|
+
.filter(index => index !== -1);
|
|
250
|
+
expect(marked, 'the selection marks the 2×2 block it covers').toEqual([
|
|
251
|
+
0, 1, 3, 4,
|
|
252
|
+
]);
|
|
253
|
+
expect(errors).toEqual([]);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
test('the mark is visible against the surface in every theme and mode', async ({
|
|
257
|
+
page,
|
|
258
|
+
}) => {
|
|
259
|
+
const failures: string[] = [];
|
|
260
|
+
for (const theme of THEMES) {
|
|
261
|
+
for (const mode of MODES) {
|
|
262
|
+
await openWithTable(page, theme, mode);
|
|
263
|
+
const before = await paints(page);
|
|
264
|
+
await dragAcross(page, 0, 4);
|
|
265
|
+
const after = await paints(page);
|
|
266
|
+
|
|
267
|
+
// Seen, not merely computed: a mark whose colour equals the surface
|
|
268
|
+
// behind it is a different computed value and no mark at all.
|
|
269
|
+
if (!looksDifferent(before[0], after[0])) {
|
|
270
|
+
failures.push(`${theme}/${mode}: a selected cell looks unchanged`);
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
const contrast = await markContrast(page);
|
|
274
|
+
if (contrast < NON_TEXT_CONTRAST) {
|
|
275
|
+
failures.push(
|
|
276
|
+
`${theme}/${mode}: the mark clears the surface by only ${contrast.toFixed(2)}:1`,
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
// And the mark costs the cell's own text nothing: a wash drawn behind
|
|
280
|
+
// the text would show up here as a drop.
|
|
281
|
+
if (after[0].textContrast < before[0].textContrast - 0.01) {
|
|
282
|
+
failures.push(
|
|
283
|
+
`${theme}/${mode}: selecting drops header text from ${before[0].textContrast.toFixed(2)}:1 to ${after[0].textContrast.toFixed(2)}:1`,
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
expect(failures).toEqual([]);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
test('the mark marks exactly the cells the next keystroke replaces', async ({
|
|
292
|
+
page,
|
|
293
|
+
}) => {
|
|
294
|
+
const errors = await openWithTable(page);
|
|
295
|
+
const before = await paints(page);
|
|
296
|
+
const filled = (await texts(page))
|
|
297
|
+
.map((text, index) => (text === '' ? -1 : index))
|
|
298
|
+
.filter(index => index !== -1);
|
|
299
|
+
|
|
300
|
+
await dragAcross(page, 0, 4);
|
|
301
|
+
const marked = (await paints(page))
|
|
302
|
+
.map((paint, index) => (looksDifferent(before[index], paint) ? index : -1))
|
|
303
|
+
.filter(index => index !== -1);
|
|
304
|
+
|
|
305
|
+
await page.keyboard.press('Backspace');
|
|
306
|
+
const emptied = (await texts(page))
|
|
307
|
+
.map((text, index) => (text === '' ? index : -1))
|
|
308
|
+
.filter(index => index !== -1 && filled.includes(index));
|
|
309
|
+
|
|
310
|
+
expect(emptied, 'the keystroke emptied the cells that were marked').toEqual(
|
|
311
|
+
marked.filter(index => filled.includes(index)),
|
|
312
|
+
);
|
|
313
|
+
expect(emptied.length, 'the keystroke emptied something').toBeGreaterThan(0);
|
|
314
|
+
expect(errors).toEqual([]);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
test('the mark goes when the selection goes', async ({page}) => {
|
|
318
|
+
const errors = await openWithTable(page);
|
|
319
|
+
const before = await paints(page);
|
|
320
|
+
|
|
321
|
+
await dragAcross(page, 0, 4);
|
|
322
|
+
expect(looksDifferent(before[0], (await paints(page))[0])).toBe(true);
|
|
323
|
+
|
|
324
|
+
// A caret in one cell is not a cell selection.
|
|
325
|
+
await page.locator(CELLS).nth(8).click();
|
|
326
|
+
await expect
|
|
327
|
+
.poll(async () => {
|
|
328
|
+
const now = await paints(page);
|
|
329
|
+
return now.filter((paint, index) => looksDifferent(before[index], paint))
|
|
330
|
+
.length;
|
|
331
|
+
})
|
|
332
|
+
.toBe(0);
|
|
333
|
+
expect(errors).toEqual([]);
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
test('a read surface marks a dragged selection the same way', async ({
|
|
337
|
+
page,
|
|
338
|
+
}) => {
|
|
339
|
+
// Lexical's table pointer handler does not ask whether the surface is
|
|
340
|
+
// editable, so a read surface makes cell selections too — and a person
|
|
341
|
+
// selecting cells there is about to copy them, so the mark belongs. Held
|
|
342
|
+
// because the two surfaces must render the same document the same way:
|
|
343
|
+
// marking only one of them would be the drift this spec exists to catch.
|
|
344
|
+
const errors = await openWithTable(page);
|
|
345
|
+
await page.getByRole('tab', {name: 'RichTextView'}).click();
|
|
346
|
+
|
|
347
|
+
const VIEW =
|
|
348
|
+
'[data-playground-output="view"] table th, [data-playground-output="view"] table td';
|
|
349
|
+
await expect(page.locator(VIEW)).toHaveCount(9);
|
|
350
|
+
const outlines = () =>
|
|
351
|
+
page.$$eval(VIEW, cells =>
|
|
352
|
+
cells.map(cell => {
|
|
353
|
+
const style = getComputedStyle(cell);
|
|
354
|
+
return `${style.outlineStyle} ${style.outlineWidth}`;
|
|
355
|
+
}),
|
|
356
|
+
);
|
|
357
|
+
const before = await outlines();
|
|
358
|
+
expect(new Set(before).size, 'nothing is marked before a drag').toBe(1);
|
|
359
|
+
|
|
360
|
+
const start = await page.locator(VIEW).nth(0).boundingBox();
|
|
361
|
+
const end = await page.locator(VIEW).nth(4).boundingBox();
|
|
362
|
+
if (start == null || end == null) {
|
|
363
|
+
throw new Error('a cell has no box');
|
|
364
|
+
}
|
|
365
|
+
await page.mouse.move(start.x + 10, start.y + start.height / 2);
|
|
366
|
+
await page.mouse.down();
|
|
367
|
+
await page.mouse.move(start.x + 30, start.y + start.height / 2, {steps: 4});
|
|
368
|
+
await page.mouse.move(end.x + end.width / 2, end.y + end.height / 2, {
|
|
369
|
+
steps: 20,
|
|
370
|
+
});
|
|
371
|
+
await page.mouse.up();
|
|
372
|
+
|
|
373
|
+
await expect
|
|
374
|
+
.poll(
|
|
375
|
+
async () => (await outlines()).filter((o, i) => o !== before[i]).length,
|
|
376
|
+
)
|
|
377
|
+
.toBeGreaterThan(0);
|
|
378
|
+
expect(errors).toEqual([]);
|
|
379
|
+
});
|
package/src/editorTheme.ts
CHANGED
|
@@ -340,6 +340,37 @@ const editorTheme = stylex.create({
|
|
|
340
340
|
fontWeight: fontWeightVars['--font-weight-semibold'],
|
|
341
341
|
color: colorVars['--color-text-secondary'],
|
|
342
342
|
},
|
|
343
|
+
// Cells in a table selection — dragging across cells, Shift+arrow between
|
|
344
|
+
// them, or selecting a row or column — are ringed, for the reason
|
|
345
|
+
// `hrSelected` gives: a person has to see what the next keystroke will
|
|
346
|
+
// replace. Lexical names this class on every highlighted cell and takes it
|
|
347
|
+
// off when the selection goes; left unnamed, a cell inside the selection is
|
|
348
|
+
// painted exactly like one outside it.
|
|
349
|
+
//
|
|
350
|
+
// A ring, not a background wash. A wash sits behind the cell's text and
|
|
351
|
+
// eats into its contrast, and no one token stays clear of the field in
|
|
352
|
+
// every theme: `--color-accent-muted` resolves to the field's own colour
|
|
353
|
+
// under Neutral dark, so the selection would be invisible there, and a
|
|
354
|
+
// 10% accent tint drops Neutral dark's header text from 5.65:1 to 4.25:1.
|
|
355
|
+
// The focus ring is drawn for exactly this job — it clears the field by
|
|
356
|
+
// 5.24:1 at worst across every shipped theme and mode — and sits beside
|
|
357
|
+
// the text rather than behind it, so no cell's contrast moves at all.
|
|
358
|
+
// `outline` takes no space, so the document's geometry is untouched
|
|
359
|
+
// (spec:AST-061 FR9), and the inset offset keeps each ring inside its own
|
|
360
|
+
// cell instead of bleeding over the neighbour it is not marking.
|
|
361
|
+
//
|
|
362
|
+
// `RichTextView` and a read-only editor ring a dragged cell selection too:
|
|
363
|
+
// Lexical's table pointer handler does not ask whether the surface is
|
|
364
|
+
// editable, and a person selects cells in a read surface to copy them, so
|
|
365
|
+
// seeing the selection is as right there. Both surfaces draw the same ring
|
|
366
|
+
// and neither moves a block, so they still render the same document the
|
|
367
|
+
// same way.
|
|
368
|
+
tableCellSelected: {
|
|
369
|
+
outlineWidth: focusVars['--focus-outline-width'],
|
|
370
|
+
outlineStyle: focusVars['--focus-outline-style'],
|
|
371
|
+
outlineColor: focusVars['--focus-outline-color'],
|
|
372
|
+
outlineOffset: `calc(-1 * ${focusVars['--focus-outline-width']})`,
|
|
373
|
+
},
|
|
343
374
|
// Thematic breaks, drawn like core Markdown's rule. A rule is a decorator,
|
|
344
375
|
// and Lexical puts a zero-size caret boundary element beside a decorator at
|
|
345
376
|
// either edge of the document, so a rule there is not literally the first
|
|
@@ -481,6 +512,9 @@ export function sharedEditorTheme(): EditorThemeClasses {
|
|
|
481
512
|
tableRow: block(editorTheme.tableRow),
|
|
482
513
|
tableCell: block(editorTheme.tableCell),
|
|
483
514
|
tableCellHeader: block(editorTheme.tableCellHeader),
|
|
515
|
+
// Added on top of the cell's own class by Lexical while the cell is in a
|
|
516
|
+
// table selection, so it carries no direction of its own.
|
|
517
|
+
tableCellSelected: className(editorTheme.tableCellSelected),
|
|
484
518
|
tableScrollableWrapper: block(editorTheme.tableScrollableWrapper),
|
|
485
519
|
};
|
|
486
520
|
}
|
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
|
|
8
|
+
* @position @astryxdesign/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
|
*
|
|
@@ -17,9 +17,8 @@
|
|
|
17
17
|
* - /packages/richtext/src/RichTextEditor.test.tsx (tests)
|
|
18
18
|
*
|
|
19
19
|
* NOTE: `@lexical/headless`, `@lexical/markdown`, and `lexical` are OPTIONAL
|
|
20
|
-
* peer dependencies
|
|
21
|
-
*
|
|
22
|
-
* Node / SSR contexts.
|
|
20
|
+
* peer dependencies. Install them to use these helpers. `@lexical/headless`
|
|
21
|
+
* runs Lexical without a DOM, so these work in Node / SSR contexts.
|
|
23
22
|
*/
|
|
24
23
|
|
|
25
24
|
import {createHeadlessEditor} from '@lexical/headless';
|