cogsbox-state 0.5.396 → 0.5.398

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cogsbox-state",
3
- "version": "0.5.396",
3
+ "version": "0.5.398",
4
4
  "description": "React state management library with form controls and server sync",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/CogsState.tsx CHANGED
@@ -2345,7 +2345,7 @@ function createProxyHandler<T>(
2345
2345
  callbackfn: (
2346
2346
  value: InferArrayElement<T>,
2347
2347
  setter: StateObject<InferArrayElement<T>>,
2348
- index: { localIndex: number; originalIndex: number },
2348
+ index: number,
2349
2349
  array: T,
2350
2350
  arraySetter: StateObject<T>
2351
2351
  ) => any
@@ -2371,19 +2371,42 @@ function createProxyHandler<T>(
2371
2371
  const setter = rebuildStateShape(item, finalPath, meta);
2372
2372
  const itemComponentId = `${componentId}-${path.join(".")}-${originalIndex}`;
2373
2373
 
2374
- return createElement(CogsItemWrapper, {
2374
+ // Get the validation wrapper from formElements
2375
+ const options = getGlobalStore
2376
+ .getState()
2377
+ .getInitialOptions(stateKey);
2378
+ const validationWrapper = options?.formElements?.validation;
2379
+
2380
+ const childContent = callbackfn(
2381
+ item,
2382
+ setter,
2383
+ originalIndex, // Use originalIndex here
2384
+ arrayToMap as any,
2385
+ rebuildStateShape(arrayToMap as any, path, meta)
2386
+ );
2387
+
2388
+ const wrappedContent = createElement(CogsItemWrapper, {
2375
2389
  key: originalIndex,
2376
2390
  stateKey,
2377
2391
  itemComponentId,
2378
2392
  itemPath: finalPath,
2379
- children: callbackfn(
2380
- item,
2381
- setter,
2382
- { localIndex, originalIndex },
2383
- arrayToMap as any,
2384
- rebuildStateShape(arrayToMap as any, path, meta)
2393
+ children: validationWrapper ? (
2394
+ // Automatically wrap with validation wrapper
2395
+ <ValidationWrapper
2396
+ formOpts={undefined}
2397
+ path={finalPath}
2398
+ validationKey={options?.validation?.key || ""}
2399
+ stateKey={stateKey}
2400
+ validIndices={meta?.validIndices}
2401
+ >
2402
+ {childContent}
2403
+ </ValidationWrapper>
2404
+ ) : (
2405
+ childContent
2385
2406
  ),
2386
2407
  });
2408
+
2409
+ return wrappedContent;
2387
2410
  });
2388
2411
  };
2389
2412
  }
@@ -2675,10 +2698,11 @@ function createProxyHandler<T>(
2675
2698
 
2676
2699
  // Clear existing errors for this validation key
2677
2700
  removeValidationError(init.key);
2678
-
2701
+ console.log("addValidationError", errors);
2679
2702
  // Add each new error
2680
2703
  errors.forEach((error) => {
2681
2704
  const fullErrorPath = [init.key, ...error.path].join(".");
2705
+ console.log("fullErrorPath", fullErrorPath);
2682
2706
  addValidationError(fullErrorPath, error.message);
2683
2707
  });
2684
2708