@astryxdesign/richtext 0.7.5-canary.9effa5c → 0.7.5-canary.a73f030

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.
Files changed (36) hide show
  1. package/dist/CodeBlockHeaderPlugin.d.ts +5 -1
  2. package/dist/CodeBlockHeaderPlugin.d.ts.map +1 -1
  3. package/dist/CodeBlockHeaderPlugin.js +11 -3
  4. package/dist/CodeSyntaxPlugin.d.ts +6 -3
  5. package/dist/CodeSyntaxPlugin.d.ts.map +1 -1
  6. package/dist/CodeSyntaxPlugin.js +18 -4
  7. package/dist/RichTextEditor.d.ts +10 -1
  8. package/dist/RichTextEditor.d.ts.map +1 -1
  9. package/dist/RichTextEditor.js +7 -2
  10. package/dist/RichTextView.d.ts +10 -1
  11. package/dist/RichTextView.d.ts.map +1 -1
  12. package/dist/RichTextView.js +6 -1
  13. package/dist/codeLanguages.d.ts +14 -0
  14. package/dist/codeLanguages.d.ts.map +1 -0
  15. package/dist/codeLanguages.js +34 -0
  16. package/dist/editorTheme.d.ts.map +1 -1
  17. package/dist/editorTheme.js +6 -1
  18. package/dist/richtext.css +3 -1
  19. package/package.json +7 -7
  20. package/src/CodeBlockHeaderPlugin.tsx +23 -3
  21. package/src/CodeSyntaxPlugin.test.tsx +20 -0
  22. package/src/CodeSyntaxPlugin.tsx +22 -5
  23. package/src/RichTextEditor.doc.mjs +6 -0
  24. package/src/RichTextEditor.test.tsx +1 -0
  25. package/src/RichTextEditor.tsx +13 -3
  26. package/src/RichTextView.tsx +12 -2
  27. package/src/__tests__/MarkdownParitySandbox.a11y.chromium.spec.ts +41 -3
  28. package/src/__tests__/MarkdownPlugins.a11y.chromium.spec.ts +1 -0
  29. package/src/__tests__/MarkdownPluginsImportExport.a11y.chromium.spec.ts +1 -0
  30. package/src/__tests__/Playground.a11y.chromium.spec.ts +1 -0
  31. package/src/__tests__/RichTextCodeLanguages.a11y.chromium.spec.ts +61 -0
  32. package/src/__tests__/RichTextEditorToolbar.a11y.chromium.spec.ts +1 -0
  33. package/src/__tests__/RichTextView.a11y.chromium.spec.ts +1 -0
  34. package/src/__tests__/TableCellSelection.a11y.chromium.spec.ts +1 -0
  35. package/src/codeLanguages.ts +42 -0
  36. package/src/editorTheme.ts +12 -1
@@ -1,7 +1,11 @@
1
1
  import { type JSX } from 'react';
2
+ import type { CodeLanguage } from '@astryxdesign/core/CodeBlock';
2
3
  /**
3
4
  * Draws a header over each top-level code block and keeps it there as the
4
5
  * document, the editor's size, or the window changes.
5
6
  */
6
- export declare function CodeBlockHeaderPlugin(): JSX.Element;
7
+ export declare function CodeBlockHeaderPlugin({ codeLanguages, }?: {
8
+ /** Language values a fence may name; a matched fence shows the value's name. */
9
+ codeLanguages?: ReadonlyArray<CodeLanguage>;
10
+ }): JSX.Element;
7
11
  //# sourceMappingURL=CodeBlockHeaderPlugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CodeBlockHeaderPlugin.d.ts","sourceRoot":"","sources":["../src/CodeBlockHeaderPlugin.tsx"],"names":[],"mappings":"AAmBA,OAAO,EAAsB,KAAK,GAAG,EAAC,MAAM,OAAO,CAAC;AA+JpD;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,GAAG,CAAC,OAAO,CA+EnD"}
1
+ {"version":3,"file":"CodeBlockHeaderPlugin.d.ts","sourceRoot":"","sources":["../src/CodeBlockHeaderPlugin.tsx"],"names":[],"mappings":"AAmBA,OAAO,EAAsB,KAAK,GAAG,EAAC,MAAM,OAAO,CAAC;AAQpD,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,8BAA8B,CAAC;AA4J/D;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,aAAa,GACd,GAAE;IACD,gFAAgF;IAChF,aAAa,CAAC,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;CACxC,GAAG,GAAG,CAAC,OAAO,CAyFnB"}
@@ -24,6 +24,7 @@ import { Icon } from '@astryxdesign/core/Icon';
24
24
  import { IconButton } from '@astryxdesign/core/IconButton';
25
25
  import { useClipboard } from '@astryxdesign/core/hooks';
26
26
  import { useTranslator } from '@astryxdesign/core/i18n';
27
+ import { listedLanguage } from "./codeLanguages.js";
27
28
  import '@astryxdesign/core/theme/tokens.stylex';
28
29
  import { fontWeightVars, spacingVars, typeScaleVars, typographyVars } from '@astryxdesign/core/theme/tokens.stylex';
29
30
 
@@ -82,7 +83,8 @@ function samePlacements(a, b) {
82
83
  return a.length === b.length && a.every((placement, index) => placement.key === b[index].key && placement.language === b[index].language && placement.top === b[index].top && placement.left === b[index].left && placement.width === b[index].width);
83
84
  }
84
85
  function CodeBlockHeader({
85
- placement
86
+ placement,
87
+ label
86
88
  }) {
87
89
  const [editor] = useLexicalComposerContext();
88
90
  const t = useTranslator();
@@ -123,7 +125,7 @@ function CodeBlockHeader({
123
125
  ...{
124
126
  className: "x141an7d x9m5x89 x1e4wzip x1ltkj2j x1mjzq1q xeuugli xb3r6kr xlyipyv xuxw1ft"
125
127
  },
126
- children: placement.language
128
+ children: label ?? placement.language
127
129
  }), copyButton]
128
130
  });
129
131
  }
@@ -132,7 +134,9 @@ function CodeBlockHeader({
132
134
  * Draws a header over each top-level code block and keeps it there as the
133
135
  * document, the editor's size, or the window changes.
134
136
  */
135
- export function CodeBlockHeaderPlugin() {
137
+ export function CodeBlockHeaderPlugin({
138
+ codeLanguages
139
+ } = {}) {
136
140
  const [editor] = useLexicalComposerContext();
137
141
  const [placements, setPlacements] = useState([]);
138
142
  useEffect(() => {
@@ -191,6 +195,10 @@ export function CodeBlockHeaderPlugin() {
191
195
  return /*#__PURE__*/_jsx(_Fragment, {
192
196
  children: placements.map(placement => /*#__PURE__*/_jsx(CodeBlockHeader, {
193
197
  placement: placement
198
+ // A fence matched in `codeLanguages` shows the value's name, as
199
+ // Markdown does (spec:AST-061).
200
+ ,
201
+ label: placement.language == null ? undefined : listedLanguage(codeLanguages, placement.language)?.name
194
202
  }, placement.key))
195
203
  });
196
204
  }
@@ -1,4 +1,4 @@
1
- import { type TokenLine } from '@astryxdesign/core/CodeBlock';
1
+ import { type CodeLanguage, type TokenLine } from '@astryxdesign/core/CodeBlock';
2
2
  /** The class the theme adds to every code block (editorTheme.ts). */
3
3
  export declare const CODE_SYNTAX_CLASS = "astryx-richtext-code";
4
4
  /**
@@ -7,6 +7,9 @@ export declare const CODE_SYNTAX_CLASS = "astryx-richtext-code";
7
7
  * each line break is an element with no text. Null when the rendered text is
8
8
  * not the code (it is mid-update), so nothing is colored out of place.
9
9
  */
10
- export declare function renderedTokens(code: string, language: string, rendered: string): TokenLine[] | null;
11
- export declare function CodeSyntaxPlugin(): null;
10
+ export declare function renderedTokens(code: string, language: string | CodeLanguage, rendered: string): TokenLine[] | null;
11
+ export declare function CodeSyntaxPlugin({ codeLanguages, }?: {
12
+ /** Language values a fence may name (component:Markdown FR30). */
13
+ codeLanguages?: ReadonlyArray<CodeLanguage>;
14
+ }): null;
12
15
  //# sourceMappingURL=CodeSyntaxPlugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CodeSyntaxPlugin.d.ts","sourceRoot":"","sources":["../src/CodeSyntaxPlugin.tsx"],"names":[],"mappings":"AA2BA,OAAO,EAIL,KAAK,SAAS,EACf,MAAM,8BAA8B,CAAC;AAEtC,qEAAqE;AACrE,eAAO,MAAM,iBAAiB,yBAAyB,CAAC;AA8BxD;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,SAAS,EAAE,GAAG,IAAI,CAqBpB;AASD,wBAAgB,gBAAgB,IAAI,IAAI,CAuFvC"}
1
+ {"version":3,"file":"CodeSyntaxPlugin.d.ts","sourceRoot":"","sources":["../src/CodeSyntaxPlugin.tsx"],"names":[],"mappings":"AA2BA,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,SAAS,EACf,MAAM,8BAA8B,CAAC;AAGtC,qEAAqE;AACrE,eAAO,MAAM,iBAAiB,yBAAyB,CAAC;AA8BxD;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GAAG,YAAY,EAC/B,QAAQ,EAAE,MAAM,GACf,SAAS,EAAE,GAAG,IAAI,CAqBpB;AASD,wBAAgB,gBAAgB,CAAC,EAC/B,aAAa,GACd,GAAE;IACD,kEAAkE;IAClE,aAAa,CAAC,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;CACxC,GAAG,IAAI,CAiGZ"}
@@ -20,11 +20,12 @@
20
20
  * are untouched; the ranges are rebuilt when a block's code or language
21
21
  * changes. Browsers without the Highlight API show plain code.
22
22
  */
23
- import { useEffect } from 'react';
23
+ import { useEffect, useState } from 'react';
24
24
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
25
25
  import { $isCodeNode, CodeNode } from '@lexical/code';
26
26
  import { $getNodeByKey } from 'lexical';
27
27
  import { applyHighlightRangesFlat, TOKEN_TYPES, tokenize } from '@astryxdesign/core/CodeBlock';
28
+ import { listedLanguage, sameLanguages } from "./codeLanguages.js";
28
29
 
29
30
  /** The class the theme adds to every code block (editorTheme.ts). */
30
31
  export const CODE_SYNTAX_CLASS = 'astryx-richtext-code';
@@ -76,8 +77,21 @@ export function renderedTokens(code, language, rendered) {
76
77
  });
77
78
  return [flat];
78
79
  }
79
- export function CodeSyntaxPlugin() {
80
+ export function CodeSyntaxPlugin({
81
+ codeLanguages
82
+ } = {}) {
80
83
  const [editor] = useLexicalComposerContext();
84
+ // Keep one list while it names the same values, so an inline
85
+ // `codeLanguages={[…]}` does not re-colour every block on each parent
86
+ // render (adjusting state during render, not in an Effect).
87
+ const [languages, setLanguages] = useState(codeLanguages);
88
+ if (!sameLanguages(languages, codeLanguages)) {
89
+ setLanguages(codeLanguages);
90
+ }
91
+
92
+ // Synchronizes the editor's code blocks with the CSS highlight registry:
93
+ // Lexical update and mutation listeners colour each block, and the cleanup
94
+ // removes the listeners and every highlight range they added.
81
95
  useEffect(() => {
82
96
  if (!supportsHighlights()) {
83
97
  return undefined;
@@ -108,7 +122,7 @@ export function CodeSyntaxPlugin() {
108
122
  return;
109
123
  }
110
124
  previous?.cleanup();
111
- const tokens = renderedTokens(block.code, block.language, element.textContent ?? '');
125
+ const tokens = renderedTokens(block.code, listedLanguage(languages, block.language) ?? block.language, element.textContent ?? '');
112
126
  if (tokens == null) {
113
127
  // Not rendered yet; the next update tries again.
114
128
  colored.delete(key);
@@ -149,6 +163,6 @@ export function CodeSyntaxPlugin() {
149
163
  }
150
164
  blocks.clear();
151
165
  };
152
- }, [editor]);
166
+ }, [editor, languages]);
153
167
  return null;
154
168
  }
@@ -24,6 +24,7 @@ import { type FieldStatusVariant } from '@astryxdesign/core/Field';
24
24
  import type { BaseProps } from '@astryxdesign/core';
25
25
  import { type SizeValue } from '@astryxdesign/core/utils';
26
26
  import type { RichTextMarkdownExtension } from './markdownExtensions.js';
27
+ import type { CodeLanguage } from '@astryxdesign/core/CodeBlock';
27
28
  import { type Transformer } from '@lexical/markdown';
28
29
  import { type EditorState, type Klass, type LexicalEditor, type LexicalNode } from 'lexical';
29
30
  export type RichTextEditorStatusType = 'warning' | 'error' | 'success';
@@ -213,6 +214,14 @@ export interface RichTextEditorProps extends Omit<BaseProps, 'onChange' | 'defau
213
214
  * serializable props.
214
215
  */
215
216
  markdownExtensions?: ReadonlyArray<RichTextMarkdownExtension>;
217
+ /**
218
+ * CodeBlock language values a fence may name, each imported on its own,
219
+ * such as `graphql` from `@astryxdesign/core/CodeBlock/languages/graphql`,
220
+ * or made with `createCodeLanguage`. Pass the same list as `Markdown`'s
221
+ * `codeLanguages`, so reading and editing paint and label the same
222
+ * languages (spec:AST-061).
223
+ */
224
+ codeLanguages?: ReadonlyArray<CodeLanguage>;
216
225
  /** Whether to automatically focus the editor on mount. @default false */
217
226
  hasAutoFocus?: boolean;
218
227
  /**
@@ -263,7 +272,7 @@ export interface RichTextEditorProps extends Omit<BaseProps, 'onChange' | 'defau
263
272
  * ```
264
273
  */
265
274
  export declare const RichTextEditor: {
266
- ({ label, isLabelHidden, description, isOptional, isRequired, defaultValue, onChange, placeholder, isReadOnly, isDisabled, status, statusVariant, width, minHeight, labelTooltip, size: sizeProp, nodes, toolbar, plugins, hasMarkdownShortcuts, transformers, markdownExtensions, hasAutoFocus, tabEscapeHint: tabEscapeHintFromProps, maxLength, namespace, xstyle, className, style, ref, ...rest }: RichTextEditorProps): import("react").JSX.Element;
275
+ ({ label, isLabelHidden, description, isOptional, isRequired, defaultValue, onChange, placeholder, isReadOnly, isDisabled, status, statusVariant, width, minHeight, labelTooltip, size: sizeProp, nodes, toolbar, plugins, hasMarkdownShortcuts, transformers, markdownExtensions, codeLanguages, hasAutoFocus, tabEscapeHint: tabEscapeHintFromProps, maxLength, namespace, xstyle, className, style, ref, ...rest }: RichTextEditorProps): import("react").JSX.Element;
267
276
  displayName: string;
268
277
  };
269
278
  //# sourceMappingURL=RichTextEditor.d.ts.map
@@ -1 +1 @@
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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AY,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;IAC1C;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,aAAa,CAAC,yBAAyB,CAAC,CAAC;IAC9D;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IAC5C,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;2ZAiCxB,mBAAmB;;CAoPrB,CAAC"}
@@ -186,6 +186,7 @@ export const RichTextEditor = function RichTextEditor({
186
186
  hasMarkdownShortcuts = true,
187
187
  transformers = DEFAULT_TRANSFORMERS,
188
188
  markdownExtensions,
189
+ codeLanguages,
189
190
  hasAutoFocus = false,
190
191
  tabEscapeHint: tabEscapeHintFromProps,
191
192
  maxLength,
@@ -353,7 +354,11 @@ export const RichTextEditor = function RichTextEditor({
353
354
  hasCellBackgroundColor: false,
354
355
  hasTabHandler: false,
355
356
  hasHorizontalScroll: true
356
- }), /*#__PURE__*/_jsx(TableColumnFloorPlugin, {}), /*#__PURE__*/_jsx(CodeBlockHeaderPlugin, {}), /*#__PURE__*/_jsx(CodeSyntaxPlugin, {}), markdownExtensions != null && markdownExtensions.length > 0 ? /*#__PURE__*/_jsx(MarkdownExtensionsPlugin, {
357
+ }), /*#__PURE__*/_jsx(TableColumnFloorPlugin, {}), /*#__PURE__*/_jsx(CodeBlockHeaderPlugin, {
358
+ codeLanguages: codeLanguages
359
+ }), /*#__PURE__*/_jsx(CodeSyntaxPlugin, {
360
+ codeLanguages: codeLanguages
361
+ }), markdownExtensions != null && markdownExtensions.length > 0 ? /*#__PURE__*/_jsx(MarkdownExtensionsPlugin, {
357
362
  extensions: markdownExtensions,
358
363
  transformers: markdownTransformers
359
364
  }) : null, /*#__PURE__*/_jsx(TabIndentationPlugin, {}), /*#__PURE__*/_jsx(TabFocusEscapePlugin, {}), hasMarkdownShortcuts && /*#__PURE__*/_jsx(MarkdownShortcutPlugin, {
@@ -387,7 +392,7 @@ export const RichTextEditor = function RichTextEditor({
387
392
  className: "x78zum5 x13a6bvl xcsaf9d x9ynric x141an7d xv1l7n4"
388
393
  },
389
394
  1: {
390
- className: "x78zum5 x13a6bvl xcsaf9d x9ynric x141an7d xjt36v0"
395
+ className: "x78zum5 x13a6bvl xcsaf9d x9ynric x141an7d x1wj83wy"
391
396
  }
392
397
  }[!!(charCount > maxLength) << 0],
393
398
  children: [charCount, "/", maxLength, /*#__PURE__*/_jsx(VisuallyHidden, {
@@ -16,6 +16,7 @@
16
16
  import { type ReactNode } from 'react';
17
17
  import type { BaseProps } from '@astryxdesign/core';
18
18
  import type { RichTextMarkdownExtension } from './markdownExtensions.js';
19
+ import type { CodeLanguage } from '@astryxdesign/core/CodeBlock';
19
20
  import type { Klass, LexicalNode } from 'lexical';
20
21
  export interface RichTextViewProps extends BaseProps {
21
22
  /**
@@ -37,6 +38,14 @@ export interface RichTextViewProps extends BaseProps {
37
38
  * serializable props.
38
39
  */
39
40
  markdownExtensions?: ReadonlyArray<RichTextMarkdownExtension>;
41
+ /**
42
+ * CodeBlock language values a fence may name, each imported on its own,
43
+ * such as `graphql` from `@astryxdesign/core/CodeBlock/languages/graphql`,
44
+ * or made with `createCodeLanguage`. Pass the same list as `Markdown`'s
45
+ * `codeLanguages`, so reading and editing paint and label the same
46
+ * languages (spec:AST-061).
47
+ */
48
+ codeLanguages?: ReadonlyArray<CodeLanguage>;
40
49
  /**
41
50
  * Additional read-only plugins to render inside the composer (e.g. hover
42
51
  * cards, decorators).
@@ -76,7 +85,7 @@ export interface RichTextViewProps extends BaseProps {
76
85
  * <RichTextView value={storedEditorStateJSON} />
77
86
  * ```
78
87
  */
79
- export declare function RichTextView({ value, nodes, markdownExtensions, plugins, namespace, onParseError, errorFallback, xstyle, className, style, ...rest }: RichTextViewProps): import("react").JSX.Element;
88
+ export declare function RichTextView({ value, nodes, markdownExtensions, codeLanguages, plugins, namespace, onParseError, errorFallback, xstyle, className, style, ...rest }: RichTextViewProps): import("react").JSX.Element;
80
89
  export declare namespace RichTextView {
81
90
  var displayName: string;
82
91
  }
@@ -1 +1 @@
1
- {"version":3,"file":"RichTextView.d.ts","sourceRoot":"","sources":["../src/RichTextView.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAA8B,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAGlE,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAmBlD,OAAO,KAAK,EAAC,yBAAyB,EAAC,MAAM,sBAAsB,CAAC;AAEpE,OAAO,KAAK,EAEV,KAAK,EACL,WAAW,EAEZ,MAAM,SAAS,CAAC;AAoDjB,MAAM,WAAW,iBAAkB,SAAQ,SAAS;IAClD;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;IAC1C;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,aAAa,CAAC,yBAAyB,CAAC,CAAC;IAC9D;;;OAGG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACtC;;;;OAIG;IACH,aAAa,CAAC,EAAE,SAAS,CAAC;CAC3B;AAyCD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,KAAK,EACL,kBAAkB,EAClB,OAAO,EACP,S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Y,EACZ,aAAoB,EACpB,MAAM,EACN,SAAS,EACT,KAAK,EACL,GAAG,IAAI,EACR,EAAE,iBAAiB,+BA8HnB;yBA3Ie,YAAY"}
@@ -142,6 +142,7 @@ export function RichTextView({
142
142
  value,
143
143
  nodes,
144
144
  markdownExtensions,
145
+ codeLanguages,
145
146
  plugins,
146
147
  namespace = 'astryx-view',
147
148
  onParseError,
@@ -250,7 +251,11 @@ export function RichTextView({
250
251
  }),
251
252
  placeholder: null,
252
253
  ErrorBoundary: LexicalErrorBoundary
253
- }), /*#__PURE__*/_jsx(CodeBlockHeaderPlugin, {}), /*#__PURE__*/_jsx(CodeSyntaxPlugin, {}), markdownExtensions != null && markdownExtensions.length > 0 ? /*#__PURE__*/_jsx(MarkdownExtensionsPlugin, {
254
+ }), /*#__PURE__*/_jsx(CodeBlockHeaderPlugin, {
255
+ codeLanguages: codeLanguages
256
+ }), /*#__PURE__*/_jsx(CodeSyntaxPlugin, {
257
+ codeLanguages: codeLanguages
258
+ }), markdownExtensions != null && markdownExtensions.length > 0 ? /*#__PURE__*/_jsx(MarkdownExtensionsPlugin, {
254
259
  extensions: markdownExtensions,
255
260
  transformers: NO_TRANSFORMERS
256
261
  }) : null, /*#__PURE__*/_jsx(TaskCheckboxPlugin, {
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @file codeLanguages.ts
3
+ * @input CodeLanguage values from @astryxdesign/core/CodeBlock
4
+ * @output listedLanguage, which finds the listed value a fence word names, and
5
+ * sameLanguages, which compares two lists entry by entry
6
+ * @position Shared by CodeSyntaxPlugin and CodeBlockHeaderPlugin, so RichText
7
+ * resolves a fence as Markdown does (component:Markdown FR30)
8
+ */
9
+ import type { CodeLanguage } from '@astryxdesign/core/CodeBlock';
10
+ /** The listed value whose identifiers include `word`; a later entry wins. */
11
+ export declare function listedLanguage(languages: ReadonlyArray<CodeLanguage> | undefined, word: string): CodeLanguage | undefined;
12
+ /** Whether two lists name the same values in the same order. */
13
+ export declare function sameLanguages(a: ReadonlyArray<CodeLanguage> | undefined, b: ReadonlyArray<CodeLanguage> | undefined): boolean;
14
+ //# sourceMappingURL=codeLanguages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codeLanguages.d.ts","sourceRoot":"","sources":["../src/codeLanguages.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,8BAA8B,CAAC;AAE/D,6EAA6E;AAC7E,wBAAgB,cAAc,CAC5B,SAAS,EAAE,aAAa,CAAC,YAAY,CAAC,GAAG,SAAS,EAClD,IAAI,EAAE,MAAM,GACX,YAAY,GAAG,SAAS,CAU1B;AAED,gEAAgE;AAChE,wBAAgB,aAAa,CAC3B,CAAC,EAAE,aAAa,CAAC,YAAY,CAAC,GAAG,SAAS,EAC1C,CAAC,EAAE,aAAa,CAAC,YAAY,CAAC,GAAG,SAAS,GACzC,OAAO,CAQT"}
@@ -0,0 +1,34 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file codeLanguages.ts
5
+ * @input CodeLanguage values from @astryxdesign/core/CodeBlock
6
+ * @output listedLanguage, which finds the listed value a fence word names, and
7
+ * sameLanguages, which compares two lists entry by entry
8
+ * @position Shared by CodeSyntaxPlugin and CodeBlockHeaderPlugin, so RichText
9
+ * resolves a fence as Markdown does (component:Markdown FR30)
10
+ */
11
+
12
+ /** The listed value whose identifiers include `word`; a later entry wins. */
13
+ export function listedLanguage(languages, word) {
14
+ if (languages == null) {
15
+ return undefined;
16
+ }
17
+ for (let i = languages.length - 1; i >= 0; i--) {
18
+ if (languages[i].identifiers.includes(word)) {
19
+ return languages[i];
20
+ }
21
+ }
22
+ return undefined;
23
+ }
24
+
25
+ /** Whether two lists name the same values in the same order. */
26
+ export function sameLanguages(a, b) {
27
+ if (a === b) {
28
+ return true;
29
+ }
30
+ if (a == null || b == null || a.length !== b.length) {
31
+ return false;
32
+ }
33
+ return a.every((language, i) => language === b[i]);
34
+ }
@@ -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;AA0bhD;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,kBAAkB,CAgEtD"}
1
+ {"version":3,"file":"editorTheme.d.ts","sourceRoot":"","sources":["../src/editorTheme.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,SAAS,CAAC;AAqchD;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,kBAAkB,CAgEtD"}
@@ -42,6 +42,10 @@ const CODE_SPACE = `calc(${spacingVars['--spacing-3']})`;
42
42
  // Core CodeBlock's header (8px, a small control, 8px) overlaps the code's
43
43
  // 12px top padding by 8px, so its code starts 8px + control + 12px down.
44
44
  const CODE_HEADER_SPACE = `calc(${spacingVars['--spacing-2']} + ${sizeVars['--size-element-sm']} + ${spacingVars['--spacing-3']})`;
45
+ // A block that names no language has no header: core CodeBlock puts its copy
46
+ // button in a column of its own at the inline end (8px, a small control, 8px),
47
+ // beside the code rather than over it, so the code ends that much earlier.
48
+ const CODE_CORNER_SPACE = `calc(${spacingVars['--spacing-4']} + ${sizeVars['--size-element-sm']} + 2 * ${spacingVars['--spacing-2']})`;
45
49
  const editorTheme = {
46
50
  providerDirection: {
47
51
  ksoyAI: "x1epdd7z",
@@ -226,7 +230,8 @@ const editorTheme = {
226
230
  kaIpWk: "xh6dtrn",
227
231
  kLKAdn: "xekneqv x2w4pp4",
228
232
  kGO01o: "xvmdzux",
229
- kg3NbH: "x1pzlopt",
233
+ kZCmMZ: "x1rey3nv",
234
+ kwRFfy: "xza90q5 x18crcbm",
230
235
  kB7OPa: "x9f619",
231
236
  kzqmXN: "xeq5yr9",
232
237
  k7Eaqz: "xejm5pw",
package/dist/richtext.css CHANGED
@@ -52,9 +52,9 @@
52
52
  .x9f619:not(#\#):not(#\#):not(#\#){box-sizing:border-box}
53
53
  .x1afcbsf:not(#\#):not(#\#):not(#\#){box-sizing:content-box}
54
54
  .x1heor9g:not(#\#):not(#\#):not(#\#){color:inherit}
55
- .xjt36v0:not(#\#):not(#\#):not(#\#){color:var(--color-error)}
56
55
  .x1mjzq1q:not(#\#):not(#\#):not(#\#){color:var(--color-syntax-comment)}
57
56
  .xjse4m1:not(#\#):not(#\#):not(#\#){color:var(--color-text-accent)}
57
+ .x1wj83wy:not(#\#):not(#\#):not(#\#){color:var(--color-text-error)}
58
58
  .x1tgivj0:not(#\#):not(#\#):not(#\#){color:var(--color-text-primary)}
59
59
  .xv1l7n4:not(#\#):not(#\#):not(#\#){color:var(--color-text-secondary)}
60
60
  .xt0e3qv:not(#\#):not(#\#):not(#\#){cursor:default}
@@ -120,6 +120,7 @@
120
120
  .xak0ai5:not(#\#):not(#\#):not(#\#){outline-width:var(--focus-outline-width)}
121
121
  .x1mzt3pk:not(#\#):not(#\#):not(#\#){overflow-wrap:break-word}
122
122
  .xp74n0j:not(#\#):not(#\#):not(#\#){padding-inline-end:calc(var(--spacing-2) + var(--spacing-6))}
123
+ .xza90q5:not(#\#):not(#\#):not(#\#){padding-inline-end:calc(var(--spacing-4) + var(--size-element-sm) + 2 * var(--spacing-2))}
123
124
  .xbj1ybn:not(#\#):not(#\#):not(#\#){padding-inline-start:calc(var(--spacing-0))}
124
125
  .x1rey3nv:not(#\#):not(#\#):not(#\#){padding-inline-start:var(--spacing-4)}
125
126
  .x31w388:not(#\#):not(#\#):not(#\#){padding-inline-start:var(--spacing-6)}
@@ -139,6 +140,7 @@
139
140
  .x16khyan:is(:disabled,[aria-disabled="true"]):not(#\#):not(#\#):not(#\#){cursor:default}
140
141
  .x2i8j16:is([data-richtext-task]):not(#\#):not(#\#):not(#\#){list-style-type:none}
141
142
  .x1pvqllw:is([data-richtext-task]):not(#\#):not(#\#):not(#\#){margin-inline-start:calc(-1 * var(--spacing-6))}
143
+ .x18crcbm:is([data-language]:not([data-language="plaintext"])):not(#\#):not(#\#):not(#\#){padding-inline-end:var(--spacing-4)}
142
144
  .x1kuvm45:is([data-richtext-task]):not(#\#):not(#\#):not(#\#){padding-inline-start:calc(20px + var(--spacing-2))}
143
145
  .x81k3mc:has(ul):not(#\#):not(#\#):not(#\#){list-style-type:none}
144
146
  .xovwveo:has(ol):not(#\#):not(#\#):not(#\#){list-style-type:none}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@astryxdesign/richtext",
3
3
  "displayName": "Rich Text",
4
- "version": "0.7.5-canary.9effa5c",
4
+ "version": "0.7.5-canary.a73f030",
5
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",
@@ -53,7 +53,7 @@
53
53
  },
54
54
  "peerDependencies": {
55
55
  "@stylexjs/stylex": ">=0.10.0",
56
- "@astryxdesign/core": "0.7.5-canary.9effa5c",
56
+ "@astryxdesign/core": "0.7.5-canary.a73f030",
57
57
  "react": ">=19.0.0",
58
58
  "react-dom": ">=19.0.0",
59
59
  "lexical": "^0.52.0",
@@ -112,8 +112,8 @@
112
112
  }
113
113
  },
114
114
  "devDependencies": {
115
- "@astryxdesign/a11y-spec": "0.7.5-canary.9effa5c",
116
- "@astryxdesign/cli": "0.7.5-canary.9effa5c",
115
+ "@astryxdesign/a11y-spec": "0.7.5-canary.a73f030",
116
+ "@astryxdesign/cli": "0.7.5-canary.a73f030",
117
117
  "@babel/cli": "^7.29.7",
118
118
  "@babel/core": "^7.29.7",
119
119
  "@babel/preset-react": "^7.29.7",
@@ -136,13 +136,13 @@
136
136
  },
137
137
  "scripts": {
138
138
  "build": "node ../../scripts/clean-dist.mjs && pnpm build:esm && tsc --project tsconfig.build.json && node ../../scripts/add-declaration-extensions.mjs && pnpm build:css && node ../../scripts/check-no-dev-jsx.mjs && node ../../scripts/check-fully-specified.mjs",
139
- "build:esm": "babel src --out-dir dist --extensions \".ts,.tsx\" --out-file-extension \".js\" --ignore \"**/*.test.ts,**/*.test.tsx,**/__tests__/**,**/*.perf.test.*,**/*.doc.mjs,**/*.d.ts,**/*.css,**/*.css.d.ts\" --config-file ./babel.config.json",
139
+ "build:esm": "babel src --out-dir dist --extensions \".ts,.tsx\" --out-file-extension \".js\" --ignore \"**/*.test.ts,**/*.test.tsx,**/__tests__/**,**/*.perf.test.*,**/*.doc.mjs,**/*.d.ts,**/*.css,**/*.css.d.ts\" --config-file ./babel.config.cjs",
140
140
  "build:css": "node ../../scripts/build-css.mjs --package richtext",
141
- "dev": "babel src --watch --out-dir dist --extensions \".ts,.tsx\" --out-file-extension \".js\" --ignore \"**/*.test.*,**/*.doc.mjs,**/*.d.ts,**/*.css*\" --config-file ./babel.config.json",
141
+ "dev": "babel src --watch --out-dir dist --extensions \".ts,.tsx\" --out-file-extension \".js\" --ignore \"**/*.test.*,**/*.doc.mjs,**/*.d.ts,**/*.css*\" --config-file ./babel.config.cjs",
142
142
  "test": "vitest run --root ../..",
143
143
  "test:watch": "vitest --root ../..",
144
144
  "lint": "eslint src",
145
145
  "typecheck:docs": "tsc --project tsconfig.docs.json",
146
- "typecheck": "tsc --project tsconfig.json --noEmit"
146
+ "typecheck": "tsc --project tsconfig.json --noEmit && pnpm typecheck:docs"
147
147
  }
148
148
  }
@@ -25,6 +25,8 @@ import {Icon} from '@astryxdesign/core/Icon';
25
25
  import {IconButton} from '@astryxdesign/core/IconButton';
26
26
  import {useClipboard} from '@astryxdesign/core/hooks';
27
27
  import {useTranslator} from '@astryxdesign/core/i18n';
28
+ import type {CodeLanguage} from '@astryxdesign/core/CodeBlock';
29
+ import {listedLanguage} from './codeLanguages';
28
30
  import {
29
31
  fontWeightVars,
30
32
  spacingVars,
@@ -119,8 +121,11 @@ function samePlacements(
119
121
 
120
122
  function CodeBlockHeader({
121
123
  placement,
124
+ label,
122
125
  }: {
123
126
  readonly placement: HeaderPlacement;
127
+ /** The matched language value's name, when a listed value claims the fence. */
128
+ readonly label?: string;
124
129
  }): JSX.Element {
125
130
  const [editor] = useLexicalComposerContext();
126
131
  const t = useTranslator();
@@ -170,7 +175,7 @@ function CodeBlockHeader({
170
175
  <div
171
176
  data-richtext-code-header=""
172
177
  {...stylex.props(styles.header, position)}>
173
- <span {...stylex.props(styles.title)}>{placement.language}</span>
178
+ <span {...stylex.props(styles.title)}>{label ?? placement.language}</span>
174
179
  {copyButton}
175
180
  </div>
176
181
  );
@@ -180,7 +185,12 @@ function CodeBlockHeader({
180
185
  * Draws a header over each top-level code block and keeps it there as the
181
186
  * document, the editor's size, or the window changes.
182
187
  */
183
- export function CodeBlockHeaderPlugin(): JSX.Element {
188
+ export function CodeBlockHeaderPlugin({
189
+ codeLanguages,
190
+ }: {
191
+ /** Language values a fence may name; a matched fence shows the value's name. */
192
+ codeLanguages?: ReadonlyArray<CodeLanguage>;
193
+ } = {}): JSX.Element {
184
194
  const [editor] = useLexicalComposerContext();
185
195
  const [placements, setPlacements] = useState<ReadonlyArray<HeaderPlacement>>(
186
196
  [],
@@ -255,7 +265,17 @@ export function CodeBlockHeaderPlugin(): JSX.Element {
255
265
  return (
256
266
  <>
257
267
  {placements.map(placement => (
258
- <CodeBlockHeader key={placement.key} placement={placement} />
268
+ <CodeBlockHeader
269
+ key={placement.key}
270
+ placement={placement}
271
+ // A fence matched in `codeLanguages` shows the value's name, as
272
+ // Markdown does (spec:AST-061).
273
+ label={
274
+ placement.language == null
275
+ ? undefined
276
+ : listedLanguage(codeLanguages, placement.language)?.name
277
+ }
278
+ />
259
279
  ))}
260
280
  </>
261
281
  );
@@ -3,6 +3,8 @@
3
3
  import {describe, it, expect} from 'vitest';
4
4
  import {render, screen} from '@testing-library/react';
5
5
  import {tokenize} from '@astryxdesign/core/CodeBlock';
6
+ import {thrift} from '@astryxdesign/core/CodeBlock/languages/thrift';
7
+ import {listedLanguage, sameLanguages} from './codeLanguages';
6
8
  import {renderedTokens} from './CodeSyntaxPlugin';
7
9
  import {RichTextView} from './RichTextView';
8
10
  import {markdownToEditorStateJSON} from './markdownSerializers';
@@ -14,6 +16,24 @@ describe('code block syntax colors (spec:AST-061 FR1)', () => {
14
16
  expect(renderedTokens(code, 'ts', code)).toEqual(tokenize(code, 'ts'));
15
17
  });
16
18
 
19
+ it('paints a listed language value, as Markdown does (CodeBlock FR13)', () => {
20
+ const idl = 'struct User {}';
21
+ expect(renderedTokens(idl, 'thrift', idl)?.flat()).toEqual([]);
22
+ expect(
23
+ renderedTokens(idl, listedLanguage([thrift], 'thrift') ?? 'thrift', idl)
24
+ ?.flat()
25
+ .map(t => t.type),
26
+ ).toContain('keyword');
27
+ expect(listedLanguage([thrift], 'graphql')).toBeUndefined();
28
+ });
29
+
30
+ it('treats lists naming the same values as the same', () => {
31
+ expect(sameLanguages([thrift], [thrift])).toBe(true);
32
+ expect(sameLanguages(undefined, undefined)).toBe(true);
33
+ expect(sameLanguages([thrift], [])).toBe(false);
34
+ expect(sameLanguages([thrift], undefined)).toBe(false);
35
+ });
36
+
17
37
  it('lays the tokens over the text as one line when line breaks render without text', () => {
18
38
  const rendered = code.replace('\n', '');
19
39
  const [line] = renderedTokens(code, 'ts', rendered) ?? [];
@@ -21,7 +21,7 @@
21
21
  * changes. Browsers without the Highlight API show plain code.
22
22
  */
23
23
 
24
- import {useEffect} from 'react';
24
+ import {useEffect, useState} from 'react';
25
25
  import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
26
26
  import {$isCodeNode, CodeNode} from '@lexical/code';
27
27
  import {$getNodeByKey, type NodeKey} from 'lexical';
@@ -29,8 +29,10 @@ import {
29
29
  applyHighlightRangesFlat,
30
30
  TOKEN_TYPES,
31
31
  tokenize,
32
+ type CodeLanguage,
32
33
  type TokenLine,
33
34
  } from '@astryxdesign/core/CodeBlock';
35
+ import {listedLanguage, sameLanguages} from './codeLanguages';
34
36
 
35
37
  /** The class the theme adds to every code block (editorTheme.ts). */
36
38
  export const CODE_SYNTAX_CLASS = 'astryx-richtext-code';
@@ -71,7 +73,7 @@ function supportsHighlights(): boolean {
71
73
  */
72
74
  export function renderedTokens(
73
75
  code: string,
74
- language: string,
76
+ language: string | CodeLanguage,
75
77
  rendered: string,
76
78
  ): TokenLine[] | null {
77
79
  const lines = tokenize(code, language);
@@ -103,9 +105,24 @@ interface Colored {
103
105
  readonly cleanup: () => void;
104
106
  }
105
107
 
106
- export function CodeSyntaxPlugin(): null {
108
+ export function CodeSyntaxPlugin({
109
+ codeLanguages,
110
+ }: {
111
+ /** Language values a fence may name (component:Markdown FR30). */
112
+ codeLanguages?: ReadonlyArray<CodeLanguage>;
113
+ } = {}): null {
107
114
  const [editor] = useLexicalComposerContext();
115
+ // Keep one list while it names the same values, so an inline
116
+ // `codeLanguages={[…]}` does not re-colour every block on each parent
117
+ // render (adjusting state during render, not in an Effect).
118
+ const [languages, setLanguages] = useState(codeLanguages);
119
+ if (!sameLanguages(languages, codeLanguages)) {
120
+ setLanguages(codeLanguages);
121
+ }
108
122
 
123
+ // Synchronizes the editor's code blocks with the CSS highlight registry:
124
+ // Lexical update and mutation listeners colour each block, and the cleanup
125
+ // removes the listeners and every highlight range they added.
109
126
  useEffect(() => {
110
127
  if (!supportsHighlights()) {
111
128
  return undefined;
@@ -142,7 +159,7 @@ export function CodeSyntaxPlugin(): null {
142
159
  previous?.cleanup();
143
160
  const tokens = renderedTokens(
144
161
  block.code,
145
- block.language,
162
+ listedLanguage(languages, block.language) ?? block.language,
146
163
  element.textContent ?? '',
147
164
  );
148
165
  if (tokens == null) {
@@ -187,7 +204,7 @@ export function CodeSyntaxPlugin(): null {
187
204
  }
188
205
  blocks.clear();
189
206
  };
190
- }, [editor]);
207
+ }, [editor, languages]);
191
208
 
192
209
  return null;
193
210
  }
@@ -138,6 +138,12 @@ export const docs = {
138
138
  description:
139
139
  'Markdown plugins whose nodes the editor draws, each adopted with createRichTextExtension. A plugin node renders exactly as core Markdown renders it and edits as one unit; a node whose plugin is not given here shows its source. Pass the extensions the content was converted with, and create them in a client module. RichTextView takes the same prop.',
140
140
  },
141
+ {
142
+ name: 'codeLanguages',
143
+ type: 'ReadonlyArray<CodeLanguage>',
144
+ description:
145
+ 'CodeBlock language values a fence may name, each imported on its own (e.g. graphql from @astryxdesign/core/CodeBlock/languages/graphql) or made with createCodeLanguage. Pass the same list as Markdown codeLanguages so a matched fence paints and labels the same while reading and editing. RichTextView takes the same prop.',
146
+ },
141
147
  {
142
148
  name: 'transformers',
143
149
  type: 'ReadonlyArray<Transformer>',
@@ -318,6 +318,7 @@ describe('RichTextEditor', () => {
318
318
  'plugins',
319
319
  'hasMarkdownShortcuts',
320
320
  'markdownExtensions',
321
+ 'codeLanguages',
321
322
  'transformers',
322
323
  'hasAutoFocus',
323
324
  'tabEscapeHint',
@@ -76,6 +76,7 @@ import {CodeBlockHeaderPlugin} from './CodeBlockHeaderPlugin';
76
76
  import {CodeSyntaxPlugin} from './CodeSyntaxPlugin';
77
77
  import {MarkdownExtensionsPlugin} from './MarkdownExtensionsPlugin';
78
78
  import type {RichTextMarkdownExtension} from './markdownExtensions';
79
+ import type {CodeLanguage} from '@astryxdesign/core/CodeBlock';
79
80
  import {TaskCheckboxPlugin} from './TaskCheckboxPlugin';
80
81
  import {type Transformer} from '@lexical/markdown';
81
82
  import {$generateHtmlFromNodes} from '@lexical/html';
@@ -226,7 +227,7 @@ const styles = stylex.create({
226
227
  color: colorVars['--color-text-secondary'],
227
228
  },
228
229
  counterError: {
229
- color: colorVars['--color-error'],
230
+ color: colorVars['--color-text-error'],
230
231
  },
231
232
  });
232
233
 
@@ -442,6 +443,14 @@ export interface RichTextEditorProps extends Omit<
442
443
  * serializable props.
443
444
  */
444
445
  markdownExtensions?: ReadonlyArray<RichTextMarkdownExtension>;
446
+ /**
447
+ * CodeBlock language values a fence may name, each imported on its own,
448
+ * such as `graphql` from `@astryxdesign/core/CodeBlock/languages/graphql`,
449
+ * or made with `createCodeLanguage`. Pass the same list as `Markdown`'s
450
+ * `codeLanguages`, so reading and editing paint and label the same
451
+ * languages (spec:AST-061).
452
+ */
453
+ codeLanguages?: ReadonlyArray<CodeLanguage>;
445
454
  /** Whether to automatically focus the editor on mount. @default false */
446
455
  hasAutoFocus?: boolean;
447
456
  /**
@@ -515,6 +524,7 @@ export const RichTextEditor = function RichTextEditor({
515
524
  hasMarkdownShortcuts = true,
516
525
  transformers = DEFAULT_TRANSFORMERS,
517
526
  markdownExtensions,
527
+ codeLanguages,
518
528
  hasAutoFocus = false,
519
529
  tabEscapeHint: tabEscapeHintFromProps,
520
530
  maxLength,
@@ -705,8 +715,8 @@ export const RichTextEditor = function RichTextEditor({
705
715
  hasHorizontalScroll
706
716
  />
707
717
  <TableColumnFloorPlugin />
708
- <CodeBlockHeaderPlugin />
709
- <CodeSyntaxPlugin />
718
+ <CodeBlockHeaderPlugin codeLanguages={codeLanguages} />
719
+ <CodeSyntaxPlugin codeLanguages={codeLanguages} />
710
720
  {markdownExtensions != null && markdownExtensions.length > 0 ? (
711
721
  <MarkdownExtensionsPlugin
712
722
  extensions={markdownExtensions}
@@ -41,6 +41,7 @@ import {CodeBlockHeaderPlugin} from './CodeBlockHeaderPlugin';
41
41
  import {CodeSyntaxPlugin} from './CodeSyntaxPlugin';
42
42
  import {MarkdownExtensionsPlugin} from './MarkdownExtensionsPlugin';
43
43
  import type {RichTextMarkdownExtension} from './markdownExtensions';
44
+ import type {CodeLanguage} from '@astryxdesign/core/CodeBlock';
44
45
  import {TaskCheckboxPlugin} from './TaskCheckboxPlugin';
45
46
  import type {
46
47
  AnyLexicalExtension,
@@ -119,6 +120,14 @@ export interface RichTextViewProps extends BaseProps {
119
120
  * serializable props.
120
121
  */
121
122
  markdownExtensions?: ReadonlyArray<RichTextMarkdownExtension>;
123
+ /**
124
+ * CodeBlock language values a fence may name, each imported on its own,
125
+ * such as `graphql` from `@astryxdesign/core/CodeBlock/languages/graphql`,
126
+ * or made with `createCodeLanguage`. Pass the same list as `Markdown`'s
127
+ * `codeLanguages`, so reading and editing paint and label the same
128
+ * languages (spec:AST-061).
129
+ */
130
+ codeLanguages?: ReadonlyArray<CodeLanguage>;
122
131
  /**
123
132
  * Additional read-only plugins to render inside the composer (e.g. hover
124
133
  * cards, decorators).
@@ -202,6 +211,7 @@ export function RichTextView({
202
211
  value,
203
212
  nodes,
204
213
  markdownExtensions,
214
+ codeLanguages,
205
215
  plugins,
206
216
  namespace = 'astryx-view',
207
217
  onParseError,
@@ -323,8 +333,8 @@ export function RichTextView({
323
333
  />
324
334
  {/* After the content, so the copy buttons and checkboxes follow it
325
335
  in tab order. */}
326
- <CodeBlockHeaderPlugin />
327
- <CodeSyntaxPlugin />
336
+ <CodeBlockHeaderPlugin codeLanguages={codeLanguages} />
337
+ <CodeSyntaxPlugin codeLanguages={codeLanguages} />
328
338
  {markdownExtensions != null && markdownExtensions.length > 0 ? (
329
339
  <MarkdownExtensionsPlugin
330
340
  extensions={markdownExtensions}
@@ -1,4 +1,5 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ // @pr-a11y scope core/Markdown richtext/* ^(apps/storybook/stories/RichTextEditor\.(markdownParity|stories)|packages/richtext/src/__tests__/(MarkdownParitySandbox|RichTextView|RichTextEditorToolbar)) ^packages/richtext/src/
2
3
 
3
4
  /**
4
5
  * @file MarkdownParitySandbox.a11y.chromium.spec.ts
@@ -807,7 +808,7 @@ for (const viewport of [PHONE, DESKTOP, {width: 2200, height: 900}] as const) {
807
808
  // One header per fenced block; the first is the `ts` block's.
808
809
  await expect(
809
810
  page.locator(`${RICH_TEXT} [data-richtext-code-header]`),
810
- ).toHaveCount(6);
811
+ ).toHaveCount(7);
811
812
  const header = page
812
813
  .locator(`${RICH_TEXT} [data-richtext-code-header]`)
813
814
  .first();
@@ -890,6 +891,7 @@ for (const globals of [
890
891
  'code-plaintext': '',
891
892
  'code-unknown': 'notalanguage',
892
893
  'code-long': 'sh',
894
+ 'code-plain-long': '',
893
895
  } as const;
894
896
  const markdown = await surfaceGeometry(page, MARKDOWN);
895
897
  const richText = await surfaceGeometry(page, RICH_TEXT);
@@ -904,6 +906,42 @@ for (const globals of [
904
906
  `${key} height`,
905
907
  ).toBeLessThanOrEqual(2);
906
908
  }
909
+ // A fence that names no language keeps its corner copy button beside the
910
+ // code, never over it: the text ends as far from the frame's inline end
911
+ // on both surfaces.
912
+ const textInset = (surface: string, key: string) =>
913
+ page.evaluate(
914
+ ({selector}) => {
915
+ const block = document.querySelector<HTMLElement>(selector);
916
+ const frame = block?.matches('pre, code')
917
+ ? block
918
+ : block?.querySelector<HTMLElement>('pre, code');
919
+ if (frame == null) {
920
+ return -1;
921
+ }
922
+ const rect = frame.getBoundingClientRect();
923
+ const style = getComputedStyle(frame);
924
+ const rtl = style.direction === 'rtl';
925
+ const line = frame.querySelector('[data-line="1"]');
926
+ if (line != null) {
927
+ const text = line.getBoundingClientRect();
928
+ return rtl ? text.left - rect.left : rect.right - text.right;
929
+ }
930
+ return rtl
931
+ ? parseFloat(style.borderLeftWidth) + parseFloat(style.paddingLeft)
932
+ : parseFloat(style.borderRightWidth) +
933
+ parseFloat(style.paddingRight);
934
+ },
935
+ {selector: `${surface} [data-parity-block="${key}"]`},
936
+ );
937
+ for (const key of ['code-plain', 'code-plain-long']) {
938
+ const markdownInset = await textInset(MARKDOWN, key);
939
+ expect(markdownInset, `${key} markdown inset`).toBeGreaterThan(40);
940
+ expect(
941
+ Math.abs((await textInset(RICH_TEXT, key)) - markdownInset),
942
+ `${key} text inset`,
943
+ ).toBeLessThanOrEqual(2);
944
+ }
907
945
  // The label core Markdown shows for each fence.
908
946
  const markdownLabels = await page.evaluate(
909
947
  ({selector, names}) =>
@@ -926,14 +964,14 @@ for (const globals of [
926
964
  // RichText draws one header per fence, in order, each with a copy button
927
965
  // and the same label.
928
966
  const headers = page.locator(`${RICH_TEXT} [data-richtext-code-header]`);
929
- await expect(headers).toHaveCount(6);
967
+ await expect(headers).toHaveCount(7);
930
968
  const richTextLabels = await headers.evaluateAll(elements =>
931
969
  elements.map(element =>
932
970
  (element.textContent ?? '').replace('Copy code', '').trim(),
933
971
  ),
934
972
  );
935
973
  expect(richTextLabels).toEqual(Object.values(fences));
936
- for (const index of [0, 1, 2, 3, 4, 5]) {
974
+ for (const index of [0, 1, 2, 3, 4, 5, 6]) {
937
975
  await expect(
938
976
  headers.nth(index).getByRole('button', {name: 'Copy code'}),
939
977
  ).toBeVisible();
@@ -1,4 +1,5 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ // @pr-a11y release-only
2
3
 
3
4
  /**
4
5
  * @file MarkdownPlugins.a11y.chromium.spec.ts
@@ -1,4 +1,5 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ // @pr-a11y release-only
2
3
 
3
4
  /**
4
5
  * @file MarkdownPluginsImportExport.a11y.chromium.spec.ts
@@ -1,4 +1,5 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ // @pr-a11y release-only
2
3
 
3
4
  /**
4
5
  * @file Playground.a11y.chromium.spec.ts
@@ -0,0 +1,61 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file RichTextCodeLanguages.a11y.chromium.spec.ts
5
+ * @input The built Storybook's "Code language modules" story: one Thrift
6
+ * fence with `codeLanguages={[thrift]}` and the same fence without it
7
+ * @output CodeBlock FR13 for RichText in a real browser: CodeSyntaxPlugin
8
+ * paints a listed value and labels with its name; unlisted stays plain
9
+ * @position spec:AST-061 read/edit parity, CodeBlock FR13 evidence
10
+ */
11
+
12
+ import {expect, test, type Page} from '@playwright/test';
13
+ import {
14
+ DEFAULT_STORYBOOK_DIR,
15
+ serveStorybook,
16
+ type StaticServer,
17
+ } from '@astryxdesign/a11y-spec/storybook';
18
+
19
+ let storybook: StaticServer;
20
+ test.beforeAll(async () => {
21
+ storybook = await serveStorybook(
22
+ process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR,
23
+ );
24
+ });
25
+ test.afterAll(async () => {
26
+ await storybook?.close();
27
+ });
28
+
29
+ /** The keyword-highlighted text inside the element with `testId`. */
30
+ async function keywordsIn(page: Page, testId: string) {
31
+ return page.evaluate(id => {
32
+ const root = document.querySelector(`[data-testid="${id}"]`);
33
+ const highlight = CSS.highlights.get('astryx-keyword');
34
+ if (!root || !highlight) {
35
+ return [];
36
+ }
37
+ return Array.from(highlight as unknown as Iterable<Range>)
38
+ .filter(range => root.contains(range.startContainer))
39
+ .map(range => range.toString());
40
+ }, testId);
41
+ }
42
+
43
+ test('RichText code blocks colour and label a listed language value', async ({
44
+ page,
45
+ }) => {
46
+ await page.goto(
47
+ `${storybook.origin}/iframe.html?id=richtext-richtexteditor--code-language-modules&viewMode=story`,
48
+ );
49
+ await expect(page.getByText('struct User {').first()).toBeVisible();
50
+ await expect
51
+ .poll(async () => keywordsIn(page, 'listed'))
52
+ .toEqual(expect.arrayContaining(['struct', 'required', 'string']));
53
+ expect(await keywordsIn(page, 'unlisted')).toEqual([]);
54
+ await expect(
55
+ page.locator('[data-testid="listed"] [data-richtext-code-header]'),
56
+ ).toContainText('thrift');
57
+ // An `objc` fence matched by objectiveC is labelled with the value's name.
58
+ await expect(
59
+ page.locator('[data-testid="listed-renamed"] [data-richtext-code-header]'),
60
+ ).toContainText('objective-c');
61
+ });
@@ -1,4 +1,5 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ // @pr-a11y scope core/Markdown richtext/* ^(apps/storybook/stories/RichTextEditor\.(markdownParity|stories)|packages/richtext/src/__tests__/(MarkdownParitySandbox|RichTextView|RichTextEditorToolbar)) ^packages/richtext/src/
2
3
 
3
4
  /**
4
5
  * @file RichTextEditorToolbar.a11y.chromium.spec.ts
@@ -1,4 +1,5 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ // @pr-a11y scope core/Markdown richtext/* ^(apps/storybook/stories/RichTextEditor\.(markdownParity|stories)|packages/richtext/src/__tests__/(MarkdownParitySandbox|RichTextView|RichTextEditorToolbar)) ^packages/richtext/src/
2
3
 
3
4
  /**
4
5
  * @file RichTextView.a11y.chromium.spec.ts
@@ -1,4 +1,5 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ // @pr-a11y release-only
2
3
 
3
4
  /**
4
5
  * @file TableCellSelection.a11y.chromium.spec.ts
@@ -0,0 +1,42 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file codeLanguages.ts
5
+ * @input CodeLanguage values from @astryxdesign/core/CodeBlock
6
+ * @output listedLanguage, which finds the listed value a fence word names, and
7
+ * sameLanguages, which compares two lists entry by entry
8
+ * @position Shared by CodeSyntaxPlugin and CodeBlockHeaderPlugin, so RichText
9
+ * resolves a fence as Markdown does (component:Markdown FR30)
10
+ */
11
+
12
+ import type {CodeLanguage} from '@astryxdesign/core/CodeBlock';
13
+
14
+ /** The listed value whose identifiers include `word`; a later entry wins. */
15
+ export function listedLanguage(
16
+ languages: ReadonlyArray<CodeLanguage> | undefined,
17
+ word: string,
18
+ ): CodeLanguage | undefined {
19
+ if (languages == null) {
20
+ return undefined;
21
+ }
22
+ for (let i = languages.length - 1; i >= 0; i--) {
23
+ if (languages[i].identifiers.includes(word)) {
24
+ return languages[i];
25
+ }
26
+ }
27
+ return undefined;
28
+ }
29
+
30
+ /** Whether two lists name the same values in the same order. */
31
+ export function sameLanguages(
32
+ a: ReadonlyArray<CodeLanguage> | undefined,
33
+ b: ReadonlyArray<CodeLanguage> | undefined,
34
+ ): boolean {
35
+ if (a === b) {
36
+ return true;
37
+ }
38
+ if (a == null || b == null || a.length !== b.length) {
39
+ return false;
40
+ }
41
+ return a.every((language, i) => language === b[i]);
42
+ }
@@ -53,6 +53,10 @@ const CODE_SPACE = `calc(${spacingVars['--spacing-3']})`;
53
53
  // Core CodeBlock's header (8px, a small control, 8px) overlaps the code's
54
54
  // 12px top padding by 8px, so its code starts 8px + control + 12px down.
55
55
  const CODE_HEADER_SPACE = `calc(${spacingVars['--spacing-2']} + ${sizeVars['--size-element-sm']} + ${spacingVars['--spacing-3']})`;
56
+ // A block that names no language has no header: core CodeBlock puts its copy
57
+ // button in a column of its own at the inline end (8px, a small control, 8px),
58
+ // beside the code rather than over it, so the code ends that much earlier.
59
+ const CODE_CORNER_SPACE = `calc(${spacingVars['--spacing-4']} + ${sizeVars['--size-element-sm']} + 2 * ${spacingVars['--spacing-2']})`;
56
60
 
57
61
  const editorTheme = stylex.create({
58
62
  // Lexical marks every top-level block `dir="auto"`, which picks each
@@ -443,7 +447,14 @@ const editorTheme = stylex.create({
443
447
  CODE_HEADER_SPACE,
444
448
  },
445
449
  paddingBlockEnd: spacingVars['--spacing-3'],
446
- paddingInline: spacingVars['--spacing-4'],
450
+ paddingInlineStart: spacingVars['--spacing-4'],
451
+ paddingInlineEnd: {
452
+ // Room for the corner copy button CodeBlockHeaderPlugin draws over a
453
+ // block that names no language, so no line runs under it.
454
+ default: CODE_CORNER_SPACE,
455
+ ':is([data-language]:not([data-language="plaintext"]))':
456
+ spacingVars['--spacing-4'],
457
+ },
447
458
  // Sized like core Markdown's code frame: as wide as its longest line, at
448
459
  // least the prose measure (or the whole width when that is narrower), and
449
460
  // never wider than the editor, where long lines wrap.