@ehfuse/forma 1.4.6 → 1.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/contexts/GlobalFormaContext.d.ts.map +1 -1
- package/dist/contexts/GlobalFormaContext.js +122 -1
- package/dist/contexts/GlobalFormaContext.js.map +1 -1
- package/dist/esm/contexts/GlobalFormaContext.d.ts.map +1 -1
- package/dist/esm/contexts/GlobalFormaContext.js +122 -1
- package/dist/esm/contexts/GlobalFormaContext.js.map +1 -1
- package/dist/esm/hooks/useFormaState.d.ts.map +1 -1
- package/dist/esm/hooks/useFormaState.js +26 -12
- package/dist/esm/hooks/useFormaState.js.map +1 -1
- package/dist/esm/hooks/useGlobalForm.d.ts +1 -1
- package/dist/esm/hooks/useGlobalForm.d.ts.map +1 -1
- package/dist/esm/hooks/useGlobalForm.js +50 -5
- package/dist/esm/hooks/useGlobalForm.js.map +1 -1
- package/dist/esm/hooks/useGlobalFormaState.d.ts +1 -1
- package/dist/esm/hooks/useGlobalFormaState.d.ts.map +1 -1
- package/dist/esm/hooks/useGlobalFormaState.js +60 -5
- package/dist/esm/hooks/useGlobalFormaState.js.map +1 -1
- package/dist/esm/types/globalForm.d.ts +10 -0
- package/dist/esm/types/globalForm.d.ts.map +1 -1
- package/dist/esm/types/globalForm.js.map +1 -1
- package/dist/hooks/useFormaState.d.ts.map +1 -1
- package/dist/hooks/useFormaState.js +25 -11
- package/dist/hooks/useFormaState.js.map +1 -1
- package/dist/hooks/useGlobalForm.d.ts +1 -1
- package/dist/hooks/useGlobalForm.d.ts.map +1 -1
- package/dist/hooks/useGlobalForm.js +49 -4
- package/dist/hooks/useGlobalForm.js.map +1 -1
- package/dist/hooks/useGlobalFormaState.d.ts +1 -1
- package/dist/hooks/useGlobalFormaState.d.ts.map +1 -1
- package/dist/hooks/useGlobalFormaState.js +59 -4
- package/dist/hooks/useGlobalFormaState.js.map +1 -1
- package/dist/types/globalForm.d.ts +10 -0
- package/dist/types/globalForm.d.ts.map +1 -1
- package/dist/types/globalForm.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GlobalFormaContext.d.ts","sourceRoot":"","sources":["../../contexts/GlobalFormaContext.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAyB,SAAS,EAAE,MAAM,OAAO,CAAC;AAEzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D;;GAEG;AACH,eAAO,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"GlobalFormaContext.d.ts","sourceRoot":"","sources":["../../contexts/GlobalFormaContext.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAyB,SAAS,EAAE,MAAM,OAAO,CAAC;AAEzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D;;GAEG;AACH,eAAO,MAAM,kBAAkB,iDAoC7B,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,2CAiNxE"}
|
|
@@ -49,6 +49,15 @@ exports.GlobalFormaContext = (0, react_1.createContext)({
|
|
|
49
49
|
clearStores: () => {
|
|
50
50
|
throw new Error("GlobalFormaContext must be used within GlobalFormaProvider");
|
|
51
51
|
},
|
|
52
|
+
incrementRef: () => {
|
|
53
|
+
throw new Error("GlobalFormaContext must be used within GlobalFormaProvider");
|
|
54
|
+
},
|
|
55
|
+
decrementRef: () => {
|
|
56
|
+
throw new Error("GlobalFormaContext must be used within GlobalFormaProvider");
|
|
57
|
+
},
|
|
58
|
+
validateAndStoreAutoCleanupSetting: () => {
|
|
59
|
+
throw new Error("GlobalFormaContext must be used within GlobalFormaProvider");
|
|
60
|
+
},
|
|
52
61
|
});
|
|
53
62
|
/**
|
|
54
63
|
* 글로벌 Forma 상태 관리 Provider | Global Forma state management provider
|
|
@@ -81,6 +90,12 @@ exports.GlobalFormaContext = (0, react_1.createContext)({
|
|
|
81
90
|
function GlobalFormaProvider({ children }) {
|
|
82
91
|
// formId별 FieldStore 인스턴스들을 관리하는 Map | Map managing FieldStore instances by formId
|
|
83
92
|
const storesRef = (0, react_1.useRef)(new Map());
|
|
93
|
+
// formId별 참조 카운트를 관리하는 Map | Map managing reference count by formId
|
|
94
|
+
const refCountsRef = (0, react_1.useRef)(new Map());
|
|
95
|
+
// formId별 autoCleanup 컴포넌트 참조 카운트를 관리하는 Map | Map managing autoCleanup component reference count by formId
|
|
96
|
+
const autoCleanupRefCountsRef = (0, react_1.useRef)(new Map());
|
|
97
|
+
// formId별 autoCleanup 설정을 추적하는 Map | Map tracking autoCleanup settings by formId
|
|
98
|
+
const autoCleanupSettingsRef = (0, react_1.useRef)(new Map());
|
|
84
99
|
/**
|
|
85
100
|
* formId에 해당하는 FieldStore를 가져오거나 새로 생성합니다. | Get or create FieldStore for the given formId.
|
|
86
101
|
*
|
|
@@ -97,6 +112,22 @@ function GlobalFormaProvider({ children }) {
|
|
|
97
112
|
}
|
|
98
113
|
return stores.get(formId);
|
|
99
114
|
};
|
|
115
|
+
/**
|
|
116
|
+
* autoCleanup 설정의 일관성을 검증하고 설정을 저장합니다. | Validate and store autoCleanup setting consistency.
|
|
117
|
+
*
|
|
118
|
+
* @param formId 폼 식별자 | Form identifier
|
|
119
|
+
* @param autoCleanup 현재 autoCleanup 설정 | Current autoCleanup setting
|
|
120
|
+
*/
|
|
121
|
+
const validateAndStoreAutoCleanupSetting = (formId, autoCleanup) => {
|
|
122
|
+
const autoCleanupSettings = autoCleanupSettingsRef.current;
|
|
123
|
+
const existingSetting = autoCleanupSettings.get(formId);
|
|
124
|
+
if (existingSetting !== undefined && existingSetting !== autoCleanup) {
|
|
125
|
+
console.warn(`⚠️ Conflicting autoCleanup settings for stateId "${formId}": ` +
|
|
126
|
+
`existing=${existingSetting}, new=${autoCleanup}. ` +
|
|
127
|
+
`All components using the same stateId should have consistent autoCleanup settings.`);
|
|
128
|
+
}
|
|
129
|
+
autoCleanupSettings.set(formId, autoCleanup);
|
|
130
|
+
};
|
|
100
131
|
/**
|
|
101
132
|
* 기존 FieldStore를 글로벌 폼에 등록합니다. | Register existing FieldStore to global form.
|
|
102
133
|
*
|
|
@@ -109,13 +140,27 @@ function GlobalFormaProvider({ children }) {
|
|
|
109
140
|
};
|
|
110
141
|
/**
|
|
111
142
|
* 글로벌 스토어에서 특정 formId의 FieldStore를 제거합니다. | Remove specific FieldStore from global store.
|
|
143
|
+
* 참조 카운트를 무시하고 강제로 제거합니다. | Force remove ignoring reference count.
|
|
112
144
|
*
|
|
113
145
|
* @param formId 제거할 폼 식별자 | Form identifier to remove
|
|
114
146
|
* @returns 제거 성공 여부 | Whether removal was successful
|
|
115
147
|
*/
|
|
116
148
|
const unregisterStore = (formId) => {
|
|
117
149
|
const stores = storesRef.current;
|
|
118
|
-
|
|
150
|
+
const refCounts = refCountsRef.current;
|
|
151
|
+
const autoCleanupRefCounts = autoCleanupRefCountsRef.current;
|
|
152
|
+
const autoCleanupSettings = autoCleanupSettingsRef.current;
|
|
153
|
+
const store = stores.get(formId);
|
|
154
|
+
// 스토어가 존재하면 리소스 정리 후 제거 | Clean up resources before removal if store exists
|
|
155
|
+
if (store) {
|
|
156
|
+
store.destroy();
|
|
157
|
+
stores.delete(formId);
|
|
158
|
+
refCounts.delete(formId); // 참조 카운트도 함께 제거 | Remove reference count as well
|
|
159
|
+
autoCleanupRefCounts.delete(formId); // autoCleanup 참조 카운트도 제거 | Remove autoCleanup reference count as well
|
|
160
|
+
autoCleanupSettings.delete(formId); // autoCleanup 설정도 제거 | Remove autoCleanup settings as well
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
return false;
|
|
119
164
|
};
|
|
120
165
|
/**
|
|
121
166
|
* 모든 글로벌 스토어를 제거합니다. | Clear all global stores.
|
|
@@ -123,13 +168,89 @@ function GlobalFormaProvider({ children }) {
|
|
|
123
168
|
*/
|
|
124
169
|
const clearStores = () => {
|
|
125
170
|
const stores = storesRef.current;
|
|
171
|
+
const refCounts = refCountsRef.current;
|
|
172
|
+
const autoCleanupRefCounts = autoCleanupRefCountsRef.current;
|
|
173
|
+
const autoCleanupSettings = autoCleanupSettingsRef.current;
|
|
174
|
+
// 모든 스토어의 리소스 정리 후 제거 | Clean up all store resources before clearing
|
|
175
|
+
stores.forEach((store) => {
|
|
176
|
+
store.destroy();
|
|
177
|
+
});
|
|
126
178
|
stores.clear();
|
|
179
|
+
refCounts.clear();
|
|
180
|
+
autoCleanupRefCounts.clear();
|
|
181
|
+
autoCleanupSettings.clear();
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* 스토어 사용 참조를 증가시킵니다 | Increment store usage reference
|
|
185
|
+
*
|
|
186
|
+
* @param formId 폼 식별자 | Form identifier
|
|
187
|
+
* @param autoCleanup autoCleanup 설정 | autoCleanup setting
|
|
188
|
+
*/
|
|
189
|
+
const incrementRef = (formId, autoCleanup) => {
|
|
190
|
+
const refCounts = refCountsRef.current;
|
|
191
|
+
const autoCleanupRefCounts = autoCleanupRefCountsRef.current;
|
|
192
|
+
// 전체 참조 카운트 증가 (모든 컴포넌트)
|
|
193
|
+
const currentCount = refCounts.get(formId) || 0;
|
|
194
|
+
const newCount = currentCount + 1;
|
|
195
|
+
refCounts.set(formId, newCount);
|
|
196
|
+
// autoCleanup 참조 카운트 증가 (autoCleanup: true인 컴포넌트만)
|
|
197
|
+
if (autoCleanup) {
|
|
198
|
+
const currentAutoCleanupCount = autoCleanupRefCounts.get(formId) || 0;
|
|
199
|
+
const newAutoCleanupCount = currentAutoCleanupCount + 1;
|
|
200
|
+
autoCleanupRefCounts.set(formId, newAutoCleanupCount);
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* 스토어 사용 참조를 감소시키고, autoCleanup 참조가 0이 되면 자동 정리합니다 | Decrement store usage reference and auto cleanup when autoCleanup refs reach 0
|
|
205
|
+
*
|
|
206
|
+
* @param formId 폼 식별자 | Form identifier
|
|
207
|
+
* @param autoCleanup autoCleanup 설정 | autoCleanup setting
|
|
208
|
+
*/
|
|
209
|
+
const decrementRef = (formId, autoCleanup) => {
|
|
210
|
+
const refCounts = refCountsRef.current;
|
|
211
|
+
const autoCleanupRefCounts = autoCleanupRefCountsRef.current;
|
|
212
|
+
const stores = storesRef.current;
|
|
213
|
+
// 전체 참조 카운트가 없는 경우 (이미 수동으로 제거됨) 무시 | Ignore if no reference count (already manually removed)
|
|
214
|
+
if (!refCounts.has(formId)) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const currentCount = refCounts.get(formId) || 0;
|
|
218
|
+
const currentAutoCleanupCount = autoCleanupRefCounts.get(formId) || 0;
|
|
219
|
+
// 전체 참조 카운트 감소
|
|
220
|
+
const newCount = Math.max(0, currentCount - 1);
|
|
221
|
+
refCounts.set(formId, newCount);
|
|
222
|
+
if (autoCleanup) {
|
|
223
|
+
// autoCleanup 참조 카운트 감소
|
|
224
|
+
const newAutoCleanupCount = Math.max(0, currentAutoCleanupCount - 1);
|
|
225
|
+
autoCleanupRefCounts.set(formId, newAutoCleanupCount);
|
|
226
|
+
// autoCleanup 참조가 0이 되면 스토어 정리 (autoCleanup: false 컴포넌트가 있어도)
|
|
227
|
+
if (newAutoCleanupCount === 0) {
|
|
228
|
+
const store = stores.get(formId);
|
|
229
|
+
if (store) {
|
|
230
|
+
store.destroy();
|
|
231
|
+
stores.delete(formId);
|
|
232
|
+
refCounts.delete(formId);
|
|
233
|
+
autoCleanupRefCounts.delete(formId);
|
|
234
|
+
autoCleanupSettingsRef.current.delete(formId);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
// 전체 참조가 0이 되면 카운트 정리 (스토어는 이미 정리되었거나 영구 참조만 남음)
|
|
239
|
+
if (newCount === 0) {
|
|
240
|
+
refCounts.delete(formId);
|
|
241
|
+
if (autoCleanupRefCounts.get(formId) === 0) {
|
|
242
|
+
autoCleanupRefCounts.delete(formId);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
127
245
|
};
|
|
128
246
|
const contextValue = {
|
|
129
247
|
getOrCreateStore,
|
|
130
248
|
registerStore,
|
|
131
249
|
unregisterStore,
|
|
132
250
|
clearStores,
|
|
251
|
+
incrementRef,
|
|
252
|
+
decrementRef,
|
|
253
|
+
validateAndStoreAutoCleanupSetting,
|
|
133
254
|
};
|
|
134
255
|
return ((0, jsx_runtime_1.jsx)(exports.GlobalFormaContext.Provider, { value: contextValue, children: children }));
|
|
135
256
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GlobalFormaContext.js","sourceRoot":"","sources":["../../contexts/GlobalFormaContext.tsx"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"GlobalFormaContext.js","sourceRoot":"","sources":["../../contexts/GlobalFormaContext.tsx"],"names":[],"mappings":";;;AAsGA,kDAiNC;;AAvTD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,iCAAyD;AACzD,mDAAgD;AAGhD;;GAEG;AACU,QAAA,kBAAkB,GAAG,IAAA,qBAAa,EAAyB;IACpE,gBAAgB,EAAE,GAAG,EAAE;QACnB,MAAM,IAAI,KAAK,CACX,4DAA4D,CAC/D,CAAC;IACN,CAAC;IACD,aAAa,EAAE,GAAG,EAAE;QAChB,MAAM,IAAI,KAAK,CACX,4DAA4D,CAC/D,CAAC;IACN,CAAC;IACD,eAAe,EAAE,GAAG,EAAE;QAClB,MAAM,IAAI,KAAK,CACX,4DAA4D,CAC/D,CAAC;IACN,CAAC;IACD,WAAW,EAAE,GAAG,EAAE;QACd,MAAM,IAAI,KAAK,CACX,4DAA4D,CAC/D,CAAC;IACN,CAAC;IACD,YAAY,EAAE,GAAG,EAAE;QACf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B,oBAAoB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;oBACpC,sBAAsB,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAClD,CAAC;YACL,CAAC;QACL,CAAC;QAED,iDAAiD;QACjD,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;YACjB,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACzB,IAAI,oBAAoB,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;gBACzC,oBAAoB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACxC,CAAC;QACL,CAAC;IACL,CAAC,CAAC;IAEF,MAAM,YAAY,GAA2B;QACzC,gBAAgB;QAChB,aAAa;QACb,eAAe;QACf,WAAW;QACX,YAAY;QACZ,YAAY;QACZ,kCAAkC;KACrC,CAAC;IAEF,OAAO,CACH,uBAAC,0BAAkB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,YAC3C,QAAQ,GACiB,CACjC,CAAC;AACN,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GlobalFormaContext.d.ts","sourceRoot":"","sources":["../../../contexts/GlobalFormaContext.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAyB,SAAS,EAAE,MAAM,OAAO,CAAC;AAEzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D;;GAEG;AACH,eAAO,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"GlobalFormaContext.d.ts","sourceRoot":"","sources":["../../../contexts/GlobalFormaContext.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAyB,SAAS,EAAE,MAAM,OAAO,CAAC;AAEzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D;;GAEG;AACH,eAAO,MAAM,kBAAkB,iDAoC7B,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,2CAiNxE"}
|
|
@@ -45,6 +45,15 @@ export const GlobalFormaContext = createContext({
|
|
|
45
45
|
clearStores: () => {
|
|
46
46
|
throw new Error("GlobalFormaContext must be used within GlobalFormaProvider");
|
|
47
47
|
},
|
|
48
|
+
incrementRef: () => {
|
|
49
|
+
throw new Error("GlobalFormaContext must be used within GlobalFormaProvider");
|
|
50
|
+
},
|
|
51
|
+
decrementRef: () => {
|
|
52
|
+
throw new Error("GlobalFormaContext must be used within GlobalFormaProvider");
|
|
53
|
+
},
|
|
54
|
+
validateAndStoreAutoCleanupSetting: () => {
|
|
55
|
+
throw new Error("GlobalFormaContext must be used within GlobalFormaProvider");
|
|
56
|
+
},
|
|
48
57
|
});
|
|
49
58
|
/**
|
|
50
59
|
* 글로벌 Forma 상태 관리 Provider | Global Forma state management provider
|
|
@@ -77,6 +86,12 @@ export const GlobalFormaContext = createContext({
|
|
|
77
86
|
export function GlobalFormaProvider({ children }) {
|
|
78
87
|
// formId별 FieldStore 인스턴스들을 관리하는 Map | Map managing FieldStore instances by formId
|
|
79
88
|
const storesRef = useRef(new Map());
|
|
89
|
+
// formId별 참조 카운트를 관리하는 Map | Map managing reference count by formId
|
|
90
|
+
const refCountsRef = useRef(new Map());
|
|
91
|
+
// formId별 autoCleanup 컴포넌트 참조 카운트를 관리하는 Map | Map managing autoCleanup component reference count by formId
|
|
92
|
+
const autoCleanupRefCountsRef = useRef(new Map());
|
|
93
|
+
// formId별 autoCleanup 설정을 추적하는 Map | Map tracking autoCleanup settings by formId
|
|
94
|
+
const autoCleanupSettingsRef = useRef(new Map());
|
|
80
95
|
/**
|
|
81
96
|
* formId에 해당하는 FieldStore를 가져오거나 새로 생성합니다. | Get or create FieldStore for the given formId.
|
|
82
97
|
*
|
|
@@ -93,6 +108,22 @@ export function GlobalFormaProvider({ children }) {
|
|
|
93
108
|
}
|
|
94
109
|
return stores.get(formId);
|
|
95
110
|
};
|
|
111
|
+
/**
|
|
112
|
+
* autoCleanup 설정의 일관성을 검증하고 설정을 저장합니다. | Validate and store autoCleanup setting consistency.
|
|
113
|
+
*
|
|
114
|
+
* @param formId 폼 식별자 | Form identifier
|
|
115
|
+
* @param autoCleanup 현재 autoCleanup 설정 | Current autoCleanup setting
|
|
116
|
+
*/
|
|
117
|
+
const validateAndStoreAutoCleanupSetting = (formId, autoCleanup) => {
|
|
118
|
+
const autoCleanupSettings = autoCleanupSettingsRef.current;
|
|
119
|
+
const existingSetting = autoCleanupSettings.get(formId);
|
|
120
|
+
if (existingSetting !== undefined && existingSetting !== autoCleanup) {
|
|
121
|
+
console.warn(`⚠️ Conflicting autoCleanup settings for stateId "${formId}": ` +
|
|
122
|
+
`existing=${existingSetting}, new=${autoCleanup}. ` +
|
|
123
|
+
`All components using the same stateId should have consistent autoCleanup settings.`);
|
|
124
|
+
}
|
|
125
|
+
autoCleanupSettings.set(formId, autoCleanup);
|
|
126
|
+
};
|
|
96
127
|
/**
|
|
97
128
|
* 기존 FieldStore를 글로벌 폼에 등록합니다. | Register existing FieldStore to global form.
|
|
98
129
|
*
|
|
@@ -105,13 +136,27 @@ export function GlobalFormaProvider({ children }) {
|
|
|
105
136
|
};
|
|
106
137
|
/**
|
|
107
138
|
* 글로벌 스토어에서 특정 formId의 FieldStore를 제거합니다. | Remove specific FieldStore from global store.
|
|
139
|
+
* 참조 카운트를 무시하고 강제로 제거합니다. | Force remove ignoring reference count.
|
|
108
140
|
*
|
|
109
141
|
* @param formId 제거할 폼 식별자 | Form identifier to remove
|
|
110
142
|
* @returns 제거 성공 여부 | Whether removal was successful
|
|
111
143
|
*/
|
|
112
144
|
const unregisterStore = (formId) => {
|
|
113
145
|
const stores = storesRef.current;
|
|
114
|
-
|
|
146
|
+
const refCounts = refCountsRef.current;
|
|
147
|
+
const autoCleanupRefCounts = autoCleanupRefCountsRef.current;
|
|
148
|
+
const autoCleanupSettings = autoCleanupSettingsRef.current;
|
|
149
|
+
const store = stores.get(formId);
|
|
150
|
+
// 스토어가 존재하면 리소스 정리 후 제거 | Clean up resources before removal if store exists
|
|
151
|
+
if (store) {
|
|
152
|
+
store.destroy();
|
|
153
|
+
stores.delete(formId);
|
|
154
|
+
refCounts.delete(formId); // 참조 카운트도 함께 제거 | Remove reference count as well
|
|
155
|
+
autoCleanupRefCounts.delete(formId); // autoCleanup 참조 카운트도 제거 | Remove autoCleanup reference count as well
|
|
156
|
+
autoCleanupSettings.delete(formId); // autoCleanup 설정도 제거 | Remove autoCleanup settings as well
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
return false;
|
|
115
160
|
};
|
|
116
161
|
/**
|
|
117
162
|
* 모든 글로벌 스토어를 제거합니다. | Clear all global stores.
|
|
@@ -119,13 +164,89 @@ export function GlobalFormaProvider({ children }) {
|
|
|
119
164
|
*/
|
|
120
165
|
const clearStores = () => {
|
|
121
166
|
const stores = storesRef.current;
|
|
167
|
+
const refCounts = refCountsRef.current;
|
|
168
|
+
const autoCleanupRefCounts = autoCleanupRefCountsRef.current;
|
|
169
|
+
const autoCleanupSettings = autoCleanupSettingsRef.current;
|
|
170
|
+
// 모든 스토어의 리소스 정리 후 제거 | Clean up all store resources before clearing
|
|
171
|
+
stores.forEach((store) => {
|
|
172
|
+
store.destroy();
|
|
173
|
+
});
|
|
122
174
|
stores.clear();
|
|
175
|
+
refCounts.clear();
|
|
176
|
+
autoCleanupRefCounts.clear();
|
|
177
|
+
autoCleanupSettings.clear();
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* 스토어 사용 참조를 증가시킵니다 | Increment store usage reference
|
|
181
|
+
*
|
|
182
|
+
* @param formId 폼 식별자 | Form identifier
|
|
183
|
+
* @param autoCleanup autoCleanup 설정 | autoCleanup setting
|
|
184
|
+
*/
|
|
185
|
+
const incrementRef = (formId, autoCleanup) => {
|
|
186
|
+
const refCounts = refCountsRef.current;
|
|
187
|
+
const autoCleanupRefCounts = autoCleanupRefCountsRef.current;
|
|
188
|
+
// 전체 참조 카운트 증가 (모든 컴포넌트)
|
|
189
|
+
const currentCount = refCounts.get(formId) || 0;
|
|
190
|
+
const newCount = currentCount + 1;
|
|
191
|
+
refCounts.set(formId, newCount);
|
|
192
|
+
// autoCleanup 참조 카운트 증가 (autoCleanup: true인 컴포넌트만)
|
|
193
|
+
if (autoCleanup) {
|
|
194
|
+
const currentAutoCleanupCount = autoCleanupRefCounts.get(formId) || 0;
|
|
195
|
+
const newAutoCleanupCount = currentAutoCleanupCount + 1;
|
|
196
|
+
autoCleanupRefCounts.set(formId, newAutoCleanupCount);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* 스토어 사용 참조를 감소시키고, autoCleanup 참조가 0이 되면 자동 정리합니다 | Decrement store usage reference and auto cleanup when autoCleanup refs reach 0
|
|
201
|
+
*
|
|
202
|
+
* @param formId 폼 식별자 | Form identifier
|
|
203
|
+
* @param autoCleanup autoCleanup 설정 | autoCleanup setting
|
|
204
|
+
*/
|
|
205
|
+
const decrementRef = (formId, autoCleanup) => {
|
|
206
|
+
const refCounts = refCountsRef.current;
|
|
207
|
+
const autoCleanupRefCounts = autoCleanupRefCountsRef.current;
|
|
208
|
+
const stores = storesRef.current;
|
|
209
|
+
// 전체 참조 카운트가 없는 경우 (이미 수동으로 제거됨) 무시 | Ignore if no reference count (already manually removed)
|
|
210
|
+
if (!refCounts.has(formId)) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const currentCount = refCounts.get(formId) || 0;
|
|
214
|
+
const currentAutoCleanupCount = autoCleanupRefCounts.get(formId) || 0;
|
|
215
|
+
// 전체 참조 카운트 감소
|
|
216
|
+
const newCount = Math.max(0, currentCount - 1);
|
|
217
|
+
refCounts.set(formId, newCount);
|
|
218
|
+
if (autoCleanup) {
|
|
219
|
+
// autoCleanup 참조 카운트 감소
|
|
220
|
+
const newAutoCleanupCount = Math.max(0, currentAutoCleanupCount - 1);
|
|
221
|
+
autoCleanupRefCounts.set(formId, newAutoCleanupCount);
|
|
222
|
+
// autoCleanup 참조가 0이 되면 스토어 정리 (autoCleanup: false 컴포넌트가 있어도)
|
|
223
|
+
if (newAutoCleanupCount === 0) {
|
|
224
|
+
const store = stores.get(formId);
|
|
225
|
+
if (store) {
|
|
226
|
+
store.destroy();
|
|
227
|
+
stores.delete(formId);
|
|
228
|
+
refCounts.delete(formId);
|
|
229
|
+
autoCleanupRefCounts.delete(formId);
|
|
230
|
+
autoCleanupSettingsRef.current.delete(formId);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
// 전체 참조가 0이 되면 카운트 정리 (스토어는 이미 정리되었거나 영구 참조만 남음)
|
|
235
|
+
if (newCount === 0) {
|
|
236
|
+
refCounts.delete(formId);
|
|
237
|
+
if (autoCleanupRefCounts.get(formId) === 0) {
|
|
238
|
+
autoCleanupRefCounts.delete(formId);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
123
241
|
};
|
|
124
242
|
const contextValue = {
|
|
125
243
|
getOrCreateStore,
|
|
126
244
|
registerStore,
|
|
127
245
|
unregisterStore,
|
|
128
246
|
clearStores,
|
|
247
|
+
incrementRef,
|
|
248
|
+
decrementRef,
|
|
249
|
+
validateAndStoreAutoCleanupSetting,
|
|
129
250
|
};
|
|
130
251
|
return (_jsx(GlobalFormaContext.Provider, { value: contextValue, children: children }));
|
|
131
252
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GlobalFormaContext.js","sourceRoot":"","sources":["../../../contexts/GlobalFormaContext.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,EAAa,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAAyB;IACpE,gBAAgB,EAAE,GAAG,EAAE;QACnB,MAAM,IAAI,KAAK,CACX,4DAA4D,CAC/D,CAAC;IACN,CAAC;IACD,aAAa,EAAE,GAAG,EAAE;QAChB,MAAM,IAAI,KAAK,CACX,4DAA4D,CAC/D,CAAC;IACN,CAAC;IACD,eAAe,EAAE,GAAG,EAAE;QAClB,MAAM,IAAI,KAAK,CACX,4DAA4D,CAC/D,CAAC;IACN,CAAC;IACD,WAAW,EAAE,GAAG,EAAE;QACd,MAAM,IAAI,KAAK,CACX,4DAA4D,CAC/D,CAAC;IACN,CAAC;CACJ,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAAE,QAAQ,EAA2B;IACrE,mFAAmF;IACnF,MAAM,SAAS,GAAG,MAAM,CAA+B,IAAI,GAAG,EAAE,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"GlobalFormaContext.js","sourceRoot":"","sources":["../../../contexts/GlobalFormaContext.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,EAAa,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAAyB;IACpE,gBAAgB,EAAE,GAAG,EAAE;QACnB,MAAM,IAAI,KAAK,CACX,4DAA4D,CAC/D,CAAC;IACN,CAAC;IACD,aAAa,EAAE,GAAG,EAAE;QAChB,MAAM,IAAI,KAAK,CACX,4DAA4D,CAC/D,CAAC;IACN,CAAC;IACD,eAAe,EAAE,GAAG,EAAE;QAClB,MAAM,IAAI,KAAK,CACX,4DAA4D,CAC/D,CAAC;I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,CAAC;oBAChB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;oBACtB,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;oBACzB,oBAAoB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;oBACpC,sBAAsB,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAClD,CAAC;YACL,CAAC;QACL,CAAC;QAED,iDAAiD;QACjD,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;YACjB,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACzB,IAAI,oBAAoB,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;gBACzC,oBAAoB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACxC,CAAC;QACL,CAAC;IACL,CAAC,CAAC;IAEF,MAAM,YAAY,GAA2B;QACzC,gBAAgB;QAChB,aAAa;QACb,eAAe;QACf,WAAW;QACX,YAAY;QACZ,YAAY;QACZ,kCAAkC;KACrC,CAAC;IAEF,OAAO,CACH,KAAC,kBAAkB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,YAC3C,QAAQ,GACiB,CACjC,CAAC;AACN,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormaState.d.ts","sourceRoot":"","sources":["../../../hooks/useFormaState.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"useFormaState.d.ts","sourceRoot":"","sources":["../../../hooks/useFormaState.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAWH,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD;;;GAGG;AACH,MAAM,WAAW,oBAAoB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAC/D,4DAA4D;IAC5D,QAAQ,CAAC,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AAC,IAAI,EAAE,MAAM,KAAK,GAAG,CAAC;IAEhC,oDAAoD;IACpD,SAAS,EAAE,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,KAAK,MAAM,IAAI,CAAC;IAEzD,sFAAsF;IACtF,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;CACzB;AAgCD;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,GAAG,GAAG,EACxC,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC,EACtB,IAAI,EAAE,MAAM,GACb,CAAC,CAEH;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,wBAAgB,aAAa,CACzB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACrD,aAAa,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAAC;AAGhF,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACvD,aAAa,EAAE,CAAC,EAChB,OAAO,CAAC,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAClC,mBAAmB,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @author KIM YOUNG JIN (ehfuse@gmail.com)
|
|
8
8
|
* @license MIT License
|
|
9
9
|
*/
|
|
10
|
-
import { useRef, useCallback, useState, useEffect } from "react";
|
|
10
|
+
import { useRef, useCallback, useState, useEffect, useReducer, } from "react";
|
|
11
11
|
import { FieldStore } from "../core/FieldStore";
|
|
12
12
|
import { devWarn } from "../utils";
|
|
13
13
|
/**
|
|
@@ -20,14 +20,20 @@ import { devWarn } from "../utils";
|
|
|
20
20
|
*/
|
|
21
21
|
function useFieldValue(store, fieldName) {
|
|
22
22
|
const [value, setValue] = useState(() => store.getValue(fieldName));
|
|
23
|
+
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
23
24
|
useEffect(() => {
|
|
25
|
+
// 초기값 강제 동기화
|
|
26
|
+
const currentValue = store.getValue(fieldName);
|
|
27
|
+
setValue(currentValue);
|
|
24
28
|
// 구독 설정 / Setup subscription
|
|
25
29
|
const unsubscribe = store.subscribe(fieldName, () => {
|
|
26
30
|
const newValue = store.getValue(fieldName);
|
|
27
31
|
setValue(newValue);
|
|
32
|
+
// useReducer를 사용한 강제 리렌더링
|
|
33
|
+
forceUpdate();
|
|
28
34
|
});
|
|
29
35
|
return unsubscribe;
|
|
30
|
-
}, [fieldName]); //
|
|
36
|
+
}, [fieldName, store]); // 깔끔한 의존성 배열
|
|
31
37
|
return value;
|
|
32
38
|
}
|
|
33
39
|
/**
|
|
@@ -54,6 +60,14 @@ export function useFormaState(initialValues = {}, options = {}) {
|
|
|
54
60
|
const storeRef = useRef(null);
|
|
55
61
|
if (_externalStore) {
|
|
56
62
|
storeRef.current = _externalStore;
|
|
63
|
+
// 외부 스토어 사용 시 초기값이 비어있으면 설정
|
|
64
|
+
const currentValues = _externalStore.getValues();
|
|
65
|
+
if (Object.keys(currentValues).length === 0 &&
|
|
66
|
+
Object.keys(initialValues).length > 0) {
|
|
67
|
+
Object.keys(initialValues).forEach((key) => {
|
|
68
|
+
_externalStore.setValue(key, initialValues[key]);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
57
71
|
}
|
|
58
72
|
else if (!storeRef.current) {
|
|
59
73
|
storeRef.current = new FieldStore(stableInitialValues.current);
|
|
@@ -70,38 +84,38 @@ export function useFormaState(initialValues = {}, options = {}) {
|
|
|
70
84
|
// dot notation으로 특정 필드 값 구독
|
|
71
85
|
const useValue = useCallback((path) => {
|
|
72
86
|
return useFieldValue(store, path);
|
|
73
|
-
}, [] // store 의존성
|
|
87
|
+
}, [store] // store 의존성 추가 - 외부 스토어 사용 시 중요
|
|
74
88
|
);
|
|
75
89
|
// Set a specific field value with dot notation
|
|
76
90
|
// dot notation으로 특정 필드 값 설정
|
|
77
91
|
const setValue = useCallback((path, value) => {
|
|
78
92
|
store.setValue(path, value);
|
|
79
|
-
}, [] // store 의존성
|
|
93
|
+
}, [store] // store 의존성 추가
|
|
80
94
|
);
|
|
81
95
|
// Get all current values (non-reactive)
|
|
82
96
|
// 모든 현재 값 가져오기 (반응형 아님)
|
|
83
97
|
const getValues = useCallback(() => {
|
|
84
98
|
return store.getValues();
|
|
85
|
-
}, []); // store 의존성
|
|
99
|
+
}, [store]); // store 의존성 추가
|
|
86
100
|
// Set all values at once
|
|
87
101
|
// 모든 값을 한 번에 설정
|
|
88
102
|
const setValues = useCallback((values) => {
|
|
89
103
|
const currentValues = store.getValues();
|
|
90
104
|
const newValues = { ...currentValues, ...values };
|
|
91
105
|
store.setValues(newValues);
|
|
92
|
-
}, [] // store 의존성
|
|
106
|
+
}, [store] // store 의존성 추가
|
|
93
107
|
);
|
|
94
108
|
// Reset to initial values
|
|
95
109
|
// 초기값으로 재설정
|
|
96
110
|
const reset = useCallback(() => {
|
|
97
111
|
store.reset();
|
|
98
|
-
}, []); // store 의존성
|
|
112
|
+
}, [store]); // store 의존성 추가
|
|
99
113
|
// Set new initial values (for dynamic initialization)
|
|
100
114
|
// 새 초기값 설정 (동적 초기화용)
|
|
101
115
|
const setInitialValues = useCallback((newInitialValues) => {
|
|
102
116
|
stableInitialValues.current = newInitialValues;
|
|
103
117
|
store.setInitialValues(newInitialValues);
|
|
104
|
-
}, []); // store 의존성
|
|
118
|
+
}, [store]); // store 의존성 추가
|
|
105
119
|
// Handle standard input change events
|
|
106
120
|
// 표준 입력 변경 이벤트 처리
|
|
107
121
|
const handleChange = useCallback((event) => {
|
|
@@ -140,19 +154,19 @@ export function useFormaState(initialValues = {}, options = {}) {
|
|
|
140
154
|
handleChange,
|
|
141
155
|
hasField: useCallback((path) => {
|
|
142
156
|
return store.hasField(path);
|
|
143
|
-
}, [] // store 의존성
|
|
157
|
+
}, [store] // store 의존성 추가
|
|
144
158
|
),
|
|
145
159
|
removeField: useCallback((path) => {
|
|
146
160
|
store.removeField(path);
|
|
147
|
-
}, [] // store 의존성
|
|
161
|
+
}, [store] // store 의존성 추가
|
|
148
162
|
),
|
|
149
163
|
getValue: useCallback((path) => {
|
|
150
164
|
return store.getValue(path);
|
|
151
|
-
}, [] // store 의존성
|
|
165
|
+
}, [store] // store 의존성 추가
|
|
152
166
|
),
|
|
153
167
|
subscribe: useCallback((callback) => {
|
|
154
168
|
return store.subscribeToAll(callback);
|
|
155
|
-
}, [] // store 의존성
|
|
169
|
+
}, [store] // store 의존성 추가
|
|
156
170
|
),
|
|
157
171
|
_store: store,
|
|
158
172
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormaState.js","sourceRoot":"","sources":["../../../hooks/useFormaState.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"useFormaState.js","sourceRoot":"","sources":["../../../hooks/useFormaState.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACH,MAAM,EACN,WAAW,EAEX,QAAQ,EACR,SAAS,EAET,UAAU,GACb,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAkC,OAAO,EAAE,MAAM,UAAU,CAAC;AAqEnE;;;;;;;GAOG;AACH,SAAS,aAAa,CAAI,KAAsB,EAAE,SAAiB;IAC/D,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;IACpE,MAAM,CAAC,EAAE,WAAW,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IAEpD,SAAS,CAAC,GAAG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SAAS,EAAE,WAAW,CAClB,CAAC,QAA6B,EAAE,EAAE;YAC9B,OAAO,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QAC1C,CAAC,EACD,CAAC,KAAK,CAAC,CAAC,eAAe;SAC1B;QACD,MAAM,EAAE,KAAK;KAChB,CAAC;AACN,CAAC"}
|
|
@@ -41,5 +41,5 @@ import { UseGlobalFormProps, UseGlobalFormReturn } from "../types/globalForm";
|
|
|
41
41
|
* @param props 글로벌 폼 설정 옵션 / Global form configuration options
|
|
42
42
|
* @returns 글로벌 폼 관리 API 객체 / Global form management API object
|
|
43
43
|
*/
|
|
44
|
-
export declare function useGlobalForm<T extends Record<string, any>>({ formId, }: UseGlobalFormProps<T>): UseGlobalFormReturn<T>;
|
|
44
|
+
export declare function useGlobalForm<T extends Record<string, any>>({ formId, initialValues, autoCleanup, }: UseGlobalFormProps<T>): UseGlobalFormReturn<T>;
|
|
45
45
|
//# sourceMappingURL=useGlobalForm.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGlobalForm.d.ts","sourceRoot":"","sources":["../../../hooks/useGlobalForm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAIH,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAG9E;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,EACzD,MAAM,
|
|
1
|
+
{"version":3,"file":"useGlobalForm.d.ts","sourceRoot":"","sources":["../../../hooks/useGlobalForm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAIH,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAG9E;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,EACzD,MAAM,EACN,aAAa,EACb,WAAkB,GACrB,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CA2EhD"}
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
28
|
* SOFTWARE.
|
|
29
29
|
*/
|
|
30
|
-
import { useContext } from "react";
|
|
30
|
+
import { useContext, useEffect } from "react";
|
|
31
31
|
import { useForm } from "./useForm";
|
|
32
32
|
import { GlobalFormaContext } from "../contexts/GlobalFormaContext";
|
|
33
33
|
/**
|
|
@@ -43,15 +43,60 @@ import { GlobalFormaContext } from "../contexts/GlobalFormaContext";
|
|
|
43
43
|
* @param props 글로벌 폼 설정 옵션 / Global form configuration options
|
|
44
44
|
* @returns 글로벌 폼 관리 API 객체 / Global form management API object
|
|
45
45
|
*/
|
|
46
|
-
export function useGlobalForm({ formId, }) {
|
|
47
|
-
const
|
|
46
|
+
export function useGlobalForm({ formId, initialValues, autoCleanup = true, }) {
|
|
47
|
+
const context = useContext(GlobalFormaContext);
|
|
48
|
+
// Context가 제대로 설정되지 않았을 때 명확한 에러 표시
|
|
49
|
+
// Show clear error when Context is not properly configured
|
|
50
|
+
if (!context || !context.getOrCreateStore) {
|
|
51
|
+
// 페이지에 에러가 표시되도록 컴포넌트 렌더링을 방해하는 에러를 던짐
|
|
52
|
+
// Throw error that prevents component rendering so error shows on page
|
|
53
|
+
const errorMessage = `
|
|
54
|
+
🚨 GlobalFormaProvider 설정 오류 | Configuration Error
|
|
55
|
+
|
|
56
|
+
GlobalFormaProvider가 App.tsx에 설정되지 않았습니다!
|
|
57
|
+
GlobalFormaProvider is not configured in App.tsx!
|
|
58
|
+
|
|
59
|
+
해결 방법 | Solution:
|
|
60
|
+
1. App.tsx 파일에서 GlobalFormaProvider로 컴포넌트를 감싸주세요.
|
|
61
|
+
2. import { GlobalFormaProvider } from '@/forma';
|
|
62
|
+
3. <GlobalFormaProvider><YourApp /></GlobalFormaProvider>
|
|
63
|
+
|
|
64
|
+
Details: GlobalFormaContext must be used within GlobalFormaProvider (formId: ${formId})
|
|
65
|
+
`.trim();
|
|
66
|
+
throw new Error(errorMessage);
|
|
67
|
+
}
|
|
68
|
+
const { getOrCreateStore, incrementRef, decrementRef, validateAndStoreAutoCleanupSetting, } = context;
|
|
69
|
+
// autoCleanup 설정 일관성 검증
|
|
70
|
+
validateAndStoreAutoCleanupSetting(formId, autoCleanup);
|
|
48
71
|
// 글로벌 스토어 가져오기 또는 생성 / Get or create global store
|
|
49
72
|
const store = getOrCreateStore(formId);
|
|
50
|
-
// useForm에 외부 스토어 전달
|
|
73
|
+
// useForm에 외부 스토어 전달 / Pass external store to useForm
|
|
51
74
|
const form = useForm({
|
|
52
|
-
initialValues: {},
|
|
75
|
+
initialValues: initialValues || {},
|
|
53
76
|
_externalStore: store,
|
|
54
77
|
});
|
|
78
|
+
// 초기값이 있고 스토어가 비어있다면 초기값 설정 (올바른 방법으로)
|
|
79
|
+
// Set initial values if provided and store is empty (using proper method)
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (initialValues && Object.keys(store.getValues()).length === 0) {
|
|
82
|
+
form.setInitialFormValues(initialValues);
|
|
83
|
+
}
|
|
84
|
+
}, [formId, initialValues, store, form]);
|
|
85
|
+
// 참조 카운팅을 통한 자동 정리 관리
|
|
86
|
+
// Auto cleanup management through reference counting
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (autoCleanup) {
|
|
89
|
+
// 컴포넌트 마운트 시 참조 카운트 증가
|
|
90
|
+
// Increment reference count on component mount
|
|
91
|
+
incrementRef(formId, autoCleanup);
|
|
92
|
+
return () => {
|
|
93
|
+
// 컴포넌트 언마운트 시 참조 카운트 감소 (마지막 참조자면 자동 정리)
|
|
94
|
+
// Decrement reference count on unmount (auto cleanup if last reference)
|
|
95
|
+
decrementRef(formId, autoCleanup);
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return undefined;
|
|
99
|
+
}, [formId, autoCleanup, incrementRef, decrementRef]);
|
|
55
100
|
return {
|
|
56
101
|
...form,
|
|
57
102
|
formId, // 글로벌 폼 ID 추가 제공 / Provide additional global form ID
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGlobalForm.js","sourceRoot":"","sources":["../../../hooks/useGlobalForm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"useGlobalForm.js","sourceRoot":"","sources":["../../../hooks/useGlobalForm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEpE;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAAgC,EACzD,MAAM,EACN,aAAa,EACb,WAAW,GAAG,IAAI,GACE;IACpB,MAAM,OAAO,GAAG,UAAU,CAAC,kBAAkB,CAAC,CAAC;IAE/C,oCAAoC;IACpC,2DAA2D;IAC3D,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC;QACxC,uCAAuC;QACvC,uEAAuE;QACvE,MAAM,YAAY,GAAG;;;;;;;;;;;+EAWkD,MAAM;SAC5E,CAAC,IAAI,EAAE,CAAC;QAET,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;IAClC,CAAC;IAED,MAAM,EACF,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,kCAAkC,GACrC,GAAG,OAAO,CAAC;IAEZ,wBAAwB;I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