@arcgis/toolkit 5.1.0-next.13 → 5.1.0-next.131

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/README.md CHANGED
@@ -8,5 +8,5 @@ It is not intended to be used directly, but rather used as a dependency by other
8
8
 
9
9
  ## License
10
10
 
11
- This package is licensed under the terms described in the `LICENSE.md` file, located in the root of the package, and at https://js.arcgis.com/5.0/LICENSE.txt.
12
- For third party notices, see https://js.arcgis.com/5.0/third-party-notices.txt.
11
+ This package is licensed under the terms described in the `LICENSE.md` file, located in the root of the package, and at https://js.arcgis.com/5.1/LICENSE.txt.
12
+ For third party notices, see https://js.arcgis.com/5.1/third-party-notices.txt.
@@ -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
  *
@@ -37,7 +38,7 @@ export declare const observeAncestorsMutation: (element: Node, attributeFilter:
37
38
  * @returns The closest element that matches the selector or null if not found.
38
39
  *
39
40
  * @remarks
40
- * This is similar to [Element.closest()](https://developer.mozilla.org/en-US/docs/Web/API/Element/closest),
41
+ * This is similar to [Element.closest()](https://developer.mozilla.org/docs/Web/API/Element/closest),
41
42
  * but the DOM's utility only looks up until the first shadow boundary.
42
43
  *
43
44
  * @example
@@ -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
  *
@@ -37,7 +38,7 @@ export declare const observeAncestorsMutation: (element: Node, attributeFilter:
37
38
  * @returns The closest element that matches the selector or null if not found.
38
39
  *
39
40
  * @remarks
40
- * This is similar to [Element.closest()](https://developer.mozilla.org/en-US/docs/Web/API/Element/closest),
41
+ * This is similar to [Element.closest()](https://developer.mozilla.org/docs/Web/API/Element/closest),
41
42
  * but the DOM's utility only looks up until the first shadow boundary.
42
43
  *
43
44
  * @example
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
@@ -33,6 +33,7 @@ const log = (level, context, message, options) => {
33
33
  if ((typeof value === "object" || typeof value === "function") && value !== null) {
34
34
  const weakRefValue = new WeakRef(value);
35
35
  Object.defineProperty(memorySafeDetail, key, {
36
+ enumerable: true,
36
37
  get() {
37
38
  return weakRefValue.deref();
38
39
  }
package/dist/log/index.js CHANGED
@@ -31,6 +31,7 @@ const log = (level, context, message, options) => {
31
31
  if ((typeof value === "object" || typeof value === "function") && value !== null) {
32
32
  const weakRefValue = new WeakRef(value);
33
33
  Object.defineProperty(memorySafeDetail, key, {
34
+ enumerable: true,
34
35
  get() {
35
36
  return weakRefValue.deref();
36
37
  }
@@ -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;
@@ -11,7 +11,7 @@
11
11
  *
12
12
  * @deprecated
13
13
  * If browser support permits, prefer using
14
- * [Promise.withResolvers()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers)
14
+ * [Promise.withResolvers()](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers)
15
15
  */
16
16
  export declare class Deferred<T> {
17
17
  /**
@@ -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.
@@ -11,7 +11,7 @@
11
11
  *
12
12
  * @deprecated
13
13
  * If browser support permits, prefer using
14
- * [Promise.withResolvers()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers)
14
+ * [Promise.withResolvers()](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers)
15
15
  */
16
16
  export declare class Deferred<T> {
17
17
  /**
@@ -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
  };
@@ -75,11 +75,39 @@ const getPreamble = (version) => (
75
75
  `COPYRIGHT Esri - https://js.arcgis.com/${getMinorVersion(version)}/LICENSE.txt`
76
76
  );
77
77
  const setValuesInString = (message, values = {}) => (message ?? "").replace(/\{(?<valueName>.*?)\}/gu, (match, valueName) => values[valueName] ?? match);
78
+ const regionStartPattern = /^\s*\/\/\s*#region(?::)?\s*(?<regionName>.*?)\s*$/u;
79
+ const regionAnyStartPattern = /^\s*\/\/\s*#region(?::)?\s*.*$/u;
80
+ const regionEndPattern = /^\s*\/\/\s*#endregion(?::)?(?:\s+.*)?\s*$/u;
81
+ const extractRegion = (source, regionName) => {
82
+ const lines = source.split(/\r?\n/gu);
83
+ const startLineIndex = lines.findIndex((line) => regionStartPattern.exec(line)?.groups?.regionName === regionName);
84
+ if (startLineIndex === -1) {
85
+ throw new Error(`Unable to locate source region "${regionName}".`);
86
+ }
87
+ let nestedRegionDepth = 0;
88
+ for (let lineIndex = startLineIndex + 1; lineIndex < lines.length; lineIndex++) {
89
+ const line = lines[lineIndex];
90
+ if (regionAnyStartPattern.test(line)) {
91
+ nestedRegionDepth++;
92
+ continue;
93
+ }
94
+ if (!regionEndPattern.test(line)) {
95
+ continue;
96
+ }
97
+ if (nestedRegionDepth > 0) {
98
+ nestedRegionDepth--;
99
+ continue;
100
+ }
101
+ return lines.slice(startLineIndex + 1, lineIndex).join("\n").trim();
102
+ }
103
+ throw new Error(`Unable to locate source region end for "${regionName}".`);
104
+ };
78
105
  exports.addLtrMark = addLtrMark;
79
106
  exports.camelToHuman = camelToHuman;
80
107
  exports.camelToKebab = camelToKebab;
81
108
  exports.capitalize = capitalize;
82
109
  exports.createFilterExpression = createFilterExpression;
110
+ exports.extractRegion = extractRegion;
83
111
  exports.generateGuid = generateGuid;
84
112
  exports.getMinorVersion = getMinorVersion;
85
113
  exports.getPreamble = getPreamble;
@@ -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");
@@ -104,3 +107,24 @@ export declare const getPreamble: (version: string) => string;
104
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;
110
+ /**
111
+ * Use `extractRegion` when you need to read a named `#region` block from a JavaScript/TypeScript source string,
112
+ * such as docs or MDX snippets that should stay in sync with the real implementation.
113
+ *
114
+ * Throws when the named region cannot be found or is missing its closing marker.
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * import code from "my-code-file.ts?raw";
119
+ * const snippet = extractRegion(code, "myRegion");
120
+ *
121
+ * // where code is:
122
+ * `
123
+ * //#region myRegion
124
+ * const value = 1;
125
+ * //#endregion
126
+ * `
127
+ * // const value = 1;
128
+ * ```
129
+ */
130
+ export declare const extractRegion: (source: string, regionName: 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/sdk/contributing/licensing
93
96
  * @example
94
97
  * ```ts
95
98
  * const preamble = getPreamble("5.0.1-next.456");
@@ -104,3 +107,24 @@ export declare const getPreamble: (version: string) => string;
104
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;
110
+ /**
111
+ * Use `extractRegion` when you need to read a named `#region` block from a JavaScript/TypeScript source string,
112
+ * such as docs or MDX snippets that should stay in sync with the real implementation.
113
+ *
114
+ * Throws when the named region cannot be found or is missing its closing marker.
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * import code from "my-code-file.ts?raw";
119
+ * const snippet = extractRegion(code, "myRegion");
120
+ *
121
+ * // where code is:
122
+ * `
123
+ * //#region myRegion
124
+ * const value = 1;
125
+ * //#endregion
126
+ * `
127
+ * // const value = 1;
128
+ * ```
129
+ */
130
+ export declare const extractRegion: (source: string, regionName: string) => string;
@@ -73,12 +73,40 @@ const getPreamble = (version) => (
73
73
  `COPYRIGHT Esri - https://js.arcgis.com/${getMinorVersion(version)}/LICENSE.txt`
74
74
  );
75
75
  const setValuesInString = (message, values = {}) => (message ?? "").replace(/\{(?<valueName>.*?)\}/gu, (match, valueName) => values[valueName] ?? match);
76
+ const regionStartPattern = /^\s*\/\/\s*#region(?::)?\s*(?<regionName>.*?)\s*$/u;
77
+ const regionAnyStartPattern = /^\s*\/\/\s*#region(?::)?\s*.*$/u;
78
+ const regionEndPattern = /^\s*\/\/\s*#endregion(?::)?(?:\s+.*)?\s*$/u;
79
+ const extractRegion = (source, regionName) => {
80
+ const lines = source.split(/\r?\n/gu);
81
+ const startLineIndex = lines.findIndex((line) => regionStartPattern.exec(line)?.groups?.regionName === regionName);
82
+ if (startLineIndex === -1) {
83
+ throw new Error(`Unable to locate source region "${regionName}".`);
84
+ }
85
+ let nestedRegionDepth = 0;
86
+ for (let lineIndex = startLineIndex + 1; lineIndex < lines.length; lineIndex++) {
87
+ const line = lines[lineIndex];
88
+ if (regionAnyStartPattern.test(line)) {
89
+ nestedRegionDepth++;
90
+ continue;
91
+ }
92
+ if (!regionEndPattern.test(line)) {
93
+ continue;
94
+ }
95
+ if (nestedRegionDepth > 0) {
96
+ nestedRegionDepth--;
97
+ continue;
98
+ }
99
+ return lines.slice(startLineIndex + 1, lineIndex).join("\n").trim();
100
+ }
101
+ throw new Error(`Unable to locate source region end for "${regionName}".`);
102
+ };
76
103
  export {
77
104
  addLtrMark,
78
105
  camelToHuman,
79
106
  camelToKebab,
80
107
  capitalize,
81
108
  createFilterExpression,
109
+ extractRegion,
82
110
  generateGuid,
83
111
  getMinorVersion,
84
112
  getPreamble,
@@ -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.
@@ -12,7 +12,7 @@ export declare const hasSameOrigin: (url1: string | null | undefined, url2: stri
12
12
  * @param url The url string to test
13
13
  * @returns True if the string is a URL.
14
14
  *
15
- * @remarks If browser support permits, use https://developer.mozilla.org/en-US/docs/Web/API/URL/parse_static instead
15
+ * @remarks If browser support permits, use https://developer.mozilla.org/docs/Web/API/URL/parse_static instead
16
16
  * @privateRemarks TODO: DEPRECATE
17
17
  */
18
18
  export declare const isURL: (url: string) => boolean;
@@ -12,7 +12,7 @@ export declare const hasSameOrigin: (url1: string | null | undefined, url2: stri
12
12
  * @param url The url string to test
13
13
  * @returns True if the string is a URL.
14
14
  *
15
- * @remarks If browser support permits, use https://developer.mozilla.org/en-US/docs/Web/API/URL/parse_static instead
15
+ * @remarks If browser support permits, use https://developer.mozilla.org/docs/Web/API/URL/parse_static instead
16
16
  * @privateRemarks TODO: DEPRECATE
17
17
  */
18
18
  export declare const isURL: (url: string) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcgis/toolkit",
3
- "version": "5.1.0-next.13",
3
+ "version": "5.1.0-next.131",
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,