@vitral/editor 0.2.5 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/find.js ADDED
@@ -0,0 +1,319 @@
1
+ import { iconView } from "./render/toolbar.js";
2
+ import { editorInlineText, editorNodeAt, en, findInEditor, formatMessage, replaceEditorMatches } from "@vitral/core";
3
+ import { h, mergeAttrs } from "@vitral/dom";
4
+ //#region src/find.ts
5
+ var painted = /* @__PURE__ */ new Map();
6
+ function repaint() {
7
+ const registry = typeof CSS !== "undefined" ? CSS.highlights : void 0;
8
+ const Highlight = globalThis.Highlight;
9
+ if (!registry || !Highlight) return;
10
+ const all = [];
11
+ const current = [];
12
+ for (const entry of painted.values()) {
13
+ all.push(...entry.all);
14
+ if (entry.current) current.push(entry.current);
15
+ }
16
+ if (all.length) registry.set("vt-find", new Highlight(...all));
17
+ else registry.delete("vt-find");
18
+ if (current.length) registry.set("vt-find-current", new Highlight(...current));
19
+ else registry.delete("vt-find-current");
20
+ }
21
+ function createFindBar(options) {
22
+ const key = {};
23
+ const locale = () => options.locale?.() ?? en;
24
+ const editable = () => options.editable?.() ?? true;
25
+ const id = options.id ?? "vt-find";
26
+ let isOpen = false;
27
+ let replacing = false;
28
+ let query = "";
29
+ let replacement = "";
30
+ const flags = {
31
+ caseSensitive: false,
32
+ wholeWord: false,
33
+ regex: false
34
+ };
35
+ let found = [];
36
+ let current = 0;
37
+ let input = null;
38
+ let wantFocus = false;
39
+ let scrollToCurrent = false;
40
+ function search() {
41
+ found = isOpen ? findInEditor(options.editor.state.doc, query, flags) : [];
42
+ if (current >= found.length) current = Math.max(0, found.length - 1);
43
+ }
44
+ /** The first match at or after the caret, so opening the bar starts where the reader is. */
45
+ function nearestToCaret() {
46
+ const head = options.editor.state.selection.head;
47
+ const index = found.findIndex((m) => {
48
+ const order = m.path.join(".").localeCompare(head.path.join("."), void 0, { numeric: true });
49
+ return order > 0 || order === 0 && m.to > head.offset;
50
+ });
51
+ current = index === -1 ? 0 : index;
52
+ }
53
+ function rangeOf(match) {
54
+ const view = options.view();
55
+ const start = view?.domFromPos({
56
+ path: match.path,
57
+ offset: match.from
58
+ });
59
+ const end = view?.domFromPos({
60
+ path: match.path,
61
+ offset: match.to
62
+ });
63
+ if (!start || !end || typeof document === "undefined") return null;
64
+ try {
65
+ const range = document.createRange();
66
+ range.setStart(start.node, start.offset);
67
+ range.setEnd(end.node, end.offset);
68
+ return range;
69
+ } catch {
70
+ return null;
71
+ }
72
+ }
73
+ let queued = false;
74
+ function paint() {
75
+ if (queued) return;
76
+ queued = true;
77
+ queueMicrotask(() => {
78
+ queued = false;
79
+ if (wantFocus && input) {
80
+ wantFocus = false;
81
+ input.focus();
82
+ input.select();
83
+ }
84
+ if (!isOpen || !found.length) {
85
+ painted.delete(key);
86
+ repaint();
87
+ return;
88
+ }
89
+ const all = found.map(rangeOf).filter((r) => !!r);
90
+ const now = found[current] ? rangeOf(found[current]) : null;
91
+ painted.set(key, {
92
+ all,
93
+ current: now
94
+ });
95
+ repaint();
96
+ if (scrollToCurrent && now) {
97
+ scrollToCurrent = false;
98
+ (now.startContainer.nodeType === 1 ? now.startContainer : now.startContainer.parentElement)?.scrollIntoView?.({
99
+ block: "nearest",
100
+ inline: "nearest"
101
+ });
102
+ }
103
+ });
104
+ }
105
+ function changed() {
106
+ search();
107
+ options.render();
108
+ paint();
109
+ }
110
+ function go(step) {
111
+ if (!found.length) return;
112
+ current = (current + step + found.length) % found.length;
113
+ scrollToCurrent = true;
114
+ options.render();
115
+ paint();
116
+ }
117
+ /** Leaves the current match selected in the document, where Escape takes the reader. */
118
+ function selectCurrent() {
119
+ const match = found[current];
120
+ if (!match) return;
121
+ options.editor.setSelection({
122
+ anchor: {
123
+ path: match.path,
124
+ offset: match.from
125
+ },
126
+ head: {
127
+ path: match.path,
128
+ offset: match.to
129
+ }
130
+ });
131
+ }
132
+ function replaceOne() {
133
+ const match = found[current];
134
+ if (!match || !editable()) return;
135
+ options.editor.apply(replaceEditorMatches(options.editor.state, [match], replacement, flags), {
136
+ origin: "user",
137
+ history: "other"
138
+ });
139
+ search();
140
+ scrollToCurrent = true;
141
+ options.render();
142
+ paint();
143
+ }
144
+ function replaceAll() {
145
+ if (!found.length || !editable()) return;
146
+ options.editor.apply(replaceEditorMatches(options.editor.state, found, replacement, flags), {
147
+ origin: "user",
148
+ history: "other"
149
+ });
150
+ search();
151
+ options.render();
152
+ paint();
153
+ }
154
+ const close = ({ focusEditor = true } = {}) => {
155
+ if (!isOpen) return;
156
+ if (focusEditor) selectCurrent();
157
+ isOpen = false;
158
+ found = [];
159
+ painted.delete(key);
160
+ repaint();
161
+ options.render();
162
+ if (focusEditor) options.view()?.focus();
163
+ };
164
+ const toggle = (name, label, glyph) => h("button", mergeAttrs({
165
+ key: name,
166
+ type: "button"
167
+ }, options.part("findToggle", { active: flags[name] }), {
168
+ "aria-label": label,
169
+ "aria-pressed": flags[name] ? "true" : "false",
170
+ title: label,
171
+ onClick: () => {
172
+ flags[name] = !flags[name];
173
+ changed();
174
+ }
175
+ }), glyph);
176
+ const iconButton = (name, label, icon, onClick, disabled = false) => h("button", mergeAttrs({
177
+ key: name,
178
+ type: "button"
179
+ }, options.part("button", { disabled }), {
180
+ "aria-label": label,
181
+ title: label,
182
+ disabled,
183
+ onClick
184
+ }), iconView(icon, options.part("buttonIcon")));
185
+ function view() {
186
+ if (!isOpen) return null;
187
+ const words = locale().editor;
188
+ const canReplace = editable();
189
+ const count = !query ? "" : found.length ? formatMessage(words.matchCount, {
190
+ current: current + 1,
191
+ total: found.length
192
+ }) : words.noMatches;
193
+ const keydown = (event) => {
194
+ if (event.key === "Escape") {
195
+ event.preventDefault();
196
+ close();
197
+ }
198
+ };
199
+ return h("div", mergeAttrs({
200
+ key: "find",
201
+ id,
202
+ role: "search"
203
+ }, options.part("find"), {
204
+ "aria-label": words.find,
205
+ onKeydown: keydown
206
+ }), h("div", mergeAttrs({ key: "row" }, options.part("findRow")), canReplace ? h("button", mergeAttrs({
207
+ key: "expand",
208
+ type: "button"
209
+ }, options.part("button"), {
210
+ "aria-label": words.toggleReplace,
211
+ title: words.toggleReplace,
212
+ "aria-expanded": replacing ? "true" : "false",
213
+ "aria-controls": `${id}-replace`,
214
+ onClick: () => {
215
+ replacing = !replacing;
216
+ options.render();
217
+ }
218
+ }), iconView(replacing ? "chevronDown" : "chevronRight", options.part("buttonIcon"))) : null, h("span", {
219
+ key: "query",
220
+ class: "vt-field vt-field-sm vt-editor-find-field"
221
+ }, h("input", {
222
+ type: "text",
223
+ class: "vt-field-input",
224
+ value: query,
225
+ placeholder: words.find,
226
+ "aria-label": words.find,
227
+ "aria-describedby": `${id}-count`,
228
+ spellcheck: "false",
229
+ ref: (el) => input = el,
230
+ onInput: (event) => {
231
+ query = event.target.value;
232
+ search();
233
+ nearestToCaret();
234
+ scrollToCurrent = true;
235
+ options.render();
236
+ paint();
237
+ },
238
+ onKeydown: (event) => {
239
+ if (event.key !== "Enter") return;
240
+ event.preventDefault();
241
+ go(event.shiftKey ? -1 : 1);
242
+ }
243
+ })), toggle("caseSensitive", words.matchCase, "Aa"), toggle("wholeWord", words.wholeWord, "ab"), toggle("regex", words.useRegex, ".*"), h("span", mergeAttrs({
244
+ key: "count",
245
+ id: `${id}-count`,
246
+ "aria-live": "polite"
247
+ }, options.part("findCount", { empty: !!query && !found.length })), count), iconButton("prev", words.previousMatch, "chevronUp", () => go(-1), !found.length), iconButton("next", words.nextMatch, "chevronDown", () => go(1), !found.length), iconButton("close", words.closeFind, "close", () => close())), canReplace && replacing ? h("div", mergeAttrs({
248
+ key: "replace",
249
+ id: `${id}-replace`
250
+ }, options.part("findRow", { replace: true })), h("span", {
251
+ key: "with",
252
+ class: "vt-field vt-field-sm vt-editor-find-field"
253
+ }, h("input", {
254
+ type: "text",
255
+ class: "vt-field-input",
256
+ value: replacement,
257
+ placeholder: words.replaceWith,
258
+ "aria-label": words.replaceWith,
259
+ spellcheck: "false",
260
+ onInput: (event) => replacement = event.target.value,
261
+ onKeydown: (event) => {
262
+ if (event.key !== "Enter") return;
263
+ event.preventDefault();
264
+ if (event.ctrlKey || event.metaKey) replaceAll();
265
+ else replaceOne();
266
+ }
267
+ })), h("button", {
268
+ key: "one",
269
+ type: "button",
270
+ class: "vt-button vt-button-text vt-button-secondary vt-button-sm",
271
+ disabled: !found.length,
272
+ onClick: replaceOne
273
+ }, words.replace), h("button", {
274
+ key: "all",
275
+ type: "button",
276
+ class: "vt-button vt-button-text vt-button-secondary vt-button-sm",
277
+ disabled: !found.length,
278
+ onClick: replaceAll
279
+ }, words.replaceAll)) : null);
280
+ }
281
+ return {
282
+ get isOpen() {
283
+ return isOpen;
284
+ },
285
+ open({ replace = false, query: next } = {}) {
286
+ const { anchor, head } = options.editor.state.selection;
287
+ if (next === void 0 && anchor.path.join() === head.path.join() && anchor.offset !== head.offset) {
288
+ const block = editorNodeAt(options.editor.state.doc, anchor.path);
289
+ const selected = editorInlineText(block?.content).slice(Math.min(anchor.offset, head.offset), Math.max(anchor.offset, head.offset));
290
+ if (selected && !/[\n\ufffc]/.test(selected) && selected.length <= 200) next = selected;
291
+ }
292
+ if (next !== void 0) query = next;
293
+ isOpen = true;
294
+ replacing = replace && editable() ? true : replacing && editable();
295
+ wantFocus = true;
296
+ search();
297
+ nearestToCaret();
298
+ scrollToCurrent = true;
299
+ options.render();
300
+ paint();
301
+ },
302
+ close,
303
+ sync() {
304
+ if (!isOpen) return;
305
+ search();
306
+ paint();
307
+ },
308
+ view,
309
+ matches: () => found,
310
+ destroy() {
311
+ painted.delete(key);
312
+ repaint();
313
+ }
314
+ };
315
+ }
316
+ //#endregion
317
+ export { createFindBar };
318
+
319
+ //# sourceMappingURL=find.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find.js","names":[],"sources":["../src/find.ts"],"sourcesContent":["import { editorInlineText, editorNodeAt, en, findInEditor, formatMessage, replaceEditorMatches, type EditorFindOptions, type EditorInstance, type EditorMatch, type EditorView, type Locale } from '@vitral/core';\nimport { h, mergeAttrs, type Child, type Props } from '@vitral/dom';\nimport { iconView } from './render/toolbar';\n\n/**\n * The bar that finds words in an editor and replaces them, over the text the\n * way a code editor's does. Every match is painted with the CSS Custom\n * Highlight API — nothing is added to the document, so the words stay what\n * they are for undo, for a screen reader and for the caret — and where a\n * browser has no highlights the count and the selection still work.\n */\n\nexport interface FindBarOptions {\n editor: EditorInstance;\n view: () => EditorView | null;\n part: (name: string, state?: unknown) => Props;\n locale?: () => Locale;\n /** Whether the words can be changed; without it the bar only finds. */\n editable?: () => boolean;\n /** The bar changed and wants drawing again. */\n render: () => void;\n id?: string;\n}\n\nexport interface FindBar {\n readonly isOpen: boolean;\n open(options?: { replace?: boolean; query?: string }): void;\n close(options?: { focusEditor?: boolean }): void;\n /** The document changed: find again and repaint. */\n sync(): void;\n view(): Child;\n matches(): readonly EditorMatch[];\n destroy(): void;\n}\n\n// Highlights are named for the whole page, so every bar adds its ranges to\n// one shared set and the set is rebuilt from all of them.\nconst painted = new Map<object, { all: Range[]; current: Range | null }>();\n\nfunction repaint() {\n const registry = typeof CSS !== 'undefined' ? (CSS as unknown as { highlights?: Map<string, unknown> }).highlights : undefined;\n const Highlight = (globalThis as { Highlight?: new (...ranges: Range[]) => unknown }).Highlight;\n if (!registry || !Highlight) return;\n const all: Range[] = [];\n const current: Range[] = [];\n for (const entry of painted.values()) {\n all.push(...entry.all);\n if (entry.current) current.push(entry.current);\n }\n if (all.length) registry.set('vt-find', new Highlight(...all));\n else registry.delete('vt-find');\n if (current.length) registry.set('vt-find-current', new Highlight(...current));\n else registry.delete('vt-find-current');\n}\n\nexport function createFindBar(options: FindBarOptions): FindBar {\n const key = {};\n const locale = () => options.locale?.() ?? en;\n const editable = () => options.editable?.() ?? true;\n const id = options.id ?? 'vt-find';\n let isOpen = false;\n let replacing = false;\n let query = '';\n let replacement = '';\n const flags: Required<EditorFindOptions> = { caseSensitive: false, wholeWord: false, regex: false };\n let found: EditorMatch[] = [];\n let current = 0;\n let input: HTMLInputElement | null = null;\n let wantFocus = false;\n let scrollToCurrent = false;\n\n function search() {\n found = isOpen ? findInEditor(options.editor.state.doc, query, flags) : [];\n if (current >= found.length) current = Math.max(0, found.length - 1);\n }\n\n /** The first match at or after the caret, so opening the bar starts where the reader is. */\n function nearestToCaret() {\n const head = options.editor.state.selection.head;\n const index = found.findIndex((m) => {\n const order = m.path.join('.').localeCompare(head.path.join('.'), undefined, { numeric: true });\n return order > 0 || (order === 0 && m.to > head.offset);\n });\n current = index === -1 ? 0 : index;\n }\n\n function rangeOf(match: EditorMatch): Range | null {\n const view = options.view();\n const start = view?.domFromPos({ path: match.path, offset: match.from });\n const end = view?.domFromPos({ path: match.path, offset: match.to });\n if (!start || !end || typeof document === 'undefined') return null;\n try {\n const range = document.createRange();\n range.setStart(start.node, start.offset);\n range.setEnd(end.node, end.offset);\n return range;\n } catch {\n return null;\n }\n }\n\n // The view draws the document after the handle hears of a change, so the\n // ranges are taken once it has.\n let queued = false;\n function paint() {\n if (queued) return;\n queued = true;\n queueMicrotask(() => {\n queued = false;\n if (wantFocus && input) {\n wantFocus = false;\n input.focus();\n input.select();\n }\n if (!isOpen || !found.length) {\n painted.delete(key);\n repaint();\n return;\n }\n const all = found.map(rangeOf).filter((r): r is Range => !!r);\n const now = found[current] ? rangeOf(found[current]!) : null;\n painted.set(key, { all, current: now });\n repaint();\n if (scrollToCurrent && now) {\n scrollToCurrent = false;\n const block = now.startContainer.nodeType === 1 ? (now.startContainer as Element) : now.startContainer.parentElement;\n block?.scrollIntoView?.({ block: 'nearest', inline: 'nearest' });\n }\n });\n }\n\n function changed() {\n search();\n options.render();\n paint();\n }\n\n function go(step: number) {\n if (!found.length) return;\n current = (current + step + found.length) % found.length;\n scrollToCurrent = true;\n options.render();\n paint();\n }\n\n /** Leaves the current match selected in the document, where Escape takes the reader. */\n function selectCurrent() {\n const match = found[current];\n if (!match) return;\n options.editor.setSelection({ anchor: { path: match.path, offset: match.from }, head: { path: match.path, offset: match.to } });\n }\n\n function replaceOne() {\n const match = found[current];\n if (!match || !editable()) return;\n options.editor.apply(replaceEditorMatches(options.editor.state, [match], replacement, flags), { origin: 'user', history: 'other' });\n search();\n scrollToCurrent = true;\n options.render();\n paint();\n }\n\n function replaceAll() {\n if (!found.length || !editable()) return;\n options.editor.apply(replaceEditorMatches(options.editor.state, found, replacement, flags), { origin: 'user', history: 'other' });\n search();\n options.render();\n paint();\n }\n\n const close: FindBar['close'] = ({ focusEditor = true } = {}) => {\n if (!isOpen) return;\n if (focusEditor) selectCurrent();\n isOpen = false;\n found = [];\n painted.delete(key);\n repaint();\n options.render();\n if (focusEditor) options.view()?.focus();\n };\n\n const toggle = (name: keyof EditorFindOptions, label: string, glyph: string): Child =>\n h(\n 'button',\n mergeAttrs({ key: name, type: 'button' }, options.part('findToggle', { active: flags[name] }), {\n 'aria-label': label,\n 'aria-pressed': flags[name] ? 'true' : 'false',\n title: label,\n onClick: () => {\n flags[name] = !flags[name];\n changed();\n }\n }),\n glyph\n );\n\n const iconButton = (name: string, label: string, icon: string, onClick: () => void, disabled = false): Child =>\n h(\n 'button',\n mergeAttrs({ key: name, type: 'button' }, options.part('button', { disabled }), { 'aria-label': label, title: label, disabled, onClick }),\n iconView(icon, options.part('buttonIcon'))\n );\n\n function view(): Child {\n if (!isOpen) return null;\n const words = locale().editor;\n const canReplace = editable();\n const count = !query ? '' : found.length ? formatMessage(words.matchCount, { current: current + 1, total: found.length }) : words.noMatches;\n const keydown = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n event.preventDefault();\n close();\n }\n };\n return h(\n 'div',\n mergeAttrs({ key: 'find', id, role: 'search' }, options.part('find'), { 'aria-label': words.find, onKeydown: keydown }),\n h(\n 'div',\n mergeAttrs({ key: 'row' }, options.part('findRow')),\n canReplace\n ? h(\n 'button',\n mergeAttrs({ key: 'expand', type: 'button' }, options.part('button'), {\n 'aria-label': words.toggleReplace,\n title: words.toggleReplace,\n 'aria-expanded': replacing ? 'true' : 'false',\n 'aria-controls': `${id}-replace`,\n onClick: () => {\n replacing = !replacing;\n options.render();\n }\n }),\n iconView(replacing ? 'chevronDown' : 'chevronRight', options.part('buttonIcon'))\n )\n : null,\n h(\n 'span',\n { key: 'query', class: 'vt-field vt-field-sm vt-editor-find-field' },\n h('input', {\n type: 'text',\n class: 'vt-field-input',\n value: query,\n placeholder: words.find,\n 'aria-label': words.find,\n 'aria-describedby': `${id}-count`,\n spellcheck: 'false',\n ref: (el: Element | null) => (input = el as HTMLInputElement | null),\n onInput: (event: Event) => {\n query = (event.target as HTMLInputElement).value;\n search();\n nearestToCaret();\n scrollToCurrent = true;\n options.render();\n paint();\n },\n onKeydown: (event: KeyboardEvent) => {\n if (event.key !== 'Enter') return;\n event.preventDefault();\n go(event.shiftKey ? -1 : 1);\n }\n })\n ),\n toggle('caseSensitive', words.matchCase, 'Aa'),\n toggle('wholeWord', words.wholeWord, 'ab'),\n toggle('regex', words.useRegex, '.*'),\n h('span', mergeAttrs({ key: 'count', id: `${id}-count`, 'aria-live': 'polite' }, options.part('findCount', { empty: !!query && !found.length })), count),\n iconButton('prev', words.previousMatch, 'chevronUp', () => go(-1), !found.length),\n iconButton('next', words.nextMatch, 'chevronDown', () => go(1), !found.length),\n iconButton('close', words.closeFind, 'close', () => close())\n ),\n canReplace && replacing\n ? h(\n 'div',\n mergeAttrs({ key: 'replace', id: `${id}-replace` }, options.part('findRow', { replace: true })),\n h(\n 'span',\n { key: 'with', class: 'vt-field vt-field-sm vt-editor-find-field' },\n h('input', {\n type: 'text',\n class: 'vt-field-input',\n value: replacement,\n placeholder: words.replaceWith,\n 'aria-label': words.replaceWith,\n spellcheck: 'false',\n onInput: (event: Event) => (replacement = (event.target as HTMLInputElement).value),\n onKeydown: (event: KeyboardEvent) => {\n if (event.key !== 'Enter') return;\n event.preventDefault();\n if (event.ctrlKey || event.metaKey) replaceAll();\n else replaceOne();\n }\n })\n ),\n h('button', { key: 'one', type: 'button', class: 'vt-button vt-button-text vt-button-secondary vt-button-sm', disabled: !found.length, onClick: replaceOne }, words.replace),\n h('button', { key: 'all', type: 'button', class: 'vt-button vt-button-text vt-button-secondary vt-button-sm', disabled: !found.length, onClick: replaceAll }, words.replaceAll)\n )\n : null\n );\n }\n\n return {\n get isOpen() {\n return isOpen;\n },\n open({ replace = false, query: next } = {}) {\n // What is selected is what the reader wants to find, when it is a few words on one line.\n const { anchor, head } = options.editor.state.selection;\n if (next === undefined && anchor.path.join() === head.path.join() && anchor.offset !== head.offset) {\n const block = editorNodeAt(options.editor.state.doc, anchor.path);\n const selected = editorInlineText(block?.content).slice(Math.min(anchor.offset, head.offset), Math.max(anchor.offset, head.offset));\n if (selected && !/[\\n\\ufffc]/.test(selected) && selected.length <= 200) next = selected;\n }\n if (next !== undefined) query = next;\n isOpen = true;\n replacing = replace && editable() ? true : replacing && editable();\n wantFocus = true;\n search();\n nearestToCaret();\n scrollToCurrent = true;\n options.render();\n paint();\n },\n close,\n sync() {\n if (!isOpen) return;\n search();\n paint();\n },\n view,\n matches: () => found,\n destroy() {\n painted.delete(key);\n repaint();\n }\n };\n}\n"],"mappings":";;;;AAqCA,IAAM,0BAAU,IAAI,IAAqD;AAEzE,SAAS,UAAU;CACf,MAAM,WAAW,OAAO,QAAQ,cAAe,IAAyD,aAAa,KAAA;CACrH,MAAM,YAAa,WAAmE;CACtF,IAAI,CAAC,YAAY,CAAC,WAAW;CAC7B,MAAM,MAAe,CAAC;CACtB,MAAM,UAAmB,CAAC;CAC1B,KAAK,MAAM,SAAS,QAAQ,OAAO,GAAG;EAClC,IAAI,KAAK,GAAG,MAAM,GAAG;EACrB,IAAI,MAAM,SAAS,QAAQ,KAAK,MAAM,OAAO;CACjD;CACA,IAAI,IAAI,QAAQ,SAAS,IAAI,WAAW,IAAI,UAAU,GAAG,GAAG,CAAC;MACxD,SAAS,OAAO,SAAS;CAC9B,IAAI,QAAQ,QAAQ,SAAS,IAAI,mBAAmB,IAAI,UAAU,GAAG,OAAO,CAAC;MACxE,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K;GAAO,MAAM;GAAU,OAAO;GAA6D,UAAU,CAAC,MAAM;GAAQ,SAAS;EAAW,GAAG,MAAM,UAAU,CAClL,IACA,IACV;CACJ;CAEA,OAAO;EACH,IAAI,SAAS;GACT,OAAO;EACX;EACA,KAAK,EAAE,UAAU,OAAO,OAAO,SAAS,CAAC,GAAG;GAExC,MAAM,EAAE,QAAQ,SAAS,QAAQ,OAAO,MAAM;GAC9C,IAAI,SAAS,KAAA,KAAa,OAAO,KAAK,KAAK,MAAM,KAAK,KAAK,KAAK,KAAK,OAAO,WAAW,KAAK,QAAQ;IAChG,MAAM,QAAQ,aAAa,QAAQ,OAAO,MAAM,KAAK,OAAO,IAAI;IAChE,MAAM,WAAW,iBAAiB,OAAO,OAAO,CAAC,CAAC,MAAM,KAAK,IAAI,OAAO,QAAQ,KAAK,MAAM,GAAG,KAAK,IAAI,OAAO,QAAQ,KAAK,MAAM,CAAC;IAClI,IAAI,YAAY,CAAC,aAAa,KAAK,QAAQ,KAAK,SAAS,UAAU,KAAK,OAAO;GACnF;GACA,IAAI,SAAS,KAAA,GAAW,QAAQ;GAChC,SAAS;GACT,YAAY,WAAW,SAAS,IAAI,OAAO,aAAa,SAAS;GACjE,YAAY;GACZ,OAAO;GACP,eAAe;GACf,kBAAkB;GAClB,QAAQ,OAAO;GACf,MAAM;EACV;EACA;EACA,OAAO;GACH,IAAI,CAAC,QAAQ;GACb,OAAO;GACP,MAAM;EACV;EACA;EACA,eAAe;EACf,UAAU;GACN,QAAQ,OAAO,GAAG;GAClB,QAAQ;EACZ;CACJ;AACJ"}
package/dist/index.d.ts CHANGED
@@ -6,6 +6,8 @@
6
6
  */
7
7
  export { createTextEditor } from './editor';
8
8
  export { createSlashMenu, defaultSlashCommands, type SlashMenu, type SlashMenuOptions } from './slash';
9
+ export { createChipMenu, type ChipMenu, type ChipMenuOptions } from './chips';
10
+ export { createFindBar, type FindBar, type FindBarOptions } from './find';
9
11
  export { createBlockHandle, defaultBlockActions, type BlockHandle, type BlockHandleOptions } from './block';
10
12
  export { editorButtons, editorIcons, shortcutCommands, defaultToolbar, defaultBubbleMenu, type EditorButtonSpec } from './buttons';
11
13
  export * from './types';
package/dist/index.js CHANGED
@@ -2,6 +2,8 @@ import { defaultBubbleMenu, defaultToolbar, editorButtons, editorIcons, shortcut
2
2
  import { bubbleView, buttonView, iconView, toolbarView } from "./render/toolbar.js";
3
3
  import { blockHandleView, blockMenuView, colorPanelView, imagePanelView, linkPanelView, slashMenuView, tablePanelView } from "./render/menus.js";
4
4
  import { createBlockHandle, defaultBlockActions } from "./block.js";
5
+ import { createChipMenu } from "./chips.js";
6
+ import { createFindBar } from "./find.js";
5
7
  import { createSlashMenu, defaultSlashCommands } from "./slash.js";
6
8
  import { createTextEditor } from "./editor.js";
7
- export { blockHandleView, blockMenuView, bubbleView, buttonView, colorPanelView, createBlockHandle, createSlashMenu, createTextEditor, defaultBlockActions, defaultBubbleMenu, defaultSlashCommands, defaultToolbar, editorButtons, editorIcons, iconView, imagePanelView, linkPanelView, shortcutCommands, slashMenuView, tablePanelView, toolbarView };
9
+ export { blockHandleView, blockMenuView, bubbleView, buttonView, colorPanelView, createBlockHandle, createChipMenu, createFindBar, createSlashMenu, createTextEditor, defaultBlockActions, defaultBubbleMenu, defaultSlashCommands, defaultToolbar, editorButtons, editorIcons, iconView, imagePanelView, linkPanelView, shortcutCommands, slashMenuView, tablePanelView, toolbarView };
@@ -48,6 +48,13 @@ export interface SlashMenuState {
48
48
  query: string;
49
49
  items: SlashCommand[];
50
50
  active: number;
51
+ /** The list's name and the words when nothing matches; the slash menu's otherwise. */
52
+ labels?: {
53
+ list: string;
54
+ empty: string;
55
+ };
56
+ /** Where the options' ids start; the slash menu's id otherwise. */
57
+ id?: string;
51
58
  }
52
59
  /**
53
60
  * What a `/` opens: a listbox of commands, filtered as it is typed. The text
@@ -127,8 +127,9 @@ function imagePanelView(context, on) {
127
127
  */
128
128
  function slashMenuView(context, state, on) {
129
129
  const { part, locale } = context;
130
- const optionId = (index) => `${context.ids.slash}-option-${index}`;
131
- return h("div", mergeAttrs({ id: context.ids.slash }, part("slashMenu")), state.items.length ? h("ul", mergeAttrs({ role: "listbox" }, part("slashList"), { "aria-label": locale.editor.slashMenu }), state.items.map((item, index) => h("li", mergeAttrs({
130
+ const menuId = state.id ?? context.ids.slash;
131
+ const optionId = (index) => `${menuId}-option-${index}`;
132
+ return h("div", mergeAttrs({ id: menuId }, part("slashMenu")), state.items.length ? h("ul", mergeAttrs({ role: "listbox" }, part("slashList"), { "aria-label": state.labels?.list ?? locale.editor.slashMenu }), state.items.map((item, index) => h("li", mergeAttrs({
132
133
  key: item.id,
133
134
  id: optionId(index),
134
135
  role: "option"
@@ -140,7 +141,7 @@ function slashMenuView(context, state, on) {
140
141
  if (state.active === index) return;
141
142
  state.active = index;
142
143
  }
143
- }), item.icon ? iconView(item.icon, part("slashIcon")) : null, h("span", part("slashText"), h("span", part("slashLabel"), item.label), item.description ? h("span", part("slashDescription"), item.description) : null)))) : h("div", mergeAttrs({ role: "status" }, part("slashEmpty")), formatMessage(locale.editor.slashEmpty, { query: state.query })));
144
+ }), item.icon ? iconView(item.icon, part("slashIcon")) : null, h("span", part("slashText"), h("span", part("slashLabel"), item.label), item.description ? h("span", part("slashDescription"), item.description) : null)))) : h("div", mergeAttrs({ role: "status" }, part("slashEmpty")), formatMessage(state.labels?.empty ?? locale.editor.slashEmpty, { query: state.query })));
144
145
  }
145
146
  function blockMenuView(context, block, actions, on) {
146
147
  const { part, locale } = context;
@@ -1 +1 @@
1
- {"version":3,"file":"menus.js","names":[],"sources":["../../src/render/menus.ts"],"sourcesContent":["import { formatMessage, type EditorColor, type EditorNode, type Locale } from '@vitral/core';\nimport { h, mergeAttrs, type Child, type Props, type VElement } from '@vitral/dom';\nimport type { BlockAction, SlashCommand } from '../types';\nimport { iconView } from './toolbar';\n\n/**\n * The panels the toolbar opens, and the two menus the text itself opens: the\n * one a `/` brings up in an empty block, and the one the handle beside a block\n * offers. All of them are listboxes or dialogs the handle puts in an overlay.\n */\n\nexport interface PanelContext {\n locale: Locale;\n part: (name: string, state?: unknown) => Props;\n ids: { slash: string; block: string };\n}\n\n// ---- the link panel ---------------------------------------------------------------\n\nexport interface LinkPanelState {\n href: string;\n text: string;\n newTab: boolean;\n /** Editing a link that is already there, rather than making one. */\n existing: boolean;\n error?: string;\n}\n\nexport interface LinkPanelActions {\n change: (patch: Partial<LinkPanelState>) => void;\n apply: () => void;\n remove: () => void;\n /** Follows the link, in a new tab. */\n open: () => void;\n cancel: () => void;\n}\n\nexport function linkPanelView(context: PanelContext, state: LinkPanelState, on: LinkPanelActions): VElement {\n const { part, locale } = context;\n const words = locale.editor;\n const field = (label: string, value: string, key: 'href' | 'text', type = 'text') =>\n h(\n 'label',\n mergeAttrs({ key }, part('field')),\n h('span', part('fieldLabel'), label),\n h(\n 'span',\n { class: 'vt-field vt-field-sm vt-field-fluid' },\n h(\n 'input',\n mergeAttrs({ type, class: 'vt-field-input' }, {\n value,\n onInput: (event: Event) => on.change({ [key]: (event.target as HTMLInputElement).value } as Partial<LinkPanelState>),\n onKeydown: (event: KeyboardEvent) => {\n if (event.key !== 'Enter') return;\n event.preventDefault();\n on.apply();\n }\n })\n )\n )\n );\n return h(\n 'div',\n mergeAttrs({ role: 'dialog' }, part('panel'), { 'aria-label': words.link }),\n field(words.linkUrl, state.href, 'href', 'url'),\n field(words.linkText, state.text, 'text'),\n h(\n 'label',\n mergeAttrs({ key: 'newtab' }, part('check')),\n h('input', { type: 'checkbox', checked: state.newTab, onChange: (event: Event) => on.change({ newTab: (event.target as HTMLInputElement).checked }) }),\n h('span', null, words.openInNewTab)\n ),\n state.error ? h('span', mergeAttrs({ key: 'error', role: 'alert' }, part('fieldError')), state.error) : null,\n h(\n 'div',\n mergeAttrs({ key: 'actions' }, part('actions')),\n state.existing\n ? [\n h('button', mergeAttrs({ key: 'open', type: 'button', class: 'vt-button vt-button-text vt-button-secondary vt-button-sm' }, { onClick: on.open }), words.openLink),\n h('button', mergeAttrs({ key: 'remove', type: 'button', class: 'vt-button vt-button-text vt-button-secondary vt-button-sm' }, { onClick: on.remove }), words.removeLink)\n ]\n : null,\n h('button', mergeAttrs({ key: 'cancel', type: 'button', class: 'vt-button vt-button-text vt-button-secondary vt-button-sm' }, { onClick: on.cancel }), locale.cancel),\n h('button', mergeAttrs({ key: 'apply', type: 'button', class: 'vt-button vt-button-sm' }, { onClick: on.apply }), words.apply)\n )\n ) as VElement;\n}\n\n// ---- the colour swatches ------------------------------------------------------------\n\nexport function colorPanelView(\n context: PanelContext,\n options: { kind: 'color' | 'highlight'; palette: readonly EditorColor[]; chosen?: EditorColor; onChoose: (color: EditorColor | null) => void }\n): VElement {\n const { part, locale } = context;\n const words = locale.editor;\n const none = options.kind === 'color' ? words.defaultColor : words.noHighlight;\n const nameOf = (color: EditorColor) => words.colors[color.name] ?? color.name;\n return h(\n 'div',\n mergeAttrs({ role: 'dialog' }, part('panel'), { 'aria-label': options.kind === 'color' ? words.textColor : words.highlight }),\n h(\n 'div',\n mergeAttrs({ key: 'swatches', role: 'group' }, part('swatches')),\n [\n h(\n 'button',\n mergeAttrs({ key: 'none', type: 'button' }, part('swatch', { none: true, kind: options.kind, selected: !options.chosen }), {\n 'aria-label': none,\n title: none,\n onClick: () => options.onChoose(null)\n })\n ),\n ...options.palette.map((color) =>\n h(\n 'button',\n mergeAttrs({ key: color.name, type: 'button' }, part('swatch', { kind: options.kind, selected: options.chosen?.name === color.name }), {\n 'aria-label': nameOf(color),\n title: nameOf(color),\n style: { background: options.kind === 'color' ? color.text : color.highlight },\n onClick: () => options.onChoose(color)\n })\n )\n )\n ]\n )\n ) as VElement;\n}\n\n// ---- the table picker ----------------------------------------------------------------\n\nexport function tablePanelView(context: PanelContext, on: { insert: (rows: number, columns: number) => void }): VElement {\n const { part, locale } = context;\n const words = locale.editor;\n const number = (label: string, name: 'rows' | 'columns', value: number) =>\n h(\n 'label',\n mergeAttrs({ key: name }, part('field')),\n h('span', part('fieldLabel'), label),\n h(\n 'span',\n { class: 'vt-field vt-field-sm' },\n h('input', { type: 'number', min: '1', max: '20', value: String(value), class: 'vt-field-input', 'data-vt-table': name })\n )\n );\n const read = (element: Element | null, name: string, fallback: number) => {\n const input = element?.querySelector<HTMLInputElement>(`[data-vt-table=\"${name}\"]`);\n const value = Number(input?.value);\n return Number.isFinite(value) && value > 0 ? Math.min(20, Math.round(value)) : fallback;\n };\n return h(\n 'div',\n mergeAttrs({ role: 'dialog' }, part('panel'), { 'aria-label': words.table }),\n number(words.tableRows, 'rows', 3),\n number(words.tableColumns, 'columns', 3),\n h(\n 'div',\n mergeAttrs({ key: 'actions' }, part('actions')),\n h(\n 'button',\n mergeAttrs({ type: 'button', class: 'vt-button vt-button-sm' }, {\n onClick: (event: MouseEvent) => {\n const panel = (event.currentTarget as HTMLElement).closest('[role=\"dialog\"]');\n on.insert(read(panel, 'rows', 3), read(panel, 'columns', 3));\n }\n }),\n words.insertTable\n )\n )\n ) as VElement;\n}\n\n// ---- the image panel -------------------------------------------------------------------\n\nexport function imagePanelView(context: PanelContext, on: { insert: (src: string, alt: string) => void; cancel: () => void }): VElement {\n const { part, locale } = context;\n const words = locale.editor;\n const field = (label: string, name: string, type = 'text') =>\n h(\n 'label',\n mergeAttrs({ key: name }, part('field')),\n h('span', part('fieldLabel'), label),\n h('span', { class: 'vt-field vt-field-sm vt-field-fluid' }, h('input', { type, class: 'vt-field-input', 'data-vt-image': name }))\n );\n const read = (element: Element | null, name: string) => element?.querySelector<HTMLInputElement>(`[data-vt-image=\"${name}\"]`)?.value ?? '';\n return h(\n 'div',\n mergeAttrs({ role: 'dialog' }, part('panel'), { 'aria-label': words.image }),\n field(words.imageUrl, 'src', 'url'),\n field(words.imageAlt, 'alt'),\n h(\n 'div',\n mergeAttrs({ key: 'actions' }, part('actions')),\n h('button', mergeAttrs({ key: 'cancel', type: 'button', class: 'vt-button vt-button-text vt-button-secondary vt-button-sm' }, { onClick: on.cancel }), locale.cancel),\n h(\n 'button',\n mergeAttrs({ key: 'insert', type: 'button', class: 'vt-button vt-button-sm' }, {\n onClick: (event: MouseEvent) => {\n const panel = (event.currentTarget as HTMLElement).closest('[role=\"dialog\"]');\n on.insert(read(panel, 'src'), read(panel, 'alt'));\n }\n }),\n words.insert\n )\n )\n ) as VElement;\n}\n\n// ---- the slash menu ----------------------------------------------------------------------\n\nexport interface SlashMenuState {\n query: string;\n items: SlashCommand[];\n active: number;\n}\n\n/**\n * What a `/` opens: a listbox of commands, filtered as it is typed. The text\n * keeps the keyboard — the caret is still in the document — so the list is\n * pointed at through `aria-activedescendant` rather than focused.\n */\nexport function slashMenuView(context: PanelContext, state: SlashMenuState, on: { choose: (index: number) => void }): VElement {\n const { part, locale } = context;\n const optionId = (index: number) => `${context.ids.slash}-option-${index}`;\n return h(\n 'div',\n mergeAttrs({ id: context.ids.slash }, part('slashMenu')),\n state.items.length\n ? h(\n 'ul',\n mergeAttrs({ role: 'listbox' }, part('slashList'), { 'aria-label': locale.editor.slashMenu }),\n state.items.map((item, index) =>\n h(\n 'li',\n mergeAttrs({ key: item.id, id: optionId(index), role: 'option' }, part('slashItem', { focused: index === state.active }), {\n 'aria-selected': index === state.active ? 'true' : 'false',\n onMousedown: (event: MouseEvent) => event.preventDefault(),\n onClick: () => on.choose(index),\n onMousemove: () => {\n if (state.active === index) return;\n state.active = index;\n }\n }),\n item.icon ? iconView(item.icon, part('slashIcon')) : null,\n h(\n 'span',\n part('slashText'),\n h('span', part('slashLabel'), item.label),\n item.description ? h('span', part('slashDescription'), item.description) : null\n )\n )\n )\n )\n : h('div', mergeAttrs({ role: 'status' }, part('slashEmpty')), formatMessage(locale.editor.slashEmpty, { query: state.query }))\n ) as VElement;\n}\n\n// ---- the block handle's menu ----------------------------------------------------------------\n\nexport function blockMenuView(context: PanelContext, block: EditorNode, actions: BlockAction[], on: { choose: (id: string) => void }): VElement {\n const { part, locale } = context;\n return h(\n 'div',\n mergeAttrs({ id: context.ids.block, role: 'menu' }, part('blockMenu'), { 'aria-label': locale.editor.blockMenu }),\n actions\n .filter((action) => !action.when || action.when(block))\n .map((action) =>\n h(\n 'button',\n mergeAttrs({ key: action.id, type: 'button', role: 'menuitem' }, part('blockItem'), { onClick: () => on.choose(action.id) }),\n action.icon ? iconView(action.icon, part('blockIcon')) : null,\n h('span', null, action.label)\n )\n )\n ) as VElement;\n}\n\n/** The handle beside the block the caret is in: it drags nothing yet, it opens the menu. */\nexport function blockHandleView(context: PanelContext, on: { open: (event: MouseEvent) => void }, position: { top: number; left: number }): Child {\n const { part, locale } = context;\n return h(\n 'button',\n mergeAttrs({ key: 'block-handle', type: 'button' }, part('blockHandle'), {\n 'aria-label': locale.editor.blockMenu,\n 'aria-haspopup': 'menu',\n style: { top: `${position.top}px`, left: `${position.left}px` },\n onMousedown: (event: MouseEvent) => event.preventDefault(),\n onClick: on.open\n }),\n iconView('grip', part('blockHandleIcon'))\n );\n}\n"],"mappings":";;;;AAqCA,SAAgB,cAAc,SAAuB,OAAuB,IAAgC;CACxG,MAAM,EAAE,MAAM,WAAW;CACzB,MAAM,QAAQ,OAAO;CACrB,MAAM,SAAS,OAAe,OAAe,KAAsB,OAAO,WACtE,EACI,SACA,WAAW,EAAE,IAAI,GAAG,KAAK,OAAO,CAAC,GACjC,EAAE,QAAQ,KAAK,YAAY,GAAG,KAAK,GACnC,EACI,QACA,EAAE,OAAO,sCAAsC,GAC/C,EACI,SACA,WAAW;EAAE;EAAM,OAAO;CAAiB,GAAG;EAC1C;EACA,UAAU,UAAiB,GAAG,OAAO,GAAG,MAAO,MAAM,OAA4B,MAAM,CAA4B;EACnH,YAAY,UAAyB;GACjC,IAAI,MAAM,QAAQ,SAAS;GAC3B,MAAM,eAAe;GACrB,GAAG,MAAM;EACb;CACJ,CAAC,CACL,CACJ,CACJ;CACJ,OAAO,EACH,OACA,WAAW,EAAE,MAAM,SAAS,GAAG,KAAK,OAAO,GAAG,EAAE,cAAc,MAAM,KAAK,CAAC,GAC1E,MAAM,MAAM,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AChB,CAAC,GACD,SAAS,QAAQ,KAAK,iBAAiB,CAAC,CAC5C;AACJ"}
1
+ {"version":3,"file":"menus.js","names":[],"sources":["../../src/render/menus.ts"],"sourcesContent":["import { formatMessage, type EditorColor, type EditorNode, type Locale } from '@vitral/core';\nimport { h, mergeAttrs, type Child, type Props, type VElement } from '@vitral/dom';\nimport type { BlockAction, SlashCommand } from '../types';\nimport { iconView } from './toolbar';\n\n/**\n * The panels the toolbar opens, and the two menus the text itself opens: the\n * one a `/` brings up in an empty block, and the one the handle beside a block\n * offers. All of them are listboxes or dialogs the handle puts in an overlay.\n */\n\nexport interface PanelContext {\n locale: Locale;\n part: (name: string, state?: unknown) => Props;\n ids: { slash: string; block: string };\n}\n\n// ---- the link panel ---------------------------------------------------------------\n\nexport interface LinkPanelState {\n href: string;\n text: string;\n newTab: boolean;\n /** Editing a link that is already there, rather than making one. */\n existing: boolean;\n error?: string;\n}\n\nexport interface LinkPanelActions {\n change: (patch: Partial<LinkPanelState>) => void;\n apply: () => void;\n remove: () => void;\n /** Follows the link, in a new tab. */\n open: () => void;\n cancel: () => void;\n}\n\nexport function linkPanelView(context: PanelContext, state: LinkPanelState, on: LinkPanelActions): VElement {\n const { part, locale } = context;\n const words = locale.editor;\n const field = (label: string, value: string, key: 'href' | 'text', type = 'text') =>\n h(\n 'label',\n mergeAttrs({ key }, part('field')),\n h('span', part('fieldLabel'), label),\n h(\n 'span',\n { class: 'vt-field vt-field-sm vt-field-fluid' },\n h(\n 'input',\n mergeAttrs({ type, class: 'vt-field-input' }, {\n value,\n onInput: (event: Event) => on.change({ [key]: (event.target as HTMLInputElement).value } as Partial<LinkPanelState>),\n onKeydown: (event: KeyboardEvent) => {\n if (event.key !== 'Enter') return;\n event.preventDefault();\n on.apply();\n }\n })\n )\n )\n );\n return h(\n 'div',\n mergeAttrs({ role: 'dialog' }, part('panel'), { 'aria-label': words.link }),\n field(words.linkUrl, state.href, 'href', 'url'),\n field(words.linkText, state.text, 'text'),\n h(\n 'label',\n mergeAttrs({ key: 'newtab' }, part('check')),\n h('input', { type: 'checkbox', checked: state.newTab, onChange: (event: Event) => on.change({ newTab: (event.target as HTMLInputElement).checked }) }),\n h('span', null, words.openInNewTab)\n ),\n state.error ? h('span', mergeAttrs({ key: 'error', role: 'alert' }, part('fieldError')), state.error) : null,\n h(\n 'div',\n mergeAttrs({ key: 'actions' }, part('actions')),\n state.existing\n ? [\n h('button', mergeAttrs({ key: 'open', type: 'button', class: 'vt-button vt-button-text vt-button-secondary vt-button-sm' }, { onClick: on.open }), words.openLink),\n h('button', mergeAttrs({ key: 'remove', type: 'button', class: 'vt-button vt-button-text vt-button-secondary vt-button-sm' }, { onClick: on.remove }), words.removeLink)\n ]\n : null,\n h('button', mergeAttrs({ key: 'cancel', type: 'button', class: 'vt-button vt-button-text vt-button-secondary vt-button-sm' }, { onClick: on.cancel }), locale.cancel),\n h('button', mergeAttrs({ key: 'apply', type: 'button', class: 'vt-button vt-button-sm' }, { onClick: on.apply }), words.apply)\n )\n ) as VElement;\n}\n\n// ---- the colour swatches ------------------------------------------------------------\n\nexport function colorPanelView(\n context: PanelContext,\n options: { kind: 'color' | 'highlight'; palette: readonly EditorColor[]; chosen?: EditorColor; onChoose: (color: EditorColor | null) => void }\n): VElement {\n const { part, locale } = context;\n const words = locale.editor;\n const none = options.kind === 'color' ? words.defaultColor : words.noHighlight;\n const nameOf = (color: EditorColor) => words.colors[color.name] ?? color.name;\n return h(\n 'div',\n mergeAttrs({ role: 'dialog' }, part('panel'), { 'aria-label': options.kind === 'color' ? words.textColor : words.highlight }),\n h(\n 'div',\n mergeAttrs({ key: 'swatches', role: 'group' }, part('swatches')),\n [\n h(\n 'button',\n mergeAttrs({ key: 'none', type: 'button' }, part('swatch', { none: true, kind: options.kind, selected: !options.chosen }), {\n 'aria-label': none,\n title: none,\n onClick: () => options.onChoose(null)\n })\n ),\n ...options.palette.map((color) =>\n h(\n 'button',\n mergeAttrs({ key: color.name, type: 'button' }, part('swatch', { kind: options.kind, selected: options.chosen?.name === color.name }), {\n 'aria-label': nameOf(color),\n title: nameOf(color),\n style: { background: options.kind === 'color' ? color.text : color.highlight },\n onClick: () => options.onChoose(color)\n })\n )\n )\n ]\n )\n ) as VElement;\n}\n\n// ---- the table picker ----------------------------------------------------------------\n\nexport function tablePanelView(context: PanelContext, on: { insert: (rows: number, columns: number) => void }): VElement {\n const { part, locale } = context;\n const words = locale.editor;\n const number = (label: string, name: 'rows' | 'columns', value: number) =>\n h(\n 'label',\n mergeAttrs({ key: name }, part('field')),\n h('span', part('fieldLabel'), label),\n h(\n 'span',\n { class: 'vt-field vt-field-sm' },\n h('input', { type: 'number', min: '1', max: '20', value: String(value), class: 'vt-field-input', 'data-vt-table': name })\n )\n );\n const read = (element: Element | null, name: string, fallback: number) => {\n const input = element?.querySelector<HTMLInputElement>(`[data-vt-table=\"${name}\"]`);\n const value = Number(input?.value);\n return Number.isFinite(value) && value > 0 ? Math.min(20, Math.round(value)) : fallback;\n };\n return h(\n 'div',\n mergeAttrs({ role: 'dialog' }, part('panel'), { 'aria-label': words.table }),\n number(words.tableRows, 'rows', 3),\n number(words.tableColumns, 'columns', 3),\n h(\n 'div',\n mergeAttrs({ key: 'actions' }, part('actions')),\n h(\n 'button',\n mergeAttrs({ type: 'button', class: 'vt-button vt-button-sm' }, {\n onClick: (event: MouseEvent) => {\n const panel = (event.currentTarget as HTMLElement).closest('[role=\"dialog\"]');\n on.insert(read(panel, 'rows', 3), read(panel, 'columns', 3));\n }\n }),\n words.insertTable\n )\n )\n ) as VElement;\n}\n\n// ---- the image panel -------------------------------------------------------------------\n\nexport function imagePanelView(context: PanelContext, on: { insert: (src: string, alt: string) => void; cancel: () => void }): VElement {\n const { part, locale } = context;\n const words = locale.editor;\n const field = (label: string, name: string, type = 'text') =>\n h(\n 'label',\n mergeAttrs({ key: name }, part('field')),\n h('span', part('fieldLabel'), label),\n h('span', { class: 'vt-field vt-field-sm vt-field-fluid' }, h('input', { type, class: 'vt-field-input', 'data-vt-image': name }))\n );\n const read = (element: Element | null, name: string) => element?.querySelector<HTMLInputElement>(`[data-vt-image=\"${name}\"]`)?.value ?? '';\n return h(\n 'div',\n mergeAttrs({ role: 'dialog' }, part('panel'), { 'aria-label': words.image }),\n field(words.imageUrl, 'src', 'url'),\n field(words.imageAlt, 'alt'),\n h(\n 'div',\n mergeAttrs({ key: 'actions' }, part('actions')),\n h('button', mergeAttrs({ key: 'cancel', type: 'button', class: 'vt-button vt-button-text vt-button-secondary vt-button-sm' }, { onClick: on.cancel }), locale.cancel),\n h(\n 'button',\n mergeAttrs({ key: 'insert', type: 'button', class: 'vt-button vt-button-sm' }, {\n onClick: (event: MouseEvent) => {\n const panel = (event.currentTarget as HTMLElement).closest('[role=\"dialog\"]');\n on.insert(read(panel, 'src'), read(panel, 'alt'));\n }\n }),\n words.insert\n )\n )\n ) as VElement;\n}\n\n// ---- the slash menu ----------------------------------------------------------------------\n\nexport interface SlashMenuState {\n query: string;\n items: SlashCommand[];\n active: number;\n /** The list's name and the words when nothing matches; the slash menu's otherwise. */\n labels?: { list: string; empty: string };\n /** Where the options' ids start; the slash menu's id otherwise. */\n id?: string;\n}\n\n/**\n * What a `/` opens: a listbox of commands, filtered as it is typed. The text\n * keeps the keyboard — the caret is still in the document — so the list is\n * pointed at through `aria-activedescendant` rather than focused.\n */\nexport function slashMenuView(context: PanelContext, state: SlashMenuState, on: { choose: (index: number) => void }): VElement {\n const { part, locale } = context;\n const menuId = state.id ?? context.ids.slash;\n const optionId = (index: number) => `${menuId}-option-${index}`;\n return h(\n 'div',\n mergeAttrs({ id: menuId }, part('slashMenu')),\n state.items.length\n ? h(\n 'ul',\n mergeAttrs({ role: 'listbox' }, part('slashList'), { 'aria-label': state.labels?.list ?? locale.editor.slashMenu }),\n state.items.map((item, index) =>\n h(\n 'li',\n mergeAttrs({ key: item.id, id: optionId(index), role: 'option' }, part('slashItem', { focused: index === state.active }), {\n 'aria-selected': index === state.active ? 'true' : 'false',\n onMousedown: (event: MouseEvent) => event.preventDefault(),\n onClick: () => on.choose(index),\n onMousemove: () => {\n if (state.active === index) return;\n state.active = index;\n }\n }),\n item.icon ? iconView(item.icon, part('slashIcon')) : null,\n h(\n 'span',\n part('slashText'),\n h('span', part('slashLabel'), item.label),\n item.description ? h('span', part('slashDescription'), item.description) : null\n )\n )\n )\n )\n : h('div', mergeAttrs({ role: 'status' }, part('slashEmpty')), formatMessage(state.labels?.empty ?? locale.editor.slashEmpty, { query: state.query }))\n ) as VElement;\n}\n\n// ---- the block handle's menu ----------------------------------------------------------------\n\nexport function blockMenuView(context: PanelContext, block: EditorNode, actions: BlockAction[], on: { choose: (id: string) => void }): VElement {\n const { part, locale } = context;\n return h(\n 'div',\n mergeAttrs({ id: context.ids.block, role: 'menu' }, part('blockMenu'), { 'aria-label': locale.editor.blockMenu }),\n actions\n .filter((action) => !action.when || action.when(block))\n .map((action) =>\n h(\n 'button',\n mergeAttrs({ key: action.id, type: 'button', role: 'menuitem' }, part('blockItem'), { onClick: () => on.choose(action.id) }),\n action.icon ? iconView(action.icon, part('blockIcon')) : null,\n h('span', null, action.label)\n )\n )\n ) as VElement;\n}\n\n/** The handle beside the block the caret is in: it drags nothing yet, it opens the menu. */\nexport function blockHandleView(context: PanelContext, on: { open: (event: MouseEvent) => void }, position: { top: number; left: number }): Child {\n const { part, locale } = context;\n return h(\n 'button',\n mergeAttrs({ key: 'block-handle', type: 'button' }, part('blockHandle'), {\n 'aria-label': locale.editor.blockMenu,\n 'aria-haspopup': 'menu',\n style: { top: `${position.top}px`, left: `${position.left}px` },\n onMousedown: (event: MouseEvent) => event.preventDefault(),\n onClick: on.open\n }),\n iconView('grip', part('blockHandleIcon'))\n );\n}\n"],"mappings":";;;;AAqCA,SAAgB,cAAc,SAAuB,OAAuB,IAAgC;CACxG,MAAM,EAAE,MAAM,WAAW;CACzB,MAAM,QAAQ,OAAO;CACrB,MAAM,SAAS,OAAe,OAAe,KAAsB,OAAO,WACtE,EACI,SACA,WAAW,EA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M;EAAU,MAAM;CAAW,GAAG,KAAK,WAAW,GAAG,EAAE,eAAe,GAAG,OAAO,OAAO,EAAE,EAAE,CAAC,GAC3H,OAAO,OAAO,SAAS,OAAO,MAAM,KAAK,WAAW,CAAC,IAAI,MACzD,EAAE,QAAQ,MAAM,OAAO,KAAK,CAChC,CACJ,CACR;AACJ;;AAGA,SAAgB,gBAAgB,SAAuB,IAA2C,UAAgD;CAC9I,MAAM,EAAE,MAAM,WAAW;CACzB,OAAO,EACH,UACA,WAAW;EAAE,KAAK;EAAgB,MAAM;CAAS,GAAG,KAAK,aAAa,GAAG;EACrE,cAAc,OAAO,OAAO;EAC5B,iBAAiB;EACjB,OAAO;GAAE,KAAK,GAAG,SAAS,IAAI;GAAK,MAAM,GAAG,SAAS,KAAK;EAAI;EAC9D,cAAc,UAAsB,MAAM,eAAe;EACzD,SAAS,GAAG;CAChB,CAAC,GACD,SAAS,QAAQ,KAAK,iBAAiB,CAAC,CAC5C;AACJ"}
@@ -32,6 +32,8 @@ export interface ToolbarActions {
32
32
  tip: (element: Element | null, text: string) => void;
33
33
  command: (name: string, args: readonly unknown[], event: MouseEvent) => void;
34
34
  openLink: (event: MouseEvent) => void;
35
+ /** Opens or shuts the find bar. */
36
+ openFind: () => void;
35
37
  openImage: (event: MouseEvent) => void;
36
38
  openTable: (event: MouseEvent) => void;
37
39
  openColor: (kind: 'color' | 'highlight', event: MouseEvent) => void;
@@ -1,5 +1,5 @@
1
1
  import { editorButtons, shortcutCommands } from "../buttons.js";
2
- import "@vitral/core";
2
+ import { ariaEditorShortcut, formatEditorShortcut } from "@vitral/core";
3
3
  import { h, iconNode, mergeAttrs } from "@vitral/dom";
4
4
  import { getIcon } from "@vitral/icons";
5
5
  //#region src/render/toolbar.ts
@@ -65,6 +65,19 @@ function openerView(context, item) {
65
65
  onClick: (event) => spec.action === "openImage" ? context.on.openImage(event) : context.on.openTable(event)
66
66
  }), iconView(spec.icon, context.part("buttonIcon")));
67
67
  }
68
+ /** The button that opens the find bar. */
69
+ function findView(context) {
70
+ const name = context.locale.editor.find;
71
+ return h("button", mergeAttrs({
72
+ key: "find",
73
+ type: "button"
74
+ }, context.part("button"), {
75
+ "aria-label": name,
76
+ "aria-keyshortcuts": ariaEditorShortcut("Mod-f"),
77
+ ref: (element) => context.on.tip(element, `${name} (${formatEditorShortcut("Mod-f")})`),
78
+ onClick: () => context.on.openFind()
79
+ }), iconView("search", context.part("buttonIcon")));
80
+ }
68
81
  /** The text and highlight pickers: a button showing the colour in hand. */
69
82
  function colorView(context, kind) {
70
83
  const { part, locale } = context;
@@ -102,7 +115,7 @@ function toolbarView(context, groups) {
102
115
  }), groups.map((group, index) => h("div", mergeAttrs({
103
116
  key: index,
104
117
  role: "group"
105
- }, part("toolbarGroup")), group.map((item) => item === "blockType" ? blockSelectView(context) : item === "color" || item === "highlight" ? colorView(context, item) : item === "image" || item === "table" ? openerView(context, item) : buttonView(context, item)))));
118
+ }, part("toolbarGroup")), group.map((item) => item === "blockType" ? blockSelectView(context) : item === "color" || item === "highlight" ? colorView(context, item) : item === "image" || item === "table" ? openerView(context, item) : item === "find" ? findView(context) : buttonView(context, item)))));
106
119
  }
107
120
  /** The floating toolbar over a selection: the same buttons, in one group. */
108
121
  function bubbleView(context, items) {
@@ -1 +1 @@
1
- {"version":3,"file":"toolbar.js","names":[],"sources":["../../src/render/toolbar.ts"],"sourcesContent":["import { formatEditorShortcut, type EditorColor, type Locale } from '@vitral/core';\nimport { h, iconNode, mergeAttrs, type Child, type Props } from '@vitral/dom';\nimport { getIcon } from '@vitral/icons';\nimport { editorButtons, shortcutCommands } from '../buttons';\nimport type { EditorButtonCommand, EditorToolbarItem } from '../types';\n\n/**\n * The toolbar as plain objects: a group of buttons a command each, the block\n * type as a select, the two colour pickers, and the buttons that open a panel.\n * What is drawn is decided here; what happens when it is pressed is the\n * handle's.\n */\n\nexport interface ToolbarContext {\n locale: Locale;\n part: (name: string, state?: unknown) => Props;\n editable: boolean;\n /** Whether a command applies right now. */\n can: (name: string, ...args: unknown[]) => boolean;\n isActive: (name: string, attrs?: Record<string, unknown>) => boolean;\n /** The shortcut for a command, as a label and as `aria-keyshortcuts`. */\n shortcut: (name: string, args?: readonly unknown[]) => { label: string; aria: string } | undefined;\n on: ToolbarActions;\n /** The element each opener is drawn into, so a panel can hang from it. */\n ref: (name: string) => (element: Element | null) => void;\n colors: { text?: EditorColor; highlight?: EditorColor };\n}\n\nexport interface ToolbarActions {\n /** Gives a button the tooltip that says what it is. */\n tip: (element: Element | null, text: string) => void;\n command: (name: string, args: readonly unknown[], event: MouseEvent) => void;\n openLink: (event: MouseEvent) => void;\n openImage: (event: MouseEvent) => void;\n openTable: (event: MouseEvent) => void;\n openColor: (kind: 'color' | 'highlight', event: MouseEvent) => void;\n blockSelect: (element: Element | null) => void;\n}\n\nexport const iconView = (name: string, props?: Props): Child => iconNode(getIcon(name), props);\n\nconst OPENERS: Partial<Record<EditorToolbarItem, { icon: string; label: (words: Locale['editor']) => string; action: keyof ToolbarActions }>> = {\n image: { icon: 'image', label: (words) => words.image, action: 'openImage' },\n table: { icon: 'table', label: (words) => words.table, action: 'openTable' }\n};\n\n/** One command's button: a toggle where the command has a pressed state. */\nexport function buttonView(context: ToolbarContext, item: EditorButtonCommand): Child {\n const { part, locale } = context;\n const spec = editorButtons[item];\n if (!spec) return null;\n const name = spec.label(locale.editor);\n const isLink = item === 'link';\n const pressed = spec.active ? context.isActive(spec.active[0], spec.active[1]) : undefined;\n const [command, ...args] = spec.command;\n const disabled = !context.editable || (isLink ? context.isActive('codeBlock') : !context.can(command, ...args));\n const [shortcutName, ...shortcutArgs] = shortcutCommands[item] ?? spec.command;\n const shortcut = context.shortcut(shortcutName, shortcutArgs);\n return h(\n 'button',\n mergeAttrs({ key: item, type: 'button' }, part('button', { active: pressed, disabled }), {\n 'aria-label': name,\n 'aria-pressed': isLink || pressed === undefined ? undefined : pressed ? 'true' : 'false',\n 'aria-haspopup': isLink ? 'dialog' : undefined,\n 'aria-keyshortcuts': shortcut?.aria,\n disabled,\n ref: (element: Element | null) => {\n if (isLink) context.ref('link')(element);\n context.on.tip(element, shortcut ? `${name} (${shortcut.label})` : name);\n },\n onClick: (event: MouseEvent) => (isLink ? context.on.openLink(event) : context.on.command(command, args, event))\n }),\n iconView(spec.icon.name, part('buttonIcon'))\n );\n}\n\n/** A button that opens a panel: the image and table pickers. */\nfunction openerView(context: ToolbarContext, item: 'image' | 'table'): Child {\n const spec = OPENERS[item]!;\n const name = spec.label(context.locale.editor);\n return h(\n 'button',\n mergeAttrs({ key: item, type: 'button' }, context.part('button', { disabled: !context.editable }), {\n 'aria-label': name,\n 'aria-haspopup': 'dialog',\n disabled: !context.editable,\n ref: (element: Element | null) => {\n context.ref(item)(element);\n context.on.tip(element, name);\n },\n onClick: (event: MouseEvent) => (spec.action === 'openImage' ? context.on.openImage(event) : context.on.openTable(event))\n }),\n iconView(spec.icon, context.part('buttonIcon'))\n );\n}\n\n/** The text and highlight pickers: a button showing the colour in hand. */\nfunction colorView(context: ToolbarContext, kind: 'color' | 'highlight'): Child {\n const { part, locale } = context;\n const name = kind === 'color' ? locale.editor.textColor : locale.editor.highlight;\n const chosen = context.colors[kind === 'color' ? 'text' : 'highlight'];\n return h(\n 'button',\n mergeAttrs({ key: kind, type: 'button' }, part('button', { disabled: !context.editable }), {\n 'aria-label': name,\n 'aria-haspopup': 'dialog',\n disabled: !context.editable,\n ref: (element: Element | null) => {\n context.ref(kind)(element);\n context.on.tip(element, name);\n },\n onClick: (event: MouseEvent) => context.on.openColor(kind, event)\n }),\n iconView(kind === 'color' ? 'textColor' : 'highlighter', part('buttonIcon')),\n h('span', mergeAttrs({ key: 'bar', 'aria-hidden': 'true' }, part('colorBar'), { style: { background: chosen ? (kind === 'color' ? chosen.text : chosen.highlight) : 'transparent' } }))\n );\n}\n\n/** The block type, as the select the control kit draws; the handle mounts it. */\nfunction blockSelectView(context: ToolbarContext): Child {\n return h('span', mergeAttrs({ key: 'blockType' }, { ref: context.on.blockSelect }));\n}\n\nexport function toolbarView(context: ToolbarContext, groups: EditorToolbarItem[][]): Child {\n const { part, locale } = context;\n return h(\n 'div',\n mergeAttrs({ key: 'toolbar', role: 'toolbar' }, part('toolbar'), { 'aria-label': locale.editor.toolbar, 'aria-orientation': 'horizontal' }),\n groups.map((group, index) =>\n h(\n 'div',\n mergeAttrs({ key: index, role: 'group' }, part('toolbarGroup')),\n group.map((item) =>\n item === 'blockType'\n ? blockSelectView(context)\n : item === 'color' || item === 'highlight'\n ? colorView(context, item)\n : item === 'image' || item === 'table'\n ? openerView(context, item)\n : buttonView(context, item as EditorButtonCommand)\n )\n )\n )\n );\n}\n\n/** The floating toolbar over a selection: the same buttons, in one group. */\nexport function bubbleView(context: ToolbarContext, items: EditorToolbarItem[]): Child {\n return h(\n 'div',\n mergeAttrs({ role: 'toolbar' }, context.part('bubble'), { 'aria-label': context.locale.editor.toolbar }),\n items.map((item) =>\n item === 'color' || item === 'highlight' ? colorView(context, item) : item === 'image' || item === 'table' ? openerView(context, item) : buttonView(context, item as EditorButtonCommand)\n )\n );\n}\n\nexport const shortcutLabel = (binding: { key: string } | undefined): string | undefined => (binding ? formatEditorShortcut(binding.key) : undefined);\n"],"mappings":";;;;;AAuCA,IAAa,YAAY,MAAc,UAAyB,SAAS,QAAQ,IAAI,GAAG,KAAK;AAE7F,IAAM,UAA0I;CAC5I,OAAO;EAAE,MAAM;EAAS,QAAQ,UAAU,MAAM;EAAO,QAAQ;CAAY;CAC3E,OAAO;EAAE,MAAM;EAAS,QAAQ,UAAU,MAAM;EAAO,QAAQ;CAAY;AAC/E;;AAGA,SAAgB,WAAW,SAAyB,MAAkC;CAClF,MAAM,EAAE,MAAM,WAAW;CACzB,MAAM,OAAO,cAAc;CAC3B,IAAI,CAAC,MAAM,OAAO;CAClB,MAAM,OAAO,KAAK,MAAM,OAAO,MAAM;CACrC,MAAM,SAAS,SAAS;CACxB,MAAM,UAAU,KAAK,SAAS,QAAQ,SAAS,KAAK,OAAO,I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c,OAAO,OAAO;EAAS,oBAAoB;CAAa,CAAC,GAC1I,OAAO,KAAK,OAAO,UACf,EACI,OACA,WAAW;EAAE,KAAK;EAAO,MAAM;CAAQ,GAAG,KAAK,cAAc,CAAC,GAC9D,MAAM,KAAK,SACP,SAAS,cACH,gBAAgB,OAAO,IACvB,SAAS,WAAW,SAAS,cAC3B,UAAU,SAAS,IAAI,IACvB,SAAS,WAAW,SAAS,UAC3B,WAAW,SAAS,IAAI,IACxB,WAAW,SAAS,IAA2B,CAC7D,CACJ,CACJ,CACJ;AACJ;;AAGA,SAAgB,WAAW,SAAyB,OAAmC;CACnF,OAAO,EACH,OACA,WAAW,EAAE,MAAM,UAAU,GAAG,QAAQ,KAAK,QAAQ,GAAG,EAAE,cAAc,QAAQ,OAAO,OAAO,QAAQ,CAAC,GACvG,MAAM,KAAK,SACP,SAAS,WAAW,SAAS,cAAc,UAAU,SAAS,IAAI,IAAI,SAAS,WAAW,SAAS,UAAU,WAAW,SAAS,IAAI,IAAI,WAAW,SAAS,IAA2B,CAC5L,CACJ;AACJ"}
1
+ {"version":3,"file":"toolbar.js","names":[],"sources":["../../src/render/toolbar.ts"],"sourcesContent":["import { ariaEditorShortcut, formatEditorShortcut, type EditorColor, type Locale } from '@vitral/core';\nimport { h, iconNode, mergeAttrs, type Child, type Props } from '@vitral/dom';\nimport { getIcon } from '@vitral/icons';\nimport { editorButtons, shortcutCommands } from '../buttons';\nimport type { EditorButtonCommand, EditorToolbarItem } from '../types';\n\n/**\n * The toolbar as plain objects: a group of buttons a command each, the block\n * type as a select, the two colour pickers, and the buttons that open a panel.\n * What is drawn is decided here; what happens when it is pressed is the\n * handle's.\n */\n\nexport interface ToolbarContext {\n locale: Locale;\n part: (name: string, state?: unknown) => Props;\n editable: boolean;\n /** Whether a command applies right now. */\n can: (name: string, ...args: unknown[]) => boolean;\n isActive: (name: string, attrs?: Record<string, unknown>) => boolean;\n /** The shortcut for a command, as a label and as `aria-keyshortcuts`. */\n shortcut: (name: string, args?: readonly unknown[]) => { label: string; aria: string } | undefined;\n on: ToolbarActions;\n /** The element each opener is drawn into, so a panel can hang from it. */\n ref: (name: string) => (element: Element | null) => void;\n colors: { text?: EditorColor; highlight?: EditorColor };\n}\n\nexport interface ToolbarActions {\n /** Gives a button the tooltip that says what it is. */\n tip: (element: Element | null, text: string) => void;\n command: (name: string, args: readonly unknown[], event: MouseEvent) => void;\n openLink: (event: MouseEvent) => void;\n /** Opens or shuts the find bar. */\n openFind: () => void;\n openImage: (event: MouseEvent) => void;\n openTable: (event: MouseEvent) => void;\n openColor: (kind: 'color' | 'highlight', event: MouseEvent) => void;\n blockSelect: (element: Element | null) => void;\n}\n\nexport const iconView = (name: string, props?: Props): Child => iconNode(getIcon(name), props);\n\nconst OPENERS: Partial<Record<EditorToolbarItem, { icon: string; label: (words: Locale['editor']) => string; action: keyof ToolbarActions }>> = {\n image: { icon: 'image', label: (words) => words.image, action: 'openImage' },\n table: { icon: 'table', label: (words) => words.table, action: 'openTable' }\n};\n\n/** One command's button: a toggle where the command has a pressed state. */\nexport function buttonView(context: ToolbarContext, item: EditorButtonCommand): Child {\n const { part, locale } = context;\n const spec = editorButtons[item];\n if (!spec) return null;\n const name = spec.label(locale.editor);\n const isLink = item === 'link';\n const pressed = spec.active ? context.isActive(spec.active[0], spec.active[1]) : undefined;\n const [command, ...args] = spec.command;\n const disabled = !context.editable || (isLink ? context.isActive('codeBlock') : !context.can(command, ...args));\n const [shortcutName, ...shortcutArgs] = shortcutCommands[item] ?? spec.command;\n const shortcut = context.shortcut(shortcutName, shortcutArgs);\n return h(\n 'button',\n mergeAttrs({ key: item, type: 'button' }, part('button', { active: pressed, disabled }), {\n 'aria-label': name,\n 'aria-pressed': isLink || pressed === undefined ? undefined : pressed ? 'true' : 'false',\n 'aria-haspopup': isLink ? 'dialog' : undefined,\n 'aria-keyshortcuts': shortcut?.aria,\n disabled,\n ref: (element: Element | null) => {\n if (isLink) context.ref('link')(element);\n context.on.tip(element, shortcut ? `${name} (${shortcut.label})` : name);\n },\n onClick: (event: MouseEvent) => (isLink ? context.on.openLink(event) : context.on.command(command, args, event))\n }),\n iconView(spec.icon.name, part('buttonIcon'))\n );\n}\n\n/** A button that opens a panel: the image and table pickers. */\nfunction openerView(context: ToolbarContext, item: 'image' | 'table'): Child {\n const spec = OPENERS[item]!;\n const name = spec.label(context.locale.editor);\n return h(\n 'button',\n mergeAttrs({ key: item, type: 'button' }, context.part('button', { disabled: !context.editable }), {\n 'aria-label': name,\n 'aria-haspopup': 'dialog',\n disabled: !context.editable,\n ref: (element: Element | null) => {\n context.ref(item)(element);\n context.on.tip(element, name);\n },\n onClick: (event: MouseEvent) => (spec.action === 'openImage' ? context.on.openImage(event) : context.on.openTable(event))\n }),\n iconView(spec.icon, context.part('buttonIcon'))\n );\n}\n\n/** The button that opens the find bar. */\nfunction findView(context: ToolbarContext): Child {\n const name = context.locale.editor.find;\n return h(\n 'button',\n mergeAttrs({ key: 'find', type: 'button' }, context.part('button'), {\n 'aria-label': name,\n 'aria-keyshortcuts': ariaEditorShortcut('Mod-f'),\n ref: (element: Element | null) => context.on.tip(element, `${name} (${formatEditorShortcut('Mod-f')})`),\n onClick: () => context.on.openFind()\n }),\n iconView('search', context.part('buttonIcon'))\n );\n}\n\n/** The text and highlight pickers: a button showing the colour in hand. */\nfunction colorView(context: ToolbarContext, kind: 'color' | 'highlight'): Child {\n const { part, locale } = context;\n const name = kind === 'color' ? locale.editor.textColor : locale.editor.highlight;\n const chosen = context.colors[kind === 'color' ? 'text' : 'highlight'];\n return h(\n 'button',\n mergeAttrs({ key: kind, type: 'button' }, part('button', { disabled: !context.editable }), {\n 'aria-label': name,\n 'aria-haspopup': 'dialog',\n disabled: !context.editable,\n ref: (element: Element | null) => {\n context.ref(kind)(element);\n context.on.tip(element, name);\n },\n onClick: (event: MouseEvent) => context.on.openColor(kind, event)\n }),\n iconView(kind === 'color' ? 'textColor' : 'highlighter', part('buttonIcon')),\n h('span', mergeAttrs({ key: 'bar', 'aria-hidden': 'true' }, part('colorBar'), { style: { background: chosen ? (kind === 'color' ? chosen.text : chosen.highlight) : 'transparent' } }))\n );\n}\n\n/** The block type, as the select the control kit draws; the handle mounts it. */\nfunction blockSelectView(context: ToolbarContext): Child {\n return h('span', mergeAttrs({ key: 'blockType' }, { ref: context.on.blockSelect }));\n}\n\nexport function toolbarView(context: ToolbarContext, groups: EditorToolbarItem[][]): Child {\n const { part, locale } = context;\n return h(\n 'div',\n mergeAttrs({ key: 'toolbar', role: 'toolbar' }, part('toolbar'), { 'aria-label': locale.editor.toolbar, 'aria-orientation': 'horizontal' }),\n groups.map((group, index) =>\n h(\n 'div',\n mergeAttrs({ key: index, role: 'group' }, part('toolbarGroup')),\n group.map((item) =>\n item === 'blockType'\n ? blockSelectView(context)\n : item === 'color' || item === 'highlight'\n ? colorView(context, item)\n : item === 'image' || item === 'table'\n ? openerView(context, item)\n : item === 'find'\n ? findView(context)\n : buttonView(context, item as EditorButtonCommand)\n )\n )\n )\n );\n}\n\n/** The floating toolbar over a selection: the same buttons, in one group. */\nexport function bubbleView(context: ToolbarContext, items: EditorToolbarItem[]): Child {\n return h(\n 'div',\n mergeAttrs({ role: 'toolbar' }, context.part('bubble'), { 'aria-label': context.locale.editor.toolbar }),\n items.map((item) =>\n item === 'color' || item === 'highlight' ? colorView(context, item) : item === 'image' || item === 'table' ? openerView(context, item) : buttonView(context, item as EditorButtonCommand)\n )\n );\n}\n\nexport const shortcutLabel = (binding: { key: string } | undefined): string | undefined => (binding ? formatEditorShortcut(binding.key) : undefined);\n"],"mappings":";;;;;AAyCA,IAAa,YAAY,MAAc,UAAyB,SAAS,QAAQ,IAAI,GAAG,KAAK;AAE7F,IAAM,UAA0I;CAC5I,OAAO;EAAE,MAAM;EAAS,QAAQ,UAAU,MAAM;EAAO,QAAQ;CAAY;CAC3E,OAAO;EAAE,MAAM;EAAS,QAAQ,UAAU,MAAM;EAAO,QAAQ;CAAY;AAC/E;;AAGA,SAAgB,WAAW,SAA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