vue-context-storage 0.1.0
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/LICENSE +21 -0
- package/README.md +262 -0
- package/dist/collection.d.cts +22 -0
- package/dist/collection.d.ts +22 -0
- package/dist/handlers/query/helpers.d.cts +45 -0
- package/dist/handlers/query/helpers.d.ts +45 -0
- package/dist/handlers/query/index.d.cts +31 -0
- package/dist/handlers/query/index.d.ts +31 -0
- package/dist/handlers/query/transform-helpers.d.cts +123 -0
- package/dist/handlers/query/transform-helpers.d.ts +123 -0
- package/dist/handlers/query/types.d.cts +103 -0
- package/dist/handlers/query/types.d.ts +103 -0
- package/dist/handlers.d.cts +15 -0
- package/dist/handlers.d.ts +15 -0
- package/dist/index.cjs +455 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +413 -0
- package/dist/index.js.map +1 -0
- package/dist/injectionSymbols.d.cts +7 -0
- package/dist/injectionSymbols.d.ts +7 -0
- package/dist/symbols.d.cts +4 -0
- package/dist/symbols.d.ts +4 -0
- package/package.json +77 -0
- package/src/collection.ts +71 -0
- package/src/components/ContextStorageActivator.vue +20 -0
- package/src/components/ContextStorageCollection.vue +91 -0
- package/src/components/ContextStorageProvider.vue +38 -0
- package/src/components/ContextStorageRoot.vue +23 -0
- package/src/components.ts +5 -0
- package/src/handlers/query/helpers.ts +134 -0
- package/src/handlers/query/index.ts +355 -0
- package/src/handlers/query/transform-helpers.ts +309 -0
- package/src/handlers/query/types.ts +125 -0
- package/src/handlers.ts +18 -0
- package/src/index.ts +42 -0
- package/src/injectionSymbols.ts +15 -0
- package/src/plugin.ts +16 -0
- package/src/shims-vue.d.ts +5 -0
- package/src/symbols.ts +4 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
# vue-context-storage
|
|
2
|
+
|
|
3
|
+
Vue 3 context storage system with URL query synchronization support.
|
|
4
|
+
|
|
5
|
+
A powerful state management solution for Vue 3 applications that provides:
|
|
6
|
+
- **Context-based storage** using Vue's provide/inject API
|
|
7
|
+
- **Automatic URL query synchronization** for preserving state across page reloads
|
|
8
|
+
- **Multiple storage contexts** with activation management
|
|
9
|
+
- **Type-safe** TypeScript support
|
|
10
|
+
- **Tree-shakeable** and lightweight
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install vue-context-storage
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Features
|
|
19
|
+
|
|
20
|
+
- ✅ **Vue 3 Composition API** - Built with modern Vue patterns
|
|
21
|
+
- ✅ **URL Query Sync** - Automatically sync state with URL parameters
|
|
22
|
+
- ✅ **Multiple Contexts** - Support multiple independent storage contexts
|
|
23
|
+
- ✅ **TypeScript** - Full type safety and IntelliSense support
|
|
24
|
+
- ✅ **Flexible** - Works with vue-router 4+
|
|
25
|
+
- ✅ **Transform Helpers** - Built-in utilities for type conversion
|
|
26
|
+
|
|
27
|
+
## Basic Usage
|
|
28
|
+
|
|
29
|
+
### Option 1: Using Vue Plugin (Recommended)
|
|
30
|
+
|
|
31
|
+
Register the plugin in your main app file:
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { createApp } from 'vue'
|
|
35
|
+
import { VueContextStoragePlugin } from 'vue-context-storage/plugin'
|
|
36
|
+
import App from './App.vue'
|
|
37
|
+
|
|
38
|
+
const app = createApp(App)
|
|
39
|
+
|
|
40
|
+
// Register components globally
|
|
41
|
+
app.use(VueContextStoragePlugin)
|
|
42
|
+
|
|
43
|
+
app.mount('#app')
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Then use components without importing:
|
|
47
|
+
|
|
48
|
+
```vue
|
|
49
|
+
<template>
|
|
50
|
+
<ContextStorageRoot>
|
|
51
|
+
<router-view />
|
|
52
|
+
</ContextStorageRoot>
|
|
53
|
+
</template>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Option 2: Manual Component Import
|
|
57
|
+
|
|
58
|
+
Import components individually when needed:
|
|
59
|
+
|
|
60
|
+
```vue
|
|
61
|
+
<template>
|
|
62
|
+
<ContextStorageRoot>
|
|
63
|
+
<router-view />
|
|
64
|
+
</ContextStorageRoot>
|
|
65
|
+
</template>
|
|
66
|
+
|
|
67
|
+
<script setup lang="ts">
|
|
68
|
+
import { ContextStorageRoot } from 'vue-context-storage/components'
|
|
69
|
+
</script>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Use Query Handler in Components
|
|
73
|
+
|
|
74
|
+
Sync reactive state with URL query parameters:
|
|
75
|
+
|
|
76
|
+
```vue
|
|
77
|
+
<script setup lang="ts">
|
|
78
|
+
import { ref } from 'vue'
|
|
79
|
+
import { useContextStorageQueryHandler } from 'vue-context-storage'
|
|
80
|
+
|
|
81
|
+
interface Filters {
|
|
82
|
+
search: string
|
|
83
|
+
status: string
|
|
84
|
+
page: number
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const filters = ref<Filters>({
|
|
88
|
+
search: '',
|
|
89
|
+
status: 'active',
|
|
90
|
+
page: 1
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
// Automatically syncs filters with URL query
|
|
94
|
+
useContextStorageQueryHandler(filters, {
|
|
95
|
+
prefix: 'filters' // URL will be: ?filters[search]=...&filters[status]=...
|
|
96
|
+
})
|
|
97
|
+
</script>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Advanced Usage
|
|
101
|
+
|
|
102
|
+
### Using Transform Helpers
|
|
103
|
+
|
|
104
|
+
Convert URL query string values to proper types:
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { ref } from 'vue'
|
|
108
|
+
import { useContextStorageQueryHandler, asNumber, asString } from 'vue-context-storage'
|
|
109
|
+
|
|
110
|
+
interface TableState {
|
|
111
|
+
page: number
|
|
112
|
+
search: string
|
|
113
|
+
perPage: number
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const state = ref<TableState>({
|
|
117
|
+
page: 1,
|
|
118
|
+
search: '',
|
|
119
|
+
perPage: 25
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
useContextStorageQueryHandler(state, {
|
|
123
|
+
prefix: 'table',
|
|
124
|
+
transform: (deserialized, initial) => ({
|
|
125
|
+
page: asNumber(deserialized.page, { fallback: 1 }),
|
|
126
|
+
search: asString(deserialized.search, { fallback: '' }),
|
|
127
|
+
perPage: asNumber(deserialized.perPage, { fallback: 25 })
|
|
128
|
+
})
|
|
129
|
+
})
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Available Transform Helpers
|
|
133
|
+
|
|
134
|
+
- `asNumber(value, options)` - Convert to number
|
|
135
|
+
- `asString(value, options)` - Convert to string
|
|
136
|
+
- `asBoolean(value, options)` - Convert to boolean
|
|
137
|
+
- `asArray(value, options)` - Convert to array
|
|
138
|
+
- `asNumberArray(value, options)` - Convert to number array
|
|
139
|
+
|
|
140
|
+
### Preserve Empty State
|
|
141
|
+
|
|
142
|
+
Keep empty state in URL to prevent resetting on reload:
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
useContextStorageQueryHandler(filters, {
|
|
146
|
+
prefix: 'filters',
|
|
147
|
+
preserveEmptyState: true
|
|
148
|
+
// Empty filters will show as: ?filters
|
|
149
|
+
// Without this option, empty filters would clear the URL completely
|
|
150
|
+
})
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Configure Query Handler
|
|
154
|
+
|
|
155
|
+
Customize global behavior:
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
import { ContextStorageQueryHandler } from 'vue-context-storage'
|
|
159
|
+
|
|
160
|
+
const CustomQueryHandler = ContextStorageQueryHandler.configure({
|
|
161
|
+
mode: 'push', // 'replace' (default) or 'push' for history
|
|
162
|
+
preserveUnusedKeys: true, // Keep other query params
|
|
163
|
+
preserveEmptyState: false
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
// Use in ContextStorageRoot
|
|
167
|
+
<ContextStorageRoot :handlers="[CustomQueryHandler]">
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## API Reference
|
|
171
|
+
|
|
172
|
+
### Composables
|
|
173
|
+
|
|
174
|
+
#### `useContextStorageQueryHandler<T>(data, options)`
|
|
175
|
+
|
|
176
|
+
Registers reactive data for URL query synchronization.
|
|
177
|
+
|
|
178
|
+
**Parameters:**
|
|
179
|
+
- `data: Ref<T>` - Reactive reference to sync
|
|
180
|
+
- `options?: RegisterQueryHandlerOptions<T>`
|
|
181
|
+
- `prefix?: string` - Query parameter prefix
|
|
182
|
+
- `transform?: (deserialized, initial) => T` - Transform function
|
|
183
|
+
- `preserveEmptyState?: boolean` - Keep empty state in URL
|
|
184
|
+
- `mergeOnlyExistingKeysWithoutTransform?: boolean` - Only merge existing keys (default: true)
|
|
185
|
+
|
|
186
|
+
### Classes
|
|
187
|
+
|
|
188
|
+
#### `ContextStorageQueryHandler`
|
|
189
|
+
|
|
190
|
+
Main handler for URL query synchronization.
|
|
191
|
+
|
|
192
|
+
**Static Methods:**
|
|
193
|
+
- `configure(options): ContextStorageHandlerConstructor` - Configure global options
|
|
194
|
+
- `getInitialStateResolver(): () => LocationQuery` - Get initial state resolver
|
|
195
|
+
|
|
196
|
+
**Methods:**
|
|
197
|
+
- `register<T>(data, options): () => void` - Register data for sync
|
|
198
|
+
- `setEnabled(state, initial): void` - Enable/disable handler
|
|
199
|
+
- `setInitialState(state): void` - Set initial state
|
|
200
|
+
|
|
201
|
+
### Transform Helpers
|
|
202
|
+
|
|
203
|
+
All transform helpers support nullable and missable options:
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
asNumber(value, {
|
|
207
|
+
fallback: 0, // Default value
|
|
208
|
+
nullable: false, // Allow null return
|
|
209
|
+
missable: false // Allow undefined return
|
|
210
|
+
})
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## TypeScript Support
|
|
214
|
+
|
|
215
|
+
Full TypeScript support with type inference:
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
import type {
|
|
219
|
+
ContextStorageHandler,
|
|
220
|
+
ContextStorageHandlerConstructor,
|
|
221
|
+
IContextStorageQueryHandler,
|
|
222
|
+
QueryValue,
|
|
223
|
+
SerializeOptions
|
|
224
|
+
} from 'vue-context-storage'
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Examples
|
|
228
|
+
|
|
229
|
+
### Pagination with URL Sync
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
import { ref } from 'vue'
|
|
233
|
+
import { useContextStorageQueryHandler, asNumber } from 'vue-context-storage'
|
|
234
|
+
|
|
235
|
+
const pagination = ref({
|
|
236
|
+
page: 1,
|
|
237
|
+
perPage: 25,
|
|
238
|
+
total: 0
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
useContextStorageQueryHandler(pagination, {
|
|
242
|
+
prefix: 'page',
|
|
243
|
+
transform: (data, initial) => ({
|
|
244
|
+
page: asNumber(data.page, { fallback: 1 }),
|
|
245
|
+
perPage: asNumber(data.perPage, { fallback: 25 }),
|
|
246
|
+
total: initial.total // Don't sync total from URL
|
|
247
|
+
})
|
|
248
|
+
})
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## Peer Dependencies
|
|
252
|
+
|
|
253
|
+
- `vue`: ^3.5.0
|
|
254
|
+
- `vue-router`: ^4.0.0
|
|
255
|
+
|
|
256
|
+
## License
|
|
257
|
+
|
|
258
|
+
MIT
|
|
259
|
+
|
|
260
|
+
## Contributing
|
|
261
|
+
|
|
262
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ContextStorageHandler, ContextStorageHandlerConstructor } from './handlers';
|
|
2
|
+
export type ContextStorageCollectionItem = {
|
|
3
|
+
key: string;
|
|
4
|
+
handlers: ContextStorageHandler[];
|
|
5
|
+
};
|
|
6
|
+
interface ItemOptions {
|
|
7
|
+
key: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class ContextStorageCollection {
|
|
10
|
+
private handlerConstructors;
|
|
11
|
+
active?: ContextStorageCollectionItem;
|
|
12
|
+
private collection;
|
|
13
|
+
private onActiveChangeCallbacks;
|
|
14
|
+
constructor(handlerConstructors: ContextStorageHandlerConstructor[]);
|
|
15
|
+
onActiveChange(callback: (item: ContextStorageCollectionItem) => void): void;
|
|
16
|
+
first(): ContextStorageCollectionItem | undefined;
|
|
17
|
+
findItemByKey(key: string): ContextStorageCollectionItem | undefined;
|
|
18
|
+
add(options: ItemOptions): ContextStorageCollectionItem;
|
|
19
|
+
remove(removeItem: ContextStorageCollectionItem): void;
|
|
20
|
+
setActive(activeItem: ContextStorageCollectionItem): void;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ContextStorageHandler, ContextStorageHandlerConstructor } from './handlers';
|
|
2
|
+
export type ContextStorageCollectionItem = {
|
|
3
|
+
key: string;
|
|
4
|
+
handlers: ContextStorageHandler[];
|
|
5
|
+
};
|
|
6
|
+
interface ItemOptions {
|
|
7
|
+
key: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class ContextStorageCollection {
|
|
10
|
+
private handlerConstructors;
|
|
11
|
+
active?: ContextStorageCollectionItem;
|
|
12
|
+
private collection;
|
|
13
|
+
private onActiveChangeCallbacks;
|
|
14
|
+
constructor(handlerConstructors: ContextStorageHandlerConstructor[]);
|
|
15
|
+
onActiveChange(callback: (item: ContextStorageCollectionItem) => void): void;
|
|
16
|
+
first(): ContextStorageCollectionItem | undefined;
|
|
17
|
+
findItemByKey(key: string): ContextStorageCollectionItem | undefined;
|
|
18
|
+
add(options: ItemOptions): ContextStorageCollectionItem;
|
|
19
|
+
remove(removeItem: ContextStorageCollectionItem): void;
|
|
20
|
+
setActive(activeItem: ContextStorageCollectionItem): void;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { LocationQuery } from 'vue-router';
|
|
2
|
+
export interface SerializeOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Custom prefix for serialized keys.
|
|
5
|
+
* @example
|
|
6
|
+
* - prefix: 'filters' => 'filters[key]'
|
|
7
|
+
* - prefix: 'search' => 'search[key]'
|
|
8
|
+
* - prefix: '' => 'key' (no prefix)
|
|
9
|
+
*/
|
|
10
|
+
prefix?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Serializes filter parameters into a URL-friendly format.
|
|
14
|
+
*
|
|
15
|
+
* @param params - Raw parameters object to serialize
|
|
16
|
+
* @param options - Serialization options
|
|
17
|
+
* @returns Serialized parameters with prefixed keys
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // With default prefix 'filters'
|
|
21
|
+
* serializeFiltersParams({ status: 'active', tags: ['a', 'b'] })
|
|
22
|
+
* // => { 'filters[status]': 'active', 'filters[tags]': 'a,b' }
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // With custom prefix
|
|
26
|
+
* serializeFiltersParams({ name: 'John', all: true }, { prefix: 'search' })
|
|
27
|
+
* // => { 'search[name]': 'John', 'search[all]': '1' }
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // Without prefix
|
|
31
|
+
* serializeFiltersParams({ page: 1, all: false }, { prefix: '' })
|
|
32
|
+
* // => { 'page': '1', 'all': '0' }
|
|
33
|
+
*/
|
|
34
|
+
export declare function serializeParams(params: Record<string, unknown>, options?: SerializeOptions): LocationQuery;
|
|
35
|
+
/**
|
|
36
|
+
* Deserializes query parameters from a URL-friendly format back to an object.
|
|
37
|
+
*
|
|
38
|
+
* @param params - Serialized parameters object
|
|
39
|
+
* @returns Deserialized parameters object
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* deserializeParams({ 'filters[status]': 'active', search: 'test' })
|
|
43
|
+
* // => { filters: {status: 'active'}, search: 'test' }
|
|
44
|
+
*/
|
|
45
|
+
export declare function deserializeParams(params: Record<string, any>): Record<string, any>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { LocationQuery } from 'vue-router';
|
|
2
|
+
export interface SerializeOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Custom prefix for serialized keys.
|
|
5
|
+
* @example
|
|
6
|
+
* - prefix: 'filters' => 'filters[key]'
|
|
7
|
+
* - prefix: 'search' => 'search[key]'
|
|
8
|
+
* - prefix: '' => 'key' (no prefix)
|
|
9
|
+
*/
|
|
10
|
+
prefix?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Serializes filter parameters into a URL-friendly format.
|
|
14
|
+
*
|
|
15
|
+
* @param params - Raw parameters object to serialize
|
|
16
|
+
* @param options - Serialization options
|
|
17
|
+
* @returns Serialized parameters with prefixed keys
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // With default prefix 'filters'
|
|
21
|
+
* serializeFiltersParams({ status: 'active', tags: ['a', 'b'] })
|
|
22
|
+
* // => { 'filters[status]': 'active', 'filters[tags]': 'a,b' }
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // With custom prefix
|
|
26
|
+
* serializeFiltersParams({ name: 'John', all: true }, { prefix: 'search' })
|
|
27
|
+
* // => { 'search[name]': 'John', 'search[all]': '1' }
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // Without prefix
|
|
31
|
+
* serializeFiltersParams({ page: 1, all: false }, { prefix: '' })
|
|
32
|
+
* // => { 'page': '1', 'all': '0' }
|
|
33
|
+
*/
|
|
34
|
+
export declare function serializeParams(params: Record<string, unknown>, options?: SerializeOptions): LocationQuery;
|
|
35
|
+
/**
|
|
36
|
+
* Deserializes query parameters from a URL-friendly format back to an object.
|
|
37
|
+
*
|
|
38
|
+
* @param params - Serialized parameters object
|
|
39
|
+
* @returns Deserialized parameters object
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* deserializeParams({ 'filters[status]': 'active', search: 'test' })
|
|
43
|
+
* // => { filters: {status: 'active'}, search: 'test' }
|
|
44
|
+
*/
|
|
45
|
+
export declare function deserializeParams(params: Record<string, any>): Record<string, any>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ContextStorageHandlerConstructor } from '../../handlers.ts';
|
|
2
|
+
import { contextStorageQueryHandler } from '../../symbols.ts';
|
|
3
|
+
import { MaybeRefOrGetter } from 'vue';
|
|
4
|
+
import { LocationQuery } from 'vue-router';
|
|
5
|
+
import { ContextStorageQueryRegisteredItem, IContextStorageQueryHandler, QueryHandlerBaseOptions, RegisterQueryHandlerBaseOptions, RegisterQueryHandlerOptions } from './types.ts';
|
|
6
|
+
export declare function useContextStorageQueryHandler<T extends Record<string, unknown>>(data: MaybeRefOrGetter<T>, options?: RegisterQueryHandlerBaseOptions<T>): void;
|
|
7
|
+
export declare class ContextStorageQueryHandler implements IContextStorageQueryHandler {
|
|
8
|
+
#private;
|
|
9
|
+
private enabled;
|
|
10
|
+
private registered;
|
|
11
|
+
private currentQuery;
|
|
12
|
+
private readonly route;
|
|
13
|
+
private router;
|
|
14
|
+
private initialState?;
|
|
15
|
+
private hasAnyRegistered;
|
|
16
|
+
private preventSyncRegisteredToQueryByAfterEachRoute;
|
|
17
|
+
private preventAfterEachRouteCallsWhileCallingRouter;
|
|
18
|
+
static customQueryHandlerOptions: QueryHandlerBaseOptions;
|
|
19
|
+
private readonly options;
|
|
20
|
+
static configure(options: QueryHandlerBaseOptions): ContextStorageHandlerConstructor;
|
|
21
|
+
constructor();
|
|
22
|
+
getInjectionKey(): typeof contextStorageQueryHandler;
|
|
23
|
+
setInitialState(state: Record<string, unknown> | undefined): void;
|
|
24
|
+
static getInitialStateResolver(): () => LocationQuery;
|
|
25
|
+
setEnabled(state: boolean, initial: boolean): void;
|
|
26
|
+
syncRegisteredToQuery(): Promise<void>;
|
|
27
|
+
afterEachRoute(): void;
|
|
28
|
+
syncInitialStateToRegisteredItem<T extends Record<string, unknown>>(item: ContextStorageQueryRegisteredItem<T>): void;
|
|
29
|
+
syncInitialStateToRegistered(): void;
|
|
30
|
+
register<T extends Record<string, unknown>>(data: MaybeRefOrGetter<T>, options: RegisterQueryHandlerOptions<T>): () => void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ContextStorageHandlerConstructor } from '../../handlers.ts';
|
|
2
|
+
import { contextStorageQueryHandler } from '../../symbols.ts';
|
|
3
|
+
import { MaybeRefOrGetter } from 'vue';
|
|
4
|
+
import { LocationQuery } from 'vue-router';
|
|
5
|
+
import { ContextStorageQueryRegisteredItem, IContextStorageQueryHandler, QueryHandlerBaseOptions, RegisterQueryHandlerBaseOptions, RegisterQueryHandlerOptions } from './types.ts';
|
|
6
|
+
export declare function useContextStorageQueryHandler<T extends Record<string, unknown>>(data: MaybeRefOrGetter<T>, options?: RegisterQueryHandlerBaseOptions<T>): void;
|
|
7
|
+
export declare class ContextStorageQueryHandler implements IContextStorageQueryHandler {
|
|
8
|
+
#private;
|
|
9
|
+
private enabled;
|
|
10
|
+
private registered;
|
|
11
|
+
private currentQuery;
|
|
12
|
+
private readonly route;
|
|
13
|
+
private router;
|
|
14
|
+
private initialState?;
|
|
15
|
+
private hasAnyRegistered;
|
|
16
|
+
private preventSyncRegisteredToQueryByAfterEachRoute;
|
|
17
|
+
private preventAfterEachRouteCallsWhileCallingRouter;
|
|
18
|
+
static customQueryHandlerOptions: QueryHandlerBaseOptions;
|
|
19
|
+
private readonly options;
|
|
20
|
+
static configure(options: QueryHandlerBaseOptions): ContextStorageHandlerConstructor;
|
|
21
|
+
constructor();
|
|
22
|
+
getInjectionKey(): typeof contextStorageQueryHandler;
|
|
23
|
+
setInitialState(state: Record<string, unknown> | undefined): void;
|
|
24
|
+
static getInitialStateResolver(): () => LocationQuery;
|
|
25
|
+
setEnabled(state: boolean, initial: boolean): void;
|
|
26
|
+
syncRegisteredToQuery(): Promise<void>;
|
|
27
|
+
afterEachRoute(): void;
|
|
28
|
+
syncInitialStateToRegisteredItem<T extends Record<string, unknown>>(item: ContextStorageQueryRegisteredItem<T>): void;
|
|
29
|
+
syncInitialStateToRegistered(): void;
|
|
30
|
+
register<T extends Record<string, unknown>>(data: MaybeRefOrGetter<T>, options: RegisterQueryHandlerOptions<T>): () => void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { QueryValue } from './types.ts';
|
|
2
|
+
export declare function asNumber(value: QueryValue | number | undefined): number;
|
|
3
|
+
export declare function asNumber(value: QueryValue | number | undefined, options: {
|
|
4
|
+
nullable: true;
|
|
5
|
+
missable: true;
|
|
6
|
+
fallbackValue?: number;
|
|
7
|
+
}): number | null | undefined;
|
|
8
|
+
export declare function asNumber(value: QueryValue | number | undefined, options: {
|
|
9
|
+
nullable: true;
|
|
10
|
+
missable?: false;
|
|
11
|
+
fallbackValue?: number;
|
|
12
|
+
}): number | null;
|
|
13
|
+
export declare function asNumber(value: QueryValue | number | undefined, options: {
|
|
14
|
+
nullable?: false;
|
|
15
|
+
missable: true;
|
|
16
|
+
fallbackValue?: number;
|
|
17
|
+
}): number | undefined;
|
|
18
|
+
export declare function asNumber(value: QueryValue | number | undefined, options: {
|
|
19
|
+
nullable?: false;
|
|
20
|
+
missable?: false;
|
|
21
|
+
fallbackValue?: number;
|
|
22
|
+
}): number;
|
|
23
|
+
export declare function asString(value: QueryValue | undefined): string;
|
|
24
|
+
export declare function asString<T extends readonly string[]>(value: QueryValue | undefined, options: {
|
|
25
|
+
nullable: true;
|
|
26
|
+
missable: true;
|
|
27
|
+
fallbackValue?: T[number];
|
|
28
|
+
allowedValues: T;
|
|
29
|
+
}): T[number] | null | undefined;
|
|
30
|
+
export declare function asString<T extends readonly string[]>(value: QueryValue | undefined, options: {
|
|
31
|
+
nullable: true;
|
|
32
|
+
missable?: false;
|
|
33
|
+
fallbackValue?: T[number];
|
|
34
|
+
allowedValues: T;
|
|
35
|
+
}): T[number] | null;
|
|
36
|
+
export declare function asString<T extends readonly string[]>(value: QueryValue | undefined, options: {
|
|
37
|
+
nullable?: false;
|
|
38
|
+
missable: true;
|
|
39
|
+
fallbackValue?: T[number];
|
|
40
|
+
allowedValues: T;
|
|
41
|
+
}): T[number] | undefined;
|
|
42
|
+
export declare function asString<T extends readonly string[]>(value: QueryValue | undefined, options: {
|
|
43
|
+
nullable?: false;
|
|
44
|
+
missable?: false;
|
|
45
|
+
fallbackValue?: T[number];
|
|
46
|
+
allowedValues: T;
|
|
47
|
+
}): T[number];
|
|
48
|
+
export declare function asString(value: QueryValue | undefined, options: {
|
|
49
|
+
nullable: true;
|
|
50
|
+
missable: true;
|
|
51
|
+
fallbackValue?: string;
|
|
52
|
+
}): string | null | undefined;
|
|
53
|
+
export declare function asString(value: QueryValue | undefined, options: {
|
|
54
|
+
nullable: true;
|
|
55
|
+
missable?: false;
|
|
56
|
+
fallbackValue?: string;
|
|
57
|
+
}): string | null;
|
|
58
|
+
export declare function asString(value: QueryValue | undefined, options: {
|
|
59
|
+
nullable?: false;
|
|
60
|
+
missable: true;
|
|
61
|
+
fallbackValue?: string;
|
|
62
|
+
}): string | undefined;
|
|
63
|
+
export declare function asString(value: QueryValue | undefined, options: {
|
|
64
|
+
nullable?: false;
|
|
65
|
+
missable?: false;
|
|
66
|
+
fallbackValue?: string;
|
|
67
|
+
}): string;
|
|
68
|
+
export declare function asNumberArray(value: QueryValue | undefined): number[];
|
|
69
|
+
export declare function asNumberArray(value: QueryValue | undefined, options: {
|
|
70
|
+
nullable: true;
|
|
71
|
+
}): number[] | null;
|
|
72
|
+
export declare function asNumberArray(value: QueryValue | undefined, options: {
|
|
73
|
+
nullable?: false;
|
|
74
|
+
}): number[];
|
|
75
|
+
export declare function asArray<T>(value: QueryValue | undefined): T[];
|
|
76
|
+
export declare function asArray<T>(value: QueryValue | undefined, options: {
|
|
77
|
+
nullable: true;
|
|
78
|
+
missable: true;
|
|
79
|
+
transform?: (value: QueryValue) => T;
|
|
80
|
+
}): T[] | null | undefined;
|
|
81
|
+
export declare function asArray<T>(value: QueryValue | undefined, options: {
|
|
82
|
+
nullable: true;
|
|
83
|
+
missable?: false;
|
|
84
|
+
transform?: (value: QueryValue) => T;
|
|
85
|
+
}): T[] | null;
|
|
86
|
+
export declare function asArray<T>(value: QueryValue | undefined, options: {
|
|
87
|
+
nullable?: false;
|
|
88
|
+
missable: true;
|
|
89
|
+
transform?: (value: QueryValue) => T;
|
|
90
|
+
}): T[] | undefined;
|
|
91
|
+
export declare function asArray<T>(value: QueryValue | undefined, options: {
|
|
92
|
+
nullable?: false;
|
|
93
|
+
missable?: false;
|
|
94
|
+
transform?: (value: QueryValue) => T;
|
|
95
|
+
}): T[];
|
|
96
|
+
export declare function asBoolean(value: QueryValue | undefined): boolean;
|
|
97
|
+
export declare function asBoolean(value: QueryValue | undefined, options: {
|
|
98
|
+
nullable: true;
|
|
99
|
+
missable: true;
|
|
100
|
+
fallbackValue?: boolean;
|
|
101
|
+
}): boolean | null | undefined;
|
|
102
|
+
export declare function asBoolean(value: QueryValue | undefined, options: {
|
|
103
|
+
nullable: true;
|
|
104
|
+
missable?: false;
|
|
105
|
+
fallbackValue?: boolean;
|
|
106
|
+
}): boolean | null;
|
|
107
|
+
export declare function asBoolean(value: QueryValue | undefined, options: {
|
|
108
|
+
nullable?: false;
|
|
109
|
+
missable: true;
|
|
110
|
+
fallbackValue?: boolean;
|
|
111
|
+
}): boolean | undefined;
|
|
112
|
+
export declare function asBoolean(value: QueryValue | undefined, options: {
|
|
113
|
+
nullable?: false;
|
|
114
|
+
missable?: false;
|
|
115
|
+
fallbackValue?: boolean;
|
|
116
|
+
}): boolean;
|
|
117
|
+
export declare const transform: {
|
|
118
|
+
asString: typeof asString;
|
|
119
|
+
asNumber: typeof asNumber;
|
|
120
|
+
asArray: typeof asArray;
|
|
121
|
+
asNumberArray: typeof asNumberArray;
|
|
122
|
+
asBoolean: typeof asBoolean;
|
|
123
|
+
};
|