@open-pioneer/notifier 3.0.0 → 4.0.0-dev-chakra-v3.20250320123304
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 +39 -0
- package/NotificationServiceImpl.d.ts +15 -26
- package/NotificationServiceImpl.js +59 -52
- package/NotificationServiceImpl.js.map +1 -1
- package/Notifier.d.ts +2 -9
- package/Notifier.js +62 -38
- package/Notifier.js.map +1 -1
- package/_virtual/_virtual-pioneer-module_react-hooks.js +3 -2
- package/_virtual/_virtual-pioneer-module_react-hooks.js.map +1 -1
- package/api.d.ts +11 -0
- package/i18n/de.yaml +5 -0
- package/i18n/en.yaml +5 -0
- package/package.json +24 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
# @open-pioneer/notifier
|
|
2
2
|
|
|
3
|
+
## 4.0.0-dev-chakra-v3.20250320123304
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- bd4f254: Update to Chakra 3.x
|
|
8
|
+
- 804d332: **Breaking**: The `position` property has moved from the `<Notifier />` component to package properties.
|
|
9
|
+
In order to change to location of notifications, you need to customize the package properties.
|
|
10
|
+
|
|
11
|
+
Before:
|
|
12
|
+
|
|
13
|
+
```jsx
|
|
14
|
+
// App.jsx
|
|
15
|
+
<Notifier position="top-right" />
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
After:
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
// app.ts
|
|
22
|
+
const Element = createCustomElement({
|
|
23
|
+
// ...
|
|
24
|
+
config: {
|
|
25
|
+
properties: {
|
|
26
|
+
"@open-pioneer/notifier": {
|
|
27
|
+
position: "top-right"
|
|
28
|
+
} satisfies NotifierProperties
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// or use resolveConfig()
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- Updated dependencies [bd4f254]
|
|
38
|
+
- @open-pioneer/react-utils@4.0.0-dev-chakra-v3.20250320123304
|
|
39
|
+
- @open-pioneer/runtime@4.0.0-dev-chakra-v3.20250320123304
|
|
40
|
+
- @open-pioneer/core@4.0.0-dev-chakra-v3.20250320123304
|
|
41
|
+
|
|
3
42
|
## 3.0.0
|
|
4
43
|
|
|
5
44
|
### Major Changes
|
|
@@ -1,34 +1,22 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { CreateToasterReturn } from "@chakra-ui/react";
|
|
2
|
+
import type { NotificationOptions, NotificationService, SimpleNotificationOptions } from "./api";
|
|
2
3
|
import { Resource } from "@open-pioneer/core";
|
|
3
|
-
import
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
level: NotificationLevel;
|
|
8
|
-
displayDuration: number | undefined;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* The notification handler is implemented by the UI in order to receive events.
|
|
12
|
-
* There can only be one handler at a time.
|
|
13
|
-
*
|
|
14
|
-
* Calls to the handler may be buffered to allow for notifications before the UI has become ready.
|
|
15
|
-
*/
|
|
16
|
-
export interface NotificationHandler {
|
|
17
|
-
/** Called by the service to emit the notification. */
|
|
18
|
-
showNotification(notification: Notification): void;
|
|
19
|
-
/** Removes all active notifications. */
|
|
20
|
-
closeAll(): void;
|
|
4
|
+
import { ApplicationContext, ServiceOptions } from "@open-pioneer/runtime";
|
|
5
|
+
export type ToasterObject = CreateToasterReturn;
|
|
6
|
+
export interface ToastMeta {
|
|
7
|
+
closable: boolean;
|
|
21
8
|
}
|
|
22
9
|
export interface InternalNotificationAPI extends NotificationService {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
10
|
+
readonly toaster: ToasterObject;
|
|
11
|
+
registerUI(): Resource | undefined;
|
|
12
|
+
}
|
|
13
|
+
interface References {
|
|
14
|
+
appCtx: ApplicationContext;
|
|
28
15
|
}
|
|
29
16
|
export declare class NotificationServiceImpl implements InternalNotificationAPI {
|
|
30
17
|
#private;
|
|
31
|
-
|
|
18
|
+
readonly toaster: ToasterObject;
|
|
19
|
+
constructor({ references: { appCtx }, properties }: ServiceOptions<References>);
|
|
32
20
|
destroy(): void;
|
|
33
21
|
notify(options: NotificationOptions): void;
|
|
34
22
|
success(options: SimpleNotificationOptions): void;
|
|
@@ -36,5 +24,6 @@ export declare class NotificationServiceImpl implements InternalNotificationAPI
|
|
|
36
24
|
warning(options: SimpleNotificationOptions): void;
|
|
37
25
|
error(options: SimpleNotificationOptions): void;
|
|
38
26
|
closeAll(): void;
|
|
39
|
-
|
|
27
|
+
registerUI(): Resource | undefined;
|
|
40
28
|
}
|
|
29
|
+
export {};
|
|
@@ -1,29 +1,46 @@
|
|
|
1
|
+
import { createToaster } from '@chakra-ui/react';
|
|
1
2
|
import { createLogger } from '@open-pioneer/core';
|
|
2
3
|
|
|
3
4
|
const LOG = createLogger("notifier:NotificationService");
|
|
5
|
+
const PERSISTENT_TIMEOUT = 7 * 24 * 60 * 60 * 1e3;
|
|
4
6
|
class NotificationServiceImpl {
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#checkTimeoutId;
|
|
7
|
+
#uiPresent = false;
|
|
8
|
+
#uiCheckTimeoutId;
|
|
8
9
|
// eslint-disable-line @typescript-eslint/no-explicit-any
|
|
9
|
-
|
|
10
|
+
toaster;
|
|
11
|
+
constructor({ references: { appCtx }, properties }) {
|
|
12
|
+
const typedProperties = properties;
|
|
13
|
+
const rootNode = appCtx.getShadowRoot();
|
|
14
|
+
this.toaster = createToaster({
|
|
15
|
+
placement: getPlacement(typedProperties.position),
|
|
16
|
+
pauseOnPageIdle: true,
|
|
17
|
+
// Needed for `.getElementById()` queries
|
|
18
|
+
getRootNode: () => rootNode
|
|
19
|
+
});
|
|
10
20
|
if (import.meta.env.DEV) {
|
|
11
|
-
this.#
|
|
12
|
-
this.#
|
|
13
|
-
this.#
|
|
21
|
+
this.#uiCheckTimeoutId = setTimeout(() => {
|
|
22
|
+
this.#checkUiNotification();
|
|
23
|
+
this.#uiCheckTimeoutId = void 0;
|
|
14
24
|
}, 5e3);
|
|
15
25
|
}
|
|
16
26
|
}
|
|
17
27
|
destroy() {
|
|
18
|
-
clearTimeout(this.#
|
|
19
|
-
this.#
|
|
28
|
+
clearTimeout(this.#uiCheckTimeoutId);
|
|
29
|
+
this.#uiCheckTimeoutId = void 0;
|
|
20
30
|
}
|
|
21
31
|
notify(options) {
|
|
22
|
-
this
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
32
|
+
this.toaster.create({
|
|
33
|
+
type: options.level,
|
|
34
|
+
title: options.title,
|
|
35
|
+
description: options.message,
|
|
36
|
+
// Chakra currently has no concept of persistent toasts (other than type "loading"),
|
|
37
|
+
// so we just use a very long timeout instead.
|
|
38
|
+
// Note: MAX_VALUE or Infinity does not work either (probably too big for some computations made internally).
|
|
39
|
+
duration: options.displayDuration ?? PERSISTENT_TIMEOUT,
|
|
40
|
+
// Additional data for the toast (can be arbitrary)
|
|
41
|
+
meta: {
|
|
42
|
+
closable: true
|
|
43
|
+
}
|
|
27
44
|
});
|
|
28
45
|
}
|
|
29
46
|
success(options) {
|
|
@@ -45,27 +62,16 @@ class NotificationServiceImpl {
|
|
|
45
62
|
this.notify({ ...options, level });
|
|
46
63
|
}
|
|
47
64
|
closeAll() {
|
|
48
|
-
this
|
|
65
|
+
this.toaster.dismiss();
|
|
49
66
|
}
|
|
50
|
-
|
|
51
|
-
if (this.#
|
|
67
|
+
registerUI() {
|
|
68
|
+
if (this.#uiPresent) {
|
|
52
69
|
LOG.warn(
|
|
53
|
-
"A
|
|
70
|
+
"A notifier UI has already been registered; this new component will be ignored.\nThe <Notifier /> component has likely been used twice in your application."
|
|
54
71
|
);
|
|
55
|
-
return
|
|
56
|
-
destroy() {
|
|
57
|
-
return void 0;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
this.#handler = handler;
|
|
62
|
-
const buffered = this.#buffered;
|
|
63
|
-
this.#buffered = void 0;
|
|
64
|
-
if (buffered) {
|
|
65
|
-
for (const [name, ...args] of buffered) {
|
|
66
|
-
handler[name](...args);
|
|
67
|
-
}
|
|
72
|
+
return void 0;
|
|
68
73
|
}
|
|
74
|
+
this.#uiPresent = true;
|
|
69
75
|
let destroyed = false;
|
|
70
76
|
return {
|
|
71
77
|
destroy: () => {
|
|
@@ -73,36 +79,37 @@ class NotificationServiceImpl {
|
|
|
73
79
|
return;
|
|
74
80
|
}
|
|
75
81
|
destroyed = true;
|
|
76
|
-
|
|
77
|
-
this.#handler = void 0;
|
|
78
|
-
}
|
|
82
|
+
this.#uiPresent = false;
|
|
79
83
|
}
|
|
80
84
|
};
|
|
81
85
|
}
|
|
82
|
-
#
|
|
83
|
-
if (this.#
|
|
84
|
-
this.#handler[method](...args);
|
|
85
|
-
} else {
|
|
86
|
-
const buffered = this.#buffered ??= [];
|
|
87
|
-
if (buffered.length >= 1024) {
|
|
88
|
-
LOG.error(
|
|
89
|
-
"Internal notification buffer overflow: this event will be dropped to prevent a memory leak.\nMake sure that the UI is configured to display notifications (use <Notifier />).",
|
|
90
|
-
{ method, args }
|
|
91
|
-
);
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
buffered.push([method, ...args]);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
#checkHandlerRegistration() {
|
|
98
|
-
if (!this.#handler) {
|
|
86
|
+
#checkUiNotification() {
|
|
87
|
+
if (!this.#uiPresent) {
|
|
99
88
|
LOG.warn(
|
|
100
|
-
`No
|
|
89
|
+
`No notifier UI has been registered: notifications will not be visible.
|
|
101
90
|
Make sure that your app contains the <Notifier /> component.`
|
|
102
91
|
);
|
|
103
92
|
}
|
|
104
93
|
}
|
|
105
94
|
}
|
|
95
|
+
function getPlacement(configPosition = "top-right") {
|
|
96
|
+
switch (configPosition) {
|
|
97
|
+
case "top":
|
|
98
|
+
return "top";
|
|
99
|
+
case "top-left":
|
|
100
|
+
return "top-start";
|
|
101
|
+
case "top-right":
|
|
102
|
+
return "top-end";
|
|
103
|
+
case "bottom":
|
|
104
|
+
return "bottom";
|
|
105
|
+
case "bottom-left":
|
|
106
|
+
return "bottom-start";
|
|
107
|
+
case "bottom-right":
|
|
108
|
+
return "bottom-end";
|
|
109
|
+
default:
|
|
110
|
+
return "top-end";
|
|
111
|
+
}
|
|
112
|
+
}
|
|
106
113
|
|
|
107
114
|
export { NotificationServiceImpl };
|
|
108
115
|
//# sourceMappingURL=NotificationServiceImpl.js.map
|
|
@@ -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\nimport type {\n NotificationLevel,\n NotificationOptions,\n NotificationService,\n SimpleNotificationOptions\n} from \"./api\";\nimport { Resource, createLogger } 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\nimport { createToaster, CreateToasterProps, CreateToasterReturn } from \"@chakra-ui/react\";\nimport type {\n NotificationLevel,\n NotificationOptions,\n NotificationService,\n NotifierProperties,\n SimpleNotificationOptions\n} from \"./api\";\nimport { Resource, createLogger } from \"@open-pioneer/core\";\nimport { ApplicationContext, ServiceOptions } from \"@open-pioneer/runtime\";\nconst LOG = createLogger(\"notifier:NotificationService\");\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\ninterface References {\n appCtx: ApplicationContext;\n}\n\n// 7 days\nconst PERSISTENT_TIMEOUT = 7 * 24 * 60 * 60 * 1000;\n\nexport class NotificationServiceImpl implements InternalNotificationAPI {\n #uiPresent = false;\n #uiCheckTimeoutId: any; // eslint-disable-line @typescript-eslint/no-explicit-any\n\n readonly toaster: ToasterObject;\n\n constructor({ references: { appCtx }, properties }: ServiceOptions<References>) {\n const typedProperties = properties as NotifierProperties;\n\n const rootNode = appCtx.getShadowRoot();\n this.toaster = createToaster({\n placement: getPlacement(typedProperties.position),\n pauseOnPageIdle: true,\n\n // Needed for `.getElementById()` queries\n getRootNode: () => rootNode\n });\n\n if (import.meta.env.DEV) {\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 this.toaster.create({\n type: options.level,\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 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"],"names":[],"mappings":";;;AAYA,MAAM,GAAA,GAAM,aAAa,8BAA8B,CAAA;AAmBvD,MAAM,kBAAqB,GAAA,CAAA,GAAI,EAAK,GAAA,EAAA,GAAK,EAAK,GAAA,GAAA;AAEvC,MAAM,uBAA2D,CAAA;AAAA,EACpE,UAAa,GAAA,KAAA;AAAA,EACb,iBAAA;AAAA;AAAA,EAES,OAAA;AAAA,EAET,YAAY,EAAE,UAAA,EAAY,EAAE,MAAO,EAAA,EAAG,YAA0C,EAAA;AAC5E,IAAA,MAAM,eAAkB,GAAA,UAAA;AAExB,IAAM,MAAA,QAAA,GAAW,OAAO,aAAc,EAAA;AACtC,IAAA,IAAA,CAAK,UAAU,aAAc,CAAA;AAAA,MACzB,SAAA,EAAW,YAAa,CAAA,eAAA,CAAgB,QAAQ,CAAA;AAAA,MAChD,eAAiB,EAAA,IAAA;AAAA;AAAA,MAGjB,aAAa,MAAM;AAAA,KACtB,CAAA;AAED,IAAI,IAA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AAA,EAAE,GAAG,OAAA,EAAS,OAAO,CAAA;AAAA;AACrC,EAEA,QAAiB,GAAA;AACb,IAAA,IAAA,CAAK,QAAQ,OAAQ,EAAA;AAAA;AACzB,EAEA,UAAmC,GAAA;AAE/B,IAAA,IAAI,KAAK,UAAY,EAAA;AACjB,MAAI,GAAA,CAAA,IAAA;AAAA,QACA;AAAA,OAEJ;AACA,MAAO,OAAA,MAAA;AAAA;AAGX,IAAA,IAAA,CAAK,UAAa,GAAA,IAAA;AAClB,IAAA,IAAI,SAAY,GAAA,KAAA;AAChB,IAAO,OAAA;AAAA,MACH,SAAS,MAAM;AACX,QAAA,IAAI,SAAW,EAAA;AACX,UAAA;AAAA;AAGJ,QAAY,SAAA,GAAA,IAAA;AACZ,QAAA,IAAA,CAAK,UAAa,GAAA,KAAA;AAAA;AACtB,KACJ;AAAA;AACJ,EAEA,oBAAuB,GAAA;AACnB,IAAI,IAAA,CAAC,KAAK,UAAY,EAAA;AAClB,MAAI,GAAA,CAAA,IAAA;AAAA,QACA,CAAA;AAAA,4DAAA;AAAA,OAEJ;AAAA;AACJ;AAER;AAGA,SAAS,YAAA,CACL,iBAAiD,WAClB,EAAA;AAC/B,EAAA,QAAQ,cAAgB;AAAA,IACpB,KAAK,KAAA;AACD,MAAO,OAAA,KAAA;AAAA,IACX,KAAK,UAAA;AACD,MAAO,OAAA,WAAA;AAAA,IACX,KAAK,WAAA;AACD,MAAO,OAAA,SAAA;AAAA,IACX,KAAK,QAAA;AACD,MAAO,OAAA,QAAA;AAAA,IACX,KAAK,aAAA;AACD,MAAO,OAAA,cAAA;AAAA,IACX,KAAK,cAAA;AACD,MAAO,OAAA,YAAA;AAAA,IACX;AACI,MAAO,OAAA,SAAA;AAAA;AAEnB;;;;"}
|
package/Notifier.d.ts
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
import { ReactElement } from "react";
|
|
2
1
|
/** Props supported by the {@link Notifier} component. */
|
|
3
2
|
export interface NotifierProps {
|
|
4
|
-
/**
|
|
5
|
-
* The position for new notifications.
|
|
6
|
-
*
|
|
7
|
-
* @default "top-right"
|
|
8
|
-
*/
|
|
9
|
-
position?: "top" | "top-left" | "top-right" | "bottom" | "bottom-left" | "bottom-right";
|
|
10
3
|
}
|
|
11
4
|
/**
|
|
12
5
|
* Shows notifications sent via the `NotificationService`.
|
|
@@ -20,11 +13,11 @@ export interface NotifierProps {
|
|
|
20
13
|
* export function AppUI() {
|
|
21
14
|
* return (
|
|
22
15
|
* <>
|
|
23
|
-
* <Notifier
|
|
16
|
+
* <Notifier />
|
|
24
17
|
* <h1>Your application</h1>
|
|
25
18
|
* </>
|
|
26
19
|
* );
|
|
27
20
|
* }
|
|
28
21
|
* ```
|
|
29
22
|
*/
|
|
30
|
-
export declare function Notifier(
|
|
23
|
+
export declare function Notifier(_props: NotifierProps): false | import("react/jsx-runtime").JSX.Element;
|
package/Notifier.js
CHANGED
|
@@ -1,44 +1,68 @@
|
|
|
1
|
-
import { jsx,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { WarningTwoIcon } from '@chakra-ui/icons';
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import { Portal, Toaster as Toaster$1, Toast, Spinner, Stack, useToastStyles, Icon } from '@chakra-ui/react';
|
|
3
|
+
import { useIntl, useService } from './_virtual/_virtual-pioneer-module_react-hooks.js';
|
|
4
|
+
import { memo, useState, useEffect } from 'react';
|
|
5
|
+
import { FiAlertTriangle, FiAlertCircle, FiCheckCircle, FiInfo } from 'react-icons/fi';
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
const [ready, setReady] = useState(!isDev);
|
|
14
|
-
const showNotification = useEvent((notification) => {
|
|
15
|
-
const icon = notification.level === "error" ? /* @__PURE__ */ jsx(WarningTwoIcon, { h: "100%", w: "100%" }) : void 0;
|
|
16
|
-
toast({
|
|
17
|
-
position,
|
|
18
|
-
title: notification.title,
|
|
19
|
-
description: notification.message || null,
|
|
20
|
-
status: notification.level,
|
|
21
|
-
isClosable: true,
|
|
22
|
-
duration: notification.displayDuration ?? null,
|
|
23
|
-
// Null: does not auto-close
|
|
24
|
-
icon
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
const closeAll = useEvent(() => {
|
|
28
|
-
toast.closeAll();
|
|
29
|
-
});
|
|
7
|
+
function Notifier(_props) {
|
|
8
|
+
const notificationService = useService(
|
|
9
|
+
"notifier.NotificationService"
|
|
10
|
+
);
|
|
11
|
+
const [active, setActive] = useState(false);
|
|
30
12
|
useEffect(() => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return
|
|
13
|
+
const handle = notificationService.registerUI();
|
|
14
|
+
if (!handle) {
|
|
15
|
+
return;
|
|
34
16
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}, [
|
|
41
|
-
return /* @__PURE__ */ jsx(
|
|
17
|
+
setActive(true);
|
|
18
|
+
return () => {
|
|
19
|
+
setActive(false);
|
|
20
|
+
handle.destroy();
|
|
21
|
+
};
|
|
22
|
+
}, [notificationService]);
|
|
23
|
+
return active && /* @__PURE__ */ jsx(Toaster, { toaster: notificationService.toaster });
|
|
24
|
+
}
|
|
25
|
+
const Toaster = memo(function Toaster2(props) {
|
|
26
|
+
const intl = useIntl();
|
|
27
|
+
return /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(
|
|
28
|
+
Toaster$1,
|
|
29
|
+
{
|
|
30
|
+
toaster: props.toaster,
|
|
31
|
+
insetInline: { mdDown: "4" },
|
|
32
|
+
"aria-label": intl.formatMessage({
|
|
33
|
+
id: "regionLabel"
|
|
34
|
+
}),
|
|
35
|
+
children: (toast) => /* @__PURE__ */ jsxs(Toast.Root, { width: { md: "sm" }, alignItems: "center", children: [
|
|
36
|
+
toast.type === "loading" ? /* @__PURE__ */ jsx(Spinner, { size: "sm", color: "blue.solid" }) : /* @__PURE__ */ jsx(ToastIndicator, { type: toast.type ?? "" }),
|
|
37
|
+
/* @__PURE__ */ jsxs(Stack, { gap: "1", flex: "1", maxWidth: "100%", children: [
|
|
38
|
+
toast.title && /* @__PURE__ */ jsx(Toast.Title, { children: toast.title }),
|
|
39
|
+
toast.description && /* @__PURE__ */ jsx(Toast.Description, { children: toast.description })
|
|
40
|
+
] }),
|
|
41
|
+
toast.action && /* @__PURE__ */ jsx(Toast.ActionTrigger, { children: toast.action.label }),
|
|
42
|
+
toast.meta?.closable && /* @__PURE__ */ jsx(
|
|
43
|
+
Toast.CloseTrigger,
|
|
44
|
+
{
|
|
45
|
+
cursor: "pointer",
|
|
46
|
+
"aria-label": intl.formatMessage({
|
|
47
|
+
id: "notification.close"
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
)
|
|
51
|
+
] })
|
|
52
|
+
}
|
|
53
|
+
) });
|
|
54
|
+
});
|
|
55
|
+
const icons = {
|
|
56
|
+
info: FiInfo,
|
|
57
|
+
success: FiCheckCircle,
|
|
58
|
+
warning: FiAlertCircle,
|
|
59
|
+
error: FiAlertTriangle
|
|
60
|
+
};
|
|
61
|
+
function ToastIndicator(props) {
|
|
62
|
+
const styles = useToastStyles();
|
|
63
|
+
const Component = icons[props.type];
|
|
64
|
+
if (!Component) return null;
|
|
65
|
+
return /* @__PURE__ */ jsx(Icon, { css: styles.indicator, children: /* @__PURE__ */ jsx("span", { children: /* @__PURE__ */ jsx(Component, { style: { width: "100%", height: "100%" } }) }) });
|
|
42
66
|
}
|
|
43
67
|
|
|
44
68
|
export { Notifier };
|
package/Notifier.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Notifier.js","sources":["Notifier.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport {
|
|
1
|
+
{"version":3,"file":"Notifier.js","sources":["Notifier.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport {\n Toaster as ChakraToaster,\n Icon,\n Portal,\n Spinner,\n Stack,\n Toast,\n useToastStyles\n} from \"@chakra-ui/react\";\nimport { useIntl, useService } from \"open-pioneer:react-hooks\";\nimport { memo, useEffect, useState } from \"react\";\nimport { FiAlertCircle, FiAlertTriangle, FiCheckCircle, FiInfo } from \"react-icons/fi\";\nimport { InternalNotificationAPI, ToasterObject } from \"./NotificationServiceImpl\";\n\n/** Props supported by the {@link Notifier} component. */\nexport interface NotifierProps {}\n\n/**\n * Shows notifications sent via the `NotificationService`.\n *\n * Only one instance of `<Notifier />` should be present in the application.\n * It currently does not matter where the Notifier is located in the react tree.\n *\n * ```ts\n * import { Notifier } from \"@open-pioneer/notifier\";\n *\n * export function AppUI() {\n * return (\n * <>\n * <Notifier />\n * <h1>Your application</h1>\n * </>\n * );\n * }\n * ```\n */\nexport function Notifier(_props: NotifierProps) {\n const notificationService = useService(\n \"notifier.NotificationService\"\n ) as InternalNotificationAPI;\n const [active, setActive] = useState(false);\n\n useEffect(() => {\n const handle = notificationService.registerUI();\n if (!handle) {\n return;\n }\n\n setActive(true);\n return () => {\n setActive(false);\n handle.destroy();\n };\n }, [notificationService]);\n\n return active && <Toaster toaster={notificationService.toaster} />;\n}\n\nconst Toaster = memo(function Toaster(props: { toaster: ToasterObject }) {\n const intl = useIntl();\n return (\n <Portal>\n <ChakraToaster\n toaster={props.toaster}\n insetInline={{ mdDown: \"4\" }}\n aria-label={intl.formatMessage({\n id: \"regionLabel\"\n })}\n >\n {(toast) => (\n <Toast.Root width={{ md: \"sm\" }} alignItems=\"center\">\n {toast.type === \"loading\" ? (\n <Spinner size=\"sm\" color=\"blue.solid\" />\n ) : (\n <ToastIndicator type={toast.type ?? \"\"} />\n )}\n <Stack gap=\"1\" flex=\"1\" maxWidth=\"100%\">\n {toast.title && <Toast.Title>{toast.title}</Toast.Title>}\n {toast.description && (\n <Toast.Description>{toast.description}</Toast.Description>\n )}\n </Stack>\n {toast.action && (\n <Toast.ActionTrigger>{toast.action.label}</Toast.ActionTrigger>\n )}\n {toast.meta?.closable && (\n <Toast.CloseTrigger\n cursor=\"pointer\"\n aria-label={intl.formatMessage({\n id: \"notification.close\"\n })}\n />\n )}\n </Toast.Root>\n )}\n </ChakraToaster>\n </Portal>\n );\n});\n\nconst icons: Record<string, React.ElementType> = {\n info: FiInfo,\n success: FiCheckCircle,\n warning: FiAlertCircle,\n error: FiAlertTriangle\n};\n\nfunction ToastIndicator(props: { type: string }) {\n const styles = useToastStyles();\n\n const Component = icons[props.type];\n if (!Component) return null;\n\n return (\n <Icon css={styles.indicator}>\n <span>\n <Component style={{ width: \"100%\", height: \"100%\" }} />\n </span>\n </Icon>\n );\n}\n"],"names":["Toaster","ChakraToaster"],"mappings":";;;;;;AAsCO,SAAS,SAAS,MAAuB,EAAA;AAC5C,EAAA,MAAM,mBAAsB,GAAA,UAAA;AAAA,IACxB;AAAA,GACJ;AACA,EAAA,MAAM,CAAC,MAAA,EAAQ,SAAS,CAAA,GAAI,SAAS,KAAK,CAAA;AAE1C,EAAA,SAAA,CAAU,MAAM;AACZ,IAAM,MAAA,MAAA,GAAS,oBAAoB,UAAW,EAAA;AAC9C,IAAA,IAAI,CAAC,MAAQ,EAAA;AACT,MAAA;AAAA;AAGJ,IAAA,SAAA,CAAU,IAAI,CAAA;AACd,IAAA,OAAO,MAAM;AACT,MAAA,SAAA,CAAU,KAAK,CAAA;AACf,MAAA,MAAA,CAAO,OAAQ,EAAA;AAAA,KACnB;AAAA,GACJ,EAAG,CAAC,mBAAmB,CAAC,CAAA;AAExB,EAAA,OAAO,MAAU,oBAAA,GAAA,CAAC,OAAQ,EAAA,EAAA,OAAA,EAAS,oBAAoB,OAAS,EAAA,CAAA;AACpE;AAEA,MAAM,OAAU,GAAA,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AA;AAAA,UAAN;AAAA,YACG,MAAO,EAAA,SAAA;AAAA,YACP,YAAA,EAAY,KAAK,aAAc,CAAA;AAAA,cAC3B,EAAI,EAAA;AAAA,aACP;AAAA;AAAA;AACL,OAER,EAAA;AAAA;AAAA,GAGZ,EAAA,CAAA;AAER,CAAC,CAAA;AAED,MAAM,KAA2C,GAAA;AAAA,EAC7C,IAAM,EAAA,MAAA;AAAA,EACN,OAAS,EAAA,aAAA;AAAA,EACT,OAAS,EAAA,aAAA;AAAA,EACT,KAAO,EAAA;AACX,CAAA;AAEA,SAAS,eAAe,KAAyB,EAAA;AAC7C,EAAA,MAAM,SAAS,cAAe,EAAA;AAE9B,EAAM,MAAA,SAAA,GAAY,KAAM,CAAA,KAAA,CAAM,IAAI,CAAA;AAClC,EAAI,IAAA,CAAC,WAAkB,OAAA,IAAA;AAEvB,EAAA,2BACK,IAAK,EAAA,EAAA,GAAA,EAAK,MAAO,CAAA,SAAA,EACd,8BAAC,MACG,EAAA,EAAA,QAAA,kBAAA,GAAA,CAAC,SAAU,EAAA,EAAA,KAAA,EAAO,EAAE,KAAO,EAAA,MAAA,EAAQ,QAAQ,MAAO,EAAA,EAAG,GACzD,CACJ,EAAA,CAAA;AAER;;;;"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { useServiceInternal } from '@open-pioneer/runtime/react-integration';
|
|
1
|
+
import { useIntlInternal, useServiceInternal } from '@open-pioneer/runtime/react-integration';
|
|
2
2
|
|
|
3
3
|
const PACKAGE_NAME = "@open-pioneer/notifier";
|
|
4
4
|
const useService = /*@__PURE__*/ useServiceInternal.bind(undefined, PACKAGE_NAME);
|
|
5
|
+
const useIntl = /*@__PURE__*/ useIntlInternal.bind(undefined, PACKAGE_NAME);
|
|
5
6
|
|
|
6
|
-
export { useService };
|
|
7
|
+
export { useIntl, useService };
|
|
7
8
|
//# sourceMappingURL=_virtual-pioneer-module_react-hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_virtual-pioneer-module_react-hooks.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"_virtual-pioneer-module_react-hooks.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
|
package/api.d.ts
CHANGED
|
@@ -58,3 +58,14 @@ export interface NotificationService extends DeclaredService<"notifier.Notificat
|
|
|
58
58
|
/** Closes all active notifications. */
|
|
59
59
|
closeAll(): void;
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Properties supported by this package.
|
|
63
|
+
*/
|
|
64
|
+
export interface NotifierProperties {
|
|
65
|
+
/**
|
|
66
|
+
* The position for new notifications.
|
|
67
|
+
*
|
|
68
|
+
* @default "top-right"
|
|
69
|
+
*/
|
|
70
|
+
position?: "top" | "top-left" | "top-right" | "bottom" | "bottom-left" | "bottom-right";
|
|
71
|
+
}
|
package/i18n/de.yaml
ADDED
package/i18n/en.yaml
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@open-pioneer/notifier",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "4.0.0-dev-chakra-v3.20250320123304",
|
|
5
5
|
"description": "Provides support for application-wide notifications.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"open-pioneer-trails"
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
"directory": "src/packages/notifier"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@chakra-ui/
|
|
17
|
+
"@chakra-ui/react": "^3.8.1",
|
|
18
|
+
"react-icons": "^5.5.0",
|
|
18
19
|
"react": "^19.0.0",
|
|
19
|
-
"@open-pioneer/
|
|
20
|
-
"@open-pioneer/
|
|
21
|
-
"@open-pioneer/
|
|
22
|
-
"@open-pioneer/runtime": "^3.0.0"
|
|
20
|
+
"@open-pioneer/core": "^4.0.0-dev-chakra-v3.20250320123304",
|
|
21
|
+
"@open-pioneer/react-utils": "^4.0.0-dev-chakra-v3.20250320123304",
|
|
22
|
+
"@open-pioneer/runtime": "^4.0.0-dev-chakra-v3.20250320123304"
|
|
23
23
|
},
|
|
24
24
|
"exports": {
|
|
25
25
|
"./package.json": "./package.json",
|
|
@@ -41,12 +41,21 @@
|
|
|
41
41
|
"interfaceName": "notifier.NotificationService"
|
|
42
42
|
}
|
|
43
43
|
],
|
|
44
|
-
"references": [
|
|
44
|
+
"references": [
|
|
45
|
+
{
|
|
46
|
+
"referenceName": "appCtx",
|
|
47
|
+
"type": "unique",
|
|
48
|
+
"interfaceName": "runtime.ApplicationContext"
|
|
49
|
+
}
|
|
50
|
+
]
|
|
45
51
|
}
|
|
46
52
|
],
|
|
47
53
|
"servicesModule": "./services",
|
|
48
54
|
"i18n": {
|
|
49
|
-
"languages": [
|
|
55
|
+
"languages": [
|
|
56
|
+
"en",
|
|
57
|
+
"de"
|
|
58
|
+
]
|
|
50
59
|
},
|
|
51
60
|
"ui": {
|
|
52
61
|
"references": [
|
|
@@ -56,7 +65,13 @@
|
|
|
56
65
|
}
|
|
57
66
|
]
|
|
58
67
|
},
|
|
59
|
-
"properties": [
|
|
68
|
+
"properties": [
|
|
69
|
+
{
|
|
70
|
+
"propertyName": "position",
|
|
71
|
+
"defaultValue": "top-right",
|
|
72
|
+
"required": false
|
|
73
|
+
}
|
|
74
|
+
],
|
|
60
75
|
"packageFormatVersion": "1.0.0"
|
|
61
76
|
}
|
|
62
77
|
}
|