@rrstudioapps/ngx-command-palette 0.3.0 → 0.4.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.
|
@@ -189,6 +189,8 @@ const DEFAULT_COMMAND_PALETTE_LABELS = {
|
|
|
189
189
|
empty: "No results found.",
|
|
190
190
|
loading: "Loading…",
|
|
191
191
|
recent: "Recent",
|
|
192
|
+
pinned: "Pinned",
|
|
193
|
+
prompt: "{name}: type a value and press Enter",
|
|
192
194
|
defaultGroup: "Commands",
|
|
193
195
|
results: "{count} results",
|
|
194
196
|
closeHint: "Esc",
|
|
@@ -207,6 +209,7 @@ const DEFAULT_COMMAND_PALETTE_CONFIG = {
|
|
|
207
209
|
maxResults: 50,
|
|
208
210
|
maxEmptyResults: 100,
|
|
209
211
|
filter: matchCommand,
|
|
212
|
+
prefixes: [],
|
|
210
213
|
labels: DEFAULT_COMMAND_PALETTE_LABELS
|
|
211
214
|
};
|
|
212
215
|
const COMMAND_PALETTE_CONFIG = new InjectionToken("COMMAND_PALETTE_CONFIG", {
|
|
@@ -233,14 +236,83 @@ function provideCommandPalette(options = {}) {
|
|
|
233
236
|
useValue: resolveConfig(options)
|
|
234
237
|
}]);
|
|
235
238
|
}
|
|
239
|
+
const MODIFIERS = {
|
|
240
|
+
mod: "mod",
|
|
241
|
+
ctrl: "ctrl",
|
|
242
|
+
control: "ctrl",
|
|
243
|
+
meta: "meta",
|
|
244
|
+
cmd: "meta",
|
|
245
|
+
command: "meta",
|
|
246
|
+
alt: "alt",
|
|
247
|
+
option: "alt",
|
|
248
|
+
shift: "shift"
|
|
249
|
+
};
|
|
250
|
+
const KEY_ALIASES = {
|
|
251
|
+
space: " ",
|
|
252
|
+
esc: "escape",
|
|
253
|
+
slash: "/",
|
|
254
|
+
plus: "+"
|
|
255
|
+
};
|
|
256
|
+
function parseShortcut(shortcut) {
|
|
257
|
+
const parts = shortcut.toLowerCase().split("+").map((p) => p.trim()).filter(Boolean);
|
|
258
|
+
if (shortcut.trim().endsWith("++") || shortcut.trim() === "+") parts.push("+");
|
|
259
|
+
const result = {
|
|
260
|
+
key: "",
|
|
261
|
+
mod: false,
|
|
262
|
+
ctrl: false,
|
|
263
|
+
meta: false,
|
|
264
|
+
alt: false,
|
|
265
|
+
shift: false
|
|
266
|
+
};
|
|
267
|
+
for (const part of parts) {
|
|
268
|
+
const modifier = MODIFIERS[part];
|
|
269
|
+
if (modifier) result[modifier] = true;
|
|
270
|
+
else result.key = KEY_ALIASES[part] ?? part;
|
|
271
|
+
}
|
|
272
|
+
if (!result.key) throw new Error(`ngx-command-palette: invalid shortcut "${shortcut}"`);
|
|
273
|
+
return result;
|
|
274
|
+
}
|
|
275
|
+
function isApplePlatform(nav = globalThis.navigator) {
|
|
276
|
+
if (!nav) return false;
|
|
277
|
+
const platform = nav.userAgentData?.platform ?? nav.platform ?? "";
|
|
278
|
+
return /mac|iphone|ipad|ipod/i.test(platform);
|
|
279
|
+
}
|
|
280
|
+
function matchesShortcut(event, shortcut, apple) {
|
|
281
|
+
const wantCtrl = shortcut.ctrl || shortcut.mod && !apple;
|
|
282
|
+
const wantMeta = shortcut.meta || shortcut.mod && apple;
|
|
283
|
+
if (event.ctrlKey !== wantCtrl || event.metaKey !== wantMeta || event.altKey !== shortcut.alt) return false;
|
|
284
|
+
const key = (event.key ?? "").toLowerCase();
|
|
285
|
+
const isLetter = /^[a-z]$/.test(shortcut.key);
|
|
286
|
+
if ((shortcut.shift || isLetter) && event.shiftKey !== shortcut.shift) return false;
|
|
287
|
+
if (key === shortcut.key) return true;
|
|
288
|
+
if (isLetter && event.code === `Key${shortcut.key.toUpperCase()}`) return true;
|
|
289
|
+
if (/^[0-9]$/.test(shortcut.key) && event.code === `Digit${shortcut.key}`) return true;
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
292
|
+
function formatShortcut(shortcut, apple) {
|
|
293
|
+
const key = shortcut.key === " " ? "Space" : shortcut.key.length === 1 ? shortcut.key.toUpperCase() : capitalize(shortcut.key);
|
|
294
|
+
if (apple) return (shortcut.ctrl ? "⌃" : "") + (shortcut.alt ? "⌥" : "") + (shortcut.shift ? "⇧" : "") + (shortcut.meta || shortcut.mod ? "⌘" : "") + key;
|
|
295
|
+
const parts = [];
|
|
296
|
+
if (shortcut.ctrl || shortcut.mod) parts.push("Ctrl");
|
|
297
|
+
if (shortcut.meta) parts.push("Win");
|
|
298
|
+
if (shortcut.alt) parts.push("Alt");
|
|
299
|
+
if (shortcut.shift) parts.push("Shift");
|
|
300
|
+
parts.push(key);
|
|
301
|
+
return parts.join("+");
|
|
302
|
+
}
|
|
303
|
+
function capitalize(s) {
|
|
304
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
305
|
+
}
|
|
236
306
|
var RecentStore = class {
|
|
237
307
|
storageKey;
|
|
238
308
|
max;
|
|
239
309
|
storage;
|
|
240
|
-
|
|
310
|
+
rank;
|
|
311
|
+
constructor(storageKey, max, storage = defaultStorage(), rank = "recent") {
|
|
241
312
|
this.storageKey = storageKey;
|
|
242
313
|
this.max = max;
|
|
243
314
|
this.storage = storage;
|
|
315
|
+
this.rank = rank;
|
|
244
316
|
}
|
|
245
317
|
load() {
|
|
246
318
|
if (!this.storage || this.max <= 0) return [];
|
|
@@ -249,20 +321,26 @@ var RecentStore = class {
|
|
|
249
321
|
if (!raw) return [];
|
|
250
322
|
const parsed = JSON.parse(raw);
|
|
251
323
|
if (!Array.isArray(parsed)) return [];
|
|
252
|
-
return parsed.filter(isEntry).slice(0, this.max);
|
|
324
|
+
return this.order(parsed.filter(isEntry), Date.now()).slice(0, this.max);
|
|
253
325
|
} catch {
|
|
254
326
|
return [];
|
|
255
327
|
}
|
|
256
328
|
}
|
|
257
|
-
add(command, current = this.load()) {
|
|
329
|
+
add(command, current = this.load(), now = Date.now()) {
|
|
258
330
|
if (this.max <= 0) return [];
|
|
259
|
-
const
|
|
331
|
+
const previous = current.find((e) => e.id === command.id);
|
|
332
|
+
const entry = {
|
|
260
333
|
id: command.id,
|
|
261
334
|
label: command.label,
|
|
335
|
+
...this.rank === "frequent" ? {
|
|
336
|
+
count: (previous?.count ?? (previous ? 1 : 0)) + 1,
|
|
337
|
+
at: now
|
|
338
|
+
} : {},
|
|
262
339
|
...command.group ? { group: command.group } : {},
|
|
263
340
|
...command.description ? { description: command.description } : {},
|
|
264
341
|
...command.route !== void 0 && isSerializable(command.route) ? { route: command.route } : {}
|
|
265
|
-
}
|
|
342
|
+
};
|
|
343
|
+
const next = this.order([entry, ...current.filter((e) => e.id !== command.id)], now).slice(0, this.max);
|
|
266
344
|
this.save(next);
|
|
267
345
|
return next;
|
|
268
346
|
}
|
|
@@ -271,12 +349,25 @@ var RecentStore = class {
|
|
|
271
349
|
this.storage?.removeItem(this.storageKey);
|
|
272
350
|
} catch {}
|
|
273
351
|
}
|
|
352
|
+
order(entries, now) {
|
|
353
|
+
if (this.rank !== "frequent") return entries;
|
|
354
|
+
return entries.map((entry, index) => ({
|
|
355
|
+
entry,
|
|
356
|
+
index,
|
|
357
|
+
score: frecency(entry, now)
|
|
358
|
+
})).sort((a, b) => b.score - a.score || a.index - b.index).map((x) => x.entry);
|
|
359
|
+
}
|
|
274
360
|
save(entries) {
|
|
275
361
|
try {
|
|
276
362
|
this.storage?.setItem(this.storageKey, JSON.stringify(entries));
|
|
277
363
|
} catch {}
|
|
278
364
|
}
|
|
279
365
|
};
|
|
366
|
+
const HALF_LIFE_MS = 6048e5;
|
|
367
|
+
function frecency(entry, now) {
|
|
368
|
+
const age = entry.at === void 0 ? 0 : Math.max(0, now - entry.at);
|
|
369
|
+
return (entry.count ?? 1) * Math.pow(.5, age / HALF_LIFE_MS);
|
|
370
|
+
}
|
|
280
371
|
function defaultStorage() {
|
|
281
372
|
try {
|
|
282
373
|
return typeof localStorage === "undefined" ? null : localStorage;
|
|
@@ -298,11 +389,12 @@ function isSerializable(route) {
|
|
|
298
389
|
}
|
|
299
390
|
}
|
|
300
391
|
const RECENT_SECTION_ID = "recent";
|
|
392
|
+
const PINNED_SECTION_ID = "pinned";
|
|
301
393
|
var CommandPaletteService = class CommandPaletteService {
|
|
302
394
|
config = inject(COMMAND_PALETTE_CONFIG);
|
|
303
395
|
router = inject(Router, { optional: true });
|
|
304
396
|
document = inject(DOCUMENT);
|
|
305
|
-
recentStore = this.config.recent ? new RecentStore(this.config.recent.storageKey ?? "rr-cp:recent", this.config.recent.max ?? 5) : null;
|
|
397
|
+
recentStore = this.config.recent ? new RecentStore(this.config.recent.storageKey ?? "rr-cp:recent", this.config.recent.max ?? 5, void 0, this.config.recent.rank) : null;
|
|
306
398
|
_isOpen = signal(false, ...ngDevMode ? [{ debugName: "_isOpen" }] : /* istanbul ignore next */ []);
|
|
307
399
|
_query = signal("", ...ngDevMode ? [{ debugName: "_query" }] : /* istanbul ignore next */ []);
|
|
308
400
|
registrations = signal([], ...ngDevMode ? [{ debugName: "registrations" }] : /* istanbul ignore next */ []);
|
|
@@ -311,8 +403,10 @@ var CommandPaletteService = class CommandPaletteService {
|
|
|
311
403
|
recents = signal(this.recentStore?.load() ?? [], ...ngDevMode ? [{ debugName: "recents" }] : /* istanbul ignore next */ []);
|
|
312
404
|
pending = /* @__PURE__ */ new Map();
|
|
313
405
|
pathIds = signal([], ...ngDevMode ? [{ debugName: "pathIds" }] : /* istanbul ignore next */ []);
|
|
406
|
+
promptCommand = signal(null, ...ngDevMode ? [{ debugName: "promptCommand" }] : /* istanbul ignore next */ []);
|
|
314
407
|
returnFocus = null;
|
|
315
408
|
isOpen = this._isOpen.asReadonly();
|
|
409
|
+
prompt = this.promptCommand.asReadonly();
|
|
316
410
|
query = this._query.asReadonly();
|
|
317
411
|
path = computed(() => {
|
|
318
412
|
const path = [];
|
|
@@ -338,7 +432,19 @@ var CommandPaletteService = class CommandPaletteService {
|
|
|
338
432
|
return [...byId.values()];
|
|
339
433
|
}, ...ngDevMode ? [{ debugName: "commands" }] : /* istanbul ignore next */ []);
|
|
340
434
|
loading = computed(() => [...this.providerState().values()].some((s) => s.loading), ...ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []);
|
|
341
|
-
|
|
435
|
+
activePrefix = computed(() => this.parseQuery(this._query()).prefix, ...ngDevMode ? [{ debugName: "activePrefix" }] : /* istanbul ignore next */ []);
|
|
436
|
+
sections = computed(() => this.buildSections(this._query()), ...ngDevMode ? [{ debugName: "sections" }] : /* istanbul ignore next */ []);
|
|
437
|
+
hotkeyCommands = computed(() => descendants(this.commands()).filter((c) => c.hotkey && !isParent(c)), ...ngDevMode ? [{ debugName: "hotkeyCommands" }] : /* istanbul ignore next */ []);
|
|
438
|
+
runHotkey(event, apple) {
|
|
439
|
+
if (this._isOpen()) return false;
|
|
440
|
+
for (const command of this.hotkeyCommands()) {
|
|
441
|
+
if (!(typeof command.hotkey === "string" ? [command.hotkey] : command.hotkey ?? []).some((k) => matchesShortcut(event, parseShortcut(k), apple))) continue;
|
|
442
|
+
if (command.disabled) return false;
|
|
443
|
+
this.execute(command);
|
|
444
|
+
return true;
|
|
445
|
+
}
|
|
446
|
+
return false;
|
|
447
|
+
}
|
|
342
448
|
open(query = "") {
|
|
343
449
|
if (!this._isOpen()) {
|
|
344
450
|
const active = this.document.activeElement;
|
|
@@ -346,6 +452,7 @@ var CommandPaletteService = class CommandPaletteService {
|
|
|
346
452
|
}
|
|
347
453
|
this._isOpen.set(true);
|
|
348
454
|
this.pathIds.set([]);
|
|
455
|
+
this.promptCommand.set(null);
|
|
349
456
|
this.setQuery(query);
|
|
350
457
|
}
|
|
351
458
|
close() {
|
|
@@ -354,6 +461,7 @@ var CommandPaletteService = class CommandPaletteService {
|
|
|
354
461
|
this.cancelAll();
|
|
355
462
|
this._query.set("");
|
|
356
463
|
this.pathIds.set([]);
|
|
464
|
+
this.promptCommand.set(null);
|
|
357
465
|
this.providerState.set(/* @__PURE__ */ new Map());
|
|
358
466
|
const target = this.returnFocus;
|
|
359
467
|
this.returnFocus = null;
|
|
@@ -369,8 +477,13 @@ var CommandPaletteService = class CommandPaletteService {
|
|
|
369
477
|
}
|
|
370
478
|
back(levels = 1) {
|
|
371
479
|
const path = this.path();
|
|
372
|
-
|
|
373
|
-
|
|
480
|
+
let remaining = levels;
|
|
481
|
+
if (levels < 1 || !(path.length || this.promptCommand())) return false;
|
|
482
|
+
if (this.promptCommand()) {
|
|
483
|
+
this.promptCommand.set(null);
|
|
484
|
+
remaining--;
|
|
485
|
+
}
|
|
486
|
+
if (remaining > 0) this.pathIds.set(path.slice(0, Math.max(0, path.length - remaining)).map((c) => c.id));
|
|
374
487
|
this.setQuery("");
|
|
375
488
|
return true;
|
|
376
489
|
}
|
|
@@ -382,7 +495,7 @@ var CommandPaletteService = class CommandPaletteService {
|
|
|
382
495
|
}
|
|
383
496
|
registerProvider(provider, destroyRef) {
|
|
384
497
|
this.providers.update((list) => [...list.filter((p) => p.id !== provider.id), provider]);
|
|
385
|
-
if (this._isOpen() && !this.pathIds().length) this.scheduleProvider(provider, this._query());
|
|
498
|
+
if (this._isOpen() && !this.pathIds().length && !this.promptCommand()) this.scheduleProvider(provider, this._query());
|
|
386
499
|
const remove = () => {
|
|
387
500
|
if (!this.providers().includes(provider)) return;
|
|
388
501
|
this.cancel(provider.id);
|
|
@@ -405,14 +518,29 @@ var CommandPaletteService = class CommandPaletteService {
|
|
|
405
518
|
this.setQuery("");
|
|
406
519
|
return;
|
|
407
520
|
}
|
|
408
|
-
|
|
521
|
+
let query = this.parseQuery(this._query()).text;
|
|
522
|
+
let value;
|
|
523
|
+
if (!isParent(command) && command.prompt !== void 0) {
|
|
524
|
+
if (this.promptCommand()?.id !== command.id) {
|
|
525
|
+
this.cancelAll();
|
|
526
|
+
this.providerState.set(/* @__PURE__ */ new Map());
|
|
527
|
+
this.promptCommand.set(command);
|
|
528
|
+
this.setQuery("");
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
query = value = this._query().trim();
|
|
532
|
+
if (!value) return;
|
|
533
|
+
}
|
|
409
534
|
if (this.recentStore) this.recents.set(this.recentStore.add(command, this.recents()));
|
|
410
535
|
this.close();
|
|
411
536
|
if (command.route !== void 0) {
|
|
412
537
|
if (!this.router) throw new Error("ngx-command-palette: route commands need provideRouter()");
|
|
413
538
|
const { route, navigationExtras } = command;
|
|
414
539
|
await (typeof route === "string" ? this.router.navigateByUrl(route, navigationExtras) : this.router.navigate(route, navigationExtras));
|
|
415
|
-
} else await command.run({ query }
|
|
540
|
+
} else await command.run(value === void 0 ? { query } : {
|
|
541
|
+
query,
|
|
542
|
+
value
|
|
543
|
+
});
|
|
416
544
|
}
|
|
417
545
|
clearRecent() {
|
|
418
546
|
this.recentStore?.clear();
|
|
@@ -425,9 +553,28 @@ var CommandPaletteService = class CommandPaletteService {
|
|
|
425
553
|
remove();
|
|
426
554
|
};
|
|
427
555
|
}
|
|
428
|
-
|
|
556
|
+
parseQuery(raw) {
|
|
557
|
+
const trimmed = raw.trim();
|
|
558
|
+
const prefix = this.config.prefixes.find((p) => p.prefix && trimmed.startsWith(p.prefix)) ?? null;
|
|
559
|
+
return {
|
|
560
|
+
prefix,
|
|
561
|
+
text: prefix ? trimmed.slice(prefix.prefix.length).trim() : trimmed
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
buildSections(rawQuery) {
|
|
429
565
|
const defaultGroup = this.config.labels.defaultGroup;
|
|
430
|
-
const
|
|
566
|
+
const prompt = this.promptCommand();
|
|
567
|
+
if (prompt) {
|
|
568
|
+
const items = [toResult(prompt, `x:${prompt.id}`, 0, [])];
|
|
569
|
+
return [{
|
|
570
|
+
id: "prompt",
|
|
571
|
+
label: prompt.group ?? defaultGroup,
|
|
572
|
+
items
|
|
573
|
+
}];
|
|
574
|
+
}
|
|
575
|
+
const { prefix, text: query } = this.parseQuery(rawQuery);
|
|
576
|
+
const levelCommands = this.levelCommands();
|
|
577
|
+
const commands = prefix ? levelCommands.filter((c) => inPrefix(c, prefix, defaultGroup)) : levelCommands;
|
|
431
578
|
const groups = /* @__PURE__ */ new Map();
|
|
432
579
|
const push = (group, result) => {
|
|
433
580
|
const list = groups.get(group);
|
|
@@ -437,7 +584,14 @@ var CommandPaletteService = class CommandPaletteService {
|
|
|
437
584
|
const sections = [];
|
|
438
585
|
const topLevel = !this.pathIds().length;
|
|
439
586
|
if (!query) {
|
|
440
|
-
const
|
|
587
|
+
const pinned = prefix ? [] : commands.filter((c) => !isHidden(c) && isPinned(c)).map((c) => toResult(c, `pin:${c.id}`, 0, []));
|
|
588
|
+
if (pinned.length) sections.push({
|
|
589
|
+
id: PINNED_SECTION_ID,
|
|
590
|
+
label: this.config.labels.pinned,
|
|
591
|
+
items: pinned
|
|
592
|
+
});
|
|
593
|
+
const pinnedIds = new Set(pinned.map((r) => r.command.id));
|
|
594
|
+
const recent = topLevel && !prefix ? this.recentResults(commands).filter((r) => !pinnedIds.has(r.command.id)) : [];
|
|
441
595
|
if (recent.length) sections.push({
|
|
442
596
|
id: RECENT_SECTION_ID,
|
|
443
597
|
label: this.config.labels.recent,
|
|
@@ -469,6 +623,7 @@ var CommandPaletteService = class CommandPaletteService {
|
|
|
469
623
|
});
|
|
470
624
|
const states = this.providerState();
|
|
471
625
|
for (const provider of topLevel ? this.providers() : []) {
|
|
626
|
+
if (prefix && (prefix.kind || prefix.groups && !prefix.groups.includes(provider.group))) continue;
|
|
472
627
|
const state = states.get(provider.id);
|
|
473
628
|
if (!state?.items.length) continue;
|
|
474
629
|
const items = state.items.filter((command) => !isHidden(command)).map((command) => {
|
|
@@ -500,13 +655,17 @@ var CommandPaletteService = class CommandPaletteService {
|
|
|
500
655
|
return results;
|
|
501
656
|
}
|
|
502
657
|
scheduleProviders() {
|
|
503
|
-
if (this.pathIds().length) return;
|
|
658
|
+
if (this.pathIds().length || this.promptCommand()) return;
|
|
504
659
|
const query = this._query();
|
|
505
660
|
for (const provider of this.providers()) this.scheduleProvider(provider, query);
|
|
506
661
|
}
|
|
507
662
|
scheduleProvider(provider, rawQuery) {
|
|
508
663
|
this.cancel(provider.id);
|
|
509
|
-
const query =
|
|
664
|
+
const { prefix, text: query } = this.parseQuery(rawQuery);
|
|
665
|
+
if (prefix && (prefix.kind || prefix.groups && !prefix.groups.includes(provider.group))) {
|
|
666
|
+
this.setProviderState(provider.id, null);
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
510
669
|
if (query.length < (provider.minQueryLength ?? 1)) {
|
|
511
670
|
this.setProviderState(provider.id, null);
|
|
512
671
|
return;
|
|
@@ -618,6 +777,16 @@ function toResult(command, key, score, indices) {
|
|
|
618
777
|
segments: highlightSegments(command.label, indices)
|
|
619
778
|
};
|
|
620
779
|
}
|
|
780
|
+
function inPrefix(command, prefix, defaultGroup) {
|
|
781
|
+
if (prefix.groups && !prefix.groups.includes(command.group ?? defaultGroup)) return false;
|
|
782
|
+
if (prefix.kind === "route") return command.route !== void 0;
|
|
783
|
+
if (prefix.kind === "action") return typeof command.run === "function";
|
|
784
|
+
return true;
|
|
785
|
+
}
|
|
786
|
+
function isPinned(command) {
|
|
787
|
+
const { pinned } = command;
|
|
788
|
+
return typeof pinned === "function" ? pinned() : !!pinned;
|
|
789
|
+
}
|
|
621
790
|
function isParent(command) {
|
|
622
791
|
return Array.isArray(command.children);
|
|
623
792
|
}
|
|
@@ -686,73 +855,6 @@ function moveIndex(disabled, current, action) {
|
|
|
686
855
|
case "prev": return current < 0 ? findFrom(count - 1, -1, false) : findFrom(current - 1, -1, true);
|
|
687
856
|
}
|
|
688
857
|
}
|
|
689
|
-
const MODIFIERS = {
|
|
690
|
-
mod: "mod",
|
|
691
|
-
ctrl: "ctrl",
|
|
692
|
-
control: "ctrl",
|
|
693
|
-
meta: "meta",
|
|
694
|
-
cmd: "meta",
|
|
695
|
-
command: "meta",
|
|
696
|
-
alt: "alt",
|
|
697
|
-
option: "alt",
|
|
698
|
-
shift: "shift"
|
|
699
|
-
};
|
|
700
|
-
const KEY_ALIASES = {
|
|
701
|
-
space: " ",
|
|
702
|
-
esc: "escape",
|
|
703
|
-
slash: "/",
|
|
704
|
-
plus: "+"
|
|
705
|
-
};
|
|
706
|
-
function parseShortcut(shortcut) {
|
|
707
|
-
const parts = shortcut.toLowerCase().split("+").map((p) => p.trim()).filter(Boolean);
|
|
708
|
-
if (shortcut.trim().endsWith("++") || shortcut.trim() === "+") parts.push("+");
|
|
709
|
-
const result = {
|
|
710
|
-
key: "",
|
|
711
|
-
mod: false,
|
|
712
|
-
ctrl: false,
|
|
713
|
-
meta: false,
|
|
714
|
-
alt: false,
|
|
715
|
-
shift: false
|
|
716
|
-
};
|
|
717
|
-
for (const part of parts) {
|
|
718
|
-
const modifier = MODIFIERS[part];
|
|
719
|
-
if (modifier) result[modifier] = true;
|
|
720
|
-
else result.key = KEY_ALIASES[part] ?? part;
|
|
721
|
-
}
|
|
722
|
-
if (!result.key) throw new Error(`ngx-command-palette: invalid shortcut "${shortcut}"`);
|
|
723
|
-
return result;
|
|
724
|
-
}
|
|
725
|
-
function isApplePlatform(nav = globalThis.navigator) {
|
|
726
|
-
if (!nav) return false;
|
|
727
|
-
const platform = nav.userAgentData?.platform ?? nav.platform ?? "";
|
|
728
|
-
return /mac|iphone|ipad|ipod/i.test(platform);
|
|
729
|
-
}
|
|
730
|
-
function matchesShortcut(event, shortcut, apple) {
|
|
731
|
-
const wantCtrl = shortcut.ctrl || shortcut.mod && !apple;
|
|
732
|
-
const wantMeta = shortcut.meta || shortcut.mod && apple;
|
|
733
|
-
if (event.ctrlKey !== wantCtrl || event.metaKey !== wantMeta || event.altKey !== shortcut.alt) return false;
|
|
734
|
-
const key = (event.key ?? "").toLowerCase();
|
|
735
|
-
const isLetter = /^[a-z]$/.test(shortcut.key);
|
|
736
|
-
if ((shortcut.shift || isLetter) && event.shiftKey !== shortcut.shift) return false;
|
|
737
|
-
if (key === shortcut.key) return true;
|
|
738
|
-
if (isLetter && event.code === `Key${shortcut.key.toUpperCase()}`) return true;
|
|
739
|
-
if (/^[0-9]$/.test(shortcut.key) && event.code === `Digit${shortcut.key}`) return true;
|
|
740
|
-
return false;
|
|
741
|
-
}
|
|
742
|
-
function formatShortcut(shortcut, apple) {
|
|
743
|
-
const key = shortcut.key === " " ? "Space" : shortcut.key.length === 1 ? shortcut.key.toUpperCase() : capitalize(shortcut.key);
|
|
744
|
-
if (apple) return (shortcut.ctrl ? "⌃" : "") + (shortcut.alt ? "⌥" : "") + (shortcut.shift ? "⇧" : "") + (shortcut.meta || shortcut.mod ? "⌘" : "") + key;
|
|
745
|
-
const parts = [];
|
|
746
|
-
if (shortcut.ctrl || shortcut.mod) parts.push("Ctrl");
|
|
747
|
-
if (shortcut.meta) parts.push("Win");
|
|
748
|
-
if (shortcut.alt) parts.push("Alt");
|
|
749
|
-
if (shortcut.shift) parts.push("Shift");
|
|
750
|
-
parts.push(key);
|
|
751
|
-
return parts.join("+");
|
|
752
|
-
}
|
|
753
|
-
function capitalize(s) {
|
|
754
|
-
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
755
|
-
}
|
|
756
858
|
var CommandItemTemplate = class CommandItemTemplate {
|
|
757
859
|
template = inject(TemplateRef);
|
|
758
860
|
static ngTemplateContextGuard(_dir, ctx) {
|
|
@@ -833,6 +935,11 @@ var CommandPaletteComponent = class CommandPaletteComponent {
|
|
|
833
935
|
apple = isApplePlatform();
|
|
834
936
|
shortcuts = (typeof this.config.shortcut === "string" ? [this.config.shortcut] : this.config.shortcut).map(parseShortcut);
|
|
835
937
|
shortcutLabel = this.shortcuts.length ? formatShortcut(this.shortcuts[0], this.apple) : "";
|
|
938
|
+
keysOf(command) {
|
|
939
|
+
if (command.shortcut?.length) return command.shortcut;
|
|
940
|
+
const hotkey = typeof command.hotkey === "string" ? command.hotkey : command.hotkey?.[0];
|
|
941
|
+
return hotkey ? [formatShortcut(parseShortcut(hotkey), this.apple)] : [];
|
|
942
|
+
}
|
|
836
943
|
prefersDark = signal(false, ...ngDevMode ? [{ debugName: "prefersDark" }] : /* istanbul ignore next */ []);
|
|
837
944
|
resolvedTheme = computed(() => {
|
|
838
945
|
const theme = this.theme() ?? this.config.theme;
|
|
@@ -867,8 +974,15 @@ var CommandPaletteComponent = class CommandPaletteComponent {
|
|
|
867
974
|
const count = this.items().length;
|
|
868
975
|
if (count === 0) return this.labels.empty;
|
|
869
976
|
const path = this.service.path();
|
|
977
|
+
const prompt = this.service.prompt();
|
|
978
|
+
if (prompt) return this.labels.prompt.replace("{name}", prompt.label);
|
|
870
979
|
return (path.length ? this.labels.level : this.labels.results).replace("{name}", path[path.length - 1]?.label ?? "").replace("{count}", String(count));
|
|
871
980
|
}, ...ngDevMode ? [{ debugName: "status" }] : /* istanbul ignore next */ []);
|
|
981
|
+
crumbs = computed(() => {
|
|
982
|
+
const prompt = this.service.prompt();
|
|
983
|
+
return prompt ? [...this.service.path(), prompt] : this.service.path();
|
|
984
|
+
}, ...ngDevMode ? [{ debugName: "crumbs" }] : /* istanbul ignore next */ []);
|
|
985
|
+
placeholder = computed(() => this.service.prompt()?.prompt ?? this.labels.placeholder, ...ngDevMode ? [{ debugName: "placeholder" }] : /* istanbul ignore next */ []);
|
|
872
986
|
constructor() {
|
|
873
987
|
const media = this.document.defaultView?.matchMedia?.("(prefers-color-scheme: dark)");
|
|
874
988
|
if (media) {
|
|
@@ -910,7 +1024,7 @@ var CommandPaletteComponent = class CommandPaletteComponent {
|
|
|
910
1024
|
this.trapTab(event);
|
|
911
1025
|
return;
|
|
912
1026
|
}
|
|
913
|
-
if (event.key === "Backspace" && !event.isComposing && this.service.query() === "" && this.
|
|
1027
|
+
if (event.key === "Backspace" && !event.isComposing && this.service.query() === "" && this.crumbs().length) {
|
|
914
1028
|
event.preventDefault();
|
|
915
1029
|
this.activeKey.set(null);
|
|
916
1030
|
this.service.back();
|
|
@@ -947,6 +1061,10 @@ var CommandPaletteComponent = class CommandPaletteComponent {
|
|
|
947
1061
|
}
|
|
948
1062
|
onDocumentKeydown(event) {
|
|
949
1063
|
if (event.repeat || event.isComposing) return;
|
|
1064
|
+
if ((event.ctrlKey || event.metaKey || event.altKey && !isEditable(event.target)) && this.service.runHotkey(event, this.apple)) {
|
|
1065
|
+
event.preventDefault();
|
|
1066
|
+
return;
|
|
1067
|
+
}
|
|
950
1068
|
const typing = isEditable(event.target);
|
|
951
1069
|
if (this.shortcuts.some((s) => (!typing || s.mod || s.ctrl || s.meta || s.alt) && matchesShortcut(event, s, this.apple))) {
|
|
952
1070
|
event.preventDefault();
|
|
@@ -1033,8 +1151,8 @@ var CommandPaletteComponent = class CommandPaletteComponent {
|
|
|
1033
1151
|
isSignal: true
|
|
1034
1152
|
}],
|
|
1035
1153
|
ngImport: i0,
|
|
1036
|
-
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 @if (
|
|
1037
|
-
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: #
|
|
1154
|
+
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 @if (crumbs(); as path) {\n @if (path.length) {\n <nav class=\"rr-cp-path\">\n <button\n type=\"button\"\n class=\"rr-cp-path-back\"\n [attr.aria-label]=\"labels.back\"\n (click)=\"onBack(1)\"\n >\n <svg viewBox=\"0 0 24 24\" width=\"16\" height=\"16\" aria-hidden=\"true\">\n <path\n d=\"m15 6-6 6 6 6\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n />\n </svg>\n </button>\n @for (parent of path; track parent.id; let i = $index; let last = $last) {\n @if (last) {\n <span class=\"rr-cp-path-current\" aria-current=\"page\">{{ parent.label }}</span>\n } @else {\n <button type=\"button\" class=\"rr-cp-path-step\" (click)=\"onBack(path.length - 1 - i)\">\n {{ parent.label }}\n </button>\n <span class=\"rr-cp-path-sep\" aria-hidden=\"true\">›</span>\n }\n }\n </nav>\n }\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]=\"placeholder()\"\n [placeholder]=\"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 (hasChildren(row.item.command)) {\n <span class=\"rr-cp-sr-only\">, {{ labels.submenu }}</span>\n <span class=\"rr-cp-chevron\" aria-hidden=\"true\">›</span>\n }\n @if (keysOf(row.item.command).length) {\n <span class=\"rr-cp-shortcut\" aria-hidden=\"true\">\n @for (key of keysOf(row.item.command); 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",
|
|
1155
|
+
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: #686872;--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-path{display:flex;align-items:center;gap:4px;padding:10px 14px 0;color:var(--rr-cp-muted);font-size:.8125rem}.rr-cp-path button{display:inline-flex;align-items:center;padding:2px 6px;border:0;border-radius:6px;background:transparent;color:inherit;font:inherit;cursor:pointer}.rr-cp-path button:hover{background:var(--rr-cp-item-active-bg);color:var(--rr-cp-fg)}.rr-cp-path button:focus-visible{outline:2px solid var(--rr-cp-accent);outline-offset:1px}.rr-cp-path-current{padding:2px 6px;color:var(--rr-cp-fg);font-weight:600}.rr-cp-chevron,.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{padding:0;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"],
|
|
1038
1156
|
dependencies: [{
|
|
1039
1157
|
kind: "directive",
|
|
1040
1158
|
type: NgTemplateOutlet,
|
|
@@ -1066,8 +1184,8 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
1066
1184
|
"(document:keydown)": "onDocumentKeydown($event)",
|
|
1067
1185
|
"(document:focusin)": "onDocumentFocusin($event)"
|
|
1068
1186
|
},
|
|
1069
|
-
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 @if (
|
|
1070
|
-
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: #
|
|
1187
|
+
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 @if (crumbs(); as path) {\n @if (path.length) {\n <nav class=\"rr-cp-path\">\n <button\n type=\"button\"\n class=\"rr-cp-path-back\"\n [attr.aria-label]=\"labels.back\"\n (click)=\"onBack(1)\"\n >\n <svg viewBox=\"0 0 24 24\" width=\"16\" height=\"16\" aria-hidden=\"true\">\n <path\n d=\"m15 6-6 6 6 6\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n />\n </svg>\n </button>\n @for (parent of path; track parent.id; let i = $index; let last = $last) {\n @if (last) {\n <span class=\"rr-cp-path-current\" aria-current=\"page\">{{ parent.label }}</span>\n } @else {\n <button type=\"button\" class=\"rr-cp-path-step\" (click)=\"onBack(path.length - 1 - i)\">\n {{ parent.label }}\n </button>\n <span class=\"rr-cp-path-sep\" aria-hidden=\"true\">›</span>\n }\n }\n </nav>\n }\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]=\"placeholder()\"\n [placeholder]=\"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 (hasChildren(row.item.command)) {\n <span class=\"rr-cp-sr-only\">, {{ labels.submenu }}</span>\n <span class=\"rr-cp-chevron\" aria-hidden=\"true\">›</span>\n }\n @if (keysOf(row.item.command).length) {\n <span class=\"rr-cp-shortcut\" aria-hidden=\"true\">\n @for (key of keysOf(row.item.command); 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",
|
|
1188
|
+
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: #686872;--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-path{display:flex;align-items:center;gap:4px;padding:10px 14px 0;color:var(--rr-cp-muted);font-size:.8125rem}.rr-cp-path button{display:inline-flex;align-items:center;padding:2px 6px;border:0;border-radius:6px;background:transparent;color:inherit;font:inherit;cursor:pointer}.rr-cp-path button:hover{background:var(--rr-cp-item-active-bg);color:var(--rr-cp-fg)}.rr-cp-path button:focus-visible{outline:2px solid var(--rr-cp-accent);outline-offset:1px}.rr-cp-path-current{padding:2px 6px;color:var(--rr-cp-fg);font-weight:600}.rr-cp-chevron,.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{padding:0;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"]
|
|
1071
1189
|
}]
|
|
1072
1190
|
}],
|
|
1073
1191
|
ctorParameters: () => [],
|
|
@@ -1104,6 +1222,6 @@ function isEditable(target) {
|
|
|
1104
1222
|
const tag = el.tagName.toLowerCase();
|
|
1105
1223
|
return tag === "input" || tag === "textarea" || tag === "select" || el.isContentEditable;
|
|
1106
1224
|
}
|
|
1107
|
-
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 };
|
|
1225
|
+
export { COMMAND_PALETTE_CONFIG, CommandEmptyTemplate, CommandItemTemplate, CommandPaletteComponent, CommandPaletteService, DEFAULT_COMMAND_PALETTE_CONFIG, DEFAULT_COMMAND_PALETTE_LABELS, PINNED_SECTION_ID, RECENT_SECTION_ID, formatShortcut, fuzzyMatch, highlightSegments, injectCommandProvider, injectCommands, isApplePlatform, matchCommand, matchesShortcut, parseShortcut, provideCommandPalette };
|
|
1108
1226
|
|
|
1109
1227
|
//# sourceMappingURL=rrstudioapps-ngx-command-palette.mjs.map
|