cross-state 0.53.3 → 0.54.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/chunk-CUT6urMc.cjs +30 -0
- package/dist/diff-BQ8bB3Wk.d.cts +22 -0
- package/dist/diff-gZezL04N.d.ts +22 -0
- package/dist/extendedJson-BZkQBXEv.js +29 -0
- package/dist/extendedJson-BZkQBXEv.js.map +1 -0
- package/dist/extendedJson-Dn2F7Edo.cjs +53 -0
- package/dist/extendedJson-Dn2F7Edo.cjs.map +1 -0
- package/dist/hash-BV06P7va.js +19 -0
- package/dist/hash-BV06P7va.js.map +1 -0
- package/dist/hash-CJPl7SRj.cjs +30 -0
- package/dist/hash-CJPl7SRj.cjs.map +1 -0
- package/dist/index.cjs +49 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +59 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/mutative/index.cjs +3 -0
- package/dist/mutative/index.d.cts +3 -0
- package/dist/mutative/index.d.ts +3 -0
- package/dist/mutative/index.js +3 -0
- package/dist/mutative/register.cjs +10 -0
- package/dist/mutative/register.cjs.map +1 -0
- package/dist/mutative/register.d.cts +11 -0
- package/dist/mutative/register.d.ts +9 -0
- package/dist/mutative/register.js +10 -0
- package/dist/mutative/register.js.map +1 -0
- package/dist/mutativeMethods-6QzygG3W.d.cts +13 -0
- package/dist/mutativeMethods-Br3xN2Iq.d.ts +13 -0
- package/dist/mutativeMethods-CZKeRIDL.js +27 -0
- package/dist/mutativeMethods-CZKeRIDL.js.map +1 -0
- package/dist/mutativeMethods-CgXk_bMt.cjs +33 -0
- package/dist/mutativeMethods-CgXk_bMt.cjs.map +1 -0
- package/dist/patchMethods-C3L7Kh8T.d.cts +48 -0
- package/dist/patchMethods-D5YJwcpn.cjs +264 -0
- package/dist/patchMethods-D5YJwcpn.cjs.map +1 -0
- package/dist/patchMethods-DRPfkhAe.js +241 -0
- package/dist/patchMethods-DRPfkhAe.js.map +1 -0
- package/dist/patchMethods-Dxad6HF6.d.ts +48 -0
- package/dist/patches/index.cjs +5 -0
- package/dist/patches/index.d.cts +4 -0
- package/dist/patches/index.d.ts +4 -0
- package/dist/patches/index.js +5 -0
- package/dist/patches/register.cjs +11 -0
- package/dist/patches/register.cjs.map +1 -0
- package/dist/patches/register.d.cts +12 -0
- package/dist/patches/register.d.ts +10 -0
- package/dist/patches/register.js +11 -0
- package/dist/patches/register.js.map +1 -0
- package/dist/persist/register.cjs +13 -0
- package/dist/persist/register.cjs.map +1 -0
- package/dist/persist/register.d.cts +15 -0
- package/dist/persist/register.d.ts +13 -0
- package/dist/persist/register.js +13 -0
- package/dist/persist/register.js.map +1 -0
- package/dist/persist-BluRVcW6.js +258 -0
- package/dist/persist-BluRVcW6.js.map +1 -0
- package/dist/persist-CPjpg6D0.d.ts +61 -0
- package/dist/persist-CztClydq.cjs +263 -0
- package/dist/persist-CztClydq.cjs.map +1 -0
- package/dist/persist-D7MAsyyW.d.cts +61 -0
- package/dist/propAccess-ByqBjC19.cjs +173 -0
- package/dist/propAccess-ByqBjC19.cjs.map +1 -0
- package/dist/propAccess-DGchzVfy.js +113 -0
- package/dist/propAccess-DGchzVfy.js.map +1 -0
- package/dist/react/index.cjs +610 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +305 -0
- package/dist/react/index.d.ts +305 -0
- package/dist/react/index.js +590 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/register.cjs +16 -0
- package/dist/react/register.cjs.map +1 -0
- package/dist/react/register.d.cts +16 -0
- package/dist/react/register.d.ts +14 -0
- package/dist/react/register.js +16 -0
- package/dist/react/register.js.map +1 -0
- package/dist/scope-DI1OFHcr.d.ts +167 -0
- package/dist/scope-DO5vpLPV.d.cts +167 -0
- package/dist/scope-DU5dFP1T.js +322 -0
- package/dist/scope-DU5dFP1T.js.map +1 -0
- package/dist/scope-DvqvkIHB.cjs +369 -0
- package/dist/scope-DvqvkIHB.cjs.map +1 -0
- package/dist/store-BEsiS8y7.d.cts +242 -0
- package/dist/store-BWMWEUpu.cjs +819 -0
- package/dist/store-BWMWEUpu.cjs.map +1 -0
- package/dist/store-DKaeE840.d.ts +242 -0
- package/dist/store-Dr8gM3lq.js +730 -0
- package/dist/store-Dr8gM3lq.js.map +1 -0
- package/dist/storeMethods-AIJSwxHz.js +315 -0
- package/dist/storeMethods-AIJSwxHz.js.map +1 -0
- package/dist/storeMethods-BQwU2Uia.d.cts +107 -0
- package/dist/storeMethods-C4luym7C.d.ts +107 -0
- package/dist/storeMethods-DVVsmUg1.cjs +375 -0
- package/dist/storeMethods-DVVsmUg1.cjs.map +1 -0
- package/package.json +92 -135
- package/dist/cjs/hash.cjs +0 -30
- package/dist/cjs/hash.cjs.map +0 -1
- package/dist/cjs/index.cjs +0 -56
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/index2.cjs +0 -300
- package/dist/cjs/index2.cjs.map +0 -1
- package/dist/cjs/mutative/index.cjs +0 -10
- package/dist/cjs/mutative/index.cjs.map +0 -1
- package/dist/cjs/mutative/register.cjs +0 -8
- package/dist/cjs/mutative/register.cjs.map +0 -1
- package/dist/cjs/mutativeMethods.cjs +0 -29
- package/dist/cjs/mutativeMethods.cjs.map +0 -1
- package/dist/cjs/patches/index.cjs +0 -10
- package/dist/cjs/patches/index.cjs.map +0 -1
- package/dist/cjs/patches/register.cjs +0 -8
- package/dist/cjs/patches/register.cjs.map +0 -1
- package/dist/cjs/persist/register.cjs +0 -11
- package/dist/cjs/persist/register.cjs.map +0 -1
- package/dist/cjs/persist.cjs +0 -302
- package/dist/cjs/persist.cjs.map +0 -1
- package/dist/cjs/propAccess.cjs +0 -162
- package/dist/cjs/propAccess.cjs.map +0 -1
- package/dist/cjs/react/index.cjs +0 -628
- package/dist/cjs/react/index.cjs.map +0 -1
- package/dist/cjs/react/register.cjs +0 -13
- package/dist/cjs/react/register.cjs.map +0 -1
- package/dist/cjs/scope.cjs +0 -400
- package/dist/cjs/scope.cjs.map +0 -1
- package/dist/cjs/store.cjs +0 -829
- package/dist/cjs/store.cjs.map +0 -1
- package/dist/cjs/storeMethods.cjs +0 -856
- package/dist/cjs/storeMethods.cjs.map +0 -1
- package/dist/cjs/urlStore.cjs +0 -120
- package/dist/cjs/urlStore.cjs.map +0 -1
- package/dist/es/hash.mjs +0 -27
- package/dist/es/hash.mjs.map +0 -1
- package/dist/es/index.mjs +0 -20
- package/dist/es/index.mjs.map +0 -1
- package/dist/es/index2.mjs +0 -291
- package/dist/es/index2.mjs.map +0 -1
- package/dist/es/mutative/index.mjs +0 -2
- package/dist/es/mutative/index.mjs.map +0 -1
- package/dist/es/mutative/register.mjs +0 -6
- package/dist/es/mutative/register.mjs.map +0 -1
- package/dist/es/mutativeMethods.mjs +0 -27
- package/dist/es/mutativeMethods.mjs.map +0 -1
- package/dist/es/patches/index.mjs +0 -2
- package/dist/es/patches/index.mjs.map +0 -1
- package/dist/es/patches/register.mjs +0 -6
- package/dist/es/patches/register.mjs.map +0 -1
- package/dist/es/persist/register.mjs +0 -9
- package/dist/es/persist/register.mjs.map +0 -1
- package/dist/es/persist.mjs +0 -300
- package/dist/es/persist.mjs.map +0 -1
- package/dist/es/propAccess.mjs +0 -151
- package/dist/es/propAccess.mjs.map +0 -1
- package/dist/es/react/index.mjs +0 -611
- package/dist/es/react/index.mjs.map +0 -1
- package/dist/es/react/register.mjs +0 -11
- package/dist/es/react/register.mjs.map +0 -1
- package/dist/es/scope.mjs +0 -391
- package/dist/es/scope.mjs.map +0 -1
- package/dist/es/store.mjs +0 -812
- package/dist/es/store.mjs.map +0 -1
- package/dist/es/storeMethods.mjs +0 -845
- package/dist/es/storeMethods.mjs.map +0 -1
- package/dist/es/urlStore.mjs +0 -116
- package/dist/es/urlStore.mjs.map +0 -1
- package/dist/types/core/cache.d.ts +0 -119
- package/dist/types/core/commonTypes.d.ts +0 -76
- package/dist/types/core/index.d.ts +0 -6
- package/dist/types/core/resourceGroup.d.ts +0 -16
- package/dist/types/core/scope.d.ts +0 -5
- package/dist/types/core/store.d.ts +0 -86
- package/dist/types/core/urlStore.d.ts +0 -21
- package/dist/types/index.d.ts +0 -14
- package/dist/types/lib/applyPatches.d.ts +0 -2
- package/dist/types/lib/autobind.d.ts +0 -1
- package/dist/types/lib/cacheState.d.ts +0 -20
- package/dist/types/lib/calcDuration.d.ts +0 -2
- package/dist/types/lib/calculatedValue.d.ts +0 -9
- package/dist/types/lib/castArray.d.ts +0 -1
- package/dist/types/lib/clone.d.ts +0 -1
- package/dist/types/lib/constrain.d.ts +0 -1
- package/dist/types/lib/debounce.d.ts +0 -12
- package/dist/types/lib/deferred.d.ts +0 -5
- package/dist/types/lib/diff.d.ts +0 -17
- package/dist/types/lib/disposable.d.ts +0 -3
- package/dist/types/lib/equals.d.ts +0 -3
- package/dist/types/lib/extendedJson.d.ts +0 -5
- package/dist/types/lib/forwardError.d.ts +0 -1
- package/dist/types/lib/hash.d.ts +0 -5
- package/dist/types/lib/helpers.d.ts +0 -2
- package/dist/types/lib/instanceCache.d.ts +0 -18
- package/dist/types/lib/isPromise.d.ts +0 -1
- package/dist/types/lib/makeSelector.d.ts +0 -2
- package/dist/types/lib/maybePromise.d.ts +0 -1
- package/dist/types/lib/path.d.ts +0 -41
- package/dist/types/lib/promiseChain.d.ts +0 -5
- package/dist/types/lib/promiseWithCancel.d.ts +0 -8
- package/dist/types/lib/promiseWithState.d.ts +0 -9
- package/dist/types/lib/propAccess.d.ts +0 -7
- package/dist/types/lib/queue.d.ts +0 -11
- package/dist/types/lib/standardMethods.d.ts +0 -20
- package/dist/types/lib/throttle.d.ts +0 -2
- package/dist/types/lib/trackingProxy.d.ts +0 -2
- package/dist/types/lib/trie.d.ts +0 -11
- package/dist/types/lib/typeHelpers.d.ts +0 -12
- package/dist/types/lib/unwrapPromise.d.ts +0 -1
- package/dist/types/lib/updateHelpers.d.ts +0 -1
- package/dist/types/lib/wildcardMatch.d.ts +0 -3
- package/dist/types/mutative/index.d.ts +0 -1
- package/dist/types/mutative/mutativeMethods.d.ts +0 -11
- package/dist/types/mutative/register.d.ts +0 -7
- package/dist/types/patches/index.d.ts +0 -1
- package/dist/types/patches/patchMethods.d.ts +0 -44
- package/dist/types/patches/register.d.ts +0 -7
- package/dist/types/persist/index.d.ts +0 -3
- package/dist/types/persist/persist.d.ts +0 -40
- package/dist/types/persist/persistPathHelpers.d.ts +0 -6
- package/dist/types/persist/persistStorage.d.ts +0 -17
- package/dist/types/persist/register.d.ts +0 -9
- package/dist/types/react/cacheMethods.d.ts +0 -5
- package/dist/types/react/form/customInput.d.ts +0 -6
- package/dist/types/react/form/form.d.ts +0 -98
- package/dist/types/react/form/formField.d.ts +0 -68
- package/dist/types/react/form/formForEach.d.ts +0 -19
- package/dist/types/react/form/index.d.ts +0 -3
- package/dist/types/react/form/useFormAutosave.d.ts +0 -9
- package/dist/types/react/index.d.ts +0 -11
- package/dist/types/react/loadingBoundary.d.ts +0 -21
- package/dist/types/react/register.d.ts +0 -15
- package/dist/types/react/scope.d.ts +0 -24
- package/dist/types/react/scopeMethods.d.ts +0 -20
- package/dist/types/react/storeMethods.d.ts +0 -15
- package/dist/types/react/useCache.d.ts +0 -34
- package/dist/types/react/useDecoupledState.d.ts +0 -7
- package/dist/types/react/useProp.d.ts +0 -8
- package/dist/types/react/useStore.d.ts +0 -16
- package/dist/types/react/useUrlParamScope.d.ts +0 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"propAccess-DGchzVfy.js","names":[],"sources":["../src/lib/equals.ts","../src/lib/helpers.ts","../src/lib/clone.ts","../src/lib/propAccess.ts"],"sourcesContent":["export function strictEqual(a: any, b: any): boolean {\n return a === b;\n}\n\nexport function shallowEqual(a: any, b: any): boolean {\n return internalEqual(strictEqual)(a, b);\n}\n\nexport function deepEqual(a: any, b: any): boolean {\n return internalEqual(deepEqual)(a, b);\n}\n\nconst internalEqual = (comp: (a: any, b: any) => boolean) => (a: any, b: any) => {\n if (a === b) {\n return true;\n }\n\n if (a === null || b === null || typeof a !== 'object' || typeof b !== 'object') {\n // eslint-disable-next-line no-self-compare\n return a !== a && b !== b;\n }\n\n if (a.constructor !== b.constructor) {\n return false;\n }\n\n if (a.constructor === Object || Array.isArray(a)) {\n const entries1 = Object.entries(a);\n const entries2 = Object.entries(b);\n return (\n entries1.length === entries2.length &&\n entries1.every(([key, value]) => key in b && comp(value, b[key]))\n );\n }\n\n if (a instanceof Date) {\n return a.getTime() === b.getTime();\n }\n\n if (a instanceof RegExp) {\n return a.source === b.source && a.flags === b.flags;\n }\n\n if (a instanceof Map) {\n return (\n a.size === b.size &&\n [...a.entries()].every(([key, value]) => b.has(key) && comp(value, b.get(key)))\n );\n }\n\n if (a instanceof Set) {\n return a.size === b.size && [...a.values()].every((value) => b.has(value));\n }\n\n if (typeof ArrayBuffer !== 'undefined' && ArrayBuffer.isView(a)) {\n if (a.byteLength !== b.byteLength) {\n return false;\n }\n\n const a_ = new Int8Array(a.buffer);\n const b_ = new Int8Array(b.buffer);\n return a_.every((value, i) => value === b_[i]);\n }\n\n return false;\n};\n","export function isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null;\n}\n\nexport function isPlainObject(value: unknown): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(value);\n return (\n (prototype === null ||\n prototype === Object.prototype ||\n Object.getPrototypeOf(prototype) === null) &&\n !(Symbol.toStringTag in value) &&\n !(Symbol.iterator in value)\n );\n}\n","import { isObject } from '@lib/helpers';\n\nexport function flatClone<T>(object: T): T {\n if (object instanceof Map) {\n return new Map(object) as any;\n }\n\n if (object instanceof Set) {\n return new Set(object) as any;\n }\n\n if (Array.isArray(object)) {\n return [...object] as any;\n }\n\n if (isObject(object)) {\n return { ...object };\n }\n\n return object;\n}\n","import type { Constrain } from '@lib/constrain';\nimport { isObject } from '@lib/helpers';\nimport { flatClone } from './clone';\nimport type { KeyType, Path, SettablePath, SettableValue, Value } from './path';\n\nexport function castArrayPath(path: string | KeyType[]): KeyType[] {\n if (Array.isArray(path)) {\n return path;\n }\n\n if (path === '') {\n return [];\n }\n\n return (path as string).split('.');\n}\n\nexport function get<T, const P>(object: T, path: Constrain<P, Path<T>>): Value<T, P> {\n const _path = castArrayPath(path as any);\n const [first, ...rest] = _path;\n\n if (first === undefined || !object) {\n return object as Value<T, P>;\n }\n\n if (object instanceof Map) {\n return get(object.get(first), rest);\n }\n\n if (object instanceof Set) {\n return get(Array.from(object)[Number(first)], rest);\n }\n\n if (isObject(object)) {\n return get(object[first as keyof T], rest as any) as Value<T, P>;\n }\n\n throw new Error(`Could not get ${path} of ${object}`);\n}\n\nexport function set<T, const P>(\n object: T,\n path: Constrain<P, SettablePath<T>>,\n value: SettableValue<T, P>,\n rootPath: string | readonly KeyType[] = path,\n): T {\n const _path = castArrayPath(path as any);\n const [first, ...rest] = _path;\n\n if (first === undefined) {\n return value as T;\n }\n\n if (object instanceof Map) {\n const copy = flatClone(object);\n const child = copy.get(first);\n copy.set(first, set(child, rest as any, value, rootPath));\n return copy;\n }\n\n if (object instanceof Set) {\n const copy = [...object];\n const child = copy[Number(first)];\n copy[Number(first)] = set(child, rest as any, value, rootPath);\n return new Set(copy) as any;\n }\n\n if (isObject(object) || object === undefined) {\n const copy = flatClone(object ?? ({} as T));\n copy[first as keyof T] = set(copy[first as keyof T], rest as any, value as any, rootPath);\n return copy;\n }\n\n throw new Error(`Could not set ${path} of ${object}`);\n}\n\nexport function remove<T, const P>(object: T, path: Constrain<P, Path<T, true>>): T {\n const _path = castArrayPath(path as any);\n\n if (_path.length === 0) {\n return undefined as any;\n }\n\n const parentPath = _path.slice(0, -1);\n const key = _path[_path.length - 1];\n\n const parent = flatClone(get(object, parentPath as any));\n\n if (parent instanceof Map) {\n parent.delete(key);\n } else if (parent instanceof Set) {\n const value = Array.from(parent)[Number(key)];\n parent.delete(value);\n } else if (Array.isArray(parent)) {\n parent.splice(Number(key), 1);\n } else {\n delete parent[key as keyof typeof parent];\n }\n\n return set(object, parentPath as any, parent);\n}\n\nexport function join(a: string, b: string): string {\n return [a, b].filter(Boolean).join('.');\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,610 @@
|
|
|
1
|
+
const require_chunk = require('../chunk-CUT6urMc.cjs');
|
|
2
|
+
const require_store = require('../store-BWMWEUpu.cjs');
|
|
3
|
+
const require_propAccess = require('../propAccess-ByqBjC19.cjs');
|
|
4
|
+
const require_hash = require('../hash-CJPl7SRj.cjs');
|
|
5
|
+
const require_extendedJson = require('../extendedJson-Dn2F7Edo.cjs');
|
|
6
|
+
const require_storeMethods = require('../storeMethods-DVVsmUg1.cjs');
|
|
7
|
+
const react = require_chunk.__toESM(require("react"));
|
|
8
|
+
const react_jsx_runtime = require_chunk.__toESM(require("react/jsx-runtime"));
|
|
9
|
+
|
|
10
|
+
//#region src/react/form/customInput.tsx
|
|
11
|
+
function CustomInput({ name, children,...props }) {
|
|
12
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
13
|
+
...props,
|
|
14
|
+
style: {
|
|
15
|
+
position: "relative",
|
|
16
|
+
...props.style
|
|
17
|
+
},
|
|
18
|
+
children: [children, /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
19
|
+
name,
|
|
20
|
+
style: {
|
|
21
|
+
position: "absolute",
|
|
22
|
+
top: 0,
|
|
23
|
+
left: 0,
|
|
24
|
+
opacity: 0,
|
|
25
|
+
width: "100%",
|
|
26
|
+
height: "100%",
|
|
27
|
+
pointerEvents: "none"
|
|
28
|
+
}
|
|
29
|
+
})]
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/lib/wildcardMatch.ts
|
|
35
|
+
function getWildCardMatches(object, path) {
|
|
36
|
+
const matches = {};
|
|
37
|
+
const [first, second, ...rest] = require_propAccess.castArrayPath(path);
|
|
38
|
+
if (first === void 0) throw new Error("Path is empty");
|
|
39
|
+
if (!Array.isArray(object) && !require_propAccess.isObject(object)) object = {};
|
|
40
|
+
for (const [key, value] of first !== "*" ? [[first, object[first]]] : Object.entries(object)) {
|
|
41
|
+
if (first !== "*" && first !== key) continue;
|
|
42
|
+
if (second === void 0) {
|
|
43
|
+
matches[key] = value;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
for (const [subKey, subValue] of Object.entries(getWildCardMatches(value, [second, ...rest]))) matches[`${key}.${subKey}`] = subValue;
|
|
47
|
+
}
|
|
48
|
+
return matches;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/react/form/formField.tsx
|
|
53
|
+
function FormField({ name = "", component, commitOnBlur, commitDebounce, render, inputFilter, defaultValue, serialize, deserialize = (x) => x, onChange, onBlur,...restProps }) {
|
|
54
|
+
const form = this.useForm();
|
|
55
|
+
const getFormState = () => ({
|
|
56
|
+
...form,
|
|
57
|
+
...getDerivedState(form)
|
|
58
|
+
});
|
|
59
|
+
const [localValue, setLocalValue] = (0, react.useState)();
|
|
60
|
+
const value = this.useFormState((form$1) => {
|
|
61
|
+
const value$1 = form$1.getField(name).value;
|
|
62
|
+
if (serialize) return serialize(value$1, getFormState());
|
|
63
|
+
if (value$1 !== void 0) return value$1;
|
|
64
|
+
return defaultValue;
|
|
65
|
+
});
|
|
66
|
+
const setValue = (x) => form.getField(name).setValue(deserialize(x, getFormState()));
|
|
67
|
+
const hasTriggeredValidations = this.useFormState((form$1) => form$1.hasTriggeredValidations);
|
|
68
|
+
(0, react.useEffect)(() => {
|
|
69
|
+
if (localValue === void 0 || !commitDebounce) return;
|
|
70
|
+
const timeout = setTimeout(() => {
|
|
71
|
+
setValue(localValue);
|
|
72
|
+
setLocalValue(void 0);
|
|
73
|
+
}, commitDebounce);
|
|
74
|
+
return () => clearTimeout(timeout);
|
|
75
|
+
}, [localValue, commitDebounce]);
|
|
76
|
+
const props = {
|
|
77
|
+
name,
|
|
78
|
+
value: localValue ?? value,
|
|
79
|
+
onChange: (event, ...moreArgs) => {
|
|
80
|
+
const value$1 = typeof event === "object" && event !== null && "target" in event ? event.target.value : event;
|
|
81
|
+
if (inputFilter && !inputFilter(value$1)) return;
|
|
82
|
+
if (commitOnBlur || commitDebounce) setLocalValue(value$1);
|
|
83
|
+
else setValue(value$1);
|
|
84
|
+
onChange?.(event, ...moreArgs);
|
|
85
|
+
},
|
|
86
|
+
onBlur(...args) {
|
|
87
|
+
if (localValue !== void 0) {
|
|
88
|
+
setValue(localValue);
|
|
89
|
+
setLocalValue(void 0);
|
|
90
|
+
}
|
|
91
|
+
onBlur?.(...args);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
if (render) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: render(props, {
|
|
95
|
+
...form.getField(name),
|
|
96
|
+
hasTriggeredValidations
|
|
97
|
+
}, form) ?? null });
|
|
98
|
+
if (component) return (0, react.createElement)(component, {
|
|
99
|
+
...restProps,
|
|
100
|
+
...props
|
|
101
|
+
});
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/react/form/formForEach.tsx
|
|
107
|
+
function FormForEach({ name, renderElement, children }) {
|
|
108
|
+
const form = this.useForm();
|
|
109
|
+
const names = this.useFormState(() => {
|
|
110
|
+
const field = form.getField(name);
|
|
111
|
+
return field.names;
|
|
112
|
+
});
|
|
113
|
+
const add = (0, react.useCallback)((...args) => {
|
|
114
|
+
const field = form.getField(name);
|
|
115
|
+
field.add(...args);
|
|
116
|
+
}, [form]);
|
|
117
|
+
const remove = (0, react.useCallback)((key) => {
|
|
118
|
+
const field = form.getField(name);
|
|
119
|
+
field.remove(key);
|
|
120
|
+
}, [form]);
|
|
121
|
+
const setValue = (0, react.useCallback)((value) => {
|
|
122
|
+
const field = form.getField(name);
|
|
123
|
+
field.setValue(value);
|
|
124
|
+
}, [form]);
|
|
125
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [renderElement && names.map((name$1, index) => {
|
|
126
|
+
const key = name$1.split(".").pop();
|
|
127
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: renderElement({
|
|
128
|
+
name: name$1,
|
|
129
|
+
key,
|
|
130
|
+
index,
|
|
131
|
+
remove: () => remove(key)
|
|
132
|
+
}) }, key);
|
|
133
|
+
}), children?.({
|
|
134
|
+
names,
|
|
135
|
+
add,
|
|
136
|
+
remove,
|
|
137
|
+
setValue
|
|
138
|
+
})] });
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/react/form/useFormAutosave.ts
|
|
143
|
+
function useFormAutosave(form) {
|
|
144
|
+
const { formState, options, getDraft } = form;
|
|
145
|
+
const debounceTime = require_store.calcDuration(options.autoSave?.debounce ?? 2e3);
|
|
146
|
+
const latestRef = (0, react.useRef)({ options });
|
|
147
|
+
const lastValue = (0, react.useRef)(void 0);
|
|
148
|
+
const q = (0, react.useMemo)(() => require_store.queue(), []);
|
|
149
|
+
const run = (0, react.useMemo)(() => require_store.debounce(async () => {
|
|
150
|
+
const { options: options$1 } = latestRef.current;
|
|
151
|
+
const save = options$1.autoSave?.save;
|
|
152
|
+
const draft = getDraft();
|
|
153
|
+
lastValue.current = draft;
|
|
154
|
+
q.clear();
|
|
155
|
+
q(async () => {
|
|
156
|
+
try {
|
|
157
|
+
formState.set("saveInProgress", true);
|
|
158
|
+
await save?.(draft, form);
|
|
159
|
+
if (q.size === 0 && options$1.autoSave?.resetAfterSave) form.reset();
|
|
160
|
+
} finally {
|
|
161
|
+
formState.set("saveInProgress", false);
|
|
162
|
+
if (q.size === 0) formState.set("saveScheduled", false);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}, debounceTime), [formState, debounceTime]);
|
|
166
|
+
(0, react.useEffect)(() => {
|
|
167
|
+
if (!options.autoSave?.save) return;
|
|
168
|
+
return formState.map((state) => state.draft).subscribe(() => {
|
|
169
|
+
if (require_propAccess.deepEqual(getDraft(), lastValue.current)) return;
|
|
170
|
+
run();
|
|
171
|
+
formState.set("saveScheduled", true);
|
|
172
|
+
}, { runNow: false });
|
|
173
|
+
}, [formState]);
|
|
174
|
+
(0, react.useEffect)(() => {
|
|
175
|
+
latestRef.current = { options };
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/react/form/form.tsx
|
|
181
|
+
function FormContainer({ form,...formProps }) {
|
|
182
|
+
const formInstance = form.useForm();
|
|
183
|
+
const hasTriggeredValidations = form.useFormState((state) => state.hasTriggeredValidations);
|
|
184
|
+
const formRef = (0, react.useRef)(null);
|
|
185
|
+
function updateValidity(errors, buttonElement) {
|
|
186
|
+
const formElement = formRef.current;
|
|
187
|
+
if (!formElement) return;
|
|
188
|
+
const localizedErrors = new Map([...errors.entries()].map(([field, errors$1]) => [field, errors$1.map((error) => formInstance.options.localizeError?.(error, field) ?? error)]));
|
|
189
|
+
for (const element of Array.from(formElement.elements)) if ("name" in element && "setCustomValidity" in element) element.setCustomValidity(localizedErrors.get(element.name)?.join("\n") ?? "");
|
|
190
|
+
if (buttonElement && "setCustomValidity" in buttonElement) {
|
|
191
|
+
const errorString = [...errors.values()].flat().join("\n");
|
|
192
|
+
buttonElement.setCustomValidity(errorString);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
(0, react.useEffect)(() => {
|
|
196
|
+
return formInstance.formState.map(() => formInstance.getErrors()).subscribe((errors) => updateValidity(errors));
|
|
197
|
+
}, []);
|
|
198
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("form", {
|
|
199
|
+
ref: formRef,
|
|
200
|
+
noValidate: true,
|
|
201
|
+
...formProps,
|
|
202
|
+
className: [formProps.className, hasTriggeredValidations ? formInstance.options.validatedClass ?? "validated" : void 0].filter(Boolean).join(" "),
|
|
203
|
+
onSubmit: async (event) => {
|
|
204
|
+
if (formInstance.saveInProgress()) return;
|
|
205
|
+
try {
|
|
206
|
+
formInstance.formState.set("saveInProgress", true);
|
|
207
|
+
event.preventDefault();
|
|
208
|
+
const formElement = event.currentTarget;
|
|
209
|
+
const buttonElement = event.nativeEvent instanceof SubmitEvent && event.nativeEvent.submitter instanceof HTMLButtonElement ? event.nativeEvent.submitter : void 0;
|
|
210
|
+
updateValidity(formInstance.getErrors(), buttonElement);
|
|
211
|
+
formElement.reportValidity();
|
|
212
|
+
const isValid = formInstance.validate();
|
|
213
|
+
if (isValid) await formProps.onSubmit?.(event, {
|
|
214
|
+
...formInstance,
|
|
215
|
+
...getDerivedState(formInstance)
|
|
216
|
+
});
|
|
217
|
+
} finally {
|
|
218
|
+
formInstance.formState.set("saveInProgress", false);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
function getField(form, path) {
|
|
224
|
+
const field = {
|
|
225
|
+
get originalValue() {
|
|
226
|
+
return form.original !== void 0 ? require_propAccess.get(form.original, path) : void 0;
|
|
227
|
+
},
|
|
228
|
+
get value() {
|
|
229
|
+
const draft = form.getDraft();
|
|
230
|
+
return require_propAccess.get(draft ?? form.original ?? form.options.defaultValue, path);
|
|
231
|
+
},
|
|
232
|
+
setValue(update) {
|
|
233
|
+
form.formState.set("draft", (draft = form.original ?? form.options.defaultValue) => {
|
|
234
|
+
if (update instanceof Function) update = update(require_propAccess.get(draft, path));
|
|
235
|
+
return require_propAccess.set(draft, path, update);
|
|
236
|
+
});
|
|
237
|
+
},
|
|
238
|
+
get hasChange() {
|
|
239
|
+
return !require_propAccess.deepEqual(this.originalValue, this.value);
|
|
240
|
+
},
|
|
241
|
+
get errors() {
|
|
242
|
+
const errors = form.getErrors();
|
|
243
|
+
return errors.get(path) ?? [];
|
|
244
|
+
},
|
|
245
|
+
get names() {
|
|
246
|
+
const { value } = this;
|
|
247
|
+
if (Array.isArray(value)) return value.map((_, index) => require_propAccess.join(path, String(index)));
|
|
248
|
+
if (require_propAccess.isObject(value)) return Object.keys(value).map((key) => require_propAccess.join(path, key));
|
|
249
|
+
return [];
|
|
250
|
+
},
|
|
251
|
+
add(...args) {
|
|
252
|
+
this.setValue((value) => {
|
|
253
|
+
if (!value) throw new Error(`Cannot add element to ${JSON.stringify(value)}`);
|
|
254
|
+
if (Array.isArray(value)) return [...value ?? [], args[0]];
|
|
255
|
+
if (require_propAccess.isObject(value)) return {
|
|
256
|
+
...value,
|
|
257
|
+
[args[0]]: args[1]
|
|
258
|
+
};
|
|
259
|
+
throw new Error(`Cannot add element to ${JSON.stringify(value)}`);
|
|
260
|
+
});
|
|
261
|
+
},
|
|
262
|
+
remove(key) {
|
|
263
|
+
this.setValue((value) => {
|
|
264
|
+
if (!value) throw new Error(`Cannot remove element from ${JSON.stringify(value)}`);
|
|
265
|
+
if (Array.isArray(value)) return value.filter((_, index) => index !== Number(key));
|
|
266
|
+
if (require_propAccess.isObject(value)) {
|
|
267
|
+
const { [key]: _,...rest } = value;
|
|
268
|
+
return rest;
|
|
269
|
+
}
|
|
270
|
+
throw new Error(`Cannot remove element from ${JSON.stringify(value)}`);
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
return field;
|
|
275
|
+
}
|
|
276
|
+
function getErrors(draft, original, validations) {
|
|
277
|
+
const errors = /* @__PURE__ */ new Map();
|
|
278
|
+
for (const [path, block] of Object.entries(validations ?? {})) for (const [validationName, validate] of Object.entries(block)) {
|
|
279
|
+
let matched = false;
|
|
280
|
+
for (const [field, value] of Object.entries(getWildCardMatches(draft, path))) {
|
|
281
|
+
matched = true;
|
|
282
|
+
if (!validate(value, {
|
|
283
|
+
draft,
|
|
284
|
+
original,
|
|
285
|
+
field
|
|
286
|
+
})) {
|
|
287
|
+
const fieldErrors = errors.get(field) ?? [];
|
|
288
|
+
fieldErrors.push(validationName);
|
|
289
|
+
errors.set(field, fieldErrors);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (!matched && !path.includes("*")) {
|
|
293
|
+
if (!validate(void 0, {
|
|
294
|
+
draft,
|
|
295
|
+
original,
|
|
296
|
+
field: path
|
|
297
|
+
})) {
|
|
298
|
+
const fieldErrors = errors.get(path) ?? [];
|
|
299
|
+
fieldErrors.push(validationName);
|
|
300
|
+
errors.set(path, fieldErrors);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return errors;
|
|
305
|
+
}
|
|
306
|
+
function getDerivedState(instance) {
|
|
307
|
+
return {
|
|
308
|
+
draft: instance.getDraft(),
|
|
309
|
+
hasTriggeredValidations: instance.hasTriggeredValidations(),
|
|
310
|
+
saveScheduled: instance.saveScheduled(),
|
|
311
|
+
saveInProgress: instance.saveInProgress(),
|
|
312
|
+
hasChanges: instance.hasChanges(),
|
|
313
|
+
errors: instance.getErrors(),
|
|
314
|
+
isValid: instance.isValid()
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
var Form = class Form {
|
|
318
|
+
constructor(options) {
|
|
319
|
+
this.options = options;
|
|
320
|
+
this.context = (0, react.createContext)(null);
|
|
321
|
+
require_store.autobind(Form);
|
|
322
|
+
}
|
|
323
|
+
useForm() {
|
|
324
|
+
const context = (0, react.useContext)(this.context);
|
|
325
|
+
if (!context) throw new Error("Form context not found");
|
|
326
|
+
return context;
|
|
327
|
+
}
|
|
328
|
+
useFormState(selector, useStoreOptions) {
|
|
329
|
+
const form = this.useForm();
|
|
330
|
+
return require_storeMethods.useStore(form.formState, () => selector({
|
|
331
|
+
...form,
|
|
332
|
+
...getDerivedState(form)
|
|
333
|
+
}), useStoreOptions);
|
|
334
|
+
}
|
|
335
|
+
useField(path, useStoreOptions) {
|
|
336
|
+
const form = this.useForm();
|
|
337
|
+
this.useFormState((form$1) => [form$1.getField(path).value, form$1.original], useStoreOptions);
|
|
338
|
+
return form.getField(path);
|
|
339
|
+
}
|
|
340
|
+
Form({ original, defaultValue, validations, localizeError, autoSave, transform, validatedClass,...formProps }) {
|
|
341
|
+
const options = {
|
|
342
|
+
defaultValue: {
|
|
343
|
+
...this.options.defaultValue,
|
|
344
|
+
...defaultValue
|
|
345
|
+
},
|
|
346
|
+
validations: {
|
|
347
|
+
...this.options.validations,
|
|
348
|
+
...validations
|
|
349
|
+
},
|
|
350
|
+
localizeError: localizeError ?? this.options.localizeError,
|
|
351
|
+
autoSave: autoSave ?? this.options.autoSave,
|
|
352
|
+
transform: transform ?? this.options.transform,
|
|
353
|
+
validatedClass: validatedClass ?? this.options.validatedClass
|
|
354
|
+
};
|
|
355
|
+
const formState = (0, react.useMemo)(() => {
|
|
356
|
+
return require_store.createStore({
|
|
357
|
+
draft: void 0,
|
|
358
|
+
hasTriggeredValidations: false,
|
|
359
|
+
saveScheduled: false,
|
|
360
|
+
saveInProgress: false
|
|
361
|
+
});
|
|
362
|
+
}, []);
|
|
363
|
+
let lastDraft;
|
|
364
|
+
const cache = /* @__PURE__ */ new Map();
|
|
365
|
+
function lazy(key, fn) {
|
|
366
|
+
if (lastDraft !== formState.get().draft) {
|
|
367
|
+
cache.clear();
|
|
368
|
+
lastDraft = formState.get().draft;
|
|
369
|
+
}
|
|
370
|
+
let value = cache.get(key);
|
|
371
|
+
if (!cache.has(key)) {
|
|
372
|
+
value = fn();
|
|
373
|
+
cache.set(key, value);
|
|
374
|
+
}
|
|
375
|
+
return value;
|
|
376
|
+
}
|
|
377
|
+
const context = {
|
|
378
|
+
formState,
|
|
379
|
+
options,
|
|
380
|
+
original,
|
|
381
|
+
getField() {
|
|
382
|
+
throw new Error("Not implemented");
|
|
383
|
+
},
|
|
384
|
+
getDraft() {
|
|
385
|
+
return formState.get().draft ?? original ?? options.defaultValue;
|
|
386
|
+
},
|
|
387
|
+
hasTriggeredValidations() {
|
|
388
|
+
return formState.get().hasTriggeredValidations;
|
|
389
|
+
},
|
|
390
|
+
saveScheduled() {
|
|
391
|
+
return formState.get().saveScheduled;
|
|
392
|
+
},
|
|
393
|
+
saveInProgress() {
|
|
394
|
+
return formState.get().saveInProgress;
|
|
395
|
+
},
|
|
396
|
+
hasChanges() {
|
|
397
|
+
return lazy("hasChanges", () => !require_propAccess.deepEqual(this.getDraft(), original ?? options.defaultValue));
|
|
398
|
+
},
|
|
399
|
+
getErrors() {
|
|
400
|
+
return lazy("getErrors", () => getErrors(this.getDraft(), original, options.validations));
|
|
401
|
+
},
|
|
402
|
+
isValid() {
|
|
403
|
+
return lazy("isValid", () => this.getErrors().size === 0);
|
|
404
|
+
},
|
|
405
|
+
validate() {
|
|
406
|
+
formState.set("hasTriggeredValidations", true);
|
|
407
|
+
return this.isValid();
|
|
408
|
+
},
|
|
409
|
+
reset() {
|
|
410
|
+
formState.set("draft", void 0);
|
|
411
|
+
formState.set("hasTriggeredValidations", false);
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
context.getField = (path) => lazy(path, () => getField(context, path));
|
|
415
|
+
useFormAutosave(context);
|
|
416
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(this.context.Provider, {
|
|
417
|
+
value: context,
|
|
418
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FormContainer, {
|
|
419
|
+
...formProps,
|
|
420
|
+
form: this
|
|
421
|
+
})
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
FormState({ selector, children }) {
|
|
425
|
+
const selectedState = this.useFormState(selector);
|
|
426
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: children(selectedState) });
|
|
427
|
+
}
|
|
428
|
+
Field(props) {
|
|
429
|
+
return Reflect.apply(FormField, this, [{
|
|
430
|
+
component: "input",
|
|
431
|
+
...props
|
|
432
|
+
}]);
|
|
433
|
+
}
|
|
434
|
+
ForEach(props) {
|
|
435
|
+
return Reflect.apply(FormForEach, this, [props]);
|
|
436
|
+
}
|
|
437
|
+
withForm(Component, formProps) {
|
|
438
|
+
const { Form: Form$1 } = this;
|
|
439
|
+
return function FormWrapper(props) {
|
|
440
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Form$1, {
|
|
441
|
+
...formProps,
|
|
442
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Component, { ...props })
|
|
443
|
+
});
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
function createForm(options) {
|
|
448
|
+
return new Form(options);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
//#endregion
|
|
452
|
+
//#region src/react/url/urlContext.tsx
|
|
453
|
+
const UrlContext = (0, react.createContext)(void 0);
|
|
454
|
+
function UrlProvider({ children,...props }) {
|
|
455
|
+
const location = "location" in props ? props.location : props.locationHook();
|
|
456
|
+
const navigate = "navigate" in props ? props.navigate : props.navigateHook();
|
|
457
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(UrlContext.Provider, {
|
|
458
|
+
value: {
|
|
459
|
+
location,
|
|
460
|
+
navigate
|
|
461
|
+
},
|
|
462
|
+
children
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
function useUrlContext() {
|
|
466
|
+
const context = (0, react.useContext)(UrlContext);
|
|
467
|
+
if (!context) throw new Error("useUrlContext must be used within a UrlContextProvider");
|
|
468
|
+
return context;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
//#endregion
|
|
472
|
+
//#region src/react/url/urlOptions.ts
|
|
473
|
+
function createUrlOptions(options) {
|
|
474
|
+
return {
|
|
475
|
+
...options,
|
|
476
|
+
defaultValue: options.defaultValue
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
//#endregion
|
|
481
|
+
//#region src/react/url/urlHelpers.ts
|
|
482
|
+
function defaultDeserializer(value) {
|
|
483
|
+
if (value === void 0) return void 0;
|
|
484
|
+
try {
|
|
485
|
+
return require_extendedJson.fromExtendedJsonString(value);
|
|
486
|
+
} catch {
|
|
487
|
+
return void 0;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
function defaultSerializer(value) {
|
|
491
|
+
return require_extendedJson.toExtendedJsonString(value);
|
|
492
|
+
}
|
|
493
|
+
function parseLocation(location) {
|
|
494
|
+
if (typeof location !== "string") location = `${location.pathname}${location.search}${location.hash}`;
|
|
495
|
+
return new URL(location, window.location.origin);
|
|
496
|
+
}
|
|
497
|
+
function createStorageKey(id, key) {
|
|
498
|
+
return `cross-state:url:${id}:${key}`;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
//#endregion
|
|
502
|
+
//#region src/react/url/useUrlParam.ts
|
|
503
|
+
function useUrlParam(input) {
|
|
504
|
+
const { key, type = "hash", serialize = defaultSerializer, deserialize = defaultDeserializer, defaultValue, writeDefaultValue, onCommit, persist } = "options" in input ? input.options : input;
|
|
505
|
+
const { location, navigate } = useUrlContext();
|
|
506
|
+
const url = parseLocation(location);
|
|
507
|
+
const params = new URLSearchParams(url[type].slice(1));
|
|
508
|
+
const urlValue = params.get(key);
|
|
509
|
+
const storageKey = persist && createStorageKey(persist.id, key);
|
|
510
|
+
const storageValue = storageKey ? localStorage.getItem(storageKey) : null;
|
|
511
|
+
const value = (0, react.useMemo)(() => urlValue !== null ? deserialize(urlValue) : storageValue !== null ? deserialize(storageValue) : defaultValue, [urlValue]);
|
|
512
|
+
function commit(value$1) {
|
|
513
|
+
const serializedValue = serialize(value$1);
|
|
514
|
+
navigate((location$1) => {
|
|
515
|
+
const url$1 = parseLocation(location$1);
|
|
516
|
+
const params$1 = new URLSearchParams(url$1[type].slice(1));
|
|
517
|
+
if (!writeDefaultValue && serializedValue === serialize(defaultValue)) params$1.delete(key);
|
|
518
|
+
else params$1.set(key, serializedValue);
|
|
519
|
+
url$1[type] = params$1.toString();
|
|
520
|
+
return url$1.toString().replace(window.location.origin, "");
|
|
521
|
+
});
|
|
522
|
+
if (storageKey) localStorage.setItem(storageKey, serializedValue);
|
|
523
|
+
onCommit?.(value$1);
|
|
524
|
+
}
|
|
525
|
+
function update(update$1) {
|
|
526
|
+
if (update$1 instanceof Function) update$1 = update$1(value);
|
|
527
|
+
commit(update$1);
|
|
528
|
+
}
|
|
529
|
+
(0, react.useEffect)(() => {
|
|
530
|
+
if (urlValue !== null) commit(deserialize(urlValue));
|
|
531
|
+
}, [urlValue]);
|
|
532
|
+
(0, react.useEffect)(() => {
|
|
533
|
+
if (urlValue === null && storageValue !== null) commit(deserialize(storageValue));
|
|
534
|
+
else if (urlValue === null && writeDefaultValue) commit(defaultValue);
|
|
535
|
+
}, []);
|
|
536
|
+
return [value, update];
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
//#endregion
|
|
540
|
+
//#region src/react/url/urlStore.ts
|
|
541
|
+
var UrlStore = class {
|
|
542
|
+
constructor(options) {
|
|
543
|
+
this.options = options;
|
|
544
|
+
}
|
|
545
|
+
useStore() {
|
|
546
|
+
return useUrlParam(this)[0];
|
|
547
|
+
}
|
|
548
|
+
useProp() {
|
|
549
|
+
return useUrlParam(this);
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
function createUrlStore(options) {
|
|
553
|
+
return new UrlStore(createUrlOptions(options));
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
//#endregion
|
|
557
|
+
//#region src/react/useDecoupledState.ts
|
|
558
|
+
function useDecoupledState(value, onChange, options = {}) {
|
|
559
|
+
const [dirty, setDirty] = (0, react.useState)();
|
|
560
|
+
const ref = (0, react.useRef)({
|
|
561
|
+
onChange,
|
|
562
|
+
onCommit: options.onCommit
|
|
563
|
+
});
|
|
564
|
+
(0, react.useEffect)(() => {
|
|
565
|
+
ref.current = {
|
|
566
|
+
onChange,
|
|
567
|
+
onCommit: options.onCommit
|
|
568
|
+
};
|
|
569
|
+
}, [onChange]);
|
|
570
|
+
const update = (0, react.useMemo)(() => {
|
|
571
|
+
const { onChange: onChange$1, onCommit } = ref.current;
|
|
572
|
+
const update$1 = (value$1) => {
|
|
573
|
+
onChange$1(value$1);
|
|
574
|
+
setDirty(void 0);
|
|
575
|
+
onCommit?.(value$1);
|
|
576
|
+
};
|
|
577
|
+
let delayedUpdate;
|
|
578
|
+
if (options.debounce) delayedUpdate = require_store.debounce(update$1, options.debounce);
|
|
579
|
+
else if (options.throttle) delayedUpdate = require_store.throttle(update$1, options.throttle);
|
|
580
|
+
else delayedUpdate = (value$1) => (0, react.startTransition)(() => update$1(value$1));
|
|
581
|
+
return (value$1) => {
|
|
582
|
+
setDirty({ v: value$1 });
|
|
583
|
+
delayedUpdate(value$1);
|
|
584
|
+
};
|
|
585
|
+
}, [require_hash.simpleHash([options.debounce, options.throttle])]);
|
|
586
|
+
return [dirty ? dirty.v : value, update];
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
//#endregion
|
|
590
|
+
exports.CustomInput = CustomInput;
|
|
591
|
+
exports.Form = Form;
|
|
592
|
+
exports.LoadingBoundary = require_storeMethods.LoadingBoundary;
|
|
593
|
+
exports.ScopeProvider = require_storeMethods.ScopeProvider;
|
|
594
|
+
exports.UrlContext = UrlContext;
|
|
595
|
+
exports.UrlProvider = UrlProvider;
|
|
596
|
+
exports.cacheMethods = require_storeMethods.cacheMethods;
|
|
597
|
+
exports.createForm = createForm;
|
|
598
|
+
exports.createUrlOptions = createUrlOptions;
|
|
599
|
+
exports.createUrlStore = createUrlStore;
|
|
600
|
+
exports.scopeMethods = require_storeMethods.scopeMethods;
|
|
601
|
+
exports.storeMethods = require_storeMethods.storeMethods;
|
|
602
|
+
exports.useCache = require_storeMethods.useCache;
|
|
603
|
+
exports.useDecoupledState = useDecoupledState;
|
|
604
|
+
exports.useLoadingBoundary = require_storeMethods.useLoadingBoundary;
|
|
605
|
+
exports.useProp = require_storeMethods.useProp;
|
|
606
|
+
exports.useScope = require_storeMethods.useScope;
|
|
607
|
+
exports.useStore = require_storeMethods.useStore;
|
|
608
|
+
exports.useUrlContext = useUrlContext;
|
|
609
|
+
exports.useUrlParam = useUrlParam;
|
|
610
|
+
//# sourceMappingURL=index.cjs.map
|