@arcgis/components-utils 4.33.0-next.9 → 4.33.0-next.91
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/array-utils.d.cts +5 -0
- package/dist/array-utils.d.ts +5 -0
- package/dist/css-utils.d.cts +15 -0
- package/dist/css-utils.d.ts +15 -0
- package/dist/deferred.d.cts +30 -0
- package/dist/deferred.d.ts +30 -0
- package/dist/dom.d.cts +65 -0
- package/dist/dom.d.ts +65 -0
- package/dist/errors.d.cts +30 -0
- package/dist/errors.d.ts +30 -0
- package/dist/guid.d.cts +5 -0
- package/dist/guid.d.ts +5 -0
- package/dist/index.cjs +68 -158
- package/dist/index.d.cts +15 -378
- package/dist/index.d.ts +15 -378
- package/dist/index.js +29 -55
- package/dist/intl.d.cts +91 -0
- package/dist/intl.d.ts +91 -0
- package/dist/preamble.d.cts +17 -0
- package/dist/preamble.d.ts +17 -0
- package/dist/strings.d.cts +29 -0
- package/dist/strings.d.ts +29 -0
- package/dist/tests/utils.d.cts +1 -0
- package/dist/tests/utils.d.ts +1 -0
- package/dist/text.d.cts +7 -0
- package/dist/text.d.ts +7 -0
- package/dist/timeouts.d.cts +7 -0
- package/dist/timeouts.d.ts +7 -0
- package/dist/type-guards.d.cts +12 -0
- package/dist/type-guards.d.ts +12 -0
- package/dist/types.d.cts +30 -0
- package/dist/types.d.ts +30 -0
- package/dist/ui.d.cts +8 -0
- package/dist/ui.d.ts +8 -0
- package/dist/url.d.cts +14 -0
- package/dist/url.d.ts +14 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,378 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* interfaces and types you create. Benefits:
|
|
17
|
-
* - Explicitly documents that a given key won't be modified/should not be
|
|
18
|
-
* modified
|
|
19
|
-
* - Favors more declarative and functional style programming
|
|
20
|
-
* - Helps prevent bugs related to mutation unexpectedly affecting other places
|
|
21
|
-
* that held a reference to the same object
|
|
22
|
-
*
|
|
23
|
-
* Your function could return a type like "ResolvedConfig", that has all keys
|
|
24
|
-
* marked as readonly. But inside the function you may wish to modify some of
|
|
25
|
-
* the keys while creating the object - casting the object to
|
|
26
|
-
* `Writable<ResolvedConfig>` helps with that
|
|
27
|
-
*/
|
|
28
|
-
type Writable<T> = {
|
|
29
|
-
-readonly [k in keyof T]: T[k];
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Find a value in an array, and return it's mapped variant.
|
|
34
|
-
*/
|
|
35
|
-
declare function mappedFind<Item, ReturnType>(array: readonly Item[], callback: (item: Item, index: number) => Nil | ReturnType): ReturnType | undefined;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* This code contains imperative syntax (like for loops and mutation) as it is
|
|
39
|
-
* in the hot path - performance optimizations are critical here.
|
|
40
|
-
* See https://devtopia.esri.com/WebGIS/arcgis-js-api/commit/2565cedd87b
|
|
41
|
-
*
|
|
42
|
-
* Stencil has native support for passing-in class prop as an object or string,
|
|
43
|
-
* but it does not support arrays or booleans, thus this utility is used
|
|
44
|
-
* instead.
|
|
45
|
-
*
|
|
46
|
-
* @remarks
|
|
47
|
-
* This function is not necessary in a Lit package as Lit's `classMap` directive
|
|
48
|
-
* accepts an object
|
|
49
|
-
*/
|
|
50
|
-
declare function classes(...classes: (Nil | Record<string, boolean> | string[] | string | false)[]): string;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* A deferred promise.
|
|
54
|
-
* Useful for when you want to return a promise but don't have the value yet.
|
|
55
|
-
* Example:
|
|
56
|
-
* ```
|
|
57
|
-
* const deferred = new Deferred<string>();
|
|
58
|
-
* setTimeout(() => deferred.resolve("Hello World"), 1000);
|
|
59
|
-
* return deferred.promise;
|
|
60
|
-
* ```
|
|
61
|
-
* @template T The type of the promise.
|
|
62
|
-
*/
|
|
63
|
-
declare class Deferred<T> {
|
|
64
|
-
/**
|
|
65
|
-
* The promise that can be awaited.
|
|
66
|
-
*/
|
|
67
|
-
promise: Promise<T>;
|
|
68
|
-
/**
|
|
69
|
-
* Resolves the promise.
|
|
70
|
-
* @param value The value to resolve the promise with.
|
|
71
|
-
*/
|
|
72
|
-
resolve(_value: PromiseLike<T> | T): void;
|
|
73
|
-
/**
|
|
74
|
-
* Rejects the promise.
|
|
75
|
-
*/
|
|
76
|
-
reject(_error: unknown): void;
|
|
77
|
-
/**
|
|
78
|
-
* Creates a new deferred promise.
|
|
79
|
-
*/
|
|
80
|
-
constructor();
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Observe the element and its ancestors for attribute mutations.
|
|
85
|
-
* If the attributes have been changed in the ancestor tree then the callback will be invoked.
|
|
86
|
-
* Example: `observeAncestorsMutation(element, ["dir", "lang"], () => console.log("dir or lang changed"));`
|
|
87
|
-
* @param element The element on which to observe the attribute mutations.
|
|
88
|
-
* @param attributeFilter The list of attributes to observe.
|
|
89
|
-
* @param callback The callback to invoke when the attributes have been changed.
|
|
90
|
-
* @returns The mutation observer
|
|
91
|
-
*/
|
|
92
|
-
declare function observeAncestorsMutation(element: Node, attributeFilter: string[], callback: () => void): () => void;
|
|
93
|
-
/**
|
|
94
|
-
* Find the closest element that matches the selector.
|
|
95
|
-
* It will traverse the element's ancestors to find the target element.
|
|
96
|
-
* Shadow DOM boundaries are also taken into account.
|
|
97
|
-
* @param base The element to start the search from.
|
|
98
|
-
* @param selector The selector to match.
|
|
99
|
-
* @returns The closest element that matches the selector or null if not found.
|
|
100
|
-
*/
|
|
101
|
-
declare function closestElement(base: Element, selector: string): Element | null;
|
|
102
|
-
/**
|
|
103
|
-
* Use the Calcite mode to determine the theme of the element.
|
|
104
|
-
* It will traverse the element's ancestors to find the theme.
|
|
105
|
-
* Shadow DOM boundaries are also taken into account.
|
|
106
|
-
* @param base The element to start the search from.
|
|
107
|
-
* @returns The theme of the element, either "light" or "dark", "light" is the default.
|
|
108
|
-
*/
|
|
109
|
-
declare function getElementTheme(base: Element): "dark" | "light";
|
|
110
|
-
/**
|
|
111
|
-
* Get direction property of closest element.
|
|
112
|
-
* @param el The element to start the search from.
|
|
113
|
-
* @returns The direction of the element, either "ltr" | "rtl", "ltr" is the default.
|
|
114
|
-
*/
|
|
115
|
-
declare function getElementDir(el: HTMLElement): "ltr" | "rtl";
|
|
116
|
-
/**
|
|
117
|
-
* Get the attribute value from the element.
|
|
118
|
-
* It will traverse the element's ancestors to find the attribute.
|
|
119
|
-
* Shadow DOM boundaries are also taken into account.
|
|
120
|
-
* If the attribute is not found then the fallback value is returned.
|
|
121
|
-
* Example: `getElementAttribute(element, "dir", "ltr");`
|
|
122
|
-
* @param base The element to start the search from.
|
|
123
|
-
* @param prop The attribute name.
|
|
124
|
-
* @param fallbackValue The fallback value if the attribute is not found.
|
|
125
|
-
* @returns The attribute value or the fallback value if the attribute is not found.
|
|
126
|
-
*/
|
|
127
|
-
declare function getElementAttribute(el: Element, prop: string, fallbackValue: string): string;
|
|
128
|
-
interface FocusableElement extends HTMLElement {
|
|
129
|
-
setFocus?: () => Promise<void>;
|
|
130
|
-
}
|
|
131
|
-
declare function focusElement(el: FocusableElement | undefined): Promise<void>;
|
|
132
|
-
/**
|
|
133
|
-
* Set the focus on the element that matches the selector.
|
|
134
|
-
* It will traverse the element's ancestors to find the target element.
|
|
135
|
-
* Shadow DOM boundaries are also taken into account.
|
|
136
|
-
* If the element is not found then the focus is not set.
|
|
137
|
-
* Example: `setFocusOnElement(element, "[role='menuitem']");`
|
|
138
|
-
* @param ref The element to start the search from.
|
|
139
|
-
* @param selector The selector to match.
|
|
140
|
-
* @returns Returns true if the focus is set on the element.
|
|
141
|
-
*
|
|
142
|
-
* REFACTOR: this is doing too much. break it into separate find element and focus
|
|
143
|
-
* element utilities
|
|
144
|
-
*/
|
|
145
|
-
declare function setFocusOnElement(ref: (Element & {
|
|
146
|
-
componentOnReady?: () => Promise<void>;
|
|
147
|
-
}) | null | undefined, selector: string): void;
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Check whether the code is executing in an Esri internal environment (for
|
|
151
|
-
* example, Lumina dev server). When true, your code can enable extra validation
|
|
152
|
-
* to detect incorrect usages or do runtime bug detection.
|
|
153
|
-
*
|
|
154
|
-
* The call to isEsriInternalEnv() MUST always appear behind one of the
|
|
155
|
-
* following guards to ensure it is correctly eliminated in production bundles:
|
|
156
|
-
*
|
|
157
|
-
* - `process.env.NODE_ENV !== "production"`
|
|
158
|
-
* - `process.env.NODE_ENV === "development"`
|
|
159
|
-
* - `process.env.NODE_ENV === "test"`
|
|
160
|
-
*
|
|
161
|
-
* @remarks
|
|
162
|
-
* This function is primary for usage in support packages. In Lumina component
|
|
163
|
-
* packages, simpler alternatives are provided:
|
|
164
|
-
* https://qawebgis.esri.com/components/lumina/publishing#bundling-code-conditionally
|
|
165
|
-
*/
|
|
166
|
-
declare function isEsriInternalEnv(): boolean;
|
|
167
|
-
/**
|
|
168
|
-
* Calls a sync method and catch any errors. Returns undefined if error occurred.
|
|
169
|
-
*
|
|
170
|
-
* Can also provide a thisContext and rest arguments
|
|
171
|
-
*/
|
|
172
|
-
declare function safeCall<Callback extends (...args: never[]) => unknown>(callback?: Callback, thisContext?: ThisParameterType<Callback>, ...rest: Parameters<Callback>): ReturnType<Callback> | void;
|
|
173
|
-
/**
|
|
174
|
-
* Calls an async method and catch any errors. Returns undefined if error occurred.
|
|
175
|
-
*
|
|
176
|
-
* Can also provide a thisContext and rest arguments
|
|
177
|
-
*/
|
|
178
|
-
declare function safeAsyncCall<Callback extends (...args: never[]) => unknown>(callback?: Callback, thisContext?: ThisParameterType<Callback>, ...rest: Parameters<Callback>): Promise<Awaited<ReturnType<Callback>> | void>;
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Generates a GUID string.
|
|
182
|
-
* @returns A GUID string with the pattern 00000000-0000-0000-0000-000000000000.
|
|
183
|
-
*/
|
|
184
|
-
declare function generateGuid(): string;
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* The interface for translated strings.
|
|
188
|
-
*/
|
|
189
|
-
interface GenericT9nStrings {
|
|
190
|
-
[key: string]: GenericT9nStrings | string;
|
|
191
|
-
}
|
|
192
|
-
declare const supportedLocalesArray: readonly ["ar", "bg", "bs", "ca", "cs", "da", "de", "el", "en", "es", "et", "fi", "fr", "he", "hr", "hu", "id", "it", "ja", "ko", "lt", "lv", "nl", "nb", "no", "pl", "pt-BR", "pt-PT", "ro", "ru", "sk", "sl", "sr", "sv", "th", "tr", "uk", "vi", "zh-CN", "zh-HK", "zh-TW"];
|
|
193
|
-
/**
|
|
194
|
-
* The list of supported locales for ArcGIS Maps SDK for JavaScript components.
|
|
195
|
-
*/
|
|
196
|
-
declare const supportedLocales: Set<"hr" | "th" | "tr" | "ar" | "bg" | "bs" | "ca" | "cs" | "da" | "de" | "el" | "en" | "es" | "et" | "fi" | "fr" | "he" | "hu" | "id" | "it" | "ja" | "ko" | "lt" | "lv" | "nl" | "nb" | "no" | "pl" | "pt-BR" | "pt-PT" | "ro" | "ru" | "sk" | "sl" | "sr" | "sv" | "uk" | "vi" | "zh-CN" | "zh-HK" | "zh-TW">;
|
|
197
|
-
type SupportedLocale = (typeof supportedLocalesArray)[number];
|
|
198
|
-
declare const defaultLocale = "en";
|
|
199
|
-
/**
|
|
200
|
-
* Fetch the T9N strings bundle for the given locale, assets path and prefix.
|
|
201
|
-
* The locale must be one of the supported locales.
|
|
202
|
-
* If the locale is not supported, it will default to 'en'.
|
|
203
|
-
* If the T9N strings bundle cannot be found, it will default to 'en'.
|
|
204
|
-
*
|
|
205
|
-
* @remarks
|
|
206
|
-
* Rather than using this function directly, prefer the `useT9n()` controller.
|
|
207
|
-
*
|
|
208
|
-
* @example
|
|
209
|
-
* ```ts
|
|
210
|
-
* const t9nStrings = await fetchT9nStringsBundle("en", getAssetPath("./assets/coding-editor/t9n"), "messages.");
|
|
211
|
-
* ```
|
|
212
|
-
*/
|
|
213
|
-
declare function fetchT9nStringsBundle<Strings extends GenericT9nStrings>(
|
|
214
|
-
/** The locale for which to fetch the T9N strings */
|
|
215
|
-
locale: string,
|
|
216
|
-
/** The path to the assets folder where the T9N strings are located */
|
|
217
|
-
assetsPath: string,
|
|
218
|
-
/** The prefix to use for the T9N strings file name. */
|
|
219
|
-
prefix?: string): Promise<Strings>;
|
|
220
|
-
/**
|
|
221
|
-
* Get the locale of the given element.
|
|
222
|
-
* It will look for the lang attribute on the element and its ancestors.
|
|
223
|
-
* If not lang is found, it will default to 'en'.
|
|
224
|
-
*/
|
|
225
|
-
declare function getElementLocales(element: HTMLElement): {
|
|
226
|
-
readonly lang: string;
|
|
227
|
-
readonly t9nLocale: SupportedLocale;
|
|
228
|
-
};
|
|
229
|
-
declare function normalizeLocale(locale: string): SupportedLocale;
|
|
230
|
-
type LocaleObserver<Strings extends GenericT9nStrings = GenericT9nStrings> = {
|
|
231
|
-
/** The T9N strings of the component */
|
|
232
|
-
t9nStrings: Strings;
|
|
233
|
-
/**
|
|
234
|
-
* The locale of the component set by the `lang` attribute on the component host element or one of its ancestors.
|
|
235
|
-
*/
|
|
236
|
-
lang: string;
|
|
237
|
-
/**
|
|
238
|
-
* The locale used by the component to load the T9N strings.
|
|
239
|
-
* It may be different than the locale of the component host element that was set by the `lang` attribute.
|
|
240
|
-
*/
|
|
241
|
-
t9nLocale: SupportedLocale;
|
|
242
|
-
};
|
|
243
|
-
/**
|
|
244
|
-
* Start the locale observer for the given component.
|
|
245
|
-
* The callback will be called when the locale changes for the component.
|
|
246
|
-
* It will observe the lang attribute on the component and its ancestors.
|
|
247
|
-
* The callback is called once at the beginning.
|
|
248
|
-
*
|
|
249
|
-
* @remarks
|
|
250
|
-
* Rather than using this function directly, prefer the `useT9n()` controller.
|
|
251
|
-
*/
|
|
252
|
-
declare function startLocaleObserver<Strings extends GenericT9nStrings = GenericT9nStrings>(
|
|
253
|
-
/** The Web component HTML element that is doing the fetching */
|
|
254
|
-
element: HTMLElement,
|
|
255
|
-
/**
|
|
256
|
-
* The callback to get path to the assets folder where the T9N strings are
|
|
257
|
-
* located.
|
|
258
|
-
*
|
|
259
|
-
* @example
|
|
260
|
-
* ```ts
|
|
261
|
-
* () => getAssetPath("./assets")
|
|
262
|
-
* ```
|
|
263
|
-
*/
|
|
264
|
-
getAssetsPath: () => string,
|
|
265
|
-
/** The callback to call when the locale changes */
|
|
266
|
-
onUpdated: (payload: LocaleObserver<Strings>) => void,
|
|
267
|
-
/**
|
|
268
|
-
* Optionally override the asset file name.
|
|
269
|
-
* Default file name is the component tag name without the part before the
|
|
270
|
-
* first dash (e.g. `arcgis-map` becomes `map`).
|
|
271
|
-
*
|
|
272
|
-
* Set to null if the component has no localization strings, but you still
|
|
273
|
-
* wish to use `startLocaleObserver` to get the locale information.
|
|
274
|
-
*/
|
|
275
|
-
assetName?: string | null): () => void;
|
|
276
|
-
|
|
277
|
-
declare const extractMinorVersion: (version: string) => string;
|
|
278
|
-
/**
|
|
279
|
-
* Creates preamble text from a version number. The preamble text is used in stencil.config.ts and inserts a comment at the top of the generated bundles.
|
|
280
|
-
* The preamble text contains the version number and a link to the license.
|
|
281
|
-
* The version number is typically extracted from the package.json file.
|
|
282
|
-
* @example
|
|
283
|
-
* ```ts
|
|
284
|
-
* const preamble = getPreamble("4.18.2-beta.1");
|
|
285
|
-
* console.log(preamble);
|
|
286
|
-
* // All material copyright Esri, All Rights Reserved, unless otherwise specified.
|
|
287
|
-
* // See https://js.arcgis.com/4.18/esri/copyright.txt for details.
|
|
288
|
-
* // v4.18.2-beta.1
|
|
289
|
-
* ```
|
|
290
|
-
* @param version the version number, typically coming from package.json.
|
|
291
|
-
* @returns a string containing the preamble text.
|
|
292
|
-
*/
|
|
293
|
-
declare const getPreamble: (version: string) => string;
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Add quotes to a string for display purposes.
|
|
297
|
-
* If the string contains a double quote, then single quotes will be used.
|
|
298
|
-
* If the string contains a single quote, then double quotes will be used.
|
|
299
|
-
* If the string contains both, then double quotes will be used and the single quotes will be escaped.
|
|
300
|
-
* @param value The string to quote
|
|
301
|
-
* @returns The quoted string
|
|
302
|
-
*/
|
|
303
|
-
declare function quoteString(value: string): string;
|
|
304
|
-
/**
|
|
305
|
-
* Create a filter expression from a filter word.
|
|
306
|
-
* @param filterWord The filter word to create the expression from.
|
|
307
|
-
* @returns The filter expression.
|
|
308
|
-
*/
|
|
309
|
-
declare function createFilterExpression(filterWord: string): RegExp;
|
|
310
|
-
/**
|
|
311
|
-
* Replace values in a string using the format {valueName} with the value from the values object.
|
|
312
|
-
* If the value is not found in the values object, then the value is not replaced.
|
|
313
|
-
* @param message The string to replace values in.
|
|
314
|
-
* @param values The values to replace in the string.
|
|
315
|
-
* @returns The string with the values replaced.
|
|
316
|
-
*/
|
|
317
|
-
declare function setValuesInString(message: string | null | undefined, values?: Record<string, string>): string;
|
|
318
|
-
/**
|
|
319
|
-
* Add LTR marks to a string to ensure it is displayed as LTR.
|
|
320
|
-
* @param value The string to add LTR marks to.
|
|
321
|
-
* @returns The string with LTR marks.
|
|
322
|
-
*/
|
|
323
|
-
declare function addLTRMark(value: string | undefined): string;
|
|
324
|
-
|
|
325
|
-
/** Convert kebab-case string to PascalCase */
|
|
326
|
-
declare const kebabToPascal: (string: string) => string;
|
|
327
|
-
/** Convert camelCase string to kebab-case */
|
|
328
|
-
declare const camelToKebab: (string: string) => string;
|
|
329
|
-
declare const capitalize: <T extends string>(string: T) => Capitalize<T>;
|
|
330
|
-
declare const uncapitalize: <T extends string>(string: T) => Uncapitalize<T>;
|
|
331
|
-
declare const camelToHuman: (string: string) => string;
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* Like setTimeout(), but does not advance the clock if the program is
|
|
335
|
-
* stopped on a debugger breakpoint.
|
|
336
|
-
*
|
|
337
|
-
* @see https://devtopia.esri.com/WebGIS/arcgis-js-api/discussions/60405
|
|
338
|
-
*/
|
|
339
|
-
declare function devToolsAwareTimeout(callback: () => void, timeout: number): ReturnType<typeof setInterval>;
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* Safeguard to ensure that an item is not null.
|
|
343
|
-
* @param item The item to check.
|
|
344
|
-
* @returns Returns true if the item is not null.
|
|
345
|
-
*/
|
|
346
|
-
declare function isNotNull<T>(item: T | null): item is T;
|
|
347
|
-
/**
|
|
348
|
-
* Safe guard to ensure that an item is not undefined.
|
|
349
|
-
* @param item The item to check.
|
|
350
|
-
* @returns Returns true if the item is not undefined.
|
|
351
|
-
*/
|
|
352
|
-
declare function isNotUndefined<T>(item: T | undefined): item is T;
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* Allows to debounce a function.
|
|
356
|
-
* @template F Function type that should extend a function with any parameters and a return type.
|
|
357
|
-
* @param func Function to be debounced
|
|
358
|
-
* @param waitFor Debounce time in milliseconds
|
|
359
|
-
* @returns Returns a function that can be called to debounce the given function.
|
|
360
|
-
*/
|
|
361
|
-
declare function debounce<F extends (...args: Parameters<F>) => ReturnType<F>>(func: F, waitFor?: number): (...args: Parameters<F>) => void;
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
* Compares two url strings for their origin and returns true if they have the same origin.
|
|
365
|
-
* @param url1 First url string
|
|
366
|
-
* @param url2 Second url string
|
|
367
|
-
* @param ignoreProtocol Indicates if protocol comparison should be ignored
|
|
368
|
-
* @returns True if the two url strings have the same origin
|
|
369
|
-
*/
|
|
370
|
-
declare function hasSameOrigin(url1: string | null | undefined, url2: string | null | undefined, ignoreProtocol?: boolean): boolean;
|
|
371
|
-
/**
|
|
372
|
-
* Tests if a url string is a URL or not.
|
|
373
|
-
* @param url The url string to test
|
|
374
|
-
* @returns True if the string is a URL.
|
|
375
|
-
*/
|
|
376
|
-
declare function isURL(url: string): boolean;
|
|
377
|
-
|
|
378
|
-
export { Deferred, type FocusableElement, type GenericT9nStrings, type IHandle, type LocaleObserver, type Nil, type SupportedLocale, type Writable, addLTRMark, camelToHuman, camelToKebab, capitalize, classes, closestElement, createFilterExpression, debounce, defaultLocale, devToolsAwareTimeout, extractMinorVersion, fetchT9nStringsBundle, focusElement, generateGuid, getElementAttribute, getElementDir, getElementLocales, getElementTheme, getPreamble, hasSameOrigin, identity, isEsriInternalEnv, isNotNull, isNotUndefined, isURL, kebabToPascal, mappedFind, normalizeLocale, observeAncestorsMutation, quoteString, safeAsyncCall, safeCall, setFocusOnElement, setValuesInString, startLocaleObserver, supportedLocales, uncapitalize };
|
|
1
|
+
export * from './array-utils';
|
|
2
|
+
export * from './css-utils';
|
|
3
|
+
export * from './deferred';
|
|
4
|
+
export * from './dom';
|
|
5
|
+
export * from './errors';
|
|
6
|
+
export * from './guid';
|
|
7
|
+
export * from './intl';
|
|
8
|
+
export * from './preamble';
|
|
9
|
+
export * from './strings';
|
|
10
|
+
export * from './text';
|
|
11
|
+
export * from './timeouts';
|
|
12
|
+
export * from './type-guards';
|
|
13
|
+
export * from './types';
|
|
14
|
+
export * from './ui';
|
|
15
|
+
export * from './url';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// src/array-utils.ts
|
|
2
1
|
function mappedFind(array, callback) {
|
|
3
2
|
for (let i = 0; i < array.length; i++) {
|
|
4
3
|
const value = callback(array[i], i);
|
|
@@ -8,8 +7,6 @@ function mappedFind(array, callback) {
|
|
|
8
7
|
}
|
|
9
8
|
return;
|
|
10
9
|
}
|
|
11
|
-
|
|
12
|
-
// src/css-utils.ts
|
|
13
10
|
function classes(...classes2) {
|
|
14
11
|
const effectiveClasses = [];
|
|
15
12
|
for (let i = 0; i < classes2.length; i++) {
|
|
@@ -30,9 +27,7 @@ function classes(...classes2) {
|
|
|
30
27
|
effectiveClasses.length = 0;
|
|
31
28
|
return className;
|
|
32
29
|
}
|
|
33
|
-
|
|
34
|
-
// src/deferred.ts
|
|
35
|
-
var Deferred = class {
|
|
30
|
+
class Deferred {
|
|
36
31
|
/**
|
|
37
32
|
* Resolves the promise.
|
|
38
33
|
* @param value The value to resolve the promise with.
|
|
@@ -53,9 +48,7 @@ var Deferred = class {
|
|
|
53
48
|
this.reject = reject;
|
|
54
49
|
});
|
|
55
50
|
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// src/dom.ts
|
|
51
|
+
}
|
|
59
52
|
function inTargetElement(element, targetElement) {
|
|
60
53
|
let currentElement = element;
|
|
61
54
|
while (currentElement) {
|
|
@@ -82,7 +75,7 @@ function observeAncestorsMutation(element, attributeFilter, callback) {
|
|
|
82
75
|
}
|
|
83
76
|
});
|
|
84
77
|
}
|
|
85
|
-
|
|
78
|
+
const observers = {};
|
|
86
79
|
function observe(attributeFilter) {
|
|
87
80
|
const attributes = attributeFilter.join(",");
|
|
88
81
|
const previousObserver = observers[attributes];
|
|
@@ -190,8 +183,6 @@ function setFocusOnElement(ref, selector) {
|
|
|
190
183
|
}
|
|
191
184
|
void Promise.resolve(ref.componentOnReady?.()).then(() => setFocus(ref, selector));
|
|
192
185
|
}
|
|
193
|
-
|
|
194
|
-
// src/errors.ts
|
|
195
186
|
function isEsriInternalEnv() {
|
|
196
187
|
return typeof globalThis.process === "object" && !!process.env.ESRI_INTERNAL;
|
|
197
188
|
}
|
|
@@ -212,8 +203,6 @@ async function safeAsyncCall(callback, thisContext, ...rest) {
|
|
|
212
203
|
}
|
|
213
204
|
return void 0;
|
|
214
205
|
}
|
|
215
|
-
|
|
216
|
-
// src/guid.ts
|
|
217
206
|
function gen(count) {
|
|
218
207
|
let out = "";
|
|
219
208
|
for (let i = 0; i < count; i++) {
|
|
@@ -224,9 +213,7 @@ function gen(count) {
|
|
|
224
213
|
function generateGuid() {
|
|
225
214
|
return [gen(2), gen(1), gen(1), gen(1), gen(3)].join("-");
|
|
226
215
|
}
|
|
227
|
-
|
|
228
|
-
// src/intl.ts
|
|
229
|
-
var supportedLocalesArray = [
|
|
216
|
+
const supportedLocalesArray = [
|
|
230
217
|
"ar",
|
|
231
218
|
"bg",
|
|
232
219
|
"bs",
|
|
@@ -269,13 +256,16 @@ var supportedLocalesArray = [
|
|
|
269
256
|
"zh-HK",
|
|
270
257
|
"zh-TW"
|
|
271
258
|
];
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
259
|
+
const supportedLocales = /* @__PURE__ */ new Set(supportedLocalesArray);
|
|
260
|
+
const defaultLocale = "en";
|
|
261
|
+
const localeEquivalencies = {
|
|
275
262
|
// We use `pt-PT` as it will have the same translations as `pt`, which has no corresponding bundle
|
|
276
263
|
pt: "pt-PT",
|
|
277
264
|
// We support both 'nb' and 'no' (BCP 47) for Norwegian but only `no` has corresponding bundle
|
|
278
265
|
nb: "no",
|
|
266
|
+
// We support both 'nn' and 'no' (BCP 47) for Norwegian but only `no` has corresponding bundle
|
|
267
|
+
// See https://devtopia.esri.com/WebGIS/arcgis-web-components/issues/4667
|
|
268
|
+
nn: "no",
|
|
279
269
|
// We use `zh-CN` as base translation for chinese locales which has no corresponding bundle.
|
|
280
270
|
zh: "zh-CN"
|
|
281
271
|
};
|
|
@@ -285,7 +275,7 @@ async function fetchT9nStringsBundle(locale, assetsPath, prefix = "") {
|
|
|
285
275
|
t9nStringsCache[filePath] ?? (t9nStringsCache[filePath] = fetchBundle(locale, path));
|
|
286
276
|
return await t9nStringsCache[filePath];
|
|
287
277
|
}
|
|
288
|
-
|
|
278
|
+
const t9nStringsCache = {};
|
|
289
279
|
async function fetchBundle(locale, path) {
|
|
290
280
|
const filePath = `${path}${locale}.json`;
|
|
291
281
|
try {
|
|
@@ -342,7 +332,7 @@ function startLocaleObserver(element, getAssetsPath, onUpdated, assetName) {
|
|
|
342
332
|
queueMicrotask(callback);
|
|
343
333
|
return observeAncestorsMutation(element, ["lang"], callback);
|
|
344
334
|
}
|
|
345
|
-
async function updateComponentLocaleState(element, assetsPath, assetName = element.
|
|
335
|
+
async function updateComponentLocaleState(element, assetsPath, assetName = element.localName.split("-").slice(1).join("-")) {
|
|
346
336
|
const { lang, t9nLocale } = getElementLocales(element);
|
|
347
337
|
const t9nAssetsPath = `${assetsPath}/${assetName}/t9n`;
|
|
348
338
|
const prefix = `messages.`;
|
|
@@ -352,18 +342,14 @@ async function updateComponentLocaleState(element, assetsPath, assetName = eleme
|
|
|
352
342
|
);
|
|
353
343
|
return { lang, t9nLocale, t9nStrings };
|
|
354
344
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
var blurb = "All material copyright Esri, All Rights Reserved, unless otherwise specified.\nSee https://js.arcgis.com/{minorVersion}/esri/copyright.txt for details.\nv{version}";
|
|
358
|
-
var extractMinorVersion = (version) => {
|
|
345
|
+
const blurb = "All material copyright Esri, All Rights Reserved, unless otherwise specified.\nSee https://js.arcgis.com/{minorVersion}/esri/copyright.txt for details.\nv{version}";
|
|
346
|
+
const extractMinorVersion = (version) => {
|
|
359
347
|
const [major, minor] = version.split(".");
|
|
360
348
|
return `${major}.${minor}`;
|
|
361
349
|
};
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
var doubleQuote = '"';
|
|
366
|
-
var singleQuote = "'";
|
|
350
|
+
const getPreamble = (version) => blurb.replace("{minorVersion}", extractMinorVersion(version)).replace("{version}", version);
|
|
351
|
+
const doubleQuote = '"';
|
|
352
|
+
const singleQuote = "'";
|
|
367
353
|
function repeatString(value, n) {
|
|
368
354
|
return new Array(n + 1).join(value);
|
|
369
355
|
}
|
|
@@ -398,18 +384,14 @@ function setValuesInString(message, values = {}) {
|
|
|
398
384
|
return (message ?? "").replace(/\{(?<valueName>.*?)\}/gu, (match, valueName) => values[valueName] ?? match);
|
|
399
385
|
}
|
|
400
386
|
function addLTRMark(value) {
|
|
401
|
-
return
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
var uncapitalize = (string) => string.charAt(0).toLowerCase() + string.slice(1);
|
|
410
|
-
var camelToHuman = (string) => capitalize(string.replace(upperBeforeLower, (upper, remainder) => `${remainder === 0 ? "" : " "}${upper}`));
|
|
411
|
-
|
|
412
|
-
// src/timeouts.ts
|
|
387
|
+
return `${value ?? ""}`;
|
|
388
|
+
}
|
|
389
|
+
const kebabToPascal = (string) => string.split("-").map(capitalize).join("");
|
|
390
|
+
const camelToKebab = (string) => string.replace(upperBeforeLower, (upper, remainder) => `${remainder === 0 ? "" : "-"}${upper.toLowerCase()}`);
|
|
391
|
+
const upperBeforeLower = /[A-Z]+(?![a-z])|[A-Z]/gu;
|
|
392
|
+
const capitalize = (string) => string.charAt(0).toUpperCase() + string.slice(1);
|
|
393
|
+
const uncapitalize = (string) => string.charAt(0).toLowerCase() + string.slice(1);
|
|
394
|
+
const camelToHuman = (string) => capitalize(string.replace(upperBeforeLower, (upper, remainder) => `${remainder === 0 ? "" : " "}${upper}`));
|
|
413
395
|
function devToolsAwareTimeout(callback, timeout) {
|
|
414
396
|
const interval = timeout > longTimeoutThreshold ? longTimeoutInterval : timeout / shortTimeoutIntervals;
|
|
415
397
|
let elapsed = 0;
|
|
@@ -422,22 +404,16 @@ function devToolsAwareTimeout(callback, timeout) {
|
|
|
422
404
|
}, interval);
|
|
423
405
|
return reference;
|
|
424
406
|
}
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
// src/type-guards.ts
|
|
407
|
+
const longTimeoutThreshold = 4e3;
|
|
408
|
+
const longTimeoutInterval = 2e3;
|
|
409
|
+
const shortTimeoutIntervals = 4;
|
|
430
410
|
function isNotNull(item) {
|
|
431
411
|
return item !== null;
|
|
432
412
|
}
|
|
433
413
|
function isNotUndefined(item) {
|
|
434
414
|
return item !== void 0;
|
|
435
415
|
}
|
|
436
|
-
|
|
437
|
-
// src/types.ts
|
|
438
|
-
var identity = (value) => value;
|
|
439
|
-
|
|
440
|
-
// src/ui.ts
|
|
416
|
+
const identity = (value) => value;
|
|
441
417
|
function debounce(func, waitFor = 100) {
|
|
442
418
|
let timeout;
|
|
443
419
|
return (...args) => {
|
|
@@ -449,8 +425,6 @@ function debounce(func, waitFor = 100) {
|
|
|
449
425
|
timeout = setTimeout(later, waitFor);
|
|
450
426
|
};
|
|
451
427
|
}
|
|
452
|
-
|
|
453
|
-
// src/url.ts
|
|
454
428
|
function hasSameOrigin(url1, url2, ignoreProtocol = false) {
|
|
455
429
|
if (!url1 || !url2) {
|
|
456
430
|
return false;
|
package/dist/intl.d.cts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The interface for translated strings.
|
|
3
|
+
*/
|
|
4
|
+
export interface GenericT9nStrings {
|
|
5
|
+
[key: string]: GenericT9nStrings | string;
|
|
6
|
+
}
|
|
7
|
+
declare const supportedLocalesArray: readonly ["ar", "bg", "bs", "ca", "cs", "da", "de", "el", "en", "es", "et", "fi", "fr", "he", "hr", "hu", "id", "it", "ja", "ko", "lt", "lv", "nl", "nb", "no", "pl", "pt-BR", "pt-PT", "ro", "ru", "sk", "sl", "sr", "sv", "th", "tr", "uk", "vi", "zh-CN", "zh-HK", "zh-TW"];
|
|
8
|
+
/**
|
|
9
|
+
* The list of supported locales for ArcGIS Maps SDK for JavaScript components.
|
|
10
|
+
*/
|
|
11
|
+
export declare const supportedLocales: Set<"hr" | "th" | "tr" | "ar" | "bg" | "bs" | "ca" | "cs" | "da" | "de" | "el" | "en" | "es" | "et" | "fi" | "fr" | "he" | "hu" | "id" | "it" | "ja" | "ko" | "lt" | "lv" | "nl" | "nb" | "no" | "pl" | "pt-BR" | "pt-PT" | "ro" | "ru" | "sk" | "sl" | "sr" | "sv" | "uk" | "vi" | "zh-CN" | "zh-HK" | "zh-TW">;
|
|
12
|
+
export type SupportedLocale = (typeof supportedLocalesArray)[number];
|
|
13
|
+
export declare const defaultLocale = "en";
|
|
14
|
+
/**
|
|
15
|
+
* Fetch the T9N strings bundle for the given locale, assets path and prefix.
|
|
16
|
+
* The locale must be one of the supported locales.
|
|
17
|
+
* If the locale is not supported, it will default to 'en'.
|
|
18
|
+
* If the T9N strings bundle cannot be found, it will default to 'en'.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* Rather than using this function directly, prefer the `useT9n()` controller.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const t9nStrings = await fetchT9nStringsBundle("en", getAssetPath("./assets/coding-editor/t9n"), "messages.");
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function fetchT9nStringsBundle<Strings extends GenericT9nStrings>(
|
|
29
|
+
/** The locale for which to fetch the T9N strings */
|
|
30
|
+
locale: string,
|
|
31
|
+
/** The path to the assets folder where the T9N strings are located */
|
|
32
|
+
assetsPath: string,
|
|
33
|
+
/** The prefix to use for the T9N strings file name. */
|
|
34
|
+
prefix?: string): Promise<Strings>;
|
|
35
|
+
/**
|
|
36
|
+
* Get the locale of the given element.
|
|
37
|
+
* It will look for the lang attribute on the element and its ancestors.
|
|
38
|
+
* If not lang is found, it will default to 'en'.
|
|
39
|
+
*/
|
|
40
|
+
export declare function getElementLocales(element: HTMLElement): {
|
|
41
|
+
readonly lang: string;
|
|
42
|
+
readonly t9nLocale: SupportedLocale;
|
|
43
|
+
};
|
|
44
|
+
export declare function normalizeLocale(locale: string): SupportedLocale;
|
|
45
|
+
export type LocaleObserver<Strings extends GenericT9nStrings = GenericT9nStrings> = {
|
|
46
|
+
/** The T9N strings of the component */
|
|
47
|
+
t9nStrings: Strings;
|
|
48
|
+
/**
|
|
49
|
+
* The locale of the component set by the `lang` attribute on the component host element or one of its ancestors.
|
|
50
|
+
*/
|
|
51
|
+
lang: string;
|
|
52
|
+
/**
|
|
53
|
+
* The locale used by the component to load the T9N strings.
|
|
54
|
+
* It may be different than the locale of the component host element that was set by the `lang` attribute.
|
|
55
|
+
*/
|
|
56
|
+
t9nLocale: SupportedLocale;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Start the locale observer for the given component.
|
|
60
|
+
* The callback will be called when the locale changes for the component.
|
|
61
|
+
* It will observe the lang attribute on the component and its ancestors.
|
|
62
|
+
* The callback is called once at the beginning.
|
|
63
|
+
*
|
|
64
|
+
* @remarks
|
|
65
|
+
* Rather than using this function directly, prefer the `useT9n()` controller.
|
|
66
|
+
*/
|
|
67
|
+
export declare function startLocaleObserver<Strings extends GenericT9nStrings = GenericT9nStrings>(
|
|
68
|
+
/** The Web component HTML element that is doing the fetching */
|
|
69
|
+
element: HTMLElement,
|
|
70
|
+
/**
|
|
71
|
+
* The callback to get path to the assets folder where the T9N strings are
|
|
72
|
+
* located.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* () => getAssetPath("./assets")
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
getAssetsPath: () => string,
|
|
80
|
+
/** The callback to call when the locale changes */
|
|
81
|
+
onUpdated: (payload: LocaleObserver<Strings>) => void,
|
|
82
|
+
/**
|
|
83
|
+
* Optionally override the asset file name.
|
|
84
|
+
* Default file name is the component tag name without the part before the
|
|
85
|
+
* first dash (e.g. `arcgis-map` becomes `map`).
|
|
86
|
+
*
|
|
87
|
+
* Set to null if the component has no localization strings, but you still
|
|
88
|
+
* wish to use `startLocaleObserver` to get the locale information.
|
|
89
|
+
*/
|
|
90
|
+
assetName?: string | null): () => void;
|
|
91
|
+
export {};
|