@open-pioneer/core 4.7.0-dev.20260625125130 → 4.7.0-dev.20260727091735
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/CHANGELOG.md +26 -21
- package/Logger.d.ts +1 -10
- package/Logger.js +11 -11
- package/Logger.js.map +1 -1
- package/NumberParser.d.ts +1 -3
- package/NumberParser.js +10 -7
- package/NumberParser.js.map +1 -1
- package/deprecated.js.map +1 -1
- package/equal.js.map +1 -1
- package/error.js.map +1 -1
- package/events.d.ts +1 -2
- package/events.js +8 -9
- package/events.js.map +1 -1
- package/package.json +2 -2
- package/resources.d.ts +2 -2
- package/resources.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
# @open-pioneer/core
|
|
2
2
|
|
|
3
|
-
## 4.7.0-dev.
|
|
3
|
+
## 4.7.0-dev.20260727091735
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
7
|
- 7c7e6d1: Add shallowEqual and deepEqual helper function to compare two objects.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Examples:
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
```ts
|
|
12
|
+
import { shallowEqual, deepEqual } from "@open-pioneer/core";
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
shallowEqual({ a: 1 }, { a: 1 }); // true
|
|
15
|
+
shallowEqual({ a: { x: 1 } }, { a: { x: 1 } }); // false
|
|
16
|
+
deepEqual({ a: { x: 1 } }, { a: { x: 1 } }); // true
|
|
17
|
+
deepEqual([1, [2, 3]], [1, [2, 3]]); // true
|
|
18
|
+
```
|
|
19
19
|
|
|
20
|
-
- e433296: Update Chakra UI to 3.36.
|
|
20
|
+
- e433296: Update Chakra UI to 3.36.1
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- 9d84f1e: Migrated from eslint to oxlint.
|
|
25
|
+
- 78aad9d: Refactor: use private javascript properties instead of typescript private keyword.
|
|
21
26
|
|
|
22
27
|
## 4.6.0
|
|
23
28
|
|
|
@@ -80,13 +85,13 @@
|
|
|
80
85
|
### Major Changes
|
|
81
86
|
|
|
82
87
|
- 9477e54: Update dependencies
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
- React 19
|
|
89
|
+
- Vite 6
|
|
90
|
+
- FormatJS 3
|
|
91
|
+
- Open Pioneer Build Tools
|
|
92
|
+
- ...
|
|
88
93
|
|
|
89
|
-
|
|
94
|
+
For more details, see https://github.com/open-pioneer/trails-core-packages/pull/81
|
|
90
95
|
|
|
91
96
|
## 2.4.0
|
|
92
97
|
|
|
@@ -94,12 +99,12 @@
|
|
|
94
99
|
|
|
95
100
|
- e3802fb: Introduce the `NumberParser` class for parsing strings in a specified locale.
|
|
96
101
|
|
|
97
|
-
|
|
98
|
-
|
|
102
|
+
```js
|
|
103
|
+
import { NumberParser } from "@open-pioneer/core";
|
|
99
104
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
105
|
+
const parser = new NumberParser("de-DE");
|
|
106
|
+
const number = parser.parse("1.234,56");
|
|
107
|
+
```
|
|
103
108
|
|
|
104
109
|
### Patch Changes
|
|
105
110
|
|
package/Logger.d.ts
CHANGED
|
@@ -79,8 +79,8 @@ export interface Logger {
|
|
|
79
79
|
* A class implementing a logger with a global log level.
|
|
80
80
|
*/
|
|
81
81
|
export declare class LoggerImpl implements Logger {
|
|
82
|
+
#private;
|
|
82
83
|
prefix: string;
|
|
83
|
-
private readonly enabledLogLevelNumber;
|
|
84
84
|
constructor(prefix: string, logLevel: LogLevel);
|
|
85
85
|
isDebug(): boolean;
|
|
86
86
|
/**
|
|
@@ -107,13 +107,4 @@ export declare class LoggerImpl implements Logger {
|
|
|
107
107
|
* @param values
|
|
108
108
|
*/
|
|
109
109
|
error(message: string | Error | unknown, ...values: unknown[]): void;
|
|
110
|
-
/**
|
|
111
|
-
* Internal method for performing the log if the specified level is enabled.
|
|
112
|
-
* @param level
|
|
113
|
-
* @param messageOrError
|
|
114
|
-
* @param values
|
|
115
|
-
* @private
|
|
116
|
-
*/
|
|
117
|
-
private _doLog;
|
|
118
|
-
private _isLogLevelEnabled;
|
|
119
110
|
}
|
package/Logger.js
CHANGED
|
@@ -10,13 +10,13 @@ const logLevelNumbers = {
|
|
|
10
10
|
};
|
|
11
11
|
class LoggerImpl {
|
|
12
12
|
prefix;
|
|
13
|
-
enabledLogLevelNumber;
|
|
13
|
+
#enabledLogLevelNumber;
|
|
14
14
|
constructor(prefix, logLevel) {
|
|
15
15
|
this.prefix = prefix;
|
|
16
|
-
this
|
|
16
|
+
this.#enabledLogLevelNumber = logLevelToLogLevelNumber(logLevel);
|
|
17
17
|
}
|
|
18
18
|
isDebug() {
|
|
19
|
-
return this
|
|
19
|
+
return this.#isLogLevelEnabled("DEBUG");
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Performs a debug log with the given message and values if DEBUG level is enabled.
|
|
@@ -24,7 +24,7 @@ class LoggerImpl {
|
|
|
24
24
|
* @param values
|
|
25
25
|
*/
|
|
26
26
|
debug(message, ...values) {
|
|
27
|
-
this
|
|
27
|
+
this.#doLog("DEBUG", message, values);
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Performs an info log with the given message and values if INFO level is enabled.
|
|
@@ -32,7 +32,7 @@ class LoggerImpl {
|
|
|
32
32
|
* @param values
|
|
33
33
|
*/
|
|
34
34
|
info(message, ...values) {
|
|
35
|
-
this
|
|
35
|
+
this.#doLog("INFO", message, values);
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
38
|
* Performs a warning log with the given message and values if WARN level is enabled.
|
|
@@ -40,7 +40,7 @@ class LoggerImpl {
|
|
|
40
40
|
* @param values
|
|
41
41
|
*/
|
|
42
42
|
warn(message, ...values) {
|
|
43
|
-
this
|
|
43
|
+
this.#doLog("WARN", message, values);
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
46
|
* Performs an error log with the given message and values if ERROR level is enabled.
|
|
@@ -48,7 +48,7 @@ class LoggerImpl {
|
|
|
48
48
|
* @param values
|
|
49
49
|
*/
|
|
50
50
|
error(message, ...values) {
|
|
51
|
-
this
|
|
51
|
+
this.#doLog("ERROR", message, values);
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
* Internal method for performing the log if the specified level is enabled.
|
|
@@ -57,8 +57,8 @@ class LoggerImpl {
|
|
|
57
57
|
* @param values
|
|
58
58
|
* @private
|
|
59
59
|
*/
|
|
60
|
-
|
|
61
|
-
if (this
|
|
60
|
+
#doLog(level, messageOrError, values) {
|
|
61
|
+
if (this.#isLogLevelEnabled(level)) {
|
|
62
62
|
let message = `[${level}] ${this.prefix}:`;
|
|
63
63
|
if (!isError(messageOrError)) {
|
|
64
64
|
message += " " + String(messageOrError);
|
|
@@ -69,9 +69,9 @@ class LoggerImpl {
|
|
|
69
69
|
console[consoleMethodName](message, ...values);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
|
|
72
|
+
#isLogLevelEnabled(logLevel) {
|
|
73
73
|
const logLevelNumber = logLevelToLogLevelNumber(logLevel);
|
|
74
|
-
return logLevelNumber >= this
|
|
74
|
+
return logLevelNumber >= this.#enabledLogLevelNumber;
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
function logLevelToConsoleMethodName(logLevel) {
|
package/Logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.js","sources":["Logger.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nconst LOG_LEVEL = typeof __LOG_LEVEL__ !== \"undefined\" ? validateLogLevel(__LOG_LEVEL__) : \"INFO\";\n\n/**\n * Creates and returns a new logger instance for an application wide standardized logging.\n * For available log methods see {@link Logger} interface.\n * The log level is globally configured (see vite.config.ts).\n *\n * You can create a logger with an arbitrary-prefix:\n *\n * ```ts\n * const logger = createLogger(\"some-prefix\");\n * logger.debug(\"...\");\n * ```\n *\n * With recent version of the trails vite plugin, you can also use this convenient way to create a logger:\n *\n * ```ts\n * import { sourceId } from \"open-pioneer:source-info\";\n *\n * // sourceId is an automatic identifier based on the current file.\n * const LOG = createLogger(sourceId);\n * ```\n *\n * @param prefix Prefix used to prefix all log messages invoked by the created logger instance.\n */\nexport function createLogger(prefix: string): Logger {\n return new LoggerImpl(prefix, LOG_LEVEL);\n}\n\n/**\n * Allowed log levels.\n * Order: DEBUG < INFO < WARN < ERROR\n */\nexport type LogLevel = \"DEBUG\" | \"INFO\" | \"WARN\" | \"ERROR\";\n\n// internal representation of log levels as numbers for log level comparison.\nconst logLevelNumbers: Record<LogLevel, number> = {\n DEBUG: 0,\n INFO: 1,\n WARN: 2,\n ERROR: 3\n};\n\nexport interface LogMethod {\n /**\n * Logger's log method signature\n *\n * @param message\n * Log message to be logged (attached to the prefix). This can be an arbitrary value.\n * Errors will be logged as-is, and other values are formatted as strings.\n * @param values Arbitrary amount of additional values to be logged (attached to message).\n */\n (message: string | Error | unknown, ...values: unknown[]): void;\n}\n\n/**\n * Provides a logger for a standardized application wide logging.\n *\n * The logger's log level is configured globally.\n *\n * Use the `createLogger` function to receive a new logger instance for logging.\n */\nexport interface Logger {\n /**\n * Prefix prepended to all logging messages\n */\n readonly prefix: string;\n\n /**\n * Returns true if debug log level is enabled.\n */\n isDebug(): boolean;\n\n /**\n * Logging method for debug log level.\n * Follows normal LogMethod structure but logs in debug level.\n */\n debug: LogMethod;\n\n /**\n * Logging method for info log level.\n * Follows normal log method structure but logs in info level.\n */\n info: LogMethod;\n\n /**\n * Logging method for warn log level.\n * Follows normal log method structure but logs in warn level.\n */\n warn: LogMethod;\n\n /**\n * Logging method for debug error level.\n * Follows normal log method structure but logs in error level.\n */\n error: LogMethod;\n}\n\n/**\n * A class implementing a logger with a global log level.\n */\nexport class LoggerImpl implements Logger {\n prefix: string;\n
|
|
1
|
+
{"version":3,"file":"Logger.js","sources":["Logger.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nconst LOG_LEVEL = typeof __LOG_LEVEL__ !== \"undefined\" ? validateLogLevel(__LOG_LEVEL__) : \"INFO\";\n\n/**\n * Creates and returns a new logger instance for an application wide standardized logging.\n * For available log methods see {@link Logger} interface.\n * The log level is globally configured (see vite.config.ts).\n *\n * You can create a logger with an arbitrary-prefix:\n *\n * ```ts\n * const logger = createLogger(\"some-prefix\");\n * logger.debug(\"...\");\n * ```\n *\n * With recent version of the trails vite plugin, you can also use this convenient way to create a logger:\n *\n * ```ts\n * import { sourceId } from \"open-pioneer:source-info\";\n *\n * // sourceId is an automatic identifier based on the current file.\n * const LOG = createLogger(sourceId);\n * ```\n *\n * @param prefix Prefix used to prefix all log messages invoked by the created logger instance.\n */\nexport function createLogger(prefix: string): Logger {\n return new LoggerImpl(prefix, LOG_LEVEL);\n}\n\n/**\n * Allowed log levels.\n * Order: DEBUG < INFO < WARN < ERROR\n */\nexport type LogLevel = \"DEBUG\" | \"INFO\" | \"WARN\" | \"ERROR\";\n\n// internal representation of log levels as numbers for log level comparison.\nconst logLevelNumbers: Record<LogLevel, number> = {\n DEBUG: 0,\n INFO: 1,\n WARN: 2,\n ERROR: 3\n};\n\nexport interface LogMethod {\n /**\n * Logger's log method signature\n *\n * @param message\n * Log message to be logged (attached to the prefix). This can be an arbitrary value.\n * Errors will be logged as-is, and other values are formatted as strings.\n * @param values Arbitrary amount of additional values to be logged (attached to message).\n */\n (message: string | Error | unknown, ...values: unknown[]): void;\n}\n\n/**\n * Provides a logger for a standardized application wide logging.\n *\n * The logger's log level is configured globally.\n *\n * Use the `createLogger` function to receive a new logger instance for logging.\n */\nexport interface Logger {\n /**\n * Prefix prepended to all logging messages\n */\n readonly prefix: string;\n\n /**\n * Returns true if debug log level is enabled.\n */\n isDebug(): boolean;\n\n /**\n * Logging method for debug log level.\n * Follows normal LogMethod structure but logs in debug level.\n */\n debug: LogMethod;\n\n /**\n * Logging method for info log level.\n * Follows normal log method structure but logs in info level.\n */\n info: LogMethod;\n\n /**\n * Logging method for warn log level.\n * Follows normal log method structure but logs in warn level.\n */\n warn: LogMethod;\n\n /**\n * Logging method for debug error level.\n * Follows normal log method structure but logs in error level.\n */\n error: LogMethod;\n}\n\n/**\n * A class implementing a logger with a global log level.\n */\nexport class LoggerImpl implements Logger {\n prefix: string;\n readonly #enabledLogLevelNumber: number;\n\n constructor(prefix: string, logLevel: LogLevel) {\n this.prefix = prefix;\n this.#enabledLogLevelNumber = logLevelToLogLevelNumber(logLevel);\n }\n\n isDebug() {\n return this.#isLogLevelEnabled(\"DEBUG\");\n }\n\n /**\n * Performs a debug log with the given message and values if DEBUG level is enabled.\n * @param message\n * @param values\n */\n debug(message: string | Error | unknown, ...values: unknown[]) {\n this.#doLog(\"DEBUG\", message, values);\n }\n\n /**\n * Performs an info log with the given message and values if INFO level is enabled.\n * @param message\n * @param values\n */\n info(message: string | Error | unknown, ...values: unknown[]) {\n this.#doLog(\"INFO\", message, values);\n }\n\n /**\n * Performs a warning log with the given message and values if WARN level is enabled.\n * @param message\n * @param values\n */\n warn(message: string | Error | unknown, ...values: unknown[]) {\n this.#doLog(\"WARN\", message, values);\n }\n\n /**\n * Performs an error log with the given message and values if ERROR level is enabled.\n * @param message\n * @param values\n */\n error(message: string | Error | unknown, ...values: unknown[]) {\n this.#doLog(\"ERROR\", message, values);\n }\n\n /**\n * Internal method for performing the log if the specified level is enabled.\n * @param level\n * @param messageOrError\n * @param values\n * @private\n */\n #doLog(level: LogLevel, messageOrError: string | Error | unknown, values: unknown[]) {\n if (this.#isLogLevelEnabled(level)) {\n let message = `[${level}] ${this.prefix}:`;\n if (!isError(messageOrError)) {\n message += \" \" + String(messageOrError);\n } else {\n values.unshift(messageOrError);\n }\n const consoleMethodName = logLevelToConsoleMethodName(level);\n console[consoleMethodName](message, ...values);\n }\n }\n\n #isLogLevelEnabled(logLevel: LogLevel) {\n const logLevelNumber = logLevelToLogLevelNumber(logLevel);\n return logLevelNumber >= this.#enabledLogLevelNumber;\n }\n}\n\n/**\n * Converts a LogLevel to a browser's debugging console method name.\n * @param logLevel\n */\nfunction logLevelToConsoleMethodName(logLevel: LogLevel): \"debug\" | \"info\" | \"warn\" | \"error\" {\n switch (logLevel) {\n case \"DEBUG\":\n return \"debug\";\n case \"INFO\":\n return \"info\";\n case \"WARN\":\n return \"warn\";\n case \"ERROR\":\n return \"error\";\n }\n}\n\nfunction logLevelToLogLevelNumber(logLevel: LogLevel) {\n return logLevelNumbers[logLevel];\n}\n\nfunction validateLogLevel(logLevelString: string): LogLevel {\n if (!logLevelString) {\n return \"INFO\";\n }\n\n switch (logLevelString) {\n case \"DEBUG\":\n case \"INFO\":\n case \"WARN\":\n case \"ERROR\":\n return logLevelString;\n default:\n throw new Error(\n `invalid log level '${logLevelString}'; allowed levels are: DEBUG, INFO, WARN, ERROR`\n );\n }\n}\n\nfunction isError(value: unknown): value is Error {\n if (value instanceof Error) {\n return true;\n }\n return !!(\n value &&\n typeof value === \"object\" &&\n typeof (value as Partial<Error>).name === \"string\" &&\n typeof (value as Partial<Error>).message === \"string\"\n );\n}\n"],"names":[],"mappings":"AAGA,MAAM,YAAY,OAAO,aAAA,KAAkB,WAAA,GAAc,gBAAA,CAAiB,aAAa,CAAA,GAAI,MAAA;AAyBpF,SAAS,aAAa,MAAA,EAAwB;AACjD,EAAA,OAAO,IAAI,UAAA,CAAW,MAAA,EAAQ,SAAS,CAAA;AAC3C;AASA,MAAM,eAAA,GAA4C;AAAA,EAC9C,KAAA,EAAO,CAAA;AAAA,EACP,IAAA,EAAM,CAAA;AAAA,EACN,IAAA,EAAM,CAAA;AAAA,EACN,KAAA,EAAO;AACX,CAAA;AA4DO,MAAM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,IAAA,OAAO,IAAA;AAAA,EACX;AACA,EAAA,OAAO,CAAC,EACJ,KAAA,IACA,OAAO,KAAA,KAAU,QAAA,IACjB,OAAQ,KAAA,CAAyB,IAAA,KAAS,QAAA,IAC1C,OAAQ,KAAA,CAAyB,OAAA,KAAY,QAAA,CAAA;AAErD;;;;"}
|
package/NumberParser.d.ts
CHANGED
|
@@ -4,12 +4,10 @@
|
|
|
4
4
|
* Only arabic numerals are supported.
|
|
5
5
|
*/
|
|
6
6
|
export declare class NumberParser {
|
|
7
|
-
private
|
|
8
|
-
private readonly groupingRegexPattern;
|
|
7
|
+
#private;
|
|
9
8
|
constructor(locales: Intl.LocalesArgument);
|
|
10
9
|
/**
|
|
11
10
|
* Parses a number from a string considering the locale.
|
|
12
11
|
*/
|
|
13
12
|
parse(numberString: string): number;
|
|
14
|
-
private escapeRegExp;
|
|
15
13
|
}
|
package/NumberParser.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
class NumberParser {
|
|
2
|
-
decimalRegexPattern;
|
|
3
|
-
groupingRegexPattern;
|
|
2
|
+
#decimalRegexPattern;
|
|
3
|
+
#groupingRegexPattern;
|
|
4
4
|
constructor(locales) {
|
|
5
5
|
const numberFormatOptions = {
|
|
6
6
|
useGrouping: true
|
|
@@ -16,11 +16,14 @@ class NumberParser {
|
|
|
16
16
|
if (!groupingSeparator) {
|
|
17
17
|
throw new Error("Could not determine grouping separator.");
|
|
18
18
|
}
|
|
19
|
-
this
|
|
19
|
+
this.#decimalRegexPattern = new RegExp(`${this.#escapeRegExp(decimalSeparator)}`, "g");
|
|
20
20
|
if (groupingSeparator.trim() === "") {
|
|
21
|
-
this
|
|
21
|
+
this.#groupingRegexPattern = /\s/g;
|
|
22
22
|
} else {
|
|
23
|
-
this
|
|
23
|
+
this.#groupingRegexPattern = new RegExp(
|
|
24
|
+
`${this.#escapeRegExp(groupingSeparator)}`,
|
|
25
|
+
"g"
|
|
26
|
+
);
|
|
24
27
|
}
|
|
25
28
|
}
|
|
26
29
|
/**
|
|
@@ -28,11 +31,11 @@ class NumberParser {
|
|
|
28
31
|
*/
|
|
29
32
|
parse(numberString) {
|
|
30
33
|
numberString = numberString.trim();
|
|
31
|
-
const parsedNumberString = numberString.replace(this
|
|
34
|
+
const parsedNumberString = numberString.replace(this.#groupingRegexPattern, "").replace(this.#decimalRegexPattern, ".");
|
|
32
35
|
return !parsedNumberString ? NaN : +parsedNumberString;
|
|
33
36
|
}
|
|
34
37
|
// see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#escaping
|
|
35
|
-
escapeRegExp(string) {
|
|
38
|
+
#escapeRegExp(string) {
|
|
36
39
|
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
37
40
|
}
|
|
38
41
|
}
|
package/NumberParser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberParser.js","sources":["NumberParser.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * This class allows to parse numbers from strings according to the given locale.\n * Currently, in JavaScript there is no built-in way to parse numbers according to the current locale.\n * Only arabic numerals are supported.\n */\nexport class NumberParser {\n
|
|
1
|
+
{"version":3,"file":"NumberParser.js","sources":["NumberParser.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * This class allows to parse numbers from strings according to the given locale.\n * Currently, in JavaScript there is no built-in way to parse numbers according to the current locale.\n * Only arabic numerals are supported.\n */\nexport class NumberParser {\n readonly #decimalRegexPattern: RegExp;\n readonly #groupingRegexPattern: RegExp;\n\n constructor(locales: Intl.LocalesArgument) {\n const numberFormatOptions: Intl.NumberFormatOptions = {\n useGrouping: true\n };\n const formattedParts = new Intl.NumberFormat(locales, numberFormatOptions).formatToParts(\n 12345.6\n );\n\n const decimalSeparator = formattedParts.find((part) => part.type === \"decimal\")?.value;\n if (!decimalSeparator) {\n throw new Error(\"Could not determine decimal separator.\");\n }\n\n const groupingSeparator = formattedParts.find((part) => part.type === \"group\")?.value;\n if (!groupingSeparator) {\n throw new Error(\"Could not determine grouping separator.\");\n }\n\n this.#decimalRegexPattern = new RegExp(`${this.#escapeRegExp(decimalSeparator)}`, \"g\");\n if (groupingSeparator.trim() === \"\") {\n // if a language uses a whitespace as grouping separator, remove all whitespaces (as numbers may not contain whitespaces)\n this.#groupingRegexPattern = /\\s/g;\n } else {\n this.#groupingRegexPattern = new RegExp(\n `${this.#escapeRegExp(groupingSeparator)}`,\n \"g\"\n );\n }\n }\n\n /**\n * Parses a number from a string considering the locale.\n */\n parse(numberString: string): number {\n numberString = numberString.trim();\n\n const parsedNumberString = numberString\n .replace(this.#groupingRegexPattern, \"\")\n .replace(this.#decimalRegexPattern, \".\");\n return !parsedNumberString ? NaN : +parsedNumberString;\n }\n\n // see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#escaping\n #escapeRegExp(string: string) {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\"); // $& means the whole matched string\n }\n}\n"],"names":[],"mappings":"AAQO,MAAM,YAAA,CAAa;AAAA,EACb,oBAAA;AAAA,EACA,qBAAA;AAAA,EAET,YAAY,OAAA,EAA+B;AACvC,IAAA,MAAM,mBAAA,GAAgD;AAAA,MAClD,WAAA,EAAa;AAAA,KACjB;AACA,IAAA,MAAM,iBAAiB,IAAI,IAAA,CAAK,YAAA,CAAa,OAAA,EAAS,mBAAmB,CAAA,CAAE,aAAA;AAAA,MACvE;AAAA,KACJ;AAEA,IAAA,MAAM,gBAAA,GAAmB,eAAe,IAAA,CAAK,CAAC,SAAS,IAAA,CAAK,IAAA,KAAS,SAAS,CAAA,EAAG,KAAA;AACjF,IAAA,IAAI,CAAC,gBAAA,EAAkB;AACnB,MAAA,MAAM,IAAI,MAAM,wCAAwC,CAA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023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nlet enabled = typeof __PRINT_DEPRECATIONS__ !== \"undefined\" ? __PRINT_DEPRECATIONS__ : true;\n\n/**\n * Options supported by {@link deprecated}.\n */\nexport interface DeprecatedOptions {\n /**\n * The package that contains the deprecated entity.\n */\n packageName?: string;\n\n /**\n * The entity name (class name, function name, option, ...) that was deprecated.\n */\n name: string;\n\n /**\n * The version or date in which the entity was deprecated.\n */\n since: string;\n\n /**\n * Available alternatives, if any.\n * Should be a succinct message like `use xyz instead`.\n */\n alternative?: string;\n}\n\n/**\n * To dynamically enable/disable deprecations at runtime.\n *\n * Currently only used for other tests in this project.\n *\n * @internal\n */\nexport function setDeprecationWarningsEnabled(newEnabled: boolean) {\n enabled = newEnabled;\n}\n\n/**\n * Creates a deprecation helper for a deprecated entity.\n *\n * This helper is used to print a deprecation warning to the browser console\n * when the deprecated functionality is being used.\n *\n * Returns a _function_ that should be called when the deprecated entity is being used.\n * The function will print a deprecation warning when usage is detected for the first time.\n * Any further calls will have no effect to prevent spamming the console.\n *\n * > NOTE: Deprecation warnings are only printed in development builds.\n *\n * Example:\n *\n * ```js\n * const printDeprecation = deprecated({\n * name: \"someFunctionName\",\n * packageName: \"some-package\",\n * since: \"v1.2.3\",\n * alternative: \"use xyz instead\"\n * });\n *\n * // Later, when the deprecated function is actually being used:\n * function someFunctionName() {\n * printDeprecation();\n * // ...\n * } *\n * ```\n */\nexport function deprecated(options: DeprecatedOptions): () => void {\n if (!enabled || !import.meta.env.DEV) {\n return () => {}; // do nothing\n }\n\n let called = false;\n return function deprecationHelper() {\n if (!enabled || called) {\n return;\n }\n\n called = true;\n console.warn(buildDeprecationWarning(options));\n };\n}\n\nfunction buildDeprecationWarning(options: DeprecatedOptions): string {\n const { packageName, name, since, alternative } = options;\n const packageInfo = packageName ? ` in ${packageName}` : \"\";\n const alternativeInfo = alternative ? `, ${alternative}` : \"\";\n const message = `⚠️ DEPRECATED: ${name}${packageInfo} (since ${since}${alternativeInfo}) - Please update your code as this may be removed in future versions.`;\n return message;\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deprecated.js","sources":["deprecated.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nlet enabled = typeof __PRINT_DEPRECATIONS__ !== \"undefined\" ? __PRINT_DEPRECATIONS__ : true;\n\n/**\n * Options supported by {@link deprecated}.\n */\nexport interface DeprecatedOptions {\n /**\n * The package that contains the deprecated entity.\n */\n packageName?: string;\n\n /**\n * The entity name (class name, function name, option, ...) that was deprecated.\n */\n name: string;\n\n /**\n * The version or date in which the entity was deprecated.\n */\n since: string;\n\n /**\n * Available alternatives, if any.\n * Should be a succinct message like `use xyz instead`.\n */\n alternative?: string;\n}\n\n/**\n * To dynamically enable/disable deprecations at runtime.\n *\n * Currently only used for other tests in this project.\n *\n * @internal\n */\nexport function setDeprecationWarningsEnabled(newEnabled: boolean) {\n enabled = newEnabled;\n}\n\n/**\n * Creates a deprecation helper for a deprecated entity.\n *\n * This helper is used to print a deprecation warning to the browser console\n * when the deprecated functionality is being used.\n *\n * Returns a _function_ that should be called when the deprecated entity is being used.\n * The function will print a deprecation warning when usage is detected for the first time.\n * Any further calls will have no effect to prevent spamming the console.\n *\n * > NOTE: Deprecation warnings are only printed in development builds.\n *\n * Example:\n *\n * ```js\n * const printDeprecation = deprecated({\n * name: \"someFunctionName\",\n * packageName: \"some-package\",\n * since: \"v1.2.3\",\n * alternative: \"use xyz instead\"\n * });\n *\n * // Later, when the deprecated function is actually being used:\n * function someFunctionName() {\n * printDeprecation();\n * // ...\n * } *\n * ```\n */\nexport function deprecated(options: DeprecatedOptions): () => void {\n if (!enabled || !import.meta.env.DEV) {\n return () => {}; // do nothing\n }\n\n let called = false;\n return function deprecationHelper() {\n if (!enabled || called) {\n return;\n }\n\n called = true;\n console.warn(buildDeprecationWarning(options));\n };\n}\n\nfunction buildDeprecationWarning(options: DeprecatedOptions): string {\n const { packageName, name, since, alternative } = options;\n const packageInfo = packageName ? ` in ${packageName}` : \"\";\n const alternativeInfo = alternative ? `, ${alternative}` : \"\";\n const message = `⚠️ DEPRECATED: ${name}${packageInfo} (since ${since}${alternativeInfo}) - Please update your code as this may be removed in future versions.`;\n return message;\n}\n"],"names":[],"mappings":"AAGA,IAAI,OAAA,GAAU,OAAO,sBAAA,KAA2B,WAAA,GAAc,sBAAA,GAAyB,IAAA;AAoEhF,SAAS,WAAW,OAAA,EAAwC;AAC/D,EAAA,IAAI,CAAC,OAAA,IAAW,CAAC,MAAA,CAAA,IAAA,CAAY,IAAI,GAAA,EAAK;AAClC,IAAA,OAAO,MAAM;AAAA,IAAC,CAAA;AAAA,EAClB;AAEA,EAAA,IAAI,MAAA,GAAS,KAAA;AACb,EAAA,OAAO,SAAS,iBAAA,GAAoB;AAChC,IAAA,IAAI,CAAC,WAAW,MAAA,EAAQ;AACpB,MAAA;AAAA,IACJ;AAEA,IAAA,MAAA,GAAS,IAAA;AACT,IAAA,OAAA,CAAQ,IAAA,CAAK,uBAAA,CAAwB,OAAO,CAAC,CAAA;AAAA,EACjD,CAAA;AACJ;AAEA,SAAS,wBAAwB,OAAA,EAAoC;AACjE,EAAA,MAAM,EAAE,WAAA,EAAa,IAAA,EAAM,KAAA,EAAO,aAAY,GAAI,OAAA;AAClD,EAAA,MAAM,WAAA,GAAc,WAAA,GAAc,CAAA,IAAA,EAAO,WAAW,CAAA,CAAA,GAAK,EAAA;AACzD,EAAA,MAAM,eAAA,GAAkB,WAAA,GAAc,CAAA,EAAA,EAAK,WAAW,CAAA,CAAA,GAAK,EAAA;AAC3D,EAAA,MAAM,OAAA,GAAU,4BAAkB,IAAI,CAAA,EAAG,WAAW,CAAA,QAAA,EAAW,KAAK,GAAG,eAAe,CAAA,sEAAA,CAAA;AACtF,EAAA,OAAO,OAAA;AACX;;;;"}
|
package/equal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"equal.js","sources":["equal.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { deepEqual as deepEqualImpl, shallowEqual as shallowEqualImpl } from \"fast-equals\";\n\n/**\n * Compares two values using shallow equality.\n *\n * This is useful when you want to detect changes on the top level without\n * recursively traversing nested objects.\n *\n * Primitive values are compared by value.\n * Arrays and objects are compared by their own enumerable keys, but nested values are only compared\n * by reference. Circular objects are not supported.\n *\n * > NOTE: This function is intended to be used with _plain old data_ inputs (i.e. mostly JSON).\n *\n * Examples:\n *\n * ```ts\n * shallowEqual({ a: 1 }, { a: 1 }); // true\n * shallowEqual({ a: { x: 1 } }, { a: { x: 1 } }); // false\n * shallowEqual([1, 2], [1, 2]); // true\n * shallowEqual(() => 1, () => 1); // false\n *\n * ```\n */\nexport function shallowEqual(a: unknown, b: unknown): boolean {\n return shallowEqualImpl(a, b);\n}\n\n/**\n * Compares two values using deep equality.\n *\n * This is useful when you need to verify structural equality of nested data.\n *\n * Primitive values are compared by value.\n * Arrays and objects are traversed recursively, so nested values must also be equal.\n * Functions are compared by reference. Circular objects are not supported.\n *\n * > NOTE: This function is intended to be used with _plain old data_ inputs (i.e. mostly JSON).\n *\n * Examples:\n *\n * ```ts\n * deepEqual({ a: { x: 1 } }, { a: { x: 1 } }); // true\n * deepEqual([1, [2, 3]], [1, [2, 3]]); // true\n * deepEqual(() => 1, () => 1); // false\n * ```\n */\nexport function deepEqual(a: unknown, b: unknown): boolean {\n return deepEqualImpl(a, b);\n}\n"],"names":["shallowEqualImpl","deepEqualImpl"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"equal.js","sources":["equal.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { deepEqual as deepEqualImpl, shallowEqual as shallowEqualImpl } from \"fast-equals\";\n\n/**\n * Compares two values using shallow equality.\n *\n * This is useful when you want to detect changes on the top level without\n * recursively traversing nested objects.\n *\n * Primitive values are compared by value.\n * Arrays and objects are compared by their own enumerable keys, but nested values are only compared\n * by reference. Circular objects are not supported.\n *\n * > NOTE: This function is intended to be used with _plain old data_ inputs (i.e. mostly JSON).\n *\n * Examples:\n *\n * ```ts\n * shallowEqual({ a: 1 }, { a: 1 }); // true\n * shallowEqual({ a: { x: 1 } }, { a: { x: 1 } }); // false\n * shallowEqual([1, 2], [1, 2]); // true\n * shallowEqual(() => 1, () => 1); // false\n *\n * ```\n */\nexport function shallowEqual(a: unknown, b: unknown): boolean {\n return shallowEqualImpl(a, b);\n}\n\n/**\n * Compares two values using deep equality.\n *\n * This is useful when you need to verify structural equality of nested data.\n *\n * Primitive values are compared by value.\n * Arrays and objects are traversed recursively, so nested values must also be equal.\n * Functions are compared by reference. Circular objects are not supported.\n *\n * > NOTE: This function is intended to be used with _plain old data_ inputs (i.e. mostly JSON).\n *\n * Examples:\n *\n * ```ts\n * deepEqual({ a: { x: 1 } }, { a: { x: 1 } }); // true\n * deepEqual([1, [2, 3]], [1, [2, 3]]); // true\n * deepEqual(() => 1, () => 1); // false\n * ```\n */\nexport function deepEqual(a: unknown, b: unknown): boolean {\n return deepEqualImpl(a, b);\n}\n"],"names":["shallowEqualImpl","deepEqualImpl"],"mappings":";;AA2BO,SAAS,YAAA,CAAa,GAAY,CAAA,EAAqB;AAC1D,EAAA,OAAOA,cAAA,CAAiB,GAAG,CAAC,CAAA;AAChC;AAqBO,SAAS,SAAA,CAAU,GAAY,CAAA,EAAqB;AACvD,EAAA,OAAOC,WAAA,CAAc,GAAG,CAAC,CAAA;AAC7B;;;;"}
|
package/error.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sources":["error.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nconst GlobalError = globalThis.Error;\n\n/**\n * A custom error class that enforces the use of error ids.\n *\n * An error must be constructed from a (computer-readable) id and a human readable informational text.\n * An optional `cause` option can be passed to indicate the nested reason for an error.\n *\n * # Conventions\n *\n * Error ids should be scoped to a package to avoid conflicts.\n * Each package should pick a sensible namespace prefix.\n *\n * An example for a good error id is `runtime:dependency-cycle`.\n */\nexport class Error extends GlobalError {\n /** Unique error id */\n public readonly id: string;\n\n /** Human readable error message */\n public readonly text: string;\n\n constructor(id: string, text: string, options?: { cause?: unknown }) {\n super(`${id}: ${text}`, options);\n this.id = id;\n this.text = text;\n }\n}\n\n/**\n * Returns the error chain for the given `err`, starting with this error.\n * The error chain contains the error itself and all its causes.\n * The first entry is `err` itself.\n */\nexport function getErrorChain(err: globalThis.Error): globalThis.Error[] {\n const chain: globalThis.Error[] = [];\n do {\n chain.push(err);\n\n //
|
|
1
|
+
{"version":3,"file":"error.js","sources":["error.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nconst GlobalError = globalThis.Error;\n\n/**\n * A custom error class that enforces the use of error ids.\n *\n * An error must be constructed from a (computer-readable) id and a human readable informational text.\n * An optional `cause` option can be passed to indicate the nested reason for an error.\n *\n * # Conventions\n *\n * Error ids should be scoped to a package to avoid conflicts.\n * Each package should pick a sensible namespace prefix.\n *\n * An example for a good error id is `runtime:dependency-cycle`.\n */\nexport class Error extends GlobalError {\n /** Unique error id */\n public readonly id: string;\n\n /** Human readable error message */\n public readonly text: string;\n\n constructor(id: string, text: string, options?: { cause?: unknown }) {\n super(`${id}: ${text}`, options);\n this.id = id;\n this.text = text;\n }\n}\n\n/**\n * Returns the error chain for the given `err`, starting with this error.\n * The error chain contains the error itself and all its causes.\n * The first entry is `err` itself.\n */\nexport function getErrorChain(err: globalThis.Error): globalThis.Error[] {\n const chain: globalThis.Error[] = [];\n do {\n chain.push(err);\n\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n const cause = (err as any).cause as unknown;\n if (!(cause instanceof GlobalError)) {\n break;\n }\n err = cause;\n } while (1); // oxlint-disable-line no-constant-condition\n return chain;\n}\n\n/**\n * Returns true if the error represents an abort error.\n */\nexport function isAbortError(err: unknown): boolean {\n return !!(err && typeof err === \"object\" && \"name\" in err && err.name === \"AbortError\");\n}\n\n/**\n * Throws an abort error (`.name` === `\"AbortError\"`).\n */\nexport function throwAbortError(): never {\n throw createAbortError();\n}\n\n/**\n * Throws `err` if it is an abort error. Does nothing otherwise.\n */\nexport function rethrowAbortError(err: unknown): void {\n if (isAbortError(err)) {\n throw err;\n }\n}\n\n/**\n * Returns an abort error (`.name` === `\"AbortError\"`).\n */\nexport function createAbortError(): globalThis.Error {\n const err = new globalThis.Error(\"Aborted\");\n err.name = \"AbortError\";\n return err;\n}\n"],"names":[],"mappings":"AAGA,MAAM,cAAc,UAAA,CAAW,KAAA;AAexB,MAAM,cAAc,WAAA,CAAY;AAAA;AAAA,EAEnB,EAAA;AAAA;AAAA,EAGA,IAAA;AAAA,EAEhB,WAAA,CAAY,EAAA,EAAY,IAAA,EAAc,OAAA,EAA+B;AACjE,IAAA,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA,EAAA,EAAK,IAAI,IAAI,OAAO,CAAA;AAC/B,IAAA,IAAA,CAAK,EAAA,GAAK,EAAA;AACV,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EAChB;AACJ;AAOO,SAAS,cAAc,GAAA,EAA2C;AACrE,EAAA,MAAM,QAA4B,EAAC;AACnC,EAAA,GAAG;AACC,IAAA,KAAA,CAAM,KAAK,GAAG,CAAA;AAGd,IAAA,MAAM,QAAS,GAAA,CAAY,KAAA;AAC3B,IAAA,IAAI,EAAE,iBAAiB,WAAA,CAAA,EAAc;AACjC,MAAA;AAAA,IACJ;AACA,IAAA,GAAA,GAAM,KAAA;AAAA,EACV,CAAA,QAAS,CAAA;AACT,EAAA,OAAO,KAAA;AACX;AAKO,SAAS,aAAa,GAAA,EAAuB;AAChD,EAAA,OAAO,CAAC,EAAE,GAAA,IAAO,OAAO,QAAQ,QAAA,IAAY,MAAA,IAAU,GAAA,IAAO,GAAA,CAAI,IAAA,KAAS,YAAA,CAAA;AAC9E;AAKO,SAAS,eAAA,GAAyB;AACrC,EAAA,MAAM,gBAAA,EAAiB;AAC3B;AAKO,SAAS,kBAAkB,GAAA,EAAoB;AAClD,EAAA,IAAI,YAAA,CAAa,GAAG,CAAA,EAAG;AACnB,IAAA,MAAM,GAAA;AAAA,EACV;AACJ;AAKO,SAAS,gBAAA,GAAqC;AACjD,EAAA,MAAM,GAAA,GAAM,IAAI,UAAA,CAAW,KAAA,CAAM,SAAS,CAAA;AAC1C,EAAA,GAAA,CAAI,IAAA,GAAO,YAAA;AACX,EAAA,OAAO,GAAA;AACX;;;;"}
|
package/events.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Resource } from "./resources";
|
|
2
|
-
declare const state: unique symbol;
|
|
3
2
|
export type EventNames<Events extends {}> = keyof Events & string;
|
|
4
3
|
type ArgType<T> = [T] extends [void] ? [] : [event: T];
|
|
5
4
|
type EventType<Events extends {}, Name extends keyof Events> = ArgType<Events[Name]>;
|
|
@@ -32,7 +31,7 @@ type EventType<Events extends {}, Name extends keyof Events> = ArgType<Events[Na
|
|
|
32
31
|
* @deprecated Use the package [@conterra/reactivity-events](https://www.npmjs.com/package/@conterra/reactivity-events) instead.
|
|
33
32
|
*/
|
|
34
33
|
export declare class EventEmitter<Events extends {}> {
|
|
35
|
-
private
|
|
34
|
+
#private;
|
|
36
35
|
constructor();
|
|
37
36
|
/**
|
|
38
37
|
* Registers the given listener function as an event handler for `eventName`.
|
package/events.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { deprecated } from './deprecated.js';
|
|
2
1
|
import { on, emit, emitter } from '@conterra/reactivity-events';
|
|
2
|
+
import { deprecated } from './deprecated.js';
|
|
3
3
|
|
|
4
|
-
const state = /* @__PURE__ */ Symbol("EventEmitterState");
|
|
5
4
|
const deprecatedHelper = deprecated({
|
|
6
5
|
name: "EventEmitter",
|
|
7
6
|
packageName: "@open-pioneer/core",
|
|
@@ -11,7 +10,7 @@ const deprecatedHelper = deprecated({
|
|
|
11
10
|
const SYNC_OPT = { dispatch: "sync" };
|
|
12
11
|
const ONCE_OPT = { dispatch: "sync", once: true };
|
|
13
12
|
class EventEmitter {
|
|
14
|
-
|
|
13
|
+
#state = new EventEmitterState();
|
|
15
14
|
constructor() {
|
|
16
15
|
deprecatedHelper();
|
|
17
16
|
}
|
|
@@ -22,7 +21,7 @@ class EventEmitter {
|
|
|
22
21
|
* when it is no longer needed.
|
|
23
22
|
*/
|
|
24
23
|
on(eventName, listener) {
|
|
25
|
-
const e = this
|
|
24
|
+
const e = this.#state.getEmitter(eventName, true);
|
|
26
25
|
return on(e, listener, SYNC_OPT);
|
|
27
26
|
}
|
|
28
27
|
/**
|
|
@@ -32,7 +31,7 @@ class EventEmitter {
|
|
|
32
31
|
* The listener function should be unregistered by destroying the returned {@link Resource}.
|
|
33
32
|
*/
|
|
34
33
|
once(eventName, listener) {
|
|
35
|
-
const e = this
|
|
34
|
+
const e = this.#state.getEmitter(eventName, true);
|
|
36
35
|
return on(e, listener, ONCE_OPT);
|
|
37
36
|
}
|
|
38
37
|
/**
|
|
@@ -42,19 +41,19 @@ class EventEmitter {
|
|
|
42
41
|
* After `emit()` has completed, all listeners will already have been invoked.
|
|
43
42
|
*/
|
|
44
43
|
emit(eventName, ...args) {
|
|
45
|
-
const e = this
|
|
44
|
+
const e = this.#state.getEmitter(eventName);
|
|
46
45
|
if (e) {
|
|
47
46
|
emit(e, args[0]);
|
|
48
47
|
}
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
50
|
class EventEmitterState {
|
|
52
|
-
emitters = /* @__PURE__ */ new Map();
|
|
51
|
+
#emitters = /* @__PURE__ */ new Map();
|
|
53
52
|
getEmitter(name, init = false) {
|
|
54
|
-
let e = this
|
|
53
|
+
let e = this.#emitters.get(name);
|
|
55
54
|
if (!e && init) {
|
|
56
55
|
e = emitter();
|
|
57
|
-
this
|
|
56
|
+
this.#emitters.set(name, e);
|
|
58
57
|
}
|
|
59
58
|
return e;
|
|
60
59
|
}
|
package/events.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sources":["events.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\
|
|
1
|
+
{"version":3,"file":"events.js","sources":["events.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n emit,\n emitter,\n on,\n EventEmitter as ReactivityEmitter,\n SubscribeOptions\n} from \"@conterra/reactivity-events\";\nimport { deprecated } from \"./deprecated\";\nimport { Resource } from \"./resources\";\n\nexport type EventNames<Events extends {}> = keyof Events & string;\n\ntype ArgType<T> = [T] extends [void] ? [] : [event: T];\n\ntype EventType<Events extends {}, Name extends keyof Events> = ArgType<Events[Name]>;\n\nconst deprecatedHelper = deprecated({\n name: \"EventEmitter\",\n packageName: \"@open-pioneer/core\",\n since: \"v4.2.0\",\n alternative: \"use @conterra/reactivity-events instead\"\n});\n\nconst SYNC_OPT = { dispatch: \"sync\" } as const satisfies SubscribeOptions;\nconst ONCE_OPT = { dispatch: \"sync\", once: true } as const satisfies SubscribeOptions;\n\n/**\n * A support class that implements emitting and listening for events.\n *\n * This class supports inheritance or direct use:\n *\n * ```js\n * const emitter = new EventEmitter();\n * class MyClass extends EventEmitter {};\n * ```\n *\n * When using this class from TypeScript, declare your supported event\n * types using an interface first:\n *\n * ```ts\n * interface Events {\n * // key: event name, value: event type\n * \"mouse-clicked\": MouseEvent;\n * }\n *\n * const emitter = new EventEmitter<Events>();\n * emitter.on(\"mouse-clicked\", (event) => {\n * // event is a MouseEvent\n * });\n * emitter.emit(\"mouse-clicked\", new MouseEvent(...));\n * ```\n *\n * @deprecated Use the package [@conterra/reactivity-events](https://www.npmjs.com/package/@conterra/reactivity-events) instead.\n */\nexport class EventEmitter<Events extends {}> {\n #state = new EventEmitterState();\n\n constructor() {\n deprecatedHelper();\n }\n\n /**\n * Registers the given listener function as an event handler for `eventName`.\n *\n * The listener function should be unregistered by destroying the returned {@link Resource}\n * when it is no longer needed.\n */\n on<Name extends EventNames<Events>>(\n eventName: Name,\n listener: (...args: EventType<Events, Name>) => void\n ): Resource {\n const e = this.#state.getEmitter(eventName, true);\n return on(e, listener as InternalListener, SYNC_OPT);\n }\n\n /**\n * Registers the given listener function to listen for `eventName` events _once_.\n * The listener function will automatically be unregistered after it has been called.\n *\n * The listener function should be unregistered by destroying the returned {@link Resource}.\n */\n once<Name extends EventNames<Events>>(\n eventName: Name,\n listener: (...args: EventType<Events, Name>) => void\n ): Resource {\n const e = this.#state.getEmitter(eventName, true);\n return on(e, listener as InternalListener, ONCE_OPT);\n }\n\n /**\n * Emits an event of the given name and calls the registered event handlers.\n *\n * _Note:_ event handlers run synchronously.\n * After `emit()` has completed, all listeners will already have been invoked.\n */\n emit<Name extends EventNames<Events>>(eventName: Name, ...args: EventType<Events, Name>): void {\n const e = this.#state.getEmitter(eventName);\n if (e) {\n emit(e, args[0]);\n }\n }\n}\n\n/**\n * Read-only version of the {@link EventEmitter} interface that only allows listening for events.\n *\n * @deprecated Use the package [@conterra/reactivity-events](https://www.npmjs.com/package/@conterra/reactivity-events) instead.\n */\nexport type EventSource<Events extends {}> = Pick<EventEmitter<Events>, \"on\" | \"once\">;\n\ntype InternalListener = (event: unknown) => void;\n\nclass EventEmitterState {\n #emitters = new Map<string, ReactivityEmitter<unknown>>();\n\n getEmitter(name: string): ReactivityEmitter<unknown> | undefined;\n getEmitter(name: string, init: true): ReactivityEmitter<unknown>;\n getEmitter(name: string, init = false) {\n let e = this.#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AC,CAAC,CAAA;AAAA,IACnB;AAAA,EACJ;AACJ;AAWA,MAAM,iBAAA,CAAkB;AAAA,EACpB,SAAA,uBAAgB,GAAA,EAAwC;AAAA,EAIxD,UAAA,CAAW,IAAA,EAAc,IAAA,GAAO,KAAA,EAAO;AACnC,IAAA,IAAI,CAAA,GAAI,IAAA,CAAK,SAAA,CAAU,GAAA,CAAI,IAAI,CAAA;AAC/B,IAAA,IAAI,CAAC,KAAK,IAAA,EAAM;AACZ,MAAA,CAAA,GAAI,OAAA,EAAQ;AACZ,MAAA,IAAA,CAAK,SAAA,CAAU,GAAA,CAAI,IAAA,EAAM,CAAC,CAAA;AAAA,IAC9B;AACA,IAAA,OAAO,CAAA;AAAA,EACX;AACJ;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@open-pioneer/core",
|
|
4
|
-
"version": "4.7.0-dev.
|
|
4
|
+
"version": "4.7.0-dev.20260727091735",
|
|
5
5
|
"description": "Contains basic utility functions and classes used by the @open-pioneer project.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"open-pioneer-trails"
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@conterra/reactivity-events": "^0.8.6",
|
|
18
|
-
"fast-equals": "^6.0.
|
|
18
|
+
"fast-equals": "^6.0.2"
|
|
19
19
|
},
|
|
20
20
|
"exports": {
|
|
21
21
|
"./package.json": "./package.json",
|
package/resources.d.ts
CHANGED
|
@@ -12,10 +12,10 @@ export interface Resource {
|
|
|
12
12
|
*
|
|
13
13
|
* ```js
|
|
14
14
|
* class Holder {
|
|
15
|
-
*
|
|
15
|
+
* #myResource: Resource | undefined;
|
|
16
16
|
*
|
|
17
17
|
* destroy() {
|
|
18
|
-
* this
|
|
18
|
+
* this.#myResource = destroyResource(this.#myResource);
|
|
19
19
|
* }
|
|
20
20
|
* }
|
|
21
21
|
* ```
|
package/resources.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resources.js","sources":["resources.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n/**\n * An object that has some cleanup code associated with it.\n */\nexport interface Resource {\n /** A function that releases any state held by the resource. */\n destroy(): void;\n}\n\n/**\n * A helper function that invokes `destroy()` on the given resource and returns undefined.\n *\n * Example:\n *\n * ```js\n * class Holder {\n *
|
|
1
|
+
{"version":3,"file":"resources.js","sources":["resources.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * An object that has some cleanup code associated with it.\n */\nexport interface Resource {\n /** A function that releases any state held by the resource. */\n destroy(): void;\n}\n\n/**\n * A helper function that invokes `destroy()` on the given resource and returns undefined.\n *\n * Example:\n *\n * ```js\n * class Holder {\n * #myResource: Resource | undefined;\n *\n * destroy() {\n * this.#myResource = destroyResource(this.#myResource);\n * }\n * }\n * ```\n */\nexport function destroyResource<R extends Resource>(resource: R | undefined): undefined {\n resource?.destroy();\n return undefined;\n}\n\n/**\n * A helper function that invokes `destroy()` on each resource in the given array.\n *\n * This function destroys the resources in reverse order (starting from the last element).\n * This is done to reverse the order of construction.\n *\n * The array will be cleared by this function.\n */\nexport function destroyResources<R extends Resource>(resources: R[]): void {\n // `destroy()` might call us in a cycle, so we modify the array in place.\n let resource: Resource | undefined;\n while ((resource = resources.pop())) {\n resource.destroy();\n }\n}\n"],"names":[],"mappings":"AA0BO,SAAS,gBAAoC,QAAA,EAAoC;AACpF,EAAA,QAAA,EAAU,OAAA,EAAQ;AAClB,EAAA,OAAO,MAAA;AACX;AAUO,SAAS,iBAAqC,SAAA,EAAsB;AAEvE,EAAA,IAAI,QAAA;AACJ,EAAA,OAAQ,QAAA,GAAW,SAAA,CAAU,GAAA,EAAI,EAAI;AACjC,IAAA,QAAA,CAAS,OAAA,EAAQ;AAAA,EACrB;AACJ;;;;"}
|