cross-state 0.55.5 → 0.56.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/{diff-BQ8bB3Wk.d.cts → diff-D7XuntCn.d.cts} +2 -2
- package/dist/{diff-gZezL04N.d.ts → diff-qAkLCsnM.d.ts} +2 -2
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -3
- package/dist/mutative/index.d.cts +2 -2
- package/dist/mutative/index.d.ts +2 -2
- package/dist/mutative/register.cjs +1 -1
- package/dist/mutative/register.d.cts +2 -2
- package/dist/mutative/register.d.ts +2 -2
- package/dist/mutative/register.js +1 -1
- package/dist/{mutativeMethods-6QzygG3W.d.cts → mutativeMethods-Be_XPk5N.d.cts} +2 -2
- package/dist/{mutativeMethods-Br3xN2Iq.d.ts → mutativeMethods-DRYtjUcH.d.ts} +2 -2
- package/dist/{patchMethods-pw_OcPA8.d.cts → patchMethods-BlYtjRUU.d.cts} +3 -3
- package/dist/{patchMethods-CT9M507t.d.ts → patchMethods-Dr2OFh02.d.ts} +3 -3
- package/dist/patches/index.d.cts +3 -3
- package/dist/patches/index.d.ts +3 -3
- package/dist/patches/register.cjs +1 -1
- package/dist/patches/register.d.cts +3 -3
- package/dist/patches/register.d.ts +3 -3
- package/dist/patches/register.js +1 -1
- package/dist/persist/register.cjs +2 -2
- package/dist/persist/register.d.cts +2 -2
- package/dist/persist/register.d.ts +2 -2
- package/dist/persist/register.js +2 -2
- package/dist/{persist-CPjpg6D0.d.ts → persist-CIEYJ0rO.d.ts} +2 -2
- package/dist/{persist-CGLe7YUX.cjs → persist-CQhYPv4d.cjs} +2 -2
- package/dist/{persist-CGLe7YUX.cjs.map → persist-CQhYPv4d.cjs.map} +1 -1
- package/dist/{persist-D7MAsyyW.d.cts → persist-CR3mhti7.d.cts} +2 -2
- package/dist/{persist-Btgg3qGU.js → persist-DFzbvNoJ.js} +2 -2
- package/dist/{persist-Btgg3qGU.js.map → persist-DFzbvNoJ.js.map} +1 -1
- package/dist/react/index.cjs +127 -82
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +25 -47
- package/dist/react/index.d.ts +25 -47
- package/dist/react/index.js +127 -79
- package/dist/react/index.js.map +1 -1
- package/dist/react/register.cjs +3 -3
- package/dist/react/register.d.cts +3 -3
- package/dist/react/register.d.ts +3 -3
- package/dist/react/register.js +3 -3
- package/dist/{scope-BbUXgNW_.d.ts → scope-ByLCVzKk.d.ts} +2 -2
- package/dist/{scope-CoDFmhxK.cjs → scope-C9JXWddv.cjs} +6 -3
- package/dist/scope-C9JXWddv.cjs.map +1 -0
- package/dist/{scope-6B7-8lwa.d.cts → scope-DkO-RIMy.d.cts} +2 -2
- package/dist/{scope-CKXL9xoi.js → scope-Mhr133F_.js} +6 -3
- package/dist/scope-Mhr133F_.js.map +1 -0
- package/dist/{store-DKaeE840.d.ts → store-B3PWCx63.d.cts} +2 -1
- package/dist/{store-BEsiS8y7.d.cts → store-BJWoRQIs.d.ts} +2 -1
- package/dist/{store-BpMJxIHt.js → store-DOEc60aP.js} +9 -7
- package/dist/store-DOEc60aP.js.map +1 -0
- package/dist/{store-1TGlSyq4.cjs → store-DQcFfgKD.cjs} +9 -7
- package/dist/store-DQcFfgKD.cjs.map +1 -0
- package/dist/{storeMethods-CkvcMFoL.js → storeMethods-C7bswcgj.js} +2 -2
- package/dist/{storeMethods-CkvcMFoL.js.map → storeMethods-C7bswcgj.js.map} +1 -1
- package/dist/{storeMethods-Bg8nMBrf.d.cts → storeMethods-Dt_mJTe3.d.cts} +3 -3
- package/dist/{storeMethods-C_RzHBQL.cjs → storeMethods-YDnpa-6-.cjs} +2 -2
- package/dist/{storeMethods-C_RzHBQL.cjs.map → storeMethods-YDnpa-6-.cjs.map} +1 -1
- package/dist/{storeMethods-DWKSveN0.d.ts → storeMethods-wsbbfJzY.d.ts} +3 -3
- package/package.json +3 -3
- package/dist/scope-CKXL9xoi.js.map +0 -1
- package/dist/scope-CoDFmhxK.cjs.map +0 -1
- package/dist/store-1TGlSyq4.cjs.map +0 -1
- package/dist/store-BpMJxIHt.js.map +0 -1
package/dist/react/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import "../scope-
|
|
2
|
-
import { Constrain, Duration, GetKeys, Join, MaybePromise, Object_, Path as Path$1, PathAsString, Selector, Store, Update,
|
|
3
|
-
import { ScopeProps, ScopeProvider, UseCacheArray, UseCacheValue, UseStoreOptions, cacheMethods, scopeMethods, storeMethods, useCache, useScope, useStore } from "../storeMethods-
|
|
4
|
-
import
|
|
1
|
+
import "../scope-DkO-RIMy.cjs";
|
|
2
|
+
import { Constrain, Duration, GetKeys, Join, MaybePromise, Object_, Path as Path$1, PathAsString, Selector, Store, Update, Value, WildcardPathAsString, WildcardValue } from "../store-B3PWCx63.cjs";
|
|
3
|
+
import { ScopeProps, ScopeProvider, UseCacheArray, UseCacheValue, UseStoreOptions, cacheMethods, scopeMethods, storeMethods, useCache, useScope, useStore } from "../storeMethods-Dt_mJTe3.cjs";
|
|
4
|
+
import { Component, ComponentPropsWithoutRef, Context, FormEvent, FunctionComponent, HTMLProps, ReactNode } from "react";
|
|
5
5
|
|
|
6
6
|
//#region src/react/form/customInput.d.ts
|
|
7
7
|
interface CustomInputProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
@@ -223,34 +223,6 @@ declare function LoadingBoundary({
|
|
|
223
223
|
}: LoadingBoundaryProps): React.JSX.Element;
|
|
224
224
|
declare function useLoadingBoundary(isLoading: boolean | undefined, label?: ReactNode): void;
|
|
225
225
|
//#endregion
|
|
226
|
-
//#region src/react/url/urlContext.d.ts
|
|
227
|
-
type Location = string | {
|
|
228
|
-
pathname: string;
|
|
229
|
-
search: string;
|
|
230
|
-
hash: string;
|
|
231
|
-
};
|
|
232
|
-
interface UrlContextType {
|
|
233
|
-
location: Location;
|
|
234
|
-
navigate: (navigate: (from: Location) => string) => void;
|
|
235
|
-
}
|
|
236
|
-
type UrlContextProviderProps = {
|
|
237
|
-
children?: ReactNode;
|
|
238
|
-
} & ({
|
|
239
|
-
location: UrlContextType["location"];
|
|
240
|
-
} | {
|
|
241
|
-
locationHook: () => UrlContextType["location"];
|
|
242
|
-
}) & ({
|
|
243
|
-
navigate: UrlContextType["navigate"];
|
|
244
|
-
} | {
|
|
245
|
-
navigateHook: () => UrlContextType["navigate"];
|
|
246
|
-
});
|
|
247
|
-
declare const UrlContext: Context<UrlContextType | undefined>;
|
|
248
|
-
declare function UrlProvider({
|
|
249
|
-
children,
|
|
250
|
-
...props
|
|
251
|
-
}: UrlContextProviderProps): React$1.JSX.Element;
|
|
252
|
-
declare function useUrlContext(): UrlContextType;
|
|
253
|
-
//#endregion
|
|
254
226
|
//#region src/react/url/urlOptions.d.ts
|
|
255
227
|
interface UrlOptions<T> {
|
|
256
228
|
key: string;
|
|
@@ -263,6 +235,7 @@ interface UrlOptions<T> {
|
|
|
263
235
|
persist?: {
|
|
264
236
|
id: string;
|
|
265
237
|
} | null;
|
|
238
|
+
path?: string | RegExp | (string | RegExp)[] | null;
|
|
266
239
|
}
|
|
267
240
|
interface UrlOptionsWithoutDefaults<T> extends Omit<UrlOptions<T | undefined>, "defaultValue"> {
|
|
268
241
|
defaultValue?: T | undefined;
|
|
@@ -270,21 +243,26 @@ interface UrlOptionsWithoutDefaults<T> extends Omit<UrlOptions<T | undefined>, "
|
|
|
270
243
|
declare function createUrlOptions<T>(options: UrlOptions<T>): Required<UrlOptions<T>>;
|
|
271
244
|
declare function createUrlOptions<T>(options: UrlOptionsWithoutDefaults<T>): Required<UrlOptions<T | undefined>>;
|
|
272
245
|
//#endregion
|
|
273
|
-
//#region src/react/url/
|
|
274
|
-
declare
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
246
|
+
//#region src/react/url/urlParamStore.d.ts
|
|
247
|
+
declare const urlStore: Store<string>;
|
|
248
|
+
declare class UrlParamStore<T> extends Store<T> {
|
|
249
|
+
readonly urlOptions: Required<UrlOptions<T>>;
|
|
250
|
+
private lastHref?;
|
|
251
|
+
private lastStorageValue?;
|
|
252
|
+
private lastValue?;
|
|
253
|
+
private storageKey;
|
|
254
|
+
constructor(urlOptions: Required<UrlOptions<T>>);
|
|
255
|
+
private getUrlValue;
|
|
256
|
+
private getStorageValue;
|
|
257
|
+
private isPathActive;
|
|
258
|
+
private calc;
|
|
259
|
+
private updateUrl;
|
|
260
|
+
private updateStorage;
|
|
261
|
+
set(update: Update<T>): void;
|
|
262
|
+
set<const P>(path: Constrain<P, Path$1<T>>, update: Update<Value<T, P>>): void;
|
|
280
263
|
}
|
|
281
|
-
declare function
|
|
282
|
-
declare function
|
|
283
|
-
//#endregion
|
|
284
|
-
//#region src/react/url/useUrlParam.d.ts
|
|
285
|
-
declare function useUrlParam<T>(store: UrlStore<T>): [T, update: UpdateFunction<T>];
|
|
286
|
-
declare function useUrlParam<T>(options: UrlOptions<T>): [T, update: UpdateFunction<T>];
|
|
287
|
-
declare function useUrlParam<T>(options: UrlOptionsWithoutDefaults<T>): [T | undefined, update: UpdateFunction<T | undefined>];
|
|
264
|
+
declare function createUrlParam<T>(options: UrlOptions<T>): UrlParamStore<T>;
|
|
265
|
+
declare function createUrlParam<T>(options: UrlOptionsWithoutDefaults<T>): UrlParamStore<T | undefined>;
|
|
288
266
|
//#endregion
|
|
289
267
|
//#region src/react/useDecoupledState.d.ts
|
|
290
268
|
interface UseDecoupledStateOptions<T> {
|
|
@@ -299,5 +277,5 @@ declare function useProp<T, S>(store: Store<T>, selector: Selector<T, S>, update
|
|
|
299
277
|
declare function useProp<T, const P>(store: Store<T>, selector: Constrain<P, Path$1<T>>, options?: UseStoreOptions<Value<T, P>>): [value: Value<T, P>, setValue: Store<Value<T, P>>["set"]];
|
|
300
278
|
declare function useProp<T>(store: Store<T>, options?: UseStoreOptions<T>): [value: T, setValue: Store<T>["set"]];
|
|
301
279
|
//#endregion
|
|
302
|
-
export { CustomInput, CustomInputProps, Field, Form, FormContext, FormDerivedState, FormFieldComponent, FormFieldComponentProps, FormFieldInfos, FormFieldProps, FormFieldPropsWithComponent, FormFieldPropsWithRender, FormInstance, FormOptions, FormState, LoadingBoundary, type LoadingBoundaryEntry, type LoadingBoundaryProps, type ScopeProps, ScopeProvider, Transform,
|
|
280
|
+
export { CustomInput, CustomInputProps, Field, Form, FormContext, FormDerivedState, FormFieldComponent, FormFieldComponentProps, FormFieldInfos, FormFieldProps, FormFieldPropsWithComponent, FormFieldPropsWithRender, FormInstance, FormOptions, FormState, LoadingBoundary, type LoadingBoundaryEntry, type LoadingBoundaryProps, type ScopeProps, ScopeProvider, Transform, type UrlOptions, type UrlOptionsWithoutDefaults, type UrlParamStore, type UseCacheArray, type UseCacheValue, type UseDecoupledStateOptions, type UseStoreOptions, Validation, Validations, cacheMethods, createForm, createUrlOptions, createUrlParam, scopeMethods, storeMethods, urlStore, useCache, useDecoupledState, useLoadingBoundary, useProp, useScope, useStore };
|
|
303
281
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import "../scope-
|
|
2
|
-
import { Constrain, Duration, GetKeys, Join, MaybePromise, Object_, Path as Path$1, PathAsString, Selector, Store, Update,
|
|
3
|
-
import { ScopeProps, ScopeProvider, UseCacheArray, UseCacheValue, UseStoreOptions, cacheMethods, scopeMethods, storeMethods, useCache, useScope, useStore } from "../storeMethods-
|
|
4
|
-
import
|
|
1
|
+
import "../scope-ByLCVzKk.js";
|
|
2
|
+
import { Constrain, Duration, GetKeys, Join, MaybePromise, Object_, Path as Path$1, PathAsString, Selector, Store, Update, Value, WildcardPathAsString, WildcardValue } from "../store-BJWoRQIs.js";
|
|
3
|
+
import { ScopeProps, ScopeProvider, UseCacheArray, UseCacheValue, UseStoreOptions, cacheMethods, scopeMethods, storeMethods, useCache, useScope, useStore } from "../storeMethods-wsbbfJzY.js";
|
|
4
|
+
import { Component, ComponentPropsWithoutRef, Context, FormEvent, FunctionComponent, HTMLProps, ReactNode } from "react";
|
|
5
5
|
|
|
6
6
|
//#region src/react/form/customInput.d.ts
|
|
7
7
|
interface CustomInputProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
@@ -223,34 +223,6 @@ declare function LoadingBoundary({
|
|
|
223
223
|
}: LoadingBoundaryProps): React.JSX.Element;
|
|
224
224
|
declare function useLoadingBoundary(isLoading: boolean | undefined, label?: ReactNode): void;
|
|
225
225
|
//#endregion
|
|
226
|
-
//#region src/react/url/urlContext.d.ts
|
|
227
|
-
type Location = string | {
|
|
228
|
-
pathname: string;
|
|
229
|
-
search: string;
|
|
230
|
-
hash: string;
|
|
231
|
-
};
|
|
232
|
-
interface UrlContextType {
|
|
233
|
-
location: Location;
|
|
234
|
-
navigate: (navigate: (from: Location) => string) => void;
|
|
235
|
-
}
|
|
236
|
-
type UrlContextProviderProps = {
|
|
237
|
-
children?: ReactNode;
|
|
238
|
-
} & ({
|
|
239
|
-
location: UrlContextType["location"];
|
|
240
|
-
} | {
|
|
241
|
-
locationHook: () => UrlContextType["location"];
|
|
242
|
-
}) & ({
|
|
243
|
-
navigate: UrlContextType["navigate"];
|
|
244
|
-
} | {
|
|
245
|
-
navigateHook: () => UrlContextType["navigate"];
|
|
246
|
-
});
|
|
247
|
-
declare const UrlContext: Context<UrlContextType | undefined>;
|
|
248
|
-
declare function UrlProvider({
|
|
249
|
-
children,
|
|
250
|
-
...props
|
|
251
|
-
}: UrlContextProviderProps): React$1.JSX.Element;
|
|
252
|
-
declare function useUrlContext(): UrlContextType;
|
|
253
|
-
//#endregion
|
|
254
226
|
//#region src/react/url/urlOptions.d.ts
|
|
255
227
|
interface UrlOptions<T> {
|
|
256
228
|
key: string;
|
|
@@ -263,6 +235,7 @@ interface UrlOptions<T> {
|
|
|
263
235
|
persist?: {
|
|
264
236
|
id: string;
|
|
265
237
|
} | null;
|
|
238
|
+
path?: string | RegExp | (string | RegExp)[] | null;
|
|
266
239
|
}
|
|
267
240
|
interface UrlOptionsWithoutDefaults<T> extends Omit<UrlOptions<T | undefined>, "defaultValue"> {
|
|
268
241
|
defaultValue?: T | undefined;
|
|
@@ -270,21 +243,26 @@ interface UrlOptionsWithoutDefaults<T> extends Omit<UrlOptions<T | undefined>, "
|
|
|
270
243
|
declare function createUrlOptions<T>(options: UrlOptions<T>): Required<UrlOptions<T>>;
|
|
271
244
|
declare function createUrlOptions<T>(options: UrlOptionsWithoutDefaults<T>): Required<UrlOptions<T | undefined>>;
|
|
272
245
|
//#endregion
|
|
273
|
-
//#region src/react/url/
|
|
274
|
-
declare
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
246
|
+
//#region src/react/url/urlParamStore.d.ts
|
|
247
|
+
declare const urlStore: Store<string>;
|
|
248
|
+
declare class UrlParamStore<T> extends Store<T> {
|
|
249
|
+
readonly urlOptions: Required<UrlOptions<T>>;
|
|
250
|
+
private lastHref?;
|
|
251
|
+
private lastStorageValue?;
|
|
252
|
+
private lastValue?;
|
|
253
|
+
private storageKey;
|
|
254
|
+
constructor(urlOptions: Required<UrlOptions<T>>);
|
|
255
|
+
private getUrlValue;
|
|
256
|
+
private getStorageValue;
|
|
257
|
+
private isPathActive;
|
|
258
|
+
private calc;
|
|
259
|
+
private updateUrl;
|
|
260
|
+
private updateStorage;
|
|
261
|
+
set(update: Update<T>): void;
|
|
262
|
+
set<const P>(path: Constrain<P, Path$1<T>>, update: Update<Value<T, P>>): void;
|
|
280
263
|
}
|
|
281
|
-
declare function
|
|
282
|
-
declare function
|
|
283
|
-
//#endregion
|
|
284
|
-
//#region src/react/url/useUrlParam.d.ts
|
|
285
|
-
declare function useUrlParam<T>(store: UrlStore<T>): [T, update: UpdateFunction<T>];
|
|
286
|
-
declare function useUrlParam<T>(options: UrlOptions<T>): [T, update: UpdateFunction<T>];
|
|
287
|
-
declare function useUrlParam<T>(options: UrlOptionsWithoutDefaults<T>): [T | undefined, update: UpdateFunction<T | undefined>];
|
|
264
|
+
declare function createUrlParam<T>(options: UrlOptions<T>): UrlParamStore<T>;
|
|
265
|
+
declare function createUrlParam<T>(options: UrlOptionsWithoutDefaults<T>): UrlParamStore<T | undefined>;
|
|
288
266
|
//#endregion
|
|
289
267
|
//#region src/react/useDecoupledState.d.ts
|
|
290
268
|
interface UseDecoupledStateOptions<T> {
|
|
@@ -299,5 +277,5 @@ declare function useProp<T, S>(store: Store<T>, selector: Selector<T, S>, update
|
|
|
299
277
|
declare function useProp<T, const P>(store: Store<T>, selector: Constrain<P, Path$1<T>>, options?: UseStoreOptions<Value<T, P>>): [value: Value<T, P>, setValue: Store<Value<T, P>>["set"]];
|
|
300
278
|
declare function useProp<T>(store: Store<T>, options?: UseStoreOptions<T>): [value: T, setValue: Store<T>["set"]];
|
|
301
279
|
//#endregion
|
|
302
|
-
export { CustomInput, CustomInputProps, Field, Form, FormContext, FormDerivedState, FormFieldComponent, FormFieldComponentProps, FormFieldInfos, FormFieldProps, FormFieldPropsWithComponent, FormFieldPropsWithRender, FormInstance, FormOptions, FormState, LoadingBoundary, type LoadingBoundaryEntry, type LoadingBoundaryProps, type ScopeProps, ScopeProvider, Transform,
|
|
280
|
+
export { CustomInput, CustomInputProps, Field, Form, FormContext, FormDerivedState, FormFieldComponent, FormFieldComponentProps, FormFieldInfos, FormFieldProps, FormFieldPropsWithComponent, FormFieldPropsWithRender, FormInstance, FormOptions, FormState, LoadingBoundary, type LoadingBoundaryEntry, type LoadingBoundaryProps, type ScopeProps, ScopeProvider, Transform, type UrlOptions, type UrlOptionsWithoutDefaults, type UrlParamStore, type UseCacheArray, type UseCacheValue, type UseDecoupledStateOptions, type UseStoreOptions, Validation, Validations, cacheMethods, createForm, createUrlOptions, createUrlParam, scopeMethods, storeMethods, urlStore, useCache, useDecoupledState, useLoadingBoundary, useProp, useScope, useStore };
|
|
303
281
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/react/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { autobind, calcDuration, createStore, debounce, queue, throttle } from "../store-
|
|
1
|
+
import { Store, autobind, calcDuration, createStore, debounce, queue, throttle } from "../store-DOEc60aP.js";
|
|
2
2
|
import { castArrayPath, deepEqual, get, isObject, join, set } from "../propAccess-B260LXN1.js";
|
|
3
3
|
import { simpleHash } from "../hash-DNFM5y_h.js";
|
|
4
4
|
import { fromExtendedJsonString, toExtendedJsonString } from "../extendedJson-BZkQBXEv.js";
|
|
5
|
-
import { LoadingBoundary, ScopeProvider, cacheMethods, scopeMethods, storeMethods, useCache, useLoadingBoundary, useProp, useScope, useStore } from "../storeMethods-
|
|
6
|
-
import
|
|
5
|
+
import { LoadingBoundary, ScopeProvider, cacheMethods, scopeMethods, storeMethods, useCache, useLoadingBoundary, useProp, useScope, useStore } from "../storeMethods-C7bswcgj.js";
|
|
6
|
+
import { Fragment, createContext, createElement, startTransition, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
7
7
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
|
|
9
9
|
//#region src/react/form/customInput.tsx
|
|
@@ -464,23 +464,9 @@ function createForm(options) {
|
|
|
464
464
|
}
|
|
465
465
|
|
|
466
466
|
//#endregion
|
|
467
|
-
//#region src/
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
const location = "location" in props ? props.location : props.locationHook();
|
|
471
|
-
const navigate = "navigate" in props ? props.navigate : props.navigateHook();
|
|
472
|
-
return /* @__PURE__ */ jsx(UrlContext.Provider, {
|
|
473
|
-
value: {
|
|
474
|
-
location,
|
|
475
|
-
navigate
|
|
476
|
-
},
|
|
477
|
-
children
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
|
-
function useUrlContext() {
|
|
481
|
-
const context = useContext(UrlContext);
|
|
482
|
-
if (!context) throw new Error("useUrlContext must be used within a UrlContextProvider");
|
|
483
|
-
return context;
|
|
467
|
+
//#region src/lib/castArray.ts
|
|
468
|
+
function castArray(value) {
|
|
469
|
+
return Array.isArray(value) ? value : [value];
|
|
484
470
|
}
|
|
485
471
|
|
|
486
472
|
//#endregion
|
|
@@ -496,17 +482,14 @@ function defaultDeserializer(value) {
|
|
|
496
482
|
function defaultSerializer(value) {
|
|
497
483
|
return toExtendedJsonString(value);
|
|
498
484
|
}
|
|
499
|
-
function
|
|
500
|
-
if (typeof
|
|
501
|
-
return
|
|
502
|
-
}
|
|
503
|
-
function createStorageKey(id, key) {
|
|
504
|
-
return `cross-state:url:${id}:${key}`;
|
|
485
|
+
function normalizePath(path) {
|
|
486
|
+
if (typeof path === "string") return path.replace(/^\//g, "").replace(/\/$/g, "");
|
|
487
|
+
return path;
|
|
505
488
|
}
|
|
506
489
|
|
|
507
490
|
//#endregion
|
|
508
491
|
//#region src/react/url/urlOptions.ts
|
|
509
|
-
function createUrlOptions({ key, type = "hash", serialize = defaultSerializer, deserialize = defaultDeserializer, defaultValue = void 0, writeDefaultValue = false, onCommit = () => void 0, persist = null }) {
|
|
492
|
+
function createUrlOptions({ key, type = "hash", serialize = defaultSerializer, deserialize = defaultDeserializer, defaultValue = void 0, writeDefaultValue = false, onCommit = () => void 0, persist = null, path = null }) {
|
|
510
493
|
return {
|
|
511
494
|
key,
|
|
512
495
|
type,
|
|
@@ -515,69 +498,134 @@ function createUrlOptions({ key, type = "hash", serialize = defaultSerializer, d
|
|
|
515
498
|
defaultValue,
|
|
516
499
|
writeDefaultValue,
|
|
517
500
|
onCommit,
|
|
518
|
-
persist
|
|
501
|
+
persist,
|
|
502
|
+
path: path === null ? null : castArray(path).map(normalizePath)
|
|
519
503
|
};
|
|
520
504
|
}
|
|
521
505
|
|
|
522
506
|
//#endregion
|
|
523
|
-
//#region src/react/url/
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
507
|
+
//#region src/react/url/urlParamStore.ts
|
|
508
|
+
const urlStore = createStore(() => window.location.href, {
|
|
509
|
+
cacheValue: false,
|
|
510
|
+
effect() {
|
|
511
|
+
const update = () => {
|
|
512
|
+
if (window.location.href !== this.calculatedValue?.value) this.invalidate();
|
|
513
|
+
};
|
|
514
|
+
const interval = setInterval(update, 1);
|
|
515
|
+
window.addEventListener("popstate", update);
|
|
516
|
+
return () => {
|
|
517
|
+
clearInterval(interval);
|
|
518
|
+
window.removeEventListener("popstate", update);
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
});
|
|
522
|
+
var UrlParamStore = class UrlParamStore extends Store {
|
|
523
|
+
constructor(urlOptions) {
|
|
524
|
+
super(() => this.calc(), { cacheValue: false });
|
|
525
|
+
this.urlOptions = urlOptions;
|
|
526
|
+
autobind(UrlParamStore);
|
|
527
|
+
this.storageKey = urlOptions.persist && createStorageKey(urlOptions.persist.id, urlOptions.key);
|
|
528
|
+
this.addEffect(() => {
|
|
529
|
+
let isActive = false;
|
|
530
|
+
let urlValue = this.getUrlValue();
|
|
531
|
+
let storageValue = this.getStorageValue();
|
|
532
|
+
const update = () => {
|
|
533
|
+
const oldIsActive = isActive;
|
|
534
|
+
isActive = this.isPathActive();
|
|
535
|
+
const oldUrlValue = urlValue;
|
|
536
|
+
urlValue = this.getUrlValue();
|
|
537
|
+
const oldStorageValue = storageValue;
|
|
538
|
+
storageValue = this.getStorageValue();
|
|
539
|
+
if (!isActive) return;
|
|
540
|
+
if (isActive === oldIsActive && urlValue === oldUrlValue && storageValue === oldStorageValue) return;
|
|
541
|
+
this.invalidate();
|
|
542
|
+
if (!oldIsActive) {
|
|
543
|
+
if (urlValue !== null) this.updateStorage(this.urlOptions.deserialize(urlValue));
|
|
544
|
+
else if (storageValue !== null) this.updateUrl(this.urlOptions.deserialize(storageValue));
|
|
545
|
+
else if (this.urlOptions.writeDefaultValue) {
|
|
546
|
+
this.updateUrl(this.urlOptions.defaultValue);
|
|
547
|
+
this.updateStorage(this.urlOptions.defaultValue);
|
|
548
|
+
}
|
|
549
|
+
} else if (urlValue !== oldUrlValue) {
|
|
550
|
+
if (urlValue === null && this.urlOptions.writeDefaultValue) this.updateUrl(this.urlOptions.defaultValue);
|
|
551
|
+
this.updateStorage();
|
|
552
|
+
} else if (storageValue !== null) {
|
|
553
|
+
if (storageValue === null && this.urlOptions.writeDefaultValue) this.updateUrl(this.urlOptions.defaultValue);
|
|
554
|
+
this.updateUrl(this.urlOptions.deserialize(storageValue));
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
const cancel = urlStore.subscribe(update);
|
|
558
|
+
window.addEventListener("storage", update);
|
|
559
|
+
return () => {
|
|
560
|
+
cancel();
|
|
561
|
+
window.removeEventListener("storage", update);
|
|
562
|
+
};
|
|
542
563
|
});
|
|
543
|
-
if (storageKey) localStorage.setItem(storageKey, serializedValue);
|
|
544
|
-
onCommit?.(value$1);
|
|
545
564
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
565
|
+
getUrlValue() {
|
|
566
|
+
const href = urlStore.get();
|
|
567
|
+
const url = new URL(href);
|
|
568
|
+
const params = new URLSearchParams(url[this.urlOptions.type].slice(1) || "");
|
|
569
|
+
return params.get(this.urlOptions.key);
|
|
549
570
|
}
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
}, [urlValue]);
|
|
553
|
-
useEffect(() => {
|
|
554
|
-
if (urlValue === null && storageValue !== null) commit(deserialize(storageValue));
|
|
555
|
-
else if (urlValue === null && writeDefaultValue) commit(defaultValue);
|
|
556
|
-
}, []);
|
|
557
|
-
return [value, update];
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
//#endregion
|
|
561
|
-
//#region src/react/url/urlStore.ts
|
|
562
|
-
var UrlStore = class {
|
|
563
|
-
constructor(options) {
|
|
564
|
-
this.options = options;
|
|
571
|
+
getStorageValue() {
|
|
572
|
+
return this.storageKey !== null ? localStorage.getItem(this.storageKey) : null;
|
|
565
573
|
}
|
|
566
|
-
|
|
567
|
-
|
|
574
|
+
isPathActive() {
|
|
575
|
+
if (this.urlOptions.path === null) return true;
|
|
576
|
+
const path = normalizePath(window.location.pathname);
|
|
577
|
+
return castArray(this.urlOptions.path).some((p) => {
|
|
578
|
+
if (typeof p === "string") return !p || p === path || path.startsWith(p + "/");
|
|
579
|
+
return p.test(path);
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
calc() {
|
|
583
|
+
let href = window.location.href;
|
|
584
|
+
const storageValue = this.storageKey !== null ? localStorage.getItem(this.storageKey) : null;
|
|
585
|
+
if (!this.isPathActive() && this.lastHref !== void 0) href = this.lastHref;
|
|
586
|
+
if (this.lastHref === href && this.lastStorageValue === storageValue) return this.lastValue;
|
|
587
|
+
const url = new URL(href);
|
|
588
|
+
const params = new URLSearchParams(url[this.urlOptions.type].slice(1));
|
|
589
|
+
const urlValue = params.get(this.urlOptions.key);
|
|
590
|
+
const value = urlValue !== null ? this.urlOptions.deserialize(urlValue) : this.storageKey !== null && storageValue !== null ? this.urlOptions.deserialize(storageValue) : this.urlOptions.defaultValue;
|
|
591
|
+
this.lastHref = href;
|
|
592
|
+
this.lastStorageValue = storageValue;
|
|
593
|
+
this.lastValue = value;
|
|
594
|
+
return value;
|
|
595
|
+
}
|
|
596
|
+
updateUrl(value = this.calc()) {
|
|
597
|
+
const serializedValue = this.urlOptions.serialize(value);
|
|
598
|
+
const url = new URL(window.location.href);
|
|
599
|
+
const params = new URLSearchParams(url[this.urlOptions.type].slice(1));
|
|
600
|
+
if (!this.urlOptions.writeDefaultValue && serializedValue === this.urlOptions.serialize(this.urlOptions.defaultValue)) params.delete(this.urlOptions.key);
|
|
601
|
+
else params.set(this.urlOptions.key, serializedValue);
|
|
602
|
+
url[this.urlOptions.type] = params.toString();
|
|
603
|
+
window.history.replaceState(window.history.state, "", url.toString());
|
|
604
|
+
window.dispatchEvent(new PopStateEvent("popstate"));
|
|
568
605
|
}
|
|
569
|
-
|
|
570
|
-
|
|
606
|
+
updateStorage(value = this.calc()) {
|
|
607
|
+
if (this.storageKey === null) return;
|
|
608
|
+
const serializedValue = this.urlOptions.serialize(value);
|
|
609
|
+
localStorage.setItem(this.storageKey, serializedValue);
|
|
571
610
|
}
|
|
572
|
-
|
|
573
|
-
const
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
611
|
+
set(...args) {
|
|
612
|
+
const path = args.length > 1 ? args[0] : [];
|
|
613
|
+
let update = args.length > 1 ? args[1] : args[0];
|
|
614
|
+
if (update instanceof Function) {
|
|
615
|
+
const before = this.get();
|
|
616
|
+
const valueBefore = get(before, path);
|
|
617
|
+
const valueAfter = update(valueBefore);
|
|
618
|
+
update = set(before, path, valueAfter);
|
|
619
|
+
} else if (path.length > 0) update = set(this.get(), path, update);
|
|
620
|
+
if (this.isPathActive()) this.updateUrl(update);
|
|
621
|
+
else this.updateStorage(update);
|
|
577
622
|
}
|
|
578
623
|
};
|
|
579
|
-
function
|
|
580
|
-
return new
|
|
624
|
+
function createUrlParam(options) {
|
|
625
|
+
return new UrlParamStore(createUrlOptions(options));
|
|
626
|
+
}
|
|
627
|
+
function createStorageKey(id, key) {
|
|
628
|
+
return `cross-state:url:${id}:${key}`;
|
|
581
629
|
}
|
|
582
630
|
|
|
583
631
|
//#endregion
|
|
@@ -614,5 +662,5 @@ function useDecoupledState(value, onChange, options = {}) {
|
|
|
614
662
|
}
|
|
615
663
|
|
|
616
664
|
//#endregion
|
|
617
|
-
export { CustomInput, Form, LoadingBoundary, ScopeProvider,
|
|
665
|
+
export { CustomInput, Form, LoadingBoundary, ScopeProvider, cacheMethods, createForm, createUrlOptions, createUrlParam, scopeMethods, storeMethods, urlStore, useCache, useDecoupledState, useLoadingBoundary, useProp, useScope, useStore };
|
|
618
666
|
//# sourceMappingURL=index.js.map
|