@open-pioneer/notifier 4.9.0-dev.20260930055642 → 4.9.0-dev.20261029090037
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 +5 -1
- package/NotificationServiceImpl.d.ts +2 -6
- package/NotificationServiceImpl.js +0 -1
- package/NotificationServiceImpl.js.map +1 -1
- package/README.md +2 -2
- package/api.d.ts +4 -4
- package/package.json +4 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CreateToasterReturn } from "@chakra-ui/react";
|
|
2
2
|
import { Resource } from "@open-pioneer/core";
|
|
3
|
-
import {
|
|
3
|
+
import { ServiceOptions } from "@open-pioneer/runtime";
|
|
4
4
|
import type { NotificationOptions, NotificationService, SimpleNotificationOptions } from "./api";
|
|
5
5
|
export type ToasterObject = CreateToasterReturn;
|
|
6
6
|
export interface ToastMeta {
|
|
@@ -10,13 +10,10 @@ export interface InternalNotificationAPI extends NotificationService {
|
|
|
10
10
|
readonly toaster: ToasterObject;
|
|
11
11
|
registerUI(): Resource | undefined;
|
|
12
12
|
}
|
|
13
|
-
interface References {
|
|
14
|
-
appCtx: ApplicationContext;
|
|
15
|
-
}
|
|
16
13
|
export declare class NotificationServiceImpl implements InternalNotificationAPI {
|
|
17
14
|
#private;
|
|
18
15
|
readonly toaster: ToasterObject;
|
|
19
|
-
constructor({ properties }: ServiceOptions
|
|
16
|
+
constructor({ properties }: ServiceOptions);
|
|
20
17
|
destroy(): void;
|
|
21
18
|
notify(options: NotificationOptions): void;
|
|
22
19
|
success(options: SimpleNotificationOptions): void;
|
|
@@ -26,4 +23,3 @@ export declare class NotificationServiceImpl implements InternalNotificationAPI
|
|
|
26
23
|
closeAll(): void;
|
|
27
24
|
registerUI(): Resource | undefined;
|
|
28
25
|
}
|
|
29
|
-
export {};
|
|
@@ -7,7 +7,6 @@ const PERSISTENT_TIMEOUT = 7 * 24 * 60 * 60 * 1e3;
|
|
|
7
7
|
class NotificationServiceImpl {
|
|
8
8
|
#uiPresent = false;
|
|
9
9
|
#uiCheckTimeoutId;
|
|
10
|
-
// oxlint-disable-line @typescript-eslint/no-explicit-any
|
|
11
10
|
toaster;
|
|
12
11
|
constructor({ properties }) {
|
|
13
12
|
const typedProperties = properties;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotificationServiceImpl.js","sources":["NotificationServiceImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { createToaster, CreateToasterProps, CreateToasterReturn } from \"@chakra-ui/react\";\nimport { createLogger, Resource } from \"@open-pioneer/core\";\nimport {
|
|
1
|
+
{"version":3,"file":"NotificationServiceImpl.js","sources":["NotificationServiceImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { createToaster, CreateToasterProps, CreateToasterReturn } from \"@chakra-ui/react\";\nimport { createLogger, Resource } from \"@open-pioneer/core\";\nimport { ServiceOptions } from \"@open-pioneer/runtime\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport type {\n NotificationLevel,\n NotificationOptions,\n NotificationService,\n NotifierProperties,\n OffsetsObject,\n SimpleNotificationOptions\n} from \"./api\";\nconst LOG = createLogger(sourceId);\n\nexport type ToasterObject = CreateToasterReturn;\n\nexport interface ToastMeta {\n closable: boolean;\n}\n\nexport interface InternalNotificationAPI extends NotificationService {\n // Toasts in here carry `ToastMeta` metadata\n readonly toaster: ToasterObject;\n registerUI(): Resource | undefined;\n}\n\n// 7 days, because Chakra has no indefinite toast duration.\nconst PERSISTENT_TIMEOUT = 7 * 24 * 60 * 60 * 1000;\n\nexport class NotificationServiceImpl implements InternalNotificationAPI {\n #uiPresent = false;\n #uiCheckTimeoutId: ReturnType<typeof setTimeout> | undefined;\n\n readonly toaster: ToasterObject;\n\n constructor({ properties }: ServiceOptions) {\n const typedProperties = properties as NotifierProperties;\n\n this.toaster = createToaster({\n placement: getPlacement(typedProperties.position),\n offsets: getOffsets(typedProperties.offsets),\n pauseOnPageIdle: true\n });\n\n if (import.meta.env.DEV && !import.meta.env.VITEST) {\n this.#uiCheckTimeoutId = setTimeout(() => {\n this.#checkUiNotification();\n this.#uiCheckTimeoutId = undefined;\n }, 5000);\n }\n }\n\n destroy() {\n clearTimeout(this.#uiCheckTimeoutId);\n this.#uiCheckTimeoutId = undefined;\n }\n\n notify(options: NotificationOptions): void {\n // Slightly delay the create call.\n // `toaster.create` currently calls `React.flushSync` somewhere deep inside zag-js.\n // This causes warnings when calling `notify()` in a useEffect().\n queueMicrotask(() => {\n this.toaster.create({\n type: options.level ?? \"info\",\n title: options.title,\n description: options.message,\n\n // Chakra currently has no concept of persistent toasts (other than type \"loading\"),\n // so we just use a very long timeout instead.\n // Note: MAX_VALUE or Infinity does not work either (probably too big for some computations made internally).\n duration: options.displayDuration ?? PERSISTENT_TIMEOUT,\n\n // Additional data for the toast (can be arbitrary)\n meta: {\n closable: true\n } satisfies ToastMeta\n });\n });\n }\n\n success(options: SimpleNotificationOptions): void {\n this.#sendSimpleNotification(\"success\", options);\n }\n\n info(options: SimpleNotificationOptions): void {\n this.#sendSimpleNotification(\"info\", options);\n }\n\n warning(options: SimpleNotificationOptions): void {\n this.#sendSimpleNotification(\"warning\", options);\n }\n\n error(options: SimpleNotificationOptions): void {\n this.#sendSimpleNotification(\"error\", options);\n }\n\n #sendSimpleNotification(level: NotificationLevel, options: SimpleNotificationOptions): void {\n if (typeof options === \"string\") {\n options = { message: options };\n }\n this.notify({ ...options, level });\n }\n\n closeAll(): void {\n this.toaster.dismiss();\n }\n\n registerUI(): Resource | undefined {\n // We only support exactly one handler.\n if (this.#uiPresent) {\n LOG.warn(\n \"A notifier UI has already been registered; this new component will be ignored.\\n\" +\n \"The <Notifier /> component has likely been used twice in your application.\"\n );\n return undefined;\n }\n\n this.#uiPresent = true;\n let destroyed = false;\n return {\n destroy: () => {\n if (destroyed) {\n return;\n }\n\n destroyed = true;\n this.#uiPresent = false;\n }\n };\n }\n\n #checkUiNotification() {\n if (!this.#uiPresent) {\n LOG.warn(\n `No notifier UI has been registered: notifications will not be visible.\\n` +\n `Make sure that your app contains the <Notifier /> component.`\n );\n }\n }\n}\n\n// Map to chakra placement\nfunction getPlacement(\n configPosition: NotifierProperties[\"position\"] = \"top-right\"\n): CreateToasterProps[\"placement\"] {\n switch (configPosition) {\n case \"top\":\n return \"top\";\n case \"top-left\":\n return \"top-start\";\n case \"top-right\":\n return \"top-end\";\n case \"bottom\":\n return \"bottom\";\n case \"bottom-left\":\n return \"bottom-start\";\n case \"bottom-right\":\n return \"bottom-end\";\n default:\n return \"top-end\";\n }\n}\n\nfunction getOffsets(offsetsConfig: NotifierProperties[\"offsets\"]): OffsetsObject | undefined {\n if (!offsetsConfig) {\n return undefined;\n }\n\n if (typeof offsetsConfig === \"string\") {\n return {\n left: offsetsConfig,\n top: offsetsConfig,\n right: offsetsConfig,\n bottom: offsetsConfig\n };\n }\n\n if (typeof offsetsConfig !== \"object\") {\n throw new Error(\"Unexpected 'offsets' property value: must be a string or an object.\");\n }\n checkProp(offsetsConfig, \"left\");\n checkProp(offsetsConfig, \"top\");\n checkProp(offsetsConfig, \"right\");\n checkProp(offsetsConfig, \"bottom\");\n return offsetsConfig;\n}\n\nfunction checkProp(obj: Partial<OffsetsObject>, prop: keyof OffsetsObject) {\n if (!obj[prop]) {\n throw new Error(`Offset '${prop}' is required.`);\n }\n}\n"],"names":[],"mappings":";;;;AAeA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAejC,MAAM,kBAAA,GAAqB,CAAA,GAAI,EAAA,GAAK,EAAA,GAAK,EAAA,GAAK,GAAA;AAEvC,MAAM,uBAAA,CAA2D;AAAA,EACpE,UAAA,GAAa,KAAA;AAAA,EACb,iBAAA;AAAA,EAES,OAAA;AAAA,EAET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
|
|
6
6
|
|
|
7
7
|
### Displaying notifications in an application
|
|
8
8
|
|
|
9
|
-
The `<Notifier />` must be used in your app's UI
|
|
9
|
+
The `<Notifier />` must be used in your app's UI, otherwise notifications from application components are not shown. It should be present exactly once.
|
|
10
10
|
|
|
11
11
|
```jsx
|
|
12
12
|
import { Notifier } from "@open-pioneer/notifier";
|
|
@@ -69,7 +69,7 @@ const Element = createCustomElement({
|
|
|
69
69
|
### Emitting notifications
|
|
70
70
|
|
|
71
71
|
Reference the interface name `notifier.NotificationService` to inject an instance of `NotificationService`.
|
|
72
|
-
That service can be used to emit
|
|
72
|
+
That service can be used to emit notifications from any service or UI component in the application:
|
|
73
73
|
|
|
74
74
|
```ts
|
|
75
75
|
const notificationService = ...; // injected
|
package/api.d.ts
CHANGED
|
@@ -47,13 +47,13 @@ export interface NotificationService extends DeclaredService<"notifier.Notificat
|
|
|
47
47
|
* @param options Options for the new notification.
|
|
48
48
|
*/
|
|
49
49
|
notify(options: NotificationOptions): void;
|
|
50
|
-
/** Emits a success notification. Same as {@link notify} with `
|
|
50
|
+
/** Emits a success notification. Same as {@link notify} with `level: "success"`. */
|
|
51
51
|
success(options: SimpleNotificationOptions): void;
|
|
52
|
-
/** Emits an info notification. Same as {@link notify} with `
|
|
52
|
+
/** Emits an info notification. Same as {@link notify} with `level: "info"`. */
|
|
53
53
|
info(options: SimpleNotificationOptions): void;
|
|
54
|
-
/** Emits a warning notification. Same as {@link notify} with `
|
|
54
|
+
/** Emits a warning notification. Same as {@link notify} with `level: "warning"`. */
|
|
55
55
|
warning(options: SimpleNotificationOptions): void;
|
|
56
|
-
/** Emits an error notification. Same as {@link notify} with `
|
|
56
|
+
/** Emits an error notification. Same as {@link notify} with `level: "error"`. */
|
|
57
57
|
error(options: SimpleNotificationOptions): void;
|
|
58
58
|
/** Closes all active notifications. */
|
|
59
59
|
closeAll(): void;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@open-pioneer/notifier",
|
|
4
|
-
"version": "4.9.0-dev.
|
|
4
|
+
"version": "4.9.0-dev.20261029090037",
|
|
5
5
|
"description": "Provides support for application-wide notifications.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"open-pioneer-trails"
|
|
@@ -15,10 +15,9 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@chakra-ui/react": "^3.37.0",
|
|
18
|
-
"@open-pioneer/core": "4.9.0-dev.
|
|
19
|
-
"@open-pioneer/
|
|
20
|
-
"
|
|
21
|
-
"react": "^19.3.0",
|
|
18
|
+
"@open-pioneer/core": "4.9.0-dev.20261029090037",
|
|
19
|
+
"@open-pioneer/runtime": "4.9.0-dev.20261029090037",
|
|
20
|
+
"react": "^19.3.1",
|
|
22
21
|
"react-icons": "^5.7.0"
|
|
23
22
|
},
|
|
24
23
|
"publishConfig": {
|