formstand 0.11.0 → 0.12.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.
package/dist/index.d.cts CHANGED
@@ -282,6 +282,7 @@ type FieldArrayFormApi = Readonly<{
282
282
  arrayInsert(path: string, index: number, item: unknown): void;
283
283
  arrayMove(path: string, from: number, to: number): void;
284
284
  arraySwap(path: string, a: number, b: number): void;
285
+ validateField?(path: string): FieldValidationResult;
285
286
  }>;
286
287
  type FieldArrayEntry<TItem> = Readonly<{
287
288
  id: string;
package/dist/index.d.ts CHANGED
@@ -282,6 +282,7 @@ type FieldArrayFormApi = Readonly<{
282
282
  arrayInsert(path: string, index: number, item: unknown): void;
283
283
  arrayMove(path: string, from: number, to: number): void;
284
284
  arraySwap(path: string, a: number, b: number): void;
285
+ validateField?(path: string): FieldValidationResult;
285
286
  }>;
286
287
  type FieldArrayEntry<TItem> = Readonly<{
287
288
  id: string;
package/dist/index.js CHANGED
@@ -1473,25 +1473,52 @@ function useFieldArray(form, pathArg) {
1473
1473
  const items = slice.items;
1474
1474
  const error = slice.error;
1475
1475
  const ids = deriveIds(form.store, path, items).ids;
1476
+ const revalidate = useCallback(() => {
1477
+ const state = form.store.getState();
1478
+ if (shouldValidateOn(
1479
+ "change",
1480
+ state.mode,
1481
+ state.reValidateMode,
1482
+ state.submitCount > 0,
1483
+ state.touched[path] ?? false
1484
+ )) {
1485
+ form.validateField?.(path);
1486
+ }
1487
+ }, [form, path]);
1476
1488
  const push = useCallback(
1477
- (item) => form.arrayPush(path, item),
1478
- [form, path]
1489
+ (item) => {
1490
+ form.arrayPush(path, item);
1491
+ revalidate();
1492
+ },
1493
+ [form, path, revalidate]
1479
1494
  );
1480
1495
  const remove = useCallback(
1481
- (index) => form.arrayRemove(path, index),
1482
- [form, path]
1496
+ (index) => {
1497
+ form.arrayRemove(path, index);
1498
+ revalidate();
1499
+ },
1500
+ [form, path, revalidate]
1483
1501
  );
1484
1502
  const insert = useCallback(
1485
- (index, item) => form.arrayInsert(path, index, item),
1486
- [form, path]
1503
+ (index, item) => {
1504
+ form.arrayInsert(path, index, item);
1505
+ revalidate();
1506
+ },
1507
+ [form, path, revalidate]
1487
1508
  );
1488
1509
  const move = useCallback(
1489
- (from, to) => form.arrayMove(path, from, to),
1490
- [form, path]
1510
+ (from, to) => {
1511
+ form.arrayMove(path, from, to);
1512
+ revalidate();
1513
+ },
1514
+ [form, path, revalidate]
1491
1515
  );
1492
1516
  const swap = useCallback(
1493
- (a, b) => form.arraySwap(path, a, b),
1494
- [form, path]
1517
+ (a, b) => {
1518
+ form.arraySwap(path, a, b);
1519
+ revalidate();
1520
+ },
1521
+ [form, path, revalidate]
1495
1522
  );
1496
1523
  const fields = useMemo(
1497
1524
  () => items.map((value, index) => ({
@@ -1932,7 +1959,10 @@ var nameMatchesAny = (el, paths) => {
1932
1959
  const name = el.getAttribute("name");
1933
1960
  return name !== null && paths.some((p) => isPathOrChild(name, p));
1934
1961
  };
1935
- var cssQuoted = (value) => `"${value.replace(/[\\"]/g, (ch) => `\\${ch}`)}"`;
1962
+ var cssQuoted = (value) => `"${value.replace(/[\\"]/g, (ch) => `\\${ch}`).replace(
1963
+ /[\x00-\x1f\x7f]/g,
1964
+ (ch) => `\\${ch.codePointAt(0).toString(16)} `
1965
+ )}"`;
1936
1966
  var idMatches = (scope, path) => path === "" ? [] : [...scope.querySelectorAll(`[id=${cssQuoted(path)}]`)];
1937
1967
  var inDomOrder = (els) => [...els].sort(
1938
1968
  (a, b) => a === b ? 0 : (a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING) !== 0 ? -1 : 1
@@ -1940,8 +1970,9 @@ var inDomOrder = (els) => [...els].sort(
1940
1970
  var pathCandidates = (scope, paths) => {
1941
1971
  const controls = namedControls(scope);
1942
1972
  const named = controls.filter((el) => nameMatchesAny(el, paths));
1973
+ const focusableControls = controls.filter(isFocusCandidate);
1943
1974
  const unnamedPaths = paths.filter(
1944
- (p) => !controls.some((el) => nameMatchesAny(el, [p]))
1975
+ (p) => !focusableControls.some((el) => nameMatchesAny(el, [p]))
1945
1976
  );
1946
1977
  const byId = unnamedPaths.flatMap((p) => idMatches(scope, p));
1947
1978
  return inDomOrder([.../* @__PURE__ */ new Set([...named, ...byId])]);