vue-context-storage 0.1.8 → 0.1.10

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.
Files changed (42) hide show
  1. package/dist/index.d.ts +411 -10
  2. package/dist/index.js +193 -22
  3. package/package.json +38 -37
  4. package/dist/collection.d.cts +0 -22
  5. package/dist/collection.d.ts +0 -22
  6. package/dist/constants.d.cts +0 -2
  7. package/dist/constants.d.ts +0 -2
  8. package/dist/handlers/query/helpers.d.cts +0 -45
  9. package/dist/handlers/query/helpers.d.ts +0 -45
  10. package/dist/handlers/query/index.d.cts +0 -31
  11. package/dist/handlers/query/index.d.ts +0 -31
  12. package/dist/handlers/query/transform-helpers.d.cts +0 -123
  13. package/dist/handlers/query/transform-helpers.d.ts +0 -123
  14. package/dist/handlers/query/types.d.cts +0 -103
  15. package/dist/handlers/query/types.d.ts +0 -103
  16. package/dist/handlers.d.cts +0 -15
  17. package/dist/handlers.d.ts +0 -15
  18. package/dist/index.cjs +0 -409
  19. package/dist/index.cjs.map +0 -1
  20. package/dist/index.d.cts +0 -10
  21. package/dist/index.js.map +0 -1
  22. package/dist/injectionSymbols.d.cts +0 -7
  23. package/dist/injectionSymbols.d.ts +0 -7
  24. package/dist/symbols.d.cts +0 -4
  25. package/dist/symbols.d.ts +0 -4
  26. package/src/collection.ts +0 -71
  27. package/src/components/ContextStorage.vue +0 -23
  28. package/src/components/ContextStorageActivator.vue +0 -20
  29. package/src/components/ContextStorageCollection.vue +0 -92
  30. package/src/components/ContextStorageProvider.vue +0 -38
  31. package/src/constants.ts +0 -5
  32. package/src/handlers/query/helpers.ts +0 -134
  33. package/src/handlers/query/index.ts +0 -355
  34. package/src/handlers/query/transform-helpers.ts +0 -309
  35. package/src/handlers/query/types.ts +0 -125
  36. package/src/handlers.ts +0 -18
  37. package/src/index.ts +0 -40
  38. package/src/injectionSymbols.ts +0 -15
  39. package/src/main.ts +0 -12
  40. package/src/plugin.ts +0 -16
  41. package/src/shims-vue.d.ts +0 -5
  42. package/src/symbols.ts +0 -4
package/dist/index.d.ts CHANGED
@@ -1,10 +1,411 @@
1
- export type { ContextStorageHandler, ContextStorageHandlerConstructor, RegisterBaseOptions, } from './handlers';
2
- export { ContextStorageQueryHandler, useContextStorageQueryHandler } from './handlers/query';
3
- export { deserializeParams, serializeParams } from './handlers/query/helpers';
4
- export type { SerializeOptions } from './handlers/query/helpers';
5
- export { asArray, asBoolean, asNumber, asNumberArray, asString, transform, } from './handlers/query/transform-helpers';
6
- export { contextStorageCollectionInjectKey, contextStorageCollectionItemInjectKey, contextStorageHandlersInjectKey, contextStorageQueryHandlerInjectKey, } from './injectionSymbols';
7
- export { collection, collectionItem, contextStorageQueryHandler, handlers } from './symbols';
8
- export { defaultHandlers } from './constants';
9
- export type { QueryValue, IContextStorageQueryHandler } from './handlers/query/types';
10
- export type { ContextStorageCollectionItem } from './collection';
1
+ import * as vue0 from "vue";
2
+ import { InjectionKey, MaybeRefOrGetter, PropType, UnwrapNestedRefs, WatchHandle } from "vue";
3
+ import { LocationQuery, LocationQueryValue } from "vue-router";
4
+
5
+ //#region src/components/ContextStorageActivator.vue.d.ts
6
+ declare const _default$1: typeof __VLS_export$3;
7
+ declare const __VLS_export$3: vue0.DefineComponent<{}, () => vue0.VNode<vue0.RendererNode, vue0.RendererElement, {
8
+ [key: string]: any;
9
+ }>, {}, {}, {}, vue0.ComponentOptionsMixin, vue0.ComponentOptionsMixin, {}, string, vue0.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, vue0.ComponentProvideOptions, true, {}, any>;
10
+ //#endregion
11
+ //#region src/handlers.d.ts
12
+ interface ContextStorageHandlerConstructor {
13
+ new (): ContextStorageHandler;
14
+ getInitialStateResolver?: () => () => Record<string, unknown>;
15
+ }
16
+ interface RegisterBaseOptions {
17
+ causer: string;
18
+ uid: number;
19
+ }
20
+ interface ContextStorageHandler {
21
+ register: (data: MaybeRefOrGetter, options: RegisterBaseOptions) => () => void;
22
+ setInitialState?: (state: Record<string, unknown>) => void;
23
+ setEnabled?: (enabled: boolean, initial: boolean) => void;
24
+ getInjectionKey(): InjectionKey<ContextStorageHandler>;
25
+ }
26
+ //#endregion
27
+ //#region src/components/ContextStorageCollection.vue.d.ts
28
+ declare const _default$2: typeof __VLS_export$2;
29
+ declare const __VLS_export$2: vue0.DefineComponent<vue0.ExtractPropTypes<{
30
+ handlers: {
31
+ type: PropType<ContextStorageHandlerConstructor[]>;
32
+ default: () => ContextStorageHandlerConstructor[];
33
+ };
34
+ }>, () => vue0.VNode<vue0.RendererNode, vue0.RendererElement, {
35
+ [key: string]: any;
36
+ }>[] | undefined, {}, {}, {}, vue0.ComponentOptionsMixin, vue0.ComponentOptionsMixin, {}, string, vue0.PublicProps, Readonly<vue0.ExtractPropTypes<{
37
+ handlers: {
38
+ type: PropType<ContextStorageHandlerConstructor[]>;
39
+ default: () => ContextStorageHandlerConstructor[];
40
+ };
41
+ }>> & Readonly<{}>, {
42
+ handlers: ContextStorageHandlerConstructor[];
43
+ }, {}, {}, {}, string, vue0.ComponentProvideOptions, true, {}, any>;
44
+ //#endregion
45
+ //#region src/components/ContextStorageProvider.vue.d.ts
46
+ declare const _default$3: typeof __VLS_export$1;
47
+ declare const __VLS_export$1: vue0.DefineComponent<vue0.ExtractPropTypes<{
48
+ itemKey: {
49
+ type: StringConstructor;
50
+ required: true;
51
+ };
52
+ }>, () => vue0.VNode<vue0.RendererNode, vue0.RendererElement, {
53
+ [key: string]: any;
54
+ }>[] | undefined, {}, {}, {}, vue0.ComponentOptionsMixin, vue0.ComponentOptionsMixin, {}, string, vue0.PublicProps, Readonly<vue0.ExtractPropTypes<{
55
+ itemKey: {
56
+ type: StringConstructor;
57
+ required: true;
58
+ };
59
+ }>> & Readonly<{}>, {}, {}, {}, {}, string, vue0.ComponentProvideOptions, true, {}, any>;
60
+ //#endregion
61
+ //#region src/components/ContextStorage.vue.d.ts
62
+ interface Props {
63
+ handlers: ContextStorageHandlerConstructor[];
64
+ }
65
+ declare var __VLS_20: {};
66
+ type __VLS_Slots = {} & {
67
+ default?: (props: typeof __VLS_20) => any;
68
+ };
69
+ declare const __VLS_base: vue0.DefineComponent<Props, {}, {}, {}, {}, vue0.ComponentOptionsMixin, vue0.ComponentOptionsMixin, {}, string, vue0.PublicProps, Readonly<Props> & Readonly<{}>, {}, {}, {}, {}, string, vue0.ComponentProvideOptions, false, {}, any>;
70
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
71
+ declare const _default: typeof __VLS_export;
72
+ type __VLS_WithSlots<T, S> = T & {
73
+ new (): {
74
+ $slots: S;
75
+ };
76
+ };
77
+ //#endregion
78
+ //#region src/symbols.d.ts
79
+ declare const collection: unique symbol;
80
+ declare const collectionItem: unique symbol;
81
+ declare const handlers: unique symbol;
82
+ declare const contextStorageQueryHandler: unique symbol;
83
+ //#endregion
84
+ //#region src/handlers/query/types.d.ts
85
+ type QueryValue = LocationQueryValue | LocationQueryValue[];
86
+ type DeepTransformValuesToLocationQueryValue<T> = { [K in keyof T]?: T[K] extends object ? T[K] extends Array<any> ? QueryValue : DeepTransformValuesToLocationQueryValue<T[K]> : QueryValue };
87
+ interface QueryHandlerSharedOptions {
88
+ /**
89
+ * Default: false
90
+ *
91
+ * If enabled - empty state will be preserved in query.
92
+ *
93
+ * Useful, when you have default values, and want to preserve empty state in query.
94
+ * @example
95
+ * ```
96
+ * Options: {preserveEmptyState: true, prefix: 'filters'}
97
+ *
98
+ * When filters are empty we will get this in query string:
99
+ *
100
+ * /list?filters
101
+ *
102
+ * After page reload state will be not restored to default
103
+ * ```
104
+ *
105
+ * @example
106
+ * ```
107
+ * Options: {preserveEmptyState: false, prefix: 'filters'}
108
+ *
109
+ * When filters are empty we will get this in query string:
110
+ *
111
+ * /list
112
+ *
113
+ * After page reload state will be restored to default
114
+ * ```
115
+ *
116
+ * @example
117
+ * ```
118
+ * Options: {preserveEmptyState: true}
119
+ *
120
+ * When filters are empty we will get this in query string:
121
+ *
122
+ * /list?_
123
+ *
124
+ * After page reload state will be not restored to default.
125
+ * Underscore (_) is default value for emptyPlaceholder option
126
+ * ```
127
+ */
128
+ preserveEmptyState?: boolean;
129
+ /**
130
+ * Default: true
131
+ *
132
+ * If transform option is not passed, ref will be merged with query only by keys that exists in ref.
133
+ */
134
+ mergeOnlyExistingKeysWithoutTransform?: boolean;
135
+ }
136
+ interface QueryHandlerBaseOptions extends QueryHandlerSharedOptions {
137
+ /**
138
+ * Default: replace
139
+ *
140
+ * Vue-router navigate mode.
141
+ * Use push if you want to add new query to history.
142
+ * Use replace if you want to replace current query without adding to history.
143
+ */
144
+ mode?: 'replace' | 'push';
145
+ /**
146
+ * Default: _
147
+ *
148
+ * Placeholder for empty state, used when preserveEmptyState is true and all ref values are empty.
149
+ */
150
+ emptyPlaceholder?: string;
151
+ /**
152
+ * Default: false
153
+ *
154
+ * If enabled - unused keys will be preserved in query.
155
+ * Unused keys are keys, that are not exists in ref.
156
+ */
157
+ preserveUnusedKeys?: boolean;
158
+ }
159
+ interface RegisterQueryHandlerBaseOptions<T> extends QueryHandlerSharedOptions {
160
+ /**
161
+ * Prefix in query string.
162
+ *
163
+ * @example
164
+ * ```
165
+ * filters, table-1[filters], table-2[filters]
166
+ * ```
167
+ */
168
+ prefix?: string;
169
+ transform?: (deserialized: DeepTransformValuesToLocationQueryValue<UnwrapNestedRefs<T>>, initialData: T) => UnwrapNestedRefs<T>;
170
+ }
171
+ interface RegisterQueryHandlerOptions<T> extends RegisterBaseOptions, RegisterQueryHandlerBaseOptions<T> {}
172
+ interface IContextStorageQueryHandler extends ContextStorageHandler {
173
+ register: <T extends Record<string, unknown>>(data: MaybeRefOrGetter<T>, options: RegisterQueryHandlerOptions<T>) => () => void;
174
+ }
175
+ interface ContextStorageQueryRegisteredItem<T extends Record<string, unknown>> {
176
+ data: MaybeRefOrGetter<T>;
177
+ initialData: T;
178
+ options: RegisterQueryHandlerOptions<T>;
179
+ watchHandle: WatchHandle;
180
+ }
181
+ //#endregion
182
+ //#region src/handlers/query/index.d.ts
183
+ declare function useContextStorageQueryHandler<T extends Record<string, unknown>>(data: MaybeRefOrGetter<T>, options?: RegisterQueryHandlerBaseOptions<T>): void;
184
+ declare class ContextStorageQueryHandler implements IContextStorageQueryHandler {
185
+ #private;
186
+ private enabled;
187
+ private registered;
188
+ private currentQuery;
189
+ private readonly route;
190
+ private router;
191
+ private initialState?;
192
+ private hasAnyRegistered;
193
+ private preventSyncRegisteredToQueryByAfterEachRoute;
194
+ private preventAfterEachRouteCallsWhileCallingRouter;
195
+ static customQueryHandlerOptions: QueryHandlerBaseOptions;
196
+ private readonly options;
197
+ static configure(options: QueryHandlerBaseOptions): ContextStorageHandlerConstructor;
198
+ constructor();
199
+ getInjectionKey(): typeof contextStorageQueryHandler;
200
+ setInitialState(state: Record<string, unknown> | undefined): void;
201
+ static getInitialStateResolver(): () => LocationQuery;
202
+ setEnabled(state: boolean, initial: boolean): void;
203
+ syncRegisteredToQuery(): Promise<void>;
204
+ afterEachRoute(): void;
205
+ syncInitialStateToRegisteredItem<T extends Record<string, unknown>>(item: ContextStorageQueryRegisteredItem<T>): void;
206
+ syncInitialStateToRegistered(): void;
207
+ register<T extends Record<string, unknown>>(data: MaybeRefOrGetter<T>, options: RegisterQueryHandlerOptions<T>): () => void;
208
+ }
209
+ //#endregion
210
+ //#region src/handlers/query/helpers.d.ts
211
+ interface SerializeOptions {
212
+ /**
213
+ * Custom prefix for serialized keys.
214
+ * @example
215
+ * - prefix: 'filters' => 'filters[key]'
216
+ * - prefix: 'search' => 'search[key]'
217
+ * - prefix: '' => 'key' (no prefix)
218
+ */
219
+ prefix?: string;
220
+ }
221
+ /**
222
+ * Serializes filter parameters into a URL-friendly format.
223
+ *
224
+ * @param params - Raw parameters object to serialize
225
+ * @param options - Serialization options
226
+ * @returns Serialized parameters with prefixed keys
227
+ *
228
+ * @example
229
+ * // With default prefix 'filters'
230
+ * serializeFiltersParams({ status: 'active', tags: ['a', 'b'] })
231
+ * // => { 'filters[status]': 'active', 'filters[tags]': 'a,b' }
232
+ *
233
+ * @example
234
+ * // With custom prefix
235
+ * serializeFiltersParams({ name: 'John', all: true }, { prefix: 'search' })
236
+ * // => { 'search[name]': 'John', 'search[all]': '1' }
237
+ *
238
+ * @example
239
+ * // Without prefix
240
+ * serializeFiltersParams({ page: 1, all: false }, { prefix: '' })
241
+ * // => { 'page': '1', 'all': '0' }
242
+ */
243
+ declare function serializeParams(params: Record<string, unknown>, options?: SerializeOptions): LocationQuery;
244
+ /**
245
+ * Deserializes query parameters from a URL-friendly format back to an object.
246
+ *
247
+ * @param params - Serialized parameters object
248
+ * @returns Deserialized parameters object
249
+ *
250
+ * @example
251
+ * deserializeParams({ 'filters[status]': 'active', search: 'test' })
252
+ * // => { filters: {status: 'active'}, search: 'test' }
253
+ */
254
+ declare function deserializeParams(params: Record<string, any>): Record<string, any>;
255
+ //#endregion
256
+ //#region src/handlers/query/transform-helpers.d.ts
257
+ declare function asNumber(value: QueryValue | number | undefined): number;
258
+ declare function asNumber(value: QueryValue | number | undefined, options: {
259
+ nullable: true;
260
+ missable: true;
261
+ fallbackValue?: number;
262
+ }): number | null | undefined;
263
+ declare function asNumber(value: QueryValue | number | undefined, options: {
264
+ nullable: true;
265
+ missable?: false;
266
+ fallbackValue?: number;
267
+ }): number | null;
268
+ declare function asNumber(value: QueryValue | number | undefined, options: {
269
+ nullable?: false;
270
+ missable: true;
271
+ fallbackValue?: number;
272
+ }): number | undefined;
273
+ declare function asNumber(value: QueryValue | number | undefined, options: {
274
+ nullable?: false;
275
+ missable?: false;
276
+ fallbackValue?: number;
277
+ }): number;
278
+ declare function asString(value: QueryValue | undefined): string;
279
+ declare function asString<T extends readonly string[]>(value: QueryValue | undefined, options: {
280
+ nullable: true;
281
+ missable: true;
282
+ fallbackValue?: T[number];
283
+ allowedValues: T;
284
+ }): T[number] | null | undefined;
285
+ declare function asString<T extends readonly string[]>(value: QueryValue | undefined, options: {
286
+ nullable: true;
287
+ missable?: false;
288
+ fallbackValue?: T[number];
289
+ allowedValues: T;
290
+ }): T[number] | null;
291
+ declare function asString<T extends readonly string[]>(value: QueryValue | undefined, options: {
292
+ nullable?: false;
293
+ missable: true;
294
+ fallbackValue?: T[number];
295
+ allowedValues: T;
296
+ }): T[number] | undefined;
297
+ declare function asString<T extends readonly string[]>(value: QueryValue | undefined, options: {
298
+ nullable?: false;
299
+ missable?: false;
300
+ fallbackValue?: T[number];
301
+ allowedValues: T;
302
+ }): T[number];
303
+ declare function asString(value: QueryValue | undefined, options: {
304
+ nullable: true;
305
+ missable: true;
306
+ fallbackValue?: string;
307
+ }): string | null | undefined;
308
+ declare function asString(value: QueryValue | undefined, options: {
309
+ nullable: true;
310
+ missable?: false;
311
+ fallbackValue?: string;
312
+ }): string | null;
313
+ declare function asString(value: QueryValue | undefined, options: {
314
+ nullable?: false;
315
+ missable: true;
316
+ fallbackValue?: string;
317
+ }): string | undefined;
318
+ declare function asString(value: QueryValue | undefined, options: {
319
+ nullable?: false;
320
+ missable?: false;
321
+ fallbackValue?: string;
322
+ }): string;
323
+ declare function asNumberArray(value: QueryValue | undefined): number[];
324
+ declare function asNumberArray(value: QueryValue | undefined, options: {
325
+ nullable: true;
326
+ }): number[] | null;
327
+ declare function asNumberArray(value: QueryValue | undefined, options: {
328
+ nullable?: false;
329
+ }): number[];
330
+ declare function asArray<T>(value: QueryValue | undefined): T[];
331
+ declare function asArray<T>(value: QueryValue | undefined, options: {
332
+ nullable: true;
333
+ missable: true;
334
+ transform?: (value: QueryValue) => T;
335
+ }): T[] | null | undefined;
336
+ declare function asArray<T>(value: QueryValue | undefined, options: {
337
+ nullable: true;
338
+ missable?: false;
339
+ transform?: (value: QueryValue) => T;
340
+ }): T[] | null;
341
+ declare function asArray<T>(value: QueryValue | undefined, options: {
342
+ nullable?: false;
343
+ missable: true;
344
+ transform?: (value: QueryValue) => T;
345
+ }): T[] | undefined;
346
+ declare function asArray<T>(value: QueryValue | undefined, options: {
347
+ nullable?: false;
348
+ missable?: false;
349
+ transform?: (value: QueryValue) => T;
350
+ }): T[];
351
+ declare function asBoolean(value: QueryValue | undefined): boolean;
352
+ declare function asBoolean(value: QueryValue | undefined, options: {
353
+ nullable: true;
354
+ missable: true;
355
+ fallbackValue?: boolean;
356
+ }): boolean | null | undefined;
357
+ declare function asBoolean(value: QueryValue | undefined, options: {
358
+ nullable: true;
359
+ missable?: false;
360
+ fallbackValue?: boolean;
361
+ }): boolean | null;
362
+ declare function asBoolean(value: QueryValue | undefined, options: {
363
+ nullable?: false;
364
+ missable: true;
365
+ fallbackValue?: boolean;
366
+ }): boolean | undefined;
367
+ declare function asBoolean(value: QueryValue | undefined, options: {
368
+ nullable?: false;
369
+ missable?: false;
370
+ fallbackValue?: boolean;
371
+ }): boolean;
372
+ declare const transform: {
373
+ asString: typeof asString;
374
+ asNumber: typeof asNumber;
375
+ asArray: typeof asArray;
376
+ asNumberArray: typeof asNumberArray;
377
+ asBoolean: typeof asBoolean;
378
+ };
379
+ //#endregion
380
+ //#region src/collection.d.ts
381
+ type ContextStorageCollectionItem = {
382
+ key: string;
383
+ handlers: ContextStorageHandler[];
384
+ };
385
+ interface ItemOptions {
386
+ key: string;
387
+ }
388
+ declare class ContextStorageCollection {
389
+ private handlerConstructors;
390
+ active?: ContextStorageCollectionItem;
391
+ private collection;
392
+ private onActiveChangeCallbacks;
393
+ constructor(handlerConstructors: ContextStorageHandlerConstructor[]);
394
+ onActiveChange(callback: (item: ContextStorageCollectionItem) => void): void;
395
+ first(): ContextStorageCollectionItem | undefined;
396
+ findItemByKey(key: string): ContextStorageCollectionItem | undefined;
397
+ add(options: ItemOptions): ContextStorageCollectionItem;
398
+ remove(removeItem: ContextStorageCollectionItem): void;
399
+ setActive(activeItem: ContextStorageCollectionItem): void;
400
+ }
401
+ //#endregion
402
+ //#region src/injectionSymbols.d.ts
403
+ declare const contextStorageCollectionInjectKey: InjectionKey<ContextStorageCollection>;
404
+ declare const contextStorageCollectionItemInjectKey: InjectionKey<ContextStorageCollectionItem>;
405
+ declare const contextStorageHandlersInjectKey: InjectionKey<ContextStorageCollectionItem['handlers']>;
406
+ declare const contextStorageQueryHandlerInjectKey: InjectionKey<InstanceType<typeof ContextStorageQueryHandler>>;
407
+ //#endregion
408
+ //#region src/constants.d.ts
409
+ declare const defaultHandlers: ContextStorageHandlerConstructor[];
410
+ //#endregion
411
+ export { _default as ContextStorage, _default$1 as ContextStorageActivator, _default$2 as ContextStorageCollection, type ContextStorageHandler, type ContextStorageHandlerConstructor, _default$3 as ContextStorageProvider, ContextStorageQueryHandler, type IContextStorageQueryHandler, type QueryValue, type RegisterBaseOptions, type SerializeOptions, asArray, asBoolean, asNumber, asNumberArray, asString, collection, collectionItem, contextStorageCollectionInjectKey, contextStorageCollectionItemInjectKey, contextStorageHandlersInjectKey, contextStorageQueryHandler, contextStorageQueryHandlerInjectKey, defaultHandlers, deserializeParams, handlers, serializeParams, transform, useContextStorageQueryHandler };
package/dist/index.js CHANGED
@@ -1,7 +1,51 @@
1
- import { cloneDeep, isEqual, merge, pick } from "lodash-es";
2
- import { getCurrentInstance, inject, onBeforeUnmount, toValue, watch } from "vue";
1
+ import { computed, createBlock, createVNode, defineComponent, getCurrentInstance, h, inject, onBeforeUnmount, onUnmounted, openBlock, provide, renderSlot, toValue, watch, withCtx } from "vue";
2
+ import { cloneDeep, isEqual, merge, pick } from "lodash";
3
3
  import { useRoute, useRouter } from "vue-router";
4
4
 
5
+ //#region src/collection.ts
6
+ var ContextStorageCollection = class {
7
+ active = void 0;
8
+ collection = [];
9
+ onActiveChangeCallbacks = [];
10
+ constructor(handlerConstructors) {
11
+ this.handlerConstructors = handlerConstructors;
12
+ }
13
+ onActiveChange(callback) {
14
+ this.onActiveChangeCallbacks.push(callback);
15
+ }
16
+ first() {
17
+ return this.collection[0];
18
+ }
19
+ findItemByKey(key) {
20
+ return this.collection.find((item) => item.key === key);
21
+ }
22
+ add(options) {
23
+ const item = {
24
+ handlers: this.handlerConstructors.map((constructor) => new constructor()),
25
+ key: options.key
26
+ };
27
+ this.collection.push(item);
28
+ return item;
29
+ }
30
+ remove(removeItem) {
31
+ if (this.collection.indexOf(removeItem) === -1) throw new Error("[ContextStorage] Item not found in collection");
32
+ this.collection = this.collection.filter((item) => item !== removeItem);
33
+ if (this.active === removeItem && this.collection.length > 0) this.setActive(this.collection[this.collection.length - 1]);
34
+ }
35
+ setActive(activeItem) {
36
+ if (this.active === activeItem) return;
37
+ const hasActiveBefore = this.active !== void 0;
38
+ this.active = activeItem;
39
+ this.collection.forEach((item) => {
40
+ Object.values(item.handlers).forEach((handler) => {
41
+ if (handler.setEnabled) handler.setEnabled(item === activeItem, !hasActiveBefore);
42
+ });
43
+ });
44
+ this.onActiveChangeCallbacks.forEach((callback) => callback(activeItem));
45
+ }
46
+ };
47
+
48
+ //#endregion
5
49
  //#region src/handlers/query/helpers.ts
6
50
  /**
7
51
  * Serializes filter parameters into a URL-friendly format.
@@ -87,9 +131,8 @@ const contextStorageQueryHandler = Symbol("context-storage-query-handler");
87
131
  function useContextStorageQueryHandler(data, options) {
88
132
  const handler = inject(contextStorageQueryHandler);
89
133
  if (!handler) throw new Error("[ContextStorage] ContextStorageQueryHandler is not provided");
90
- const currentInstance = getCurrentInstance();
91
- const uid = currentInstance?.uid || 0;
92
- const causer = new Error().stack?.split("\n")[2]?.trimStart() || "unknown";
134
+ const uid = getCurrentInstance()?.uid || 0;
135
+ const causer = (/* @__PURE__ */ new Error()).stack?.split("\n")[2]?.trimStart() || "unknown";
93
136
  const stop = handler.register(data, {
94
137
  causer,
95
138
  uid,
@@ -290,19 +333,159 @@ var ContextStorageQueryHandler = class ContextStorageQueryHandler {
290
333
  }
291
334
  };
292
335
 
336
+ //#endregion
337
+ //#region src/injectionSymbols.ts
338
+ const contextStorageCollectionInjectKey = collection;
339
+ const contextStorageCollectionItemInjectKey = collectionItem;
340
+ const contextStorageHandlersInjectKey = handlers;
341
+ const contextStorageQueryHandlerInjectKey = contextStorageQueryHandler;
342
+
343
+ //#endregion
344
+ //#region src/components/ContextStorageActivator.vue?vue&type=script&lang.ts
345
+ var ContextStorageActivator_vue_vue_type_script_lang_default = defineComponent({ setup(_, { slots }) {
346
+ const collection$1 = inject(contextStorageCollectionInjectKey);
347
+ const item = inject(contextStorageCollectionItemInjectKey);
348
+ const onActivate = () => {
349
+ collection$1.setActive(item);
350
+ };
351
+ return () => h("div", { onMousedown: onActivate }, slots.default?.());
352
+ } });
353
+
354
+ //#endregion
355
+ //#region src/components/ContextStorageActivator.vue
356
+ var ContextStorageActivator_default = ContextStorageActivator_vue_vue_type_script_lang_default;
357
+
358
+ //#endregion
359
+ //#region src/constants.ts
360
+ const defaultHandlers = [ContextStorageQueryHandler];
361
+
362
+ //#endregion
363
+ //#region src/components/ContextStorageCollection.vue?vue&type=script&lang.ts
364
+ var ContextStorageCollection_vue_vue_type_script_lang_default = defineComponent({
365
+ props: { handlers: {
366
+ type: Object,
367
+ default: () => defaultHandlers
368
+ } },
369
+ setup({ handlers: handlers$1 }, { slots }) {
370
+ const lastActive = computed({
371
+ get: () => localStorage.getItem("context-storage-last-active") || "main",
372
+ set: (value) => localStorage.setItem("context-storage-last-active", value)
373
+ });
374
+ const router = useRouter();
375
+ const initialNavigatorState = /* @__PURE__ */ new Map();
376
+ const initialNavigatorStateResolvers = /* @__PURE__ */ new Map();
377
+ handlers$1.forEach((handler) => {
378
+ if (!handler.getInitialStateResolver) return;
379
+ initialNavigatorStateResolvers.set(handler, handler.getInitialStateResolver());
380
+ });
381
+ router.isReady().then(() => {
382
+ initialNavigatorStateResolvers.forEach((resolver, handler) => {
383
+ initialNavigatorState.set(handler, resolver());
384
+ });
385
+ activateLastActiveItem();
386
+ });
387
+ const collection$1 = new ContextStorageCollection(handlers$1);
388
+ collection$1.onActiveChange((item) => {
389
+ lastActive.value = item.key;
390
+ });
391
+ provide(contextStorageCollectionInjectKey, collection$1);
392
+ const activateInitialItem = (item) => {
393
+ item.handlers.forEach((handler) => {
394
+ const state = initialNavigatorState.get(handler.constructor);
395
+ if (!state) return;
396
+ handler.setInitialState?.(state);
397
+ });
398
+ collection$1.setActive(item);
399
+ };
400
+ const activateLastActiveItem = () => {
401
+ const lastActiveItem = collection$1.findItemByKey(lastActive.value);
402
+ if (lastActiveItem) {
403
+ activateInitialItem(lastActiveItem);
404
+ return;
405
+ }
406
+ const firstItem = collection$1.first();
407
+ if (!firstItem) throw new Error("[ContextStorage] Cannot find first item in collection");
408
+ activateInitialItem(firstItem);
409
+ };
410
+ return () => {
411
+ return slots.default?.();
412
+ };
413
+ }
414
+ });
415
+
416
+ //#endregion
417
+ //#region src/components/ContextStorageCollection.vue
418
+ var ContextStorageCollection_default = ContextStorageCollection_vue_vue_type_script_lang_default;
419
+
420
+ //#endregion
421
+ //#region src/components/ContextStorageProvider.vue?vue&type=script&lang.ts
422
+ var ContextStorageProvider_vue_vue_type_script_lang_default = defineComponent({
423
+ props: { itemKey: {
424
+ type: String,
425
+ required: true
426
+ } },
427
+ setup(props, { slots }) {
428
+ const collection$1 = inject(contextStorageCollectionInjectKey);
429
+ if (!collection$1) throw new Error("[ContextStorage] Context storage collection not found");
430
+ const item = collection$1.add({ key: props.itemKey });
431
+ provide(contextStorageCollectionItemInjectKey, item);
432
+ provide(contextStorageHandlersInjectKey, item.handlers);
433
+ item.handlers.forEach((handler) => {
434
+ provide(handler.getInjectionKey(), handler);
435
+ });
436
+ onUnmounted(() => {
437
+ collection$1.remove(item);
438
+ });
439
+ return () => slots.default?.();
440
+ }
441
+ });
442
+
443
+ //#endregion
444
+ //#region src/components/ContextStorageProvider.vue
445
+ var ContextStorageProvider_default = ContextStorageProvider_vue_vue_type_script_lang_default;
446
+
447
+ //#endregion
448
+ //#region src/components/ContextStorage.vue?vue&type=script&setup=true&lang.ts
449
+ var ContextStorage_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
450
+ __name: "ContextStorage",
451
+ props: { handlers: {
452
+ type: Array,
453
+ required: true,
454
+ default: () => defaultHandlers
455
+ } },
456
+ setup(__props) {
457
+ return (_ctx, _cache) => {
458
+ return openBlock(), createBlock(ContextStorageCollection_default, { handlers: __props.handlers }, {
459
+ default: withCtx(() => [createVNode(ContextStorageProvider_default, { "item-key": "main" }, {
460
+ default: withCtx(() => [createVNode(ContextStorageActivator_default, null, {
461
+ default: withCtx(() => [renderSlot(_ctx.$slots, "default")]),
462
+ _: 3
463
+ })]),
464
+ _: 3
465
+ })]),
466
+ _: 3
467
+ }, 8, ["handlers"]);
468
+ };
469
+ }
470
+ });
471
+
472
+ //#endregion
473
+ //#region src/components/ContextStorage.vue
474
+ var ContextStorage_default = ContextStorage_vue_vue_type_script_setup_true_lang_default;
475
+
293
476
  //#endregion
294
477
  //#region src/handlers/query/transform-helpers.ts
295
478
  function asNumber(value, options) {
296
479
  const { nullable = false, missable = false, fallbackValue = missable ? void 0 : nullable ? null : 0 } = options || {};
297
480
  if (value === null && nullable) return null;
298
- if (value === void 0 && missable) return void 0;
481
+ if (value === void 0 && missable) return;
299
482
  value = Number(value);
300
483
  return isNaN(value) ? fallbackValue : value;
301
484
  }
302
485
  function asString(value, options) {
303
486
  const { nullable = false, missable = false, fallbackValue = missable ? void 0 : nullable ? null : "", allowedValues } = options || {};
304
487
  if (value === null && nullable) return null;
305
- if (value === void 0 && missable) return void 0;
488
+ if (value === void 0 && missable) return;
306
489
  const stringValue = value ?? fallbackValue;
307
490
  if (allowedValues && typeof stringValue === "string" && !allowedValues.includes(stringValue)) return fallbackValue;
308
491
  return stringValue;
@@ -324,7 +507,7 @@ function asNumberArray(value, options) {
324
507
  function asArray(value, options) {
325
508
  const { nullable = false, missable = false, transform: transform$1 } = options || {};
326
509
  if (value === null && nullable) return null;
327
- if (value === void 0 && missable) return void 0;
510
+ if (value === void 0 && missable) return;
328
511
  if (value === void 0) return nullable ? null : [];
329
512
  let arrayValue;
330
513
  if (Array.isArray(value)) arrayValue = value;
@@ -335,7 +518,7 @@ function asArray(value, options) {
335
518
  function asBoolean(value, options) {
336
519
  const { nullable = false, missable = false, fallbackValue = missable ? void 0 : nullable ? null : false } = options || {};
337
520
  if (value === null && nullable) return null;
338
- if (value === void 0 && missable) return void 0;
521
+ if (value === void 0 && missable) return;
339
522
  if (value === void 0 || value === null) return fallbackValue;
340
523
  if (typeof value === "string") {
341
524
  const lowerValue = value.toLowerCase();
@@ -353,16 +536,4 @@ const transform = {
353
536
  };
354
537
 
355
538
  //#endregion
356
- //#region src/injectionSymbols.ts
357
- const contextStorageCollectionInjectKey = collection;
358
- const contextStorageCollectionItemInjectKey = collectionItem;
359
- const contextStorageHandlersInjectKey = handlers;
360
- const contextStorageQueryHandlerInjectKey = contextStorageQueryHandler;
361
-
362
- //#endregion
363
- //#region src/constants.ts
364
- const defaultHandlers = [ContextStorageQueryHandler];
365
-
366
- //#endregion
367
- export { ContextStorageQueryHandler, asArray, asBoolean, asNumber, asNumberArray, asString, collection, collectionItem, contextStorageCollectionInjectKey, contextStorageCollectionItemInjectKey, contextStorageHandlersInjectKey, contextStorageQueryHandler, contextStorageQueryHandlerInjectKey, defaultHandlers, deserializeParams, handlers, serializeParams, transform, useContextStorageQueryHandler };
368
- //# sourceMappingURL=index.js.map
539
+ export { ContextStorage_default as ContextStorage, ContextStorageActivator_default as ContextStorageActivator, ContextStorageCollection_default as ContextStorageCollection, ContextStorageProvider_default as ContextStorageProvider, ContextStorageQueryHandler, asArray, asBoolean, asNumber, asNumberArray, asString, collection, collectionItem, contextStorageCollectionInjectKey, contextStorageCollectionItemInjectKey, contextStorageHandlersInjectKey, contextStorageQueryHandler, contextStorageQueryHandlerInjectKey, defaultHandlers, deserializeParams, handlers, serializeParams, transform, useContextStorageQueryHandler };