@lerx/promise-modal 0.2.6 → 0.2.8

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
@@ -419,30 +419,34 @@ const FallbackForegroundFrame = react.forwardRef(({ id, onChangeOrder, children
419
419
 
420
420
  const ConfigurationContext = react.createContext({});
421
421
 
422
- const ConfigurationContextProvider = react.memo(({ ForegroundComponent, BackgroundComponent, TitleComponent, SubtitleComponent, ContentComponent, FooterComponent, options, children, }) => {
423
- 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({
424
430
  BackgroundComponent,
425
431
  ForegroundComponent: ForegroundComponent || FallbackForegroundFrame,
426
432
  TitleComponent: TitleComponent || FallbackTitle,
427
433
  SubtitleComponent: SubtitleComponent || FallbackSubtitle,
428
434
  ContentComponent: react.memo(ContentComponent || FallbackContent),
429
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,
430
445
  options: {
431
- duration: DEFAULT_ANIMATION_DURATION,
432
- backdrop: DEFAULT_BACKDROP_COLOR,
433
- closeOnBackdropClick: true,
434
- manualDestroy: false,
446
+ ...DEFAULT_OPTIONS,
435
447
  ...options,
436
448
  },
437
- }), [
438
- ForegroundComponent,
439
- BackgroundComponent,
440
- ContentComponent,
441
- FooterComponent,
442
- SubtitleComponent,
443
- TitleComponent,
444
- options,
445
- ]);
449
+ }), [memoized, options]);
446
450
  return (jsxRuntime.jsx(ConfigurationContext.Provider, { value: value, children: children }));
447
451
  });
448
452
 
package/dist/index.d.ts CHANGED
@@ -5,4 +5,4 @@ export { useDestroyAfter } from './hooks/useDestroyAfter';
5
5
  export { useActiveModalCount } from './hooks/useActiveModalCount';
6
6
  export { useModalAnimation } from './hooks/useModalAnimation';
7
7
  export { alert, confirm, prompt } from './core';
8
- export type { ModalFrameProps, FooterComponentProps, ModalBackground, PromptInputProps, AlertContentProps, ConfirmContentProps, PromptContentProps, WrapperComponentProps, } from './types';
8
+ export type { ModalOptions, ModalFrameProps, FooterComponentProps, ModalBackground, PromptInputProps, AlertContentProps, ConfirmContentProps, PromptContentProps, WrapperComponentProps, } from './types';
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
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
7
  import { styleManagerFactory, destroyScope } from '@winglet/style-utils/style-manager';
@@ -417,30 +417,34 @@ const FallbackForegroundFrame = forwardRef(({ id, onChangeOrder, children }, ref
417
417
 
418
418
  const ConfigurationContext = createContext({});
419
419
 
420
- const ConfigurationContextProvider = memo(({ ForegroundComponent, BackgroundComponent, TitleComponent, SubtitleComponent, ContentComponent, FooterComponent, options, children, }) => {
421
- 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({
422
428
  BackgroundComponent,
423
429
  ForegroundComponent: ForegroundComponent || FallbackForegroundFrame,
424
430
  TitleComponent: TitleComponent || FallbackTitle,
425
431
  SubtitleComponent: SubtitleComponent || FallbackSubtitle,
426
432
  ContentComponent: memo(ContentComponent || FallbackContent),
427
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,
428
443
  options: {
429
- duration: DEFAULT_ANIMATION_DURATION,
430
- backdrop: DEFAULT_BACKDROP_COLOR,
431
- closeOnBackdropClick: true,
432
- manualDestroy: false,
444
+ ...DEFAULT_OPTIONS,
433
445
  ...options,
434
446
  },
435
- }), [
436
- ForegroundComponent,
437
- BackgroundComponent,
438
- ContentComponent,
439
- FooterComponent,
440
- SubtitleComponent,
441
- TitleComponent,
442
- options,
443
- ]);
447
+ }), [memoized, options]);
444
448
  return (jsx(ConfigurationContext.Provider, { value: value, children: children }));
445
449
  });
446
450
 
@@ -1,6 +1,5 @@
1
1
  import { type ComponentType } from 'react';
2
- import type { Color, Duration } from '../../@aileron/declare';
3
- import type { BackgroundComponent, FooterComponentProps, ForegroundComponent, WrapperComponentProps } from '../../types';
2
+ import type { BackgroundComponent, FooterComponentProps, ForegroundComponent, ModalOptions, WrapperComponentProps } from '../../types';
4
3
  export interface ConfigurationContextProps {
5
4
  ForegroundComponent: ForegroundComponent;
6
5
  BackgroundComponent?: BackgroundComponent;
@@ -8,11 +7,6 @@ export interface ConfigurationContextProps {
8
7
  SubtitleComponent: ComponentType<WrapperComponentProps>;
9
8
  ContentComponent: ComponentType<WrapperComponentProps>;
10
9
  FooterComponent: ComponentType<FooterComponentProps>;
11
- options: {
12
- duration: Duration;
13
- backdrop: Color;
14
- manualDestroy: boolean;
15
- closeOnBackdropClick: boolean;
16
- };
10
+ options: Required<ModalOptions>;
17
11
  }
18
12
  export declare const ConfigurationContext: import("react").Context<ConfigurationContextProps>;
@@ -1,6 +1,5 @@
1
1
  import { type ComponentType, type PropsWithChildren } from 'react';
2
- import type { Color, Duration } from '../../@aileron/declare';
3
- import type { FooterComponentProps, ModalFrameProps, WrapperComponentProps } from '../../types';
2
+ import type { FooterComponentProps, ModalFrameProps, ModalOptions, WrapperComponentProps } from '../../types';
4
3
  export interface ConfigurationContextProviderProps {
5
4
  BackgroundComponent?: ComponentType<ModalFrameProps>;
6
5
  ForegroundComponent?: ComponentType<ModalFrameProps>;
@@ -8,15 +7,6 @@ export interface ConfigurationContextProviderProps {
8
7
  SubtitleComponent?: ComponentType<WrapperComponentProps>;
9
8
  ContentComponent?: ComponentType<WrapperComponentProps>;
10
9
  FooterComponent?: ComponentType<FooterComponentProps>;
11
- options?: {
12
- /** Modal transition time(ms, s) */
13
- duration?: Duration;
14
- /** Modal backdrop color */
15
- backdrop?: Color;
16
- /** Whether to destroy the modal manually */
17
- manualDestroy?: boolean;
18
- /** Whether to close the modal when the backdrop is clicked */
19
- closeOnBackdropClick?: boolean;
20
- };
10
+ options?: ModalOptions;
21
11
  }
22
- export declare const ConfigurationContextProvider: import("react").MemoExoticComponent<({ ForegroundComponent, BackgroundComponent, TitleComponent, SubtitleComponent, ContentComponent, FooterComponent, options, children, }: PropsWithChildren<ConfigurationContextProviderProps>) => import("react/jsx-runtime").JSX.Element>;
12
+ export declare const ConfigurationContextProvider: import("react").MemoExoticComponent<({ ForegroundComponent, BackgroundComponent, TitleComponent, SubtitleComponent, ContentComponent, FooterComponent, options: inputOptions, children, }: PropsWithChildren<ConfigurationContextProviderProps>) => import("react/jsx-runtime").JSX.Element>;
@@ -1,10 +1,5 @@
1
1
  export declare const useConfigurationContext: () => import("./ConfigurationContext").ConfigurationContextProps;
2
- export declare const useConfigurationOptions: () => {
3
- duration: import("../../@aileron/declare").Duration;
4
- backdrop: import("../../@aileron/declare").Color;
5
- manualDestroy: boolean;
6
- closeOnBackdropClick: boolean;
7
- };
2
+ export declare const useConfigurationOptions: () => Required<import("../..").ModalOptions>;
8
3
  export declare const useConfigurationDuration: () => {
9
4
  duration: `${number}ms`;
10
5
  milliseconds: number;
@@ -4,3 +4,4 @@ export * from './confirm';
4
4
  export * from './modal';
5
5
  export * from './prompt';
6
6
  export * from './background';
7
+ export * from './option';
@@ -0,0 +1,11 @@
1
+ import type { Color, Duration } from '../@aileron/declare';
2
+ export interface ModalOptions {
3
+ /** Modal transition time(ms, s) */
4
+ duration?: Duration;
5
+ /** Modal backdrop color */
6
+ backdrop?: Color;
7
+ /** Whether to destroy the modal manually */
8
+ manualDestroy?: boolean;
9
+ /** Whether to close the modal when the backdrop is clicked */
10
+ closeOnBackdropClick?: boolean;
11
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lerx/promise-modal",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
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",
69
+ "@winglet/react-utils": "^0.2.6",
70
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",