@oscarpalmer/oui 0.35.0 → 0.36.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/dist/css/combobox.css +1 -1
- package/dist/css/listbox.css +152 -0
- package/dist/js/combobox/constants.combobox.d.mts +2 -2
- package/dist/js/combobox/constants.combobox.mjs +40 -33
- package/dist/js/combobox/dom.combobox.d.mts +8 -91
- package/dist/js/combobox/dom.combobox.mjs +204 -2
- package/dist/js/combobox/event.combobox.d.mts +14 -8
- package/dist/js/combobox/event.combobox.mjs +2 -2
- package/dist/js/combobox/index.d.mts +1 -1
- package/dist/js/combobox/index.mjs +20 -18
- package/dist/js/combobox/misc.combobox.d.mts +2 -2
- package/dist/js/combobox/misc.combobox.mjs +2 -2
- package/dist/js/combobox/models.combobox.d.mts +44 -2
- package/dist/js/combobox/state.combobox.d.mts +9 -10
- package/dist/js/combobox/state.combobox.mjs +2 -2
- package/dist/js/constants.combobox-DmRAMC64.d.mts +26 -0
- package/dist/js/constants.listbox-DRsXUxd3.d.mts +14 -0
- package/dist/js/index-EfkUSals.d.mts +139 -0
- package/dist/js/index.d.mts +4 -2
- package/dist/js/index.mjs +4 -2
- package/dist/js/internal/attributable.mjs +4 -3
- package/dist/js/internal/listbox/listbox.constants.d.mts +11 -0
- package/dist/js/internal/listbox/listbox.constants.mjs +23 -0
- package/dist/js/internal/listbox/listbox.data.d.mts +20 -0
- package/dist/js/internal/listbox/listbox.data.mjs +2 -0
- package/dist/js/internal/listbox/listbox.dom.d.mts +66 -0
- package/dist/js/internal/listbox/listbox.dom.mjs +2 -0
- package/dist/js/internal/listbox/listbox.event.d.mts +5 -0
- package/dist/js/internal/listbox/listbox.event.mjs +63 -0
- package/dist/js/internal/listbox/listbox.form.d.mts +6 -0
- package/dist/js/internal/listbox/listbox.form.mjs +52 -0
- package/dist/js/internal/listbox/listbox.misc.d.mts +12 -0
- package/dist/js/internal/listbox/listbox.misc.mjs +2 -0
- package/dist/js/internal/listbox/listbox.model.d.mts +2 -0
- package/dist/js/internal/listbox/listbox.model.mjs +1 -0
- package/dist/js/internal/listbox/listbox.state.d.mts +7 -0
- package/dist/js/internal/listbox/listbox.state.mjs +40 -0
- package/dist/js/internal/misc.d.mts +6 -0
- package/dist/js/internal/misc.mjs +13 -0
- package/dist/js/l10n-Bn-7RcwR.d.mts +20 -0
- package/dist/js/l10n.d.mts +2 -20
- package/dist/js/listbox/constants.listbox.d.mts +2 -0
- package/dist/js/listbox/constants.listbox.mjs +40 -0
- package/dist/js/listbox/event.listbox.d.mts +8 -0
- package/dist/js/listbox/event.listbox.mjs +2 -0
- package/dist/js/listbox/index.d.mts +116 -0
- package/dist/js/listbox/index.mjs +189 -0
- package/dist/js/listbox/misc.listbox.d.mts +2 -0
- package/dist/js/listbox/misc.listbox.mjs +2 -0
- package/dist/js/listbox/state.listbox.d.mts +11 -0
- package/dist/js/listbox/state.listbox.mjs +2 -0
- package/dist/js/listbox.data-BWd0PCy7.mjs +424 -0
- package/dist/js/listbox.model-CRReGOmu.d.mts +125 -0
- package/dist/js/misc.listbox-BI-XsTOf.mjs +197 -0
- package/dist/js/misc.listbox-gnoJhrTr.d.mts +20 -0
- package/dist/js/sortable/sortable.embedded.mjs +4 -2
- package/dist/js/state.combobox-4xq0FPCF.mjs +365 -0
- package/package.json +7 -3
- package/src/css/combobox.scss +1 -1
- package/src/css/listbox.scss +149 -0
- package/src/js/combobox/constants.combobox.ts +46 -25
- package/src/js/combobox/dom.combobox.ts +36 -454
- package/src/js/combobox/event.combobox.ts +129 -218
- package/src/js/combobox/index.ts +37 -30
- package/src/js/combobox/misc.combobox.ts +30 -114
- package/src/js/combobox/models.combobox.ts +7 -47
- package/src/js/combobox/state.combobox.ts +126 -127
- package/src/js/index.ts +1 -0
- package/src/js/internal/listbox/listbox.constants.ts +25 -0
- package/src/js/{combobox/data.combobox.ts → internal/listbox/listbox.data.ts} +94 -43
- package/src/js/internal/listbox/listbox.dom.ts +445 -0
- package/src/js/internal/listbox/listbox.event.ts +129 -0
- package/src/js/{combobox/form.combobox.ts → internal/listbox/listbox.form.ts} +12 -13
- package/src/js/internal/listbox/listbox.misc.ts +135 -0
- package/src/js/internal/listbox/listbox.model.ts +169 -0
- package/src/js/internal/listbox/listbox.state.ts +82 -0
- package/src/js/internal/misc.ts +27 -0
- package/src/js/l10n.ts +8 -8
- package/src/js/listbox/constants.listbox.ts +61 -0
- package/src/js/listbox/event.listbox.ts +106 -0
- package/src/js/listbox/index.ts +302 -0
- package/src/js/listbox/misc.listbox.ts +70 -0
- package/src/js/listbox/state.listbox.ts +196 -0
- package/dist/js/combobox/data.combobox.d.mts +0 -18
- package/dist/js/combobox/data.combobox.mjs +0 -2
- package/dist/js/combobox/form.combobox.d.mts +0 -6
- package/dist/js/combobox/form.combobox.mjs +0 -2
- package/dist/js/constants.combobox-h_kyDegw.d.mts +0 -248
- package/dist/js/data.combobox-B8HMkDOh.mjs +0 -1030
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { LISTBOX_KEYS } from "./listbox.constants.mjs";
|
|
2
|
+
import { S as getListboxVisibleOptions } from "../../listbox.data-BWd0PCy7.mjs";
|
|
3
|
+
import { clamp } from "@oscarpalmer/atoms/number";
|
|
4
|
+
//#region src/js/internal/listbox/listbox.event.ts
|
|
5
|
+
function processListboxKeydown(event, state) {
|
|
6
|
+
const ignore = state.disabled || state.readonly;
|
|
7
|
+
const isSelect = state.type === "select";
|
|
8
|
+
let preventDefault = ignore;
|
|
9
|
+
switch (true) {
|
|
10
|
+
case event.key === " ":
|
|
11
|
+
if (!state.disabled) state.callbacks.keydown.onActivation?.(state);
|
|
12
|
+
break;
|
|
13
|
+
case event.key === "Enter":
|
|
14
|
+
preventDefault = state.callbacks.keydown.preventActivation?.(state) ?? true;
|
|
15
|
+
if (preventDefault) state.callbacks.keydown.onEnter?.(state);
|
|
16
|
+
else if (!ignore && state.type === "select") state.callbacks.keydown.onActivation?.(state);
|
|
17
|
+
else if (!ignore) state.internals.form?.requestSubmit();
|
|
18
|
+
break;
|
|
19
|
+
case event.key === "Escape":
|
|
20
|
+
preventDefault = false;
|
|
21
|
+
state.callbacks.keydown.onEscape?.(state);
|
|
22
|
+
break;
|
|
23
|
+
case !isSelect && LISTBOX_KEYS.selection.has(event.key):
|
|
24
|
+
if (!ignore) state.callbacks.keydown.onSelection?.(state);
|
|
25
|
+
break;
|
|
26
|
+
case LISTBOX_KEYS.navigation.has(event.key):
|
|
27
|
+
if (!state.disabled) onNavigation(event, state);
|
|
28
|
+
break;
|
|
29
|
+
default:
|
|
30
|
+
preventDefault = false;
|
|
31
|
+
if (event.key === "Tab") state.callbacks.keydown.onTab?.(state);
|
|
32
|
+
}
|
|
33
|
+
if (preventDefault) {
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
event.stopPropagation();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function onNavigation(event, state) {
|
|
39
|
+
const skip = state.callbacks.keydown.skipNavigation?.(state) ?? false;
|
|
40
|
+
const visible = getListboxVisibleOptions(state);
|
|
41
|
+
if (visible.length === 0) return;
|
|
42
|
+
let next;
|
|
43
|
+
if (skip || state.active == null) next = state.active ?? visible.at(event.key === "ArrowDown" ? 0 : -1);
|
|
44
|
+
else {
|
|
45
|
+
const current = visible.findIndex((option) => option.id === state.active?.id);
|
|
46
|
+
let index;
|
|
47
|
+
switch (event.key) {
|
|
48
|
+
case "ArrowDown":
|
|
49
|
+
case "ArrowUp":
|
|
50
|
+
index = clamp(current + (event.key === "ArrowDown" ? 1 : -1), 0, visible.length - 1, true);
|
|
51
|
+
break;
|
|
52
|
+
case "PageDown":
|
|
53
|
+
case "PageUp": index = clamp(current + (event.key === "PageDown" ? 10 : -10), 0, visible.length - 1);
|
|
54
|
+
}
|
|
55
|
+
if (index != null) next = visible[index];
|
|
56
|
+
}
|
|
57
|
+
let preview;
|
|
58
|
+
if (state.type === "autocomplete" && (state.autocomplete.both || state.autocomplete.inline)) preview = "set";
|
|
59
|
+
else preview = "none";
|
|
60
|
+
state.callbacks.keydown.onNavigation(preview, state, next ?? state.active ?? visible[0]);
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
export { processListboxKeydown };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { l as OuiListboxState } from "../../listbox.model-CRReGOmu.mjs";
|
|
2
|
+
//#region src/js/internal/listbox/listbox.form.d.ts
|
|
3
|
+
declare function updateListboxForm<State extends OuiListboxState>(state: State, values: string[], emit?: boolean): void;
|
|
4
|
+
declare function updateListboxValidity(state: OuiListboxState): void;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { updateListboxForm, updateListboxValidity };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { getLocalization, localize } from "../../l10n.mjs";
|
|
2
|
+
import { dispatch } from "@oscarpalmer/toretto/event";
|
|
3
|
+
//#region src/js/internal/listbox/listbox.form.ts
|
|
4
|
+
function updateListboxForm(state, values, emit) {
|
|
5
|
+
let value;
|
|
6
|
+
if (state.multiple) {
|
|
7
|
+
const { length } = values;
|
|
8
|
+
value = new FormData();
|
|
9
|
+
for (let index = 0; index < length; index += 1) value.append(state.name, values[index]);
|
|
10
|
+
} else value = values[0];
|
|
11
|
+
state.values.current = values;
|
|
12
|
+
state.internals.setFormValue(value, JSON.stringify(values));
|
|
13
|
+
state.callbacks.data.onForm(state);
|
|
14
|
+
updateListboxValidity(state);
|
|
15
|
+
if (emit ?? true) dispatch(state.host, "change");
|
|
16
|
+
}
|
|
17
|
+
function updateListboxValidity(state) {
|
|
18
|
+
if (state.autocomplete.none && !state.listbox) {
|
|
19
|
+
const valueMissing = state.required && state.filter.element.value.length === 0;
|
|
20
|
+
const localization = getLocalization(state.localizations.global, state.host, "invalid", state.localizations.component);
|
|
21
|
+
state.internals.setValidity({ valueMissing }, localize(localization, {}, []));
|
|
22
|
+
state.internals.checkValidity();
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
let data = {};
|
|
26
|
+
let error;
|
|
27
|
+
let key;
|
|
28
|
+
let parameters = [];
|
|
29
|
+
switch (true) {
|
|
30
|
+
case state.required && state.options.selected.length === 0:
|
|
31
|
+
error = "badInput";
|
|
32
|
+
key = "input";
|
|
33
|
+
break;
|
|
34
|
+
case state.multiple && typeof state.max === "number" && state.options.selected.length > state.max:
|
|
35
|
+
data = { amount: state.max };
|
|
36
|
+
error = "rangeOverflow";
|
|
37
|
+
key = "max";
|
|
38
|
+
parameters = [state.max];
|
|
39
|
+
break;
|
|
40
|
+
case state.multiple && typeof state.min === "number" && state.options.selected.length < state.min:
|
|
41
|
+
data = { amount: state.min };
|
|
42
|
+
error = "rangeUnderflow";
|
|
43
|
+
key = "min";
|
|
44
|
+
parameters = [state.min];
|
|
45
|
+
}
|
|
46
|
+
const localization = key == null ? void 0 : getLocalization(state.localizations.global, state.host, key, state.localizations.component);
|
|
47
|
+
const message = localization == null ? void 0 : localize(localization, data, parameters);
|
|
48
|
+
state.internals.setValidity(error == null ? {} : { [error]: true }, message);
|
|
49
|
+
state.internals.checkValidity();
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
export { updateListboxForm, updateListboxValidity };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { l as OuiListboxState } from "../../listbox.model-CRReGOmu.mjs";
|
|
2
|
+
//#region src/js/internal/listbox/listbox.misc.d.ts
|
|
3
|
+
declare function generateListboxIds(prefix: string, select: HTMLSelectElement): void;
|
|
4
|
+
declare function getListboxVisibleOptions(state: OuiListboxState): HTMLElement[];
|
|
5
|
+
declare function setListboxDisabled<State extends OuiListboxState>(state: State, value: boolean): void;
|
|
6
|
+
declare function setListboxFilter<State extends OuiListboxState>(state: State, value: unknown): void;
|
|
7
|
+
declare function setListboxLimit<State extends OuiListboxState>(type: 'max' | 'min', state: State, value?: unknown): void;
|
|
8
|
+
declare function setListboxMultiple(element: HTMLElement, value: boolean): void;
|
|
9
|
+
declare function setListboxReadonly<State extends OuiListboxState>(state: State, value: boolean): void;
|
|
10
|
+
declare function setListboxRequired<State extends OuiListboxState>(state: State, value: boolean): void;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { generateListboxIds, getListboxVisibleOptions, setListboxDisabled, setListboxFilter, setListboxLimit, setListboxMultiple, setListboxReadonly, setListboxRequired };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { C as setListboxDisabled, D as setListboxReadonly, E as setListboxMultiple, O as setListboxRequired, S as getListboxVisibleOptions, T as setListboxLimit, w as setListboxFilter, x as generateListboxIds } from "../../listbox.data-BWd0PCy7.mjs";
|
|
2
|
+
export { generateListboxIds, getListboxVisibleOptions, setListboxDisabled, setListboxFilter, setListboxLimit, setListboxMultiple, setListboxReadonly, setListboxRequired };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as OuiListboxGroup, c as OuiListboxPreview, d as OuiListboxType, i as OuiListboxCallbacks, l as OuiListboxState, n as OuiListboxAutoComplete, o as OuiListboxLocalizations, r as OuiListboxAutoCompleteType, s as OuiListboxOptions, t as OuiListboxAttributes, u as OuiListboxStates } from "../../listbox.model-CRReGOmu.mjs";
|
|
2
|
+
export { OuiListboxAttributes, OuiListboxAutoComplete, OuiListboxAutoCompleteType, OuiListboxCallbacks, OuiListboxGroup, OuiListboxLocalizations, OuiListboxOptions, OuiListboxPreview, OuiListboxState, OuiListboxStates, OuiListboxType };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { l as OuiListboxState, u as OuiListboxStates } from "../../listbox.model-CRReGOmu.mjs";
|
|
2
|
+
//#region src/js/internal/listbox/listbox.state.d.ts
|
|
3
|
+
declare function attachListbox<State extends OuiListboxState>(state: State, states: OuiListboxStates<State>, onAttach: (state: State) => void): void;
|
|
4
|
+
declare function detachListbox<State extends OuiListboxState>(state: State, states: OuiListboxStates<State>, onDetach: (state: State) => void): void;
|
|
5
|
+
declare function initializeListboxState<State extends OuiListboxState>(state: State, states: OuiListboxStates<State>, onAttach: (state: State) => void): State;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { attachListbox, detachListbox, initializeListboxState };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { updateListboxForm } from "./listbox.form.mjs";
|
|
2
|
+
import { C as setListboxDisabled, D as setListboxReadonly, E as setListboxMultiple, O as setListboxRequired, T as setListboxLimit, b as updateListboxValueLabel, i as filterListboxOptions, v as updateListboxMessage, y as updateListboxPreview } from "../../listbox.data-BWd0PCy7.mjs";
|
|
3
|
+
import { getAttribute } from "@oscarpalmer/toretto/attribute";
|
|
4
|
+
//#region src/js/internal/listbox/listbox.state.ts
|
|
5
|
+
function attachListbox(state, states, onAttach) {
|
|
6
|
+
const { filter, host, label } = state;
|
|
7
|
+
label.element.htmlFor = filter.element.id;
|
|
8
|
+
label.element.id = `${state.id}_label`;
|
|
9
|
+
onAttach(state);
|
|
10
|
+
states.map.set(host, state);
|
|
11
|
+
states.set.add(state);
|
|
12
|
+
}
|
|
13
|
+
function detachListbox(state, states, onDetach) {
|
|
14
|
+
const { host, label, select } = state;
|
|
15
|
+
const listeners = state.listeners.splice(0);
|
|
16
|
+
const { length } = listeners;
|
|
17
|
+
for (let index = 0; index < length; index += 1) listeners[index]();
|
|
18
|
+
label.element.htmlFor = select.id;
|
|
19
|
+
label.element.id = label.id;
|
|
20
|
+
onDetach(state);
|
|
21
|
+
states.map.delete(host);
|
|
22
|
+
states.set.delete(state);
|
|
23
|
+
}
|
|
24
|
+
function initializeListboxState(state, states, onAttach) {
|
|
25
|
+
attachListbox(state, states, onAttach);
|
|
26
|
+
setListboxDisabled(state, state.disabled);
|
|
27
|
+
setListboxLimit("max", state, getAttribute(state.host, "max"));
|
|
28
|
+
setListboxLimit("min", state, getAttribute(state.host, "min"));
|
|
29
|
+
setListboxMultiple(state.host, state.multiple);
|
|
30
|
+
setListboxReadonly(state, state.readonly);
|
|
31
|
+
setListboxRequired(state, state.required);
|
|
32
|
+
filterListboxOptions(state);
|
|
33
|
+
updateListboxForm(state, state.values.current, false);
|
|
34
|
+
updateListboxMessage(state);
|
|
35
|
+
updateListboxValueLabel(state);
|
|
36
|
+
if (state.options.selected.length > 0) updateListboxPreview("none", state, state.options.selected[0]);
|
|
37
|
+
return state;
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { attachListbox, detachListbox, initializeListboxState };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AnyAriaBooleanAttribute } from "@oscarpalmer/toretto/models";
|
|
2
|
+
//#region src/js/internal/misc.d.ts
|
|
3
|
+
declare function getAttributeValue<Value>(element: HTMLElement, attribute: string, possible: Set<Value>, defaultValue: Value): Value;
|
|
4
|
+
declare function getBooleanAriaValue(element: HTMLElement, attribute: AnyAriaBooleanAttribute): boolean;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { getAttributeValue, getBooleanAriaValue };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { getAria } from "@oscarpalmer/toretto/aria";
|
|
2
|
+
import { getAttribute } from "@oscarpalmer/toretto/attribute";
|
|
3
|
+
//#region src/js/internal/misc.ts
|
|
4
|
+
function getAttributeValue(element, attribute, possible, defaultValue) {
|
|
5
|
+
const value = getAttribute(element, attribute);
|
|
6
|
+
return possible.has(value) ? value : defaultValue;
|
|
7
|
+
}
|
|
8
|
+
function getBooleanAriaValue(element, attribute) {
|
|
9
|
+
const value = getAria(element, attribute);
|
|
10
|
+
return value === true || value === "true";
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { getAttributeValue, getBooleanAriaValue };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { GenericCallback } from "@oscarpalmer/atoms/models";
|
|
2
|
+
//#region src/js/l10n.d.ts
|
|
3
|
+
type LocalizationParameters<Localization> = Localization extends GenericCallback ? Parameters<Localization> : never;
|
|
4
|
+
declare class OuiLocalizations<Localizations extends OuiLocalizationsValues> {
|
|
5
|
+
readonly defaults: Localizations;
|
|
6
|
+
readonly keys: Set<keyof Localizations>;
|
|
7
|
+
readonly values: Record<string, Partial<Localizations>>;
|
|
8
|
+
constructor(defaults: Localizations);
|
|
9
|
+
get<Key extends keyof Localizations>(element: Element, key: Key, localizations: Record<string, Partial<Localizations>>): string | GenericCallback;
|
|
10
|
+
set(language: string, localizations: Partial<Localizations>): void;
|
|
11
|
+
set(localizations: Record<string, Partial<Localizations>>): void;
|
|
12
|
+
}
|
|
13
|
+
type OuiLocalizationsValues = Record<string, string | GenericCallback>;
|
|
14
|
+
declare function getLanguage(element: Element): string;
|
|
15
|
+
declare function getLocalization<Localizations extends OuiLocalizationsValues, Key extends keyof Localizations>(localizations: OuiLocalizations<Localizations>, element: Element, key: Key, value: Record<string, Partial<Localizations>>): Localizations[Key] | GenericCallback;
|
|
16
|
+
declare function getLocalizations<Localizations extends OuiLocalizationsValues>(defaults: Localizations): OuiLocalizations<Localizations>;
|
|
17
|
+
declare function localize<Localizations extends OuiLocalizationsValues, Key extends keyof Localizations, Localization extends Localizations[Key]>(localization: Localization, data: Record<string, unknown>, parameters: LocalizationParameters<Localization>): string;
|
|
18
|
+
declare function updateLocalizations<Localizations extends OuiLocalizationsValues>(instance: OuiLocalizations<Localizations>, values: Record<string, Partial<Localizations>>, destination: Record<string, Partial<Localizations>>, onAfter?: () => void): void;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { getLocalizations as a, getLocalization as i, OuiLocalizationsValues as n, localize as o, getLanguage as r, updateLocalizations as s, OuiLocalizations as t };
|
package/dist/js/l10n.d.mts
CHANGED
|
@@ -1,20 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
type LocalizationParameters<Localization> = Localization extends GenericCallback ? Parameters<Localization> : never;
|
|
4
|
-
type OuiLocalizationValues = Record<string, string | GenericCallback>;
|
|
5
|
-
declare class OuiLocalizations<Localizations extends OuiLocalizationValues> {
|
|
6
|
-
readonly defaults: Localizations;
|
|
7
|
-
readonly keys: Set<keyof Localizations>;
|
|
8
|
-
readonly values: Record<string, Partial<Localizations>>;
|
|
9
|
-
constructor(defaults: Localizations);
|
|
10
|
-
get<Key extends keyof Localizations>(element: Element, key: Key, localizations: Record<string, Partial<Localizations>>): string | GenericCallback;
|
|
11
|
-
set(language: string, localizations: Partial<Localizations>): void;
|
|
12
|
-
set(localizations: Record<string, Partial<Localizations>>): void;
|
|
13
|
-
}
|
|
14
|
-
declare function getLanguage(element: Element): string;
|
|
15
|
-
declare function getLocalization<Localizations extends OuiLocalizationValues, Key extends keyof Localizations>(localizations: OuiLocalizations<Localizations>, element: Element, key: Key, value: Record<string, Partial<Localizations>>): Localizations[Key] | GenericCallback;
|
|
16
|
-
declare function getLocalizations<Localizations extends OuiLocalizationValues>(defaults: Localizations): OuiLocalizations<Localizations>;
|
|
17
|
-
declare function localize<Localizations extends OuiLocalizationValues, Key extends keyof Localizations, Localization extends Localizations[Key]>(localization: Localization, data: Record<string, unknown>, parameters: LocalizationParameters<Localization>): string;
|
|
18
|
-
declare function updateLocalizations<Localizations extends OuiLocalizationValues>(instance: OuiLocalizations<Localizations>, values: Record<string, Partial<Localizations>>, destination?: Record<string, Partial<Localizations>>, onAfter?: () => void): void;
|
|
19
|
-
//#endregion
|
|
20
|
-
export { OuiLocalizations, getLanguage, getLocalization, getLocalizations, localize, updateLocalizations };
|
|
1
|
+
import { a as getLocalizations, i as getLocalization, n as OuiLocalizationsValues, o as localize, r as getLanguage, s as updateLocalizations, t as OuiLocalizations } from "./l10n-Bn-7RcwR.mjs";
|
|
2
|
+
export { OuiLocalizations, OuiLocalizationsValues, getLanguage, getLocalization, getLocalizations, localize, updateLocalizations };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//#region src/js/listbox/constants.listbox.ts
|
|
2
|
+
const LISTBOX_TAGNAME = "oui-listbox";
|
|
3
|
+
const attributeContent = `${LISTBOX_TAGNAME}-content`;
|
|
4
|
+
const attributeFilter = `${LISTBOX_TAGNAME}-filter`;
|
|
5
|
+
const attributeFilterInput = `${attributeFilter}-input`;
|
|
6
|
+
const attributeGroup = `${LISTBOX_TAGNAME}-group`;
|
|
7
|
+
const attributeHeader = `${LISTBOX_TAGNAME}-header`;
|
|
8
|
+
const attributeHidden = `${LISTBOX_TAGNAME}-hidden`;
|
|
9
|
+
const attributeList = `${LISTBOX_TAGNAME}-list`;
|
|
10
|
+
const attributeListEmpty = `${attributeList}-empty`;
|
|
11
|
+
const attributeMessage = `${LISTBOX_TAGNAME}-message`;
|
|
12
|
+
const attributeOption = `${LISTBOX_TAGNAME}-option`;
|
|
13
|
+
const attributeOptionActive = `${LISTBOX_TAGNAME}-option-active`;
|
|
14
|
+
const messageLabel = `<${LISTBOX_TAGNAME}> must contain a <label> element for the <select> element`;
|
|
15
|
+
const messageSelect = `<${LISTBOX_TAGNAME}> must contain a valid <select> element`;
|
|
16
|
+
const selectorFilter = `[${attributeFilterInput}]`;
|
|
17
|
+
const selectorOption = `[${attributeOption}]`;
|
|
18
|
+
const LISTBOX_ATTRIBUTES = {
|
|
19
|
+
active: attributeOptionActive,
|
|
20
|
+
content: attributeContent,
|
|
21
|
+
empty: attributeListEmpty,
|
|
22
|
+
filter: attributeFilter,
|
|
23
|
+
group: attributeGroup,
|
|
24
|
+
header: attributeHeader,
|
|
25
|
+
hidden: attributeHidden,
|
|
26
|
+
input: attributeFilterInput,
|
|
27
|
+
list: attributeList,
|
|
28
|
+
message: attributeMessage,
|
|
29
|
+
option: attributeOption
|
|
30
|
+
};
|
|
31
|
+
const LISTBOX_MESSAGES = {
|
|
32
|
+
label: messageLabel,
|
|
33
|
+
select: messageSelect
|
|
34
|
+
};
|
|
35
|
+
const LISTBOX_SELECTORS = {
|
|
36
|
+
filter: selectorFilter,
|
|
37
|
+
option: selectorOption
|
|
38
|
+
};
|
|
39
|
+
//#endregion
|
|
40
|
+
export { LISTBOX_ATTRIBUTES, LISTBOX_MESSAGES, LISTBOX_SELECTORS, LISTBOX_TAGNAME };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { c as OuiListboxPreview, l as OuiListboxState } from "../listbox.model-CRReGOmu.mjs";
|
|
2
|
+
//#region src/js/listbox/event.listbox.d.ts
|
|
3
|
+
declare function onListboxEnter(state: OuiListboxState): void;
|
|
4
|
+
declare function onListboxFilter(preview: OuiListboxPreview, state: OuiListboxState, _: boolean, active?: HTMLElement): void;
|
|
5
|
+
declare function onListboxNavigation(preview: OuiListboxPreview, state: OuiListboxState, active?: HTMLElement): void;
|
|
6
|
+
declare function onListboxToggle(state: OuiListboxState): void;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { onListboxEnter, onListboxFilter, onListboxNavigation, onListboxToggle };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { o as OuiListboxLocalizations } from "../listbox.model-CRReGOmu.mjs";
|
|
2
|
+
import { i as LISTBOX_TAGNAME } from "../constants.listbox-DRsXUxd3.mjs";
|
|
3
|
+
import { n as setListboxLocalizations } from "../misc.listbox-gnoJhrTr.mjs";
|
|
4
|
+
//#region src/js/listbox/index.d.ts
|
|
5
|
+
declare global {
|
|
6
|
+
interface HTMLElementTagNameMap {
|
|
7
|
+
[LISTBOX_TAGNAME]: OuiListboxElement;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
declare class OuiListboxElement extends HTMLElement {
|
|
11
|
+
#private;
|
|
12
|
+
static formAssociated: boolean;
|
|
13
|
+
static observedAttributes: string[];
|
|
14
|
+
/**
|
|
15
|
+
* Is the listbox disabled?
|
|
16
|
+
*/
|
|
17
|
+
get disabled(): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Should the listbox be disabled?
|
|
20
|
+
*/
|
|
21
|
+
set disabled(value: boolean);
|
|
22
|
+
/**
|
|
23
|
+
* Current filter value
|
|
24
|
+
*/
|
|
25
|
+
get filter(): string;
|
|
26
|
+
/**
|
|
27
|
+
* Set the filter value
|
|
28
|
+
*/
|
|
29
|
+
set filter(value: string);
|
|
30
|
+
/**
|
|
31
|
+
* Maximum number of selected options
|
|
32
|
+
*/
|
|
33
|
+
get max(): number | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Set the maximum number of selected options
|
|
36
|
+
*/
|
|
37
|
+
set max(value: number);
|
|
38
|
+
/**
|
|
39
|
+
* Minimum number of selected options
|
|
40
|
+
*/
|
|
41
|
+
get min(): number | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Set the minimum number of selected options
|
|
44
|
+
*/
|
|
45
|
+
set min(value: number);
|
|
46
|
+
/**
|
|
47
|
+
* Does the listbox allow multiple values?
|
|
48
|
+
*/
|
|
49
|
+
get multiple(): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Name of the listbox
|
|
52
|
+
*/
|
|
53
|
+
get name(): string;
|
|
54
|
+
/**
|
|
55
|
+
* Is the listbox readonly?
|
|
56
|
+
*/
|
|
57
|
+
get readonly(): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Should the listbox be readonly?
|
|
60
|
+
*/
|
|
61
|
+
set readonly(value: boolean);
|
|
62
|
+
/**
|
|
63
|
+
* Is the listbox required?
|
|
64
|
+
*/
|
|
65
|
+
get required(): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Should the listbox be required?
|
|
68
|
+
*/
|
|
69
|
+
set required(value: boolean);
|
|
70
|
+
/**
|
|
71
|
+
* Selected options
|
|
72
|
+
*/
|
|
73
|
+
get selected(): HTMLElement[];
|
|
74
|
+
/**
|
|
75
|
+
* Current value
|
|
76
|
+
*/
|
|
77
|
+
get value(): string;
|
|
78
|
+
/**
|
|
79
|
+
* Set the value
|
|
80
|
+
*/
|
|
81
|
+
set value(value: unknown);
|
|
82
|
+
/**
|
|
83
|
+
* Current values
|
|
84
|
+
*/
|
|
85
|
+
get values(): string[];
|
|
86
|
+
/**
|
|
87
|
+
* Set the values
|
|
88
|
+
*/
|
|
89
|
+
set values(values: unknown[]);
|
|
90
|
+
constructor();
|
|
91
|
+
attributeChangedCallback(name: string, _: string | null, value: string | null): void;
|
|
92
|
+
/**
|
|
93
|
+
* Clear all selected options
|
|
94
|
+
*/
|
|
95
|
+
clear(): void;
|
|
96
|
+
connectedCallback(): void;
|
|
97
|
+
disconnectedCallback(): void;
|
|
98
|
+
formDisabledCallback(disabled: boolean): void;
|
|
99
|
+
formResetCallback(): void;
|
|
100
|
+
formStateRestoreCallback(state: string | File | FormData, reason: unknown): void;
|
|
101
|
+
/**
|
|
102
|
+
* Set listbox localizations for a specific language
|
|
103
|
+
*
|
|
104
|
+
* @param language Language code
|
|
105
|
+
* @param localizations Localizations for language
|
|
106
|
+
*/
|
|
107
|
+
setLocalizations(language: string, localizations: Partial<OuiListboxLocalizations>): void;
|
|
108
|
+
/**
|
|
109
|
+
* Set listbox localizations for one or more languages
|
|
110
|
+
*
|
|
111
|
+
* @param localizations Localizations for one or more languages
|
|
112
|
+
*/
|
|
113
|
+
setLocalizations(localizations: Record<string, Partial<OuiListboxLocalizations>>): void;
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
116
|
+
export { OuiListboxElement, setListboxLocalizations };
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { C as setListboxDisabled, D as setListboxReadonly, O as setListboxRequired, T as setListboxLimit, a as setListboxValue, o as setListboxValues, w as setListboxFilter } from "../listbox.data-BWd0PCy7.mjs";
|
|
2
|
+
import { attachListbox, detachListbox } from "../internal/listbox/listbox.state.mjs";
|
|
3
|
+
import { LISTBOX_TAGNAME } from "./constants.listbox.mjs";
|
|
4
|
+
import { c as onDetachListbox, i as createListboxState, n as setListboxLocalizations, o as listboxStates, r as updateListboxLocalizations, s as onAttachListbox } from "../misc.listbox-BI-XsTOf.mjs";
|
|
5
|
+
import { getAttribute } from "@oscarpalmer/toretto/attribute";
|
|
6
|
+
import { parse } from "@oscarpalmer/atoms/string";
|
|
7
|
+
//#region src/js/listbox/index.ts
|
|
8
|
+
var OuiListboxElement = class extends HTMLElement {
|
|
9
|
+
static formAssociated = true;
|
|
10
|
+
static observedAttributes = [
|
|
11
|
+
"max",
|
|
12
|
+
"min",
|
|
13
|
+
"required",
|
|
14
|
+
"value"
|
|
15
|
+
];
|
|
16
|
+
#internals;
|
|
17
|
+
#restored;
|
|
18
|
+
#state;
|
|
19
|
+
/**
|
|
20
|
+
* Is the listbox disabled?
|
|
21
|
+
*/
|
|
22
|
+
get disabled() {
|
|
23
|
+
return this.#state?.disabled ?? false;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Should the listbox be disabled?
|
|
27
|
+
*/
|
|
28
|
+
set disabled(value) {
|
|
29
|
+
if (typeof value === "boolean" && value !== this.disabled) setListboxDisabled(this.#state, value);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Current filter value
|
|
33
|
+
*/
|
|
34
|
+
get filter() {
|
|
35
|
+
return this.#state.filter.element.value;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Set the filter value
|
|
39
|
+
*/
|
|
40
|
+
set filter(value) {
|
|
41
|
+
setListboxFilter(this.#state, value);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Maximum number of selected options
|
|
45
|
+
*/
|
|
46
|
+
get max() {
|
|
47
|
+
return this.#state?.max;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Set the maximum number of selected options
|
|
51
|
+
*/
|
|
52
|
+
set max(value) {
|
|
53
|
+
setListboxLimit("max", this.#state, value);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Minimum number of selected options
|
|
57
|
+
*/
|
|
58
|
+
get min() {
|
|
59
|
+
return this.#state?.min;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Set the minimum number of selected options
|
|
63
|
+
*/
|
|
64
|
+
set min(value) {
|
|
65
|
+
setListboxLimit("min", this.#state, value);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Does the listbox allow multiple values?
|
|
69
|
+
*/
|
|
70
|
+
get multiple() {
|
|
71
|
+
return this.hasAttribute("multiple");
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Name of the listbox
|
|
75
|
+
*/
|
|
76
|
+
get name() {
|
|
77
|
+
return getAttribute(this, "name") ?? "";
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Is the listbox readonly?
|
|
81
|
+
*/
|
|
82
|
+
get readonly() {
|
|
83
|
+
return this.#state?.readonly ?? false;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Should the listbox be readonly?
|
|
87
|
+
*/
|
|
88
|
+
set readonly(value) {
|
|
89
|
+
if (typeof value === "boolean" && value !== this.readonly) setListboxReadonly(this.#state, value);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Is the listbox required?
|
|
93
|
+
*/
|
|
94
|
+
get required() {
|
|
95
|
+
return this.#state?.required ?? false;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Should the listbox be required?
|
|
99
|
+
*/
|
|
100
|
+
set required(value) {
|
|
101
|
+
if (typeof value === "boolean" && value !== this.required) setListboxRequired(this.#state, value);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Selected options
|
|
105
|
+
*/
|
|
106
|
+
get selected() {
|
|
107
|
+
return this.#state.options.selected.slice();
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Current value
|
|
111
|
+
*/
|
|
112
|
+
get value() {
|
|
113
|
+
return this.#state.values.current[0];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Set the value
|
|
117
|
+
*/
|
|
118
|
+
set value(value) {
|
|
119
|
+
setListboxValue(this.#state, value);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Current values
|
|
123
|
+
*/
|
|
124
|
+
get values() {
|
|
125
|
+
return this.#state.values.current.slice();
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Set the values
|
|
129
|
+
*/
|
|
130
|
+
set values(values) {
|
|
131
|
+
setListboxValues(this.#state, values);
|
|
132
|
+
}
|
|
133
|
+
constructor() {
|
|
134
|
+
super();
|
|
135
|
+
this.#internals = this.attachInternals();
|
|
136
|
+
}
|
|
137
|
+
attributeChangedCallback(name, _, value) {
|
|
138
|
+
if (this.#state == null) return;
|
|
139
|
+
switch (name) {
|
|
140
|
+
case "required":
|
|
141
|
+
this[name] = this.hasAttribute(name);
|
|
142
|
+
break;
|
|
143
|
+
case "max":
|
|
144
|
+
case "min":
|
|
145
|
+
setListboxLimit(name, this.#state, value);
|
|
146
|
+
break;
|
|
147
|
+
case "value": this.value = value ?? "";
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Clear all selected options
|
|
152
|
+
*/
|
|
153
|
+
clear() {
|
|
154
|
+
setListboxValues(this.#state, []);
|
|
155
|
+
}
|
|
156
|
+
connectedCallback() {
|
|
157
|
+
if (this.#state == null) this.#initialize();
|
|
158
|
+
else attachListbox(this.#state, listboxStates, onAttachListbox);
|
|
159
|
+
}
|
|
160
|
+
disconnectedCallback() {
|
|
161
|
+
if (this.#state != null) detachListbox(this.#state, listboxStates, onDetachListbox);
|
|
162
|
+
}
|
|
163
|
+
formDisabledCallback(disabled) {
|
|
164
|
+
this.disabled = disabled;
|
|
165
|
+
}
|
|
166
|
+
formResetCallback() {
|
|
167
|
+
setListboxValues(this.#state, this.#state.values.initial);
|
|
168
|
+
}
|
|
169
|
+
formStateRestoreCallback(state, reason) {
|
|
170
|
+
if (reason !== "restore") return;
|
|
171
|
+
const parsed = typeof state === "string" ? parse(state) : void 0;
|
|
172
|
+
if (!Array.isArray(parsed)) return;
|
|
173
|
+
if (this.#state == null) this.#restored = parsed;
|
|
174
|
+
else setListboxValues(this.#state, parsed);
|
|
175
|
+
}
|
|
176
|
+
setLocalizations(first, second) {
|
|
177
|
+
updateListboxLocalizations(this.#state.localizations.global, this.#state.localizations.component, first, second);
|
|
178
|
+
}
|
|
179
|
+
#initialize() {
|
|
180
|
+
this.#state = createListboxState(this, this.#internals);
|
|
181
|
+
if (this.#restored != null) {
|
|
182
|
+
setListboxValues(this.#state, this.#restored);
|
|
183
|
+
this.#restored = void 0;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
customElements.define(LISTBOX_TAGNAME, OuiListboxElement);
|
|
188
|
+
//#endregion
|
|
189
|
+
export { OuiListboxElement, setListboxLocalizations };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { t as OuiLocalizations } from "../l10n-Bn-7RcwR.mjs";
|
|
2
|
+
import { l as OuiListboxState, o as OuiListboxLocalizations, u as OuiListboxStates } from "../listbox.model-CRReGOmu.mjs";
|
|
3
|
+
import { OuiListboxElement } from "./index.mjs";
|
|
4
|
+
//#region src/js/listbox/state.listbox.d.ts
|
|
5
|
+
declare function createListboxState(element: OuiListboxElement, internals: ElementInternals): OuiListboxState;
|
|
6
|
+
declare function onAttachListbox(state: OuiListboxState): void;
|
|
7
|
+
declare function onDetachListbox(state: OuiListboxState): void;
|
|
8
|
+
declare const listboxLocalizations: OuiLocalizations<OuiListboxLocalizations>;
|
|
9
|
+
declare const listboxStates: OuiListboxStates;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { createListboxState, listboxLocalizations, listboxStates, onAttachListbox, onDetachListbox };
|