@rrstudioapps/ngx-command-palette 0.3.1 → 0.5.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",
|
|
@@ -198,6 +200,8 @@ const DEFAULT_COMMAND_PALETTE_LABELS = {
|
|
|
198
200
|
};
|
|
199
201
|
const DEFAULT_COMMAND_PALETTE_CONFIG = {
|
|
200
202
|
shortcut: "mod+k",
|
|
203
|
+
shortcutInFields: true,
|
|
204
|
+
shortcutEnabled: true,
|
|
201
205
|
theme: "auto",
|
|
202
206
|
recent: {
|
|
203
207
|
max: 5,
|
|
@@ -207,6 +211,7 @@ const DEFAULT_COMMAND_PALETTE_CONFIG = {
|
|
|
207
211
|
maxResults: 50,
|
|
208
212
|
maxEmptyResults: 100,
|
|
209
213
|
filter: matchCommand,
|
|
214
|
+
prefixes: [],
|
|
210
215
|
labels: DEFAULT_COMMAND_PALETTE_LABELS
|
|
211
216
|
};
|
|
212
217
|
const COMMAND_PALETTE_CONFIG = new InjectionToken("COMMAND_PALETTE_CONFIG", {
|
|
@@ -233,14 +238,83 @@ function provideCommandPalette(options = {}) {
|
|
|
233
238
|
useValue: resolveConfig(options)
|
|
234
239
|
}]);
|
|
235
240
|
}
|
|
241
|
+
const MODIFIERS = {
|
|
242
|
+
mod: "mod",
|
|
243
|
+
ctrl: "ctrl",
|
|
244
|
+
control: "ctrl",
|
|
245
|
+
meta: "meta",
|
|
246
|
+
cmd: "meta",
|
|
247
|
+
command: "meta",
|
|
248
|
+
alt: "alt",
|
|
249
|
+
option: "alt",
|
|
250
|
+
shift: "shift"
|
|
251
|
+
};
|
|
252
|
+
const KEY_ALIASES = {
|
|
253
|
+
space: " ",
|
|
254
|
+
esc: "escape",
|
|
255
|
+
slash: "/",
|
|
256
|
+
plus: "+"
|
|
257
|
+
};
|
|
258
|
+
function parseShortcut(shortcut) {
|
|
259
|
+
const parts = shortcut.toLowerCase().split("+").map((p) => p.trim()).filter(Boolean);
|
|
260
|
+
if (shortcut.trim().endsWith("++") || shortcut.trim() === "+") parts.push("+");
|
|
261
|
+
const result = {
|
|
262
|
+
key: "",
|
|
263
|
+
mod: false,
|
|
264
|
+
ctrl: false,
|
|
265
|
+
meta: false,
|
|
266
|
+
alt: false,
|
|
267
|
+
shift: false
|
|
268
|
+
};
|
|
269
|
+
for (const part of parts) {
|
|
270
|
+
const modifier = MODIFIERS[part];
|
|
271
|
+
if (modifier) result[modifier] = true;
|
|
272
|
+
else result.key = KEY_ALIASES[part] ?? part;
|
|
273
|
+
}
|
|
274
|
+
if (!result.key) throw new Error(`ngx-command-palette: invalid shortcut "${shortcut}"`);
|
|
275
|
+
return result;
|
|
276
|
+
}
|
|
277
|
+
function isApplePlatform(nav = globalThis.navigator) {
|
|
278
|
+
if (!nav) return false;
|
|
279
|
+
const platform = nav.userAgentData?.platform ?? nav.platform ?? "";
|
|
280
|
+
return /mac|iphone|ipad|ipod/i.test(platform);
|
|
281
|
+
}
|
|
282
|
+
function matchesShortcut(event, shortcut, apple) {
|
|
283
|
+
const wantCtrl = shortcut.ctrl || shortcut.mod && !apple;
|
|
284
|
+
const wantMeta = shortcut.meta || shortcut.mod && apple;
|
|
285
|
+
if (event.ctrlKey !== wantCtrl || event.metaKey !== wantMeta || event.altKey !== shortcut.alt) return false;
|
|
286
|
+
const key = (event.key ?? "").toLowerCase();
|
|
287
|
+
const isLetter = /^[a-z]$/.test(shortcut.key);
|
|
288
|
+
if ((shortcut.shift || isLetter) && event.shiftKey !== shortcut.shift) return false;
|
|
289
|
+
if (key === shortcut.key) return true;
|
|
290
|
+
if (isLetter && event.code === `Key${shortcut.key.toUpperCase()}`) return true;
|
|
291
|
+
if (/^[0-9]$/.test(shortcut.key) && event.code === `Digit${shortcut.key}`) return true;
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
function formatShortcut(shortcut, apple) {
|
|
295
|
+
const key = shortcut.key === " " ? "Space" : shortcut.key.length === 1 ? shortcut.key.toUpperCase() : capitalize(shortcut.key);
|
|
296
|
+
if (apple) return (shortcut.ctrl ? "⌃" : "") + (shortcut.alt ? "⌥" : "") + (shortcut.shift ? "⇧" : "") + (shortcut.meta || shortcut.mod ? "⌘" : "") + key;
|
|
297
|
+
const parts = [];
|
|
298
|
+
if (shortcut.ctrl || shortcut.mod) parts.push("Ctrl");
|
|
299
|
+
if (shortcut.meta) parts.push("Win");
|
|
300
|
+
if (shortcut.alt) parts.push("Alt");
|
|
301
|
+
if (shortcut.shift) parts.push("Shift");
|
|
302
|
+
parts.push(key);
|
|
303
|
+
return parts.join("+");
|
|
304
|
+
}
|
|
305
|
+
function capitalize(s) {
|
|
306
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
307
|
+
}
|
|
236
308
|
var RecentStore = class {
|
|
237
309
|
storageKey;
|
|
238
310
|
max;
|
|
239
311
|
storage;
|
|
240
|
-
|
|
312
|
+
rank;
|
|
313
|
+
constructor(storageKey, max, storage = defaultStorage(), rank = "recent") {
|
|
241
314
|
this.storageKey = storageKey;
|
|
242
315
|
this.max = max;
|
|
243
316
|
this.storage = storage;
|
|
317
|
+
this.rank = rank;
|
|
244
318
|
}
|
|
245
319
|
load() {
|
|
246
320
|
if (!this.storage || this.max <= 0) return [];
|
|
@@ -249,20 +323,26 @@ var RecentStore = class {
|
|
|
249
323
|
if (!raw) return [];
|
|
250
324
|
const parsed = JSON.parse(raw);
|
|
251
325
|
if (!Array.isArray(parsed)) return [];
|
|
252
|
-
return parsed.filter(isEntry).slice(0, this.max);
|
|
326
|
+
return this.order(parsed.filter(isEntry), Date.now()).slice(0, this.max);
|
|
253
327
|
} catch {
|
|
254
328
|
return [];
|
|
255
329
|
}
|
|
256
330
|
}
|
|
257
|
-
add(command, current = this.load()) {
|
|
331
|
+
add(command, current = this.load(), now = Date.now()) {
|
|
258
332
|
if (this.max <= 0) return [];
|
|
259
|
-
const
|
|
333
|
+
const previous = current.find((e) => e.id === command.id);
|
|
334
|
+
const entry = {
|
|
260
335
|
id: command.id,
|
|
261
336
|
label: command.label,
|
|
337
|
+
...this.rank === "frequent" ? {
|
|
338
|
+
count: (previous?.count ?? (previous ? 1 : 0)) + 1,
|
|
339
|
+
at: now
|
|
340
|
+
} : {},
|
|
262
341
|
...command.group ? { group: command.group } : {},
|
|
263
342
|
...command.description ? { description: command.description } : {},
|
|
264
343
|
...command.route !== void 0 && isSerializable(command.route) ? { route: command.route } : {}
|
|
265
|
-
}
|
|
344
|
+
};
|
|
345
|
+
const next = this.order([entry, ...current.filter((e) => e.id !== command.id)], now).slice(0, this.max);
|
|
266
346
|
this.save(next);
|
|
267
347
|
return next;
|
|
268
348
|
}
|
|
@@ -271,12 +351,25 @@ var RecentStore = class {
|
|
|
271
351
|
this.storage?.removeItem(this.storageKey);
|
|
272
352
|
} catch {}
|
|
273
353
|
}
|
|
354
|
+
order(entries, now) {
|
|
355
|
+
if (this.rank !== "frequent") return entries;
|
|
356
|
+
return entries.map((entry, index) => ({
|
|
357
|
+
entry,
|
|
358
|
+
index,
|
|
359
|
+
score: frecency(entry, now)
|
|
360
|
+
})).sort((a, b) => b.score - a.score || a.index - b.index).map((x) => x.entry);
|
|
361
|
+
}
|
|
274
362
|
save(entries) {
|
|
275
363
|
try {
|
|
276
364
|
this.storage?.setItem(this.storageKey, JSON.stringify(entries));
|
|
277
365
|
} catch {}
|
|
278
366
|
}
|
|
279
367
|
};
|
|
368
|
+
const HALF_LIFE_MS = 6048e5;
|
|
369
|
+
function frecency(entry, now) {
|
|
370
|
+
const age = entry.at === void 0 ? 0 : Math.max(0, now - entry.at);
|
|
371
|
+
return (entry.count ?? 1) * Math.pow(.5, age / HALF_LIFE_MS);
|
|
372
|
+
}
|
|
280
373
|
function defaultStorage() {
|
|
281
374
|
try {
|
|
282
375
|
return typeof localStorage === "undefined" ? null : localStorage;
|
|
@@ -298,11 +391,12 @@ function isSerializable(route) {
|
|
|
298
391
|
}
|
|
299
392
|
}
|
|
300
393
|
const RECENT_SECTION_ID = "recent";
|
|
394
|
+
const PINNED_SECTION_ID = "pinned";
|
|
301
395
|
var CommandPaletteService = class CommandPaletteService {
|
|
302
396
|
config = inject(COMMAND_PALETTE_CONFIG);
|
|
303
397
|
router = inject(Router, { optional: true });
|
|
304
398
|
document = inject(DOCUMENT);
|
|
305
|
-
recentStore = this.config.recent ? new RecentStore(this.config.recent.storageKey ?? "rr-cp:recent", this.config.recent.max ?? 5) : null;
|
|
399
|
+
recentStore = this.config.recent ? new RecentStore(this.config.recent.storageKey ?? "rr-cp:recent", this.config.recent.max ?? 5, this.config.recent.storage, this.config.recent.rank) : null;
|
|
306
400
|
_isOpen = signal(false, ...ngDevMode ? [{ debugName: "_isOpen" }] : /* istanbul ignore next */ []);
|
|
307
401
|
_query = signal("", ...ngDevMode ? [{ debugName: "_query" }] : /* istanbul ignore next */ []);
|
|
308
402
|
registrations = signal([], ...ngDevMode ? [{ debugName: "registrations" }] : /* istanbul ignore next */ []);
|
|
@@ -311,8 +405,10 @@ var CommandPaletteService = class CommandPaletteService {
|
|
|
311
405
|
recents = signal(this.recentStore?.load() ?? [], ...ngDevMode ? [{ debugName: "recents" }] : /* istanbul ignore next */ []);
|
|
312
406
|
pending = /* @__PURE__ */ new Map();
|
|
313
407
|
pathIds = signal([], ...ngDevMode ? [{ debugName: "pathIds" }] : /* istanbul ignore next */ []);
|
|
408
|
+
promptCommand = signal(null, ...ngDevMode ? [{ debugName: "promptCommand" }] : /* istanbul ignore next */ []);
|
|
314
409
|
returnFocus = null;
|
|
315
410
|
isOpen = this._isOpen.asReadonly();
|
|
411
|
+
prompt = this.promptCommand.asReadonly();
|
|
316
412
|
query = this._query.asReadonly();
|
|
317
413
|
path = computed(() => {
|
|
318
414
|
const path = [];
|
|
@@ -338,7 +434,19 @@ var CommandPaletteService = class CommandPaletteService {
|
|
|
338
434
|
return [...byId.values()];
|
|
339
435
|
}, ...ngDevMode ? [{ debugName: "commands" }] : /* istanbul ignore next */ []);
|
|
340
436
|
loading = computed(() => [...this.providerState().values()].some((s) => s.loading), ...ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []);
|
|
341
|
-
|
|
437
|
+
activePrefix = computed(() => this.parseQuery(this._query()).prefix, ...ngDevMode ? [{ debugName: "activePrefix" }] : /* istanbul ignore next */ []);
|
|
438
|
+
sections = computed(() => this.buildSections(this._query()), ...ngDevMode ? [{ debugName: "sections" }] : /* istanbul ignore next */ []);
|
|
439
|
+
hotkeyCommands = computed(() => descendants(this.commands()).filter((c) => c.hotkey && !isParent(c)), ...ngDevMode ? [{ debugName: "hotkeyCommands" }] : /* istanbul ignore next */ []);
|
|
440
|
+
runHotkey(event, apple) {
|
|
441
|
+
if (this._isOpen()) return false;
|
|
442
|
+
for (const command of this.hotkeyCommands()) {
|
|
443
|
+
if (!(typeof command.hotkey === "string" ? [command.hotkey] : command.hotkey ?? []).some((k) => matchesShortcut(event, parseShortcut(k), apple))) continue;
|
|
444
|
+
if (command.disabled) return false;
|
|
445
|
+
this.execute(command);
|
|
446
|
+
return true;
|
|
447
|
+
}
|
|
448
|
+
return false;
|
|
449
|
+
}
|
|
342
450
|
open(query = "") {
|
|
343
451
|
if (!this._isOpen()) {
|
|
344
452
|
const active = this.document.activeElement;
|
|
@@ -346,6 +454,7 @@ var CommandPaletteService = class CommandPaletteService {
|
|
|
346
454
|
}
|
|
347
455
|
this._isOpen.set(true);
|
|
348
456
|
this.pathIds.set([]);
|
|
457
|
+
this.promptCommand.set(null);
|
|
349
458
|
this.setQuery(query);
|
|
350
459
|
}
|
|
351
460
|
close() {
|
|
@@ -354,6 +463,7 @@ var CommandPaletteService = class CommandPaletteService {
|
|
|
354
463
|
this.cancelAll();
|
|
355
464
|
this._query.set("");
|
|
356
465
|
this.pathIds.set([]);
|
|
466
|
+
this.promptCommand.set(null);
|
|
357
467
|
this.providerState.set(/* @__PURE__ */ new Map());
|
|
358
468
|
const target = this.returnFocus;
|
|
359
469
|
this.returnFocus = null;
|
|
@@ -369,8 +479,13 @@ var CommandPaletteService = class CommandPaletteService {
|
|
|
369
479
|
}
|
|
370
480
|
back(levels = 1) {
|
|
371
481
|
const path = this.path();
|
|
372
|
-
|
|
373
|
-
|
|
482
|
+
let remaining = levels;
|
|
483
|
+
if (levels < 1 || !(path.length || this.promptCommand())) return false;
|
|
484
|
+
if (this.promptCommand()) {
|
|
485
|
+
this.promptCommand.set(null);
|
|
486
|
+
remaining--;
|
|
487
|
+
}
|
|
488
|
+
if (remaining > 0) this.pathIds.set(path.slice(0, Math.max(0, path.length - remaining)).map((c) => c.id));
|
|
374
489
|
this.setQuery("");
|
|
375
490
|
return true;
|
|
376
491
|
}
|
|
@@ -382,7 +497,7 @@ var CommandPaletteService = class CommandPaletteService {
|
|
|
382
497
|
}
|
|
383
498
|
registerProvider(provider, destroyRef) {
|
|
384
499
|
this.providers.update((list) => [...list.filter((p) => p.id !== provider.id), provider]);
|
|
385
|
-
if (this._isOpen() && !this.pathIds().length) this.scheduleProvider(provider, this._query());
|
|
500
|
+
if (this._isOpen() && !this.pathIds().length && !this.promptCommand()) this.scheduleProvider(provider, this._query());
|
|
386
501
|
const remove = () => {
|
|
387
502
|
if (!this.providers().includes(provider)) return;
|
|
388
503
|
this.cancel(provider.id);
|
|
@@ -405,14 +520,29 @@ var CommandPaletteService = class CommandPaletteService {
|
|
|
405
520
|
this.setQuery("");
|
|
406
521
|
return;
|
|
407
522
|
}
|
|
408
|
-
|
|
523
|
+
let query = this.parseQuery(this._query()).text;
|
|
524
|
+
let value;
|
|
525
|
+
if (!isParent(command) && command.prompt !== void 0) {
|
|
526
|
+
if (this.promptCommand()?.id !== command.id) {
|
|
527
|
+
this.cancelAll();
|
|
528
|
+
this.providerState.set(/* @__PURE__ */ new Map());
|
|
529
|
+
this.promptCommand.set(command);
|
|
530
|
+
this.setQuery("");
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
query = value = this._query().trim();
|
|
534
|
+
if (!value) return;
|
|
535
|
+
}
|
|
409
536
|
if (this.recentStore) this.recents.set(this.recentStore.add(command, this.recents()));
|
|
410
537
|
this.close();
|
|
411
538
|
if (command.route !== void 0) {
|
|
412
539
|
if (!this.router) throw new Error("ngx-command-palette: route commands need provideRouter()");
|
|
413
540
|
const { route, navigationExtras } = command;
|
|
414
541
|
await (typeof route === "string" ? this.router.navigateByUrl(route, navigationExtras) : this.router.navigate(route, navigationExtras));
|
|
415
|
-
} else await command.run({ query }
|
|
542
|
+
} else await command.run(value === void 0 ? { query } : {
|
|
543
|
+
query,
|
|
544
|
+
value
|
|
545
|
+
});
|
|
416
546
|
}
|
|
417
547
|
clearRecent() {
|
|
418
548
|
this.recentStore?.clear();
|
|
@@ -425,9 +555,28 @@ var CommandPaletteService = class CommandPaletteService {
|
|
|
425
555
|
remove();
|
|
426
556
|
};
|
|
427
557
|
}
|
|
428
|
-
|
|
558
|
+
parseQuery(raw) {
|
|
559
|
+
const trimmed = raw.trim();
|
|
560
|
+
const prefix = this.config.prefixes.find((p) => p.prefix && trimmed.startsWith(p.prefix)) ?? null;
|
|
561
|
+
return {
|
|
562
|
+
prefix,
|
|
563
|
+
text: prefix ? trimmed.slice(prefix.prefix.length).trim() : trimmed
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
buildSections(rawQuery) {
|
|
429
567
|
const defaultGroup = this.config.labels.defaultGroup;
|
|
430
|
-
const
|
|
568
|
+
const prompt = this.promptCommand();
|
|
569
|
+
if (prompt) {
|
|
570
|
+
const items = [toResult(prompt, `x:${prompt.id}`, 0, [])];
|
|
571
|
+
return [{
|
|
572
|
+
id: "prompt",
|
|
573
|
+
label: prompt.group ?? defaultGroup,
|
|
574
|
+
items
|
|
575
|
+
}];
|
|
576
|
+
}
|
|
577
|
+
const { prefix, text: query } = this.parseQuery(rawQuery);
|
|
578
|
+
const levelCommands = this.levelCommands();
|
|
579
|
+
const commands = prefix ? levelCommands.filter((c) => inPrefix(c, prefix, defaultGroup)) : levelCommands;
|
|
431
580
|
const groups = /* @__PURE__ */ new Map();
|
|
432
581
|
const push = (group, result) => {
|
|
433
582
|
const list = groups.get(group);
|
|
@@ -437,7 +586,14 @@ var CommandPaletteService = class CommandPaletteService {
|
|
|
437
586
|
const sections = [];
|
|
438
587
|
const topLevel = !this.pathIds().length;
|
|
439
588
|
if (!query) {
|
|
440
|
-
const
|
|
589
|
+
const pinned = prefix ? [] : commands.filter((c) => !isHidden(c) && isPinned(c)).map((c) => toResult(c, `pin:${c.id}`, 0, []));
|
|
590
|
+
if (pinned.length) sections.push({
|
|
591
|
+
id: PINNED_SECTION_ID,
|
|
592
|
+
label: this.config.labels.pinned,
|
|
593
|
+
items: pinned
|
|
594
|
+
});
|
|
595
|
+
const pinnedIds = new Set(pinned.map((r) => r.command.id));
|
|
596
|
+
const recent = topLevel && !prefix ? this.recentResults(commands).filter((r) => !pinnedIds.has(r.command.id)) : [];
|
|
441
597
|
if (recent.length) sections.push({
|
|
442
598
|
id: RECENT_SECTION_ID,
|
|
443
599
|
label: this.config.labels.recent,
|
|
@@ -469,6 +625,7 @@ var CommandPaletteService = class CommandPaletteService {
|
|
|
469
625
|
});
|
|
470
626
|
const states = this.providerState();
|
|
471
627
|
for (const provider of topLevel ? this.providers() : []) {
|
|
628
|
+
if (prefix && (prefix.kind || prefix.groups && !prefix.groups.includes(provider.group))) continue;
|
|
472
629
|
const state = states.get(provider.id);
|
|
473
630
|
if (!state?.items.length) continue;
|
|
474
631
|
const items = state.items.filter((command) => !isHidden(command)).map((command) => {
|
|
@@ -500,13 +657,17 @@ var CommandPaletteService = class CommandPaletteService {
|
|
|
500
657
|
return results;
|
|
501
658
|
}
|
|
502
659
|
scheduleProviders() {
|
|
503
|
-
if (this.pathIds().length) return;
|
|
660
|
+
if (this.pathIds().length || this.promptCommand()) return;
|
|
504
661
|
const query = this._query();
|
|
505
662
|
for (const provider of this.providers()) this.scheduleProvider(provider, query);
|
|
506
663
|
}
|
|
507
664
|
scheduleProvider(provider, rawQuery) {
|
|
508
665
|
this.cancel(provider.id);
|
|
509
|
-
const query =
|
|
666
|
+
const { prefix, text: query } = this.parseQuery(rawQuery);
|
|
667
|
+
if (prefix && (prefix.kind || prefix.groups && !prefix.groups.includes(provider.group))) {
|
|
668
|
+
this.setProviderState(provider.id, null);
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
510
671
|
if (query.length < (provider.minQueryLength ?? 1)) {
|
|
511
672
|
this.setProviderState(provider.id, null);
|
|
512
673
|
return;
|
|
@@ -618,6 +779,16 @@ function toResult(command, key, score, indices) {
|
|
|
618
779
|
segments: highlightSegments(command.label, indices)
|
|
619
780
|
};
|
|
620
781
|
}
|
|
782
|
+
function inPrefix(command, prefix, defaultGroup) {
|
|
783
|
+
if (prefix.groups && !prefix.groups.includes(command.group ?? defaultGroup)) return false;
|
|
784
|
+
if (prefix.kind === "route") return command.route !== void 0;
|
|
785
|
+
if (prefix.kind === "action") return typeof command.run === "function";
|
|
786
|
+
return true;
|
|
787
|
+
}
|
|
788
|
+
function isPinned(command) {
|
|
789
|
+
const { pinned } = command;
|
|
790
|
+
return typeof pinned === "function" ? pinned() : !!pinned;
|
|
791
|
+
}
|
|
621
792
|
function isParent(command) {
|
|
622
793
|
return Array.isArray(command.children);
|
|
623
794
|
}
|
|
@@ -686,73 +857,6 @@ function moveIndex(disabled, current, action) {
|
|
|
686
857
|
case "prev": return current < 0 ? findFrom(count - 1, -1, false) : findFrom(current - 1, -1, true);
|
|
687
858
|
}
|
|
688
859
|
}
|
|
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
860
|
var CommandItemTemplate = class CommandItemTemplate {
|
|
757
861
|
template = inject(TemplateRef);
|
|
758
862
|
static ngTemplateContextGuard(_dir, ctx) {
|
|
@@ -832,7 +936,16 @@ var CommandPaletteComponent = class CommandPaletteComponent {
|
|
|
832
936
|
labels = this.config.labels;
|
|
833
937
|
apple = isApplePlatform();
|
|
834
938
|
shortcuts = (typeof this.config.shortcut === "string" ? [this.config.shortcut] : this.config.shortcut).map(parseShortcut);
|
|
939
|
+
shortcutEnabled() {
|
|
940
|
+
const enabled = this.config.shortcutEnabled;
|
|
941
|
+
return typeof enabled === "function" ? enabled() : enabled;
|
|
942
|
+
}
|
|
835
943
|
shortcutLabel = this.shortcuts.length ? formatShortcut(this.shortcuts[0], this.apple) : "";
|
|
944
|
+
keysOf(command) {
|
|
945
|
+
if (command.shortcut?.length) return command.shortcut;
|
|
946
|
+
const hotkey = typeof command.hotkey === "string" ? command.hotkey : command.hotkey?.[0];
|
|
947
|
+
return hotkey ? [formatShortcut(parseShortcut(hotkey), this.apple)] : [];
|
|
948
|
+
}
|
|
836
949
|
prefersDark = signal(false, ...ngDevMode ? [{ debugName: "prefersDark" }] : /* istanbul ignore next */ []);
|
|
837
950
|
resolvedTheme = computed(() => {
|
|
838
951
|
const theme = this.theme() ?? this.config.theme;
|
|
@@ -867,8 +980,15 @@ var CommandPaletteComponent = class CommandPaletteComponent {
|
|
|
867
980
|
const count = this.items().length;
|
|
868
981
|
if (count === 0) return this.labels.empty;
|
|
869
982
|
const path = this.service.path();
|
|
983
|
+
const prompt = this.service.prompt();
|
|
984
|
+
if (prompt) return this.labels.prompt.replace("{name}", prompt.label);
|
|
870
985
|
return (path.length ? this.labels.level : this.labels.results).replace("{name}", path[path.length - 1]?.label ?? "").replace("{count}", String(count));
|
|
871
986
|
}, ...ngDevMode ? [{ debugName: "status" }] : /* istanbul ignore next */ []);
|
|
987
|
+
crumbs = computed(() => {
|
|
988
|
+
const prompt = this.service.prompt();
|
|
989
|
+
return prompt ? [...this.service.path(), prompt] : this.service.path();
|
|
990
|
+
}, ...ngDevMode ? [{ debugName: "crumbs" }] : /* istanbul ignore next */ []);
|
|
991
|
+
placeholder = computed(() => this.service.prompt()?.prompt ?? this.labels.placeholder, ...ngDevMode ? [{ debugName: "placeholder" }] : /* istanbul ignore next */ []);
|
|
872
992
|
constructor() {
|
|
873
993
|
const media = this.document.defaultView?.matchMedia?.("(prefers-color-scheme: dark)");
|
|
874
994
|
if (media) {
|
|
@@ -910,7 +1030,7 @@ var CommandPaletteComponent = class CommandPaletteComponent {
|
|
|
910
1030
|
this.trapTab(event);
|
|
911
1031
|
return;
|
|
912
1032
|
}
|
|
913
|
-
if (event.key === "Backspace" && !event.isComposing && this.service.query() === "" && this.
|
|
1033
|
+
if (event.key === "Backspace" && !event.isComposing && this.service.query() === "" && this.crumbs().length) {
|
|
914
1034
|
event.preventDefault();
|
|
915
1035
|
this.activeKey.set(null);
|
|
916
1036
|
this.service.back();
|
|
@@ -948,7 +1068,11 @@ var CommandPaletteComponent = class CommandPaletteComponent {
|
|
|
948
1068
|
onDocumentKeydown(event) {
|
|
949
1069
|
if (event.repeat || event.isComposing) return;
|
|
950
1070
|
const typing = isEditable(event.target);
|
|
951
|
-
if (this.
|
|
1071
|
+
if ((this.config.shortcutInFields || !typing) && (event.ctrlKey || event.metaKey || event.altKey && !typing) && this.service.runHotkey(event, this.apple)) {
|
|
1072
|
+
event.preventDefault();
|
|
1073
|
+
return;
|
|
1074
|
+
}
|
|
1075
|
+
if (this.shortcuts.some((s) => (!typing || this.config.shortcutInFields && (s.mod || s.ctrl || s.meta || s.alt)) && matchesShortcut(event, s, this.apple)) && (this.service.isOpen() || this.shortcutEnabled())) {
|
|
952
1076
|
event.preventDefault();
|
|
953
1077
|
this.activeKey.set(null);
|
|
954
1078
|
this.service.toggle();
|
|
@@ -1033,8 +1157,8 @@ var CommandPaletteComponent = class CommandPaletteComponent {
|
|
|
1033
1157
|
isSignal: true
|
|
1034
1158
|
}],
|
|
1035
1159
|
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: #
|
|
1160
|
+
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",
|
|
1161
|
+
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
1162
|
dependencies: [{
|
|
1039
1163
|
kind: "directive",
|
|
1040
1164
|
type: NgTemplateOutlet,
|
|
@@ -1066,8 +1190,8 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
1066
1190
|
"(document:keydown)": "onDocumentKeydown($event)",
|
|
1067
1191
|
"(document:focusin)": "onDocumentFocusin($event)"
|
|
1068
1192
|
},
|
|
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: #
|
|
1193
|
+
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",
|
|
1194
|
+
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
1195
|
}]
|
|
1072
1196
|
}],
|
|
1073
1197
|
ctorParameters: () => [],
|
|
@@ -1104,6 +1228,6 @@ function isEditable(target) {
|
|
|
1104
1228
|
const tag = el.tagName.toLowerCase();
|
|
1105
1229
|
return tag === "input" || tag === "textarea" || tag === "select" || el.isContentEditable;
|
|
1106
1230
|
}
|
|
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 };
|
|
1231
|
+
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
1232
|
|
|
1109
1233
|
//# sourceMappingURL=rrstudioapps-ngx-command-palette.mjs.map
|