@donotdev/ui 0.0.9 → 0.0.10
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/crud/components/fields/display/DateFieldDisplay.d.ts.map +1 -1
- package/dist/crud/components/fields/display/DateFieldDisplay.js +2 -3
- package/dist/crud/components/fields/display/LinkFieldDisplay.d.ts.map +1 -1
- package/dist/crud/components/fields/display/LinkFieldDisplay.js +6 -5
- package/dist/crud/components/fields/display/NumberFieldDisplay.d.ts.map +1 -1
- package/dist/crud/components/fields/display/NumberFieldDisplay.js +2 -3
- package/dist/crud/components/fields/display/PhoneNumberDisplay.d.ts.map +1 -1
- package/dist/crud/components/fields/display/PhoneNumberDisplay.js +1 -2
- package/dist/dndev.css +288 -143
- package/dist/index.js +5 -5
- package/dist/internal/common/RouteErrorFallback.d.ts.map +1 -1
- package/dist/internal/common/RouteErrorFallback.js +1 -2
- package/dist/internal/layout/DnDevLayout.d.ts.map +1 -1
- package/dist/internal/layout/DnDevLayout.js +3 -2
- package/dist/internal/layout/components/footer/FooterBranding.d.ts +0 -2
- package/dist/internal/layout/components/footer/FooterBranding.d.ts.map +1 -1
- package/dist/internal/layout/components/footer/FooterBranding.js +2 -6
- package/dist/internal/layout/components/footer/FooterCopyright.d.ts +0 -2
- package/dist/internal/layout/components/footer/FooterCopyright.d.ts.map +1 -1
- package/dist/internal/layout/components/footer/FooterCopyright.js +2 -6
- package/dist/internal/layout/config/presets/moolti.js +2 -2
- package/dist/internal/layout/zones/DnDevFooter.d.ts.map +1 -1
- package/dist/internal/layout/zones/DnDevFooter.js +2 -2
- package/dist/routing/GoTo.d.ts +1 -1
- package/dist/routing/GoTo.d.ts.map +1 -1
- package/dist/routing/GoTo.js +1 -1
- package/dist/routing/hooks/hooks.next.js +1 -1
- package/dist/routing/hooks/hooks.vite.js +1 -1
- package/dist/routing/hooks/useFormNavigationBlocker.d.ts +14 -0
- package/dist/routing/hooks/useFormNavigationBlocker.d.ts.map +1 -0
- package/dist/routing/hooks/useFormNavigationBlocker.js +42 -0
- package/dist/routing/hooks/useNavigate.next.d.ts +1 -1
- package/dist/routing/hooks/useNavigate.next.d.ts.map +1 -1
- package/dist/routing/hooks/useNavigate.next.js +7 -1
- package/dist/routing/hooks/useNavigate.vite.d.ts +1 -1
- package/dist/routing/hooks/useNavigate.vite.d.ts.map +1 -1
- package/dist/routing/hooks/useNavigate.vite.js +7 -1
- package/dist/styles/index.css +288 -143
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/useFormStoreSafe.d.ts +59 -0
- package/dist/utils/useFormStoreSafe.d.ts.map +1 -0
- package/dist/utils/useFormStoreSafe.js +115 -0
- package/package.json +5 -5
package/dist/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AAEvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AAEvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC"}
|
package/dist/utils/index.js
CHANGED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Degraded FormStore state - returned when CRUD package not installed
|
|
3
|
+
* Matches FormStoreState & FormStoreActions interface
|
|
4
|
+
*/
|
|
5
|
+
declare const DEGRADED_FORM_STORE_STATE: {
|
|
6
|
+
readonly forms: {};
|
|
7
|
+
readonly startSubmit: () => void;
|
|
8
|
+
readonly setUploading: () => void;
|
|
9
|
+
readonly setValidating: () => void;
|
|
10
|
+
readonly setSubmitting: () => void;
|
|
11
|
+
readonly setSuccess: () => void;
|
|
12
|
+
readonly setError: () => void;
|
|
13
|
+
readonly reset: () => void;
|
|
14
|
+
readonly cleanup: () => void;
|
|
15
|
+
readonly setIsDirty: () => void;
|
|
16
|
+
readonly hasDirtyForms: () => boolean;
|
|
17
|
+
readonly getDirtyFormIds: () => never[];
|
|
18
|
+
readonly getStatus: () => "idle";
|
|
19
|
+
readonly isLoading: () => boolean;
|
|
20
|
+
readonly getUploadProgress: () => number;
|
|
21
|
+
readonly getError: () => null;
|
|
22
|
+
readonly getIsDirty: () => boolean;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Check if FormStore is available
|
|
26
|
+
*/
|
|
27
|
+
export declare const isFormStoreAvailable: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Safe access to FormStore.
|
|
30
|
+
* Returns degraded state selector result if CRUD package not installed.
|
|
31
|
+
*
|
|
32
|
+
* @param selector - Zustand selector function
|
|
33
|
+
* @returns Selected state, or degraded state selection if CRUD not available
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```tsx
|
|
37
|
+
* const hasDirtyForms = useFormStoreSafe((state) => state.hasDirtyForms());
|
|
38
|
+
* // Always safe to call - returns false when degraded
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function useFormStoreSafe<T>(selector: (state: any) => T): T;
|
|
42
|
+
export declare namespace useFormStoreSafe {
|
|
43
|
+
var getState: () => typeof DEGRADED_FORM_STORE_STATE;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if any forms are dirty (safe version).
|
|
47
|
+
* Returns false if CRUD package not available.
|
|
48
|
+
*/
|
|
49
|
+
export declare function useHasDirtyFormsSafe(): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Check if navigation should be blocked (safe version).
|
|
52
|
+
* Returns a function that checks FormStore and shows confirmation if needed.
|
|
53
|
+
*
|
|
54
|
+
* @param message - Confirmation message
|
|
55
|
+
* @returns Promise<boolean> - true if navigation should proceed
|
|
56
|
+
*/
|
|
57
|
+
export declare function checkFormNavigationSafe(message?: string): Promise<boolean>;
|
|
58
|
+
export {};
|
|
59
|
+
//# sourceMappingURL=useFormStoreSafe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormStoreSafe.d.ts","sourceRoot":"","sources":["../../src/utils/useFormStoreSafe.ts"],"names":[],"mappings":"AA8BA;;;GAGG;AACH,QAAA,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;CAqBrB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,oBAAoB,SAAyC,CAAC;AAE3E;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,CAKlE;yBALe,gBAAgB;wBAmBA,OAAO,yBAAyB;;AAOhE;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,OAAO,CAG9C;AAED;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,SAA4C,GAClD,OAAO,CAAC,OAAO,CAAC,CAUlB"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// packages/ui/src/utils/useFormStoreSafe.ts
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Safe FormStore access for graceful degradation
|
|
4
|
+
* @description Provides FormStore functionality when @donotdev/crud is installed,
|
|
5
|
+
* gracefully degrades when not installed.
|
|
6
|
+
*
|
|
7
|
+
* ## CRITICAL: DO NOT USE DYNAMIC IMPORTS
|
|
8
|
+
*
|
|
9
|
+
* This file MUST use sync `import * as crudModule from '@donotdev/crud'`
|
|
10
|
+
* at module level. DO NOT refactor to use async `import('@donotdev/crud').then(...)`.
|
|
11
|
+
*
|
|
12
|
+
* @see packages/ui/src/utils/useAuthSafe.ts for pattern reference
|
|
13
|
+
* @see docs/development/GRACEFUL_DEGRADATION.md
|
|
14
|
+
* @version 0.0.1
|
|
15
|
+
* @since 0.0.1
|
|
16
|
+
* @author AMBROISE PARK Consulting
|
|
17
|
+
*/
|
|
18
|
+
import * as crudModule from '@donotdev/crud';
|
|
19
|
+
// Sync import - bundler aliases to empty module if not installed
|
|
20
|
+
// Decision made ONCE at module load time, never changes
|
|
21
|
+
// Extract useFormStore if available (undefined if package not installed/aliased)
|
|
22
|
+
// Zustand stores have both the hook and getState method
|
|
23
|
+
const realUseFormStore = crudModule?.useFormStore;
|
|
24
|
+
/**
|
|
25
|
+
* Degraded FormStore state - returned when CRUD package not installed
|
|
26
|
+
* Matches FormStoreState & FormStoreActions interface
|
|
27
|
+
*/
|
|
28
|
+
const DEGRADED_FORM_STORE_STATE = {
|
|
29
|
+
forms: {},
|
|
30
|
+
// State transitions (no-ops)
|
|
31
|
+
startSubmit: () => { },
|
|
32
|
+
setUploading: () => { },
|
|
33
|
+
setValidating: () => { },
|
|
34
|
+
setSubmitting: () => { },
|
|
35
|
+
setSuccess: () => { },
|
|
36
|
+
setError: () => { },
|
|
37
|
+
reset: () => { },
|
|
38
|
+
cleanup: () => { },
|
|
39
|
+
// Dirty state management
|
|
40
|
+
setIsDirty: () => { },
|
|
41
|
+
hasDirtyForms: () => false, // Key method - returns false when degraded
|
|
42
|
+
getDirtyFormIds: () => [],
|
|
43
|
+
// Getters
|
|
44
|
+
getStatus: () => 'idle',
|
|
45
|
+
isLoading: () => false,
|
|
46
|
+
getUploadProgress: () => 0,
|
|
47
|
+
getError: () => null,
|
|
48
|
+
getIsDirty: () => false,
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Check if FormStore is available
|
|
52
|
+
*/
|
|
53
|
+
export const isFormStoreAvailable = typeof realUseFormStore === 'function';
|
|
54
|
+
/**
|
|
55
|
+
* Safe access to FormStore.
|
|
56
|
+
* Returns degraded state selector result if CRUD package not installed.
|
|
57
|
+
*
|
|
58
|
+
* @param selector - Zustand selector function
|
|
59
|
+
* @returns Selected state, or degraded state selection if CRUD not available
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```tsx
|
|
63
|
+
* const hasDirtyForms = useFormStoreSafe((state) => state.hasDirtyForms());
|
|
64
|
+
* // Always safe to call - returns false when degraded
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export function useFormStoreSafe(selector) {
|
|
68
|
+
if (realUseFormStore) {
|
|
69
|
+
return realUseFormStore(selector);
|
|
70
|
+
}
|
|
71
|
+
return selector(DEGRADED_FORM_STORE_STATE);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get FormStore state directly (non-hook version).
|
|
75
|
+
* Use this in non-React contexts or for one-time checks.
|
|
76
|
+
*
|
|
77
|
+
* @returns FormStore state, or degraded state if CRUD not available
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```tsx
|
|
81
|
+
* const state = useFormStoreSafe.getState();
|
|
82
|
+
* const hasDirty = state.hasDirtyForms(); // Always safe to call
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
useFormStoreSafe.getState = () => {
|
|
86
|
+
if (realUseFormStore && typeof realUseFormStore.getState === 'function') {
|
|
87
|
+
return realUseFormStore.getState();
|
|
88
|
+
}
|
|
89
|
+
return DEGRADED_FORM_STORE_STATE;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Check if any forms are dirty (safe version).
|
|
93
|
+
* Returns false if CRUD package not available.
|
|
94
|
+
*/
|
|
95
|
+
export function useHasDirtyFormsSafe() {
|
|
96
|
+
const hasDirtyForms = useFormStoreSafe((state) => state.hasDirtyForms());
|
|
97
|
+
return hasDirtyForms();
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Check if navigation should be blocked (safe version).
|
|
101
|
+
* Returns a function that checks FormStore and shows confirmation if needed.
|
|
102
|
+
*
|
|
103
|
+
* @param message - Confirmation message
|
|
104
|
+
* @returns Promise<boolean> - true if navigation should proceed
|
|
105
|
+
*/
|
|
106
|
+
export async function checkFormNavigationSafe(message = 'You have unsaved changes. Discard them?') {
|
|
107
|
+
const state = useFormStoreSafe.getState();
|
|
108
|
+
const hasDirtyForms = state.hasDirtyForms();
|
|
109
|
+
if (!hasDirtyForms)
|
|
110
|
+
return true; // No dirty forms = allow navigation
|
|
111
|
+
if (typeof window !== 'undefined' && window.confirm) {
|
|
112
|
+
return window.confirm(message);
|
|
113
|
+
}
|
|
114
|
+
return true;
|
|
115
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@donotdev/ui",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
@@ -55,10 +55,10 @@
|
|
|
55
55
|
"@donotdev/adv-comps": "^0.0.8",
|
|
56
56
|
"@donotdev/auth": "^0.0.5",
|
|
57
57
|
"@donotdev/billing": "^0.0.5",
|
|
58
|
-
"@donotdev/components": "^0.0.
|
|
59
|
-
"@donotdev/core": "^0.0.
|
|
60
|
-
"@donotdev/crud": "^0.0.
|
|
61
|
-
"@donotdev/firebase": "^0.0.
|
|
58
|
+
"@donotdev/components": "^0.0.13",
|
|
59
|
+
"@donotdev/core": "^0.0.17",
|
|
60
|
+
"@donotdev/crud": "^0.0.8",
|
|
61
|
+
"@donotdev/firebase": "^0.0.6",
|
|
62
62
|
"@donotdev/oauth": "^0.0.5",
|
|
63
63
|
"firebase": "^12.5.0",
|
|
64
64
|
"lucide-react": "^0.562.0",
|