@open-pioneer/notifier 4.4.0-dev.20260121102820 → 4.4.0
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 +7 -4
- package/NotificationServiceImpl.d.ts +1 -1
- package/NotificationServiceImpl.js +29 -1
- package/NotificationServiceImpl.js.map +1 -1
- package/Notifier.d.ts +9 -1
- package/Notifier.js +7 -4
- package/Notifier.js.map +1 -1
- package/README.md +9 -0
- package/_virtual/source-info.js +4 -0
- package/_virtual/source-info.js.map +1 -0
- package/api.d.ts +17 -0
- package/package.json +9 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
# @open-pioneer/notifier
|
|
2
2
|
|
|
3
|
-
## 4.4.0
|
|
3
|
+
## 4.4.0
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
7
|
- b28d6bc: Update to chakra 3.31.0
|
|
8
|
+
- d7ec65c: Add a `rootProps` property to the `<Notifier />` component.
|
|
9
|
+
These are properties that will be applied to the notifier's root div.
|
|
10
|
+
- d7ec65c: Allow configuration of the gap between the first notification and the screen edge(s) via the new `offsets` package property.
|
|
8
11
|
|
|
9
12
|
### Patch Changes
|
|
10
13
|
|
|
@@ -17,9 +20,9 @@
|
|
|
17
20
|
- Updated dependencies [1cc3415]
|
|
18
21
|
- Updated dependencies [1872a6d]
|
|
19
22
|
- Updated dependencies [84068f2]
|
|
20
|
-
- @open-pioneer/core@4.4.0
|
|
21
|
-
- @open-pioneer/react-utils@4.4.0
|
|
22
|
-
- @open-pioneer/runtime@4.4.0
|
|
23
|
+
- @open-pioneer/core@4.4.0
|
|
24
|
+
- @open-pioneer/react-utils@4.4.0
|
|
25
|
+
- @open-pioneer/runtime@4.4.0
|
|
23
26
|
|
|
24
27
|
## 4.3.0
|
|
25
28
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CreateToasterReturn } from "@chakra-ui/react";
|
|
2
|
-
import type { NotificationOptions, NotificationService, SimpleNotificationOptions } from "./api";
|
|
3
2
|
import { Resource } from "@open-pioneer/core";
|
|
4
3
|
import { ApplicationContext, ServiceOptions } from "@open-pioneer/runtime";
|
|
4
|
+
import type { NotificationOptions, NotificationService, SimpleNotificationOptions } from "./api";
|
|
5
5
|
export type ToasterObject = CreateToasterReturn;
|
|
6
6
|
export interface ToastMeta {
|
|
7
7
|
closable: boolean;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createToaster } from '@chakra-ui/react';
|
|
2
2
|
import { createLogger } from '@open-pioneer/core';
|
|
3
|
+
import { sourceId } from './_virtual/source-info.js';
|
|
3
4
|
|
|
4
|
-
const LOG = createLogger(
|
|
5
|
+
const LOG = createLogger(sourceId);
|
|
5
6
|
const PERSISTENT_TIMEOUT = 7 * 24 * 60 * 60 * 1e3;
|
|
6
7
|
class NotificationServiceImpl {
|
|
7
8
|
#uiPresent = false;
|
|
@@ -12,6 +13,7 @@ class NotificationServiceImpl {
|
|
|
12
13
|
const typedProperties = properties;
|
|
13
14
|
this.toaster = createToaster({
|
|
14
15
|
placement: getPlacement(typedProperties.position),
|
|
16
|
+
offsets: getOffsets(typedProperties.offsets),
|
|
15
17
|
pauseOnPageIdle: true
|
|
16
18
|
});
|
|
17
19
|
if (import.meta.env.DEV && !import.meta.env.VITEST) {
|
|
@@ -109,6 +111,32 @@ function getPlacement(configPosition = "top-right") {
|
|
|
109
111
|
return "top-end";
|
|
110
112
|
}
|
|
111
113
|
}
|
|
114
|
+
function getOffsets(offsetsConfig) {
|
|
115
|
+
if (!offsetsConfig) {
|
|
116
|
+
return void 0;
|
|
117
|
+
}
|
|
118
|
+
if (typeof offsetsConfig === "string") {
|
|
119
|
+
return {
|
|
120
|
+
left: offsetsConfig,
|
|
121
|
+
top: offsetsConfig,
|
|
122
|
+
right: offsetsConfig,
|
|
123
|
+
bottom: offsetsConfig
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
if (typeof offsetsConfig !== "object") {
|
|
127
|
+
throw new Error("Unexpected 'offsets' property value: must be a string or an object.");
|
|
128
|
+
}
|
|
129
|
+
checkProp(offsetsConfig, "left");
|
|
130
|
+
checkProp(offsetsConfig, "top");
|
|
131
|
+
checkProp(offsetsConfig, "right");
|
|
132
|
+
checkProp(offsetsConfig, "bottom");
|
|
133
|
+
return offsetsConfig;
|
|
134
|
+
}
|
|
135
|
+
function checkProp(obj, prop) {
|
|
136
|
+
if (!obj[prop]) {
|
|
137
|
+
throw new Error(`Offset '${prop}' is required.`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
112
140
|
|
|
113
141
|
export { NotificationServiceImpl };
|
|
114
142
|
//# 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 { createToaster, CreateToasterProps, CreateToasterReturn } from \"@chakra-ui/react\";\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 { createLogger, Resource } from \"@open-pioneer/core\";\nimport { ApplicationContext, 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\ninterface References {\n appCtx: ApplicationContext;\n}\n\n// 7 days. Needed because there is no \"indefinite\" timeout for tooltips in current chakra.\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({ properties }: ServiceOptions<References>) {\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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A;AACjC,EAAA,OAAO,aAAA;AACX;AAEA,SAAS,SAAA,CAAU,KAA6B,IAAA,EAA2B;AACvE,EAAA,IAAI,CAAC,GAAA,CAAI,IAAI,CAAA,EAAG;AACZ,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,QAAA,EAAW,IAAI,CAAA,cAAA,CAAgB,CAAA;AAAA,EACnD;AACJ;;;;"}
|
package/Notifier.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
import { BoxProps } from "@chakra-ui/react";
|
|
1
2
|
/** Props supported by the {@link Notifier} component. */
|
|
2
3
|
export interface NotifierProps {
|
|
4
|
+
/**
|
|
5
|
+
* Props to be added to the notifier's root container.
|
|
6
|
+
*
|
|
7
|
+
* NOTE: Chakra's toaster currently hard codes many style properties using element styles.
|
|
8
|
+
* These styles cannot be easily overwritten, unless one uses `!important`.
|
|
9
|
+
**/
|
|
10
|
+
rootProps?: BoxProps;
|
|
3
11
|
}
|
|
4
12
|
/**
|
|
5
13
|
* Shows notifications sent via the `NotificationService`.
|
|
@@ -20,4 +28,4 @@ export interface NotifierProps {
|
|
|
20
28
|
* }
|
|
21
29
|
* ```
|
|
22
30
|
*/
|
|
23
|
-
export declare function Notifier(
|
|
31
|
+
export declare function Notifier(props: NotifierProps): false | import("react/jsx-runtime").JSX.Element;
|
package/Notifier.js
CHANGED
|
@@ -4,7 +4,7 @@ import { useIntl, useService } from './_virtual/hooks.js';
|
|
|
4
4
|
import { memo, useState, useEffect } from 'react';
|
|
5
5
|
import { LuTriangleAlert, LuCircleAlert, LuCircleCheck, LuInfo } from 'react-icons/lu';
|
|
6
6
|
|
|
7
|
-
function Notifier(
|
|
7
|
+
function Notifier(props) {
|
|
8
8
|
const notificationService = useService(
|
|
9
9
|
"notifier.NotificationService"
|
|
10
10
|
);
|
|
@@ -20,19 +20,22 @@ function Notifier(_props) {
|
|
|
20
20
|
handle.destroy();
|
|
21
21
|
};
|
|
22
22
|
}, [notificationService]);
|
|
23
|
-
return active && /* @__PURE__ */ jsx(Toaster, { toaster: notificationService.toaster });
|
|
23
|
+
return active && /* @__PURE__ */ jsx(Toaster, { rootProps: props.rootProps, toaster: notificationService.toaster });
|
|
24
24
|
}
|
|
25
25
|
const Toaster = memo(function Toaster2(props) {
|
|
26
|
+
const { rootProps, toaster } = props;
|
|
26
27
|
const intl = useIntl();
|
|
27
28
|
return /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(
|
|
28
29
|
Toaster$1,
|
|
29
30
|
{
|
|
30
|
-
toaster: props.toaster,
|
|
31
31
|
insetInline: { mdDown: "4" },
|
|
32
32
|
"aria-label": intl.formatMessage({
|
|
33
33
|
id: "regionLabel"
|
|
34
34
|
}),
|
|
35
|
-
|
|
35
|
+
className: "notifier-toast-group",
|
|
36
|
+
...rootProps,
|
|
37
|
+
toaster,
|
|
38
|
+
children: (toast) => /* @__PURE__ */ jsxs(Toast.Root, { className: "notifier-toast", width: { md: "sm" }, alignItems: "center", children: [
|
|
36
39
|
toast.type === "loading" ? /* @__PURE__ */ jsx(Spinner, { size: "sm", color: "blue.solid" }) : /* @__PURE__ */ jsx(ToastIndicator, { type: toast.type ?? "" }),
|
|
37
40
|
/* @__PURE__ */ jsxs(Stack, { gap: "1", flex: "1", maxWidth: "100%", children: [
|
|
38
41
|
toast.title && /* @__PURE__ */ jsx(Toast.Title, { children: toast.title }),
|
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 {\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 {
|
|
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 BoxProps,\n Toaster as ChakraToaster,\n Icon,\n Portal,\n Spinner,\n Stack,\n Toast,\n ToasterProps,\n useToastStyles\n} from \"@chakra-ui/react\";\nimport { useIntl, useService } from \"open-pioneer:react-hooks\";\nimport { memo, useEffect, useState } from \"react\";\nimport { LuCircleAlert, LuCircleCheck, LuInfo, LuTriangleAlert } from \"react-icons/lu\";\nimport { InternalNotificationAPI, ToasterObject } from \"./NotificationServiceImpl\";\n\n/** Props supported by the {@link Notifier} component. */\nexport interface NotifierProps {\n /**\n * Props to be added to the notifier's root container.\n *\n * NOTE: Chakra's toaster currently hard codes many style properties using element styles.\n * These styles cannot be easily overwritten, unless one uses `!important`.\n **/\n rootProps?: BoxProps;\n}\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 rootProps={props.rootProps} toaster={notificationService.toaster} />;\n}\n\nconst Toaster = memo(function Toaster(props: { rootProps?: BoxProps; toaster: ToasterObject }) {\n const { rootProps, toaster } = props;\n const intl = useIntl();\n\n return (\n <Portal>\n <ChakraToaster\n insetInline={{ mdDown: \"4\" }}\n aria-label={intl.formatMessage({\n id: \"regionLabel\"\n })}\n className=\"notifier-toast-group\"\n {...(rootProps as ToasterProps | undefined)}\n toaster={toaster}\n >\n {(toast) => (\n <Toast.Root className=\"notifier-toast\" 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: LuInfo,\n success: LuCircleCheck,\n warning: LuCircleAlert,\n error: LuTriangleAlert\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":";;;;;;AAgDO,SAAS,SAAS,KAAA,EAAsB;AAC3C,EAAA,MAAM,mBAAA,GAAsB,UAAA;AAAA,IACxB;AAAA,GACJ;AACA,EAAA,MAAM,CAAC,MAAA,EAAQ,SAAS,CAAA,GAAI,SAAS,KAAK,CAAA;AAE1C,EAAA,SAAA,CAAU,MAAM;AACZ,IAAA,MAAM,MAAA,GAAS,oBAAoB,UAAA,EAAW;AAC9C,IAAA,IAAI,CAAC,MAAA,EAAQ;AACT,MAAA;AAAA,IACJ;AAEA,IAAA,SAAA,CAAU,IAAI,CAAA;AACd,IAAA,OAAO,MAAM;AACT,MAAA,SAAA,CAAU,KAAK,CAA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
39
39
|
position?: "top" | "top-left" | "top-right" | "bottom" | "bottom-left" | "bottom-right";
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Offset from the edge of the screen.
|
|
43
|
+
*
|
|
44
|
+
* The default value is inherited from Chakra (currently `"1rem"`).
|
|
45
|
+
*
|
|
46
|
+
* See also https://chakra-ui.com/docs/components/toast#offset.
|
|
47
|
+
*/
|
|
48
|
+
offsets?: string | OffsetsObject | null;
|
|
40
49
|
}
|
|
41
50
|
```
|
|
42
51
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-info.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
package/api.d.ts
CHANGED
|
@@ -58,6 +58,15 @@ export interface NotificationService extends DeclaredService<"notifier.Notificat
|
|
|
58
58
|
/** Closes all active notifications. */
|
|
59
59
|
closeAll(): void;
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Offsets from the edge of the screen; one css value for each edge.
|
|
63
|
+
*/
|
|
64
|
+
export interface OffsetsObject {
|
|
65
|
+
left: string;
|
|
66
|
+
top: string;
|
|
67
|
+
right: string;
|
|
68
|
+
bottom: string;
|
|
69
|
+
}
|
|
61
70
|
/**
|
|
62
71
|
* Properties supported by this package.
|
|
63
72
|
*/
|
|
@@ -68,4 +77,12 @@ export interface NotifierProperties {
|
|
|
68
77
|
* @default "top-right"
|
|
69
78
|
*/
|
|
70
79
|
position?: "top" | "top-left" | "top-right" | "bottom" | "bottom-left" | "bottom-right";
|
|
80
|
+
/**
|
|
81
|
+
* Offset from the edge of the screen.
|
|
82
|
+
*
|
|
83
|
+
* The default value is inherited from Chakra (currently `"1rem"`).
|
|
84
|
+
*
|
|
85
|
+
* See also https://chakra-ui.com/docs/components/toast#offset.
|
|
86
|
+
*/
|
|
87
|
+
offsets?: string | OffsetsObject | null;
|
|
71
88
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@open-pioneer/notifier",
|
|
4
|
-
"version": "4.4.0
|
|
4
|
+
"version": "4.4.0",
|
|
5
5
|
"description": "Provides support for application-wide notifications.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"open-pioneer-trails"
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"@chakra-ui/react": "^3.31.0",
|
|
18
18
|
"react-icons": "^5.5.0",
|
|
19
19
|
"react": "^19.2.3",
|
|
20
|
-
"@open-pioneer/core": "4.4.0
|
|
21
|
-
"@open-pioneer/
|
|
22
|
-
"@open-pioneer/
|
|
20
|
+
"@open-pioneer/core": "4.4.0",
|
|
21
|
+
"@open-pioneer/runtime": "4.4.0",
|
|
22
|
+
"@open-pioneer/react-utils": "4.4.0"
|
|
23
23
|
},
|
|
24
24
|
"exports": {
|
|
25
25
|
"./package.json": "./package.json",
|
|
@@ -64,6 +64,11 @@
|
|
|
64
64
|
"propertyName": "position",
|
|
65
65
|
"defaultValue": "top-right",
|
|
66
66
|
"required": false
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"propertyName": "offsets",
|
|
70
|
+
"defaultValue": null,
|
|
71
|
+
"required": false
|
|
67
72
|
}
|
|
68
73
|
],
|
|
69
74
|
"packageFormatVersion": "1.0.0"
|