@astryxdesign/richtext 0.7.1-canary.4a14542 → 0.7.1-canary.4eaefd4
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 +32 -56
- package/astryx.integration.mjs +1 -1
- 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 +12 -1
- package/dist/linkUtils.js +1 -1
- package/dist/markdownSerializers.d.ts.map +1 -1
- package/dist/markdownSerializers.js +2 -3
- package/dist/richtext.css +4 -1
- package/package.json +8 -10
- 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 +40 -23
- 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 +38 -2
- 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,38 @@ 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.
|
|
41
|
+
## Install
|
|
44
42
|
|
|
45
|
-
|
|
43
|
+
```bash
|
|
44
|
+
npm install @astryxdesign/richtext @astryxdesign/core
|
|
45
|
+
```
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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).
|
|
50
50
|
|
|
51
|
-
|
|
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.
|
|
52
55
|
|
|
53
|
-
|
|
56
|
+
RichText ships prebuilt CSS and JS, like `@astryxdesign/core`: import its
|
|
57
|
+
stylesheet beside Core's and your theme's, with no StyleX or Babel setup. Never
|
|
58
|
+
compile richtext's source.
|
|
54
59
|
|
|
55
60
|
```tsx
|
|
56
|
-
import
|
|
61
|
+
import '@astryxdesign/core/reset.css';
|
|
57
62
|
import '@astryxdesign/core/astryx.css';
|
|
63
|
+
import '@astryxdesign/theme-neutral/theme.css'; // or your theme's CSS
|
|
58
64
|
import '@astryxdesign/richtext/richtext.css';
|
|
59
65
|
```
|
|
60
66
|
|
|
61
|
-
|
|
62
|
-
(`
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
`richtext.css` emits into `@layer astryx-base`, the layer `astryx.css` opens,
|
|
68
|
+
so your theme's token overrides (`@layer astryx-theme`) win over it, as long
|
|
69
|
+
as Core's `reset.css` (or a `@layer reset, astryx-base, astryx-theme;` line,
|
|
70
|
+
if your app has its own reset) loads first.
|
|
65
71
|
|
|
66
|
-
|
|
67
|
-
you must request that tag explicitly. There is no `latest` version to install.
|
|
72
|
+
## Examples
|
|
68
73
|
|
|
69
|
-
|
|
70
|
-
|
|
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.
|
|
74
|
+
Interactive examples live in Storybook under **RichText/RichTextEditor**
|
|
75
|
+
(`apps/storybook/stories/RichTextEditor.stories.tsx`).
|
package/astryx.integration.mjs
CHANGED
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":"AAIA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAOL,KAAK,SAAS,EACd,KAAK,GAAG,EACT,MAAM,OAAO,CAAC;AASf,OAAO,EAML,KAAK,kBAAkB,EACxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAIlD,OAAO,EAAyB,KAAK,SAAS,EAAC,MAAM,0BAA0B,CAAC;AAqBhF,OAAO,KAAK,EAAC,yBAAyB,EAAC,MAAM,sBAAsB,CAAC;AAEpE,OAAO,EAAC,KAAK,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAKnD,OAAO,EASL,KAAK,WAAW,EAChB,KAAK,KAAK,EACV,KAAK,aAAa,EAClB,KAAK,WAAW,EAEjB,MAAM,SAAS,CAAC;AAwJjB,MAAM,MAAM,wBAAwB,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;AAEvE,MAAM,MAAM,kBAAkB,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAEpD,MAAM,WAAW,oBAAoB;IACnC,qCAAqC;IACrC,IAAI,EAAE,wBAAwB,CAAC;IAC/B,oDAAoD;IACpD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB;;;OAGG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,6EAA6E;IAC7E,cAAc,EAAE,MAAM,WAAW,CAAC;IAClC;;;;;;;OAOG;IACH,WAAW,EAAE,MAAM,MAAM,CAAC;IAC1B;;;;OAIG;IACH,OAAO,EAAE,MAAM,MAAM,CAAC;IACtB;;;OAGG;IACH,SAAS,EAAE,MAAM,aAAa,CAAC;CAChC;AAED,MAAM,WAAW,mBAAoB,SAAQ,IAAI,CAC/C,SAAS,EACT,UAAU,GAAG,cAAc,CAC5B;IACC;;;;OAIG;IACH,GAAG,CAAC,EAAE,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAC7B,qEAAqE;IACrE,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,+DAA+D;IAC/D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,CAAC,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,KAAK,IAAI,CAAC;IACrE,uDAAuD;IACvD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,MAAM,CAAC,EAAE,oBAAoB,CAAC;IAC9B;;;;;;;;OAQG;IACH,aAAa,CAAC,EAAE,kBAAkB,CAAC;IACnC;;;OAGG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB;;;;OAIG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,uEAAuE;IACvE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,IAAI,CAAC,EAAE,kBAAkB,CAAC;IAC1B;;;;OAIG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;IAC1C;;;;;OAKG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB;;;;OAIG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB;;;;;OAKG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B;;;;;;;;;;;;;;;;;OAiBG;IACH,YAAY,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;IAC1C;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,cAAc;4YAgCxB,mBAAmB;;CAoPrB,CAAC"}
|
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",
|
|
@@ -221,7 +228,8 @@ const editorTheme = {
|
|
|
221
228
|
keoZOQ: "x1w2a574 xnhvf09",
|
|
222
229
|
k1K539: "x1u2y747 xfo59cc",
|
|
223
230
|
khDVqt: "x126k92a",
|
|
224
|
-
|
|
231
|
+
kTgw9: "x1yn0g08",
|
|
232
|
+
kHjlTd: "x1mzt3pk",
|
|
225
233
|
$$css: true
|
|
226
234
|
}
|
|
227
235
|
};
|
|
@@ -301,6 +309,9 @@ export function sharedEditorTheme() {
|
|
|
301
309
|
tableRow: block(editorTheme.tableRow),
|
|
302
310
|
tableCell: block(editorTheme.tableCell),
|
|
303
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),
|
|
304
315
|
tableScrollableWrapper: block(editorTheme.tableScrollableWrapper)
|
|
305
316
|
};
|
|
306
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
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/* Astryx Rich Text Pre-compiled StyleX CSS — Lexical editor and viewer */
|
|
2
2
|
/* Auto-generated. Do not edit manually. */
|
|
3
3
|
|
|
4
|
+
@layer reset, astryx-base, astryx-theme;
|
|
5
|
+
|
|
4
6
|
@layer astryx-base {
|
|
5
7
|
@property --x-left { syntax: "*"; inherits: false;}
|
|
6
8
|
@property --x-minHeight { syntax: "*"; inherits: false;}
|
|
@@ -109,10 +111,10 @@
|
|
|
109
111
|
.x152237o:not(#\#):not(#\#):not(#\#){list-style-type:square}
|
|
110
112
|
.x8yim9t:not(#\#):not(#\#):not(#\#){margin-inline-start:calc(var(--spacing-0))}
|
|
111
113
|
.x19bwoy8:not(#\#):not(#\#):not(#\#){outline-color:var(--focus-outline-color)}
|
|
114
|
+
.x1c097ug:not(#\#):not(#\#):not(#\#){outline-offset:calc(-1 * var(--focus-outline-width))}
|
|
112
115
|
.x1eqjuhu:not(#\#):not(#\#):not(#\#){outline-offset:var(--focus-outline-offset)}
|
|
113
116
|
.x9ssot5:not(#\#):not(#\#):not(#\#){outline-style:var(--focus-outline-style)}
|
|
114
117
|
.xak0ai5:not(#\#):not(#\#):not(#\#){outline-width:var(--focus-outline-width)}
|
|
115
|
-
.xj0a0fe:not(#\#):not(#\#):not(#\#){overflow-wrap:anywhere}
|
|
116
118
|
.x1mzt3pk:not(#\#):not(#\#):not(#\#){overflow-wrap:break-word}
|
|
117
119
|
.xp74n0j:not(#\#):not(#\#):not(#\#){padding-inline-end:calc(var(--spacing-2) + var(--spacing-6))}
|
|
118
120
|
.xbj1ybn:not(#\#):not(#\#):not(#\#){padding-inline-start:calc(var(--spacing-0))}
|
|
@@ -129,6 +131,7 @@
|
|
|
129
131
|
.xxymvpz:not(#\#):not(#\#):not(#\#){vertical-align:middle}
|
|
130
132
|
.xuxw1ft:not(#\#):not(#\#):not(#\#){white-space:nowrap}
|
|
131
133
|
.x126k92a:not(#\#):not(#\#):not(#\#){white-space:pre-wrap}
|
|
134
|
+
.x1yn0g08:not(#\#):not(#\#):not(#\#){word-break:break-all}
|
|
132
135
|
.x1vjfegm:not(#\#):not(#\#):not(#\#){z-index:1}
|
|
133
136
|
.x16khyan:is(:disabled,[aria-disabled="true"]):not(#\#):not(#\#):not(#\#){cursor:default}
|
|
134
137
|
.x2i8j16:is([data-richtext-task]):not(#\#):not(#\#):not(#\#){list-style-type:none}
|
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.4eaefd4",
|
|
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,14 +22,12 @@
|
|
|
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",
|
|
32
|
-
"sideEffects":
|
|
28
|
+
"sideEffects": [
|
|
29
|
+
"**/*.css"
|
|
30
|
+
],
|
|
33
31
|
"files": [
|
|
34
32
|
"astryx.integration.mjs",
|
|
35
33
|
"blocks",
|
|
@@ -55,7 +53,7 @@
|
|
|
55
53
|
},
|
|
56
54
|
"peerDependencies": {
|
|
57
55
|
"@stylexjs/stylex": ">=0.10.0",
|
|
58
|
-
"@astryxdesign/core": "0.7.1-canary.
|
|
56
|
+
"@astryxdesign/core": "0.7.1-canary.4eaefd4",
|
|
59
57
|
"react": ">=19.0.0",
|
|
60
58
|
"react-dom": ">=19.0.0",
|
|
61
59
|
"lexical": "^0.52.0",
|
|
@@ -114,8 +112,8 @@
|
|
|
114
112
|
}
|
|
115
113
|
},
|
|
116
114
|
"devDependencies": {
|
|
117
|
-
"@astryxdesign/a11y-spec": "0.7.1-canary.
|
|
118
|
-
"@astryxdesign/cli": "0.7.1-canary.
|
|
115
|
+
"@astryxdesign/a11y-spec": "0.7.1-canary.4eaefd4",
|
|
116
|
+
"@astryxdesign/cli": "0.7.1-canary.4eaefd4",
|
|
119
117
|
"@babel/cli": "^7.29.7",
|
|
120
118
|
"@babel/core": "^7.29.7",
|
|
121
119
|
"@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
|
|
@@ -670,9 +670,8 @@ test('task items own their checkboxes, keep link tab order, and toggle by keyboa
|
|
|
670
670
|
// both surfaces, so the code sits at the same place; the header is not part
|
|
671
671
|
// of the editable text.
|
|
672
672
|
/**
|
|
673
|
-
* Whether core Markdown scrolls a fence's lines sideways.
|
|
674
|
-
*
|
|
675
|
-
* a fence whose lines do not fit is taller in RichText by its wrapped lines.
|
|
673
|
+
* Whether core Markdown scrolls a fence's lines sideways. Under spec:AST-061
|
|
674
|
+
* FR5 / DEC-9 it never does: both surfaces wrap long code lines.
|
|
676
675
|
*/
|
|
677
676
|
async function markdownFenceScrolls(page: Page, key: string): Promise<boolean> {
|
|
678
677
|
return page.evaluate(
|
|
@@ -695,12 +694,12 @@ for (const viewport of [PHONE, DESKTOP, {width: 2200, height: 900}] as const) {
|
|
|
695
694
|
await waitForDocument(page, RICH_TEXT);
|
|
696
695
|
const markdown = await surfaceGeometry(page, MARKDOWN);
|
|
697
696
|
const richText = await surfaceGeometry(page, RICH_TEXT);
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
expect(
|
|
702
|
-
|
|
703
|
-
)
|
|
697
|
+
// Fenced code wraps on both surfaces (spec:AST-061 FR5, DEC-9): no fence
|
|
698
|
+
// scrolls sideways.
|
|
699
|
+
for (const key of ['code-fence', 'code-long']) {
|
|
700
|
+
expect(await markdownFenceScrolls(page, key), `${key} scrolls`).toBe(
|
|
701
|
+
false,
|
|
702
|
+
);
|
|
704
703
|
}
|
|
705
704
|
// Each frame is sized like core Markdown's: as wide as its longest line,
|
|
706
705
|
// at least the 680px measure (or the whole width when narrower), and no
|
|
@@ -747,6 +746,24 @@ for (const viewport of [PHONE, DESKTOP, {width: 2200, height: 900}] as const) {
|
|
|
747
746
|
keys: ['code-fence', 'code-plain', 'code-unknown', 'code-long'],
|
|
748
747
|
},
|
|
749
748
|
);
|
|
749
|
+
// The editor's frame is 18px narrower than the reader's at every width
|
|
750
|
+
// (the field inset). Above phone width `code-long` still wraps to the same
|
|
751
|
+
// number of lines on both surfaces (two at 1440px), so the block is as
|
|
752
|
+
// tall in read as in edit mode (DEC-9). At phone width it takes one more
|
|
753
|
+
// line in the editor: the known editor-frame gap that AST-061's
|
|
754
|
+
// Current-state impact records, so the check skips that width.
|
|
755
|
+
if (viewport.width !== PHONE.width) {
|
|
756
|
+
for (const key of ['code-fence', 'code-long']) {
|
|
757
|
+
const block = (geometry: SurfaceGeometry) =>
|
|
758
|
+
geometry.blocks.find(candidate => candidate.key === key);
|
|
759
|
+
expect(
|
|
760
|
+
Math.abs(
|
|
761
|
+
(block(richText)?.height ?? 0) - (block(markdown)?.height ?? 0),
|
|
762
|
+
),
|
|
763
|
+
`${key} height`,
|
|
764
|
+
).toBeLessThanOrEqual(2);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
750
767
|
for (const frame of frames) {
|
|
751
768
|
if (frame.key === 'code-long') {
|
|
752
769
|
// A long line widens the frame past the measure, up to the room.
|
|
@@ -825,7 +842,7 @@ test('code blocks wrap long lines at phone width and copy from the keyboard', as
|
|
|
825
842
|
await context.grantPermissions(['clipboard-read', 'clipboard-write']);
|
|
826
843
|
await page.setViewportSize(PHONE);
|
|
827
844
|
await page.goto(
|
|
828
|
-
`${storybook.origin}/iframe.html?id=
|
|
845
|
+
`${storybook.origin}/iframe.html?id=richtext-richtexteditor--markdown-serializers&viewMode=story&globals=astryxTheme:neutral;colorMode:light;direction:ltr`,
|
|
829
846
|
{waitUntil: 'load'},
|
|
830
847
|
);
|
|
831
848
|
const token = 'x'.repeat(160);
|
|
@@ -938,7 +955,7 @@ for (const globals of [
|
|
|
938
955
|
test(`list markers cycle by depth (${globals})`, async ({page}) => {
|
|
939
956
|
await page.setViewportSize(DESKTOP);
|
|
940
957
|
await page.goto(
|
|
941
|
-
`${storybook.origin}/iframe.html?id=
|
|
958
|
+
`${storybook.origin}/iframe.html?id=richtext-richtexteditor--markdown-serializers&viewMode=story&globals=astryxTheme:neutral;${globals}`,
|
|
942
959
|
{waitUntil: 'load'},
|
|
943
960
|
);
|
|
944
961
|
const depths = Array.from({length: 9}, (_, depth) => depth);
|
|
@@ -1044,7 +1061,7 @@ test('struck text is a deletion around its other marks, and stays one while edit
|
|
|
1044
1061
|
}) => {
|
|
1045
1062
|
await page.setViewportSize(DESKTOP);
|
|
1046
1063
|
await page.goto(
|
|
1047
|
-
`${storybook.origin}/iframe.html?id=
|
|
1064
|
+
`${storybook.origin}/iframe.html?id=richtext-richtexteditor--markdown-serializers&viewMode=story&globals=astryxTheme:neutral;colorMode:light;direction:ltr`,
|
|
1048
1065
|
{waitUntil: 'load'},
|
|
1049
1066
|
);
|
|
1050
1067
|
await page
|
|
@@ -1275,7 +1292,7 @@ for (const globals of [
|
|
|
1275
1292
|
test('edited code is colored again as it changes', async ({page}) => {
|
|
1276
1293
|
await page.setViewportSize(DESKTOP);
|
|
1277
1294
|
await page.goto(
|
|
1278
|
-
`${storybook.origin}/iframe.html?id=
|
|
1295
|
+
`${storybook.origin}/iframe.html?id=richtext-richtexteditor--markdown-serializers&viewMode=story&globals=astryxTheme:neutral;colorMode:light;direction:ltr`,
|
|
1279
1296
|
{waitUntil: 'load'},
|
|
1280
1297
|
);
|
|
1281
1298
|
await page.locator('textarea').fill('```ts\nlet value = 1;\n```');
|
|
@@ -1313,7 +1330,7 @@ test('bold italic text is emphasis and strong in the editor and the view', async
|
|
|
1313
1330
|
}) => {
|
|
1314
1331
|
await page.setViewportSize(DESKTOP);
|
|
1315
1332
|
await page.goto(
|
|
1316
|
-
`${storybook.origin}/iframe.html?id=
|
|
1333
|
+
`${storybook.origin}/iframe.html?id=richtext-richtexteditor--markdown-serializers&viewMode=story&globals=astryxTheme:neutral;colorMode:light;direction:ltr`,
|
|
1317
1334
|
{waitUntil: 'load'},
|
|
1318
1335
|
);
|
|
1319
1336
|
await page.locator('textarea').fill('Keep ***both*** and **bold** here.');
|
|
@@ -1334,7 +1351,7 @@ test('nested numbered lists keep their start in the editor and the view', async
|
|
|
1334
1351
|
}) => {
|
|
1335
1352
|
await page.setViewportSize(DESKTOP);
|
|
1336
1353
|
await page.goto(
|
|
1337
|
-
`${storybook.origin}/iframe.html?id=
|
|
1354
|
+
`${storybook.origin}/iframe.html?id=richtext-richtexteditor--markdown-serializers&viewMode=story&globals=astryxTheme:neutral;colorMode:light;direction:ltr`,
|
|
1338
1355
|
{waitUntil: 'load'},
|
|
1339
1356
|
);
|
|
1340
1357
|
await page
|
|
@@ -1381,7 +1398,7 @@ for (const viewport of [PHONE, {width: 1280, height: 900}] as const) {
|
|
|
1381
1398
|
}) => {
|
|
1382
1399
|
await page.setViewportSize(viewport);
|
|
1383
1400
|
await page.goto(
|
|
1384
|
-
`${storybook.origin}/iframe.html?id=
|
|
1401
|
+
`${storybook.origin}/iframe.html?id=richtext-richtexteditor--markdown-serializers&viewMode=story&globals=astryxTheme:neutral;${globals}`,
|
|
1385
1402
|
{waitUntil: 'load'},
|
|
1386
1403
|
);
|
|
1387
1404
|
for (const columnCount of [2, 20]) {
|
|
@@ -1853,7 +1870,7 @@ for (const direction of ['ltr', 'rtl'] as const) {
|
|
|
1853
1870
|
}) => {
|
|
1854
1871
|
await page.setViewportSize(DESKTOP);
|
|
1855
1872
|
await page.goto(
|
|
1856
|
-
`${storybook.origin}/iframe.html?id=
|
|
1873
|
+
`${storybook.origin}/iframe.html?id=richtext-richtexteditor--markdown-serializers&viewMode=story&globals=astryxTheme:neutral;colorMode:light;direction:${direction}`,
|
|
1857
1874
|
{waitUntil: 'load'},
|
|
1858
1875
|
);
|
|
1859
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
|
|
@@ -410,9 +441,11 @@ const editorTheme = stylex.create({
|
|
|
410
441
|
default: WIDE_BLOCK_SPACE,
|
|
411
442
|
':last-child': spacingVars['--spacing-0'],
|
|
412
443
|
},
|
|
444
|
+
// Long lines wrap exactly as core CodeBlock's wrapped lines do, so a code
|
|
445
|
+
// block is as tall here as in core Markdown (spec:AST-061 FR5, DEC-9).
|
|
413
446
|
whiteSpace: 'pre-wrap',
|
|
414
|
-
|
|
415
|
-
overflowWrap: '
|
|
447
|
+
wordBreak: 'break-all',
|
|
448
|
+
overflowWrap: 'break-word',
|
|
416
449
|
},
|
|
417
450
|
});
|
|
418
451
|
|
|
@@ -479,6 +512,9 @@ export function sharedEditorTheme(): EditorThemeClasses {
|
|
|
479
512
|
tableRow: block(editorTheme.tableRow),
|
|
480
513
|
tableCell: block(editorTheme.tableCell),
|
|
481
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),
|
|
482
518
|
tableScrollableWrapper: block(editorTheme.tableScrollableWrapper),
|
|
483
519
|
};
|
|
484
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';
|