@astryxdesign/richtext 0.7.15 → 0.7.16-canary.g22213fd
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/CodePastePlugin.d.ts +3 -0
- package/dist/CodePastePlugin.d.ts.map +1 -1
- package/dist/CodePastePlugin.js +3 -2
- package/dist/RichTextEditor.d.ts.map +1 -1
- package/dist/RichTextEditor.js +2 -1
- package/dist/RichTextEditorToolbar.d.ts +13 -9
- package/dist/RichTextEditorToolbar.d.ts.map +1 -1
- package/dist/RichTextEditorToolbar.js +235 -89
- package/dist/TablePastePlugin.d.ts +9 -0
- package/dist/TablePastePlugin.d.ts.map +1 -0
- package/dist/TablePastePlugin.js +183 -0
- package/dist/linkUtils.d.ts.map +1 -1
- package/dist/linkUtils.js +7 -1
- package/package.json +5 -5
- package/src/CodePastePlugin.tsx +3 -2
- package/src/RichTextEditor.doc.mjs +2 -2
- package/src/RichTextEditor.tsx +2 -0
- package/src/RichTextEditorToolbar.doc.mjs +2 -2
- package/src/RichTextEditorToolbar.tsx +276 -125
- package/src/TablePastePlugin.tsx +223 -0
- package/src/linkUtils.ts +10 -1
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
import { type BaseSelection, type RangeSelection } from 'lexical';
|
|
2
|
+
/** Whether content inserted at the selection lands in a code block. */
|
|
3
|
+
export declare function $startsInCodeBlock(selection: BaseSelection | null): selection is RangeSelection;
|
|
1
4
|
export declare function CodePastePlugin(): null;
|
|
2
5
|
//# sourceMappingURL=CodePastePlugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodePastePlugin.d.ts","sourceRoot":"","sources":["../src/CodePastePlugin.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CodePastePlugin.d.ts","sourceRoot":"","sources":["../src/CodePastePlugin.tsx"],"names":[],"mappings":"AAmBA,OAAO,EAaL,KAAK,aAAa,EAElB,KAAK,cAAc,EACpB,MAAM,SAAS,CAAC;AAKjB,uEAAuE;AACvE,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,aAAa,GAAG,IAAI,GAC9B,SAAS,IAAI,cAAc,CAQ7B;AAqCD,wBAAgB,eAAe,IAAI,IAAI,CAuDtC"}
|
package/dist/CodePastePlugin.js
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* @input Uses @lexical/react (composer context), @lexical/code (CodeNode), and
|
|
8
8
|
* lexical.
|
|
9
9
|
* @output Exports CodePastePlugin, which makes rich content pasted or dropped
|
|
10
|
-
* into a code block go in as plain lines of code
|
|
10
|
+
* into a code block go in as plain lines of code, and $startsInCodeBlock,
|
|
11
|
+
* which TablePastePlugin uses to leave such a paste to it.
|
|
11
12
|
* @position Rendered by RichTextEditor; always on; not exported. A paste
|
|
12
13
|
* whose selection starts in a code block goes in as plain text: the
|
|
13
14
|
* clipboard's plain text, or else one line per pasted block.
|
|
@@ -21,7 +22,7 @@ import { $addUpdateTag, $findMatchingParent, $getSelection, $isElementNode, $isR
|
|
|
21
22
|
const RICH_TYPES = ['text/html', 'application/x-lexical-editor'];
|
|
22
23
|
|
|
23
24
|
/** Whether content inserted at the selection lands in a code block. */
|
|
24
|
-
function $startsInCodeBlock(selection) {
|
|
25
|
+
export function $startsInCodeBlock(selection) {
|
|
25
26
|
if (!$isRangeSelection(selection)) {
|
|
26
27
|
return false;
|
|
27
28
|
}
|
|
@@ -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,E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CAAC;IACpB;;;;OAIG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB;;;;;OAKG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B;;;;;;;;;;;;;;;;;OAiBG;IACH,YAAY,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;;CAiQrB,CAAC"}
|
package/dist/RichTextEditor.js
CHANGED
|
@@ -49,6 +49,7 @@ import { TablePlugin } from '@lexical/react/LexicalTablePlugin';
|
|
|
49
49
|
import { HorizontalRuleExtension } from '@lexical/extension';
|
|
50
50
|
import { TextSemanticsExtension } from "./textSemantics.js";
|
|
51
51
|
import { TableColumnFloorPlugin } from "./TableColumnFloorPlugin.js";
|
|
52
|
+
import { TablePastePlugin } from "./TablePastePlugin.js";
|
|
52
53
|
import { CodeBackspacePlugin } from "./CodeBackspacePlugin.js";
|
|
53
54
|
import { CodeBlockHeaderPlugin } from "./CodeBlockHeaderPlugin.js";
|
|
54
55
|
import { CodePastePlugin } from "./CodePastePlugin.js";
|
|
@@ -364,7 +365,7 @@ export const RichTextEditor = function RichTextEditor({
|
|
|
364
365
|
hasCellBackgroundColor: false,
|
|
365
366
|
hasTabHandler: false,
|
|
366
367
|
hasHorizontalScroll: true
|
|
367
|
-
}), /*#__PURE__*/_jsx(TableColumnFloorPlugin, {}), /*#__PURE__*/_jsx(CodeBlockHeaderPlugin, {
|
|
368
|
+
}), /*#__PURE__*/_jsx(TableColumnFloorPlugin, {}), /*#__PURE__*/_jsx(TablePastePlugin, {}), /*#__PURE__*/_jsx(CodeBlockHeaderPlugin, {
|
|
368
369
|
codeLanguages: codeLanguages
|
|
369
370
|
}), /*#__PURE__*/_jsx(CodeSyntaxPlugin, {
|
|
370
371
|
codeLanguages: codeLanguages
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
* @input Uses React, @lexical/react (composer context), @lexical/rich-text,
|
|
4
4
|
* @lexical/selection, @lexical/list, @lexical/utils, and the lexical core
|
|
5
5
|
* command constants, plus Astryx Toolbar / IconButton / Selector /
|
|
6
|
-
* ToggleButton / Divider /
|
|
6
|
+
* ToggleButton / Divider / Popover / TextInput / Layout primitives.
|
|
7
7
|
* @output Exports RichTextEditorToolbar (a compact formatting toolbar with a
|
|
8
|
-
* RichText-owned 4px control gutter
|
|
9
|
-
* and
|
|
8
|
+
* RichText-owned 4px control gutter, a horizontally scrollable action row,
|
|
9
|
+
* and a link popover anchored to its Link button) and
|
|
10
|
+
* RichTextEditorToolbarProps.
|
|
10
11
|
* @position @astryxdesign/richtext. Drop into RichTextEditor's `toolbar` slot to
|
|
11
12
|
* add a flush top formatting toolbar. Themed via Astryx Toolbar, Selector,
|
|
12
13
|
* IconButton, and ToggleButton, so it inherits the active theme. Base props
|
|
@@ -83,11 +84,14 @@ export interface RichTextEditorToolbarProps extends BaseProps<HTMLDivElement> {
|
|
|
83
84
|
*/
|
|
84
85
|
size?: 'sm' | 'md' | 'lg';
|
|
85
86
|
/**
|
|
86
|
-
* Whether to show the insert/edit-link button. By default, pressing it
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* selection
|
|
87
|
+
* Whether to show the insert/edit-link button. By default, pressing it (or
|
|
88
|
+
* Cmd/Ctrl+K in the editor) opens an Astryx Popover anchored to the button:
|
|
89
|
+
* one URL field, applied with Enter, with Remove when the selection is in a
|
|
90
|
+
* link. The popover is not modal. Escape or Cancel closes it and returns
|
|
91
|
+
* focus and the selection to the editor; a URL that cannot be linked shows
|
|
92
|
+
* an error under the field, which keeps focus. With a collapsed selection,
|
|
93
|
+
* applying inserts the entered URL as link text at the caret; with a
|
|
94
|
+
* non-empty selection it links the selected text.
|
|
91
95
|
*
|
|
92
96
|
* Requires `LinkNode` to be registered (it is, by default) — no extra setup.
|
|
93
97
|
* The entered URL is sanitized (see `sanitizeUrl`) so only
|
|
@@ -99,7 +103,7 @@ export interface RichTextEditorToolbarProps extends BaseProps<HTMLDivElement> {
|
|
|
99
103
|
* Called to obtain a URL when the link button is pressed on a non-link
|
|
100
104
|
* selection. Return the URL string to link, or `null`/`''` to cancel.
|
|
101
105
|
* Receives the currently selected text as a hint. When omitted, the built-in
|
|
102
|
-
*
|
|
106
|
+
* link popover is used. This synchronous override is retained
|
|
103
107
|
* for consumers that already provide their own URL UI.
|
|
104
108
|
*/
|
|
105
109
|
promptForUrl?: (selectedText: string) => string | null | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextEditorToolbar.d.ts","sourceRoot":"","sources":["../src/RichTextEditorToolbar.tsx"],"names":[],"mappings":"AAIA
|
|
1
|
+
{"version":3,"file":"RichTextEditorToolbar.d.ts","sourceRoot":"","sources":["../src/RichTextEditorToolbar.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAKL,KAAK,SAAS,EACd,KAAK,GAAG,EAET,MAAM,OAAO,CAAC;AAmBf,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAgIlD;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;CAgBrB,CAAC;AA8XX,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;;;;;;;;;;;;;;OAcG;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,+BAyhB5B;yBApiBe,qBAAqB"}
|
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
* @input Uses React, @lexical/react (composer context), @lexical/rich-text,
|
|
8
8
|
* @lexical/selection, @lexical/list, @lexical/utils, and the lexical core
|
|
9
9
|
* command constants, plus Astryx Toolbar / IconButton / Selector /
|
|
10
|
-
* ToggleButton / Divider /
|
|
10
|
+
* ToggleButton / Divider / Popover / TextInput / Layout primitives.
|
|
11
11
|
* @output Exports RichTextEditorToolbar (a compact formatting toolbar with a
|
|
12
|
-
* RichText-owned 4px control gutter
|
|
13
|
-
* and
|
|
12
|
+
* RichText-owned 4px control gutter, a horizontally scrollable action row,
|
|
13
|
+
* and a link popover anchored to its Link button) and
|
|
14
|
+
* RichTextEditorToolbarProps.
|
|
14
15
|
* @position @astryxdesign/richtext. Drop into RichTextEditor's `toolbar` slot to
|
|
15
16
|
* add a flush top formatting toolbar. Themed via Astryx Toolbar, Selector,
|
|
16
17
|
* IconButton, and ToggleButton, so it inherits the active theme. Base props
|
|
@@ -49,14 +50,12 @@ import { IconButton } from '@astryxdesign/core/IconButton';
|
|
|
49
50
|
import { Selector } from '@astryxdesign/core/Selector';
|
|
50
51
|
import { ToggleButton } from '@astryxdesign/core/ToggleButton';
|
|
51
52
|
import { Divider } from '@astryxdesign/core/Divider';
|
|
52
|
-
import {
|
|
53
|
+
import { Popover } from '@astryxdesign/core/Popover';
|
|
53
54
|
import { TextInput } from '@astryxdesign/core/TextInput';
|
|
54
|
-
import {
|
|
55
|
-
import {
|
|
56
|
-
import { HStack, Layout, LayoutContent, LayoutFooter } from '@astryxdesign/core/Layout';
|
|
57
|
-
import { getExtendedIcon } from '@astryxdesign/core/Icon';
|
|
55
|
+
import { HStack, StackItem } from '@astryxdesign/core/Layout';
|
|
56
|
+
import { Icon, getExtendedIcon } from '@astryxdesign/core/Icon';
|
|
58
57
|
import { useThemeName } from '@astryxdesign/core/theme';
|
|
59
|
-
import { isRenderable, rtlStyles } from '@astryxdesign/core/utils';
|
|
58
|
+
import { isImeKeyEvent, isRenderable, rtlStyles } from '@astryxdesign/core/utils';
|
|
60
59
|
import '@astryxdesign/core/theme/tokens.stylex';
|
|
61
60
|
import { fontWeightVars, spacingVars, typeScaleVars } from '@astryxdesign/core/theme/tokens.stylex';
|
|
62
61
|
import { useTranslator } from '@astryxdesign/core/i18n';
|
|
@@ -75,6 +74,10 @@ const CONTROL_OR_META = {
|
|
|
75
74
|
ctrlKey: !IS_APPLE,
|
|
76
75
|
metaKey: IS_APPLE
|
|
77
76
|
};
|
|
77
|
+
|
|
78
|
+
// The link popover's anchor: a box around the Link button that takes no
|
|
79
|
+
// space of its own.
|
|
80
|
+
|
|
78
81
|
// A vertical Divider's default 100% height needs a definite parent height.
|
|
79
82
|
// Toolbar slots are sized by their controls instead, so let flexbox stretch
|
|
80
83
|
// these group separators across the slot's resolved height.
|
|
@@ -392,6 +395,126 @@ function DirectionalGlyph({
|
|
|
392
395
|
children: children
|
|
393
396
|
});
|
|
394
397
|
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Remove's glyph. No shared icon name means "unlink", so it is fixed
|
|
401
|
+
* component artwork until component icon slots exist.
|
|
402
|
+
*/
|
|
403
|
+
const REMOVE_LINK_GLYPH = /*#__PURE__*/_jsx("svg", {
|
|
404
|
+
width: "16",
|
|
405
|
+
height: "16",
|
|
406
|
+
viewBox: "0 0 24 24",
|
|
407
|
+
fill: "none",
|
|
408
|
+
"aria-hidden": "true",
|
|
409
|
+
children: /*#__PURE__*/_jsx("path", {
|
|
410
|
+
d: "M18 13l2-2a5 5 0 0 0-7-7l-2 2M6 11l-2 2a5 5 0 0 0 7 7l2-2M8 2v3M2 8h3M16 22v-3M22 16h-3",
|
|
411
|
+
stroke: "currentColor",
|
|
412
|
+
strokeWidth: "2",
|
|
413
|
+
strokeLinecap: "round",
|
|
414
|
+
strokeLinejoin: "round"
|
|
415
|
+
})
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
/** Room for a typical address beside the link form's icon buttons. */
|
|
419
|
+
const LINK_POPOVER_WIDTH = 320;
|
|
420
|
+
/**
|
|
421
|
+
* The link popover's content: one URL field, then Apply, Remove (only when
|
|
422
|
+
* the selection is in a link), and Cancel as icon buttons. Enter in the field
|
|
423
|
+
* applies, and Escape anywhere in the form cancels. A refused address shows
|
|
424
|
+
* the field's error status and keeps focus in the field.
|
|
425
|
+
*/
|
|
426
|
+
function ToolbarLinkForm({
|
|
427
|
+
url,
|
|
428
|
+
error,
|
|
429
|
+
isEditing,
|
|
430
|
+
size,
|
|
431
|
+
onUrlChange,
|
|
432
|
+
onApply,
|
|
433
|
+
onRemove,
|
|
434
|
+
onCancel
|
|
435
|
+
}) {
|
|
436
|
+
const t = useTranslator();
|
|
437
|
+
const inputRef = useRef(null);
|
|
438
|
+
const apply = () => {
|
|
439
|
+
if (!onApply()) {
|
|
440
|
+
inputRef.current?.focus();
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
const applyLabel = isEditing ? t('@astryx.richTextEditor.link.update') : t('@astryx.richTextEditor.link.add');
|
|
444
|
+
const removeLabel = t('@astryx.richTextEditor.link.remove');
|
|
445
|
+
const cancelLabel = t('@astryx.richTextEditor.link.cancel');
|
|
446
|
+
return /*#__PURE__*/_jsxs(HStack, {
|
|
447
|
+
gap: 1,
|
|
448
|
+
vAlign: "start",
|
|
449
|
+
onKeyDown: event => {
|
|
450
|
+
// Escape that ends an IME composition is the input method's.
|
|
451
|
+
if (event.key === 'Escape' && !isImeKeyEvent(event.nativeEvent)) {
|
|
452
|
+
// Claimed here, so the popover's own Escape handling leaves it to
|
|
453
|
+
// Cancel, which also gives the editor back its selection.
|
|
454
|
+
event.preventDefault();
|
|
455
|
+
onCancel();
|
|
456
|
+
}
|
|
457
|
+
},
|
|
458
|
+
children: [/*#__PURE__*/_jsx(StackItem, {
|
|
459
|
+
size: "fill",
|
|
460
|
+
children: /*#__PURE__*/_jsx(TextInput, {
|
|
461
|
+
ref: inputRef,
|
|
462
|
+
label: t('@astryx.richTextEditor.link.url'),
|
|
463
|
+
isLabelHidden: true,
|
|
464
|
+
value: url,
|
|
465
|
+
size: size,
|
|
466
|
+
width: "100%",
|
|
467
|
+
autoComplete: "url"
|
|
468
|
+
// A URL keyboard on touch screens and no spelling marks under an
|
|
469
|
+
// address. The field stays plain text, so a bare domain reaches
|
|
470
|
+
// the toolbar's own check, which makes it an https link.
|
|
471
|
+
,
|
|
472
|
+
inputMode: "url",
|
|
473
|
+
hasSpellCheck: false,
|
|
474
|
+
placeholder: t('@astryx.richTextEditor.link.urlPlaceholder'),
|
|
475
|
+
status: error ? {
|
|
476
|
+
type: 'error',
|
|
477
|
+
message: error
|
|
478
|
+
} : undefined,
|
|
479
|
+
statusVariant: "detached",
|
|
480
|
+
onChange: onUrlChange,
|
|
481
|
+
onEnter: apply,
|
|
482
|
+
onKeyDown: event => {
|
|
483
|
+
// Applying hands focus to the editor, which must not receive the
|
|
484
|
+
// rest of this Enter as a new line over the linked words.
|
|
485
|
+
if (event.key === 'Enter' && !isImeKeyEvent(event.nativeEvent)) {
|
|
486
|
+
event.preventDefault();
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
})
|
|
490
|
+
}), /*#__PURE__*/_jsx(IconButton, {
|
|
491
|
+
label: applyLabel,
|
|
492
|
+
icon: /*#__PURE__*/_jsx(Icon, {
|
|
493
|
+
icon: "check"
|
|
494
|
+
}),
|
|
495
|
+
variant: "ghost",
|
|
496
|
+
size: size,
|
|
497
|
+
tooltip: applyLabel,
|
|
498
|
+
onClick: apply
|
|
499
|
+
}), isEditing && /*#__PURE__*/_jsx(IconButton, {
|
|
500
|
+
label: removeLabel,
|
|
501
|
+
icon: REMOVE_LINK_GLYPH,
|
|
502
|
+
variant: "ghost",
|
|
503
|
+
size: size,
|
|
504
|
+
tooltip: removeLabel,
|
|
505
|
+
onClick: onRemove
|
|
506
|
+
}), /*#__PURE__*/_jsx(IconButton, {
|
|
507
|
+
label: cancelLabel,
|
|
508
|
+
icon: /*#__PURE__*/_jsx(Icon, {
|
|
509
|
+
icon: "close"
|
|
510
|
+
}),
|
|
511
|
+
variant: "ghost",
|
|
512
|
+
size: size,
|
|
513
|
+
tooltip: cancelLabel,
|
|
514
|
+
onClick: onCancel
|
|
515
|
+
})]
|
|
516
|
+
});
|
|
517
|
+
}
|
|
395
518
|
/**
|
|
396
519
|
* A composable formatting toolbar for {@link RichTextEditor}, built from Astryx
|
|
397
520
|
* `Toolbar` / `ToggleButton` primitives so it matches the active theme. Reads
|
|
@@ -454,7 +577,9 @@ export function RichTextEditorToolbar({
|
|
|
454
577
|
url: '',
|
|
455
578
|
isLink: false
|
|
456
579
|
});
|
|
457
|
-
const
|
|
580
|
+
const linkButtonRef = useRef(null);
|
|
581
|
+
const linkAnchorRef = useRef(null);
|
|
582
|
+
const [isLinkPopoverOpen, setIsLinkPopoverOpen] = useState(false);
|
|
458
583
|
const [isEditingLink, setIsEditingLink] = useState(false);
|
|
459
584
|
const [linkUrl, setLinkUrl] = useState('');
|
|
460
585
|
const [linkError, setLinkError] = useState('');
|
|
@@ -593,33 +718,63 @@ export function RichTextEditorToolbar({
|
|
|
593
718
|
}
|
|
594
719
|
return;
|
|
595
720
|
}
|
|
596
|
-
|
|
721
|
+
|
|
722
|
+
// The field starts from the link's address, or from selected text that
|
|
723
|
+
// already reads as one; otherwise it is empty and shows its placeholder.
|
|
724
|
+
setLinkUrl(context.url || (context.selectedText.startsWith('http') ? context.selectedText : ''));
|
|
597
725
|
setIsEditingLink(context.isLink);
|
|
598
726
|
setLinkError('');
|
|
599
|
-
|
|
727
|
+
// Cmd/Ctrl+K can open the form while the Link button is scrolled out of
|
|
728
|
+
// view, in the page or in the toolbar's own row. Bring it back so the
|
|
729
|
+
// popover opens beside it.
|
|
730
|
+
linkButtonRef.current?.scrollIntoView?.({
|
|
731
|
+
block: 'nearest',
|
|
732
|
+
inline: 'nearest'
|
|
733
|
+
});
|
|
734
|
+
setIsLinkPopoverOpen(true);
|
|
600
735
|
}, [applyLinkValue, editor, promptForUrl, readLinkContext, restoreLinkSelection]);
|
|
601
|
-
const
|
|
602
|
-
|
|
736
|
+
const closeLinkPopover = useCallback(() => {
|
|
737
|
+
setIsLinkPopoverOpen(false);
|
|
603
738
|
setLinkError('');
|
|
604
739
|
}, []);
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
740
|
+
|
|
741
|
+
// The popover reports its own opening (a press on the Link button) and its
|
|
742
|
+
// closing (a press outside it).
|
|
743
|
+
const handleLinkPopoverOpenChange = useCallback(open => {
|
|
744
|
+
if (open) {
|
|
745
|
+
toggleLink();
|
|
746
|
+
} else {
|
|
747
|
+
closeLinkPopover();
|
|
748
|
+
}
|
|
749
|
+
}, [closeLinkPopover, toggleLink]);
|
|
750
|
+
|
|
751
|
+
// Closes the popover and gives the editor back its focus. The editable root
|
|
752
|
+
// takes focus first and Lexical then draws its selection into it, so the
|
|
753
|
+
// selection survives the field having held the page's selection.
|
|
754
|
+
const closeLinkPopoverToEditor = useCallback(() => {
|
|
755
|
+
closeLinkPopover();
|
|
756
|
+
editor.getRootElement()?.focus({
|
|
757
|
+
preventScroll: true
|
|
758
|
+
});
|
|
759
|
+
editor.focus();
|
|
760
|
+
}, [closeLinkPopover, editor]);
|
|
761
|
+
const cancelLinkPopover = useCallback(() => {
|
|
762
|
+
restoreLinkSelection();
|
|
763
|
+
closeLinkPopoverToEditor();
|
|
764
|
+
}, [closeLinkPopoverToEditor, restoreLinkSelection]);
|
|
765
|
+
const applyLink = useCallback(() => {
|
|
612
766
|
if (!applyLinkValue(linkUrl)) {
|
|
613
767
|
setLinkError(t('@astryx.richTextEditor.link.invalidUrl'));
|
|
614
|
-
return;
|
|
768
|
+
return false;
|
|
615
769
|
}
|
|
616
|
-
|
|
617
|
-
|
|
770
|
+
closeLinkPopoverToEditor();
|
|
771
|
+
return true;
|
|
772
|
+
}, [applyLinkValue, closeLinkPopoverToEditor, linkUrl, t]);
|
|
618
773
|
const removeLink = useCallback(() => {
|
|
619
774
|
restoreLinkSelection();
|
|
620
775
|
editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
|
|
621
|
-
|
|
622
|
-
}, [
|
|
776
|
+
closeLinkPopoverToEditor();
|
|
777
|
+
}, [closeLinkPopoverToEditor, editor, restoreLinkSelection]);
|
|
623
778
|
useEffect(() => {
|
|
624
779
|
return mergeRegister(editor.registerUpdateListener(({
|
|
625
780
|
editorState
|
|
@@ -771,75 +926,66 @@ export function RichTextEditorToolbar({
|
|
|
771
926
|
isPressed: activeFormats.has(action.format),
|
|
772
927
|
isDisabled: !isEditable,
|
|
773
928
|
onPressedChange: () => toggleInlineFormat(action.format)
|
|
774
|
-
}, action.format)), hasLink &&
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
929
|
+
}, action.format)), hasLink &&
|
|
930
|
+
/*#__PURE__*/
|
|
931
|
+
// The popover anchors to this wrapper, which a press never
|
|
932
|
+
// scales, and finds the button inside it for its handlers.
|
|
933
|
+
_jsx("span", {
|
|
934
|
+
ref: linkAnchorRef,
|
|
935
|
+
...{
|
|
936
|
+
className: "x3nfvp2 x2lah0s"
|
|
937
|
+
},
|
|
938
|
+
children: /*#__PURE__*/_jsx(ToggleButton, {
|
|
939
|
+
ref: linkButtonRef,
|
|
940
|
+
label: t('@astryx.richTextEditor.toolbar.link'),
|
|
941
|
+
icon: icon('link'),
|
|
942
|
+
size: size,
|
|
943
|
+
isIconOnly: true,
|
|
944
|
+
isPressed: isLink || isLinkPopoverOpen,
|
|
945
|
+
isDisabled: !isEditable,
|
|
946
|
+
onMouseDown: event => event.preventDefault()
|
|
947
|
+
// The link popover owns a press on the button, and with it
|
|
948
|
+
// the button's popup state; `promptForUrl` replaces both.
|
|
949
|
+
,
|
|
950
|
+
onPressedChange: promptForUrl ? toggleLink : undefined
|
|
951
|
+
})
|
|
785
952
|
}, "link"), isRenderable(endContent) && /*#__PURE__*/_jsxs(_Fragment, {
|
|
786
953
|
children: [/*#__PURE__*/_jsx(Divider, {
|
|
787
954
|
orientation: "vertical"
|
|
788
955
|
}), endContent]
|
|
789
956
|
})]
|
|
790
957
|
})
|
|
791
|
-
}), hasLink && /*#__PURE__*/_jsx(
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
footer: /*#__PURE__*/_jsx(LayoutFooter, {
|
|
823
|
-
children: /*#__PURE__*/_jsxs(HStack, {
|
|
824
|
-
gap: 2,
|
|
825
|
-
hAlign: "end",
|
|
826
|
-
children: [isEditingLink && /*#__PURE__*/_jsx(Button, {
|
|
827
|
-
label: t('@astryx.richTextEditor.link.remove'),
|
|
828
|
-
variant: "destructive",
|
|
829
|
-
onClick: removeLink
|
|
830
|
-
}), /*#__PURE__*/_jsx(Button, {
|
|
831
|
-
label: t('@astryx.richTextEditor.link.cancel'),
|
|
832
|
-
variant: "secondary",
|
|
833
|
-
onClick: () => handleLinkDialogOpenChange(false)
|
|
834
|
-
}), /*#__PURE__*/_jsx(Button, {
|
|
835
|
-
label: isEditingLink ? t('@astryx.richTextEditor.link.update') : t('@astryx.richTextEditor.link.add'),
|
|
836
|
-
variant: "primary",
|
|
837
|
-
type: "submit"
|
|
838
|
-
})]
|
|
839
|
-
})
|
|
840
|
-
})
|
|
841
|
-
})
|
|
842
|
-
})
|
|
958
|
+
}), hasLink && promptForUrl == null && /*#__PURE__*/_jsx(Popover, {
|
|
959
|
+
anchorRef: linkAnchorRef,
|
|
960
|
+
label: isEditingLink ? t('@astryx.richTextEditor.link.editTitle') : t('@astryx.richTextEditor.link.insertTitle'),
|
|
961
|
+
isOpen: isLinkPopoverOpen,
|
|
962
|
+
onOpenChange: handleLinkPopoverOpenChange,
|
|
963
|
+
isModal: false
|
|
964
|
+
// Popover's focus entry focuses the URL field, the form's first
|
|
965
|
+
// control. Cancel is its close control.
|
|
966
|
+
,
|
|
967
|
+
hasCloseButton: false
|
|
968
|
+
// Above the toolbar, so the popover does not cover the editor's
|
|
969
|
+
// first lines, where the linked words often are. It flips below
|
|
970
|
+
// only when there is no room above.
|
|
971
|
+
,
|
|
972
|
+
placement: "above",
|
|
973
|
+
alignment: "start",
|
|
974
|
+
width: LINK_POPOVER_WIDTH,
|
|
975
|
+
padding: 2,
|
|
976
|
+
content: isLinkPopoverOpen ? /*#__PURE__*/_jsx(ToolbarLinkForm, {
|
|
977
|
+
url: linkUrl,
|
|
978
|
+
error: linkError,
|
|
979
|
+
isEditing: isEditingLink,
|
|
980
|
+
size: size,
|
|
981
|
+
onUrlChange: value => {
|
|
982
|
+
setLinkUrl(value);
|
|
983
|
+
setLinkError('');
|
|
984
|
+
},
|
|
985
|
+
onApply: applyLink,
|
|
986
|
+
onRemove: removeLink,
|
|
987
|
+
onCancel: cancelLinkPopover
|
|
988
|
+
}) : null
|
|
843
989
|
})]
|
|
844
990
|
});
|
|
845
991
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pastes a table into a table's cells. A table alone goes in cell by cell
|
|
3
|
+
* (`$pasteTableIntoCells`). A table that comes with other content, such as
|
|
4
|
+
* the paragraph and table a web page copies, goes into the cell with each
|
|
5
|
+
* table as text, since a cell holds no table. Any other paste is left to
|
|
6
|
+
* the editor's own handlers.
|
|
7
|
+
*/
|
|
8
|
+
export declare function TablePastePlugin(): null;
|
|
9
|
+
//# sourceMappingURL=TablePastePlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TablePastePlugin.d.ts","sourceRoot":"","sources":["../src/TablePastePlugin.tsx"],"names":[],"mappings":"AAoLA;;;;;;GAMG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAmCvC"}
|