@astryxdesign/richtext 0.7.7 → 0.7.8-canary.07ee4b5
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/dist/RichTextEditor.d.ts.map +1 -1
- package/dist/RichTextEditor.js +2 -1
- package/dist/SelectAllScopePlugin.d.ts +2 -0
- package/dist/SelectAllScopePlugin.d.ts.map +1 -0
- package/dist/SelectAllScopePlugin.js +67 -0
- package/package.json +5 -5
- package/src/RichTextEditor.doc.mjs +5 -0
- package/src/RichTextEditor.tsx +2 -0
- package/src/SelectAllScopePlugin.tsx +86 -0
|
@@ -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;AAqBlC,OAAO,KAAK,EAAC,yBAAyB,EAAC,MAAM,sBAAsB,CAAC;AACpE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,8BAA8B,CAAC;
|
|
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,MA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AY,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;;CAsPrB,CAAC"}
|
package/dist/RichTextEditor.js
CHANGED
|
@@ -53,6 +53,7 @@ import { CodeBlockHeaderPlugin } from "./CodeBlockHeaderPlugin.js";
|
|
|
53
53
|
import { CodeSyntaxPlugin } from "./CodeSyntaxPlugin.js";
|
|
54
54
|
import { MarkdownExtensionsPlugin } from "./MarkdownExtensionsPlugin.js";
|
|
55
55
|
import { TaskCheckboxPlugin } from "./TaskCheckboxPlugin.js";
|
|
56
|
+
import { SelectAllScopePlugin } from "./SelectAllScopePlugin.js";
|
|
56
57
|
import { $generateHtmlFromNodes } from '@lexical/html';
|
|
57
58
|
import { DEFAULT_NODES } from "./editorNodes.js";
|
|
58
59
|
import { $exportMarkdownKeepingSource } from "./markdownSource.js";
|
|
@@ -361,7 +362,7 @@ export const RichTextEditor = function RichTextEditor({
|
|
|
361
362
|
}), markdownExtensions != null && markdownExtensions.length > 0 ? /*#__PURE__*/_jsx(MarkdownExtensionsPlugin, {
|
|
362
363
|
extensions: markdownExtensions,
|
|
363
364
|
transformers: markdownTransformers
|
|
364
|
-
}) : null, /*#__PURE__*/_jsx(TabIndentationPlugin, {}), /*#__PURE__*/_jsx(TabFocusEscapePlugin, {}), hasMarkdownShortcuts && /*#__PURE__*/_jsx(MarkdownShortcutPlugin, {
|
|
365
|
+
}) : null, /*#__PURE__*/_jsx(TabIndentationPlugin, {}), /*#__PURE__*/_jsx(TabFocusEscapePlugin, {}), /*#__PURE__*/_jsx(SelectAllScopePlugin, {}), hasMarkdownShortcuts && /*#__PURE__*/_jsx(MarkdownShortcutPlugin, {
|
|
365
366
|
transformers: markdownTransformers
|
|
366
367
|
}), hasAutoFocus && /*#__PURE__*/_jsx(AutoFocusOnMount, {}), onChange && /*#__PURE__*/_jsx(OnChangePlugin, {
|
|
367
368
|
onChange: onChange,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectAllScopePlugin.d.ts","sourceRoot":"","sources":["../src/SelectAllScopePlugin.tsx"],"names":[],"mappings":"AAiFA,wBAAgB,oBAAoB,IAAI,IAAI,CAI3C"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @file SelectAllScopePlugin.tsx
|
|
7
|
+
* @input Uses @lexical/react (composer context), @lexical/code (CodeNode),
|
|
8
|
+
* @lexical/table (TableCellNode), and lexical (the select-all command and
|
|
9
|
+
* selection).
|
|
10
|
+
* @output Exports SelectAllScopePlugin, which makes Cmd+A (Ctrl+A off Apple
|
|
11
|
+
* platforms) select the content of the code block or table cell holding the
|
|
12
|
+
* caret first, and the whole document on the next press.
|
|
13
|
+
* @position Rendered by RichTextEditor, always on; a read-only or disabled
|
|
14
|
+
* editor keeps the browser's and Lexical's select all. Elsewhere, and when
|
|
15
|
+
* the selection already covers its code block or cell or runs outside it,
|
|
16
|
+
* the press falls through to Lexical's own select all, which takes the
|
|
17
|
+
* whole document.
|
|
18
|
+
*/
|
|
19
|
+
import { useEffect } from 'react';
|
|
20
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
21
|
+
import { $isCodeNode } from '@lexical/code';
|
|
22
|
+
import { $isTableCellNode } from '@lexical/table';
|
|
23
|
+
import { $getSelection, $isBlockFullySelected, $isRangeSelection, COMMAND_PRIORITY_NORMAL, SELECT_ALL_COMMAND } from 'lexical';
|
|
24
|
+
|
|
25
|
+
/** Whether select all stops at `node` before taking the whole document. */
|
|
26
|
+
function $isScope(node) {
|
|
27
|
+
return $isCodeNode(node) || $isTableCellNode(node);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The scopes holding `node`, innermost first. */
|
|
31
|
+
function $scopesOf(node) {
|
|
32
|
+
const scopes = [];
|
|
33
|
+
for (let at = node; at !== null; at = at.getParent()) {
|
|
34
|
+
if ($isScope(at)) {
|
|
35
|
+
scopes.push(at);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return scopes;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Selects the content of the innermost scope that holds the whole selection
|
|
43
|
+
* and is not yet fully selected; false, to let the document be selected,
|
|
44
|
+
* when there is none.
|
|
45
|
+
*/
|
|
46
|
+
function $selectScope() {
|
|
47
|
+
const selection = $getSelection();
|
|
48
|
+
if (!$isRangeSelection(selection)) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
const focusScopes = $scopesOf(selection.focus.getNode());
|
|
52
|
+
for (const scope of $scopesOf(selection.anchor.getNode())) {
|
|
53
|
+
if (focusScopes.some(each => each.is(scope)) && !$isBlockFullySelected(scope, selection)) {
|
|
54
|
+
scope.select(0, scope.getChildrenSize());
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
function registerSelectAllScope(editor) {
|
|
61
|
+
return editor.registerCommand(SELECT_ALL_COMMAND, () => editor.isEditable() && $selectScope(), COMMAND_PRIORITY_NORMAL);
|
|
62
|
+
}
|
|
63
|
+
export function SelectAllScopePlugin() {
|
|
64
|
+
const [editor] = useLexicalComposerContext();
|
|
65
|
+
useEffect(() => registerSelectAllScope(editor), [editor]);
|
|
66
|
+
return null;
|
|
67
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/richtext",
|
|
3
3
|
"displayName": "Rich Text",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.8-canary.07ee4b5",
|
|
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.
|
|
69
|
+
"@astryxdesign/core": "0.7.8-canary.07ee4b5",
|
|
70
70
|
"react": ">=19.0.0",
|
|
71
71
|
"react-dom": ">=19.0.0",
|
|
72
72
|
"lexical": "^0.52.0",
|
|
@@ -125,6 +125,8 @@
|
|
|
125
125
|
}
|
|
126
126
|
},
|
|
127
127
|
"devDependencies": {
|
|
128
|
+
"@astryxdesign/a11y-spec": "0.7.8-canary.07ee4b5",
|
|
129
|
+
"@astryxdesign/cli": "0.7.8-canary.07ee4b5",
|
|
128
130
|
"@babel/cli": "^7.29.7",
|
|
129
131
|
"@babel/core": "^7.29.7",
|
|
130
132
|
"@babel/preset-react": "^7.29.7",
|
|
@@ -143,9 +145,7 @@
|
|
|
143
145
|
"@lexical/utils": "^0.52.0",
|
|
144
146
|
"@stylexjs/babel-plugin": "^0.19.0",
|
|
145
147
|
"@testing-library/react": "^16.3.2",
|
|
146
|
-
"lexical": "^0.52.0"
|
|
147
|
-
"@astryxdesign/a11y-spec": "0.0.0",
|
|
148
|
-
"@astryxdesign/cli": "0.7.7"
|
|
148
|
+
"lexical": "^0.52.0"
|
|
149
149
|
},
|
|
150
150
|
"scripts": {
|
|
151
151
|
"api:report": "node ../../scripts/api-report/cli.mjs --package .",
|
|
@@ -238,6 +238,11 @@ export const docs = {
|
|
|
238
238
|
description:
|
|
239
239
|
'GFM pipe tables import, edit, and export by default. The first row renders as header cells, delimiter-row colons set each column alignment, rows shorter than the widest row gain empty cells, and a wide table scrolls inside its own wrapper. Arrow keys move between cells; Tab keeps its editor meaning, so Escape then Tab still leaves the editor. Tables export in the canonical form: outer pipes and three-dash delimiters. RichTextView renders the same tables. Install @lexical/table with the other lexical peers.',
|
|
240
240
|
},
|
|
241
|
+
{
|
|
242
|
+
guidance: true,
|
|
243
|
+
description:
|
|
244
|
+
'Cmd+A (Ctrl+A on other platforms) in a code block or a table cell selects the code or the cell text first; pressing it again selects the whole document. Anywhere else it selects the whole document at once.',
|
|
245
|
+
},
|
|
241
246
|
{
|
|
242
247
|
guidance: true,
|
|
243
248
|
description:
|
package/src/RichTextEditor.tsx
CHANGED
|
@@ -83,6 +83,7 @@ import {MarkdownExtensionsPlugin} from './MarkdownExtensionsPlugin';
|
|
|
83
83
|
import type {RichTextMarkdownExtension} from './markdownExtensions';
|
|
84
84
|
import type {CodeLanguage} from '@astryxdesign/core/CodeBlock';
|
|
85
85
|
import {TaskCheckboxPlugin} from './TaskCheckboxPlugin';
|
|
86
|
+
import {SelectAllScopePlugin} from './SelectAllScopePlugin';
|
|
86
87
|
import {type Transformer} from '@lexical/markdown';
|
|
87
88
|
import {$generateHtmlFromNodes} from '@lexical/html';
|
|
88
89
|
import {DEFAULT_NODES} from './editorNodes';
|
|
@@ -730,6 +731,7 @@ export const RichTextEditor = function RichTextEditor({
|
|
|
730
731
|
) : null}
|
|
731
732
|
<TabIndentationPlugin />
|
|
732
733
|
<TabFocusEscapePlugin />
|
|
734
|
+
<SelectAllScopePlugin />
|
|
733
735
|
{hasMarkdownShortcuts && (
|
|
734
736
|
<MarkdownShortcutPlugin transformers={markdownTransformers} />
|
|
735
737
|
)}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @file SelectAllScopePlugin.tsx
|
|
7
|
+
* @input Uses @lexical/react (composer context), @lexical/code (CodeNode),
|
|
8
|
+
* @lexical/table (TableCellNode), and lexical (the select-all command and
|
|
9
|
+
* selection).
|
|
10
|
+
* @output Exports SelectAllScopePlugin, which makes Cmd+A (Ctrl+A off Apple
|
|
11
|
+
* platforms) select the content of the code block or table cell holding the
|
|
12
|
+
* caret first, and the whole document on the next press.
|
|
13
|
+
* @position Rendered by RichTextEditor, always on; a read-only or disabled
|
|
14
|
+
* editor keeps the browser's and Lexical's select all. Elsewhere, and when
|
|
15
|
+
* the selection already covers its code block or cell or runs outside it,
|
|
16
|
+
* the press falls through to Lexical's own select all, which takes the
|
|
17
|
+
* whole document.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import {useEffect} from 'react';
|
|
21
|
+
import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
|
|
22
|
+
import {$isCodeNode} from '@lexical/code';
|
|
23
|
+
import {$isTableCellNode} from '@lexical/table';
|
|
24
|
+
import {
|
|
25
|
+
$getSelection,
|
|
26
|
+
$isBlockFullySelected,
|
|
27
|
+
$isRangeSelection,
|
|
28
|
+
COMMAND_PRIORITY_NORMAL,
|
|
29
|
+
SELECT_ALL_COMMAND,
|
|
30
|
+
type ElementNode,
|
|
31
|
+
type LexicalEditor,
|
|
32
|
+
type LexicalNode,
|
|
33
|
+
} from 'lexical';
|
|
34
|
+
|
|
35
|
+
/** Whether select all stops at `node` before taking the whole document. */
|
|
36
|
+
function $isScope(node: LexicalNode): node is ElementNode {
|
|
37
|
+
return $isCodeNode(node) || $isTableCellNode(node);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The scopes holding `node`, innermost first. */
|
|
41
|
+
function $scopesOf(node: LexicalNode): Array<ElementNode> {
|
|
42
|
+
const scopes: Array<ElementNode> = [];
|
|
43
|
+
for (let at: LexicalNode | null = node; at !== null; at = at.getParent()) {
|
|
44
|
+
if ($isScope(at)) {
|
|
45
|
+
scopes.push(at);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return scopes;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Selects the content of the innermost scope that holds the whole selection
|
|
53
|
+
* and is not yet fully selected; false, to let the document be selected,
|
|
54
|
+
* when there is none.
|
|
55
|
+
*/
|
|
56
|
+
function $selectScope(): boolean {
|
|
57
|
+
const selection = $getSelection();
|
|
58
|
+
if (!$isRangeSelection(selection)) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
const focusScopes = $scopesOf(selection.focus.getNode());
|
|
62
|
+
for (const scope of $scopesOf(selection.anchor.getNode())) {
|
|
63
|
+
if (
|
|
64
|
+
focusScopes.some(each => each.is(scope)) &&
|
|
65
|
+
!$isBlockFullySelected(scope, selection)
|
|
66
|
+
) {
|
|
67
|
+
scope.select(0, scope.getChildrenSize());
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function registerSelectAllScope(editor: LexicalEditor): () => void {
|
|
75
|
+
return editor.registerCommand(
|
|
76
|
+
SELECT_ALL_COMMAND,
|
|
77
|
+
() => editor.isEditable() && $selectScope(),
|
|
78
|
+
COMMAND_PRIORITY_NORMAL,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function SelectAllScopePlugin(): null {
|
|
83
|
+
const [editor] = useLexicalComposerContext();
|
|
84
|
+
useEffect(() => registerSelectAllScope(editor), [editor]);
|
|
85
|
+
return null;
|
|
86
|
+
}
|