@arcgis/toolkit 5.1.0-next.7 → 5.1.0-next.71

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
@@ -19,15 +19,15 @@ type LogOptions = {
19
19
  type EsriConfig = {
20
20
  log: {
21
21
  /**
22
- * @link {https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html#LogInterceptor}
22
+ * @link {https://developers.arcgis.com/javascript/latest/references/core/config/#LogInterceptor}
23
23
  */
24
24
  interceptors?: ((level: LogLevel | "none", module: string, ...args: any[]) => void)[];
25
25
  };
26
26
  };
27
27
  /**
28
- * Workaround for setting {@link https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html#log log interceptors} and maintaining compatibility with {@link https://devtopia.esri.com/WebGIS/arcgis-websceneviewer-app/blob/8f0a1bbcf12d1193134d94589d9e187f0afa72fa/src/js/support/ApiLoggerInstrumentation.ts#L17 js-api's interceptor usage}.
28
+ * Workaround for setting {@link https://developers.arcgis.com/javascript/latest/references/core/config/#log log interceptors} and maintaining compatibility with {@link https://devtopia.esri.com/WebGIS/arcgis-websceneviewer-app/blob/8f0a1bbcf12d1193134d94589d9e187f0afa72fa/src/js/support/ApiLoggerInstrumentation.ts#L17 js-api's interceptor usage}.
29
29
  * @see {@link https://devtopia.esri.com/WebGIS/arcgis-js-api/discussions/74935}
30
- * @param config {@link https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html}
30
+ * @param config {@link https://developers.arcgis.com/javascript/latest/references/core/config/}
31
31
  * @example
32
32
  * ```ts
33
33
  * // IMPORTANT: do this only in config.ts or another early-loaded module
@@ -19,15 +19,15 @@ type LogOptions = {
19
19
  type EsriConfig = {
20
20
  log: {
21
21
  /**
22
- * @link {https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html#LogInterceptor}
22
+ * @link {https://developers.arcgis.com/javascript/latest/references/core/config/#LogInterceptor}
23
23
  */
24
24
  interceptors?: ((level: LogLevel | "none", module: string, ...args: any[]) => void)[];
25
25
  };
26
26
  };
27
27
  /**
28
- * Workaround for setting {@link https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html#log log interceptors} and maintaining compatibility with {@link https://devtopia.esri.com/WebGIS/arcgis-websceneviewer-app/blob/8f0a1bbcf12d1193134d94589d9e187f0afa72fa/src/js/support/ApiLoggerInstrumentation.ts#L17 js-api's interceptor usage}.
28
+ * Workaround for setting {@link https://developers.arcgis.com/javascript/latest/references/core/config/#log log interceptors} and maintaining compatibility with {@link https://devtopia.esri.com/WebGIS/arcgis-websceneviewer-app/blob/8f0a1bbcf12d1193134d94589d9e187f0afa72fa/src/js/support/ApiLoggerInstrumentation.ts#L17 js-api's interceptor usage}.
29
29
  * @see {@link https://devtopia.esri.com/WebGIS/arcgis-js-api/discussions/74935}
30
- * @param config {@link https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html}
30
+ * @param config {@link https://developers.arcgis.com/javascript/latest/references/core/config/}
31
31
  * @example
32
32
  * ```ts
33
33
  * // IMPORTANT: do this only in config.ts or another early-loaded module
@@ -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/webgis/contributing/licensing
93
96
  * @example
94
97
  * ```ts
95
98
  * const preamble = getPreamble("5.0.1-next.456");
@@ -101,6 +104,6 @@ export declare const getPreamble: (version: string) => string;
101
104
  * Replace values in a string using the format {valueName} with the value from the values object.
102
105
  * If the value is not found in the values object, then the value is not replaced.
103
106
  *
104
- * @deprecated Import from https://next.gha.afd.arcgis.com/javascript/latest/api-reference/esri-intl.html#substitute instead
107
+ * @deprecated Import from https://next.gha.afd.arcgis.com/javascript/latest/references/core/intl/#substitute instead
105
108
  */
106
109
  export declare const setValuesInString: (message: string | null | undefined, values?: Record<string, string>) => string;
@@ -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/webgis/contributing/licensing
93
96
  * @example
94
97
  * ```ts
95
98
  * const preamble = getPreamble("5.0.1-next.456");
@@ -101,6 +104,6 @@ export declare const getPreamble: (version: string) => string;
101
104
  * Replace values in a string using the format {valueName} with the value from the values object.
102
105
  * If the value is not found in the values object, then the value is not replaced.
103
106
  *
104
- * @deprecated Import from https://next.gha.afd.arcgis.com/javascript/latest/api-reference/esri-intl.html#substitute instead
107
+ * @deprecated Import from https://next.gha.afd.arcgis.com/javascript/latest/references/core/intl/#substitute instead
105
108
  */
106
109
  export declare const setValuesInString: (message: string | null | undefined, values?: Record<string, string>) => string;
@@ -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;
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcgis/toolkit",
3
- "version": "5.1.0-next.7",
3
+ "version": "5.1.0-next.71",
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,