@helloworldqq/react-modal 1.0.2 → 1.1.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/dist/hook/index.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +74 -62
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +74 -62
- package/dist/index.modern.js.map +1 -1
- package/dist/provider/index.d.ts +14 -0
- package/dist/provider/index.d.ts.map +1 -1
- package/dist/store/index.d.ts.map +1 -1
- package/package.json +4 -3
package/dist/hook/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/hook/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAG/B,oBAAY,GAAG,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAEtF,MAAM,WAAW,mBAAmB,CAAC,CAAC;IACpC,GAAG,EAAE,OAAO,CAAA;IACZ,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAA;IACnB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;IACrB,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAA;IACpC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,IAAI,CAAA;IAC3B,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;CACtB;AAED,eAAO,MAAM,aAAa;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/hook/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAG/B,oBAAY,GAAG,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAEtF,MAAM,WAAW,mBAAmB,CAAC,CAAC;IACpC,GAAG,EAAE,OAAO,CAAA;IACZ,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAA;IACnB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;IACrB,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAA;IACpC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,IAAI,CAAA;IAC3B,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;CACtB;AAED,eAAO,MAAM,aAAa;;;;;;;uBAgEc,OAAO;;;CAiC9C,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,8 +3,9 @@ declare type ModalComponent = React.FunctionComponent<any> | React.ComponentType
|
|
|
3
3
|
export declare type ReactHookModalProviderProps = {
|
|
4
4
|
children: React.ReactNode;
|
|
5
5
|
modals: Record<string, ModalComponent>;
|
|
6
|
+
renderStrategy?: 'eager' | 'lazy';
|
|
6
7
|
};
|
|
7
|
-
export declare const ReactHookModalProvider: ({ children, modals }: ReactHookModalProviderProps) => React.JSX.Element;
|
|
8
|
+
export declare const ReactHookModalProvider: ({ children, modals, renderStrategy }: ReactHookModalProviderProps) => React.JSX.Element;
|
|
8
9
|
export * from './hook';
|
|
9
10
|
export * from './provider';
|
|
10
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,aAAK,cAAc,GAAG,KAAK,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,CAAA;AAE7E,oBAAY,2BAA2B,GAAG;IACxC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,aAAK,cAAc,GAAG,KAAK,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,CAAA;AAE7E,oBAAY,2BAA2B,GAAG;IACxC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IACtC,cAAc,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;CAClC,CAAA;AAED,eAAO,MAAM,sBAAsB,yCAIhC,2BAA2B,sBAO7B,CAAA;AAED,cAAc,QAAQ,CAAA;AACtB,cAAc,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -3,68 +3,50 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
|
|
|
3
3
|
var React = require('react');
|
|
4
4
|
var React__default = _interopDefault(React);
|
|
5
5
|
var reactStore = require('@tanstack/react-store');
|
|
6
|
-
|
|
7
|
-
function _extends() {
|
|
8
|
-
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
9
|
-
for (var e = 1; e < arguments.length; e++) {
|
|
10
|
-
var t = arguments[e];
|
|
11
|
-
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
12
|
-
}
|
|
13
|
-
return n;
|
|
14
|
-
}, _extends.apply(null, arguments);
|
|
15
|
-
}
|
|
6
|
+
var immer = require('immer');
|
|
16
7
|
|
|
17
8
|
var store = new reactStore.Store({
|
|
18
9
|
modalTags: {}
|
|
19
10
|
});
|
|
20
11
|
var openModal = function openModal(tag, input) {
|
|
21
|
-
store.setState(function (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
28
|
-
});
|
|
12
|
+
store.setState(immer.produce(function (draft) {
|
|
13
|
+
if (!draft.modalTags[tag]) {
|
|
14
|
+
draft.modalTags[tag] = {};
|
|
15
|
+
}
|
|
16
|
+
draft.modalTags[tag].input = input != null ? input : true;
|
|
17
|
+
}));
|
|
29
18
|
};
|
|
30
19
|
var okModal = function okModal(tag, output) {
|
|
31
|
-
store.setState(function (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
};
|
|
38
|
-
});
|
|
20
|
+
store.setState(immer.produce(function (draft) {
|
|
21
|
+
if (!draft.modalTags[tag]) {
|
|
22
|
+
draft.modalTags[tag] = {};
|
|
23
|
+
}
|
|
24
|
+
draft.modalTags[tag].output = output;
|
|
25
|
+
}));
|
|
39
26
|
};
|
|
40
27
|
var closeModal = function closeModal(tag) {
|
|
41
|
-
store.setState(function (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
input: false
|
|
46
|
-
}, _extends4))
|
|
28
|
+
store.setState(immer.produce(function (draft) {
|
|
29
|
+
draft.modalTags[tag] = {
|
|
30
|
+
input: false,
|
|
31
|
+
output: undefined
|
|
47
32
|
};
|
|
48
|
-
});
|
|
33
|
+
}));
|
|
49
34
|
};
|
|
50
35
|
var toggleModal = function toggleModal(tag) {
|
|
51
|
-
store.setState(function (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
36
|
+
store.setState(immer.produce(function (draft) {
|
|
37
|
+
if (!draft.modalTags[tag]) {
|
|
38
|
+
draft.modalTags[tag] = {
|
|
39
|
+
input: true
|
|
40
|
+
};
|
|
41
|
+
} else {
|
|
42
|
+
draft.modalTags[tag].input = !draft.modalTags[tag].input;
|
|
43
|
+
}
|
|
44
|
+
}));
|
|
59
45
|
};
|
|
60
46
|
var clearModalTag = function clearModalTag(tag) {
|
|
61
|
-
store.setState(function (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
modalTags: newModalTags
|
|
66
|
-
};
|
|
67
|
-
});
|
|
47
|
+
store.setState(immer.produce(function (draft) {
|
|
48
|
+
delete draft.modalTags[tag];
|
|
49
|
+
}));
|
|
68
50
|
};
|
|
69
51
|
var clearAllModalTags = function clearAllModalTags() {
|
|
70
52
|
store.setState(function () {
|
|
@@ -88,11 +70,30 @@ var useModalActions = function useModalActions(actionCallback) {
|
|
|
88
70
|
};
|
|
89
71
|
|
|
90
72
|
var ModalWrapper = React.memo(function ModalWrapper(_ref) {
|
|
91
|
-
var modals = _ref.modals
|
|
73
|
+
var modals = _ref.modals,
|
|
74
|
+
_ref$renderStrategy = _ref.renderStrategy,
|
|
75
|
+
renderStrategy = _ref$renderStrategy === void 0 ? 'lazy' : _ref$renderStrategy;
|
|
92
76
|
var modalTags = useModalStore(function (state) {
|
|
93
77
|
return state.modalTags;
|
|
94
78
|
});
|
|
95
79
|
var allModals = React.useMemo(function () {
|
|
80
|
+
if (renderStrategy === 'lazy') {
|
|
81
|
+
return Object.keys(modalTags).map(function (tag) {
|
|
82
|
+
var Modal = modals[tag];
|
|
83
|
+
if (!Modal) {
|
|
84
|
+
console.warn("[ModalWrapper] Modal \"" + tag + "\" not found in modals registry");
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
return React__default.createElement(Modal, {
|
|
89
|
+
key: tag
|
|
90
|
+
});
|
|
91
|
+
} catch (error) {
|
|
92
|
+
console.error("[ModalWrapper] Error rendering modal \"" + tag + "\":", error);
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
96
97
|
return Object.entries(modals).map(function (_ref2) {
|
|
97
98
|
var tag = _ref2[0],
|
|
98
99
|
Modal = _ref2[1];
|
|
@@ -101,10 +102,11 @@ var ModalWrapper = React.memo(function ModalWrapper(_ref) {
|
|
|
101
102
|
key: tag
|
|
102
103
|
});
|
|
103
104
|
} catch (error) {
|
|
105
|
+
console.error("[ModalWrapper] Error rendering modal \"" + tag + "\":", error);
|
|
104
106
|
return null;
|
|
105
107
|
}
|
|
106
108
|
});
|
|
107
|
-
}, [modals]);
|
|
109
|
+
}, [renderStrategy, modalTags, modals]);
|
|
108
110
|
return React__default.createElement(React__default.Fragment, null, allModals);
|
|
109
111
|
});
|
|
110
112
|
|
|
@@ -112,14 +114,20 @@ var useDisclosure = function useDisclosure(disclosureHook) {
|
|
|
112
114
|
var tag = disclosureHook.tag;
|
|
113
115
|
var disclosureHookRef = React.useRef(disclosureHook);
|
|
114
116
|
disclosureHookRef.current = disclosureHook;
|
|
115
|
-
var
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
117
|
+
var inputSelector = React.useMemo(function () {
|
|
118
|
+
return function (state) {
|
|
119
|
+
var _state$modalTags$tag;
|
|
120
|
+
return (_state$modalTags$tag = state.modalTags[tag]) === null || _state$modalTags$tag === void 0 ? void 0 : _state$modalTags$tag.input;
|
|
121
|
+
};
|
|
122
|
+
}, [tag]);
|
|
123
|
+
var outputSelector = React.useMemo(function () {
|
|
124
|
+
return function (state) {
|
|
125
|
+
var _state$modalTags$tag2;
|
|
126
|
+
return (_state$modalTags$tag2 = state.modalTags[tag]) === null || _state$modalTags$tag2 === void 0 ? void 0 : _state$modalTags$tag2.output;
|
|
127
|
+
};
|
|
128
|
+
}, [tag]);
|
|
129
|
+
var inputState = useModalStore(inputSelector);
|
|
130
|
+
var outputState = useModalStore(outputSelector);
|
|
123
131
|
var clearDisclosureTag = useModalActions(function (actions) {
|
|
124
132
|
return actions.clearModalTag;
|
|
125
133
|
});
|
|
@@ -178,9 +186,10 @@ var useDisclosure = function useDisclosure(disclosureHook) {
|
|
|
178
186
|
}, [tag, clearDisclosureTag]);
|
|
179
187
|
React.useEffect(function () {
|
|
180
188
|
if (outputState) {
|
|
181
|
-
|
|
189
|
+
var _disclosureHookRef$cu1, _disclosureHookRef$cu10;
|
|
190
|
+
(_disclosureHookRef$cu1 = disclosureHookRef.current) === null || _disclosureHookRef$cu1 === void 0 ? void 0 : (_disclosureHookRef$cu10 = _disclosureHookRef$cu1.onOk) === null || _disclosureHookRef$cu10 === void 0 ? void 0 : _disclosureHookRef$cu10.call(_disclosureHookRef$cu1, outputState);
|
|
182
191
|
}
|
|
183
|
-
}, [outputState
|
|
192
|
+
}, [outputState]);
|
|
184
193
|
return {
|
|
185
194
|
isOpen: !!inputState,
|
|
186
195
|
input: typeof inputState === 'boolean' ? undefined : inputState,
|
|
@@ -196,9 +205,12 @@ var useDisclosure = function useDisclosure(disclosureHook) {
|
|
|
196
205
|
|
|
197
206
|
var ReactHookModalProvider = function ReactHookModalProvider(_ref) {
|
|
198
207
|
var children = _ref.children,
|
|
199
|
-
modals = _ref.modals
|
|
208
|
+
modals = _ref.modals,
|
|
209
|
+
_ref$renderStrategy = _ref.renderStrategy,
|
|
210
|
+
renderStrategy = _ref$renderStrategy === void 0 ? 'lazy' : _ref$renderStrategy;
|
|
200
211
|
return React.createElement(React.Fragment, null, React.createElement(ModalWrapper, {
|
|
201
|
-
modals: modals
|
|
212
|
+
modals: modals,
|
|
213
|
+
renderStrategy: renderStrategy
|
|
202
214
|
}), children);
|
|
203
215
|
};
|
|
204
216
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/store/index.ts","../src/provider/index.tsx","../src/hook/index.ts","../src/index.tsx"],"sourcesContent":["import { Store, useStore } from \"@tanstack/react-store\";\n\n// You can instantiate the store outside of React components too!\n\nimport { Any } from '../hook'\n\nexport type State = {\n modalTags: {\n [tag: string]: {\n input?: Any\n output?: Any\n }\n }\n}\n\nexport type Action = {\n openModal: (tag: string, input?: Any) => void\n okModal: (tag: string, output?: Any) => void\n closeModal: (tag: string) => void\n toggleModal: (tag: string) => void\n clearModalTag: (tag: string) => void\n clearAllModalTags: () => void\n}\nexport const store = new Store<State>({\n modalTags: {}\n});\n\n\nconst openModal = (tag: string, input?: Any) => {\n store.setState((state) => ({\n modalTags: {\n ...state.modalTags,\n [tag]: {\n ...state.modalTags[tag],\n input: input ?? true // Default to true if no input is provided\n }\n }\n }))\n}\nconst okModal = (tag: string, output?: Any) => {\n store.setState((state) => ({\n modalTags: {\n ...state.modalTags,\n [tag]: {\n ...state.modalTags[tag],\n output\n }\n }\n }))\n}\nconst closeModal = (tag: string) => {\n store.setState((state) => ({\n modalTags: {\n ...state.modalTags,\n [tag]: { input: false }\n }\n }))\n}\nconst toggleModal = (tag: string) => {\n store.setState((state) => ({\n modalTags: {\n ...state.modalTags,\n [tag]: {\n ...state.modalTags[tag],\n input: !state.modalTags[tag]?.input\n }\n }\n }))\n}\nconst clearModalTag = (tag: string) => {\n store.setState((state) => {\n const newModalTags = { ...state.modalTags };\n delete newModalTags[tag];\n return { modalTags: newModalTags };\n })\n}\nconst clearAllModalTags = () => {\n store.setState(() => ({ modalTags: {} }))\n}\n\nexport const useModalStore = <T>(\n stateCallback: (state: State) => T,\n): T => {\n return useStore(store, stateCallback)\n}\n\nexport const useModalActions = <T>(\n actionCallback: (action: Action) => T\n): T => {\n return actionCallback(\n {\n openModal,\n okModal,\n closeModal,\n toggleModal,\n clearModalTag,\n clearAllModalTags\n }\n )\n}","import React, { useMemo, memo } from 'react'\nimport { useModalStore, State } from '../store'\n\ntype ModalComponent = React.FunctionComponent<any> | React.ComponentType<any>\n\nexport interface ModalWrapperProps {\n modals: Record<string, ModalComponent>\n}\n\nexport const ModalWrapper = memo(function ModalWrapper({\n modals\n}: ModalWrapperProps) {\n const modalTags = useModalStore((state: State) => state.modalTags)\n \n // LUÔN render tất cả modals - KHÔNG conditional render\n // Modal components tự control hiển thị qua isOpen prop\n const allModals = useMemo(() => {\n return Object.entries(modals).map(([tag, Modal]) => {\n try {\n return <Modal key={tag} />\n } catch (error) {\n return null\n }\n })\n }, [modals]) // Chỉ phụ thuộc vào modals object, KHÔNG phụ thuộc modalTags\n \n return <React.Fragment>{allModals}</React.Fragment>\n})\n","import { useEffect, useCallback, useRef } from 'react'\nimport { TagType } from './tag'\nimport { useModalStore, useModalActions, store } from '../store'\n\nexport type Any = string | number | boolean | object | undefined | Record<string, any>\n\nexport interface DisclosureHookProps<O> {\n tag: TagType\n isOpen?: boolean\n onOpen?: () => void\n onClose?: () => void\n onToggle?: () => void\n onChange?: (isOpen: boolean) => void\n onOk?: (output?: O) => void\n onCancel?: () => void\n}\n\nexport const useDisclosure = <Input = Any, Output = Any>(\n disclosureHook: DisclosureHookProps<Output>\n) => {\n const tag = disclosureHook.tag\n \n // Use refs to store callbacks to avoid stale closures\n const disclosureHookRef = useRef(disclosureHook)\n disclosureHookRef.current = disclosureHook\n\n const inputState = useModalStore(\n (state) => state.modalTags[tag]?.input\n ) as Input\n const outputState = useModalStore(\n (state) => state.modalTags[tag]?.output\n ) as Output\n const clearDisclosureTag = useModalActions(\n (actions) => actions.clearModalTag\n )\n\n const onOpenAction = useModalActions((actions) => actions.openModal)\n const okAction = useModalActions((actions) => actions.okModal)\n const onCloseAction = useModalActions((actions) => actions.closeModal)\n const onToggleAction = useModalActions((actions) => actions.toggleModal)\n\n const updateInput = useCallback((input?: Input) => {\n // If input is a function, call it and set the result as input\n let processedInput = input\n if (processedInput && typeof processedInput == 'object' && 'preventDefault' in processedInput) {\n processedInput = undefined\n }\n onOpenAction(tag, processedInput as Any)\n }, [tag, onOpenAction])\n\n const onOpen = useCallback((input?: Input) => {\n updateInput(input)\n disclosureHookRef.current?.onOpen?.()\n }, [updateInput])\n\n const onClose = useCallback(() => {\n onCloseAction(tag)\n disclosureHookRef.current?.onClose?.()\n }, [tag, onCloseAction])\n\n const onToggle = useCallback(() => {\n onToggleAction(tag)\n disclosureHookRef.current?.onToggle?.()\n }, [tag, onToggleAction])\n\n const onOk = useCallback((output?: Output) => {\n disclosureHookRef.current?.onOk?.(output)\n okAction(tag, output as Any)\n }, [tag, okAction])\n\n const onChange = useCallback((isOpen: boolean) => {\n if (isOpen) {\n onOpen()\n } else {\n onClose()\n }\n disclosureHookRef.current?.onChange?.(isOpen)\n }, [onOpen, onClose])\n\n useEffect(() => {\n return () => {\n clearDisclosureTag(tag)\n }\n }, [tag, clearDisclosureTag])\n\n useEffect(() => {\n if (outputState) {\n onOk(outputState as Output)\n }\n }, [outputState, onOk])\n\n return {\n isOpen: !!inputState,\n input: typeof inputState === 'boolean' ? undefined : inputState,\n onOpen,\n onClose,\n onToggle,\n onOk,\n onChange,\n updateInput,\n store\n }\n}\n","import * as React from 'react'\nimport { ModalWrapper } from './provider'\n\ntype ModalComponent = React.FunctionComponent<any> | React.ComponentType<any>\n\nexport type ReactHookModalProviderProps = {\n children: React.ReactNode\n modals: Record<string, ModalComponent>\n}\n\nexport const ReactHookModalProvider = ({\n children,\n modals\n}: ReactHookModalProviderProps) => {\n return (\n <React.Fragment>\n <ModalWrapper modals={modals} />\n {children}\n </React.Fragment>\n )\n}\n\nexport * from './hook'\nexport * from './provider'\n"],"names":["store","Store","modalTags","openModal","tag","input","setState","state","_extends2","_extends","okModal","output","_extends3","closeModal","_extends4","toggleModal","_state$modalTags$tag","_extends5","clearModalTag","newModalTags","clearAllModalTags","useModalStore","stateCallback","useStore","useModalActions","actionCallback","ModalWrapper","memo","_ref","modals","allModals","useMemo","Object","entries","map","_ref2","Modal","React","key","error","Fragment","useDisclosure","disclosureHook","disclosureHookRef","useRef","current","inputState","outputState","_state$modalTags$tag2","clearDisclosureTag","actions","onOpenAction","okAction","onCloseAction","onToggleAction","updateInput","useCallback","processedInput","undefined","onOpen","_disclosureHookRef$cu","_disclosureHookRef$cu2","call","onClose","_disclosureHookRef$cu3","_disclosureHookRef$cu4","onToggle","_disclosureHookRef$cu5","_disclosureHookRef$cu6","onOk","_disclosureHookRef$cu7","_disclosureHookRef$cu8","onChange","isOpen","_disclosureHookRef$cu9","_disclosureHookRef$cu0","useEffect","ReactHookModalProvider","children"],"mappings":";;;;;;;;;;;;;;;;AAuBO,IAAMA,KAAK,GAAG,IAAIC,gBAAK,CAAQ;EACpCC,SAAS,EAAE;CACZ,CAAC;AAGF,IAAMC,SAAS,GAAG,SAAZA,SAASA,CAAIC,GAAW,EAAEC,KAAW;EACzCL,KAAK,CAACM,QAAQ,CAAC,UAACC,KAAK;IAAA,IAAAC,SAAA;IAAA,OAAM;MACzBN,SAAS,EAAAO,QAAA,KACJF,KAAK,CAACL,SAAS,GAAAM,SAAA,OAAAA,SAAA,CACjBJ,GAAG,IAAAK,QAAA,KACCF,KAAK,CAACL,SAAS,CAACE,GAAG,CAAC;QACvBC,KAAK,EAAEA,KAAK,WAALA,KAAK,GAAI;UAAIG,SAAA;KAGzB;GAAC,CAAC;AACL,CAAC;AACD,IAAME,OAAO,GAAG,SAAVA,OAAOA,CAAIN,GAAW,EAAEO,MAAY;EACxCX,KAAK,CAACM,QAAQ,CAAC,UAACC,KAAK;IAAA,IAAAK,SAAA;IAAA,OAAM;MACzBV,SAAS,EAAAO,QAAA,KACJF,KAAK,CAACL,SAAS,GAAAU,SAAA,OAAAA,SAAA,CACjBR,GAAG,IAAAK,QAAA,KACCF,KAAK,CAACL,SAAS,CAACE,GAAG,CAAC;QACvBO,MAAM,EAANA;UAAMC,SAAA;KAGX;GAAC,CAAC;AACL,CAAC;AACD,IAAMC,UAAU,GAAG,SAAbA,UAAUA,CAAIT,GAAW;EAC7BJ,KAAK,CAACM,QAAQ,CAAC,UAACC,KAAK;IAAA,IAAAO,SAAA;IAAA,OAAM;MACzBZ,SAAS,EAAAO,QAAA,KACJF,KAAK,CAACL,SA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EI,OAAO,CAAC,CAAC;EAErBa,eAAS,CAAC;IACR,OAAO;MACL3B,kBAAkB,CAAC7C,GAAG,CAAC;KACxB;GACF,EAAE,CAACA,GAAG,EAAE6C,kBAAkB,CAAC,CAAC;EAE7B2B,eAAS,CAAC;IACR,IAAI7B,WAAW,EAAE;MACfsB,IAAI,CAACtB,WAAqB,CAAC;;GAE9B,EAAE,CAACA,WAAW,EAAEsB,IAAI,CAAC,CAAC;EAEvB,OAAO;IACLI,MAAM,EAAE,CAAC,CAAC3B,UAAU;IACpBzC,KAAK,EAAE,OAAOyC,UAAU,KAAK,SAAS,GAAGY,SAAS,GAAGZ,UAAU;IAC/Da,MAAM,EAANA,MAAM;IACNI,OAAO,EAAPA,OAAO;IACPG,QAAQ,EAARA,QAAQ;IACRG,IAAI,EAAJA,IAAI;IACJG,QAAQ,EAARA,QAAQ;IACRjB,WAAW,EAAXA,WAAW;IACXvD,KAAK,EAALA;GACD;AACH,CAAC;;IC5FY6E,sBAAsB,GAAG,SAAzBA,sBAAsBA,CAAAjD,IAAA;MACjCkD,QAAQ,GAAAlD,IAAA,CAARkD,QAAQ;IACRjD,MAAM,GAAAD,IAAA,CAANC,MAAM;EAEN,OACEQ,oBAACA,cAAc,QACbA,oBAACX,YAAY;IAACG,MAAM,EAAEA;IAAU,EAC/BiD,QAAQ,CACM;AAErB,CAAC;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/store/index.ts","../src/provider/index.tsx","../src/hook/index.ts","../src/index.tsx"],"sourcesContent":["import { Store, useStore } from \"@tanstack/react-store\";\nimport { produce } from \"immer\";\n\n// You can instantiate the store outside of React components too!\n\nimport { Any } from '../hook'\n\nexport type State = {\n modalTags: {\n [tag: string]: {\n input?: Any\n output?: Any\n }\n }\n}\n\nexport type Action = {\n openModal: (tag: string, input?: Any) => void\n okModal: (tag: string, output?: Any) => void\n closeModal: (tag: string) => void\n toggleModal: (tag: string) => void\n clearModalTag: (tag: string) => void\n clearAllModalTags: () => void\n}\n\nexport const store = new Store<State>({\n modalTags: {}\n});\n\n/**\n * ⚡ Performance: Sử dụng Immer produce để tối ưu immutable updates\n * - Chỉ tạo object mới cho phần thay đổi, không copy toàn bộ modalTags\n * - O(1) thay vì O(n) khi có nhiều modals\n */\nconst openModal = (tag: string, input?: Any) => {\n store.setState(produce((draft: State) => {\n if (!draft.modalTags[tag]) {\n draft.modalTags[tag] = {}\n }\n draft.modalTags[tag].input = input ?? true\n }))\n}\n\nconst okModal = (tag: string, output?: Any) => {\n store.setState(produce((draft: State) => {\n if (!draft.modalTags[tag]) {\n draft.modalTags[tag] = {}\n }\n draft.modalTags[tag].output = output\n }))\n}\n\nconst closeModal = (tag: string) => {\n store.setState(produce((draft: State) => {\n draft.modalTags[tag] = { input: false, output: undefined }\n }))\n}\n\nconst toggleModal = (tag: string) => {\n store.setState(produce((draft: State) => {\n if (!draft.modalTags[tag]) {\n draft.modalTags[tag] = { input: true }\n } else {\n draft.modalTags[tag].input = !draft.modalTags[tag].input\n }\n }))\n}\n\nconst clearModalTag = (tag: string) => {\n store.setState(produce((draft: State) => {\n delete draft.modalTags[tag]\n }))\n}\n\nconst clearAllModalTags = () => {\n store.setState(() => ({ modalTags: {} }))\n}\n\nexport const useModalStore = <T>(\n stateCallback: (state: State) => T,\n): T => {\n return useStore(store, stateCallback)\n}\n\nexport const useModalActions = <T>(\n actionCallback: (action: Action) => T\n): T => {\n return actionCallback(\n {\n openModal,\n okModal,\n closeModal,\n toggleModal,\n clearModalTag,\n clearAllModalTags\n }\n )\n}","import React, { useMemo, memo } from 'react'\nimport { useModalStore, State } from '../store'\n\ntype ModalComponent = React.FunctionComponent<any> | React.ComponentType<any>\n\nexport interface ModalWrapperProps {\n modals: Record<string, ModalComponent>\n /**\n * Strategy for rendering modals:\n * - 'lazy': Only mount modals that have been opened at least once (default, recommended)\n * - 'eager': Mount all modals upfront (use only if you need all modals pre-mounted)\n * \n * ⚡ Performance comparison:\n * - 10 modals: Both strategies are fine\n * - 50 modals: Lazy recommended (~200ms faster initial render)\n * - 100+ modals: Lazy strongly recommended (~500ms+ faster initial render)\n * - 1000 modals: Lazy is mandatory (~10s faster initial render, ~100MB less memory)\n * \n * Trade-off: With lazy mode, first modal open has ~50-100ms delay for mounting.\n */\n renderStrategy?: 'eager' | 'lazy'\n}\n\nexport const ModalWrapper = memo(function ModalWrapper({\n modals,\n renderStrategy = 'lazy'\n}: ModalWrapperProps) {\n const modalTags = useModalStore((state: State) => state.modalTags)\n\n /**\n * ⚡ Performance optimization:\n * - Dependency array đã được chuẩn hóa để tránh behavior không mong muốn\n * - LAZY mode: Chỉ re-compute khi modalTags thay đổi (modals đã mở)\n * - EAGER mode: Chỉ re-compute khi modals registry thay đổi\n */\n const allModals = useMemo(() => {\n if (renderStrategy === 'lazy') {\n // LAZY MODE: Chỉ render modals đã được mở ít nhất 1 lần\n // ⚡ Significantly faster for apps with many modals!\n // - 50 modals: ~200ms faster initial render\n // - 100+ modals: ~500ms+ faster initial render\n // - Trade-off: First modal open has ~50-100ms delay for mounting\n return Object.keys(modalTags).map((tag) => {\n const Modal = modals[tag]\n if (!Modal) {\n console.warn(`[ModalWrapper] Modal \"${tag}\" not found in modals registry`)\n return null\n }\n\n try {\n return <Modal key={tag} />\n } catch (error) {\n console.error(`[ModalWrapper] Error rendering modal \"${tag}\":`, error)\n return null\n }\n })\n }\n\n // EAGER MODE: Render tất cả modals ngay từ đầu (backward compatible)\n // ⚠️ Warning: Với 100+ modals, có thể gây memory pressure\n // Modal components tự control hiển thị qua isOpen prop\n return Object.entries(modals).map(([tag, Modal]) => {\n try {\n return <Modal key={tag} />\n } catch (error) {\n console.error(`[ModalWrapper] Error rendering modal \"${tag}\":`, error)\n return null\n }\n })\n }, [renderStrategy, modalTags, modals])\n\n return <React.Fragment>{allModals}</React.Fragment>\n})\n","import { useEffect, useCallback, useRef, useMemo } from 'react'\nimport { TagType } from './tag'\nimport { useModalStore, useModalActions, store } from '../store'\n\nexport type Any = string | number | boolean | object | undefined | Record<string, any>\n\nexport interface DisclosureHookProps<O> {\n tag: TagType\n isOpen?: boolean\n onOpen?: () => void\n onClose?: () => void\n onToggle?: () => void\n onChange?: (isOpen: boolean) => void\n onOk?: (output?: O) => void\n onCancel?: () => void\n}\n\nexport const useDisclosure = <Input = Any, Output = Any>(\n disclosureHook: DisclosureHookProps<Output>\n) => {\n const tag = disclosureHook.tag\n\n // Use refs to store callbacks to avoid stale closures\n const disclosureHookRef = useRef(disclosureHook)\n disclosureHookRef.current = disclosureHook\n\n // ⚡ Selective Subscription: Memoize selectors để TanStack Store\n // chỉ trigger re-render khi state của MODAL NÀY thay đổi\n // Không re-render khi modal khác thay đổi state\n const inputSelector = useMemo(\n () => (state: { modalTags: Record<string, { input?: Any; output?: Any }> }) =>\n state.modalTags[tag]?.input,\n [tag]\n )\n\n const outputSelector = useMemo(\n () => (state: { modalTags: Record<string, { input?: Any; output?: Any }> }) =>\n state.modalTags[tag]?.output,\n [tag]\n )\n\n const inputState = useModalStore(inputSelector) as Input\n const outputState = useModalStore(outputSelector) as Output\n const clearDisclosureTag = useModalActions(\n (actions) => actions.clearModalTag\n )\n\n const onOpenAction = useModalActions((actions) => actions.openModal)\n const okAction = useModalActions((actions) => actions.okModal)\n const onCloseAction = useModalActions((actions) => actions.closeModal)\n const onToggleAction = useModalActions((actions) => actions.toggleModal)\n\n const updateInput = useCallback((input?: Input) => {\n // If input is a function, call it and set the result as input\n let processedInput = input\n if (processedInput && typeof processedInput == 'object' && 'preventDefault' in processedInput) {\n processedInput = undefined\n }\n onOpenAction(tag, processedInput as Any)\n }, [tag, onOpenAction])\n\n const onOpen = useCallback((input?: Input) => {\n updateInput(input)\n disclosureHookRef.current?.onOpen?.()\n }, [updateInput])\n\n const onClose = useCallback(() => {\n onCloseAction(tag)\n disclosureHookRef.current?.onClose?.()\n }, [tag, onCloseAction])\n\n const onToggle = useCallback(() => {\n onToggleAction(tag)\n disclosureHookRef.current?.onToggle?.()\n }, [tag, onToggleAction])\n\n const onOk = useCallback((output?: Output) => {\n disclosureHookRef.current?.onOk?.(output)\n okAction(tag, output as Any)\n }, [tag, okAction])\n\n const onChange = useCallback((isOpen: boolean) => {\n if (isOpen) {\n onOpen()\n } else {\n onClose()\n }\n disclosureHookRef.current?.onChange?.(isOpen)\n }, [onOpen, onClose])\n\n useEffect(() => {\n return () => {\n clearDisclosureTag(tag)\n }\n }, [tag, clearDisclosureTag])\n\n useEffect(() => {\n if (outputState) {\n // Use ref instead of direct callback to avoid infinite loop\n disclosureHookRef.current?.onOk?.(outputState as Output)\n }\n }, [outputState])\n\n return {\n isOpen: !!inputState,\n input: typeof inputState === 'boolean' ? undefined : inputState,\n onOpen,\n onClose,\n onToggle,\n onOk,\n onChange,\n updateInput,\n store\n }\n}\n","import * as React from 'react'\nimport { ModalWrapper } from './provider'\n\ntype ModalComponent = React.FunctionComponent<any> | React.ComponentType<any>\n\nexport type ReactHookModalProviderProps = {\n children: React.ReactNode\n modals: Record<string, ModalComponent>\n renderStrategy?: 'eager' | 'lazy'\n}\n\nexport const ReactHookModalProvider = ({\n children,\n modals,\n renderStrategy = 'lazy'\n}: ReactHookModalProviderProps) => {\n return (\n <React.Fragment>\n <ModalWrapper modals={modals} renderStrategy={renderStrategy} />\n {children}\n </React.Fragment>\n )\n}\n\nexport * from './hook'\nexport * from './provider'\n"],"names":["store","Store","modalTags","openModal","tag","input","setState","produce","draft","okModal","output","closeModal","undefined","toggleModal","clearModalTag","clearAllModalTags","useModalStore","stateCallback","useStore","useModalActions","actionCallback","ModalWrapper","memo","_ref","modals","_ref$renderStrategy","renderStrategy","state","allModals","useMemo","Object","keys","map","Modal","console","warn","React","key","error","entries","_ref2","Fragment","useDisclosure","disclosureHook","disclosureHookRef","useRef","current","inputSelector","_state$modalTags$tag","outputSelector","_state$modalTags$tag2","inputState","outputState","clearDisclosureTag","actions","onOpenAction","okAction","onCloseAction","onToggleAction","updateInput","useCallback","processedInput","onOpen","_disclosureHookRef$cu","_disclosureHookRef$cu2","call","onClose","_disclosureHookRef$cu3","_disclosureHookRef$cu4","onToggle","_disclosureHookRef$cu5","_disclosureHookRef$cu6","onOk","_disclosureHookRef$cu7","_disclosureHookRef$cu8","onChange","isOpen","_disclosureHookRef$cu9","_disclosureHookRef$cu0","useEffect","_disclosureHookRef$cu1","_disclosureHookRef$cu10","ReactHookModalProvider","children"],"mappings":";;;;;;;AAyBO,IAAMA,KAAK,GAAG,IAAIC,gBAAK,CAAQ;EACpCC,SAAS,EAAE;CACZ,CAAC;AAOF,IAAMC,SAAS,GAAG,SAAZA,SAASA,CAAIC,GAAW,EAAEC,KAAW;EACzCL,KAAK,CAACM,QAAQ,CAACC,aAAO,CAAC,UAACC,KAAY;IAClC,IAAI,CAACA,KAAK,CAACN,SAAS,CAACE,GAAG,CAAC,EAAE;MACzBI,KAAK,CAACN,SAAS,CAACE,GAAG,CAAC,GAAG,EAAE;;IAE3BI,KAAK,CAACN,SAAS,CAACE,GAAG,CAAC,CAACC,KAAK,GAAGA,KAAK,WAALA,KAAK,GAAI,IAAI;GAC3C,CAAC,CAAC;AACL,CAAC;AAED,IAAMI,OAAO,GAAG,SAAVA,OAAOA,CAAIL,GAAW,EAAEM,MAAY;EACxCV,KAAK,CAACM,QAAQ,CAACC,aAAO,CAAC,UAACC,KAAY;IAClC,IAAI,CAACA,KAAK,CAACN,SAAS,CAACE,GAAG,CAAC,EAAE;MACzBI,KAAK,CAACN,SAAS,CAACE,GAAG,CAAC,GAAG,EAAE;;IAE3BI,KAAK,CAACN,SAAS,CAACE,GAAG,CAAC,CAACM,MAAM,GAAGA,MAAM;GACrC,CAAC,CAAC;AACL,CAAC;AAED,IAAMC,UAAU,GAAG,SAAbA,UAAUA,CAAIP,GAAW;EAC7BJ,KAAK,CAACM,QAAQ,CAACC,aAAO,CAAC,UAACC,KAAY;IAClCA,KAAK,CAACN,SAAS,CAACE,GAAG,CAAC,GAAG;MAAEC,KAAK,EAAE,KAAK;MAAEK,MAAM,EAAEE;KAAW;GAC3D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AAM,EAANA,MAAM;IACNI,OAAO,EAAPA,OAAO;IACPG,QAAQ,EAARA,QAAQ;IACRG,IAAI,EAAJA,IAAI;IACJG,QAAQ,EAARA,QAAQ;IACRhB,WAAW,EAAXA,WAAW;IACX3D,KAAK,EAALA;GACD;AACH,CAAC;;ICvGYkF,sBAAsB,GAAG,SAAzBA,sBAAsBA,CAAA3D,IAAA;MACjC4D,QAAQ,GAAA5D,IAAA,CAAR4D,QAAQ;IACR3D,MAAM,GAAAD,IAAA,CAANC,MAAM;IAAAC,mBAAA,GAAAF,IAAA,CACNG,cAAc;IAAdA,cAAc,GAAAD,mBAAA,cAAG,MAAM,GAAAA,mBAAA;EAEvB,OACEW,oBAACA,cAAc,QACbA,oBAACf,YAAY;IAACG,MAAM,EAAEA,MAAM;IAAEE,cAAc,EAAEA;IAAkB,EAC/DyD,QAAQ,CACM;AAErB,CAAC;;;;;;"}
|
package/dist/index.modern.js
CHANGED
|
@@ -1,67 +1,49 @@
|
|
|
1
1
|
import React__default, { memo, useMemo, useRef, useCallback, useEffect, createElement, Fragment } from 'react';
|
|
2
2
|
import { Store, useStore } from '@tanstack/react-store';
|
|
3
|
-
|
|
4
|
-
function _extends() {
|
|
5
|
-
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
6
|
-
for (var e = 1; e < arguments.length; e++) {
|
|
7
|
-
var t = arguments[e];
|
|
8
|
-
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
9
|
-
}
|
|
10
|
-
return n;
|
|
11
|
-
}, _extends.apply(null, arguments);
|
|
12
|
-
}
|
|
3
|
+
import { produce } from 'immer';
|
|
13
4
|
|
|
14
5
|
var store = new Store({
|
|
15
6
|
modalTags: {}
|
|
16
7
|
});
|
|
17
8
|
var openModal = function openModal(tag, input) {
|
|
18
|
-
store.setState(function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
});
|
|
9
|
+
store.setState(produce(function (draft) {
|
|
10
|
+
if (!draft.modalTags[tag]) {
|
|
11
|
+
draft.modalTags[tag] = {};
|
|
12
|
+
}
|
|
13
|
+
draft.modalTags[tag].input = input != null ? input : true;
|
|
14
|
+
}));
|
|
26
15
|
};
|
|
27
16
|
var okModal = function okModal(tag, output) {
|
|
28
|
-
store.setState(function (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
};
|
|
35
|
-
});
|
|
17
|
+
store.setState(produce(function (draft) {
|
|
18
|
+
if (!draft.modalTags[tag]) {
|
|
19
|
+
draft.modalTags[tag] = {};
|
|
20
|
+
}
|
|
21
|
+
draft.modalTags[tag].output = output;
|
|
22
|
+
}));
|
|
36
23
|
};
|
|
37
24
|
var closeModal = function closeModal(tag) {
|
|
38
|
-
store.setState(function (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
input: false
|
|
43
|
-
}, _extends4))
|
|
25
|
+
store.setState(produce(function (draft) {
|
|
26
|
+
draft.modalTags[tag] = {
|
|
27
|
+
input: false,
|
|
28
|
+
output: undefined
|
|
44
29
|
};
|
|
45
|
-
});
|
|
30
|
+
}));
|
|
46
31
|
};
|
|
47
32
|
var toggleModal = function toggleModal(tag) {
|
|
48
|
-
store.setState(function (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
33
|
+
store.setState(produce(function (draft) {
|
|
34
|
+
if (!draft.modalTags[tag]) {
|
|
35
|
+
draft.modalTags[tag] = {
|
|
36
|
+
input: true
|
|
37
|
+
};
|
|
38
|
+
} else {
|
|
39
|
+
draft.modalTags[tag].input = !draft.modalTags[tag].input;
|
|
40
|
+
}
|
|
41
|
+
}));
|
|
56
42
|
};
|
|
57
43
|
var clearModalTag = function clearModalTag(tag) {
|
|
58
|
-
store.setState(function (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
modalTags: newModalTags
|
|
63
|
-
};
|
|
64
|
-
});
|
|
44
|
+
store.setState(produce(function (draft) {
|
|
45
|
+
delete draft.modalTags[tag];
|
|
46
|
+
}));
|
|
65
47
|
};
|
|
66
48
|
var clearAllModalTags = function clearAllModalTags() {
|
|
67
49
|
store.setState(function () {
|
|
@@ -85,11 +67,30 @@ var useModalActions = function useModalActions(actionCallback) {
|
|
|
85
67
|
};
|
|
86
68
|
|
|
87
69
|
var ModalWrapper = memo(function ModalWrapper(_ref) {
|
|
88
|
-
var modals = _ref.modals
|
|
70
|
+
var modals = _ref.modals,
|
|
71
|
+
_ref$renderStrategy = _ref.renderStrategy,
|
|
72
|
+
renderStrategy = _ref$renderStrategy === void 0 ? 'lazy' : _ref$renderStrategy;
|
|
89
73
|
var modalTags = useModalStore(function (state) {
|
|
90
74
|
return state.modalTags;
|
|
91
75
|
});
|
|
92
76
|
var allModals = useMemo(function () {
|
|
77
|
+
if (renderStrategy === 'lazy') {
|
|
78
|
+
return Object.keys(modalTags).map(function (tag) {
|
|
79
|
+
var Modal = modals[tag];
|
|
80
|
+
if (!Modal) {
|
|
81
|
+
console.warn("[ModalWrapper] Modal \"" + tag + "\" not found in modals registry");
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
return React__default.createElement(Modal, {
|
|
86
|
+
key: tag
|
|
87
|
+
});
|
|
88
|
+
} catch (error) {
|
|
89
|
+
console.error("[ModalWrapper] Error rendering modal \"" + tag + "\":", error);
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
93
94
|
return Object.entries(modals).map(function (_ref2) {
|
|
94
95
|
var tag = _ref2[0],
|
|
95
96
|
Modal = _ref2[1];
|
|
@@ -98,10 +99,11 @@ var ModalWrapper = memo(function ModalWrapper(_ref) {
|
|
|
98
99
|
key: tag
|
|
99
100
|
});
|
|
100
101
|
} catch (error) {
|
|
102
|
+
console.error("[ModalWrapper] Error rendering modal \"" + tag + "\":", error);
|
|
101
103
|
return null;
|
|
102
104
|
}
|
|
103
105
|
});
|
|
104
|
-
}, [modals]);
|
|
106
|
+
}, [renderStrategy, modalTags, modals]);
|
|
105
107
|
return React__default.createElement(React__default.Fragment, null, allModals);
|
|
106
108
|
});
|
|
107
109
|
|
|
@@ -109,14 +111,20 @@ var useDisclosure = function useDisclosure(disclosureHook) {
|
|
|
109
111
|
var tag = disclosureHook.tag;
|
|
110
112
|
var disclosureHookRef = useRef(disclosureHook);
|
|
111
113
|
disclosureHookRef.current = disclosureHook;
|
|
112
|
-
var
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
114
|
+
var inputSelector = useMemo(function () {
|
|
115
|
+
return function (state) {
|
|
116
|
+
var _state$modalTags$tag;
|
|
117
|
+
return (_state$modalTags$tag = state.modalTags[tag]) === null || _state$modalTags$tag === void 0 ? void 0 : _state$modalTags$tag.input;
|
|
118
|
+
};
|
|
119
|
+
}, [tag]);
|
|
120
|
+
var outputSelector = useMemo(function () {
|
|
121
|
+
return function (state) {
|
|
122
|
+
var _state$modalTags$tag2;
|
|
123
|
+
return (_state$modalTags$tag2 = state.modalTags[tag]) === null || _state$modalTags$tag2 === void 0 ? void 0 : _state$modalTags$tag2.output;
|
|
124
|
+
};
|
|
125
|
+
}, [tag]);
|
|
126
|
+
var inputState = useModalStore(inputSelector);
|
|
127
|
+
var outputState = useModalStore(outputSelector);
|
|
120
128
|
var clearDisclosureTag = useModalActions(function (actions) {
|
|
121
129
|
return actions.clearModalTag;
|
|
122
130
|
});
|
|
@@ -175,9 +183,10 @@ var useDisclosure = function useDisclosure(disclosureHook) {
|
|
|
175
183
|
}, [tag, clearDisclosureTag]);
|
|
176
184
|
useEffect(function () {
|
|
177
185
|
if (outputState) {
|
|
178
|
-
|
|
186
|
+
var _disclosureHookRef$cu1, _disclosureHookRef$cu10;
|
|
187
|
+
(_disclosureHookRef$cu1 = disclosureHookRef.current) === null || _disclosureHookRef$cu1 === void 0 ? void 0 : (_disclosureHookRef$cu10 = _disclosureHookRef$cu1.onOk) === null || _disclosureHookRef$cu10 === void 0 ? void 0 : _disclosureHookRef$cu10.call(_disclosureHookRef$cu1, outputState);
|
|
179
188
|
}
|
|
180
|
-
}, [outputState
|
|
189
|
+
}, [outputState]);
|
|
181
190
|
return {
|
|
182
191
|
isOpen: !!inputState,
|
|
183
192
|
input: typeof inputState === 'boolean' ? undefined : inputState,
|
|
@@ -193,9 +202,12 @@ var useDisclosure = function useDisclosure(disclosureHook) {
|
|
|
193
202
|
|
|
194
203
|
var ReactHookModalProvider = function ReactHookModalProvider(_ref) {
|
|
195
204
|
var children = _ref.children,
|
|
196
|
-
modals = _ref.modals
|
|
205
|
+
modals = _ref.modals,
|
|
206
|
+
_ref$renderStrategy = _ref.renderStrategy,
|
|
207
|
+
renderStrategy = _ref$renderStrategy === void 0 ? 'lazy' : _ref$renderStrategy;
|
|
197
208
|
return createElement(Fragment, null, createElement(ModalWrapper, {
|
|
198
|
-
modals: modals
|
|
209
|
+
modals: modals,
|
|
210
|
+
renderStrategy: renderStrategy
|
|
199
211
|
}), children);
|
|
200
212
|
};
|
|
201
213
|
|
package/dist/index.modern.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.modern.js","sources":["../src/store/index.ts","../src/provider/index.tsx","../src/hook/index.ts","../src/index.tsx"],"sourcesContent":["import { Store, useStore } from \"@tanstack/react-store\";\n\n// You can instantiate the store outside of React components too!\n\nimport { Any } from '../hook'\n\nexport type State = {\n modalTags: {\n [tag: string]: {\n input?: Any\n output?: Any\n }\n }\n}\n\nexport type Action = {\n openModal: (tag: string, input?: Any) => void\n okModal: (tag: string, output?: Any) => void\n closeModal: (tag: string) => void\n toggleModal: (tag: string) => void\n clearModalTag: (tag: string) => void\n clearAllModalTags: () => void\n}\nexport const store = new Store<State>({\n modalTags: {}\n});\n\n\nconst openModal = (tag: string, input?: Any) => {\n store.setState((state) => ({\n modalTags: {\n ...state.modalTags,\n [tag]: {\n ...state.modalTags[tag],\n input: input ?? true // Default to true if no input is provided\n }\n }\n }))\n}\nconst okModal = (tag: string, output?: Any) => {\n store.setState((state) => ({\n modalTags: {\n ...state.modalTags,\n [tag]: {\n ...state.modalTags[tag],\n output\n }\n }\n }))\n}\nconst closeModal = (tag: string) => {\n store.setState((state) => ({\n modalTags: {\n ...state.modalTags,\n [tag]: { input: false }\n }\n }))\n}\nconst toggleModal = (tag: string) => {\n store.setState((state) => ({\n modalTags: {\n ...state.modalTags,\n [tag]: {\n ...state.modalTags[tag],\n input: !state.modalTags[tag]?.input\n }\n }\n }))\n}\nconst clearModalTag = (tag: string) => {\n store.setState((state) => {\n const newModalTags = { ...state.modalTags };\n delete newModalTags[tag];\n return { modalTags: newModalTags };\n })\n}\nconst clearAllModalTags = () => {\n store.setState(() => ({ modalTags: {} }))\n}\n\nexport const useModalStore = <T>(\n stateCallback: (state: State) => T,\n): T => {\n return useStore(store, stateCallback)\n}\n\nexport const useModalActions = <T>(\n actionCallback: (action: Action) => T\n): T => {\n return actionCallback(\n {\n openModal,\n okModal,\n closeModal,\n toggleModal,\n clearModalTag,\n clearAllModalTags\n }\n )\n}","import React, { useMemo, memo } from 'react'\nimport { useModalStore, State } from '../store'\n\ntype ModalComponent = React.FunctionComponent<any> | React.ComponentType<any>\n\nexport interface ModalWrapperProps {\n modals: Record<string, ModalComponent>\n}\n\nexport const ModalWrapper = memo(function ModalWrapper({\n modals\n}: ModalWrapperProps) {\n const modalTags = useModalStore((state: State) => state.modalTags)\n \n // LUÔN render tất cả modals - KHÔNG conditional render\n // Modal components tự control hiển thị qua isOpen prop\n const allModals = useMemo(() => {\n return Object.entries(modals).map(([tag, Modal]) => {\n try {\n return <Modal key={tag} />\n } catch (error) {\n return null\n }\n })\n }, [modals]) // Chỉ phụ thuộc vào modals object, KHÔNG phụ thuộc modalTags\n \n return <React.Fragment>{allModals}</React.Fragment>\n})\n","import { useEffect, useCallback, useRef } from 'react'\nimport { TagType } from './tag'\nimport { useModalStore, useModalActions, store } from '../store'\n\nexport type Any = string | number | boolean | object | undefined | Record<string, any>\n\nexport interface DisclosureHookProps<O> {\n tag: TagType\n isOpen?: boolean\n onOpen?: () => void\n onClose?: () => void\n onToggle?: () => void\n onChange?: (isOpen: boolean) => void\n onOk?: (output?: O) => void\n onCancel?: () => void\n}\n\nexport const useDisclosure = <Input = Any, Output = Any>(\n disclosureHook: DisclosureHookProps<Output>\n) => {\n const tag = disclosureHook.tag\n \n // Use refs to store callbacks to avoid stale closures\n const disclosureHookRef = useRef(disclosureHook)\n disclosureHookRef.current = disclosureHook\n\n const inputState = useModalStore(\n (state) => state.modalTags[tag]?.input\n ) as Input\n const outputState = useModalStore(\n (state) => state.modalTags[tag]?.output\n ) as Output\n const clearDisclosureTag = useModalActions(\n (actions) => actions.clearModalTag\n )\n\n const onOpenAction = useModalActions((actions) => actions.openModal)\n const okAction = useModalActions((actions) => actions.okModal)\n const onCloseAction = useModalActions((actions) => actions.closeModal)\n const onToggleAction = useModalActions((actions) => actions.toggleModal)\n\n const updateInput = useCallback((input?: Input) => {\n // If input is a function, call it and set the result as input\n let processedInput = input\n if (processedInput && typeof processedInput == 'object' && 'preventDefault' in processedInput) {\n processedInput = undefined\n }\n onOpenAction(tag, processedInput as Any)\n }, [tag, onOpenAction])\n\n const onOpen = useCallback((input?: Input) => {\n updateInput(input)\n disclosureHookRef.current?.onOpen?.()\n }, [updateInput])\n\n const onClose = useCallback(() => {\n onCloseAction(tag)\n disclosureHookRef.current?.onClose?.()\n }, [tag, onCloseAction])\n\n const onToggle = useCallback(() => {\n onToggleAction(tag)\n disclosureHookRef.current?.onToggle?.()\n }, [tag, onToggleAction])\n\n const onOk = useCallback((output?: Output) => {\n disclosureHookRef.current?.onOk?.(output)\n okAction(tag, output as Any)\n }, [tag, okAction])\n\n const onChange = useCallback((isOpen: boolean) => {\n if (isOpen) {\n onOpen()\n } else {\n onClose()\n }\n disclosureHookRef.current?.onChange?.(isOpen)\n }, [onOpen, onClose])\n\n useEffect(() => {\n return () => {\n clearDisclosureTag(tag)\n }\n }, [tag, clearDisclosureTag])\n\n useEffect(() => {\n if (outputState) {\n onOk(outputState as Output)\n }\n }, [outputState, onOk])\n\n return {\n isOpen: !!inputState,\n input: typeof inputState === 'boolean' ? undefined : inputState,\n onOpen,\n onClose,\n onToggle,\n onOk,\n onChange,\n updateInput,\n store\n }\n}\n","import * as React from 'react'\nimport { ModalWrapper } from './provider'\n\ntype ModalComponent = React.FunctionComponent<any> | React.ComponentType<any>\n\nexport type ReactHookModalProviderProps = {\n children: React.ReactNode\n modals: Record<string, ModalComponent>\n}\n\nexport const ReactHookModalProvider = ({\n children,\n modals\n}: ReactHookModalProviderProps) => {\n return (\n <React.Fragment>\n <ModalWrapper modals={modals} />\n {children}\n </React.Fragment>\n )\n}\n\nexport * from './hook'\nexport * from './provider'\n"],"names":["store","Store","modalTags","openModal","tag","input","setState","state","_extends2","_extends","okModal","output","_extends3","closeModal","_extends4","toggleModal","_state$modalTags$tag","_extends5","clearModalTag","newModalTags","clearAllModalTags","useModalStore","stateCallback","useStore","useModalActions","actionCallback","ModalWrapper","memo","_ref","modals","allModals","useMemo","Object","entries","map","_ref2","Modal","React","key","error","Fragment","useDisclosure","disclosureHook","disclosureHookRef","useRef","current","inputState","outputState","_state$modalTags$tag2","clearDisclosureTag","actions","onOpenAction","okAction","onCloseAction","onToggleAction","updateInput","useCallback","processedInput","undefined","onOpen","_disclosureHookRef$cu","_disclosureHookRef$cu2","call","onClose","_disclosureHookRef$cu3","_disclosureHookRef$cu4","onToggle","_disclosureHookRef$cu5","_disclosureHookRef$cu6","onOk","_disclosureHookRef$cu7","_disclosureHookRef$cu8","onChange","isOpen","_disclosureHookRef$cu9","_disclosureHookRef$cu0","useEffect","ReactHookModalProvider","children"],"mappings":";;;;;;;;;;;;;AAuBO,IAAMA,KAAK,GAAG,IAAIC,K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,MAAM,EAAE,CAAC,CAAC3B,UAAU;IACpBzC,KAAK,EAAE,OAAOyC,UAAU,KAAK,SAAS,GAAGY,SAAS,GAAGZ,UAAU;IAC/Da,MAAM,EAANA,MAAM;IACNI,OAAO,EAAPA,OAAO;IACPG,QAAQ,EAARA,QAAQ;IACRG,IAAI,EAAJA,IAAI;IACJG,QAAQ,EAARA,QAAQ;IACRjB,WAAW,EAAXA,WAAW;IACXvD,KAAK,EAALA;GACD;AACH,CAAC;;IC5FY6E,sBAAsB,GAAG,SAAzBA,sBAAsBA,CAAAjD,IAAA;MACjCkD,QAAQ,GAAAlD,IAAA,CAARkD,QAAQ;IACRjD,MAAM,GAAAD,IAAA,CAANC,MAAM;EAEN,OACEQ,cAACA,QAAc,QACbA,cAACX,YAAY;IAACG,MAAM,EAAEA;IAAU,EAC/BiD,QAAQ,CACM;AAErB,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"index.modern.js","sources":["../src/store/index.ts","../src/provider/index.tsx","../src/hook/index.ts","../src/index.tsx"],"sourcesContent":["import { Store, useStore } from \"@tanstack/react-store\";\nimport { produce } from \"immer\";\n\n// You can instantiate the store outside of React components too!\n\nimport { Any } from '../hook'\n\nexport type State = {\n modalTags: {\n [tag: string]: {\n input?: Any\n output?: Any\n }\n }\n}\n\nexport type Action = {\n openModal: (tag: string, input?: Any) => void\n okModal: (tag: string, output?: Any) => void\n closeModal: (tag: string) => void\n toggleModal: (tag: string) => void\n clearModalTag: (tag: string) => void\n clearAllModalTags: () => void\n}\n\nexport const store = new Store<State>({\n modalTags: {}\n});\n\n/**\n * ⚡ Performance: Sử dụng Immer produce để tối ưu immutable updates\n * - Chỉ tạo object mới cho phần thay đổi, không copy toàn bộ modalTags\n * - O(1) thay vì O(n) khi có nhiều modals\n */\nconst openModal = (tag: string, input?: Any) => {\n store.setState(produce((draft: State) => {\n if (!draft.modalTags[tag]) {\n draft.modalTags[tag] = {}\n }\n draft.modalTags[tag].input = input ?? true\n }))\n}\n\nconst okModal = (tag: string, output?: Any) => {\n store.setState(produce((draft: State) => {\n if (!draft.modalTags[tag]) {\n draft.modalTags[tag] = {}\n }\n draft.modalTags[tag].output = output\n }))\n}\n\nconst closeModal = (tag: string) => {\n store.setState(produce((draft: State) => {\n draft.modalTags[tag] = { input: false, output: undefined }\n }))\n}\n\nconst toggleModal = (tag: string) => {\n store.setState(produce((draft: State) => {\n if (!draft.modalTags[tag]) {\n draft.modalTags[tag] = { input: true }\n } else {\n draft.modalTags[tag].input = !draft.modalTags[tag].input\n }\n }))\n}\n\nconst clearModalTag = (tag: string) => {\n store.setState(produce((draft: State) => {\n delete draft.modalTags[tag]\n }))\n}\n\nconst clearAllModalTags = () => {\n store.setState(() => ({ modalTags: {} }))\n}\n\nexport const useModalStore = <T>(\n stateCallback: (state: State) => T,\n): T => {\n return useStore(store, stateCallback)\n}\n\nexport const useModalActions = <T>(\n actionCallback: (action: Action) => T\n): T => {\n return actionCallback(\n {\n openModal,\n okModal,\n closeModal,\n toggleModal,\n clearModalTag,\n clearAllModalTags\n }\n )\n}","import React, { useMemo, memo } from 'react'\nimport { useModalStore, State } from '../store'\n\ntype ModalComponent = React.FunctionComponent<any> | React.ComponentType<any>\n\nexport interface ModalWrapperProps {\n modals: Record<string, ModalComponent>\n /**\n * Strategy for rendering modals:\n * - 'lazy': Only mount modals that have been opened at least once (default, recommended)\n * - 'eager': Mount all modals upfront (use only if you need all modals pre-mounted)\n * \n * ⚡ Performance comparison:\n * - 10 modals: Both strategies are fine\n * - 50 modals: Lazy recommended (~200ms faster initial render)\n * - 100+ modals: Lazy strongly recommended (~500ms+ faster initial render)\n * - 1000 modals: Lazy is mandatory (~10s faster initial render, ~100MB less memory)\n * \n * Trade-off: With lazy mode, first modal open has ~50-100ms delay for mounting.\n */\n renderStrategy?: 'eager' | 'lazy'\n}\n\nexport const ModalWrapper = memo(function ModalWrapper({\n modals,\n renderStrategy = 'lazy'\n}: ModalWrapperProps) {\n const modalTags = useModalStore((state: State) => state.modalTags)\n\n /**\n * ⚡ Performance optimization:\n * - Dependency array đã được chuẩn hóa để tránh behavior không mong muốn\n * - LAZY mode: Chỉ re-compute khi modalTags thay đổi (modals đã mở)\n * - EAGER mode: Chỉ re-compute khi modals registry thay đổi\n */\n const allModals = useMemo(() => {\n if (renderStrategy === 'lazy') {\n // LAZY MODE: Chỉ render modals đã được mở ít nhất 1 lần\n // ⚡ Significantly faster for apps with many modals!\n // - 50 modals: ~200ms faster initial render\n // - 100+ modals: ~500ms+ faster initial render\n // - Trade-off: First modal open has ~50-100ms delay for mounting\n return Object.keys(modalTags).map((tag) => {\n const Modal = modals[tag]\n if (!Modal) {\n console.warn(`[ModalWrapper] Modal \"${tag}\" not found in modals registry`)\n return null\n }\n\n try {\n return <Modal key={tag} />\n } catch (error) {\n console.error(`[ModalWrapper] Error rendering modal \"${tag}\":`, error)\n return null\n }\n })\n }\n\n // EAGER MODE: Render tất cả modals ngay từ đầu (backward compatible)\n // ⚠️ Warning: Với 100+ modals, có thể gây memory pressure\n // Modal components tự control hiển thị qua isOpen prop\n return Object.entries(modals).map(([tag, Modal]) => {\n try {\n return <Modal key={tag} />\n } catch (error) {\n console.error(`[ModalWrapper] Error rendering modal \"${tag}\":`, error)\n return null\n }\n })\n }, [renderStrategy, modalTags, modals])\n\n return <React.Fragment>{allModals}</React.Fragment>\n})\n","import { useEffect, useCallback, useRef, useMemo } from 'react'\nimport { TagType } from './tag'\nimport { useModalStore, useModalActions, store } from '../store'\n\nexport type Any = string | number | boolean | object | undefined | Record<string, any>\n\nexport interface DisclosureHookProps<O> {\n tag: TagType\n isOpen?: boolean\n onOpen?: () => void\n onClose?: () => void\n onToggle?: () => void\n onChange?: (isOpen: boolean) => void\n onOk?: (output?: O) => void\n onCancel?: () => void\n}\n\nexport const useDisclosure = <Input = Any, Output = Any>(\n disclosureHook: DisclosureHookProps<Output>\n) => {\n const tag = disclosureHook.tag\n\n // Use refs to store callbacks to avoid stale closures\n const disclosureHookRef = useRef(disclosureHook)\n disclosureHookRef.current = disclosureHook\n\n // ⚡ Selective Subscription: Memoize selectors để TanStack Store\n // chỉ trigger re-render khi state của MODAL NÀY thay đổi\n // Không re-render khi modal khác thay đổi state\n const inputSelector = useMemo(\n () => (state: { modalTags: Record<string, { input?: Any; output?: Any }> }) =>\n state.modalTags[tag]?.input,\n [tag]\n )\n\n const outputSelector = useMemo(\n () => (state: { modalTags: Record<string, { input?: Any; output?: Any }> }) =>\n state.modalTags[tag]?.output,\n [tag]\n )\n\n const inputState = useModalStore(inputSelector) as Input\n const outputState = useModalStore(outputSelector) as Output\n const clearDisclosureTag = useModalActions(\n (actions) => actions.clearModalTag\n )\n\n const onOpenAction = useModalActions((actions) => actions.openModal)\n const okAction = useModalActions((actions) => actions.okModal)\n const onCloseAction = useModalActions((actions) => actions.closeModal)\n const onToggleAction = useModalActions((actions) => actions.toggleModal)\n\n const updateInput = useCallback((input?: Input) => {\n // If input is a function, call it and set the result as input\n let processedInput = input\n if (processedInput && typeof processedInput == 'object' && 'preventDefault' in processedInput) {\n processedInput = undefined\n }\n onOpenAction(tag, processedInput as Any)\n }, [tag, onOpenAction])\n\n const onOpen = useCallback((input?: Input) => {\n updateInput(input)\n disclosureHookRef.current?.onOpen?.()\n }, [updateInput])\n\n const onClose = useCallback(() => {\n onCloseAction(tag)\n disclosureHookRef.current?.onClose?.()\n }, [tag, onCloseAction])\n\n const onToggle = useCallback(() => {\n onToggleAction(tag)\n disclosureHookRef.current?.onToggle?.()\n }, [tag, onToggleAction])\n\n const onOk = useCallback((output?: Output) => {\n disclosureHookRef.current?.onOk?.(output)\n okAction(tag, output as Any)\n }, [tag, okAction])\n\n const onChange = useCallback((isOpen: boolean) => {\n if (isOpen) {\n onOpen()\n } else {\n onClose()\n }\n disclosureHookRef.current?.onChange?.(isOpen)\n }, [onOpen, onClose])\n\n useEffect(() => {\n return () => {\n clearDisclosureTag(tag)\n }\n }, [tag, clearDisclosureTag])\n\n useEffect(() => {\n if (outputState) {\n // Use ref instead of direct callback to avoid infinite loop\n disclosureHookRef.current?.onOk?.(outputState as Output)\n }\n }, [outputState])\n\n return {\n isOpen: !!inputState,\n input: typeof inputState === 'boolean' ? undefined : inputState,\n onOpen,\n onClose,\n onToggle,\n onOk,\n onChange,\n updateInput,\n store\n }\n}\n","import * as React from 'react'\nimport { ModalWrapper } from './provider'\n\ntype ModalComponent = React.FunctionComponent<any> | React.ComponentType<any>\n\nexport type ReactHookModalProviderProps = {\n children: React.ReactNode\n modals: Record<string, ModalComponent>\n renderStrategy?: 'eager' | 'lazy'\n}\n\nexport const ReactHookModalProvider = ({\n children,\n modals,\n renderStrategy = 'lazy'\n}: ReactHookModalProviderProps) => {\n return (\n <React.Fragment>\n <ModalWrapper modals={modals} renderStrategy={renderStrategy} />\n {children}\n </React.Fragment>\n )\n}\n\nexport * from './hook'\nexport * from './provider'\n"],"names":["store","Store","modalTags","openModal","tag","input","setState","produce","draft","okModal","output","closeModal","undefined","toggleModal","clearModalTag","clearAllModalTags","useModalStore","stateCallback","useStore","useModalActions","actionCallback","ModalWrapper","memo","_ref","modals","_ref$renderStrategy","renderStrategy","state","allModals","useMemo","Object","keys","map","Modal","console","warn","React","key","error","entries","_ref2","Fragment","useDisclosure","disclosureHook","disclosureHookRef","useRef","current","inputSelector","_state$modalTags$tag","outputSelector","_state$modalTags$tag2","inputState","outputState","clearDisclosureTag","actions","onOpenAction","okAction","onCloseAction","onToggleAction","updateInput","useCallback","processedInput","onOpen","_disclosureHookRef$cu","_disclosureHookRef$cu2","call","onClose","_disclosureHookRef$cu3","_disclosureHookRef$cu4","onToggle","_disclosureHookRef$cu5","_disclosureHookRef$cu6","onOk","_disclosureHookRef$cu7","_disclosureHookRef$cu8","onChange","isOpen","_disclosureHookRef$cu9","_disclosureHookRef$cu0","useEffect","_disclosureHookRef$cu1","_disclosureHookRef$cu10","ReactHookModalProvider","children"],"mappings":";;;;AAyBO,IAAMA,KAAK,GAAG,IAAIC,KAAK,CAAQ;EACpCC,SAAS,EAAE;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CAANC,MAAM;IAAAC,mBAAA,GAAAF,IAAA,CACNG,cAAc;IAAdA,cAAc,GAAAD,mBAAA,cAAG,MAAM,GAAAA,mBAAA;EAEvB,OACEW,cAACA,QAAc,QACbA,cAACf,YAAY;IAACG,MAAM,EAAEA,MAAM;IAAEE,cAAc,EAAEA;IAAkB,EAC/DyD,QAAQ,CACM;AAErB,CAAC;;;;"}
|
package/dist/provider/index.d.ts
CHANGED
|
@@ -2,6 +2,20 @@ import React from 'react';
|
|
|
2
2
|
declare type ModalComponent = React.FunctionComponent<any> | React.ComponentType<any>;
|
|
3
3
|
export interface ModalWrapperProps {
|
|
4
4
|
modals: Record<string, ModalComponent>;
|
|
5
|
+
/**
|
|
6
|
+
* Strategy for rendering modals:
|
|
7
|
+
* - 'lazy': Only mount modals that have been opened at least once (default, recommended)
|
|
8
|
+
* - 'eager': Mount all modals upfront (use only if you need all modals pre-mounted)
|
|
9
|
+
*
|
|
10
|
+
* ⚡ Performance comparison:
|
|
11
|
+
* - 10 modals: Both strategies are fine
|
|
12
|
+
* - 50 modals: Lazy recommended (~200ms faster initial render)
|
|
13
|
+
* - 100+ modals: Lazy strongly recommended (~500ms+ faster initial render)
|
|
14
|
+
* - 1000 modals: Lazy is mandatory (~10s faster initial render, ~100MB less memory)
|
|
15
|
+
*
|
|
16
|
+
* Trade-off: With lazy mode, first modal open has ~50-100ms delay for mounting.
|
|
17
|
+
*/
|
|
18
|
+
renderStrategy?: 'eager' | 'lazy';
|
|
5
19
|
}
|
|
6
20
|
export declare const ModalWrapper: React.NamedExoticComponent<ModalWrapperProps>;
|
|
7
21
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/provider/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAwB,MAAM,OAAO,CAAA;AAG5C,aAAK,cAAc,GAAG,KAAK,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,CAAA;AAE7E,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/provider/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAwB,MAAM,OAAO,CAAA;AAG5C,aAAK,cAAc,GAAG,KAAK,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,CAAA;AAE7E,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IACtC;;;;;;;;;;;;OAYG;IACH,cAAc,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;CAClC;AAED,eAAO,MAAM,YAAY,+CAiDvB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/store/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAY,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/store/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAY,MAAM,uBAAuB,CAAC;AAKxD,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AAE7B,oBAAY,KAAK,GAAG;IAClB,SAAS,EAAE;QACT,CAAC,GAAG,EAAE,MAAM,GAAG;YACb,KAAK,CAAC,EAAE,GAAG,CAAA;YACX,MAAM,CAAC,EAAE,GAAG,CAAA;SACb,CAAA;KACF,CAAA;CACF,CAAA;AAED,oBAAY,MAAM,GAAG;IACnB,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG,KAAK,IAAI,CAAA;IAC7C,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,KAAK,IAAI,CAAA;IAC5C,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IACjC,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IAClC,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IACpC,iBAAiB,EAAE,MAAM,IAAI,CAAA;CAC9B,CAAA;AAED,eAAO,MAAM,KAAK,oCAEhB,CAAC;AAmDH,eAAO,MAAM,aAAa,6BACD,KAAK,YAG7B,CAAA;AAED,eAAO,MAAM,eAAe,+BACD,MAAM,YAYhC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helloworldqq/react-modal",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "React hook disclosure modal - A powerful and flexible React hook library for managing modals",
|
|
5
5
|
"author": "helloworldqq",
|
|
6
6
|
"license": "MIT",
|
|
@@ -79,7 +79,8 @@
|
|
|
79
79
|
"dist"
|
|
80
80
|
],
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"@tanstack/react-store": "^0.7.3"
|
|
82
|
+
"@tanstack/react-store": "^0.7.3",
|
|
83
|
+
"immer": "^11.1.3"
|
|
83
84
|
},
|
|
84
85
|
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
85
|
-
}
|
|
86
|
+
}
|