@rrstudioapps/ngx-command-palette 0.0.0-stage → 0.1.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,1001 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { ChangeDetectionStrategy, Component, DOCUMENT, DestroyRef, Directive, Injectable, InjectionToken, TemplateRef, ViewEncapsulation, afterRenderEffect, assertInInjectionContext, computed, contentChild, inject, input, isSignal, makeEnvironmentProviders, signal, viewChild } from "@angular/core";
|
|
3
|
+
import { Router } from "@angular/router";
|
|
4
|
+
import { NgTemplateOutlet } from "@angular/common";
|
|
5
|
+
const DEFAULT_COMMAND_PALETTE_LABELS = {
|
|
6
|
+
placeholder: "Type a command or search…",
|
|
7
|
+
dialog: "Command palette",
|
|
8
|
+
listbox: "Commands",
|
|
9
|
+
empty: "No results found.",
|
|
10
|
+
loading: "Loading…",
|
|
11
|
+
recent: "Recent",
|
|
12
|
+
defaultGroup: "Commands",
|
|
13
|
+
results: "{count} results",
|
|
14
|
+
closeHint: "Esc"
|
|
15
|
+
};
|
|
16
|
+
const DEFAULT_COMMAND_PALETTE_CONFIG = {
|
|
17
|
+
shortcut: "mod+k",
|
|
18
|
+
theme: "auto",
|
|
19
|
+
recent: {
|
|
20
|
+
max: 5,
|
|
21
|
+
storageKey: "rr-cp:recent"
|
|
22
|
+
},
|
|
23
|
+
debounceMs: 200,
|
|
24
|
+
maxResults: 50,
|
|
25
|
+
labels: DEFAULT_COMMAND_PALETTE_LABELS
|
|
26
|
+
};
|
|
27
|
+
const COMMAND_PALETTE_CONFIG = new InjectionToken("COMMAND_PALETTE_CONFIG", {
|
|
28
|
+
providedIn: "root",
|
|
29
|
+
factory: () => DEFAULT_COMMAND_PALETTE_CONFIG
|
|
30
|
+
});
|
|
31
|
+
function resolveConfig(options = {}) {
|
|
32
|
+
return {
|
|
33
|
+
...DEFAULT_COMMAND_PALETTE_CONFIG,
|
|
34
|
+
...options,
|
|
35
|
+
recent: options.recent === false ? false : {
|
|
36
|
+
...DEFAULT_COMMAND_PALETTE_CONFIG.recent,
|
|
37
|
+
...options.recent
|
|
38
|
+
},
|
|
39
|
+
labels: {
|
|
40
|
+
...DEFAULT_COMMAND_PALETTE_LABELS,
|
|
41
|
+
...options.labels
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function provideCommandPalette(options = {}) {
|
|
46
|
+
return makeEnvironmentProviders([{
|
|
47
|
+
provide: COMMAND_PALETTE_CONFIG,
|
|
48
|
+
useValue: resolveConfig(options)
|
|
49
|
+
}]);
|
|
50
|
+
}
|
|
51
|
+
const SCORE_CHAR = 1;
|
|
52
|
+
const BONUS_CONSECUTIVE = 5;
|
|
53
|
+
const BONUS_WORD_START = 8;
|
|
54
|
+
const BONUS_STRING_START = 4;
|
|
55
|
+
const PENALTY_GAP = 1;
|
|
56
|
+
const PENALTY_LEADING = .2;
|
|
57
|
+
const SEPARATORS = /* @__PURE__ */ new Set([
|
|
58
|
+
" ",
|
|
59
|
+
"-",
|
|
60
|
+
"_",
|
|
61
|
+
".",
|
|
62
|
+
"/",
|
|
63
|
+
":",
|
|
64
|
+
"(",
|
|
65
|
+
"[",
|
|
66
|
+
","
|
|
67
|
+
]);
|
|
68
|
+
function fold(char) {
|
|
69
|
+
return (char.normalize("NFD").replace(/\p{M}/gu, "")[0] ?? char).toLowerCase();
|
|
70
|
+
}
|
|
71
|
+
function isWordStart(text, i) {
|
|
72
|
+
if (i === 0) return true;
|
|
73
|
+
const prev = text[i - 1];
|
|
74
|
+
if (SEPARATORS.has(prev)) return true;
|
|
75
|
+
const cur = text[i];
|
|
76
|
+
return prev === prev.toLowerCase() && cur !== cur.toLowerCase() && cur === cur.toUpperCase();
|
|
77
|
+
}
|
|
78
|
+
function fuzzyMatch(query, text) {
|
|
79
|
+
const q = query.replace(/\s+/g, "").split("").map(fold);
|
|
80
|
+
if (q.length === 0) return {
|
|
81
|
+
score: 0,
|
|
82
|
+
indices: []
|
|
83
|
+
};
|
|
84
|
+
const t = [];
|
|
85
|
+
for (let i = 0; i < text.length; i++) t.push(fold(text[i]));
|
|
86
|
+
const m = q.length;
|
|
87
|
+
const n = t.length;
|
|
88
|
+
if (m > n) return null;
|
|
89
|
+
const NEG = -Infinity;
|
|
90
|
+
const M = [];
|
|
91
|
+
const D = [];
|
|
92
|
+
const bonus = new Float64Array(n);
|
|
93
|
+
for (let j = 0; j < n; j++) bonus[j] = SCORE_CHAR + (isWordStart(text, j) ? BONUS_WORD_START : 0) + (j === 0 ? BONUS_STRING_START : 0);
|
|
94
|
+
const consec = [];
|
|
95
|
+
const Dk = [];
|
|
96
|
+
for (let i = 0; i < m; i++) {
|
|
97
|
+
const Mi = new Float64Array(n).fill(NEG);
|
|
98
|
+
const Di = new Float64Array(n).fill(NEG);
|
|
99
|
+
const Ci = new Uint8Array(n);
|
|
100
|
+
const Ki = new Int32Array(n).fill(-1);
|
|
101
|
+
for (let j = i; j < n; j++) {
|
|
102
|
+
if (t[j] === q[i]) {
|
|
103
|
+
if (i === 0) Mi[j] = bonus[j] - PENALTY_LEADING * j;
|
|
104
|
+
else if (j > 0) {
|
|
105
|
+
const consecutive = M[i - 1][j - 1] + BONUS_CONSECUTIVE;
|
|
106
|
+
const jump = D[i - 1][j - 1];
|
|
107
|
+
if (consecutive >= jump && consecutive > NEG) {
|
|
108
|
+
Mi[j] = consecutive + bonus[j];
|
|
109
|
+
Ci[j] = 1;
|
|
110
|
+
} else if (jump > NEG) Mi[j] = jump + bonus[j];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const carried = j > 0 ? Di[j - 1] - PENALTY_GAP : NEG;
|
|
114
|
+
if (Mi[j] > NEG && Mi[j] >= carried) {
|
|
115
|
+
Di[j] = Mi[j];
|
|
116
|
+
Ki[j] = j;
|
|
117
|
+
} else if (j > 0) {
|
|
118
|
+
Di[j] = carried;
|
|
119
|
+
Ki[j] = Ki[j - 1];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
M.push(Mi);
|
|
123
|
+
D.push(Di);
|
|
124
|
+
consec.push(Ci);
|
|
125
|
+
Dk.push(Ki);
|
|
126
|
+
}
|
|
127
|
+
let end = -1;
|
|
128
|
+
let best = NEG;
|
|
129
|
+
for (let j = m - 1; j < n; j++) if (M[m - 1][j] > best) {
|
|
130
|
+
best = M[m - 1][j];
|
|
131
|
+
end = j;
|
|
132
|
+
}
|
|
133
|
+
if (end < 0) return null;
|
|
134
|
+
const indices = new Array(m);
|
|
135
|
+
let j = end;
|
|
136
|
+
for (let i = m - 1; i >= 0; i--) {
|
|
137
|
+
indices[i] = j;
|
|
138
|
+
if (i === 0) break;
|
|
139
|
+
j = consec[i][j] ? j - 1 : Dk[i - 1][j - 1];
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
score: best - (n - m) * .01,
|
|
143
|
+
indices
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function highlightSegments(text, indices) {
|
|
147
|
+
if (indices.length === 0) return text ? [{
|
|
148
|
+
text,
|
|
149
|
+
match: false
|
|
150
|
+
}] : [];
|
|
151
|
+
const set = new Set(indices);
|
|
152
|
+
const out = [];
|
|
153
|
+
let buf = "";
|
|
154
|
+
let bufMatch = set.has(0);
|
|
155
|
+
for (let i = 0; i < text.length; i++) {
|
|
156
|
+
const match = set.has(i);
|
|
157
|
+
if (match !== bufMatch && buf) {
|
|
158
|
+
out.push({
|
|
159
|
+
text: buf,
|
|
160
|
+
match: bufMatch
|
|
161
|
+
});
|
|
162
|
+
buf = "";
|
|
163
|
+
}
|
|
164
|
+
bufMatch = match;
|
|
165
|
+
buf += text[i];
|
|
166
|
+
}
|
|
167
|
+
if (buf) out.push({
|
|
168
|
+
text: buf,
|
|
169
|
+
match: bufMatch
|
|
170
|
+
});
|
|
171
|
+
return out;
|
|
172
|
+
}
|
|
173
|
+
const WEIGHT_KEYWORD = .8;
|
|
174
|
+
const WEIGHT_DESCRIPTION = .5;
|
|
175
|
+
const MIN_SECONDARY_QUALITY = 4;
|
|
176
|
+
function strongEnough(match, query) {
|
|
177
|
+
const length = query.replace(/\s+/g, "").length;
|
|
178
|
+
return !!match && length > 0 && match.score / length >= MIN_SECONDARY_QUALITY;
|
|
179
|
+
}
|
|
180
|
+
function matchCommand(query, command) {
|
|
181
|
+
const label = fuzzyMatch(query, command.label);
|
|
182
|
+
let best = label;
|
|
183
|
+
for (const keyword of command.keywords ?? []) {
|
|
184
|
+
const m = fuzzyMatch(query, keyword);
|
|
185
|
+
if (strongEnough(m, query) && (!best || m.score * WEIGHT_KEYWORD > best.score)) best = {
|
|
186
|
+
score: m.score * WEIGHT_KEYWORD,
|
|
187
|
+
indices: label?.indices ?? []
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
if (command.description) {
|
|
191
|
+
const m = fuzzyMatch(query, command.description);
|
|
192
|
+
if (strongEnough(m, query) && (!best || m.score * WEIGHT_DESCRIPTION > best.score)) best = {
|
|
193
|
+
score: m.score * WEIGHT_DESCRIPTION,
|
|
194
|
+
indices: label?.indices ?? []
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
return best;
|
|
198
|
+
}
|
|
199
|
+
var RecentStore = class {
|
|
200
|
+
storageKey;
|
|
201
|
+
max;
|
|
202
|
+
storage;
|
|
203
|
+
constructor(storageKey, max, storage = defaultStorage()) {
|
|
204
|
+
this.storageKey = storageKey;
|
|
205
|
+
this.max = max;
|
|
206
|
+
this.storage = storage;
|
|
207
|
+
}
|
|
208
|
+
load() {
|
|
209
|
+
if (!this.storage || this.max <= 0) return [];
|
|
210
|
+
try {
|
|
211
|
+
const raw = this.storage.getItem(this.storageKey);
|
|
212
|
+
if (!raw) return [];
|
|
213
|
+
const parsed = JSON.parse(raw);
|
|
214
|
+
if (!Array.isArray(parsed)) return [];
|
|
215
|
+
return parsed.filter(isEntry).slice(0, this.max);
|
|
216
|
+
} catch {
|
|
217
|
+
return [];
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
add(command, current = this.load()) {
|
|
221
|
+
if (this.max <= 0) return [];
|
|
222
|
+
const next = [{
|
|
223
|
+
id: command.id,
|
|
224
|
+
label: command.label,
|
|
225
|
+
...command.group ? { group: command.group } : {},
|
|
226
|
+
...command.description ? { description: command.description } : {},
|
|
227
|
+
...command.route !== void 0 && isSerializable(command.route) ? { route: command.route } : {}
|
|
228
|
+
}, ...current.filter((e) => e.id !== command.id)].slice(0, this.max);
|
|
229
|
+
this.save(next);
|
|
230
|
+
return next;
|
|
231
|
+
}
|
|
232
|
+
clear() {
|
|
233
|
+
try {
|
|
234
|
+
this.storage?.removeItem(this.storageKey);
|
|
235
|
+
} catch {}
|
|
236
|
+
}
|
|
237
|
+
save(entries) {
|
|
238
|
+
try {
|
|
239
|
+
this.storage?.setItem(this.storageKey, JSON.stringify(entries));
|
|
240
|
+
} catch {}
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
function defaultStorage() {
|
|
244
|
+
try {
|
|
245
|
+
return typeof localStorage === "undefined" ? null : localStorage;
|
|
246
|
+
} catch {
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
function isEntry(value) {
|
|
251
|
+
if (!value || typeof value !== "object") return false;
|
|
252
|
+
const v = value;
|
|
253
|
+
return typeof v["id"] === "string" && typeof v["label"] === "string";
|
|
254
|
+
}
|
|
255
|
+
function isSerializable(route) {
|
|
256
|
+
try {
|
|
257
|
+
JSON.stringify(route);
|
|
258
|
+
return typeof route === "string" || Array.isArray(route);
|
|
259
|
+
} catch {
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
const RECENT_SECTION_ID = "recent";
|
|
264
|
+
var CommandPaletteService = class CommandPaletteService {
|
|
265
|
+
config = inject(COMMAND_PALETTE_CONFIG);
|
|
266
|
+
router = inject(Router, { optional: true });
|
|
267
|
+
document = inject(DOCUMENT);
|
|
268
|
+
recentStore = this.config.recent ? new RecentStore(this.config.recent.storageKey ?? "rr-cp:recent", this.config.recent.max ?? 5) : null;
|
|
269
|
+
_isOpen = signal(false, ...ngDevMode ? [{ debugName: "_isOpen" }] : /* istanbul ignore next */ []);
|
|
270
|
+
_query = signal("", ...ngDevMode ? [{ debugName: "_query" }] : /* istanbul ignore next */ []);
|
|
271
|
+
registrations = signal([], ...ngDevMode ? [{ debugName: "registrations" }] : /* istanbul ignore next */ []);
|
|
272
|
+
providers = signal([], ...ngDevMode ? [{ debugName: "providers" }] : /* istanbul ignore next */ []);
|
|
273
|
+
providerState = signal(/* @__PURE__ */ new Map(), ...ngDevMode ? [{ debugName: "providerState" }] : /* istanbul ignore next */ []);
|
|
274
|
+
recents = signal(this.recentStore?.load() ?? [], ...ngDevMode ? [{ debugName: "recents" }] : /* istanbul ignore next */ []);
|
|
275
|
+
pending = /* @__PURE__ */ new Map();
|
|
276
|
+
returnFocus = null;
|
|
277
|
+
isOpen = this._isOpen.asReadonly();
|
|
278
|
+
query = this._query.asReadonly();
|
|
279
|
+
commands = computed(() => {
|
|
280
|
+
const byId = /* @__PURE__ */ new Map();
|
|
281
|
+
for (const registration of this.registrations()) for (const command of registration.source()) {
|
|
282
|
+
byId.delete(command.id);
|
|
283
|
+
byId.set(command.id, command);
|
|
284
|
+
}
|
|
285
|
+
return [...byId.values()];
|
|
286
|
+
}, ...ngDevMode ? [{ debugName: "commands" }] : /* istanbul ignore next */ []);
|
|
287
|
+
loading = computed(() => [...this.providerState().values()].some((s) => s.loading), ...ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []);
|
|
288
|
+
sections = computed(() => this.buildSections(this._query().trim()), ...ngDevMode ? [{ debugName: "sections" }] : /* istanbul ignore next */ []);
|
|
289
|
+
open(query = "") {
|
|
290
|
+
if (!this._isOpen()) {
|
|
291
|
+
const active = this.document.activeElement;
|
|
292
|
+
this.returnFocus = active && active !== this.document.body && typeof active.focus === "function" ? active : null;
|
|
293
|
+
}
|
|
294
|
+
this._isOpen.set(true);
|
|
295
|
+
this.setQuery(query);
|
|
296
|
+
}
|
|
297
|
+
close() {
|
|
298
|
+
if (!this._isOpen()) return;
|
|
299
|
+
this._isOpen.set(false);
|
|
300
|
+
this.cancelAll();
|
|
301
|
+
this._query.set("");
|
|
302
|
+
this.providerState.set(/* @__PURE__ */ new Map());
|
|
303
|
+
const target = this.returnFocus;
|
|
304
|
+
this.returnFocus = null;
|
|
305
|
+
if (target?.isConnected) target.focus({ preventScroll: true });
|
|
306
|
+
}
|
|
307
|
+
toggle() {
|
|
308
|
+
if (this._isOpen()) this.close();
|
|
309
|
+
else this.open();
|
|
310
|
+
}
|
|
311
|
+
setQuery(query) {
|
|
312
|
+
this._query.set(query);
|
|
313
|
+
if (this._isOpen()) this.scheduleProviders();
|
|
314
|
+
}
|
|
315
|
+
register(commands, destroyRef) {
|
|
316
|
+
const registration = { source: isSignal(commands) ? commands : () => commands };
|
|
317
|
+
this.registrations.update((list) => [...list, registration]);
|
|
318
|
+
const remove = () => this.registrations.update((list) => list.filter((r) => r !== registration));
|
|
319
|
+
return this.bindToDestroy(remove, destroyRef);
|
|
320
|
+
}
|
|
321
|
+
registerProvider(provider, destroyRef) {
|
|
322
|
+
this.providers.update((list) => [...list.filter((p) => p.id !== provider.id), provider]);
|
|
323
|
+
if (this._isOpen()) this.scheduleProvider(provider, this._query());
|
|
324
|
+
const remove = () => {
|
|
325
|
+
if (!this.providers().includes(provider)) return;
|
|
326
|
+
this.cancel(provider.id);
|
|
327
|
+
this.providers.update((list) => list.filter((p) => p !== provider));
|
|
328
|
+
this.providerState.update((map) => {
|
|
329
|
+
const next = new Map(map);
|
|
330
|
+
next.delete(provider.id);
|
|
331
|
+
return next;
|
|
332
|
+
});
|
|
333
|
+
};
|
|
334
|
+
return this.bindToDestroy(remove, destroyRef);
|
|
335
|
+
}
|
|
336
|
+
async execute(command) {
|
|
337
|
+
if (command.disabled) return;
|
|
338
|
+
const query = this._query();
|
|
339
|
+
if (this.recentStore) this.recents.set(this.recentStore.add(command, this.recents()));
|
|
340
|
+
this.close();
|
|
341
|
+
if (command.route !== void 0) {
|
|
342
|
+
if (!this.router) throw new Error("ngx-command-palette: route commands need provideRouter()");
|
|
343
|
+
const { route, navigationExtras } = command;
|
|
344
|
+
await (typeof route === "string" ? this.router.navigateByUrl(route, navigationExtras) : this.router.navigate(route, navigationExtras));
|
|
345
|
+
} else await command.run({ query });
|
|
346
|
+
}
|
|
347
|
+
clearRecent() {
|
|
348
|
+
this.recentStore?.clear();
|
|
349
|
+
this.recents.set([]);
|
|
350
|
+
}
|
|
351
|
+
bindToDestroy(remove, destroyRef) {
|
|
352
|
+
const unsubscribe = (destroyRef ?? currentDestroyRef())?.onDestroy(remove);
|
|
353
|
+
return () => {
|
|
354
|
+
unsubscribe?.();
|
|
355
|
+
remove();
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
buildSections(query) {
|
|
359
|
+
const defaultGroup = this.config.labels.defaultGroup;
|
|
360
|
+
const commands = this.commands();
|
|
361
|
+
const groups = /* @__PURE__ */ new Map();
|
|
362
|
+
const push = (group, result) => {
|
|
363
|
+
const list = groups.get(group);
|
|
364
|
+
if (list) list.push(result);
|
|
365
|
+
else groups.set(group, [result]);
|
|
366
|
+
};
|
|
367
|
+
const sections = [];
|
|
368
|
+
if (!query) {
|
|
369
|
+
const recent = this.recentResults(commands);
|
|
370
|
+
if (recent.length) sections.push({
|
|
371
|
+
id: RECENT_SECTION_ID,
|
|
372
|
+
label: this.config.labels.recent,
|
|
373
|
+
items: recent
|
|
374
|
+
});
|
|
375
|
+
for (const command of commands) {
|
|
376
|
+
const group = command.group ?? defaultGroup;
|
|
377
|
+
push(group, toResult(command, `g:${group}:${command.id}`, 0, []));
|
|
378
|
+
}
|
|
379
|
+
} else {
|
|
380
|
+
const scored = [];
|
|
381
|
+
for (const command of commands) {
|
|
382
|
+
const match = matchCommand(query, command);
|
|
383
|
+
if (!match) continue;
|
|
384
|
+
const group = command.group ?? defaultGroup;
|
|
385
|
+
scored.push(toResult(command, `g:${group}:${command.id}`, match.score, match.indices));
|
|
386
|
+
}
|
|
387
|
+
scored.sort((a, b) => b.score - a.score);
|
|
388
|
+
for (const result of scored.slice(0, this.config.maxResults)) push(result.command.group ?? defaultGroup, result);
|
|
389
|
+
}
|
|
390
|
+
for (const [label, items] of groups) sections.push({
|
|
391
|
+
id: `g:${label}`,
|
|
392
|
+
label,
|
|
393
|
+
items
|
|
394
|
+
});
|
|
395
|
+
const states = this.providerState();
|
|
396
|
+
for (const provider of this.providers()) {
|
|
397
|
+
const state = states.get(provider.id);
|
|
398
|
+
if (!state?.items.length) continue;
|
|
399
|
+
const items = state.items.map((command) => {
|
|
400
|
+
const match = query ? fuzzyMatch(query, command.label) : null;
|
|
401
|
+
return toResult(command, `p:${provider.id}:${command.id}`, match?.score ?? 0, match?.indices ?? []);
|
|
402
|
+
});
|
|
403
|
+
sections.push({
|
|
404
|
+
id: `p:${provider.id}`,
|
|
405
|
+
label: provider.group,
|
|
406
|
+
items
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
return sections;
|
|
410
|
+
}
|
|
411
|
+
recentResults(commands) {
|
|
412
|
+
if (!this.recentStore) return [];
|
|
413
|
+
const byId = new Map(commands.map((c) => [c.id, c]));
|
|
414
|
+
const results = [];
|
|
415
|
+
for (const entry of this.recents()) {
|
|
416
|
+
const command = byId.get(entry.id) ?? (entry.route !== void 0 ? {
|
|
417
|
+
id: entry.id,
|
|
418
|
+
label: entry.label,
|
|
419
|
+
route: entry.route,
|
|
420
|
+
...entry.group ? { group: entry.group } : {},
|
|
421
|
+
...entry.description ? { description: entry.description } : {}
|
|
422
|
+
} : void 0);
|
|
423
|
+
if (command && !command.disabled) results.push(toResult(command, `r:${entry.id}`, 0, []));
|
|
424
|
+
}
|
|
425
|
+
return results;
|
|
426
|
+
}
|
|
427
|
+
scheduleProviders() {
|
|
428
|
+
const query = this._query();
|
|
429
|
+
for (const provider of this.providers()) this.scheduleProvider(provider, query);
|
|
430
|
+
}
|
|
431
|
+
scheduleProvider(provider, rawQuery) {
|
|
432
|
+
this.cancel(provider.id);
|
|
433
|
+
const query = rawQuery.trim();
|
|
434
|
+
if (query.length < (provider.minQueryLength ?? 1)) {
|
|
435
|
+
this.setProviderState(provider.id, null);
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
const previous = this.providerState().get(provider.id);
|
|
439
|
+
this.setProviderState(provider.id, {
|
|
440
|
+
items: previous?.items ?? [],
|
|
441
|
+
loading: true
|
|
442
|
+
});
|
|
443
|
+
const request = {};
|
|
444
|
+
this.pending.set(provider.id, request);
|
|
445
|
+
request.timer = setTimeout(() => {
|
|
446
|
+
request.timer = void 0;
|
|
447
|
+
const controller = new AbortController();
|
|
448
|
+
request.controller = controller;
|
|
449
|
+
const done = (state) => {
|
|
450
|
+
if (!controller.signal.aborted && this.pending.get(provider.id) === request) this.setProviderState(provider.id, state);
|
|
451
|
+
};
|
|
452
|
+
let result;
|
|
453
|
+
try {
|
|
454
|
+
result = provider.search(query, controller.signal);
|
|
455
|
+
} catch (error) {
|
|
456
|
+
done({
|
|
457
|
+
items: [],
|
|
458
|
+
loading: false,
|
|
459
|
+
error
|
|
460
|
+
});
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
if (isSubscribable(result)) request.subscription = result.subscribe({
|
|
464
|
+
next: (items) => done({
|
|
465
|
+
items,
|
|
466
|
+
loading: false
|
|
467
|
+
}),
|
|
468
|
+
error: (error) => done({
|
|
469
|
+
items: [],
|
|
470
|
+
loading: false,
|
|
471
|
+
error
|
|
472
|
+
}),
|
|
473
|
+
complete: () => {
|
|
474
|
+
const state = this.providerState().get(provider.id);
|
|
475
|
+
if (state?.loading) done({
|
|
476
|
+
items: state.items,
|
|
477
|
+
loading: false
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
else Promise.resolve(result).then((items) => done({
|
|
482
|
+
items,
|
|
483
|
+
loading: false
|
|
484
|
+
}), (error) => done({
|
|
485
|
+
items: [],
|
|
486
|
+
loading: false,
|
|
487
|
+
error
|
|
488
|
+
}));
|
|
489
|
+
}, provider.debounceMs ?? this.config.debounceMs);
|
|
490
|
+
}
|
|
491
|
+
setProviderState(id, state) {
|
|
492
|
+
this.providerState.update((map) => {
|
|
493
|
+
const next = new Map(map);
|
|
494
|
+
if (state) next.set(id, state);
|
|
495
|
+
else next.delete(id);
|
|
496
|
+
return next;
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
cancel(id) {
|
|
500
|
+
const request = this.pending.get(id);
|
|
501
|
+
if (!request) return;
|
|
502
|
+
this.pending.delete(id);
|
|
503
|
+
if (request.timer) clearTimeout(request.timer);
|
|
504
|
+
request.controller?.abort();
|
|
505
|
+
request.subscription?.unsubscribe();
|
|
506
|
+
}
|
|
507
|
+
cancelAll() {
|
|
508
|
+
for (const id of [...this.pending.keys()]) this.cancel(id);
|
|
509
|
+
}
|
|
510
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
511
|
+
minVersion: "12.0.0",
|
|
512
|
+
version: "22.2.4",
|
|
513
|
+
ngImport: i0,
|
|
514
|
+
type: CommandPaletteService,
|
|
515
|
+
deps: [],
|
|
516
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
517
|
+
});
|
|
518
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
519
|
+
minVersion: "12.0.0",
|
|
520
|
+
version: "22.2.4",
|
|
521
|
+
ngImport: i0,
|
|
522
|
+
type: CommandPaletteService,
|
|
523
|
+
providedIn: "root"
|
|
524
|
+
});
|
|
525
|
+
};
|
|
526
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
527
|
+
minVersion: "12.0.0",
|
|
528
|
+
version: "22.2.4",
|
|
529
|
+
ngImport: i0,
|
|
530
|
+
type: CommandPaletteService,
|
|
531
|
+
decorators: [{
|
|
532
|
+
type: Injectable,
|
|
533
|
+
args: [{ providedIn: "root" }]
|
|
534
|
+
}]
|
|
535
|
+
});
|
|
536
|
+
function toResult(command, key, score, indices) {
|
|
537
|
+
return {
|
|
538
|
+
command,
|
|
539
|
+
key,
|
|
540
|
+
score,
|
|
541
|
+
indices,
|
|
542
|
+
segments: highlightSegments(command.label, indices)
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
function isSubscribable(value) {
|
|
546
|
+
return !!value && typeof value.subscribe === "function";
|
|
547
|
+
}
|
|
548
|
+
function currentDestroyRef() {
|
|
549
|
+
try {
|
|
550
|
+
return inject(DestroyRef, { optional: true });
|
|
551
|
+
} catch {
|
|
552
|
+
return null;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
function injectCommands(commands) {
|
|
556
|
+
assertInInjectionContext(injectCommands);
|
|
557
|
+
return inject(CommandPaletteService).register(commands, inject(DestroyRef));
|
|
558
|
+
}
|
|
559
|
+
function injectCommandProvider(provider) {
|
|
560
|
+
assertInInjectionContext(injectCommandProvider);
|
|
561
|
+
return inject(CommandPaletteService).registerProvider(provider, inject(DestroyRef));
|
|
562
|
+
}
|
|
563
|
+
function keyToAction(event) {
|
|
564
|
+
if (event.isComposing) return null;
|
|
565
|
+
switch (event.key) {
|
|
566
|
+
case "ArrowDown": return "next";
|
|
567
|
+
case "ArrowUp": return "prev";
|
|
568
|
+
case "Home": return event.shiftKey ? null : "first";
|
|
569
|
+
case "End": return event.shiftKey ? null : "last";
|
|
570
|
+
case "PageUp": return "first";
|
|
571
|
+
case "PageDown": return "last";
|
|
572
|
+
case "Enter": return "select";
|
|
573
|
+
case "Escape": return "close";
|
|
574
|
+
case "n": return event.ctrlKey && !event.metaKey && !event.altKey ? "next" : null;
|
|
575
|
+
case "p": return event.ctrlKey && !event.metaKey && !event.altKey ? "prev" : null;
|
|
576
|
+
default: return null;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
function moveIndex(disabled, current, action) {
|
|
580
|
+
const count = disabled.length;
|
|
581
|
+
if (count === 0) return -1;
|
|
582
|
+
const findFrom = (start, step, wrap) => {
|
|
583
|
+
for (let n = 0, i = start; n < count; n++, i += step) {
|
|
584
|
+
if (wrap) i = (i + count) % count;
|
|
585
|
+
else if (i < 0 || i >= count) return -1;
|
|
586
|
+
if (!disabled[i]) return i;
|
|
587
|
+
}
|
|
588
|
+
return -1;
|
|
589
|
+
};
|
|
590
|
+
switch (action) {
|
|
591
|
+
case "first": return findFrom(0, 1, false);
|
|
592
|
+
case "last": return findFrom(count - 1, -1, false);
|
|
593
|
+
case "next": return current < 0 ? findFrom(0, 1, false) : findFrom(current + 1, 1, true);
|
|
594
|
+
case "prev": return current < 0 ? findFrom(count - 1, -1, false) : findFrom(current - 1, -1, true);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
const MODIFIERS = {
|
|
598
|
+
mod: "mod",
|
|
599
|
+
ctrl: "ctrl",
|
|
600
|
+
control: "ctrl",
|
|
601
|
+
meta: "meta",
|
|
602
|
+
cmd: "meta",
|
|
603
|
+
command: "meta",
|
|
604
|
+
alt: "alt",
|
|
605
|
+
option: "alt",
|
|
606
|
+
shift: "shift"
|
|
607
|
+
};
|
|
608
|
+
const KEY_ALIASES = {
|
|
609
|
+
space: " ",
|
|
610
|
+
esc: "escape",
|
|
611
|
+
slash: "/",
|
|
612
|
+
plus: "+"
|
|
613
|
+
};
|
|
614
|
+
function parseShortcut(shortcut) {
|
|
615
|
+
const parts = shortcut.toLowerCase().split("+").map((p) => p.trim()).filter(Boolean);
|
|
616
|
+
if (shortcut.trim().endsWith("++") || shortcut.trim() === "+") parts.push("+");
|
|
617
|
+
const result = {
|
|
618
|
+
key: "",
|
|
619
|
+
mod: false,
|
|
620
|
+
ctrl: false,
|
|
621
|
+
meta: false,
|
|
622
|
+
alt: false,
|
|
623
|
+
shift: false
|
|
624
|
+
};
|
|
625
|
+
for (const part of parts) {
|
|
626
|
+
const modifier = MODIFIERS[part];
|
|
627
|
+
if (modifier) result[modifier] = true;
|
|
628
|
+
else result.key = KEY_ALIASES[part] ?? part;
|
|
629
|
+
}
|
|
630
|
+
if (!result.key) throw new Error(`ngx-command-palette: invalid shortcut "${shortcut}"`);
|
|
631
|
+
return result;
|
|
632
|
+
}
|
|
633
|
+
function isApplePlatform(nav = globalThis.navigator) {
|
|
634
|
+
if (!nav) return false;
|
|
635
|
+
const platform = nav.userAgentData?.platform ?? nav.platform ?? "";
|
|
636
|
+
return /mac|iphone|ipad|ipod/i.test(platform);
|
|
637
|
+
}
|
|
638
|
+
function matchesShortcut(event, shortcut, apple) {
|
|
639
|
+
const wantCtrl = shortcut.ctrl || shortcut.mod && !apple;
|
|
640
|
+
const wantMeta = shortcut.meta || shortcut.mod && apple;
|
|
641
|
+
if (event.ctrlKey !== wantCtrl || event.metaKey !== wantMeta || event.altKey !== shortcut.alt) return false;
|
|
642
|
+
const key = (event.key ?? "").toLowerCase();
|
|
643
|
+
const isLetter = /^[a-z]$/.test(shortcut.key);
|
|
644
|
+
if ((shortcut.shift || isLetter) && event.shiftKey !== shortcut.shift) return false;
|
|
645
|
+
if (key === shortcut.key) return true;
|
|
646
|
+
if (isLetter && event.code === `Key${shortcut.key.toUpperCase()}`) return true;
|
|
647
|
+
if (/^[0-9]$/.test(shortcut.key) && event.code === `Digit${shortcut.key}`) return true;
|
|
648
|
+
return false;
|
|
649
|
+
}
|
|
650
|
+
function formatShortcut(shortcut, apple) {
|
|
651
|
+
const key = shortcut.key === " " ? "Space" : shortcut.key.length === 1 ? shortcut.key.toUpperCase() : capitalize(shortcut.key);
|
|
652
|
+
if (apple) return (shortcut.ctrl ? "⌃" : "") + (shortcut.alt ? "⌥" : "") + (shortcut.shift ? "⇧" : "") + (shortcut.meta || shortcut.mod ? "⌘" : "") + key;
|
|
653
|
+
const parts = [];
|
|
654
|
+
if (shortcut.ctrl || shortcut.mod) parts.push("Ctrl");
|
|
655
|
+
if (shortcut.meta) parts.push("Win");
|
|
656
|
+
if (shortcut.alt) parts.push("Alt");
|
|
657
|
+
if (shortcut.shift) parts.push("Shift");
|
|
658
|
+
parts.push(key);
|
|
659
|
+
return parts.join("+");
|
|
660
|
+
}
|
|
661
|
+
function capitalize(s) {
|
|
662
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
663
|
+
}
|
|
664
|
+
var CommandItemTemplate = class CommandItemTemplate {
|
|
665
|
+
template = inject(TemplateRef);
|
|
666
|
+
static ngTemplateContextGuard(_dir, ctx) {
|
|
667
|
+
return true;
|
|
668
|
+
}
|
|
669
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
670
|
+
minVersion: "12.0.0",
|
|
671
|
+
version: "22.2.4",
|
|
672
|
+
ngImport: i0,
|
|
673
|
+
type: CommandItemTemplate,
|
|
674
|
+
deps: [],
|
|
675
|
+
target: i0.ɵɵFactoryTarget.Directive
|
|
676
|
+
});
|
|
677
|
+
static ɵdir = i0.ɵɵngDeclareDirective({
|
|
678
|
+
minVersion: "14.0.0",
|
|
679
|
+
version: "22.2.4",
|
|
680
|
+
type: CommandItemTemplate,
|
|
681
|
+
isStandalone: true,
|
|
682
|
+
selector: "ng-template[rrCommandItem]",
|
|
683
|
+
ngImport: i0
|
|
684
|
+
});
|
|
685
|
+
};
|
|
686
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
687
|
+
minVersion: "12.0.0",
|
|
688
|
+
version: "22.2.4",
|
|
689
|
+
ngImport: i0,
|
|
690
|
+
type: CommandItemTemplate,
|
|
691
|
+
decorators: [{
|
|
692
|
+
type: Directive,
|
|
693
|
+
args: [{ selector: "ng-template[rrCommandItem]" }]
|
|
694
|
+
}]
|
|
695
|
+
});
|
|
696
|
+
var CommandEmptyTemplate = class CommandEmptyTemplate {
|
|
697
|
+
template = inject(TemplateRef);
|
|
698
|
+
static ngTemplateContextGuard(_dir, ctx) {
|
|
699
|
+
return true;
|
|
700
|
+
}
|
|
701
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
702
|
+
minVersion: "12.0.0",
|
|
703
|
+
version: "22.2.4",
|
|
704
|
+
ngImport: i0,
|
|
705
|
+
type: CommandEmptyTemplate,
|
|
706
|
+
deps: [],
|
|
707
|
+
target: i0.ɵɵFactoryTarget.Directive
|
|
708
|
+
});
|
|
709
|
+
static ɵdir = i0.ɵɵngDeclareDirective({
|
|
710
|
+
minVersion: "14.0.0",
|
|
711
|
+
version: "22.2.4",
|
|
712
|
+
type: CommandEmptyTemplate,
|
|
713
|
+
isStandalone: true,
|
|
714
|
+
selector: "ng-template[rrCommandEmpty]",
|
|
715
|
+
ngImport: i0
|
|
716
|
+
});
|
|
717
|
+
};
|
|
718
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
719
|
+
minVersion: "12.0.0",
|
|
720
|
+
version: "22.2.4",
|
|
721
|
+
ngImport: i0,
|
|
722
|
+
type: CommandEmptyTemplate,
|
|
723
|
+
decorators: [{
|
|
724
|
+
type: Directive,
|
|
725
|
+
args: [{ selector: "ng-template[rrCommandEmpty]" }]
|
|
726
|
+
}]
|
|
727
|
+
});
|
|
728
|
+
let nextId = 0;
|
|
729
|
+
const FOCUSABLE = "a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])";
|
|
730
|
+
var CommandPaletteComponent = class CommandPaletteComponent {
|
|
731
|
+
service = inject(CommandPaletteService);
|
|
732
|
+
config = inject(COMMAND_PALETTE_CONFIG);
|
|
733
|
+
document = inject(DOCUMENT);
|
|
734
|
+
theme = input(void 0, ...ngDevMode ? [{ debugName: "theme" }] : /* istanbul ignore next */ []);
|
|
735
|
+
itemTemplate = contentChild(CommandItemTemplate, ...ngDevMode ? [{ debugName: "itemTemplate" }] : /* istanbul ignore next */ []);
|
|
736
|
+
emptyTemplate = contentChild(CommandEmptyTemplate, ...ngDevMode ? [{ debugName: "emptyTemplate" }] : /* istanbul ignore next */ []);
|
|
737
|
+
input = viewChild("input", ...ngDevMode ? [{ debugName: "input" }] : /* istanbul ignore next */ []);
|
|
738
|
+
dialog = viewChild("dialog", ...ngDevMode ? [{ debugName: "dialog" }] : /* istanbul ignore next */ []);
|
|
739
|
+
uid = `rr-cp-${nextId++}`;
|
|
740
|
+
labels = this.config.labels;
|
|
741
|
+
apple = isApplePlatform();
|
|
742
|
+
shortcuts = (typeof this.config.shortcut === "string" ? [this.config.shortcut] : this.config.shortcut).map(parseShortcut);
|
|
743
|
+
shortcutLabel = this.shortcuts.length ? formatShortcut(this.shortcuts[0], this.apple) : "";
|
|
744
|
+
prefersDark = signal(false, ...ngDevMode ? [{ debugName: "prefersDark" }] : /* istanbul ignore next */ []);
|
|
745
|
+
resolvedTheme = computed(() => {
|
|
746
|
+
const theme = this.theme() ?? this.config.theme;
|
|
747
|
+
return theme === "auto" ? this.prefersDark() ? "dark" : "light" : theme;
|
|
748
|
+
}, ...ngDevMode ? [{ debugName: "resolvedTheme" }] : /* istanbul ignore next */ []);
|
|
749
|
+
view = computed(() => {
|
|
750
|
+
let index = 0;
|
|
751
|
+
return this.service.sections().map((section, sectionIndex) => ({
|
|
752
|
+
section,
|
|
753
|
+
headingId: `${this.uid}-group-${sectionIndex}`,
|
|
754
|
+
rows: section.items.map((item) => ({
|
|
755
|
+
item,
|
|
756
|
+
index: index++
|
|
757
|
+
}))
|
|
758
|
+
}));
|
|
759
|
+
}, ...ngDevMode ? [{ debugName: "view" }] : /* istanbul ignore next */ []);
|
|
760
|
+
items = computed(() => this.service.sections().flatMap((s) => s.items), ...ngDevMode ? [{ debugName: "items" }] : /* istanbul ignore next */ []);
|
|
761
|
+
activeKey = signal(null, ...ngDevMode ? [{ debugName: "activeKey" }] : /* istanbul ignore next */ []);
|
|
762
|
+
activeIndex = computed(() => {
|
|
763
|
+
const items = this.items();
|
|
764
|
+
const key = this.activeKey();
|
|
765
|
+
const found = key === null ? -1 : items.findIndex((i) => i.key === key);
|
|
766
|
+
if (found >= 0 && !items[found].command.disabled) return found;
|
|
767
|
+
return moveIndex(items.map((i) => !!i.command.disabled), -1, "first");
|
|
768
|
+
}, ...ngDevMode ? [{ debugName: "activeIndex" }] : /* istanbul ignore next */ []);
|
|
769
|
+
activeDescendant = computed(() => {
|
|
770
|
+
const index = this.activeIndex();
|
|
771
|
+
return index >= 0 ? this.optionId(index) : null;
|
|
772
|
+
}, ...ngDevMode ? [{ debugName: "activeDescendant" }] : /* istanbul ignore next */ []);
|
|
773
|
+
status = computed(() => {
|
|
774
|
+
if (this.service.loading()) return this.labels.loading;
|
|
775
|
+
const count = this.items().length;
|
|
776
|
+
return count === 0 ? this.labels.empty : this.labels.results.replace("{count}", String(count));
|
|
777
|
+
}, ...ngDevMode ? [{ debugName: "status" }] : /* istanbul ignore next */ []);
|
|
778
|
+
constructor() {
|
|
779
|
+
const media = this.document.defaultView?.matchMedia?.("(prefers-color-scheme: dark)");
|
|
780
|
+
if (media) {
|
|
781
|
+
this.prefersDark.set(media.matches);
|
|
782
|
+
const listener = (e) => this.prefersDark.set(e.matches);
|
|
783
|
+
media.addEventListener?.("change", listener);
|
|
784
|
+
inject(DestroyRef).onDestroy(() => media.removeEventListener?.("change", listener));
|
|
785
|
+
}
|
|
786
|
+
afterRenderEffect(() => {
|
|
787
|
+
const input = this.input()?.nativeElement;
|
|
788
|
+
if (input && this.document.activeElement !== input) input.focus({ preventScroll: true });
|
|
789
|
+
});
|
|
790
|
+
afterRenderEffect(() => {
|
|
791
|
+
const id = this.activeDescendant();
|
|
792
|
+
if (!id) return;
|
|
793
|
+
this.document.getElementById(id)?.scrollIntoView?.({ block: "nearest" });
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
optionId(index) {
|
|
797
|
+
return `${this.uid}-option-${index}`;
|
|
798
|
+
}
|
|
799
|
+
isTemplate(icon) {
|
|
800
|
+
return icon instanceof TemplateRef;
|
|
801
|
+
}
|
|
802
|
+
onInput(event) {
|
|
803
|
+
this.activeKey.set(null);
|
|
804
|
+
this.service.setQuery(event.target.value);
|
|
805
|
+
}
|
|
806
|
+
onKeydown(event) {
|
|
807
|
+
if (event.key === "Tab") {
|
|
808
|
+
this.trapTab(event);
|
|
809
|
+
return;
|
|
810
|
+
}
|
|
811
|
+
const action = keyToAction(event);
|
|
812
|
+
if (!action) return;
|
|
813
|
+
event.preventDefault();
|
|
814
|
+
event.stopPropagation();
|
|
815
|
+
const items = this.items();
|
|
816
|
+
switch (action) {
|
|
817
|
+
case "close":
|
|
818
|
+
this.service.close();
|
|
819
|
+
return;
|
|
820
|
+
case "select": {
|
|
821
|
+
const item = items[this.activeIndex()];
|
|
822
|
+
if (item) this.service.execute(item.command);
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
default: {
|
|
826
|
+
const next = moveIndex(items.map((i) => !!i.command.disabled), this.activeIndex(), action);
|
|
827
|
+
if (next >= 0) this.activeKey.set(items[next].key);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
onPointerMove(item) {
|
|
832
|
+
if (!item.command.disabled && this.activeKey() !== item.key) this.activeKey.set(item.key);
|
|
833
|
+
}
|
|
834
|
+
onSelect(item) {
|
|
835
|
+
this.service.execute(item.command);
|
|
836
|
+
}
|
|
837
|
+
onOverlayDown(event) {
|
|
838
|
+
if (event.target === event.currentTarget) this.service.close();
|
|
839
|
+
}
|
|
840
|
+
onDocumentKeydown(event) {
|
|
841
|
+
if (event.repeat || event.isComposing) return;
|
|
842
|
+
const typing = isEditable(event.target);
|
|
843
|
+
if (this.shortcuts.some((s) => (!typing || s.mod || s.ctrl || s.meta || s.alt) && matchesShortcut(event, s, this.apple))) {
|
|
844
|
+
event.preventDefault();
|
|
845
|
+
this.activeKey.set(null);
|
|
846
|
+
this.service.toggle();
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
onDocumentFocusin(event) {
|
|
850
|
+
if (!this.service.isOpen()) return;
|
|
851
|
+
const dialog = this.dialog()?.nativeElement;
|
|
852
|
+
if (dialog && event.target instanceof Node && !dialog.contains(event.target)) this.input()?.nativeElement.focus({ preventScroll: true });
|
|
853
|
+
}
|
|
854
|
+
trapTab(event) {
|
|
855
|
+
const dialog = this.dialog()?.nativeElement;
|
|
856
|
+
if (!dialog) return;
|
|
857
|
+
const focusable = Array.from(dialog.querySelectorAll(FOCUSABLE));
|
|
858
|
+
if (focusable.length <= 1) {
|
|
859
|
+
event.preventDefault();
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
const first = focusable[0];
|
|
863
|
+
const last = focusable[focusable.length - 1];
|
|
864
|
+
const active = this.document.activeElement;
|
|
865
|
+
if (event.shiftKey && active === first) {
|
|
866
|
+
event.preventDefault();
|
|
867
|
+
last.focus();
|
|
868
|
+
} else if (!event.shiftKey && active === last) {
|
|
869
|
+
event.preventDefault();
|
|
870
|
+
first.focus();
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
874
|
+
minVersion: "12.0.0",
|
|
875
|
+
version: "22.2.4",
|
|
876
|
+
ngImport: i0,
|
|
877
|
+
type: CommandPaletteComponent,
|
|
878
|
+
deps: [],
|
|
879
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
880
|
+
});
|
|
881
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
882
|
+
minVersion: "17.0.0",
|
|
883
|
+
version: "22.2.4",
|
|
884
|
+
type: CommandPaletteComponent,
|
|
885
|
+
isStandalone: true,
|
|
886
|
+
selector: "rr-command-palette",
|
|
887
|
+
inputs: { theme: {
|
|
888
|
+
classPropertyName: "theme",
|
|
889
|
+
publicName: "theme",
|
|
890
|
+
isSignal: true,
|
|
891
|
+
isRequired: false,
|
|
892
|
+
transformFunction: null
|
|
893
|
+
} },
|
|
894
|
+
host: {
|
|
895
|
+
listeners: {
|
|
896
|
+
"document:keydown": "onDocumentKeydown($event)",
|
|
897
|
+
"document:focusin": "onDocumentFocusin($event)"
|
|
898
|
+
},
|
|
899
|
+
classAttribute: "rr-cp-host"
|
|
900
|
+
},
|
|
901
|
+
queries: [{
|
|
902
|
+
propertyName: "itemTemplate",
|
|
903
|
+
first: true,
|
|
904
|
+
predicate: CommandItemTemplate,
|
|
905
|
+
descendants: true,
|
|
906
|
+
isSignal: true
|
|
907
|
+
}, {
|
|
908
|
+
propertyName: "emptyTemplate",
|
|
909
|
+
first: true,
|
|
910
|
+
predicate: CommandEmptyTemplate,
|
|
911
|
+
descendants: true,
|
|
912
|
+
isSignal: true
|
|
913
|
+
}],
|
|
914
|
+
viewQueries: [{
|
|
915
|
+
propertyName: "input",
|
|
916
|
+
first: true,
|
|
917
|
+
predicate: ["input"],
|
|
918
|
+
descendants: true,
|
|
919
|
+
isSignal: true
|
|
920
|
+
}, {
|
|
921
|
+
propertyName: "dialog",
|
|
922
|
+
first: true,
|
|
923
|
+
predicate: ["dialog"],
|
|
924
|
+
descendants: true,
|
|
925
|
+
isSignal: true
|
|
926
|
+
}],
|
|
927
|
+
ngImport: i0,
|
|
928
|
+
template: "@if (service.isOpen()) {\n <div class=\"rr-cp\" [attr.data-theme]=\"resolvedTheme()\" (mousedown)=\"onOverlayDown($event)\">\n <div\n #dialog\n class=\"rr-cp-dialog\"\n role=\"dialog\"\n aria-modal=\"true\"\n [attr.aria-label]=\"labels.dialog\"\n (keydown)=\"onKeydown($event)\"\n >\n <div class=\"rr-cp-search\">\n <svg\n class=\"rr-cp-search-icon\"\n viewBox=\"0 0 24 24\"\n width=\"18\"\n height=\"18\"\n aria-hidden=\"true\"\n >\n <circle cx=\"11\" cy=\"11\" r=\"7\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" />\n <path\n d=\"m20 20-3.5-3.5\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n />\n </svg>\n <input\n #input\n class=\"rr-cp-input\"\n type=\"text\"\n role=\"combobox\"\n aria-expanded=\"true\"\n aria-autocomplete=\"list\"\n aria-haspopup=\"listbox\"\n [attr.aria-controls]=\"uid + '-listbox'\"\n [attr.aria-activedescendant]=\"activeDescendant()\"\n [attr.aria-label]=\"labels.placeholder\"\n [placeholder]=\"labels.placeholder\"\n [value]=\"service.query()\"\n (input)=\"onInput($event)\"\n autocomplete=\"off\"\n autocapitalize=\"off\"\n spellcheck=\"false\"\n />\n @if (service.loading()) {\n <span class=\"rr-cp-spinner\" aria-hidden=\"true\"></span>\n }\n <kbd class=\"rr-cp-esc\" aria-hidden=\"true\">{{ labels.closeHint }}</kbd>\n </div>\n\n <div\n class=\"rr-cp-list\"\n role=\"listbox\"\n [id]=\"uid + '-listbox'\"\n [attr.aria-label]=\"labels.listbox\"\n [attr.aria-busy]=\"service.loading()\"\n >\n @for (group of view(); track group.section.id) {\n <div class=\"rr-cp-group\" role=\"group\" [attr.aria-labelledby]=\"group.headingId\">\n <!-- prettier-ignore -->\n <div class=\"rr-cp-group-label\" [id]=\"group.headingId\" aria-hidden=\"true\">{{ group.section.label }}</div>\n @for (row of group.rows; track row.item.key) {\n <!-- Combobox pattern: options never get focus, the keyboard goes through the input (aria-activedescendant) -->\n <!-- eslint-disable-next-line @angular-eslint/template/click-events-have-key-events, @angular-eslint/template/interactive-supports-focus -->\n <div\n class=\"rr-cp-item\"\n role=\"option\"\n [id]=\"optionId(row.index)\"\n [class.rr-cp-item-active]=\"row.index === activeIndex()\"\n [attr.aria-selected]=\"row.index === activeIndex()\"\n [attr.aria-disabled]=\"row.item.command.disabled ? true : null\"\n (mousedown)=\"$event.preventDefault()\"\n (mousemove)=\"onPointerMove(row.item)\"\n (click)=\"onSelect(row.item)\"\n >\n @if (itemTemplate(); as custom) {\n <ng-container\n [ngTemplateOutlet]=\"custom.template\"\n [ngTemplateOutletContext]=\"{\n $implicit: row.item.command,\n result: row.item,\n segments: row.item.segments,\n active: row.index === activeIndex(),\n query: service.query(),\n }\"\n />\n } @else {\n @if (row.item.command.icon; as icon) {\n <span class=\"rr-cp-icon\" aria-hidden=\"true\">\n @if (isTemplate(icon)) {\n <ng-container [ngTemplateOutlet]=\"icon\" />\n } @else {\n {{ icon }}\n }\n </span>\n }\n <span class=\"rr-cp-text\">\n <!-- Single line: line breaks would become spaces inside the label -->\n <!-- prettier-ignore -->\n <span class=\"rr-cp-label\">@for (segment of row.item.segments; track $index) {@if (segment.match) {<mark class=\"rr-cp-match\">{{ segment.text }}</mark>} @else {{{ segment.text }}}}</span>\n @if (row.item.command.description) {\n <span class=\"rr-cp-description\">{{ row.item.command.description }}</span>\n }\n </span>\n @if (row.item.command.shortcut?.length) {\n <span class=\"rr-cp-shortcut\" aria-hidden=\"true\">\n @for (key of row.item.command.shortcut; track $index) {\n <kbd>{{ key }}</kbd>\n }\n </span>\n }\n }\n </div>\n }\n </div>\n }\n </div>\n\n @if (items().length === 0) {\n <div class=\"rr-cp-empty\">\n @if (service.loading()) {\n {{ labels.loading }}\n } @else if (emptyTemplate(); as custom) {\n <ng-container\n [ngTemplateOutlet]=\"custom.template\"\n [ngTemplateOutletContext]=\"{ $implicit: service.query() }\"\n />\n } @else {\n {{ labels.empty }}\n }\n </div>\n }\n\n <div class=\"rr-cp-sr-only\" aria-live=\"polite\" aria-atomic=\"true\">{{ status() }}</div>\n </div>\n </div>\n}\n",
|
|
929
|
+
styles: [":where(.rr-cp){--rr-cp-font: system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif;--rr-cp-font-size: .9375rem;--rr-cp-width: 640px;--rr-cp-max-height: min(420px, 60vh);--rr-cp-top: 12vh;--rr-cp-radius: 12px;--rr-cp-item-radius: 8px;--rr-cp-z-index: 1000;--rr-cp-bg: #ffffff;--rr-cp-fg: #18181b;--rr-cp-muted: #71717a;--rr-cp-border: #e4e4e7;--rr-cp-accent: #4f46e5;--rr-cp-item-active-bg: #f4f4f5;--rr-cp-highlight: #4f46e5;--rr-cp-highlight-bg: transparent;--rr-cp-kbd-bg: #f4f4f5;--rr-cp-kbd-fg: #52525b;--rr-cp-backdrop: rgb(9 9 11 / .4);--rr-cp-shadow: 0 16px 70px rgb(0 0 0 / .2);--rr-cp-duration: .14s}:where(.rr-cp[data-theme=dark]){--rr-cp-bg: #18181b;--rr-cp-fg: #f4f4f5;--rr-cp-muted: #a1a1aa;--rr-cp-border: #27272a;--rr-cp-accent: #818cf8;--rr-cp-item-active-bg: #27272a;--rr-cp-highlight: #a5b4fc;--rr-cp-kbd-bg: #27272a;--rr-cp-kbd-fg: #d4d4d8;--rr-cp-backdrop: rgb(0 0 0 / .6);--rr-cp-shadow: 0 16px 70px rgb(0 0 0 / .6)}.rr-cp-host{display:contents}.rr-cp{position:fixed;inset:0;z-index:var(--rr-cp-z-index);display:flex;justify-content:center;align-items:flex-start;padding:var(--rr-cp-top) 16px 16px;background:var(--rr-cp-backdrop);color-scheme:light;animation:rr-cp-fade var(--rr-cp-duration) ease-out}.rr-cp[data-theme=dark]{color-scheme:dark}.rr-cp-dialog{box-sizing:border-box;display:flex;flex-direction:column;width:100%;max-width:var(--rr-cp-width);overflow:hidden;border:1px solid var(--rr-cp-border);border-radius:var(--rr-cp-radius);background:var(--rr-cp-bg);color:var(--rr-cp-fg);box-shadow:var(--rr-cp-shadow);font-family:var(--rr-cp-font);font-size:var(--rr-cp-font-size);line-height:1.4;animation:rr-cp-pop var(--rr-cp-duration) ease-out}.rr-cp-search{display:flex;align-items:center;gap:10px;padding:0 14px;border-bottom:1px solid var(--rr-cp-border)}.rr-cp-search-icon{flex:none;color:var(--rr-cp-muted)}.rr-cp-input{flex:1;min-width:0;height:52px;padding:0;border:0;outline:0;background:transparent;color:inherit;font:inherit;font-size:1rem}.rr-cp-input::placeholder{color:var(--rr-cp-muted);opacity:1}.rr-cp-list{max-height:var(--rr-cp-max-height);overflow-y:auto;overscroll-behavior:contain;padding:6px;scroll-padding:6px}.rr-cp-list:empty{display:none}.rr-cp-group+.rr-cp-group{margin-top:4px}.rr-cp-group-label{padding:8px 10px 4px;color:var(--rr-cp-muted);font-size:.75rem;font-weight:600;letter-spacing:.02em}.rr-cp-item{display:flex;align-items:center;gap:10px;min-height:40px;padding:6px 10px;border-radius:var(--rr-cp-item-radius);cursor:pointer;-webkit-user-select:none;user-select:none}.rr-cp-item-active{background:var(--rr-cp-item-active-bg);box-shadow:inset 2px 0 0 var(--rr-cp-accent)}.rr-cp-item[aria-disabled=true]{cursor:default;opacity:.5}.rr-cp-icon{display:inline-flex;flex:none;align-items:center;justify-content:center;width:20px;height:20px;color:var(--rr-cp-muted)}.rr-cp-item-active .rr-cp-icon{color:var(--rr-cp-fg)}.rr-cp-text{display:flex;flex:1;flex-direction:column;min-width:0}.rr-cp-label,.rr-cp-description{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.rr-cp-description{color:var(--rr-cp-muted);font-size:.8125rem}.rr-cp-match{background:var(--rr-cp-highlight-bg);color:var(--rr-cp-highlight);font-weight:600}.rr-cp-shortcut{display:inline-flex;flex:none;gap:4px}.rr-cp kbd{display:inline-flex;align-items:center;justify-content:center;min-width:20px;height:20px;padding:0 5px;box-sizing:border-box;border:1px solid var(--rr-cp-border);border-radius:4px;background:var(--rr-cp-kbd-bg);color:var(--rr-cp-kbd-fg);font-family:inherit;font-size:.6875rem;font-weight:500}.rr-cp-empty{padding:32px 16px;color:var(--rr-cp-muted);text-align:center}.rr-cp-spinner{flex:none;width:14px;height:14px;border:2px solid var(--rr-cp-border);border-top-color:var(--rr-cp-accent);border-radius:50%;animation:rr-cp-spin .7s linear infinite}.rr-cp-sr-only{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap;border:0}@keyframes rr-cp-fade{0%{opacity:0}}@keyframes rr-cp-pop{0%{opacity:0;transform:scale(.98) translateY(-4px)}}@keyframes rr-cp-spin{to{transform:rotate(360deg)}}@media(prefers-reduced-motion:reduce){.rr-cp,.rr-cp-dialog{animation:none}.rr-cp-spinner{animation-duration:2s}}@media(max-width:480px){:where(.rr-cp){--rr-cp-top: 8px;--rr-cp-max-height: calc(100dvh - 90px) }.rr-cp-shortcut{display:none}}@media(forced-colors:active){.rr-cp-item-active{outline:2px solid Highlight}.rr-cp-match{text-decoration:underline}}\n"],
|
|
930
|
+
dependencies: [{
|
|
931
|
+
kind: "directive",
|
|
932
|
+
type: NgTemplateOutlet,
|
|
933
|
+
selector: "[ngTemplateOutlet]",
|
|
934
|
+
inputs: [
|
|
935
|
+
"ngTemplateOutletContext",
|
|
936
|
+
"ngTemplateOutlet",
|
|
937
|
+
"ngTemplateOutletInjector"
|
|
938
|
+
]
|
|
939
|
+
}],
|
|
940
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush,
|
|
941
|
+
encapsulation: i0.ViewEncapsulation.None
|
|
942
|
+
});
|
|
943
|
+
};
|
|
944
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
945
|
+
minVersion: "12.0.0",
|
|
946
|
+
version: "22.2.4",
|
|
947
|
+
ngImport: i0,
|
|
948
|
+
type: CommandPaletteComponent,
|
|
949
|
+
decorators: [{
|
|
950
|
+
type: Component,
|
|
951
|
+
args: [{
|
|
952
|
+
selector: "rr-command-palette",
|
|
953
|
+
imports: [NgTemplateOutlet],
|
|
954
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
955
|
+
encapsulation: ViewEncapsulation.None,
|
|
956
|
+
host: {
|
|
957
|
+
class: "rr-cp-host",
|
|
958
|
+
"(document:keydown)": "onDocumentKeydown($event)",
|
|
959
|
+
"(document:focusin)": "onDocumentFocusin($event)"
|
|
960
|
+
},
|
|
961
|
+
template: "@if (service.isOpen()) {\n <div class=\"rr-cp\" [attr.data-theme]=\"resolvedTheme()\" (mousedown)=\"onOverlayDown($event)\">\n <div\n #dialog\n class=\"rr-cp-dialog\"\n role=\"dialog\"\n aria-modal=\"true\"\n [attr.aria-label]=\"labels.dialog\"\n (keydown)=\"onKeydown($event)\"\n >\n <div class=\"rr-cp-search\">\n <svg\n class=\"rr-cp-search-icon\"\n viewBox=\"0 0 24 24\"\n width=\"18\"\n height=\"18\"\n aria-hidden=\"true\"\n >\n <circle cx=\"11\" cy=\"11\" r=\"7\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" />\n <path\n d=\"m20 20-3.5-3.5\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n />\n </svg>\n <input\n #input\n class=\"rr-cp-input\"\n type=\"text\"\n role=\"combobox\"\n aria-expanded=\"true\"\n aria-autocomplete=\"list\"\n aria-haspopup=\"listbox\"\n [attr.aria-controls]=\"uid + '-listbox'\"\n [attr.aria-activedescendant]=\"activeDescendant()\"\n [attr.aria-label]=\"labels.placeholder\"\n [placeholder]=\"labels.placeholder\"\n [value]=\"service.query()\"\n (input)=\"onInput($event)\"\n autocomplete=\"off\"\n autocapitalize=\"off\"\n spellcheck=\"false\"\n />\n @if (service.loading()) {\n <span class=\"rr-cp-spinner\" aria-hidden=\"true\"></span>\n }\n <kbd class=\"rr-cp-esc\" aria-hidden=\"true\">{{ labels.closeHint }}</kbd>\n </div>\n\n <div\n class=\"rr-cp-list\"\n role=\"listbox\"\n [id]=\"uid + '-listbox'\"\n [attr.aria-label]=\"labels.listbox\"\n [attr.aria-busy]=\"service.loading()\"\n >\n @for (group of view(); track group.section.id) {\n <div class=\"rr-cp-group\" role=\"group\" [attr.aria-labelledby]=\"group.headingId\">\n <!-- prettier-ignore -->\n <div class=\"rr-cp-group-label\" [id]=\"group.headingId\" aria-hidden=\"true\">{{ group.section.label }}</div>\n @for (row of group.rows; track row.item.key) {\n <!-- Combobox pattern: options never get focus, the keyboard goes through the input (aria-activedescendant) -->\n <!-- eslint-disable-next-line @angular-eslint/template/click-events-have-key-events, @angular-eslint/template/interactive-supports-focus -->\n <div\n class=\"rr-cp-item\"\n role=\"option\"\n [id]=\"optionId(row.index)\"\n [class.rr-cp-item-active]=\"row.index === activeIndex()\"\n [attr.aria-selected]=\"row.index === activeIndex()\"\n [attr.aria-disabled]=\"row.item.command.disabled ? true : null\"\n (mousedown)=\"$event.preventDefault()\"\n (mousemove)=\"onPointerMove(row.item)\"\n (click)=\"onSelect(row.item)\"\n >\n @if (itemTemplate(); as custom) {\n <ng-container\n [ngTemplateOutlet]=\"custom.template\"\n [ngTemplateOutletContext]=\"{\n $implicit: row.item.command,\n result: row.item,\n segments: row.item.segments,\n active: row.index === activeIndex(),\n query: service.query(),\n }\"\n />\n } @else {\n @if (row.item.command.icon; as icon) {\n <span class=\"rr-cp-icon\" aria-hidden=\"true\">\n @if (isTemplate(icon)) {\n <ng-container [ngTemplateOutlet]=\"icon\" />\n } @else {\n {{ icon }}\n }\n </span>\n }\n <span class=\"rr-cp-text\">\n <!-- Single line: line breaks would become spaces inside the label -->\n <!-- prettier-ignore -->\n <span class=\"rr-cp-label\">@for (segment of row.item.segments; track $index) {@if (segment.match) {<mark class=\"rr-cp-match\">{{ segment.text }}</mark>} @else {{{ segment.text }}}}</span>\n @if (row.item.command.description) {\n <span class=\"rr-cp-description\">{{ row.item.command.description }}</span>\n }\n </span>\n @if (row.item.command.shortcut?.length) {\n <span class=\"rr-cp-shortcut\" aria-hidden=\"true\">\n @for (key of row.item.command.shortcut; track $index) {\n <kbd>{{ key }}</kbd>\n }\n </span>\n }\n }\n </div>\n }\n </div>\n }\n </div>\n\n @if (items().length === 0) {\n <div class=\"rr-cp-empty\">\n @if (service.loading()) {\n {{ labels.loading }}\n } @else if (emptyTemplate(); as custom) {\n <ng-container\n [ngTemplateOutlet]=\"custom.template\"\n [ngTemplateOutletContext]=\"{ $implicit: service.query() }\"\n />\n } @else {\n {{ labels.empty }}\n }\n </div>\n }\n\n <div class=\"rr-cp-sr-only\" aria-live=\"polite\" aria-atomic=\"true\">{{ status() }}</div>\n </div>\n </div>\n}\n",
|
|
962
|
+
styles: [":where(.rr-cp){--rr-cp-font: system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif;--rr-cp-font-size: .9375rem;--rr-cp-width: 640px;--rr-cp-max-height: min(420px, 60vh);--rr-cp-top: 12vh;--rr-cp-radius: 12px;--rr-cp-item-radius: 8px;--rr-cp-z-index: 1000;--rr-cp-bg: #ffffff;--rr-cp-fg: #18181b;--rr-cp-muted: #71717a;--rr-cp-border: #e4e4e7;--rr-cp-accent: #4f46e5;--rr-cp-item-active-bg: #f4f4f5;--rr-cp-highlight: #4f46e5;--rr-cp-highlight-bg: transparent;--rr-cp-kbd-bg: #f4f4f5;--rr-cp-kbd-fg: #52525b;--rr-cp-backdrop: rgb(9 9 11 / .4);--rr-cp-shadow: 0 16px 70px rgb(0 0 0 / .2);--rr-cp-duration: .14s}:where(.rr-cp[data-theme=dark]){--rr-cp-bg: #18181b;--rr-cp-fg: #f4f4f5;--rr-cp-muted: #a1a1aa;--rr-cp-border: #27272a;--rr-cp-accent: #818cf8;--rr-cp-item-active-bg: #27272a;--rr-cp-highlight: #a5b4fc;--rr-cp-kbd-bg: #27272a;--rr-cp-kbd-fg: #d4d4d8;--rr-cp-backdrop: rgb(0 0 0 / .6);--rr-cp-shadow: 0 16px 70px rgb(0 0 0 / .6)}.rr-cp-host{display:contents}.rr-cp{position:fixed;inset:0;z-index:var(--rr-cp-z-index);display:flex;justify-content:center;align-items:flex-start;padding:var(--rr-cp-top) 16px 16px;background:var(--rr-cp-backdrop);color-scheme:light;animation:rr-cp-fade var(--rr-cp-duration) ease-out}.rr-cp[data-theme=dark]{color-scheme:dark}.rr-cp-dialog{box-sizing:border-box;display:flex;flex-direction:column;width:100%;max-width:var(--rr-cp-width);overflow:hidden;border:1px solid var(--rr-cp-border);border-radius:var(--rr-cp-radius);background:var(--rr-cp-bg);color:var(--rr-cp-fg);box-shadow:var(--rr-cp-shadow);font-family:var(--rr-cp-font);font-size:var(--rr-cp-font-size);line-height:1.4;animation:rr-cp-pop var(--rr-cp-duration) ease-out}.rr-cp-search{display:flex;align-items:center;gap:10px;padding:0 14px;border-bottom:1px solid var(--rr-cp-border)}.rr-cp-search-icon{flex:none;color:var(--rr-cp-muted)}.rr-cp-input{flex:1;min-width:0;height:52px;padding:0;border:0;outline:0;background:transparent;color:inherit;font:inherit;font-size:1rem}.rr-cp-input::placeholder{color:var(--rr-cp-muted);opacity:1}.rr-cp-list{max-height:var(--rr-cp-max-height);overflow-y:auto;overscroll-behavior:contain;padding:6px;scroll-padding:6px}.rr-cp-list:empty{display:none}.rr-cp-group+.rr-cp-group{margin-top:4px}.rr-cp-group-label{padding:8px 10px 4px;color:var(--rr-cp-muted);font-size:.75rem;font-weight:600;letter-spacing:.02em}.rr-cp-item{display:flex;align-items:center;gap:10px;min-height:40px;padding:6px 10px;border-radius:var(--rr-cp-item-radius);cursor:pointer;-webkit-user-select:none;user-select:none}.rr-cp-item-active{background:var(--rr-cp-item-active-bg);box-shadow:inset 2px 0 0 var(--rr-cp-accent)}.rr-cp-item[aria-disabled=true]{cursor:default;opacity:.5}.rr-cp-icon{display:inline-flex;flex:none;align-items:center;justify-content:center;width:20px;height:20px;color:var(--rr-cp-muted)}.rr-cp-item-active .rr-cp-icon{color:var(--rr-cp-fg)}.rr-cp-text{display:flex;flex:1;flex-direction:column;min-width:0}.rr-cp-label,.rr-cp-description{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.rr-cp-description{color:var(--rr-cp-muted);font-size:.8125rem}.rr-cp-match{background:var(--rr-cp-highlight-bg);color:var(--rr-cp-highlight);font-weight:600}.rr-cp-shortcut{display:inline-flex;flex:none;gap:4px}.rr-cp kbd{display:inline-flex;align-items:center;justify-content:center;min-width:20px;height:20px;padding:0 5px;box-sizing:border-box;border:1px solid var(--rr-cp-border);border-radius:4px;background:var(--rr-cp-kbd-bg);color:var(--rr-cp-kbd-fg);font-family:inherit;font-size:.6875rem;font-weight:500}.rr-cp-empty{padding:32px 16px;color:var(--rr-cp-muted);text-align:center}.rr-cp-spinner{flex:none;width:14px;height:14px;border:2px solid var(--rr-cp-border);border-top-color:var(--rr-cp-accent);border-radius:50%;animation:rr-cp-spin .7s linear infinite}.rr-cp-sr-only{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap;border:0}@keyframes rr-cp-fade{0%{opacity:0}}@keyframes rr-cp-pop{0%{opacity:0;transform:scale(.98) translateY(-4px)}}@keyframes rr-cp-spin{to{transform:rotate(360deg)}}@media(prefers-reduced-motion:reduce){.rr-cp,.rr-cp-dialog{animation:none}.rr-cp-spinner{animation-duration:2s}}@media(max-width:480px){:where(.rr-cp){--rr-cp-top: 8px;--rr-cp-max-height: calc(100dvh - 90px) }.rr-cp-shortcut{display:none}}@media(forced-colors:active){.rr-cp-item-active{outline:2px solid Highlight}.rr-cp-match{text-decoration:underline}}\n"]
|
|
963
|
+
}]
|
|
964
|
+
}],
|
|
965
|
+
ctorParameters: () => [],
|
|
966
|
+
propDecorators: {
|
|
967
|
+
theme: [{
|
|
968
|
+
type: i0.Input,
|
|
969
|
+
args: [{
|
|
970
|
+
isSignal: true,
|
|
971
|
+
alias: "theme",
|
|
972
|
+
required: false
|
|
973
|
+
}]
|
|
974
|
+
}],
|
|
975
|
+
itemTemplate: [{
|
|
976
|
+
type: i0.ContentChild,
|
|
977
|
+
args: [i0.forwardRef(() => CommandItemTemplate), { isSignal: true }]
|
|
978
|
+
}],
|
|
979
|
+
emptyTemplate: [{
|
|
980
|
+
type: i0.ContentChild,
|
|
981
|
+
args: [i0.forwardRef(() => CommandEmptyTemplate), { isSignal: true }]
|
|
982
|
+
}],
|
|
983
|
+
input: [{
|
|
984
|
+
type: i0.ViewChild,
|
|
985
|
+
args: ["input", { isSignal: true }]
|
|
986
|
+
}],
|
|
987
|
+
dialog: [{
|
|
988
|
+
type: i0.ViewChild,
|
|
989
|
+
args: ["dialog", { isSignal: true }]
|
|
990
|
+
}]
|
|
991
|
+
}
|
|
992
|
+
});
|
|
993
|
+
function isEditable(target) {
|
|
994
|
+
const el = target;
|
|
995
|
+
if (!el || typeof el.tagName !== "string") return false;
|
|
996
|
+
const tag = el.tagName.toLowerCase();
|
|
997
|
+
return tag === "input" || tag === "textarea" || tag === "select" || el.isContentEditable;
|
|
998
|
+
}
|
|
999
|
+
export { COMMAND_PALETTE_CONFIG, CommandEmptyTemplate, CommandItemTemplate, CommandPaletteComponent, CommandPaletteService, DEFAULT_COMMAND_PALETTE_CONFIG, DEFAULT_COMMAND_PALETTE_LABELS, RECENT_SECTION_ID, formatShortcut, fuzzyMatch, highlightSegments, injectCommandProvider, injectCommands, isApplePlatform, matchCommand, matchesShortcut, parseShortcut, provideCommandPalette };
|
|
1000
|
+
|
|
1001
|
+
//# sourceMappingURL=rrstudioapps-ngx-command-palette.mjs.map
|