@arcgis/toolkit 5.0.0-next.6 → 5.0.0-next.61

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.
@@ -76,7 +76,7 @@ export declare function unsafeGetCalciteModeName(el: HTMLElement): "dark" | "lig
76
76
  * expected to respect what was set by the consumer.
77
77
  *
78
78
  * @remarks
79
- * Prefer [useDirection()](https://qawebgis.esri.com/components/lumina/controllers/useDirection)
79
+ * Prefer [useDirection()](https://qawebgis.esri.com/references/lumina/controllers/useDirection)
80
80
  * to ensure your component is responsive to direction changes.
81
81
  */
82
82
  export declare const unsafeGetElementDirection: (el: HTMLElement) => "ltr" | "rtl";
@@ -76,7 +76,7 @@ export declare function unsafeGetCalciteModeName(el: HTMLElement): "dark" | "lig
76
76
  * expected to respect what was set by the consumer.
77
77
  *
78
78
  * @remarks
79
- * Prefer [useDirection()](https://qawebgis.esri.com/components/lumina/controllers/useDirection)
79
+ * Prefer [useDirection()](https://qawebgis.esri.com/references/lumina/controllers/useDirection)
80
80
  * to ensure your component is responsive to direction changes.
81
81
  */
82
82
  export declare const unsafeGetElementDirection: (el: HTMLElement) => "ltr" | "rtl";
@@ -10,12 +10,12 @@
10
10
  * - `process.env.NODE_ENV === "development"`
11
11
  * - `process.env.NODE_ENV === "test"`
12
12
  *
13
- * [Documentation](https://qawebgis.esri.com/components/lumina/publishing#internal-esri-environment)
13
+ * [Documentation](https://qawebgis.esri.com/references/lumina/publishing#internal-esri-environment)
14
14
  *
15
15
  * @remarks
16
16
  * This function is primary for usage in support packages. In Lumina component
17
17
  * packages, simpler alternatives are provided:
18
- * https://qawebgis.esri.com/components/lumina/publishing#bundling-code-conditionally
18
+ * https://qawebgis.esri.com/references/lumina/publishing#bundling-code-conditionally
19
19
  */
20
20
  export declare const isEsriInternalEnv: () => boolean;
21
21
  /**
@@ -10,12 +10,12 @@
10
10
  * - `process.env.NODE_ENV === "development"`
11
11
  * - `process.env.NODE_ENV === "test"`
12
12
  *
13
- * [Documentation](https://qawebgis.esri.com/components/lumina/publishing#internal-esri-environment)
13
+ * [Documentation](https://qawebgis.esri.com/references/lumina/publishing#internal-esri-environment)
14
14
  *
15
15
  * @remarks
16
16
  * This function is primary for usage in support packages. In Lumina component
17
17
  * packages, simpler alternatives are provided:
18
- * https://qawebgis.esri.com/components/lumina/publishing#bundling-code-conditionally
18
+ * https://qawebgis.esri.com/references/lumina/publishing#bundling-code-conditionally
19
19
  */
20
20
  export declare const isEsriInternalEnv: () => boolean;
21
21
  /**
@@ -23,7 +23,7 @@ export declare const defaultLocale = "en";
23
23
  *
24
24
  * @remarks
25
25
  * Rather than using this function directly, prefer the
26
- * [useT9n()](https://qawebgis.esri.com/components/lumina/controllers/useT9n)
26
+ * [useT9n()](https://qawebgis.esri.com/references/lumina/controllers/useT9n)
27
27
  * controller.
28
28
  *
29
29
  * @remarks
@@ -39,7 +39,7 @@ export declare const defaultLocale = "en";
39
39
  * );
40
40
  * ```
41
41
  *
42
- * @see [Lumina asset handling](https://qawebgis.esri.com/components/lumina/assets)
42
+ * @see [Lumina asset handling](https://qawebgis.esri.com/references/lumina/assets)
43
43
  */
44
44
  export declare const fetchT9nStringsBundle: <Strings extends GenericT9nStrings>(locale: string, assetsPath: string, prefix?: string) => Promise<Strings>;
45
45
  /**
@@ -55,7 +55,7 @@ export interface GenericT9nStrings {
55
55
  *
56
56
  * @returns an object with the `lang` and `t9nLocale` properties.
57
57
  *
58
- * @see [lang vs t9nLocale](https://qawebgis.esri.com/components/lumina/controllers/useT9n#difference-between-lang-and-t9nlocale).
58
+ * @see [lang vs t9nLocale](https://qawebgis.esri.com/references/lumina/controllers/useT9n#difference-between-lang-and-t9nlocale).
59
59
  */
60
60
  export declare const getElementLocale: (element: HTMLElement) => {
61
61
  readonly lang: string;
@@ -103,7 +103,7 @@ export interface LocaleObserverResult<Strings extends GenericT9nStrings = Generi
103
103
  *
104
104
  * @remarks
105
105
  * Rather than using this function directly, prefer the
106
- * [useT9n()](https://qawebgis.esri.com/components/lumina/controllers/useT9n)
106
+ * [useT9n()](https://qawebgis.esri.com/references/lumina/controllers/useT9n)
107
107
  * controller.
108
108
  *
109
109
  * @example
@@ -23,7 +23,7 @@ export declare const defaultLocale = "en";
23
23
  *
24
24
  * @remarks
25
25
  * Rather than using this function directly, prefer the
26
- * [useT9n()](https://qawebgis.esri.com/components/lumina/controllers/useT9n)
26
+ * [useT9n()](https://qawebgis.esri.com/references/lumina/controllers/useT9n)
27
27
  * controller.
28
28
  *
29
29
  * @remarks
@@ -39,7 +39,7 @@ export declare const defaultLocale = "en";
39
39
  * );
40
40
  * ```
41
41
  *
42
- * @see [Lumina asset handling](https://qawebgis.esri.com/components/lumina/assets)
42
+ * @see [Lumina asset handling](https://qawebgis.esri.com/references/lumina/assets)
43
43
  */
44
44
  export declare const fetchT9nStringsBundle: <Strings extends GenericT9nStrings>(locale: string, assetsPath: string, prefix?: string) => Promise<Strings>;
45
45
  /**
@@ -55,7 +55,7 @@ export interface GenericT9nStrings {
55
55
  *
56
56
  * @returns an object with the `lang` and `t9nLocale` properties.
57
57
  *
58
- * @see [lang vs t9nLocale](https://qawebgis.esri.com/components/lumina/controllers/useT9n#difference-between-lang-and-t9nlocale).
58
+ * @see [lang vs t9nLocale](https://qawebgis.esri.com/references/lumina/controllers/useT9n#difference-between-lang-and-t9nlocale).
59
59
  */
60
60
  export declare const getElementLocale: (element: HTMLElement) => {
61
61
  readonly lang: string;
@@ -103,7 +103,7 @@ export interface LocaleObserverResult<Strings extends GenericT9nStrings = Generi
103
103
  *
104
104
  * @remarks
105
105
  * Rather than using this function directly, prefer the
106
- * [useT9n()](https://qawebgis.esri.com/components/lumina/controllers/useT9n)
106
+ * [useT9n()](https://qawebgis.esri.com/references/lumina/controllers/useT9n)
107
107
  * controller.
108
108
  *
109
109
  * @example
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const loggedMessages = /* @__PURE__ */ new Set();
4
+ let esriConfig;
5
+ const setEsriConfig = (config) => {
6
+ esriConfig = config;
7
+ };
8
+ const getContextString = (context) => {
9
+ if (typeof context === "string") {
10
+ return context;
11
+ }
12
+ if ("el" in context) {
13
+ return context.el.localName;
14
+ }
15
+ if ("localName" in context) {
16
+ return context.localName;
17
+ }
18
+ return context.declaredClass;
19
+ };
20
+ const log = (level, context, message, options) => {
21
+ const contextString = getContextString(context);
22
+ if (options?.once) {
23
+ const key = `${level}${contextString}${message}`;
24
+ if (loggedMessages.has(key)) {
25
+ return;
26
+ }
27
+ loggedMessages.add(key);
28
+ }
29
+ esriConfig?.log.interceptors?.forEach((interceptor) => interceptor(level, contextString, message));
30
+ console[level](`[${contextString}]`, message);
31
+ };
32
+ const composeMissingPropertyMessage = (property) => (
33
+ //#endregion composeMissingPropertyMessage
34
+ `The property \`${property.toString()}\` is required but missing.`
35
+ );
36
+ const composeEmptyPropertyMessage = (property) => (
37
+ //#endregion composeEmptyPropertyMessage
38
+ `The property \`${property.toString()}\` is empty but must have at least one element.`
39
+ );
40
+ const logDeprecatedProperty = (context, oldName, newName, options) => (
41
+ //#endregion logDeprecatedProperty
42
+ log("warn", context, `\`${oldName.toString()}\` is deprecated. Use \`${newName.toString()}\` instead.`, options)
43
+ );
44
+ exports.composeEmptyPropertyMessage = composeEmptyPropertyMessage;
45
+ exports.composeMissingPropertyMessage = composeMissingPropertyMessage;
46
+ exports.log = log;
47
+ exports.logDeprecatedProperty = logDeprecatedProperty;
48
+ exports.setEsriConfig = setEsriConfig;
@@ -0,0 +1,94 @@
1
+ export type LogLevel = "error" | "info" | "warn";
2
+ type CustomElementLike = {
3
+ el: {
4
+ localName: string;
5
+ };
6
+ } | {
7
+ localName: string;
8
+ };
9
+ type AccessorLike = {
10
+ declaredClass: string;
11
+ };
12
+ export type LogContext = AccessorLike | CustomElementLike | string;
13
+ type LogOptions = {
14
+ /** Whether the message should only be logged once */
15
+ once?: boolean;
16
+ };
17
+ type EsriConfig = {
18
+ log: {
19
+ /**
20
+ * @link {https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html#LogInterceptor}
21
+ */
22
+ interceptors?: ((level: LogLevel | "none", module: string, ...args: any[]) => void)[];
23
+ };
24
+ };
25
+ /**
26
+ * 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}.
27
+ * @see {@link https://devtopia.esri.com/WebGIS/arcgis-js-api/discussions/74935}
28
+ * @param config {@link https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html}
29
+ * @example
30
+ * ```ts
31
+ * // IMPORTANT: do this only in config.ts or another early-loaded module
32
+ * import esriConfig from "@arcgis/core/config.js";
33
+ * import { setEsriConfig } from "@arcgis/toolkit/log";
34
+ *
35
+ * setEsriConfig(esriConfig);
36
+ *
37
+ * // either here or in another file, you can add your interceptors
38
+ * // and they will be respected when log is called later on
39
+ * esriConfig.log.interceptors?.push(yourInterceptor);
40
+ * ```
41
+ */
42
+ export declare const setEsriConfig: (config: EsriConfig) => void;
43
+ /**
44
+ * Helper utility for logging messages in a consistent manner.
45
+ *
46
+ * @see [setEsriConfig](#setEsriConfig)
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * log("error", this, "message to log",
51
+ * {
52
+ * once: true, // only log this message once
53
+ * }
54
+ * );
55
+ * ```
56
+ */
57
+ export declare const log: (level: LogLevel, context: LogContext, message: unknown, options?: LogOptions) => void;
58
+ type LogContextOrObject = Exclude<LogContext, string> | object;
59
+ type InferPropertyType<T extends LogContextOrObject> = [object] extends [T] ? string : keyof T;
60
+ /**
61
+ * Returns a string that can be used in log messages for missing required properties.
62
+ * @param property The name of the required property
63
+ * @example
64
+ * ```ts
65
+ * // returns "The property `x` is required but missing."
66
+ * composeMissingPropertyMessage<YourClass>("x");
67
+ * // you don't need to provide a generic type argument if you don't have one
68
+ * composeMissingPropertyMessage("object.sub.property");
69
+ * ```
70
+ */
71
+ export declare const composeMissingPropertyMessage: <T extends LogContextOrObject = object>(property: InferPropertyType<T>) => string;
72
+ /**
73
+ * Returns a string that can be used in log messages for empty required arrays.
74
+ * @param property The name of the required property
75
+ * @example
76
+ * ```ts
77
+ * // returns "The property `x` is empty but must have at least one element."
78
+ * composeEmptyPropertyMessage<YourClass>("x");
79
+ * // you don't need to provide a generic type argument if you don't have one
80
+ * composeEmptyPropertyMessage("object.sub.property");
81
+ * ```
82
+ */
83
+ export declare const composeEmptyPropertyMessage: <T extends LogContextOrObject = object>(property: InferPropertyType<T>) => string;
84
+ /**
85
+ * Logs a warning message for deprecated object properties.
86
+ * @example
87
+ * ```ts
88
+ * logDeprecatedProperty(this, "oldName", "newName", {
89
+ * once: true,
90
+ * });
91
+ * ```
92
+ */
93
+ export declare const logDeprecatedProperty: <T extends LogContext>(context: T, oldName: keyof T, newName: keyof T, options?: LogOptions) => ReturnType<typeof log>;
94
+ export {};
@@ -0,0 +1,94 @@
1
+ export type LogLevel = "error" | "info" | "warn";
2
+ type CustomElementLike = {
3
+ el: {
4
+ localName: string;
5
+ };
6
+ } | {
7
+ localName: string;
8
+ };
9
+ type AccessorLike = {
10
+ declaredClass: string;
11
+ };
12
+ export type LogContext = AccessorLike | CustomElementLike | string;
13
+ type LogOptions = {
14
+ /** Whether the message should only be logged once */
15
+ once?: boolean;
16
+ };
17
+ type EsriConfig = {
18
+ log: {
19
+ /**
20
+ * @link {https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html#LogInterceptor}
21
+ */
22
+ interceptors?: ((level: LogLevel | "none", module: string, ...args: any[]) => void)[];
23
+ };
24
+ };
25
+ /**
26
+ * 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}.
27
+ * @see {@link https://devtopia.esri.com/WebGIS/arcgis-js-api/discussions/74935}
28
+ * @param config {@link https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html}
29
+ * @example
30
+ * ```ts
31
+ * // IMPORTANT: do this only in config.ts or another early-loaded module
32
+ * import esriConfig from "@arcgis/core/config.js";
33
+ * import { setEsriConfig } from "@arcgis/toolkit/log";
34
+ *
35
+ * setEsriConfig(esriConfig);
36
+ *
37
+ * // either here or in another file, you can add your interceptors
38
+ * // and they will be respected when log is called later on
39
+ * esriConfig.log.interceptors?.push(yourInterceptor);
40
+ * ```
41
+ */
42
+ export declare const setEsriConfig: (config: EsriConfig) => void;
43
+ /**
44
+ * Helper utility for logging messages in a consistent manner.
45
+ *
46
+ * @see [setEsriConfig](#setEsriConfig)
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * log("error", this, "message to log",
51
+ * {
52
+ * once: true, // only log this message once
53
+ * }
54
+ * );
55
+ * ```
56
+ */
57
+ export declare const log: (level: LogLevel, context: LogContext, message: unknown, options?: LogOptions) => void;
58
+ type LogContextOrObject = Exclude<LogContext, string> | object;
59
+ type InferPropertyType<T extends LogContextOrObject> = [object] extends [T] ? string : keyof T;
60
+ /**
61
+ * Returns a string that can be used in log messages for missing required properties.
62
+ * @param property The name of the required property
63
+ * @example
64
+ * ```ts
65
+ * // returns "The property `x` is required but missing."
66
+ * composeMissingPropertyMessage<YourClass>("x");
67
+ * // you don't need to provide a generic type argument if you don't have one
68
+ * composeMissingPropertyMessage("object.sub.property");
69
+ * ```
70
+ */
71
+ export declare const composeMissingPropertyMessage: <T extends LogContextOrObject = object>(property: InferPropertyType<T>) => string;
72
+ /**
73
+ * Returns a string that can be used in log messages for empty required arrays.
74
+ * @param property The name of the required property
75
+ * @example
76
+ * ```ts
77
+ * // returns "The property `x` is empty but must have at least one element."
78
+ * composeEmptyPropertyMessage<YourClass>("x");
79
+ * // you don't need to provide a generic type argument if you don't have one
80
+ * composeEmptyPropertyMessage("object.sub.property");
81
+ * ```
82
+ */
83
+ export declare const composeEmptyPropertyMessage: <T extends LogContextOrObject = object>(property: InferPropertyType<T>) => string;
84
+ /**
85
+ * Logs a warning message for deprecated object properties.
86
+ * @example
87
+ * ```ts
88
+ * logDeprecatedProperty(this, "oldName", "newName", {
89
+ * once: true,
90
+ * });
91
+ * ```
92
+ */
93
+ export declare const logDeprecatedProperty: <T extends LogContext>(context: T, oldName: keyof T, newName: keyof T, options?: LogOptions) => ReturnType<typeof log>;
94
+ export {};
@@ -0,0 +1,48 @@
1
+ const loggedMessages = /* @__PURE__ */ new Set();
2
+ let esriConfig;
3
+ const setEsriConfig = (config) => {
4
+ esriConfig = config;
5
+ };
6
+ const getContextString = (context) => {
7
+ if (typeof context === "string") {
8
+ return context;
9
+ }
10
+ if ("el" in context) {
11
+ return context.el.localName;
12
+ }
13
+ if ("localName" in context) {
14
+ return context.localName;
15
+ }
16
+ return context.declaredClass;
17
+ };
18
+ const log = (level, context, message, options) => {
19
+ const contextString = getContextString(context);
20
+ if (options?.once) {
21
+ const key = `${level}${contextString}${message}`;
22
+ if (loggedMessages.has(key)) {
23
+ return;
24
+ }
25
+ loggedMessages.add(key);
26
+ }
27
+ esriConfig?.log.interceptors?.forEach((interceptor) => interceptor(level, contextString, message));
28
+ console[level](`[${contextString}]`, message);
29
+ };
30
+ const composeMissingPropertyMessage = (property) => (
31
+ //#endregion composeMissingPropertyMessage
32
+ `The property \`${property.toString()}\` is required but missing.`
33
+ );
34
+ const composeEmptyPropertyMessage = (property) => (
35
+ //#endregion composeEmptyPropertyMessage
36
+ `The property \`${property.toString()}\` is empty but must have at least one element.`
37
+ );
38
+ const logDeprecatedProperty = (context, oldName, newName, options) => (
39
+ //#endregion logDeprecatedProperty
40
+ log("warn", context, `\`${oldName.toString()}\` is deprecated. Use \`${newName.toString()}\` instead.`, options)
41
+ );
42
+ export {
43
+ composeEmptyPropertyMessage,
44
+ composeMissingPropertyMessage,
45
+ log,
46
+ logDeprecatedProperty,
47
+ setEsriConfig
48
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcgis/toolkit",
3
- "version": "5.0.0-next.6",
3
+ "version": "5.0.0-next.61",
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,
@@ -31,6 +31,11 @@
31
31
  "import": "./dist/intl/index.js",
32
32
  "require": "./dist/intl/index.cjs"
33
33
  },
34
+ "./log": {
35
+ "types": "./dist/log/index.d.ts",
36
+ "import": "./dist/log/index.js",
37
+ "require": "./dist/log/index.cjs"
38
+ },
34
39
  "./number": {
35
40
  "types": "./dist/number/index.d.ts",
36
41
  "import": "./dist/number/index.js",