@process.co/ui 0.0.9 → 0.0.11
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/README.md +365 -282
- package/css/ui.css +176 -7
- package/dist/components/dev/index.cjs +486 -0
- package/dist/components/dev/index.cjs.map +1 -0
- package/dist/components/dev/index.d.cts +88 -0
- package/dist/components/dev/index.d.ts +88 -0
- package/dist/components/dev/index.js +474 -0
- package/dist/components/dev/index.js.map +1 -0
- package/dist/components/fields/index.cjs +452 -78
- package/dist/components/fields/index.cjs.map +1 -1
- package/dist/components/fields/index.d.cts +1 -1
- package/dist/components/fields/index.d.ts +1 -1
- package/dist/components/fields/index.js +435 -68
- package/dist/components/fields/index.js.map +1 -1
- package/dist/{index-nu_JyZnb.d.cts → index-B-kAG1RW.d.cts} +204 -18
- package/dist/{index-nu_JyZnb.d.ts → index-B-kAG1RW.d.ts} +204 -18
- package/dist/index.cjs +413 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +414 -26
- package/dist/index.js.map +1 -1
- package/package.json +11 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import React__default, { PropsWithChildren } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for the DevProvider
|
|
5
|
+
*/
|
|
6
|
+
interface DevProviderConfig {
|
|
7
|
+
/** Unique key for localStorage persistence (defaults to 'process-dev') */
|
|
8
|
+
storageKey?: string;
|
|
9
|
+
/** Initial data to populate the store */
|
|
10
|
+
initialData?: Record<string, any>;
|
|
11
|
+
/** Whether to persist to localStorage (default: true) */
|
|
12
|
+
persist?: boolean;
|
|
13
|
+
/** Mock node ID (default: 'dev-node-1') */
|
|
14
|
+
nodeId?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Context value for development/testing
|
|
18
|
+
*/
|
|
19
|
+
interface DevContextValue {
|
|
20
|
+
data: Record<string, any>;
|
|
21
|
+
setProperty: (key: string, value: any) => void;
|
|
22
|
+
getProperty: <T = any>(key: string) => T | undefined;
|
|
23
|
+
inferredTypes: Record<string, string>;
|
|
24
|
+
setInferredType: (fieldName: string, type: string) => void;
|
|
25
|
+
getInferredType: (fieldName: string) => string | undefined;
|
|
26
|
+
/** Remove an inferred type by field name */
|
|
27
|
+
clearInferredType: (fieldName: string) => void;
|
|
28
|
+
/** Remove all inferred types */
|
|
29
|
+
clearAllInferredTypes: () => void;
|
|
30
|
+
nodeId: string;
|
|
31
|
+
clearAll: () => void;
|
|
32
|
+
exportData: () => string;
|
|
33
|
+
importData: (json: string) => void;
|
|
34
|
+
}
|
|
35
|
+
declare const DevContext: React__default.Context<DevContextValue | null>;
|
|
36
|
+
/**
|
|
37
|
+
* Hook to access the dev context for property management
|
|
38
|
+
*/
|
|
39
|
+
declare function useDevContext(): DevContextValue | null;
|
|
40
|
+
/**
|
|
41
|
+
* Hook that mimics useNodeProperty from the real system
|
|
42
|
+
* Works in both dev mode (with DevProvider) and production (with NodePropertyProvider)
|
|
43
|
+
*/
|
|
44
|
+
declare function useNodeProperty<T = any>(fieldName: string): [T | undefined, (value: T) => void];
|
|
45
|
+
/**
|
|
46
|
+
* Hook that mimics useInferredTypes from the real system
|
|
47
|
+
*/
|
|
48
|
+
declare function useInferredTypes(): {
|
|
49
|
+
inferredTypes: Record<string, string>;
|
|
50
|
+
setInferredType: (fieldName: string, type: string) => void;
|
|
51
|
+
getInferredType: (fieldName: string) => string | undefined;
|
|
52
|
+
} | null;
|
|
53
|
+
/**
|
|
54
|
+
* DevProvider - Development environment for testing custom UI components
|
|
55
|
+
*
|
|
56
|
+
* Features:
|
|
57
|
+
* - Persists data to localStorage
|
|
58
|
+
* - Provides mock implementations of useNodeProperty and useInferredTypes
|
|
59
|
+
* - Supports import/export of data for testing scenarios
|
|
60
|
+
*
|
|
61
|
+
* Usage:
|
|
62
|
+
* ```tsx
|
|
63
|
+
* import { DevProvider } from '@process.co/ui/dev';
|
|
64
|
+
*
|
|
65
|
+
* function App() {
|
|
66
|
+
* return (
|
|
67
|
+
* <DevProvider
|
|
68
|
+
* storageKey="my-component-dev"
|
|
69
|
+
* initialData={{ switchValue: { cases: [] } }}
|
|
70
|
+
* >
|
|
71
|
+
* <MyCustomComponent fieldName="switchValue" />
|
|
72
|
+
* </DevProvider>
|
|
73
|
+
* );
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
declare function DevProvider({ children, storageKey, initialData, persist, nodeId, }: PropsWithChildren<DevProviderConfig>): React__default.JSX.Element;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* DevToolbar - Optional toolbar for development
|
|
81
|
+
* Shows current data state and provides controls for import/export/clear
|
|
82
|
+
* Also allows spoofing inferred types for testing components that depend on external field types
|
|
83
|
+
*/
|
|
84
|
+
declare function DevToolbar({ className }: {
|
|
85
|
+
className?: string;
|
|
86
|
+
}): React__default.JSX.Element;
|
|
87
|
+
|
|
88
|
+
export { DevContext, type DevContextValue, DevProvider, type DevProviderConfig, DevToolbar, useDevContext, useInferredTypes, useNodeProperty };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import React__default, { PropsWithChildren } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for the DevProvider
|
|
5
|
+
*/
|
|
6
|
+
interface DevProviderConfig {
|
|
7
|
+
/** Unique key for localStorage persistence (defaults to 'process-dev') */
|
|
8
|
+
storageKey?: string;
|
|
9
|
+
/** Initial data to populate the store */
|
|
10
|
+
initialData?: Record<string, any>;
|
|
11
|
+
/** Whether to persist to localStorage (default: true) */
|
|
12
|
+
persist?: boolean;
|
|
13
|
+
/** Mock node ID (default: 'dev-node-1') */
|
|
14
|
+
nodeId?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Context value for development/testing
|
|
18
|
+
*/
|
|
19
|
+
interface DevContextValue {
|
|
20
|
+
data: Record<string, any>;
|
|
21
|
+
setProperty: (key: string, value: any) => void;
|
|
22
|
+
getProperty: <T = any>(key: string) => T | undefined;
|
|
23
|
+
inferredTypes: Record<string, string>;
|
|
24
|
+
setInferredType: (fieldName: string, type: string) => void;
|
|
25
|
+
getInferredType: (fieldName: string) => string | undefined;
|
|
26
|
+
/** Remove an inferred type by field name */
|
|
27
|
+
clearInferredType: (fieldName: string) => void;
|
|
28
|
+
/** Remove all inferred types */
|
|
29
|
+
clearAllInferredTypes: () => void;
|
|
30
|
+
nodeId: string;
|
|
31
|
+
clearAll: () => void;
|
|
32
|
+
exportData: () => string;
|
|
33
|
+
importData: (json: string) => void;
|
|
34
|
+
}
|
|
35
|
+
declare const DevContext: React__default.Context<DevContextValue | null>;
|
|
36
|
+
/**
|
|
37
|
+
* Hook to access the dev context for property management
|
|
38
|
+
*/
|
|
39
|
+
declare function useDevContext(): DevContextValue | null;
|
|
40
|
+
/**
|
|
41
|
+
* Hook that mimics useNodeProperty from the real system
|
|
42
|
+
* Works in both dev mode (with DevProvider) and production (with NodePropertyProvider)
|
|
43
|
+
*/
|
|
44
|
+
declare function useNodeProperty<T = any>(fieldName: string): [T | undefined, (value: T) => void];
|
|
45
|
+
/**
|
|
46
|
+
* Hook that mimics useInferredTypes from the real system
|
|
47
|
+
*/
|
|
48
|
+
declare function useInferredTypes(): {
|
|
49
|
+
inferredTypes: Record<string, string>;
|
|
50
|
+
setInferredType: (fieldName: string, type: string) => void;
|
|
51
|
+
getInferredType: (fieldName: string) => string | undefined;
|
|
52
|
+
} | null;
|
|
53
|
+
/**
|
|
54
|
+
* DevProvider - Development environment for testing custom UI components
|
|
55
|
+
*
|
|
56
|
+
* Features:
|
|
57
|
+
* - Persists data to localStorage
|
|
58
|
+
* - Provides mock implementations of useNodeProperty and useInferredTypes
|
|
59
|
+
* - Supports import/export of data for testing scenarios
|
|
60
|
+
*
|
|
61
|
+
* Usage:
|
|
62
|
+
* ```tsx
|
|
63
|
+
* import { DevProvider } from '@process.co/ui/dev';
|
|
64
|
+
*
|
|
65
|
+
* function App() {
|
|
66
|
+
* return (
|
|
67
|
+
* <DevProvider
|
|
68
|
+
* storageKey="my-component-dev"
|
|
69
|
+
* initialData={{ switchValue: { cases: [] } }}
|
|
70
|
+
* >
|
|
71
|
+
* <MyCustomComponent fieldName="switchValue" />
|
|
72
|
+
* </DevProvider>
|
|
73
|
+
* );
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
declare function DevProvider({ children, storageKey, initialData, persist, nodeId, }: PropsWithChildren<DevProviderConfig>): React__default.JSX.Element;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* DevToolbar - Optional toolbar for development
|
|
81
|
+
* Shows current data state and provides controls for import/export/clear
|
|
82
|
+
* Also allows spoofing inferred types for testing components that depend on external field types
|
|
83
|
+
*/
|
|
84
|
+
declare function DevToolbar({ className }: {
|
|
85
|
+
className?: string;
|
|
86
|
+
}): React__default.JSX.Element;
|
|
87
|
+
|
|
88
|
+
export { DevContext, type DevContextValue, DevProvider, type DevProviderConfig, DevToolbar, useDevContext, useInferredTypes, useNodeProperty };
|
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _array_with_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
8
|
+
}
|
|
9
|
+
function _define_property(obj, key, value) {
|
|
10
|
+
if (key in obj) {
|
|
11
|
+
Object.defineProperty(obj, key, {
|
|
12
|
+
value: value,
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true
|
|
16
|
+
});
|
|
17
|
+
} else {
|
|
18
|
+
obj[key] = value;
|
|
19
|
+
}
|
|
20
|
+
return obj;
|
|
21
|
+
}
|
|
22
|
+
function _iterable_to_array_limit(arr, i) {
|
|
23
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
24
|
+
if (_i == null) return;
|
|
25
|
+
var _arr = [];
|
|
26
|
+
var _n = true;
|
|
27
|
+
var _d = false;
|
|
28
|
+
var _s, _e;
|
|
29
|
+
try {
|
|
30
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
31
|
+
_arr.push(_s.value);
|
|
32
|
+
if (i && _arr.length === i) break;
|
|
33
|
+
}
|
|
34
|
+
} catch (err) {
|
|
35
|
+
_d = true;
|
|
36
|
+
_e = err;
|
|
37
|
+
} finally{
|
|
38
|
+
try {
|
|
39
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
40
|
+
} finally{
|
|
41
|
+
if (_d) throw _e;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return _arr;
|
|
45
|
+
}
|
|
46
|
+
function _non_iterable_rest() {
|
|
47
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
48
|
+
}
|
|
49
|
+
function _object_spread(target) {
|
|
50
|
+
for(var i = 1; i < arguments.length; i++){
|
|
51
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
52
|
+
var ownKeys = Object.keys(source);
|
|
53
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
54
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
55
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
ownKeys.forEach(function(key) {
|
|
59
|
+
_define_property(target, key, source[key]);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return target;
|
|
63
|
+
}
|
|
64
|
+
function ownKeys(object, enumerableOnly) {
|
|
65
|
+
var keys = Object.keys(object);
|
|
66
|
+
if (Object.getOwnPropertySymbols) {
|
|
67
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
68
|
+
if (enumerableOnly) {
|
|
69
|
+
symbols = symbols.filter(function(sym) {
|
|
70
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
keys.push.apply(keys, symbols);
|
|
74
|
+
}
|
|
75
|
+
return keys;
|
|
76
|
+
}
|
|
77
|
+
function _object_spread_props(target, source) {
|
|
78
|
+
source = source != null ? source : {};
|
|
79
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
80
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
81
|
+
} else {
|
|
82
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
83
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return target;
|
|
87
|
+
}
|
|
88
|
+
function _object_without_properties(source, excluded) {
|
|
89
|
+
if (source == null) return {};
|
|
90
|
+
var target = _object_without_properties_loose(source, excluded);
|
|
91
|
+
var key, i;
|
|
92
|
+
if (Object.getOwnPropertySymbols) {
|
|
93
|
+
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
94
|
+
for(i = 0; i < sourceSymbolKeys.length; i++){
|
|
95
|
+
key = sourceSymbolKeys[i];
|
|
96
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
97
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
98
|
+
target[key] = source[key];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return target;
|
|
102
|
+
}
|
|
103
|
+
function _object_without_properties_loose(source, excluded) {
|
|
104
|
+
if (source == null) return {};
|
|
105
|
+
var target = {};
|
|
106
|
+
var sourceKeys = Object.keys(source);
|
|
107
|
+
var key, i;
|
|
108
|
+
for(i = 0; i < sourceKeys.length; i++){
|
|
109
|
+
key = sourceKeys[i];
|
|
110
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
111
|
+
target[key] = source[key];
|
|
112
|
+
}
|
|
113
|
+
return target;
|
|
114
|
+
}
|
|
115
|
+
function _sliced_to_array(arr, i) {
|
|
116
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
117
|
+
}
|
|
118
|
+
function _to_primitive(input, hint) {
|
|
119
|
+
if (_type_of(input) !== "object" || input === null) return input;
|
|
120
|
+
var prim = input[Symbol.toPrimitive];
|
|
121
|
+
if (prim !== undefined) {
|
|
122
|
+
var res = prim.call(input, hint || "default");
|
|
123
|
+
if (_type_of(res) !== "object") return res;
|
|
124
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
125
|
+
}
|
|
126
|
+
return (hint === "string" ? String : Number)(input);
|
|
127
|
+
}
|
|
128
|
+
function _to_property_key(arg) {
|
|
129
|
+
var key = _to_primitive(arg, "string");
|
|
130
|
+
return _type_of(key) === "symbol" ? key : String(key);
|
|
131
|
+
}
|
|
132
|
+
function _type_of(obj) {
|
|
133
|
+
"@swc/helpers - typeof";
|
|
134
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
135
|
+
}
|
|
136
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
137
|
+
if (!o) return;
|
|
138
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
139
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
140
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
141
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
142
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
143
|
+
}
|
|
144
|
+
import React2, { createContext, useContext, useCallback, useState, useEffect, useMemo } from 'react';
|
|
145
|
+
// src/components/dev/DevProvider.tsx
|
|
146
|
+
var DevContext = createContext(null);
|
|
147
|
+
function useDevContext() {
|
|
148
|
+
return useContext(DevContext);
|
|
149
|
+
}
|
|
150
|
+
function useNodeProperty(fieldName) {
|
|
151
|
+
var devCtx = useDevContext();
|
|
152
|
+
if (devCtx) {
|
|
153
|
+
var value = devCtx.getProperty(fieldName);
|
|
154
|
+
var setValue = useCallback(function(newValue) {
|
|
155
|
+
devCtx.setProperty(fieldName, newValue);
|
|
156
|
+
}, [
|
|
157
|
+
devCtx,
|
|
158
|
+
fieldName
|
|
159
|
+
]);
|
|
160
|
+
return [
|
|
161
|
+
value,
|
|
162
|
+
setValue
|
|
163
|
+
];
|
|
164
|
+
}
|
|
165
|
+
console.warn("useNodeProperty('".concat(fieldName, "') called outside of DevProvider - returning undefined"));
|
|
166
|
+
var _useState = _sliced_to_array(useState(void 0), 2), localValue = _useState[0], setLocalValue = _useState[1];
|
|
167
|
+
return [
|
|
168
|
+
localValue,
|
|
169
|
+
setLocalValue
|
|
170
|
+
];
|
|
171
|
+
}
|
|
172
|
+
function useInferredTypes() {
|
|
173
|
+
var devCtx = useDevContext();
|
|
174
|
+
if (devCtx) {
|
|
175
|
+
return {
|
|
176
|
+
inferredTypes: devCtx.inferredTypes,
|
|
177
|
+
setInferredType: devCtx.setInferredType,
|
|
178
|
+
getInferredType: devCtx.getInferredType
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
function DevProvider(param) {
|
|
184
|
+
var children = param.children, _param_storageKey = param.storageKey, storageKey = _param_storageKey === void 0 ? "process-dev" : _param_storageKey, _param_initialData = param.initialData, initialData = _param_initialData === void 0 ? {} : _param_initialData, _param_persist = param.persist, persist = _param_persist === void 0 ? true : _param_persist, _param_nodeId = param.nodeId, nodeId = _param_nodeId === void 0 ? "dev-node-1" : _param_nodeId;
|
|
185
|
+
var _useState = _sliced_to_array(useState(function() {
|
|
186
|
+
if (persist && typeof window !== "undefined") {
|
|
187
|
+
try {
|
|
188
|
+
var stored = localStorage.getItem("".concat(storageKey, ":data"));
|
|
189
|
+
if (stored) {
|
|
190
|
+
return _object_spread({}, initialData, JSON.parse(stored));
|
|
191
|
+
}
|
|
192
|
+
} catch (e) {
|
|
193
|
+
console.warn("DevProvider: Failed to load from localStorage", e);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return initialData;
|
|
197
|
+
}), 2), data = _useState[0], setData = _useState[1];
|
|
198
|
+
var _useState1 = _sliced_to_array(useState(function() {
|
|
199
|
+
if (persist && typeof window !== "undefined") {
|
|
200
|
+
try {
|
|
201
|
+
var stored = localStorage.getItem("".concat(storageKey, ":inferredTypes"));
|
|
202
|
+
if (stored) {
|
|
203
|
+
return JSON.parse(stored);
|
|
204
|
+
}
|
|
205
|
+
} catch (e) {
|
|
206
|
+
console.warn("DevProvider: Failed to load inferredTypes from localStorage", e);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return {};
|
|
210
|
+
}), 2), inferredTypes = _useState1[0], setInferredTypesState = _useState1[1];
|
|
211
|
+
useEffect(function() {
|
|
212
|
+
if (persist && typeof window !== "undefined") {
|
|
213
|
+
try {
|
|
214
|
+
localStorage.setItem("".concat(storageKey, ":data"), JSON.stringify(data));
|
|
215
|
+
} catch (e) {
|
|
216
|
+
console.warn("DevProvider: Failed to save data to localStorage", e);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}, [
|
|
220
|
+
data,
|
|
221
|
+
storageKey,
|
|
222
|
+
persist
|
|
223
|
+
]);
|
|
224
|
+
useEffect(function() {
|
|
225
|
+
if (persist && typeof window !== "undefined") {
|
|
226
|
+
try {
|
|
227
|
+
localStorage.setItem("".concat(storageKey, ":inferredTypes"), JSON.stringify(inferredTypes));
|
|
228
|
+
} catch (e) {
|
|
229
|
+
console.warn("DevProvider: Failed to save inferredTypes to localStorage", e);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}, [
|
|
233
|
+
inferredTypes,
|
|
234
|
+
storageKey,
|
|
235
|
+
persist
|
|
236
|
+
]);
|
|
237
|
+
var setProperty = useCallback(function(key, value2) {
|
|
238
|
+
setData(function(prev) {
|
|
239
|
+
return _object_spread_props(_object_spread({}, prev), _define_property({}, key, value2));
|
|
240
|
+
});
|
|
241
|
+
}, []);
|
|
242
|
+
var getProperty = useCallback(function(key) {
|
|
243
|
+
return data[key];
|
|
244
|
+
}, [
|
|
245
|
+
data
|
|
246
|
+
]);
|
|
247
|
+
var setInferredType = useCallback(function(fieldName, type) {
|
|
248
|
+
setInferredTypesState(function(prev) {
|
|
249
|
+
return _object_spread_props(_object_spread({}, prev), _define_property({}, fieldName, type));
|
|
250
|
+
});
|
|
251
|
+
}, []);
|
|
252
|
+
var getInferredType = useCallback(function(fieldName) {
|
|
253
|
+
return inferredTypes[fieldName];
|
|
254
|
+
}, [
|
|
255
|
+
inferredTypes
|
|
256
|
+
]);
|
|
257
|
+
var clearInferredType = useCallback(function(fieldName) {
|
|
258
|
+
setInferredTypesState(function(prev) {
|
|
259
|
+
var _ = prev[fieldName], rest = _object_without_properties(prev, [
|
|
260
|
+
fieldName
|
|
261
|
+
].map(_to_property_key));
|
|
262
|
+
return rest;
|
|
263
|
+
});
|
|
264
|
+
}, []);
|
|
265
|
+
var clearAllInferredTypes = useCallback(function() {
|
|
266
|
+
setInferredTypesState({});
|
|
267
|
+
}, []);
|
|
268
|
+
var clearAll = useCallback(function() {
|
|
269
|
+
setData({});
|
|
270
|
+
setInferredTypesState({});
|
|
271
|
+
if (persist && typeof window !== "undefined") {
|
|
272
|
+
localStorage.removeItem("".concat(storageKey, ":data"));
|
|
273
|
+
localStorage.removeItem("".concat(storageKey, ":inferredTypes"));
|
|
274
|
+
}
|
|
275
|
+
}, [
|
|
276
|
+
storageKey,
|
|
277
|
+
persist
|
|
278
|
+
]);
|
|
279
|
+
var exportData = useCallback(function() {
|
|
280
|
+
return JSON.stringify({
|
|
281
|
+
data: data,
|
|
282
|
+
inferredTypes: inferredTypes
|
|
283
|
+
}, null, 2);
|
|
284
|
+
}, [
|
|
285
|
+
data,
|
|
286
|
+
inferredTypes
|
|
287
|
+
]);
|
|
288
|
+
var importData = useCallback(function(json) {
|
|
289
|
+
try {
|
|
290
|
+
var parsed = JSON.parse(json);
|
|
291
|
+
if (parsed.data) setData(parsed.data);
|
|
292
|
+
if (parsed.inferredTypes) setInferredTypesState(parsed.inferredTypes);
|
|
293
|
+
} catch (e) {
|
|
294
|
+
console.error("DevProvider: Failed to import data", e);
|
|
295
|
+
}
|
|
296
|
+
}, []);
|
|
297
|
+
var value = useMemo(function() {
|
|
298
|
+
return {
|
|
299
|
+
data: data,
|
|
300
|
+
setProperty: setProperty,
|
|
301
|
+
getProperty: getProperty,
|
|
302
|
+
inferredTypes: inferredTypes,
|
|
303
|
+
setInferredType: setInferredType,
|
|
304
|
+
getInferredType: getInferredType,
|
|
305
|
+
clearInferredType: clearInferredType,
|
|
306
|
+
clearAllInferredTypes: clearAllInferredTypes,
|
|
307
|
+
nodeId: nodeId,
|
|
308
|
+
clearAll: clearAll,
|
|
309
|
+
exportData: exportData,
|
|
310
|
+
importData: importData
|
|
311
|
+
};
|
|
312
|
+
}, [
|
|
313
|
+
data,
|
|
314
|
+
setProperty,
|
|
315
|
+
getProperty,
|
|
316
|
+
inferredTypes,
|
|
317
|
+
setInferredType,
|
|
318
|
+
getInferredType,
|
|
319
|
+
clearInferredType,
|
|
320
|
+
clearAllInferredTypes,
|
|
321
|
+
nodeId,
|
|
322
|
+
clearAll,
|
|
323
|
+
exportData,
|
|
324
|
+
importData
|
|
325
|
+
]);
|
|
326
|
+
return /* @__PURE__ */ React2.createElement(DevContext.Provider, {
|
|
327
|
+
value: value
|
|
328
|
+
}, children);
|
|
329
|
+
}
|
|
330
|
+
function DevToolbar(param) {
|
|
331
|
+
var className = param.className;
|
|
332
|
+
var devCtx = useDevContext();
|
|
333
|
+
var _useState = _sliced_to_array(useState(false), 2), showData = _useState[0], setShowData = _useState[1];
|
|
334
|
+
var _useState1 = _sliced_to_array(useState(false), 2), showTypeEditor = _useState1[0], setShowTypeEditor = _useState1[1];
|
|
335
|
+
var _useState2 = _sliced_to_array(useState(""), 2), newTypeKey = _useState2[0], setNewTypeKey = _useState2[1];
|
|
336
|
+
var _useState3 = _sliced_to_array(useState(""), 2), newTypeValue = _useState3[0], setNewTypeValue = _useState3[1];
|
|
337
|
+
if (!devCtx) {
|
|
338
|
+
return /* @__PURE__ */ React2.createElement("div", {
|
|
339
|
+
className: className
|
|
340
|
+
}, "DevToolbar: Not inside DevProvider");
|
|
341
|
+
}
|
|
342
|
+
var handleAddType = function() {
|
|
343
|
+
if (newTypeKey.trim() && newTypeValue.trim()) {
|
|
344
|
+
devCtx.setInferredType(newTypeKey.trim(), newTypeValue.trim());
|
|
345
|
+
setNewTypeKey("");
|
|
346
|
+
setNewTypeValue("");
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
var handleRemoveType = function(key) {
|
|
350
|
+
devCtx.clearInferredType(key);
|
|
351
|
+
};
|
|
352
|
+
var handleClearAllTypes = function() {
|
|
353
|
+
if (confirm("Clear all inferred types?")) {
|
|
354
|
+
devCtx.clearAllInferredTypes();
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
return /* @__PURE__ */ React2.createElement("div", {
|
|
358
|
+
className: "".concat(className || "", " uii:border uii:rounded-lg uii:p-4 uii:bg-gray-50 dark:uii:bg-gray-900")
|
|
359
|
+
}, /* @__PURE__ */ React2.createElement("div", {
|
|
360
|
+
className: "uii:flex uii:items-center uii:gap-4 uii:mb-2 uii:flex-wrap"
|
|
361
|
+
}, /* @__PURE__ */ React2.createElement("span", {
|
|
362
|
+
className: "uii:font-semibold uii:text-sm"
|
|
363
|
+
}, "\uD83D\uDEE0️ Dev Mode"), /* @__PURE__ */ React2.createElement("span", {
|
|
364
|
+
className: "uii:text-xs uii:text-gray-500"
|
|
365
|
+
}, "Node: ", devCtx.nodeId), /* @__PURE__ */ React2.createElement("button", {
|
|
366
|
+
onClick: function() {
|
|
367
|
+
return setShowData(!showData);
|
|
368
|
+
},
|
|
369
|
+
className: "uii:text-xs uii:px-2 uii:py-1 uii:bg-blue-100 dark:uii:bg-blue-900 uii:rounded hover:uii:bg-blue-200"
|
|
370
|
+
}, showData ? "Hide" : "Show", " Data"), /* @__PURE__ */ React2.createElement("button", {
|
|
371
|
+
onClick: function() {
|
|
372
|
+
return setShowTypeEditor(!showTypeEditor);
|
|
373
|
+
},
|
|
374
|
+
className: "uii:text-xs uii:px-2 uii:py-1 uii:bg-purple-100 dark:uii:bg-purple-900 uii:rounded hover:uii:bg-purple-200"
|
|
375
|
+
}, showTypeEditor ? "Hide" : "Spoof", " Types"), /* @__PURE__ */ React2.createElement("button", {
|
|
376
|
+
onClick: function() {
|
|
377
|
+
var json = devCtx.exportData();
|
|
378
|
+
navigator.clipboard.writeText(json);
|
|
379
|
+
alert("Data copied to clipboard!");
|
|
380
|
+
},
|
|
381
|
+
className: "uii:text-xs uii:px-2 uii:py-1 uii:bg-green-100 dark:uii:bg-green-900 uii:rounded hover:uii:bg-green-200"
|
|
382
|
+
}, "Export"), /* @__PURE__ */ React2.createElement("button", {
|
|
383
|
+
onClick: function() {
|
|
384
|
+
var json = prompt("Paste JSON data:");
|
|
385
|
+
if (json) devCtx.importData(json);
|
|
386
|
+
},
|
|
387
|
+
className: "uii:text-xs uii:px-2 uii:py-1 uii:bg-yellow-100 dark:uii:bg-yellow-900 uii:rounded hover:uii:bg-yellow-200"
|
|
388
|
+
}, "Import"), /* @__PURE__ */ React2.createElement("button", {
|
|
389
|
+
onClick: function() {
|
|
390
|
+
if (confirm("Clear all data?")) devCtx.clearAll();
|
|
391
|
+
},
|
|
392
|
+
className: "uii:text-xs uii:px-2 uii:py-1 uii:bg-red-100 dark:uii:bg-red-900 uii:rounded hover:uii:bg-red-200"
|
|
393
|
+
}, "Clear")), showTypeEditor && /* @__PURE__ */ React2.createElement("div", {
|
|
394
|
+
className: "uii:mt-3 uii:p-3 uii:bg-purple-50 dark:uii:bg-purple-950 uii:rounded-lg uii:border uii:border-purple-200 dark:uii:border-purple-800"
|
|
395
|
+
}, /* @__PURE__ */ React2.createElement("div", {
|
|
396
|
+
className: "uii:text-xs uii:font-medium uii:mb-2 uii:text-purple-700 dark:uii:text-purple-300"
|
|
397
|
+
}, "Spoof Inferred Types (simulate external field types)"), /* @__PURE__ */ React2.createElement("div", {
|
|
398
|
+
className: "uii:flex uii:gap-2 uii:mb-2 uii:flex-wrap"
|
|
399
|
+
}, /* @__PURE__ */ React2.createElement("input", {
|
|
400
|
+
type: "text",
|
|
401
|
+
placeholder: "Field name (e.g., switchExpression)",
|
|
402
|
+
value: newTypeKey,
|
|
403
|
+
onChange: function(e) {
|
|
404
|
+
return setNewTypeKey(e.target.value);
|
|
405
|
+
},
|
|
406
|
+
className: "uii:text-xs uii:px-2 uii:py-1 uii:border uii:rounded uii:flex-1 uii:min-w-[150px] uii:bg-white dark:uii:bg-gray-800"
|
|
407
|
+
}), /* @__PURE__ */ React2.createElement("input", {
|
|
408
|
+
type: "text",
|
|
409
|
+
placeholder: "Type (e.g., string | number)",
|
|
410
|
+
value: newTypeValue,
|
|
411
|
+
onChange: function(e) {
|
|
412
|
+
return setNewTypeValue(e.target.value);
|
|
413
|
+
},
|
|
414
|
+
onKeyDown: function(e) {
|
|
415
|
+
return e.key === "Enter" && handleAddType();
|
|
416
|
+
},
|
|
417
|
+
className: "uii:text-xs uii:px-2 uii:py-1 uii:border uii:rounded uii:flex-1 uii:min-w-[200px] uii:bg-white dark:uii:bg-gray-800"
|
|
418
|
+
}), /* @__PURE__ */ React2.createElement("button", {
|
|
419
|
+
onClick: handleAddType,
|
|
420
|
+
disabled: !newTypeKey.trim() || !newTypeValue.trim(),
|
|
421
|
+
className: "uii:text-xs uii:px-3 uii:py-1 uii:bg-purple-500 uii:text-white uii:rounded hover:uii:bg-purple-600 disabled:uii:opacity-50 disabled:uii:cursor-not-allowed"
|
|
422
|
+
}, "Add")), Object.keys(devCtx.inferredTypes).length > 0 && /* @__PURE__ */ React2.createElement("div", {
|
|
423
|
+
className: "uii:mt-2"
|
|
424
|
+
}, /* @__PURE__ */ React2.createElement("div", {
|
|
425
|
+
className: "uii:flex uii:items-center uii:justify-between uii:mb-1"
|
|
426
|
+
}, /* @__PURE__ */ React2.createElement("span", {
|
|
427
|
+
className: "uii:text-xs uii:text-gray-500"
|
|
428
|
+
}, "Current inferred types:"), /* @__PURE__ */ React2.createElement("button", {
|
|
429
|
+
onClick: handleClearAllTypes,
|
|
430
|
+
className: "uii:text-xs uii:px-2 uii:py-0.5 uii:bg-red-100 dark:uii:bg-red-900 uii:text-red-700 dark:uii:text-red-300 uii:rounded hover:uii:bg-red-200"
|
|
431
|
+
}, "Clear All")), /* @__PURE__ */ React2.createElement("div", {
|
|
432
|
+
className: "uii:space-y-1"
|
|
433
|
+
}, Object.entries(devCtx.inferredTypes).map(function(param) {
|
|
434
|
+
var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
|
|
435
|
+
return value && /* @__PURE__ */ React2.createElement("div", {
|
|
436
|
+
key: key,
|
|
437
|
+
className: "uii:flex uii:items-center uii:gap-2 uii:text-xs uii:bg-white dark:uii:bg-gray-800 uii:px-2 uii:py-1 uii:rounded"
|
|
438
|
+
}, /* @__PURE__ */ React2.createElement("button", {
|
|
439
|
+
onClick: function() {
|
|
440
|
+
navigator.clipboard.writeText(key);
|
|
441
|
+
},
|
|
442
|
+
className: "uii:text-gray-400 hover:uii:text-purple-600 uii:text-xs",
|
|
443
|
+
title: "Copy field name"
|
|
444
|
+
}, "\uD83D\uDCCB"), /* @__PURE__ */ React2.createElement("span", {
|
|
445
|
+
className: "uii:font-mono uii:text-purple-600 dark:uii:text-purple-400 uii:cursor-pointer uii:truncate uii:max-w-[300px]",
|
|
446
|
+
onClick: function() {
|
|
447
|
+
navigator.clipboard.writeText(key);
|
|
448
|
+
},
|
|
449
|
+
title: key
|
|
450
|
+
}, key), /* @__PURE__ */ React2.createElement("span", {
|
|
451
|
+
className: "uii:text-gray-400"
|
|
452
|
+
}, "\u2192"), /* @__PURE__ */ React2.createElement("span", {
|
|
453
|
+
className: "uii:font-mono uii:text-gray-600 dark:uii:text-gray-300 uii:flex-1 uii:truncate"
|
|
454
|
+
}, value), /* @__PURE__ */ React2.createElement("button", {
|
|
455
|
+
onClick: function() {
|
|
456
|
+
return handleRemoveType(key);
|
|
457
|
+
},
|
|
458
|
+
className: "uii:text-red-500 hover:uii:text-red-700 uii:text-xs",
|
|
459
|
+
title: "Remove"
|
|
460
|
+
}, "\u2715"));
|
|
461
|
+
})))), showData && /* @__PURE__ */ React2.createElement("div", {
|
|
462
|
+
className: "uii:mt-2"
|
|
463
|
+
}, /* @__PURE__ */ React2.createElement("div", {
|
|
464
|
+
className: "uii:text-xs uii:mb-1 uii:font-medium"
|
|
465
|
+
}, "Data:"), /* @__PURE__ */ React2.createElement("pre", {
|
|
466
|
+
className: "uii:text-xs uii:bg-gray-100 dark:uii:bg-gray-800 uii:p-2 uii:rounded uii:overflow-auto uii:max-h-48"
|
|
467
|
+
}, JSON.stringify(devCtx.data, null, 2)), /* @__PURE__ */ React2.createElement("div", {
|
|
468
|
+
className: "uii:text-xs uii:mb-1 uii:mt-2 uii:font-medium"
|
|
469
|
+
}, "Inferred Types:"), /* @__PURE__ */ React2.createElement("pre", {
|
|
470
|
+
className: "uii:text-xs uii:bg-gray-100 dark:uii:bg-gray-800 uii:p-2 uii:rounded uii:overflow-auto uii:max-h-24"
|
|
471
|
+
}, JSON.stringify(devCtx.inferredTypes, null, 2))));
|
|
472
|
+
}
|
|
473
|
+
export { DevContext, DevProvider, DevToolbar, useDevContext, useInferredTypes, useNodeProperty }; //# sourceMappingURL=index.js.map
|
|
474
|
+
//# sourceMappingURL=index.js.map
|