@astryxdesign/richtext 0.7.1-canary.ff40b78 → 0.7.1
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/CHANGELOG.md +23 -0
- package/README.md +47 -57
- package/astryx.integration.mjs +1 -1
- package/dist/RichTextEditor.d.ts +16 -12
- package/dist/RichTextEditor.d.ts.map +1 -1
- package/dist/RichTextEditor.js +40 -45
- package/dist/RichTextEditorAutoLinkPlugin.d.ts +3 -3
- package/dist/RichTextEditorAutoLinkPlugin.js +3 -3
- package/dist/RichTextEditorToolbar.d.ts +19 -8
- package/dist/RichTextEditorToolbar.d.ts.map +1 -1
- package/dist/RichTextEditorToolbar.js +16 -9
- 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 +15 -4
- package/dist/index.d.ts +10 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -4
- package/dist/linkUtils.js +1 -1
- package/dist/markdownLink.d.ts.map +1 -1
- package/dist/markdownLink.js +25 -33
- package/dist/markdownListExport.d.ts.map +1 -1
- package/dist/markdownListExport.js +4 -1
- package/dist/markdownSerializers.d.ts.map +1 -1
- package/dist/markdownSerializers.js +2 -3
- package/dist/richtext.css +6 -1
- package/package.json +34 -36
- package/src/RichTextEditor.doc.mjs +3 -3
- package/src/RichTextEditor.test.tsx +36 -2
- package/src/RichTextEditor.tsx +54 -54
- package/src/RichTextEditorAutoLinkPlugin.tsx +3 -3
- package/src/RichTextEditorToolbar.tsx +27 -10
- 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 +35 -1
- package/src/__tests__/Playground.a11y.chromium.spec.ts +298 -0
- 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 +53 -3
- package/src/index.ts +9 -11
- package/src/linkUtils.ts +1 -1
- package/src/markdownAngleDestinations.test.ts +29 -0
- package/src/markdownLink.ts +29 -35
- package/src/markdownListExport.ts +6 -1
- package/src/markdownSerializers.ts +2 -3
- package/src/publicSurface.test.ts +42 -0
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 {
|
|
@@ -34,7 +31,6 @@ import {
|
|
|
34
31
|
useMemo,
|
|
35
32
|
useRef,
|
|
36
33
|
useState,
|
|
37
|
-
forwardRef,
|
|
38
34
|
type ReactNode,
|
|
39
35
|
type Ref,
|
|
40
36
|
} from 'react';
|
|
@@ -82,7 +78,6 @@ import {MarkdownExtensionsPlugin} from './MarkdownExtensionsPlugin';
|
|
|
82
78
|
import type {RichTextMarkdownExtension} from './markdownExtensions';
|
|
83
79
|
import {TaskCheckboxPlugin} from './TaskCheckboxPlugin';
|
|
84
80
|
import {type Transformer} from '@lexical/markdown';
|
|
85
|
-
export type {Transformer} from '@lexical/markdown';
|
|
86
81
|
import {$generateHtmlFromNodes} from '@lexical/html';
|
|
87
82
|
import {DEFAULT_NODES} from './editorNodes';
|
|
88
83
|
import {$exportMarkdownKeepingSource} from './markdownSource';
|
|
@@ -240,8 +235,8 @@ const dynamicStyles = stylex.create({
|
|
|
240
235
|
});
|
|
241
236
|
|
|
242
237
|
const editorBodySizeStyles = stylex.create({
|
|
243
|
-
sm
|
|
244
|
-
|
|
238
|
+
// Only `lg` adds block padding; `sm` and `md` take the base body spacing.
|
|
239
|
+
// An empty entry each would read as deliberate size-specific styling.
|
|
245
240
|
lg: {
|
|
246
241
|
paddingBlock: spacingVars['--spacing-2'],
|
|
247
242
|
},
|
|
@@ -307,6 +302,12 @@ export interface RichTextEditorProps extends Omit<
|
|
|
307
302
|
BaseProps,
|
|
308
303
|
'onChange' | 'defaultValue'
|
|
309
304
|
> {
|
|
305
|
+
/**
|
|
306
|
+
* Imperative handle for callers that manage the editor from outside. In
|
|
307
|
+
* React 19 `ref` is an ordinary prop, so it is declared here rather than
|
|
308
|
+
* supplied by a `forwardRef` wrapper.
|
|
309
|
+
*/
|
|
310
|
+
ref?: Ref<RichTextEditorRef>;
|
|
310
311
|
/** Label text for the editor (always rendered for accessibility). */
|
|
311
312
|
label: string;
|
|
312
313
|
/**
|
|
@@ -469,9 +470,8 @@ export interface RichTextEditorProps extends Omit<
|
|
|
469
470
|
|
|
470
471
|
/**
|
|
471
472
|
* A WYSIWYG rich-text editor built on Lexical, styled with Astryx design
|
|
472
|
-
* tokens.
|
|
473
|
-
*
|
|
474
|
-
* component.
|
|
473
|
+
* tokens. Ships from `@astryxdesign/richtext`. `lexical` and `@lexical/*` are
|
|
474
|
+
* optional peer dependencies — install them to use this component.
|
|
475
475
|
*
|
|
476
476
|
* The editor is intentionally minimal and extensible: pass `toolbar`, `nodes`,
|
|
477
477
|
* and `plugins` to layer richer behaviour (formatting, mentions, hover cards)
|
|
@@ -492,44 +492,39 @@ export interface RichTextEditorProps extends Omit<
|
|
|
492
492
|
* />
|
|
493
493
|
* ```
|
|
494
494
|
*/
|
|
495
|
-
export const RichTextEditor =
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
style,
|
|
529
|
-
...rest
|
|
530
|
-
}: RichTextEditorProps,
|
|
531
|
-
ref: Ref<RichTextEditorRef>,
|
|
532
|
-
) {
|
|
495
|
+
export const RichTextEditor = function RichTextEditor({
|
|
496
|
+
label,
|
|
497
|
+
isLabelHidden = false,
|
|
498
|
+
description,
|
|
499
|
+
isOptional = false,
|
|
500
|
+
isRequired = false,
|
|
501
|
+
defaultValue,
|
|
502
|
+
onChange,
|
|
503
|
+
placeholder,
|
|
504
|
+
isReadOnly = false,
|
|
505
|
+
isDisabled = false,
|
|
506
|
+
status,
|
|
507
|
+
statusVariant = 'attached',
|
|
508
|
+
width,
|
|
509
|
+
minHeight = '4.5rem',
|
|
510
|
+
labelTooltip,
|
|
511
|
+
size: sizeProp,
|
|
512
|
+
nodes,
|
|
513
|
+
toolbar,
|
|
514
|
+
plugins,
|
|
515
|
+
hasMarkdownShortcuts = true,
|
|
516
|
+
transformers = DEFAULT_TRANSFORMERS,
|
|
517
|
+
markdownExtensions,
|
|
518
|
+
hasAutoFocus = false,
|
|
519
|
+
tabEscapeHint: tabEscapeHintFromProps,
|
|
520
|
+
maxLength,
|
|
521
|
+
namespace = 'astryx-editor',
|
|
522
|
+
xstyle,
|
|
523
|
+
className,
|
|
524
|
+
style,
|
|
525
|
+
ref,
|
|
526
|
+
...rest
|
|
527
|
+
}: RichTextEditorProps) {
|
|
533
528
|
const size = useSize(sizeProp, 'md');
|
|
534
529
|
const t = useTranslator();
|
|
535
530
|
const tabEscapeHint =
|
|
@@ -672,7 +667,7 @@ export const RichTextEditor = forwardRef<
|
|
|
672
667
|
styles.editorBody,
|
|
673
668
|
hasToolbar && styles.editorBodyWithToolbar,
|
|
674
669
|
!!statusIcon && styles.editorBodyWithStatus,
|
|
675
|
-
editorBodySizeStyles
|
|
670
|
+
size === 'lg' && editorBodySizeStyles.lg,
|
|
676
671
|
)}>
|
|
677
672
|
<div {...stylex.props(styles.editorRoot)}>
|
|
678
673
|
<RichTextPlugin
|
|
@@ -773,8 +768,11 @@ export const RichTextEditor = forwardRef<
|
|
|
773
768
|
)}
|
|
774
769
|
</Field>
|
|
775
770
|
);
|
|
776
|
-
}
|
|
771
|
+
};
|
|
777
772
|
|
|
773
|
+
// Keeps the editor inside `@astryx/require-baseprops-passthrough`, which only
|
|
774
|
+
// checks components that assign a top-level `displayName`. Without it, a
|
|
775
|
+
// dropped `className`, `style` or `xstyle` on the root stops warning.
|
|
778
776
|
RichTextEditor.displayName = 'RichTextEditor';
|
|
779
777
|
|
|
780
778
|
/**
|
|
@@ -890,7 +888,9 @@ function EditorRefBridge({
|
|
|
890
888
|
editable,
|
|
891
889
|
transformers,
|
|
892
890
|
}: {
|
|
893
|
-
|
|
891
|
+
// Optional, matching the public `ref` prop: with `forwardRef` gone, React
|
|
892
|
+
// no longer supplies `null` when the caller passes nothing.
|
|
893
|
+
editorRef: Ref<RichTextEditorRef> | undefined;
|
|
894
894
|
editable: boolean;
|
|
895
895
|
transformers: Array<Transformer>;
|
|
896
896
|
}): null {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* `linkUtils`.
|
|
10
10
|
* @output Exports `RichTextEditorAutoLinkPlugin` and its props type, plus the
|
|
11
11
|
* default `DEFAULT_LINK_MATCHERS`.
|
|
12
|
-
* @position
|
|
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,9 +11,11 @@
|
|
|
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
|
-
* IconButton, and ToggleButton, so it inherits the active theme.
|
|
16
|
+
* IconButton, and ToggleButton, so it inherits the active theme. Base props
|
|
17
|
+
* pass through to the Astryx Toolbar exactly as Toolbar places them
|
|
18
|
+
* (spec:AST-061/DEC-8).
|
|
17
19
|
*
|
|
18
20
|
* SYNC: When modified, update:
|
|
19
21
|
* - /packages/richtext/src/index.ts (exports)
|
|
@@ -21,8 +23,8 @@
|
|
|
21
23
|
* - /packages/richtext/src/RichTextEditor.test.tsx (tests)
|
|
22
24
|
* - /apps/storybook/stories/RichTextEditor.stories.tsx (WithToolbar story)
|
|
23
25
|
*
|
|
24
|
-
* NOTE:
|
|
25
|
-
*
|
|
26
|
+
* NOTE: `lexical` and `@lexical/*` are OPTIONAL peer dependencies — install them
|
|
27
|
+
* to use this.
|
|
26
28
|
* Behavior mirrors the Lexical playground toolbar (selection sync + format
|
|
27
29
|
* commands); the UI is built from Astryx primitives so it matches the theme.
|
|
28
30
|
*
|
|
@@ -42,6 +44,7 @@ import {
|
|
|
42
44
|
useState,
|
|
43
45
|
type FormEvent,
|
|
44
46
|
type ReactNode,
|
|
47
|
+
type Ref,
|
|
45
48
|
} from 'react';
|
|
46
49
|
import * as stylex from '@stylexjs/stylex';
|
|
47
50
|
import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
|
|
@@ -61,6 +64,7 @@ import {
|
|
|
61
64
|
} from '@lexical/list';
|
|
62
65
|
import {$getNearestNodeOfType, mergeRegister} from '@lexical/utils';
|
|
63
66
|
import {TOGGLE_LINK_COMMAND, $isLinkNode, $createLinkNode} from '@lexical/link';
|
|
67
|
+
import type {BaseProps} from '@astryxdesign/core';
|
|
64
68
|
import {Toolbar} from '@astryxdesign/core/Toolbar';
|
|
65
69
|
import {IconButton} from '@astryxdesign/core/IconButton';
|
|
66
70
|
import {Selector, type SelectorOptionType} from '@astryxdesign/core/Selector';
|
|
@@ -451,7 +455,15 @@ function DirectionalGlyph({children}: {children: ReactNode}) {
|
|
|
451
455
|
);
|
|
452
456
|
}
|
|
453
457
|
|
|
454
|
-
export interface RichTextEditorToolbarProps {
|
|
458
|
+
export interface RichTextEditorToolbarProps extends BaseProps<HTMLDivElement> {
|
|
459
|
+
/**
|
|
460
|
+
* Ref to the toolbar's root element. Base props pass through to the
|
|
461
|
+
* underlying Astryx `Toolbar`: the ref, `className`, `style`, and `xstyle`
|
|
462
|
+
* reach its root, and `data-*`, other `aria-*` attributes, and DOM
|
|
463
|
+
* handlers reach the `role="toolbar"` element inside it. The toolbar names
|
|
464
|
+
* itself, so pass `label` rather than `aria-label`.
|
|
465
|
+
*/
|
|
466
|
+
ref?: Ref<HTMLDivElement>;
|
|
455
467
|
/**
|
|
456
468
|
* Accessible label for the toolbar element.
|
|
457
469
|
* @default 'Text formatting', translated for the active locale
|
|
@@ -495,7 +507,7 @@ export interface RichTextEditorToolbarProps {
|
|
|
495
507
|
* create same-tab links.
|
|
496
508
|
* @default true
|
|
497
509
|
*/
|
|
498
|
-
|
|
510
|
+
hasNewTabLinks?: boolean;
|
|
499
511
|
/**
|
|
500
512
|
* Extra items rendered at the end of the toolbar (after a divider). Use this
|
|
501
513
|
* to compose product-specific controls (e.g. mentions, AI) alongside the
|
|
@@ -530,8 +542,11 @@ export function RichTextEditorToolbar({
|
|
|
530
542
|
size = 'sm',
|
|
531
543
|
hasLink = true,
|
|
532
544
|
promptForUrl,
|
|
533
|
-
|
|
545
|
+
hasNewTabLinks = true,
|
|
534
546
|
endContent,
|
|
547
|
+
xstyle,
|
|
548
|
+
ref,
|
|
549
|
+
...rest
|
|
535
550
|
}: RichTextEditorToolbarProps) {
|
|
536
551
|
const [editor] = useLexicalComposerContext();
|
|
537
552
|
const themeName = useThemeName();
|
|
@@ -680,7 +695,7 @@ export function RichTextEditorToolbar({
|
|
|
680
695
|
}
|
|
681
696
|
|
|
682
697
|
restoreLinkSelection();
|
|
683
|
-
const linkAttributes =
|
|
698
|
+
const linkAttributes = hasNewTabLinks
|
|
684
699
|
? {target: '_blank', rel: 'noopener noreferrer'}
|
|
685
700
|
: {};
|
|
686
701
|
const handled = editor.dispatchCommand(TOGGLE_LINK_COMMAND, {
|
|
@@ -699,7 +714,7 @@ export function RichTextEditorToolbar({
|
|
|
699
714
|
}
|
|
700
715
|
return true;
|
|
701
716
|
},
|
|
702
|
-
[editor,
|
|
717
|
+
[editor, hasNewTabLinks, restoreLinkSelection],
|
|
703
718
|
);
|
|
704
719
|
|
|
705
720
|
const toggleLink = useCallback(() => {
|
|
@@ -896,9 +911,11 @@ export function RichTextEditorToolbar({
|
|
|
896
911
|
return (
|
|
897
912
|
<>
|
|
898
913
|
<Toolbar
|
|
914
|
+
{...rest}
|
|
915
|
+
ref={ref}
|
|
899
916
|
label={label}
|
|
900
917
|
size={size}
|
|
901
|
-
xstyle={toolbarScrollStyles.compactToolbar}
|
|
918
|
+
xstyle={[toolbarScrollStyles.compactToolbar, xstyle]}
|
|
902
919
|
startContent={
|
|
903
920
|
<HStack
|
|
904
921
|
gap={1}
|
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
|
|
|
@@ -99,6 +99,40 @@ test('editing the text beside the nodes keeps every node and its marks', async (
|
|
|
99
99
|
expect(errors).toEqual([]);
|
|
100
100
|
});
|
|
101
101
|
|
|
102
|
+
// spec:AST-061 FR3: the first block's leading margin and the last block's
|
|
103
|
+
// trailing margin are zero, a plugin block included. Lexical puts a zero-size
|
|
104
|
+
// caret boundary element beside a decorator at either edge of the document, so
|
|
105
|
+
// a plugin block there is not literally the first or last child.
|
|
106
|
+
test('a plugin block at either edge of the document adds no outer margin', async ({
|
|
107
|
+
page,
|
|
108
|
+
}) => {
|
|
109
|
+
const errors = await openStory(page);
|
|
110
|
+
await page
|
|
111
|
+
.locator('[data-plugins-input]')
|
|
112
|
+
.fill(':::note\nfirst\n:::\n\nBetween the notes.\n\n:::note\nlast\n:::');
|
|
113
|
+
const editor = page.locator('[contenteditable="true"]');
|
|
114
|
+
await expect(editor.getByText('Between the notes.')).toBeVisible();
|
|
115
|
+
const margins = await editor.evaluate(root => {
|
|
116
|
+
const blocks = [...root.children].filter(
|
|
117
|
+
child => !child.hasAttribute('data-lexical-decorator-boundary'),
|
|
118
|
+
);
|
|
119
|
+
const first = blocks[0];
|
|
120
|
+
const last = blocks[blocks.length - 1];
|
|
121
|
+
return {
|
|
122
|
+
first: first?.hasAttribute('data-lexical-decorator') ?? false,
|
|
123
|
+
last: last?.hasAttribute('data-lexical-decorator') ?? false,
|
|
124
|
+
start: first == null ? null : getComputedStyle(first).marginTop,
|
|
125
|
+
end: last == null ? null : getComputedStyle(last).marginBottom,
|
|
126
|
+
};
|
|
127
|
+
});
|
|
128
|
+
// Both edge blocks are the plugin's note blocks.
|
|
129
|
+
expect(margins.first).toBe(true);
|
|
130
|
+
expect(margins.last).toBe(true);
|
|
131
|
+
expect(margins.start).toBe('0px');
|
|
132
|
+
expect(margins.end).toBe('0px');
|
|
133
|
+
expect(errors).toEqual([]);
|
|
134
|
+
});
|
|
135
|
+
|
|
102
136
|
for (const colorMode of ['light', 'dark'] as const) {
|
|
103
137
|
test(`the story meets text contrast in ${colorMode} mode`, async ({page}) => {
|
|
104
138
|
const errors = await openStory(page, colorMode);
|