@arcgis/components-utils 4.33.0-next.16 → 4.33.0-next.161

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.
@@ -0,0 +1,5 @@
1
+ import { Nil } from './types';
2
+ /**
3
+ * Find a value in an array, and return it's mapped variant.
4
+ */
5
+ export declare const mappedFind: <Item, ReturnType>(array: readonly Item[], callback: (item: Item, index: number) => Nil | ReturnType) => ReturnType | undefined;
@@ -0,0 +1,5 @@
1
+ import { Nil } from './types';
2
+ /**
3
+ * Find a value in an array, and return it's mapped variant.
4
+ */
5
+ export declare const mappedFind: <Item, ReturnType>(array: readonly Item[], callback: (item: Item, index: number) => Nil | ReturnType) => ReturnType | undefined;
@@ -0,0 +1,15 @@
1
+ import { Nil } from './types';
2
+ /**
3
+ * This code contains imperative syntax (like for loops and mutation) as it is
4
+ * in the hot path - performance optimizations are critical here.
5
+ * See https://devtopia.esri.com/WebGIS/arcgis-js-api/commit/2565cedd87b
6
+ *
7
+ * Stencil has native support for passing-in class prop as an object or string,
8
+ * but it does not support arrays or booleans, thus this utility is used
9
+ * instead.
10
+ *
11
+ * @remarks
12
+ * This function is not necessary in a Lit package as Lit's `classMap` directive
13
+ * accepts an object
14
+ */
15
+ export declare const classes: (...classes: (Nil | Record<string, boolean> | string[] | string | false)[]) => string;
@@ -0,0 +1,15 @@
1
+ import { Nil } from './types';
2
+ /**
3
+ * This code contains imperative syntax (like for loops and mutation) as it is
4
+ * in the hot path - performance optimizations are critical here.
5
+ * See https://devtopia.esri.com/WebGIS/arcgis-js-api/commit/2565cedd87b
6
+ *
7
+ * Stencil has native support for passing-in class prop as an object or string,
8
+ * but it does not support arrays or booleans, thus this utility is used
9
+ * instead.
10
+ *
11
+ * @remarks
12
+ * This function is not necessary in a Lit package as Lit's `classMap` directive
13
+ * accepts an object
14
+ */
15
+ export declare const classes: (...classes: (Nil | Record<string, boolean> | string[] | string | false)[]) => string;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * A deferred promise.
3
+ * Useful for when you want to return a promise but don't have the value yet.
4
+ * Example:
5
+ * ```
6
+ * const deferred = new Deferred<string>();
7
+ * setTimeout(() => deferred.resolve("Hello World"), 1000);
8
+ * return deferred.promise;
9
+ * ```
10
+ * @template T The type of the promise.
11
+ */
12
+ export declare class Deferred<T> {
13
+ /**
14
+ * The promise that can be awaited.
15
+ */
16
+ promise: Promise<T>;
17
+ /**
18
+ * Creates a new deferred promise.
19
+ */
20
+ constructor();
21
+ }
22
+ export interface Deferred<T> {
23
+ /**
24
+ * Resolves the promise.
25
+ * @param value The value to resolve the promise with.
26
+ *
27
+ * @privateRemarks
28
+ * Defined as a method to disable covariance checks. Overridden in constructor.
29
+ */
30
+ resolve(_value: PromiseLike<T> | T): void;
31
+ /**
32
+ * Rejects the promise.
33
+ */
34
+ reject(_error: unknown): void;
35
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * A deferred promise.
3
+ * Useful for when you want to return a promise but don't have the value yet.
4
+ * Example:
5
+ * ```
6
+ * const deferred = new Deferred<string>();
7
+ * setTimeout(() => deferred.resolve("Hello World"), 1000);
8
+ * return deferred.promise;
9
+ * ```
10
+ * @template T The type of the promise.
11
+ */
12
+ export declare class Deferred<T> {
13
+ /**
14
+ * The promise that can be awaited.
15
+ */
16
+ promise: Promise<T>;
17
+ /**
18
+ * Creates a new deferred promise.
19
+ */
20
+ constructor();
21
+ }
22
+ export interface Deferred<T> {
23
+ /**
24
+ * Resolves the promise.
25
+ * @param value The value to resolve the promise with.
26
+ *
27
+ * @privateRemarks
28
+ * Defined as a method to disable covariance checks. Overridden in constructor.
29
+ */
30
+ resolve(_value: PromiseLike<T> | T): void;
31
+ /**
32
+ * Rejects the promise.
33
+ */
34
+ reject(_error: unknown): void;
35
+ }
package/dist/dom.d.cts ADDED
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Observe the element and its ancestors for attribute mutations.
3
+ * If the attributes have been changed in the ancestor tree then the callback will be invoked.
4
+ * Example: `observeAncestorsMutation(element, ["dir", "lang"], () => console.log("dir or lang changed"));`
5
+ * @param element The element on which to observe the attribute mutations.
6
+ * @param attributeFilter The list of attributes to observe.
7
+ * @param callback The callback to invoke when the attributes have been changed.
8
+ * @returns The mutation observer
9
+ */
10
+ export declare const observeAncestorsMutation: (element: Node, attributeFilter: string[], callback: () => void) => (() => void);
11
+ /**
12
+ * Find the closest element that matches the selector.
13
+ * It will traverse the element's ancestors to find the target element.
14
+ * Shadow DOM boundaries are also taken into account.
15
+ * @param base The element to start the search from.
16
+ * @param selector The selector to match.
17
+ * @returns The closest element that matches the selector or null if not found.
18
+ */
19
+ export declare const closestElement: (base: Element, selector: string) => Element | null;
20
+ /**
21
+ * Use the Calcite mode to determine the theme of the element.
22
+ * It will traverse the element's ancestors to find the theme.
23
+ * Shadow DOM boundaries are also taken into account.
24
+ * @param base The element to start the search from.
25
+ * @returns The theme of the element, either "light" or "dark", "light" is the default.
26
+ */
27
+ export declare const getElementTheme: (base: Element) => "dark" | "light";
28
+ /**
29
+ * Get direction property of closest element.
30
+ * @param el The element to start the search from.
31
+ * @returns The direction of the element, either "ltr" | "rtl", "ltr" is the default.
32
+ */
33
+ export declare const getElementDir: (el: HTMLElement) => "ltr" | "rtl";
34
+ /**
35
+ * Get the attribute value from the element.
36
+ * It will traverse the element's ancestors to find the attribute.
37
+ * Shadow DOM boundaries are also taken into account.
38
+ * If the attribute is not found then the fallback value is returned.
39
+ * Example: `getElementAttribute(element, "dir", "ltr");`
40
+ * @param base The element to start the search from.
41
+ * @param prop The attribute name.
42
+ * @param fallbackValue The fallback value if the attribute is not found.
43
+ * @returns The attribute value or the fallback value if the attribute is not found.
44
+ */
45
+ export declare const getElementAttribute: (el: Element, prop: string, fallbackValue: string) => string;
46
+ export interface FocusableElement extends HTMLElement {
47
+ setFocus?: () => Promise<void>;
48
+ }
49
+ export declare const focusElement: (el: FocusableElement | undefined) => Promise<void>;
50
+ /**
51
+ * Set the focus on the element that matches the selector.
52
+ * It will traverse the element's ancestors to find the target element.
53
+ * Shadow DOM boundaries are also taken into account.
54
+ * If the element is not found then the focus is not set.
55
+ * Example: `setFocusOnElement(element, "[role='menuitem']");`
56
+ * @param ref The element to start the search from.
57
+ * @param selector The selector to match.
58
+ * @returns Returns true if the focus is set on the element.
59
+ *
60
+ * REFACTOR: this is doing too much. break it into separate find element and focus
61
+ * element utilities
62
+ */
63
+ export declare const setFocusOnElement: (ref: (Element & {
64
+ componentOnReady?: () => Promise<void>;
65
+ }) | null | undefined, selector: string) => void;
package/dist/dom.d.ts ADDED
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Observe the element and its ancestors for attribute mutations.
3
+ * If the attributes have been changed in the ancestor tree then the callback will be invoked.
4
+ * Example: `observeAncestorsMutation(element, ["dir", "lang"], () => console.log("dir or lang changed"));`
5
+ * @param element The element on which to observe the attribute mutations.
6
+ * @param attributeFilter The list of attributes to observe.
7
+ * @param callback The callback to invoke when the attributes have been changed.
8
+ * @returns The mutation observer
9
+ */
10
+ export declare const observeAncestorsMutation: (element: Node, attributeFilter: string[], callback: () => void) => (() => void);
11
+ /**
12
+ * Find the closest element that matches the selector.
13
+ * It will traverse the element's ancestors to find the target element.
14
+ * Shadow DOM boundaries are also taken into account.
15
+ * @param base The element to start the search from.
16
+ * @param selector The selector to match.
17
+ * @returns The closest element that matches the selector or null if not found.
18
+ */
19
+ export declare const closestElement: (base: Element, selector: string) => Element | null;
20
+ /**
21
+ * Use the Calcite mode to determine the theme of the element.
22
+ * It will traverse the element's ancestors to find the theme.
23
+ * Shadow DOM boundaries are also taken into account.
24
+ * @param base The element to start the search from.
25
+ * @returns The theme of the element, either "light" or "dark", "light" is the default.
26
+ */
27
+ export declare const getElementTheme: (base: Element) => "dark" | "light";
28
+ /**
29
+ * Get direction property of closest element.
30
+ * @param el The element to start the search from.
31
+ * @returns The direction of the element, either "ltr" | "rtl", "ltr" is the default.
32
+ */
33
+ export declare const getElementDir: (el: HTMLElement) => "ltr" | "rtl";
34
+ /**
35
+ * Get the attribute value from the element.
36
+ * It will traverse the element's ancestors to find the attribute.
37
+ * Shadow DOM boundaries are also taken into account.
38
+ * If the attribute is not found then the fallback value is returned.
39
+ * Example: `getElementAttribute(element, "dir", "ltr");`
40
+ * @param base The element to start the search from.
41
+ * @param prop The attribute name.
42
+ * @param fallbackValue The fallback value if the attribute is not found.
43
+ * @returns The attribute value or the fallback value if the attribute is not found.
44
+ */
45
+ export declare const getElementAttribute: (el: Element, prop: string, fallbackValue: string) => string;
46
+ export interface FocusableElement extends HTMLElement {
47
+ setFocus?: () => Promise<void>;
48
+ }
49
+ export declare const focusElement: (el: FocusableElement | undefined) => Promise<void>;
50
+ /**
51
+ * Set the focus on the element that matches the selector.
52
+ * It will traverse the element's ancestors to find the target element.
53
+ * Shadow DOM boundaries are also taken into account.
54
+ * If the element is not found then the focus is not set.
55
+ * Example: `setFocusOnElement(element, "[role='menuitem']");`
56
+ * @param ref The element to start the search from.
57
+ * @param selector The selector to match.
58
+ * @returns Returns true if the focus is set on the element.
59
+ *
60
+ * REFACTOR: this is doing too much. break it into separate find element and focus
61
+ * element utilities
62
+ */
63
+ export declare const setFocusOnElement: (ref: (Element & {
64
+ componentOnReady?: () => Promise<void>;
65
+ }) | null | undefined, selector: string) => void;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Check whether the code is executing in an Esri internal environment (for
3
+ * example, Lumina dev server). When true, your code can enable extra validation
4
+ * to detect incorrect usages or do runtime bug detection.
5
+ *
6
+ * The call to isEsriInternalEnv() MUST always appear behind one of the
7
+ * following guards to ensure it is correctly eliminated in production bundles:
8
+ *
9
+ * - `process.env.NODE_ENV !== "production"`
10
+ * - `process.env.NODE_ENV === "development"`
11
+ * - `process.env.NODE_ENV === "test"`
12
+ *
13
+ * @remarks
14
+ * This function is primary for usage in support packages. In Lumina component
15
+ * packages, simpler alternatives are provided:
16
+ * https://qawebgis.esri.com/components/lumina/publishing#bundling-code-conditionally
17
+ */
18
+ export declare const isEsriInternalEnv: () => boolean;
19
+ /**
20
+ * Calls a sync method and catch any errors. Returns undefined if error occurred.
21
+ *
22
+ * Can also provide a thisContext and rest arguments
23
+ */
24
+ export declare const safeCall: <Callback extends (...args: never[]) => unknown>(callback?: Callback, thisContext?: ThisParameterType<Callback>, ...rest: Parameters<Callback>) => ReturnType<Callback> | void;
25
+ /**
26
+ * Calls an async method and catch any errors. Returns undefined if error occurred.
27
+ *
28
+ * Can also provide a thisContext and rest arguments
29
+ */
30
+ export declare const safeAsyncCall: <Callback extends (...args: never[]) => unknown>(callback?: Callback, thisContext?: ThisParameterType<Callback>, ...rest: Parameters<Callback>) => Promise<Awaited<ReturnType<Callback>> | void>;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Check whether the code is executing in an Esri internal environment (for
3
+ * example, Lumina dev server). When true, your code can enable extra validation
4
+ * to detect incorrect usages or do runtime bug detection.
5
+ *
6
+ * The call to isEsriInternalEnv() MUST always appear behind one of the
7
+ * following guards to ensure it is correctly eliminated in production bundles:
8
+ *
9
+ * - `process.env.NODE_ENV !== "production"`
10
+ * - `process.env.NODE_ENV === "development"`
11
+ * - `process.env.NODE_ENV === "test"`
12
+ *
13
+ * @remarks
14
+ * This function is primary for usage in support packages. In Lumina component
15
+ * packages, simpler alternatives are provided:
16
+ * https://qawebgis.esri.com/components/lumina/publishing#bundling-code-conditionally
17
+ */
18
+ export declare const isEsriInternalEnv: () => boolean;
19
+ /**
20
+ * Calls a sync method and catch any errors. Returns undefined if error occurred.
21
+ *
22
+ * Can also provide a thisContext and rest arguments
23
+ */
24
+ export declare const safeCall: <Callback extends (...args: never[]) => unknown>(callback?: Callback, thisContext?: ThisParameterType<Callback>, ...rest: Parameters<Callback>) => ReturnType<Callback> | void;
25
+ /**
26
+ * Calls an async method and catch any errors. Returns undefined if error occurred.
27
+ *
28
+ * Can also provide a thisContext and rest arguments
29
+ */
30
+ export declare const safeAsyncCall: <Callback extends (...args: never[]) => unknown>(callback?: Callback, thisContext?: ThisParameterType<Callback>, ...rest: Parameters<Callback>) => Promise<Awaited<ReturnType<Callback>> | void>;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Generates a GUID string.
3
+ * @returns A GUID string with the pattern 00000000-0000-0000-0000-000000000000.
4
+ */
5
+ export declare const generateGuid: () => string;
package/dist/guid.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Generates a GUID string.
3
+ * @returns A GUID string with the pattern 00000000-0000-0000-0000-000000000000.
4
+ */
5
+ export declare const generateGuid: () => string;