vue-context-storage 0.1.24 → 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 +155 -146
- package/dist/index.js +516 -454
- 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>;
|
|
54
|
+
}
|
|
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>;
|
|
19
60
|
}
|
|
20
|
-
interface ContextStorageHandler<T> {
|
|
21
|
-
register: (data: MaybeRefOrGetter<T>, options:
|
|
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;
|
|
@@ -109,6 +150,25 @@ declare class CollectionManager {
|
|
|
109
150
|
type QueryValue = LocationQueryValue | LocationQueryValue[];
|
|
110
151
|
type DeepTransformValuesToLocationQueryValue<T> = { [K in keyof T]?: T[K] extends object ? T[K] extends Array<any> ? QueryValue : DeepTransformValuesToLocationQueryValue<T[K]> : QueryValue };
|
|
111
152
|
interface QueryHandlerSharedOptions {
|
|
153
|
+
/**
|
|
154
|
+
* Default: false
|
|
155
|
+
*
|
|
156
|
+
* If enabled - only values that differ from the initial state will be written to URL.
|
|
157
|
+
* This keeps URLs clean by omitting default values.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```
|
|
161
|
+
* Options: { onlyChanges: true }
|
|
162
|
+
*
|
|
163
|
+
* Initial state: { page: 1, search: '', with_trashed: false }
|
|
164
|
+
* Current state: { page: 1, search: 'test', with_trashed: true }
|
|
165
|
+
*
|
|
166
|
+
* URL will be: ?search=test&with_trashed=1
|
|
167
|
+
*
|
|
168
|
+
* The page parameter is omitted because it equals the initial value.
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
onlyChanges?: boolean;
|
|
112
172
|
/**
|
|
113
173
|
* Default: false
|
|
114
174
|
*
|
|
@@ -196,46 +256,12 @@ interface RegisterQueryHandlerBaseOptions<T> extends QueryHandlerSharedOptions {
|
|
|
196
256
|
* Note: If `schema` is provided, it takes priority over `transform`.
|
|
197
257
|
*/
|
|
198
258
|
transform?: (deserialized: DeepTransformValuesToLocationQueryValue<UnwrapNestedRefs<T>>, initialData: T) => UnwrapNestedRefs<T>;
|
|
199
|
-
/**
|
|
200
|
-
* Zod schema for automatic validation and type coercion.
|
|
201
|
-
*
|
|
202
|
-
* When provided, the schema will be used to parse and validate query parameters.
|
|
203
|
-
* This option takes priority over the `transform` option.
|
|
204
|
-
*
|
|
205
|
-
* @example
|
|
206
|
-
* ```typescript
|
|
207
|
-
* import { z } from 'zod'
|
|
208
|
-
*
|
|
209
|
-
* const FiltersSchema = z.object({
|
|
210
|
-
* search: z.string().default(''),
|
|
211
|
-
* page: z.coerce.number().int().positive().default(1),
|
|
212
|
-
* status: z.enum(['active', 'inactive']).default('active'),
|
|
213
|
-
* })
|
|
214
|
-
*
|
|
215
|
-
* useContextStorageQueryHandler(filters, {
|
|
216
|
-
* prefix: 'filters',
|
|
217
|
-
* schema: FiltersSchema,
|
|
218
|
-
* })
|
|
219
|
-
* ```
|
|
220
|
-
*/
|
|
221
|
-
schema?: {
|
|
222
|
-
safeParse: (data: unknown) => {
|
|
223
|
-
success: true;
|
|
224
|
-
data: T;
|
|
225
|
-
} | {
|
|
226
|
-
success: false;
|
|
227
|
-
error: any;
|
|
228
|
-
};
|
|
229
|
-
parse: (data: unknown) => T;
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
interface RegisterQueryHandlerOptions<T> extends RegisterBaseOptions, RegisterQueryHandlerBaseOptions<T> {}
|
|
233
|
-
interface IContextStorageQueryHandler<T extends Record<string, unknown>> extends ContextStorageHandler<T> {
|
|
234
|
-
register: <T extends Record<string, unknown>>(data: MaybeRefOrGetter<T>, options: RegisterQueryHandlerOptions<T>) => () => void;
|
|
235
259
|
}
|
|
260
|
+
interface RegisterQueryHandlerOptions<T> extends RegisterBaseOptions<T>, RegisterQueryHandlerBaseOptions<T> {}
|
|
236
261
|
interface ContextStorageQueryRegisteredItem<T extends Record<string, unknown>> {
|
|
237
262
|
data: MaybeRefOrGetter<T>;
|
|
238
263
|
initialData: T;
|
|
264
|
+
initialQueryData: LocationQuery;
|
|
239
265
|
options: RegisterQueryHandlerOptions<T>;
|
|
240
266
|
watchHandle: WatchHandle;
|
|
241
267
|
}
|
|
@@ -251,9 +277,6 @@ interface WebStorageHandlerBaseOptions {
|
|
|
251
277
|
listenToStorageEvents?: boolean;
|
|
252
278
|
}
|
|
253
279
|
interface RegisterWebStorageHandlerBaseOptions<T> {
|
|
254
|
-
/**
|
|
255
|
-
* Storage key for this data.
|
|
256
|
-
*/
|
|
257
280
|
key?: string;
|
|
258
281
|
/**
|
|
259
282
|
* Optional prefix for nested data within the storage key.
|
|
@@ -266,37 +289,6 @@ interface RegisterWebStorageHandlerBaseOptions<T> {
|
|
|
266
289
|
* Note: If `schema` is provided, it takes priority over `transform`.
|
|
267
290
|
*/
|
|
268
291
|
transform?: (deserialized: Record<string, unknown>, initialData: T) => UnwrapNestedRefs<T>;
|
|
269
|
-
/**
|
|
270
|
-
* Zod schema for automatic validation and type coercion.
|
|
271
|
-
*
|
|
272
|
-
* When provided, the schema will be used to parse and validate storage data.
|
|
273
|
-
* This option takes priority over the `transform` option.
|
|
274
|
-
*
|
|
275
|
-
* @example
|
|
276
|
-
* ```typescript
|
|
277
|
-
* import { z } from 'zod'
|
|
278
|
-
*
|
|
279
|
-
* const SettingsSchema = z.object({
|
|
280
|
-
* theme: z.enum(['light', 'dark']).default('light'),
|
|
281
|
-
* fontSize: z.number().int().positive().default(14),
|
|
282
|
-
* })
|
|
283
|
-
*
|
|
284
|
-
* useContextStorageLocalStorage(settings, {
|
|
285
|
-
* key: 'app-settings',
|
|
286
|
-
* schema: SettingsSchema,
|
|
287
|
-
* })
|
|
288
|
-
* ```
|
|
289
|
-
*/
|
|
290
|
-
schema?: {
|
|
291
|
-
safeParse: (data: unknown) => {
|
|
292
|
-
success: true;
|
|
293
|
-
data: T;
|
|
294
|
-
} | {
|
|
295
|
-
success: false;
|
|
296
|
-
error: any;
|
|
297
|
-
};
|
|
298
|
-
parse: (data: unknown) => T;
|
|
299
|
-
};
|
|
300
292
|
/**
|
|
301
293
|
* Custom serializer function. Defaults to JSON.stringify.
|
|
302
294
|
*/
|
|
@@ -306,10 +298,7 @@ interface RegisterWebStorageHandlerBaseOptions<T> {
|
|
|
306
298
|
*/
|
|
307
299
|
deserializer?: (str: string) => unknown;
|
|
308
300
|
}
|
|
309
|
-
interface RegisterWebStorageHandlerOptions<T> extends RegisterBaseOptions
|
|
310
|
-
interface IContextStorageWebStorageHandler<T extends Record<string, unknown>> extends ContextStorageHandler<T> {
|
|
311
|
-
register: <T extends Record<string, unknown>>(data: MaybeRefOrGetter<T>, options: RegisterWebStorageHandlerOptions<T>) => () => void;
|
|
312
|
-
}
|
|
301
|
+
interface RegisterWebStorageHandlerOptions<T> extends RegisterBaseOptions<T>, RegisterWebStorageHandlerBaseOptions<T> {}
|
|
313
302
|
interface ContextStorageWebStorageRegisteredItem<T extends Record<string, unknown>> {
|
|
314
303
|
data: MaybeRefOrGetter<T>;
|
|
315
304
|
initialData: T;
|
|
@@ -317,33 +306,6 @@ interface ContextStorageWebStorageRegisteredItem<T extends Record<string, unknow
|
|
|
317
306
|
watchHandle: WatchHandle;
|
|
318
307
|
}
|
|
319
308
|
//#endregion
|
|
320
|
-
//#region src/handlers/web-storage-base/index.d.ts
|
|
321
|
-
declare abstract class ContextStorageWebStorageHandler<T extends Record<string, unknown>> implements IContextStorageWebStorageHandler<T> {
|
|
322
|
-
protected enabled: boolean;
|
|
323
|
-
protected registered: ContextStorageWebStorageRegisteredItem<any>[];
|
|
324
|
-
protected initialState?: Record<string, unknown>;
|
|
325
|
-
protected hasAnyRegistered: boolean;
|
|
326
|
-
protected preventSyncToStorage: boolean;
|
|
327
|
-
protected abstract readonly storage: Storage;
|
|
328
|
-
protected abstract readonly injectionKey: InjectionKey<ContextStorageWebStorageHandler<T>>;
|
|
329
|
-
protected readonly options: Required<WebStorageHandlerBaseOptions>;
|
|
330
|
-
private storageEventHandler;
|
|
331
|
-
constructor(defaultOptions: Required<WebStorageHandlerBaseOptions>);
|
|
332
|
-
protected initializeStorageListener(): void;
|
|
333
|
-
protected handleStorageEvent(event: StorageEvent): void;
|
|
334
|
-
getInjectionKey(): InjectionKey<ContextStorageWebStorageHandler<T>>;
|
|
335
|
-
setInitialState(state: Record<string, unknown> | undefined): void;
|
|
336
|
-
setEnabled(state: boolean, initial: boolean): void;
|
|
337
|
-
syncRegisteredToStorage(): void;
|
|
338
|
-
syncStorageToRegisteredItem<T extends Record<string, unknown>>(item: ContextStorageWebStorageRegisteredItem<T>): void;
|
|
339
|
-
syncStorageToRegistered(): void;
|
|
340
|
-
register<T extends Record<string, unknown>>(data: MaybeRefOrGetter<T>, options: RegisterWebStorageHandlerOptions<T>): () => void;
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* Options for the web storage composable with required key
|
|
344
|
-
*/
|
|
345
|
-
type UseWebStorageOptions<T> = RegisterWebStorageHandlerBaseOptions<T> & Required<Pick<RegisterWebStorageHandlerBaseOptions<T>, 'key'>>;
|
|
346
|
-
//#endregion
|
|
347
309
|
//#region src/registry.d.ts
|
|
348
310
|
/**
|
|
349
311
|
* Augmentable interface mapping handler names to their options types.
|
|
@@ -358,15 +320,23 @@ type UseWebStorageOptions<T> = RegisterWebStorageHandlerBaseOptions<T> & Require
|
|
|
358
320
|
* ```
|
|
359
321
|
*/
|
|
360
322
|
interface ContextStorageHandlerMap<T> {
|
|
361
|
-
query:
|
|
362
|
-
localStorage:
|
|
363
|
-
sessionStorage:
|
|
323
|
+
query: RegisterQueryHandlerOptions<T>;
|
|
324
|
+
localStorage: RegisterWebStorageHandlerOptions<T>;
|
|
325
|
+
sessionStorage: RegisterWebStorageHandlerOptions<T>;
|
|
364
326
|
}
|
|
365
|
-
declare function defineContextStorageHandler<T>(name: string, injectionKey: InjectionKey<ContextStorageHandler<T>>): void;
|
|
366
|
-
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
|
+
};
|
|
367
337
|
//#endregion
|
|
368
338
|
//#region src/composables/useContextStorage.d.ts
|
|
369
|
-
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>;
|
|
370
340
|
//#endregion
|
|
371
341
|
//#region src/composables/useContextStorageActivator.d.ts
|
|
372
342
|
declare function useContextStorageActivator(): {
|
|
@@ -383,11 +353,12 @@ declare function useContextStorageProvider(key: string): void;
|
|
|
383
353
|
declare const contextStorageQueryHandler: unique symbol;
|
|
384
354
|
//#endregion
|
|
385
355
|
//#region src/handlers/query/index.d.ts
|
|
386
|
-
declare function useContextStorageQueryHandler<T extends Record<string, unknown>>(data: MaybeRefOrGetter<T>, options?:
|
|
387
|
-
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>> {
|
|
388
358
|
#private;
|
|
389
359
|
private enabled;
|
|
390
360
|
private registered;
|
|
361
|
+
private registeredDataObjects;
|
|
391
362
|
private currentQuery;
|
|
392
363
|
private readonly route;
|
|
393
364
|
private router;
|
|
@@ -395,6 +366,8 @@ declare class ContextStorageQueryHandler<T extends Record<string, unknown>> impl
|
|
|
395
366
|
private hasAnyRegistered;
|
|
396
367
|
private preventSyncRegisteredToQueryByAfterEachRoute;
|
|
397
368
|
private preventAfterEachRouteCallsWhileCallingRouter;
|
|
369
|
+
private syncToQueryScheduled;
|
|
370
|
+
private registeredVersion;
|
|
398
371
|
static customQueryHandlerOptions: QueryHandlerBaseOptions;
|
|
399
372
|
private readonly options;
|
|
400
373
|
static configure<T extends Record<string, unknown>>(options: QueryHandlerBaseOptions): ContextStorageHandlerConstructor<T>;
|
|
@@ -404,31 +377,67 @@ declare class ContextStorageQueryHandler<T extends Record<string, unknown>> impl
|
|
|
404
377
|
static getInitialStateResolver(): () => LocationQuery;
|
|
405
378
|
setEnabled(state: boolean, initial: boolean): void;
|
|
406
379
|
syncRegisteredToQuery(): Promise<void>;
|
|
380
|
+
private scheduleSyncToQuery;
|
|
407
381
|
afterEachRoute(): void;
|
|
408
|
-
syncInitialStateToRegisteredItem<T extends Record<string, unknown>>(item: ContextStorageQueryRegisteredItem<T>): void;
|
|
409
382
|
syncInitialStateToRegistered(): void;
|
|
410
|
-
|
|
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
|
+
};
|
|
411
418
|
}
|
|
412
419
|
//#endregion
|
|
413
420
|
//#region src/handlers/local-storage/index.d.ts
|
|
414
421
|
declare class ContextStorageLocalStorageHandler<T extends Record<string, unknown>> extends ContextStorageWebStorageHandler<T> {
|
|
415
422
|
protected readonly storage: Storage;
|
|
416
423
|
protected readonly injectionKey: InjectionKey<ContextStorageLocalStorageHandler<T>>;
|
|
424
|
+
protected readonly handlerName = "localStorage";
|
|
417
425
|
static customHandlerOptions: WebStorageHandlerBaseOptions;
|
|
418
426
|
constructor();
|
|
419
427
|
static configure<T extends Record<string, unknown>>(options: WebStorageHandlerBaseOptions): ContextStorageHandlerConstructor<T>;
|
|
420
428
|
}
|
|
421
|
-
declare const useContextStorageLocalStorage: <
|
|
429
|
+
declare const useContextStorageLocalStorage: (data: vue19.MaybeRefOrGetter<Record<string, unknown>>, options: RegisterWebStorageHandlerOptions<Record<string, unknown>>) => UseContextStorageResult<Record<string, unknown>>;
|
|
422
430
|
//#endregion
|
|
423
431
|
//#region src/handlers/session-storage/index.d.ts
|
|
424
432
|
declare class ContextStorageSessionStorageHandler<T extends Record<string, unknown>> extends ContextStorageWebStorageHandler<T> {
|
|
425
433
|
protected readonly storage: Storage;
|
|
426
434
|
protected readonly injectionKey: InjectionKey<ContextStorageSessionStorageHandler<T>>;
|
|
435
|
+
protected readonly handlerName = "sessionStorage";
|
|
427
436
|
static customHandlerOptions: WebStorageHandlerBaseOptions;
|
|
428
437
|
constructor();
|
|
429
438
|
static configure<T extends Record<string, unknown>>(options: WebStorageHandlerBaseOptions): ContextStorageHandlerConstructor<T>;
|
|
430
439
|
}
|
|
431
|
-
declare const useContextStorageSessionStorage: <
|
|
440
|
+
declare const useContextStorageSessionStorage: (data: vue19.MaybeRefOrGetter<Record<string, unknown>>, options: RegisterWebStorageHandlerOptions<Record<string, unknown>>) => UseContextStorageResult<Record<string, unknown>>;
|
|
432
441
|
//#endregion
|
|
433
442
|
//#region src/handlers/query/transform-helpers.d.ts
|
|
434
443
|
declare function asNumber(value: QueryValue | number | undefined): number;
|
|
@@ -598,7 +607,7 @@ declare function serializeParams(params: Record<string, unknown>, options?: Seri
|
|
|
598
607
|
* deserializeParams({ 'filters[status]': 'active', search: 'test' })
|
|
599
608
|
* // => { filters: {status: 'active'}, search: 'test' }
|
|
600
609
|
*/
|
|
601
|
-
declare function deserializeParams(params: Record<string, any>): Record<string,
|
|
610
|
+
declare function deserializeParams(params: Record<string, any>): Record<string, unknown>;
|
|
602
611
|
//#endregion
|
|
603
612
|
//#region src/injectionSymbols.d.ts
|
|
604
613
|
declare const contextStorageCollectionInjectKey: InjectionKey<CollectionManager>;
|
|
@@ -611,4 +620,4 @@ declare const contextStorageSessionStorageHandlerInjectKey: InjectionKey<Instanc
|
|
|
611
620
|
//#region src/constants.d.ts
|
|
612
621
|
declare const defaultHandlers: ContextStorageHandlerConstructor[];
|
|
613
622
|
//#endregion
|
|
614
|
-
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 };
|