@lerx/promise-modal 0.8.5 → 0.8.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.
@@ -1,23 +1,11 @@
1
1
  import type { ComponentType, ReactNode } from 'react';
2
2
  import type { Fn } from '../../@aileron/declare';
3
3
  import type { AlertContentProps, AlertFooterRender, BackgroundComponent, ConfirmContentProps, ConfirmFooterRender, FooterOptions, ForegroundComponent, ModalBackground, PromptContentProps, PromptFooterRender, PromptInputProps } from '../../types';
4
- export interface AlertProps<BackgroundValue> {
4
+ export interface OverridableHandleProps {
5
5
  /** Modal group identifier for managing related modals */
6
6
  group?: string;
7
7
  /** Alert subtype that affects UI styling */
8
8
  subtype?: 'info' | 'success' | 'warning' | 'error';
9
- /** Modal title */
10
- title?: ReactNode;
11
- /** Modal subtitle */
12
- subtitle?: ReactNode;
13
- /** Modal content. Can be a ReactNode or a component */
14
- content?: ReactNode | ComponentType<AlertContentProps>;
15
- /** Background layer data and configuration */
16
- background?: ModalBackground<BackgroundValue>;
17
- /** Footer configuration. Can be a render function, options object, or false */
18
- footer?: AlertFooterRender | Pick<FooterOptions, 'confirm' | 'hideConfirm'> | false;
19
- /** Abort signal to cancel the modal */
20
- signal?: AbortSignal;
21
9
  /** Whether to dim the background */
22
10
  dimmed?: boolean;
23
11
  /** Modal animation duration in milliseconds */
@@ -31,45 +19,27 @@ export interface AlertProps<BackgroundValue> {
31
19
  /** Custom background component */
32
20
  BackgroundComponent?: BackgroundComponent;
33
21
  }
34
- export interface ConfirmProps<BackgroundValue> {
35
- /** Modal group identifier for managing related modals */
36
- group?: string;
37
- /** Confirmation subtype that affects UI styling */
38
- subtype?: 'info' | 'success' | 'warning' | 'error';
22
+ interface BaseHandleProps<ContentProps, BackgroundValue> extends OverridableHandleProps {
39
23
  /** Modal title */
40
24
  title?: ReactNode;
41
25
  /** Modal subtitle */
42
26
  subtitle?: ReactNode;
43
27
  /** Modal content. Can be a ReactNode or a component */
44
- content?: ReactNode | ComponentType<ConfirmContentProps>;
28
+ content?: ReactNode | ComponentType<ContentProps>;
45
29
  /** Background layer data and configuration */
46
30
  background?: ModalBackground<BackgroundValue>;
47
- /** Footer configuration. Can be a render function, options object, or false */
48
- footer?: ConfirmFooterRender | FooterOptions | false;
49
31
  /** Abort signal to cancel the modal */
50
32
  signal?: AbortSignal;
51
- /** Whether to dim the background */
52
- dimmed?: boolean;
53
- /** Modal animation duration in milliseconds */
54
- duration?: number;
55
- /** If true, keeps modal in DOM after closing (for animations) */
56
- manualDestroy?: boolean;
57
- /** Whether to close modal on backdrop click */
58
- closeOnBackdropClick?: boolean;
59
- /** Custom foreground component */
60
- ForegroundComponent?: ForegroundComponent;
61
- /** Custom background component */
62
- BackgroundComponent?: BackgroundComponent;
63
33
  }
64
- export interface PromptProps<InputValue, BackgroundValue = any> {
65
- /** Modal group identifier for managing related modals */
66
- group?: string;
67
- /** Modal title */
68
- title?: ReactNode;
69
- /** Modal subtitle */
70
- subtitle?: ReactNode;
71
- /** Modal content. Can be a ReactNode or a component */
72
- content?: ReactNode | ComponentType<PromptContentProps>;
34
+ export interface AlertProps<BackgroundValue> extends BaseHandleProps<AlertContentProps, BackgroundValue> {
35
+ /** Footer configuration. Can be a render function, options object, or false */
36
+ footer?: AlertFooterRender | Pick<FooterOptions, 'confirm' | 'hideConfirm'> | false;
37
+ }
38
+ export interface ConfirmProps<BackgroundValue> extends BaseHandleProps<ConfirmContentProps, BackgroundValue> {
39
+ /** Footer configuration. Can be a render function, options object, or false */
40
+ footer?: ConfirmFooterRender | FooterOptions | false;
41
+ }
42
+ export interface PromptProps<InputValue, BackgroundValue = any> extends BaseHandleProps<PromptContentProps, BackgroundValue> {
73
43
  /** Initial value for the input field */
74
44
  defaultValue?: InputValue;
75
45
  /** Input component that receives value, onChange, and other props */
@@ -78,22 +48,7 @@ export interface PromptProps<InputValue, BackgroundValue = any> {
78
48
  disabled?: Fn<[value: InputValue], boolean>;
79
49
  /** If true, returns defaultValue instead of rejecting on cancel */
80
50
  returnOnCancel?: boolean;
81
- /** Background layer data and configuration */
82
- background?: ModalBackground<BackgroundValue>;
83
51
  /** Footer configuration. Can be a render function, options object, or false */
84
52
  footer?: PromptFooterRender<InputValue> | FooterOptions | false;
85
- /** Abort signal to cancel the modal */
86
- signal?: AbortSignal;
87
- /** Whether to dim the background */
88
- dimmed?: boolean;
89
- /** Modal animation duration in milliseconds */
90
- duration?: number;
91
- /** If true, keeps modal in DOM after closing (for animations) */
92
- manualDestroy?: boolean;
93
- /** Whether to close modal on backdrop click */
94
- closeOnBackdropClick?: boolean;
95
- /** Custom foreground component */
96
- ForegroundComponent?: ForegroundComponent;
97
- /** Custom background component */
98
- BackgroundComponent?: BackgroundComponent;
99
53
  }
54
+ export {};
@@ -1,6 +1,7 @@
1
1
  import { type AlertProps, type ConfirmProps, type PromptProps } from '../core';
2
- export declare const useModal: () => {
3
- readonly alert: <BackgroundValue = any>(args: AlertProps<BackgroundValue>) => Promise<void>;
4
- readonly confirm: <BackgroundValue = any>(args: ConfirmProps<BackgroundValue>) => Promise<boolean>;
5
- readonly prompt: <InputValue, BackgroundValue = any>(args: PromptProps<InputValue, BackgroundValue>) => Promise<InputValue>;
2
+ import type { OverridableHandleProps } from '../core/handle/type';
3
+ export declare const useModal: (configuration?: OverridableHandleProps) => {
4
+ readonly alert: <Background = any>(args: AlertProps<Background>) => Promise<void>;
5
+ readonly confirm: <Background = any>(args: ConfirmProps<Background>) => Promise<boolean>;
6
+ readonly prompt: <Value, Background = any>(args: PromptProps<Value, Background>) => Promise<Value>;
6
7
  };
@@ -0,0 +1,5 @@
1
+ import type { ModalNode } from '../core';
2
+ export declare const useModalDuration: (id?: ModalNode["id"]) => {
3
+ duration: string;
4
+ milliseconds: number;
5
+ };
package/dist/index.cjs CHANGED
@@ -985,20 +985,21 @@ const useBootstrap = ({ usePathname: useExternalPathname, ForegroundComponent, B
985
985
  return { portal, initialize };
986
986
  };
987
987
 
988
- const useModal = () => {
988
+ const useModal = (configuration) => {
989
989
  const modalNodesRef = react.useRef([]);
990
+ const baseArgsRef = react.useRef(configuration);
990
991
  const alertRef = react.useRef((args) => {
991
- const { modalNode, promiseHandler } = alertHandler(args);
992
+ const { modalNode, promiseHandler } = alertHandler(baseArgsRef.current ? { ...baseArgsRef.current, ...args } : args);
992
993
  modalNodesRef.current.push(modalNode);
993
994
  return promiseHandler;
994
995
  });
995
996
  const confirmRef = react.useRef((args) => {
996
- const { modalNode, promiseHandler } = confirmHandler(args);
997
+ const { modalNode, promiseHandler } = confirmHandler(baseArgsRef.current ? { ...baseArgsRef.current, ...args } : args);
997
998
  modalNodesRef.current.push(modalNode);
998
999
  return promiseHandler;
999
1000
  });
1000
1001
  const promptRef = react.useRef((args) => {
1001
- const { modalNode, promiseHandler } = promptHandler(args);
1002
+ const { modalNode, promiseHandler } = promptHandler(baseArgsRef.current ? { ...baseArgsRef.current, ...args } : args);
1002
1003
  modalNodesRef.current.push(modalNode);
1003
1004
  return promiseHandler;
1004
1005
  });
@@ -1057,6 +1058,17 @@ const useModalAnimation = (visible, handler) => {
1057
1058
  }, [visible]);
1058
1059
  };
1059
1060
 
1061
+ const useModalDuration = (id) => {
1062
+ const globalDuration = useConfigurationDuration();
1063
+ if (id === undefined)
1064
+ return globalDuration;
1065
+ const { modal } = useModalManager(id);
1066
+ if (modal === undefined)
1067
+ return globalDuration;
1068
+ const milliseconds = modal.duration;
1069
+ return { duration: milliseconds + 'ms', milliseconds };
1070
+ };
1071
+
1060
1072
  exports.ModalProvider = BootstrapProvider;
1061
1073
  exports.alert = alert;
1062
1074
  exports.confirm = confirm;
@@ -1067,6 +1079,6 @@ exports.useInitializeModal = useBootstrap;
1067
1079
  exports.useModal = useModal;
1068
1080
  exports.useModalAnimation = useModalAnimation;
1069
1081
  exports.useModalBackdrop = useConfigurationBackdrop;
1070
- exports.useModalDuration = useConfigurationDuration;
1082
+ exports.useModalDuration = useModalDuration;
1071
1083
  exports.useModalOptions = useConfigurationOptions;
1072
1084
  exports.useSubscribeModal = useSubscribeModal;
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- export { useConfigurationOptions as useModalOptions, useConfigurationDuration as useModalDuration, useConfigurationBackdrop as useModalBackdrop, } from './providers';
1
+ export { useConfigurationOptions as useModalOptions, useConfigurationBackdrop as useModalBackdrop, } from './providers';
2
2
  export { useBootstrap as useInitializeModal, BootstrapProvider as ModalProvider, type BootstrapProviderHandle as ModalProviderHandle, type BootstrapProviderProps as ModalProviderProps, } from './bootstrap';
3
3
  export { useModal } from './hooks/useModal';
4
4
  export { useActiveModalCount } from './hooks/useActiveModalCount';
5
5
  export { useDestroyAfter } from './hooks/useDestroyAfter';
6
6
  export { useModalAnimation } from './hooks/useModalAnimation';
7
+ export { useModalDuration } from './hooks/useModalDuration';
7
8
  export { useSubscribeModal } from './hooks/useSubscribeModal';
8
9
  export { alert, confirm, prompt } from './core';
9
10
  export type { ModalOptions, ModalFrameProps, FooterComponentProps, ModalBackground, PromptInputProps, AlertContentProps, ConfirmContentProps, PromptContentProps, WrapperComponentProps, } from './types';
package/dist/index.mjs CHANGED
@@ -983,20 +983,21 @@ const useBootstrap = ({ usePathname: useExternalPathname, ForegroundComponent, B
983
983
  return { portal, initialize };
984
984
  };
985
985
 
986
- const useModal = () => {
986
+ const useModal = (configuration) => {
987
987
  const modalNodesRef = useRef([]);
988
+ const baseArgsRef = useRef(configuration);
988
989
  const alertRef = useRef((args) => {
989
- const { modalNode, promiseHandler } = alertHandler(args);
990
+ const { modalNode, promiseHandler } = alertHandler(baseArgsRef.current ? { ...baseArgsRef.current, ...args } : args);
990
991
  modalNodesRef.current.push(modalNode);
991
992
  return promiseHandler;
992
993
  });
993
994
  const confirmRef = useRef((args) => {
994
- const { modalNode, promiseHandler } = confirmHandler(args);
995
+ const { modalNode, promiseHandler } = confirmHandler(baseArgsRef.current ? { ...baseArgsRef.current, ...args } : args);
995
996
  modalNodesRef.current.push(modalNode);
996
997
  return promiseHandler;
997
998
  });
998
999
  const promptRef = useRef((args) => {
999
- const { modalNode, promiseHandler } = promptHandler(args);
1000
+ const { modalNode, promiseHandler } = promptHandler(baseArgsRef.current ? { ...baseArgsRef.current, ...args } : args);
1000
1001
  modalNodesRef.current.push(modalNode);
1001
1002
  return promiseHandler;
1002
1003
  });
@@ -1055,4 +1056,15 @@ const useModalAnimation = (visible, handler) => {
1055
1056
  }, [visible]);
1056
1057
  };
1057
1058
 
1058
- export { BootstrapProvider as ModalProvider, alert, confirm, prompt, useActiveModalCount, useDestroyAfter, useBootstrap as useInitializeModal, useModal, useModalAnimation, useConfigurationBackdrop as useModalBackdrop, useConfigurationDuration as useModalDuration, useConfigurationOptions as useModalOptions, useSubscribeModal };
1059
+ const useModalDuration = (id) => {
1060
+ const globalDuration = useConfigurationDuration();
1061
+ if (id === undefined)
1062
+ return globalDuration;
1063
+ const { modal } = useModalManager(id);
1064
+ if (modal === undefined)
1065
+ return globalDuration;
1066
+ const milliseconds = modal.duration;
1067
+ return { duration: milliseconds + 'ms', milliseconds };
1068
+ };
1069
+
1070
+ export { BootstrapProvider as ModalProvider, alert, confirm, prompt, useActiveModalCount, useDestroyAfter, useBootstrap as useInitializeModal, useModal, useModalAnimation, useConfigurationBackdrop as useModalBackdrop, useModalDuration, useConfigurationOptions as useModalOptions, useSubscribeModal };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lerx/promise-modal",
3
- "version": "0.8.5",
3
+ "version": "0.8.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",