@arcgis/toolkit 5.1.0-next.9 → 5.1.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.
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const log_index = require("../log/index.cjs");
3
4
  function slotChangeHasContent(event) {
4
5
  return slotChangeHasAssignedElement(event) || slotChangeHasTextContent(event);
5
6
  }
@@ -29,6 +30,33 @@ function getSlotAssignedElements(slot, selector) {
29
30
  });
30
31
  return selector ? assignedElements.filter((element) => element.matches(selector)) : assignedElements;
31
32
  }
33
+ const allowedTags = ["arcgis-map", "arcgis-scene", "arcgis-link-chart"];
34
+ function resolveReferenceElement(component, referenceElementString) {
35
+ const referenceElement = referenceElementString ?? component.referenceElement;
36
+ if (typeof referenceElement !== "string") {
37
+ return referenceElement ?? void 0;
38
+ }
39
+ const isComplexSelector = referenceElement.includes("#") || referenceElement.includes(".") || referenceElement.includes("[");
40
+ const rootNode = component.el.getRootNode();
41
+ const resolved = (isComplexSelector ? void 0 : rootNode.querySelector(`#${referenceElement}`)) ?? rootNode.querySelector(referenceElement) ?? (isComplexSelector ? void 0 : getClosestElement(component.el, `#${referenceElement}`)) ?? getClosestElement(component.el, referenceElement);
42
+ if (resolved == null) {
43
+ log_index.log(
44
+ "error",
45
+ component,
46
+ `Expected property \`referenceElement\` to resolve to an <arcgis-map>, <arcgis-scene>, or <arcgis-link-chart> element, but no element matched \`${referenceElement}\`.`
47
+ );
48
+ return void 0;
49
+ }
50
+ if (!allowedTags.includes(resolved.localName)) {
51
+ log_index.log(
52
+ "error",
53
+ component,
54
+ `Expected property \`referenceElement\` to point to an <arcgis-map>, <arcgis-scene>, or <arcgis-link-chart> element, but instead found <${resolved?.localName}>.`,
55
+ { detail: { referenceElement, resolved } }
56
+ );
57
+ }
58
+ return resolved ?? void 0;
59
+ }
32
60
  const classes = (...classes2) => {
33
61
  const effectiveClasses = [];
34
62
  for (let i = 0; i < classes2.length; ++i) {
@@ -117,7 +145,7 @@ const getClosestElement = (base, selector) => {
117
145
  if (rootElement === globalThis.document) {
118
146
  return;
119
147
  }
120
- currentElement = rootElement.host;
148
+ currentElement = rootElement?.host;
121
149
  }
122
150
  return;
123
151
  };
@@ -186,6 +214,7 @@ exports.getClosestElement = getClosestElement;
186
214
  exports.getElementAttribute = getElementAttribute;
187
215
  exports.getSlotAssignedElements = getSlotAssignedElements;
188
216
  exports.observeAncestorsMutation = observeAncestorsMutation;
217
+ exports.resolveReferenceElement = resolveReferenceElement;
189
218
  exports.setFocusOnElement = setFocusOnElement;
190
219
  exports.slotChangeGetAssignedElements = slotChangeGetAssignedElements;
191
220
  exports.slotChangeGetAssignedNodes = slotChangeGetAssignedNodes;
@@ -1,5 +1,6 @@
1
1
  import { nil } from '../type/index.ts';
2
2
  export * from './slots.ts';
3
+ export * from './reference-element.ts';
3
4
  /**
4
5
  * Combine multiple class names into a single string.
5
6
  *
@@ -1,5 +1,6 @@
1
1
  import { nil } from '../type/index.ts';
2
2
  export * from './slots.ts';
3
+ export * from './reference-element.ts';
3
4
  /**
4
5
  * Combine multiple class names into a single string.
5
6
  *
package/dist/dom/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { log } from "../log/index.js";
1
2
  function slotChangeHasContent(event) {
2
3
  return slotChangeHasAssignedElement(event) || slotChangeHasTextContent(event);
3
4
  }
@@ -27,6 +28,33 @@ function getSlotAssignedElements(slot, selector) {
27
28
  });
28
29
  return selector ? assignedElements.filter((element) => element.matches(selector)) : assignedElements;
29
30
  }
31
+ const allowedTags = ["arcgis-map", "arcgis-scene", "arcgis-link-chart"];
32
+ function resolveReferenceElement(component, referenceElementString) {
33
+ const referenceElement = referenceElementString ?? component.referenceElement;
34
+ if (typeof referenceElement !== "string") {
35
+ return referenceElement ?? void 0;
36
+ }
37
+ const isComplexSelector = referenceElement.includes("#") || referenceElement.includes(".") || referenceElement.includes("[");
38
+ const rootNode = component.el.getRootNode();
39
+ const resolved = (isComplexSelector ? void 0 : rootNode.querySelector(`#${referenceElement}`)) ?? rootNode.querySelector(referenceElement) ?? (isComplexSelector ? void 0 : getClosestElement(component.el, `#${referenceElement}`)) ?? getClosestElement(component.el, referenceElement);
40
+ if (resolved == null) {
41
+ log(
42
+ "error",
43
+ component,
44
+ `Expected property \`referenceElement\` to resolve to an <arcgis-map>, <arcgis-scene>, or <arcgis-link-chart> element, but no element matched \`${referenceElement}\`.`
45
+ );
46
+ return void 0;
47
+ }
48
+ if (!allowedTags.includes(resolved.localName)) {
49
+ log(
50
+ "error",
51
+ component,
52
+ `Expected property \`referenceElement\` to point to an <arcgis-map>, <arcgis-scene>, or <arcgis-link-chart> element, but instead found <${resolved?.localName}>.`,
53
+ { detail: { referenceElement, resolved } }
54
+ );
55
+ }
56
+ return resolved ?? void 0;
57
+ }
30
58
  const classes = (...classes2) => {
31
59
  const effectiveClasses = [];
32
60
  for (let i = 0; i < classes2.length; ++i) {
@@ -115,7 +143,7 @@ const getClosestElement = (base, selector) => {
115
143
  if (rootElement === globalThis.document) {
116
144
  return;
117
145
  }
118
- currentElement = rootElement.host;
146
+ currentElement = rootElement?.host;
119
147
  }
120
148
  return;
121
149
  };
@@ -185,6 +213,7 @@ export {
185
213
  getElementAttribute,
186
214
  getSlotAssignedElements,
187
215
  observeAncestorsMutation,
216
+ resolveReferenceElement,
188
217
  setFocusOnElement,
189
218
  slotChangeGetAssignedElements,
190
219
  slotChangeGetAssignedNodes,
@@ -0,0 +1,6 @@
1
+ type ArcgisComponentBase<T> = {
2
+ el: HTMLElement;
3
+ referenceElement?: T | string | null | undefined;
4
+ };
5
+ export declare function resolveReferenceElement<T extends Element>(component: ArcgisComponentBase<T>, referenceElementString?: ArcgisComponentBase<T>["referenceElement"] | string): T | undefined;
6
+ export {};
@@ -0,0 +1,6 @@
1
+ type ArcgisComponentBase<T> = {
2
+ el: HTMLElement;
3
+ referenceElement?: T | string | null | undefined;
4
+ };
5
+ export declare function resolveReferenceElement<T extends Element>(component: ArcgisComponentBase<T>, referenceElementString?: ArcgisComponentBase<T>["referenceElement"] | string): T | undefined;
6
+ export {};
@@ -12,8 +12,10 @@ const supportedLocales = (
12
12
  const defaultLocale = "en";
13
13
  const localeEquivalencies = {
14
14
  //#region localeEquivalencies
15
- // We use `pt-PT` as it will have the same translations as `pt`, which has no corresponding bundle
16
- pt: "pt-PT",
15
+ // Locale equivalencies aligned with ArcGIS Maps SDK for JavaScript:
16
+ // https://developers.arcgis.com/javascript/latest/localization/#locale-support
17
+ // We resolve to `pt-BR` as it will have the same translations as `pt`, which has no corresponding bundle
18
+ pt: "pt-BR",
17
19
  // We support both 'nb' and 'no' (BCP 47) for Norwegian but only `no` has corresponding bundle
18
20
  nb: "no",
19
21
  // We support both 'nn' and 'no' (BCP 47) for Norwegian but only `no` has corresponding bundle
@@ -65,6 +65,9 @@ export declare const getElementLocale: (element: HTMLElement) => {
65
65
  * Try to parse any language string into one of the locales supported by WebGIS SDK.
66
66
  *
67
67
  * @remarks
68
+ * Follows the ArcGIS Maps SDK for JavaScript locale support:
69
+ * https://developers.arcgis.com/javascript/latest/localization/#locale-support
70
+ *
68
71
  * If language includes a region code, but we don't have a bundle for it, the
69
72
  * language is normalized to the language code only.
70
73
  */
@@ -65,6 +65,9 @@ export declare const getElementLocale: (element: HTMLElement) => {
65
65
  * Try to parse any language string into one of the locales supported by WebGIS SDK.
66
66
  *
67
67
  * @remarks
68
+ * Follows the ArcGIS Maps SDK for JavaScript locale support:
69
+ * https://developers.arcgis.com/javascript/latest/localization/#locale-support
70
+ *
68
71
  * If language includes a region code, but we don't have a bundle for it, the
69
72
  * language is normalized to the language code only.
70
73
  */
@@ -10,8 +10,10 @@ const supportedLocales = (
10
10
  const defaultLocale = "en";
11
11
  const localeEquivalencies = {
12
12
  //#region localeEquivalencies
13
- // We use `pt-PT` as it will have the same translations as `pt`, which has no corresponding bundle
14
- pt: "pt-PT",
13
+ // Locale equivalencies aligned with ArcGIS Maps SDK for JavaScript:
14
+ // https://developers.arcgis.com/javascript/latest/localization/#locale-support
15
+ // We resolve to `pt-BR` as it will have the same translations as `pt`, which has no corresponding bundle
16
+ pt: "pt-BR",
15
17
  // We support both 'nb' and 'no' (BCP 47) for Norwegian but only `no` has corresponding bundle
16
18
  nb: "no",
17
19
  // We support both 'nn' and 'no' (BCP 47) for Norwegian but only `no` has corresponding bundle
@@ -11,6 +11,20 @@ class Deferred {
11
11
  });
12
12
  }
13
13
  }
14
+ async function forEachWithConcurrency(items, concurrency, callback) {
15
+ if (items.length === 0) {
16
+ return;
17
+ }
18
+ let index = 0;
19
+ async function consumeItems() {
20
+ while (index < items.length) {
21
+ const item = items[index];
22
+ index += 1;
23
+ await callback(item);
24
+ }
25
+ }
26
+ await Promise.all(Array.from({ length: Math.min(concurrency, items.length) }, async () => await consumeItems()));
27
+ }
14
28
  const devToolsAwareTimeout = (callback, timeout) => {
15
29
  const interval = timeout > longTimeoutThreshold ? longTimeoutInterval : timeout / shortTimeoutIntervals;
16
30
  let elapsed = 0;
@@ -28,3 +42,4 @@ const longTimeoutInterval = 2e3;
28
42
  const shortTimeoutIntervals = 4;
29
43
  exports.Deferred = Deferred;
30
44
  exports.devToolsAwareTimeout = devToolsAwareTimeout;
45
+ exports.forEachWithConcurrency = forEachWithConcurrency;
@@ -37,6 +37,20 @@ export interface Deferred<T> {
37
37
  */
38
38
  reject(_error: unknown): void;
39
39
  }
40
+ /**
41
+ * Execute async callbacks against a list with a fixed number of in-flight
42
+ * operations.
43
+ * Useful for rate-limiting or to avoid overwhelming resources with too many concurrent operations.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * const items = [...lotsOfItems];
48
+ * await forEachWithConcurrency(items, 5, async (item) => {
49
+ * await doSomethingAsync(item);
50
+ * });
51
+ * ```
52
+ */
53
+ export declare function forEachWithConcurrency<T>(items: readonly T[], concurrency: number, callback: (item: T) => Promise<void>): Promise<void>;
40
54
  /**
41
55
  * Like setTimeout(), but does not advance the clock if the program is
42
56
  * stopped on a debugger breakpoint.
@@ -37,6 +37,20 @@ export interface Deferred<T> {
37
37
  */
38
38
  reject(_error: unknown): void;
39
39
  }
40
+ /**
41
+ * Execute async callbacks against a list with a fixed number of in-flight
42
+ * operations.
43
+ * Useful for rate-limiting or to avoid overwhelming resources with too many concurrent operations.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * const items = [...lotsOfItems];
48
+ * await forEachWithConcurrency(items, 5, async (item) => {
49
+ * await doSomethingAsync(item);
50
+ * });
51
+ * ```
52
+ */
53
+ export declare function forEachWithConcurrency<T>(items: readonly T[], concurrency: number, callback: (item: T) => Promise<void>): Promise<void>;
40
54
  /**
41
55
  * Like setTimeout(), but does not advance the clock if the program is
42
56
  * stopped on a debugger breakpoint.
@@ -9,6 +9,20 @@ class Deferred {
9
9
  });
10
10
  }
11
11
  }
12
+ async function forEachWithConcurrency(items, concurrency, callback) {
13
+ if (items.length === 0) {
14
+ return;
15
+ }
16
+ let index = 0;
17
+ async function consumeItems() {
18
+ while (index < items.length) {
19
+ const item = items[index];
20
+ index += 1;
21
+ await callback(item);
22
+ }
23
+ }
24
+ await Promise.all(Array.from({ length: Math.min(concurrency, items.length) }, async () => await consumeItems()));
25
+ }
12
26
  const devToolsAwareTimeout = (callback, timeout) => {
13
27
  const interval = timeout > longTimeoutThreshold ? longTimeoutInterval : timeout / shortTimeoutIntervals;
14
28
  let elapsed = 0;
@@ -26,5 +40,6 @@ const longTimeoutInterval = 2e3;
26
40
  const shortTimeoutIntervals = 4;
27
41
  export {
28
42
  Deferred,
29
- devToolsAwareTimeout
43
+ devToolsAwareTimeout,
44
+ forEachWithConcurrency
30
45
  };
@@ -62,15 +62,18 @@ export declare const addLtrMark: (value: string | undefined) => string;
62
62
  export type UUID = ReturnType<typeof crypto.randomUUID>;
63
63
  /**
64
64
  * Generate a GUID string.
65
+ *
66
+ * If your component is using shadow root, the DOM element IDs do not need
67
+ * to be globally unique - IDs are scoped to the shadow root.
68
+ *
69
+ * Avoid using GUID and other non-deterministic output in render() as they
70
+ * cause SSR hydration issues and snapshot test instability.
71
+ *
65
72
  * @example
66
73
  * ```ts
67
74
  * const id = generateGuid();
68
75
  * // 00000000-0000-0000-0000-000000000000.
69
76
  * ```
70
- *
71
- * @remarks
72
- * If your component is using shadow root, the DOM element IDs do not need
73
- * to be globally unique.
74
77
  */
75
78
  export declare const generateGuid: () => UUID;
76
79
  /**
@@ -89,7 +92,7 @@ export declare const getMinorVersion: (version: string) => string;
89
92
  * The preamble text contains the version number and a link to the license.
90
93
  * The version number should normally come from package.json.
91
94
  *
92
- * @see https://webgis.esri.com/webgis/platform-guidelines/licensing
95
+ * @see https://webgis.esri.com/sdk/contributing/licensing
93
96
  * @example
94
97
  * ```ts
95
98
  * const preamble = getPreamble("5.0.1-next.456");
@@ -62,15 +62,18 @@ export declare const addLtrMark: (value: string | undefined) => string;
62
62
  export type UUID = ReturnType<typeof crypto.randomUUID>;
63
63
  /**
64
64
  * Generate a GUID string.
65
+ *
66
+ * If your component is using shadow root, the DOM element IDs do not need
67
+ * to be globally unique - IDs are scoped to the shadow root.
68
+ *
69
+ * Avoid using GUID and other non-deterministic output in render() as they
70
+ * cause SSR hydration issues and snapshot test instability.
71
+ *
65
72
  * @example
66
73
  * ```ts
67
74
  * const id = generateGuid();
68
75
  * // 00000000-0000-0000-0000-000000000000.
69
76
  * ```
70
- *
71
- * @remarks
72
- * If your component is using shadow root, the DOM element IDs do not need
73
- * to be globally unique.
74
77
  */
75
78
  export declare const generateGuid: () => UUID;
76
79
  /**
@@ -89,7 +92,7 @@ export declare const getMinorVersion: (version: string) => string;
89
92
  * The preamble text contains the version number and a link to the license.
90
93
  * The version number should normally come from package.json.
91
94
  *
92
- * @see https://webgis.esri.com/webgis/platform-guidelines/licensing
95
+ * @see https://webgis.esri.com/sdk/contributing/licensing
93
96
  * @example
94
97
  * ```ts
95
98
  * const preamble = getPreamble("5.0.1-next.456");
@@ -4,7 +4,7 @@
4
4
  */
5
5
  export type nil = null | undefined;
6
6
  /**
7
- * @deprecated Import from `__esri.IHandle` instead
7
+ * @deprecated import type { ResourceHandle } from "@arcgis/core/core/Handles.js";
8
8
  */
9
9
  export type IHandle = {
10
10
  remove: () => void;
@@ -18,7 +18,7 @@ export type Nil = nil;
18
18
  * This complements the TypeScript's `satisfies` operator.
19
19
  *
20
20
  * See usage examples:
21
- * https://webgis.esri.com/webgis/additional-resources/typescript-tips#use-satisfies-operator-for-type-tests
21
+ * https://webgis.esri.com/sdk/resources/typescript-tips#use-satisfies-operator-for-type-tests
22
22
  *
23
23
  * During production end-application build, such type tests will be removed as
24
24
  * they have no runtime impact.
@@ -4,7 +4,7 @@
4
4
  */
5
5
  export type nil = null | undefined;
6
6
  /**
7
- * @deprecated Import from `__esri.IHandle` instead
7
+ * @deprecated import type { ResourceHandle } from "@arcgis/core/core/Handles.js";
8
8
  */
9
9
  export type IHandle = {
10
10
  remove: () => void;
@@ -18,7 +18,7 @@ export type Nil = nil;
18
18
  * This complements the TypeScript's `satisfies` operator.
19
19
  *
20
20
  * See usage examples:
21
- * https://webgis.esri.com/webgis/additional-resources/typescript-tips#use-satisfies-operator-for-type-tests
21
+ * https://webgis.esri.com/sdk/resources/typescript-tips#use-satisfies-operator-for-type-tests
22
22
  *
23
23
  * During production end-application build, such type tests will be removed as
24
24
  * they have no runtime impact.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcgis/toolkit",
3
- "version": "5.1.0-next.9",
3
+ "version": "5.1.0-next.91",
4
4
  "description": "Collection of common internal patterns and utilities for ArcGIS Maps SDK for JavaScript components.",
5
5
  "homepage": "https://developers.arcgis.com/javascript/latest/",
6
6
  "sideEffects": false,