@nanahoshi/mona-ui 0.25.1 → 0.26.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.
- package/README.md +2 -0
- package/command/package.json +4 -0
- package/docs/auto-complete.md +733 -0
- package/docs/avatar.md +220 -0
- package/docs/breadcrumb.md +320 -0
- package/docs/button-group.md +392 -0
- package/docs/button.md +256 -0
- package/docs/calendar.md +515 -0
- package/docs/card.md +292 -0
- package/docs/chart.md +4058 -0
- package/docs/checkbox.md +374 -0
- package/docs/chip.md +339 -0
- package/docs/circular-progress-bar.md +287 -0
- package/docs/collapsible.md +308 -0
- package/docs/color-gradient.md +336 -0
- package/docs/color-palette.md +317 -0
- package/docs/color-picker.md +387 -0
- package/docs/combo-box.md +764 -0
- package/docs/command.md +582 -0
- package/docs/contextmenu.md +530 -0
- package/docs/date-picker.md +251 -0
- package/docs/datetime-picker.md +284 -0
- package/docs/decimal-textbox.md +260 -0
- package/docs/dialog.md +822 -0
- package/docs/dropdown-button.md +507 -0
- package/docs/dropdown-list.md +779 -0
- package/docs/editor.md +374 -0
- package/docs/expansion-panel.md +348 -0
- package/docs/fieldset.md +217 -0
- package/docs/forms.md +162 -0
- package/docs/grid.md +2053 -0
- package/docs/input.md +197 -0
- package/docs/installation.md +54 -0
- package/docs/introduction.md +46 -0
- package/docs/label.md +340 -0
- package/docs/list-box.md +637 -0
- package/docs/list-view.md +584 -0
- package/docs/menubar.md +559 -0
- package/docs/multi-select.md +765 -0
- package/docs/notification.md +460 -0
- package/docs/numeric-textbox.md +301 -0
- package/docs/otp-input.md +539 -0
- package/docs/pager.md +513 -0
- package/docs/placeholder.md +176 -0
- package/docs/popover.md +423 -0
- package/docs/popup-menu.md +658 -0
- package/docs/popup.md +617 -0
- package/docs/progress-bar.md +368 -0
- package/docs/radio-button.md +451 -0
- package/docs/range-slider.md +367 -0
- package/docs/rating.md +518 -0
- package/docs/scroll-view.md +375 -0
- package/docs/segmented.md +434 -0
- package/docs/sheet.md +348 -0
- package/docs/sidebar.md +1126 -0
- package/docs/skeleton.md +181 -0
- package/docs/slider.md +423 -0
- package/docs/spinner.md +370 -0
- package/docs/split-button.md +522 -0
- package/docs/splitter.md +342 -0
- package/docs/stepper.md +539 -0
- package/docs/switch.md +340 -0
- package/docs/tabs.md +542 -0
- package/docs/textarea.md +196 -0
- package/docs/textbox.md +332 -0
- package/docs/theming.md +403 -0
- package/docs/time-picker.md +254 -0
- package/docs/tooltip-directive.md +340 -0
- package/docs/tooltip.md +321 -0
- package/docs/tree-view.md +1018 -0
- package/docs/window.md +663 -0
- package/fesm2022/nanahoshi-mona-ui-auto-complete.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-breadcrumb.mjs +8 -0
- package/fesm2022/nanahoshi-mona-ui-button.mjs +12 -0
- package/fesm2022/nanahoshi-mona-ui-calendar.mjs +5 -2
- package/fesm2022/nanahoshi-mona-ui-chart.mjs +86 -0
- package/fesm2022/nanahoshi-mona-ui-check-box.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-circular-progress-bar.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-collapsible.mjs +16 -2
- package/fesm2022/nanahoshi-mona-ui-combo-box.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-command.mjs +924 -0
- package/fesm2022/nanahoshi-mona-ui-common.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-contextmenu.mjs +10 -6
- package/fesm2022/nanahoshi-mona-ui-date-picker.mjs +2 -1
- package/fesm2022/nanahoshi-mona-ui-datetime-picker.mjs +2 -1
- package/fesm2022/nanahoshi-mona-ui-dialog.mjs +9 -5
- package/fesm2022/nanahoshi-mona-ui-dropdown-button.mjs +9 -5
- package/fesm2022/nanahoshi-mona-ui-dropdowns.mjs +55 -1
- package/fesm2022/nanahoshi-mona-ui-editor.mjs +3 -2
- package/fesm2022/nanahoshi-mona-ui-expansion-panel.mjs +13 -0
- package/fesm2022/nanahoshi-mona-ui-fieldset.mjs +5 -0
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-footer-row.component-2tVhD2hK.mjs → nanahoshi-mona-ui-grid-grid-footer-row.component-DjNnVxHE.mjs} +2 -2
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-list.component-BAN70Wcn.mjs → nanahoshi-mona-ui-grid-grid-list.component-ihQIKeP-.mjs} +5 -5
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-row.component-C_kCaA5b.mjs → nanahoshi-mona-ui-grid-grid-row.component-BpnybNcs.mjs} +18 -35
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-virtual-list.component-BsNfrAHz.mjs → nanahoshi-mona-ui-grid-grid-virtual-list.component-CYlgfc7c.mjs} +5 -5
- package/fesm2022/{nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-CEfVa7eo.mjs → nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-LCzfCYd3.mjs} +4653 -4529
- package/fesm2022/nanahoshi-mona-ui-grid.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-internal-list.mjs +1 -0
- package/fesm2022/nanahoshi-mona-ui-internal-popup-menu.mjs +168 -0
- package/fesm2022/nanahoshi-mona-ui-internal-tree.mjs +19 -1
- package/fesm2022/nanahoshi-mona-ui-list-box.mjs +14 -0
- package/fesm2022/nanahoshi-mona-ui-list-view.mjs +32 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-menubar.mjs +15 -8
- package/fesm2022/nanahoshi-mona-ui-multi-select.mjs +8 -5
- package/fesm2022/nanahoshi-mona-ui-notification.mjs +9 -0
- package/fesm2022/nanahoshi-mona-ui-numeric-text-box.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-otp-input.mjs +5 -0
- package/fesm2022/nanahoshi-mona-ui-pager.mjs +2 -1
- package/fesm2022/nanahoshi-mona-ui-popover.mjs +14 -6
- package/fesm2022/nanahoshi-mona-ui-popup-menu.mjs +48 -183
- package/fesm2022/nanahoshi-mona-ui-popup.mjs +16 -0
- package/fesm2022/nanahoshi-mona-ui-progress-bar.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-rating.mjs +2 -0
- package/fesm2022/nanahoshi-mona-ui-segmented.mjs +1 -0
- package/fesm2022/nanahoshi-mona-ui-sheet.mjs +5 -5
- package/fesm2022/nanahoshi-mona-ui-sidebar.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-slider.mjs +7 -2
- package/fesm2022/nanahoshi-mona-ui-split-button.mjs +9 -6
- package/fesm2022/nanahoshi-mona-ui-stepper.mjs +18 -21
- package/fesm2022/nanahoshi-mona-ui-tabs.mjs +11 -8
- package/fesm2022/nanahoshi-mona-ui-text-box.mjs +9 -1
- package/fesm2022/nanahoshi-mona-ui-time-picker.mjs +2 -1
- package/fesm2022/nanahoshi-mona-ui-tooltip.mjs +16 -5
- package/fesm2022/nanahoshi-mona-ui-tree-view.mjs +13 -11
- package/fesm2022/nanahoshi-mona-ui-window.mjs +12 -5
- package/i18n/catalogs/en-US.messages.json +10 -0
- package/internal/popup-menu/package.json +4 -0
- package/llms.txt +123 -0
- package/locales/ar-sa/ar-sa.messages.json +10 -0
- package/locales/de-de/de-de.messages.json +10 -0
- package/locales/es-es/es-es.messages.json +10 -0
- package/locales/fr-fr/fr-fr.messages.json +10 -0
- package/locales/id-id/id-id.messages.json +10 -0
- package/locales/it-it/it-it.messages.json +10 -0
- package/locales/ja-jp/ja-jp.messages.json +10 -0
- package/locales/ko-kr/ko-kr.messages.json +10 -0
- package/locales/pt-br/pt-br.messages.json +10 -0
- package/locales/ru-ru/ru-ru.messages.json +10 -0
- package/locales/tr-tr/tr-tr.messages.json +10 -0
- package/locales/zh-cn/zh-cn.messages.json +10 -0
- package/locales/zh-tw/zh-tw.messages.json +10 -0
- package/package.json +9 -1
- package/types/nanahoshi-mona-ui-auto-complete.d.ts +1 -1
- package/types/nanahoshi-mona-ui-breadcrumb.d.ts +8 -0
- package/types/nanahoshi-mona-ui-button.d.ts +12 -0
- package/types/nanahoshi-mona-ui-calendar.d.ts +3 -0
- package/types/nanahoshi-mona-ui-chart.d.ts +200 -0
- package/types/nanahoshi-mona-ui-check-box.d.ts +4 -0
- package/types/nanahoshi-mona-ui-circular-progress-bar.d.ts +4 -0
- package/types/nanahoshi-mona-ui-collapsible.d.ts +10 -0
- package/types/nanahoshi-mona-ui-combo-box.d.ts +1 -1
- package/types/nanahoshi-mona-ui-command.d.ts +253 -0
- package/types/nanahoshi-mona-ui-common.d.ts +17 -1
- package/types/nanahoshi-mona-ui-contextmenu.d.ts +5 -2
- package/types/nanahoshi-mona-ui-date-picker.d.ts +2 -1
- package/types/nanahoshi-mona-ui-datetime-picker.d.ts +2 -1
- package/types/nanahoshi-mona-ui-dialog.d.ts +58 -1
- package/types/nanahoshi-mona-ui-dropdown-button.d.ts +7 -3
- package/types/nanahoshi-mona-ui-dropdowns.d.ts +55 -1
- package/types/nanahoshi-mona-ui-editor.d.ts +31 -0
- package/types/nanahoshi-mona-ui-expansion-panel.d.ts +13 -0
- package/types/nanahoshi-mona-ui-fieldset.d.ts +5 -0
- package/types/nanahoshi-mona-ui-grid.d.ts +162 -35
- package/types/nanahoshi-mona-ui-i18n.d.ts +144 -1
- package/types/nanahoshi-mona-ui-internal-list.d.ts +16 -1
- package/types/nanahoshi-mona-ui-internal-popup-menu.d.ts +165 -0
- package/types/nanahoshi-mona-ui-internal-tree.d.ts +21 -2
- package/types/nanahoshi-mona-ui-internal.d.ts +4 -5
- package/types/nanahoshi-mona-ui-label.d.ts +1 -0
- package/types/nanahoshi-mona-ui-list-box.d.ts +27 -4
- package/types/nanahoshi-mona-ui-list-view.d.ts +34 -1
- package/types/nanahoshi-mona-ui-list.d.ts +1 -1
- package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-de-de.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-es-es.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-id-id.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-it-it.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +10 -0
- package/types/nanahoshi-mona-ui-menubar.d.ts +10 -3
- package/types/nanahoshi-mona-ui-multi-select.d.ts +3 -3
- package/types/nanahoshi-mona-ui-notification.d.ts +9 -0
- package/types/nanahoshi-mona-ui-numeric-text-box.d.ts +1 -1
- package/types/nanahoshi-mona-ui-otp-input.d.ts +1 -0
- package/types/nanahoshi-mona-ui-pager.d.ts +5 -1
- package/types/nanahoshi-mona-ui-popover.d.ts +9 -1
- package/types/nanahoshi-mona-ui-popup-menu.d.ts +48 -161
- package/types/nanahoshi-mona-ui-popup.d.ts +16 -0
- package/types/nanahoshi-mona-ui-progress-bar.d.ts +4 -0
- package/types/nanahoshi-mona-ui-rating.d.ts +2 -0
- package/types/nanahoshi-mona-ui-segmented.d.ts +1 -0
- package/types/nanahoshi-mona-ui-sheet.d.ts +1 -1
- package/types/nanahoshi-mona-ui-slider.d.ts +2 -0
- package/types/nanahoshi-mona-ui-spinner.d.ts +7 -0
- package/types/nanahoshi-mona-ui-split-button.d.ts +7 -4
- package/types/nanahoshi-mona-ui-stepper.d.ts +11 -2
- package/types/nanahoshi-mona-ui-tabs.d.ts +4 -1
- package/types/nanahoshi-mona-ui-text-box.d.ts +9 -1
- package/types/nanahoshi-mona-ui-time-picker.d.ts +2 -1
- package/types/nanahoshi-mona-ui-tooltip.d.ts +10 -2
- package/types/nanahoshi-mona-ui-tree-view.d.ts +6 -5
- package/types/nanahoshi-mona-ui-window.d.ts +66 -1
|
@@ -0,0 +1,924 @@
|
|
|
1
|
+
import * as i1 from '@angular/cdk/a11y';
|
|
2
|
+
import { LiveAnnouncer, A11yModule } from '@angular/cdk/a11y';
|
|
3
|
+
import * as i0 from '@angular/core';
|
|
4
|
+
import { signal, inject, computed, input, output, booleanAttribute, model, effect, untracked, afterRenderEffect, Component, Directive, Injector, Renderer2, contentChild, TemplateRef, viewChild, DestroyRef, afterNextRender, ElementRef } from '@angular/core';
|
|
5
|
+
import { ImmutableSet } from '@mirei/ts-collections';
|
|
6
|
+
import { formatNumber, MonaI18nService } from '@nanahoshi/mona-ui/i18n';
|
|
7
|
+
import { createElementControlId, positionGlobalOverlay, inertOutside } from '@nanahoshi/mona-ui/internal';
|
|
8
|
+
import { cva } from 'class-variance-authority';
|
|
9
|
+
import { DOCUMENT, NgTemplateOutlet } from '@angular/common';
|
|
10
|
+
import { PopupService } from '@nanahoshi/mona-ui/popup';
|
|
11
|
+
import { merge, take } from 'rxjs';
|
|
12
|
+
import { LucideSearch } from '@lucide/angular';
|
|
13
|
+
|
|
14
|
+
// Generated from i18n/catalogs/en-US.messages.json by scripts/generate-locale-catalogs.ts. Do not edit.
|
|
15
|
+
// Edit the JSON file and run `npm run generate:locale-catalogs`.
|
|
16
|
+
function localizeNumber(value, options) {
|
|
17
|
+
return formatNumber(value, "en-US", options);
|
|
18
|
+
}
|
|
19
|
+
const COMMAND_DEFAULT_MESSAGES = {
|
|
20
|
+
dialogLabel: "Command menu",
|
|
21
|
+
inputLabel: "Search commands",
|
|
22
|
+
listLabel: "Results",
|
|
23
|
+
loading: "Loading",
|
|
24
|
+
noResults: "No results found",
|
|
25
|
+
placeholder: "Type a command or search…",
|
|
26
|
+
resultsAvailable: (count) => count === 1 ? `${localizeNumber(count)} result available` : `${localizeNumber(count)} results available`
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const commandBaseThemeVariants = cva(`
|
|
30
|
+
flex max-h-[inherit] min-h-0 w-full flex-col overflow-hidden
|
|
31
|
+
bg-[var(--mona-command-background,var(--color-surface))] text-foreground
|
|
32
|
+
border border-border-subtle
|
|
33
|
+
`, {
|
|
34
|
+
variants: {
|
|
35
|
+
rounded: {
|
|
36
|
+
none: "rounded-none",
|
|
37
|
+
small: "rounded-sm",
|
|
38
|
+
medium: "rounded-md",
|
|
39
|
+
large: "rounded-lg"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
defaultVariants: {
|
|
43
|
+
rounded: "medium"
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
const commandInputThemeVariants = cva(`
|
|
47
|
+
flex shrink-0 items-center gap-2 border-b border-border-subtle px-3
|
|
48
|
+
focus-within:border-b-focus-indicator
|
|
49
|
+
`);
|
|
50
|
+
const commandInputIconThemeVariants = cva("shrink-0 text-muted-foreground");
|
|
51
|
+
const commandInputFieldThemeVariants = cva(`
|
|
52
|
+
h-10 min-w-0 flex-1 bg-transparent text-sm text-foreground
|
|
53
|
+
placeholder:text-muted-foreground
|
|
54
|
+
outline-none focus-visible:outline-hidden
|
|
55
|
+
`);
|
|
56
|
+
const commandListThemeVariants = cva(`
|
|
57
|
+
min-h-0 flex-1 overflow-y-auto overscroll-contain p-1
|
|
58
|
+
max-h-[var(--mona-command-list-max-height,20rem)]
|
|
59
|
+
`);
|
|
60
|
+
const commandGroupThemeVariants = cva("block");
|
|
61
|
+
const commandGroupHeadingThemeVariants = cva("px-2 py-1.5 text-xs font-medium text-muted-foreground");
|
|
62
|
+
const commandItemThemeVariants = cva(`
|
|
63
|
+
flex min-h-8 cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm text-foreground
|
|
64
|
+
data-[active='true']:bg-[var(--mona-command-item-active-background,var(--color-hover))]
|
|
65
|
+
data-[active='true']:forced-color-adjust-none
|
|
66
|
+
data-[active='true']:forced-colors:bg-[Highlight]
|
|
67
|
+
data-[active='true']:forced-colors:text-[HighlightText]
|
|
68
|
+
data-[disabled='true']:opacity-50
|
|
69
|
+
forced-colors:data-[disabled='true']:text-[GrayText]
|
|
70
|
+
`);
|
|
71
|
+
const commandHighlightMarkThemeVariants = cva("bg-transparent font-semibold text-current underline");
|
|
72
|
+
const commandSeparatorThemeVariants = cva("-mx-1 my-1 block h-px bg-border-subtle forced-colors:bg-[CanvasText]");
|
|
73
|
+
const commandStatusThemeVariants = cva("px-3 py-6 text-center text-sm text-muted-foreground");
|
|
74
|
+
const commandHeaderThemeVariants = cva("flex shrink-0 items-center gap-2 border-b border-border-subtle px-3 py-2 text-xs text-muted-foreground");
|
|
75
|
+
const commandFooterThemeVariants = cva("flex shrink-0 items-center gap-2 border-t border-border-subtle px-3 py-2 text-xs text-muted-foreground");
|
|
76
|
+
const commandShortcutThemeVariants = cva("ms-auto flex shrink-0 items-center gap-1");
|
|
77
|
+
const commandShortcutKeyThemeVariants = cva(`
|
|
78
|
+
rounded-sm border border-border-subtle px-1 font-sans text-xs text-muted-foreground
|
|
79
|
+
in-data-[active='true']:forced-colors:border-[HighlightText]
|
|
80
|
+
in-data-[active='true']:forced-colors:text-[HighlightText]
|
|
81
|
+
`);
|
|
82
|
+
const commandDialogPanelThemeVariants = cva(`
|
|
83
|
+
flex max-h-[inherit] min-h-0 w-full flex-col overflow-hidden rounded-md shadow-(--shadow-overlay)
|
|
84
|
+
outline-none focus-visible:outline-hidden
|
|
85
|
+
`);
|
|
86
|
+
|
|
87
|
+
const MARKS = /\p{M}/gu;
|
|
88
|
+
/** Lowers case and removes accents, so "cafe" finds "Café". */
|
|
89
|
+
const fold = (text) => text.normalize("NFKD").replace(MARKS, "").toLowerCase();
|
|
90
|
+
const tokenize = (query) => fold(query).split(/\s+/).filter(Boolean);
|
|
91
|
+
/**
|
|
92
|
+
* The default filter: an item stays when every word of the query appears in its value or keywords, ignoring case and
|
|
93
|
+
* accents.
|
|
94
|
+
*/
|
|
95
|
+
const defaultCommandFilter = (query, item) => {
|
|
96
|
+
const text = fold([item.value, ...item.keywords].join("\n"));
|
|
97
|
+
return tokenize(query).every(token => text.includes(token));
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Splits a text into the parts a query matches and the parts it doesn't. Folding can change a string's length, so
|
|
101
|
+
* each folded character remembers where it came from, and a match always covers whole source characters.
|
|
102
|
+
*/
|
|
103
|
+
const splitByQuery = (text, query) => {
|
|
104
|
+
const tokens = tokenize(query);
|
|
105
|
+
if (tokens.length === 0) {
|
|
106
|
+
return [{ match: false, text }];
|
|
107
|
+
}
|
|
108
|
+
let folded = "";
|
|
109
|
+
const starts = [];
|
|
110
|
+
const ends = [];
|
|
111
|
+
let offset = 0;
|
|
112
|
+
for (const character of text) {
|
|
113
|
+
const start = offset;
|
|
114
|
+
offset += character.length;
|
|
115
|
+
const piece = fold(character);
|
|
116
|
+
if (piece.length === 0 && ends.length > 0) {
|
|
117
|
+
// A combining mark belongs to the character before it.
|
|
118
|
+
ends[ends.length - 1] = offset;
|
|
119
|
+
}
|
|
120
|
+
for (let index = 0; index < piece.length; index++) {
|
|
121
|
+
starts.push(start);
|
|
122
|
+
ends.push(offset);
|
|
123
|
+
}
|
|
124
|
+
folded += piece;
|
|
125
|
+
}
|
|
126
|
+
const matched = new Array(text.length).fill(false);
|
|
127
|
+
for (const token of tokens) {
|
|
128
|
+
let index = folded.indexOf(token);
|
|
129
|
+
while (index !== -1) {
|
|
130
|
+
matched.fill(true, starts[index], ends[index + token.length - 1]);
|
|
131
|
+
index = folded.indexOf(token, index + token.length);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const parts = [];
|
|
135
|
+
let partStart = 0;
|
|
136
|
+
for (let index = 1; index <= text.length; index++) {
|
|
137
|
+
if (index === text.length || matched[index] !== matched[partStart]) {
|
|
138
|
+
parts.push({ match: matched[partStart], text: text.slice(partStart, index) });
|
|
139
|
+
partStart = index;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return parts;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* A searchable list of actions or options, operated from one input. It works inline, in a popover, or in a
|
|
147
|
+
* `mona-command-dialog`. It only runs what the consumer asks for: choosing an item emits an event, and nothing closes
|
|
148
|
+
* or navigates by itself.
|
|
149
|
+
*/
|
|
150
|
+
class CommandComponent {
|
|
151
|
+
#activeItem;
|
|
152
|
+
#i18n;
|
|
153
|
+
#inputElement;
|
|
154
|
+
#items;
|
|
155
|
+
#liveAnnouncer;
|
|
156
|
+
#visibleItems;
|
|
157
|
+
constructor() {
|
|
158
|
+
this.#activeItem = signal(null, /* @ts-ignore */
|
|
159
|
+
...(ngDevMode ? [{ debugName: "#activeItem" }] : /* istanbul ignore next */ []));
|
|
160
|
+
this.#i18n = inject(MonaI18nService);
|
|
161
|
+
this.#inputElement = signal(null, /* @ts-ignore */
|
|
162
|
+
...(ngDevMode ? [{ debugName: "#inputElement" }] : /* istanbul ignore next */ []));
|
|
163
|
+
this.#items = signal(ImmutableSet.create(), /* @ts-ignore */
|
|
164
|
+
...(ngDevMode ? [{ debugName: "#items" }] : /* istanbul ignore next */ []));
|
|
165
|
+
this.#liveAnnouncer = inject(LiveAnnouncer);
|
|
166
|
+
this.#visibleItems = computed(() => this.#items()
|
|
167
|
+
.where(item => item.visible())
|
|
168
|
+
.toArray(), /* @ts-ignore */
|
|
169
|
+
...(ngDevMode ? [{ debugName: "#visibleItems" }] : /* istanbul ignore next */ []));
|
|
170
|
+
this.baseClass = computed(() => commandBaseThemeVariants({ rounded: this.rounded() }), /* @ts-ignore */
|
|
171
|
+
...(ngDevMode ? [{ debugName: "baseClass" }] : /* istanbul ignore next */ []));
|
|
172
|
+
/**
|
|
173
|
+
* The item Enter would choose.
|
|
174
|
+
* @internal
|
|
175
|
+
*/
|
|
176
|
+
this.activeItem = this.#activeItem.asReadonly();
|
|
177
|
+
/**
|
|
178
|
+
* @description What counts as a match while `filterMode` is `"auto"`.
|
|
179
|
+
* @default defaultCommandFilter
|
|
180
|
+
*/
|
|
181
|
+
this.filter = input(defaultCommandFilter, /* @ts-ignore */
|
|
182
|
+
...(ngDevMode ? [{ debugName: "filter" }] : /* istanbul ignore next */ []));
|
|
183
|
+
/** @description Whether the component filters the items, or the consumer supplies only the matching ones. */
|
|
184
|
+
this.filterMode = input("auto", /* @ts-ignore */
|
|
185
|
+
...(ngDevMode ? [{ debugName: "filterMode" }] : /* istanbul ignore next */ []));
|
|
186
|
+
/**
|
|
187
|
+
* Whether there's nothing to show for the current query.
|
|
188
|
+
* @internal
|
|
189
|
+
*/
|
|
190
|
+
this.isEmpty = computed(() => this.query().trim() !== "" && !this.loading() && this.resultCount() === 0, /* @ts-ignore */
|
|
191
|
+
...(ngDevMode ? [{ debugName: "isEmpty" }] : /* istanbul ignore next */ []));
|
|
192
|
+
/** @description Emits when any item is chosen, with the pointer or with Enter. */
|
|
193
|
+
this.itemSelect = output();
|
|
194
|
+
/**
|
|
195
|
+
* The id the input points at with `aria-controls`.
|
|
196
|
+
* @internal
|
|
197
|
+
*/
|
|
198
|
+
this.listId = createElementControlId();
|
|
199
|
+
/** @description Whether results are on their way. Shows `mona-command-loading` and holds back the empty state. */
|
|
200
|
+
this.loading = input(false, { ...(ngDevMode ? { debugName: "loading" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
201
|
+
/** @description Whether the arrow keys wrap around at the ends of the list. */
|
|
202
|
+
this.loop = input(true, { ...(ngDevMode ? { debugName: "loop" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
203
|
+
/** @internal */
|
|
204
|
+
this.messages = this.#i18n.componentMessages("command", COMMAND_DEFAULT_MESSAGES);
|
|
205
|
+
/** @description The text in the input. */
|
|
206
|
+
this.query = model("", /* @ts-ignore */
|
|
207
|
+
...(ngDevMode ? [{ debugName: "query" }] : /* istanbul ignore next */ []));
|
|
208
|
+
/**
|
|
209
|
+
* How many items are showing.
|
|
210
|
+
* @internal
|
|
211
|
+
*/
|
|
212
|
+
this.resultCount = computed(() => this.#visibleItems().length, /* @ts-ignore */
|
|
213
|
+
...(ngDevMode ? [{ debugName: "resultCount" }] : /* istanbul ignore next */ []));
|
|
214
|
+
/** @description The corner radius. */
|
|
215
|
+
this.rounded = input("medium", /* @ts-ignore */
|
|
216
|
+
...(ngDevMode ? [{ debugName: "rounded" }] : /* istanbul ignore next */ []));
|
|
217
|
+
this.#keepAnItemActive();
|
|
218
|
+
this.#announceResults();
|
|
219
|
+
}
|
|
220
|
+
/** Moves focus to the input. */
|
|
221
|
+
focus() {
|
|
222
|
+
this.#inputElement()?.focus();
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Whether an item shows for the current query.
|
|
226
|
+
* @internal
|
|
227
|
+
*/
|
|
228
|
+
matches(item) {
|
|
229
|
+
const query = this.query().trim();
|
|
230
|
+
if (this.filterMode() === "manual" || query === "") {
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
return this.filter()(query, { keywords: item.keywords(), value: item.value() });
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Moves the active item, skipping disabled ones.
|
|
237
|
+
* @internal
|
|
238
|
+
*/
|
|
239
|
+
move(step) {
|
|
240
|
+
const items = this.#enabledInOrder();
|
|
241
|
+
if (items.length === 0) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
const active = this.#activeItem();
|
|
245
|
+
const current = active ? items.indexOf(active) : -1;
|
|
246
|
+
let next = current === -1 ? (step === 1 ? 0 : items.length - 1) : current + step;
|
|
247
|
+
if (next < 0 || next >= items.length) {
|
|
248
|
+
if (!this.loop()) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
next = next < 0 ? items.length - 1 : 0;
|
|
252
|
+
}
|
|
253
|
+
this.#activeItem.set(items[next]);
|
|
254
|
+
items[next].scrollIntoView();
|
|
255
|
+
}
|
|
256
|
+
/** @internal */
|
|
257
|
+
register(item) {
|
|
258
|
+
this.#items.update(items => items.add(item));
|
|
259
|
+
}
|
|
260
|
+
/** @internal */
|
|
261
|
+
registerInput(element) {
|
|
262
|
+
this.#inputElement.set(element);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Chooses the active item.
|
|
266
|
+
* @internal
|
|
267
|
+
*/
|
|
268
|
+
selectActive(event) {
|
|
269
|
+
const item = this.#activeItem();
|
|
270
|
+
if (item) {
|
|
271
|
+
this.selectItem(item, event);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
/** @internal */
|
|
275
|
+
selectItem(item, event) {
|
|
276
|
+
if (item.disabled()) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
const selection = { originalEvent: event, value: item.value() };
|
|
280
|
+
item.itemSelect.emit(selection);
|
|
281
|
+
this.itemSelect.emit(selection);
|
|
282
|
+
}
|
|
283
|
+
/** @internal */
|
|
284
|
+
setActive(item) {
|
|
285
|
+
if (!item.disabled()) {
|
|
286
|
+
this.#activeItem.set(item);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
/** @internal */
|
|
290
|
+
unregister(item) {
|
|
291
|
+
this.#items.update(items => items.remove(item));
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Announces the outcome of a search. The live region is the CDK's, at the end of the document, so it never becomes
|
|
295
|
+
* part of the list. The active item needs no announcement: `aria-activedescendant` does that.
|
|
296
|
+
*/
|
|
297
|
+
#announceResults() {
|
|
298
|
+
let lastState = "";
|
|
299
|
+
effect(() => {
|
|
300
|
+
const query = this.query().trim();
|
|
301
|
+
const count = this.resultCount();
|
|
302
|
+
const loading = this.loading();
|
|
303
|
+
untracked(() => {
|
|
304
|
+
if (loading) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
const state = query === "" ? "" : `${query}\u0000${count}`;
|
|
308
|
+
if (state === lastState) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
lastState = state;
|
|
312
|
+
if (query !== "") {
|
|
313
|
+
const messages = this.messages();
|
|
314
|
+
void this.#liveAnnouncer.announce(count === 0 ? messages.noResults : messages.resultsAvailable(count), "polite");
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
/** The items that can be chosen, in the order they're on the page, whatever order they were created in. */
|
|
320
|
+
#enabledInOrder() {
|
|
321
|
+
return this.#visibleItems()
|
|
322
|
+
.filter(item => !item.disabled())
|
|
323
|
+
.sort((first, second) => first.compareOrder(second));
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Enter always has something to choose while there are results: a new query starts from the first one, and new
|
|
327
|
+
* results keep the active item as long as it's still among them. This runs after rendering because it reads the
|
|
328
|
+
* items' order from the page.
|
|
329
|
+
*/
|
|
330
|
+
#keepAnItemActive() {
|
|
331
|
+
let lastQuery = "";
|
|
332
|
+
afterRenderEffect(() => {
|
|
333
|
+
const query = this.query();
|
|
334
|
+
const visible = this.#visibleItems();
|
|
335
|
+
untracked(() => {
|
|
336
|
+
const active = this.#activeItem();
|
|
337
|
+
const queryChanged = query !== lastQuery;
|
|
338
|
+
lastQuery = query;
|
|
339
|
+
if (!queryChanged && active && visible.includes(active) && !active.disabled()) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
const first = this.#enabledInOrder().at(0) ?? null;
|
|
343
|
+
this.#activeItem.set(first);
|
|
344
|
+
if (queryChanged) {
|
|
345
|
+
first?.scrollListToTop();
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
351
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.0.6", type: CommandComponent, isStandalone: true, selector: "mona-command", inputs: { filter: { classPropertyName: "filter", publicName: "filter", isSignal: true, isRequired: false, transformFunction: null }, filterMode: { classPropertyName: "filterMode", publicName: "filterMode", isSignal: true, isRequired: false, transformFunction: null }, loading: { classPropertyName: "loading", publicName: "loading", isSignal: true, isRequired: false, transformFunction: null }, loop: { classPropertyName: "loop", publicName: "loop", isSignal: true, isRequired: false, transformFunction: null }, query: { classPropertyName: "query", publicName: "query", isSignal: true, isRequired: false, transformFunction: null }, rounded: { classPropertyName: "rounded", publicName: "rounded", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { itemSelect: "itemSelect", query: "queryChange" }, host: { properties: { "class": "baseClass()" } }, ngImport: i0, template: "<ng-content />", isInline: true }); }
|
|
352
|
+
}
|
|
353
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandComponent, decorators: [{
|
|
354
|
+
type: Component,
|
|
355
|
+
args: [{
|
|
356
|
+
selector: "mona-command",
|
|
357
|
+
template: "<ng-content />",
|
|
358
|
+
host: {
|
|
359
|
+
"[class]": "baseClass()"
|
|
360
|
+
}
|
|
361
|
+
}]
|
|
362
|
+
}], ctorParameters: () => [], propDecorators: { filter: [{ type: i0.Input, args: [{ isSignal: true, alias: "filter", required: false }] }], filterMode: [{ type: i0.Input, args: [{ isSignal: true, alias: "filterMode", required: false }] }], itemSelect: [{ type: i0.Output, args: ["itemSelect"] }], loading: [{ type: i0.Input, args: [{ isSignal: true, alias: "loading", required: false }] }], loop: [{ type: i0.Input, args: [{ isSignal: true, alias: "loop", required: false }] }], query: [{ type: i0.Input, args: [{ isSignal: true, alias: "query", required: false }] }, { type: i0.Output, args: ["queryChange"] }], rounded: [{ type: i0.Input, args: [{ isSignal: true, alias: "rounded", required: false }] }] } });
|
|
363
|
+
|
|
364
|
+
/** Marks the template a `mona-command-dialog` renders while it's open. */
|
|
365
|
+
class CommandDialogContentDirective {
|
|
366
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandDialogContentDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
367
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.0.6", type: CommandDialogContentDirective, isStandalone: true, selector: "ng-template[monaCommandDialogContent]", ngImport: i0 }); }
|
|
368
|
+
}
|
|
369
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandDialogContentDirective, decorators: [{
|
|
370
|
+
type: Directive,
|
|
371
|
+
args: [{
|
|
372
|
+
selector: "ng-template[monaCommandDialogContent]"
|
|
373
|
+
}]
|
|
374
|
+
}] });
|
|
375
|
+
|
|
376
|
+
const APPLE_PLATFORM = /mac|iphone|ipad|ipod/i;
|
|
377
|
+
const EDITABLE = "input, textarea, select, [contenteditable]:not([contenteditable='false'])";
|
|
378
|
+
const isApplePlatform = (view) => APPLE_PLATFORM.test(view?.navigator.platform ?? "");
|
|
379
|
+
const parseShortcut = (shortcut, apple) => {
|
|
380
|
+
const parts = shortcut.toLowerCase().split("+");
|
|
381
|
+
const has = (name) => parts.slice(0, -1).includes(name);
|
|
382
|
+
return {
|
|
383
|
+
alt: has("alt"),
|
|
384
|
+
control: has("ctrl") || (has("mod") && !apple),
|
|
385
|
+
key: parts.at(-1) ?? "",
|
|
386
|
+
meta: has("meta") || (has("mod") && apple),
|
|
387
|
+
shift: has("shift")
|
|
388
|
+
};
|
|
389
|
+
};
|
|
390
|
+
/** Whether a key press is this shortcut. A shortcut without Ctrl, Alt or Meta doesn't fire while the user is typing. */
|
|
391
|
+
const matchesShortcut = (event, shortcut, apple) => {
|
|
392
|
+
const parsed = parseShortcut(shortcut, apple);
|
|
393
|
+
if (event.key?.toLowerCase() !== parsed.key ||
|
|
394
|
+
event.altKey !== parsed.alt ||
|
|
395
|
+
event.ctrlKey !== parsed.control ||
|
|
396
|
+
event.metaKey !== parsed.meta ||
|
|
397
|
+
event.shiftKey !== parsed.shift) {
|
|
398
|
+
return false;
|
|
399
|
+
}
|
|
400
|
+
if (parsed.alt || parsed.control || parsed.meta) {
|
|
401
|
+
return true;
|
|
402
|
+
}
|
|
403
|
+
return !(event.target instanceof Element && event.target.closest(EDITABLE));
|
|
404
|
+
};
|
|
405
|
+
const appleKey = (part) => {
|
|
406
|
+
switch (part) {
|
|
407
|
+
case "alt":
|
|
408
|
+
return { name: "Option", symbol: "\u2325" };
|
|
409
|
+
case "ctrl":
|
|
410
|
+
return { name: "Control", symbol: "\u2303" };
|
|
411
|
+
case "meta":
|
|
412
|
+
case "mod":
|
|
413
|
+
return { name: "Command", symbol: "\u2318" };
|
|
414
|
+
case "shift":
|
|
415
|
+
return { name: "Shift", symbol: "\u21E7" };
|
|
416
|
+
default:
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
const otherKey = (part) => {
|
|
421
|
+
switch (part) {
|
|
422
|
+
case "alt":
|
|
423
|
+
return { name: "Alt", symbol: "Alt" };
|
|
424
|
+
case "ctrl":
|
|
425
|
+
case "mod":
|
|
426
|
+
return { name: "Control", symbol: "Ctrl" };
|
|
427
|
+
case "meta":
|
|
428
|
+
return { name: "Meta", symbol: "Meta" };
|
|
429
|
+
case "shift":
|
|
430
|
+
return { name: "Shift", symbol: "Shift" };
|
|
431
|
+
default:
|
|
432
|
+
return null;
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
/** The keys of a shortcut as the platform writes them: `mod+k` is Ctrl and K, or Command and K on Apple devices. */
|
|
436
|
+
const describeShortcut = (shortcut, apple) => shortcut
|
|
437
|
+
.toLowerCase()
|
|
438
|
+
.split("+")
|
|
439
|
+
.map(part => {
|
|
440
|
+
const modifier = apple ? appleKey(part) : otherKey(part);
|
|
441
|
+
const key = part.length === 1 ? part.toUpperCase() : part.charAt(0).toUpperCase() + part.slice(1);
|
|
442
|
+
return modifier ?? { name: key, symbol: key };
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
const VIEWPORT_MARGIN = "2rem";
|
|
446
|
+
const TOP_OF_VIEWPORT = 0.12;
|
|
447
|
+
/**
|
|
448
|
+
* A modal for a `mona-command`. It stays near the top of the page instead of centering, so the input doesn't jump as
|
|
449
|
+
* results come and go, and the `mona-command` inside is created each time it opens, so it starts with an empty query.
|
|
450
|
+
*/
|
|
451
|
+
class CommandDialogComponent {
|
|
452
|
+
#document;
|
|
453
|
+
#i18n;
|
|
454
|
+
#injector;
|
|
455
|
+
#popupService;
|
|
456
|
+
#renderer;
|
|
457
|
+
#popupRef;
|
|
458
|
+
constructor() {
|
|
459
|
+
this.#document = inject(DOCUMENT);
|
|
460
|
+
this.#i18n = inject(MonaI18nService);
|
|
461
|
+
this.#injector = inject(Injector);
|
|
462
|
+
this.#popupService = inject(PopupService);
|
|
463
|
+
this.#renderer = inject(Renderer2);
|
|
464
|
+
this.#popupRef = null;
|
|
465
|
+
this.content = contentChild(CommandDialogContentDirective, { ...(ngDevMode ? { debugName: "content" } : /* istanbul ignore next */ {}), read: TemplateRef });
|
|
466
|
+
this.messages = this.#i18n.componentMessages("command", COMMAND_DEFAULT_MESSAGES);
|
|
467
|
+
this.panel = viewChild.required("panel", /* @ts-ignore */
|
|
468
|
+
...(ngDevMode ? [{ debugName: "panel" }] : /* istanbul ignore next */ []));
|
|
469
|
+
this.panelClass = computed(() => commandDialogPanelThemeVariants(), /* @ts-ignore */
|
|
470
|
+
...(ngDevMode ? [{ debugName: "panelClass" }] : /* istanbul ignore next */ []));
|
|
471
|
+
/** @description The accessible name of the dialog. */
|
|
472
|
+
this.ariaLabel = input(undefined, { ...(ngDevMode ? { debugName: "ariaLabel" } : /* istanbul ignore next */ {}), alias: "aria-label" });
|
|
473
|
+
/** @description Whether the dialog is open. */
|
|
474
|
+
this.open = model(false, /* @ts-ignore */
|
|
475
|
+
...(ngDevMode ? [{ debugName: "open" }] : /* istanbul ignore next */ []));
|
|
476
|
+
/**
|
|
477
|
+
* @description A key combination that opens and closes the dialog from anywhere on the page, such as `mod+k`.
|
|
478
|
+
* `mod` is Command on Apple devices and Ctrl elsewhere. Nothing is bound unless this is set.
|
|
479
|
+
*/
|
|
480
|
+
this.shortcut = input(null, /* @ts-ignore */
|
|
481
|
+
...(ngDevMode ? [{ debugName: "shortcut" }] : /* istanbul ignore next */ []));
|
|
482
|
+
/** @description The dialog's width. It never gets wider than the viewport. */
|
|
483
|
+
this.width = input("36rem", /* @ts-ignore */
|
|
484
|
+
...(ngDevMode ? [{ debugName: "width" }] : /* istanbul ignore next */ []));
|
|
485
|
+
effect(() => {
|
|
486
|
+
const open = this.open();
|
|
487
|
+
untracked(() => {
|
|
488
|
+
if (open && !this.#popupRef) {
|
|
489
|
+
this.#show();
|
|
490
|
+
}
|
|
491
|
+
else if (!open && this.#popupRef) {
|
|
492
|
+
this.#popupRef.close();
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
});
|
|
496
|
+
effect(onCleanup => {
|
|
497
|
+
const shortcut = this.shortcut();
|
|
498
|
+
if (shortcut) {
|
|
499
|
+
onCleanup(untracked(() => this.#listenFor(shortcut)));
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
inject(DestroyRef).onDestroy(() => this.#popupRef?.close());
|
|
503
|
+
}
|
|
504
|
+
#listenFor(shortcut) {
|
|
505
|
+
const apple = isApplePlatform(this.#document.defaultView);
|
|
506
|
+
return this.#renderer.listen(this.#document, "keydown", (event) => {
|
|
507
|
+
if (!event.repeat && !event.isComposing && matchesShortcut(event, shortcut, apple)) {
|
|
508
|
+
event.preventDefault();
|
|
509
|
+
this.open.update(open => !open);
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
#show() {
|
|
514
|
+
const top = Math.round((this.#document.defaultView?.innerHeight ?? 0) * TOP_OF_VIEWPORT);
|
|
515
|
+
const popupRef = this.#popupService.create({
|
|
516
|
+
anchor: this.#document.body,
|
|
517
|
+
backdropClass: ["fixed", "inset-0", "bg-background/50", "transition-opacity", "z-40", "backdrop-blur-xs"],
|
|
518
|
+
blockScroll: true,
|
|
519
|
+
closeOnBackdropClick: true,
|
|
520
|
+
closeOnEscape: true,
|
|
521
|
+
closeOnOutsideClick: false,
|
|
522
|
+
content: this.panel(),
|
|
523
|
+
hasBackdrop: true,
|
|
524
|
+
maxHeight: `calc(100dvh - ${2 * top}px)`,
|
|
525
|
+
maxWidth: `calc(100dvw - ${VIEWPORT_MARGIN})`,
|
|
526
|
+
popupWrapperClass: "mona-popup-constrain-height",
|
|
527
|
+
positionStrategy: "global",
|
|
528
|
+
width: this.width()
|
|
529
|
+
});
|
|
530
|
+
this.#popupRef = popupRef;
|
|
531
|
+
positionGlobalOverlay(popupRef.overlayRef, { top });
|
|
532
|
+
afterNextRender({
|
|
533
|
+
write: () => popupRef.overlayRef.hostElement.querySelector("[role='combobox']")?.focus()
|
|
534
|
+
}, { injector: this.#injector });
|
|
535
|
+
const release = inertOutside(popupRef.overlayRef.hostElement);
|
|
536
|
+
merge(popupRef.closeStart, popupRef.closed)
|
|
537
|
+
.pipe(take(1))
|
|
538
|
+
.subscribe(() => {
|
|
539
|
+
release();
|
|
540
|
+
this.#popupRef = null;
|
|
541
|
+
this.open.set(false);
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandDialogComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
545
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.0.6", type: CommandDialogComponent, isStandalone: true, selector: "mona-command-dialog", inputs: { ariaLabel: { classPropertyName: "ariaLabel", publicName: "aria-label", isSignal: true, isRequired: false, transformFunction: null }, open: { classPropertyName: "open", publicName: "open", isSignal: true, isRequired: false, transformFunction: null }, shortcut: { classPropertyName: "shortcut", publicName: "shortcut", isSignal: true, isRequired: false, transformFunction: null }, width: { classPropertyName: "width", publicName: "width", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { open: "openChange" }, host: { properties: { "attr.aria-label": "null" }, classAttribute: "hidden" }, queries: [{ propertyName: "content", first: true, predicate: CommandDialogContentDirective, descendants: true, read: TemplateRef, isSignal: true }], viewQueries: [{ propertyName: "panel", first: true, predicate: ["panel"], descendants: true, isSignal: true }], ngImport: i0, template: "<ng-template #panel>\n <div\n cdkTrapFocus\n role=\"dialog\"\n aria-modal=\"true\"\n [attr.aria-label]=\"ariaLabel() || messages().dialogLabel\"\n [class]=\"panelClass()\">\n <ng-container [ngTemplateOutlet]=\"content() ?? null\" />\n </div>\n</ng-template>\n", dependencies: [{ kind: "ngmodule", type: A11yModule }, { kind: "directive", type: i1.CdkTrapFocus, selector: "[cdkTrapFocus]", inputs: ["cdkTrapFocus", "cdkTrapFocusAutoCapture"], exportAs: ["cdkTrapFocus"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }] }); }
|
|
546
|
+
}
|
|
547
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandDialogComponent, decorators: [{
|
|
548
|
+
type: Component,
|
|
549
|
+
args: [{ selector: "mona-command-dialog", imports: [A11yModule, NgTemplateOutlet], host: {
|
|
550
|
+
"[attr.aria-label]": "null",
|
|
551
|
+
class: "hidden"
|
|
552
|
+
}, template: "<ng-template #panel>\n <div\n cdkTrapFocus\n role=\"dialog\"\n aria-modal=\"true\"\n [attr.aria-label]=\"ariaLabel() || messages().dialogLabel\"\n [class]=\"panelClass()\">\n <ng-container [ngTemplateOutlet]=\"content() ?? null\" />\n </div>\n</ng-template>\n" }]
|
|
553
|
+
}], ctorParameters: () => [], propDecorators: { content: [{ type: i0.ContentChild, args: [i0.forwardRef(() => CommandDialogContentDirective), { ...{ read: TemplateRef }, isSignal: true }] }], panel: [{ type: i0.ViewChild, args: ["panel", { isSignal: true }] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "aria-label", required: false }] }], open: [{ type: i0.Input, args: [{ isSignal: true, alias: "open", required: false }] }, { type: i0.Output, args: ["openChange"] }], shortcut: [{ type: i0.Input, args: [{ isSignal: true, alias: "shortcut", required: false }] }], width: [{ type: i0.Input, args: [{ isSignal: true, alias: "width", required: false }] }] } });
|
|
554
|
+
|
|
555
|
+
/** Shows while a query has no results. Its content replaces the default message. */
|
|
556
|
+
class CommandEmptyComponent {
|
|
557
|
+
constructor() {
|
|
558
|
+
this.root = inject(CommandComponent);
|
|
559
|
+
this.statusClass = computed(() => commandStatusThemeVariants(), /* @ts-ignore */
|
|
560
|
+
...(ngDevMode ? [{ debugName: "statusClass" }] : /* istanbul ignore next */ []));
|
|
561
|
+
}
|
|
562
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandEmptyComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
563
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: CommandEmptyComponent, isStandalone: true, selector: "mona-command-empty", host: { classAttribute: "contents" }, ngImport: i0, template: "@if (root.isEmpty()) {\n <div [class]=\"statusClass()\">\n <ng-content>{{ root.messages().noResults }}</ng-content>\n </div>\n}\n" }); }
|
|
564
|
+
}
|
|
565
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandEmptyComponent, decorators: [{
|
|
566
|
+
type: Component,
|
|
567
|
+
args: [{ selector: "mona-command-empty", host: {
|
|
568
|
+
class: "contents"
|
|
569
|
+
}, template: "@if (root.isEmpty()) {\n <div [class]=\"statusClass()\">\n <ng-content>{{ root.messages().noResults }}</ng-content>\n </div>\n}\n" }]
|
|
570
|
+
}] });
|
|
571
|
+
|
|
572
|
+
/** A strip below the list, for key hints or links. */
|
|
573
|
+
class CommandFooterComponent {
|
|
574
|
+
constructor() {
|
|
575
|
+
this.hostClass = computed(() => commandFooterThemeVariants(), /* @ts-ignore */
|
|
576
|
+
...(ngDevMode ? [{ debugName: "hostClass" }] : /* istanbul ignore next */ []));
|
|
577
|
+
}
|
|
578
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandFooterComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
579
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "22.0.6", type: CommandFooterComponent, isStandalone: true, selector: "mona-command-footer", host: { properties: { "class": "hostClass()" } }, ngImport: i0, template: "<ng-content />", isInline: true }); }
|
|
580
|
+
}
|
|
581
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandFooterComponent, decorators: [{
|
|
582
|
+
type: Component,
|
|
583
|
+
args: [{
|
|
584
|
+
selector: "mona-command-footer",
|
|
585
|
+
template: "<ng-content />",
|
|
586
|
+
host: {
|
|
587
|
+
"[class]": "hostClass()"
|
|
588
|
+
}
|
|
589
|
+
}]
|
|
590
|
+
}] });
|
|
591
|
+
|
|
592
|
+
/** A titled set of items. It hides itself while none of its items show. */
|
|
593
|
+
class CommandGroupComponent {
|
|
594
|
+
constructor() {
|
|
595
|
+
this.#items = signal(ImmutableSet.create(), /* @ts-ignore */
|
|
596
|
+
...(ngDevMode ? [{ debugName: "#items" }] : /* istanbul ignore next */ []));
|
|
597
|
+
this.headingClass = computed(() => commandGroupHeadingThemeVariants(), /* @ts-ignore */
|
|
598
|
+
...(ngDevMode ? [{ debugName: "headingClass" }] : /* istanbul ignore next */ []));
|
|
599
|
+
this.headingId = createElementControlId();
|
|
600
|
+
this.hostClass = computed(() => commandGroupThemeVariants(), /* @ts-ignore */
|
|
601
|
+
...(ngDevMode ? [{ debugName: "hostClass" }] : /* istanbul ignore next */ []));
|
|
602
|
+
this.visible = computed(() => this.#items().any(item => item.visible()), /* @ts-ignore */
|
|
603
|
+
...(ngDevMode ? [{ debugName: "visible" }] : /* istanbul ignore next */ []));
|
|
604
|
+
/** @description The title above the group's items. */
|
|
605
|
+
this.heading = input(/* @ts-ignore */
|
|
606
|
+
...(ngDevMode ? [undefined, { debugName: "heading" }] : /* istanbul ignore next */ []));
|
|
607
|
+
}
|
|
608
|
+
#items;
|
|
609
|
+
/** @internal */
|
|
610
|
+
register(item) {
|
|
611
|
+
this.#items.update(items => items.add(item));
|
|
612
|
+
}
|
|
613
|
+
/** @internal */
|
|
614
|
+
unregister(item) {
|
|
615
|
+
this.#items.update(items => items.remove(item));
|
|
616
|
+
}
|
|
617
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandGroupComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
618
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: CommandGroupComponent, isStandalone: true, selector: "mona-command-group", inputs: { heading: { classPropertyName: "heading", publicName: "heading", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "role": "group" }, properties: { "attr.aria-labelledby": "heading() ? headingId : null", "class": "hostClass()", "class.hidden": "!visible()" } }, ngImport: i0, template: "@if (heading()) {\n <div [class]=\"headingClass()\" [id]=\"headingId\">{{ heading() }}</div>\n}\n<ng-content />\n" }); }
|
|
619
|
+
}
|
|
620
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandGroupComponent, decorators: [{
|
|
621
|
+
type: Component,
|
|
622
|
+
args: [{ selector: "mona-command-group", host: {
|
|
623
|
+
role: "group",
|
|
624
|
+
"[attr.aria-labelledby]": "heading() ? headingId : null",
|
|
625
|
+
"[class]": "hostClass()",
|
|
626
|
+
"[class.hidden]": "!visible()"
|
|
627
|
+
}, template: "@if (heading()) {\n <div [class]=\"headingClass()\" [id]=\"headingId\">{{ heading() }}</div>\n}\n<ng-content />\n" }]
|
|
628
|
+
}], propDecorators: { heading: [{ type: i0.Input, args: [{ isSignal: true, alias: "heading", required: false }] }] } });
|
|
629
|
+
|
|
630
|
+
/** A strip above or below the input, for filters or a title. */
|
|
631
|
+
class CommandHeaderComponent {
|
|
632
|
+
constructor() {
|
|
633
|
+
this.hostClass = computed(() => commandHeaderThemeVariants(), /* @ts-ignore */
|
|
634
|
+
...(ngDevMode ? [{ debugName: "hostClass" }] : /* istanbul ignore next */ []));
|
|
635
|
+
}
|
|
636
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandHeaderComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
637
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "22.0.6", type: CommandHeaderComponent, isStandalone: true, selector: "mona-command-header", host: { properties: { "class": "hostClass()" } }, ngImport: i0, template: "<ng-content />", isInline: true }); }
|
|
638
|
+
}
|
|
639
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandHeaderComponent, decorators: [{
|
|
640
|
+
type: Component,
|
|
641
|
+
args: [{
|
|
642
|
+
selector: "mona-command-header",
|
|
643
|
+
template: "<ng-content />",
|
|
644
|
+
host: {
|
|
645
|
+
"[class]": "hostClass()"
|
|
646
|
+
}
|
|
647
|
+
}]
|
|
648
|
+
}] });
|
|
649
|
+
|
|
650
|
+
/** Shows a text with the parts the query matches marked. Marks the query's words, however the item was matched. */
|
|
651
|
+
class CommandHighlightComponent {
|
|
652
|
+
constructor() {
|
|
653
|
+
this.#root = inject(CommandComponent);
|
|
654
|
+
this.markClass = computed(() => commandHighlightMarkThemeVariants(), /* @ts-ignore */
|
|
655
|
+
...(ngDevMode ? [{ debugName: "markClass" }] : /* istanbul ignore next */ []));
|
|
656
|
+
this.parts = computed(() => splitByQuery(this.text(), this.#root.query()), /* @ts-ignore */
|
|
657
|
+
...(ngDevMode ? [{ debugName: "parts" }] : /* istanbul ignore next */ []));
|
|
658
|
+
/** @description The text to show. */
|
|
659
|
+
this.text = input.required(/* @ts-ignore */
|
|
660
|
+
...(ngDevMode ? [{ debugName: "text" }] : /* istanbul ignore next */ []));
|
|
661
|
+
}
|
|
662
|
+
#root;
|
|
663
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandHighlightComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
664
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: CommandHighlightComponent, isStandalone: true, selector: "mona-command-highlight", inputs: { text: { classPropertyName: "text", publicName: "text", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0, template: "@for (part of parts(); track $index) {\n @if (part.match) {\n <mark [class]=\"markClass()\">{{ part.text }}</mark>\n } @else {\n <span>{{ part.text }}</span>\n }\n}\n" }); }
|
|
665
|
+
}
|
|
666
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandHighlightComponent, decorators: [{
|
|
667
|
+
type: Component,
|
|
668
|
+
args: [{ selector: "mona-command-highlight", template: "@for (part of parts(); track $index) {\n @if (part.match) {\n <mark [class]=\"markClass()\">{{ part.text }}</mark>\n } @else {\n <span>{{ part.text }}</span>\n }\n}\n" }]
|
|
669
|
+
}], propDecorators: { text: [{ type: i0.Input, args: [{ isSignal: true, alias: "text", required: true }] }] } });
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* The search field of a `mona-command`. Focus stays here while the arrow keys move through the list, so typing always
|
|
673
|
+
* continues the search.
|
|
674
|
+
*/
|
|
675
|
+
class CommandInputComponent {
|
|
676
|
+
constructor() {
|
|
677
|
+
this.field = viewChild.required("field", /* @ts-ignore */
|
|
678
|
+
...(ngDevMode ? [{ debugName: "field" }] : /* istanbul ignore next */ []));
|
|
679
|
+
this.fieldClass = computed(() => commandInputFieldThemeVariants(), /* @ts-ignore */
|
|
680
|
+
...(ngDevMode ? [{ debugName: "fieldClass" }] : /* istanbul ignore next */ []));
|
|
681
|
+
this.hostClass = computed(() => commandInputThemeVariants(), /* @ts-ignore */
|
|
682
|
+
...(ngDevMode ? [{ debugName: "hostClass" }] : /* istanbul ignore next */ []));
|
|
683
|
+
this.iconClass = computed(() => commandInputIconThemeVariants(), /* @ts-ignore */
|
|
684
|
+
...(ngDevMode ? [{ debugName: "iconClass" }] : /* istanbul ignore next */ []));
|
|
685
|
+
this.root = inject(CommandComponent);
|
|
686
|
+
/** @description The accessible name of the field. */
|
|
687
|
+
this.ariaLabel = input(undefined, { ...(ngDevMode ? { debugName: "ariaLabel" } : /* istanbul ignore next */ {}), alias: "aria-label" });
|
|
688
|
+
/** @description The text shown while the field is empty. */
|
|
689
|
+
this.placeholder = input(/* @ts-ignore */
|
|
690
|
+
...(ngDevMode ? [undefined, { debugName: "placeholder" }] : /* istanbul ignore next */ []));
|
|
691
|
+
afterNextRender({ read: () => this.root.registerInput(this.field().nativeElement) });
|
|
692
|
+
}
|
|
693
|
+
onInput(event) {
|
|
694
|
+
this.root.query.set(event.target.value);
|
|
695
|
+
}
|
|
696
|
+
onKeydown(event) {
|
|
697
|
+
// While an input method composes text, these keys belong to it. Enter there confirms the composition.
|
|
698
|
+
if (event.isComposing) {
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
switch (event.key) {
|
|
702
|
+
case "ArrowDown":
|
|
703
|
+
event.preventDefault();
|
|
704
|
+
this.root.move(1);
|
|
705
|
+
break;
|
|
706
|
+
case "ArrowUp":
|
|
707
|
+
event.preventDefault();
|
|
708
|
+
this.root.move(-1);
|
|
709
|
+
break;
|
|
710
|
+
case "Enter":
|
|
711
|
+
event.preventDefault();
|
|
712
|
+
this.root.selectActive(event);
|
|
713
|
+
break;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandInputComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
717
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.0.6", type: CommandInputComponent, isStandalone: true, selector: "mona-command-input", inputs: { ariaLabel: { classPropertyName: "ariaLabel", publicName: "aria-label", isSignal: true, isRequired: false, transformFunction: null }, placeholder: { classPropertyName: "placeholder", publicName: "placeholder", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "attr.aria-label": "null", "class": "hostClass()" } }, viewQueries: [{ propertyName: "field", first: true, predicate: ["field"], descendants: true, isSignal: true }], ngImport: i0, template: "<svg lucideSearch aria-hidden=\"true\" [class]=\"iconClass()\" [size]=\"16\"></svg>\n<input\n #field\n type=\"text\"\n role=\"combobox\"\n autocapitalize=\"off\"\n autocomplete=\"off\"\n aria-autocomplete=\"list\"\n spellcheck=\"false\"\n [attr.aria-activedescendant]=\"root.activeItem()?.id ?? null\"\n [attr.aria-controls]=\"root.listId\"\n [attr.aria-expanded]=\"root.resultCount() > 0\"\n [attr.aria-label]=\"ariaLabel() || root.messages().inputLabel\"\n [attr.placeholder]=\"placeholder() ?? root.messages().placeholder\"\n [class]=\"fieldClass()\"\n [value]=\"root.query()\"\n (input)=\"onInput($event)\"\n (keydown)=\"onKeydown($event)\" />\n", dependencies: [{ kind: "component", type: LucideSearch, selector: "svg[lucideSearch]" }] }); }
|
|
718
|
+
}
|
|
719
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandInputComponent, decorators: [{
|
|
720
|
+
type: Component,
|
|
721
|
+
args: [{ selector: "mona-command-input", imports: [LucideSearch], host: {
|
|
722
|
+
"[attr.aria-label]": "null",
|
|
723
|
+
"[class]": "hostClass()"
|
|
724
|
+
}, template: "<svg lucideSearch aria-hidden=\"true\" [class]=\"iconClass()\" [size]=\"16\"></svg>\n<input\n #field\n type=\"text\"\n role=\"combobox\"\n autocapitalize=\"off\"\n autocomplete=\"off\"\n aria-autocomplete=\"list\"\n spellcheck=\"false\"\n [attr.aria-activedescendant]=\"root.activeItem()?.id ?? null\"\n [attr.aria-controls]=\"root.listId\"\n [attr.aria-expanded]=\"root.resultCount() > 0\"\n [attr.aria-label]=\"ariaLabel() || root.messages().inputLabel\"\n [attr.placeholder]=\"placeholder() ?? root.messages().placeholder\"\n [class]=\"fieldClass()\"\n [value]=\"root.query()\"\n (input)=\"onInput($event)\"\n (keydown)=\"onKeydown($event)\" />\n" }]
|
|
725
|
+
}], ctorParameters: () => [], propDecorators: { field: [{ type: i0.ViewChild, args: ["field", { isSignal: true }] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "aria-label", required: false }] }], placeholder: [{ type: i0.Input, args: [{ isSignal: true, alias: "placeholder", required: false }] }] } });
|
|
726
|
+
|
|
727
|
+
/** One action or option in a `mona-command`. What it shows is its content; what it's found by is its value. */
|
|
728
|
+
class CommandItemComponent {
|
|
729
|
+
#element;
|
|
730
|
+
#group;
|
|
731
|
+
#root;
|
|
732
|
+
constructor() {
|
|
733
|
+
this.#element = inject(ElementRef);
|
|
734
|
+
this.#group = inject(CommandGroupComponent, { optional: true });
|
|
735
|
+
this.#root = inject(CommandComponent);
|
|
736
|
+
this.active = computed(() => this.#root.activeItem() === this, /* @ts-ignore */
|
|
737
|
+
...(ngDevMode ? [{ debugName: "active" }] : /* istanbul ignore next */ []));
|
|
738
|
+
this.hostClass = computed(() => commandItemThemeVariants(), /* @ts-ignore */
|
|
739
|
+
...(ngDevMode ? [{ debugName: "hostClass" }] : /* istanbul ignore next */ []));
|
|
740
|
+
/** @description Whether the item shows but can't be chosen. */
|
|
741
|
+
this.disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
742
|
+
/** @internal */
|
|
743
|
+
this.id = createElementControlId();
|
|
744
|
+
/** @description Emits when this item is chosen, with the pointer or with Enter. */
|
|
745
|
+
this.itemSelect = output();
|
|
746
|
+
/** @description Other words the item should be found by, such as synonyms. */
|
|
747
|
+
this.keywords = input([], /* @ts-ignore */
|
|
748
|
+
...(ngDevMode ? [{ debugName: "keywords" }] : /* istanbul ignore next */ []));
|
|
749
|
+
/** @description What the item is found by, and what the select event carries. */
|
|
750
|
+
this.value = input.required(/* @ts-ignore */
|
|
751
|
+
...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
|
|
752
|
+
/**
|
|
753
|
+
* Whether the item shows for the current query.
|
|
754
|
+
* @internal
|
|
755
|
+
*/
|
|
756
|
+
this.visible = computed(() => this.#root.matches(this), /* @ts-ignore */
|
|
757
|
+
...(ngDevMode ? [{ debugName: "visible" }] : /* istanbul ignore next */ []));
|
|
758
|
+
this.#root.register(this);
|
|
759
|
+
this.#group?.register(this);
|
|
760
|
+
inject(DestroyRef).onDestroy(() => {
|
|
761
|
+
this.#root.unregister(this);
|
|
762
|
+
this.#group?.unregister(this);
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Negative when this item comes before the other on the page.
|
|
767
|
+
* @internal
|
|
768
|
+
*/
|
|
769
|
+
compareOrder(other) {
|
|
770
|
+
const position = this.#element.nativeElement.compareDocumentPosition(other.#element.nativeElement);
|
|
771
|
+
return position & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
|
|
772
|
+
}
|
|
773
|
+
/** @internal */
|
|
774
|
+
scrollIntoView() {
|
|
775
|
+
this.#element.nativeElement.scrollIntoView({ block: "nearest" });
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* Back to the top rather than to this item, so the first group's heading shows too.
|
|
779
|
+
* @internal
|
|
780
|
+
*/
|
|
781
|
+
scrollListToTop() {
|
|
782
|
+
const list = this.#element.nativeElement.closest("[role='listbox']");
|
|
783
|
+
if (list) {
|
|
784
|
+
list.scrollTop = 0;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
onClick(event) {
|
|
788
|
+
this.#root.selectItem(this, event);
|
|
789
|
+
}
|
|
790
|
+
/** Not `mouseenter`: that also fires when the list scrolls under a resting pointer, which would steal the active item. */
|
|
791
|
+
onPointerMove() {
|
|
792
|
+
this.#root.setActive(this);
|
|
793
|
+
}
|
|
794
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandItemComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
795
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.0.6", type: CommandItemComponent, isStandalone: true, selector: "mona-command-item", inputs: { disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, keywords: { classPropertyName: "keywords", publicName: "keywords", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { itemSelect: "itemSelect" }, host: { attributes: { "role": "option" }, listeners: { "click": "onClick($event)", "mousedown": "$event.preventDefault()", "pointermove": "onPointerMove()" }, properties: { "attr.aria-disabled": "disabled() || null", "attr.aria-selected": "active()", "attr.data-active": "active()", "attr.data-disabled": "disabled() || null", "class": "hostClass()", "class.hidden": "!visible()", "id": "id" } }, ngImport: i0, template: "<ng-content />", isInline: true }); }
|
|
796
|
+
}
|
|
797
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandItemComponent, decorators: [{
|
|
798
|
+
type: Component,
|
|
799
|
+
args: [{
|
|
800
|
+
selector: "mona-command-item",
|
|
801
|
+
template: "<ng-content />",
|
|
802
|
+
host: {
|
|
803
|
+
role: "option",
|
|
804
|
+
"[attr.aria-disabled]": "disabled() || null",
|
|
805
|
+
"[attr.aria-selected]": "active()",
|
|
806
|
+
"[attr.data-active]": "active()",
|
|
807
|
+
"[attr.data-disabled]": "disabled() || null",
|
|
808
|
+
"[class]": "hostClass()",
|
|
809
|
+
"[class.hidden]": "!visible()",
|
|
810
|
+
"[id]": "id",
|
|
811
|
+
"(click)": "onClick($event)",
|
|
812
|
+
"(mousedown)": "$event.preventDefault()",
|
|
813
|
+
"(pointermove)": "onPointerMove()"
|
|
814
|
+
}
|
|
815
|
+
}]
|
|
816
|
+
}], ctorParameters: () => [], propDecorators: { disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], itemSelect: [{ type: i0.Output, args: ["itemSelect"] }], keywords: [{ type: i0.Input, args: [{ isSignal: true, alias: "keywords", required: false }] }], value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: true }] }] } });
|
|
817
|
+
|
|
818
|
+
/**
|
|
819
|
+
* Holds the items of a `mona-command`, and scrolls them. The empty and loading states sit outside the listbox, which
|
|
820
|
+
* may only contain options and groups.
|
|
821
|
+
*/
|
|
822
|
+
class CommandListComponent {
|
|
823
|
+
constructor() {
|
|
824
|
+
this.listClass = computed(() => commandListThemeVariants(), /* @ts-ignore */
|
|
825
|
+
...(ngDevMode ? [{ debugName: "listClass" }] : /* istanbul ignore next */ []));
|
|
826
|
+
this.root = inject(CommandComponent);
|
|
827
|
+
/** @description The accessible name of the list. */
|
|
828
|
+
this.ariaLabel = input(undefined, { ...(ngDevMode ? { debugName: "ariaLabel" } : /* istanbul ignore next */ {}), alias: "aria-label" });
|
|
829
|
+
}
|
|
830
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandListComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
831
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.0.6", type: CommandListComponent, isStandalone: true, selector: "mona-command-list", inputs: { ariaLabel: { classPropertyName: "ariaLabel", publicName: "aria-label", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "attr.aria-label": "null" }, classAttribute: "flex min-h-0 flex-1 flex-col" }, ngImport: i0, template: "<ng-content select=\"mona-command-empty, mona-command-loading\" />\n<div\n role=\"listbox\"\n [attr.aria-busy]=\"root.loading() || null\"\n [attr.aria-label]=\"ariaLabel() || root.messages().listLabel\"\n [class]=\"listClass()\"\n [class.hidden]=\"root.resultCount() === 0\"\n [id]=\"root.listId\">\n <ng-content />\n</div>\n" }); }
|
|
832
|
+
}
|
|
833
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandListComponent, decorators: [{
|
|
834
|
+
type: Component,
|
|
835
|
+
args: [{ selector: "mona-command-list", host: {
|
|
836
|
+
"[attr.aria-label]": "null",
|
|
837
|
+
class: "flex min-h-0 flex-1 flex-col"
|
|
838
|
+
}, template: "<ng-content select=\"mona-command-empty, mona-command-loading\" />\n<div\n role=\"listbox\"\n [attr.aria-busy]=\"root.loading() || null\"\n [attr.aria-label]=\"ariaLabel() || root.messages().listLabel\"\n [class]=\"listClass()\"\n [class.hidden]=\"root.resultCount() === 0\"\n [id]=\"root.listId\">\n <ng-content />\n</div>\n" }]
|
|
839
|
+
}], propDecorators: { ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "aria-label", required: false }] }] } });
|
|
840
|
+
|
|
841
|
+
/** Shows while the `mona-command` is `loading`. Its content replaces the default message. */
|
|
842
|
+
class CommandLoadingComponent {
|
|
843
|
+
constructor() {
|
|
844
|
+
this.root = inject(CommandComponent);
|
|
845
|
+
this.statusClass = computed(() => commandStatusThemeVariants(), /* @ts-ignore */
|
|
846
|
+
...(ngDevMode ? [{ debugName: "statusClass" }] : /* istanbul ignore next */ []));
|
|
847
|
+
}
|
|
848
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandLoadingComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
849
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: CommandLoadingComponent, isStandalone: true, selector: "mona-command-loading", host: { classAttribute: "contents" }, ngImport: i0, template: "@if (root.loading()) {\n <div [class]=\"statusClass()\">\n <ng-content>{{ root.messages().loading }}</ng-content>\n </div>\n}\n" }); }
|
|
850
|
+
}
|
|
851
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandLoadingComponent, decorators: [{
|
|
852
|
+
type: Component,
|
|
853
|
+
args: [{ selector: "mona-command-loading", host: {
|
|
854
|
+
class: "contents"
|
|
855
|
+
}, template: "@if (root.loading()) {\n <div [class]=\"statusClass()\">\n <ng-content>{{ root.messages().loading }}</ng-content>\n </div>\n}\n" }]
|
|
856
|
+
}] });
|
|
857
|
+
|
|
858
|
+
/**
|
|
859
|
+
* A line between items. It's only visual, because a listbox can't contain a separator role. It hides while the
|
|
860
|
+
* component filters, when it would divide nothing.
|
|
861
|
+
*/
|
|
862
|
+
class CommandSeparatorComponent {
|
|
863
|
+
constructor() {
|
|
864
|
+
this.#root = inject(CommandComponent);
|
|
865
|
+
this.hidden = computed(() => this.#root.filterMode() === "auto" && this.#root.query().trim() !== "", /* @ts-ignore */
|
|
866
|
+
...(ngDevMode ? [{ debugName: "hidden" }] : /* istanbul ignore next */ []));
|
|
867
|
+
this.hostClass = computed(() => commandSeparatorThemeVariants(), /* @ts-ignore */
|
|
868
|
+
...(ngDevMode ? [{ debugName: "hostClass" }] : /* istanbul ignore next */ []));
|
|
869
|
+
}
|
|
870
|
+
#root;
|
|
871
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandSeparatorComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
872
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "22.0.6", type: CommandSeparatorComponent, isStandalone: true, selector: "mona-command-separator", host: { attributes: { "aria-hidden": "true" }, properties: { "class": "hostClass()", "class.hidden": "hidden()" } }, ngImport: i0, template: "", isInline: true }); }
|
|
873
|
+
}
|
|
874
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandSeparatorComponent, decorators: [{
|
|
875
|
+
type: Component,
|
|
876
|
+
args: [{
|
|
877
|
+
selector: "mona-command-separator",
|
|
878
|
+
template: "",
|
|
879
|
+
host: {
|
|
880
|
+
"aria-hidden": "true",
|
|
881
|
+
"[class]": "hostClass()",
|
|
882
|
+
"[class.hidden]": "hidden()"
|
|
883
|
+
}
|
|
884
|
+
}]
|
|
885
|
+
}] });
|
|
886
|
+
|
|
887
|
+
/**
|
|
888
|
+
* Shows an item's shortcut the way the platform writes it. It's only a hint: binding the keys stays with the consumer,
|
|
889
|
+
* who knows what they do.
|
|
890
|
+
*/
|
|
891
|
+
class CommandShortcutComponent {
|
|
892
|
+
constructor() {
|
|
893
|
+
this.#apple = isApplePlatform(inject(DOCUMENT).defaultView);
|
|
894
|
+
this.hostClass = computed(() => commandShortcutThemeVariants(), /* @ts-ignore */
|
|
895
|
+
...(ngDevMode ? [{ debugName: "hostClass" }] : /* istanbul ignore next */ []));
|
|
896
|
+
this.keyClass = computed(() => commandShortcutKeyThemeVariants(), /* @ts-ignore */
|
|
897
|
+
...(ngDevMode ? [{ debugName: "keyClass" }] : /* istanbul ignore next */ []));
|
|
898
|
+
this.parts = computed(() => describeShortcut(this.keys(), this.#apple), /* @ts-ignore */
|
|
899
|
+
...(ngDevMode ? [{ debugName: "parts" }] : /* istanbul ignore next */ []));
|
|
900
|
+
/** @description The keys, joined with `+`, such as `mod+k`. `mod` is Command on Apple devices and Ctrl elsewhere. */
|
|
901
|
+
this.keys = input.required(/* @ts-ignore */
|
|
902
|
+
...(ngDevMode ? [{ debugName: "keys" }] : /* istanbul ignore next */ []));
|
|
903
|
+
}
|
|
904
|
+
#apple;
|
|
905
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandShortcutComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
906
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: CommandShortcutComponent, isStandalone: true, selector: "mona-command-shortcut", inputs: { keys: { classPropertyName: "keys", publicName: "keys", isSignal: true, isRequired: true, transformFunction: null } }, host: { properties: { "class": "hostClass()" } }, ngImport: i0, template: "@for (key of parts(); track $index) {\n <kbd aria-hidden=\"true\" [class]=\"keyClass()\">{{ key.symbol }}</kbd>\n <span class=\"sr-only\">{{ key.name }}</span>\n}\n" }); }
|
|
907
|
+
}
|
|
908
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CommandShortcutComponent, decorators: [{
|
|
909
|
+
type: Component,
|
|
910
|
+
args: [{ selector: "mona-command-shortcut", host: {
|
|
911
|
+
"[class]": "hostClass()"
|
|
912
|
+
}, template: "@for (key of parts(); track $index) {\n <kbd aria-hidden=\"true\" [class]=\"keyClass()\">{{ key.symbol }}</kbd>\n <span class=\"sr-only\">{{ key.name }}</span>\n}\n" }]
|
|
913
|
+
}], propDecorators: { keys: [{ type: i0.Input, args: [{ isSignal: true, alias: "keys", required: true }] }] } });
|
|
914
|
+
|
|
915
|
+
/*
|
|
916
|
+
* Public API Surface of @nanahoshi/mona-ui/command
|
|
917
|
+
*/
|
|
918
|
+
|
|
919
|
+
/**
|
|
920
|
+
* Generated bundle index. Do not edit.
|
|
921
|
+
*/
|
|
922
|
+
|
|
923
|
+
export { COMMAND_DEFAULT_MESSAGES, CommandComponent, CommandDialogComponent, CommandDialogContentDirective, CommandEmptyComponent, CommandFooterComponent, CommandGroupComponent, CommandHeaderComponent, CommandHighlightComponent, CommandInputComponent, CommandItemComponent, CommandListComponent, CommandLoadingComponent, CommandSeparatorComponent, CommandShortcutComponent, defaultCommandFilter };
|
|
924
|
+
//# sourceMappingURL=nanahoshi-mona-ui-command.mjs.map
|