@open-pioneer/notifier 0.3.0 → 0.3.1

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # @open-pioneer/notifier
2
2
 
3
+ ## 0.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 4eac7c7: Move packages into core-packages repository.
8
+ - @open-pioneer/runtime@2.1.2
9
+
3
10
  ## 0.3.0
4
11
 
5
12
  ### Minor Changes
package/Notifier.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsx, Fragment } from 'react/jsx-runtime';
2
2
  import { useToast } from '@open-pioneer/chakra-integration';
3
- import { useEvent } from '@open-pioneer/react-utils';
3
+ import { useEvent } from './useEvent.js';
4
4
  import { useService } from './_virtual/_virtual-pioneer-module_react-hooks.js';
5
5
  import { useState, useEffect } from 'react';
6
6
  import { WarningTwoIcon } from '@chakra-ui/icons';
package/Notifier.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Notifier.js","sources":["Notifier.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { useToast } from \"@open-pioneer/chakra-integration\";\nimport { useEvent } from \"@open-pioneer/react-utils\";\nimport { useService } from \"open-pioneer:react-hooks\";\nimport { ReactElement, useEffect, useState } from \"react\";\nimport { InternalNotificationAPI, Notification } from \"./NotificationServiceImpl\";\nimport { WarningTwoIcon } from \"@chakra-ui/icons\";\n\n/** Props supported by the {@link Notifier} component. */\nexport interface NotifierProps {\n /**\n * The position for new notifications.\n *\n * @default \"top-right\"\n */\n position?: \"top\" | \"top-left\" | \"top-right\" | \"bottom\" | \"bottom-left\" | \"bottom-right\";\n}\n\nconst isDev = import.meta.env.DEV;\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 position=\"top-right\" />\n * <h1>Your application</h1>\n * </>\n * );\n * }\n * ```\n */\nexport function Notifier(props: NotifierProps): ReactElement {\n const { position = \"top-right\" } = props;\n const toast = useToast();\n const notifications = useService(\"notifier.NotificationService\") as InternalNotificationAPI;\n const [ready, setReady] = useState(!isDev);\n\n const showNotification = useEvent((notification: Notification) => {\n // use different icons for warning and error\n const icon =\n notification.level === \"error\" ? <WarningTwoIcon h=\"100%\" w=\"100%\" /> : undefined;\n toast({\n position,\n title: notification.title,\n description: notification.message || null,\n status: notification.level,\n isClosable: true,\n duration: notification.displayDuration ?? null, // Null: does not auto-close\n icon\n });\n });\n const closeAll = useEvent(() => {\n toast.closeAll();\n });\n\n useEffect(() => {\n /*\n * Delay registering the notification handler a bit during development.\n * Chakra's toast implementation clears its store when it gets unmounted.\n * During development, that may also happen during initialization because of React's\n * StrictMode (https://react.dev/reference/react/StrictMode).\n *\n * Unfortunately, that means that toasts that were emitted very early (such as in service constructors)\n * will be deleted. Waiting for a few milliseconds prevents this issue and has no effect on production.\n */\n if (isDev && !ready) {\n const id = setTimeout(() => setReady(true), 100);\n return () => clearTimeout(id);\n }\n\n const handle = notifications.registerHandler({\n showNotification,\n closeAll\n });\n return () => handle.destroy();\n }, [ready, notifications, showNotification, closeAll]);\n\n // No actual UI representation right now\n return <></>;\n}\n"],"names":[],"mappings":";;;;;;;AAmBA,MAAM,KAAA,GAAQ,YAAY,GAAI,CAAA,GAAA,CAAA;AAqBvB,SAAS,SAAS,KAAoC,EAAA;AACzD,EAAM,MAAA,EAAE,QAAW,GAAA,WAAA,EAAgB,GAAA,KAAA,CAAA;AACnC,EAAA,MAAM,QAAQ,QAAS,EAAA,CAAA;AACvB,EAAM,MAAA,aAAA,GAAgB,WAAW,8BAA8B,CAAA,CAAA;AAC/D,EAAA,MAAM,CAAC,KAAO,EAAA,QAAQ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;;;;"}
1
+ {"version":3,"file":"Notifier.js","sources":["Notifier.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { useToast } from \"@open-pioneer/chakra-integration\";\nimport { useEvent } from \"./useEvent\";\nimport { useService } from \"open-pioneer:react-hooks\";\nimport { ReactElement, useEffect, useState } from \"react\";\nimport { InternalNotificationAPI, Notification } from \"./NotificationServiceImpl\";\nimport { WarningTwoIcon } from \"@chakra-ui/icons\";\n\n/** Props supported by the {@link Notifier} component. */\nexport interface NotifierProps {\n /**\n * The position for new notifications.\n *\n * @default \"top-right\"\n */\n position?: \"top\" | \"top-left\" | \"top-right\" | \"bottom\" | \"bottom-left\" | \"bottom-right\";\n}\n\nconst isDev = import.meta.env.DEV;\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 position=\"top-right\" />\n * <h1>Your application</h1>\n * </>\n * );\n * }\n * ```\n */\nexport function Notifier(props: NotifierProps): ReactElement {\n const { position = \"top-right\" } = props;\n const toast = useToast();\n const notifications = useService(\"notifier.NotificationService\") as InternalNotificationAPI;\n const [ready, setReady] = useState(!isDev);\n\n const showNotification = useEvent((notification: Notification) => {\n // use different icons for warning and error\n const icon =\n notification.level === \"error\" ? <WarningTwoIcon h=\"100%\" w=\"100%\" /> : undefined;\n toast({\n position,\n title: notification.title,\n description: notification.message || null,\n status: notification.level,\n isClosable: true,\n duration: notification.displayDuration ?? null, // Null: does not auto-close\n icon\n });\n });\n const closeAll = useEvent(() => {\n toast.closeAll();\n });\n\n useEffect(() => {\n /*\n * Delay registering the notification handler a bit during development.\n * Chakra's toast implementation clears its store when it gets unmounted.\n * During development, that may also happen during initialization because of React's\n * StrictMode (https://react.dev/reference/react/StrictMode).\n *\n * Unfortunately, that means that toasts that were emitted very early (such as in service constructors)\n * will be deleted. Waiting for a few milliseconds prevents this issue and has no effect on production.\n */\n if (isDev && !ready) {\n const id = setTimeout(() => setReady(true), 100);\n return () => clearTimeout(id);\n }\n\n const handle = notifications.registerHandler({\n showNotification,\n closeAll\n });\n return () => handle.destroy();\n }, [ready, notifications, showNotification, closeAll]);\n\n // No actual UI representation right now\n return <></>;\n}\n"],"names":[],"mappings":";;;;;;;AAmBA,MAAM,KAAA,GAAQ,YAAY,GAAI,CAAA,GAAA,CAAA;AAqBvB,SAAS,SAAS,KAAoC,EAAA;AACzD,EAAM,MAAA,EAAE,QAAW,GAAA,WAAA,EAAgB,GAAA,KAAA,CAAA;AACnC,EAAA,MAAM,QAAQ,QAAS,EAAA,CAAA;AACvB,EAAM,MAAA,aAAA,GAAgB,WAAW,8BAA8B,CAAA,CAAA;AAC/D,EAAA,MAAM,CAAC,KAAO,EAAA,QAAQ,CAAI,GAAA,QAAA,CAAS,CAAC,KAAK,CAAA,CAAA;AAEzC,EAAM,MAAA,gBAAA,GAAmB,QAAS,CAAA,CAAC,YAA+B,KAAA;AAE9D,IAAM,MAAA,IAAA,GACF,YAAa,CAAA,KAAA,KAAU,OAAU,mBAAA,GAAA,CAAC,kBAAe,CAAE,EAAA,MAAA,EAAO,CAAE,EAAA,MAAA,EAAO,CAAK,GAAA,KAAA,CAAA,CAAA;AAC5E,IAAM,KAAA,CAAA;AAAA,MACF,QAAA;AAAA,MACA,OAAO,YAAa,CAAA,KAAA;AAAA,MACpB,WAAA,EAAa,aAAa,OAAW,IAAA,IAAA;AAAA,MACrC,QAAQ,YAAa,CAAA,KAAA;AAAA,MACrB,UAAY,EAAA,IAAA;AAAA,MACZ,QAAA,EAAU,aAAa,eAAmB,IAAA,IAAA;AAAA;AAAA,MAC1C,IAAA;AAAA,KACH,CAAA,CAAA;AAAA,GACJ,CAAA,CAAA;AACD,EAAM,MAAA,QAAA,GAAW,SAAS,MAAM;AAC5B,IAAA,KAAA,CAAM,QAAS,EAAA,CAAA;AAAA,GAClB,CAAA,CAAA;AAED,EAAA,SAAA,CAAU,MAAM;AAUZ,IAAI,IAAA,KAAA,IAAS,CAAC,KAAO,EAAA;AACjB,MAAA,MAAM,KAAK,UAAW,CAAA,MAAM,QAAS,CAAA,IAAI,GAAG,GAAG,CAAA,CAAA;AAC/C,MAAO,OAAA,MAAM,aAAa,EAAE,CAAA,CAAA;AAAA,KAChC;AAEA,IAAM,MAAA,MAAA,GAAS,cAAc,eAAgB,CAAA;AAAA,MACzC,gBAAA;AAAA,MACA,QAAA;AAAA,KACH,CAAA,CAAA;AACD,IAAO,OAAA,MAAM,OAAO,OAAQ,EAAA,CAAA;AAAA,KAC7B,CAAC,KAAA,EAAO,aAAe,EAAA,gBAAA,EAAkB,QAAQ,CAAC,CAAA,CAAA;AAGrD,EAAA,uBAAS,GAAA,CAAA,QAAA,EAAA,EAAA,CAAA,CAAA;AACb;;;;"}
package/package.json CHANGED
@@ -1,17 +1,15 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@open-pioneer/notifier",
4
- "version": "0.3.0",
4
+ "version": "0.3.1",
5
5
  "description": "Provides support for application-wide notifications",
6
6
  "license": "Apache-2.0",
7
- "dependencies": {},
8
7
  "peerDependencies": {
9
- "@open-pioneer/core": "^1.2.1",
10
- "@open-pioneer/chakra-integration": "^1.1.1",
11
8
  "@chakra-ui/icons": "^2.1.1",
12
- "@open-pioneer/runtime": "^2.1.0",
13
9
  "react": "^18.2.0",
14
- "@open-pioneer/react-utils": "^0.2.1"
10
+ "@open-pioneer/chakra-integration": "^1.1.1",
11
+ "@open-pioneer/runtime": "^2.1.2",
12
+ "@open-pioneer/core": "^1.2.1"
15
13
  },
16
14
  "exports": {
17
15
  "./package.json": "./package.json",
package/useEvent.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Creates an event handler with stable function identity.
3
+ * The returned function will always invoke the most recent implementation of `handler`.
4
+ *
5
+ * The returned event handler can be used, for example, as an event handler in `useEffect()`.
6
+ * Because the function identity is stable, `useEffect()` will not re-trigger if the implementation changes.
7
+ *
8
+ * NOTE: the event handler must not be called during rendering!
9
+ *
10
+ * See also: https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md
11
+ */
12
+ export declare function useEvent<Args extends unknown[], Ret>(handler: (...args: Args) => Ret): typeof handler;
package/useEvent.js ADDED
@@ -0,0 +1,16 @@
1
+ import { useRef, useLayoutEffect, useCallback } from 'react';
2
+
3
+ function useEvent(handler) {
4
+ const handlerRef = useRef(null);
5
+ useLayoutEffect(() => {
6
+ handlerRef.current = handler;
7
+ });
8
+ const stableHandler = useCallback((...args) => {
9
+ const currentHandler = handlerRef.current;
10
+ return currentHandler(...args);
11
+ }, []);
12
+ return stableHandler;
13
+ }
14
+
15
+ export { useEvent };
16
+ //# sourceMappingURL=useEvent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEvent.js","sources":["useEvent.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { useCallback, useLayoutEffect, useRef } from \"react\";\n\n// TODO: Remove this hook and use useEvent from @open-pioneer/react-utils instead\n// once that hook has moved in this repository.\n\n/**\n * Creates an event handler with stable function identity.\n * The returned function will always invoke the most recent implementation of `handler`.\n *\n * The returned event handler can be used, for example, as an event handler in `useEffect()`.\n * Because the function identity is stable, `useEffect()` will not re-trigger if the implementation changes.\n *\n * NOTE: the event handler must not be called during rendering!\n *\n * See also: https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md\n */\nexport function useEvent<Args extends unknown[], Ret>(\n handler: (...args: Args) => Ret\n): typeof handler {\n const handlerRef = useRef<typeof handler | null>(null);\n\n useLayoutEffect(() => {\n handlerRef.current = handler;\n });\n\n const stableHandler = useCallback((...args: Args): Ret => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const currentHandler = handlerRef.current!;\n return currentHandler(...args);\n }, []);\n return stableHandler;\n}\n"],"names":[],"mappings":";;AAkBO,SAAS,SACZ,OACc,EAAA;AACd,EAAM,MAAA,UAAA,GAAa,OAA8B,IAAI,CAAA,CAAA;AAErD,EAAA,eAAA,CAAgB,MAAM;AAClB,IAAA,UAAA,CAAW,OAAU,GAAA,OAAA,CAAA;AAAA,GACxB,CAAA,CAAA;AAED,EAAM,MAAA,aAAA,GAAgB,WAAY,CAAA,CAAA,GAAI,IAAoB,KAAA;AAEtD,IAAA,MAAM,iBAAiB,UAAW,CAAA,OAAA,CAAA;AAClC,IAAO,OAAA,cAAA,CAAe,GAAG,IAAI,CAAA,CAAA;AAAA,GACjC,EAAG,EAAE,CAAA,CAAA;AACL,EAAO,OAAA,aAAA,CAAA;AACX;;;;"}