@gaddario98/react-core 2.0.9 → 2.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.
@@ -1,4 +1,4 @@
1
- 'use strict';var jsxRuntime=require('react/jsx-runtime'),React=require('react'),jotai=require('jotai'),utils=require('jotai/utils'),fflate=require('fflate'),compilerRuntime=require('react/compiler-runtime'),reactQuery=require('@tanstack/react-query'),axios=require('axios'),equal=require('fast-deep-equal'),jotaiFamily=require('jotai-family'),reactForm=require('@tanstack/react-form');/******************************************************************************
1
+ 'use strict';var jsxRuntime=require('react/jsx-runtime'),react=require('react'),reactQueries=require('@gaddario98/react-queries'),jotai=require('jotai'),compilerRuntime=require('react/compiler-runtime'),reactState=require('@gaddario98/react-state'),equal=require('fast-deep-equal'),reactForm=require('@gaddario98/react-form'),jotaiFamily=require('jotai-family'),reactQuery=require('@tanstack/react-query');/******************************************************************************
2
2
  Copyright (c) Microsoft Corporation.
3
3
 
4
4
  Permission to use, copy, modify, and/or distribute this software for any
@@ -25,1593 +25,6 @@ function __rest(s, e) {
25
25
  typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
26
26
  var e = new Error(message);
27
27
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
28
- };const RAW_PREFIX = 'storage:raw:';
29
- const DEFLATE_PREFIX = 'storage:deflate:v1:';
30
- const isProbablyJson = value => {
31
- if (!value) return false;
32
- const c = value.charCodeAt(0);
33
- // { [ " digits, t/f/n (true/false/null)
34
- return c === 123 || c === 91 || c === 34 || c >= 48 && c <= 57 || c === 45 || c === 116 || c === 102 || c === 110;
35
- };
36
- const u8ToBase64 = bytes => {
37
- let binary = '';
38
- const chunkSize = 0x8000;
39
- for (let i = 0; i < bytes.length; i += chunkSize) {
40
- binary += String.fromCharCode(...bytes.subarray(i, i + chunkSize));
41
- }
42
- return btoa(binary);
43
- };
44
- const base64ToU8 = base64 => {
45
- const binary = atob(base64);
46
- const bytes = new Uint8Array(binary.length);
47
- for (let i = 0; i < binary.length; i++) {
48
- bytes[i] = binary.charCodeAt(i);
49
- }
50
- return bytes;
51
- };
52
- const createCompressedStorage = (base, options = {}) => {
53
- const {
54
- minSizeToCompress = 1024,
55
- deflateLevel = 1,
56
- writeDebounceMs = 50
57
- } = options;
58
- const pendingWrites = new Map();
59
- let flushTimer;
60
- let lifecycleHooksInstalled = false;
61
- const flush = () => {
62
- flushTimer = undefined;
63
- for (const [key, value] of pendingWrites) {
64
- try {
65
- if (value.length < minSizeToCompress) {
66
- base.setItem(key, RAW_PREFIX + value);
67
- continue;
68
- }
69
- const input = fflate.strToU8(value);
70
- const compressed = fflate.deflateSync(input, {
71
- level: deflateLevel
72
- });
73
- base.setItem(key, DEFLATE_PREFIX + u8ToBase64(compressed));
74
- } catch (error) {
75
- console.error('Error setting item:', error);
76
- try {
77
- base.setItem(key, RAW_PREFIX + value);
78
- } catch (_a) {
79
- // ignore
80
- }
81
- }
82
- }
83
- pendingWrites.clear();
84
- };
85
- const scheduleFlush = () => {
86
- if (flushTimer != null) return;
87
- if (!lifecycleHooksInstalled && typeof window !== 'undefined') {
88
- lifecycleHooksInstalled = true;
89
- window.addEventListener('beforeunload', flush);
90
- document.addEventListener('visibilitychange', () => {
91
- if (document.visibilityState === 'hidden') flush();
92
- });
93
- }
94
- flushTimer = globalThis.setTimeout(flush, writeDebounceMs);
95
- };
96
- return {
97
- getItem: key => {
98
- try {
99
- const stored = base.getItem(key);
100
- if (!stored) return null;
101
- if (stored.startsWith(RAW_PREFIX)) {
102
- return stored.slice(RAW_PREFIX.length);
103
- }
104
- if (stored.startsWith(DEFLATE_PREFIX)) {
105
- const b64 = stored.slice(DEFLATE_PREFIX.length);
106
- const bytes = base64ToU8(b64);
107
- const decompressed = fflate.inflateSync(bytes);
108
- return fflate.strFromU8(decompressed);
109
- }
110
- // Back-compat: older versions may have stored raw JSON without any prefix
111
- if (isProbablyJson(stored)) return stored;
112
- return null;
113
- } catch (error) {
114
- console.error('Error getting item:', error);
115
- return null;
116
- }
117
- },
118
- setItem: (key, value) => {
119
- try {
120
- // Some upstream serializers can return `undefined` (e.g. JSON.stringify(undefined)).
121
- const rawValue = value;
122
- if (rawValue == null) {
123
- pendingWrites.delete(key);
124
- base.removeItem(key);
125
- return;
126
- }
127
- const stringValue = typeof rawValue === 'string' ? rawValue : String(rawValue);
128
- pendingWrites.set(key, stringValue);
129
- scheduleFlush();
130
- } catch (error) {
131
- console.error('Error setting item:', error);
132
- }
133
- },
134
- removeItem: key => {
135
- try {
136
- pendingWrites.delete(key);
137
- base.removeItem(key);
138
- } catch (error) {
139
- console.error('Error removing item:', error);
140
- }
141
- }
142
- };
143
- };
144
- const baseStorage = {
145
- getItem: key => {
146
- if (typeof localStorage === 'undefined') return null;
147
- return localStorage.getItem(key);
148
- },
149
- setItem: (key, value) => {
150
- if (typeof localStorage === 'undefined') return;
151
- localStorage.setItem(key, value);
152
- },
153
- removeItem: key => {
154
- if (typeof localStorage === 'undefined') return;
155
- localStorage.removeItem(key);
156
- }
157
- };
158
- let storage = createCompressedStorage(baseStorage);// Implementazione
159
- function atomStateGenerator({
160
- key,
161
- defaultValue,
162
- persist = false,
163
- storage: customStorage
164
- }) {
165
- const resolvedStorage = customStorage || storage;
166
- // Usa atomWithStorage solo se persist è true, altrimenti atom normale
167
- const jotaiAtom = persist ? utils.atomWithStorage(key, defaultValue, utils.createJSONStorage(() => resolvedStorage)) : jotai.atom(defaultValue);
168
- const useValue = () => {
169
- const [value] = jotai.useAtom(jotaiAtom);
170
- return value;
171
- };
172
- const useState = () => {
173
- const $ = compilerRuntime.c(3);
174
- const [value, setValue] = jotai.useAtom(jotaiAtom);
175
- let t0;
176
- if ($[0] !== setValue || $[1] !== value) {
177
- t0 = [value, setValue];
178
- $[0] = setValue;
179
- $[1] = value;
180
- $[2] = t0;
181
- } else {
182
- t0 = $[2];
183
- }
184
- return t0;
185
- };
186
- const useReset = () => {
187
- const $ = compilerRuntime.c(2);
188
- const [, setValue] = jotai.useAtom(jotaiAtom);
189
- let t0;
190
- if ($[0] !== setValue) {
191
- t0 = () => {
192
- setValue(defaultValue);
193
- if (persist) {
194
- resolvedStorage.removeItem(key);
195
- }
196
- };
197
- $[0] = setValue;
198
- $[1] = t0;
199
- } else {
200
- t0 = $[1];
201
- }
202
- return t0;
203
- };
204
- return {
205
- atom: jotaiAtom,
206
- useValue,
207
- useState,
208
- useReset
209
- };
210
- }// ============================================================================
211
- // Default Values
212
- // ============================================================================
213
- const DEFAULT_QUERY_ENTRY = Object.freeze({
214
- data: undefined,
215
- isLoading: false,
216
- isLoadingMapped: false,
217
- isFetching: false,
218
- isPending: false,
219
- isSuccess: false,
220
- isError: false,
221
- isStale: false,
222
- error: null,
223
- dataUpdatedAt: 0,
224
- errorUpdatedAt: 0,
225
- fetchStatus: 'idle',
226
- refetch: () => Promise.resolve()
227
- });
228
- const DEFAULT_MUTATION_ENTRY = Object.freeze({
229
- data: undefined,
230
- status: 'idle',
231
- error: null,
232
- variables: undefined,
233
- submittedAt: 0,
234
- isIdle: true,
235
- isPending: false,
236
- isSuccess: false,
237
- isError: false,
238
- mutate: () => {},
239
- mutateAsync: async () => Promise.resolve(undefined),
240
- reset: () => {},
241
- context: 0,
242
- failureCount: 0,
243
- failureReason: null,
244
- isPaused: false
245
- });
246
- // ============================================================================
247
- // Global Atoms (single atom for all queries, single atom for all mutations)
248
- // ============================================================================
249
- /**
250
- * Global atom storing all query results.
251
- * Key format: "scopeId:queryKey"
252
- */
253
- const queriesAtom = utils.atomWithStorage('queries-atom', {}, utils.createJSONStorage(() => storage), {
254
- getOnInit: true
255
- });
256
- /**
257
- * Global atom storing all mutation results.
258
- * Key format: "scopeId:mutationKey"
259
- */
260
- const mutationsAtom = jotai.atom({});
261
- // ============================================================================
262
- // Helper to generate composite keys
263
- // ============================================================================
264
- const getCompositeKey = (scopeId, key) => `${scopeId}:${key}`;const apiClient = axios.create({
265
- timeout: 30000,
266
- headers: {
267
- 'Content-Type': 'application/json'
268
- }
269
- });
270
- apiClient.interceptors.response.use(response => response, error => {
271
- var _a, _b;
272
- if (error.response) {
273
- throw new Error(((_a = error.response.data) === null || _a === void 0 ? void 0 : _a.message) || ((_b = error.response.data) === null || _b === void 0 ? void 0 : _b.error) || `Error ${error.response.status}`);
274
- } else if (error.request) {
275
- throw new Error('No response from server - request timeout or network issue');
276
- } else {
277
- throw new Error('Request configuration error');
278
- }
279
- });
280
- const apiRequest = async ({
281
- method,
282
- url,
283
- body,
284
- headers,
285
- converter
286
- }) => {
287
- try {
288
- const isPrimitive = typeof body === 'string' || typeof body === 'number' || typeof body === 'boolean';
289
- let finalUrl = url;
290
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
291
- let finalBody = body;
292
- // 1. Primitive Body Handling (Append to URL)
293
- if (isPrimitive && body) {
294
- if (method !== 'POST') {
295
- finalUrl = `${url}/${body}`;
296
- finalBody = undefined;
297
- }
298
- }
299
- // 2. Object Body Handling (Path Param Replacement)
300
- if (!isPrimitive && typeof body === 'object' && body !== null) {
301
- // Look for :param in string
302
- // e.g. /users/:uid/availability
303
- const pathParams = finalUrl.match(/:[a-zA-Z0-9_]+/g);
304
- if (pathParams) {
305
- // Create shallow copy to avoid mutating original
306
- finalBody = Object.assign({}, body);
307
- pathParams.forEach(param => {
308
- if (finalBody) {
309
- const key = param.substring(1); // remove :
310
- if (key in finalBody) {
311
- finalUrl = finalUrl.replace(param, String(finalBody[key]));
312
- // Optional: remove from body if it was used in path?
313
- // Usually yes for simple IDs, maybe not for others.
314
- // Let's remove to keep body clean.
315
- delete finalBody[key];
316
- }
317
- }
318
- });
319
- }
320
- // Also handle case where we append ID to end if URL ends with / and we have 'id' or 'uid' in body?
321
- // No, explicit :param or explicit append logic is safer.
322
- // But we have logic for 'updateUser' where we just set endpoint ['api', 'users'] and method PUT.
323
- // We expect /users/123.
324
- // If body is { uid: 123, ...data }, we want /users/123.
325
- // If no :param is found, and method is PUT/DELETE/PATCH, and body has 'id' or 'uid', should we append?
326
- // User asked to eliminate customRequest.
327
- // Let's add: "If method is PUT/DELETE/PATCH, and no :param replacement happened, and body has (id|uid), append it."
328
- const hasId = 'id' in finalBody || 'uid' in finalBody;
329
- if ((method === 'PUT' || method === 'DELETE' || method === 'PATCH') && hasId && !pathParams) {
330
- const id = finalBody.id || finalBody.uid;
331
- if (id) {
332
- finalUrl = `${finalUrl}/${id}`;
333
- // We generally DON'T remove ID from body in this implicit case as it might be needed for validation
334
- // But for cleaner API calls we might want to.
335
- // Let's keep it safe: Don't remove ID here.
336
- }
337
- }
338
- }
339
- const data = converter && finalBody ? converter(finalBody) : finalBody;
340
- const response = await apiClient({
341
- url: finalUrl,
342
- method,
343
- data,
344
- headers
345
- });
346
- if (response.status >= 200 && response.status < 300) {
347
- return response.data;
348
- }
349
- throw new Error(`Request failed with status ${response.status}`);
350
- } catch (error) {
351
- console.error('API Request Error:', error);
352
- if (error instanceof Error) {
353
- throw error;
354
- }
355
- throw new Error('Unknown error occurred');
356
- }
357
- };const _endpoints = {
358
- custom: '',
359
- api: 'http://localhost:3000' // import.meta.env.VITE_API_URL ||
360
- };
361
- const defaultQueryClient = new reactQuery.QueryClient({
362
- defaultOptions: {
363
- queries: {
364
- retry: 2
365
- // staleTime: 2 * 60 * 1000,
366
- }
367
- }
368
- });
369
- const {
370
- useValue: useApiConfigValue} = atomStateGenerator({
371
- key: 'apiConfig',
372
- defaultValue: {
373
- endpoints: _endpoints,
374
- requestFn: apiRequest,
375
- queryClient: defaultQueryClient
376
- },
377
- persist: false
378
- });const useMultipleQuery = t0 => {
379
- const $ = compilerRuntime.c(30);
380
- let t1;
381
- if ($[0] !== t0) {
382
- t1 = t0 === undefined ? [] : t0;
383
- $[0] = t0;
384
- $[1] = t1;
385
- } else {
386
- t1 = $[1];
387
- }
388
- const settings = t1;
389
- const {
390
- requestFn,
391
- validateAuthFn,
392
- defaultHeaders,
393
- queryClient,
394
- endpoints
395
- } = useApiConfigValue();
396
- let t2;
397
- if ($[2] !== endpoints) {
398
- t2 = endpoint => {
399
- const [key, path] = endpoint;
400
- const baseUrl = endpoints[key];
401
- return [baseUrl, path].filter(Boolean).join("/");
402
- };
403
- $[2] = endpoints;
404
- $[3] = t2;
405
- } else {
406
- t2 = $[3];
407
- }
408
- const generateEndpoint = t2;
409
- let t3;
410
- if ($[4] !== validateAuthFn) {
411
- t3 = validateAuthFn ? validateAuthFn() : true;
412
- $[4] = validateAuthFn;
413
- $[5] = t3;
414
- } else {
415
- t3 = $[5];
416
- }
417
- const isLogged = t3;
418
- let t4;
419
- if ($[6] !== defaultHeaders || $[7] !== generateEndpoint || $[8] !== requestFn) {
420
- t4 = async t5 => {
421
- const {
422
- endpoint: endpoint_0,
423
- customQueryFn,
424
- headers
425
- } = t5;
426
- const fullEndpoint = generateEndpoint(endpoint_0);
427
- if (customQueryFn) {
428
- const res = await customQueryFn();
429
- return res;
430
- }
431
- const mergedHeaders = Object.assign(Object.assign({}, defaultHeaders), headers);
432
- return await requestFn({
433
- url: fullEndpoint,
434
- method: "GET",
435
- headers: mergedHeaders
436
- });
437
- };
438
- $[6] = defaultHeaders;
439
- $[7] = generateEndpoint;
440
- $[8] = requestFn;
441
- $[9] = t4;
442
- } else {
443
- t4 = $[9];
444
- }
445
- const generateQueryFn = t4;
446
- let t5;
447
- let t6;
448
- if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
449
- t5 = {};
450
- t6 = {};
451
- $[10] = t5;
452
- $[11] = t6;
453
- } else {
454
- t5 = $[10];
455
- t6 = $[11];
456
- }
457
- let t7;
458
- if ($[12] !== settings) {
459
- t7 = {
460
- settings,
461
- data: t5,
462
- results: t6
463
- };
464
- $[12] = settings;
465
- $[13] = t7;
466
- } else {
467
- t7 = $[13];
468
- }
469
- const ref = React.useRef(t7);
470
- let t8;
471
- let t9;
472
- if ($[14] !== settings) {
473
- t8 = () => {
474
- ref.current.settings = settings;
475
- };
476
- t9 = [settings];
477
- $[14] = settings;
478
- $[15] = t8;
479
- $[16] = t9;
480
- } else {
481
- t8 = $[15];
482
- t9 = $[16];
483
- }
484
- React.useEffect(t8, t9);
485
- let t10;
486
- if ($[17] !== generateQueryFn || $[18] !== isLogged || $[19] !== settings) {
487
- let t11;
488
- if ($[21] !== generateQueryFn || $[22] !== isLogged) {
489
- t11 = setting => {
490
- const {
491
- queryKey,
492
- enabled: t12,
493
- disableAuthControl
494
- } = setting;
495
- const enabled = t12 === undefined ? true : t12;
496
- const rest = __rest(setting, ["queryKey", "enabled", "disableAuthControl"]);
497
- return Object.assign({
498
- queryKey,
499
- queryFn: () => generateQueryFn(setting),
500
- enabled: !!enabled && (disableAuthControl || !!isLogged)
501
- }, rest);
502
- };
503
- $[21] = generateQueryFn;
504
- $[22] = isLogged;
505
- $[23] = t11;
506
- } else {
507
- t11 = $[23];
508
- }
509
- t10 = settings.map(t11);
510
- $[17] = generateQueryFn;
511
- $[18] = isLogged;
512
- $[19] = settings;
513
- $[20] = t10;
514
- } else {
515
- t10 = $[20];
516
- }
517
- const queries = t10;
518
- let t11;
519
- if ($[24] === Symbol.for("react.memo_cache_sentinel")) {
520
- t11 = results => results.reduce((prev, result, index) => {
521
- const setting_0 = ref.current.settings[index];
522
- const keyToMap = setting_0.keyToMap;
523
- Object.assign(prev, {
524
- [keyToMap]: {
525
- data: result.data,
526
- isLoadingMapped: !setting_0.disableLoading && result.isLoading,
527
- isLoading: result.isLoading,
528
- isFetching: result.isFetching,
529
- isPending: result.isPending,
530
- error: result.error,
531
- refetch: result.refetch
532
- }
533
- });
534
- return prev;
535
- }, {});
536
- $[24] = t11;
537
- } else {
538
- t11 = $[24];
539
- }
540
- const combine = t11;
541
- let t12;
542
- if ($[25] !== queries) {
543
- t12 = {
544
- queries,
545
- combine
546
- };
547
- $[25] = queries;
548
- $[26] = t12;
549
- } else {
550
- t12 = $[26];
551
- }
552
- const result_0 = reactQuery.useQueries(t12, queryClient);
553
- let t13;
554
- let t14;
555
- if ($[27] !== result_0) {
556
- t13 = () => {
557
- ref.current.settings.forEach(setting_1 => {
558
- const {
559
- keyToMap: keyToMap_0,
560
- onDataChanged,
561
- onStateChange
562
- } = setting_1;
563
- if (!onDataChanged && !onStateChange) {
564
- return;
565
- }
566
- const currentResult = result_0[keyToMap_0];
567
- const prevResult = ref.current.results[keyToMap_0];
568
- if (onStateChange) {
569
- if (!prevResult || prevResult.data !== currentResult.data || prevResult.isLoading !== currentResult.isLoading || prevResult.isLoadingMapped !== currentResult.isLoadingMapped || prevResult.isFetching !== currentResult.isFetching || prevResult.isPending !== currentResult.isPending || prevResult.error !== currentResult.error) {
570
- ref.current.results[keyToMap_0] = currentResult;
571
- onStateChange(currentResult);
572
- }
573
- }
574
- if (onDataChanged) {
575
- const currentData = currentResult.data;
576
- const prevData = ref.current.data[keyToMap_0];
577
- if (currentData !== undefined && currentData !== prevData) {
578
- ref.current.data[keyToMap_0] = currentData;
579
- onDataChanged(currentData);
580
- }
581
- }
582
- });
583
- };
584
- t14 = [result_0];
585
- $[27] = result_0;
586
- $[28] = t13;
587
- $[29] = t14;
588
- } else {
589
- t13 = $[28];
590
- t14 = $[29];
591
- }
592
- React.useEffect(t13, t14);
593
- return result_0;
594
- };/* eslint-disable @typescript-eslint/no-explicit-any */
595
- const defaultState = DEFAULT_MUTATION_ENTRY;
596
- const mutationReducer = (state, action) => {
597
- switch (action.type) {
598
- case "RESET":
599
- return Object.assign(Object.assign({}, state), {
600
- [action.key]: Object.assign({}, defaultState)
601
- });
602
- case "PENDING":
603
- return Object.assign(Object.assign({}, state), {
604
- [action.key]: {
605
- status: "pending",
606
- data: undefined,
607
- error: null,
608
- submittedAt: action.submittedAt,
609
- variables: action.variables
610
- }
611
- });
612
- case "SUCCESS":
613
- return Object.assign(Object.assign({}, state), {
614
- [action.key]: Object.assign(Object.assign({}, state[action.key]), {
615
- status: "success",
616
- data: action.data,
617
- error: null
618
- })
619
- });
620
- case "ERROR":
621
- return Object.assign(Object.assign({}, state), {
622
- [action.key]: Object.assign(Object.assign({}, state[action.key]), {
623
- status: "error",
624
- error: action.error
625
- })
626
- });
627
- default:
628
- return state;
629
- }
630
- };
631
- const initMutationStates = configs => {
632
- const states = {};
633
- configs.forEach(config => {
634
- states[config.key] = Object.assign({}, defaultState);
635
- });
636
- return states;
637
- };
638
- const useMultipleMutation = configs => {
639
- const {
640
- requestFn,
641
- validateAuthFn,
642
- defaultHeaders,
643
- queryClient,
644
- showNotification,
645
- endpoints
646
- } = useApiConfigValue();
647
- const [reducerStates, dispatchReducer] = React.useReducer(mutationReducer, configs, initMutationStates);
648
- // Accessor for current state
649
- const getState = React.useCallback(key => {
650
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
651
- return reducerStates[key] || defaultState;
652
- }, [reducerStates]);
653
- // Dispatcher that handles both modes
654
- const dispatch = React.useCallback(action => {
655
- dispatchReducer(action);
656
- }, []);
657
- const executeMutation = React.useCallback(async (key_0, config, data, mutationOptions) => {
658
- var _a, _b, _c, _d, _e, _f, _g;
659
- const {
660
- endpoint,
661
- method,
662
- headers,
663
- queryKeyToInvalidate,
664
- customRequest,
665
- converter,
666
- isTest,
667
- notification,
668
- mutateOptions
669
- } = config;
670
- dispatch({
671
- type: "PENDING",
672
- key: key_0,
673
- submittedAt: Date.now(),
674
- variables: data
675
- });
676
- let context;
677
- try {
678
- // Auth validation
679
- const isValidAuth = validateAuthFn ? validateAuthFn() : true;
680
- if (!isValidAuth) {
681
- throw new Error("Utente non autenticato");
682
- }
683
- // Build endpoint
684
- const [endpointKey, path] = endpoint;
685
- const baseUrl = (_a = endpoints[endpointKey]) !== null && _a !== void 0 ? _a : "";
686
- const fullEndpoint = [baseUrl, path].filter(Boolean).join("/");
687
- // Merge headers
688
- const mergedHeaders = Object.assign(Object.assign({}, defaultHeaders), headers);
689
- // Execute request
690
- let result;
691
- if (isTest) {
692
- result = "test";
693
- } else if (customRequest) {
694
- result = await customRequest(fullEndpoint, method, data);
695
- } else {
696
- result = await requestFn({
697
- url: fullEndpoint,
698
- method,
699
- body: data,
700
- headers: mergedHeaders,
701
- converter
702
- });
703
- }
704
- dispatch({
705
- type: "SUCCESS",
706
- key: key_0,
707
- data: result
708
- });
709
- // Invalidate queries
710
- if (queryKeyToInvalidate) {
711
- queryKeyToInvalidate.forEach(qKey => {
712
- queryClient.invalidateQueries({
713
- queryKey: [qKey],
714
- exact: false
715
- });
716
- });
717
- }
718
- // Success notification
719
- const notificationProps_0 = typeof (notification === null || notification === void 0 ? void 0 : notification.success) === "function" ? notification.success(result) : notification === null || notification === void 0 ? void 0 : notification.success;
720
- if (notificationProps_0 === null || notificationProps_0 === void 0 ? void 0 : notificationProps_0.message) {
721
- showNotification === null || showNotification === void 0 ? void 0 : showNotification(Object.assign({
722
- message: notificationProps_0.message,
723
- type: (_b = notificationProps_0.type) !== null && _b !== void 0 ? _b : "success"
724
- }, notificationProps_0));
725
- }
726
- // Callbacks
727
- // @ts-expect-error - MutateOptions callback signature varies by TanStack Query version
728
- (_c = mutateOptions === null || mutateOptions === void 0 ? void 0 : mutateOptions.onSuccess) === null || _c === void 0 ? void 0 : _c.call(mutateOptions, result, data, context);
729
- (_d = mutationOptions === null || mutationOptions === void 0 ? void 0 : mutationOptions.onSuccess) === null || _d === void 0 ? void 0 : _d.call(mutationOptions, result, data, undefined, context);
730
- return result;
731
- } catch (error) {
732
- const err = error instanceof Error ? error : new Error("Unknown error");
733
- dispatch({
734
- type: "ERROR",
735
- key: key_0,
736
- error: err
737
- });
738
- // Error notification
739
- const notificationProps = typeof (notification === null || notification === void 0 ? void 0 : notification.error) === "function" ? notification.error(err.message) : notification === null || notification === void 0 ? void 0 : notification.error;
740
- if ((notificationProps === null || notificationProps === void 0 ? void 0 : notificationProps.message) || err.message) {
741
- showNotification === null || showNotification === void 0 ? void 0 : showNotification(Object.assign({
742
- message: (notificationProps === null || notificationProps === void 0 ? void 0 : notificationProps.message) || err.message || "An unexpected error occurred",
743
- type: (_e = notificationProps === null || notificationProps === void 0 ? void 0 : notificationProps.type) !== null && _e !== void 0 ? _e : "error"
744
- }, notificationProps));
745
- }
746
- // Callbacks
747
- // @ts-expect-error - MutateOptions callback signature varies by TanStack Query version
748
- (_f = mutateOptions === null || mutateOptions === void 0 ? void 0 : mutateOptions.onError) === null || _f === void 0 ? void 0 : _f.call(mutateOptions, err, data, context);
749
- (_g = mutationOptions === null || mutationOptions === void 0 ? void 0 : mutationOptions.onError) === null || _g === void 0 ? void 0 : _g.call(mutationOptions, err, data, undefined, context);
750
- throw err;
751
- }
752
- }, [queryClient, validateAuthFn, defaultHeaders, endpoints, requestFn, showNotification, dispatch // dispatch is now stable/wrapped
753
- ]);
754
- const ref = React.useRef({
755
- dispatch,
756
- executeMutation
757
- });
758
- React.useEffect(() => {
759
- ref.current = {
760
- dispatch,
761
- executeMutation
762
- };
763
- }, [dispatch, executeMutation]);
764
- const allMutation = React.useMemo(() => {
765
- const result_0 = {};
766
- configs.forEach(item => {
767
- var _a_0, _b_0, _c_0;
768
- // In silent mode, this is just the INITIAL state (or whatever triggered last render).
769
- // The real data comes from Proxy if used.
770
- const state = getState(item.key);
771
- const mutationConfig = item.mutationConfig;
772
- const mutationKey = item.key;
773
- result_0[mutationKey] = {
774
- // State
775
- data: state.data,
776
- error: state.error,
777
- isIdle: state.status === "idle",
778
- isPending: state.status === "pending",
779
- isSuccess: state.status === "success",
780
- isError: state.status === "error",
781
- status: state.status,
782
- variables: state.variables,
783
- submittedAt: (_a_0 = state.submittedAt) !== null && _a_0 !== void 0 ? _a_0 : 0,
784
- endpoint: mutationConfig.endpoint,
785
- // Methods
786
- mutate: (data_0, mutationOptions_0) => {
787
- ref.current.executeMutation(item.key, mutationConfig, data_0, mutationOptions_0);
788
- },
789
- mutateAsync: (data_1, mutationOptions_1) => {
790
- return ref.current.executeMutation(item.key, mutationConfig, data_1, mutationOptions_1);
791
- },
792
- reset: () => ref.current.dispatch({
793
- type: "RESET",
794
- key: item.key
795
- }),
796
- // Compatibility fields
797
- failureCount: 0,
798
- failureReason: null,
799
- context: undefined,
800
- isPaused: false
801
- };
802
- (_c_0 = (_b_0 = item.mutationConfig).onStateChange) === null || _c_0 === void 0 ? void 0 : _c_0.call(_b_0, result_0[mutationKey]);
803
- });
804
- return result_0;
805
- }, [getState, configs]);
806
- return allMutation;
807
- };const useMultipleWebSocket = (configs = []) => {
808
- const {
809
- websocketConfig
810
- } = useApiConfigValue();
811
- const {
812
- queryClient
813
- } = useApiConfigValue();
814
- const socketsRef = React.useRef(new Map());
815
- const [statuses, setStatuses] = React.useState(new Map());
816
- const [lastMessages, setLastMessages] = React.useState(new Map());
817
- // Stabilize configs reference
818
- const stableConfigs = React.useMemo(() => configs, [configs]);
819
- React.useEffect(() => {
820
- const sockets = socketsRef.current;
821
- stableConfigs.forEach(config => {
822
- const url = config.endpoint || (websocketConfig === null || websocketConfig === void 0 ? void 0 : websocketConfig.url);
823
- const shouldConnect = config.autoConnect !== false && ((websocketConfig === null || websocketConfig === void 0 ? void 0 : websocketConfig.autoConnect) || config.endpoint);
824
- if (!url || !shouldConnect) return;
825
- // Skip if already connected
826
- if (sockets.has(config.key)) return;
827
- setStatuses(prev => new Map(prev).set(config.key, 'connecting'));
828
- const ws = new WebSocket(url);
829
- sockets.set(config.key, ws);
830
- ws.onopen = () => {
831
- setStatuses(prev_0 => new Map(prev_0).set(config.key, 'open'));
832
- console.log(`WebSocket [${config.key}] connected`);
833
- };
834
- ws.onmessage = event => {
835
- var _a, _b;
836
- try {
837
- const data = JSON.parse(event.data);
838
- setLastMessages(prev_1 => new Map(prev_1).set(config.key, data));
839
- // Global handler
840
- (_a = websocketConfig === null || websocketConfig === void 0 ? void 0 : websocketConfig.onMessage) === null || _a === void 0 ? void 0 : _a.call(websocketConfig, data);
841
- // Local handler
842
- (_b = config.onMessage) === null || _b === void 0 ? void 0 : _b.call(config, data);
843
- // Auto invalidation
844
- if (config.invalidateQueriesOnMessage && Array.isArray(config.invalidateQueriesOnMessage)) {
845
- config.invalidateQueriesOnMessage.forEach(key => {
846
- queryClient.invalidateQueries({
847
- queryKey: [key],
848
- exact: false
849
- });
850
- });
851
- }
852
- } catch (e) {
853
- console.error(`WebSocket [${config.key}] message parse error`, e);
854
- }
855
- };
856
- ws.onclose = () => {
857
- setStatuses(prev_2 => new Map(prev_2).set(config.key, 'closed'));
858
- console.log(`WebSocket [${config.key}] disconnected`);
859
- sockets.delete(config.key);
860
- };
861
- });
862
- return () => {
863
- sockets.forEach((ws_0, key_0) => {
864
- ws_0.close();
865
- sockets.delete(key_0);
866
- });
867
- };
868
- }, [stableConfigs, websocketConfig, queryClient]);
869
- const createSendMessage = React.useCallback(key_1 => message => {
870
- const ws_1 = socketsRef.current.get(key_1);
871
- if ((ws_1 === null || ws_1 === void 0 ? void 0 : ws_1.readyState) === WebSocket.OPEN) {
872
- ws_1.send(JSON.stringify(message));
873
- } else {
874
- console.warn(`WebSocket [${key_1}] is not open`);
875
- }
876
- }, []);
877
- const result = React.useMemo(() => {
878
- const mapped = {};
879
- stableConfigs.forEach(config_0 => {
880
- var _a_0, _b_0;
881
- mapped[config_0.key] = {
882
- lastMessage: (_a_0 = lastMessages.get(config_0.key)) !== null && _a_0 !== void 0 ? _a_0 : null,
883
- sendMessage: createSendMessage(config_0.key),
884
- status: (_b_0 = statuses.get(config_0.key)) !== null && _b_0 !== void 0 ? _b_0 : 'closed'
885
- };
886
- });
887
- return mapped;
888
- }, [stableConfigs, lastMessages, statuses, createSendMessage]);
889
- return result;
890
- };function useApi(configs, optionsOrId) {
891
- const options = typeof optionsOrId === 'string' ? {
892
- scopeId: optionsOrId
893
- } : optionsOrId !== null && optionsOrId !== void 0 ? optionsOrId : {};
894
- const {
895
- scopeId = 'default',
896
- persistToAtoms = true
897
- } = options;
898
- // Global atom setters
899
- const setQueriesAtom = jotai.useSetAtom(queriesAtom);
900
- const setMutationsAtom = jotai.useSetAtom(mutationsAtom);
901
- // Update a single query in the global atom
902
- const updateQueryAtom = React.useCallback((key, state) => {
903
- const compositeKey = getCompositeKey(scopeId, key);
904
- setQueriesAtom(prev => Object.assign(Object.assign({}, prev), {
905
- [compositeKey]: state
906
- }));
907
- }, [setQueriesAtom, scopeId]);
908
- // Update a single mutation in the global atom
909
- const updateMutationAtom = React.useCallback((key, state) => {
910
- const compositeKey = getCompositeKey(scopeId, key);
911
- setMutationsAtom(prev => Object.assign(Object.assign({}, prev), {
912
- [compositeKey]: state
913
- }));
914
- }, [setMutationsAtom, scopeId]);
915
- // Enhanced query configs with atom persistence
916
- const enhancedQueryConfigs = React.useMemo(() => {
917
- const items = configs.filter(q => q.type === 'query');
918
- return items.map(item => {
919
- if (!item.queryConfig) return null;
920
- const key = item.key;
921
- const originalOnStateChange = item.queryConfig.onStateChange;
922
- return Object.assign(Object.assign({}, item.queryConfig), {
923
- keyToMap: key,
924
- onStateChange: state => {
925
- if (persistToAtoms) {
926
- updateQueryAtom(key, state);
927
- }
928
- originalOnStateChange === null || originalOnStateChange === void 0 ? void 0 : originalOnStateChange(state);
929
- },
930
- options: item.queryConfig.options
931
- });
932
- }).filter(Boolean);
933
- // eslint-disable-next-line react-hooks/exhaustive-deps
934
- }, [
935
- // eslint-disable-next-line react-hooks/exhaustive-deps
936
- JSON.stringify(configs), persistToAtoms, updateQueryAtom]);
937
- // Enhanced mutation configs with atom persistence
938
- const enhancedMutationItems = React.useMemo(() => {
939
- const items = configs.filter(q => q.type === 'mutation' && !!q.mutationConfig);
940
- return items.map(item => {
941
- const key = item.key;
942
- const originalOnStateChange = item.mutationConfig.onStateChange;
943
- return Object.assign(Object.assign({}, item), {
944
- mutationConfig: Object.assign(Object.assign({}, item.mutationConfig), {
945
- onStateChange: state => {
946
- if (persistToAtoms) {
947
- updateMutationAtom(key, state);
948
- }
949
- originalOnStateChange === null || originalOnStateChange === void 0 ? void 0 : originalOnStateChange(state);
950
- }
951
- })
952
- });
953
- });
954
- // eslint-disable-next-line react-hooks/exhaustive-deps
955
- }, [JSON.stringify(configs), persistToAtoms, updateMutationAtom]);
956
- const webSocketItems = React.useMemo(() => configs.filter(q => q.type === 'websocket'),
957
- // eslint-disable-next-line react-hooks/exhaustive-deps
958
- [JSON.stringify(configs)]);
959
- // Execute hooks
960
- const allQuery = useMultipleQuery(enhancedQueryConfigs);
961
- const allMutation = useMultipleMutation(enhancedMutationItems);
962
- const allWebSocket = useMultipleWebSocket(webSocketItems);
963
- const queryKeys = enhancedQueryConfigs.map(el => el.keyToMap);
964
- const mutationKeys = enhancedMutationItems.map(el => el.key);
965
- const ref = React.useRef({
966
- allQuery,
967
- allMutation,
968
- queryKeys,
969
- mutationKeys
970
- });
971
- React.useEffect(() => {
972
- ref.current = {
973
- allQuery,
974
- allMutation,
975
- queryKeys,
976
- mutationKeys
977
- };
978
- }, [allQuery, allMutation, queryKeys, mutationKeys]);
979
- const refreshQueries = React.useCallback(() => {
980
- ref.current.queryKeys.forEach(k => {
981
- ref.current.allQuery[k].refetch();
982
- });
983
- }, []);
984
- return {
985
- allQuery,
986
- allMutation,
987
- allWebSocket,
988
- refreshQueries
989
- };
990
- }// ============================================================================
991
- // Bulk Query/Mutation Hooks
992
- // ============================================================================
993
- /**
994
- * Hook to read all queries for a scope.
995
- */
996
- function useJotaiQueries(options) {
997
- const $ = compilerRuntime.c(3);
998
- const {
999
- scopeId
1000
- } = options;
1001
- const allQueries = jotai.useAtomValue(queriesAtom);
1002
- const prefix = `${scopeId}:`;
1003
- let scopeQueries;
1004
- if ($[0] !== allQueries || $[1] !== prefix) {
1005
- scopeQueries = {};
1006
- for (const [key, value] of Object.entries(allQueries)) {
1007
- if (key.startsWith(prefix)) {
1008
- scopeQueries[key.slice(prefix.length)] = value;
1009
- }
1010
- }
1011
- $[0] = allQueries;
1012
- $[1] = prefix;
1013
- $[2] = scopeQueries;
1014
- } else {
1015
- scopeQueries = $[2];
1016
- }
1017
- return scopeQueries;
1018
- }
1019
- /**
1020
- * Hook to read all mutations for a scope.
1021
- */
1022
- function useJotaiMutations(options) {
1023
- const $ = compilerRuntime.c(3);
1024
- const {
1025
- scopeId
1026
- } = options;
1027
- const allMutations = jotai.useAtomValue(mutationsAtom);
1028
- const prefix = `${scopeId}:`;
1029
- let scopeMutations;
1030
- if ($[0] !== allMutations || $[1] !== prefix) {
1031
- scopeMutations = {};
1032
- for (const [key, value] of Object.entries(allMutations)) {
1033
- if (key.startsWith(prefix)) {
1034
- scopeMutations[key.slice(prefix.length)] = value;
1035
- }
1036
- }
1037
- $[0] = allMutations;
1038
- $[1] = prefix;
1039
- $[2] = scopeMutations;
1040
- } else {
1041
- scopeMutations = $[2];
1042
- }
1043
- return scopeMutations;
1044
- }const getValueAtPath$2 = (obj, path, defaultObj) => {
1045
- if (!path) return undefined;
1046
- const normalized = path.replace(/\[(\d+)\]/g, ".$1");
1047
- const parts = normalized.split(".").filter(Boolean);
1048
- let current = obj;
1049
- for (let index = 0; index < parts.length; index++) {
1050
- const part = parts[index];
1051
- if (current == null) return undefined;
1052
- if (typeof current !== "object") return undefined;
1053
- const record = current;
1054
- // Only apply the default entry when the *root* key is missing (e.g. queryKey not found).
1055
- // For deeper missing paths, return undefined so callers can use the provided defaultValue.
1056
- if (!(part in record)) {
1057
- if (index === 0 && defaultObj !== undefined) {
1058
- current = defaultObj;
1059
- continue;
1060
- }
1061
- return undefined;
1062
- }
1063
- current = record[part];
1064
- }
1065
- return current;
1066
- };
1067
- const useApiValues = ({
1068
- scopeId
1069
- }) => {
1070
- const allQuery = useJotaiQueries({
1071
- scopeId
1072
- });
1073
- const allMutation = useJotaiMutations({
1074
- scopeId
1075
- });
1076
- const subscriptions = React.useRef(new Map());
1077
- const [trigger, setTrigger] = React.useState(0);
1078
- const dataRef = React.useRef({
1079
- query: allQuery,
1080
- mutation: allMutation
1081
- });
1082
- // Sync dataRef with latest values
1083
- React.useEffect(() => {
1084
- let internalTrigger = false;
1085
- const currentQuery = dataRef.current.query;
1086
- subscriptions.current.forEach((_, key) => {
1087
- const [type, keyPath] = key.split(":");
1088
- if (type === "query") {
1089
- const newValue = getValueAtPath$2(allQuery, keyPath);
1090
- const oldValue = getValueAtPath$2(currentQuery, keyPath);
1091
- // console.log(key, !equal(newValue, oldValue), newValue, oldValue)
1092
- if (!equal(newValue, oldValue)) {
1093
- internalTrigger = true;
1094
- }
1095
- }
1096
- if (type === "mutation") {
1097
- const newValue = getValueAtPath$2(allMutation, keyPath);
1098
- const oldValue = getValueAtPath$2(dataRef.current.mutation, keyPath);
1099
- if (!equal(newValue, oldValue)) {
1100
- internalTrigger = true;
1101
- }
1102
- }
1103
- });
1104
- dataRef.current = {
1105
- query: allQuery,
1106
- mutation: allMutation
1107
- };
1108
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1109
- if (internalTrigger) {
1110
- setTrigger(v => v + 1);
1111
- }
1112
- }, [allQuery, allMutation]);
1113
- // get che legge dallo store e registra le dipendenze
1114
- const get = React.useCallback((type, key, defaultValue) => {
1115
- var _a;
1116
- const keyMap = `${type}:${key}`;
1117
- const defaultQueries = type === "query" ? DEFAULT_QUERY_ENTRY :
1118
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1119
- type === "mutation" ? DEFAULT_MUTATION_ENTRY : undefined;
1120
- const value = (_a = getValueAtPath$2(dataRef.current[type], String(key), defaultQueries)) !== null && _a !== void 0 ? _a : defaultValue;
1121
- subscriptions.current.set(keyMap, value);
1122
- return subscriptions.current.get(keyMap);
1123
- },
1124
- // eslint-disable-next-line react-hooks/exhaustive-deps
1125
- [trigger]);
1126
- return {
1127
- get
1128
- };
1129
- };new TextEncoder();
1130
- new TextDecoder();const DefaultContainer$1 = ({
1131
- children
1132
- }) => {
1133
- return children;
1134
- };
1135
- // Lazy initialization to avoid side effects at module load time
1136
- const _formConfig = {
1137
- formFieldContainer: DefaultContainer$1
1138
- };
1139
- const {
1140
- useValue: useFormConfigValue} = atomStateGenerator({
1141
- key: 'formConfig',
1142
- defaultValue: _formConfig,
1143
- persist: false
1144
- });/* eslint-disable @typescript-eslint/no-explicit-any */
1145
- function useJotaiForm(formOptions) {
1146
- const form = reactForm.useForm(formOptions);
1147
- return form;
1148
- }const FormField = ({
1149
- config,
1150
- onFieldChange,
1151
- ns: globalNs,
1152
- globalErrorNs
1153
- }) => {
1154
- var _a, _b;
1155
- const ns = (_a = config.ns) !== null && _a !== void 0 ? _a : globalNs;
1156
- const errorNs = (_b = config.errorNs) !== null && _b !== void 0 ? _b : globalErrorNs;
1157
- const {
1158
- formFieldContainer,
1159
- translateText
1160
- } = useFormConfigValue();
1161
- // TanStack Form uses field.state.meta.errors which is an array of ValidationError
1162
- const firstError = config.field.state.meta.errors.length > 0 ? config.field.state.meta.errors[0] : undefined;
1163
- const errorMessageStr = firstError ? String(firstError) : undefined;
1164
- const errorMessage = React.useMemo(() => {
1165
- if (!errorMessageStr) return undefined;
1166
- return errorNs ? translateText === null || translateText === void 0 ? void 0 : translateText(errorMessageStr, {
1167
- ns: errorNs || '',
1168
- defaultValue: ''
1169
- }) : errorMessageStr;
1170
- }, [errorMessageStr, errorNs, translateText]);
1171
- const label = React.useMemo(() => {
1172
- var _a_0;
1173
- return ns ? translateText === null || translateText === void 0 ? void 0 : translateText((_a_0 = config.label) !== null && _a_0 !== void 0 ? _a_0 : '') : config.label;
1174
- }, [ns, config.label, translateText]);
1175
- const helperMessage = React.useMemo(() => {
1176
- var _a_1;
1177
- return ((_a_1 = config.helper) === null || _a_1 === void 0 ? void 0 : _a_1.text) ? translateText === null || translateText === void 0 ? void 0 : translateText(config.helper.text, config.helper.translationOption) : '';
1178
- }, [config.helper, translateText]);
1179
- const ref = React.useRef({
1180
- onFieldChange,
1181
- handleChange: config.field.handleChange
1182
- });
1183
- React.useEffect(() => {
1184
- ref.current = {
1185
- onFieldChange,
1186
- handleChange: config.field.handleChange
1187
- };
1188
- }, [config.field.handleChange, onFieldChange]);
1189
- const handleChange = React.useCallback(value => {
1190
- var _a_2, _b_0;
1191
- // TanStack Form handleChange usually expects just the value for input
1192
- // but if we are manually calling it we should pass the value.
1193
- ref.current.handleChange(value);
1194
- (_b_0 = (_a_2 = ref.current).onFieldChange) === null || _b_0 === void 0 ? void 0 : _b_0.call(_a_2, value);
1195
- }, []);
1196
- const handleBlur = React.useCallback(() => {
1197
- config.field.handleBlur();
1198
- }, [config.field]);
1199
- const baseProps = React.useMemo(() => ({
1200
- value: config.field.state.value,
1201
- onChange: handleChange,
1202
- onBlur: handleBlur,
1203
- error: config.field.state.meta.errors.length > 0,
1204
- errorMessage,
1205
- label,
1206
- helperMessage
1207
- }), [config.field.state.value, handleChange, handleBlur, config.field.state.meta.errors.length, errorMessage, label, helperMessage]);
1208
- const ConfigContainer = React.useMemo(() => config.container, [config.container]);
1209
- const FormFieldContainer = React.useMemo(() => formFieldContainer, [formFieldContainer]);
1210
- if (ConfigContainer) {
1211
- return jsxRuntime.jsx(ConfigContainer, {
1212
- children: config.component(baseProps)
1213
- });
1214
- }
1215
- return jsxRuntime.jsx(FormFieldContainer, {
1216
- children: config.component(baseProps)
1217
- });
1218
- };const DEFAULT_FORM_ENTRY = Object.freeze({
1219
- formValues: {},
1220
- setValue: () => {}
1221
- });
1222
- /**
1223
- * Global atom storing all form state.
1224
- * Key format: "scopeId:formId" or just "formId" for backward compatibility.
1225
- */
1226
- const formAtom = jotai.atom({});
1227
- const createFormSelector = formId => utils.selectAtom(formAtom, forms => {
1228
- const entry = forms[formId];
1229
- return entry !== null && entry !== void 0 ? entry : DEFAULT_FORM_ENTRY;
1230
- }, (a, b) => a === b || a.formValues === b.formValues && a.setValue === b.setValue);
1231
- const useFormValue = formId => {
1232
- const $ = compilerRuntime.c(2);
1233
- let t0;
1234
- if ($[0] !== formId) {
1235
- t0 = createFormSelector(formId);
1236
- $[0] = formId;
1237
- $[1] = t0;
1238
- } else {
1239
- t0 = $[1];
1240
- }
1241
- const selectorAtom = t0;
1242
- return jotai.useAtomValue(selectorAtom);
1243
- };
1244
- const useSetFormState = formId => {
1245
- const setForms = jotai.useSetAtom(formAtom);
1246
- return React.useCallback(val => {
1247
- setForms(prev => {
1248
- var _a;
1249
- const prevEntry = (_a = prev[formId]) !== null && _a !== void 0 ? _a : DEFAULT_FORM_ENTRY;
1250
- return Object.assign(Object.assign({}, prev), {
1251
- [formId]: Object.assign(Object.assign({}, prevEntry), val)
1252
- });
1253
- });
1254
- }, [formId, setForms]);
1255
- };const getValueAtPath$1 = (obj, path, defaultObj) => {
1256
- if (!path) return undefined;
1257
- const normalized = path.replace(/\[(\d+)\]/g, '.$1');
1258
- const parts = normalized.split('.').filter(Boolean);
1259
- let current = obj;
1260
- for (const part of parts) {
1261
- if (!current || !Object.keys(current).length) {
1262
- return undefined;
1263
- }
1264
- if (typeof current !== 'object') return undefined;
1265
- current = current[part];
1266
- }
1267
- return current;
1268
- };
1269
- const useFormValues = ({
1270
- formId
1271
- }) => {
1272
- // We subscribe to the specific form entry in the atoms
1273
- // Note: This subscription is a bit coarse (entire form entry), but we optimize re-renders locally
1274
- // Ideally we would want to subscribe only to specific paths, but Jotai atoms are per-form.
1275
- const formEntry = useFormValue(formId);
1276
- const currentValues = React.useMemo(() => formEntry.formValues, [formEntry.formValues]);
1277
- const subscriptions = React.useRef(new Map());
1278
- // trigger state is used to force re-render when a subscribed value changes
1279
- const [trigger, setTrigger] = React.useState(0);
1280
- // Ref to hold the latest values without causing re-renders itself
1281
- const formRef = React.useRef({
1282
- formValues: formEntry.formValues,
1283
- setValue: formEntry.setValue
1284
- });
1285
- React.useEffect(() => {
1286
- formRef.current.setValue = formEntry.setValue;
1287
- }, [formEntry.setValue]);
1288
- React.useEffect(() => {
1289
- let shouldTrigger = false;
1290
- subscriptions.current.forEach((_, path) => {
1291
- const newValue = getValueAtPath$1(currentValues, path);
1292
- const oldValue = getValueAtPath$1(formRef.current.formValues, path);
1293
- if (!equal(newValue, oldValue)) {
1294
- shouldTrigger = true;
1295
- }
1296
- });
1297
- formRef.current.formValues = currentValues;
1298
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1299
- if (shouldTrigger) {
1300
- setTrigger(c => c + 1);
1301
- }
1302
- }, [currentValues]);
1303
- const get = React.useCallback((key, defaultValue) => {
1304
- var _a;
1305
- const val = (_a = getValueAtPath$1(formRef.current.formValues, key)) !== null && _a !== void 0 ? _a : defaultValue;
1306
- subscriptions.current.set(key, val);
1307
- return subscriptions.current.get(key);
1308
- },
1309
- // eslint-disable-next-line react-hooks/exhaustive-deps
1310
- [trigger]);
1311
- const set = React.useCallback((field, value) => {
1312
- formRef.current.setValue(field, value);
1313
- }, []);
1314
- return {
1315
- get,
1316
- set
1317
- };
1318
- };const trimObject = obj => Object.entries(obj !== null && obj !== void 0 ? obj : {}).reduce((prev, [key, val]) => Object.assign(Object.assign({}, prev), {
1319
- [key]: typeof val === 'string' && !['password', 'pPassword'].includes(key) ? val.trim() : val
1320
- }), {});
1321
- const RenderField = t0 => {
1322
- const $ = compilerRuntime.c(9);
1323
- const {
1324
- field,
1325
- fieldState,
1326
- fieldProps,
1327
- onFieldChange
1328
- } = t0;
1329
- let t1;
1330
- if ($[0] !== field || $[1] !== fieldProps || $[2] !== fieldState) {
1331
- t1 = Object.assign(Object.assign({}, fieldProps), {
1332
- field,
1333
- fieldState
1334
- });
1335
- $[0] = field;
1336
- $[1] = fieldProps;
1337
- $[2] = fieldState;
1338
- $[3] = t1;
1339
- } else {
1340
- t1 = $[3];
1341
- }
1342
- const config = t1;
1343
- let t2;
1344
- if ($[4] !== config || $[5] !== fieldProps.errorNs || $[6] !== fieldProps.ns || $[7] !== onFieldChange) {
1345
- t2 = jsxRuntime.jsx(FormField, {
1346
- config,
1347
- ns: fieldProps.ns,
1348
- globalErrorNs: fieldProps.errorNs,
1349
- onFieldChange
1350
- });
1351
- $[4] = config;
1352
- $[5] = fieldProps.errorNs;
1353
- $[6] = fieldProps.ns;
1354
- $[7] = onFieldChange;
1355
- $[8] = t2;
1356
- } else {
1357
- t2 = $[8];
1358
- }
1359
- return t2;
1360
- };
1361
- const DynamicFieldItem = ({
1362
- item,
1363
- form,
1364
- globalErrorNs,
1365
- formId
1366
- }) => {
1367
- const {
1368
- get,
1369
- set
1370
- } = useFormValues({
1371
- formId
1372
- });
1373
- const fieldProps = React.useMemo(() => {
1374
- if (typeof item === 'function') {
1375
- return item({
1376
- get,
1377
- set
1378
- });
1379
- } else {
1380
- return item;
1381
- }
1382
- }, [get, set, item]);
1383
- const isHidden = React.useMemo(() => {
1384
- if (!fieldProps.hidden) {
1385
- return false;
1386
- } else if (typeof fieldProps.hidden === 'function') {
1387
- return fieldProps.hidden({
1388
- get,
1389
- set
1390
- });
1391
- } else {
1392
- return !!fieldProps.hidden;
1393
- }
1394
- }, [get, set, fieldProps]);
1395
- const rules = React.useMemo(() => {
1396
- if (!fieldProps.rules) {
1397
- return undefined;
1398
- } else if (typeof fieldProps.rules === 'function') {
1399
- return fieldProps.rules({
1400
- get,
1401
- set
1402
- });
1403
- } else {
1404
- return fieldProps.rules;
1405
- }
1406
- }, [get, set, fieldProps]);
1407
- const props = React.useMemo(() => {
1408
- var _a;
1409
- return Object.assign(Object.assign({}, fieldProps), {
1410
- errorNs: (_a = fieldProps.errorNs) !== null && _a !== void 0 ? _a : globalErrorNs
1411
- });
1412
- }, [fieldProps, globalErrorNs]);
1413
- if (isHidden) {
1414
- return jsxRuntime.jsx(jsxRuntime.Fragment, {});
1415
- }
1416
- return jsxRuntime.jsx(form.Field, {
1417
- name: props.name,
1418
- validators: rules,
1419
- // eslint-disable-next-line react/no-children-prop
1420
- children: field => jsxRuntime.jsx(RenderField, {
1421
- field: field,
1422
- fieldState: field.state,
1423
- fieldProps: props,
1424
- onFieldChange: props.onFieldChange
1425
- })
1426
- });
1427
- };
1428
- const SubmitItem = ({
1429
- item,
1430
- index,
1431
- handlersRef
1432
- }) => {
1433
- const handleClick = React.useCallback(async () => {
1434
- const {
1435
- formControl,
1436
- createSubmitHandler,
1437
- onInvalidHandle
1438
- } = handlersRef.current;
1439
- // Partial or full validation logic
1440
- let isValid = true;
1441
- const keys = item.values;
1442
- if (keys && keys.length > 0) {
1443
- // Validate only specific fields
1444
- await Promise.all(keys.map(key => formControl.validateField(key, 'change')));
1445
- const hasError = keys.some(key_0 => {
1446
- // This is a simplified check. TanStack form errors might be structured differently.
1447
- // You might need deep checking if errors are nested objects.
1448
- // For now assume flat or use lodash get if possible, but state.errors is usually flat-ish map in newer versions or object.
1449
- // Checking standard TanStack: form.state.fieldMeta[key]?.errors
1450
- const meta = formControl.getFieldMeta(key_0);
1451
- return (meta === null || meta === void 0 ? void 0 : meta.errors) && meta.errors.length > 0;
1452
- });
1453
- isValid = !hasError;
1454
- } else {
1455
- // Validate all
1456
- await formControl.validateAllFields('submit');
1457
- isValid = formControl.state.isValid;
1458
- }
1459
- if (!isValid) {
1460
- onInvalidHandle(formControl.state.errors, item);
1461
- return;
1462
- }
1463
- const values = formControl.state.values;
1464
- // Call handlers
1465
- await createSubmitHandler(item)(values);
1466
- }, [item, handlersRef]);
1467
- const Component = React.useMemo(() => item.component, [item]);
1468
- if (item.hidden || !Component) return jsxRuntime.jsx(jsxRuntime.Fragment, {});
1469
- return jsxRuntime.jsx(Component, {
1470
- onClick: handleClick,
1471
- index: index,
1472
- type: item.type || 'button'
1473
- }, `submit-${index}`);
1474
- };
1475
- const useFormManager = ({
1476
- data,
1477
- onInvalid,
1478
- submit = [],
1479
- notification,
1480
- formOptions,
1481
- onValuesChange,
1482
- globalErrorNs,
1483
- id = 'form-manager'
1484
- }) => {
1485
- const formControl = useJotaiForm(formOptions);
1486
- const formState = React.useMemo(() => formControl.state, [formControl.state]);
1487
- const errors = React.useMemo(() => formState.errors, [formState.errors]);
1488
- const values = React.useMemo(() => formState.values, [formState.values]);
1489
- const setFormState = useSetFormState(id);
1490
- const {
1491
- showNotification
1492
- } = useFormConfigValue();
1493
- const setValue = React.useCallback((field, updater) => formControl.setFieldValue(field, updater), [formControl]);
1494
- React.useEffect(() => {
1495
- setFormState({
1496
- setValue,
1497
- formValues: formState.values
1498
- });
1499
- const unsubscribe = formControl.store.subscribe(store => {
1500
- setFormState({
1501
- formValues: store.currentVal.values
1502
- });
1503
- });
1504
- return () => {
1505
- unsubscribe();
1506
- }; /**/
1507
- }, [formControl.store, setValue, formState.values, setFormState]);
1508
- const handleNotification = React.useCallback(props => {
1509
- if (props.message) {
1510
- showNotification === null || showNotification === void 0 ? void 0 : showNotification(props);
1511
- }
1512
- }, [showNotification]);
1513
- const filterFormData = React.useCallback((v, submitConfig) => {
1514
- const keys = submitConfig.values;
1515
- if (!keys || keys.length === 0) {
1516
- return v;
1517
- }
1518
- const out = {};
1519
- for (const key of keys) {
1520
- if (key in v) {
1521
- out[key] = v[key];
1522
- }
1523
- }
1524
- return out;
1525
- }, []);
1526
- const processSubmit = React.useCallback(async (d, submitConfig_0) => {
1527
- const filteredData = filterFormData(d, submitConfig_0);
1528
- if (submitConfig_0.onSuccess) {
1529
- return await submitConfig_0.onSuccess(filteredData);
1530
- }
1531
- throw new Error('No submit handler provided');
1532
- }, [filterFormData]);
1533
- const handleError = React.useCallback((error, submitConfig_1) => {
1534
- if (submitConfig_1.onError) {
1535
- submitConfig_1.onError(error);
1536
- }
1537
- const notificationProps = typeof (notification === null || notification === void 0 ? void 0 : notification.error) === 'function' ? notification.error(error.message) : notification === null || notification === void 0 ? void 0 : notification.error;
1538
- if (notificationProps === null || notificationProps === void 0 ? void 0 : notificationProps.message) {
1539
- handleNotification(notificationProps);
1540
- }
1541
- }, [handleNotification, notification]);
1542
- const createSubmitHandler = React.useCallback(submitConfig_2 => async dataSubmit => {
1543
- try {
1544
- const res = await processSubmit(trimObject(dataSubmit), submitConfig_2);
1545
- const notificationProps_0 = typeof (notification === null || notification === void 0 ? void 0 : notification.success) === 'function' ? notification.success(res) : notification === null || notification === void 0 ? void 0 : notification.success;
1546
- if (notificationProps_0 === null || notificationProps_0 === void 0 ? void 0 : notificationProps_0.message) {
1547
- handleNotification(notificationProps_0);
1548
- }
1549
- return res;
1550
- } catch (error_0) {
1551
- handleError(error_0, submitConfig_2);
1552
- throw error_0;
1553
- }
1554
- }, [processSubmit, notification, handleNotification, handleError]);
1555
- const onInvalidHandle = React.useCallback((err, submitConfig_3) => {
1556
- onInvalid === null || onInvalid === void 0 ? void 0 : onInvalid(err);
1557
- handleError(new Error('invalidData'), submitConfig_3);
1558
- }, [handleError, onInvalid]);
1559
- const handlersRef = React.useRef({
1560
- formControl,
1561
- onInvalidHandle,
1562
- createSubmitHandler,
1563
- setValue: formControl.setFieldValue,
1564
- trigger: formControl.validateField,
1565
- onValuesChange
1566
- });
1567
- React.useEffect(() => {
1568
- handlersRef.current.onInvalidHandle = onInvalidHandle;
1569
- handlersRef.current.createSubmitHandler = createSubmitHandler;
1570
- handlersRef.current.setValue = formControl.setFieldValue;
1571
- handlersRef.current.trigger = formControl.validateField;
1572
- handlersRef.current.onValuesChange = onValuesChange;
1573
- }, [onInvalidHandle, createSubmitHandler, formControl, onValuesChange]);
1574
- const fields = React.useMemo(() => data.map((item, index) => {
1575
- var _a, _b;
1576
- const staticItem = typeof item === 'function' ? null : item;
1577
- return {
1578
- index: (_a = staticItem === null || staticItem === void 0 ? void 0 : staticItem.index) !== null && _a !== void 0 ? _a : index,
1579
- element: jsxRuntime.jsx(DynamicFieldItem, {
1580
- item: item,
1581
- form: formControl,
1582
- globalErrorNs: globalErrorNs,
1583
- formId: id
1584
- }, (_b = staticItem === null || staticItem === void 0 ? void 0 : staticItem.name) !== null && _b !== void 0 ? _b : index),
1585
- renderInFooter: !!(staticItem === null || staticItem === void 0 ? void 0 : staticItem.renderInFooter),
1586
- renderInHeader: !!(staticItem === null || staticItem === void 0 ? void 0 : staticItem.renderInHeader)
1587
- };
1588
- }), [data, formControl, globalErrorNs, id]);
1589
- const submits = React.useMemo(() => submit.map((submitConfig_4, index_0) => {
1590
- return {
1591
- index: submitConfig_4.index === undefined ? index_0 : submitConfig_4.index,
1592
- element: jsxRuntime.jsx(SubmitItem, {
1593
- item: submitConfig_4,
1594
- index: index_0,
1595
- handlersRef: handlersRef
1596
- }, `submit-${index_0}`),
1597
- renderInFooter: !!submitConfig_4.renderInFooter,
1598
- renderInHeader: !!submitConfig_4.renderInHeader,
1599
- isSubmit: true
1600
- };
1601
- }), [submit]);
1602
- const elements = React.useMemo(() => fields.concat(submits), [fields, submits]);
1603
- const formContents = React.useMemo(() => [...data, ...submit], [data, submit]);
1604
- React.useEffect(() => {
1605
- var _a_0, _b_0;
1606
- (_b_0 = (_a_0 = handlersRef.current).onValuesChange) === null || _b_0 === void 0 ? void 0 : _b_0.call(_a_0, values, handlersRef.current.setValue);
1607
- }, [values]);
1608
- return {
1609
- elements,
1610
- formContents,
1611
- errors,
1612
- formValues: values,
1613
- setValue
1614
- };
1615
28
  };/* eslint-disable @typescript-eslint/no-explicit-any */
1616
29
  /**
1617
30
  * Optimized shallow equality check for objects and functions
@@ -1793,30 +206,30 @@ const usePageValues = ({
1793
206
  }) => {
1794
207
  const {
1795
208
  get: getApiValues
1796
- } = useApiValues({
209
+ } = reactQueries.useApiValues({
1797
210
  scopeId: pageId
1798
211
  });
1799
212
  const {
1800
213
  get: getFormValues,
1801
214
  set: setFormValues
1802
- } = useFormValues({
215
+ } = reactForm.useFormValues({
1803
216
  formId: pageId
1804
217
  });
1805
- const subscriptions = React.useRef(new Map());
1806
- const [trigger, setTrigger] = React.useState(0);
218
+ const subscriptions = react.useRef(new Map());
219
+ const [trigger, setTrigger] = react.useState(0);
1807
220
  const [pageVariables, setPageVariables] = jotai.useAtom(pageVariablesAtomFamily(pageId));
1808
- const initialized = React.useRef(false);
1809
- React.useEffect(() => {
221
+ const initialized = react.useRef(false);
222
+ react.useEffect(() => {
1810
223
  if (!initialized.current && initialValues) {
1811
224
  setPageVariables(initialValues);
1812
225
  initialized.current = true;
1813
226
  }
1814
227
  }, [initialValues, setPageVariables]);
1815
- const dataRef = React.useRef({
228
+ const dataRef = react.useRef({
1816
229
  state: pageVariables
1817
230
  });
1818
231
  // Sync dataRef with latest values
1819
- React.useEffect(() => {
232
+ react.useEffect(() => {
1820
233
  let internalTrigger = false;
1821
234
  subscriptions.current.forEach((_, key) => {
1822
235
  const [type, keyPath] = key.split(':');
@@ -1835,7 +248,7 @@ const usePageValues = ({
1835
248
  }
1836
249
  }, [pageVariables]);
1837
250
  // get che legge dallo store e registra le dipendenze
1838
- const get = React.useCallback((type, key, defaultValue) => {
251
+ const get = react.useCallback((type, key, defaultValue) => {
1839
252
  var _a;
1840
253
  const keyMap = `${type}:${key}`;
1841
254
  switch (type) {
@@ -1869,7 +282,7 @@ const usePageValues = ({
1869
282
  // eslint-disable-next-line react-hooks/exhaustive-deps
1870
283
  [pageId, trigger, getApiValues, getFormValues]);
1871
284
  // set stabile
1872
- const set = React.useCallback(type => {
285
+ const set = react.useCallback(type => {
1873
286
  if (type === 'form') {
1874
287
  return setFormValues;
1875
288
  }
@@ -1899,7 +312,7 @@ const PageContentItemInner = ({
1899
312
  } = usePageValues({
1900
313
  pageId
1901
314
  });
1902
- const isHidden = React.useMemo(() => {
315
+ const isHidden = react.useMemo(() => {
1903
316
  if (typeof item.hidden === 'function') {
1904
317
  return item.hidden({
1905
318
  get,
@@ -1915,7 +328,7 @@ const PageContentItemInner = ({
1915
328
  pageId: pageId
1916
329
  }, (_a = item.key) !== null && _a !== void 0 ? _a : '');
1917
330
  };
1918
- const PageContentItem = React.memo(PageContentItemInner);
331
+ const PageContentItem = react.memo(PageContentItemInner);
1919
332
  const useGenerateContentRender = ({
1920
333
  pageId,
1921
334
  ns = '',
@@ -1928,7 +341,7 @@ const useGenerateContentRender = ({
1928
341
  } = usePageValues({
1929
342
  pageId
1930
343
  });
1931
- const contentsWithQueriesDeps = React.useMemo(() => {
344
+ const contentsWithQueriesDeps = react.useMemo(() => {
1932
345
  if (typeof contents === 'function') {
1933
346
  return contents({
1934
347
  get,
@@ -1938,14 +351,14 @@ const useGenerateContentRender = ({
1938
351
  return Array.isArray(contents) ? contents : [];
1939
352
  }, [contents, get, set]);
1940
353
  // Memoize form elements separately - only recalculate when formData.elements changes
1941
- const formElementsWithKey = React.useMemo(() => {
354
+ const formElementsWithKey = react.useMemo(() => {
1942
355
  if (!Array.isArray(formData.elements)) return [];
1943
356
  return formData.elements.map((el, idx) => Object.assign(Object.assign({}, el), {
1944
357
  key: `form-element-${el.index || idx}`
1945
358
  }));
1946
359
  }, [formData.elements]);
1947
360
  // Memoize dynamic elements - only recalculate when contents change
1948
- const dynamicElements = React.useMemo(() => contentsWithQueriesDeps.map((content, index) => {
361
+ const dynamicElements = react.useMemo(() => contentsWithQueriesDeps.map((content, index) => {
1949
362
  var _a;
1950
363
  const stableKey = getStableKey(content, index);
1951
364
  return {
@@ -1961,7 +374,7 @@ const useGenerateContentRender = ({
1961
374
  };
1962
375
  }), [contentsWithQueriesDeps, ns, pageId]);
1963
376
  // Merge and sort - only when either array changes
1964
- const memorizedContents = React.useMemo(() => [...dynamicElements, ...formElementsWithKey].sort((a, b) => a.index - b.index || String(a.key).localeCompare(String(b.key))), [dynamicElements, formElementsWithKey]);
377
+ const memorizedContents = react.useMemo(() => [...dynamicElements, ...formElementsWithKey].sort((a, b) => a.index - b.index || String(a.key).localeCompare(String(b.key))), [dynamicElements, formElementsWithKey]);
1965
378
  return {
1966
379
  components: memorizedContents,
1967
380
  allContents: [...contentsWithQueriesDeps, ...formData.formContents]
@@ -2770,7 +1183,7 @@ function resolveMetadata(meta, ctx) {
2770
1183
  resolved.customMeta = customMeta;
2771
1184
  }
2772
1185
  return resolved;
2773
- }const MetadataStoreContext = React.createContext(null);
1186
+ }const MetadataStoreContext = react.createContext(null);
2774
1187
  /**
2775
1188
  * Provides a request-scoped MetadataStore via React Context.
2776
1189
  *
@@ -2824,7 +1237,7 @@ function MetadataStoreProvider(t0) {
2824
1237
  * Returns `null` if no provider is found (falls back to global store in consumers).
2825
1238
  */
2826
1239
  function useMetadataStore() {
2827
- return React.useContext(MetadataStoreContext);
1240
+ return react.useContext(MetadataStoreContext);
2828
1241
  }/**
2829
1242
  * Optional dev-only metadata logging.
2830
1243
  *
@@ -2887,9 +1300,9 @@ let _pageConfig = {
2887
1300
  HeaderContainer: DefaultContainer,
2888
1301
  FooterContainer: DefaultContainer,
2889
1302
  BodyContainer: DefaultContainer,
2890
- authPageImage: '',
1303
+ authPageImage: "",
2891
1304
  authPageProps: {
2892
- id: 'auth-page'
1305
+ id: "auth-page"
2893
1306
  },
2894
1307
  isLogged: val => !!(val === null || val === void 0 ? void 0 : val.id) && !!val.isLogged,
2895
1308
  ItemsContainer: ({
@@ -2899,8 +1312,8 @@ let _pageConfig = {
2899
1312
  children
2900
1313
  }) => children,
2901
1314
  meta: {
2902
- title: '',
2903
- description: ''
1315
+ title: "",
1316
+ description: ""
2904
1317
  },
2905
1318
  // Metadata configuration
2906
1319
  defaultMetadata: {},
@@ -2913,7 +1326,7 @@ let _pageConfig = {
2913
1326
  preloadOnHover: false,
2914
1327
  preloadOnFocus: false,
2915
1328
  timeout: 30000,
2916
- logMetrics: process.env.NODE_ENV === 'development'
1329
+ logMetrics: process.env.NODE_ENV === "development"
2917
1330
  }
2918
1331
  };
2919
1332
  /**
@@ -2925,9 +1338,9 @@ function initializePageConfig() {
2925
1338
  HeaderContainer: DefaultContainer,
2926
1339
  FooterContainer: DefaultContainer,
2927
1340
  BodyContainer: DefaultContainer,
2928
- authPageImage: '',
1341
+ authPageImage: "",
2929
1342
  authPageProps: {
2930
- id: 'auth-page'
1343
+ id: "auth-page"
2931
1344
  },
2932
1345
  isLogged: val => !!(val === null || val === void 0 ? void 0 : val.id) && !!val.isLogged,
2933
1346
  ItemsContainer: ({
@@ -2937,8 +1350,8 @@ function initializePageConfig() {
2937
1350
  children
2938
1351
  }) => children,
2939
1352
  meta: {
2940
- title: '',
2941
- description: ''
1353
+ title: "",
1354
+ description: ""
2942
1355
  },
2943
1356
  // Metadata configuration
2944
1357
  defaultMetadata: {},
@@ -2951,7 +1364,7 @@ function initializePageConfig() {
2951
1364
  preloadOnHover: false,
2952
1365
  preloadOnFocus: false,
2953
1366
  timeout: 30000,
2954
- logMetrics: process.env.NODE_ENV === 'development'
1367
+ logMetrics: process.env.NODE_ENV === "development"
2955
1368
  }
2956
1369
  };
2957
1370
  return _pageConfig;
@@ -2965,8 +1378,8 @@ const {
2965
1378
  useValue: usePageConfigValue,
2966
1379
  useState: usePageConfigState,
2967
1380
  useReset: usePageConfigReset
2968
- } = atomStateGenerator({
2969
- key: 'pageConfig',
1381
+ } = reactState.atomStateGenerator({
1382
+ key: "pageConfig",
2970
1383
  defaultValue: _pageConfig,
2971
1384
  persist: false
2972
1385
  });/**
@@ -3029,7 +1442,7 @@ function useFormData({
3029
1442
  } = usePageValues({
3030
1443
  pageId
3031
1444
  });
3032
- const hiddenMapped = React.useCallback(() => {
1445
+ const hiddenMapped = react.useCallback(() => {
3033
1446
  const isHidden = form === null || form === void 0 ? void 0 : form.hidden;
3034
1447
  if (!isHidden) return false;
3035
1448
  if (typeof isHidden === 'function') {
@@ -3041,7 +1454,7 @@ function useFormData({
3041
1454
  return !!isHidden;
3042
1455
  }
3043
1456
  }, [form === null || form === void 0 ? void 0 : form.hidden, get, set]);
3044
- const mappedFormData = React.useMemo(() => {
1457
+ const mappedFormData = react.useMemo(() => {
3045
1458
  if (!(form === null || form === void 0 ? void 0 : form.data) || hiddenMapped()) return [];
3046
1459
  return form.data.map(el => {
3047
1460
  if (typeof el === 'function') {
@@ -3060,7 +1473,7 @@ function useFormData({
3060
1473
  });
3061
1474
  });
3062
1475
  }, [form, get, hiddenMapped, set]);
3063
- const formSubmit = React.useMemo(() => {
1476
+ const formSubmit = react.useMemo(() => {
3064
1477
  if (!(form === null || form === void 0 ? void 0 : form.submit) || hiddenMapped()) return [];
3065
1478
  const submitFn = form.submit;
3066
1479
  return (typeof submitFn === 'function' ? submitFn({
@@ -3085,9 +1498,9 @@ function useFormData({
3085
1498
  var _a_0;
3086
1499
  const {
3087
1500
  queryClient
3088
- } = useApiConfigValue();
3089
- const [defaultValueQuery, setDefaultValueQuery] = React.useState(form === null || form === void 0 ? void 0 : form.defaultValues);
3090
- React.useEffect(() => {
1501
+ } = reactQueries.useApiConfigValue();
1502
+ const [defaultValueQuery, setDefaultValueQuery] = react.useState(form === null || form === void 0 ? void 0 : form.defaultValues);
1503
+ react.useEffect(() => {
3091
1504
  if (!(form === null || form === void 0 ? void 0 : form.defaultValueQueryKey)) {
3092
1505
  // setDefaultValueQuery(form?.defaultValues)
3093
1506
  return;
@@ -3106,7 +1519,7 @@ function useFormData({
3106
1519
  });
3107
1520
  return () => unsubscribe();
3108
1521
  }, [form === null || form === void 0 ? void 0 : form.defaultValueQueryKey, form === null || form === void 0 ? void 0 : form.defaultValues, queryClient]);
3109
- const defaultValues = React.useMemo(() => {
1522
+ const defaultValues = react.useMemo(() => {
3110
1523
  var _a, _b;
3111
1524
  return Object.assign(Object.assign({}, defaultValueQuery !== null && defaultValueQuery !== void 0 ? defaultValueQuery : {}), (_b = (_a = form === null || form === void 0 ? void 0 : form.defaultValueQueryMap) === null || _a === void 0 ? void 0 : _a.call(form, defaultValueQuery)) !== null && _b !== void 0 ? _b : {});
3112
1525
  }, [defaultValueQuery, form]);
@@ -3118,7 +1531,7 @@ function useFormData({
3118
1531
  pageId
3119
1532
  });
3120
1533
  // Call useFormManager hook at top level (maintains hook order)
3121
- const rawFormData = useFormManager(Object.assign(Object.assign({}, form), {
1534
+ const rawFormData = reactForm.useFormManager(Object.assign(Object.assign({}, form), {
3122
1535
  data: mappedFormData,
3123
1536
  ns,
3124
1537
  submit: formSubmit,
@@ -3129,7 +1542,7 @@ function useFormData({
3129
1542
  formId: pageId
3130
1543
  })
3131
1544
  }));
3132
- const formData = React.useMemo(() => Object.assign(Object.assign({}, rawFormData), {
1545
+ const formData = react.useMemo(() => Object.assign(Object.assign({}, rawFormData), {
3133
1546
  formContents: rawFormData.formContents
3134
1547
  }), [rawFormData]);
3135
1548
  return {
@@ -3244,7 +1657,7 @@ const usePageConfig = t0 => {
3244
1657
  } else {
3245
1658
  t7 = $[17];
3246
1659
  }
3247
- useApi(processedQueries, t7);
1660
+ reactQueries.useApi(processedQueries, t7);
3248
1661
  let t8;
3249
1662
  if ($[18] !== pageId || $[19] !== viewSettings) {
3250
1663
  t8 = {
@@ -3300,7 +1713,7 @@ function useMetadata({
3300
1713
  translateText,
3301
1714
  locale
3302
1715
  } = usePageConfigValue();
3303
- const t = React.useMemo(() => translateText !== null && translateText !== void 0 ? translateText : key => key, [translateText]);
1716
+ const t = react.useMemo(() => translateText !== null && translateText !== void 0 ? translateText : key => key, [translateText]);
3304
1717
  const {
3305
1718
  get,
3306
1719
  set
@@ -3309,7 +1722,7 @@ function useMetadata({
3309
1722
  });
3310
1723
  const metadataStore = useMetadataStore();
3311
1724
  // Step 1: Evaluate metadata (if function)
3312
- const evaluatedMeta = React.useMemo(() => {
1725
+ const evaluatedMeta = react.useMemo(() => {
3313
1726
  if (!meta) return {};
3314
1727
  if (typeof meta === 'function') {
3315
1728
  return meta({
@@ -3320,12 +1733,12 @@ function useMetadata({
3320
1733
  return meta;
3321
1734
  }, [meta, get, set]);
3322
1735
  // Step 2: Resolve all dynamic evaluator functions into plain values
3323
- const resolved = React.useMemo(() => resolveMetadata(evaluatedMeta, {
1736
+ const resolved = react.useMemo(() => resolveMetadata(evaluatedMeta, {
3324
1737
  get,
3325
1738
  set
3326
1739
  }), [evaluatedMeta, get, set]);
3327
1740
  // Step 3: Translate metadata strings (i18n)
3328
- const translated = React.useMemo(() => {
1741
+ const translated = react.useMemo(() => {
3329
1742
  var _a;
3330
1743
  const result = Object.assign({}, resolved);
3331
1744
  // Translate basic fields
@@ -3396,7 +1809,7 @@ function useMetadata({
3396
1809
  return result;
3397
1810
  }, [resolved, t, locale]);
3398
1811
  // Step 4: Apply metadata
3399
- React.useEffect(() => {
1812
+ react.useEffect(() => {
3400
1813
  if (!autoApply) return;
3401
1814
  // If we have a request-scoped store (SSR), write to it
3402
1815
  if (metadataStore) {
@@ -3493,8 +1906,8 @@ const MetadataManager = MetadataManagerImpl;const PageGenerator = _a => {
3493
1906
  authValues,
3494
1907
  authPageProps
3495
1908
  } = usePageConfigValue();
3496
- const isUnlogged = React.useMemo(() => enableAuthControl && !isLogged(authValues ? authValues : null), [enableAuthControl, authValues, isLogged]);
3497
- const selectedProps = React.useMemo(() => {
1909
+ const isUnlogged = react.useMemo(() => enableAuthControl && !isLogged(authValues ? authValues : null), [enableAuthControl, authValues, isLogged]);
1910
+ const selectedProps = react.useMemo(() => {
3498
1911
  return enableAuthControl && isUnlogged ? authPageProps : props;
3499
1912
  }, [enableAuthControl, isUnlogged, authPageProps, props]);
3500
1913
  const {
@@ -3504,7 +1917,7 @@ const MetadataManager = MetadataManagerImpl;const PageGenerator = _a => {
3504
1917
  id = 'default-page-id',
3505
1918
  viewSettings,
3506
1919
  ns
3507
- } = React.useMemo(() => selectedProps, [selectedProps]);
1920
+ } = react.useMemo(() => selectedProps, [selectedProps]);
3508
1921
  const config = usePageConfig({
3509
1922
  queries,
3510
1923
  form,
@@ -3527,26 +1940,26 @@ const MetadataManager = MetadataManagerImpl;const PageGenerator = _a => {
3527
1940
  ns,
3528
1941
  pageConfig: config
3529
1942
  });
3530
- const LayoutComponent = React.useMemo(() => {
1943
+ const LayoutComponent = react.useMemo(() => {
3531
1944
  var _a_0;
3532
1945
  return (_a_0 = mappedViewSettings.layoutComponent) !== null && _a_0 !== void 0 ? _a_0 : BodyContainer;
3533
1946
  }, [mappedViewSettings.layoutComponent, BodyContainer]);
3534
- const layoutProps = React.useMemo(() => {
1947
+ const layoutProps = react.useMemo(() => {
3535
1948
  var _a_1;
3536
1949
  return (_a_1 = mappedViewSettings.layoutProps) !== null && _a_1 !== void 0 ? _a_1 : {};
3537
1950
  }, [mappedViewSettings.layoutProps]);
3538
- const PageContainerComponent = React.useMemo(() => {
1951
+ const PageContainerComponent = react.useMemo(() => {
3539
1952
  var _a_2;
3540
1953
  return (_a_2 = mappedViewSettings.pageContainerComponent) !== null && _a_2 !== void 0 ? _a_2 : PageContainer;
3541
1954
  }, [mappedViewSettings.pageContainerComponent, PageContainer]);
3542
- const pageContainerProps = React.useMemo(() => {
1955
+ const pageContainerProps = react.useMemo(() => {
3543
1956
  var _a_3;
3544
1957
  return (_a_3 = mappedViewSettings.pageContainerProps) !== null && _a_3 !== void 0 ? _a_3 : {};
3545
1958
  }, [mappedViewSettings.pageContainerProps]);
3546
- const layoutBody = React.useMemo(() => body, [body]);
1959
+ const layoutBody = react.useMemo(() => body, [body]);
3547
1960
  const store = jotai.useStore();
3548
- const refreshQueries = React.useCallback(() => {
3549
- const val = store.get(queriesAtom);
1961
+ const refreshQueries = react.useCallback(() => {
1962
+ const val = store.get(reactQueries.queriesAtom);
3550
1963
  Object.values(val).forEach(query => {
3551
1964
  query.refetch();
3552
1965
  });
@@ -3658,7 +2071,7 @@ const MetadataManager = MetadataManagerImpl;const PageGenerator = _a => {
3658
2071
  return t4;
3659
2072
  };
3660
2073
  // Export with React.memo and fast-deep-equal comparator for optimal performance
3661
- const Container = React.memo(ContainerImpl, (prevProps, nextProps) => {
2074
+ const Container = react.memo(ContainerImpl, (prevProps, nextProps) => {
3662
2075
  // Return true if props are equal (component should NOT re-render)
3663
2076
  return deepEqual(prevProps, nextProps);
3664
2077
  });
@@ -3718,7 +2131,7 @@ const RenderComponentImpl = ({
3718
2131
  }
3719
2132
  };
3720
2133
  // Export with React.memo and fast-deep-equal comparator for optimal performance
3721
- const RenderComponent = React.memo(RenderComponentImpl, (prevProps, nextProps) => {
2134
+ const RenderComponent = react.memo(RenderComponentImpl, (prevProps, nextProps) => {
3722
2135
  // Return true if props are equal (component should NOT re-render)
3723
2136
  return deepEqual(prevProps, nextProps);
3724
2137
  });const RenderComponents = props => {