@hebium-ui/core 0.1.0-alpha.2 → 0.1.0-alpha.4
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/dist/index.d.ts +14 -2
- package/dist/index.js +17 -5
- package/dist/logics/avatar-placeholder/get-avatar-placeholder.d.ts +1 -4
- package/dist/logics/avatar-placeholder/get-avatar-placeholder.js +1 -2
- package/dist/logics/avatar-placeholder/should-show-avatar-placeholder.d.ts +2 -5
- package/dist/logics/avatar-placeholder/should-show-avatar-placeholder.js +1 -2
- package/dist/logics/avatar-placeholder/should-show-avatar-placeholder.js.map +1 -1
- package/dist/logics/bool/to-bool.d.ts +1 -4
- package/dist/logics/bool/to-bool.js +1 -2
- package/dist/logics/bool/to-strbool.d.ts +1 -4
- package/dist/logics/bool/to-strbool.js +1 -2
- package/dist/logics/button-control/button-control.d.ts +16 -0
- package/dist/logics/button-control/button-control.js +26 -0
- package/dist/logics/button-control/button-control.js.map +1 -0
- package/dist/logics/cc/cc-all.d.ts +2 -5
- package/dist/logics/cc/cc-all.js +1 -2
- package/dist/logics/cc/cc-all.js.map +1 -1
- package/dist/logics/cc/cc.d.ts +2 -5
- package/dist/logics/cc/cc.js +1 -2
- package/dist/logics/cc/cc.js.map +1 -1
- package/dist/logics/checkbox-control/checkbox-control.d.ts +5 -8
- package/dist/logics/checkbox-control/checkbox-control.js +2 -3
- package/dist/logics/checkbox-control/checkbox-control.js.map +1 -1
- package/dist/logics/combobox-control/combobox-control.d.ts +100 -0
- package/dist/logics/combobox-control/combobox-control.js +100 -0
- package/dist/logics/combobox-control/combobox-control.js.map +1 -0
- package/dist/logics/combobox-control/combobox-filter.d.ts +13 -0
- package/dist/logics/combobox-control/combobox-filter.js +11 -0
- package/dist/logics/combobox-control/combobox-filter.js.map +1 -0
- package/dist/logics/combobox-control/combobox-navigation.d.ts +2 -0
- package/dist/logics/combobox-control/combobox-navigation.js +10 -0
- package/dist/logics/combobox-control/combobox-navigation.js.map +1 -0
- package/dist/logics/dialog-control/dialog-control.d.ts +5 -8
- package/dist/logics/dialog-control/dialog-control.js +1 -2
- package/dist/logics/dialog-control/dialog-control.js.map +1 -1
- package/dist/logics/input-control/input-control.d.ts +3 -6
- package/dist/logics/input-control/input-control.js +1 -2
- package/dist/logics/input-control/input-control.js.map +1 -1
- package/dist/logics/label-marker/label-marker.d.ts +2 -5
- package/dist/logics/label-marker/label-marker.js +1 -2
- package/dist/logics/label-marker/label-marker.js.map +1 -1
- package/dist/logics/menu-control/menu-control.d.ts +5 -8
- package/dist/logics/menu-control/menu-control.js +1 -2
- package/dist/logics/menu-control/menu-control.js.map +1 -1
- package/dist/logics/ms/ms-all.d.ts +3 -5
- package/dist/logics/ms/ms-all.js +1 -2
- package/dist/logics/ms/ms-all.js.map +1 -1
- package/dist/logics/multi-combobox-control/multi-combobox-control.d.ts +58 -0
- package/dist/logics/multi-combobox-control/multi-combobox-control.js +76 -0
- package/dist/logics/multi-combobox-control/multi-combobox-control.js.map +1 -0
- package/dist/logics/multi-combobox-control/multi-combobox-focus.d.ts +15 -0
- package/dist/logics/multi-combobox-control/multi-combobox-focus.js +46 -0
- package/dist/logics/multi-combobox-control/multi-combobox-focus.js.map +1 -0
- package/dist/logics/popover-control/popover-control.d.ts +5 -6
- package/dist/logics/popover-control/popover-control.js +6 -3
- package/dist/logics/popover-control/popover-control.js.map +1 -1
- package/dist/logics/progress-control/progress-control.d.ts +4 -7
- package/dist/logics/progress-control/progress-control.js +2 -3
- package/dist/logics/progress-control/progress-control.js.map +1 -1
- package/dist/logics/radio-control/radio-control.d.ts +4 -7
- package/dist/logics/radio-control/radio-control.js +1 -2
- package/dist/logics/radio-control/radio-control.js.map +1 -1
- package/dist/logics/radiogroup-control/radiogroup-control.d.ts +3 -6
- package/dist/logics/radiogroup-control/radiogroup-control.js +1 -2
- package/dist/logics/radiogroup-control/radiogroup-control.js.map +1 -1
- package/dist/logics/segmented-control/segmented-control.d.ts +3 -6
- package/dist/logics/segmented-control/segmented-control.js +2 -3
- package/dist/logics/segmented-control/segmented-control.js.map +1 -1
- package/dist/logics/tabs-control/tabs-control.d.ts +5 -8
- package/dist/logics/tabs-control/tabs-control.js +1 -2
- package/dist/logics/tabs-control/tabs-control.js.map +1 -1
- package/dist/logics/tabs-control/tabs-keymap.js +1 -2
- package/dist/logics/tabs-control/tabs-keymap.js.map +1 -1
- package/dist/logics/tooltip-control/tooltip-control.d.ts +3 -6
- package/dist/logics/tooltip-control/tooltip-control.js +1 -2
- package/dist/logics/tooltip-control/tooltip-control.js.map +1 -1
- package/dist/recipes/alert/alert.d.ts +4 -7
- package/dist/recipes/alert/alert.js +6 -9
- package/dist/recipes/alert/alert.js.map +1 -1
- package/dist/recipes/anchor/anchor.d.ts +1 -4
- package/dist/recipes/anchor/anchor.js +1 -2
- package/dist/recipes/avatar/avatar.d.ts +1 -4
- package/dist/recipes/avatar/avatar.js +1 -2
- package/dist/recipes/blockquote/blockquote.d.ts +1 -4
- package/dist/recipes/blockquote/blockquote.js +4 -3
- package/dist/recipes/blockquote/blockquote.js.map +1 -1
- package/dist/recipes/button/button.d.ts +16 -7
- package/dist/recipes/button/button.js +39 -16
- package/dist/recipes/button/button.js.map +1 -1
- package/dist/recipes/checkbox/checkbox.d.ts +4 -27
- package/dist/recipes/checkbox/checkbox.js +14 -20
- package/dist/recipes/checkbox/checkbox.js.map +1 -1
- package/dist/recipes/code/code.d.ts +1 -4
- package/dist/recipes/code/code.js +1 -2
- package/dist/recipes/combobox/combobox.d.ts +8 -0
- package/dist/recipes/combobox/combobox.js +34 -0
- package/dist/recipes/combobox/combobox.js.map +1 -0
- package/dist/recipes/container/container.d.ts +1 -4
- package/dist/recipes/container/container.js +1 -2
- package/dist/recipes/details/details.d.ts +4 -7
- package/dist/recipes/details/details.js +10 -6
- package/dist/recipes/details/details.js.map +1 -1
- package/dist/recipes/dialog/dialog.d.ts +4 -5
- package/dist/recipes/dialog/dialog.js +6 -3
- package/dist/recipes/dialog/dialog.js.map +1 -1
- package/dist/recipes/dl/dl.d.ts +1 -4
- package/dist/recipes/dl/dl.js +6 -3
- package/dist/recipes/dl/dl.js.map +1 -1
- package/dist/recipes/drawer/drawer.d.ts +1 -4
- package/dist/recipes/drawer/drawer.js +1 -2
- package/dist/recipes/fieldset/fieldset.d.ts +1 -4
- package/dist/recipes/fieldset/fieldset.js +4 -3
- package/dist/recipes/fieldset/fieldset.js.map +1 -1
- package/dist/recipes/focus-ring/focus-ring.d.ts +1 -4
- package/dist/recipes/focus-ring/focus-ring.js +1 -2
- package/dist/recipes/heading/heading.d.ts +1 -4
- package/dist/recipes/heading/heading.js +1 -2
- package/dist/recipes/hr/hr.d.ts +1 -4
- package/dist/recipes/hr/hr.js +4 -3
- package/dist/recipes/hr/hr.js.map +1 -1
- package/dist/recipes/inline-feedback/inline-feedback.d.ts +50 -0
- package/dist/recipes/inline-feedback/inline-feedback.js +45 -0
- package/dist/recipes/inline-feedback/inline-feedback.js.map +1 -0
- package/dist/recipes/input/input.d.ts +4 -7
- package/dist/recipes/input/input.js +6 -5
- package/dist/recipes/input/input.js.map +1 -1
- package/dist/recipes/label/label.d.ts +2 -5
- package/dist/recipes/label/label.js +2 -2
- package/dist/recipes/label/label.js.map +1 -1
- package/dist/recipes/menu/menu.d.ts +1 -4
- package/dist/recipes/menu/menu.js +5 -3
- package/dist/recipes/menu/menu.js.map +1 -1
- package/dist/recipes/multi-combobox/multi-combobox.d.ts +8 -0
- package/dist/recipes/multi-combobox/multi-combobox.js +52 -0
- package/dist/recipes/multi-combobox/multi-combobox.js.map +1 -0
- package/dist/recipes/paragraph/paragraph.d.ts +1 -4
- package/dist/recipes/paragraph/paragraph.js +1 -2
- package/dist/recipes/popover/popover.d.ts +1 -4
- package/dist/recipes/popover/popover.js +4 -4
- package/dist/recipes/popover/popover.js.map +1 -1
- package/dist/recipes/progress/progress.d.ts +2 -5
- package/dist/recipes/progress/progress.js +1 -2
- package/dist/recipes/radio/radio.d.ts +4 -7
- package/dist/recipes/radio/radio.js +7 -6
- package/dist/recipes/radio/radio.js.map +1 -1
- package/dist/recipes/radiogroup/radiogroup.d.ts +1 -4
- package/dist/recipes/radiogroup/radiogroup.js +1 -2
- package/dist/recipes/section/section.d.ts +4 -5
- package/dist/recipes/section/section.js +6 -3
- package/dist/recipes/section/section.js.map +1 -1
- package/dist/recipes/segmented-control/segmented-control.d.ts +1 -4
- package/dist/recipes/segmented-control/segmented-control.js +11 -6
- package/dist/recipes/segmented-control/segmented-control.js.map +1 -1
- package/dist/recipes/select/select.d.ts +3 -6
- package/dist/recipes/select/select.js +6 -5
- package/dist/recipes/select/select.js.map +1 -1
- package/dist/recipes/skip-link/skip-link.d.ts +5 -0
- package/dist/recipes/skip-link/skip-link.js +9 -0
- package/dist/recipes/skip-link/skip-link.js.map +1 -0
- package/dist/recipes/status-icon/status-icon.d.ts +55 -0
- package/dist/recipes/status-icon/status-icon.js +39 -0
- package/dist/recipes/status-icon/status-icon.js.map +1 -0
- package/dist/recipes/table/table.d.ts +7 -8
- package/dist/recipes/table/table.js +17 -7
- package/dist/recipes/table/table.js.map +1 -1
- package/dist/recipes/tabs/tabs.d.ts +1 -4
- package/dist/recipes/tabs/tabs.js +4 -3
- package/dist/recipes/tabs/tabs.js.map +1 -1
- package/dist/recipes/tag/tag.d.ts +64 -0
- package/dist/recipes/tag/tag.js +86 -0
- package/dist/recipes/tag/tag.js.map +1 -0
- package/dist/recipes/text/text.d.ts +52 -0
- package/dist/recipes/text/text.js +42 -0
- package/dist/recipes/text/text.js.map +1 -0
- package/dist/recipes/visually-hidden/visually-hidden.d.ts +1 -4
- package/dist/recipes/visually-hidden/visually-hidden.js +1 -2
- package/dist/style.css +1 -1
- package/dist/styles/css-vars.d.ts +1 -4
- package/dist/styles/css-vars.js +1 -2
- package/dist/styles/make-recipe-type.d.ts +1 -4
- package/dist/styles/make-recipe.d.ts +2 -5
- package/dist/styles/make-recipe.js +3 -4
- package/dist/styles/make-recipe.js.map +1 -1
- package/dist/styles/primitive-css/{active.module.js → active.module.css.js} +2 -3
- package/dist/styles/primitive-css/active.module.css.js.map +1 -0
- package/dist/styles/primitive-css/{base.module.js → base.module.css.js} +3 -3
- package/dist/styles/primitive-css/base.module.css.js.map +1 -0
- package/dist/styles/primitive-css/checked.module.css.js +11 -0
- package/dist/styles/primitive-css/checked.module.css.js.map +1 -0
- package/dist/styles/primitive-css/composite.module.css.js +5 -0
- package/dist/styles/primitive-css/composite.module.css.js.map +1 -0
- package/dist/styles/primitive-css/{disabled.module.js → disabled.module.css.js} +2 -3
- package/dist/styles/primitive-css/disabled.module.css.js.map +1 -0
- package/dist/styles/primitive-css/focus.module.css.js +10 -0
- package/dist/styles/primitive-css/focus.module.css.js.map +1 -0
- package/dist/styles/primitive-css/{hover.module.js → hover.module.css.js} +4 -4
- package/dist/styles/primitive-css/hover.module.css.js.map +1 -0
- package/dist/styles/primitive-css/icon.module.css.js +13 -0
- package/dist/styles/primitive-css/icon.module.css.js.map +1 -0
- package/dist/styles/primitive-css/{misc.module.js → misc.module.css.js} +8 -7
- package/dist/styles/primitive-css/misc.module.css.js.map +1 -0
- package/dist/styles/primitive-css/{neutral.module.js → neutral.module.css.js} +29 -13
- package/dist/styles/primitive-css/neutral.module.css.js.map +1 -0
- package/dist/styles/primitive-css/{pseudo-element.module.js → pseudo-element.module.css.js} +2 -3
- package/dist/styles/primitive-css/pseudo-element.module.css.js.map +1 -0
- package/dist/styles/primitive.gen.d.ts +80 -21
- package/dist/styles/primitive.gen.js +77 -38
- package/dist/styles/primitive.gen.js.map +1 -1
- package/package.json +5 -5
- package/dist/styles/primitive-css/active.module.js.map +0 -1
- package/dist/styles/primitive-css/base.module.js.map +0 -1
- package/dist/styles/primitive-css/checked.module.js +0 -10
- package/dist/styles/primitive-css/checked.module.js.map +0 -1
- package/dist/styles/primitive-css/composite.module.js +0 -6
- package/dist/styles/primitive-css/composite.module.js.map +0 -1
- package/dist/styles/primitive-css/disabled.module.js.map +0 -1
- package/dist/styles/primitive-css/focus.module.js +0 -10
- package/dist/styles/primitive-css/focus.module.js.map +0 -1
- package/dist/styles/primitive-css/hover.module.js.map +0 -1
- package/dist/styles/primitive-css/icon.module.js +0 -11
- package/dist/styles/primitive-css/icon.module.js.map +0 -1
- package/dist/styles/primitive-css/misc.module.js.map +0 -1
- package/dist/styles/primitive-css/neutral.module.js.map +0 -1
- package/dist/styles/primitive-css/pseudo-element.module.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"combobox-control.js","names":[],"sources":["../../../src/logics/combobox-control/combobox-control.ts"],"sourcesContent":["import { type Strbool, toStrbool } from \"../bool\";\nimport { popoverControl } from \"../popover-control\";\nimport { type ComboboxMode, type ComboboxSelectOption, getComboboxOptionText } from \"./combobox-filter\";\n\nconst DEFAULT_REQUIRED_MESSAGE = \"Please fill out this field.\";\n\nexport interface ComboboxState {\n mode: ComboboxMode;\n value: string | null;\n query: string;\n activeValue: string | null;\n disabled: boolean;\n readOnly: boolean;\n}\n\nfunction canEdit(state: Pick<ComboboxState, \"disabled\" | \"readOnly\">): boolean {\n return !state.disabled && !state.readOnly;\n}\n\nfunction getInputValue(state: Readonly<ComboboxState>, options: readonly ComboboxSelectOption[]): string {\n if (state.mode === \"text\") return state.value ?? \"\";\n if (state.value === null) return state.query;\n const option = options.find((candidate) => candidate.value === state.value);\n return option ? getComboboxOptionText(state.mode, option) : state.value;\n}\n\ntype ComboboxValueUpdate = Pick<ComboboxState, \"value\" | \"query\">;\nfunction edit(mode: ComboboxMode, text: string): ComboboxValueUpdate {\n return mode === \"text\"\n ? { value: text, query: \"\" }\n : { value: null, query: text };\n}\n\ntype ComboboxSelectionUpdate = ComboboxValueUpdate & {\n value: NonNullable<ComboboxState[\"value\"]>;\n};\nfunction select(\n state: Readonly<ComboboxState>,\n option: Readonly<ComboboxSelectOption>,\n): ComboboxSelectionUpdate | null {\n if (!canEdit(state) || option.disabled) return null;\n return { value: option.value, query: \"\" };\n}\n\nexport interface ComboboxValidationState {\n value: string | null;\n required: boolean;\n disabled: boolean;\n readOnly: boolean;\n requiredMessage?: string | undefined;\n}\n\nfunction getValidationMessage(state: Readonly<ComboboxValidationState>): string {\n if (!state.required || state.disabled || state.readOnly || (state.value !== null && state.value !== \"\")) return \"\";\n return state.requiredMessage || DEFAULT_REQUIRED_MESSAGE;\n}\n\nexport interface ComboboxFormValueProps {\n name: string;\n value: string;\n form: string | undefined;\n disabled: boolean;\n}\n\nexport interface ComboboxFormValueOptions {\n name: string | undefined;\n value: string | null;\n form: string | undefined;\n disabled: boolean;\n}\n\nfunction getFormValueProps(\n { name, value, form, disabled }: Readonly<ComboboxFormValueOptions>,\n): ComboboxFormValueProps | null {\n return name !== undefined && value !== null ? { name, value, form, disabled } : null;\n}\n\nexport type ComboboxKeyAction = \"none\" | \"next\" | \"previous\" | \"commit\" | \"blocked\" | \"submit\";\n\nexport interface ComboboxKeyEvent {\n key: string;\n isComposing: boolean;\n keyCode: number;\n altKey: boolean;\n ctrlKey: boolean;\n metaKey: boolean;\n shiftKey: boolean;\n}\n\nexport interface ComboboxKeyState extends Pick<ComboboxState, \"disabled\" | \"readOnly\"> {\n opened: boolean;\n}\n\nfunction getKeyAction(\n event: Readonly<ComboboxKeyEvent>,\n state: Readonly<ComboboxKeyState>,\n activeOption: Readonly<ComboboxSelectOption> | undefined,\n): ComboboxKeyAction {\n if (!canEdit(state) || event.isComposing || event.keyCode === 229) return \"none\";\n if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return \"none\";\n switch (event.key) {\n case \"ArrowDown\":\n return \"next\";\n case \"ArrowUp\":\n return state.opened ? \"previous\" : \"none\";\n case \"Enter\":\n if (!state.opened || !activeOption) return \"submit\";\n return activeOption.disabled ? \"blocked\" : \"commit\";\n default:\n return \"none\";\n }\n}\n\nexport interface ComboboxInputAttributeState {\n inputId: string;\n listId: string;\n activeId: string | undefined;\n opened: boolean;\n required: boolean;\n}\n\nexport interface ComboboxInputAttributes {\n id: string;\n type: \"text\";\n role: \"combobox\";\n \"aria-autocomplete\": \"list\";\n \"aria-controls\": string;\n \"aria-expanded\": boolean;\n \"aria-activedescendant\": string | undefined;\n \"aria-required\": boolean;\n}\n\nfunction getInputAttributes(state: Readonly<ComboboxInputAttributeState>): ComboboxInputAttributes {\n return {\n id: state.inputId,\n type: \"text\",\n role: \"combobox\",\n \"aria-autocomplete\": \"list\",\n \"aria-controls\": state.listId,\n \"aria-expanded\": state.opened,\n \"aria-activedescendant\": state.opened ? state.activeId : undefined,\n \"aria-required\": state.required,\n } as const;\n}\n\nexport interface ComboboxListAttributes {\n id: string;\n popover: \"auto\" | undefined;\n hidden: boolean;\n role: \"listbox\";\n \"aria-labelledby\": string;\n}\n\nfunction getListAttributes(\n listId: string,\n inputId: string,\n state: Pick<ComboboxState, \"disabled\" | \"readOnly\">,\n): ComboboxListAttributes {\n const editable = canEdit(state);\n return {\n ...popoverControl.getContentAttributes({ popoverId: listId }),\n popover: editable ? \"auto\" : undefined,\n hidden: !editable,\n role: \"listbox\",\n \"aria-labelledby\": inputId,\n } as const;\n}\n\nexport interface ComboboxItemAttributes {\n id: string;\n role: \"option\";\n \"aria-selected\": boolean;\n \"aria-disabled\": boolean;\n \"data-focus\": Strbool;\n}\n\nfunction getItemAttributes(id: string, active: boolean, disabled: boolean): ComboboxItemAttributes {\n return {\n id,\n role: \"option\",\n \"aria-selected\": active,\n \"aria-disabled\": disabled,\n \"data-focus\": toStrbool(active),\n } as const;\n}\n\nexport const comboboxControl = {\n canEdit,\n getInputValue,\n edit,\n select,\n getValidationMessage,\n getFormValueProps,\n getKeyAction,\n getInputAttributes,\n getListAttributes,\n getItemAttributes,\n} as const;\n"],"mappings":";;;;AAIA,MAAM,2BAA2B;AAWjC,SAAS,QAAQ,OAA8D;CAC7E,OAAO,CAAC,MAAM,YAAY,CAAC,MAAM;AACnC;AAEA,SAAS,cAAc,OAAgC,SAAkD;CACvG,IAAI,MAAM,SAAS,QAAQ,OAAO,MAAM,SAAS;CACjD,IA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;EACvB,yBAAyB,MAAM,SAAS,MAAM,WAAW,KAAA;EACzD,iBAAiB,MAAM;CACzB;AACF;AAUA,SAAS,kBACP,QACA,SACA,OACwB;CACxB,MAAM,WAAW,QAAQ,KAAK;CAC9B,OAAO;EACL,GAAG,eAAe,qBAAqB,EAAE,WAAW,OAAO,CAAC;EAC5D,SAAS,WAAW,SAAS,KAAA;EAC7B,QAAQ,CAAC;EACT,MAAM;EACN,mBAAmB;CACrB;AACF;AAUA,SAAS,kBAAkB,IAAY,QAAiB,UAA2C;CACjG,OAAO;EACL;EACA,MAAM;EACN,iBAAiB;EACjB,iBAAiB;EACjB,cAAc,UAAU,MAAM;CAChC;AACF;AAEA,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface ComboboxSelectOption {
|
|
2
|
+
value: string;
|
|
3
|
+
label?: string | undefined;
|
|
4
|
+
disabled?: boolean | undefined;
|
|
5
|
+
}
|
|
6
|
+
export interface ComboboxTextOption {
|
|
7
|
+
value: string;
|
|
8
|
+
disabled?: boolean | undefined;
|
|
9
|
+
label?: never;
|
|
10
|
+
}
|
|
11
|
+
export type ComboboxMode = "select" | "text";
|
|
12
|
+
export declare function getComboboxOptionText(mode: ComboboxMode, option: Readonly<ComboboxSelectOption>): string;
|
|
13
|
+
export declare function filterComboboxOptions<O extends ComboboxSelectOption>(mode: ComboboxMode, options: readonly O[], query: string): O[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/logics/combobox-control/combobox-filter.ts
|
|
2
|
+
function getComboboxOptionText(mode, option) {
|
|
3
|
+
return mode === "select" ? option.label ?? option.value : option.value;
|
|
4
|
+
}
|
|
5
|
+
function filterComboboxOptions(mode, options, query) {
|
|
6
|
+
const search = query.trim().normalize("NFKC").toLowerCase();
|
|
7
|
+
return options.filter((option) => getComboboxOptionText(mode, option).normalize("NFKC").toLowerCase().includes(search));
|
|
8
|
+
}
|
|
9
|
+
export { filterComboboxOptions, getComboboxOptionText };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=combobox-filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"combobox-filter.js","names":[],"sources":["../../../src/logics/combobox-control/combobox-filter.ts"],"sourcesContent":["export interface ComboboxSelectOption {\n value: string;\n label?: string | undefined;\n disabled?: boolean | undefined;\n}\n\nexport interface ComboboxTextOption {\n value: string;\n disabled?: boolean | undefined;\n label?: never;\n}\n\nexport type ComboboxMode = \"select\" | \"text\";\n\nexport function getComboboxOptionText(mode: ComboboxMode, option: Readonly<ComboboxSelectOption>): string {\n return mode === \"select\" ? option.label ?? option.value : option.value;\n}\n\nexport function filterComboboxOptions<O extends ComboboxSelectOption>(\n mode: ComboboxMode,\n options: readonly O[],\n query: string,\n): O[] {\n const search = query.trim().normalize(\"NFKC\").toLowerCase();\n return options.filter((option) =>\n getComboboxOptionText(mode, option).normalize(\"NFKC\").toLowerCase().includes(search)\n );\n}\n"],"mappings":";AAcA,SAAgB,sBAAsB,MAAoB,QAAgD;CACxG,OAAO,SAAS,WAAW,OAAO,SAAS,OAAO,QAAQ,OAAO;AACnE;AAEA,SAAgB,sBACd,MACA,SACA,OACK;CACL,MAAM,SAAS,MAAM,KAAK,CAAC,CAAC,UAAU,MAAM,CAAC,CAAC,YAAY;CAC1D,OAAO,QAAQ,QAAQ,WACrB,sBAAsB,MAAM,MAAM,CAAC,CAAC,UAAU,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,SAAS,MAAM,CACrF;AACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/logics/combobox-control/combobox-navigation.ts
|
|
2
|
+
function moveComboboxActiveValue(options, activeValue, direction) {
|
|
3
|
+
if (options.length === 0) return null;
|
|
4
|
+
const activeIndex = options.findIndex((option) => option.value === activeValue);
|
|
5
|
+
if (activeIndex === -1) return (direction === "next" ? options[0] : options.at(-1))?.value ?? null;
|
|
6
|
+
return options[activeIndex + (direction === "next" ? 1 : -1)]?.value ?? activeValue;
|
|
7
|
+
}
|
|
8
|
+
export { moveComboboxActiveValue };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=combobox-navigation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"combobox-navigation.js","names":[],"sources":["../../../src/logics/combobox-control/combobox-navigation.ts"],"sourcesContent":["import { type ComboboxSelectOption } from \"./combobox-filter\";\n\nexport function moveComboboxActiveValue(\n options: readonly ComboboxSelectOption[],\n activeValue: string | null,\n direction: \"next\" | \"previous\",\n): string | null {\n if (options.length === 0) return null;\n\n const activeIndex = options.findIndex((option) => option.value === activeValue);\n if (activeIndex === -1) {\n const initialOption = direction === \"next\" ? options[0] : options.at(-1);\n return initialOption?.value ?? null;\n }\n\n const step = direction === \"next\" ? 1 : -1;\n const nextOption = options[activeIndex + step];\n return nextOption?.value ?? activeValue;\n}\n"],"mappings":";AAEA,SAAgB,wBACd,SACA,aACA,WACe;CACf,IAAI,QAAQ,WAAW,GAAG,OAAO;CAEjC,MAAM,cAAc,QAAQ,WAAW,WAAW,OAAO,UAAU,WAAW;CAC9E,IAAI,gBAAgB,IAElB,QADsB,cAAc,SAAS,QAAQ,KAAK,QAAQ,GAAG,EAAE,EAAA,EACjD,SAAS;CAKjC,OADmB,QAAQ,eADd,cAAc,SAAS,IAAI,IAEvB,EAAE,SAAS;AAC9B"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/logics/dialog-control/dialog-control.d.ts
|
|
2
1
|
export interface DialogState {
|
|
3
2
|
id: string;
|
|
4
3
|
}
|
|
@@ -12,7 +11,7 @@ export interface DialogTriggerAttributes {
|
|
|
12
11
|
command: "show-modal" | undefined;
|
|
13
12
|
commandfor: string | undefined;
|
|
14
13
|
}
|
|
15
|
-
declare function getTriggerAttributes(state: DialogState
|
|
14
|
+
declare function getTriggerAttributes(state: Readonly<DialogState>, options: Readonly<DialogTriggerAttributeOptions>): DialogTriggerAttributes;
|
|
16
15
|
export interface DialogContentAttributeOptions {
|
|
17
16
|
hasHeading: boolean;
|
|
18
17
|
ariaLabel?: string | undefined;
|
|
@@ -23,17 +22,17 @@ export interface DialogContentAttributes {
|
|
|
23
22
|
"aria-label": string | undefined;
|
|
24
23
|
"aria-labelledby": string | undefined;
|
|
25
24
|
}
|
|
26
|
-
declare function getContentAttributes(state: DialogState
|
|
25
|
+
declare function getContentAttributes(state: Readonly<DialogState>, options: Readonly<DialogContentAttributeOptions>): DialogContentAttributes;
|
|
27
26
|
export interface DialogHeadingAttributes {
|
|
28
27
|
id: string;
|
|
29
28
|
}
|
|
30
|
-
declare function getHeadingAttributes(state: DialogState): DialogHeadingAttributes;
|
|
29
|
+
declare function getHeadingAttributes(state: Readonly<DialogState>): DialogHeadingAttributes;
|
|
31
30
|
export interface DialogCloseAttributes {
|
|
32
31
|
type: "button";
|
|
33
32
|
command: "request-close";
|
|
34
33
|
commandfor: string;
|
|
35
34
|
}
|
|
36
|
-
declare function getCloseAttributes(state: DialogState): DialogCloseAttributes;
|
|
35
|
+
declare function getCloseAttributes(state: Readonly<DialogState>): DialogCloseAttributes;
|
|
37
36
|
declare function openDialog(dialogId: string, modal: boolean): void;
|
|
38
37
|
export declare const dialogControl: {
|
|
39
38
|
readonly getTriggerAttributes: typeof getTriggerAttributes;
|
|
@@ -43,6 +42,4 @@ export declare const dialogControl: {
|
|
|
43
42
|
readonly openDialog: typeof openDialog;
|
|
44
43
|
readonly headingId: typeof headingId;
|
|
45
44
|
};
|
|
46
|
-
|
|
47
|
-
export {};
|
|
48
|
-
//# sourceMappingURL=dialog-control.d.ts.map
|
|
45
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/logics/dialog-control/dialog-control.ts
|
|
2
2
|
function headingId(dialogId) {
|
|
3
3
|
return `${dialogId}-heading`;
|
|
4
4
|
}
|
|
@@ -45,7 +45,6 @@ const dialogControl = {
|
|
|
45
45
|
openDialog,
|
|
46
46
|
headingId
|
|
47
47
|
};
|
|
48
|
-
//#endregion
|
|
49
48
|
export { dialogControl };
|
|
50
49
|
|
|
51
50
|
//# sourceMappingURL=dialog-control.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog-control.js","names":[],"sources":["../../../src/logics/dialog-control/dialog-control.ts"],"sourcesContent":["export interface DialogState {\n id: string;\n}\n\nfunction headingId(dialogId: string): string {\n return `${dialogId}-heading`;\n}\n\nexport interface DialogTriggerAttributeOptions {\n modal: boolean;\n isButtonElement: boolean;\n}\n\nexport interface DialogTriggerAttributes {\n type: \"button\" | undefined;\n command: \"show-modal\" | undefined;\n commandfor: string | undefined;\n}\n\nfunction getTriggerAttributes(\n state: DialogState
|
|
1
|
+
{"version":3,"file":"dialog-control.js","names":[],"sources":["../../../src/logics/dialog-control/dialog-control.ts"],"sourcesContent":["export interface DialogState {\n id: string;\n}\n\nfunction headingId(dialogId: string): string {\n return `${dialogId}-heading`;\n}\n\nexport interface DialogTriggerAttributeOptions {\n modal: boolean;\n isButtonElement: boolean;\n}\n\nexport interface DialogTriggerAttributes {\n type: \"button\" | undefined;\n command: \"show-modal\" | undefined;\n commandfor: string | undefined;\n}\n\nfunction getTriggerAttributes(\n state: Readonly<DialogState>,\n options: Readonly<DialogTriggerAttributeOptions>,\n): DialogTriggerAttributes {\n return {\n type: options.isButtonElement ? \"button\" : undefined,\n command: options.modal ? \"show-modal\" : undefined,\n commandfor: options.modal ? state.id : undefined,\n };\n}\n\nexport interface DialogContentAttributeOptions {\n hasHeading: boolean;\n ariaLabel?: string | undefined;\n ariaLabelledBy?: string | undefined;\n}\n\nexport interface DialogContentAttributes {\n id: string;\n \"aria-label\": string | undefined;\n \"aria-labelledby\": string | undefined;\n}\n\nfunction getContentAttributes(\n state: Readonly<DialogState>,\n options: Readonly<DialogContentAttributeOptions>,\n): DialogContentAttributes {\n return {\n id: state.id,\n \"aria-label\": options.ariaLabel,\n \"aria-labelledby\": options.ariaLabelledBy\n ?? (!options.ariaLabel && options.hasHeading ? headingId(state.id) : undefined),\n };\n}\n\nexport interface DialogHeadingAttributes {\n id: string;\n}\n\nfunction getHeadingAttributes(state: Readonly<DialogState>): DialogHeadingAttributes {\n return {\n id: headingId(state.id),\n };\n}\n\nexport interface DialogCloseAttributes {\n type: \"button\";\n command: \"request-close\";\n commandfor: string;\n}\n\nfunction getCloseAttributes(state: Readonly<DialogState>): DialogCloseAttributes {\n return {\n type: \"button\",\n command: \"request-close\",\n commandfor: state.id,\n };\n}\n\nfunction getDialogElement(dialogId: string): HTMLDialogElement {\n const element = document.getElementById(dialogId);\n if (!(element instanceof HTMLDialogElement)) {\n throw new Error(\"[Hebium UI|Dialog] Dialog element is not found\");\n }\n return element;\n}\n\nfunction openDialog(dialogId: string, modal: boolean): void {\n const element = getDialogElement(dialogId);\n if (element.open) return;\n\n if (modal) {\n element.showModal();\n } else {\n element.show();\n }\n}\n\nexport const dialogControl = {\n getTriggerAttributes,\n getContentAttributes,\n getHeadingAttributes,\n getCloseAttributes,\n openDialog,\n headingId,\n} as const;\n"],"mappings":";AAIA,SAAS,UAAU,UAA0B;CAC3C,OAAO,GAAG,SAAS;AACrB;AAaA,SAAS,qBACP,OACA,SACyB;CACzB,OAAO;EACL,MAAM,QAAQ,kBAAkB,WAAW,KAAA;EAC3C,SAAS,QAAQ,QAAQ,eAAe,KAAA;EACxC,YAAY,QAAQ,QAAQ,MAAM,KAAK,KAAA;CACzC;AACF;AAcA,SAAS,qBACP,OACA,SACyB;CACzB,OAAO;EACL,IAAI,MAAM;EACV,cAAc,QAAQ;EACtB,mBAAmB,QAAQ,mBACrB,CAAC,QAAQ,aAAa,QAAQ,aAAa,UAAU,MAAM,EAAE,IAAI,KAAA;CACzE;AACF;AAMA,SAAS,qBAAqB,OAAuD;CACnF,OAAO,EACL,IAAI,UAAU,MAAM,EAAE,EACxB;AACF;AAQA,SAAS,mBAAmB,OAAqD;CAC/E,OAAO;EACL,MAAM;EACN,SAAS;EACT,YAAY,MAAM;CACpB;AACF;AAEA,SAAS,iBAAiB,UAAqC;CAC7D,MAAM,UAAU,SAAS,eAAe,QAAQ;CAChD,IAAI,EAAE,mBAAmB,oBACvB,MAAM,IAAI,MAAM,gDAAgD;CAElE,OAAO;AACT;AAEA,SAAS,WAAW,UAAkB,OAAsB;CAC1D,MAAM,UAAU,iBAAiB,QAAQ;CACzC,IAAI,QAAQ,MAAM;CAElB,IAAI,OACF,QAAQ,UAAU;MAElB,QAAQ,KAAK;AAEjB;AAEA,MAAa,gBAAgB;CAC3B;CACA;CACA;CACA;CACA;CACA;AACF"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { LabelVariants } from "../../recipes/label/label.js";
|
|
2
|
-
//#region src/logics/input-control/input-control.d.ts
|
|
3
2
|
export interface InputControlState {
|
|
4
3
|
id: string;
|
|
5
4
|
invalid: boolean;
|
|
@@ -13,17 +12,15 @@ export interface InputControlAttributes {
|
|
|
13
12
|
id: string;
|
|
14
13
|
"aria-invalid": boolean;
|
|
15
14
|
}
|
|
16
|
-
declare function getControlAttributes(state: InputControlState): InputControlAttributes;
|
|
15
|
+
declare function getControlAttributes(state: Readonly<InputControlState>): InputControlAttributes;
|
|
17
16
|
export interface InputLabelAttributes {
|
|
18
17
|
for: string;
|
|
19
18
|
"data-required": boolean;
|
|
20
19
|
variant: LabelVariants["variant"] | undefined;
|
|
21
20
|
}
|
|
22
|
-
declare function getLabelAttributes(state: InputState): InputLabelAttributes;
|
|
21
|
+
declare function getLabelAttributes(state: Readonly<InputState>): InputLabelAttributes;
|
|
23
22
|
export declare const inputControl: {
|
|
24
23
|
readonly getControlAttributes: typeof getControlAttributes;
|
|
25
24
|
readonly getLabelAttributes: typeof getLabelAttributes;
|
|
26
25
|
};
|
|
27
|
-
|
|
28
|
-
export {};
|
|
29
|
-
//# sourceMappingURL=input-control.d.ts.map
|
|
26
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/logics/input-control/input-control.ts
|
|
2
2
|
function getControlAttributes(state) {
|
|
3
3
|
return {
|
|
4
4
|
id: state.id,
|
|
@@ -16,7 +16,6 @@ const inputControl = {
|
|
|
16
16
|
getControlAttributes,
|
|
17
17
|
getLabelAttributes
|
|
18
18
|
};
|
|
19
|
-
//#endregion
|
|
20
19
|
export { inputControl };
|
|
21
20
|
|
|
22
21
|
//# sourceMappingURL=input-control.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-control.js","names":[],"sources":["../../../src/logics/input-control/input-control.ts"],"sourcesContent":["import { type LabelVariants } from \"~/recipes\";\n\nexport interface InputControlState {\n id: string;\n invalid: boolean;\n}\n\nexport interface InputState extends InputControlState {\n required: boolean;\n disabled: boolean;\n readOnly?: boolean | undefined;\n}\n\nexport interface InputControlAttributes {\n id: string;\n \"aria-invalid\": boolean;\n}\n\nfunction getControlAttributes(state: InputControlState): InputControlAttributes {\n return {\n id: state.id,\n \"aria-invalid\": state.invalid,\n };\n}\n\nexport interface InputLabelAttributes {\n for: string;\n \"data-required\": boolean;\n variant: LabelVariants[\"variant\"] | undefined;\n}\n\nfunction getLabelAttributes(state: InputState): InputLabelAttributes {\n return {\n for: state.id,\n \"data-required\": state.required,\n variant: state.disabled ? \"disabled\" : state.readOnly ? \"readonly\" : undefined,\n };\n}\n\nexport const inputControl = {\n getControlAttributes,\n getLabelAttributes,\n} as const;\n"],"mappings":";AAkBA,SAAS,qBAAqB,
|
|
1
|
+
{"version":3,"file":"input-control.js","names":[],"sources":["../../../src/logics/input-control/input-control.ts"],"sourcesContent":["import { type LabelVariants } from \"~/recipes\";\n\nexport interface InputControlState {\n id: string;\n invalid: boolean;\n}\n\nexport interface InputState extends InputControlState {\n required: boolean;\n disabled: boolean;\n readOnly?: boolean | undefined;\n}\n\nexport interface InputControlAttributes {\n id: string;\n \"aria-invalid\": boolean;\n}\n\nfunction getControlAttributes(state: Readonly<InputControlState>): InputControlAttributes {\n return {\n id: state.id,\n \"aria-invalid\": state.invalid,\n };\n}\n\nexport interface InputLabelAttributes {\n for: string;\n \"data-required\": boolean;\n variant: LabelVariants[\"variant\"] | undefined;\n}\n\nfunction getLabelAttributes(state: Readonly<InputState>): InputLabelAttributes {\n return {\n for: state.id,\n \"data-required\": state.required,\n variant: state.disabled ? \"disabled\" : state.readOnly ? \"readonly\" : undefined,\n };\n}\n\nexport const inputControl = {\n getControlAttributes,\n getLabelAttributes,\n} as const;\n"],"mappings":";AAkBA,SAAS,qBAAqB,OAA4D;CACxF,OAAO;EACL,IAAI,MAAM;EACV,gBAAgB,MAAM;CACxB;AACF;AAQA,SAAS,mBAAmB,OAAmD;CAC7E,OAAO;EACL,KAAK,MAAM;EACX,iBAAiB,MAAM;EACvB,SAAS,MAAM,WAAW,aAAa,MAAM,WAAW,aAAa,KAAA;CACvE;AACF;AAEA,MAAa,eAAe;CAC1B;CACA;AACF"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { LabelVariants } from "../../recipes/label/label.js";
|
|
2
|
-
//#region src/logics/label-marker/label-marker.d.ts
|
|
3
2
|
interface BaseMarker<Node> {
|
|
4
3
|
label: Node;
|
|
5
4
|
"aria-label"?: string | undefined;
|
|
@@ -30,7 +29,5 @@ export declare const DEFAULT_LABEL_MAKER: {
|
|
|
30
29
|
readonly type: "required";
|
|
31
30
|
readonly label: "(required)";
|
|
32
31
|
};
|
|
33
|
-
export declare function labelMarker<Node>(marker: LabelMarker<Node
|
|
34
|
-
|
|
35
|
-
export {};
|
|
36
|
-
//# sourceMappingURL=label-marker.d.ts.map
|
|
32
|
+
export declare function labelMarker<Node>(marker: Readonly<LabelMarker<Node>>, required: boolean | undefined): LabelMarkerData<Node>;
|
|
33
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/logics/label-marker/label-marker.ts
|
|
2
2
|
const DEFAULT_LABEL_MAKER = {
|
|
3
3
|
type: "required",
|
|
4
4
|
label: "(required)"
|
|
@@ -13,7 +13,6 @@ function labelMarker(marker, required) {
|
|
|
13
13
|
...ariaLabel !== void 0 && { "aria-label": ariaLabel }
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
-
//#endregion
|
|
17
16
|
export { DEFAULT_LABEL_MAKER, labelMarker };
|
|
18
17
|
|
|
19
18
|
//# sourceMappingURL=label-marker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"label-marker.js","names":[],"sources":["../../../src/logics/label-marker/label-marker.ts"],"sourcesContent":["import { type LabelVariants } from \"~/recipes\";\n\ninterface BaseMarker<Node> {\n label: Node;\n \"aria-label\"?: string | undefined;\n /**\n * The visual style of the marker. Defaults to `\"asterisk\"` when `label` is `\"*\"`, otherwise `\"text\"`.\n */\n variant?: LabelVariants[\"marker\"] | undefined;\n}\n\ninterface RequiredMarker<Node> extends BaseMarker<Node> {\n type: \"required\";\n}\n\ninterface OptionalMarker<Node> extends BaseMarker<Node> {\n type: \"optional\";\n}\n\nexport type LabelMarker<Node> =\n | RequiredMarker<Node>\n | OptionalMarker<Node>\n | { type: \"none\" };\n\nexport interface LabelMarkerNullData {\n label: null;\n}\n\nexport interface LabelMarkerNodeData<Node> {\n label: Node;\n variant: LabelVariants[\"marker\"];\n \"aria-label\"?: string | undefined;\n}\n\nexport type LabelMarkerData<Node> = LabelMarkerNullData | LabelMarkerNodeData<Node>;\n\nexport const DEFAULT_LABEL_MAKER = {\n type: \"required\",\n label: \"(required)\",\n} as const satisfies LabelMarker<string>;\n\nexport function labelMarker<Node>(marker: LabelMarker<Node
|
|
1
|
+
{"version":3,"file":"label-marker.js","names":[],"sources":["../../../src/logics/label-marker/label-marker.ts"],"sourcesContent":["import { type LabelVariants } from \"~/recipes\";\n\ninterface BaseMarker<Node> {\n label: Node;\n \"aria-label\"?: string | undefined;\n /**\n * The visual style of the marker. Defaults to `\"asterisk\"` when `label` is `\"*\"`, otherwise `\"text\"`.\n */\n variant?: LabelVariants[\"marker\"] | undefined;\n}\n\ninterface RequiredMarker<Node> extends BaseMarker<Node> {\n type: \"required\";\n}\n\ninterface OptionalMarker<Node> extends BaseMarker<Node> {\n type: \"optional\";\n}\n\nexport type LabelMarker<Node> =\n | RequiredMarker<Node>\n | OptionalMarker<Node>\n | { type: \"none\" };\n\nexport interface LabelMarkerNullData {\n label: null;\n}\n\nexport interface LabelMarkerNodeData<Node> {\n label: Node;\n variant: LabelVariants[\"marker\"];\n \"aria-label\"?: string | undefined;\n}\n\nexport type LabelMarkerData<Node> = LabelMarkerNullData | LabelMarkerNodeData<Node>;\n\nexport const DEFAULT_LABEL_MAKER = {\n type: \"required\",\n label: \"(required)\",\n} as const satisfies LabelMarker<string>;\n\nexport function labelMarker<Node>(\n marker: Readonly<LabelMarker<Node>>,\n required: boolean | undefined,\n): LabelMarkerData<Node> {\n if (marker.type === \"none\") {\n return { label: null };\n }\n const shown = marker.type === \"required\" ? required : !required;\n if (!shown) {\n return { label: null };\n }\n const ariaLabel = \"aria-label\" in marker ? marker[\"aria-label\"] : undefined;\n return {\n label: marker.label,\n variant: marker.variant ?? (marker.label === \"*\" ? \"asterisk\" : \"text\"),\n ...(ariaLabel !== undefined && { \"aria-label\": ariaLabel }),\n };\n}\n"],"mappings":";AAoCA,MAAa,sBAAsB;CACjC,MAAM;CACN,OAAO;AACT;AAEA,SAAgB,YACd,QACA,UACuB;CACvB,IAAI,OAAO,SAAS,QAClB,OAAO,EAAE,OAAO,KAAK;CAGvB,IAAI,EADU,OAAO,SAAS,aAAa,WAAW,CAAC,WAErD,OAAO,EAAE,OAAO,KAAK;CAEvB,MAAM,YAAY,gBAAgB,SAAS,OAAO,gBAAgB,KAAA;CAClE,OAAO;EACL,OAAO,OAAO;EACd,SAAS,OAAO,YAAY,OAAO,UAAU,MAAM,aAAa;EAChE,GAAI,cAAc,KAAA,KAAa,EAAE,cAAc,UAAU;CAC3D;AACF"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/logics/menu-control/menu-control.d.ts
|
|
2
1
|
export interface MenuState {
|
|
3
2
|
menuId: string;
|
|
4
3
|
}
|
|
@@ -11,7 +10,7 @@ export interface MenuTriggerAttributes {
|
|
|
11
10
|
popovertarget: string;
|
|
12
11
|
type: "button" | undefined;
|
|
13
12
|
}
|
|
14
|
-
declare function getTriggerAttributes(state: MenuState
|
|
13
|
+
declare function getTriggerAttributes(state: Readonly<MenuState>, options: Readonly<MenuTriggerAttributeOptions>): MenuTriggerAttributes;
|
|
15
14
|
export interface MenuContentAttributeOptions {
|
|
16
15
|
ariaLabel?: string | undefined;
|
|
17
16
|
ariaLabelledBy?: string | undefined;
|
|
@@ -23,7 +22,7 @@ export interface MenuContentAttributes {
|
|
|
23
22
|
"aria-label": string | undefined;
|
|
24
23
|
"aria-labelledby": string | undefined;
|
|
25
24
|
}
|
|
26
|
-
declare function getContentAttributes(state: MenuState
|
|
25
|
+
declare function getContentAttributes(state: Readonly<MenuState>, options: Readonly<MenuContentAttributeOptions>): MenuContentAttributes;
|
|
27
26
|
export interface MenuItemAttributeOptions {
|
|
28
27
|
focusKey?: string | undefined;
|
|
29
28
|
disabled?: boolean | undefined;
|
|
@@ -35,7 +34,7 @@ export interface MenuItemAttributes {
|
|
|
35
34
|
"data-hui-menuitem": string;
|
|
36
35
|
"data-hui-focus-key"?: string | undefined;
|
|
37
36
|
}
|
|
38
|
-
declare function getItemAttributes(state: MenuState
|
|
37
|
+
declare function getItemAttributes(state: Readonly<MenuState>, options: Readonly<MenuItemAttributeOptions>): MenuItemAttributes;
|
|
39
38
|
declare function handleMenuTriggerKeydown(e: KeyboardEvent, menuId: string): void;
|
|
40
39
|
type ItemAction = "none" | "action" | "focus-move" | "focus-set" | "focus-out";
|
|
41
40
|
declare function handleMenuitemKeydown(e: KeyboardEvent, activation: MenuItemActivation): ItemAction;
|
|
@@ -43,7 +42,7 @@ export interface MenuItemActivationOptions {
|
|
|
43
42
|
activation: MenuItemActivation;
|
|
44
43
|
disabled: boolean;
|
|
45
44
|
}
|
|
46
|
-
declare function handleMenuitemActivation(e: Event, menuId: string, options: MenuItemActivationOptions
|
|
45
|
+
declare function handleMenuitemActivation(e: Event, menuId: string, options: Readonly<MenuItemActivationOptions>, onActivate?: (() => void) | undefined): void;
|
|
47
46
|
declare function moveMenuitemFocus(e: KeyboardEvent, menuId: string): void;
|
|
48
47
|
declare function setMenuitemFocus(e: KeyboardEvent, menuId: string): void;
|
|
49
48
|
declare function hideMenu(menuId: string): void;
|
|
@@ -58,6 +57,4 @@ export declare const menuControl: {
|
|
|
58
57
|
readonly setMenuitemFocus: typeof setMenuitemFocus;
|
|
59
58
|
readonly hideMenu: typeof hideMenu;
|
|
60
59
|
};
|
|
61
|
-
|
|
62
|
-
export {};
|
|
63
|
-
//# sourceMappingURL=menu-control.d.ts.map
|
|
60
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { toStrbool } from "../bool/to-strbool.js";
|
|
2
2
|
import { popoverControl } from "../popover-control/popover-control.js";
|
|
3
|
-
|
|
3
|
+
// src/logics/menu-control/menu-control.ts
|
|
4
4
|
const nextIndexMap = {
|
|
5
5
|
"ArrowUp": (currentIndex, itemsLength) => (currentIndex - 1 + itemsLength) % itemsLength,
|
|
6
6
|
"ArrowDown": (currentIndex, itemsLength) => (currentIndex + 1) % itemsLength,
|
|
@@ -130,7 +130,6 @@ const menuControl = {
|
|
|
130
130
|
setMenuitemFocus,
|
|
131
131
|
hideMenu
|
|
132
132
|
};
|
|
133
|
-
//#endregion
|
|
134
133
|
export { menuControl };
|
|
135
134
|
|
|
136
135
|
//# sourceMappingURL=menu-control.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-control.js","names":[],"sources":["../../../src/logics/menu-control/menu-control.ts"],"sourcesContent":["import { toStrbool } from \"../bool\";\nimport { popoverControl } from \"../popover-control\";\n\nexport interface MenuState {\n menuId: string;\n}\n\nexport type MenuItemActivation = \"managed\" | \"native\";\n\ntype indexMap = (currentIndex: number, itemsLength: number) => number;\nconst nextIndexMap: Readonly<Record<string, indexMap>> = {\n \"ArrowUp\": (currentIndex, itemsLength) => (currentIndex - 1 + itemsLength) % itemsLength,\n \"ArrowDown\": (currentIndex, itemsLength) => (currentIndex + 1) % itemsLength,\n \"Home\": (): number => 0,\n \"End\": (_, itemsLength) => itemsLength - 1,\n} as const;\n\nconst openKeys = new Set([\"ArrowUp\", \"ArrowDown\", \"Enter\", \" \"]);\nconst itemMotionKeys = Object.keys(nextIndexMap);\nconst itemActivationKeys = new Set([\"Enter\", \" \"]);\n\nconst menuitemDatasetItemKey = \"data-hui-menuitem\";\nconst menuitemDatasetFocusKeyKey = \"data-hui-focus-key\";\nconst menuitemDatasetFocusKeyName = \"huiFocusKey\";\n\nfunction triggerId(menuId: string): string {\n return `${menuId}-trigger`;\n}\n\ninterface MenuitemDataset {\n [menuitemDatasetItemKey]: string;\n [menuitemDatasetFocusKeyKey]?: string;\n}\n\nfunction menuitemDataset(menuId: string, focusKey?: string): MenuitemDataset {\n if (focusKey) {\n return {\n [menuitemDatasetItemKey]: `${menuId}-item`,\n [menuitemDatasetFocusKeyKey]: focusKey,\n };\n } else {\n return {\n [menuitemDatasetItemKey]: `${menuId}-item`,\n };\n }\n}\n\nexport interface MenuTriggerAttributeOptions {\n isButtonElement: boolean;\n}\n\nexport interface MenuTriggerAttributes {\n id: string;\n popovertarget: string;\n type: \"button\" | undefined;\n}\n\nfunction getTriggerAttributes(\n state: MenuState,\n options: MenuTriggerAttributeOptions,\n): MenuTriggerAttributes {\n return {\n id: triggerId(state.menuId),\n ...popoverControl.getTriggerAttributes(\n { popoverId: state.menuId },\n options,\n ),\n };\n}\n\nexport interface MenuContentAttributeOptions {\n ariaLabel?: string | undefined;\n ariaLabelledBy?: string | undefined;\n}\n\nexport interface MenuContentAttributes {\n role: \"menu\";\n id: string;\n popover: \"auto\";\n \"aria-label\": string | undefined;\n \"aria-labelledby\": string | undefined;\n}\n\nfunction getContentAttributes(\n state: MenuState,\n options: MenuContentAttributeOptions,\n): MenuContentAttributes {\n return {\n role: \"menu\",\n ...popoverControl.getContentAttributes({ popoverId: state.menuId }),\n \"aria-label\": options.ariaLabel,\n \"aria-labelledby\": options.ariaLabelledBy\n ?? (!options.ariaLabel ? triggerId(state.menuId) : undefined),\n };\n}\n\nexport interface MenuItemAttributeOptions {\n focusKey?: string | undefined;\n disabled?: boolean | undefined;\n}\n\nexport interface MenuItemAttributes {\n role: \"menuitem\";\n tabindex: -1;\n \"aria-disabled\": \"true\" | \"false\" | undefined;\n \"data-hui-menuitem\": string;\n \"data-hui-focus-key\"?: string | undefined;\n}\n\nfunction getItemAttributes(\n state: MenuState,\n options: MenuItemAttributeOptions,\n): MenuItemAttributes {\n return {\n role: \"menuitem\",\n tabindex: -1,\n \"aria-disabled\": options.disabled === undefined ? undefined : toStrbool(options.disabled),\n ...menuitemDataset(state.menuId, options.focusKey),\n };\n}\n\nfunction getMenu(menuId: string): HTMLElement {\n const menu = document.getElementById(menuId);\n if (!(menu instanceof HTMLElement)) {\n throw new Error(\"[Hebium UI|Menu] Menu element is not found\");\n }\n return menu;\n}\n\nfunction getFocusableMenuitems(menuId: string): HTMLElement[] {\n const itemDataset = menuitemDataset(menuId);\n const menuitemList = getMenu(menuId).querySelectorAll(\n `[${menuitemDatasetItemKey}=\"${itemDataset[menuitemDatasetItemKey]}\"]`,\n );\n return Array.from(menuitemList)\n .filter((e) => e instanceof HTMLElement);\n}\n\nfunction isCharKey(key: string): boolean {\n return key.length === 1 && /^\\S$/.test(key);\n}\n\nfunction handleMenuTriggerKeydown(e: KeyboardEvent, menuId: string): void {\n if (!openKeys.has(e.key)) return;\n const trigger = e.target;\n if (!(trigger instanceof HTMLElement)) {\n throw new Error(\"[Hebuim UI|Menu] Only HTMLElement events are supported\");\n }\n const menu = getMenu(menuId);\n\n e.preventDefault();\n menu.showPopover({ source: trigger });\n if (e.key === \"ArrowUp\") {\n const menuitems = getFocusableMenuitems(menuId);\n menuitems.at(-1)?.focus();\n } else {\n const menuitems = getFocusableMenuitems(menuId);\n menuitems.at(0)?.focus();\n }\n}\n\ntype ItemAction = \"none\" | \"action\" | \"focus-move\" | \"focus-set\" | \"focus-out\";\nfunction handleMenuitemKeydown(e: KeyboardEvent, activation: MenuItemActivation): ItemAction {\n if (itemActivationKeys.has(e.key)) return activation === \"managed\" ? \"action\" : \"none\";\n if (itemMotionKeys.includes(e.key)) return \"focus-move\";\n if (e.key === \"Tab\") return \"focus-out\";\n if (isCharKey(e.key)) return \"focus-set\";\n return \"none\";\n}\n\nexport interface MenuItemActivationOptions {\n activation: MenuItemActivation;\n disabled: boolean;\n}\n\nfunction handleMenuitemActivation(\n e: Event,\n menuId: string,\n options: MenuItemActivationOptions,\n onActivate?: (() => void) | undefined,\n): void {\n if (e.defaultPrevented) return;\n if (options.activation === \"managed\") e.preventDefault();\n if (options.disabled) return;\n onActivate?.();\n hideMenu(menuId);\n}\n\nfunction moveMenuitemFocus(e: KeyboardEvent, menuId: string): void {\n const currentItem = e.target;\n if (!(currentItem instanceof HTMLElement)) {\n throw new Error(\"[Hebuim UI|Menu] Only HTMLElement events are supported\");\n }\n\n const menuitems = getFocusableMenuitems(menuId);\n const currentIndex = menuitems.indexOf(currentItem);\n\n const map = nextIndexMap[e.key];\n if (typeof map === \"undefined\") {\n throw new Error(\"[Hebuim UI|Menu] Unexpected event key: \" + e.key);\n }\n const nextIndex = map(currentIndex, menuitems.length);\n const nextElement = menuitems[nextIndex];\n\n e.preventDefault();\n nextElement?.focus();\n}\n\nfunction findFocusItemIndex(\n menuitems: HTMLElement[],\n currentIndex: number,\n char: string,\n): number {\n const normalizedChar = char.toLowerCase();\n\n for (let offset = 1; offset <= menuitems.length; offset++) {\n const index = (currentIndex + offset) % menuitems.length;\n const item = menuitems[index];\n\n if (item?.dataset[menuitemDatasetFocusKeyName]?.toLowerCase() === normalizedChar) {\n return index;\n }\n }\n\n return -1;\n}\n\nfunction setMenuitemFocus(e: KeyboardEvent, menuId: string): void {\n const currentItem = e.target;\n if (!(currentItem instanceof HTMLElement)) {\n throw new Error(\"[Hebuim UI|Menu] Only HTMLElement events are supported\");\n }\n\n const menuitems = getFocusableMenuitems(menuId);\n const currentIndex = menuitems.indexOf(currentItem);\n const char = e.key.slice(0, 1);\n const nextIndex = findFocusItemIndex(menuitems, currentIndex, char);\n if (nextIndex === -1) return;\n const nextElement = menuitems[nextIndex];\n\n e.preventDefault();\n nextElement?.focus();\n}\n\nfunction hideMenu(menuId: string): void {\n const menu = getMenu(menuId);\n menu.hidePopover();\n}\n\nexport const menuControl = {\n getTriggerAttributes,\n getContentAttributes,\n getItemAttributes,\n handleMenuTriggerKeydown,\n handleMenuitemKeydown,\n handleMenuitemActivation,\n moveMenuitemFocus,\n setMenuitemFocus,\n hideMenu,\n} as const;\n"],"mappings":";;;AAUA,MAAM,eAAmD;CACvD,YAAY,cAAc,iBAAiB,eAAe,IAAI,eAAe;CAC7E,cAAc,cAAc,iBAAiB,eAAe,KAAK;CACjE,cAAsB;CACtB,QAAQ,GAAG,gBAAgB,cAAc;AAC3C;AAEA,MAAM,2BAAW,IAAI,IAAI;CAAC;CAAW;CAAa;CAAS;AAAG,CAAC;AAC/D,MAAM,iBAAiB,OAAO,KAAK,YAAY;AAC/C,MAAM,qCAAqB,IAAI,IAAI,CAAC,SAAS,GAAG,CAAC;AAEjD,MAAM,yBAAyB;AAC/B,MAAM,6BAA6B;AACnC,MAAM,8BAA8B;AAEpC,SAAS,UAAU,QAAwB;CACzC,OAAO,GAAG,OAAO;AACnB;AAOA,SAAS,gBAAgB,QAAgB,UAAoC;CAC3E,IAAI,UACF,OAAO;GACJ,yBAAyB,GAAG,OAAO;GACnC,6BAA6B;CAChC;MAEA,OAAO,GACJ,yBAAyB,GAAG,OAAO,OACtC;AAEJ;AAYA,SAAS,qBACP,OACA,SACuB;CACvB,OAAO;EACL,IAAI,UAAU,MAAM,MAAM;EAC1B,GAAG,eAAe,qBAChB,EAAE,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cAC3B,MAAM,IAAI,MAAM,wDAAwD;CAG1E,MAAM,YAAY,sBAAsB,MAAM;CAG9C,MAAM,YAAY,mBAAmB,WAFhB,UAAU,QAAQ,WAEoB,GAD9C,EAAE,IAAI,MAAM,GAAG,CACqC,CAAC;CAClE,IAAI,cAAc,IAAI;CACtB,MAAM,cAAc,UAAU;CAE9B,EAAE,eAAe;CACjB,aAAa,MAAM;AACrB;AAEA,SAAS,SAAS,QAAsB;CAEtC,QADqB,MAClB,CAAC,CAAC,YAAY;AACnB;AAEA,MAAa,cAAc;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
|
|
1
|
+
{"version":3,"file":"menu-control.js","names":[],"sources":["../../../src/logics/menu-control/menu-control.ts"],"sourcesContent":["import { toStrbool } from \"../bool\";\nimport { popoverControl } from \"../popover-control\";\n\nexport interface MenuState {\n menuId: string;\n}\n\nexport type MenuItemActivation = \"managed\" | \"native\";\n\ntype indexMap = (currentIndex: number, itemsLength: number) => number;\nconst nextIndexMap: Readonly<Record<string, indexMap>> = {\n \"ArrowUp\": (currentIndex, itemsLength) => (currentIndex - 1 + itemsLength) % itemsLength,\n \"ArrowDown\": (currentIndex, itemsLength) => (currentIndex + 1) % itemsLength,\n \"Home\": (): number => 0,\n \"End\": (_, itemsLength) => itemsLength - 1,\n} as const;\n\nconst openKeys: ReadonlySet<string> = new Set([\"ArrowUp\", \"ArrowDown\", \"Enter\", \" \"]);\nconst itemMotionKeys: readonly string[] = Object.keys(nextIndexMap);\nconst itemActivationKeys: ReadonlySet<string> = new Set([\"Enter\", \" \"]);\n\nconst menuitemDatasetItemKey = \"data-hui-menuitem\";\nconst menuitemDatasetFocusKeyKey = \"data-hui-focus-key\";\nconst menuitemDatasetFocusKeyName = \"huiFocusKey\";\n\nfunction triggerId(menuId: string): string {\n return `${menuId}-trigger`;\n}\n\ninterface MenuitemDataset {\n [menuitemDatasetItemKey]: string;\n [menuitemDatasetFocusKeyKey]?: string;\n}\n\nfunction menuitemDataset(menuId: string, focusKey?: string): MenuitemDataset {\n if (focusKey) {\n return {\n [menuitemDatasetItemKey]: `${menuId}-item`,\n [menuitemDatasetFocusKeyKey]: focusKey,\n };\n } else {\n return {\n [menuitemDatasetItemKey]: `${menuId}-item`,\n };\n }\n}\n\nexport interface MenuTriggerAttributeOptions {\n isButtonElement: boolean;\n}\n\nexport interface MenuTriggerAttributes {\n id: string;\n popovertarget: string;\n type: \"button\" | undefined;\n}\n\nfunction getTriggerAttributes(\n state: Readonly<MenuState>,\n options: Readonly<MenuTriggerAttributeOptions>,\n): MenuTriggerAttributes {\n return {\n id: triggerId(state.menuId),\n ...popoverControl.getTriggerAttributes(\n { popoverId: state.menuId },\n options,\n ),\n };\n}\n\nexport interface MenuContentAttributeOptions {\n ariaLabel?: string | undefined;\n ariaLabelledBy?: string | undefined;\n}\n\nexport interface MenuContentAttributes {\n role: \"menu\";\n id: string;\n popover: \"auto\";\n \"aria-label\": string | undefined;\n \"aria-labelledby\": string | undefined;\n}\n\nfunction getContentAttributes(\n state: Readonly<MenuState>,\n options: Readonly<MenuContentAttributeOptions>,\n): MenuContentAttributes {\n return {\n role: \"menu\",\n ...popoverControl.getContentAttributes({ popoverId: state.menuId }),\n \"aria-label\": options.ariaLabel,\n \"aria-labelledby\": options.ariaLabelledBy\n ?? (!options.ariaLabel ? triggerId(state.menuId) : undefined),\n };\n}\n\nexport interface MenuItemAttributeOptions {\n focusKey?: string | undefined;\n disabled?: boolean | undefined;\n}\n\nexport interface MenuItemAttributes {\n role: \"menuitem\";\n tabindex: -1;\n \"aria-disabled\": \"true\" | \"false\" | undefined;\n \"data-hui-menuitem\": string;\n \"data-hui-focus-key\"?: string | undefined;\n}\n\nfunction getItemAttributes(\n state: Readonly<MenuState>,\n options: Readonly<MenuItemAttributeOptions>,\n): MenuItemAttributes {\n return {\n role: \"menuitem\",\n tabindex: -1,\n \"aria-disabled\": options.disabled === undefined ? undefined : toStrbool(options.disabled),\n ...menuitemDataset(state.menuId, options.focusKey),\n };\n}\n\nfunction getMenu(menuId: string): HTMLElement {\n const menu = document.getElementById(menuId);\n if (!(menu instanceof HTMLElement)) {\n throw new Error(\"[Hebium UI|Menu] Menu element is not found\");\n }\n return menu;\n}\n\nfunction getFocusableMenuitems(menuId: string): HTMLElement[] {\n const itemDataset = menuitemDataset(menuId);\n const menuitemList = getMenu(menuId).querySelectorAll(\n `[${menuitemDatasetItemKey}=\"${itemDataset[menuitemDatasetItemKey]}\"]`,\n );\n return Array.from(menuitemList)\n .filter((e) => e instanceof HTMLElement);\n}\n\nfunction isCharKey(key: string): boolean {\n return key.length === 1 && /^\\S$/.test(key);\n}\n\nfunction handleMenuTriggerKeydown(e: KeyboardEvent, menuId: string): void {\n if (!openKeys.has(e.key)) return;\n const trigger = e.target;\n if (!(trigger instanceof HTMLElement)) {\n throw new Error(\"[Hebuim UI|Menu] Only HTMLElement events are supported\");\n }\n const menu = getMenu(menuId);\n\n e.preventDefault();\n menu.showPopover({ source: trigger });\n if (e.key === \"ArrowUp\") {\n const menuitems = getFocusableMenuitems(menuId);\n menuitems.at(-1)?.focus();\n } else {\n const menuitems = getFocusableMenuitems(menuId);\n menuitems.at(0)?.focus();\n }\n}\n\ntype ItemAction = \"none\" | \"action\" | \"focus-move\" | \"focus-set\" | \"focus-out\";\nfunction handleMenuitemKeydown(e: KeyboardEvent, activation: MenuItemActivation): ItemAction {\n if (itemActivationKeys.has(e.key)) return activation === \"managed\" ? \"action\" : \"none\";\n if (itemMotionKeys.includes(e.key)) return \"focus-move\";\n if (e.key === \"Tab\") return \"focus-out\";\n if (isCharKey(e.key)) return \"focus-set\";\n return \"none\";\n}\n\nexport interface MenuItemActivationOptions {\n activation: MenuItemActivation;\n disabled: boolean;\n}\n\nfunction handleMenuitemActivation(\n e: Event,\n menuId: string,\n options: Readonly<MenuItemActivationOptions>,\n onActivate?: (() => void) | undefined,\n): void {\n if (e.defaultPrevented) return;\n if (options.activation === \"managed\") e.preventDefault();\n if (options.disabled) return;\n onActivate?.();\n hideMenu(menuId);\n}\n\nfunction moveMenuitemFocus(e: KeyboardEvent, menuId: string): void {\n const currentItem = e.target;\n if (!(currentItem instanceof HTMLElement)) {\n throw new Error(\"[Hebuim UI|Menu] Only HTMLElement events are supported\");\n }\n\n const menuitems = getFocusableMenuitems(menuId);\n const currentIndex = menuitems.indexOf(currentItem);\n\n const map = nextIndexMap[e.key];\n if (typeof map === \"undefined\") {\n throw new Error(\"[Hebuim UI|Menu] Unexpected event key: \" + e.key);\n }\n const nextIndex = map(currentIndex, menuitems.length);\n const nextElement = menuitems[nextIndex];\n\n e.preventDefault();\n nextElement?.focus();\n}\n\nfunction findFocusItemIndex(\n menuitems: readonly HTMLElement[],\n currentIndex: number,\n char: string,\n): number {\n const normalizedChar = char.toLowerCase();\n\n for (let offset = 1; offset <= menuitems.length; offset++) {\n const index = (currentIndex + offset) % menuitems.length;\n const item = menuitems[index];\n\n if (item?.dataset[menuitemDatasetFocusKeyName]?.toLowerCase() === normalizedChar) {\n return index;\n }\n }\n\n return -1;\n}\n\nfunction setMenuitemFocus(e: KeyboardEvent, menuId: string): void {\n const currentItem = e.target;\n if (!(currentItem instanceof HTMLElement)) {\n throw new Error(\"[Hebuim UI|Menu] Only HTMLElement events are supported\");\n }\n\n const menuitems = getFocusableMenuitems(menuId);\n const currentIndex = menuitems.indexOf(currentItem);\n const char = e.key.slice(0, 1);\n const nextIndex = findFocusItemIndex(menuitems, currentIndex, char);\n if (nextIndex === -1) return;\n const nextElement = menuitems[nextIndex];\n\n e.preventDefault();\n nextElement?.focus();\n}\n\nfunction hideMenu(menuId: string): void {\n const menu = getMenu(menuId);\n menu.hidePopover();\n}\n\nexport const menuControl = {\n getTriggerAttributes,\n getContentAttributes,\n getItemAttributes,\n handleMenuTriggerKeydown,\n handleMenuitemKeydown,\n handleMenuitemActivation,\n moveMenuitemFocus,\n setMenuitemFocus,\n hideMenu,\n} as const;\n"],"mappings":";;;AAUA,MAAM,eAAmD;CACvD,YAAY,c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;CACtB,IAAI,EAAE,uBAAuB,cAC3B,MAAM,IAAI,MAAM,wDAAwD;CAG1E,MAAM,YAAY,sBAAsB,MAAM;CAC9C,MAAM,eAAe,UAAU,QAAQ,WAAW;CAElD,MAAM,MAAM,aAAa,EAAE;CAC3B,IAAI,OAAO,QAAQ,aACjB,MAAM,IAAI,MAAM,4CAA4C,EAAE,GAAG;CAGnE,MAAM,cAAc,UADF,IAAI,cAAc,UAAU,MACR;CAEtC,EAAE,eAAe;CACjB,aAAa,MAAM;AACrB;AAEA,SAAS,mBACP,WACA,cACA,MACQ;CACR,MAAM,iBAAiB,KAAK,YAAY;CAExC,KAAK,IAAI,SAAS,GAAG,UAAU,UAAU,QAAQ,UAAU;EACzD,MAAM,SAAS,eAAe,UAAU,UAAU;EAGlD,IAFa,UAAU,MAEf,EAAE,QAAQ,4BAA4B,EAAE,YAAY,MAAM,gBAChE,OAAO;CAEX;CAEA,OAAO;AACT;AAEA,SAAS,iBAAiB,GAAkB,QAAsB;CAChE,MAAM,cAAc,EAAE;CACtB,IAAI,EAAE,uBAAuB,cAC3B,MAAM,IAAI,MAAM,wDAAwD;CAG1E,MAAM,YAAY,sBAAsB,MAAM;CAG9C,MAAM,YAAY,mBAAmB,WAFhB,UAAU,QAAQ,WAEoB,GAD9C,EAAE,IAAI,MAAM,GAAG,CACqC,CAAC;CAClE,IAAI,cAAc,IAAI;CACtB,MAAM,cAAc,UAAU;CAE9B,EAAE,eAAe;CACjB,aAAa,MAAM;AACrB;AAEA,SAAS,SAAS,QAAsB;CACzB,QAAQ,MAClB,CAAC,CAAC,YAAY;AACnB;AAEA,MAAa,cAAc;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
type ReadonlySlotStyles<S extends string, P extends object> = Partial<Readonly<Record<S, P | undefined>>>;
|
|
2
2
|
type SlotStyles<S extends string, P extends object> = Partial<Record<S, P | undefined>>;
|
|
3
3
|
/** Merge styles to every slot. **/
|
|
4
|
-
export declare function msAll<S extends string, P extends object>(defaultStyels:
|
|
5
|
-
|
|
6
|
-
export {};
|
|
7
|
-
//# sourceMappingURL=ms-all.d.ts.map
|
|
4
|
+
export declare function msAll<S extends string, P extends object>(defaultStyels: ReadonlySlotStyles<S, P>, overrides: ReadonlySlotStyles<S, P>): SlotStyles<S, P>;
|
|
5
|
+
export {};
|
package/dist/logics/ms/ms-all.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/logics/ms/ms-all.ts
|
|
2
2
|
/** Merge styles to every slot. **/
|
|
3
3
|
function msAll(defaultStyels, overrides) {
|
|
4
4
|
const keys = /* @__PURE__ */ new Set([...Object.keys(defaultStyels), ...Object.keys(overrides)]);
|
|
@@ -13,7 +13,6 @@ function msAll(defaultStyels, overrides) {
|
|
|
13
13
|
});
|
|
14
14
|
return output;
|
|
15
15
|
}
|
|
16
|
-
//#endregion
|
|
17
16
|
export { msAll };
|
|
18
17
|
|
|
19
18
|
//# sourceMappingURL=ms-all.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ms-all.js","names":[],"sources":["../../../src/logics/ms/ms-all.ts"],"sourcesContent":["type SlotStyles<S extends string, P extends object> = Partial<Record<S, P | undefined>>;\n\n/** Merge styles to every slot. **/\nexport function msAll<S extends string, P extends object>(\n defaultStyels:
|
|
1
|
+
{"version":3,"file":"ms-all.js","names":[],"sources":["../../../src/logics/ms/ms-all.ts"],"sourcesContent":["type ReadonlySlotStyles<S extends string, P extends object> = Partial<Readonly<Record<S, P | undefined>>>;\ntype SlotStyles<S extends string, P extends object> = Partial<Record<S, P | undefined>>;\n\n/** Merge styles to every slot. **/\nexport function msAll<S extends string, P extends object>(\n defaultStyels: ReadonlySlotStyles<S, P>,\n overrides: ReadonlySlotStyles<S, P>,\n): SlotStyles<S, P> {\n const keys = new Set([...Object.keys(defaultStyels), ...Object.keys(overrides)]);\n const output: SlotStyles<S, P> = {};\n keys.forEach((k) => {\n const defaultValue = defaultStyels[k as S];\n const overrideValue = overrides[k as S];\n output[k as S] = { ...defaultValue, ...overrideValue };\n });\n return output;\n}\n"],"mappings":";;AAIA,SAAgB,MACd,eACA,WACkB;CAClB,MAAM,uBAAO,IAAI,IAAI,CAAC,GAAG,OAAO,KAAK,aAAa,GAAG,GAAG,OAAO,KAAK,SAAS,CAAC,CAAC;CAC/E,MAAM,SAA2B,CAAC;CAClC,KAAK,SAAS,MAAM;EAClB,MAAM,eAAe,cAAc;EACnC,MAAM,gBAAgB,UAAU;EAChC,OAAO,KAAU;GAAE,GAAG;GAAc,GAAG;EAAc;CACvD,CAAC;CACD,OAAO;AACT"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ComboboxKeyEvent, comboboxControl } from "../combobox-control/combobox-control.js";
|
|
2
|
+
import { ComboboxMode, ComboboxSelectOption } from "../combobox-control/combobox-filter.js";
|
|
3
|
+
import { createTagRemovalFocus, focusLastTag, getTagRemovalFocusValue, getTagRemoveButtonAttributes } from "./multi-combobox-focus.js";
|
|
4
|
+
export interface MultiComboboxState {
|
|
5
|
+
mode: ComboboxMode;
|
|
6
|
+
value: readonly string[];
|
|
7
|
+
query: string;
|
|
8
|
+
activeValue: string | null;
|
|
9
|
+
disabled: boolean;
|
|
10
|
+
readOnly: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface MultiComboboxItemState {
|
|
13
|
+
selected: boolean;
|
|
14
|
+
active: boolean;
|
|
15
|
+
}
|
|
16
|
+
declare function getTagLabel(mode: ComboboxMode, value: string, option: Readonly<ComboboxSelectOption> | undefined): string;
|
|
17
|
+
declare function toggle(state: Readonly<MultiComboboxState>, option: Readonly<ComboboxSelectOption>): string[] | null;
|
|
18
|
+
declare function remove(state: Readonly<MultiComboboxState>, value: string): string[] | null;
|
|
19
|
+
declare function addText(state: Readonly<MultiComboboxState>): string[] | null;
|
|
20
|
+
interface MultiComboboxValidationState extends Pick<MultiComboboxState, "value" | "disabled" | "readOnly"> {
|
|
21
|
+
required: boolean;
|
|
22
|
+
requiredMessage?: string | undefined;
|
|
23
|
+
}
|
|
24
|
+
declare function getValidationMessage(state: Readonly<MultiComboboxValidationState>): string;
|
|
25
|
+
export interface MultiComboboxFormValueProps {
|
|
26
|
+
name: string;
|
|
27
|
+
value: readonly string[];
|
|
28
|
+
form: string | undefined;
|
|
29
|
+
}
|
|
30
|
+
interface MultiComboboxFormValueOptions extends Omit<MultiComboboxFormValueProps, "name"> {
|
|
31
|
+
name: string | undefined;
|
|
32
|
+
}
|
|
33
|
+
declare function getFormValueProps({ name, value, form }: Readonly<MultiComboboxFormValueOptions>): MultiComboboxFormValueProps | null;
|
|
34
|
+
export type MultiComboboxKeyAction = "none" | "next" | "previous" | "commit" | "blocked" | "submit" | "add" | "focus-tag";
|
|
35
|
+
interface MultiComboboxKeyState extends MultiComboboxState {
|
|
36
|
+
opened: boolean;
|
|
37
|
+
}
|
|
38
|
+
declare function getKeyAction(event: Readonly<ComboboxKeyEvent>, state: Readonly<MultiComboboxKeyState>, activeOption: Readonly<ComboboxSelectOption> | undefined): MultiComboboxKeyAction;
|
|
39
|
+
declare function getListAttributes(listId: string, inputId: string, state: Pick<MultiComboboxState, "disabled" | "readOnly">): ReturnType<typeof comboboxControl.getListAttributes> & {
|
|
40
|
+
"aria-multiselectable": true;
|
|
41
|
+
};
|
|
42
|
+
declare function getItemAttributes(id: string, { selected, active }: Readonly<MultiComboboxItemState>, disabled: boolean): ReturnType<typeof comboboxControl.getItemAttributes>;
|
|
43
|
+
export declare const multiComboboxControl: {
|
|
44
|
+
readonly getTagLabel: typeof getTagLabel;
|
|
45
|
+
readonly toggle: typeof toggle;
|
|
46
|
+
readonly remove: typeof remove;
|
|
47
|
+
readonly addText: typeof addText;
|
|
48
|
+
readonly getValidationMessage: typeof getValidationMessage;
|
|
49
|
+
readonly getFormValueProps: typeof getFormValueProps;
|
|
50
|
+
readonly getKeyAction: typeof getKeyAction;
|
|
51
|
+
readonly getListAttributes: typeof getListAttributes;
|
|
52
|
+
readonly getItemAttributes: typeof getItemAttributes;
|
|
53
|
+
readonly getTagRemoveButtonAttributes: typeof getTagRemoveButtonAttributes;
|
|
54
|
+
readonly getTagRemovalFocusValue: typeof getTagRemovalFocusValue;
|
|
55
|
+
readonly createTagRemovalFocus: typeof createTagRemovalFocus;
|
|
56
|
+
readonly focusLastTag: typeof focusLastTag;
|
|
57
|
+
};
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { comboboxControl } from "../combobox-control/combobox-control.js";
|
|
2
|
+
import { getComboboxOptionText } from "../combobox-control/combobox-filter.js";
|
|
3
|
+
import { createTagRemovalFocus, focusLastTag, getTagRemovalFocusValue, getTagRemoveButtonAttributes } from "./multi-combobox-focus.js";
|
|
4
|
+
// src/logics/multi-combobox-control/multi-combobox-control.ts
|
|
5
|
+
function getTagLabel(mode, value, option) {
|
|
6
|
+
return option ? getComboboxOptionText(mode, option) : value;
|
|
7
|
+
}
|
|
8
|
+
function toggle(state, option) {
|
|
9
|
+
if (!comboboxControl.canEdit(state) || option.disabled) return null;
|
|
10
|
+
return state.value.includes(option.value) ? state.value.filter((value) => value !== option.value) : [...state.value, option.value];
|
|
11
|
+
}
|
|
12
|
+
function remove(state, value) {
|
|
13
|
+
if (!comboboxControl.canEdit(state) || !state.value.includes(value)) return null;
|
|
14
|
+
return state.value.filter((selected) => selected !== value);
|
|
15
|
+
}
|
|
16
|
+
function addText(state) {
|
|
17
|
+
if (!comboboxControl.canEdit(state) || state.mode !== "text") return null;
|
|
18
|
+
const value = state.query.trim();
|
|
19
|
+
if (value === "" || state.value.includes(value)) return null;
|
|
20
|
+
return [...state.value, value];
|
|
21
|
+
}
|
|
22
|
+
function getValidationMessage(state) {
|
|
23
|
+
if (!state.required || !comboboxControl.canEdit(state) || state.value.length > 0) return "";
|
|
24
|
+
return state.requiredMessage || "Please fill out this field.";
|
|
25
|
+
}
|
|
26
|
+
function getFormValueProps({ name, value, form }) {
|
|
27
|
+
return name !== void 0 ? {
|
|
28
|
+
name,
|
|
29
|
+
value,
|
|
30
|
+
form
|
|
31
|
+
} : null;
|
|
32
|
+
}
|
|
33
|
+
function getKeyAction(event, state, activeOption) {
|
|
34
|
+
if (!comboboxControl.canEdit(state)) return "none";
|
|
35
|
+
if (event.isComposing || event.keyCode === 229) return "none";
|
|
36
|
+
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return "none";
|
|
37
|
+
if (event.key === "Backspace") {
|
|
38
|
+
if (state.query !== "") return "none";
|
|
39
|
+
if (state.value.length === 0) return "none";
|
|
40
|
+
return "focus-tag";
|
|
41
|
+
}
|
|
42
|
+
const action = comboboxControl.getKeyAction(event, state, activeOption);
|
|
43
|
+
if (action !== "submit") return action;
|
|
44
|
+
if (state.mode === "select" || state.query.trim() === "") return "submit";
|
|
45
|
+
else return "add";
|
|
46
|
+
}
|
|
47
|
+
function getListAttributes(listId, inputId, state) {
|
|
48
|
+
return {
|
|
49
|
+
...comboboxControl.getListAttributes(listId, inputId, state),
|
|
50
|
+
"aria-multiselectable": true
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function getItemAttributes(id, { selected, active }, disabled) {
|
|
54
|
+
return {
|
|
55
|
+
...comboboxControl.getItemAttributes(id, active, disabled),
|
|
56
|
+
"aria-selected": selected
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const multiComboboxControl = {
|
|
60
|
+
getTagLabel,
|
|
61
|
+
toggle,
|
|
62
|
+
remove,
|
|
63
|
+
addText,
|
|
64
|
+
getValidationMessage,
|
|
65
|
+
getFormValueProps,
|
|
66
|
+
getKeyAction,
|
|
67
|
+
getListAttributes,
|
|
68
|
+
getItemAttributes,
|
|
69
|
+
getTagRemoveButtonAttributes,
|
|
70
|
+
getTagRemovalFocusValue,
|
|
71
|
+
createTagRemovalFocus,
|
|
72
|
+
focusLastTag
|
|
73
|
+
};
|
|
74
|
+
export { multiComboboxControl };
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=multi-combobox-control.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-combobox-control.js","names":[],"sources":["../../../src/logics/multi-combobox-control/multi-combobox-control.ts"],"sourcesContent":["import {\n comboboxControl,\n type ComboboxKeyEvent,\n type ComboboxMode,\n type ComboboxSelectOption,\n getComboboxOptionText,\n} from \"../combobox-control\";\nimport {\n createTagRemovalFocus,\n focusLastTag,\n getTagRemovalFocusValue,\n getTagRemoveButtonAttributes,\n} from \"./multi-combobox-focus\";\n\nexport interface MultiComboboxState {\n mode: ComboboxMode;\n value: readonly string[];\n query: string;\n activeValue: string | null;\n disabled: boolean;\n readOnly: boolean;\n}\n\nexport interface MultiComboboxItemState {\n selected: boolean;\n active: boolean;\n}\n\nfunction getTagLabel(\n mode: ComboboxMode,\n value: string,\n option: Readonly<ComboboxSelectOption> | undefined,\n): string {\n return option ? getComboboxOptionText(mode, option) : value;\n}\n\nfunction toggle(\n state: Readonly<MultiComboboxState>,\n option: Readonly<ComboboxSelectOption>,\n): string[] | null {\n if (!comboboxControl.canEdit(state) || option.disabled) return null;\n return state.value.includes(option.value)\n ? state.value.filter((value) => value !== option.value)\n : [...state.value, option.value];\n}\n\nfunction remove(\n state: Readonly<MultiComboboxState>,\n value: string,\n): string[] | null {\n if (!comboboxControl.canEdit(state) || !state.value.includes(value)) return null;\n return state.value.filter((selected) => selected !== value);\n}\n\nfunction addText(state: Readonly<MultiComboboxState>): string[] | null {\n if (!comboboxControl.canEdit(state) || state.mode !== \"text\") return null;\n const value = state.query.trim();\n if (value === \"\" || state.value.includes(value)) return null;\n return [...state.value, value];\n}\n\ninterface MultiComboboxValidationState extends Pick<MultiComboboxState, \"value\" | \"disabled\" | \"readOnly\"> {\n required: boolean;\n requiredMessage?: string | undefined;\n}\n\nfunction getValidationMessage(state: Readonly<MultiComboboxValidationState>): string {\n if (!state.required || !comboboxControl.canEdit(state) || state.value.length > 0) return \"\";\n return state.requiredMessage || \"Please fill out this field.\";\n}\n\nexport interface MultiComboboxFormValueProps {\n name: string;\n value: readonly string[];\n form: string | undefined;\n}\n\ninterface MultiComboboxFormValueOptions extends Omit<MultiComboboxFormValueProps, \"name\"> {\n name: string | undefined;\n}\n\nfunction getFormValueProps(\n { name, value, form }: Readonly<MultiComboboxFormValueOptions>,\n): MultiComboboxFormValueProps | null {\n return name !== undefined\n ? { name, value, form }\n : null;\n}\n\nexport type MultiComboboxKeyAction =\n | \"none\"\n | \"next\"\n | \"previous\"\n | \"commit\"\n | \"blocked\"\n | \"submit\"\n | \"add\"\n | \"focus-tag\";\n\ninterface MultiComboboxKeyState extends MultiComboboxState {\n opened: boolean;\n}\n\nfunction getKeyAction(\n event: Readonly<ComboboxKeyEvent>,\n state: Readonly<MultiComboboxKeyState>,\n activeOption: Readonly<ComboboxSelectOption> | undefined,\n): MultiComboboxKeyAction {\n if (!comboboxControl.canEdit(state)) return \"none\";\n if (event.isComposing || event.keyCode === 229) return \"none\";\n if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return \"none\";\n\n if (event.key === \"Backspace\") {\n if (state.query !== \"\") return \"none\";\n if (state.value.length === 0) return \"none\";\n return \"focus-tag\";\n }\n\n const action = comboboxControl.getKeyAction(event, state, activeOption);\n if (action !== \"submit\") return action;\n\n if (state.mode === \"select\" || state.query.trim() === \"\") {\n return \"submit\";\n } else {\n return \"add\";\n }\n}\n\nfunction getListAttributes(\n listId: string,\n inputId: string,\n state: Pick<MultiComboboxState, \"disabled\" | \"readOnly\">,\n): ReturnType<typeof comboboxControl.getListAttributes> & { \"aria-multiselectable\": true } {\n return {\n ...comboboxControl.getListAttributes(listId, inputId, state),\n \"aria-multiselectable\": true,\n };\n}\n\nfunction getItemAttributes(\n id: string,\n { selected, active }: Readonly<MultiComboboxItemState>,\n disabled: boolean,\n): ReturnType<typeof comboboxControl.getItemAttributes> {\n return {\n ...comboboxControl.getItemAttributes(id, active, disabled),\n \"aria-selected\": selected,\n };\n}\n\nexport const multiComboboxControl = {\n getTagLabel,\n toggle,\n remove,\n addText,\n getValidationMessage,\n getFormValueProps,\n getKeyAction,\n getListAttributes,\n getItemAttributes,\n getTagRemoveButtonAttributes,\n getTagRemovalFocusValue,\n createTagRemovalFocus,\n focusLastTag,\n} as const;\n"],"mappings":";;;;AA4BA,SAAS,YACP,MACA,OACA,QACQ;CACR,OAAO,SAAS,sBAAsB,MAAM,MAAM,IAAI;AACxD;AAEA,SAAS,OACP,OACA,QACiB;CACjB,IAAI,CAAC,gBAAgB,QAAQ,KAAK,KAAK,OAAO,UAAU,OAAO;CAC/D,OAAO,MAAM,MAAM,SAAS,OAAO,KAAK,IACpC,MAAM,MAAM,QAAQ,UAAU,UAAU,OAAO,KAAK,IACpD,CAAC,GAAG,MAAM,OAAO,OAAO,KAAK;AACnC;AAEA,SAAS,OACP,OACA,OACiB;CACjB,IAAI,CAAC,gBAAgB,QAAQ,KAAK,KAAK,CAAC,MAAM,MAAM,SAAS,KAAK,GAAG,OAAO;CAC5E,OAAO,MAAM,MAAM,QAAQ,aAAa,aAAa,KAAK;AAC5D;AAEA,SAAS,QAAQ,OAAsD;CACrE,IAAI,CAAC,gBAAgB,QAAQ,KAAK,KAAK,MAAM,SAAS,QAAQ,OAAO;CACrE,MAAM,QAAQ,MAAM,MAAM,KAAK;CAC/B,IAAI,UAAU,MAAM,MAAM,MAAM,SAAS,KAAK,GAAG,OAAO;CACxD,OAAO,CAAC,GAAG,MAAM,OAAO,KAAK;AAC/B;AAOA,SAAS,qBAAqB,OAAuD;CACnF,IAAI,CAAC,MAAM,YAAY,CAAC,gBAAgB,QAAQ,KAAK,KAAK,MAAM,MAAM,SAAS,GAAG,OAAO;CACzF,OAAO,MAAM,mBAAmB;AAClC;AAYA,SAAS,kBACP,EAAE,MAAM,OAAO,QACqB;CACpC,OAAO,SAAS,KAAA,IACZ;EAAE;EAAM;EAAO;CAAK,IACpB;AACN;AAgBA,SAAS,aACP,OACA,OACA,cACwB;CACxB,IAAI,CAAC,gBAAgB,QAAQ,KAAK,GAAG,OAAO;CAC5C,IAAI,MAAM,eAAe,MAAM,YAAY,KAAK,OAAO;CACvD,IAAI,MAAM,UAAU,MAAM,WAAW,MAAM,WAAW,MAAM,UAAU,OAAO;CAE7E,IAAI,MAAM,QAAQ,aAAa;EAC7B,IAAI,MAAM,UAAU,IAAI,OAAO;EAC/B,IAAI,MAAM,MAAM,WAAW,GAAG,OAAO;EACrC,OAAO;CACT;CAEA,MAAM,SAAS,gBAAgB,aAAa,OAAO,OAAO,YAAY;CACtE,IAAI,WAAW,UAAU,OAAO;CAEhC,IAAI,MAAM,SAAS,YAAY,MAAM,MAAM,KAAK,MAAM,IACpD,OAAO;MAEP,OAAO;AAEX;AAEA,SAAS,kBACP,QACA,SACA,OACyF;CACzF,OAAO;EACL,GAAG,gBAAgB,kBAAkB,QAAQ,SAAS,KAAK;EAC3D,wBAAwB;CAC1B;AACF;AAEA,SAAS,kBACP,IACA,EAAE,UAAU,UACZ,UACsD;CACtD,OAAO;EACL,GAAG,gBAAgB,kBAAkB,IAAI,QAAQ,QAAQ;EACzD,iBAAiB;CACnB;AACF;AAEA,MAAa,uBAAuB;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface MultiComboboxTagRemoveButtonAttributes {
|
|
2
|
+
"data-hui-multi-combobox-remove": string;
|
|
3
|
+
}
|
|
4
|
+
export declare function getTagRemoveButtonAttributes(value: string): MultiComboboxTagRemoveButtonAttributes;
|
|
5
|
+
export declare function getTagRemovalFocusValue(previousValues: readonly string[], removedValue: string, focusableValues: readonly string[]): string | null;
|
|
6
|
+
interface MultiComboboxRemovalFocusOptions {
|
|
7
|
+
root: HTMLElement | null;
|
|
8
|
+
input: HTMLInputElement | null;
|
|
9
|
+
button: HTMLButtonElement;
|
|
10
|
+
value: readonly string[];
|
|
11
|
+
removedValue: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function createTagRemovalFocus({ root, input, button, value, removedValue }: MultiComboboxRemovalFocusOptions): (() => void) | undefined;
|
|
14
|
+
export declare function focusLastTag(root: HTMLElement | null, value: readonly string[]): void;
|
|
15
|
+
export {};
|