@astryxdesign/richtext 0.7.17-canary.g5a3fd39 → 0.7.17-canary.g5cf5d69

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.
@@ -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,EAIL,KAAK,SAAS,EACf,MAAM,0BAA0B,CAAC;AAyBlC,OAAO,KAAK,EAAC,yBAAyB,EAAC,MAAM,sBAAsB,CAAC;AACpE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,8BAA8B,CAAC;AAM/D,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;AAyJjB,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,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,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,cAAc;2ZAiCxB,mBAAmB;;CAqQrB,CAAC"}
@@ -54,6 +54,7 @@ import { CodeBackspacePlugin } from "./internal/CodeBackspacePlugin.js";
54
54
  import { CodeBlockHeaderPlugin } from "./internal/CodeBlockHeaderPlugin.js";
55
55
  import { CodePastePlugin } from "./internal/CodePastePlugin.js";
56
56
  import { CodeSyntaxPlugin } from "./internal/CodeSyntaxPlugin.js";
57
+ import { BlockDirectionPlugin } from "./internal/BlockDirectionPlugin.js";
57
58
  import { CodeTabPlugin } from "./internal/CodeTabPlugin.js";
58
59
  import { MarkdownExtensionsPlugin } from "./internal/MarkdownExtensionsPlugin.js";
59
60
  import { TaskCheckboxPlugin } from "./internal/TaskCheckboxPlugin.js";
@@ -337,7 +338,7 @@ export const RichTextEditor = function RichTextEditor({
337
338
  }[!!hasToolbar << 2 | !!!!statusIcon << 1 | !!(size === 'lg') << 0],
338
339
  children: [/*#__PURE__*/_jsxs("div", {
339
340
  ...{
340
- className: "x1n2onr6 xh8yej3 x9ynric xjm74w1 xf9zqsd xw6l6zx"
341
+ className: "xrjygrn xss4jc1 x1n2onr6 xh8yej3 x9ynric xjm74w1 xf9zqsd xw6l6zx"
341
342
  },
342
343
  dir: rest.dir,
343
344
  children: [/*#__PURE__*/_jsx(RichTextPlugin, {
@@ -370,7 +371,7 @@ export const RichTextEditor = function RichTextEditor({
370
371
  codeLanguages: codeLanguages
371
372
  }), /*#__PURE__*/_jsx(CodeSyntaxPlugin, {
372
373
  codeLanguages: codeLanguages
373
- }), /*#__PURE__*/_jsx(CodeBackspacePlugin, {}), /*#__PURE__*/_jsx(CodePastePlugin, {}), markdownExtensions != null && markdownExtensions.length > 0 ? /*#__PURE__*/_jsx(MarkdownExtensionsPlugin, {
374
+ }), /*#__PURE__*/_jsx(BlockDirectionPlugin, {}), /*#__PURE__*/_jsx(CodeBackspacePlugin, {}), /*#__PURE__*/_jsx(CodePastePlugin, {}), markdownExtensions != null && markdownExtensions.length > 0 ? /*#__PURE__*/_jsx(MarkdownExtensionsPlugin, {
374
375
  extensions: markdownExtensions,
375
376
  transformers: markdownTransformers
376
377
  }) : null, /*#__PURE__*/_jsx(CodeTabPlugin, {}), /*#__PURE__*/_jsx(TabIndentationPlugin, {}), /*#__PURE__*/_jsx(TabFocusEscapePlugin, {}), /*#__PURE__*/_jsx(SelectAllScopePlugin, {}), /*#__PURE__*/_jsx(ImageSourceCaretPlugin, {}), hasMarkdownShortcuts && /*#__PURE__*/_jsx(MarkdownShortcutPlugin, {
@@ -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;AACpE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,8BAA8B,CAAC;AAE/D,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;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IAC5C;;;OAGG;IACH,OAAO,CAAC,EAAE,SAAS,C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6D;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,aAAa,EACb,OAAO,EACP,SAAyB,EACzB,YAAY,EACZ,aAAoB,EACpB,MAAM,EACN,SAAS,EACT,KAAK,EACL,GAAG,IAAI,EACR,EAAE,iBAAiB,+BA+HnB;yBA5Ie,YAAY"}
@@ -33,6 +33,7 @@ import { TableScrollRegionPlugin } from "./internal/TableScrollRegionPlugin.js";
33
33
  import { TableColumnFloorPlugin } from "./internal/TableColumnFloorPlugin.js";
34
34
  import { CodeBlockHeaderPlugin } from "./internal/CodeBlockHeaderPlugin.js";
35
35
  import { CodeSyntaxPlugin } from "./internal/CodeSyntaxPlugin.js";
36
+ import { BlockDirectionPlugin } from "./internal/BlockDirectionPlugin.js";
36
37
  import { MarkdownExtensionsPlugin } from "./internal/MarkdownExtensionsPlugin.js";
37
38
  import { TaskCheckboxPlugin } from "./internal/TaskCheckboxPlugin.js";
38
39
  import { defineExtension } from 'lexical';
@@ -42,6 +43,7 @@ import { DEFAULT_NODES } from "./editorNodes.js";
42
43
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
43
44
  const styles = {
44
45
  root: {
46
+ "--_richtext-document-direction": "xrjygrn xss4jc1",
45
47
  kzqmXN: "xh8yej3",
46
48
  kVAEAm: "x1n2onr6",
47
49
  kMv6JI: "x9ynric",
@@ -255,7 +257,7 @@ export function RichTextView({
255
257
  codeLanguages: codeLanguages
256
258
  }), /*#__PURE__*/_jsx(CodeSyntaxPlugin, {
257
259
  codeLanguages: codeLanguages
258
- }), markdownExtensions != null && markdownExtensions.length > 0 ? /*#__PURE__*/_jsx(MarkdownExtensionsPlugin, {
260
+ }), /*#__PURE__*/_jsx(BlockDirectionPlugin, {}), markdownExtensions != null && markdownExtensions.length > 0 ? /*#__PURE__*/_jsx(MarkdownExtensionsPlugin, {
259
261
  extensions: markdownExtensions,
260
262
  transformers: NO_TRANSFORMERS
261
263
  }) : null, /*#__PURE__*/_jsx(TaskCheckboxPlugin, {
@@ -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;AAschD;;;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;AAgfhD;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,kBAAkB,CAyEtD"}
@@ -47,8 +47,17 @@ const CODE_HEADER_SPACE = `calc(${spacingVars['--spacing-2']} + ${sizeVars['--si
47
47
  // beside the code rather than over it, so the code ends that much earlier.
48
48
  const CODE_CORNER_SPACE = `calc(${spacingVars['--spacing-4']} + ${sizeVars['--size-element-sm']} + 2 * ${spacingVars['--spacing-2']})`;
49
49
  const editorTheme = {
50
- providerDirection: {
50
+ blockDirection: {
51
+ ksoyAI: "x2dh0mw xz38kqs",
52
+ $$css: true
53
+ },
54
+ surfaceDirection: {
55
+ ksoyAI: "x1epdd7z",
56
+ $$css: true
57
+ },
58
+ codeDirection: {
51
59
  ksoyAI: "x1epdd7z",
60
+ kQ0QjF: "xa7awgv",
52
61
  $$css: true
53
62
  },
54
63
  paragraph: {
@@ -135,7 +144,7 @@ const editorTheme = {
135
144
  keoZOQ: "x1ftnraw xnhvf09",
136
145
  k1K539: "x18pneqc xfo59cc",
137
146
  ks0D6T: "x7ep2pv",
138
- kZCmMZ: "x31w388",
147
+ kg3NbH: "x17a0aqu",
139
148
  kpqbRz: "x43c9pm",
140
149
  $$css: true
141
150
  },
@@ -143,7 +152,7 @@ const editorTheme = {
143
152
  keoZOQ: "x1ftnraw xnhvf09",
144
153
  k1K539: "x18pneqc xfo59cc",
145
154
  ks0D6T: "x7ep2pv",
146
- kZCmMZ: "x31w388",
155
+ kg3NbH: "x17a0aqu",
147
156
  kpqbRz: "x43c9pm",
148
157
  $$css: true
149
158
  },
@@ -171,6 +180,16 @@ const editorTheme = {
171
180
  kH6xsr: "x19k9dhg",
172
181
  $$css: true
173
182
  },
183
+ listItem: {
184
+ kLKAdn: "x1f3mx8c xmvvslv x1uerj9w",
185
+ kGO01o: "x13xdy6z",
186
+ keoZOQ: "x1wqhfsw xkuhcwz xsgnyjk",
187
+ k1K539: "x10j6jf0 xfo59cc",
188
+ kH6xsr: "x1sle589 x81k3mc xovwveo x2i8j16",
189
+ keTefX: "x1l10yog x1w4ozbb",
190
+ kZCmMZ: "xbj1ybn x1kuvm45",
191
+ $$css: true
192
+ },
174
193
  tableScrollableWrapper: {
175
194
  kXHlph: "xw2csxc",
176
195
  ks0D6T: "x193iq5w",
@@ -250,8 +269,14 @@ const editorTheme = {
250
269
  * class-name strings, which `stylex.props(...).className` yields.
251
270
  */
252
271
  export function sharedEditorTheme() {
253
- // A class for a block Lexical may mark `dir="auto"`.
254
- const block = (...styles) => stylex.props(...styles, editorTheme.providerDirection).className ?? '';
272
+ // A class for a block Lexical can mark `dir="auto"`: it reads its own way
273
+ // once BlockDirectionPlugin has written a direction onto it, and follows
274
+ // the document while it still says `auto`.
275
+ const block = (...styles) => stylex.props(...styles, editorTheme.blockDirection).className ?? '';
276
+ // A class for a container — a list, a table and its parts — which orders
277
+ // its contents in its parent's direction: the document's at the top level,
278
+ // its wrapper item's when nested.
279
+ const container = (...styles) => stylex.props(...styles, editorTheme.surfaceDirection).className ?? '';
255
280
  const className = style => stylex.props(style).className ?? '';
256
281
  return {
257
282
  paragraph: block(editorTheme.paragraph),
@@ -268,15 +293,13 @@ export function sharedEditorTheme() {
268
293
  },
269
294
  quote: block(editorTheme.quote),
270
295
  list: {
271
- ul: block(editorTheme.ul),
272
- ol: block(editorTheme.ol),
273
- listitem: {
274
- className: "x1f3mx8c xmvvslv x1uerj9w x13xdy6z x1wqhfsw xkuhcwz xsgnyjk x10j6jf0 xfo59cc x1sle589 x81k3mc xovwveo x2i8j16 x8yim9t x1pvqllw xbj1ybn x1kuvm45"
275
- }.className,
296
+ ul: container(editorTheme.ul),
297
+ ol: container(editorTheme.ol),
298
+ // An item is prose: it reads the way its own text reads, and the
299
+ // document's way when its text decides nothing.
300
+ listitem: block(editorTheme.listItem),
276
301
  nested: {
277
- listitem: {
278
- className: "x1f3mx8c xmvvslv x1uerj9w x13xdy6z x1wqhfsw xkuhcwz xsgnyjk x10j6jf0 xfo59cc x1sle589 x81k3mc xovwveo x2i8j16 x8yim9t x1pvqllw xbj1ybn x1kuvm45"
279
- }.className
302
+ listitem: block(editorTheme.listItem)
280
303
  },
281
304
  // Lexical picks the class at `depth % 3` (spec:AST-061 DEC-6).
282
305
  ulDepth: [className(editorTheme.ulMarker0), className(editorTheme.ulMarker1), className(editorTheme.ulMarker2)],
@@ -303,7 +326,7 @@ export function sharedEditorTheme() {
303
326
  }.className
304
327
  },
305
328
  // The plain class lets CodeSyntaxPlugin's highlight rules find code blocks.
306
- code: `${block(editorTheme.code)} ${CODE_SYNTAX_CLASS}`,
329
+ code: `${container(editorTheme.code)} ${className(editorTheme.codeDirection)} ${CODE_SYNTAX_CLASS}`,
307
330
  hr: {
308
331
  className: "xc342km x11xkdxz x13fuv20 x1pc3f07 x13xmvwt xnhvf09 xe66n16 x1qaki06 xfo59cc x1vugyqv"
309
332
  }.className,
@@ -314,15 +337,15 @@ export function sharedEditorTheme() {
314
337
  markdownExtensionSelected: {
315
338
  className: "xak0ai5 x9ssot5 x19bwoy8 x1eqjuhu"
316
339
  }.className,
317
- table: block(editorTheme.table),
340
+ table: container(editorTheme.table),
318
341
  // Lexical stamps rows and cells `dir="auto"` too, which would set a cell
319
342
  // of English text left-to-right inside a right-to-left document.
320
- tableRow: block(editorTheme.tableRow),
321
- tableCell: block(editorTheme.tableCell),
322
- tableCellHeader: block(editorTheme.tableCellHeader),
343
+ tableRow: container(editorTheme.tableRow),
344
+ tableCell: container(editorTheme.tableCell),
345
+ tableCellHeader: container(editorTheme.tableCellHeader),
323
346
  // Added on top of the cell's own class by Lexical while the cell is in a
324
347
  // table selection, so it carries no direction of its own.
325
348
  tableCellSelected: className(editorTheme.tableCellSelected),
326
- tableScrollableWrapper: block(editorTheme.tableScrollableWrapper)
349
+ tableScrollableWrapper: container(editorTheme.tableScrollableWrapper)
327
350
  };
328
351
  }
@@ -0,0 +1,14 @@
1
+ import { type LexicalEditor } from 'lexical';
2
+ /**
3
+ * Keeps every prose container's `dir` equal to the direction of its own
4
+ * text. Returns the usual teardown.
5
+ */
6
+ export declare function registerBlockDirection(editor: LexicalEditor): () => void;
7
+ /**
8
+ * Gives each prose container — paragraph, heading, quote, list item, at any
9
+ * depth — an explicit `dir` taken from its own text, so a strongly
10
+ * directional one reads its own way in either document and one with no
11
+ * direction of its own follows the document.
12
+ */
13
+ export declare function BlockDirectionPlugin(): null;
14
+ //# sourceMappingURL=BlockDirectionPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BlockDirectionPlugin.d.ts","sourceRoot":"","sources":["../../src/internal/BlockDirectionPlugin.tsx"],"names":[],"mappings":"AA+BA,OAAO,EAUL,KAAK,aAAa,EAEnB,MAAM,SAAS,CAAC;AAuMjB;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,IAAI,CAkDxE;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAqB3C"}
@@ -0,0 +1,283 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ /**
6
+ * @file BlockDirectionPlugin.tsx
7
+ * @input Uses @lexical/react (composer context) and the prose container
8
+ * classes, and classifies text with `firstStrongDirection`.
9
+ * @output Exports BlockDirectionPlugin, which gives each prose container an
10
+ * explicit `dir` taken from its own text, and registerBlockDirection for
11
+ * a caller driving a Lexical editor directly.
12
+ * @position Rendered by RichTextEditor and RichTextView inside the composer,
13
+ * so a document reads the same way in both.
14
+ *
15
+ * SYNC: RichTextEditor.tsx and RichTextView.tsx both mount this plugin and
16
+ * set `--_richtext-document-direction` on their own root.
17
+ */
18
+ import { useLayoutEffect } from 'react';
19
+ import { firstStrongDirection } from "./firstStrongDirection.js";
20
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
21
+ import { mergeRegister } from '@lexical/utils';
22
+ import { HeadingNode, QuoteNode } from '@lexical/rich-text';
23
+ import { $isListItemNode, $isListNode, ListItemNode, ListNode } from '@lexical/list';
24
+ import { CodeNode } from '@lexical/code';
25
+ import { TableCellNode, TableNode, TableRowNode } from '@lexical/table';
26
+ import { $getRoot, $isRootNode, $isDecoratorNode, $isElementNode, HISTORY_MERGE_TAG, ParagraphNode, TextNode } from 'lexical';
27
+
28
+ /**
29
+ * The containers read as one piece of prose, so one direction covers the
30
+ * whole of each, at any depth — a paragraph inside a table cell included.
31
+ *
32
+ * Lexical leaves a top-level block at `dir="auto"` and writes none below
33
+ * that, and neither state can say "this block has no direction of its own":
34
+ * under `auto`, digits, an image and an empty block all resolve
35
+ * left-to-right, exactly like English. Writing the direction out separates
36
+ * the two, and Lexical serializes it, so a stored document reopens the way
37
+ * it was written.
38
+ *
39
+ * A list, a fenced code block and a table are not here: they hold several
40
+ * items, lines or cells that are read on their own terms.
41
+ */
42
+ const PROSE_NODES = [ParagraphNode, HeadingNode, QuoteNode, ListItemNode];
43
+
44
+ /**
45
+ * The containers. They take their parent's direction from the theme whatever
46
+ * `dir` says, so an arriving one changes no pixels. It can still arrive from
47
+ * pasted HTML (`$setDirectionFromDOM`) or an older stored document; clearing
48
+ * it keeps the stored state saying what the document shows.
49
+ *
50
+ * A fenced code block has no per-line node to carry a direction, so the
51
+ * theme gives it `unicode-bidi: plaintext` and each line reads its own way.
52
+ * Core `Markdown` reaches the same rule through CodeBlock, which puts each
53
+ * line in its own `dir="auto"` element; `pnpm specs:for` finds the record.
54
+ */
55
+ const CONTAINER_NODES = [ListNode, CodeNode, TableNode, TableRowNode, TableCellNode];
56
+
57
+ /**
58
+ * Whether this node is a prose container that carries its own `dir`.
59
+ *
60
+ * A list item holding a nested list takes one too, from the item it hangs
61
+ * from. The nesting step is an inline margin on the item, so it resolves
62
+ * against that item's own direction: left unwritten it puts the step on the
63
+ * document's side while the items inside start on theirs, and every level of
64
+ * an English list in a right-to-left document then begins at
65
+ * the same edge, with only the marker shape showing the depth.
66
+ */
67
+ function $isOwnDirectionBlock(node) {
68
+ return $isElementNode(node) && PROSE_NODES.some(k => node instanceof k);
69
+ }
70
+
71
+ /**
72
+ * The direction this container's own text asks for; null when it has none.
73
+ *
74
+ * Only text a reader reads counts. A decorator — an image, a chart, an
75
+ * embed — shows no prose of its own, and `getTextContent` gives its
76
+ * alternative text, so a picture captioned in English would turn a Hebrew
77
+ * item left-to-right. Core Markdown skips the same nodes when it reads a
78
+ * block's direction. A fenced code block is skipped for its own reason:
79
+ * each of its lines reads on its own terms.
80
+ *
81
+ * Lexical puts a nested list in an item of its own after the item it hangs
82
+ * from. That holder shows no text and is not a block a reader sees: it
83
+ * belongs to the item above it, and a nested list is anchored on its parent
84
+ * item's text start. So it takes that item's direction, not the direction of
85
+ * the list inside it. Reading its own contents instead would anchor the
86
+ * nested list on whichever language its first item happened to use, which
87
+ * costs an item that reads the other way its nesting step, and leaves a
88
+ * neutral item — digits, an image — following that first item rather than
89
+ * the document.
90
+ */
91
+ function $ownDirection(node) {
92
+ const holds = $heldList(node);
93
+ if (holds !== null) {
94
+ const parentItem = $parentItemOf(node);
95
+ return parentItem === null ? null : $ownDirection(parentItem);
96
+ }
97
+ return firstStrongDirection($proseText(node));
98
+ }
99
+
100
+ /** The list a holder item exists to carry, or null when it carries prose. */
101
+ function $heldList(node) {
102
+ if (!$isListItemNode(node)) {
103
+ return null;
104
+ }
105
+ const children = node.getChildren();
106
+ const lists = children.filter($isListNode);
107
+ return lists.length === 1 && children.length === lists.length ? lists[0] : null;
108
+ }
109
+
110
+ /** The item a holder hangs from: the nearest prose item before it. */
111
+ function $parentItemOf(node) {
112
+ let sibling = node.getPreviousSibling();
113
+ while (sibling !== null) {
114
+ if ($isListItemNode(sibling) && $heldList(sibling) === null) {
115
+ return sibling;
116
+ }
117
+ sibling = sibling.getPreviousSibling();
118
+ }
119
+ return null;
120
+ }
121
+
122
+ /** The text of a node's prose descendants, decorators and code aside. */
123
+ function $proseText(node) {
124
+ let text = '';
125
+ for (const child of node.getChildren()) {
126
+ if ($isDecoratorNode(child) || child instanceof CodeNode) {
127
+ continue;
128
+ }
129
+ text += $isElementNode(child) ? $proseText(child) : child.getTextContent();
130
+ if (firstStrongDirection(text) !== null) {
131
+ break;
132
+ }
133
+ }
134
+ return text;
135
+ }
136
+
137
+ /** Whether this node is a container, which carries no direction of its own. */
138
+ function $isContainer(node) {
139
+ return $isElementNode(node) && CONTAINER_NODES.some(klass => node instanceof klass);
140
+ }
141
+
142
+ /** The direction this node should carry: its text's, or none at all. */
143
+ function $wantedDirection(node) {
144
+ return $isOwnDirectionBlock(node) ? $ownDirection(node) : null;
145
+ }
146
+
147
+ /** Whether this node's `dir` is already what it should be. */
148
+ function $isSettled(node) {
149
+ if ($isRootNode(node)) {
150
+ return node.getDirection() === null;
151
+ }
152
+ if (!$isOwnDirectionBlock(node) && !$isContainer(node)) {
153
+ return true;
154
+ }
155
+ return node.getDirection() === $wantedDirection(node);
156
+ }
157
+
158
+ /** Writes a node's direction onto it, if that is not what it says. */
159
+ function $writeOwnDirection(node) {
160
+ if (!$isSettled(node)) {
161
+ node.setDirection($wantedDirection(node));
162
+ }
163
+ }
164
+
165
+ /**
166
+ * Every prose container at or above this node, nearest first.
167
+ *
168
+ * A keystroke deep in a list changes its own item, and a wrapper above it
169
+ * follows the item it hangs from, so both are written here.
170
+ * All of them have to be written inside the keystroke's own update: the
171
+ * sweep that follows is tagged `history-merge`, which `OnChangePlugin`
172
+ * does not report, so a wrapper left to the sweep would hold a stale
173
+ * direction in the value a caller stores until the next edit.
174
+ */
175
+ function $proseContainers(node) {
176
+ const found = [];
177
+ for (let current = node; current !== null; current = current.getParent()) {
178
+ if ($isOwnDirectionBlock(current)) {
179
+ found.push(current);
180
+ }
181
+ }
182
+ return found;
183
+ }
184
+
185
+ /** Every node whose direction this plugin owns, in document order. */
186
+ function $allProseContainers() {
187
+ const found = [];
188
+ const visit = node => {
189
+ if ($isOwnDirectionBlock(node) || $isContainer(node)) {
190
+ found.push(node);
191
+ }
192
+ if ($isElementNode(node)) {
193
+ node.getChildren().forEach(visit);
194
+ }
195
+ };
196
+ // The root is a container too. Lexical writes a stored root direction onto
197
+ // the editable element, and every container under it inherits, so a value
198
+ // saved in one document direction would lay its tables and code frames out
199
+ // that way in the other. It carries no text of its own, so it always gives
200
+ // the direction up and the surface decides.
201
+ found.push($getRoot());
202
+ $getRoot().getChildren().forEach(visit);
203
+ return found;
204
+ }
205
+
206
+ /**
207
+ * Keeps every prose container's `dir` equal to the direction of its own
208
+ * text. Returns the usual teardown.
209
+ */
210
+ export function registerBlockDirection(editor) {
211
+ return mergeRegister(
212
+ // Typing inside an existing paragraph dirties its text node, not the
213
+ // container, so the text node is where a keystroke can be caught.
214
+ // Running here keeps the direction in the update that changed the text,
215
+ // and so in that keystroke's own history entry: a later `editor.update`
216
+ // would be a history step of its own, and undo would bounce off it.
217
+ editor.registerNodeTransform(TextNode, node => {
218
+ $proseContainers(node).forEach($writeOwnDirection);
219
+ }),
220
+ // A container that gains or loses its text without a text node of its
221
+ // own being dirtied — a new empty paragraph, a heading conversion, a
222
+ // list item split, a deletion that empties a block.
223
+ ...PROSE_NODES.map(klass => editor.registerNodeTransform(klass, node => {
224
+ $proseContainers(node).forEach($writeOwnDirection);
225
+ })),
226
+ // A container that arrives carrying a direction — pasted HTML, or an
227
+ // older stored document — gives it up, so its contents are ordered by
228
+ // the document as they are everywhere else. Removing a node dirties its
229
+ // parent, so a removed list item reaches its list here; the walk settles
230
+ // the wrapper above it in the same update, which the sweep below would
231
+ // otherwise do a history step later.
232
+ ...CONTAINER_NODES.map(klass => editor.registerNodeTransform(klass, node => {
233
+ $writeOwnDirection(node);
234
+ $proseContainers(node).forEach($writeOwnDirection);
235
+ })),
236
+ // Replacing the whole state runs no transform at all, and RichTextView
237
+ // does exactly that whenever its `value` changes. Sweep the document
238
+ // when a container is left disagreeing with its text. The sweep merges
239
+ // into the update that caused it rather than taking an undo step of its
240
+ // own, and writing the direction settles the container, so this does
241
+ // not loop.
242
+ editor.registerUpdateListener(({
243
+ editorState
244
+ }) => {
245
+ const stale = editorState.read(() => $allProseContainers().some(node => !$isSettled(node)));
246
+ if (stale) {
247
+ editor.update(() => {
248
+ $allProseContainers().forEach($writeOwnDirection);
249
+ }, {
250
+ tag: HISTORY_MERGE_TAG
251
+ });
252
+ }
253
+ }));
254
+ }
255
+
256
+ /**
257
+ * Gives each prose container — paragraph, heading, quote, list item, at any
258
+ * depth — an explicit `dir` taken from its own text, so a strongly
259
+ * directional one reads its own way in either document and one with no
260
+ * direction of its own follows the document.
261
+ */
262
+ export function BlockDirectionPlugin() {
263
+ const [editor] = useLexicalComposerContext();
264
+ // A layout effect, not an ordinary one: it runs after Lexical has written
265
+ // the document into the DOM and before the browser paints, so the first
266
+ // frame a reader sees already has every block on its own side. An
267
+ // ordinary effect runs after that frame, which showed an English
268
+ // paragraph right-aligned in a right-to-left page for about one frame
269
+ // before it moved.
270
+ useLayoutEffect(() => {
271
+ const teardown = registerBlockDirection(editor);
272
+ // Registering only arms the transforms; a document already in the
273
+ // editor has run none of them. Settle it now, in this same frame.
274
+ editor.update(() => {
275
+ $allProseContainers().forEach($writeOwnDirection);
276
+ }, {
277
+ discrete: true,
278
+ tag: HISTORY_MERGE_TAG
279
+ });
280
+ return teardown;
281
+ }, [editor]);
282
+ return null;
283
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Approximates rules P2 and P3 of the Unicode Bidirectional Algorithm from
3
+ * script and category: the direction of the first strongly directional
4
+ * character, or null when there is none. It does not skip isolated runs. The
5
+ * loop reads whole code points, so a surrogate pair counts as one character.
6
+ */
7
+ export declare function firstStrongDirection(text: string): 'ltr' | 'rtl' | null;
8
+ //# sourceMappingURL=firstStrongDirection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firstStrongDirection.d.ts","sourceRoot":"","sources":["../../src/internal/firstStrongDirection.ts"],"names":[],"mappings":"AAwFA;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,IAAI,CAgBvE"}
@@ -0,0 +1,104 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file firstStrongDirection.ts
5
+ * @input A string of text
6
+ * @output 'ltr' | 'rtl' | null — the direction of the text's first strongly
7
+ * directional character, or null when it has none
8
+ * @position Classifies a RichText block, so a block reads the way its own
9
+ * text reads. Server-safe: it reads no context.
10
+ *
11
+ * SYNC: a copy of packages/core/src/i18n/firstStrongDirection.ts, which
12
+ * classifies Markdown's blocks. The two surfaces have to answer alike, so a
13
+ * change to either set belongs in both files and in both test files. Core's
14
+ * `internal/*` entry points are reserved for Core and Lab, so RichText keeps
15
+ * its own copy rather than widening that rule; sharing one classifier across
16
+ * packages is its own decision.
17
+ */
18
+
19
+ // Each expression with a Unicode property escape is built at runtime: a
20
+ // source build may rewrite a regular expression literal with one, and the
21
+ // Babel copy that Next.js bundles has no Unicode data to do that.
22
+
23
+ /**
24
+ * The strongly right-to-left characters of the Unicode Bidirectional
25
+ * Algorithm: Bidi_Class `R` and `AL`. The living scripts are named. The two
26
+ * ranges cover the historic right-to-left scripts in the Supplementary
27
+ * Multilingual Plane, which have no script escapes that every engine knows.
28
+ *
29
+ * JavaScript has no `\p{Bidi_Class=...}` escape, so these sets approximate
30
+ * that property from script and category, and name the characters this
31
+ * surface has needed where the two disagree; others still do, as they did
32
+ * before: some Arabic and NKo `ON` signs, `ON` modifier letters, and `L`
33
+ * punctuation. Three `AL` characters have script `Common` and are written
34
+ * out here: the semicolon, the question mark, and tatweel. Tatweel is also a
35
+ * modifier letter, so without it the scan reads an Arabic word that starts
36
+ * with one as left-to-right. The Arabic letter mark is beside them for the
37
+ * same reason.
38
+ */
39
+ const STRONG_RTL = new RegExp(String.raw`[\p{Script=Adlam}\p{Script=Arabic}\p{Script=Hebrew}\p{Script=Mandaic}\p{Script=Nko}\p{Script=Samaritan}\p{Script=Syriac}\p{Script=Thaana}\u061B\u061C\u061F\u0640\u200F\u{10800}-\u{10FFF}\u{1E800}-\u{1EFFF}]`, 'u');
40
+
41
+ /**
42
+ * The characters the scan passes over: Bidi_Class `AN`, `EN`, `ET` and
43
+ * `ON`, none of which decides a direction. Most are the right-to-left
44
+ * scripts' own, and the digits that are weak everywhere are here too: the
45
+ * ASCII, fullwidth and mathematical ones are `EN`.
46
+ *
47
+ * The first group is the Arabic script's own: its digits, the number signs
48
+ * before them, and the currency and per-cent marks beside them.
49
+ *
50
+ * The rest sit inside the two supplementary ranges above, which are drawn
51
+ * around whole planes and so sweep up every digit and mark those scripts
52
+ * carry as well as their letters: the Phoenician word separator, Avestan
53
+ * punctuation, the Hanifi Rohingya, Garay, Yezidi and Rumi digits, a Garay
54
+ * mark, and the Arabic mathematical operators. Each one is verified against
55
+ * the browser's own implementation of the algorithm in
56
+ * firstStrongDirection.test.ts.
57
+ *
58
+ * Membership here is about Bidi_Class, never about looking like a number.
59
+ * The Indic Siyaq and Ottoman Siyaq numerals sit beside Rumi and are
60
+ * Bidi_Class `AL`, so they stay strong; NKo and Adlam digits are `R`, so
61
+ * they do too.
62
+ */
63
+ const WEAK_NUMBER_OR_NEUTRAL = /[0-9\u0600-\u0605\u0609\u060A\u0660-\u0669\u066A-\u066C\u06DD\u06F0-\u06F9\u0890\u0891\u08E2\uFF10-\uFF19\u{1091F}\u{10B39}-\u{10B3F}\u{10D30}-\u{10D39}\u{10D40}-\u{10D49}\u{10D6E}\u{10E60}-\u{10E7E}\u{10ED0}-\u{10ED8}\u{1CCF0}-\u{1CCF9}\u{1D7CE}-\u{1D7FF}\u{1EEF0}\u{1EEF1}\u{1FBF0}-\u{1FBF9}]/u;
64
+
65
+ /**
66
+ * Bidi_Class `L`: every other letter, the letter numbers (`\p{Letter}` does
67
+ * not include them), the left-to-right mark, and the decimal digits.
68
+ *
69
+ * Most scripts' digits are `L` — Devanagari, Bengali, Tamil, Thai and the
70
+ * rest — so a line opening with them reads left-to-right. The digits that
71
+ * are not are read before this: the European ones are `EN` and the
72
+ * Arabic-Indic ones `AN`, both in the weak set above, and NKo's and Adlam's
73
+ * are `R`, matched as their own scripts. Punctuation and symbols are not
74
+ * here, so the scan passes over them.
75
+ */
76
+ const STRONG_LTR = new RegExp(String.raw`[\p{Letter}\p{Nl}\p{Nd}\u200E]`, 'u');
77
+
78
+ /**
79
+ * Bidi_Class `NSM`: a combining mark takes the direction of its base
80
+ * character. A mark has its base letter's script, so without this check a
81
+ * leading Hebrew point would read as right-to-left.
82
+ */
83
+ const COMBINING_MARK = new RegExp(String.raw`\p{Mark}`, 'u');
84
+
85
+ /**
86
+ * Approximates rules P2 and P3 of the Unicode Bidirectional Algorithm from
87
+ * script and category: the direction of the first strongly directional
88
+ * character, or null when there is none. It does not skip isolated runs. The
89
+ * loop reads whole code points, so a surrogate pair counts as one character.
90
+ */
91
+ export function firstStrongDirection(text) {
92
+ for (const character of text) {
93
+ if (COMBINING_MARK.test(character) || WEAK_NUMBER_OR_NEUTRAL.test(character)) {
94
+ continue;
95
+ }
96
+ if (STRONG_RTL.test(character)) {
97
+ return 'rtl';
98
+ }
99
+ if (STRONG_LTR.test(character)) {
100
+ return 'ltr';
101
+ }
102
+ }
103
+ return null;
104
+ }