@lerx/promise-modal 0.2.5 → 0.2.7

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/dist/index.cjs CHANGED
@@ -6,12 +6,11 @@ const convert = require('@winglet/common-utils/convert');
6
6
  const hook = require('@winglet/react-utils/hook');
7
7
  const hash = require('@winglet/common-utils/hash');
8
8
  const lib = require('@winglet/common-utils/lib');
9
- const compressCss = require('@winglet/style-utils/compressCss');
10
- const styleManager = require('@winglet/style-utils/styleManager');
9
+ const styleManager = require('@winglet/style-utils/style-manager');
10
+ const util = require('@winglet/style-utils/util');
11
11
  const reactDom = require('react-dom');
12
12
  const array = require('@winglet/common-utils/array');
13
13
  const hoc = require('@winglet/react-utils/hoc');
14
- const classNames = require('@winglet/style-utils/classNames');
15
14
  const filter = require('@winglet/common-utils/filter');
16
15
  const render = require('@winglet/react-utils/render');
17
16
  const console = require('@winglet/common-utils/console');
@@ -52,7 +51,7 @@ class ModalManager {
52
51
  static #styleManager = styleManager.styleManagerFactory(ModalManager.#scope);
53
52
  static #styleSheetDefinition = new Map();
54
53
  static defineStyleSheet(styleId, css) {
55
- ModalManager.#styleSheetDefinition.set(styleId, compressCss.compressCss(css));
54
+ ModalManager.#styleSheetDefinition.set(styleId, util.compressCss(css));
56
55
  }
57
56
  static applyStyleSheet() {
58
57
  for (const [styleId, css] of ModalManager.#styleSheetDefinition)
@@ -420,30 +419,34 @@ const FallbackForegroundFrame = react.forwardRef(({ id, onChangeOrder, children
420
419
 
421
420
  const ConfigurationContext = react.createContext({});
422
421
 
423
- const ConfigurationContextProvider = react.memo(({ ForegroundComponent, BackgroundComponent, TitleComponent, SubtitleComponent, ContentComponent, FooterComponent, options, children, }) => {
424
- const value = react.useMemo(() => ({
422
+ const DEFAULT_OPTIONS = {
423
+ duration: DEFAULT_ANIMATION_DURATION,
424
+ backdrop: DEFAULT_BACKDROP_COLOR,
425
+ closeOnBackdropClick: true,
426
+ manualDestroy: false,
427
+ };
428
+ const ConfigurationContextProvider = react.memo(({ ForegroundComponent, BackgroundComponent, TitleComponent, SubtitleComponent, ContentComponent, FooterComponent, options: inputOptions, children, }) => {
429
+ const memoized = hook.useMemorize({
425
430
  BackgroundComponent,
426
431
  ForegroundComponent: ForegroundComponent || FallbackForegroundFrame,
427
432
  TitleComponent: TitleComponent || FallbackTitle,
428
433
  SubtitleComponent: SubtitleComponent || FallbackSubtitle,
429
434
  ContentComponent: react.memo(ContentComponent || FallbackContent),
430
435
  FooterComponent: react.memo(FooterComponent || FallbackFooter),
436
+ });
437
+ const options = hook.useSnapshot(inputOptions);
438
+ const value = react.useMemo(() => ({
439
+ ForegroundComponent: memoized.ForegroundComponent,
440
+ BackgroundComponent: memoized.BackgroundComponent,
441
+ TitleComponent: memoized.TitleComponent,
442
+ SubtitleComponent: memoized.SubtitleComponent,
443
+ ContentComponent: memoized.ContentComponent,
444
+ FooterComponent: memoized.FooterComponent,
431
445
  options: {
432
- duration: DEFAULT_ANIMATION_DURATION,
433
- backdrop: DEFAULT_BACKDROP_COLOR,
434
- closeOnBackdropClick: true,
435
- manualDestroy: false,
446
+ ...DEFAULT_OPTIONS,
436
447
  ...options,
437
448
  },
438
- }), [
439
- ForegroundComponent,
440
- BackgroundComponent,
441
- ContentComponent,
442
- FooterComponent,
443
- SubtitleComponent,
444
- TitleComponent,
445
- options,
446
- ]);
449
+ }), [memoized, options]);
447
450
  return (jsxRuntime.jsx(ConfigurationContext.Provider, { value: value, children: children }));
448
451
  });
449
452
 
@@ -678,10 +681,7 @@ const BackgroundFrame = ({ modalId, onChangeOrder, }) => {
678
681
  const Background = react.useMemo(() => modal?.BackgroundComponent || BackgroundComponent, [BackgroundComponent, modal]);
679
682
  if (!modal)
680
683
  return null;
681
- return (jsxRuntime.jsx("div", { className: classNames.cx(background, {
682
- [active$1]: modal.closeOnBackdropClick && modal.visible,
683
- [visible$1]: modal.manualDestroy ? modal.alive : modal.visible,
684
- }), onClick: handleClose, children: Background && (jsxRuntime.jsx(Background, { id: modal.id, type: modal.type, alive: modal.alive, visible: modal.visible, initiator: modal.initiator, manualDestroy: modal.manualDestroy, closeOnBackdropClick: modal.closeOnBackdropClick, background: modal.background, onChange: onChange, onConfirm: onConfirm, onClose: onClose, onDestroy: onDestroy, onChangeOrder: onChangeOrder, context: userDefinedContext })) }));
684
+ return (jsxRuntime.jsx("div", { className: util.cxLite(background, modal.closeOnBackdropClick && modal.visible && active$1, (modal.manualDestroy ? modal.alive : modal.visible) && visible$1), onClick: handleClose, children: Background && (jsxRuntime.jsx(Background, { id: modal.id, type: modal.type, alive: modal.alive, visible: modal.visible, initiator: modal.initiator, manualDestroy: modal.manualDestroy, closeOnBackdropClick: modal.closeOnBackdropClick, background: modal.background, onChange: onChange, onConfirm: onConfirm, onClose: onClose, onDestroy: onDestroy, onChangeOrder: onChangeOrder, context: userDefinedContext })) }));
685
685
  };
686
686
 
687
687
  const AlertInner = react.memo(({ modal, handlers }) => {
@@ -792,10 +792,7 @@ const ForegroundFrame = ({ modalId, onChangeOrder, }) => {
792
792
  const Foreground = react.useMemo(() => modal?.ForegroundComponent || ForegroundComponent, [ForegroundComponent, modal]);
793
793
  if (!modal)
794
794
  return null;
795
- return (jsxRuntime.jsx("div", { className: classNames.cx(foreground, {
796
- [active]: modal.visible,
797
- [visible]: modal.manualDestroy ? modal.alive : modal.visible,
798
- }), children: jsxRuntime.jsxs(Foreground, { id: modal.id, type: modal.type, alive: modal.alive, visible: modal.visible, initiator: modal.initiator, manualDestroy: modal.manualDestroy, closeOnBackdropClick: modal.closeOnBackdropClick, background: modal.background, onChange: onChange, onConfirm: onConfirm, onClose: onClose, onDestroy: onDestroy, onChangeOrder: onChangeOrder, context: userDefinedContext, children: [modal.type === 'alert' && (jsxRuntime.jsx(AlertInner, { modal: modal, handlers: { onConfirm } })), modal.type === 'confirm' && (jsxRuntime.jsx(ConfirmInner, { modal: modal, handlers: { onConfirm, onClose } })), modal.type === 'prompt' && (jsxRuntime.jsx(PromptInner, { modal: modal, handlers: { onChange, onConfirm, onClose } }))] }) }));
795
+ return (jsxRuntime.jsx("div", { className: util.cxLite(foreground, modal.visible && active, (modal.manualDestroy ? modal.alive : modal.visible) && visible), children: jsxRuntime.jsxs(Foreground, { id: modal.id, type: modal.type, alive: modal.alive, visible: modal.visible, initiator: modal.initiator, manualDestroy: modal.manualDestroy, closeOnBackdropClick: modal.closeOnBackdropClick, background: modal.background, onChange: onChange, onConfirm: onConfirm, onClose: onClose, onDestroy: onDestroy, onChangeOrder: onChangeOrder, context: userDefinedContext, children: [modal.type === 'alert' && (jsxRuntime.jsx(AlertInner, { modal: modal, handlers: { onConfirm } })), modal.type === 'confirm' && (jsxRuntime.jsx(ConfirmInner, { modal: modal, handlers: { onConfirm, onClose } })), modal.type === 'prompt' && (jsxRuntime.jsx(PromptInner, { modal: modal, handlers: { onChange, onConfirm, onClose } }))] }) }));
799
796
  };
800
797
 
801
798
  const useSubscribeModal = (modal) => {
package/dist/index.mjs CHANGED
@@ -1,15 +1,14 @@
1
1
  import { jsx, jsxs } from 'react/jsx-runtime';
2
2
  import { createContext, useContext, useMemo, forwardRef, memo, useRef, useState, useLayoutEffect, useCallback, Fragment, useEffect, useImperativeHandle } from 'react';
3
3
  import { convertMsFromDuration } from '@winglet/common-utils/convert';
4
- import { useReference, useOnMountLayout, useHandle, useVersion, useOnMount } from '@winglet/react-utils/hook';
4
+ import { useMemorize, useSnapshot, useReference, useOnMountLayout, useHandle, useVersion, useOnMount } from '@winglet/react-utils/hook';
5
5
  import { polynomialHash } from '@winglet/common-utils/hash';
6
6
  import { getRandomString, counterFactory } from '@winglet/common-utils/lib';
7
- import { compressCss } from '@winglet/style-utils/compressCss';
8
- import { styleManagerFactory, destroyScope } from '@winglet/style-utils/styleManager';
7
+ import { styleManagerFactory, destroyScope } from '@winglet/style-utils/style-manager';
8
+ import { compressCss, cxLite } from '@winglet/style-utils/util';
9
9
  import { createPortal } from 'react-dom';
10
10
  import { map } from '@winglet/common-utils/array';
11
11
  import { withErrorBoundary } from '@winglet/react-utils/hoc';
12
- import { cx } from '@winglet/style-utils/classNames';
13
12
  import { isString, isFunction } from '@winglet/common-utils/filter';
14
13
  import { renderComponent } from '@winglet/react-utils/render';
15
14
  import { printError } from '@winglet/common-utils/console';
@@ -418,30 +417,34 @@ const FallbackForegroundFrame = forwardRef(({ id, onChangeOrder, children }, ref
418
417
 
419
418
  const ConfigurationContext = createContext({});
420
419
 
421
- const ConfigurationContextProvider = memo(({ ForegroundComponent, BackgroundComponent, TitleComponent, SubtitleComponent, ContentComponent, FooterComponent, options, children, }) => {
422
- const value = useMemo(() => ({
420
+ const DEFAULT_OPTIONS = {
421
+ duration: DEFAULT_ANIMATION_DURATION,
422
+ backdrop: DEFAULT_BACKDROP_COLOR,
423
+ closeOnBackdropClick: true,
424
+ manualDestroy: false,
425
+ };
426
+ const ConfigurationContextProvider = memo(({ ForegroundComponent, BackgroundComponent, TitleComponent, SubtitleComponent, ContentComponent, FooterComponent, options: inputOptions, children, }) => {
427
+ const memoized = useMemorize({
423
428
  BackgroundComponent,
424
429
  ForegroundComponent: ForegroundComponent || FallbackForegroundFrame,
425
430
  TitleComponent: TitleComponent || FallbackTitle,
426
431
  SubtitleComponent: SubtitleComponent || FallbackSubtitle,
427
432
  ContentComponent: memo(ContentComponent || FallbackContent),
428
433
  FooterComponent: memo(FooterComponent || FallbackFooter),
434
+ });
435
+ const options = useSnapshot(inputOptions);
436
+ const value = useMemo(() => ({
437
+ ForegroundComponent: memoized.ForegroundComponent,
438
+ BackgroundComponent: memoized.BackgroundComponent,
439
+ TitleComponent: memoized.TitleComponent,
440
+ SubtitleComponent: memoized.SubtitleComponent,
441
+ ContentComponent: memoized.ContentComponent,
442
+ FooterComponent: memoized.FooterComponent,
429
443
  options: {
430
- duration: DEFAULT_ANIMATION_DURATION,
431
- backdrop: DEFAULT_BACKDROP_COLOR,
432
- closeOnBackdropClick: true,
433
- manualDestroy: false,
444
+ ...DEFAULT_OPTIONS,
434
445
  ...options,
435
446
  },
436
- }), [
437
- ForegroundComponent,
438
- BackgroundComponent,
439
- ContentComponent,
440
- FooterComponent,
441
- SubtitleComponent,
442
- TitleComponent,
443
- options,
444
- ]);
447
+ }), [memoized, options]);
445
448
  return (jsx(ConfigurationContext.Provider, { value: value, children: children }));
446
449
  });
447
450
 
@@ -676,10 +679,7 @@ const BackgroundFrame = ({ modalId, onChangeOrder, }) => {
676
679
  const Background = useMemo(() => modal?.BackgroundComponent || BackgroundComponent, [BackgroundComponent, modal]);
677
680
  if (!modal)
678
681
  return null;
679
- return (jsx("div", { className: cx(background, {
680
- [active$1]: modal.closeOnBackdropClick && modal.visible,
681
- [visible$1]: modal.manualDestroy ? modal.alive : modal.visible,
682
- }), onClick: handleClose, children: Background && (jsx(Background, { id: modal.id, type: modal.type, alive: modal.alive, visible: modal.visible, initiator: modal.initiator, manualDestroy: modal.manualDestroy, closeOnBackdropClick: modal.closeOnBackdropClick, background: modal.background, onChange: onChange, onConfirm: onConfirm, onClose: onClose, onDestroy: onDestroy, onChangeOrder: onChangeOrder, context: userDefinedContext })) }));
682
+ return (jsx("div", { className: cxLite(background, modal.closeOnBackdropClick && modal.visible && active$1, (modal.manualDestroy ? modal.alive : modal.visible) && visible$1), onClick: handleClose, children: Background && (jsx(Background, { id: modal.id, type: modal.type, alive: modal.alive, visible: modal.visible, initiator: modal.initiator, manualDestroy: modal.manualDestroy, closeOnBackdropClick: modal.closeOnBackdropClick, background: modal.background, onChange: onChange, onConfirm: onConfirm, onClose: onClose, onDestroy: onDestroy, onChangeOrder: onChangeOrder, context: userDefinedContext })) }));
683
683
  };
684
684
 
685
685
  const AlertInner = memo(({ modal, handlers }) => {
@@ -790,10 +790,7 @@ const ForegroundFrame = ({ modalId, onChangeOrder, }) => {
790
790
  const Foreground = useMemo(() => modal?.ForegroundComponent || ForegroundComponent, [ForegroundComponent, modal]);
791
791
  if (!modal)
792
792
  return null;
793
- return (jsx("div", { className: cx(foreground, {
794
- [active]: modal.visible,
795
- [visible]: modal.manualDestroy ? modal.alive : modal.visible,
796
- }), children: jsxs(Foreground, { id: modal.id, type: modal.type, alive: modal.alive, visible: modal.visible, initiator: modal.initiator, manualDestroy: modal.manualDestroy, closeOnBackdropClick: modal.closeOnBackdropClick, background: modal.background, onChange: onChange, onConfirm: onConfirm, onClose: onClose, onDestroy: onDestroy, onChangeOrder: onChangeOrder, context: userDefinedContext, children: [modal.type === 'alert' && (jsx(AlertInner, { modal: modal, handlers: { onConfirm } })), modal.type === 'confirm' && (jsx(ConfirmInner, { modal: modal, handlers: { onConfirm, onClose } })), modal.type === 'prompt' && (jsx(PromptInner, { modal: modal, handlers: { onChange, onConfirm, onClose } }))] }) }));
793
+ return (jsx("div", { className: cxLite(foreground, modal.visible && active, (modal.manualDestroy ? modal.alive : modal.visible) && visible), children: jsxs(Foreground, { id: modal.id, type: modal.type, alive: modal.alive, visible: modal.visible, initiator: modal.initiator, manualDestroy: modal.manualDestroy, closeOnBackdropClick: modal.closeOnBackdropClick, background: modal.background, onChange: onChange, onConfirm: onConfirm, onClose: onClose, onDestroy: onDestroy, onChangeOrder: onChangeOrder, context: userDefinedContext, children: [modal.type === 'alert' && (jsx(AlertInner, { modal: modal, handlers: { onConfirm } })), modal.type === 'confirm' && (jsx(ConfirmInner, { modal: modal, handlers: { onConfirm, onClose } })), modal.type === 'prompt' && (jsx(PromptInner, { modal: modal, handlers: { onChange, onConfirm, onClose } }))] }) }));
797
794
  };
798
795
 
799
796
  const useSubscribeModal = (modal) => {
@@ -19,4 +19,4 @@ export interface ConfigurationContextProviderProps {
19
19
  closeOnBackdropClick?: boolean;
20
20
  };
21
21
  }
22
- export declare const ConfigurationContextProvider: import("react").MemoExoticComponent<({ ForegroundComponent, BackgroundComponent, TitleComponent, SubtitleComponent, ContentComponent, FooterComponent, options, children, }: PropsWithChildren<ConfigurationContextProviderProps>) => import("react/jsx-runtime").JSX.Element>;
22
+ export declare const ConfigurationContextProvider: import("react").MemoExoticComponent<({ ForegroundComponent, BackgroundComponent, TitleComponent, SubtitleComponent, ContentComponent, FooterComponent, options: inputOptions, children, }: PropsWithChildren<ConfigurationContextProviderProps>) => import("react/jsx-runtime").JSX.Element>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lerx/promise-modal",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Universal React modal utility that can be used outside React components with promise-based results for alert, confirm, and prompt modals",
5
5
  "keywords": [
6
6
  "react",
@@ -66,11 +66,11 @@
66
66
  },
67
67
  "dependencies": {
68
68
  "@winglet/common-utils": "^0.2.2",
69
- "@winglet/react-utils": "^0.2.4",
70
- "@winglet/style-utils": "^0.2.1"
69
+ "@winglet/react-utils": "^0.2.6",
70
+ "@winglet/style-utils": "^0.2.2"
71
71
  },
72
72
  "devDependencies": {
73
- "@chromatic-com/storybook": "^3.2.6",
73
+ "@chromatic-com/storybook": "^4.0.1",
74
74
  "@rollup/plugin-commonjs": "^28.0.1",
75
75
  "@rollup/plugin-node-resolve": "^15.3.0",
76
76
  "@rollup/plugin-terser": "^0.4.4",
@@ -78,12 +78,8 @@
78
78
  "@size-limit/preset-app": "^11.1.6",
79
79
  "@size-limit/preset-big-lib": "^11.1.6",
80
80
  "@size-limit/preset-small-lib": "^11.1.6",
81
- "@storybook/addon-essentials": "^8.6.14",
82
- "@storybook/addon-interactions": "^8.6.14",
83
- "@storybook/blocks": "^8.6.14",
84
- "@storybook/react": "^8.6.14",
85
- "@storybook/react-vite": "^8.6.14",
86
- "@storybook/test": "^8.6.14",
81
+ "@storybook/addon-docs": "^9.0.14",
82
+ "@storybook/react-vite": "^9.0.14",
87
83
  "@testing-library/dom": "^10.4.0",
88
84
  "@testing-library/jest-dom": "^6.6.3",
89
85
  "@testing-library/react": "^16.1.0",
@@ -102,7 +98,7 @@
102
98
  "rollup-plugin-peer-deps-external": "^2.2.4",
103
99
  "rollup-plugin-visualizer": "^5.12.0",
104
100
  "size-limit": "^11.2.0",
105
- "storybook": "^8.6.14",
101
+ "storybook": "^9.0.14",
106
102
  "tsc-alias": "^1.8.16",
107
103
  "typescript": "^5.7.2",
108
104
  "vite": "^6.3.5",