vue-context-storage 0.1.9 → 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 (39) hide show
  1. package/dist/index.d.ts +411 -14
  2. package/dist/index.js +84 -71
  3. package/package.json +73 -83
  4. package/dist/collection.d.cts +0 -22
  5. package/dist/collection.d.ts +0 -22
  6. package/dist/handlers/query/helpers.d.cts +0 -45
  7. package/dist/handlers/query/helpers.d.ts +0 -45
  8. package/dist/handlers/query/index.d.cts +0 -31
  9. package/dist/handlers/query/index.d.ts +0 -31
  10. package/dist/handlers/query/transform-helpers.d.cts +0 -123
  11. package/dist/handlers/query/transform-helpers.d.ts +0 -123
  12. package/dist/handlers/query/types.d.cts +0 -103
  13. package/dist/handlers/query/types.d.ts +0 -103
  14. package/dist/handlers.d.cts +0 -15
  15. package/dist/handlers.d.ts +0 -15
  16. package/dist/index.cjs +0 -571
  17. package/dist/index.cjs.map +0 -1
  18. package/dist/index.d.cts +0 -14
  19. package/dist/index.js.map +0 -1
  20. package/dist/injectionSymbols.d.cts +0 -7
  21. package/dist/injectionSymbols.d.ts +0 -7
  22. package/dist/symbols.d.cts +0 -4
  23. package/dist/symbols.d.ts +0 -4
  24. package/src/collection.ts +0 -71
  25. package/src/components/ContextStorage.vue +0 -23
  26. package/src/components/ContextStorageActivator.vue +0 -20
  27. package/src/components/ContextStorageCollection.vue +0 -92
  28. package/src/components/ContextStorageProvider.vue +0 -38
  29. package/src/components.ts +0 -5
  30. package/src/handlers/query/helpers.ts +0 -134
  31. package/src/handlers/query/index.ts +0 -355
  32. package/src/handlers/query/transform-helpers.ts +0 -309
  33. package/src/handlers/query/types.ts +0 -125
  34. package/src/handlers.ts +0 -18
  35. package/src/index.ts +0 -44
  36. package/src/injectionSymbols.ts +0 -15
  37. package/src/plugin.ts +0 -16
  38. package/src/shims-vue.d.ts +0 -5
  39. package/src/symbols.ts +0 -4
package/dist/index.d.ts CHANGED
@@ -1,14 +1,411 @@
1
- import type { ContextStorageHandlerConstructor } from './handlers';
2
- export { default as ContextStorageActivator } from './components/ContextStorageActivator.vue';
3
- export { default as ContextStorageCollection } from './components/ContextStorageCollection.vue';
4
- export { default as ContextStorageProvider } from './components/ContextStorageProvider.vue';
5
- export { default as ContextStorage } from './components/ContextStorage.vue';
6
- export type { ContextStorageHandler, ContextStorageHandlerConstructor, RegisterBaseOptions, } from './handlers';
7
- export { ContextStorageQueryHandler, useContextStorageQueryHandler } from './handlers/query';
8
- export { deserializeParams, serializeParams } from './handlers/query/helpers.ts';
9
- export type { SerializeOptions } from './handlers/query/helpers.ts';
10
- export { asArray, asBoolean, asNumber, asNumberArray, asString, transform, } from './handlers/query/transform-helpers.ts';
11
- export { contextStorageCollectionInjectKey, contextStorageCollectionItemInjectKey, contextStorageHandlersInjectKey, contextStorageQueryHandlerInjectKey, } from './injectionSymbols';
12
- export { collection, collectionItem, contextStorageQueryHandler, handlers } from './symbols';
13
- export declare const defaultHandlers: ContextStorageHandlerConstructor[];
14
- export type { QueryValue, IContextStorageQueryHandler } from './handlers/query/types';
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";
2
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,
@@ -298,8 +341,8 @@ const contextStorageHandlersInjectKey = handlers;
298
341
  const contextStorageQueryHandlerInjectKey = contextStorageQueryHandler;
299
342
 
300
343
  //#endregion
301
- //#region src/components/ContextStorageActivator.vue
302
- const _sfc_main$3 = defineComponent({ setup(_, { slots }) {
344
+ //#region src/components/ContextStorageActivator.vue?vue&type=script&lang.ts
345
+ var ContextStorageActivator_vue_vue_type_script_lang_default = defineComponent({ setup(_, { slots }) {
303
346
  const collection$1 = inject(contextStorageCollectionInjectKey);
304
347
  const item = inject(contextStorageCollectionItemInjectKey);
305
348
  const onActivate = () => {
@@ -307,59 +350,21 @@ const _sfc_main$3 = defineComponent({ setup(_, { slots }) {
307
350
  };
308
351
  return () => h("div", { onMousedown: onActivate }, slots.default?.());
309
352
  } });
310
- var ContextStorageActivator_default = _sfc_main$3;
311
353
 
312
354
  //#endregion
313
- //#region src/collection.ts
314
- var ContextStorageCollection = class {
315
- active = void 0;
316
- collection = [];
317
- onActiveChangeCallbacks = [];
318
- constructor(handlerConstructors) {
319
- this.handlerConstructors = handlerConstructors;
320
- }
321
- onActiveChange(callback) {
322
- this.onActiveChangeCallbacks.push(callback);
323
- }
324
- first() {
325
- return this.collection[0];
326
- }
327
- findItemByKey(key) {
328
- return this.collection.find((item) => item.key === key);
329
- }
330
- add(options) {
331
- const handlers$1 = this.handlerConstructors.map((constructor) => new constructor());
332
- const item = {
333
- handlers: handlers$1,
334
- key: options.key
335
- };
336
- this.collection.push(item);
337
- return item;
338
- }
339
- remove(removeItem) {
340
- if (this.collection.indexOf(removeItem) === -1) throw new Error("[ContextStorage] Item not found in collection");
341
- this.collection = this.collection.filter((item) => item !== removeItem);
342
- if (this.active === removeItem && this.collection.length > 0) this.setActive(this.collection[this.collection.length - 1]);
343
- }
344
- setActive(activeItem) {
345
- if (this.active === activeItem) return;
346
- const hasActiveBefore = this.active !== void 0;
347
- this.active = activeItem;
348
- this.collection.forEach((item) => {
349
- Object.values(item.handlers).forEach((handler) => {
350
- if (handler.setEnabled) handler.setEnabled(item === activeItem, !hasActiveBefore);
351
- });
352
- });
353
- this.onActiveChangeCallbacks.forEach((callback) => callback(activeItem));
354
- }
355
- };
355
+ //#region src/components/ContextStorageActivator.vue
356
+ var ContextStorageActivator_default = ContextStorageActivator_vue_vue_type_script_lang_default;
356
357
 
357
358
  //#endregion
358
- //#region src/components/ContextStorageCollection.vue
359
- const _sfc_main$2 = defineComponent({
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({
360
365
  props: { handlers: {
361
366
  type: Object,
362
- default: defaultHandlers
367
+ default: () => defaultHandlers
363
368
  } },
364
369
  setup({ handlers: handlers$1 }, { slots }) {
365
370
  const lastActive = computed({
@@ -407,11 +412,14 @@ const _sfc_main$2 = defineComponent({
407
412
  };
408
413
  }
409
414
  });
410
- var ContextStorageCollection_default = _sfc_main$2;
411
415
 
412
416
  //#endregion
413
- //#region src/components/ContextStorageProvider.vue
414
- const _sfc_main$1 = defineComponent({
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({
415
423
  props: { itemKey: {
416
424
  type: String,
417
425
  required: true
@@ -431,13 +439,20 @@ const _sfc_main$1 = defineComponent({
431
439
  return () => slots.default?.();
432
440
  }
433
441
  });
434
- var ContextStorageProvider_default = _sfc_main$1;
435
442
 
436
443
  //#endregion
437
- //#region src/components/ContextStorage.vue
438
- const _sfc_main = /* @__PURE__ */ defineComponent({
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({
439
450
  __name: "ContextStorage",
440
- props: { handlers: { default: () => defaultHandlers } },
451
+ props: { handlers: {
452
+ type: Array,
453
+ required: true,
454
+ default: () => defaultHandlers
455
+ } },
441
456
  setup(__props) {
442
457
  return (_ctx, _cache) => {
443
458
  return openBlock(), createBlock(ContextStorageCollection_default, { handlers: __props.handlers }, {
@@ -453,21 +468,24 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
453
468
  };
454
469
  }
455
470
  });
456
- var ContextStorage_default = _sfc_main;
471
+
472
+ //#endregion
473
+ //#region src/components/ContextStorage.vue
474
+ var ContextStorage_default = ContextStorage_vue_vue_type_script_setup_true_lang_default;
457
475
 
458
476
  //#endregion
459
477
  //#region src/handlers/query/transform-helpers.ts
460
478
  function asNumber(value, options) {
461
479
  const { nullable = false, missable = false, fallbackValue = missable ? void 0 : nullable ? null : 0 } = options || {};
462
480
  if (value === null && nullable) return null;
463
- if (value === void 0 && missable) return void 0;
481
+ if (value === void 0 && missable) return;
464
482
  value = Number(value);
465
483
  return isNaN(value) ? fallbackValue : value;
466
484
  }
467
485
  function asString(value, options) {
468
486
  const { nullable = false, missable = false, fallbackValue = missable ? void 0 : nullable ? null : "", allowedValues } = options || {};
469
487
  if (value === null && nullable) return null;
470
- if (value === void 0 && missable) return void 0;
488
+ if (value === void 0 && missable) return;
471
489
  const stringValue = value ?? fallbackValue;
472
490
  if (allowedValues && typeof stringValue === "string" && !allowedValues.includes(stringValue)) return fallbackValue;
473
491
  return stringValue;
@@ -489,7 +507,7 @@ function asNumberArray(value, options) {
489
507
  function asArray(value, options) {
490
508
  const { nullable = false, missable = false, transform: transform$1 } = options || {};
491
509
  if (value === null && nullable) return null;
492
- if (value === void 0 && missable) return void 0;
510
+ if (value === void 0 && missable) return;
493
511
  if (value === void 0) return nullable ? null : [];
494
512
  let arrayValue;
495
513
  if (Array.isArray(value)) arrayValue = value;
@@ -500,7 +518,7 @@ function asArray(value, options) {
500
518
  function asBoolean(value, options) {
501
519
  const { nullable = false, missable = false, fallbackValue = missable ? void 0 : nullable ? null : false } = options || {};
502
520
  if (value === null && nullable) return null;
503
- if (value === void 0 && missable) return void 0;
521
+ if (value === void 0 && missable) return;
504
522
  if (value === void 0 || value === null) return fallbackValue;
505
523
  if (typeof value === "string") {
506
524
  const lowerValue = value.toLowerCase();
@@ -518,9 +536,4 @@ const transform = {
518
536
  };
519
537
 
520
538
  //#endregion
521
- //#region src/index.ts
522
- const defaultHandlers = [ContextStorageQueryHandler];
523
-
524
- //#endregion
525
- 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 };
526
- //# 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 };