@arcgis/components-utils 4.33.0-next.16 → 4.33.0-next.160
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 +35 -0
- package/dist/deferred.d.ts +35 -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 +148 -294
- package/dist/index.d.cts +15 -378
- package/dist/index.d.ts +15 -378
- package/dist/index.js +109 -191
- 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 +2 -2
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
function mappedFind(array, callback) {
|
|
1
|
+
const mappedFind = (array, callback) => {
|
|
3
2
|
for (let i = 0; i < array.length; i++) {
|
|
4
3
|
const value = callback(array[i], i);
|
|
5
4
|
if (value != null) {
|
|
@@ -7,10 +6,8 @@ function mappedFind(array, callback) {
|
|
|
7
6
|
}
|
|
8
7
|
}
|
|
9
8
|
return;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// src/css-utils.ts
|
|
13
|
-
function classes(...classes2) {
|
|
9
|
+
};
|
|
10
|
+
const classes = (...classes2) => {
|
|
14
11
|
const effectiveClasses = [];
|
|
15
12
|
for (let i = 0; i < classes2.length; i++) {
|
|
16
13
|
const arg = classes2[i];
|
|
@@ -29,21 +26,8 @@ function classes(...classes2) {
|
|
|
29
26
|
const className = effectiveClasses.join(" ");
|
|
30
27
|
effectiveClasses.length = 0;
|
|
31
28
|
return className;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// src/deferred.ts
|
|
35
|
-
var Deferred = class {
|
|
36
|
-
/**
|
|
37
|
-
* Resolves the promise.
|
|
38
|
-
* @param value The value to resolve the promise with.
|
|
39
|
-
*/
|
|
40
|
-
resolve(_value) {
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Rejects the promise.
|
|
44
|
-
*/
|
|
45
|
-
reject(_error) {
|
|
46
|
-
}
|
|
29
|
+
};
|
|
30
|
+
class Deferred {
|
|
47
31
|
/**
|
|
48
32
|
* Creates a new deferred promise.
|
|
49
33
|
*/
|
|
@@ -53,10 +37,8 @@ var Deferred = class {
|
|
|
53
37
|
this.reject = reject;
|
|
54
38
|
});
|
|
55
39
|
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// src/dom.ts
|
|
59
|
-
function inTargetElement(element, targetElement) {
|
|
40
|
+
}
|
|
41
|
+
const inTargetElement = (element, targetElement) => {
|
|
60
42
|
let currentElement = element;
|
|
61
43
|
while (currentElement) {
|
|
62
44
|
if (currentElement === targetElement) {
|
|
@@ -72,18 +54,18 @@ function inTargetElement(element, targetElement) {
|
|
|
72
54
|
}
|
|
73
55
|
}
|
|
74
56
|
return false;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const
|
|
57
|
+
};
|
|
58
|
+
const observeAncestorsMutation = (element, attributeFilter, callback) => {
|
|
59
|
+
const subscribe = observe(attributeFilter).subscribe;
|
|
78
60
|
return subscribe((mutations) => {
|
|
79
61
|
const matched = mutations.some((mutation) => inTargetElement(element, mutation.target));
|
|
80
62
|
if (matched) {
|
|
81
63
|
callback();
|
|
82
64
|
}
|
|
83
65
|
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
66
|
+
};
|
|
67
|
+
const observers = {};
|
|
68
|
+
const observe = (attributeFilter) => {
|
|
87
69
|
const attributes = attributeFilter.join(",");
|
|
88
70
|
const previousObserver = observers[attributes];
|
|
89
71
|
if (previousObserver !== void 0) {
|
|
@@ -99,7 +81,7 @@ function observe(attributeFilter) {
|
|
|
99
81
|
});
|
|
100
82
|
}
|
|
101
83
|
const observer = {
|
|
102
|
-
subscribe(callback) {
|
|
84
|
+
subscribe: (callback) => {
|
|
103
85
|
subscribers.add(callback);
|
|
104
86
|
return () => {
|
|
105
87
|
subscribers.delete(callback);
|
|
@@ -112,8 +94,8 @@ function observe(attributeFilter) {
|
|
|
112
94
|
};
|
|
113
95
|
observers[attributes] = observer;
|
|
114
96
|
return observer;
|
|
115
|
-
}
|
|
116
|
-
|
|
97
|
+
};
|
|
98
|
+
const closestElement = (base, selector) => {
|
|
117
99
|
let currentElement = base;
|
|
118
100
|
while (currentElement) {
|
|
119
101
|
const element = currentElement.closest?.(selector);
|
|
@@ -127,25 +109,19 @@ function closestElement(base, selector) {
|
|
|
127
109
|
currentElement = rootElement.host;
|
|
128
110
|
}
|
|
129
111
|
return null;
|
|
130
|
-
}
|
|
131
|
-
|
|
112
|
+
};
|
|
113
|
+
const getElementTheme = (base) => {
|
|
132
114
|
const themeElement = closestElement(base, ":is(.calcite-mode-light, .calcite-mode-dark)");
|
|
133
115
|
return themeElement?.classList.contains("calcite-mode-dark") ? "dark" : "light";
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
function getElementAttribute(el, prop, fallbackValue) {
|
|
116
|
+
};
|
|
117
|
+
const getElementDir = (el) => getElementAttribute(el, "dir", "ltr");
|
|
118
|
+
const getElementAttribute = (el, prop, fallbackValue) => {
|
|
139
119
|
const closest = closestElement(el, `[${prop}]`);
|
|
140
120
|
return closest?.getAttribute(prop) ?? fallbackValue;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
function hasSetFocus(ref) {
|
|
146
|
-
return typeof ref.setFocus === "function";
|
|
147
|
-
}
|
|
148
|
-
function setFocus(ref, selector = "") {
|
|
121
|
+
};
|
|
122
|
+
const isElement = (ref) => ref.nodeType === Node.ELEMENT_NODE;
|
|
123
|
+
const hasSetFocus = (ref) => typeof ref.setFocus === "function";
|
|
124
|
+
const setFocus = (ref, selector = "") => {
|
|
149
125
|
if (!isElement(ref)) {
|
|
150
126
|
return false;
|
|
151
127
|
}
|
|
@@ -169,8 +145,8 @@ function setFocus(ref, selector = "") {
|
|
|
169
145
|
}
|
|
170
146
|
}
|
|
171
147
|
return false;
|
|
172
|
-
}
|
|
173
|
-
async
|
|
148
|
+
};
|
|
149
|
+
const focusElement = async (el) => {
|
|
174
150
|
if (el == null) {
|
|
175
151
|
return;
|
|
176
152
|
}
|
|
@@ -179,8 +155,8 @@ async function focusElement(el) {
|
|
|
179
155
|
} else {
|
|
180
156
|
el.focus();
|
|
181
157
|
}
|
|
182
|
-
}
|
|
183
|
-
|
|
158
|
+
};
|
|
159
|
+
const setFocusOnElement = (ref, selector) => {
|
|
184
160
|
if (!ref?.shadowRoot) {
|
|
185
161
|
return;
|
|
186
162
|
}
|
|
@@ -189,104 +165,69 @@ function setFocusOnElement(ref, selector) {
|
|
|
189
165
|
return;
|
|
190
166
|
}
|
|
191
167
|
void Promise.resolve(ref.componentOnReady?.()).then(() => setFocus(ref, selector));
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
168
|
+
};
|
|
169
|
+
const isEsriInternalEnv = () => (
|
|
170
|
+
/*
|
|
171
|
+
* `globalThis.` is important here. Some bundlers remove the `typeof process`
|
|
172
|
+
* checks, but don't remove the usages of undefined variables - this can cause
|
|
173
|
+
* runtime error. By adding `globalThis.`, we avoid having `typeof process`
|
|
174
|
+
* check removed by the bundler.
|
|
175
|
+
* This does meant tree-shaking won't happen for the isEsriInternalEnv()
|
|
176
|
+
* check, but this is ok since this check is meant to always be behind the
|
|
177
|
+
* development/test guard.
|
|
178
|
+
* See https://devtopia.esri.com/WebGIS/arcgis-web-components/pull/2087#issuecomment-5152454
|
|
179
|
+
*/
|
|
180
|
+
typeof globalThis.process === "object" && !!process.env.ESRI_INTERNAL
|
|
181
|
+
);
|
|
182
|
+
const safeCall = (callback, thisContext, ...rest) => {
|
|
199
183
|
try {
|
|
200
184
|
return callback?.call(thisContext, ...rest);
|
|
201
185
|
} catch (error) {
|
|
202
186
|
console.error(error, callback);
|
|
203
187
|
}
|
|
204
188
|
return void 0;
|
|
205
|
-
}
|
|
206
|
-
async
|
|
189
|
+
};
|
|
190
|
+
const safeAsyncCall = async (callback, thisContext, ...rest) => {
|
|
207
191
|
try {
|
|
208
192
|
const result = callback?.call(thisContext, ...rest);
|
|
209
|
-
return
|
|
193
|
+
return await result;
|
|
210
194
|
} catch (error) {
|
|
211
195
|
console.error(error, callback);
|
|
212
196
|
}
|
|
213
197
|
return void 0;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// src/guid.ts
|
|
217
|
-
function gen(count) {
|
|
198
|
+
};
|
|
199
|
+
const gen = (count) => {
|
|
218
200
|
let out = "";
|
|
219
201
|
for (let i = 0; i < count; i++) {
|
|
220
202
|
out += ((1 + Math.random()) * 65536 | 0).toString(16).substring(1);
|
|
221
203
|
}
|
|
222
204
|
return out;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
"bg",
|
|
232
|
-
"bs",
|
|
233
|
-
"ca",
|
|
234
|
-
"cs",
|
|
235
|
-
"da",
|
|
236
|
-
"de",
|
|
237
|
-
"el",
|
|
238
|
-
"en",
|
|
239
|
-
"es",
|
|
240
|
-
"et",
|
|
241
|
-
"fi",
|
|
242
|
-
"fr",
|
|
243
|
-
"he",
|
|
244
|
-
"hr",
|
|
245
|
-
"hu",
|
|
246
|
-
"id",
|
|
247
|
-
"it",
|
|
248
|
-
"ja",
|
|
249
|
-
"ko",
|
|
250
|
-
"lt",
|
|
251
|
-
"lv",
|
|
252
|
-
"nl",
|
|
253
|
-
"nb",
|
|
254
|
-
"no",
|
|
255
|
-
"pl",
|
|
256
|
-
"pt-BR",
|
|
257
|
-
"pt-PT",
|
|
258
|
-
"ro",
|
|
259
|
-
"ru",
|
|
260
|
-
"sk",
|
|
261
|
-
"sl",
|
|
262
|
-
"sr",
|
|
263
|
-
"sv",
|
|
264
|
-
"th",
|
|
265
|
-
"tr",
|
|
266
|
-
"uk",
|
|
267
|
-
"vi",
|
|
268
|
-
"zh-CN",
|
|
269
|
-
"zh-HK",
|
|
270
|
-
"zh-TW"
|
|
271
|
-
];
|
|
272
|
-
var supportedLocales = /* @__PURE__ */ new Set(supportedLocalesArray);
|
|
273
|
-
var defaultLocale = "en";
|
|
274
|
-
var localeEquivalencies = {
|
|
205
|
+
};
|
|
206
|
+
const generateGuid = () => [gen(2), gen(1), gen(1), gen(1), gen(3)].join("-");
|
|
207
|
+
const supportedLocalesArray = "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".split(
|
|
208
|
+
","
|
|
209
|
+
);
|
|
210
|
+
const supportedLocales = /* @__PURE__ */ new Set(supportedLocalesArray);
|
|
211
|
+
const defaultLocale = "en";
|
|
212
|
+
const localeEquivalencies = {
|
|
275
213
|
// We use `pt-PT` as it will have the same translations as `pt`, which has no corresponding bundle
|
|
276
214
|
pt: "pt-PT",
|
|
277
215
|
// We support both 'nb' and 'no' (BCP 47) for Norwegian but only `no` has corresponding bundle
|
|
278
216
|
nb: "no",
|
|
217
|
+
// We support both 'nn' and 'no' (BCP 47) for Norwegian but only `no` has corresponding bundle
|
|
218
|
+
// See https://devtopia.esri.com/WebGIS/arcgis-web-components/issues/4667
|
|
219
|
+
nn: "no",
|
|
279
220
|
// We use `zh-CN` as base translation for chinese locales which has no corresponding bundle.
|
|
280
221
|
zh: "zh-CN"
|
|
281
222
|
};
|
|
282
|
-
async
|
|
223
|
+
const fetchT9nStringsBundle = async (locale, assetsPath, prefix = "") => {
|
|
283
224
|
const path = `${assetsPath}/${prefix}`;
|
|
284
225
|
const filePath = `${path}${locale}.json`;
|
|
285
226
|
t9nStringsCache[filePath] ?? (t9nStringsCache[filePath] = fetchBundle(locale, path));
|
|
286
227
|
return await t9nStringsCache[filePath];
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
async
|
|
228
|
+
};
|
|
229
|
+
const t9nStringsCache = {};
|
|
230
|
+
const fetchBundle = async (locale, path) => {
|
|
290
231
|
const filePath = `${path}${locale}.json`;
|
|
291
232
|
try {
|
|
292
233
|
const response = await fetch(filePath);
|
|
@@ -310,12 +251,12 @@ async function fetchBundle(locale, path) {
|
|
|
310
251
|
return {};
|
|
311
252
|
}
|
|
312
253
|
return await fetchBundle(defaultLocale, path);
|
|
313
|
-
}
|
|
314
|
-
|
|
254
|
+
};
|
|
255
|
+
const getElementLocales = (element) => {
|
|
315
256
|
const lang = getElementAttribute(element, "lang", globalThis.navigator?.language || defaultLocale);
|
|
316
257
|
return { lang, t9nLocale: normalizeLocale(lang) };
|
|
317
|
-
}
|
|
318
|
-
|
|
258
|
+
};
|
|
259
|
+
const normalizeLocale = (locale) => {
|
|
319
260
|
const [rawLanguageCode, regionCode] = locale.split("-");
|
|
320
261
|
const languageCode = rawLanguageCode.toLowerCase();
|
|
321
262
|
let normalizedLocale = languageCode;
|
|
@@ -330,10 +271,10 @@ function normalizeLocale(locale) {
|
|
|
330
271
|
return normalizeLocale(languageCode);
|
|
331
272
|
}
|
|
332
273
|
return defaultLocale;
|
|
333
|
-
}
|
|
334
|
-
|
|
274
|
+
};
|
|
275
|
+
const startLocaleObserver = (element, getAssetsPath, onUpdated, assetName) => {
|
|
335
276
|
let result = void 0;
|
|
336
|
-
const callback = () =>
|
|
277
|
+
const callback = () => updateComponentLocaleState(element, getAssetsPath(), assetName).then((newResult) => {
|
|
337
278
|
if (result?.lang !== newResult.lang || result.t9nLocale !== newResult.t9nLocale || result.t9nStrings !== newResult.t9nStrings) {
|
|
338
279
|
onUpdated(newResult);
|
|
339
280
|
}
|
|
@@ -341,8 +282,8 @@ function startLocaleObserver(element, getAssetsPath, onUpdated, assetName) {
|
|
|
341
282
|
}).catch(console.error);
|
|
342
283
|
queueMicrotask(callback);
|
|
343
284
|
return observeAncestorsMutation(element, ["lang"], callback);
|
|
344
|
-
}
|
|
345
|
-
async
|
|
285
|
+
};
|
|
286
|
+
const updateComponentLocaleState = async (element, assetsPath, assetName = element.localName.split("-").slice(1).join("-")) => {
|
|
346
287
|
const { lang, t9nLocale } = getElementLocales(element);
|
|
347
288
|
const t9nAssetsPath = `${assetsPath}/${assetName}/t9n`;
|
|
348
289
|
const prefix = `messages.`;
|
|
@@ -351,23 +292,17 @@ async function updateComponentLocaleState(element, assetsPath, assetName = eleme
|
|
|
351
292
|
assetName === null ? {} : await fetchT9nStringsBundle(t9nLocale, t9nAssetsPath, prefix)
|
|
352
293
|
);
|
|
353
294
|
return { lang, t9nLocale, t9nStrings };
|
|
354
|
-
}
|
|
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) => {
|
|
295
|
+
};
|
|
296
|
+
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}";
|
|
297
|
+
const extractMinorVersion = (version) => {
|
|
359
298
|
const [major, minor] = version.split(".");
|
|
360
299
|
return `${major}.${minor}`;
|
|
361
300
|
};
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
function repeatString(value, n) {
|
|
368
|
-
return new Array(n + 1).join(value);
|
|
369
|
-
}
|
|
370
|
-
function quoteString(value) {
|
|
301
|
+
const getPreamble = (version) => blurb.replace("{minorVersion}", extractMinorVersion(version)).replace("{version}", version);
|
|
302
|
+
const doubleQuote = '"';
|
|
303
|
+
const singleQuote = "'";
|
|
304
|
+
const repeatString = (value, n) => new Array(n + 1).join(value);
|
|
305
|
+
const quoteString = (value) => {
|
|
371
306
|
let quote = doubleQuote;
|
|
372
307
|
let alternateQuote = singleQuote;
|
|
373
308
|
const avoidEscape = value.includes(quote) && !value.includes(alternateQuote);
|
|
@@ -389,28 +324,23 @@ function quoteString(value) {
|
|
|
389
324
|
(_, boundaryChar, leadingEscapedSlashes, quoteChars) => boundaryChar + leadingEscapedSlashes + repeatString(`\\${quote}`, quoteChars.length)
|
|
390
325
|
);
|
|
391
326
|
return quote + value + quote;
|
|
392
|
-
}
|
|
393
|
-
|
|
327
|
+
};
|
|
328
|
+
const createFilterExpression = (filterWord) => {
|
|
394
329
|
const sanitizedWord = filterWord ? filterWord.replaceAll(/[-[\]/{}()*+?.\\^$|]/gu, "\\$&") : "^.*$";
|
|
395
330
|
return new RegExp(sanitizedWord, "i");
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
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
|
|
413
|
-
function devToolsAwareTimeout(callback, timeout) {
|
|
331
|
+
};
|
|
332
|
+
const setValuesInString = (message, values = {}) => (message ?? "").replace(/\{(?<valueName>.*?)\}/gu, (match, valueName) => values[valueName] ?? match);
|
|
333
|
+
const addLTRMark = (value) => (
|
|
334
|
+
// Make sure the string value is LTR. This prevent issues with RTL language used in LTR containers.
|
|
335
|
+
`${value ?? ""}`
|
|
336
|
+
);
|
|
337
|
+
const kebabToPascal = (string) => string.split("-").map(capitalize).join("");
|
|
338
|
+
const camelToKebab = (string) => string.replace(upperBeforeLower, (upper, remainder) => `${remainder === 0 ? "" : "-"}${upper.toLowerCase()}`);
|
|
339
|
+
const upperBeforeLower = /[A-Z]+(?![a-z])|[A-Z]/gu;
|
|
340
|
+
const capitalize = (string) => string.charAt(0).toUpperCase() + string.slice(1);
|
|
341
|
+
const uncapitalize = (string) => string.charAt(0).toLowerCase() + string.slice(1);
|
|
342
|
+
const camelToHuman = (string) => capitalize(string.replace(upperBeforeLower, (upper, remainder) => `${remainder === 0 ? "" : " "}${upper}`));
|
|
343
|
+
const devToolsAwareTimeout = (callback, timeout) => {
|
|
414
344
|
const interval = timeout > longTimeoutThreshold ? longTimeoutInterval : timeout / shortTimeoutIntervals;
|
|
415
345
|
let elapsed = 0;
|
|
416
346
|
const reference = setInterval(() => {
|
|
@@ -421,24 +351,14 @@ function devToolsAwareTimeout(callback, timeout) {
|
|
|
421
351
|
}
|
|
422
352
|
}, interval);
|
|
423
353
|
return reference;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
}
|
|
433
|
-
function isNotUndefined(item) {
|
|
434
|
-
return item !== void 0;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
// src/types.ts
|
|
438
|
-
var identity = (value) => value;
|
|
439
|
-
|
|
440
|
-
// src/ui.ts
|
|
441
|
-
function debounce(func, waitFor = 100) {
|
|
354
|
+
};
|
|
355
|
+
const longTimeoutThreshold = 4e3;
|
|
356
|
+
const longTimeoutInterval = 2e3;
|
|
357
|
+
const shortTimeoutIntervals = 4;
|
|
358
|
+
const isNotNull = (item) => item !== null;
|
|
359
|
+
const isNotUndefined = (item) => item !== void 0;
|
|
360
|
+
const identity = (value) => value;
|
|
361
|
+
const debounce = (func, waitFor = 100) => {
|
|
442
362
|
let timeout;
|
|
443
363
|
return (...args) => {
|
|
444
364
|
const later = () => {
|
|
@@ -448,10 +368,8 @@ function debounce(func, waitFor = 100) {
|
|
|
448
368
|
clearTimeout(timeout);
|
|
449
369
|
timeout = setTimeout(later, waitFor);
|
|
450
370
|
};
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
// src/url.ts
|
|
454
|
-
function hasSameOrigin(url1, url2, ignoreProtocol = false) {
|
|
371
|
+
};
|
|
372
|
+
const hasSameOrigin = (url1, url2, ignoreProtocol = false) => {
|
|
455
373
|
if (!url1 || !url2) {
|
|
456
374
|
return false;
|
|
457
375
|
}
|
|
@@ -464,15 +382,15 @@ function hasSameOrigin(url1, url2, ignoreProtocol = false) {
|
|
|
464
382
|
return false;
|
|
465
383
|
}
|
|
466
384
|
return url1Obj.host.toLowerCase() === url2Obj.host.toLowerCase() && url1Obj.port === url2Obj.port;
|
|
467
|
-
}
|
|
468
|
-
|
|
385
|
+
};
|
|
386
|
+
const isURL = (url) => {
|
|
469
387
|
try {
|
|
470
388
|
new URL(url);
|
|
471
389
|
return true;
|
|
472
390
|
} catch (e) {
|
|
473
391
|
return false;
|
|
474
392
|
}
|
|
475
|
-
}
|
|
393
|
+
};
|
|
476
394
|
export {
|
|
477
395
|
Deferred,
|
|
478
396
|
addLTRMark,
|
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: ["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 const 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 const getElementLocales: (element: HTMLElement) => {
|
|
41
|
+
readonly lang: string;
|
|
42
|
+
readonly t9nLocale: SupportedLocale;
|
|
43
|
+
};
|
|
44
|
+
export declare const 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 const 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 {};
|
package/dist/intl.d.ts
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: ["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 const 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 const getElementLocales: (element: HTMLElement) => {
|
|
41
|
+
readonly lang: string;
|
|
42
|
+
readonly t9nLocale: SupportedLocale;
|
|
43
|
+
};
|
|
44
|
+
export declare const 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 const 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 {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const extractMinorVersion: (version: string) => string;
|
|
2
|
+
/**
|
|
3
|
+
* 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.
|
|
4
|
+
* The preamble text contains the version number and a link to the license.
|
|
5
|
+
* The version number is typically extracted from the package.json file.
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const preamble = getPreamble("4.18.2-beta.1");
|
|
9
|
+
* console.log(preamble);
|
|
10
|
+
* // All material copyright Esri, All Rights Reserved, unless otherwise specified.
|
|
11
|
+
* // See https://js.arcgis.com/4.18/esri/copyright.txt for details.
|
|
12
|
+
* // v4.18.2-beta.1
|
|
13
|
+
* ```
|
|
14
|
+
* @param version the version number, typically coming from package.json.
|
|
15
|
+
* @returns a string containing the preamble text.
|
|
16
|
+
*/
|
|
17
|
+
export declare const getPreamble: (version: string) => string;
|