@minnalstack/editor-plugin-find 0.0.0-stage → 0.3.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.
@@ -0,0 +1,201 @@
1
+ /** The names the stylesheet colours, with `::highlight(mn-find)` and `::highlight(mn-find-current)`. */
2
+ const everyMatch = 'mn-find';
3
+ const currentMatch = 'mn-find-current';
4
+ /** Whether this browser can paint matches. Where it can't, moving to a match selects it, because nothing else would show it. */
5
+ export function canPaint() {
6
+ return typeof CSS !== 'undefined' && 'highlights' in CSS && typeof Highlight !== 'undefined';
7
+ }
8
+ /**
9
+ * One of the page's highlights. A page has one highlight of each name, so every editor on it shares the two, and each adds and takes away only its own ranges. The current
10
+ * match is in both, and its higher priority is what paints it over the other.
11
+ */
12
+ function highlightNamed(name, priority) {
13
+ if (!canPaint())
14
+ return null;
15
+ let found = CSS.highlights.get(name);
16
+ if (found === undefined) {
17
+ found = new Highlight();
18
+ found.priority = priority;
19
+ CSS.highlights.set(name, found);
20
+ }
21
+ return found;
22
+ }
23
+ /** How far beyond the view a block is painted, so that scrolling finds it painted already. */
24
+ const ahead = '50% 0px';
25
+ /**
26
+ * What one editor has painted. The editor finds a match's range in time that grows with how far into the document its block is: 1,000 of them at the end of 20,000 blocks
27
+ * take most of a second. So only the blocks near the view are painted, as an IntersectionObserver reports them, and a block keeps its ranges until it changes.
28
+ * https://developer.mozilla.org/docs/Web/API/Intersection_Observer_API
29
+ */
30
+ export class Painter {
31
+ editor;
32
+ root;
33
+ /** The matches of each block that has some. */
34
+ matches = new Map();
35
+ /** The ranges painted for a block, one for each of its matches, and null where the page has none. */
36
+ painted = new Map();
37
+ /** The element of each block that has matches, which the observer watches. */
38
+ watched = new Map();
39
+ /** The blocks the observer last said are near the view. */
40
+ near = new Set();
41
+ observer;
42
+ current = null;
43
+ constructor(editor, root) {
44
+ this.editor = editor;
45
+ this.root = root;
46
+ this.observer = canPaint() ? new IntersectionObserver((entries) => this.seen(entries), { rootMargin: ahead }) : null;
47
+ }
48
+ /** Paints the matches. A block's ranges are found again when it is in `changed`, or always when that is null, and when the page has drawn it again. */
49
+ paint(matches, changed) {
50
+ const all = highlightNamed(everyMatch, 0);
51
+ if (all === null || this.observer === null)
52
+ return;
53
+ const byBlock = new Map();
54
+ for (const match of matches) {
55
+ const list = byBlock.get(match.block);
56
+ if (list === undefined)
57
+ byBlock.set(match.block, [match]);
58
+ else
59
+ list.push(match);
60
+ }
61
+ this.matches = byBlock;
62
+ for (const [block, ranges] of this.painted) {
63
+ const isRedrawn = ranges.some((range) => range !== null && !(range.startContainer.isConnected && range.endContainer.isConnected));
64
+ if (changed === null || changed.has(block) || !byBlock.has(block) || isRedrawn)
65
+ this.unpaint(block, all);
66
+ }
67
+ for (const [block, element] of this.watched) {
68
+ if (byBlock.has(block) && element.isConnected)
69
+ continue;
70
+ this.observer.unobserve(element);
71
+ this.watched.delete(block);
72
+ this.near.delete(block);
73
+ }
74
+ // A block watched for the first time is reported once the browser has laid it out, and painted then.
75
+ for (const [block, element] of this.elementsOf([...byBlock.keys()].filter((block) => !this.watched.has(block)))) {
76
+ this.watched.set(block, element);
77
+ this.observer.observe(element);
78
+ }
79
+ for (const block of this.near)
80
+ this.paintBlock(block, all);
81
+ }
82
+ /** Paints the current match over the others, or none. It is painted wherever it is, because it is what was moved to. */
83
+ setCurrent(match) {
84
+ const now = highlightNamed(currentMatch, 1);
85
+ if (now === null)
86
+ return;
87
+ if (this.current !== null)
88
+ now.delete(this.current);
89
+ this.current = match === undefined ? null : this.rangeOf(match);
90
+ if (this.current !== null)
91
+ now.add(this.current);
92
+ }
93
+ /** The range of a match, painted or not, for bringing it into view. */
94
+ rangeOf(match) {
95
+ const index = this.matches.get(match.block)?.findIndex((found) => found.from === match.from && found.to === match.to) ?? -1;
96
+ return this.painted.get(match.block)?.[index] ?? this.editor.getDomRange(match);
97
+ }
98
+ /** Takes away everything this editor painted, and stops watching. */
99
+ clear() {
100
+ this.observer?.disconnect();
101
+ const all = highlightNamed(everyMatch, 0);
102
+ const now = highlightNamed(currentMatch, 1);
103
+ for (const ranges of this.painted.values())
104
+ for (const range of ranges)
105
+ if (range !== null)
106
+ all?.delete(range);
107
+ if (this.current !== null)
108
+ now?.delete(this.current);
109
+ this.current = null;
110
+ this.matches = new Map();
111
+ this.painted.clear();
112
+ this.watched.clear();
113
+ this.near.clear();
114
+ }
115
+ paintBlock(block, all) {
116
+ if (this.painted.has(block))
117
+ return;
118
+ const ranges = (this.matches.get(block) ?? []).map((match) => this.editor.getDomRange(match));
119
+ this.painted.set(block, ranges);
120
+ for (const range of ranges)
121
+ if (range !== null)
122
+ all.add(range);
123
+ }
124
+ unpaint(block, all) {
125
+ for (const range of this.painted.get(block) ?? [])
126
+ if (range !== null)
127
+ all.delete(range);
128
+ this.painted.delete(block);
129
+ }
130
+ seen(entries) {
131
+ const all = highlightNamed(everyMatch, 0);
132
+ for (const { target, isIntersecting } of entries) {
133
+ const block = target.dataset['blockId'];
134
+ // An element no longer watched, one drawn again or one from before find closed, can still be reported once.
135
+ if (block === undefined || this.watched.get(block) !== target)
136
+ continue;
137
+ if (!isIntersecting)
138
+ this.near.delete(block);
139
+ else {
140
+ this.near.add(block);
141
+ if (all !== null)
142
+ this.paintBlock(block, all);
143
+ }
144
+ }
145
+ }
146
+ /** The elements of these blocks, from the `data-block-id` the editor draws on each: one look through the page for many, or one look each for a few. */
147
+ elementsOf(blocks) {
148
+ const found = new Map();
149
+ if (blocks.length <= 8) {
150
+ for (const block of blocks) {
151
+ const element = this.root.querySelector(`[data-block-id="${CSS.escape(block)}"]`);
152
+ if (element !== null)
153
+ found.set(block, element);
154
+ }
155
+ return found;
156
+ }
157
+ const wanted = new Set(blocks);
158
+ for (const element of this.root.querySelectorAll('[data-block-id]')) {
159
+ const block = element.dataset['blockId'];
160
+ if (block !== undefined && wanted.has(block) && !found.has(block))
161
+ found.set(block, element);
162
+ }
163
+ return found;
164
+ }
165
+ }
166
+ /** Whether a box scrolls its content, in either direction. */
167
+ function scrolls(box) {
168
+ const { overflowX, overflowY } = getComputedStyle(box);
169
+ return (box.scrollHeight > box.clientHeight && /auto|scroll|overlay/.test(overflowY)) || (box.scrollWidth > box.clientWidth && /auto|scroll|overlay/.test(overflowX));
170
+ }
171
+ /** How far to scroll to bring `start` to `end` to the middle of `low` to `high`, or 0 when it is already well inside. */
172
+ function distance(start, end, low, high) {
173
+ const margin = Math.min(48, (high - low) / 4);
174
+ return start >= low + margin && end <= high - margin ? 0 : (start + end) / 2 - (low + high) / 2;
175
+ }
176
+ /**
177
+ * Brings a match into view in each box that scrolls around it, from the inside out, and to the middle when it is out of view, as a browser's own find does. In the middle it
178
+ * stays clear of what sticks to the top of the page, such as a toolbar.
179
+ */
180
+ export function scrollIntoView(range) {
181
+ const page = document.scrollingElement;
182
+ for (let box = range.startContainer instanceof Element ? range.startContainer : range.startContainer.parentElement; box !== null; box = box.parentElement) {
183
+ const isPage = box === page;
184
+ if (!isPage && !scrolls(box))
185
+ continue;
186
+ const rect = range.getBoundingClientRect();
187
+ // Text that isn't drawn, such as in a closed section, has nowhere to be brought to.
188
+ if (rect.height === 0)
189
+ return;
190
+ const view = isPage ? new DOMRect(0, 0, window.innerWidth, window.innerHeight) : box.getBoundingClientRect();
191
+ const x = distance(rect.left, rect.right, view.left, view.right);
192
+ const y = distance(rect.top, rect.bottom, view.top, view.bottom);
193
+ if (x === 0 && y === 0)
194
+ continue;
195
+ if (isPage)
196
+ window.scrollBy(x, y);
197
+ else
198
+ box.scrollBy(x, y);
199
+ }
200
+ }
201
+ //# sourceMappingURL=highlights.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"highlights.js","sourceRoot":"","sources":["../src/highlights.ts"],"names":[],"mappings":"AAIA,wGAAwG;AACxG,MAAM,UAAU,GAAG,SAAS,CAAC;AAC7B,MAAM,YAAY,GAAG,iBAAiB,CAAC;AAEvC,gIAAgI;AAChI,MAAM,UAAU,QAAQ;IACtB,OAAO,OAAO,GAAG,KA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AM,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,qBAAqB,EAAE,CAAC;QAC7G,MAAM,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QACjE,MAAM,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACjE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;YAAE,SAAS;QACjC,IAAI,MAAM;YAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;;YAC7B,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1B,CAAC;AACH,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { type EditorPage, EditorPlugin, type PluginContext } from '@minnalstack/editor-core';
2
+ export { CloseFind, FindNext, FindPrevious, OpenFind, OpenFindAndReplace, ReplaceAllMatches, ReplaceMatch } from './commands.js';
3
+ /**
4
+ * Find and replace, in a panel of Aranghat's components before the document, which the editor's stylesheet keeps in view at its top right.
5
+ *
6
+ * - Mod-f opens find, with selected text in one block as what to look for. Mod-h, and Mod-Shift-h where Mod-h is the system's (a Mac hides the window with it), open find and
7
+ * replace, as does the toolbar's button. In the panel, Enter and Shift-Enter move to the next and previous match, Enter in the replacement replaces one, and Escape closes it.
8
+ * Mod-g and Mod-Shift-g move in the text too, and Escape there closes the panel.
9
+ * - Each block's text is searched on its own, so no match crosses from one block to the next, and an embedded item is never part of one. Match case and whole word are options.
10
+ * A search finds at most 1,000 matches, and the count says when there are more, which bounds what each change costs while the panel is open.
11
+ * - Matches are painted with the CSS Custom Highlight API, as `::highlight(mn-find)` and the current one as `::highlight(mn-find-current)`, so the page's elements don't change.
12
+ * The current match scrolls into view. It becomes the selection when the keyboard is in the text, or when the panel closes from the panel, and at once in a browser that
13
+ * can't paint it.
14
+ * - Replacing is one edit, and one undo step, however many matches it replaces. The new text takes the formats of the first character it replaces. A read-only editor offers
15
+ * find, from its keys while text in it is selected, and never replacing.
16
+ *
17
+ * It needs the editor on a page, and draws nothing until find opens. An application that draws its own panel can run the commands.
18
+ */
19
+ export declare class FindPlugin extends EditorPlugin {
20
+ readonly name = "find";
21
+ private editor;
22
+ private finder;
23
+ configure(context: PluginContext): void;
24
+ attach(page: EditorPage): void;
25
+ dispose(): void;
26
+ }
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,UAAU,EAAE,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAK1G,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAEjI;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,UAAW,SAAQ,YAAY;IAC1C,SAAkB,IAAI,UAAU;IAChC,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,MAAM,CAAuB;IAE5B,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAgB/C;IAEQ,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAKtC;IAEQ,OAAO,IAAI,IAAI,CAGvB;CACF"}
package/dist/index.js ADDED
@@ -0,0 +1,55 @@
1
+ import { EditorPlugin } from '@minnalstack/editor-core';
2
+ import { CloseFind, FindNext, FindPrevious, OpenFind, OpenFindAndReplace, ReplaceAllMatches, ReplaceMatch } from './commands.js';
3
+ import { Finder } from './finder.js';
4
+ import { defineElements } from './panel.js';
5
+ export { CloseFind, FindNext, FindPrevious, OpenFind, OpenFindAndReplace, ReplaceAllMatches, ReplaceMatch } from './commands.js';
6
+ /**
7
+ * Find and replace, in a panel of Aranghat's components before the document, which the editor's stylesheet keeps in view at its top right.
8
+ *
9
+ * - Mod-f opens find, with selected text in one block as what to look for. Mod-h, and Mod-Shift-h where Mod-h is the system's (a Mac hides the window with it), open find and
10
+ * replace, as does the toolbar's button. In the panel, Enter and Shift-Enter move to the next and previous match, Enter in the replacement replaces one, and Escape closes it.
11
+ * Mod-g and Mod-Shift-g move in the text too, and Escape there closes the panel.
12
+ * - Each block's text is searched on its own, so no match crosses from one block to the next, and an embedded item is never part of one. Match case and whole word are options.
13
+ * A search finds at most 1,000 matches, and the count says when there are more, which bounds what each change costs while the panel is open.
14
+ * - Matches are painted with the CSS Custom Highlight API, as `::highlight(mn-find)` and the current one as `::highlight(mn-find-current)`, so the page's elements don't change.
15
+ * The current match scrolls into view. It becomes the selection when the keyboard is in the text, or when the panel closes from the panel, and at once in a browser that
16
+ * can't paint it.
17
+ * - Replacing is one edit, and one undo step, however many matches it replaces. The new text takes the formats of the first character it replaces. A read-only editor offers
18
+ * find, from its keys while text in it is selected, and never replacing.
19
+ *
20
+ * It needs the editor on a page, and draws nothing until find opens. An application that draws its own panel can run the commands.
21
+ */
22
+ export class FindPlugin extends EditorPlugin {
23
+ name = 'find';
24
+ editor = null;
25
+ finder = null;
26
+ configure(context) {
27
+ this.editor = context.editor;
28
+ context.commands.add(OpenFind, { canExecute: () => this.finder !== null, execute: () => this.finder.open(false) });
29
+ context.commands.add(OpenFindAndReplace, { canExecute: () => this.finder !== null, execute: () => this.finder.open(true) });
30
+ context.commands.add(FindNext, { canExecute: () => this.finder?.hasMatches === true, execute: () => this.finder.next() });
31
+ context.commands.add(FindPrevious, { canExecute: () => this.finder?.hasMatches === true, execute: () => this.finder.previous() });
32
+ context.commands.add(ReplaceMatch, { canExecute: () => this.finder?.canReplace === true, execute: () => this.finder.replace() });
33
+ context.commands.add(ReplaceAllMatches, { canExecute: () => this.finder?.canReplace === true, execute: () => this.finder.replaceAll() });
34
+ context.commands.add(CloseFind, { canExecute: () => this.finder?.isOpen === true, execute: () => this.finder.close() });
35
+ context.keys.add('Mod-f', OpenFind);
36
+ context.keys.add('Mod-h', OpenFindAndReplace);
37
+ context.keys.add('Mod-Shift-h', OpenFindAndReplace);
38
+ context.keys.add('Mod-g', FindNext);
39
+ context.keys.add('Mod-Shift-g', FindPrevious);
40
+ context.keys.add('Escape', CloseFind);
41
+ context.menus.toolbar.add({ command: OpenFindAndReplace, label: 'Find and replace', icon: 'search', group: 'find', order: -18 });
42
+ }
43
+ attach(page) {
44
+ const host = page.root.parentElement;
45
+ if (this.editor === null || host === null)
46
+ return;
47
+ defineElements();
48
+ this.finder = new Finder(this.editor, page.root, host);
49
+ }
50
+ dispose() {
51
+ this.finder?.dispose();
52
+ this.finder = null;
53
+ }
54
+ }
55
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,YAAY,EAAsB,MAAM,0BAA0B,CAAC;AAC1G,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACjI,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAEjI;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,UAAW,SAAQ,YAAY;IACxB,IAAI,GAAG,MAAM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AC,aAAa,CAAC;QACrC,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO;QAClD,cAAc,EAAE,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACzD,CAAC;IAEQ,OAAO;QACd,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACrB,CAAC;CACF"}
@@ -0,0 +1,60 @@
1
+ import type { SearchOptions } from './search.js';
2
+ /** What the panel asks for, when someone uses it. */
3
+ export interface PanelActions {
4
+ /** What to look for, or how, has changed. */
5
+ readonly search: () => void;
6
+ readonly next: () => void;
7
+ readonly previous: () => void;
8
+ readonly replace: () => void;
9
+ readonly replaceAll: () => void;
10
+ readonly close: () => void;
11
+ /** Words in the page's language, from the editor. */
12
+ readonly translate: (text: string, values?: Readonly<Record<string, string>>) => string;
13
+ }
14
+ /** Before any of them is made, because an element made first would lose what it is given. Each is safe to call twice, or from two packages. */
15
+ export declare function defineElements(): void;
16
+ /** Command on a Mac and Control elsewhere, as the editor reads `Mod` in its keys. */
17
+ export declare function hasModifier(event: KeyboardEvent): boolean;
18
+ /**
19
+ * A strip before the document, which the stylesheet keeps at the top of the view as the page scrolls, with the panel at its end. It is a search region with a name, its
20
+ * fields and buttons are named, and the count is a status, so a screen reader says it as it changes.
21
+ */
22
+ export declare class FindPanel {
23
+ private readonly actions;
24
+ readonly element: HTMLDivElement;
25
+ private readonly box;
26
+ private readonly findField;
27
+ private readonly replaceField;
28
+ private readonly count;
29
+ private readonly previousButton;
30
+ private readonly nextButton;
31
+ private readonly closeButton;
32
+ private readonly replaceButton;
33
+ private readonly replaceAllButton;
34
+ private readonly replaceRow;
35
+ private readonly matchCase;
36
+ private readonly wholeWord;
37
+ private isReplaceAsked;
38
+ private isReadOnly;
39
+ constructor(actions: PanelActions);
40
+ get isOpen(): boolean;
41
+ /** Whether the keyboard is in the panel. */
42
+ get hasFocus(): boolean;
43
+ get query(): string;
44
+ set query(text: string);
45
+ get replacement(): string;
46
+ get options(): SearchOptions;
47
+ /** Whether replacing is offered now. It never is in a read-only editor. */
48
+ get showsReplace(): boolean;
49
+ open(replace: boolean): void;
50
+ close(): void;
51
+ setReadOnly(readOnly: boolean): void;
52
+ /** Puts the keyboard in the field to look for, with what it holds selected, so that typing replaces it. */
53
+ focusFind(): void;
54
+ focusReplace(): void;
55
+ /** Where the current match is among them, such as "3 of 12", and what can be done with them. */
56
+ showCount(current: number, total: number, hasMore: boolean): void;
57
+ private update;
58
+ private onKey;
59
+ }
60
+ //# sourceMappingURL=panel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"panel.d.ts","sourceRoot":"","sources":["../src/panel.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAejD,qDAAqD;AACrD,MAAM,WAAW,YAAY;IAC3B,6CAA6C;IAC7C,QAAQ,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,IAAI,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,IAAI,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC;IAC3B,qDAAqD;IACrD,QAAQ,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,KAAK,MAAM,CAAC;CACzF;AAED,+IAA+I;AAC/I,wBAAgB,cAAc,IAAI,IAAI,CAErC;AAID,qFAAqF;AACrF,wBAAgB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nC;IAED,2GAA2G;IAC3G,SAAS,IAAI,IAAI,CAGhB;IAED,YAAY,IAAI,IAAI,CAGnB;IAED,gGAAgG;IAChG,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAShE;IAED,OAAO,CAAC,MAAM;IAKd,OAAO,CAAC,KAAK;CAgBd"}
package/dist/panel.js ADDED
@@ -0,0 +1,228 @@
1
+ // The panel find and replace are typed in, in Aranghat's components. It sits beside the document, never in it, because the editor owns everything inside its root.
2
+ import { defineCustomElement as defineButton } from '@aranghat/base/button';
3
+ import { defineCustomElement as defineCheckbox } from '@aranghat/base/checkbox';
4
+ import { defineCustomElement as defineIcon } from '@aranghat/base/icon';
5
+ import { defineCustomElement as defineInput } from '@aranghat/base/input';
6
+ import { defineCustomElement as defineLabel } from '@aranghat/base/label';
7
+ import { arrowDown } from '@minnalstack/icons/arrow-down';
8
+ import { arrowUp } from '@minnalstack/icons/arrow-up';
9
+ import { x } from '@minnalstack/icons/x';
10
+ /** Before any of them is made, because an element made first would lose what it is given. Each is safe to call twice, or from two packages. */
11
+ export function defineElements() {
12
+ for (const define of [defineButton, defineCheckbox, defineIcon, defineInput, defineLabel])
13
+ define();
14
+ }
15
+ const isMac = typeof navigator !== 'undefined' && /Mac|iP(hone|[oa]d)/.test(navigator.platform);
16
+ /** Command on a Mac and Control elsewhere, as the editor reads `Mod` in its keys. */
17
+ export function hasModifier(event) {
18
+ return isMac ? event.metaKey && !event.ctrlKey : event.ctrlKey && !event.metaKey;
19
+ }
20
+ /** Ids are looked up in the page, so each panel needs its own. */
21
+ let panels = 0;
22
+ function iconButton(label, icon, keys) {
23
+ const button = document.createElement('art-button');
24
+ button.setAttribute('variant', 'ghost');
25
+ button.setAttribute('size', 'sm');
26
+ button.setAttribute('icon', '');
27
+ button.setAttribute('aria-label', label);
28
+ button.setAttribute('aria-keyshortcuts', keys);
29
+ button.title = label;
30
+ const glyph = document.createElement('art-icon');
31
+ glyph.icon = icon;
32
+ button.append(glyph);
33
+ return button;
34
+ }
35
+ function textButton(label) {
36
+ const button = document.createElement('art-button');
37
+ button.setAttribute('variant', 'secondary');
38
+ button.setAttribute('size', 'sm');
39
+ button.append(label);
40
+ return button;
41
+ }
42
+ function input(label) {
43
+ const field = document.createElement('art-input');
44
+ field.setAttribute('size', 'sm');
45
+ field.setAttribute('aria-label', label);
46
+ field.setAttribute('autocomplete', 'off');
47
+ field.placeholder = label;
48
+ return field;
49
+ }
50
+ /** A checkbox with its name beside it, which a click on the name toggles too. */
51
+ function option(label, id) {
52
+ const checkbox = document.createElement('art-checkbox');
53
+ checkbox.id = id;
54
+ checkbox.setAttribute('size', 'sm');
55
+ const name = document.createElement('art-label');
56
+ name.setAttribute('for', id);
57
+ name.append(label);
58
+ const element = document.createElement('div');
59
+ element.className = 'mn-find-option';
60
+ element.append(checkbox, name);
61
+ return { element, checkbox };
62
+ }
63
+ function row(...children) {
64
+ const element = document.createElement('div');
65
+ element.className = 'mn-find-row';
66
+ element.append(...children);
67
+ return element;
68
+ }
69
+ /**
70
+ * A strip before the document, which the stylesheet keeps at the top of the view as the page scrolls, with the panel at its end. It is a search region with a name, its
71
+ * fields and buttons are named, and the count is a status, so a screen reader says it as it changes.
72
+ */
73
+ export class FindPanel {
74
+ actions;
75
+ element = document.createElement('div');
76
+ box = document.createElement('div');
77
+ findField = input('Find');
78
+ replaceField = input('Replace with');
79
+ count = document.createElement('span');
80
+ previousButton = iconButton('Previous match', arrowUp, 'Shift+Enter');
81
+ nextButton = iconButton('Next match', arrowDown, 'Enter');
82
+ closeButton = iconButton('Close find', x, 'Escape');
83
+ replaceButton = textButton('Replace');
84
+ replaceAllButton = textButton('Replace all');
85
+ replaceRow;
86
+ matchCase;
87
+ wholeWord;
88
+ isReplaceAsked = false;
89
+ isReadOnly = false;
90
+ constructor(actions) {
91
+ this.actions = actions;
92
+ const serial = ++panels;
93
+ // The controls are made before there is an editor to ask for their words, so they are named here.
94
+ const say = actions.translate;
95
+ for (const [field, name] of [[this.findField, 'Find'], [this.replaceField, 'Replace with']]) {
96
+ field.setAttribute('aria-label', say(name));
97
+ field.placeholder = say(name);
98
+ }
99
+ for (const [button, name] of [[this.previousButton, 'Previous match'], [this.nextButton, 'Next match'], [this.closeButton, 'Close find']]) {
100
+ button.setAttribute('aria-label', say(name));
101
+ button.title = say(name);
102
+ }
103
+ this.replaceButton.textContent = say('Replace');
104
+ this.replaceAllButton.textContent = say('Replace all');
105
+ this.element.className = 'mn-find';
106
+ this.element.hidden = true;
107
+ this.box.className = 'mn-find-panel';
108
+ this.box.setAttribute('role', 'search');
109
+ this.count.slot = 'end';
110
+ this.count.className = 'mn-find-count';
111
+ this.count.setAttribute('role', 'status');
112
+ this.count.setAttribute('aria-atomic', 'true');
113
+ this.findField.append(this.count);
114
+ const matchCase = option(say('Match case'), `mn-find-${serial}-case`);
115
+ const wholeWord = option(say('Whole word'), `mn-find-${serial}-word`);
116
+ this.matchCase = matchCase.checkbox;
117
+ this.wholeWord = wholeWord.checkbox;
118
+ this.replaceRow = row(this.replaceField, this.replaceButton, this.replaceAllButton);
119
+ const options = row(matchCase.element, wholeWord.element);
120
+ options.classList.add('mn-find-options');
121
+ this.box.append(row(this.findField, this.previousButton, this.nextButton, this.closeButton), this.replaceRow, options);
122
+ this.element.append(this.box);
123
+ this.findField.addEventListener('input', () => actions.search());
124
+ this.matchCase.addEventListener('change', () => actions.search());
125
+ this.wholeWord.addEventListener('change', () => actions.search());
126
+ this.previousButton.addEventListener('click', () => actions.previous());
127
+ this.nextButton.addEventListener('click', () => actions.next());
128
+ this.closeButton.addEventListener('click', () => actions.close());
129
+ this.replaceButton.addEventListener('click', () => actions.replace());
130
+ this.replaceAllButton.addEventListener('click', () => actions.replaceAll());
131
+ this.box.addEventListener('keydown', (event) => this.onKey(event));
132
+ // A press on the panel itself, between its controls, would take the keyboard out of it.
133
+ this.box.addEventListener('mousedown', (event) => {
134
+ if (event.target === this.box || event.target.classList.contains('mn-find-row'))
135
+ event.preventDefault();
136
+ });
137
+ }
138
+ get isOpen() {
139
+ return !this.element.hidden;
140
+ }
141
+ /** Whether the keyboard is in the panel. */
142
+ get hasFocus() {
143
+ return this.element.contains(document.activeElement);
144
+ }
145
+ get query() {
146
+ return this.findField.value;
147
+ }
148
+ set query(text) {
149
+ this.findField.value = text;
150
+ }
151
+ get replacement() {
152
+ return this.replaceField.value;
153
+ }
154
+ get options() {
155
+ return { matchCase: this.matchCase.checked === true, wholeWord: this.wholeWord.checked === true };
156
+ }
157
+ /** Whether replacing is offered now. It never is in a read-only editor. */
158
+ get showsReplace() {
159
+ return this.isReplaceAsked && !this.isReadOnly;
160
+ }
161
+ open(replace) {
162
+ this.isReplaceAsked ||= replace;
163
+ this.element.hidden = false;
164
+ this.update();
165
+ }
166
+ close() {
167
+ this.element.hidden = true;
168
+ this.isReplaceAsked = false;
169
+ }
170
+ setReadOnly(readOnly) {
171
+ this.isReadOnly = readOnly;
172
+ this.update();
173
+ }
174
+ /** Puts the keyboard in the field to look for, with what it holds selected, so that typing replaces it. */
175
+ focusFind() {
176
+ this.findField.focus();
177
+ void this.findField.select();
178
+ }
179
+ focusReplace() {
180
+ this.replaceField.focus();
181
+ void this.replaceField.select();
182
+ }
183
+ /** Where the current match is among them, such as "3 of 12", and what can be done with them. */
184
+ showCount(current, total, hasMore) {
185
+ if (this.query === '')
186
+ this.count.textContent = '';
187
+ else if (total === 0)
188
+ this.count.textContent = this.actions.translate('No results');
189
+ else
190
+ this.count.textContent = this.actions.translate('{current} of {total}', { current: (current + 1).toLocaleString(), total: `${total.toLocaleString()}${hasMore ? '+' : ''}` });
191
+ const buttons = [this.previousButton, this.nextButton, this.replaceButton, this.replaceAllButton];
192
+ const wasFocused = buttons.includes(document.activeElement);
193
+ for (const button of buttons)
194
+ button.disabled = total === 0;
195
+ // A button that is turned off loses the keyboard to the page, as after Replace all, and the panel's keys would stop working.
196
+ if (wasFocused && total === 0)
197
+ this.findField.focus();
198
+ }
199
+ update() {
200
+ this.replaceRow.hidden = !this.showsReplace;
201
+ this.box.setAttribute('aria-label', this.actions.translate(this.showsReplace ? 'Find and replace' : 'Find'));
202
+ }
203
+ onKey(event) {
204
+ if (event.isComposing)
205
+ return;
206
+ const key = event.key.toLowerCase();
207
+ const isPlain = !event.altKey && !event.ctrlKey && !event.metaKey;
208
+ if (event.key === 'Escape' && isPlain)
209
+ this.actions.close();
210
+ else if (event.key === 'Enter' && isPlain && event.target === this.findField)
211
+ (event.shiftKey ? this.actions.previous : this.actions.next)();
212
+ else if (event.key === 'Enter' && isPlain && !event.shiftKey && event.target === this.replaceField)
213
+ this.actions.replace();
214
+ else if (hasModifier(event) && !event.altKey && key === 'f' && !event.shiftKey)
215
+ this.focusFind();
216
+ else if (hasModifier(event) && !event.altKey && key === 'g')
217
+ (event.shiftKey ? this.actions.previous : this.actions.next)();
218
+ else if (hasModifier(event) && !event.altKey && key === 'h' && !this.isReadOnly) {
219
+ this.open(true);
220
+ this.focusReplace();
221
+ }
222
+ else
223
+ return;
224
+ event.preventDefault();
225
+ event.stopPropagation();
226
+ }
227
+ }
228
+ //# sourceMappingURL=panel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"panel.js","sourceRoot":"","sources":["../src/panel.ts"],"names":[],"mappings":"AAAA,mKAAmK;AACnK,OAAO,EAAE,mBAAmB,IAAI,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,mBAAmB,IAAI,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,mBAAmB,IAAI,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,mBAAmB,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,mBAAmB,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAE1E,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,OAAO,EAA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