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