@astryxdesign/richtext 0.6.6-canary.6ea1fb7 → 0.6.6-canary.7c8ddf2
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 +2 -2
- package/dist/RichTextEditor.d.ts.map +1 -1
- package/dist/RichTextEditor.js +9 -8
- package/dist/RichTextEditorToolbar.d.ts +12 -11
- package/dist/RichTextEditorToolbar.d.ts.map +1 -1
- package/dist/RichTextEditorToolbar.js +106 -70
- package/dist/RichTextView.d.ts.map +1 -1
- package/dist/RichTextView.js +6 -0
- package/dist/richtext.css +4 -0
- package/package.json +4 -4
- package/src/RichTextEditor.doc.mjs +4 -3
- package/src/RichTextEditor.test.tsx +94 -1
- package/src/RichTextEditor.tsx +13 -12
- package/src/RichTextEditorToolbar.tsx +140 -77
- package/src/RichTextView.tsx +12 -0
- package/src/__tests__/RichTextEditorToolbar.a11y.chromium.spec.ts +112 -0
- package/src/__tests__/RichTextView.a11y.chromium.spec.ts +100 -0
package/dist/RichTextEditor.d.ts
CHANGED
|
@@ -217,9 +217,9 @@ export interface RichTextEditorProps extends Omit<BaseProps, 'onChange' | 'defau
|
|
|
217
217
|
* Screen-reader hint describing how to move focus out of the editor, since
|
|
218
218
|
* Tab is bound to indentation (press Escape, then Tab). Rendered visually
|
|
219
219
|
* hidden and referenced from the editor's `aria-describedby`. Override it
|
|
220
|
-
* to
|
|
220
|
+
* to change the text, or pass an empty string to omit the hint entirely
|
|
221
221
|
* (e.g. when the host app provides its own instructions).
|
|
222
|
-
* @default 'Press Escape then Tab to move focus out of the editor.'
|
|
222
|
+
* @default 'Press Escape then Tab to move focus out of the editor.', translated for the active locale
|
|
223
223
|
*/
|
|
224
224
|
tabEscapeHint?: string;
|
|
225
225
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextEditor.d.ts","sourceRoot":"","sources":["../src/RichTextEditor.tsx"],"names":[],"mappings":"AAIA;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AC,WAAW,CAAC,CAAC,CAAC;IAC1C;;;;;OAKG;IACH,OAAO,CAAC,EAAE,SAAS,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,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;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,cAAc,mHAyRzB,CAAC"}
|
package/dist/RichTextEditor.js
CHANGED
|
@@ -34,6 +34,7 @@ import { sharedEditorTheme } from "./editorTheme.js";
|
|
|
34
34
|
import { Field, inputWrapperStyles, inputStatusBorderStyles, inputStatusHoverShadowStyles, inputStatusFocusWithinStyles } from '@astryxdesign/core/Field';
|
|
35
35
|
import { useInputStatusIcon } from '@astryxdesign/core/hooks';
|
|
36
36
|
import { VisuallyHidden } from '@astryxdesign/core/VisuallyHidden';
|
|
37
|
+
import { useTranslator } from '@astryxdesign/core/i18n';
|
|
37
38
|
import { mergeProps, themeProps } from '@astryxdesign/core/utils';
|
|
38
39
|
import { useSize } from '@astryxdesign/core/SizeContext';
|
|
39
40
|
import { LexicalExtensionComposer } from '@lexical/react/LexicalExtensionComposer';
|
|
@@ -161,12 +162,6 @@ const editorBodySizeStyles = {
|
|
|
161
162
|
}
|
|
162
163
|
};
|
|
163
164
|
|
|
164
|
-
/**
|
|
165
|
-
* Default screen-reader hint advertising the Tab escape. Overridable (or
|
|
166
|
-
* suppressible) via the `tabEscapeHint` prop for localization.
|
|
167
|
-
*/
|
|
168
|
-
const DEFAULT_TAB_ESCAPE_HINT = 'Press Escape then Tab to move focus out of the editor.';
|
|
169
|
-
|
|
170
165
|
/**
|
|
171
166
|
* Fraction of `maxLength` at which the character counter begins announcing
|
|
172
167
|
* remaining/over-limit characters to screen readers. Matches TextArea.
|
|
@@ -227,7 +222,7 @@ export const RichTextEditor = /*#__PURE__*/forwardRef(function RichTextEditor({
|
|
|
227
222
|
transformers = DEFAULT_TRANSFORMERS,
|
|
228
223
|
markdownExtensions,
|
|
229
224
|
hasAutoFocus = false,
|
|
230
|
-
tabEscapeHint
|
|
225
|
+
tabEscapeHint: tabEscapeHintFromProps,
|
|
231
226
|
maxLength,
|
|
232
227
|
namespace = 'astryx-editor',
|
|
233
228
|
xstyle,
|
|
@@ -236,6 +231,8 @@ export const RichTextEditor = /*#__PURE__*/forwardRef(function RichTextEditor({
|
|
|
236
231
|
...rest
|
|
237
232
|
}, ref) {
|
|
238
233
|
const size = useSize(sizeProp, 'md');
|
|
234
|
+
const t = useTranslator();
|
|
235
|
+
const tabEscapeHint = tabEscapeHintFromProps ?? t('@astryx.richTextEditor.tabEscapeHint');
|
|
239
236
|
const inputID = useId();
|
|
240
237
|
const labelID = useId();
|
|
241
238
|
const descriptionID = useId();
|
|
@@ -404,7 +401,11 @@ export const RichTextEditor = /*#__PURE__*/forwardRef(function RichTextEditor({
|
|
|
404
401
|
}[!!(charCount > maxLength) << 0],
|
|
405
402
|
children: [charCount, "/", maxLength, /*#__PURE__*/_jsx(VisuallyHidden, {
|
|
406
403
|
"aria-live": "polite",
|
|
407
|
-
children: charCount >= maxLength * COUNTER_WARNING_THRESHOLD ? charCount > maxLength ?
|
|
404
|
+
children: charCount >= maxLength * COUNTER_WARNING_THRESHOLD ? charCount > maxLength ? t('@astryx.textArea.charactersOverLimit', {
|
|
405
|
+
count: charCount - maxLength
|
|
406
|
+
}) : t('@astryx.textArea.charactersRemaining', {
|
|
407
|
+
count: maxLength - charCount
|
|
408
|
+
}) : ''
|
|
408
409
|
})]
|
|
409
410
|
})]
|
|
410
411
|
});
|
|
@@ -22,18 +22,19 @@
|
|
|
22
22
|
* commands); the UI is built from Astryx primitives so it matches the theme.
|
|
23
23
|
*
|
|
24
24
|
* ICONS: Each control resolves its glyph through the core icon registry under a
|
|
25
|
-
* stable `richtext:*` key (see {@link RICHTEXT_ICON_KEYS})
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
25
|
+
* stable `richtext:*` key (see {@link RICHTEXT_ICON_KEYS}) for the active
|
|
26
|
+
* theme, falling back to the bundled inline SVGs below — the library seam
|
|
27
|
+
* `getExtendedIcon` documents. A theme restyles any glyph by naming its key:
|
|
28
|
+
* defineTheme({icons: {'richtext:bold': <MyBoldIcon />}});
|
|
29
|
+
* Undo and redo point backward and forward in time, so they mirror under RTL
|
|
30
|
+
* whichever glyph draws them.
|
|
30
31
|
*/
|
|
31
32
|
import { type ReactNode } from 'react';
|
|
32
33
|
/**
|
|
33
|
-
* Stable icon-registry keys for the toolbar's controls.
|
|
34
|
-
* of these
|
|
35
|
-
*
|
|
36
|
-
*
|
|
34
|
+
* Stable icon-registry keys for the toolbar's controls. A theme overrides any
|
|
35
|
+
* of these by key: `defineTheme({icons: {'richtext:bold': <MyIcon />}})`.
|
|
36
|
+
* Keys are namespaced (`richtext:*`) to avoid collisions with the core
|
|
37
|
+
* semantic icon set.
|
|
37
38
|
*/
|
|
38
39
|
export declare const RICHTEXT_ICON_KEYS: {
|
|
39
40
|
readonly bold: "richtext:bold";
|
|
@@ -55,7 +56,7 @@ export declare const RICHTEXT_ICON_KEYS: {
|
|
|
55
56
|
export interface RichTextEditorToolbarProps {
|
|
56
57
|
/**
|
|
57
58
|
* Accessible label for the toolbar element.
|
|
58
|
-
* @default 'Text formatting'
|
|
59
|
+
* @default 'Text formatting', translated for the active locale
|
|
59
60
|
*/
|
|
60
61
|
label?: string;
|
|
61
62
|
/**
|
|
@@ -124,7 +125,7 @@ export interface RichTextEditorToolbarProps {
|
|
|
124
125
|
* />
|
|
125
126
|
* ```
|
|
126
127
|
*/
|
|
127
|
-
export declare function RichTextEditorToolbar({ label, headingLevels, size, hasLink, promptForUrl, linkOpensInNewTab, endContent, }: RichTextEditorToolbarProps): import("react").JSX.Element;
|
|
128
|
+
export declare function RichTextEditorToolbar({ label: labelFromProps, headingLevels, size, hasLink, promptForUrl, linkOpensInNewTab, endContent, }: RichTextEditorToolbarProps): import("react").JSX.Element;
|
|
128
129
|
export declare namespace RichTextEditorToolbar {
|
|
129
130
|
var displayName: string;
|
|
130
131
|
}
|
|
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAML,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAsIf;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;CAgBrB,CAAC;AAmPX,MAAM,WAAW,0BAA0B;IACzC;;;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,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;;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,iBAAwB,EACxB,UAAU,GACX,EAAE,0BAA0B,+BAugB5B;yBA/gBe,qBAAqB"}
|
|
@@ -26,11 +26,12 @@
|
|
|
26
26
|
* commands); the UI is built from Astryx primitives so it matches the theme.
|
|
27
27
|
*
|
|
28
28
|
* ICONS: Each control resolves its glyph through the core icon registry under a
|
|
29
|
-
* stable `richtext:*` key (see {@link RICHTEXT_ICON_KEYS})
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
29
|
+
* stable `richtext:*` key (see {@link RICHTEXT_ICON_KEYS}) for the active
|
|
30
|
+
* theme, falling back to the bundled inline SVGs below — the library seam
|
|
31
|
+
* `getExtendedIcon` documents. A theme restyles any glyph by naming its key:
|
|
32
|
+
* defineTheme({icons: {'richtext:bold': <MyBoldIcon />}});
|
|
33
|
+
* Undo and redo point backward and forward in time, so they mirror under RTL
|
|
34
|
+
* whichever glyph draws them.
|
|
34
35
|
*/
|
|
35
36
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
36
37
|
import * as stylex from '@stylexjs/stylex';
|
|
@@ -51,18 +52,17 @@ import { Button } from '@astryxdesign/core/Button';
|
|
|
51
52
|
import { Stack } from '@astryxdesign/core/Stack';
|
|
52
53
|
import { HStack, Layout, LayoutContent, LayoutFooter } from '@astryxdesign/core/Layout';
|
|
53
54
|
import { getExtendedIcon } from '@astryxdesign/core/Icon';
|
|
55
|
+
import { useThemeName } from '@astryxdesign/core/theme';
|
|
56
|
+
import { rtlStyles } from '@astryxdesign/core/utils';
|
|
57
|
+
import '@astryxdesign/core/theme/tokens.stylex';
|
|
58
|
+
import { fontWeightVars, typeScaleVars } from '@astryxdesign/core/theme/tokens.stylex';
|
|
59
|
+
import { useTranslator } from '@astryxdesign/core/i18n';
|
|
54
60
|
import { FORMAT_TEXT_COMMAND, UNDO_COMMAND, REDO_COMMAND, CAN_UNDO_COMMAND, CAN_REDO_COMMAND, SELECTION_CHANGE_COMMAND, KEY_DOWN_COMMAND, COMMAND_PRIORITY_CRITICAL, COMMAND_PRIORITY_NORMAL, IS_APPLE, isExactShortcutMatch, $getSelection, $isNodeSelection, $isRangeSelection, $setSelection, $createParagraphNode, $createTextNode } from 'lexical';
|
|
55
61
|
import { sanitizeUrl } from "./linkUtils.js";
|
|
56
62
|
import { $selectedExtensionNodesOnly } from "./markdownExtensionNode.js";
|
|
57
63
|
|
|
58
64
|
/** Block types exposed by the toolbar's format selector. */
|
|
59
65
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
60
|
-
const HEADING_LABELS = {
|
|
61
|
-
h1: 'Heading 1',
|
|
62
|
-
h2: 'Heading 2',
|
|
63
|
-
h3: 'Heading 3'
|
|
64
|
-
};
|
|
65
|
-
|
|
66
66
|
/**
|
|
67
67
|
* The platform-primary modifier for shortcuts: Cmd on Apple, Ctrl elsewhere.
|
|
68
68
|
* Mirrors the Lexical playground's `CONTROL_OR_META`
|
|
@@ -82,6 +82,12 @@ const toolbarDividerStyles = {
|
|
|
82
82
|
$$css: true
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
|
+
const glyphStyles = {
|
|
86
|
+
directional: {
|
|
87
|
+
k1xSpc: "x3nfvp2",
|
|
88
|
+
$$css: true
|
|
89
|
+
}
|
|
90
|
+
};
|
|
85
91
|
const toolbarScrollStyles = {
|
|
86
92
|
actions: {
|
|
87
93
|
kUk6DE: "x845mor",
|
|
@@ -107,10 +113,10 @@ function isInsertLink(event) {
|
|
|
107
113
|
}
|
|
108
114
|
|
|
109
115
|
/**
|
|
110
|
-
* Stable icon-registry keys for the toolbar's controls.
|
|
111
|
-
* of these
|
|
112
|
-
*
|
|
113
|
-
*
|
|
116
|
+
* Stable icon-registry keys for the toolbar's controls. A theme overrides any
|
|
117
|
+
* of these by key: `defineTheme({icons: {'richtext:bold': <MyIcon />}})`.
|
|
118
|
+
* Keys are namespaced (`richtext:*`) to avoid collisions with the core
|
|
119
|
+
* semantic icon set.
|
|
114
120
|
*/
|
|
115
121
|
export const RICHTEXT_ICON_KEYS = {
|
|
116
122
|
bold: 'richtext:bold',
|
|
@@ -131,23 +137,18 @@ export const RICHTEXT_ICON_KEYS = {
|
|
|
131
137
|
};
|
|
132
138
|
const INLINE_FORMAT_ACTIONS = [{
|
|
133
139
|
format: 'bold',
|
|
134
|
-
label: 'Bold',
|
|
135
140
|
icon: 'bold'
|
|
136
141
|
}, {
|
|
137
142
|
format: 'italic',
|
|
138
|
-
label: 'Italic',
|
|
139
143
|
icon: 'italic'
|
|
140
144
|
}, {
|
|
141
145
|
format: 'underline',
|
|
142
|
-
label: 'Underline',
|
|
143
146
|
icon: 'underline'
|
|
144
147
|
}, {
|
|
145
148
|
format: 'strikethrough',
|
|
146
|
-
label: 'Strikethrough',
|
|
147
149
|
icon: 'strikethrough'
|
|
148
150
|
}, {
|
|
149
151
|
format: 'code',
|
|
150
|
-
label: 'Inline code',
|
|
151
152
|
icon: 'code'
|
|
152
153
|
}];
|
|
153
154
|
/**
|
|
@@ -356,21 +357,30 @@ function TextGlyph({
|
|
|
356
357
|
}) {
|
|
357
358
|
return /*#__PURE__*/_jsx("span", {
|
|
358
359
|
"aria-hidden": "true",
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
fontWeight: 700,
|
|
362
|
-
fontVariantNumeric: 'tabular-nums'
|
|
360
|
+
...{
|
|
361
|
+
className: "x141an7d x1lvx875 xss6m8b"
|
|
363
362
|
},
|
|
364
363
|
children: label
|
|
365
364
|
});
|
|
366
365
|
}
|
|
367
|
-
|
|
368
366
|
/**
|
|
369
|
-
* Resolve a toolbar glyph
|
|
370
|
-
* `richtext:*` key,
|
|
367
|
+
* Resolve a toolbar glyph for the active theme: the theme's icon for the
|
|
368
|
+
* stable `richtext:*` key, then a globally registered one, then the bundled
|
|
369
|
+
* inline default.
|
|
371
370
|
*/
|
|
372
|
-
function resolveIcon(name) {
|
|
373
|
-
return getExtendedIcon(RICHTEXT_ICON_KEYS[name], defaultToolbarIcons[name]);
|
|
371
|
+
function resolveIcon(name, themeName) {
|
|
372
|
+
return getExtendedIcon(RICHTEXT_ICON_KEYS[name], defaultToolbarIcons[name], themeName);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** A glyph that points along the reading direction, mirrored under RTL. */
|
|
376
|
+
function DirectionalGlyph({
|
|
377
|
+
children
|
|
378
|
+
}) {
|
|
379
|
+
return /*#__PURE__*/_jsx("span", {
|
|
380
|
+
"aria-hidden": "true",
|
|
381
|
+
...stylex.props(glyphStyles.directional, rtlStyles.mirror),
|
|
382
|
+
children: children
|
|
383
|
+
});
|
|
374
384
|
}
|
|
375
385
|
/**
|
|
376
386
|
* A composable formatting toolbar for {@link RichTextEditor}, built from Astryx
|
|
@@ -393,7 +403,7 @@ function resolveIcon(name) {
|
|
|
393
403
|
* ```
|
|
394
404
|
*/
|
|
395
405
|
export function RichTextEditorToolbar({
|
|
396
|
-
label
|
|
406
|
+
label: labelFromProps,
|
|
397
407
|
headingLevels = ['h1', 'h2', 'h3'],
|
|
398
408
|
size = 'sm',
|
|
399
409
|
hasLink = true,
|
|
@@ -402,6 +412,23 @@ export function RichTextEditorToolbar({
|
|
|
402
412
|
endContent
|
|
403
413
|
}) {
|
|
404
414
|
const [editor] = useLexicalComposerContext();
|
|
415
|
+
const themeName = useThemeName();
|
|
416
|
+
const icon = name => resolveIcon(name, themeName);
|
|
417
|
+
const t = useTranslator();
|
|
418
|
+
const label = labelFromProps ?? t('@astryx.richTextEditor.toolbar.label');
|
|
419
|
+
// Literal keys, so the catalog gate can verify every one.
|
|
420
|
+
const headingLabels = {
|
|
421
|
+
h1: t('@astryx.richTextEditor.toolbar.heading1'),
|
|
422
|
+
h2: t('@astryx.richTextEditor.toolbar.heading2'),
|
|
423
|
+
h3: t('@astryx.richTextEditor.toolbar.heading3')
|
|
424
|
+
};
|
|
425
|
+
const inlineFormatLabels = {
|
|
426
|
+
bold: t('@astryx.richTextEditor.toolbar.bold'),
|
|
427
|
+
italic: t('@astryx.richTextEditor.toolbar.italic'),
|
|
428
|
+
underline: t('@astryx.richTextEditor.toolbar.underline'),
|
|
429
|
+
strikethrough: t('@astryx.richTextEditor.toolbar.strikethrough'),
|
|
430
|
+
code: t('@astryx.richTextEditor.toolbar.inlineCode')
|
|
431
|
+
};
|
|
405
432
|
const [activeFormats, setActiveFormats] = useState(new Set());
|
|
406
433
|
const [blockType, setBlockType] = useState('paragraph');
|
|
407
434
|
const [isLink, setIsLink] = useState(false);
|
|
@@ -558,11 +585,11 @@ export function RichTextEditorToolbar({
|
|
|
558
585
|
const handleLinkSubmit = useCallback(event => {
|
|
559
586
|
event.preventDefault();
|
|
560
587
|
if (!applyLinkValue(linkUrl)) {
|
|
561
|
-
setLinkError('
|
|
588
|
+
setLinkError(t('@astryx.richTextEditor.link.invalidUrl'));
|
|
562
589
|
return;
|
|
563
590
|
}
|
|
564
591
|
closeLinkDialogToEditor();
|
|
565
|
-
}, [applyLinkValue, closeLinkDialogToEditor, linkUrl]);
|
|
592
|
+
}, [applyLinkValue, closeLinkDialogToEditor, linkUrl, t]);
|
|
566
593
|
const removeLink = useCallback(() => {
|
|
567
594
|
restoreLinkSelection();
|
|
568
595
|
editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
|
|
@@ -639,24 +666,24 @@ export function RichTextEditorToolbar({
|
|
|
639
666
|
};
|
|
640
667
|
const blockOptions = [{
|
|
641
668
|
value: 'paragraph',
|
|
642
|
-
label: '
|
|
643
|
-
icon:
|
|
669
|
+
label: t('@astryx.richTextEditor.toolbar.paragraph'),
|
|
670
|
+
icon: icon('paragraph')
|
|
644
671
|
}, ...headingLevels.map(level => ({
|
|
645
672
|
value: level,
|
|
646
|
-
label:
|
|
647
|
-
icon:
|
|
673
|
+
label: headingLabels[level],
|
|
674
|
+
icon: icon(level)
|
|
648
675
|
})), {
|
|
649
676
|
value: 'bullet',
|
|
650
|
-
label: '
|
|
651
|
-
icon:
|
|
677
|
+
label: t('@astryx.richTextEditor.toolbar.bulletedList'),
|
|
678
|
+
icon: icon('bullet')
|
|
652
679
|
}, {
|
|
653
680
|
value: 'number',
|
|
654
|
-
label: '
|
|
655
|
-
icon:
|
|
681
|
+
label: t('@astryx.richTextEditor.toolbar.numberedList'),
|
|
682
|
+
icon: icon('number')
|
|
656
683
|
}, {
|
|
657
684
|
value: 'quote',
|
|
658
|
-
label: '
|
|
659
|
-
icon:
|
|
685
|
+
label: t('@astryx.richTextEditor.toolbar.blockQuote'),
|
|
686
|
+
icon: icon('quote')
|
|
660
687
|
}];
|
|
661
688
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
662
689
|
children: [/*#__PURE__*/_jsx(Toolbar, {
|
|
@@ -665,51 +692,60 @@ export function RichTextEditorToolbar({
|
|
|
665
692
|
startContent: /*#__PURE__*/_jsxs(HStack, {
|
|
666
693
|
gap: 1,
|
|
667
694
|
role: "group",
|
|
668
|
-
"aria-label":
|
|
695
|
+
"aria-label": t('@astryx.richTextEditor.toolbar.actions'),
|
|
669
696
|
xstyle: toolbarScrollStyles.actions,
|
|
670
697
|
children: [/*#__PURE__*/_jsx(IconButton, {
|
|
671
|
-
label:
|
|
672
|
-
icon:
|
|
698
|
+
label: t('@astryx.richTextEditor.toolbar.undo'),
|
|
699
|
+
icon: /*#__PURE__*/_jsx(DirectionalGlyph, {
|
|
700
|
+
children: icon('undo')
|
|
701
|
+
}),
|
|
673
702
|
variant: "ghost",
|
|
674
|
-
tooltip:
|
|
703
|
+
tooltip: t('@astryx.richTextEditor.toolbar.undo'),
|
|
675
704
|
isDisabled: !isEditable || !canUndo,
|
|
676
705
|
onClick: () => editor.dispatchCommand(UNDO_COMMAND, undefined)
|
|
677
706
|
}), /*#__PURE__*/_jsx(IconButton, {
|
|
678
|
-
label:
|
|
679
|
-
icon:
|
|
707
|
+
label: t('@astryx.richTextEditor.toolbar.redo'),
|
|
708
|
+
icon: /*#__PURE__*/_jsx(DirectionalGlyph, {
|
|
709
|
+
children: icon('redo')
|
|
710
|
+
}),
|
|
680
711
|
variant: "ghost",
|
|
681
|
-
tooltip:
|
|
712
|
+
tooltip: t('@astryx.richTextEditor.toolbar.redo'),
|
|
682
713
|
isDisabled: !isEditable || !canRedo,
|
|
683
714
|
onClick: () => editor.dispatchCommand(REDO_COMMAND, undefined)
|
|
684
715
|
}), /*#__PURE__*/_jsx(Divider, {
|
|
685
716
|
orientation: "vertical",
|
|
686
|
-
"aria-label":
|
|
717
|
+
"aria-label": t('@astryx.richTextEditor.toolbar.historyDivider'),
|
|
687
718
|
xstyle: toolbarDividerStyles.vertical
|
|
688
|
-
}), /*#__PURE__*/_jsx(
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
719
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
720
|
+
...{
|
|
721
|
+
className: "x78zum5 x2lah0s"
|
|
722
|
+
},
|
|
723
|
+
children: /*#__PURE__*/_jsx(Selector, {
|
|
724
|
+
label: t('@astryx.richTextEditor.toolbar.blockFormat'),
|
|
725
|
+
isLabelHidden: true,
|
|
726
|
+
variant: "ghost",
|
|
727
|
+
size: size,
|
|
728
|
+
value: blockType,
|
|
729
|
+
options: blockOptions,
|
|
730
|
+
startIcon: icon(blockType),
|
|
731
|
+
isDisabled: !isEditable,
|
|
732
|
+
onChange: value => setBlock(value)
|
|
733
|
+
})
|
|
698
734
|
}), /*#__PURE__*/_jsx(Divider, {
|
|
699
735
|
orientation: "vertical",
|
|
700
|
-
"aria-label":
|
|
736
|
+
"aria-label": t('@astryx.richTextEditor.toolbar.formatDivider'),
|
|
701
737
|
xstyle: toolbarDividerStyles.vertical
|
|
702
738
|
}), INLINE_FORMAT_ACTIONS.map(action => /*#__PURE__*/_jsx(ToggleButton, {
|
|
703
|
-
label: action.
|
|
704
|
-
icon:
|
|
739
|
+
label: inlineFormatLabels[action.format],
|
|
740
|
+
icon: icon(action.icon),
|
|
705
741
|
size: size,
|
|
706
742
|
isIconOnly: true,
|
|
707
743
|
isPressed: activeFormats.has(action.format),
|
|
708
744
|
isDisabled: !isEditable,
|
|
709
745
|
onPressedChange: () => toggleInlineFormat(action.format)
|
|
710
746
|
}, action.format)), hasLink && /*#__PURE__*/_jsx(ToggleButton, {
|
|
711
|
-
label:
|
|
712
|
-
icon:
|
|
747
|
+
label: t('@astryx.richTextEditor.toolbar.link'),
|
|
748
|
+
icon: icon('link'),
|
|
713
749
|
size: size,
|
|
714
750
|
isIconOnly: true,
|
|
715
751
|
isPressed: isLink || isLinkDialogOpen,
|
|
@@ -735,12 +771,12 @@ export function RichTextEditorToolbar({
|
|
|
735
771
|
children: /*#__PURE__*/_jsx(Layout, {
|
|
736
772
|
height: "auto",
|
|
737
773
|
header: /*#__PURE__*/_jsx(DialogHeader, {
|
|
738
|
-
title: isEditingLink ? '
|
|
774
|
+
title: isEditingLink ? t('@astryx.richTextEditor.link.editTitle') : t('@astryx.richTextEditor.link.insertTitle'),
|
|
739
775
|
onOpenChange: handleLinkDialogOpenChange
|
|
740
776
|
}),
|
|
741
777
|
content: /*#__PURE__*/_jsx(LayoutContent, {
|
|
742
778
|
children: /*#__PURE__*/_jsx(TextInput, {
|
|
743
|
-
label:
|
|
779
|
+
label: t('@astryx.richTextEditor.link.url'),
|
|
744
780
|
value: linkUrl,
|
|
745
781
|
width: "100%",
|
|
746
782
|
hasAutoFocus: true,
|
|
@@ -760,15 +796,15 @@ export function RichTextEditorToolbar({
|
|
|
760
796
|
gap: 2,
|
|
761
797
|
hAlign: "end",
|
|
762
798
|
children: [isEditingLink && /*#__PURE__*/_jsx(Button, {
|
|
763
|
-
label:
|
|
799
|
+
label: t('@astryx.richTextEditor.link.remove'),
|
|
764
800
|
variant: "destructive",
|
|
765
801
|
onClick: removeLink
|
|
766
802
|
}), /*#__PURE__*/_jsx(Button, {
|
|
767
|
-
label:
|
|
803
|
+
label: t('@astryx.richTextEditor.link.cancel'),
|
|
768
804
|
variant: "secondary",
|
|
769
805
|
onClick: () => handleLinkDialogOpenChange(false)
|
|
770
806
|
}), /*#__PURE__*/_jsx(Button, {
|
|
771
|
-
label: isEditingLink ? '
|
|
807
|
+
label: isEditingLink ? t('@astryx.richTextEditor.link.update') : t('@astryx.richTextEditor.link.add'),
|
|
772
808
|
variant: "primary",
|
|
773
809
|
type: "submit"
|
|
774
810
|
})]
|
|
@@ -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;
|
|
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,SAAyB,EACzB,YAAY,EACZ,aAAoB,EACpB,MAAM,EACN,SAAS,EACT,KAAK,EACL,GAAG,IAAI,EACR,EAAE,iBAAiB,+BA8HnB;yBA1Ie,YAAY"}
|
package/dist/RichTextView.js
CHANGED
|
@@ -21,6 +21,8 @@ import { useEffect, useRef, useState } from 'react';
|
|
|
21
21
|
import * as stylex from '@stylexjs/stylex';
|
|
22
22
|
import { sharedEditorTheme } from "./editorTheme.js";
|
|
23
23
|
import { mergeProps } from '@astryxdesign/core/utils';
|
|
24
|
+
import '@astryxdesign/core/theme/tokens.stylex';
|
|
25
|
+
import { colorVars, typeScaleVars, typographyVars } from '@astryxdesign/core/theme/tokens.stylex';
|
|
24
26
|
import { LexicalExtensionComposer } from '@lexical/react/LexicalExtensionComposer';
|
|
25
27
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
26
28
|
import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
|
|
@@ -42,6 +44,10 @@ const styles = {
|
|
|
42
44
|
root: {
|
|
43
45
|
kzqmXN: "xh8yej3",
|
|
44
46
|
kVAEAm: "x1n2onr6",
|
|
47
|
+
kMv6JI: "x9ynric",
|
|
48
|
+
kGuDYH: "xjm74w1",
|
|
49
|
+
kLWn49: "xw6l6zx",
|
|
50
|
+
kMwMTN: "x1tgivj0",
|
|
45
51
|
$$css: true
|
|
46
52
|
}
|
|
47
53
|
};
|
package/dist/richtext.css
CHANGED
|
@@ -56,7 +56,9 @@
|
|
|
56
56
|
.x1lliihq:not(#\#):not(#\#):not(#\#){display:block}
|
|
57
57
|
.x78zum5:not(#\#):not(#\#):not(#\#){display:flex}
|
|
58
58
|
.xrvj5dj:not(#\#):not(#\#):not(#\#){display:grid}
|
|
59
|
+
.x3nfvp2:not(#\#):not(#\#):not(#\#){display:inline-flex}
|
|
59
60
|
.xdt5ytf:not(#\#):not(#\#):not(#\#){flex-direction:column}
|
|
61
|
+
.x2lah0s:not(#\#):not(#\#):not(#\#){flex-shrink:0}
|
|
60
62
|
.x9ynric:not(#\#):not(#\#):not(#\#){font-family:var(--font-family-body)}
|
|
61
63
|
.x9m5x89:not(#\#):not(#\#):not(#\#){font-family:var(--font-family-code)}
|
|
62
64
|
.x1g81bgm:not(#\#):not(#\#):not(#\#){font-family:var(--font-family-heading)}
|
|
@@ -70,7 +72,9 @@
|
|
|
70
72
|
.xw5ohdf:not(#\#):not(#\#):not(#\#){font-size:var(--text-heading-6-size)}
|
|
71
73
|
.x141an7d:not(#\#):not(#\#):not(#\#){font-size:var(--text-supporting-size)}
|
|
72
74
|
.x1k4tb9n:not(#\#):not(#\#):not(#\#){font-style:italic}
|
|
75
|
+
.xss6m8b:not(#\#):not(#\#):not(#\#){font-variant-numeric:tabular-nums}
|
|
73
76
|
.x1pd3egz:not(#\#):not(#\#):not(#\#){font-weight:inherit}
|
|
77
|
+
.x1lvx875:not(#\#):not(#\#):not(#\#){font-weight:var(--font-weight-bold)}
|
|
74
78
|
.x1e4wzip:not(#\#):not(#\#):not(#\#){font-weight:var(--font-weight-medium)}
|
|
75
79
|
.x2mo6ok:not(#\#):not(#\#):not(#\#){font-weight:var(--font-weight-semibold)}
|
|
76
80
|
.x1v68xuy:not(#\#):not(#\#):not(#\#){font-weight:var(--text-heading-1-weight)}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/richtext",
|
|
3
3
|
"displayName": "Rich Text",
|
|
4
|
-
"version": "0.6.6-canary.
|
|
4
|
+
"version": "0.6.6-canary.7c8ddf2",
|
|
5
5
|
"description": "Astryx rich text — a Lexical-based rich text editor and viewer. Published to npm only under the @canary dist-tag for early testing; never released as a stable (latest) version.",
|
|
6
6
|
"author": "Meta Open Source",
|
|
7
7
|
"license": "MIT",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"@stylexjs/stylex": ">=0.10.0",
|
|
58
|
-
"@astryxdesign/core": "0.6.6-canary.
|
|
58
|
+
"@astryxdesign/core": "0.6.6-canary.7c8ddf2",
|
|
59
59
|
"react": ">=19.0.0",
|
|
60
60
|
"react-dom": ">=19.0.0",
|
|
61
61
|
"lexical": "^0.46.0",
|
|
@@ -114,8 +114,8 @@
|
|
|
114
114
|
}
|
|
115
115
|
},
|
|
116
116
|
"devDependencies": {
|
|
117
|
-
"@astryxdesign/a11y-spec": "0.6.6-canary.
|
|
118
|
-
"@astryxdesign/cli": "0.6.6-canary.
|
|
117
|
+
"@astryxdesign/a11y-spec": "0.6.6-canary.7c8ddf2",
|
|
118
|
+
"@astryxdesign/cli": "0.6.6-canary.7c8ddf2",
|
|
119
119
|
"@babel/cli": "^7.29.7",
|
|
120
120
|
"@babel/core": "^7.29.7",
|
|
121
121
|
"@babel/preset-react": "^7.29.7",
|
|
@@ -135,8 +135,9 @@ export const docs = {
|
|
|
135
135
|
name: 'tabEscapeHint',
|
|
136
136
|
type: 'string',
|
|
137
137
|
description:
|
|
138
|
-
'Screen-reader hint describing how to move focus out of the editor, since Tab is bound to indentation (press Escape, then Tab). Visually hidden, wired via aria-describedby.
|
|
139
|
-
default:
|
|
138
|
+
'Screen-reader hint describing how to move focus out of the editor, since Tab is bound to indentation (press Escape, then Tab). Visually hidden, wired via aria-describedby. Translated for the active locale; override to change the text, or pass "" to omit.',
|
|
139
|
+
default:
|
|
140
|
+
"'Press Escape then Tab to move focus out of the editor.' (translated)",
|
|
140
141
|
},
|
|
141
142
|
{
|
|
142
143
|
name: 'maxLength',
|
|
@@ -238,7 +239,7 @@ export const docs = {
|
|
|
238
239
|
{
|
|
239
240
|
guidance: true,
|
|
240
241
|
description:
|
|
241
|
-
"The toolbar's glyphs are themeable. Each control resolves its icon from the core icon registry under a stable richtext:* key (see RICHTEXT_ICON_KEYS), falling back to a bundled inline SVG. A theme
|
|
242
|
+
"The toolbar's glyphs are themeable. Each control resolves its icon from the core icon registry under a stable richtext:* key (see RICHTEXT_ICON_KEYS), falling back to a bundled inline SVG. A theme restyles any glyph without forking the toolbar by naming its key: defineTheme({icons: {'richtext:bold': <MyBoldIcon />}}). Undo and redo mirror under right-to-left direction, whichever glyph draws them.",
|
|
242
243
|
},
|
|
243
244
|
{
|
|
244
245
|
guidance: false,
|