remix-validated-form 3.2.2 → 3.3.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/.turbo/turbo-build.log +2 -2
- package/browser/ValidatedForm.js +1 -1
- package/browser/internal/MultiValueMap.d.ts +9 -0
- package/browser/internal/MultiValueMap.js +39 -1
- package/browser/internal/SingleTypeMultiValueMap.d.ts +1 -0
- package/browser/internal/SingleTypeMultiValueMap.js +1 -0
- package/browser/internal/flatten.js +6 -1
- package/browser/internal/test.d.ts +0 -1
- package/browser/internal/test.js +15 -10
- package/build/ValidatedForm.js +2 -2
- package/build/internal/MultiValueMap.d.ts +9 -0
- package/build/internal/MultiValueMap.js +44 -0
- package/build/internal/flatten.js +6 -1
- package/package.json +1 -1
- package/src/ValidatedForm.tsx +1 -4
- package/src/internal/{SingleTypeMultiValueMap.ts → MultiValueMap.ts} +2 -1
- package/src/internal/flatten.ts +9 -2
package/.turbo/turbo-build.log
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
[2K[1G[2m$ npm run build:browser && npm run build:main[22m
|
2
2
|
|
3
|
-
> remix-validated-form@3.
|
3
|
+
> remix-validated-form@3.2.2 build:browser
|
4
4
|
> tsc --module ESNext --outDir ./browser
|
5
5
|
|
6
6
|
|
7
|
-
> remix-validated-form@3.
|
7
|
+
> remix-validated-form@3.2.2 build:main
|
8
8
|
> tsc --module CommonJS --outDir ./build
|
9
9
|
|
package/browser/ValidatedForm.js
CHANGED
@@ -3,7 +3,7 @@ import { Form as RemixForm, useActionData, useFormAction, useTransition, } from
|
|
3
3
|
import { useEffect, useMemo, useRef, useState, } from "react";
|
4
4
|
import invariant from "tiny-invariant";
|
5
5
|
import { FormContext } from "./internal/formContext";
|
6
|
-
import { useMultiValueMap
|
6
|
+
import { useMultiValueMap } from "./internal/MultiValueMap";
|
7
7
|
import { useSubmitComplete } from "./internal/submissionCallbacks";
|
8
8
|
import { omit, mergeRefs } from "./internal/util";
|
9
9
|
function useFieldErrorsFromBackend(fetcher, subaction) {
|
@@ -0,0 +1,9 @@
|
|
1
|
+
export declare class MultiValueMap<Key, Value> {
|
2
|
+
private dict;
|
3
|
+
add: (key: Key, value: Value) => void;
|
4
|
+
remove: (key: Key, value: Value) => void;
|
5
|
+
getAll: (key: Key) => Value[];
|
6
|
+
entries: () => IterableIterator<[Key, Value[]]>;
|
7
|
+
has: (key: Key) => boolean;
|
8
|
+
}
|
9
|
+
export declare const useMultiValueMap: <Key, Value>() => () => MultiValueMap<Key, Value>;
|
@@ -1 +1,39 @@
|
|
1
|
-
|
1
|
+
import { useRef } from "react";
|
2
|
+
export class MultiValueMap {
|
3
|
+
constructor() {
|
4
|
+
this.dict = new Map();
|
5
|
+
this.add = (key, value) => {
|
6
|
+
if (this.dict.has(key)) {
|
7
|
+
this.dict.get(key).push(value);
|
8
|
+
}
|
9
|
+
else {
|
10
|
+
this.dict.set(key, [value]);
|
11
|
+
}
|
12
|
+
};
|
13
|
+
this.remove = (key, value) => {
|
14
|
+
if (!this.dict.has(key))
|
15
|
+
return;
|
16
|
+
const array = this.dict.get(key);
|
17
|
+
const index = array.indexOf(value);
|
18
|
+
if (index !== -1)
|
19
|
+
array.splice(index, 1);
|
20
|
+
if (array.length === 0)
|
21
|
+
this.dict.delete(key);
|
22
|
+
};
|
23
|
+
this.getAll = (key) => {
|
24
|
+
var _a;
|
25
|
+
return (_a = this.dict.get(key)) !== null && _a !== void 0 ? _a : [];
|
26
|
+
};
|
27
|
+
this.entries = () => this.dict.entries();
|
28
|
+
this.has = (key) => this.dict.has(key);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
export const useMultiValueMap = () => {
|
32
|
+
const ref = useRef(null);
|
33
|
+
return () => {
|
34
|
+
if (ref.current)
|
35
|
+
return ref.current;
|
36
|
+
ref.current = new MultiValueMap();
|
37
|
+
return ref.current;
|
38
|
+
};
|
39
|
+
};
|
@@ -3,6 +3,7 @@ export declare class MultiValueMap<Key, Value> {
|
|
3
3
|
add: (key: Key, value: Value) => void;
|
4
4
|
remove: (key: Key, value: Value) => void;
|
5
5
|
getAll: (key: Key) => Value[];
|
6
|
+
entries: () => IterableIterator<[Key, Value[]]>;
|
6
7
|
has: (key: Key) => boolean;
|
7
8
|
}
|
8
9
|
export declare const useMultiValueMap: <Key, Value>() => () => MultiValueMap<Key, Value>;
|
@@ -6,7 +6,12 @@ import keys from "lodash/keys";
|
|
6
6
|
import mapKeys from "lodash/mapKeys";
|
7
7
|
import set from "lodash/set";
|
8
8
|
import transform from "lodash/transform";
|
9
|
-
|
9
|
+
import { MultiValueMap } from "./MultiValueMap";
|
10
|
+
export const objectFromPathEntries = (entries) => {
|
11
|
+
const map = new MultiValueMap();
|
12
|
+
entries.forEach(([key, value]) => map.add(key, value));
|
13
|
+
return [...map.entries()].reduce((acc, [key, value]) => set(acc, key, value.length === 1 ? value[0] : value), {});
|
14
|
+
};
|
10
15
|
/** Flatten an object so there are no nested objects or arrays */
|
11
16
|
export function flatten(obj, preserveEmpty = false) {
|
12
17
|
return transform(obj, function (result, value, key) {
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
package/browser/internal/test.js
CHANGED
@@ -1,10 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
}
|
1
|
+
"use strict";
|
2
|
+
z.preprocess((val) => {
|
3
|
+
// Somewhat awkward -- this gets processed per item in the form,
|
4
|
+
// but as a whole array in the backend
|
5
|
+
if (Array.isArray(val)) {
|
6
|
+
return val;
|
7
|
+
}
|
8
|
+
else {
|
9
|
+
return [val];
|
10
|
+
}
|
11
|
+
}, z.array(z.preprocess((val) => {
|
12
|
+
return typeof val !== "string" || val === ""
|
13
|
+
? undefined
|
14
|
+
: Number.parseInt(val);
|
15
|
+
}, z.number())));
|
package/build/ValidatedForm.js
CHANGED
@@ -9,7 +9,7 @@ const react_1 = require("@remix-run/react");
|
|
9
9
|
const react_2 = require("react");
|
10
10
|
const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
|
11
11
|
const formContext_1 = require("./internal/formContext");
|
12
|
-
const
|
12
|
+
const MultiValueMap_1 = require("./internal/MultiValueMap");
|
13
13
|
const submissionCallbacks_1 = require("./internal/submissionCallbacks");
|
14
14
|
const util_1 = require("./internal/util");
|
15
15
|
function useFieldErrorsFromBackend(fetcher, subaction) {
|
@@ -111,7 +111,7 @@ function ValidatedForm({ validator, onSubmit, children, fetcher, action, default
|
|
111
111
|
(_a = formRef.current) === null || _a === void 0 ? void 0 : _a.reset();
|
112
112
|
}
|
113
113
|
});
|
114
|
-
const customFocusHandlers = (0,
|
114
|
+
const customFocusHandlers = (0, MultiValueMap_1.useMultiValueMap)();
|
115
115
|
const contextValue = (0, react_2.useMemo)(() => ({
|
116
116
|
fieldErrors,
|
117
117
|
action,
|
@@ -0,0 +1,9 @@
|
|
1
|
+
export declare class MultiValueMap<Key, Value> {
|
2
|
+
private dict;
|
3
|
+
add: (key: Key, value: Value) => void;
|
4
|
+
remove: (key: Key, value: Value) => void;
|
5
|
+
getAll: (key: Key) => Value[];
|
6
|
+
entries: () => IterableIterator<[Key, Value[]]>;
|
7
|
+
has: (key: Key) => boolean;
|
8
|
+
}
|
9
|
+
export declare const useMultiValueMap: <Key, Value>() => () => MultiValueMap<Key, Value>;
|
@@ -0,0 +1,44 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.useMultiValueMap = exports.MultiValueMap = void 0;
|
4
|
+
const react_1 = require("react");
|
5
|
+
class MultiValueMap {
|
6
|
+
constructor() {
|
7
|
+
this.dict = new Map();
|
8
|
+
this.add = (key, value) => {
|
9
|
+
if (this.dict.has(key)) {
|
10
|
+
this.dict.get(key).push(value);
|
11
|
+
}
|
12
|
+
else {
|
13
|
+
this.dict.set(key, [value]);
|
14
|
+
}
|
15
|
+
};
|
16
|
+
this.remove = (key, value) => {
|
17
|
+
if (!this.dict.has(key))
|
18
|
+
return;
|
19
|
+
const array = this.dict.get(key);
|
20
|
+
const index = array.indexOf(value);
|
21
|
+
if (index !== -1)
|
22
|
+
array.splice(index, 1);
|
23
|
+
if (array.length === 0)
|
24
|
+
this.dict.delete(key);
|
25
|
+
};
|
26
|
+
this.getAll = (key) => {
|
27
|
+
var _a;
|
28
|
+
return (_a = this.dict.get(key)) !== null && _a !== void 0 ? _a : [];
|
29
|
+
};
|
30
|
+
this.entries = () => this.dict.entries();
|
31
|
+
this.has = (key) => this.dict.has(key);
|
32
|
+
}
|
33
|
+
}
|
34
|
+
exports.MultiValueMap = MultiValueMap;
|
35
|
+
const useMultiValueMap = () => {
|
36
|
+
const ref = (0, react_1.useRef)(null);
|
37
|
+
return () => {
|
38
|
+
if (ref.current)
|
39
|
+
return ref.current;
|
40
|
+
ref.current = new MultiValueMap();
|
41
|
+
return ref.current;
|
42
|
+
};
|
43
|
+
};
|
44
|
+
exports.useMultiValueMap = useMultiValueMap;
|
@@ -12,7 +12,12 @@ const keys_1 = __importDefault(require("lodash/keys"));
|
|
12
12
|
const mapKeys_1 = __importDefault(require("lodash/mapKeys"));
|
13
13
|
const set_1 = __importDefault(require("lodash/set"));
|
14
14
|
const transform_1 = __importDefault(require("lodash/transform"));
|
15
|
-
const
|
15
|
+
const MultiValueMap_1 = require("./MultiValueMap");
|
16
|
+
const objectFromPathEntries = (entries) => {
|
17
|
+
const map = new MultiValueMap_1.MultiValueMap();
|
18
|
+
entries.forEach(([key, value]) => map.add(key, value));
|
19
|
+
return [...map.entries()].reduce((acc, [key, value]) => (0, set_1.default)(acc, key, value.length === 1 ? value[0] : value), {});
|
20
|
+
};
|
16
21
|
exports.objectFromPathEntries = objectFromPathEntries;
|
17
22
|
/** Flatten an object so there are no nested objects or arrays */
|
18
23
|
function flatten(obj, preserveEmpty = false) {
|
package/package.json
CHANGED
package/src/ValidatedForm.tsx
CHANGED
@@ -14,10 +14,7 @@ import React, {
|
|
14
14
|
} from "react";
|
15
15
|
import invariant from "tiny-invariant";
|
16
16
|
import { FormContext, FormContextValue } from "./internal/formContext";
|
17
|
-
import {
|
18
|
-
MultiValueMap,
|
19
|
-
useMultiValueMap,
|
20
|
-
} from "./internal/SingleTypeMultiValueMap";
|
17
|
+
import { MultiValueMap, useMultiValueMap } from "./internal/MultiValueMap";
|
21
18
|
import { useSubmitComplete } from "./internal/submissionCallbacks";
|
22
19
|
import { omit, mergeRefs } from "./internal/util";
|
23
20
|
import {
|
@@ -4,7 +4,6 @@ export class MultiValueMap<Key, Value> {
|
|
4
4
|
private dict: Map<Key, Value[]> = new Map();
|
5
5
|
|
6
6
|
add = (key: Key, value: Value) => {
|
7
|
-
this.dict.set(key, [...(this.dict.get(key) ?? []), value]);
|
8
7
|
if (this.dict.has(key)) {
|
9
8
|
this.dict.get(key)!.push(value);
|
10
9
|
} else {
|
@@ -24,6 +23,8 @@ export class MultiValueMap<Key, Value> {
|
|
24
23
|
return this.dict.get(key) ?? [];
|
25
24
|
};
|
26
25
|
|
26
|
+
entries = (): IterableIterator<[Key, Value[]]> => this.dict.entries();
|
27
|
+
|
27
28
|
has = (key: Key): boolean => this.dict.has(key);
|
28
29
|
}
|
29
30
|
|
package/src/internal/flatten.ts
CHANGED
@@ -7,9 +7,16 @@ import mapKeys from "lodash/mapKeys";
|
|
7
7
|
import set from "lodash/set";
|
8
8
|
import transform from "lodash/transform";
|
9
9
|
import { GenericObject } from "..";
|
10
|
+
import { MultiValueMap } from "./MultiValueMap";
|
10
11
|
|
11
|
-
export const objectFromPathEntries = (entries: [string, any][]) =>
|
12
|
-
|
12
|
+
export const objectFromPathEntries = (entries: [string, any][]) => {
|
13
|
+
const map = new MultiValueMap<string, any>();
|
14
|
+
entries.forEach(([key, value]) => map.add(key, value));
|
15
|
+
return [...map.entries()].reduce(
|
16
|
+
(acc, [key, value]) => set(acc, key, value.length === 1 ? value[0] : value),
|
17
|
+
{}
|
18
|
+
);
|
19
|
+
};
|
13
20
|
|
14
21
|
/** Flatten an object so there are no nested objects or arrays */
|
15
22
|
export function flatten(obj: GenericObject, preserveEmpty = false) {
|