@oscarpalmer/oui 0.34.0 → 0.35.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/js/combobox/constants.combobox.d.mts +1 -1
- package/dist/js/combobox/data.combobox.d.mts +1 -1
- package/dist/js/combobox/data.combobox.mjs +1 -1
- package/dist/js/combobox/dom.combobox.d.mts +1 -1
- package/dist/js/combobox/dom.combobox.mjs +1 -1
- package/dist/js/combobox/event.combobox.d.mts +1 -1
- package/dist/js/combobox/event.combobox.mjs +1 -1
- package/dist/js/combobox/form.combobox.d.mts +1 -1
- package/dist/js/combobox/form.combobox.mjs +1 -1
- package/dist/js/combobox/index.d.mts +1 -1
- package/dist/js/combobox/index.mjs +3 -2
- package/dist/js/combobox/misc.combobox.d.mts +2 -14
- package/dist/js/combobox/misc.combobox.mjs +2 -2
- package/dist/js/combobox/models.combobox.d.mts +1 -1
- package/dist/js/combobox/state.combobox.d.mts +4 -2
- package/dist/js/combobox/state.combobox.mjs +2 -2
- package/dist/js/{constants.combobox-DqNUGBLS.d.mts → constants.combobox-h_kyDegw.d.mts} +12 -7
- package/dist/js/{data.combobox-8RwBv5ey.mjs → data.combobox-B8HMkDOh.mjs} +245 -292
- package/dist/js/index.d.mts +1 -1
- package/dist/js/index.mjs +1 -1
- package/dist/js/l10n.d.mts +20 -0
- package/dist/js/l10n.mjs +80 -0
- package/package.json +1 -1
- package/src/js/combobox/dom.combobox.ts +57 -26
- package/src/js/combobox/form.combobox.ts +26 -25
- package/src/js/combobox/index.ts +10 -4
- package/src/js/combobox/misc.combobox.ts +50 -0
- package/src/js/combobox/state.combobox.ts +13 -1
- package/src/js/l10n.ts +192 -0
- package/dist/js/combobox/i18n.combobox.d.mts +0 -2
- package/dist/js/combobox/i18n.combobox.mjs +0 -2
- package/src/js/combobox/i18n.combobox.ts +0 -179
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { B as getComboboxLanguage, H as setComboboxLocalizations, U as updateComboboxLocalizations, V as getComboboxLocalization } from "../constants.combobox-DqNUGBLS.mjs";
|
|
2
|
-
export { getComboboxLanguage, getComboboxLocalization, setComboboxLocalizations, updateComboboxLocalizations };
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { F as setComboboxLocalizations, I as updateComboboxLocalizations, N as getComboboxLanguage, P as getComboboxLocalization } from "../data.combobox-8RwBv5ey.mjs";
|
|
2
|
-
export { getComboboxLanguage, getComboboxLocalization, setComboboxLocalizations, updateComboboxLocalizations };
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import type {GenericCallback} from '@oscarpalmer/atoms/models';
|
|
2
|
-
import {
|
|
3
|
-
updateComboboxAnchor,
|
|
4
|
-
updateComboboxMessage,
|
|
5
|
-
updateComboboxSelectionItems,
|
|
6
|
-
} from './dom.combobox';
|
|
7
|
-
import {getComboboxVisibleOptions} from './misc.combobox';
|
|
8
|
-
import type {OuiComboboxLocalizations, OuiComboboxState} from './models.combobox';
|
|
9
|
-
import {comboboxStates} from './state.combobox';
|
|
10
|
-
|
|
11
|
-
// #region Functions
|
|
12
|
-
|
|
13
|
-
export function getComboboxLanguage(state: OuiComboboxState): string {
|
|
14
|
-
return (
|
|
15
|
-
state.host.closest('[lang]')?.getAttribute('lang') ?? document.documentElement.lang
|
|
16
|
-
).toLowerCase();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function getComboboxLocalization<Key extends keyof OuiComboboxLocalizations>(
|
|
20
|
-
key: Key,
|
|
21
|
-
state: OuiComboboxState,
|
|
22
|
-
): OuiComboboxLocalizations[Key] {
|
|
23
|
-
const language = getComboboxLanguage(state);
|
|
24
|
-
|
|
25
|
-
const allLocalizations = [state.localizations, LOCALIZATIONS.globals];
|
|
26
|
-
const {length} = allLocalizations;
|
|
27
|
-
|
|
28
|
-
let localization: OuiComboboxLocalizations[Key] | undefined;
|
|
29
|
-
let shortLanguage: string | undefined;
|
|
30
|
-
|
|
31
|
-
for (let index = 0; index < length; index += 1) {
|
|
32
|
-
const localizations = allLocalizations[index];
|
|
33
|
-
|
|
34
|
-
localization = localizations?.[language]?.[key];
|
|
35
|
-
|
|
36
|
-
if (localization != null) {
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
shortLanguage ??= language.split('-')[0];
|
|
41
|
-
|
|
42
|
-
if (shortLanguage === language) {
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
localization = localizations?.[shortLanguage]?.[key];
|
|
47
|
-
|
|
48
|
-
if (localization != null) {
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return localization ?? LOCALIZATIONS.defaults[key];
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Set combobox localizations for a specific language
|
|
58
|
-
*
|
|
59
|
-
* @param language Language code
|
|
60
|
-
* @param localizations Localizations for language
|
|
61
|
-
*/
|
|
62
|
-
export function setComboboxLocalizations(
|
|
63
|
-
language: string,
|
|
64
|
-
localizations: Partial<OuiComboboxLocalizations>,
|
|
65
|
-
): void;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Set combobox localizations for one or more languages
|
|
69
|
-
*
|
|
70
|
-
* @param localizations Localizations for one or more languages
|
|
71
|
-
*/
|
|
72
|
-
export function setComboboxLocalizations(
|
|
73
|
-
localizations: Record<string, Partial<OuiComboboxLocalizations>>,
|
|
74
|
-
): void;
|
|
75
|
-
|
|
76
|
-
export function setComboboxLocalizations(
|
|
77
|
-
first: string | Record<string, Partial<OuiComboboxLocalizations>>,
|
|
78
|
-
second?: Partial<OuiComboboxLocalizations>,
|
|
79
|
-
): void {
|
|
80
|
-
updateComboboxLocalizations(
|
|
81
|
-
typeof first === 'string'
|
|
82
|
-
? {
|
|
83
|
-
[first]: second!,
|
|
84
|
-
}
|
|
85
|
-
: first,
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export function updateComboboxLocalizations(
|
|
90
|
-
values: Record<string, Partial<Record<string, string | GenericCallback>>>,
|
|
91
|
-
destination?: Record<string, Partial<OuiComboboxLocalizations>>,
|
|
92
|
-
): void {
|
|
93
|
-
if (typeof values !== 'object' || values == null) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const localizations = destination ?? LOCALIZATIONS.globals;
|
|
98
|
-
|
|
99
|
-
const languages = Object.keys(values);
|
|
100
|
-
const languagesLength = languages.length;
|
|
101
|
-
|
|
102
|
-
let updated = false;
|
|
103
|
-
|
|
104
|
-
for (let languagesIndex = 0; languagesIndex < languagesLength; languagesIndex += 1) {
|
|
105
|
-
const language = languages[languagesIndex];
|
|
106
|
-
const languageValue = values[language];
|
|
107
|
-
|
|
108
|
-
if (typeof languageValue !== 'object' || languageValue == null) {
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const normalizedLanguage = language.toLowerCase();
|
|
113
|
-
|
|
114
|
-
localizations[normalizedLanguage] ??= {};
|
|
115
|
-
|
|
116
|
-
const keys = Object.keys(languageValue);
|
|
117
|
-
const keysLength = keys.length;
|
|
118
|
-
|
|
119
|
-
for (let keysIndex = 0; keysIndex < keysLength; keysIndex += 1) {
|
|
120
|
-
const key = keys[keysIndex];
|
|
121
|
-
const keyValue = languageValue[key];
|
|
122
|
-
|
|
123
|
-
const normalizedKey = key.toLowerCase() as keyof OuiComboboxLocalizations;
|
|
124
|
-
|
|
125
|
-
if (
|
|
126
|
-
LOCALIZATIONS.keys.has(normalizedKey) &&
|
|
127
|
-
(typeof keyValue === 'string' || typeof keyValue === 'function')
|
|
128
|
-
) {
|
|
129
|
-
updated = true;
|
|
130
|
-
|
|
131
|
-
localizations[normalizedLanguage][normalizedKey] = keyValue as never;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (!updated) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
for (const state of comboboxStates.set) {
|
|
141
|
-
updateComboboxAnchor(state);
|
|
142
|
-
updateComboboxMessage(state, getComboboxVisibleOptions(state).length);
|
|
143
|
-
updateComboboxSelectionItems(state);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// #endregion
|
|
148
|
-
|
|
149
|
-
// #region Variables
|
|
150
|
-
|
|
151
|
-
const LOCALIZATIONS: {
|
|
152
|
-
defaults: OuiComboboxLocalizations;
|
|
153
|
-
globals: Record<string, Partial<OuiComboboxLocalizations>>;
|
|
154
|
-
keys: Set<keyof OuiComboboxLocalizations>;
|
|
155
|
-
} = {
|
|
156
|
-
defaults: {
|
|
157
|
-
empty: 'No results found',
|
|
158
|
-
input: 'Please enter a value',
|
|
159
|
-
invalid: 'Please select an option from the list',
|
|
160
|
-
max: max => `Please select fewer options (maximum is ${max})`,
|
|
161
|
-
min: min => `Please select more options (minimum is ${min})`,
|
|
162
|
-
remove: label => `Remove ${label}`,
|
|
163
|
-
results: amount => `${amount} results available`,
|
|
164
|
-
selected: amount => `${amount} selected`,
|
|
165
|
-
},
|
|
166
|
-
globals: {},
|
|
167
|
-
keys: new Set<keyof OuiComboboxLocalizations>([
|
|
168
|
-
'empty',
|
|
169
|
-
'input',
|
|
170
|
-
'invalid',
|
|
171
|
-
'max',
|
|
172
|
-
'min',
|
|
173
|
-
'remove',
|
|
174
|
-
'results',
|
|
175
|
-
'selected',
|
|
176
|
-
]),
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
// #endregion
|