vue-context-storage 0.1.9 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +414 -14
- package/dist/index.js +93 -71
- package/package.json +73 -83
- package/dist/collection.d.cts +0 -22
- package/dist/collection.d.ts +0 -22
- package/dist/handlers/query/helpers.d.cts +0 -45
- package/dist/handlers/query/helpers.d.ts +0 -45
- package/dist/handlers/query/index.d.cts +0 -31
- package/dist/handlers/query/index.d.ts +0 -31
- package/dist/handlers/query/transform-helpers.d.cts +0 -123
- package/dist/handlers/query/transform-helpers.d.ts +0 -123
- package/dist/handlers/query/types.d.cts +0 -103
- package/dist/handlers/query/types.d.ts +0 -103
- package/dist/handlers.d.cts +0 -15
- package/dist/handlers.d.ts +0 -15
- package/dist/index.cjs +0 -571
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -14
- package/dist/index.js.map +0 -1
- package/dist/injectionSymbols.d.cts +0 -7
- package/dist/injectionSymbols.d.ts +0 -7
- package/dist/symbols.d.cts +0 -4
- package/dist/symbols.d.ts +0 -4
- package/src/collection.ts +0 -71
- package/src/components/ContextStorage.vue +0 -23
- package/src/components/ContextStorageActivator.vue +0 -20
- package/src/components/ContextStorageCollection.vue +0 -92
- package/src/components/ContextStorageProvider.vue +0 -38
- package/src/components.ts +0 -5
- package/src/handlers/query/helpers.ts +0 -134
- package/src/handlers/query/index.ts +0 -355
- package/src/handlers/query/transform-helpers.ts +0 -309
- package/src/handlers/query/types.ts +0 -125
- package/src/handlers.ts +0 -18
- package/src/index.ts +0 -44
- package/src/injectionSymbols.ts +0 -15
- package/src/plugin.ts +0 -16
- package/src/shims-vue.d.ts +0 -5
- package/src/symbols.ts +0 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,414 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import * as vue0 from "vue";
|
|
2
|
+
import { InjectionKey, MaybeRefOrGetter, Plugin, 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/plugin.d.ts
|
|
79
|
+
declare const VueContextStoragePlugin: Plugin;
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/symbols.d.ts
|
|
82
|
+
declare const collection: unique symbol;
|
|
83
|
+
declare const collectionItem: unique symbol;
|
|
84
|
+
declare const handlers: unique symbol;
|
|
85
|
+
declare const contextStorageQueryHandler: unique symbol;
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/handlers/query/types.d.ts
|
|
88
|
+
type QueryValue = LocationQueryValue | LocationQueryValue[];
|
|
89
|
+
type DeepTransformValuesToLocationQueryValue<T> = { [K in keyof T]?: T[K] extends object ? T[K] extends Array<any> ? QueryValue : DeepTransformValuesToLocationQueryValue<T[K]> : QueryValue };
|
|
90
|
+
interface QueryHandlerSharedOptions {
|
|
91
|
+
/**
|
|
92
|
+
* Default: false
|
|
93
|
+
*
|
|
94
|
+
* If enabled - empty state will be preserved in query.
|
|
95
|
+
*
|
|
96
|
+
* Useful, when you have default values, and want to preserve empty state in query.
|
|
97
|
+
* @example
|
|
98
|
+
* ```
|
|
99
|
+
* Options: {preserveEmptyState: true, prefix: 'filters'}
|
|
100
|
+
*
|
|
101
|
+
* When filters are empty we will get this in query string:
|
|
102
|
+
*
|
|
103
|
+
* /list?filters
|
|
104
|
+
*
|
|
105
|
+
* After page reload state will be not restored to default
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```
|
|
110
|
+
* Options: {preserveEmptyState: false, prefix: 'filters'}
|
|
111
|
+
*
|
|
112
|
+
* When filters are empty we will get this in query string:
|
|
113
|
+
*
|
|
114
|
+
* /list
|
|
115
|
+
*
|
|
116
|
+
* After page reload state will be restored to default
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```
|
|
121
|
+
* Options: {preserveEmptyState: true}
|
|
122
|
+
*
|
|
123
|
+
* When filters are empty we will get this in query string:
|
|
124
|
+
*
|
|
125
|
+
* /list?_
|
|
126
|
+
*
|
|
127
|
+
* After page reload state will be not restored to default.
|
|
128
|
+
* Underscore (_) is default value for emptyPlaceholder option
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
preserveEmptyState?: boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Default: true
|
|
134
|
+
*
|
|
135
|
+
* If transform option is not passed, ref will be merged with query only by keys that exists in ref.
|
|
136
|
+
*/
|
|
137
|
+
mergeOnlyExistingKeysWithoutTransform?: boolean;
|
|
138
|
+
}
|
|
139
|
+
interface QueryHandlerBaseOptions extends QueryHandlerSharedOptions {
|
|
140
|
+
/**
|
|
141
|
+
* Default: replace
|
|
142
|
+
*
|
|
143
|
+
* Vue-router navigate mode.
|
|
144
|
+
* Use push if you want to add new query to history.
|
|
145
|
+
* Use replace if you want to replace current query without adding to history.
|
|
146
|
+
*/
|
|
147
|
+
mode?: 'replace' | 'push';
|
|
148
|
+
/**
|
|
149
|
+
* Default: _
|
|
150
|
+
*
|
|
151
|
+
* Placeholder for empty state, used when preserveEmptyState is true and all ref values are empty.
|
|
152
|
+
*/
|
|
153
|
+
emptyPlaceholder?: string;
|
|
154
|
+
/**
|
|
155
|
+
* Default: false
|
|
156
|
+
*
|
|
157
|
+
* If enabled - unused keys will be preserved in query.
|
|
158
|
+
* Unused keys are keys, that are not exists in ref.
|
|
159
|
+
*/
|
|
160
|
+
preserveUnusedKeys?: boolean;
|
|
161
|
+
}
|
|
162
|
+
interface RegisterQueryHandlerBaseOptions<T> extends QueryHandlerSharedOptions {
|
|
163
|
+
/**
|
|
164
|
+
* Prefix in query string.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```
|
|
168
|
+
* filters, table-1[filters], table-2[filters]
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
prefix?: string;
|
|
172
|
+
transform?: (deserialized: DeepTransformValuesToLocationQueryValue<UnwrapNestedRefs<T>>, initialData: T) => UnwrapNestedRefs<T>;
|
|
173
|
+
}
|
|
174
|
+
interface RegisterQueryHandlerOptions<T> extends RegisterBaseOptions, RegisterQueryHandlerBaseOptions<T> {}
|
|
175
|
+
interface IContextStorageQueryHandler extends ContextStorageHandler {
|
|
176
|
+
register: <T extends Record<string, unknown>>(data: MaybeRefOrGetter<T>, options: RegisterQueryHandlerOptions<T>) => () => void;
|
|
177
|
+
}
|
|
178
|
+
interface ContextStorageQueryRegisteredItem<T extends Record<string, unknown>> {
|
|
179
|
+
data: MaybeRefOrGetter<T>;
|
|
180
|
+
initialData: T;
|
|
181
|
+
options: RegisterQueryHandlerOptions<T>;
|
|
182
|
+
watchHandle: WatchHandle;
|
|
183
|
+
}
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region src/handlers/query/index.d.ts
|
|
186
|
+
declare function useContextStorageQueryHandler<T extends Record<string, unknown>>(data: MaybeRefOrGetter<T>, options?: RegisterQueryHandlerBaseOptions<T>): void;
|
|
187
|
+
declare class ContextStorageQueryHandler implements IContextStorageQueryHandler {
|
|
188
|
+
#private;
|
|
189
|
+
private enabled;
|
|
190
|
+
private registered;
|
|
191
|
+
private currentQuery;
|
|
192
|
+
private readonly route;
|
|
193
|
+
private router;
|
|
194
|
+
private initialState?;
|
|
195
|
+
private hasAnyRegistered;
|
|
196
|
+
private preventSyncRegisteredToQueryByAfterEachRoute;
|
|
197
|
+
private preventAfterEachRouteCallsWhileCallingRouter;
|
|
198
|
+
static customQueryHandlerOptions: QueryHandlerBaseOptions;
|
|
199
|
+
private readonly options;
|
|
200
|
+
static configure(options: QueryHandlerBaseOptions): ContextStorageHandlerConstructor;
|
|
201
|
+
constructor();
|
|
202
|
+
getInjectionKey(): typeof contextStorageQueryHandler;
|
|
203
|
+
setInitialState(state: Record<string, unknown> | undefined): void;
|
|
204
|
+
static getInitialStateResolver(): () => LocationQuery;
|
|
205
|
+
setEnabled(state: boolean, initial: boolean): void;
|
|
206
|
+
syncRegisteredToQuery(): Promise<void>;
|
|
207
|
+
afterEachRoute(): void;
|
|
208
|
+
syncInitialStateToRegisteredItem<T extends Record<string, unknown>>(item: ContextStorageQueryRegisteredItem<T>): void;
|
|
209
|
+
syncInitialStateToRegistered(): void;
|
|
210
|
+
register<T extends Record<string, unknown>>(data: MaybeRefOrGetter<T>, options: RegisterQueryHandlerOptions<T>): () => void;
|
|
211
|
+
}
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region src/handlers/query/helpers.d.ts
|
|
214
|
+
interface SerializeOptions {
|
|
215
|
+
/**
|
|
216
|
+
* Custom prefix for serialized keys.
|
|
217
|
+
* @example
|
|
218
|
+
* - prefix: 'filters' => 'filters[key]'
|
|
219
|
+
* - prefix: 'search' => 'search[key]'
|
|
220
|
+
* - prefix: '' => 'key' (no prefix)
|
|
221
|
+
*/
|
|
222
|
+
prefix?: string;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Serializes filter parameters into a URL-friendly format.
|
|
226
|
+
*
|
|
227
|
+
* @param params - Raw parameters object to serialize
|
|
228
|
+
* @param options - Serialization options
|
|
229
|
+
* @returns Serialized parameters with prefixed keys
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* // With default prefix 'filters'
|
|
233
|
+
* serializeFiltersParams({ status: 'active', tags: ['a', 'b'] })
|
|
234
|
+
* // => { 'filters[status]': 'active', 'filters[tags]': 'a,b' }
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* // With custom prefix
|
|
238
|
+
* serializeFiltersParams({ name: 'John', all: true }, { prefix: 'search' })
|
|
239
|
+
* // => { 'search[name]': 'John', 'search[all]': '1' }
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* // Without prefix
|
|
243
|
+
* serializeFiltersParams({ page: 1, all: false }, { prefix: '' })
|
|
244
|
+
* // => { 'page': '1', 'all': '0' }
|
|
245
|
+
*/
|
|
246
|
+
declare function serializeParams(params: Record<string, unknown>, options?: SerializeOptions): LocationQuery;
|
|
247
|
+
/**
|
|
248
|
+
* Deserializes query parameters from a URL-friendly format back to an object.
|
|
249
|
+
*
|
|
250
|
+
* @param params - Serialized parameters object
|
|
251
|
+
* @returns Deserialized parameters object
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* deserializeParams({ 'filters[status]': 'active', search: 'test' })
|
|
255
|
+
* // => { filters: {status: 'active'}, search: 'test' }
|
|
256
|
+
*/
|
|
257
|
+
declare function deserializeParams(params: Record<string, any>): Record<string, any>;
|
|
258
|
+
//#endregion
|
|
259
|
+
//#region src/handlers/query/transform-helpers.d.ts
|
|
260
|
+
declare function asNumber(value: QueryValue | number | undefined): number;
|
|
261
|
+
declare function asNumber(value: QueryValue | number | undefined, options: {
|
|
262
|
+
nullable: true;
|
|
263
|
+
missable: true;
|
|
264
|
+
fallbackValue?: number;
|
|
265
|
+
}): number | null | undefined;
|
|
266
|
+
declare function asNumber(value: QueryValue | number | undefined, options: {
|
|
267
|
+
nullable: true;
|
|
268
|
+
missable?: false;
|
|
269
|
+
fallbackValue?: number;
|
|
270
|
+
}): number | null;
|
|
271
|
+
declare function asNumber(value: QueryValue | number | undefined, options: {
|
|
272
|
+
nullable?: false;
|
|
273
|
+
missable: true;
|
|
274
|
+
fallbackValue?: number;
|
|
275
|
+
}): number | undefined;
|
|
276
|
+
declare function asNumber(value: QueryValue | number | undefined, options: {
|
|
277
|
+
nullable?: false;
|
|
278
|
+
missable?: false;
|
|
279
|
+
fallbackValue?: number;
|
|
280
|
+
}): number;
|
|
281
|
+
declare function asString(value: QueryValue | undefined): string;
|
|
282
|
+
declare function asString<T extends readonly string[]>(value: QueryValue | undefined, options: {
|
|
283
|
+
nullable: true;
|
|
284
|
+
missable: true;
|
|
285
|
+
fallbackValue?: T[number];
|
|
286
|
+
allowedValues: T;
|
|
287
|
+
}): T[number] | null | undefined;
|
|
288
|
+
declare function asString<T extends readonly string[]>(value: QueryValue | undefined, options: {
|
|
289
|
+
nullable: true;
|
|
290
|
+
missable?: false;
|
|
291
|
+
fallbackValue?: T[number];
|
|
292
|
+
allowedValues: T;
|
|
293
|
+
}): T[number] | null;
|
|
294
|
+
declare function asString<T extends readonly string[]>(value: QueryValue | undefined, options: {
|
|
295
|
+
nullable?: false;
|
|
296
|
+
missable: true;
|
|
297
|
+
fallbackValue?: T[number];
|
|
298
|
+
allowedValues: T;
|
|
299
|
+
}): T[number] | undefined;
|
|
300
|
+
declare function asString<T extends readonly string[]>(value: QueryValue | undefined, options: {
|
|
301
|
+
nullable?: false;
|
|
302
|
+
missable?: false;
|
|
303
|
+
fallbackValue?: T[number];
|
|
304
|
+
allowedValues: T;
|
|
305
|
+
}): T[number];
|
|
306
|
+
declare function asString(value: QueryValue | undefined, options: {
|
|
307
|
+
nullable: true;
|
|
308
|
+
missable: true;
|
|
309
|
+
fallbackValue?: string;
|
|
310
|
+
}): string | null | undefined;
|
|
311
|
+
declare function asString(value: QueryValue | undefined, options: {
|
|
312
|
+
nullable: true;
|
|
313
|
+
missable?: false;
|
|
314
|
+
fallbackValue?: string;
|
|
315
|
+
}): string | null;
|
|
316
|
+
declare function asString(value: QueryValue | undefined, options: {
|
|
317
|
+
nullable?: false;
|
|
318
|
+
missable: true;
|
|
319
|
+
fallbackValue?: string;
|
|
320
|
+
}): string | undefined;
|
|
321
|
+
declare function asString(value: QueryValue | undefined, options: {
|
|
322
|
+
nullable?: false;
|
|
323
|
+
missable?: false;
|
|
324
|
+
fallbackValue?: string;
|
|
325
|
+
}): string;
|
|
326
|
+
declare function asNumberArray(value: QueryValue | undefined): number[];
|
|
327
|
+
declare function asNumberArray(value: QueryValue | undefined, options: {
|
|
328
|
+
nullable: true;
|
|
329
|
+
}): number[] | null;
|
|
330
|
+
declare function asNumberArray(value: QueryValue | undefined, options: {
|
|
331
|
+
nullable?: false;
|
|
332
|
+
}): number[];
|
|
333
|
+
declare function asArray<T>(value: QueryValue | undefined): T[];
|
|
334
|
+
declare function asArray<T>(value: QueryValue | undefined, options: {
|
|
335
|
+
nullable: true;
|
|
336
|
+
missable: true;
|
|
337
|
+
transform?: (value: QueryValue) => T;
|
|
338
|
+
}): T[] | null | undefined;
|
|
339
|
+
declare function asArray<T>(value: QueryValue | undefined, options: {
|
|
340
|
+
nullable: true;
|
|
341
|
+
missable?: false;
|
|
342
|
+
transform?: (value: QueryValue) => T;
|
|
343
|
+
}): T[] | null;
|
|
344
|
+
declare function asArray<T>(value: QueryValue | undefined, options: {
|
|
345
|
+
nullable?: false;
|
|
346
|
+
missable: true;
|
|
347
|
+
transform?: (value: QueryValue) => T;
|
|
348
|
+
}): T[] | undefined;
|
|
349
|
+
declare function asArray<T>(value: QueryValue | undefined, options: {
|
|
350
|
+
nullable?: false;
|
|
351
|
+
missable?: false;
|
|
352
|
+
transform?: (value: QueryValue) => T;
|
|
353
|
+
}): T[];
|
|
354
|
+
declare function asBoolean(value: QueryValue | undefined): boolean;
|
|
355
|
+
declare function asBoolean(value: QueryValue | undefined, options: {
|
|
356
|
+
nullable: true;
|
|
357
|
+
missable: true;
|
|
358
|
+
fallbackValue?: boolean;
|
|
359
|
+
}): boolean | null | undefined;
|
|
360
|
+
declare function asBoolean(value: QueryValue | undefined, options: {
|
|
361
|
+
nullable: true;
|
|
362
|
+
missable?: false;
|
|
363
|
+
fallbackValue?: boolean;
|
|
364
|
+
}): boolean | null;
|
|
365
|
+
declare function asBoolean(value: QueryValue | undefined, options: {
|
|
366
|
+
nullable?: false;
|
|
367
|
+
missable: true;
|
|
368
|
+
fallbackValue?: boolean;
|
|
369
|
+
}): boolean | undefined;
|
|
370
|
+
declare function asBoolean(value: QueryValue | undefined, options: {
|
|
371
|
+
nullable?: false;
|
|
372
|
+
missable?: false;
|
|
373
|
+
fallbackValue?: boolean;
|
|
374
|
+
}): boolean;
|
|
375
|
+
declare const transform: {
|
|
376
|
+
asString: typeof asString;
|
|
377
|
+
asNumber: typeof asNumber;
|
|
378
|
+
asArray: typeof asArray;
|
|
379
|
+
asNumberArray: typeof asNumberArray;
|
|
380
|
+
asBoolean: typeof asBoolean;
|
|
381
|
+
};
|
|
382
|
+
//#endregion
|
|
383
|
+
//#region src/collection.d.ts
|
|
384
|
+
type ContextStorageCollectionItem = {
|
|
385
|
+
key: string;
|
|
386
|
+
handlers: ContextStorageHandler[];
|
|
387
|
+
};
|
|
388
|
+
interface ItemOptions {
|
|
389
|
+
key: string;
|
|
390
|
+
}
|
|
391
|
+
declare class ContextStorageCollection {
|
|
392
|
+
private handlerConstructors;
|
|
393
|
+
active?: ContextStorageCollectionItem;
|
|
394
|
+
private collection;
|
|
395
|
+
private onActiveChangeCallbacks;
|
|
396
|
+
constructor(handlerConstructors: ContextStorageHandlerConstructor[]);
|
|
397
|
+
onActiveChange(callback: (item: ContextStorageCollectionItem) => void): void;
|
|
398
|
+
first(): ContextStorageCollectionItem | undefined;
|
|
399
|
+
findItemByKey(key: string): ContextStorageCollectionItem | undefined;
|
|
400
|
+
add(options: ItemOptions): ContextStorageCollectionItem;
|
|
401
|
+
remove(removeItem: ContextStorageCollectionItem): void;
|
|
402
|
+
setActive(activeItem: ContextStorageCollectionItem): void;
|
|
403
|
+
}
|
|
404
|
+
//#endregion
|
|
405
|
+
//#region src/injectionSymbols.d.ts
|
|
406
|
+
declare const contextStorageCollectionInjectKey: InjectionKey<ContextStorageCollection>;
|
|
407
|
+
declare const contextStorageCollectionItemInjectKey: InjectionKey<ContextStorageCollectionItem>;
|
|
408
|
+
declare const contextStorageHandlersInjectKey: InjectionKey<ContextStorageCollectionItem['handlers']>;
|
|
409
|
+
declare const contextStorageQueryHandlerInjectKey: InjectionKey<InstanceType<typeof ContextStorageQueryHandler>>;
|
|
410
|
+
//#endregion
|
|
411
|
+
//#region src/constants.d.ts
|
|
412
|
+
declare const defaultHandlers: ContextStorageHandlerConstructor[];
|
|
413
|
+
//#endregion
|
|
414
|
+
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, VueContextStoragePlugin, 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
|
|
91
|
-
const
|
|
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
|
-
|
|
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/
|
|
314
|
-
var
|
|
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/
|
|
359
|
-
const
|
|
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/
|
|
414
|
-
|
|
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/
|
|
438
|
-
|
|
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: {
|
|
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,33 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
453
468
|
};
|
|
454
469
|
}
|
|
455
470
|
});
|
|
456
|
-
|
|
471
|
+
|
|
472
|
+
//#endregion
|
|
473
|
+
//#region src/components/ContextStorage.vue
|
|
474
|
+
var ContextStorage_default = ContextStorage_vue_vue_type_script_setup_true_lang_default;
|
|
475
|
+
|
|
476
|
+
//#endregion
|
|
477
|
+
//#region src/plugin.ts
|
|
478
|
+
const VueContextStoragePlugin = { install(app) {
|
|
479
|
+
app.component("ContextStorageActivator", ContextStorageActivator_default);
|
|
480
|
+
app.component("ContextStorageCollection", ContextStorageCollection_default);
|
|
481
|
+
app.component("ContextStorageProvider", ContextStorageProvider_default);
|
|
482
|
+
app.component("ContextStorage", ContextStorage_default);
|
|
483
|
+
} };
|
|
457
484
|
|
|
458
485
|
//#endregion
|
|
459
486
|
//#region src/handlers/query/transform-helpers.ts
|
|
460
487
|
function asNumber(value, options) {
|
|
461
488
|
const { nullable = false, missable = false, fallbackValue = missable ? void 0 : nullable ? null : 0 } = options || {};
|
|
462
489
|
if (value === null && nullable) return null;
|
|
463
|
-
if (value === void 0 && missable) return
|
|
490
|
+
if (value === void 0 && missable) return;
|
|
464
491
|
value = Number(value);
|
|
465
492
|
return isNaN(value) ? fallbackValue : value;
|
|
466
493
|
}
|
|
467
494
|
function asString(value, options) {
|
|
468
495
|
const { nullable = false, missable = false, fallbackValue = missable ? void 0 : nullable ? null : "", allowedValues } = options || {};
|
|
469
496
|
if (value === null && nullable) return null;
|
|
470
|
-
if (value === void 0 && missable) return
|
|
497
|
+
if (value === void 0 && missable) return;
|
|
471
498
|
const stringValue = value ?? fallbackValue;
|
|
472
499
|
if (allowedValues && typeof stringValue === "string" && !allowedValues.includes(stringValue)) return fallbackValue;
|
|
473
500
|
return stringValue;
|
|
@@ -489,7 +516,7 @@ function asNumberArray(value, options) {
|
|
|
489
516
|
function asArray(value, options) {
|
|
490
517
|
const { nullable = false, missable = false, transform: transform$1 } = options || {};
|
|
491
518
|
if (value === null && nullable) return null;
|
|
492
|
-
if (value === void 0 && missable) return
|
|
519
|
+
if (value === void 0 && missable) return;
|
|
493
520
|
if (value === void 0) return nullable ? null : [];
|
|
494
521
|
let arrayValue;
|
|
495
522
|
if (Array.isArray(value)) arrayValue = value;
|
|
@@ -500,7 +527,7 @@ function asArray(value, options) {
|
|
|
500
527
|
function asBoolean(value, options) {
|
|
501
528
|
const { nullable = false, missable = false, fallbackValue = missable ? void 0 : nullable ? null : false } = options || {};
|
|
502
529
|
if (value === null && nullable) return null;
|
|
503
|
-
if (value === void 0 && missable) return
|
|
530
|
+
if (value === void 0 && missable) return;
|
|
504
531
|
if (value === void 0 || value === null) return fallbackValue;
|
|
505
532
|
if (typeof value === "string") {
|
|
506
533
|
const lowerValue = value.toLowerCase();
|
|
@@ -518,9 +545,4 @@ const transform = {
|
|
|
518
545
|
};
|
|
519
546
|
|
|
520
547
|
//#endregion
|
|
521
|
-
|
|
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
|
|
548
|
+
export { ContextStorage_default as ContextStorage, ContextStorageActivator_default as ContextStorageActivator, ContextStorageCollection_default as ContextStorageCollection, ContextStorageProvider_default as ContextStorageProvider, ContextStorageQueryHandler, VueContextStoragePlugin, asArray, asBoolean, asNumber, asNumberArray, asString, collection, collectionItem, contextStorageCollectionInjectKey, contextStorageCollectionItemInjectKey, contextStorageHandlersInjectKey, contextStorageQueryHandler, contextStorageQueryHandlerInjectKey, defaultHandlers, deserializeParams, handlers, serializeParams, transform, useContextStorageQueryHandler };
|