vue-context-storage 0.1.25 → 0.1.26
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/README.md +17 -4
- package/dist/index.d.ts +134 -145
- package/dist/index.js +500 -465
- package/package.json +90 -90
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ A powerful state management solution for Vue 3 applications that provides:
|
|
|
21
21
|
- **Multiple storage contexts** with activation management
|
|
22
22
|
- **Type-safe** TypeScript support
|
|
23
23
|
- **Tree-shakeable** and lightweight
|
|
24
|
-
|
|
24
|
+
-
|
|
25
25
|
## Live Demo
|
|
26
26
|
|
|
27
27
|
🚀 **[Try the interactive playground](https://lviobio.github.io/vue-context-storage)**
|
|
@@ -40,9 +40,22 @@ npm install vue-context-storage
|
|
|
40
40
|
- ✅ **sessionStorage Handler** - Session-scoped state that survives page refreshes
|
|
41
41
|
- ✅ **Multiple Contexts** - Support multiple independent storage contexts
|
|
42
42
|
- ✅ **TypeScript** - Full type safety and IntelliSense support
|
|
43
|
-
- ✅ **Flexible** - Works with vue-router 4+
|
|
43
|
+
- ✅ **Flexible** - Works with vue-router 4+ or 5+
|
|
44
44
|
- ✅ **Transform Helpers** - Built-in utilities for type conversion
|
|
45
45
|
|
|
46
|
+
## Motivation
|
|
47
|
+
|
|
48
|
+
In Vue applications, reactive state often needs to live beyond a single component. Filters, pagination, sorting, and user preferences must survive page reloads, be shareable via URL, or persist across sessions. Solving this typically means writing the same boilerplate over and over: manually reading and writing query parameters with vue-router, serializing objects to localStorage, handling type coercion from URL strings, and keeping everything in sync.
|
|
49
|
+
|
|
50
|
+
`vue-context-storage` eliminates that repetitive work. You declare your reactive state once, point it at a storage target, and the library handles the rest:
|
|
51
|
+
|
|
52
|
+
- **URL query parameters** stay in sync with your data automatically -- users can bookmark or share a page and get the exact same state back.
|
|
53
|
+
- **localStorage and sessionStorage** are kept up to date without manual `getItem`/`setItem` calls, including cross-tab synchronization.
|
|
54
|
+
- **Type safety** is preserved end-to-end: URL strings are coerced back to numbers, booleans, and arrays via transform helpers or Zod schemas.
|
|
55
|
+
- **Multiple independent contexts** (e.g. two data tables on the same page) are supported out of the box through the prefix pattern, so query parameters never collide.
|
|
56
|
+
|
|
57
|
+
The goal is a single, declarative API -- `useContextStorage('query', data, options)` -- that replaces scattered watchers, router guards, and storage listeners with one composable call per piece of state.
|
|
58
|
+
|
|
46
59
|
## Basic Usage
|
|
47
60
|
|
|
48
61
|
### Option 1: Manual Component Import (Recommended)
|
|
@@ -590,8 +603,8 @@ useContextStorageQueryHandler(pagination, {
|
|
|
590
603
|
|
|
591
604
|
## Peer Dependencies
|
|
592
605
|
|
|
593
|
-
- `vue`: ^3.
|
|
594
|
-
- `vue-router`: ^4.0.0
|
|
606
|
+
- `vue`: ^3.0.0
|
|
607
|
+
- `vue-router`: ^4.0.0 || ^5.0.0
|
|
595
608
|
- `zod`: ^4.0.0 (optional - only if using schema validation)
|
|
596
609
|
|
|
597
610
|
## License
|
package/dist/index.d.ts
CHANGED
|
@@ -1,80 +1,121 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { InjectionKey, MaybeRefOrGetter, Plugin, PropType, UnwrapNestedRefs, WatchHandle } from "vue";
|
|
1
|
+
import * as vue19 from "vue";
|
|
2
|
+
import { ComputedRef, InjectionKey, MaybeRefOrGetter, Plugin, PropType, UnwrapNestedRefs, WatchHandle } from "vue";
|
|
3
3
|
import { LocationQuery, LocationQueryValue } from "vue-router";
|
|
4
4
|
|
|
5
5
|
//#region src/components/ContextStorageActivator.vue.d.ts
|
|
6
6
|
declare const _default$1: typeof __VLS_export$3;
|
|
7
|
-
declare const __VLS_export$3:
|
|
7
|
+
declare const __VLS_export$3: vue19.DefineComponent<{}, () => vue19.VNode<vue19.RendererNode, vue19.RendererElement, {
|
|
8
8
|
[key: string]: any;
|
|
9
|
-
}>, {}, {}, {},
|
|
9
|
+
}>, {}, {}, {}, vue19.ComponentOptionsMixin, vue19.ComponentOptionsMixin, {}, string, vue19.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, vue19.ComponentProvideOptions, true, {}, any>;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/handlers/types.d.ts
|
|
12
|
+
interface HandlerSchema<T> {
|
|
13
|
+
safeParse: (data: unknown) => {
|
|
14
|
+
success: true;
|
|
15
|
+
data: T;
|
|
16
|
+
} | {
|
|
17
|
+
success: false;
|
|
18
|
+
error: any;
|
|
19
|
+
};
|
|
20
|
+
parse: (data: unknown) => T;
|
|
21
|
+
}
|
|
10
22
|
//#endregion
|
|
11
23
|
//#region src/handlers.d.ts
|
|
12
|
-
interface ContextStorageHandlerConstructor<T =
|
|
13
|
-
new (): ContextStorageHandler<T>;
|
|
24
|
+
interface ContextStorageHandlerConstructor<T extends Record<string, unknown> = {}, O extends RegisterOptions<T> = RegisterOptions<T>> {
|
|
25
|
+
new (): ContextStorageHandler<T, O>;
|
|
14
26
|
getInitialStateResolver?: () => () => Record<string, unknown>;
|
|
15
27
|
}
|
|
16
|
-
interface RegisterBaseOptions {
|
|
17
|
-
causer
|
|
18
|
-
uid
|
|
28
|
+
interface RegisterBaseOptions<T> {
|
|
29
|
+
causer?: string;
|
|
30
|
+
uid?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Zod schema for automatic validation and type coercion.
|
|
33
|
+
*
|
|
34
|
+
* When provided, the schema will be used to parse and validate query parameters.
|
|
35
|
+
* This option takes priority over the `transform` option.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { z } from 'zod'
|
|
40
|
+
*
|
|
41
|
+
* const FiltersSchema = z.object({
|
|
42
|
+
* search: z.string().default(''),
|
|
43
|
+
* page: z.coerce.number().int().positive().default(1),
|
|
44
|
+
* status: z.enum(['active', 'inactive']).default('active'),
|
|
45
|
+
* })
|
|
46
|
+
*
|
|
47
|
+
* useContextStorageQueryHandler(filters, {
|
|
48
|
+
* prefix: 'filters',
|
|
49
|
+
* schema: FiltersSchema,
|
|
50
|
+
* })
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
schema?: HandlerSchema<T>;
|
|
19
54
|
}
|
|
20
|
-
|
|
21
|
-
|
|
55
|
+
type RegisterOptions<T> = Required<Pick<RegisterBaseOptions<T>, 'causer' | 'uid'>> & Omit<RegisterBaseOptions<T>, 'causer' | 'uid'>;
|
|
56
|
+
interface RegisterResult {
|
|
57
|
+
stop: () => void;
|
|
58
|
+
reset: () => void;
|
|
59
|
+
wasChanged: ComputedRef<boolean>;
|
|
60
|
+
}
|
|
61
|
+
interface ContextStorageHandler<T, O> {
|
|
62
|
+
register: (data: MaybeRefOrGetter<T>, options: O) => RegisterResult;
|
|
22
63
|
setInitialState?: (state: Record<string, unknown>) => void;
|
|
23
64
|
setEnabled?: (enabled: boolean, initial: boolean) => void;
|
|
24
|
-
getInjectionKey(): InjectionKey<ContextStorageHandler<T>>;
|
|
65
|
+
getInjectionKey(): InjectionKey<ContextStorageHandler<T, O>>;
|
|
25
66
|
}
|
|
26
67
|
//#endregion
|
|
27
68
|
//#region src/components/ContextStorageCollection.vue.d.ts
|
|
28
69
|
declare const _default$2: typeof __VLS_export$2;
|
|
29
|
-
declare const __VLS_export$2:
|
|
70
|
+
declare const __VLS_export$2: vue19.DefineComponent<vue19.ExtractPropTypes<{
|
|
30
71
|
handlers: {
|
|
31
72
|
type: PropType<ContextStorageHandlerConstructor[]>;
|
|
32
|
-
default: () => ContextStorageHandlerConstructor<
|
|
73
|
+
default: () => ContextStorageHandlerConstructor<{}, RegisterOptions<{}>>[];
|
|
33
74
|
};
|
|
34
|
-
}>, () =>
|
|
75
|
+
}>, () => vue19.VNode<vue19.RendererNode, vue19.RendererElement, {
|
|
35
76
|
[key: string]: any;
|
|
36
|
-
}>[] | undefined, {}, {}, {},
|
|
77
|
+
}>[] | undefined, {}, {}, {}, vue19.ComponentOptionsMixin, vue19.ComponentOptionsMixin, {}, string, vue19.PublicProps, Readonly<vue19.ExtractPropTypes<{
|
|
37
78
|
handlers: {
|
|
38
79
|
type: PropType<ContextStorageHandlerConstructor[]>;
|
|
39
|
-
default: () => ContextStorageHandlerConstructor<
|
|
80
|
+
default: () => ContextStorageHandlerConstructor<{}, RegisterOptions<{}>>[];
|
|
40
81
|
};
|
|
41
82
|
}>> & Readonly<{}>, {
|
|
42
|
-
handlers: ContextStorageHandlerConstructor<
|
|
43
|
-
}, {}, {}, {}, string,
|
|
83
|
+
handlers: ContextStorageHandlerConstructor<{}, RegisterOptions<{}>>[];
|
|
84
|
+
}, {}, {}, {}, string, vue19.ComponentProvideOptions, true, {}, any>;
|
|
44
85
|
//#endregion
|
|
45
86
|
//#region src/components/ContextStorageProvider.vue.d.ts
|
|
46
87
|
declare const _default$3: typeof __VLS_export$1;
|
|
47
|
-
declare const __VLS_export$1:
|
|
88
|
+
declare const __VLS_export$1: vue19.DefineComponent<vue19.ExtractPropTypes<{
|
|
48
89
|
itemKey: {
|
|
49
90
|
type: StringConstructor;
|
|
50
91
|
required: true;
|
|
51
92
|
};
|
|
52
|
-
}>, () =>
|
|
93
|
+
}>, () => vue19.VNode<vue19.RendererNode, vue19.RendererElement, {
|
|
53
94
|
[key: string]: any;
|
|
54
|
-
}>[] | undefined, {}, {}, {},
|
|
95
|
+
}>[] | undefined, {}, {}, {}, vue19.ComponentOptionsMixin, vue19.ComponentOptionsMixin, {}, string, vue19.PublicProps, Readonly<vue19.ExtractPropTypes<{
|
|
55
96
|
itemKey: {
|
|
56
97
|
type: StringConstructor;
|
|
57
98
|
required: true;
|
|
58
99
|
};
|
|
59
|
-
}>> & Readonly<{}>, {}, {}, {}, {}, string,
|
|
100
|
+
}>> & Readonly<{}>, {}, {}, {}, {}, string, vue19.ComponentProvideOptions, true, {}, any>;
|
|
60
101
|
//#endregion
|
|
61
102
|
//#region src/components/ContextStorage.vue.d.ts
|
|
62
103
|
declare const _default: typeof __VLS_export;
|
|
63
|
-
declare const __VLS_export:
|
|
104
|
+
declare const __VLS_export: vue19.DefineComponent<vue19.ExtractPropTypes<{
|
|
64
105
|
handlers: {
|
|
65
106
|
type: PropType<ContextStorageHandlerConstructor[]>;
|
|
66
|
-
default: () => ContextStorageHandlerConstructor<
|
|
107
|
+
default: () => ContextStorageHandlerConstructor<{}, RegisterOptions<{}>>[];
|
|
67
108
|
};
|
|
68
|
-
}>, () =>
|
|
109
|
+
}>, () => vue19.VNode<vue19.RendererNode, vue19.RendererElement, {
|
|
69
110
|
[key: string]: any;
|
|
70
|
-
}>[] | undefined, {}, {}, {},
|
|
111
|
+
}>[] | undefined, {}, {}, {}, vue19.ComponentOptionsMixin, vue19.ComponentOptionsMixin, {}, string, vue19.PublicProps, Readonly<vue19.ExtractPropTypes<{
|
|
71
112
|
handlers: {
|
|
72
113
|
type: PropType<ContextStorageHandlerConstructor[]>;
|
|
73
|
-
default: () => ContextStorageHandlerConstructor<
|
|
114
|
+
default: () => ContextStorageHandlerConstructor<{}, RegisterOptions<{}>>[];
|
|
74
115
|
};
|
|
75
116
|
}>> & Readonly<{}>, {
|
|
76
|
-
handlers: ContextStorageHandlerConstructor<
|
|
77
|
-
}, {}, {}, {}, string,
|
|
117
|
+
handlers: ContextStorageHandlerConstructor<{}, RegisterOptions<{}>>[];
|
|
118
|
+
}, {}, {}, {}, string, vue19.ComponentProvideOptions, true, {}, any>;
|
|
78
119
|
//#endregion
|
|
79
120
|
//#region src/plugin.d.ts
|
|
80
121
|
declare const VueContextStoragePlugin: Plugin;
|
|
@@ -82,7 +123,7 @@ declare const VueContextStoragePlugin: Plugin;
|
|
|
82
123
|
//#region src/collection.d.ts
|
|
83
124
|
type CollectionManagerItem = {
|
|
84
125
|
key: string;
|
|
85
|
-
handlers: ContextStorageHandler<any
|
|
126
|
+
handlers: ContextStorageHandler<any, RegisterOptions<any>>[];
|
|
86
127
|
};
|
|
87
128
|
interface ItemOptions {
|
|
88
129
|
key: string;
|
|
@@ -215,43 +256,8 @@ interface RegisterQueryHandlerBaseOptions<T> extends QueryHandlerSharedOptions {
|
|
|
215
256
|
* Note: If `schema` is provided, it takes priority over `transform`.
|
|
216
257
|
*/
|
|
217
258
|
transform?: (deserialized: DeepTransformValuesToLocationQueryValue<UnwrapNestedRefs<T>>, initialData: T) => UnwrapNestedRefs<T>;
|
|
218
|
-
/**
|
|
219
|
-
* Zod schema for automatic validation and type coercion.
|
|
220
|
-
*
|
|
221
|
-
* When provided, the schema will be used to parse and validate query parameters.
|
|
222
|
-
* This option takes priority over the `transform` option.
|
|
223
|
-
*
|
|
224
|
-
* @example
|
|
225
|
-
* ```typescript
|
|
226
|
-
* import { z } from 'zod'
|
|
227
|
-
*
|
|
228
|
-
* const FiltersSchema = z.object({
|
|
229
|
-
* search: z.string().default(''),
|
|
230
|
-
* page: z.coerce.number().int().positive().default(1),
|
|
231
|
-
* status: z.enum(['active', 'inactive']).default('active'),
|
|
232
|
-
* })
|
|
233
|
-
*
|
|
234
|
-
* useContextStorageQueryHandler(filters, {
|
|
235
|
-
* prefix: 'filters',
|
|
236
|
-
* schema: FiltersSchema,
|
|
237
|
-
* })
|
|
238
|
-
* ```
|
|
239
|
-
*/
|
|
240
|
-
schema?: {
|
|
241
|
-
safeParse: (data: unknown) => {
|
|
242
|
-
success: true;
|
|
243
|
-
data: T;
|
|
244
|
-
} | {
|
|
245
|
-
success: false;
|
|
246
|
-
error: any;
|
|
247
|
-
};
|
|
248
|
-
parse: (data: unknown) => T;
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
interface RegisterQueryHandlerOptions<T> extends RegisterBaseOptions, RegisterQueryHandlerBaseOptions<T> {}
|
|
252
|
-
interface IContextStorageQueryHandler<T extends Record<string, unknown>> extends ContextStorageHandler<T> {
|
|
253
|
-
register: <T extends Record<string, unknown>>(data: MaybeRefOrGetter<T>, options: RegisterQueryHandlerOptions<T>) => () => void;
|
|
254
259
|
}
|
|
260
|
+
interface RegisterQueryHandlerOptions<T> extends RegisterBaseOptions<T>, RegisterQueryHandlerBaseOptions<T> {}
|
|
255
261
|
interface ContextStorageQueryRegisteredItem<T extends Record<string, unknown>> {
|
|
256
262
|
data: MaybeRefOrGetter<T>;
|
|
257
263
|
initialData: T;
|
|
@@ -271,9 +277,6 @@ interface WebStorageHandlerBaseOptions {
|
|
|
271
277
|
listenToStorageEvents?: boolean;
|
|
272
278
|
}
|
|
273
279
|
interface RegisterWebStorageHandlerBaseOptions<T> {
|
|
274
|
-
/**
|
|
275
|
-
* Storage key for this data.
|
|
276
|
-
*/
|
|
277
280
|
key?: string;
|
|
278
281
|
/**
|
|
279
282
|
* Optional prefix for nested data within the storage key.
|
|
@@ -286,37 +289,6 @@ interface RegisterWebStorageHandlerBaseOptions<T> {
|
|
|
286
289
|
* Note: If `schema` is provided, it takes priority over `transform`.
|
|
287
290
|
*/
|
|
288
291
|
transform?: (deserialized: Record<string, unknown>, initialData: T) => UnwrapNestedRefs<T>;
|
|
289
|
-
/**
|
|
290
|
-
* Zod schema for automatic validation and type coercion.
|
|
291
|
-
*
|
|
292
|
-
* When provided, the schema will be used to parse and validate storage data.
|
|
293
|
-
* This option takes priority over the `transform` option.
|
|
294
|
-
*
|
|
295
|
-
* @example
|
|
296
|
-
* ```typescript
|
|
297
|
-
* import { z } from 'zod'
|
|
298
|
-
*
|
|
299
|
-
* const SettingsSchema = z.object({
|
|
300
|
-
* theme: z.enum(['light', 'dark']).default('light'),
|
|
301
|
-
* fontSize: z.number().int().positive().default(14),
|
|
302
|
-
* })
|
|
303
|
-
*
|
|
304
|
-
* useContextStorageLocalStorage(settings, {
|
|
305
|
-
* key: 'app-settings',
|
|
306
|
-
* schema: SettingsSchema,
|
|
307
|
-
* })
|
|
308
|
-
* ```
|
|
309
|
-
*/
|
|
310
|
-
schema?: {
|
|
311
|
-
safeParse: (data: unknown) => {
|
|
312
|
-
success: true;
|
|
313
|
-
data: T;
|
|
314
|
-
} | {
|
|
315
|
-
success: false;
|
|
316
|
-
error: any;
|
|
317
|
-
};
|
|
318
|
-
parse: (data: unknown) => T;
|
|
319
|
-
};
|
|
320
292
|
/**
|
|
321
293
|
* Custom serializer function. Defaults to JSON.stringify.
|
|
322
294
|
*/
|
|
@@ -326,10 +298,7 @@ interface RegisterWebStorageHandlerBaseOptions<T> {
|
|
|
326
298
|
*/
|
|
327
299
|
deserializer?: (str: string) => unknown;
|
|
328
300
|
}
|
|
329
|
-
interface RegisterWebStorageHandlerOptions<T> extends RegisterBaseOptions
|
|
330
|
-
interface IContextStorageWebStorageHandler<T extends Record<string, unknown>> extends ContextStorageHandler<T> {
|
|
331
|
-
register: <T extends Record<string, unknown>>(data: MaybeRefOrGetter<T>, options: RegisterWebStorageHandlerOptions<T>) => () => void;
|
|
332
|
-
}
|
|
301
|
+
interface RegisterWebStorageHandlerOptions<T> extends RegisterBaseOptions<T>, RegisterWebStorageHandlerBaseOptions<T> {}
|
|
333
302
|
interface ContextStorageWebStorageRegisteredItem<T extends Record<string, unknown>> {
|
|
334
303
|
data: MaybeRefOrGetter<T>;
|
|
335
304
|
initialData: T;
|
|
@@ -337,33 +306,6 @@ interface ContextStorageWebStorageRegisteredItem<T extends Record<string, unknow
|
|
|
337
306
|
watchHandle: WatchHandle;
|
|
338
307
|
}
|
|
339
308
|
//#endregion
|
|
340
|
-
//#region src/handlers/web-storage-base/index.d.ts
|
|
341
|
-
declare abstract class ContextStorageWebStorageHandler<T extends Record<string, unknown>> implements IContextStorageWebStorageHandler<T> {
|
|
342
|
-
protected enabled: boolean;
|
|
343
|
-
protected registered: ContextStorageWebStorageRegisteredItem<any>[];
|
|
344
|
-
protected initialState?: Record<string, unknown>;
|
|
345
|
-
protected hasAnyRegistered: boolean;
|
|
346
|
-
protected preventSyncToStorage: boolean;
|
|
347
|
-
protected abstract readonly storage: Storage;
|
|
348
|
-
protected abstract readonly injectionKey: InjectionKey<ContextStorageWebStorageHandler<T>>;
|
|
349
|
-
protected readonly options: Required<WebStorageHandlerBaseOptions>;
|
|
350
|
-
private storageEventHandler;
|
|
351
|
-
constructor(defaultOptions: Required<WebStorageHandlerBaseOptions>);
|
|
352
|
-
protected initializeStorageListener(): void;
|
|
353
|
-
protected handleStorageEvent(event: StorageEvent): void;
|
|
354
|
-
getInjectionKey(): InjectionKey<ContextStorageWebStorageHandler<T>>;
|
|
355
|
-
setInitialState(state: Record<string, unknown> | undefined): void;
|
|
356
|
-
setEnabled(state: boolean, initial: boolean): void;
|
|
357
|
-
syncRegisteredToStorage(): void;
|
|
358
|
-
syncStorageToRegisteredItem<T extends Record<string, unknown>>(item: ContextStorageWebStorageRegisteredItem<T>): void;
|
|
359
|
-
syncStorageToRegistered(): void;
|
|
360
|
-
register<T extends Record<string, unknown>>(data: MaybeRefOrGetter<T>, options: RegisterWebStorageHandlerOptions<T>): () => void;
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* Options for the web storage composable with required key
|
|
364
|
-
*/
|
|
365
|
-
type UseWebStorageOptions<T> = RegisterWebStorageHandlerBaseOptions<T> & Required<Pick<RegisterWebStorageHandlerBaseOptions<T>, 'key'>>;
|
|
366
|
-
//#endregion
|
|
367
309
|
//#region src/registry.d.ts
|
|
368
310
|
/**
|
|
369
311
|
* Augmentable interface mapping handler names to their options types.
|
|
@@ -378,15 +320,23 @@ type UseWebStorageOptions<T> = RegisterWebStorageHandlerBaseOptions<T> & Require
|
|
|
378
320
|
* ```
|
|
379
321
|
*/
|
|
380
322
|
interface ContextStorageHandlerMap<T> {
|
|
381
|
-
query:
|
|
382
|
-
localStorage:
|
|
383
|
-
sessionStorage:
|
|
323
|
+
query: RegisterQueryHandlerOptions<T>;
|
|
324
|
+
localStorage: RegisterWebStorageHandlerOptions<T>;
|
|
325
|
+
sessionStorage: RegisterWebStorageHandlerOptions<T>;
|
|
384
326
|
}
|
|
385
|
-
declare function defineContextStorageHandler<T>(name: string, injectionKey: InjectionKey<ContextStorageHandler<T>>): void;
|
|
386
|
-
declare function resolveHandlerInjectionKey<K$1 extends keyof ContextStorageHandlerMap<T>, T>(type: K$1): InjectionKey<ContextStorageHandler<T>> | undefined;
|
|
327
|
+
declare function defineContextStorageHandler<T, O extends object>(name: string, injectionKey: InjectionKey<ContextStorageHandler<T, O>>): void;
|
|
328
|
+
declare function resolveHandlerInjectionKey<K$1 extends keyof ContextStorageHandlerMap<T>, T>(type: K$1): InjectionKey<ContextStorageHandler<T, ContextStorageHandlerMap<T>[K$1]>> | undefined;
|
|
329
|
+
//#endregion
|
|
330
|
+
//#region src/composables/types.d.ts
|
|
331
|
+
type UseContextStorageResult<T> = {
|
|
332
|
+
data: MaybeRefOrGetter<T>;
|
|
333
|
+
stop: () => void;
|
|
334
|
+
reset: () => void;
|
|
335
|
+
wasChanged: ComputedRef<boolean>;
|
|
336
|
+
};
|
|
387
337
|
//#endregion
|
|
388
338
|
//#region src/composables/useContextStorage.d.ts
|
|
389
|
-
declare function useContextStorage<K$1 extends keyof ContextStorageHandlerMap<T>, T>(type: K$1, data: MaybeRefOrGetter<T>, options: ContextStorageHandlerMap<T>[K$1]):
|
|
339
|
+
declare function useContextStorage<K$1 extends keyof ContextStorageHandlerMap<T>, T>(type: K$1, data: MaybeRefOrGetter<T>, options: ContextStorageHandlerMap<T>[K$1]): UseContextStorageResult<T>;
|
|
390
340
|
//#endregion
|
|
391
341
|
//#region src/composables/useContextStorageActivator.d.ts
|
|
392
342
|
declare function useContextStorageActivator(): {
|
|
@@ -403,11 +353,12 @@ declare function useContextStorageProvider(key: string): void;
|
|
|
403
353
|
declare const contextStorageQueryHandler: unique symbol;
|
|
404
354
|
//#endregion
|
|
405
355
|
//#region src/handlers/query/index.d.ts
|
|
406
|
-
declare function useContextStorageQueryHandler<T extends Record<string, unknown>>(data: MaybeRefOrGetter<T>, options?:
|
|
407
|
-
declare class ContextStorageQueryHandler<T extends Record<string, unknown>> implements
|
|
356
|
+
declare function useContextStorageQueryHandler<T extends Record<string, unknown>>(data: MaybeRefOrGetter<T>, options?: RegisterQueryHandlerOptions<T>): UseContextStorageResult<T>;
|
|
357
|
+
declare class ContextStorageQueryHandler<T extends Record<string, unknown>> implements ContextStorageHandler<T, RegisterQueryHandlerOptions<T>> {
|
|
408
358
|
#private;
|
|
409
359
|
private enabled;
|
|
410
360
|
private registered;
|
|
361
|
+
private registeredDataObjects;
|
|
411
362
|
private currentQuery;
|
|
412
363
|
private readonly route;
|
|
413
364
|
private router;
|
|
@@ -415,6 +366,8 @@ declare class ContextStorageQueryHandler<T extends Record<string, unknown>> impl
|
|
|
415
366
|
private hasAnyRegistered;
|
|
416
367
|
private preventSyncRegisteredToQueryByAfterEachRoute;
|
|
417
368
|
private preventAfterEachRouteCallsWhileCallingRouter;
|
|
369
|
+
private syncToQueryScheduled;
|
|
370
|
+
private registeredVersion;
|
|
418
371
|
static customQueryHandlerOptions: QueryHandlerBaseOptions;
|
|
419
372
|
private readonly options;
|
|
420
373
|
static configure<T extends Record<string, unknown>>(options: QueryHandlerBaseOptions): ContextStorageHandlerConstructor<T>;
|
|
@@ -424,31 +377,67 @@ declare class ContextStorageQueryHandler<T extends Record<string, unknown>> impl
|
|
|
424
377
|
static getInitialStateResolver(): () => LocationQuery;
|
|
425
378
|
setEnabled(state: boolean, initial: boolean): void;
|
|
426
379
|
syncRegisteredToQuery(): Promise<void>;
|
|
380
|
+
private scheduleSyncToQuery;
|
|
427
381
|
afterEachRoute(): void;
|
|
428
|
-
syncInitialStateToRegisteredItem<T extends Record<string, unknown>>(item: ContextStorageQueryRegisteredItem<T>): void;
|
|
429
382
|
syncInitialStateToRegistered(): void;
|
|
430
|
-
|
|
383
|
+
syncInitialStateToRegisteredItem<T extends Record<string, unknown>>(item: ContextStorageQueryRegisteredItem<T>): void;
|
|
384
|
+
register<T extends Record<string, unknown>>(data: MaybeRefOrGetter<T>, options: RegisterQueryHandlerOptions<T>): {
|
|
385
|
+
stop: () => void;
|
|
386
|
+
reset: () => void;
|
|
387
|
+
wasChanged: vue19.ComputedRef<boolean>;
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
//#endregion
|
|
391
|
+
//#region src/handlers/web-storage-base/index.d.ts
|
|
392
|
+
declare abstract class ContextStorageWebStorageHandler<T extends Record<string, unknown>> implements ContextStorageHandler<T, RegisterWebStorageHandlerOptions<T>> {
|
|
393
|
+
protected enabled: boolean;
|
|
394
|
+
protected registered: ContextStorageWebStorageRegisteredItem<any>[];
|
|
395
|
+
private registeredDataObjects;
|
|
396
|
+
protected initialState?: Record<string, unknown>;
|
|
397
|
+
protected hasAnyRegistered: boolean;
|
|
398
|
+
protected preventSyncToStorage: boolean;
|
|
399
|
+
protected abstract readonly storage: Storage;
|
|
400
|
+
protected abstract readonly injectionKey: InjectionKey<ContextStorageWebStorageHandler<T>>;
|
|
401
|
+
protected abstract readonly handlerName: string;
|
|
402
|
+
protected readonly options: Required<WebStorageHandlerBaseOptions>;
|
|
403
|
+
private storageEventHandler;
|
|
404
|
+
protected constructor(defaultOptions: Required<WebStorageHandlerBaseOptions>);
|
|
405
|
+
protected initializeStorageListener(): void;
|
|
406
|
+
protected handleStorageEvent(event: StorageEvent): void;
|
|
407
|
+
getInjectionKey(): InjectionKey<ContextStorageWebStorageHandler<T>>;
|
|
408
|
+
setInitialState(state: Record<string, unknown> | undefined): void;
|
|
409
|
+
setEnabled(state: boolean, initial: boolean): void;
|
|
410
|
+
syncRegisteredToStorage(): void;
|
|
411
|
+
syncStorageToRegisteredItem<T extends Record<string, unknown>>(item: ContextStorageWebStorageRegisteredItem<T>): void;
|
|
412
|
+
syncStorageToRegistered(): void;
|
|
413
|
+
register<T extends Record<string, unknown>>(data: MaybeRefOrGetter<T>, options: RegisterWebStorageHandlerOptions<T>): {
|
|
414
|
+
stop: () => void;
|
|
415
|
+
reset: () => void;
|
|
416
|
+
wasChanged: vue19.ComputedRef<boolean>;
|
|
417
|
+
};
|
|
431
418
|
}
|
|
432
419
|
//#endregion
|
|
433
420
|
//#region src/handlers/local-storage/index.d.ts
|
|
434
421
|
declare class ContextStorageLocalStorageHandler<T extends Record<string, unknown>> extends ContextStorageWebStorageHandler<T> {
|
|
435
422
|
protected readonly storage: Storage;
|
|
436
423
|
protected readonly injectionKey: InjectionKey<ContextStorageLocalStorageHandler<T>>;
|
|
424
|
+
protected readonly handlerName = "localStorage";
|
|
437
425
|
static customHandlerOptions: WebStorageHandlerBaseOptions;
|
|
438
426
|
constructor();
|
|
439
427
|
static configure<T extends Record<string, unknown>>(options: WebStorageHandlerBaseOptions): ContextStorageHandlerConstructor<T>;
|
|
440
428
|
}
|
|
441
|
-
declare const useContextStorageLocalStorage: <
|
|
429
|
+
declare const useContextStorageLocalStorage: (data: vue19.MaybeRefOrGetter<Record<string, unknown>>, options: RegisterWebStorageHandlerOptions<Record<string, unknown>>) => UseContextStorageResult<Record<string, unknown>>;
|
|
442
430
|
//#endregion
|
|
443
431
|
//#region src/handlers/session-storage/index.d.ts
|
|
444
432
|
declare class ContextStorageSessionStorageHandler<T extends Record<string, unknown>> extends ContextStorageWebStorageHandler<T> {
|
|
445
433
|
protected readonly storage: Storage;
|
|
446
434
|
protected readonly injectionKey: InjectionKey<ContextStorageSessionStorageHandler<T>>;
|
|
435
|
+
protected readonly handlerName = "sessionStorage";
|
|
447
436
|
static customHandlerOptions: WebStorageHandlerBaseOptions;
|
|
448
437
|
constructor();
|
|
449
438
|
static configure<T extends Record<string, unknown>>(options: WebStorageHandlerBaseOptions): ContextStorageHandlerConstructor<T>;
|
|
450
439
|
}
|
|
451
|
-
declare const useContextStorageSessionStorage: <
|
|
440
|
+
declare const useContextStorageSessionStorage: (data: vue19.MaybeRefOrGetter<Record<string, unknown>>, options: RegisterWebStorageHandlerOptions<Record<string, unknown>>) => UseContextStorageResult<Record<string, unknown>>;
|
|
452
441
|
//#endregion
|
|
453
442
|
//#region src/handlers/query/transform-helpers.d.ts
|
|
454
443
|
declare function asNumber(value: QueryValue | number | undefined): number;
|
|
@@ -631,4 +620,4 @@ declare const contextStorageSessionStorageHandlerInjectKey: InjectionKey<Instanc
|
|
|
631
620
|
//#region src/constants.d.ts
|
|
632
621
|
declare const defaultHandlers: ContextStorageHandlerConstructor[];
|
|
633
622
|
//#endregion
|
|
634
|
-
export { CollectionManager, type CollectionManagerItem, _default as ContextStorage, _default$1 as ContextStorageActivator, _default$2 as ContextStorageCollection, type ContextStorageHandler, type ContextStorageHandlerConstructor, type ContextStorageHandlerMap, ContextStorageLocalStorageHandler, _default$3 as ContextStorageProvider, ContextStorageQueryHandler, ContextStorageSessionStorageHandler, type
|
|
623
|
+
export { CollectionManager, type CollectionManagerItem, _default as ContextStorage, _default$1 as ContextStorageActivator, _default$2 as ContextStorageCollection, type ContextStorageHandler, type ContextStorageHandlerConstructor, type ContextStorageHandlerMap, ContextStorageLocalStorageHandler, _default$3 as ContextStorageProvider, ContextStorageQueryHandler, ContextStorageSessionStorageHandler, type WebStorageHandlerBaseOptions as LocalStorageHandlerBaseOptions, type QueryValue, type RegisterBaseOptions, type RegisterWebStorageHandlerBaseOptions as RegisterLocalStorageHandlerBaseOptions, VueContextStoragePlugin, asArray, asBoolean, asNumber, asNumberArray, asString, contextStorageCollectionInjectKey, contextStorageCollectionItemInjectKey, contextStorageHandlersInjectKey, contextStorageLocalStorageHandlerInjectKey, contextStorageQueryHandlerInjectKey, contextStorageSessionStorageHandlerInjectKey, defaultHandlers, defineContextStorageHandler, deserializeParams as deserializeQueryParams, resolveHandlerInjectionKey, serializeParams as serializeQueryParams, transform, useContextStorage, useContextStorageActivator, useContextStorageCollection, useContextStorageLocalStorage, useContextStorageProvider, useContextStorageQueryHandler, useContextStorageSessionStorage };
|