@helloworldqq/react-modal 1.0.3 → 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/index.d.ts CHANGED
@@ -3,13 +3,6 @@ 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
- /**
7
- * Strategy for rendering modals:
8
- * - 'eager': Mount all modals upfront (default, backward compatible)
9
- * - 'lazy': Only mount modals that have been opened at least once
10
- *
11
- * Use 'lazy' if you have 50+ modals for better performance.
12
- */
13
6
  renderStrategy?: 'eager' | 'lazy';
14
7
  };
15
8
  export declare const ReactHookModalProvider: ({ children, modals, renderStrategy }: ReactHookModalProviderProps) => React.JSX.Element;
@@ -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;IACtC;;;;;;OAMG;IACH,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"}
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,69 +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 (state) {
22
- var _extends2;
23
- return {
24
- modalTags: _extends({}, state.modalTags, (_extends2 = {}, _extends2[tag] = _extends({}, state.modalTags[tag], {
25
- input: input != null ? input : true
26
- }), _extends2))
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 (state) {
32
- var _extends3;
33
- return {
34
- modalTags: _extends({}, state.modalTags, (_extends3 = {}, _extends3[tag] = _extends({}, state.modalTags[tag], {
35
- output: output
36
- }), _extends3))
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 (state) {
42
- var _extends4;
43
- return {
44
- modalTags: _extends({}, state.modalTags, (_extends4 = {}, _extends4[tag] = {
45
- input: false,
46
- output: undefined
47
- }, _extends4))
28
+ store.setState(immer.produce(function (draft) {
29
+ draft.modalTags[tag] = {
30
+ input: false,
31
+ output: undefined
48
32
  };
49
- });
33
+ }));
50
34
  };
51
35
  var toggleModal = function toggleModal(tag) {
52
- store.setState(function (state) {
53
- var _state$modalTags$tag, _extends5;
54
- return {
55
- modalTags: _extends({}, state.modalTags, (_extends5 = {}, _extends5[tag] = _extends({}, state.modalTags[tag], {
56
- input: !((_state$modalTags$tag = state.modalTags[tag]) !== null && _state$modalTags$tag !== void 0 && _state$modalTags$tag.input)
57
- }), _extends5))
58
- };
59
- });
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
+ }));
60
45
  };
61
46
  var clearModalTag = function clearModalTag(tag) {
62
- store.setState(function (state) {
63
- var newModalTags = _extends({}, state.modalTags);
64
- delete newModalTags[tag];
65
- return {
66
- modalTags: newModalTags
67
- };
68
- });
47
+ store.setState(immer.produce(function (draft) {
48
+ delete draft.modalTags[tag];
49
+ }));
69
50
  };
70
51
  var clearAllModalTags = function clearAllModalTags() {
71
52
  store.setState(function () {
@@ -91,7 +72,7 @@ var useModalActions = function useModalActions(actionCallback) {
91
72
  var ModalWrapper = React.memo(function ModalWrapper(_ref) {
92
73
  var modals = _ref.modals,
93
74
  _ref$renderStrategy = _ref.renderStrategy,
94
- renderStrategy = _ref$renderStrategy === void 0 ? 'eager' : _ref$renderStrategy;
75
+ renderStrategy = _ref$renderStrategy === void 0 ? 'lazy' : _ref$renderStrategy;
95
76
  var modalTags = useModalStore(function (state) {
96
77
  return state.modalTags;
97
78
  });
@@ -125,7 +106,7 @@ var ModalWrapper = React.memo(function ModalWrapper(_ref) {
125
106
  return null;
126
107
  }
127
108
  });
128
- }, [renderStrategy === 'lazy' ? modalTags : modals, modals, renderStrategy]);
109
+ }, [renderStrategy, modalTags, modals]);
129
110
  return React__default.createElement(React__default.Fragment, null, allModals);
130
111
  });
131
112
 
@@ -226,7 +207,7 @@ var ReactHookModalProvider = function ReactHookModalProvider(_ref) {
226
207
  var children = _ref.children,
227
208
  modals = _ref.modals,
228
209
  _ref$renderStrategy = _ref.renderStrategy,
229
- renderStrategy = _ref$renderStrategy === void 0 ? 'eager' : _ref$renderStrategy;
210
+ renderStrategy = _ref$renderStrategy === void 0 ? 'lazy' : _ref$renderStrategy;
230
211
  return React.createElement(React.Fragment, null, React.createElement(ModalWrapper, {
231
212
  modals: modals,
232
213
  renderStrategy: renderStrategy
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, output: undefined }\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 * Strategy for rendering modals:\n * - 'eager': Mount all modals upfront (default, backward compatible)\n * - 'lazy': Only mount modals that have been opened at least once\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 = 'eager'\n}: ModalWrapperProps) {\n const modalTags = useModalStore((state: State) => state.modalTags)\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 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 // 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 === 'lazy' ? modalTags : modals, modals, renderStrategy])\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 /**\n * Strategy for rendering modals:\n * - 'eager': Mount all modals upfront (default, backward compatible)\n * - 'lazy': Only mount modals that have been opened at least once\n * \n * Use 'lazy' if you have 50+ modals for better performance.\n */\n renderStrategy?: 'eager' | 'lazy'\n}\n\nexport const ReactHookModalProvider = ({\n children,\n modals,\n renderStrategy = 'eager'\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","state","_extends2","_extends","okModal","output","_extends3","closeModal","_extends4","undefined","toggleModal","_state$modalTags$tag","_extends5","clearModalTag","newModalTags","clearAllModalTags","useModalStore","stateCallback","useStore","useModalActions","actionCallback","ModalWrapper","memo","_ref","modals","_ref$renderStrategy","renderStrategy","allModals","useMemo","Object","keys","map","Modal","console","warn","React","key","error","entries","_ref2","Fragment","useDisclosure","disclosureHook","disclosureHookRef","useRef","current","inputSelector","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":";;;;;;;;;;;;;;;;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,O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AAC;;IChGYsF,sBAAsB,GAAG,SAAzBA,sBAAsBA,CAAAzD,IAAA;MACjC0D,QAAQ,GAAA1D,IAAA,CAAR0D,QAAQ;IACRzD,MAAM,GAAAD,IAAA,CAANC,MAAM;IAAAC,mBAAA,GAAAF,IAAA,CACNG,cAAc;IAAdA,cAAc,GAAAD,mBAAA,cAAG,OAAO,GAAAA,mBAAA;EAExB,OACEU,oBAACA,cAAc,QACbA,oBAACd,YAAY;IAACG,MAAM,EAAEA,MAAM;IAAEE,cAAc,EAAEA;IAAkB,EAC/DuD,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,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EA,MAAM;IAAEE,cAAc,EAAEA;IAAkB,EAC/DyD,QAAQ,CACM;AAErB,CAAC;;;;;;"}
@@ -1,68 +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 (state) {
19
- var _extends2;
20
- return {
21
- modalTags: _extends({}, state.modalTags, (_extends2 = {}, _extends2[tag] = _extends({}, state.modalTags[tag], {
22
- input: input != null ? input : true
23
- }), _extends2))
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 (state) {
29
- var _extends3;
30
- return {
31
- modalTags: _extends({}, state.modalTags, (_extends3 = {}, _extends3[tag] = _extends({}, state.modalTags[tag], {
32
- output: output
33
- }), _extends3))
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 (state) {
39
- var _extends4;
40
- return {
41
- modalTags: _extends({}, state.modalTags, (_extends4 = {}, _extends4[tag] = {
42
- input: false,
43
- output: undefined
44
- }, _extends4))
25
+ store.setState(produce(function (draft) {
26
+ draft.modalTags[tag] = {
27
+ input: false,
28
+ output: undefined
45
29
  };
46
- });
30
+ }));
47
31
  };
48
32
  var toggleModal = function toggleModal(tag) {
49
- store.setState(function (state) {
50
- var _state$modalTags$tag, _extends5;
51
- return {
52
- modalTags: _extends({}, state.modalTags, (_extends5 = {}, _extends5[tag] = _extends({}, state.modalTags[tag], {
53
- input: !((_state$modalTags$tag = state.modalTags[tag]) !== null && _state$modalTags$tag !== void 0 && _state$modalTags$tag.input)
54
- }), _extends5))
55
- };
56
- });
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
+ }));
57
42
  };
58
43
  var clearModalTag = function clearModalTag(tag) {
59
- store.setState(function (state) {
60
- var newModalTags = _extends({}, state.modalTags);
61
- delete newModalTags[tag];
62
- return {
63
- modalTags: newModalTags
64
- };
65
- });
44
+ store.setState(produce(function (draft) {
45
+ delete draft.modalTags[tag];
46
+ }));
66
47
  };
67
48
  var clearAllModalTags = function clearAllModalTags() {
68
49
  store.setState(function () {
@@ -88,7 +69,7 @@ var useModalActions = function useModalActions(actionCallback) {
88
69
  var ModalWrapper = memo(function ModalWrapper(_ref) {
89
70
  var modals = _ref.modals,
90
71
  _ref$renderStrategy = _ref.renderStrategy,
91
- renderStrategy = _ref$renderStrategy === void 0 ? 'eager' : _ref$renderStrategy;
72
+ renderStrategy = _ref$renderStrategy === void 0 ? 'lazy' : _ref$renderStrategy;
92
73
  var modalTags = useModalStore(function (state) {
93
74
  return state.modalTags;
94
75
  });
@@ -122,7 +103,7 @@ var ModalWrapper = memo(function ModalWrapper(_ref) {
122
103
  return null;
123
104
  }
124
105
  });
125
- }, [renderStrategy === 'lazy' ? modalTags : modals, modals, renderStrategy]);
106
+ }, [renderStrategy, modalTags, modals]);
126
107
  return React__default.createElement(React__default.Fragment, null, allModals);
127
108
  });
128
109
 
@@ -223,7 +204,7 @@ var ReactHookModalProvider = function ReactHookModalProvider(_ref) {
223
204
  var children = _ref.children,
224
205
  modals = _ref.modals,
225
206
  _ref$renderStrategy = _ref.renderStrategy,
226
- renderStrategy = _ref$renderStrategy === void 0 ? 'eager' : _ref$renderStrategy;
207
+ renderStrategy = _ref$renderStrategy === void 0 ? 'lazy' : _ref$renderStrategy;
227
208
  return createElement(Fragment, null, createElement(ModalWrapper, {
228
209
  modals: modals,
229
210
  renderStrategy: renderStrategy
@@ -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, output: undefined }\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 * Strategy for rendering modals:\n * - 'eager': Mount all modals upfront (default, backward compatible)\n * - 'lazy': Only mount modals that have been opened at least once\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 = 'eager'\n}: ModalWrapperProps) {\n const modalTags = useModalStore((state: State) => state.modalTags)\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 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 // 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 === 'lazy' ? modalTags : modals, modals, renderStrategy])\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 /**\n * Strategy for rendering modals:\n * - 'eager': Mount all modals upfront (default, backward compatible)\n * - 'lazy': Only mount modals that have been opened at least once\n * \n * Use 'lazy' if you have 50+ modals for better performance.\n */\n renderStrategy?: 'eager' | 'lazy'\n}\n\nexport const ReactHookModalProvider = ({\n children,\n modals,\n renderStrategy = 'eager'\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","state","_extends2","_extends","okModal","output","_extends3","closeModal","_extends4","undefined","toggleModal","_state$modalTags$tag","_extends5","clearModalTag","newModalTags","clearAllModalTags","useModalStore","stateCallback","useStore","useModalActions","actionCallback","ModalWrapper","memo","_ref","modals","_ref$renderStrategy","renderStrategy","allModals","useMemo","Object","keys","map","Modal","console","warn","React","key","error","entries","_ref2","Fragment","useDisclosure","disclosureHook","disclosureHookRef","useRef","current","inputSelector","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":";;;;;;;;;;;;;AAuBO,IAAMA,KAAK,GAAG,IAAIC,KAAK,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,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;;"}
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;CACZ,CAAC;AAOF,IAAMC,SAAS,GAAG,SAAZA,SAASA,CAAIC,GAAW,EAAEC,KAAW;EACzCL,KAAK,CAACM,QAAQ,CAACC,OAAO,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,OAAO,CAAC,UAACC,KAAY;IAClC,IAAI,CAACA,KAAK,CAACN,SAAS,CAACE,GAAG,CAAC,E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;MAEf,CAAAD,sBAAA,GAAApC,iBAAiB,CAACE,OAAO,cAAAkC,sBAAA,wBAAAC,uBAAA,GAAzBD,sBAAA,CAA2BR,IAAI,cAAAS,uBAAA,uBAA/BA,uBAAA,CAAAhB,IAAA,CAAAe,sBAAA,EAAkC5B,WAAqB,CAAC;;GAE3D,EAAE,CAACA,WAAW,CAAC,CAAC;EAEjB,OAAO;IACLwB,MAAM,EAAE,CAAC,CAACzB,UAAU;IACpB9C,KAAK,EAAE,OAAO8C,UAAU,KAAK,SAAS,GAAGvC,SAAS,GAAGuC,UAAU;IAC/DW,MAAM,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,cAACA,QAAc,QACbA,cAACf,YAAY;IAACG,MAAM,EAAEA,MAAM;IAAEE,cAAc,EAAEA;IAAkB,EAC/DyD,QAAQ,CACM;AAErB,CAAC;;;;"}
@@ -4,10 +4,10 @@ export interface ModalWrapperProps {
4
4
  modals: Record<string, ModalComponent>;
5
5
  /**
6
6
  * Strategy for rendering modals:
7
- * - 'eager': Mount all modals upfront (default, backward compatible)
8
- * - 'lazy': Only mount modals that have been opened at least once
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
9
  *
10
- * Performance comparison:
10
+ * Performance comparison:
11
11
  * - 10 modals: Both strategies are fine
12
12
  * - 50 modals: Lazy recommended (~200ms faster initial render)
13
13
  * - 100+ modals: Lazy strongly recommended (~500ms+ faster initial render)
@@ -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;IACtC;;;;;;;;;;;;OAYG;IACH,cAAc,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;CAClC;AAED,eAAO,MAAM,YAAY,+CAuCvB,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;AAIxD,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AAE7B,oBAAY,KAAK,GAAG;IAClB,SAAS,EAAE;QACT,CAAC,GAAG,EAAE,MAAM,GAAG;YACb,KAAK,CAAC,EAA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,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",
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
+ }