@astryxdesign/richtext 0.7.7-canary.f9ac85f → 0.7.7

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 CHANGED
@@ -1,5 +1,25 @@
1
1
  # @astryxdesign/richtext
2
2
 
3
+ # 0.7.7
4
+
5
+ #### Fixes
6
+
7
+ - RichTextEditorToolbar: Insert link with nothing selected did not insert a link at the caret. In an empty paragraph nothing was inserted, and with the caret inside text the whole text around it was linked, while the dialog closed as if it had worked. Now, with the caret outside a link, Insert link inserts the entered URL as link text at the caret; with a non-empty selection it links the selected text, and with the caret inside a link it updates that link, as before.
8
+
9
+ #### Performance
10
+
11
+ - Typing in a `RichTextEditor` code block no longer re-tokenizes the whole block. In TypeScript, JavaScript, Python, and shell code, an edit inside one line re-tokenizes that line, plus at most the line above it, and replaces only the color ranges inside the text node it edited, so a keystroke in a 2,000-line block tokenizes as little code as one in a short block. Edits that open or close a string or comment across lines, and other languages, still re-tokenize the whole block. Colors are unchanged, except that a block whose text nodes are replaced by others with the same text is now recolored instead of left uncolored.
12
+
13
+ #### Contributors
14
+
15
+ Thanks to everyone who contributed to this release:
16
+
17
+ - @cixzhang
18
+ - @emilyhorsman
19
+ - @ernestt
20
+
21
+ ---
22
+
3
23
  # 0.7.6
4
24
 
5
25
  #### Fixes
@@ -85,7 +85,9 @@ export interface RichTextEditorToolbarProps extends BaseProps<HTMLDivElement> {
85
85
  /**
86
86
  * Whether to show the insert/edit-link button. By default, pressing it opens
87
87
  * an Astryx Dialog. The form can add, update, or remove a link without
88
- * losing the editor selection.
88
+ * losing the editor selection. With a collapsed selection, Insert link
89
+ * inserts the entered URL as link text at the caret; with a non-empty
90
+ * selection it links the selected text.
89
91
  *
90
92
  * Requires `LinkNode` to be registered (it is, by default) — no extra setup.
91
93
  * The entered URL is sanitized (see `sanitizeUrl`) so only
@@ -1 +1 @@
1
- {"version":3,"file":"RichTextEditorToolbar.d.ts","sourceRoot":"","sources":["../src/RichTextEditorToolbar.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,EAML,KAAK,SAAS,EACd,KAAK,GAAG,EACT,MAAM,OAAO,CAAC;AAmBf,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAC;AA8HlD;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;CAgBrB,CAAC;AAmPX,MAAM,WAAW,0BAA2B,SAAQ,SAAS,CAAC,cAAc,CAAC;IAC3E;;;;;;OAMG;IACH,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;IAC1B;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC;IAClD;;;;OAIG;IACH,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;IAC1B;;;;;;;;;OASG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACnE;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;OAIG;IACH,UAAU,CAAC,EAAE,SAAS,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,KAAK,EAAE,cAAc,EACrB,aAAkC,EAClC,IAAW,EACX,OAAc,EACd,YAAY,EACZ,cAAqB,EACrB,UAAU,EACV,MAAM,EACN,GAAG,EACH,GAAG,IAAI,EACR,EAAE,0BAA0B,+BA0gB5B;yBArhBe,qBAAqB"}
1
+ {"version":3,"file":"RichTextEditorToolbar.d.ts","sourceRoot":"","sources":["../src/RichTextEditorToolbar.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,EAML,KAAK,SAAS,EACd,KAAK,GAAG,EACT,MAAM,OAAO,CAAC;AAmBf,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAC;AA8HlD;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;CAgBrB,CAAC;AAmPX,MAAM,WAAW,0BAA2B,SAAQ,SAAS,CAAC,cAAc,CAAC;IAC3E;;;;;;OAMG;IACH,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;IAC1B;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC;IAClD;;;;OAIG;IACH,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;IAC1B;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACnE;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;OAIG;IACH,UAAU,CAAC,EAAE,SAAS,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,KAAK,EAAE,cAAc,EACrB,aAAkC,EAClC,IAAW,EACX,OAAc,EACd,YAAY,EACZ,cAAqB,EACrB,UAAU,EACV,MAAM,EACN,GAAG,EACH,GAAG,IAAI,EACR,EAAE,0BAA0B,+BAmhB5B;yBA9hBe,qBAAqB"}
@@ -541,27 +541,39 @@ export function RichTextEditorToolbar({
541
541
  if (url === 'about:blank') {
542
542
  return false;
543
543
  }
544
- restoreLinkSelection();
545
544
  const linkAttributes = hasNewTabLinks ? {
546
545
  target: '_blank',
547
546
  rel: 'noopener noreferrer'
548
547
  } : {};
549
- const handled = editor.dispatchCommand(TOGGLE_LINK_COMMAND, {
550
- url,
551
- ...linkAttributes
552
- });
553
- if (!handled) {
554
- editor.update(() => {
555
- const selection = $getSelection();
556
- if ($isRangeSelection(selection) && selection.isCollapsed()) {
548
+ const savedSelection = savedSelectionRef.current;
549
+ // One update restores the selection, decides, and applies. Inside a
550
+ // command listener (Cmd/Ctrl+K) Lexical queues an update, so a flag set
551
+ // in one update cannot steer code that runs after it.
552
+ editor.update(() => {
553
+ if (savedSelection) {
554
+ $setSelection(savedSelection.clone());
555
+ }
556
+ const selection = $getSelection();
557
+ if ($isRangeSelection(selection) && selection.isCollapsed()) {
558
+ const node = selection.anchor.getNode();
559
+ const isInLink = $isLinkNode(node) || $isLinkNode(node.getParent());
560
+ // At a caret outside a link there is no text to link, so the URL
561
+ // becomes the link's text. The toggle command would link the whole
562
+ // text node around the caret instead.
563
+ if (!isInLink) {
557
564
  const linkNode = $createLinkNode(url, linkAttributes);
558
565
  linkNode.append($createTextNode(trimmed));
559
566
  selection.insertNodes([linkNode]);
567
+ return;
560
568
  }
569
+ }
570
+ editor.dispatchCommand(TOGGLE_LINK_COMMAND, {
571
+ url,
572
+ ...linkAttributes
561
573
  });
562
- }
574
+ });
563
575
  return true;
564
- }, [editor, hasNewTabLinks, restoreLinkSelection]);
576
+ }, [editor, hasNewTabLinks]);
565
577
  const toggleLink = useCallback(() => {
566
578
  if (!editor.isEditable()) {
567
579
  return;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@astryxdesign/richtext",
3
3
  "displayName": "Rich Text",
4
- "version": "0.7.7-canary.f9ac85f",
4
+ "version": "0.7.7",
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",
@@ -66,7 +66,7 @@
66
66
  },
67
67
  "peerDependencies": {
68
68
  "@stylexjs/stylex": ">=0.10.0",
69
- "@astryxdesign/core": "0.7.7-canary.f9ac85f",
69
+ "@astryxdesign/core": "0.7.7",
70
70
  "react": ">=19.0.0",
71
71
  "react-dom": ">=19.0.0",
72
72
  "lexical": "^0.52.0",
@@ -125,8 +125,6 @@
125
125
  }
126
126
  },
127
127
  "devDependencies": {
128
- "@astryxdesign/a11y-spec": "0.7.7-canary.f9ac85f",
129
- "@astryxdesign/cli": "0.7.7-canary.f9ac85f",
130
128
  "@babel/cli": "^7.29.7",
131
129
  "@babel/core": "^7.29.7",
132
130
  "@babel/preset-react": "^7.29.7",
@@ -145,7 +143,9 @@
145
143
  "@lexical/utils": "^0.52.0",
146
144
  "@stylexjs/babel-plugin": "^0.19.0",
147
145
  "@testing-library/react": "^16.3.2",
148
- "lexical": "^0.52.0"
146
+ "lexical": "^0.52.0",
147
+ "@astryxdesign/a11y-spec": "0.0.0",
148
+ "@astryxdesign/cli": "0.7.7"
149
149
  },
150
150
  "scripts": {
151
151
  "api:report": "node ../../scripts/api-report/cli.mjs --package .",
@@ -483,7 +483,9 @@ export interface RichTextEditorToolbarProps extends BaseProps<HTMLDivElement> {
483
483
  /**
484
484
  * Whether to show the insert/edit-link button. By default, pressing it opens
485
485
  * an Astryx Dialog. The form can add, update, or remove a link without
486
- * losing the editor selection.
486
+ * losing the editor selection. With a collapsed selection, Insert link
487
+ * inserts the entered URL as link text at the caret; with a non-empty
488
+ * selection it links the selected text.
487
489
  *
488
490
  * Requires `LinkNode` to be registered (it is, by default) — no extra setup.
489
491
  * The entered URL is sanitized (see `sanitizeUrl`) so only
@@ -694,27 +696,36 @@ export function RichTextEditorToolbar({
694
696
  return false;
695
697
  }
696
698
 
697
- restoreLinkSelection();
698
699
  const linkAttributes = hasNewTabLinks
699
700
  ? {target: '_blank', rel: 'noopener noreferrer'}
700
701
  : {};
701
- const handled = editor.dispatchCommand(TOGGLE_LINK_COMMAND, {
702
- url,
703
- ...linkAttributes,
704
- });
705
- if (!handled) {
706
- editor.update(() => {
707
- const selection = $getSelection();
708
- if ($isRangeSelection(selection) && selection.isCollapsed()) {
702
+ const savedSelection = savedSelectionRef.current;
703
+ // One update restores the selection, decides, and applies. Inside a
704
+ // command listener (Cmd/Ctrl+K) Lexical queues an update, so a flag set
705
+ // in one update cannot steer code that runs after it.
706
+ editor.update(() => {
707
+ if (savedSelection) {
708
+ $setSelection(savedSelection.clone());
709
+ }
710
+ const selection = $getSelection();
711
+ if ($isRangeSelection(selection) && selection.isCollapsed()) {
712
+ const node = selection.anchor.getNode();
713
+ const isInLink = $isLinkNode(node) || $isLinkNode(node.getParent());
714
+ // At a caret outside a link there is no text to link, so the URL
715
+ // becomes the link's text. The toggle command would link the whole
716
+ // text node around the caret instead.
717
+ if (!isInLink) {
709
718
  const linkNode = $createLinkNode(url, linkAttributes);
710
719
  linkNode.append($createTextNode(trimmed));
711
720
  selection.insertNodes([linkNode]);
721
+ return;
712
722
  }
713
- });
714
- }
723
+ }
724
+ editor.dispatchCommand(TOGGLE_LINK_COMMAND, {url, ...linkAttributes});
725
+ });
715
726
  return true;
716
727
  },
717
- [editor, hasNewTabLinks, restoreLinkSelection],
728
+ [editor, hasNewTabLinks],
718
729
  );
719
730
 
720
731
  const toggleLink = useCallback(() => {