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.
- package/dist/index.d.ts +411 -14
- package/dist/index.js +84 -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.cjs
DELETED
|
@@ -1,571 +0,0 @@
|
|
|
1
|
-
//#region rolldown:runtime
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
-
key = keys[i];
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
-
get: ((k) => from[k]).bind(null, key),
|
|
13
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
-
value: mod,
|
|
20
|
-
enumerable: true
|
|
21
|
-
}) : target, mod));
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
const lodash = __toESM(require("lodash"));
|
|
25
|
-
const vue = __toESM(require("vue"));
|
|
26
|
-
const vue_router = __toESM(require("vue-router"));
|
|
27
|
-
|
|
28
|
-
//#region src/handlers/query/helpers.ts
|
|
29
|
-
/**
|
|
30
|
-
* Serializes filter parameters into a URL-friendly format.
|
|
31
|
-
*
|
|
32
|
-
* @param params - Raw parameters object to serialize
|
|
33
|
-
* @param options - Serialization options
|
|
34
|
-
* @returns Serialized parameters with prefixed keys
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* // With default prefix 'filters'
|
|
38
|
-
* serializeFiltersParams({ status: 'active', tags: ['a', 'b'] })
|
|
39
|
-
* // => { 'filters[status]': 'active', 'filters[tags]': 'a,b' }
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* // With custom prefix
|
|
43
|
-
* serializeFiltersParams({ name: 'John', all: true }, { prefix: 'search' })
|
|
44
|
-
* // => { 'search[name]': 'John', 'search[all]': '1' }
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* // Without prefix
|
|
48
|
-
* serializeFiltersParams({ page: 1, all: false }, { prefix: '' })
|
|
49
|
-
* // => { 'page': '1', 'all': '0' }
|
|
50
|
-
*/
|
|
51
|
-
function serializeParams(params, options = {}) {
|
|
52
|
-
const { prefix = "" } = options;
|
|
53
|
-
const result = {};
|
|
54
|
-
Object.keys(params).forEach((key) => {
|
|
55
|
-
const value = params[key];
|
|
56
|
-
if (value === "") return;
|
|
57
|
-
if (value === null) return;
|
|
58
|
-
if (Array.isArray(value) && value.length === 0) return;
|
|
59
|
-
const formattedKey = prefix ? `${prefix}[${key}]` : key;
|
|
60
|
-
if (typeof value === "object") if (Array.isArray(value)) result[formattedKey] = value.map(String);
|
|
61
|
-
else Object.assign(result, serializeParams(value, {
|
|
62
|
-
...options,
|
|
63
|
-
prefix: formattedKey
|
|
64
|
-
}));
|
|
65
|
-
else if (typeof value === "boolean") result[formattedKey] = value ? "1" : "0";
|
|
66
|
-
else result[formattedKey] = String(value);
|
|
67
|
-
});
|
|
68
|
-
return result;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Deserializes query parameters from a URL-friendly format back to an object.
|
|
72
|
-
*
|
|
73
|
-
* @param params - Serialized parameters object
|
|
74
|
-
* @returns Deserialized parameters object
|
|
75
|
-
*
|
|
76
|
-
* @example
|
|
77
|
-
* deserializeParams({ 'filters[status]': 'active', search: 'test' })
|
|
78
|
-
* // => { filters: {status: 'active'}, search: 'test' }
|
|
79
|
-
*/
|
|
80
|
-
function deserializeParams(params) {
|
|
81
|
-
return Object.keys(params).reduce((acc, key) => {
|
|
82
|
-
const value = params[key];
|
|
83
|
-
const bracketMatch = key.match(/^([^[]+)\[(.+)]$/);
|
|
84
|
-
if (bracketMatch) {
|
|
85
|
-
const [, rootKey, nestedPath] = bracketMatch;
|
|
86
|
-
if (!acc[rootKey]) acc[rootKey] = {};
|
|
87
|
-
const pathParts = nestedPath.split("][");
|
|
88
|
-
let current = acc[rootKey];
|
|
89
|
-
for (let i = 0; i < pathParts.length - 1; i++) {
|
|
90
|
-
const part = pathParts[i];
|
|
91
|
-
if (!current[part]) current[part] = {};
|
|
92
|
-
current = current[part];
|
|
93
|
-
}
|
|
94
|
-
const finalKey = pathParts[pathParts.length - 1];
|
|
95
|
-
current[finalKey] = value;
|
|
96
|
-
} else acc[key] = value;
|
|
97
|
-
return acc;
|
|
98
|
-
}, {});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
//#endregion
|
|
102
|
-
//#region src/symbols.ts
|
|
103
|
-
const collection = Symbol("context-storage-collection");
|
|
104
|
-
const collectionItem = Symbol("context-storage-collection-item");
|
|
105
|
-
const handlers = Symbol("context-storage-handlers");
|
|
106
|
-
const contextStorageQueryHandler = Symbol("context-storage-query-handler");
|
|
107
|
-
|
|
108
|
-
//#endregion
|
|
109
|
-
//#region src/handlers/query/index.ts
|
|
110
|
-
function useContextStorageQueryHandler(data, options) {
|
|
111
|
-
const handler = (0, vue.inject)(contextStorageQueryHandler);
|
|
112
|
-
if (!handler) throw new Error("[ContextStorage] ContextStorageQueryHandler is not provided");
|
|
113
|
-
const currentInstance = (0, vue.getCurrentInstance)();
|
|
114
|
-
const uid = currentInstance?.uid || 0;
|
|
115
|
-
const causer = new Error().stack?.split("\n")[2]?.trimStart() || "unknown";
|
|
116
|
-
const stop = handler.register(data, {
|
|
117
|
-
causer,
|
|
118
|
-
uid,
|
|
119
|
-
...options
|
|
120
|
-
});
|
|
121
|
-
(0, vue.onBeforeUnmount)(() => {
|
|
122
|
-
stop();
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
function sortQueryByReference(query, ...references) {
|
|
126
|
-
const sorted = {};
|
|
127
|
-
const referenceKeys = /* @__PURE__ */ new Set();
|
|
128
|
-
references.forEach((reference) => {
|
|
129
|
-
Object.keys(reference).forEach((key) => {
|
|
130
|
-
referenceKeys.add(key);
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
referenceKeys.forEach((key) => {
|
|
134
|
-
if (key in query && !(key in sorted)) sorted[key] = query[key];
|
|
135
|
-
});
|
|
136
|
-
Object.keys(query).forEach((key) => {
|
|
137
|
-
if (!(key in sorted)) sorted[key] = query[key];
|
|
138
|
-
});
|
|
139
|
-
return sorted;
|
|
140
|
-
}
|
|
141
|
-
var ContextStorageQueryHandler = class ContextStorageQueryHandler {
|
|
142
|
-
enabled = false;
|
|
143
|
-
registered = [];
|
|
144
|
-
currentQuery = void 0;
|
|
145
|
-
route;
|
|
146
|
-
router;
|
|
147
|
-
initialState;
|
|
148
|
-
hasAnyRegistered = false;
|
|
149
|
-
preventSyncRegisteredToQueryByAfterEachRoute = false;
|
|
150
|
-
preventAfterEachRouteCallsWhileCallingRouter = false;
|
|
151
|
-
static customQueryHandlerOptions = {};
|
|
152
|
-
options = {
|
|
153
|
-
mode: "replace",
|
|
154
|
-
emptyPlaceholder: "_",
|
|
155
|
-
mergeOnlyExistingKeysWithoutTransform: true,
|
|
156
|
-
preserveUnusedKeys: false,
|
|
157
|
-
preserveEmptyState: false
|
|
158
|
-
};
|
|
159
|
-
static configure(options) {
|
|
160
|
-
ContextStorageQueryHandler.customQueryHandlerOptions = options;
|
|
161
|
-
return ContextStorageQueryHandler;
|
|
162
|
-
}
|
|
163
|
-
constructor() {
|
|
164
|
-
this.route = (0, vue_router.useRoute)();
|
|
165
|
-
this.router = (0, vue_router.useRouter)();
|
|
166
|
-
this.options = {
|
|
167
|
-
...this.options,
|
|
168
|
-
...ContextStorageQueryHandler.customQueryHandlerOptions
|
|
169
|
-
};
|
|
170
|
-
const stopAfterEach = this.router.afterEach(() => {
|
|
171
|
-
this.afterEachRoute();
|
|
172
|
-
});
|
|
173
|
-
(0, vue.onBeforeUnmount)(() => {
|
|
174
|
-
stopAfterEach();
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
getInjectionKey() {
|
|
178
|
-
return contextStorageQueryHandler;
|
|
179
|
-
}
|
|
180
|
-
setInitialState(state) {
|
|
181
|
-
this.initialState = state;
|
|
182
|
-
}
|
|
183
|
-
static getInitialStateResolver() {
|
|
184
|
-
const route = (0, vue_router.useRoute)();
|
|
185
|
-
return () => route.query;
|
|
186
|
-
}
|
|
187
|
-
setEnabled(state, initial) {
|
|
188
|
-
const prevState = this.enabled;
|
|
189
|
-
this.enabled = state;
|
|
190
|
-
if (this.hasAnyRegistered) {
|
|
191
|
-
if (initial) this.syncInitialStateToRegistered();
|
|
192
|
-
if (state && !prevState || !initial) this.syncRegisteredToQuery();
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
async syncRegisteredToQuery() {
|
|
196
|
-
if (!this.enabled) return;
|
|
197
|
-
if (this.preventSyncRegisteredToQueryByAfterEachRoute) return;
|
|
198
|
-
const { newQuery, newQueryRaw } = this.#buildQueryFromRegistered();
|
|
199
|
-
this.currentQuery = newQueryRaw;
|
|
200
|
-
if ((0, lodash.isEqual)(newQuery, this.route.query)) return;
|
|
201
|
-
this.preventAfterEachRouteCallsWhileCallingRouter = true;
|
|
202
|
-
try {
|
|
203
|
-
if (this.options.mode === "replace") await this.router.replace({
|
|
204
|
-
...this.route,
|
|
205
|
-
query: newQuery
|
|
206
|
-
});
|
|
207
|
-
else await this.router.push({
|
|
208
|
-
...this.route,
|
|
209
|
-
query: newQuery
|
|
210
|
-
});
|
|
211
|
-
} catch (e) {
|
|
212
|
-
console.error("[ContextStorage] Got error while routing", e);
|
|
213
|
-
}
|
|
214
|
-
this.preventAfterEachRouteCallsWhileCallingRouter = false;
|
|
215
|
-
}
|
|
216
|
-
afterEachRoute() {
|
|
217
|
-
if (!this.enabled) return;
|
|
218
|
-
if (this.preventAfterEachRouteCallsWhileCallingRouter) return;
|
|
219
|
-
this.setInitialState(this.route.query);
|
|
220
|
-
this.preventSyncRegisteredToQueryByAfterEachRoute = true;
|
|
221
|
-
queueMicrotask(() => {
|
|
222
|
-
this.preventSyncRegisteredToQueryByAfterEachRoute = false;
|
|
223
|
-
this.syncInitialStateToRegistered();
|
|
224
|
-
this.syncRegisteredToQuery();
|
|
225
|
-
});
|
|
226
|
-
setTimeout(() => {
|
|
227
|
-
this.syncInitialStateToRegistered();
|
|
228
|
-
this.syncRegisteredToQuery();
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
syncInitialStateToRegisteredItem(item) {
|
|
232
|
-
if (this.initialState === void 0) return;
|
|
233
|
-
let deserialized = deserializeParams(this.initialState);
|
|
234
|
-
const { prefix, mergeOnlyExistingKeysWithoutTransform = this.options.mergeOnlyExistingKeysWithoutTransform } = item.options || {};
|
|
235
|
-
if (typeof prefix === "string" && prefix.length > 0) deserialized = deserialized[prefix];
|
|
236
|
-
if (deserialized === void 0) return;
|
|
237
|
-
const itemData = (0, vue.toValue)(item.data);
|
|
238
|
-
/**
|
|
239
|
-
* null can be if query parameter only has a name without a value sign
|
|
240
|
-
*/
|
|
241
|
-
if (deserialized !== null) {
|
|
242
|
-
const deserializedKeys = Object.keys(deserialized);
|
|
243
|
-
/**
|
|
244
|
-
* If the data is empty, return the initial value.
|
|
245
|
-
*
|
|
246
|
-
* This can happen when directly navigating to a route, for example through a menu item.
|
|
247
|
-
*/
|
|
248
|
-
if (!deserializedKeys.length) {
|
|
249
|
-
(0, lodash.merge)(itemData, item.initialData);
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
if (deserializedKeys.length === 1 && deserialized[this.options.emptyPlaceholder] === null) delete deserialized[this.options.emptyPlaceholder];
|
|
253
|
-
}
|
|
254
|
-
if (item.options?.transform) deserialized = item.options.transform(deserialized, item.initialData);
|
|
255
|
-
else if (mergeOnlyExistingKeysWithoutTransform) deserialized = (0, lodash.pick)(deserialized, Object.keys(item.initialData));
|
|
256
|
-
if ((0, lodash.isEqual)(itemData, deserialized)) return;
|
|
257
|
-
(0, lodash.merge)(itemData, deserialized);
|
|
258
|
-
}
|
|
259
|
-
syncInitialStateToRegistered() {
|
|
260
|
-
this.registered.forEach((item) => this.syncInitialStateToRegisteredItem(item));
|
|
261
|
-
}
|
|
262
|
-
register(data, options) {
|
|
263
|
-
this.hasAnyRegistered = true;
|
|
264
|
-
const watchHandle = (0, vue.watch)(data, () => this.syncRegisteredToQuery(), { deep: true });
|
|
265
|
-
const item = {
|
|
266
|
-
data,
|
|
267
|
-
initialData: (0, lodash.cloneDeep)((0, vue.toValue)(data)),
|
|
268
|
-
options,
|
|
269
|
-
watchHandle
|
|
270
|
-
};
|
|
271
|
-
this.registered.push(item);
|
|
272
|
-
const syncCallback = () => {
|
|
273
|
-
this.syncInitialStateToRegisteredItem(item);
|
|
274
|
-
this.syncRegisteredToQuery();
|
|
275
|
-
};
|
|
276
|
-
if (this.preventAfterEachRouteCallsWhileCallingRouter)
|
|
277
|
-
/**
|
|
278
|
-
* Macrotask solves syncing issues when syncRegisteredToQuery called after HMR
|
|
279
|
-
*/
|
|
280
|
-
setTimeout(syncCallback);
|
|
281
|
-
else queueMicrotask(syncCallback);
|
|
282
|
-
return () => {
|
|
283
|
-
this.registered.splice(this.registered.indexOf(item), 1);
|
|
284
|
-
this.syncRegisteredToQuery();
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
#buildQueryFromRegistered() {
|
|
288
|
-
const newQueryRaw = {};
|
|
289
|
-
this.registered.forEach((item) => {
|
|
290
|
-
const { prefix, preserveEmptyState = this.options.preserveEmptyState } = item.options || {};
|
|
291
|
-
const patch = serializeParams((0, vue.toValue)(item.data), { prefix });
|
|
292
|
-
const patchKeys = Object.keys(patch);
|
|
293
|
-
patchKeys.forEach((key) => {
|
|
294
|
-
if (newQueryRaw.hasOwnProperty(key)) console.warn(`[ContextStorage] Key ${key} is already present, overriding ` + (item.options?.causer || ""));
|
|
295
|
-
});
|
|
296
|
-
if (!patchKeys.length && preserveEmptyState) patch[prefix || this.options.emptyPlaceholder] = null;
|
|
297
|
-
Object.assign(newQueryRaw, patch);
|
|
298
|
-
});
|
|
299
|
-
let newQuery = { ...newQueryRaw };
|
|
300
|
-
if (this.options.preserveUnusedKeys) newQuery = {
|
|
301
|
-
...this.route.query,
|
|
302
|
-
...newQuery
|
|
303
|
-
};
|
|
304
|
-
if (this.currentQuery !== void 0) Object.keys(this.currentQuery).forEach((key) => {
|
|
305
|
-
if (!newQueryRaw.hasOwnProperty(key)) delete newQuery[key];
|
|
306
|
-
});
|
|
307
|
-
if (Object.keys(newQuery).length > 1 && newQuery[this.options.emptyPlaceholder] === null) delete newQuery[this.options.emptyPlaceholder];
|
|
308
|
-
newQuery = sortQueryByReference(newQuery, newQueryRaw);
|
|
309
|
-
return {
|
|
310
|
-
newQuery,
|
|
311
|
-
newQueryRaw
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
//#endregion
|
|
317
|
-
//#region src/injectionSymbols.ts
|
|
318
|
-
const contextStorageCollectionInjectKey = collection;
|
|
319
|
-
const contextStorageCollectionItemInjectKey = collectionItem;
|
|
320
|
-
const contextStorageHandlersInjectKey = handlers;
|
|
321
|
-
const contextStorageQueryHandlerInjectKey = contextStorageQueryHandler;
|
|
322
|
-
|
|
323
|
-
//#endregion
|
|
324
|
-
//#region src/components/ContextStorageActivator.vue
|
|
325
|
-
const _sfc_main$3 = (0, vue.defineComponent)({ setup(_, { slots }) {
|
|
326
|
-
const collection$1 = (0, vue.inject)(contextStorageCollectionInjectKey);
|
|
327
|
-
const item = (0, vue.inject)(contextStorageCollectionItemInjectKey);
|
|
328
|
-
const onActivate = () => {
|
|
329
|
-
collection$1.setActive(item);
|
|
330
|
-
};
|
|
331
|
-
return () => (0, vue.h)("div", { onMousedown: onActivate }, slots.default?.());
|
|
332
|
-
} });
|
|
333
|
-
var ContextStorageActivator_default = _sfc_main$3;
|
|
334
|
-
|
|
335
|
-
//#endregion
|
|
336
|
-
//#region src/collection.ts
|
|
337
|
-
var ContextStorageCollection = class {
|
|
338
|
-
active = void 0;
|
|
339
|
-
collection = [];
|
|
340
|
-
onActiveChangeCallbacks = [];
|
|
341
|
-
constructor(handlerConstructors) {
|
|
342
|
-
this.handlerConstructors = handlerConstructors;
|
|
343
|
-
}
|
|
344
|
-
onActiveChange(callback) {
|
|
345
|
-
this.onActiveChangeCallbacks.push(callback);
|
|
346
|
-
}
|
|
347
|
-
first() {
|
|
348
|
-
return this.collection[0];
|
|
349
|
-
}
|
|
350
|
-
findItemByKey(key) {
|
|
351
|
-
return this.collection.find((item) => item.key === key);
|
|
352
|
-
}
|
|
353
|
-
add(options) {
|
|
354
|
-
const handlers$1 = this.handlerConstructors.map((constructor) => new constructor());
|
|
355
|
-
const item = {
|
|
356
|
-
handlers: handlers$1,
|
|
357
|
-
key: options.key
|
|
358
|
-
};
|
|
359
|
-
this.collection.push(item);
|
|
360
|
-
return item;
|
|
361
|
-
}
|
|
362
|
-
remove(removeItem) {
|
|
363
|
-
if (this.collection.indexOf(removeItem) === -1) throw new Error("[ContextStorage] Item not found in collection");
|
|
364
|
-
this.collection = this.collection.filter((item) => item !== removeItem);
|
|
365
|
-
if (this.active === removeItem && this.collection.length > 0) this.setActive(this.collection[this.collection.length - 1]);
|
|
366
|
-
}
|
|
367
|
-
setActive(activeItem) {
|
|
368
|
-
if (this.active === activeItem) return;
|
|
369
|
-
const hasActiveBefore = this.active !== void 0;
|
|
370
|
-
this.active = activeItem;
|
|
371
|
-
this.collection.forEach((item) => {
|
|
372
|
-
Object.values(item.handlers).forEach((handler) => {
|
|
373
|
-
if (handler.setEnabled) handler.setEnabled(item === activeItem, !hasActiveBefore);
|
|
374
|
-
});
|
|
375
|
-
});
|
|
376
|
-
this.onActiveChangeCallbacks.forEach((callback) => callback(activeItem));
|
|
377
|
-
}
|
|
378
|
-
};
|
|
379
|
-
|
|
380
|
-
//#endregion
|
|
381
|
-
//#region src/components/ContextStorageCollection.vue
|
|
382
|
-
const _sfc_main$2 = (0, vue.defineComponent)({
|
|
383
|
-
props: { handlers: {
|
|
384
|
-
type: Object,
|
|
385
|
-
default: defaultHandlers
|
|
386
|
-
} },
|
|
387
|
-
setup({ handlers: handlers$1 }, { slots }) {
|
|
388
|
-
const lastActive = (0, vue.computed)({
|
|
389
|
-
get: () => localStorage.getItem("context-storage-last-active") || "main",
|
|
390
|
-
set: (value) => localStorage.setItem("context-storage-last-active", value)
|
|
391
|
-
});
|
|
392
|
-
const router = (0, vue_router.useRouter)();
|
|
393
|
-
const initialNavigatorState = /* @__PURE__ */ new Map();
|
|
394
|
-
const initialNavigatorStateResolvers = /* @__PURE__ */ new Map();
|
|
395
|
-
handlers$1.forEach((handler) => {
|
|
396
|
-
if (!handler.getInitialStateResolver) return;
|
|
397
|
-
initialNavigatorStateResolvers.set(handler, handler.getInitialStateResolver());
|
|
398
|
-
});
|
|
399
|
-
router.isReady().then(() => {
|
|
400
|
-
initialNavigatorStateResolvers.forEach((resolver, handler) => {
|
|
401
|
-
initialNavigatorState.set(handler, resolver());
|
|
402
|
-
});
|
|
403
|
-
activateLastActiveItem();
|
|
404
|
-
});
|
|
405
|
-
const collection$1 = new ContextStorageCollection(handlers$1);
|
|
406
|
-
collection$1.onActiveChange((item) => {
|
|
407
|
-
lastActive.value = item.key;
|
|
408
|
-
});
|
|
409
|
-
(0, vue.provide)(contextStorageCollectionInjectKey, collection$1);
|
|
410
|
-
const activateInitialItem = (item) => {
|
|
411
|
-
item.handlers.forEach((handler) => {
|
|
412
|
-
const state = initialNavigatorState.get(handler.constructor);
|
|
413
|
-
if (!state) return;
|
|
414
|
-
handler.setInitialState?.(state);
|
|
415
|
-
});
|
|
416
|
-
collection$1.setActive(item);
|
|
417
|
-
};
|
|
418
|
-
const activateLastActiveItem = () => {
|
|
419
|
-
const lastActiveItem = collection$1.findItemByKey(lastActive.value);
|
|
420
|
-
if (lastActiveItem) {
|
|
421
|
-
activateInitialItem(lastActiveItem);
|
|
422
|
-
return;
|
|
423
|
-
}
|
|
424
|
-
const firstItem = collection$1.first();
|
|
425
|
-
if (!firstItem) throw new Error("[ContextStorage] Cannot find first item in collection");
|
|
426
|
-
activateInitialItem(firstItem);
|
|
427
|
-
};
|
|
428
|
-
return () => {
|
|
429
|
-
return slots.default?.();
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
|
-
});
|
|
433
|
-
var ContextStorageCollection_default = _sfc_main$2;
|
|
434
|
-
|
|
435
|
-
//#endregion
|
|
436
|
-
//#region src/components/ContextStorageProvider.vue
|
|
437
|
-
const _sfc_main$1 = (0, vue.defineComponent)({
|
|
438
|
-
props: { itemKey: {
|
|
439
|
-
type: String,
|
|
440
|
-
required: true
|
|
441
|
-
} },
|
|
442
|
-
setup(props, { slots }) {
|
|
443
|
-
const collection$1 = (0, vue.inject)(contextStorageCollectionInjectKey);
|
|
444
|
-
if (!collection$1) throw new Error("[ContextStorage] Context storage collection not found");
|
|
445
|
-
const item = collection$1.add({ key: props.itemKey });
|
|
446
|
-
(0, vue.provide)(contextStorageCollectionItemInjectKey, item);
|
|
447
|
-
(0, vue.provide)(contextStorageHandlersInjectKey, item.handlers);
|
|
448
|
-
item.handlers.forEach((handler) => {
|
|
449
|
-
(0, vue.provide)(handler.getInjectionKey(), handler);
|
|
450
|
-
});
|
|
451
|
-
(0, vue.onUnmounted)(() => {
|
|
452
|
-
collection$1.remove(item);
|
|
453
|
-
});
|
|
454
|
-
return () => slots.default?.();
|
|
455
|
-
}
|
|
456
|
-
});
|
|
457
|
-
var ContextStorageProvider_default = _sfc_main$1;
|
|
458
|
-
|
|
459
|
-
//#endregion
|
|
460
|
-
//#region src/components/ContextStorage.vue
|
|
461
|
-
const _sfc_main = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
462
|
-
__name: "ContextStorage",
|
|
463
|
-
props: { handlers: { default: () => defaultHandlers } },
|
|
464
|
-
setup(__props) {
|
|
465
|
-
return (_ctx, _cache) => {
|
|
466
|
-
return (0, vue.openBlock)(), (0, vue.createBlock)(ContextStorageCollection_default, { handlers: __props.handlers }, {
|
|
467
|
-
default: (0, vue.withCtx)(() => [(0, vue.createVNode)(ContextStorageProvider_default, { "item-key": "main" }, {
|
|
468
|
-
default: (0, vue.withCtx)(() => [(0, vue.createVNode)(ContextStorageActivator_default, null, {
|
|
469
|
-
default: (0, vue.withCtx)(() => [(0, vue.renderSlot)(_ctx.$slots, "default")]),
|
|
470
|
-
_: 3
|
|
471
|
-
})]),
|
|
472
|
-
_: 3
|
|
473
|
-
})]),
|
|
474
|
-
_: 3
|
|
475
|
-
}, 8, ["handlers"]);
|
|
476
|
-
};
|
|
477
|
-
}
|
|
478
|
-
});
|
|
479
|
-
var ContextStorage_default = _sfc_main;
|
|
480
|
-
|
|
481
|
-
//#endregion
|
|
482
|
-
//#region src/handlers/query/transform-helpers.ts
|
|
483
|
-
function asNumber(value, options) {
|
|
484
|
-
const { nullable = false, missable = false, fallbackValue = missable ? void 0 : nullable ? null : 0 } = options || {};
|
|
485
|
-
if (value === null && nullable) return null;
|
|
486
|
-
if (value === void 0 && missable) return void 0;
|
|
487
|
-
value = Number(value);
|
|
488
|
-
return isNaN(value) ? fallbackValue : value;
|
|
489
|
-
}
|
|
490
|
-
function asString(value, options) {
|
|
491
|
-
const { nullable = false, missable = false, fallbackValue = missable ? void 0 : nullable ? null : "", allowedValues } = options || {};
|
|
492
|
-
if (value === null && nullable) return null;
|
|
493
|
-
if (value === void 0 && missable) return void 0;
|
|
494
|
-
const stringValue = value ?? fallbackValue;
|
|
495
|
-
if (allowedValues && typeof stringValue === "string" && !allowedValues.includes(stringValue)) return fallbackValue;
|
|
496
|
-
return stringValue;
|
|
497
|
-
}
|
|
498
|
-
function asNumberArray(value, options) {
|
|
499
|
-
const { nullable = false } = options || {};
|
|
500
|
-
if (value === null && nullable) return null;
|
|
501
|
-
if (value === void 0) return nullable ? null : [];
|
|
502
|
-
let arrayValue;
|
|
503
|
-
if (Array.isArray(value)) arrayValue = value;
|
|
504
|
-
else if (typeof value === "string") arrayValue = [value];
|
|
505
|
-
else arrayValue = [];
|
|
506
|
-
return arrayValue.map((item) => {
|
|
507
|
-
if (item === null) return 0;
|
|
508
|
-
const num = Number(item);
|
|
509
|
-
return isNaN(num) ? 0 : num;
|
|
510
|
-
});
|
|
511
|
-
}
|
|
512
|
-
function asArray(value, options) {
|
|
513
|
-
const { nullable = false, missable = false, transform: transform$1 } = options || {};
|
|
514
|
-
if (value === null && nullable) return null;
|
|
515
|
-
if (value === void 0 && missable) return void 0;
|
|
516
|
-
if (value === void 0) return nullable ? null : [];
|
|
517
|
-
let arrayValue;
|
|
518
|
-
if (Array.isArray(value)) arrayValue = value;
|
|
519
|
-
else arrayValue = [value];
|
|
520
|
-
if (transform$1) return arrayValue.map((item) => transform$1(item));
|
|
521
|
-
return arrayValue;
|
|
522
|
-
}
|
|
523
|
-
function asBoolean(value, options) {
|
|
524
|
-
const { nullable = false, missable = false, fallbackValue = missable ? void 0 : nullable ? null : false } = options || {};
|
|
525
|
-
if (value === null && nullable) return null;
|
|
526
|
-
if (value === void 0 && missable) return void 0;
|
|
527
|
-
if (value === void 0 || value === null) return fallbackValue;
|
|
528
|
-
if (typeof value === "string") {
|
|
529
|
-
const lowerValue = value.toLowerCase();
|
|
530
|
-
if (lowerValue === "true" || lowerValue === "1") return true;
|
|
531
|
-
if (lowerValue === "false" || lowerValue === "0") return false;
|
|
532
|
-
}
|
|
533
|
-
return fallbackValue;
|
|
534
|
-
}
|
|
535
|
-
const transform = {
|
|
536
|
-
asString,
|
|
537
|
-
asNumber,
|
|
538
|
-
asArray,
|
|
539
|
-
asNumberArray,
|
|
540
|
-
asBoolean
|
|
541
|
-
};
|
|
542
|
-
|
|
543
|
-
//#endregion
|
|
544
|
-
//#region src/index.ts
|
|
545
|
-
const defaultHandlers = [ContextStorageQueryHandler];
|
|
546
|
-
|
|
547
|
-
//#endregion
|
|
548
|
-
exports.ContextStorage = ContextStorage_default;
|
|
549
|
-
exports.ContextStorageActivator = ContextStorageActivator_default;
|
|
550
|
-
exports.ContextStorageCollection = ContextStorageCollection_default;
|
|
551
|
-
exports.ContextStorageProvider = ContextStorageProvider_default;
|
|
552
|
-
exports.ContextStorageQueryHandler = ContextStorageQueryHandler;
|
|
553
|
-
exports.asArray = asArray;
|
|
554
|
-
exports.asBoolean = asBoolean;
|
|
555
|
-
exports.asNumber = asNumber;
|
|
556
|
-
exports.asNumberArray = asNumberArray;
|
|
557
|
-
exports.asString = asString;
|
|
558
|
-
exports.collection = collection;
|
|
559
|
-
exports.collectionItem = collectionItem;
|
|
560
|
-
exports.contextStorageCollectionInjectKey = contextStorageCollectionInjectKey;
|
|
561
|
-
exports.contextStorageCollectionItemInjectKey = contextStorageCollectionItemInjectKey;
|
|
562
|
-
exports.contextStorageHandlersInjectKey = contextStorageHandlersInjectKey;
|
|
563
|
-
exports.contextStorageQueryHandler = contextStorageQueryHandler;
|
|
564
|
-
exports.contextStorageQueryHandlerInjectKey = contextStorageQueryHandlerInjectKey;
|
|
565
|
-
exports.defaultHandlers = defaultHandlers;
|
|
566
|
-
exports.deserializeParams = deserializeParams;
|
|
567
|
-
exports.handlers = handlers;
|
|
568
|
-
exports.serializeParams = serializeParams;
|
|
569
|
-
exports.transform = transform;
|
|
570
|
-
exports.useContextStorageQueryHandler = useContextStorageQueryHandler;
|
|
571
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["params: Record<string, unknown>","options: SerializeOptions","result: LocationQuery","params: Record<string, any>","collection: unique symbol","collectionItem: unique symbol","handlers: unique symbol","contextStorageQueryHandler: unique symbol","data: MaybeRefOrGetter<T>","options?: RegisterQueryHandlerBaseOptions<T>","query: LocationQuery","sorted: LocationQuery","options: QueryHandlerBaseOptions","state: Record<string, unknown> | undefined","state: boolean","initial: boolean","#buildQueryFromRegistered","item: ContextStorageQueryRegisteredItem<T>","options: RegisterQueryHandlerOptions<T>","newQueryRaw: LocationQuery","contextStorageCollectionInjectKey: InjectionKey<ContextStorageCollection>","contextStorageCollectionItemInjectKey: InjectionKey<ContextStorageCollectionItem>","contextStorageHandlersInjectKey: InjectionKey<\n ContextStorageCollectionItem['handlers']\n>","contextStorageQueryHandlerInjectKey: InjectionKey<\n InstanceType<typeof ContextStorageQueryHandler>\n>","handlerConstructors: ContextStorageHandlerConstructor[]","callback: (item: ContextStorageCollectionItem) => void","key: string","options: ItemOptions","handlers","item: ContextStorageCollectionItem","removeItem: ContextStorageCollectionItem","activeItem: ContextStorageCollectionItem","value: QueryValue | number | undefined","options?: AsNumberOptions","value: QueryValue | undefined","options?: AsStringOptions","options?: AsNumberArrayOptions","arrayValue: (string | null)[]","options?: AsArrayOptions<T>","arrayValue: QueryValue[]","transform","options?: AsBooleanOptions","transform: {\n asString: typeof asString\n asNumber: typeof asNumber\n asArray: typeof asArray\n asNumberArray: typeof asNumberArray\n asBoolean: typeof asBoolean\n}","defaultHandlers: ContextStorageHandlerConstructor[]"],"sources":["../src/handlers/query/helpers.ts","../src/symbols.ts","../src/handlers/query/index.ts","../src/injectionSymbols.ts","../src/components/ContextStorageActivator.vue","../src/collection.ts","../src/components/ContextStorageCollection.vue","../src/components/ContextStorageProvider.vue","../src/components/ContextStorage.vue","../src/handlers/query/transform-helpers.ts","../src/index.ts"],"sourcesContent":["import { LocationQuery } from 'vue-router'\n\nexport interface SerializeOptions {\n /**\n * Custom prefix for serialized keys.\n * @example\n * - prefix: 'filters' => 'filters[key]'\n * - prefix: 'search' => 'search[key]'\n * - prefix: '' => 'key' (no prefix)\n */\n prefix?: string\n}\n\n/**\n * Serializes filter parameters into a URL-friendly format.\n *\n * @param params - Raw parameters object to serialize\n * @param options - Serialization options\n * @returns Serialized parameters with prefixed keys\n *\n * @example\n * // With default prefix 'filters'\n * serializeFiltersParams({ status: 'active', tags: ['a', 'b'] })\n * // => { 'filters[status]': 'active', 'filters[tags]': 'a,b' }\n *\n * @example\n * // With custom prefix\n * serializeFiltersParams({ name: 'John', all: true }, { prefix: 'search' })\n * // => { 'search[name]': 'John', 'search[all]': '1' }\n *\n * @example\n * // Without prefix\n * serializeFiltersParams({ page: 1, all: false }, { prefix: '' })\n * // => { 'page': '1', 'all': '0' }\n */\nexport function serializeParams(\n params: Record<string, unknown>,\n options: SerializeOptions = {},\n): LocationQuery {\n const { prefix = '' } = options\n\n const result: LocationQuery = {}\n\n Object.keys(params).forEach((key) => {\n const value = params[key]\n\n // Skip empty values, null, and empty arrays\n if (value === '') {\n return\n }\n\n if (value === null) {\n return\n }\n\n if (Array.isArray(value) && value.length === 0) {\n return\n }\n\n // Format the key with prefix (or without if prefix is empty)\n const formattedKey = prefix ? `${prefix}[${key}]` : key\n\n if (typeof value === 'object') {\n if (Array.isArray(value)) {\n // Serialize arrays directly: a=1&a=2&a=3\n result[formattedKey] = value.map(String)\n } else {\n Object.assign(\n result,\n serializeParams(value as Record<string, unknown>, {\n ...options,\n prefix: formattedKey,\n }),\n )\n }\n } else if (typeof value === 'boolean') {\n result[formattedKey] = value ? '1' : '0'\n } else {\n result[formattedKey] = String(value)\n }\n })\n\n return result\n}\n\n/**\n * Deserializes query parameters from a URL-friendly format back to an object.\n *\n * @param params - Serialized parameters object\n * @returns Deserialized parameters object\n *\n * @example\n * deserializeParams({ 'filters[status]': 'active', search: 'test' })\n * // => { filters: {status: 'active'}, search: 'test' }\n */\nexport function deserializeParams(params: Record<string, any>): Record<string, any> {\n return Object.keys(params).reduce<Record<string, any>>((acc, key) => {\n const value = params[key]\n\n // Parse nested structure: 'filters[status]' -> { filters: { status: value } }\n const bracketMatch = key.match(/^([^[]+)\\[(.+)]$/)\n\n if (bracketMatch) {\n const [, rootKey, nestedPath] = bracketMatch\n\n // Initialize root object if needed\n if (!acc[rootKey]) {\n acc[rootKey] = {}\n }\n\n // Parse nested path: 'created_at][from' -> ['created_at', 'from']\n const pathParts = nestedPath.split('][')\n\n // Navigate/create nested structure\n let current = acc[rootKey]\n for (let i = 0; i < pathParts.length - 1; i++) {\n const part = pathParts[i]\n if (!current[part]) {\n current[part] = {}\n }\n current = current[part]\n }\n\n // Set the final value\n const finalKey = pathParts[pathParts.length - 1]\n current[finalKey] = value\n } else {\n // No brackets - simple key\n acc[key] = value\n }\n\n return acc\n }, {})\n}\n","export const collection: unique symbol = Symbol('context-storage-collection')\nexport const collectionItem: unique symbol = Symbol('context-storage-collection-item')\nexport const handlers: unique symbol = Symbol('context-storage-handlers')\nexport const contextStorageQueryHandler: unique symbol = Symbol('context-storage-query-handler')\n","import { ContextStorageHandlerConstructor } from '../../handlers.ts'\nimport { deserializeParams, serializeParams } from './helpers.ts'\nimport { contextStorageQueryHandler } from '../../symbols.ts'\nimport { cloneDeep, isEqual, merge, pick } from 'lodash'\nimport { getCurrentInstance, inject, MaybeRefOrGetter, onBeforeUnmount, toValue, watch } from 'vue'\nimport { LocationQuery, useRoute, useRouter } from 'vue-router'\nimport {\n ContextStorageQueryRegisteredItem,\n IContextStorageQueryHandler,\n QueryHandlerBaseOptions,\n RegisterQueryHandlerBaseOptions,\n RegisterQueryHandlerOptions,\n} from './types.ts'\n\nexport function useContextStorageQueryHandler<T extends Record<string, unknown>>(\n data: MaybeRefOrGetter<T>,\n options?: RegisterQueryHandlerBaseOptions<T>,\n): void {\n const handler = inject<InstanceType<typeof ContextStorageQueryHandler>>(\n contextStorageQueryHandler,\n )\n\n if (!handler) {\n throw new Error('[ContextStorage] ContextStorageQueryHandler is not provided')\n }\n\n const currentInstance = getCurrentInstance()\n const uid = currentInstance?.uid || 0\n\n const causer = new Error().stack?.split('\\n')[2]?.trimStart() || 'unknown'\n\n const stop = handler.register(data, { causer, uid, ...options })\n onBeforeUnmount(() => {\n stop()\n })\n}\n\nfunction sortQueryByReference(query: LocationQuery, ...references: LocationQuery[]): LocationQuery {\n const sorted: LocationQuery = {}\n\n const referenceKeys = new Set<string>()\n\n references.forEach((reference) => {\n Object.keys(reference).forEach((key) => {\n referenceKeys.add(key)\n })\n })\n\n referenceKeys.forEach((key) => {\n if (key in query && !(key in sorted)) {\n sorted[key] = query[key]\n }\n })\n\n Object.keys(query).forEach((key) => {\n if (!(key in sorted)) {\n sorted[key] = query[key]\n }\n })\n\n return sorted\n}\n\nexport class ContextStorageQueryHandler implements IContextStorageQueryHandler {\n private enabled = false\n private registered: ContextStorageQueryRegisteredItem<any>[] = []\n private currentQuery: LocationQuery | undefined = undefined\n private readonly route: ReturnType<typeof useRoute>\n private router: ReturnType<typeof useRouter>\n private initialState?: Record<string, unknown>\n private hasAnyRegistered = false\n private preventSyncRegisteredToQueryByAfterEachRoute = false\n private preventAfterEachRouteCallsWhileCallingRouter = false\n\n static customQueryHandlerOptions: QueryHandlerBaseOptions = {}\n\n private readonly options: Required<QueryHandlerBaseOptions> = {\n mode: 'replace',\n emptyPlaceholder: '_',\n mergeOnlyExistingKeysWithoutTransform: true,\n preserveUnusedKeys: false,\n preserveEmptyState: false,\n }\n\n // noinspection JSUnusedGlobalSymbols\n static configure(options: QueryHandlerBaseOptions): ContextStorageHandlerConstructor {\n ContextStorageQueryHandler.customQueryHandlerOptions = options\n\n return ContextStorageQueryHandler\n }\n\n constructor() {\n this.route = useRoute()\n this.router = useRouter()\n\n this.options = {\n ...this.options,\n ...ContextStorageQueryHandler.customQueryHandlerOptions,\n }\n\n const stopAfterEach = this.router.afterEach(() => {\n this.afterEachRoute()\n })\n\n onBeforeUnmount(() => {\n stopAfterEach()\n })\n }\n\n getInjectionKey(): typeof contextStorageQueryHandler {\n return contextStorageQueryHandler\n }\n\n setInitialState(state: Record<string, unknown> | undefined): void {\n this.initialState = state\n }\n\n static getInitialStateResolver(): () => LocationQuery {\n const route = useRoute()\n\n return () => route.query\n }\n\n setEnabled(state: boolean, initial: boolean): void {\n const prevState = this.enabled\n this.enabled = state\n\n if (this.hasAnyRegistered) {\n if (initial) {\n this.syncInitialStateToRegistered()\n }\n\n if ((state && !prevState) || !initial) {\n this.syncRegisteredToQuery()\n }\n }\n }\n\n async syncRegisteredToQuery(): Promise<void> {\n if (!this.enabled) {\n return\n }\n\n if (this.preventSyncRegisteredToQueryByAfterEachRoute) {\n return\n }\n\n const { newQuery, newQueryRaw } = this.#buildQueryFromRegistered()\n\n this.currentQuery = newQueryRaw\n\n if (isEqual(newQuery, this.route.query)) {\n return\n }\n\n this.preventAfterEachRouteCallsWhileCallingRouter = true\n try {\n if (this.options.mode === 'replace') {\n await this.router.replace({ ...this.route, query: newQuery })\n } else {\n await this.router.push({ ...this.route, query: newQuery })\n }\n } catch (e) {\n console.error('[ContextStorage] Got error while routing', e)\n }\n this.preventAfterEachRouteCallsWhileCallingRouter = false\n }\n\n afterEachRoute(): void {\n if (!this.enabled) {\n return\n }\n\n if (this.preventAfterEachRouteCallsWhileCallingRouter) {\n return\n }\n\n this.setInitialState(this.route.query)\n\n this.preventSyncRegisteredToQueryByAfterEachRoute = true\n queueMicrotask(() => {\n this.preventSyncRegisteredToQueryByAfterEachRoute = false\n\n this.syncInitialStateToRegistered()\n this.syncRegisteredToQuery()\n })\n\n setTimeout(() => {\n this.syncInitialStateToRegistered()\n this.syncRegisteredToQuery()\n })\n }\n\n syncInitialStateToRegisteredItem<T extends Record<string, unknown>>(\n item: ContextStorageQueryRegisteredItem<T>,\n ): void {\n if (this.initialState === undefined) {\n return\n }\n\n let deserialized = deserializeParams(this.initialState)\n\n const {\n prefix,\n mergeOnlyExistingKeysWithoutTransform = this.options.mergeOnlyExistingKeysWithoutTransform,\n } = item.options || {}\n\n if (typeof prefix === 'string' && prefix.length > 0) {\n deserialized = deserialized[prefix]\n }\n\n if (deserialized === undefined) {\n return\n }\n\n const itemData = toValue(item.data)\n\n /**\n * null can be if query parameter only has a name without a value sign\n */\n if (deserialized !== null) {\n const deserializedKeys = Object.keys(deserialized)\n\n /**\n * If the data is empty, return the initial value.\n *\n * This can happen when directly navigating to a route, for example through a menu item.\n */\n if (!deserializedKeys.length) {\n merge(itemData, item.initialData)\n return\n }\n\n if (deserializedKeys.length === 1 && deserialized[this.options.emptyPlaceholder] === null) {\n delete deserialized[this.options.emptyPlaceholder]\n }\n }\n\n if (item.options?.transform) {\n deserialized = item.options.transform(deserialized, item.initialData)\n } else {\n if (mergeOnlyExistingKeysWithoutTransform) {\n deserialized = pick(deserialized, Object.keys(item.initialData))\n }\n }\n\n if (isEqual(itemData, deserialized)) {\n return\n }\n\n merge(itemData, deserialized)\n }\n\n syncInitialStateToRegistered(): void {\n this.registered.forEach((item) => this.syncInitialStateToRegisteredItem(item))\n }\n\n register<T extends Record<string, unknown>>(\n data: MaybeRefOrGetter<T>,\n options: RegisterQueryHandlerOptions<T>,\n ): () => void {\n this.hasAnyRegistered = true\n\n const watchHandle = watch(data, () => this.syncRegisteredToQuery(), {\n deep: true,\n })\n\n const item: ContextStorageQueryRegisteredItem<T> = {\n data,\n initialData: cloneDeep(toValue(data)) as T,\n options,\n watchHandle,\n }\n this.registered.push(item)\n\n const syncCallback = (): void => {\n this.syncInitialStateToRegisteredItem(item)\n this.syncRegisteredToQuery()\n }\n\n if (this.preventAfterEachRouteCallsWhileCallingRouter) {\n /**\n * Macrotask solves syncing issues when syncRegisteredToQuery called after HMR\n */\n setTimeout(syncCallback)\n } else {\n queueMicrotask(syncCallback)\n }\n\n return (): void => {\n this.registered.splice(this.registered.indexOf(item), 1)\n this.syncRegisteredToQuery()\n }\n }\n\n #buildQueryFromRegistered(): { newQuery: LocationQuery; newQueryRaw: LocationQuery } {\n const newQueryRaw: LocationQuery = {}\n\n this.registered.forEach((item) => {\n const { prefix, preserveEmptyState = this.options.preserveEmptyState } = item.options || {}\n const patch = serializeParams(toValue(item.data), {\n prefix,\n })\n\n const patchKeys = Object.keys(patch)\n\n // If there are key intersections between the query and the patch, a warning is issued.\n // Patches should not overwrite each other, otherwise, upon reload, an incorrect value will be restored.\n patchKeys.forEach((key) => {\n if (newQueryRaw.hasOwnProperty(key)) {\n console.warn(\n `[ContextStorage] Key ${key} is already present, overriding ` +\n (item.options?.causer || ''),\n )\n }\n })\n\n if (!patchKeys.length && preserveEmptyState) {\n patch[prefix || this.options.emptyPlaceholder] = null\n }\n\n Object.assign(newQueryRaw, patch)\n })\n\n let newQuery = { ...newQueryRaw }\n\n /*\n * It will not delete from the query the keys that are not used in the patch.\n *\n * It will only work if the registered item has a transform, otherwise without\n * it - all keys are dumped into item.data during the initial fill from initialState\n */\n if (this.options.preserveUnusedKeys) {\n newQuery = { ...this.route.query, ...newQuery }\n }\n\n if (this.currentQuery !== undefined) {\n //Perform a diff of keys between currentQuery and newQueryRaw, and remove the keys that are in currentQuery but not in newQueryRaw.\n //This is necessary to ensure that the query string does not contain keys that are no longer used.\n Object.keys(this.currentQuery).forEach((key) => {\n if (!newQueryRaw.hasOwnProperty(key)) {\n delete newQuery[key]\n }\n })\n }\n\n if (Object.keys(newQuery).length > 1 && newQuery[this.options.emptyPlaceholder] === null) {\n delete newQuery[this.options.emptyPlaceholder]\n }\n\n newQuery = sortQueryByReference(newQuery, newQueryRaw)\n\n return { newQuery, newQueryRaw }\n }\n}\n","import { ContextStorageCollection, ContextStorageCollectionItem } from './collection'\nimport { ContextStorageQueryHandler } from './handlers/query'\nimport { collection, collectionItem, contextStorageQueryHandler, handlers } from './symbols'\nimport { InjectionKey } from 'vue'\n\nexport const contextStorageCollectionInjectKey: InjectionKey<ContextStorageCollection> = collection\nexport const contextStorageCollectionItemInjectKey: InjectionKey<ContextStorageCollectionItem> =\n collectionItem\nexport const contextStorageHandlersInjectKey: InjectionKey<\n ContextStorageCollectionItem['handlers']\n> = handlers\n\nexport const contextStorageQueryHandlerInjectKey: InjectionKey<\n InstanceType<typeof ContextStorageQueryHandler>\n> = contextStorageQueryHandler\n","<script lang=\"ts\">\nimport { defineComponent, h, inject } from 'vue'\nimport {\n contextStorageCollectionInjectKey,\n contextStorageCollectionItemInjectKey,\n} from '../injectionSymbols'\n\nexport default defineComponent({\n setup(_, { slots }) {\n const collection = inject(contextStorageCollectionInjectKey)!\n const item = inject(contextStorageCollectionItemInjectKey)!\n\n const onActivate = () => {\n collection.setActive(item)\n }\n\n return () => h('div', { onMousedown: onActivate }, slots.default?.())\n },\n})\n</script>\n","import { ContextStorageHandler, ContextStorageHandlerConstructor } from './handlers'\n\nexport type ContextStorageCollectionItem = {\n key: string\n handlers: ContextStorageHandler[]\n}\n\ninterface ItemOptions {\n key: string\n}\n\nexport class ContextStorageCollection {\n public active?: ContextStorageCollectionItem = undefined\n private collection: ContextStorageCollectionItem[] = []\n private onActiveChangeCallbacks: ((item: ContextStorageCollectionItem) => void)[] = []\n\n constructor(private handlerConstructors: ContextStorageHandlerConstructor[]) {}\n\n onActiveChange(callback: (item: ContextStorageCollectionItem) => void): void {\n this.onActiveChangeCallbacks.push(callback)\n }\n\n first(): ContextStorageCollectionItem | undefined {\n return this.collection[0]\n }\n\n findItemByKey(key: string): ContextStorageCollectionItem | undefined {\n return this.collection.find((item) => item.key === key)\n }\n\n add(options: ItemOptions): ContextStorageCollectionItem {\n const handlers = this.handlerConstructors.map((constructor) => new constructor())\n\n const item: ContextStorageCollectionItem = { handlers, key: options.key }\n\n this.collection.push(item)\n\n return item\n }\n\n remove(removeItem: ContextStorageCollectionItem): void {\n if (this.collection.indexOf(removeItem) === -1) {\n throw new Error('[ContextStorage] Item not found in collection')\n }\n\n this.collection = this.collection.filter((item) => item !== removeItem)\n\n if (this.active === removeItem && this.collection.length > 0) {\n this.setActive(this.collection[this.collection.length - 1])\n }\n }\n\n setActive(activeItem: ContextStorageCollectionItem): void {\n if (this.active === activeItem) {\n return\n }\n\n const hasActiveBefore = this.active !== undefined\n this.active = activeItem\n\n this.collection.forEach((item) => {\n Object.values(item.handlers).forEach((handler) => {\n if (handler.setEnabled) {\n handler.setEnabled(item === activeItem, !hasActiveBefore)\n }\n })\n })\n\n this.onActiveChangeCallbacks.forEach((callback) => callback(activeItem))\n }\n}\n","<script lang=\"ts\">\nimport { ContextStorageCollection, ContextStorageCollectionItem } from '../collection'\nimport { ContextStorageHandlerConstructor } from '../handlers'\nimport { contextStorageCollectionInjectKey } from '../injectionSymbols'\nimport { computed, defineComponent, PropType, provide } from 'vue'\nimport { useRouter } from 'vue-router'\nimport { defaultHandlers } from '../index.ts'\n\nexport default defineComponent({\n props: {\n handlers: {\n type: Object as PropType<ContextStorageHandlerConstructor[]>,\n default: defaultHandlers,\n },\n },\n setup({ handlers }, { slots }) {\n const lastActive = computed({\n get: () => localStorage.getItem('context-storage-last-active') || 'main',\n set: (value) => localStorage.setItem('context-storage-last-active', value),\n })\n\n const router = useRouter()\n\n const initialNavigatorState = new Map<\n ContextStorageHandlerConstructor,\n Record<string, unknown>\n >()\n const initialNavigatorStateResolvers = new Map<\n ContextStorageHandlerConstructor,\n () => Record<string, unknown>\n >()\n\n handlers.forEach((handler) => {\n if (!handler.getInitialStateResolver) {\n return\n }\n\n initialNavigatorStateResolvers.set(handler, handler.getInitialStateResolver())\n })\n\n router.isReady().then(() => {\n initialNavigatorStateResolvers.forEach((resolver, handler) => {\n initialNavigatorState.set(handler, resolver())\n })\n\n activateLastActiveItem()\n })\n\n const collection = new ContextStorageCollection(handlers)\n collection.onActiveChange((item) => {\n lastActive.value = item.key\n })\n\n provide(contextStorageCollectionInjectKey, collection)\n\n const activateInitialItem = (item: ContextStorageCollectionItem) => {\n item.handlers.forEach((handler) => {\n const state = initialNavigatorState.get(\n handler.constructor as ContextStorageHandlerConstructor,\n )\n\n if (!state) {\n return\n }\n\n handler.setInitialState?.(state)\n })\n\n collection.setActive(item)\n }\n\n const activateLastActiveItem = () => {\n const lastActiveItem = collection.findItemByKey(lastActive.value)\n if (lastActiveItem) {\n activateInitialItem(lastActiveItem)\n return\n }\n\n const firstItem = collection.first()\n if (!firstItem) {\n throw new Error('[ContextStorage] Cannot find first item in collection')\n }\n\n activateInitialItem(firstItem)\n }\n\n return () => {\n return slots.default?.()\n }\n },\n})\n</script>\n","<script lang=\"ts\">\nimport {\n contextStorageCollectionInjectKey,\n contextStorageCollectionItemInjectKey,\n contextStorageHandlersInjectKey,\n} from '../injectionSymbols'\nimport { defineComponent, inject, onUnmounted, provide } from 'vue'\n\nexport default defineComponent({\n props: {\n itemKey: {\n type: String,\n required: true,\n },\n },\n setup(props, { slots }) {\n const collection = inject(contextStorageCollectionInjectKey)\n if (!collection) throw new Error('[ContextStorage] Context storage collection not found')\n\n const item = collection.add({\n key: props.itemKey,\n })\n\n provide(contextStorageCollectionItemInjectKey, item)\n provide(contextStorageHandlersInjectKey, item.handlers)\n\n item.handlers.forEach((handler) => {\n provide(handler.getInjectionKey(), handler)\n })\n\n onUnmounted(() => {\n collection.remove(item)\n })\n\n return () => slots.default?.()\n },\n})\n</script>\n","<template>\n <ContextStorageCollection :handlers=\"handlers\">\n <ContextStorageProvider item-key=\"main\">\n <ContextStorageActivator>\n <slot />\n </ContextStorageActivator>\n </ContextStorageProvider>\n </ContextStorageCollection>\n</template>\n\n<script setup lang=\"ts\">\nimport ContextStorageActivator from './ContextStorageActivator.vue'\nimport ContextStorageCollection from './ContextStorageCollection.vue'\nimport ContextStorageProvider from './ContextStorageProvider.vue'\nimport { ContextStorageHandlerConstructor } from '../handlers'\nimport { defaultHandlers } from '../index'\n\ninterface Props {\n handlers: ContextStorageHandlerConstructor[]\n}\n\nconst { handlers = defaultHandlers } = defineProps<Props>()\n</script>\n","import { QueryValue } from './types.ts'\n\ninterface AsNumberOptions {\n nullable?: boolean\n missable?: boolean\n fallbackValue?: number\n}\n\nexport function asNumber(value: QueryValue | number | undefined): number\nexport function asNumber(\n value: QueryValue | number | undefined,\n options: { nullable: true; missable: true; fallbackValue?: number },\n): number | null | undefined\nexport function asNumber(\n value: QueryValue | number | undefined,\n options: { nullable: true; missable?: false; fallbackValue?: number },\n): number | null\nexport function asNumber(\n value: QueryValue | number | undefined,\n options: { nullable?: false; missable: true; fallbackValue?: number },\n): number | undefined\nexport function asNumber(\n value: QueryValue | number | undefined,\n options: { nullable?: false; missable?: false; fallbackValue?: number },\n): number\nexport function asNumber(\n value: QueryValue | number | undefined,\n options?: AsNumberOptions,\n): number | null | undefined {\n const {\n nullable = false,\n missable = false,\n fallbackValue = missable ? undefined : nullable ? null : 0,\n } = options || {}\n\n if (value === null && nullable) {\n return null\n }\n\n if (value === undefined && missable) {\n return undefined\n }\n\n value = Number(value)\n\n return isNaN(value) ? fallbackValue : value\n}\n\ninterface AsStringOptions<T extends readonly string[] = string[]> {\n nullable?: boolean\n missable?: boolean\n fallbackValue?: T extends readonly string[] ? T[number] : string\n allowedValues?: T\n}\n\nexport function asString(value: QueryValue | undefined): string\nexport function asString<T extends readonly string[]>(\n value: QueryValue | undefined,\n options: {\n nullable: true\n missable: true\n fallbackValue?: T[number]\n allowedValues: T\n },\n): T[number] | null | undefined\nexport function asString<T extends readonly string[]>(\n value: QueryValue | undefined,\n options: {\n nullable: true\n missable?: false\n fallbackValue?: T[number]\n allowedValues: T\n },\n): T[number] | null\nexport function asString<T extends readonly string[]>(\n value: QueryValue | undefined,\n options: {\n nullable?: false\n missable: true\n fallbackValue?: T[number]\n allowedValues: T\n },\n): T[number] | undefined\nexport function asString<T extends readonly string[]>(\n value: QueryValue | undefined,\n options: {\n nullable?: false\n missable?: false\n fallbackValue?: T[number]\n allowedValues: T\n },\n): T[number]\nexport function asString(\n value: QueryValue | undefined,\n options: { nullable: true; missable: true; fallbackValue?: string },\n): string | null | undefined\nexport function asString(\n value: QueryValue | undefined,\n options: { nullable: true; missable?: false; fallbackValue?: string },\n): string | null\nexport function asString(\n value: QueryValue | undefined,\n options: { nullable?: false; missable: true; fallbackValue?: string },\n): string | undefined\nexport function asString(\n value: QueryValue | undefined,\n options: { nullable?: false; missable?: false; fallbackValue?: string },\n): string\nexport function asString(\n value: QueryValue | undefined,\n options?: AsStringOptions,\n): QueryValue | undefined {\n const {\n nullable = false,\n missable = false,\n fallbackValue = missable ? undefined : nullable ? null : '',\n allowedValues,\n } = options || {}\n\n if (value === null && nullable) {\n return null\n }\n\n if (value === undefined && missable) {\n return undefined\n }\n\n const stringValue = value ?? fallbackValue\n\n if (allowedValues && typeof stringValue === 'string' && !allowedValues.includes(stringValue)) {\n return fallbackValue\n }\n\n return stringValue\n}\n\ninterface AsNumberArrayOptions {\n nullable?: boolean\n}\n\nexport function asNumberArray(value: QueryValue | undefined): number[]\nexport function asNumberArray(\n value: QueryValue | undefined,\n options: { nullable: true },\n): number[] | null\nexport function asNumberArray(\n value: QueryValue | undefined,\n options: { nullable?: false },\n): number[]\nexport function asNumberArray(\n value: QueryValue | undefined,\n options?: AsNumberArrayOptions,\n): number[] | null {\n const { nullable = false } = options || {}\n\n if (value === null && nullable) {\n return null\n }\n\n if (value === undefined) {\n return nullable ? null : []\n }\n\n let arrayValue: (string | null)[]\n\n if (Array.isArray(value)) {\n arrayValue = value\n } else if (typeof value === 'string') {\n arrayValue = [value]\n } else {\n arrayValue = []\n }\n\n return arrayValue.map((item) => {\n if (item === null) {\n return 0\n }\n const num = Number(item)\n return isNaN(num) ? 0 : num\n })\n}\n\ninterface AsArrayOptions<T> {\n nullable?: boolean\n missable?: boolean\n transform?: (value: QueryValue) => T\n}\n\nexport function asArray<T>(value: QueryValue | undefined): T[]\nexport function asArray<T>(\n value: QueryValue | undefined,\n options: { nullable: true; missable: true; transform?: (value: QueryValue) => T },\n): T[] | null | undefined\nexport function asArray<T>(\n value: QueryValue | undefined,\n options: { nullable: true; missable?: false; transform?: (value: QueryValue) => T },\n): T[] | null\nexport function asArray<T>(\n value: QueryValue | undefined,\n options: { nullable?: false; missable: true; transform?: (value: QueryValue) => T },\n): T[] | undefined\nexport function asArray<T>(\n value: QueryValue | undefined,\n options: { nullable?: false; missable?: false; transform?: (value: QueryValue) => T },\n): T[]\nexport function asArray<T>(\n value: QueryValue | undefined,\n options?: AsArrayOptions<T>,\n): T[] | null | undefined {\n const { nullable = false, missable = false, transform } = options || {}\n\n if (value === null && nullable) {\n return null\n }\n\n if (value === undefined && missable) {\n return undefined\n }\n\n if (value === undefined) {\n return nullable ? null : []\n }\n\n let arrayValue: QueryValue[]\n\n if (Array.isArray(value)) {\n arrayValue = value\n } else {\n arrayValue = [value]\n }\n\n if (transform) {\n return arrayValue.map((item) => transform(item))\n }\n\n return arrayValue as T[]\n}\n\ninterface AsBooleanOptions {\n nullable?: boolean\n missable?: boolean\n fallbackValue?: boolean\n}\n\nexport function asBoolean(value: QueryValue | undefined): boolean\nexport function asBoolean(\n value: QueryValue | undefined,\n options: { nullable: true; missable: true; fallbackValue?: boolean },\n): boolean | null | undefined\nexport function asBoolean(\n value: QueryValue | undefined,\n options: { nullable: true; missable?: false; fallbackValue?: boolean },\n): boolean | null\nexport function asBoolean(\n value: QueryValue | undefined,\n options: { nullable?: false; missable: true; fallbackValue?: boolean },\n): boolean | undefined\nexport function asBoolean(\n value: QueryValue | undefined,\n options: { nullable?: false; missable?: false; fallbackValue?: boolean },\n): boolean\nexport function asBoolean(\n value: QueryValue | undefined,\n options?: AsBooleanOptions,\n): boolean | null | undefined {\n const {\n nullable = false,\n missable = false,\n fallbackValue = missable ? undefined : nullable ? null : false,\n } = options || {}\n\n if (value === null && nullable) {\n return null\n }\n\n if (value === undefined && missable) {\n return undefined\n }\n\n if (value === undefined || value === null) {\n return fallbackValue\n }\n\n if (typeof value === 'string') {\n const lowerValue = value.toLowerCase()\n if (lowerValue === 'true' || lowerValue === '1') {\n return true\n }\n if (lowerValue === 'false' || lowerValue === '0') {\n return false\n }\n }\n\n return fallbackValue\n}\n\nexport const transform: {\n asString: typeof asString\n asNumber: typeof asNumber\n asArray: typeof asArray\n asNumberArray: typeof asNumberArray\n asBoolean: typeof asBoolean\n} = {\n asString,\n asNumber,\n asArray,\n asNumberArray,\n asBoolean,\n}\n","// Core exports\nimport { ContextStorageQueryHandler } from './handlers/query'\nimport type { ContextStorageHandlerConstructor } from './handlers'\n\nexport { default as ContextStorageActivator } from './components/ContextStorageActivator.vue'\nexport { default as ContextStorageCollection } from './components/ContextStorageCollection.vue'\nexport { default as ContextStorageProvider } from './components/ContextStorageProvider.vue'\nexport { default as ContextStorage } from './components/ContextStorage.vue'\n\nexport type {\n ContextStorageHandler,\n ContextStorageHandlerConstructor,\n RegisterBaseOptions,\n} from './handlers'\n\nexport { ContextStorageQueryHandler, useContextStorageQueryHandler } from './handlers/query'\n\n// Query helpers\nexport { deserializeParams, serializeParams } from './handlers/query/helpers.ts'\nexport type { SerializeOptions } from './handlers/query/helpers.ts'\n\n// Query transform helpers\nexport {\n asArray,\n asBoolean,\n asNumber,\n asNumberArray,\n asString,\n transform,\n} from './handlers/query/transform-helpers.ts'\n\n// Injection symbols\nexport {\n contextStorageCollectionInjectKey,\n contextStorageCollectionItemInjectKey,\n contextStorageHandlersInjectKey,\n contextStorageQueryHandlerInjectKey,\n} from './injectionSymbols'\n\n// Symbols\nexport { collection, collectionItem, contextStorageQueryHandler, handlers } from './symbols'\n\nexport const defaultHandlers: ContextStorageHandlerConstructor[] = [ContextStorageQueryHandler]\nexport type { QueryValue, IContextStorageQueryHandler } from './handlers/query/types'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,SAAgB,gBACdA,QACAC,UAA4B,CAAE,GACf;CACf,MAAM,EAAE,SAAS,IAAI,GAAG;CAExB,MAAMC,SAAwB,CAAE;AAEhC,QAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,QAAQ;EACnC,MAAM,QAAQ,OAAO;AAGrB,MAAI,UAAU,GACZ;AAGF,MAAI,UAAU,KACZ;AAGF,MAAI,MAAM,QAAQ,MAAM,IAAI,MAAM,WAAW,EAC3C;EAIF,MAAM,eAAe,UAAU,EAAE,OAAO,GAAG,IAAI,KAAK;AAEpD,aAAW,UAAU,SACnB,KAAI,MAAM,QAAQ,MAAM,CAEtB,QAAO,gBAAgB,MAAM,IAAI,OAAO;MAExC,QAAO,OACL,QACA,gBAAgB,OAAkC;GAChD,GAAG;GACH,QAAQ;EACT,EAAC,CACH;kBAEa,UAAU,UAC1B,QAAO,gBAAgB,QAAQ,MAAM;MAErC,QAAO,gBAAgB,OAAO,MAAM;CAEvC,EAAC;AAEF,QAAO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