cogsbox-state 0.5.483 → 0.5.484
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/CogsState.d.ts.map +1 -1
- package/dist/CogsState.js +360 -363
- package/dist/CogsState.js.map +1 -1
- package/dist/Components.d.ts.map +1 -1
- package/dist/Components.js +202 -201
- package/dist/Components.js.map +1 -1
- package/dist/PluginRunner.d.ts.map +1 -1
- package/dist/PluginRunner.js +44 -44
- package/dist/PluginRunner.js.map +1 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +124 -118
- package/dist/store.js.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +31 -27
- package/src/Components.tsx +13 -6
- package/src/PluginRunner.tsx +2 -1
- package/src/store.ts +24 -7
package/src/store.ts
CHANGED
|
@@ -316,16 +316,25 @@ function getTypeFromZodSchema(
|
|
|
316
316
|
|
|
317
317
|
const typeIdentifier = def.typeName || def.type || current._type;
|
|
318
318
|
|
|
319
|
-
// --- START: THE CRITICAL FIX FOR ZodUnion ---
|
|
320
319
|
if (typeIdentifier === 'ZodUnion' || typeIdentifier === 'union') {
|
|
321
320
|
if (def.options && def.options.length > 0) {
|
|
322
|
-
|
|
323
|
-
|
|
321
|
+
const preferredOption = def.options.find((option: any) => {
|
|
322
|
+
const optionDef = option?.def || option?._def;
|
|
323
|
+
const optionType =
|
|
324
|
+
optionDef?.typeName || optionDef?.type || option?._type;
|
|
325
|
+
return (
|
|
326
|
+
optionType !== 'ZodNull' &&
|
|
327
|
+
optionType !== 'null' &&
|
|
328
|
+
optionType !== 'ZodUndefined' &&
|
|
329
|
+
optionType !== 'undefined'
|
|
330
|
+
);
|
|
331
|
+
});
|
|
332
|
+
current = preferredOption ?? def.options[0];
|
|
333
|
+
continue;
|
|
324
334
|
} else {
|
|
325
|
-
break;
|
|
335
|
+
break;
|
|
326
336
|
}
|
|
327
337
|
}
|
|
328
|
-
// --- END: THE CRITICAL FIX ---
|
|
329
338
|
|
|
330
339
|
if (typeIdentifier === 'ZodOptional' || typeIdentifier === 'optional') {
|
|
331
340
|
isOptional = true;
|
|
@@ -684,9 +693,10 @@ function getSchemaAtPath(schema: any, path: string[]): any {
|
|
|
684
693
|
const typeIdentifier = def?.typeName || def?.type || containerSchema._type;
|
|
685
694
|
|
|
686
695
|
if (typeIdentifier === 'ZodObject' || typeIdentifier === 'object') {
|
|
687
|
-
|
|
696
|
+
const rawShape =
|
|
697
|
+
def?.shape ?? containerSchema.shape ?? containerSchema._shape;
|
|
688
698
|
const shape =
|
|
689
|
-
|
|
699
|
+
typeof rawShape === 'function' ? rawShape() : rawShape;
|
|
690
700
|
currentSchema = shape?.[segment];
|
|
691
701
|
} else if (typeIdentifier === 'ZodArray' || typeIdentifier === 'array') {
|
|
692
702
|
// For arrays, the next schema is always the element's schema.
|
|
@@ -1006,6 +1016,13 @@ export const getGlobalStore = create<CogsGlobalState>((set, get) => ({
|
|
|
1006
1016
|
|
|
1007
1017
|
const storageKey = Array.isArray(initialState) ? `[${key}` : key;
|
|
1008
1018
|
shadowStateStore.set(storageKey, newRoot);
|
|
1019
|
+
|
|
1020
|
+
const latestOptions = get().getInitialOptions(key);
|
|
1021
|
+
if (latestOptions?.validation?.zodSchemaV4) {
|
|
1022
|
+
updateShadowTypeInfo(key, latestOptions.validation.zodSchemaV4, 'zod4');
|
|
1023
|
+
} else if (latestOptions?.validation?.zodSchemaV3) {
|
|
1024
|
+
updateShadowTypeInfo(key, latestOptions.validation.zodSchemaV3, 'zod3');
|
|
1025
|
+
}
|
|
1009
1026
|
},
|
|
1010
1027
|
getShadowNode: (key: string, path: string[]): ShadowNode | undefined => {
|
|
1011
1028
|
let current: any =
|