@vokality/design-system 2.0.0 → 3.0.0

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.
Files changed (161) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +49 -3
  3. package/dist/browser.d.ts +13 -0
  4. package/dist/browser.js +7 -0
  5. package/dist/charts/chart.d.ts +6 -5
  6. package/dist/charts/chart.js +44 -25
  7. package/dist/chat.d.ts +54 -0
  8. package/dist/chat.js +1 -0
  9. package/dist/components/Accordion/Accordion.js +1 -1
  10. package/dist/components/Alert/Alert.js +5 -2
  11. package/dist/components/AppShell/AppShell.js +10 -14
  12. package/dist/components/Avatar/Avatar.js +2 -2
  13. package/dist/components/AvatarGroup/AvatarGroup.js +2 -2
  14. package/dist/components/BarChart/BarChart.js +17 -15
  15. package/dist/components/Breadcrumbs/Breadcrumbs.js +6 -3
  16. package/dist/components/Calendar/Calendar.js +6 -5
  17. package/dist/components/Card/Card.js +2 -3
  18. package/dist/components/ChatInbox/ChatInbox.d.ts +11 -0
  19. package/dist/components/ChatInbox/ChatInbox.js +49 -0
  20. package/dist/components/ChatPanel/ChatPanel.d.ts +3 -0
  21. package/dist/components/ChatPanel/ChatPanel.js +13 -0
  22. package/dist/components/ChatPanel/composer.d.ts +5 -0
  23. package/dist/components/ChatPanel/composer.js +32 -0
  24. package/dist/components/ChatPanel/transcript.d.ts +13 -0
  25. package/dist/components/ChatPanel/transcript.js +39 -0
  26. package/dist/components/ChatWidget/ChatWidget.d.ts +12 -0
  27. package/dist/components/ChatWidget/ChatWidget.js +42 -0
  28. package/dist/components/Checkbox/Checkbox.d.ts +5 -10
  29. package/dist/components/Checkbox/Checkbox.js +5 -19
  30. package/dist/components/CodeBlock/CodeBlock.js +19 -5
  31. package/dist/components/Combobox/Combobox.js +22 -15
  32. package/dist/components/Combobox/ListPanel.js +20 -9
  33. package/dist/components/CommandPalette/CommandPalette.js +33 -14
  34. package/dist/components/ContextMenu/ContextMenu.d.ts +2 -2
  35. package/dist/components/ContextMenu/ContextMenu.js +5 -50
  36. package/dist/components/DatePicker/DatePicker.js +35 -29
  37. package/dist/components/DescriptionList/DescriptionList.js +1 -1
  38. package/dist/components/Dialog/Dialog.d.ts +24 -7
  39. package/dist/components/Dialog/Dialog.js +30 -41
  40. package/dist/components/Drawer/Drawer.d.ts +4 -2
  41. package/dist/components/EmptyState/EmptyState.js +2 -2
  42. package/dist/components/ErrorSummary/ErrorSummary.js +5 -3
  43. package/dist/components/FaqList/FaqList.js +1 -1
  44. package/dist/components/Field/Field.js +2 -2
  45. package/dist/components/FileUpload/FileUpload.js +17 -9
  46. package/dist/components/Grid/Grid.d.ts +5 -5
  47. package/dist/components/Grid/Grid.js +1 -1
  48. package/dist/components/Heading/Heading.js +2 -1
  49. package/dist/components/Icon/Icon.js +4 -2
  50. package/dist/components/Inline/Inline.d.ts +7 -7
  51. package/dist/components/LineChart/LineChart.js +17 -15
  52. package/dist/components/LinkProvider/LinkProvider.d.ts +1 -1
  53. package/dist/components/LinkProvider/LinkProvider.js +6 -2
  54. package/dist/components/List/List.js +1 -1
  55. package/dist/components/MediaCard/MediaCard.js +2 -2
  56. package/dist/components/Menu/Menu.js +6 -43
  57. package/dist/components/Menu/entries.d.ts +1 -30
  58. package/dist/components/Menu/entries.js +16 -100
  59. package/dist/components/MultiSelect/MultiSelect.js +43 -34
  60. package/dist/components/NumberInput/NumberInput.js +17 -18
  61. package/dist/components/OtpInput/OtpInput.d.ts +1 -1
  62. package/dist/components/OtpInput/OtpInput.js +10 -67
  63. package/dist/components/PageHeader/PageHeader.js +2 -2
  64. package/dist/components/Pagination/Pagination.js +3 -1
  65. package/dist/components/PasswordInput/PasswordInput.d.ts +1 -1
  66. package/dist/components/PasswordInput/PasswordInput.js +9 -4
  67. package/dist/components/Popover/Popover.d.ts +6 -7
  68. package/dist/components/Popover/Popover.js +2 -19
  69. package/dist/components/Progress/Progress.d.ts +1 -1
  70. package/dist/components/Progress/Progress.js +7 -11
  71. package/dist/components/Radio/Radio.d.ts +4 -2
  72. package/dist/components/RadioGroup/RadioGroup.d.ts +5 -12
  73. package/dist/components/RadioGroup/RadioGroup.js +6 -33
  74. package/dist/components/RichTextEditor/RichTextEditor.d.ts +63 -0
  75. package/dist/components/RichTextEditor/RichTextEditor.js +175 -0
  76. package/dist/components/RichTextEditor/toolbar.d.ts +15 -0
  77. package/dist/components/RichTextEditor/toolbar.js +142 -0
  78. package/dist/components/RichTextEditor/uploads.d.ts +41 -0
  79. package/dist/components/RichTextEditor/uploads.js +124 -0
  80. package/dist/components/SearchInput/SearchInput.js +4 -2
  81. package/dist/components/SectionHeader/SectionHeader.js +1 -3
  82. package/dist/components/SegmentedControl/SegmentedControl.js +2 -12
  83. package/dist/components/Select/Select.d.ts +15 -16
  84. package/dist/components/Select/Select.js +11 -252
  85. package/dist/components/Slider/Slider.js +11 -21
  86. package/dist/components/Sparkline/Sparkline.js +8 -3
  87. package/dist/components/Spinner/Spinner.js +5 -2
  88. package/dist/components/Stack/Stack.d.ts +5 -5
  89. package/dist/components/Stat/Stat.js +6 -3
  90. package/dist/components/Steps/Steps.js +6 -3
  91. package/dist/components/Switch/Switch.d.ts +7 -7
  92. package/dist/components/Switch/Switch.js +4 -10
  93. package/dist/components/Table/Table.js +38 -19
  94. package/dist/components/Tabs/Tabs.js +2 -22
  95. package/dist/components/Tag/Tag.js +3 -1
  96. package/dist/components/Text/Text.d.ts +1 -1
  97. package/dist/components/TileGrid/TileGrid.js +1 -1
  98. package/dist/components/TimePicker/TimePicker.js +35 -33
  99. package/dist/components/Timeline/Timeline.js +5 -4
  100. package/dist/components/Toaster/Toaster.js +21 -17
  101. package/dist/components/Tooltip/Tooltip.d.ts +6 -6
  102. package/dist/components/Tooltip/Tooltip.js +3 -17
  103. package/dist/components/TreeView/TreeView.js +15 -12
  104. package/dist/components.css +179 -8
  105. package/dist/hooks/useTheme.js +6 -6
  106. package/dist/icons/message-circle.svg +1 -0
  107. package/dist/internal/CharCount.js +3 -1
  108. package/dist/internal/choice.d.ts +10 -48
  109. package/dist/internal/choice.js +8 -96
  110. package/dist/internal/options.d.ts +10 -5
  111. package/dist/internal/options.js +25 -11
  112. package/dist/internal/status.d.ts +3 -2
  113. package/dist/internal/status.js +10 -2
  114. package/dist/internal/useScrollActive.js +2 -2
  115. package/dist/internal/useToday.d.ts +3 -0
  116. package/dist/internal/useToday.js +42 -0
  117. package/dist/lib/dates.js +25 -15
  118. package/dist/lib/format.js +11 -8
  119. package/dist/lib/icons.d.ts +5 -0
  120. package/dist/lib/icons.js +2 -0
  121. package/dist/lib/math.js +17 -5
  122. package/dist/lib/rich-text.d.ts +13 -0
  123. package/dist/lib/rich-text.js +62 -0
  124. package/dist/lib/space.d.ts +1 -2
  125. package/dist/lib/space.js +4 -1
  126. package/dist/lib/text.js +1 -1
  127. package/dist/lib/theme.js +1 -1
  128. package/dist/localization.d.ts +166 -0
  129. package/dist/localization.js +142 -0
  130. package/dist/vokality.css +179 -8
  131. package/dist/vokality.iife.js +35986 -9685
  132. package/docs/brand.md +6 -3
  133. package/docs/components/AppShell/README.md +1 -1
  134. package/docs/components/BarChart/README.md +1 -0
  135. package/docs/components/ChatInbox/README.md +41 -0
  136. package/docs/components/ChatWidget/README.md +47 -0
  137. package/docs/components/Checkbox/README.md +7 -3
  138. package/docs/components/ContextMenu/README.md +7 -3
  139. package/docs/components/Dialog/README.md +9 -4
  140. package/docs/components/Drawer/README.md +1 -1
  141. package/docs/components/Field/README.md +1 -1
  142. package/docs/components/Fieldset/README.md +2 -2
  143. package/docs/components/LineChart/README.md +1 -0
  144. package/docs/components/LocaleProvider/README.md +48 -0
  145. package/docs/components/Menu/README.md +13 -8
  146. package/docs/components/OtpInput/README.md +9 -5
  147. package/docs/components/PasswordInput/README.md +11 -2
  148. package/docs/components/Popover/README.md +6 -3
  149. package/docs/components/Progress/README.md +3 -1
  150. package/docs/components/RadioGroup/README.md +5 -2
  151. package/docs/components/RichTextEditor/README.md +84 -0
  152. package/docs/components/SegmentedControl/README.md +2 -0
  153. package/docs/components/Select/README.md +13 -17
  154. package/docs/components/Skeleton/README.md +1 -1
  155. package/docs/components/Slider/README.md +4 -2
  156. package/docs/components/Steps/README.md +1 -1
  157. package/docs/components/Switch/README.md +5 -2
  158. package/docs/components/Tabs/README.md +4 -2
  159. package/docs/components/Toaster/README.md +3 -1
  160. package/docs/components/Tooltip/README.md +5 -3
  161. package/package.json +49 -5
@@ -0,0 +1,63 @@
1
+ import { type FocusEventHandler } from "react";
2
+ /** A durable, app-managed attachment; its link is persisted in the Markdown document. */
3
+ export interface RichTextAttachment {
4
+ name: string;
5
+ url: string;
6
+ }
7
+ /** The application owns authentication and storage. Abort on signal when an attempt is canceled. */
8
+ export type RichTextUpload = (file: File, options: {
9
+ signal: AbortSignal;
10
+ }) => Promise<RichTextAttachment>;
11
+ /** Unicode emoji and its localized accessible/search label. */
12
+ export interface RichTextEmoji {
13
+ value: string;
14
+ label: string;
15
+ }
16
+ export interface RichTextEditorProps {
17
+ /** Controlled CommonMark document. */
18
+ value?: string;
19
+ /** Initial CommonMark document for an uncontrolled editor. */
20
+ defaultValue?: string;
21
+ /** Emits canonical CommonMark after document changes; selection changes do not emit. */
22
+ onChange?: (markdown: string) => void;
23
+ /** Native form field name; submissions contain the Markdown string. */
24
+ name?: string;
25
+ /** ID of the editable textbox, including when wired by Field. */
26
+ id?: string;
27
+ /** Prevent all changes, uploads and form submission of this field. */
28
+ disabled?: boolean;
29
+ /** Keep the document readable/selectable, without editing or a toolbar. */
30
+ readOnly?: boolean;
31
+ /** Full controls above the field, or a small action row with expandable formatting below. */
32
+ toolbar?: "full" | "minimal";
33
+ /** Native form validation focuses the editor when the Markdown field is empty. */
34
+ required?: boolean;
35
+ /** Hint shown inside an empty editor; supply a visible Field label too. */
36
+ placeholder?: string;
37
+ /** Outer wrapper class. */
38
+ className?: string;
39
+ /** Called when focus leaves the editable textbox. */
40
+ onBlur?: FocusEventHandler<HTMLDivElement>;
41
+ /** Enable attachments with an app-provided upload callback. */
42
+ onUploadAttachment?: RichTextUpload;
43
+ /** File chooser accept filter, for example "image/*,.pdf". Enforce server-side too. */
44
+ accept?: string;
45
+ /** Reject files larger than this byte count before calling the upload callback. */
46
+ maxFileSize?: number;
47
+ /** Override the built-in labeled Unicode emoji choices. */
48
+ emojiOptions?: readonly RichTextEmoji[];
49
+ /** Observe upload and callback-contract errors; the UI shows localized retry feedback. */
50
+ onUploadError?: (error: Error, file: File) => void;
51
+ /** Observe the existing upload state, for example to disable a surrounding Send action. */
52
+ onUploadPendingChange?: (pending: boolean) => void;
53
+ /** Accessible name when a visible Field does not provide one. */
54
+ "aria-label"?: string;
55
+ /** Visible label ID, set by Field. */
56
+ "aria-labelledby"?: string;
57
+ /** Hint/error IDs, set by Field. */
58
+ "aria-describedby"?: string;
59
+ /** Invalid state, set by Field. */
60
+ "aria-invalid"?: boolean | "true" | "false" | "grammar" | "spelling";
61
+ }
62
+ /** A ProseMirror editor with CommonMark persistence, formatting, Unicode emoji and attachment uploads. */
63
+ export declare const RichTextEditor: import("react").ForwardRefExoticComponent<RichTextEditorProps & import("react").RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,175 @@
1
+ "use client";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { forwardRef, useCallback, useEffect, useRef, useState } from "react";
4
+ import { EditorState, Plugin } from "prosemirror-state";
5
+ import { EditorView } from "prosemirror-view";
6
+ import { baseKeymap, chainCommands, exitCode, setBlockType, toggleMark } from "prosemirror-commands";
7
+ import { history, undo, redo } from "prosemirror-history";
8
+ import { keymap } from "prosemirror-keymap";
9
+ import { schema } from "prosemirror-markdown";
10
+ import { liftListItem, sinkListItem, splitListItem, wrapInList } from "prosemirror-schema-list";
11
+ import { hasSafeRichTextUrls, parseRichTextMarkdown, serializeRichTextMarkdown } from "../../lib/rich-text.js";
12
+ import { cx } from "../../lib/cx.js";
13
+ import { useUid } from "../../internal/useUid.js";
14
+ import { useIsoLayoutEffect } from "../../internal/useIsoLayoutEffect.js";
15
+ import { RichTextToolbar } from "./toolbar.js";
16
+ import { RichTextUploads, useRichTextUploads } from "./uploads.js";
17
+ function editorPlugins() {
18
+ const hardBreak = chainCommands(exitCode, (state, dispatch) => {
19
+ if (dispatch)
20
+ dispatch(state.tr.replaceSelectionWith(schema.nodes.hard_break.create()).scrollIntoView());
21
+ return true;
22
+ });
23
+ return [
24
+ new Plugin({ filterTransaction: (transaction) => !transaction.docChanged || hasSafeRichTextUrls(transaction.doc) }),
25
+ history(),
26
+ keymap({
27
+ "Mod-z": undo, "Mod-y": redo, "Shift-Mod-z": redo,
28
+ "Mod-b": toggleMark(schema.marks.strong), "Mod-i": toggleMark(schema.marks.em), "Mod-`": toggleMark(schema.marks.code),
29
+ "Shift-Ctrl-1": setBlockType(schema.nodes.heading, { level: 1 }),
30
+ "Shift-Ctrl-2": setBlockType(schema.nodes.heading, { level: 2 }),
31
+ "Shift-Ctrl-3": setBlockType(schema.nodes.heading, { level: 3 }),
32
+ "Shift-Ctrl-0": setBlockType(schema.nodes.paragraph),
33
+ "Shift-Ctrl-8": wrapInList(schema.nodes.bullet_list), "Shift-Ctrl-9": wrapInList(schema.nodes.ordered_list),
34
+ Enter: splitListItem(schema.nodes.list_item), "Mod-[": liftListItem(schema.nodes.list_item), "Mod-]": sinkListItem(schema.nodes.list_item),
35
+ "Shift-Enter": hardBreak, "Mod-Enter": hardBreak,
36
+ }),
37
+ keymap(baseKeymap),
38
+ ];
39
+ }
40
+ function useRichTextEditor(props) {
41
+ const surfaceRef = useRef(null);
42
+ const viewRef = useRef(null);
43
+ const settings = useRef(props);
44
+ useIsoLayoutEffect(() => { settings.current = props; }, [props]);
45
+ const [initial] = useState(() => props.value ?? props.defaultValue ?? "");
46
+ const [initialDoc] = useState(() => parseRichTextMarkdown(initial));
47
+ const [uncontrolledMarkdown, setUncontrolledMarkdown] = useState(initial);
48
+ const markdown = props.value ?? uncontrolledMarkdown;
49
+ const [editorView, setEditorView] = useState(null);
50
+ const [editorState, setEditorState] = useState(null);
51
+ const locked = !!(props.disabled || props.readOnly);
52
+ const insertAttachment = (attachment) => {
53
+ const view = viewRef.current;
54
+ if (!view || !view.editable || settings.current.disabled || settings.current.readOnly)
55
+ return;
56
+ const link = schema.marks.link.create({ href: attachment.url });
57
+ const paragraph = schema.nodes.paragraph.create(null, schema.text(attachment.name, [link]));
58
+ // Append a separate paragraph: asynchronous completion never replaces a later selection.
59
+ view.dispatch(view.state.tr.insert(view.state.doc.content.size, paragraph));
60
+ };
61
+ const removeAttachment = (attachment) => {
62
+ const view = viewRef.current;
63
+ if (!view || !view.editable || settings.current.disabled || settings.current.readOnly)
64
+ return;
65
+ let match;
66
+ view.state.doc.descendants((node, position) => {
67
+ if (node.isText && node.marks.some((mark) => mark.type === schema.marks.link && mark.attrs.href === attachment.url)) {
68
+ match = match?.to === position ? { from: match.from, to: position + node.nodeSize } : { from: position, to: position + node.nodeSize };
69
+ }
70
+ });
71
+ if (match)
72
+ view.dispatch(view.state.tr.delete(match.from, match.to));
73
+ };
74
+ const uploads = useRichTextUploads({ upload: props.onUploadAttachment, locked, maxFileSize: props.maxFileSize, insert: insertAttachment, remove: removeAttachment, onError: props.onUploadError, onPendingChange: props.onUploadPendingChange });
75
+ const resetUploads = uploads.reset;
76
+ useEffect(() => {
77
+ if (!surfaceRef.current)
78
+ return;
79
+ const view = new EditorView({ mount: surfaceRef.current }, {
80
+ state: EditorState.create({ doc: initialDoc, plugins: editorPlugins() }),
81
+ editable: () => !(settings.current.disabled || settings.current.readOnly),
82
+ dispatchTransaction(transaction) {
83
+ if (transaction.docChanged && (settings.current.disabled || settings.current.readOnly))
84
+ return;
85
+ const next = view.state.apply(transaction);
86
+ view.updateState(next);
87
+ setEditorState(next);
88
+ if (transaction.docChanged && !next.doc.eq(transaction.before)) {
89
+ const content = serializeRichTextMarkdown(next.doc);
90
+ if (settings.current.value === undefined)
91
+ setUncontrolledMarkdown(content);
92
+ settings.current.onChange?.(content);
93
+ }
94
+ },
95
+ handleClickOn(_view, _position, _node, _nodePosition, event) {
96
+ // Editing links selects text; it never navigates the hosting application.
97
+ return event.target instanceof Element && !!event.target.closest("a");
98
+ },
99
+ });
100
+ viewRef.current = view;
101
+ setEditorView(view);
102
+ setEditorState(view.state);
103
+ const form = surfaceRef.current.closest("form");
104
+ // Listen after React's delegated root handler, so a canceled onReset is respected.
105
+ const resetTarget = form?.getRootNode();
106
+ const reset = (event) => {
107
+ if (event.target !== form || event.defaultPrevented || view.isDestroyed)
108
+ return;
109
+ resetUploads();
110
+ if (settings.current.value !== undefined)
111
+ return;
112
+ const value = settings.current.defaultValue ?? "";
113
+ view.updateState(EditorState.create({ doc: parseRichTextMarkdown(value), plugins: editorPlugins() }));
114
+ setEditorState(view.state);
115
+ setUncontrolledMarkdown(value);
116
+ };
117
+ resetTarget?.addEventListener("reset", reset);
118
+ return () => {
119
+ resetTarget?.removeEventListener("reset", reset);
120
+ viewRef.current = null;
121
+ view.destroy();
122
+ };
123
+ }, [initialDoc, resetUploads]);
124
+ useEffect(() => {
125
+ const view = viewRef.current;
126
+ if (!view)
127
+ return;
128
+ view.setProps({ editable: () => !(props.disabled || props.readOnly) });
129
+ }, [props.disabled, props.readOnly]);
130
+ const currentDoc = editorState?.doc;
131
+ useEffect(() => {
132
+ const view = viewRef.current;
133
+ if (props.value === undefined || !view)
134
+ return;
135
+ const document = parseRichTextMarkdown(props.value);
136
+ if (!view.state.doc.eq(document)) {
137
+ resetUploads();
138
+ view.updateState(EditorState.create({ doc: document, plugins: editorPlugins() }));
139
+ setEditorState(view.state);
140
+ }
141
+ }, [props.value, currentDoc, resetUploads]);
142
+ return { surfaceRef, editorView, editorState, initialDoc, markdown, uploads };
143
+ }
144
+ /** The forwarded ref and Field id identify the same ProseMirror-owned textbox. */
145
+ const RichTextSurface = forwardRef(function RichTextSurface({ props, id, document }, ref) {
146
+ return _jsx("div", { ref: ref, id: id, className: "vk-rich-content vk-prose", role: "textbox", "aria-multiline": "true", "aria-label": props["aria-label"], "aria-labelledby": props["aria-labelledby"], "aria-describedby": props["aria-describedby"], "aria-invalid": props["aria-invalid"], "aria-required": props.required || undefined, "aria-disabled": props.disabled || undefined, "aria-readonly": props.readOnly || undefined, tabIndex: props.disabled ? -1 : 0, "data-placeholder": props.placeholder, "data-empty": document.textContent.length === 0 && document.childCount === 1 && document.firstChild?.type === schema.nodes.paragraph, onBlur: props.onBlur });
147
+ });
148
+ /** Native submission/validation and file selection stay separate from the editable DOM. */
149
+ function RichTextFormFields({ props, markdown, editorView, chooser, uploads }) {
150
+ const locked = !!(props.disabled || props.readOnly);
151
+ return _jsxs(_Fragment, { children: [_jsx("textarea", { className: "vk-sr-only", tabIndex: -1, "aria-hidden": "true", name: props.name, value: markdown, disabled: props.disabled, required: props.required && !props.readOnly, onChange: () => { }, onInvalid: (event) => { event.preventDefault(); editorView?.focus(); } }), props.onUploadAttachment ? _jsx("input", { ref: chooser, type: "file", className: "vk-sr-only", tabIndex: -1, "aria-hidden": "true", multiple: true, accept: props.accept, disabled: locked, onChange: (event) => { uploads.add(Array.from(event.currentTarget.files || [])); event.currentTarget.value = ""; } }) : null] });
152
+ }
153
+ /** Minimal composition follows the field in DOM order; the full editor keeps its toolbar first. */
154
+ function RichTextTools({ props, position, view, state, chooser }) {
155
+ const minimal = props.toolbar === "minimal";
156
+ if (props.readOnly || (position === "after") !== minimal)
157
+ return null;
158
+ return _jsx(RichTextToolbar, { variant: props.toolbar, view: view, state: state, disabled: Boolean(props.disabled), emojiOptions: props.emojiOptions, onAttach: props.onUploadAttachment ? () => chooser.current?.click() : undefined });
159
+ }
160
+ /** A ProseMirror editor with CommonMark persistence, formatting, Unicode emoji and attachment uploads. */
161
+ export const RichTextEditor = forwardRef(function RichTextEditor(props, forwardedRef) {
162
+ const uid = useUid("vk-rich");
163
+ const id = props.id || uid;
164
+ const chooser = useRef(null);
165
+ const { surfaceRef, editorView, editorState, initialDoc, markdown, uploads } = useRichTextEditor(props);
166
+ const locked = !!(props.disabled || props.readOnly);
167
+ const connectSurface = useCallback((node) => {
168
+ surfaceRef.current = node;
169
+ if (typeof forwardedRef === "function")
170
+ forwardedRef(node);
171
+ else if (forwardedRef)
172
+ forwardedRef.current = node;
173
+ }, [forwardedRef, surfaceRef]);
174
+ return _jsxs("div", { className: cx("vk-rich", props.className), "data-disabled": props.disabled || undefined, "data-readonly": props.readOnly || undefined, "data-invalid": props["aria-invalid"] || undefined, children: [_jsx(RichTextTools, { props: props, position: "before", view: editorView, state: editorState, chooser: chooser }), _jsx(RichTextSurface, { ref: connectSurface, props: props, id: id, document: editorState?.doc ?? initialDoc }), _jsx(RichTextTools, { props: props, position: "after", view: editorView, state: editorState, chooser: chooser }), _jsx(RichTextFormFields, { props: props, markdown: markdown, editorView: editorView, chooser: chooser, uploads: uploads }), _jsx(RichTextUploads, { uploads: uploads, locked: locked })] });
175
+ });
@@ -0,0 +1,15 @@
1
+ import type { EditorState } from "prosemirror-state";
2
+ import type { EditorView } from "prosemirror-view";
3
+ import type { RichTextEmoji } from "./RichTextEditor.js";
4
+ interface ToolbarProps {
5
+ view: EditorView | null;
6
+ state: EditorState | null;
7
+ disabled: boolean;
8
+ emojiOptions?: readonly RichTextEmoji[];
9
+ onAttach?: () => void;
10
+ }
11
+ /** Radix owns toolbar navigation and the minimal formatting disclosure. */
12
+ export declare function RichTextToolbar({ variant, ...props }: ToolbarProps & {
13
+ variant?: "full" | "minimal";
14
+ }): import("react/jsx-runtime").JSX.Element;
15
+ export {};
@@ -0,0 +1,142 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useState } from "react";
4
+ import { Collapsible, Popover, Toolbar } from "radix-ui";
5
+ import { lift, setBlockType, toggleMark, wrapIn } from "prosemirror-commands";
6
+ import { undo, redo } from "prosemirror-history";
7
+ import { schema } from "prosemirror-markdown";
8
+ import { liftListItem, wrapInList } from "prosemirror-schema-list";
9
+ import { Input } from "../Input/Input.js";
10
+ import { Button } from "../Button/Button.js";
11
+ import { useLocale } from "../../localization.js";
12
+ import { isRichTextUrl } from "../../lib/rich-text.js";
13
+ function activeNode(state, name, level) {
14
+ if (!state)
15
+ return false;
16
+ for (let depth = state.selection.$from.depth; depth > 0; depth--) {
17
+ const node = state.selection.$from.node(depth);
18
+ if (node.type.name === name && (level === undefined || node.attrs.level === level))
19
+ return true;
20
+ }
21
+ return false;
22
+ }
23
+ function activeMark(state, name) {
24
+ if (!state)
25
+ return false;
26
+ const mark = schema.marks[name];
27
+ const { from, to, empty, $from } = state.selection;
28
+ return empty ? !!mark.isInSet(state.storedMarks || $from.marks()) : state.doc.rangeHasMark(from, to, mark);
29
+ }
30
+ function CommandButton({ label, children, command, view, state, disabled, pressed }) {
31
+ return _jsx(Toolbar.Button, { type: "button", className: "vk-rich-tool", "aria-label": label, title: label, "aria-pressed": pressed, disabled: disabled || !view || !state || !command(state), onMouseDown: (event) => { event.preventDefault(); }, onClick: () => {
32
+ if (!view || !view.editable || disabled)
33
+ return;
34
+ command(view.state, view.dispatch, view);
35
+ view.focus();
36
+ }, children: _jsx("span", { "aria-hidden": "true", children: children }) });
37
+ }
38
+ function LinkTool({ view, disabled, state }) {
39
+ const { messages } = useLocale();
40
+ const copy = messages.richText;
41
+ const [open, setOpen] = useState(false);
42
+ const [url, setUrl] = useState("");
43
+ const [text, setText] = useState("");
44
+ const [invalid, setInvalid] = useState(false);
45
+ const openPanel = (next) => {
46
+ if (next && view) {
47
+ const { from, to, $from } = view.state.selection;
48
+ const link = schema.marks.link.isInSet(view.state.storedMarks || $from.marks());
49
+ setUrl(typeof link?.attrs.href === "string" ? link.attrs.href : "");
50
+ setText(view.state.doc.textBetween(from, to, " "));
51
+ setInvalid(false);
52
+ }
53
+ setOpen(next);
54
+ };
55
+ const apply = () => {
56
+ if (!view || !view.editable || disabled)
57
+ return;
58
+ if (!isRichTextUrl(url)) {
59
+ setInvalid(true);
60
+ return;
61
+ }
62
+ const { from, to } = view.state.selection;
63
+ const label = text || url;
64
+ const transaction = view.state.tr.insertText(label, from, to).addMark(from, from + label.length, schema.marks.link.create({ href: url }));
65
+ view.dispatch(transaction);
66
+ setOpen(false);
67
+ view.focus();
68
+ };
69
+ const remove = () => {
70
+ if (!view || !view.editable || disabled)
71
+ return;
72
+ const { from, to, empty, $from } = view.state.selection;
73
+ let start = from, end = to;
74
+ if (empty) {
75
+ const link = schema.marks.link.isInSet($from.marks());
76
+ if (link)
77
+ $from.parent.forEach((node, offset) => {
78
+ if (link.isInSet(node.marks)) {
79
+ const nodeStart = $from.start() + offset;
80
+ if (nodeStart <= from && nodeStart + node.nodeSize >= from) {
81
+ start = nodeStart;
82
+ end = nodeStart + node.nodeSize;
83
+ }
84
+ }
85
+ });
86
+ }
87
+ view.dispatch(view.state.tr.removeMark(start, end, schema.marks.link).removeStoredMark(schema.marks.link));
88
+ setOpen(false);
89
+ view.focus();
90
+ };
91
+ return _jsxs(Popover.Root, { open: open && !disabled, onOpenChange: openPanel, children: [_jsx(Toolbar.Button, { asChild: true, disabled: disabled || !view, children: _jsx(Popover.Trigger, { type: "button", className: "vk-rich-tool", "aria-label": copy.addLink, title: copy.addLink, "aria-pressed": activeMark(state, "link"), onMouseDown: (event) => { event.preventDefault(); }, children: _jsx("span", { "aria-hidden": "true", children: "\u2197" }) }) }), _jsx(Popover.Portal, { children: _jsxs(Popover.Content, { className: "vk-popover vk-rich-panel", sideOffset: 4, collisionPadding: 8, "aria-label": copy.addLink, onCloseAutoFocus: (event) => { event.preventDefault(); view?.focus(); }, children: [_jsxs("label", { className: "vk-rich-panel-field", children: [_jsx("span", { children: copy.linkUrl }), _jsx(Input, { type: "url", value: url, onChange: (event) => { setUrl(event.target.value); setInvalid(false); }, "aria-invalid": invalid, onKeyDown: (event) => { if (event.key === "Enter") {
92
+ event.preventDefault();
93
+ apply();
94
+ } } })] }), _jsxs("label", { className: "vk-rich-panel-field", children: [_jsx("span", { children: copy.linkText }), _jsx(Input, { value: text, onChange: (event) => { setText(event.target.value); }, onKeyDown: (event) => { if (event.key === "Enter") {
95
+ event.preventDefault();
96
+ apply();
97
+ } } })] }), invalid ? _jsx("span", { className: "vk-field-error", role: "alert", children: copy.invalidUrl }) : null, _jsxs("div", { className: "vk-rich-panel-actions", children: [_jsx(Button, { type: "button", size: "sm", onClick: apply, children: copy.applyLink }), activeMark(state, "link") ? _jsx(Button, { type: "button", size: "sm", variant: "ghost", onClick: remove, children: copy.removeLink }) : null, _jsx(Popover.Close, { asChild: true, children: _jsx(Button, { type: "button", size: "sm", variant: "ghost", children: copy.cancel }) })] })] }) })] });
98
+ }
99
+ const emojiValues = ["😀", "🙂", "❤️", "👍", "👎", "🎉", "✅", "⚠️", "💡", "🚀", "👀", "🙏"];
100
+ function EmojiTool({ view, disabled, emojiOptions }) {
101
+ const { locale, messages } = useLocale();
102
+ const copy = messages.richText;
103
+ const [open, setOpen] = useState(false);
104
+ const [query, setQuery] = useState("");
105
+ const choices = emojiOptions || emojiValues.map((value) => ({ value, label: copy.emojiName(value) }));
106
+ const filtered = choices.filter((option) => option.value.includes(query) || option.label.toLocaleLowerCase(locale).includes(query.toLocaleLowerCase(locale)));
107
+ return _jsxs(Popover.Root, { open: open && !disabled, onOpenChange: (next) => { setQuery(""); setOpen(next); }, children: [_jsx(Toolbar.Button, { asChild: true, disabled: disabled || !view, children: _jsx(Popover.Trigger, { type: "button", className: "vk-rich-tool", "aria-label": copy.emoji, title: copy.emoji, onMouseDown: (event) => { event.preventDefault(); }, children: _jsx("span", { "aria-hidden": "true", children: "\u263A" }) }) }), _jsx(Popover.Portal, { children: _jsxs(Popover.Content, { className: "vk-popover vk-rich-panel", sideOffset: 4, collisionPadding: 8, "aria-label": copy.emoji, onCloseAutoFocus: (event) => { event.preventDefault(); view?.focus(); }, children: [_jsx(Input, { "aria-label": copy.emojiSearch, placeholder: copy.emojiSearch, value: query, onChange: (event) => { setQuery(event.target.value); } }), _jsx("div", { className: "vk-rich-emoji", role: "group", "aria-label": copy.emoji, children: filtered.map((option) => _jsx("button", { type: "button", className: "vk-rich-tool", "aria-label": option.label, title: option.label, onClick: () => {
108
+ if (!view || !view.editable || disabled)
109
+ return;
110
+ view.dispatch(view.state.tr.insertText(option.value).scrollIntoView());
111
+ setOpen(false);
112
+ view.focus();
113
+ }, children: _jsx("span", { "aria-hidden": "true", children: option.value }) }, option.value + option.label)) }), !filtered.length ? _jsx("p", { role: "status", children: copy.noEmoji }) : null] }) })] });
114
+ }
115
+ function AttachTool({ view, disabled, onAttach }) {
116
+ const { messages } = useLocale();
117
+ const label = messages.richText.attachFiles;
118
+ if (!onAttach)
119
+ return null;
120
+ return _jsx(Toolbar.Button, { type: "button", className: "vk-rich-tool", disabled: disabled || !view, "aria-label": label, title: label, onMouseDown: (event) => { event.preventDefault(); }, onClick: onAttach, children: _jsx("span", { "aria-hidden": "true", children: "\uFF0B" }) });
121
+ }
122
+ function MinimalToolbar({ view, state, disabled, emojiOptions, onAttach }) {
123
+ const { messages } = useLocale();
124
+ const copy = messages.richText;
125
+ const shared = { view, state, disabled };
126
+ const bullet = activeNode(state, "bullet_list");
127
+ const formattingLabel = "Aa: " + copy.formatting;
128
+ return _jsxs(Collapsible.Root, { className: "vk-rich-minimal", disabled: disabled, children: [_jsxs(Toolbar.Root, { className: "vk-rich-toolbar vk-rich-minimal-actions", "aria-label": copy.toolbar, children: [_jsx(Collapsible.Trigger, { asChild: true, children: _jsx(Toolbar.Button, { type: "button", className: "vk-rich-tool", "aria-label": formattingLabel, title: formattingLabel, disabled: disabled || !view, onMouseDown: (event) => { event.preventDefault(); }, children: _jsx("span", { "aria-hidden": "true", children: "Aa" }) }) }), _jsx(EmojiTool, { view: view, disabled: disabled, emojiOptions: emojiOptions }), _jsx(AttachTool, { view: view, disabled: disabled, onAttach: onAttach })] }), _jsx(Collapsible.Content, { children: _jsxs(Toolbar.Root, { className: "vk-rich-toolbar vk-rich-minimal-formatting", "aria-label": copy.formatting, children: [_jsx(CommandButton, { ...shared, label: copy.bold, command: toggleMark(schema.marks.strong), pressed: activeMark(state, "strong"), children: _jsx("strong", { children: "B" }) }), _jsx(CommandButton, { ...shared, label: copy.italic, command: toggleMark(schema.marks.em), pressed: activeMark(state, "em"), children: _jsx("em", { children: "I" }) }), _jsx(LinkTool, { ...shared }), _jsx(CommandButton, { ...shared, label: copy.bulletList, command: bullet ? liftListItem(schema.nodes.list_item) : wrapInList(schema.nodes.bullet_list), pressed: bullet, children: "\u2022\u2261" })] }) })] });
129
+ }
130
+ function FullToolbar({ view, state, disabled, emojiOptions, onAttach }) {
131
+ const { messages } = useLocale();
132
+ const copy = messages.richText;
133
+ const shared = { view, state, disabled };
134
+ const bullet = activeNode(state, "bullet_list");
135
+ const ordered = activeNode(state, "ordered_list");
136
+ const quote = activeNode(state, "blockquote");
137
+ return _jsxs(Toolbar.Root, { className: "vk-rich-toolbar", "aria-label": copy.toolbar, children: [_jsx(CommandButton, { ...shared, label: copy.paragraph, command: setBlockType(schema.nodes.paragraph), pressed: activeNode(state, "paragraph"), children: "\u00B6" }), [1, 2, 3].map((level) => _jsxs(CommandButton, { ...shared, label: "H" + String(level) + ": " + copy.heading(level), command: setBlockType(schema.nodes.heading, { level }), pressed: activeNode(state, "heading", level), children: ["H", level] }, level)), _jsx(Toolbar.Separator, { className: "vk-rich-separator" }), _jsx(CommandButton, { ...shared, label: copy.bold, command: toggleMark(schema.marks.strong), pressed: activeMark(state, "strong"), children: _jsx("strong", { children: "B" }) }), _jsx(CommandButton, { ...shared, label: copy.italic, command: toggleMark(schema.marks.em), pressed: activeMark(state, "em"), children: _jsx("em", { children: "I" }) }), _jsx(CommandButton, { ...shared, label: copy.inlineCode, command: toggleMark(schema.marks.code), pressed: activeMark(state, "code"), children: "\u3008/\u3009" }), _jsx(CommandButton, { ...shared, label: copy.codeBlock, command: setBlockType(schema.nodes.code_block), pressed: activeNode(state, "code_block"), children: "{ }" }), _jsx(Toolbar.Separator, { className: "vk-rich-separator" }), _jsx(CommandButton, { ...shared, label: copy.bulletList, command: bullet ? liftListItem(schema.nodes.list_item) : wrapInList(schema.nodes.bullet_list), pressed: bullet, children: "\u2022\u2261" }), _jsx(CommandButton, { ...shared, label: copy.orderedList, command: ordered ? liftListItem(schema.nodes.list_item) : wrapInList(schema.nodes.ordered_list), pressed: ordered, children: _jsx("svg", { "aria-hidden": "true", width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", children: _jsx("path", { d: "M10 6h11M10 12h11M10 18h11M4 2v6M3 3l1-1M3 8h2M3 12h2l-2 4h2M3 20h2M3 19h2v3H3" }) }) }), _jsx(CommandButton, { ...shared, label: copy.quote, command: quote ? lift : wrapIn(schema.nodes.blockquote), pressed: quote, children: "\u275E" }), _jsx(LinkTool, { ...shared }), _jsx(EmojiTool, { view: view, disabled: disabled, emojiOptions: emojiOptions }), _jsx(AttachTool, { view: view, disabled: disabled, onAttach: onAttach }), _jsx(Toolbar.Separator, { className: "vk-rich-separator" }), _jsx(CommandButton, { ...shared, label: copy.undo, command: undo, children: "\u21B6" }), _jsx(CommandButton, { ...shared, label: copy.redo, command: redo, children: "\u21B7" })] });
138
+ }
139
+ /** Radix owns toolbar navigation and the minimal formatting disclosure. */
140
+ export function RichTextToolbar({ variant, ...props }) {
141
+ return variant === "minimal" ? _jsx(MinimalToolbar, { ...props }) : _jsx(FullToolbar, { ...props });
142
+ }
@@ -0,0 +1,41 @@
1
+ import type { RichTextAttachment, RichTextUpload } from "./RichTextEditor.js";
2
+ type UploadIssue = {
3
+ kind: "too-large";
4
+ limit: number;
5
+ } | {
6
+ kind: "failed";
7
+ };
8
+ interface UploadEntry {
9
+ id: number;
10
+ file: File;
11
+ state: "pending" | "error" | "complete";
12
+ issue?: UploadIssue;
13
+ attachment?: RichTextAttachment;
14
+ }
15
+ interface UploadOptions {
16
+ upload?: RichTextUpload;
17
+ locked: boolean;
18
+ maxFileSize?: number;
19
+ insert: (attachment: RichTextAttachment) => void;
20
+ remove: (attachment: RichTextAttachment) => void;
21
+ onError?: (error: Error, file: File) => void;
22
+ onPendingChange?: (pending: boolean) => void;
23
+ }
24
+ /** Even a typed app callback is an external runtime boundary. */
25
+ export declare function validateAttachment(value: unknown): RichTextAttachment;
26
+ /** Tracks upload attempts independently of editor transactions, including canceled/stale promises. */
27
+ export declare function useRichTextUploads(options: UploadOptions): {
28
+ entries: UploadEntry[];
29
+ announcement: string;
30
+ add: (files: File[]) => void;
31
+ retry: (entry: UploadEntry) => void;
32
+ cancel: (id: number) => void;
33
+ remove: (entry: UploadEntry) => void;
34
+ reset: () => void;
35
+ pending: boolean;
36
+ };
37
+ export declare function RichTextUploads({ uploads, locked }: {
38
+ uploads: ReturnType<typeof useRichTextUploads>;
39
+ locked: boolean;
40
+ }): import("react/jsx-runtime").JSX.Element;
41
+ export {};
@@ -0,0 +1,124 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { useCallback, useEffect, useRef, useState } from "react";
4
+ import { hasRichTextControlCharacters, isRichTextUrl } from "../../lib/rich-text.js";
5
+ import { formatBytes } from "../../lib/format.js";
6
+ import { useLocale } from "../../localization.js";
7
+ import { useIsoLayoutEffect } from "../../internal/useIsoLayoutEffect.js";
8
+ /** Even a typed app callback is an external runtime boundary. */
9
+ export function validateAttachment(value) {
10
+ if (typeof value !== "object" || value === null || !("name" in value) || !("url" in value) ||
11
+ typeof value.name !== "string" || !value.name.trim() || hasRichTextControlCharacters(value.name) || !isRichTextUrl(value.url) || /^(mailto|tel):/i.test(value.url)) {
12
+ throw new TypeError("An attachment upload must return a non-empty name and a safe HTTP(S) or relative URL.");
13
+ }
14
+ return { name: value.name, url: value.url };
15
+ }
16
+ /** Tracks upload attempts independently of editor transactions, including canceled/stale promises. */
17
+ export function useRichTextUploads(options) {
18
+ const { messages } = useLocale();
19
+ const [entries, setEntries] = useState([]);
20
+ const [announcement, setAnnouncement] = useState(null);
21
+ const settings = useRef(options);
22
+ useIsoLayoutEffect(() => { settings.current = options; }, [options]);
23
+ const nextId = useRef(0);
24
+ const attempts = useRef(new Map());
25
+ const alive = useRef(true);
26
+ const reportPending = () => { settings.current.onPendingChange?.(attempts.current.size > 0); };
27
+ useEffect(() => {
28
+ alive.current = true;
29
+ const controllers = attempts.current;
30
+ return () => { alive.current = false; controllers.forEach((controller) => { controller.abort(); }); controllers.clear(); };
31
+ }, []);
32
+ useEffect(() => {
33
+ if (!options.locked)
34
+ return;
35
+ attempts.current.forEach((controller) => { controller.abort(); });
36
+ attempts.current.clear();
37
+ }, [options.locked]);
38
+ const reset = useCallback(() => {
39
+ attempts.current.forEach((controller) => { controller.abort(); });
40
+ attempts.current.clear();
41
+ setEntries([]);
42
+ setAnnouncement(null);
43
+ }, []);
44
+ const isCurrentAttempt = (id, controller) => alive.current && !controller.signal.aborted && !settings.current.locked && attempts.current.get(id) === controller;
45
+ const start = async (id, file) => {
46
+ if (settings.current.locked || !settings.current.upload)
47
+ return;
48
+ const controller = new AbortController();
49
+ attempts.current.get(id)?.abort();
50
+ attempts.current.set(id, controller);
51
+ controller.signal.addEventListener("abort", () => {
52
+ if (attempts.current.get(id) === controller) {
53
+ attempts.current.delete(id);
54
+ reportPending();
55
+ }
56
+ if (alive.current)
57
+ setEntries((current) => current.filter((entry) => entry.id !== id));
58
+ }, { once: true });
59
+ reportPending();
60
+ setEntries((current) => {
61
+ const entry = { id, file, state: "pending" };
62
+ return current.some((item) => item.id === id) ? current.map((item) => item.id === id ? entry : item) : current.concat(entry);
63
+ });
64
+ try {
65
+ const limit = settings.current.maxFileSize;
66
+ if (limit !== undefined && file.size > limit) {
67
+ setEntries((current) => current.map((entry) => entry.id === id ? { ...entry, state: "error", issue: { kind: "too-large", limit } } : entry));
68
+ setAnnouncement({ kind: "too-large", limit });
69
+ settings.current.onError?.(new RangeError("Attachment exceeds the configured file size limit."), file);
70
+ return;
71
+ }
72
+ const result = await settings.current.upload(file, { signal: controller.signal });
73
+ if (!isCurrentAttempt(id, controller))
74
+ return;
75
+ const attachment = validateAttachment(result);
76
+ settings.current.insert(attachment);
77
+ setEntries((current) => current.map((entry) => entry.id === id ? { ...entry, state: "complete", attachment } : entry));
78
+ setAnnouncement({ kind: "uploaded", name: attachment.name });
79
+ }
80
+ catch (cause) {
81
+ if (!isCurrentAttempt(id, controller))
82
+ return;
83
+ const error = cause instanceof Error ? cause : new Error("Attachment upload failed.");
84
+ setEntries((current) => current.map((entry) => entry.id === id ? { ...entry, state: "error", issue: { kind: "failed" } } : entry));
85
+ setAnnouncement({ kind: "failed", name: file.name });
86
+ settings.current.onError?.(error, file);
87
+ }
88
+ finally {
89
+ if (attempts.current.get(id) === controller) {
90
+ attempts.current.delete(id);
91
+ reportPending();
92
+ }
93
+ }
94
+ };
95
+ const cancel = (id) => {
96
+ attempts.current.get(id)?.abort();
97
+ attempts.current.delete(id);
98
+ setEntries((current) => current.filter((entry) => entry.id !== id));
99
+ };
100
+ const remove = (entry) => {
101
+ if (settings.current.locked)
102
+ return;
103
+ if (entry.attachment)
104
+ settings.current.remove(entry.attachment);
105
+ cancel(entry.id);
106
+ };
107
+ return {
108
+ entries, announcement: announcement?.kind === "uploaded" ? messages.richText.attachmentUploaded(announcement.name) : announcement?.kind === "failed" ? messages.richText.uploadFailed(announcement.name) : announcement?.kind === "too-large" ? messages.richText.maxFileSize(formatBytes(announcement.limit)) : "",
109
+ add: (files) => { if (!settings.current.locked)
110
+ files.forEach((file) => { nextId.current += 1; void start(nextId.current, file); }); },
111
+ retry: (entry) => { void start(entry.id, entry.file); },
112
+ cancel, remove,
113
+ reset,
114
+ pending: entries.some((entry) => entry.state === "pending"),
115
+ };
116
+ }
117
+ export function RichTextUploads({ uploads, locked }) {
118
+ const { messages } = useLocale();
119
+ const copy = messages.richText;
120
+ return _jsxs(_Fragment, { children: [_jsx("span", { className: "vk-sr-only", role: "status", "aria-live": "polite", children: uploads.announcement }), uploads.entries.length ? _jsx("ul", { className: "vk-rich-uploads", children: uploads.entries.map((entry) => _jsxs("li", { className: "vk-rich-upload", "data-state": entry.state, children: [_jsx("span", { children: entry.file.name }), _jsx("span", { className: entry.state === "error" ? "vk-field-error" : "vk-rich-upload-status", children: entry.state === "pending" ? copy.uploading(entry.file.name) : entry.state === "error" ? (entry.issue?.kind === "too-large" ? copy.maxFileSize(formatBytes(entry.issue.limit)) : copy.uploadFailed(entry.file.name)) : copy.attachmentUploaded(entry.attachment?.name || entry.file.name) }), entry.state === "error" ? _jsx("button", { type: "button", className: "vk-link", disabled: locked, onClick: () => { uploads.retry(entry); }, "aria-label": copy.retryUpload(entry.file.name), children: copy.retryUpload(entry.file.name) }) : null, _jsx("button", { type: "button", className: "vk-link", disabled: locked, onClick: () => { if (entry.state === "pending")
121
+ uploads.cancel(entry.id);
122
+ else
123
+ uploads.remove(entry); }, "aria-label": entry.state === "pending" ? copy.cancelUpload(entry.file.name) : copy.removeAttachment(entry.file.name), children: entry.state === "pending" ? copy.cancel : messages.remove(entry.file.name) })] }, entry.id)) }) : null] });
124
+ }
@@ -1,11 +1,13 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useLocale } from "../../localization.js";
3
4
  import { forwardRef, useCallback, useRef, useState } from "react";
4
5
  import { Icon } from "../Icon/Icon.js";
5
6
  import { cx } from "../../lib/cx.js";
6
7
  import { omit } from "../../lib/omit.js";
7
8
  /** Search field with icon and clear button; no suggestions. The ref is the <input>. */
8
9
  export const SearchInput = forwardRef(function SearchInput(props, ref) {
10
+ const { messages } = useLocale();
9
11
  const controlled = props.value !== undefined;
10
12
  const [text, setText] = useState(props.defaultValue || "");
11
13
  const value = controlled ? props.value : text;
@@ -24,14 +26,14 @@ export const SearchInput = forwardRef(function SearchInput(props, ref) {
24
26
  setText(v);
25
27
  props.onChange?.(v, e);
26
28
  };
27
- return (_jsxs("span", { className: cx("vk-search", props.className), children: [_jsx(Icon, { name: "search", size: 16, className: "vk-search-icon" }), _jsx("input", { ref: setRef, type: "search", className: "vk-input vk-search-input", autoComplete: "off", ...rest, value: value, onChange: (e) => set(e.target.value, e), onKeyDown: (e) => {
29
+ return (_jsxs("span", { className: cx("vk-search", props.className), children: [_jsx(Icon, { name: "search", size: 16, className: "vk-search-icon" }), _jsx("input", { ref: setRef, type: "search", className: "vk-input vk-search-input", autoComplete: "off", ...rest, value: value, onChange: (e) => { set(e.target.value, e); }, onKeyDown: (e) => {
28
30
  if (e.key === "Escape" && value) {
29
31
  e.preventDefault();
30
32
  set("");
31
33
  props.onClear?.();
32
34
  }
33
35
  props.onKeyDown?.(e);
34
- } }), value && !props.disabled ? (_jsx("button", { type: "button", className: "vk-field-clear", "aria-label": props.clearLabel || "Clear search", onClick: () => {
36
+ } }), value && !props.disabled ? (_jsx("button", { type: "button", className: "vk-field-clear", "aria-label": props.clearLabel || messages.clearSearch, onClick: () => {
35
37
  set("");
36
38
  props.onClear?.();
37
39
  inputRef.current?.focus();
@@ -1,9 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { SquareGlyph } from "../SquareGlyph/SquareGlyph.js";
3
- import { para } from "../../lib/text.js";
4
3
  /** Section header: square glyph, uppercase label, optional lead. */
5
4
  export function SectionHeader({ id, heading, lead, glyph, as }) {
6
5
  const Tag = as || "h2";
7
- const Lead = para(lead);
8
- return (_jsxs("header", { className: "vk-section-header", children: [_jsxs(Tag, { id: id, className: "vk-section-heading", children: [_jsx(SquareGlyph, { children: glyph == null ? "+" : glyph }), _jsx("span", { children: heading })] }), lead ? _jsx(Lead, { className: "vk-section-lead", children: lead }) : null] }));
6
+ return (_jsxs("header", { className: "vk-section-header", children: [_jsxs(Tag, { id: id, className: "vk-section-heading", children: [_jsx(SquareGlyph, { children: glyph == null ? "+" : glyph }), _jsx("span", { children: heading })] }), lead ? _jsx("p", { className: "vk-section-lead", children: lead }) : null] }));
9
7
  }