vue-context-storage 0.1.1 → 0.1.2
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/README.md
CHANGED
|
@@ -47,9 +47,9 @@ Then use components without importing:
|
|
|
47
47
|
|
|
48
48
|
```vue
|
|
49
49
|
<template>
|
|
50
|
-
<
|
|
50
|
+
<ContextStorage>
|
|
51
51
|
<router-view />
|
|
52
|
-
</
|
|
52
|
+
</ContextStorage>
|
|
53
53
|
</template>
|
|
54
54
|
```
|
|
55
55
|
|
|
@@ -59,13 +59,13 @@ Import components individually when needed:
|
|
|
59
59
|
|
|
60
60
|
```vue
|
|
61
61
|
<template>
|
|
62
|
-
<
|
|
62
|
+
<ContextStorage>
|
|
63
63
|
<router-view />
|
|
64
|
-
</
|
|
64
|
+
</ContextStorage>
|
|
65
65
|
</template>
|
|
66
66
|
|
|
67
67
|
<script setup lang="ts">
|
|
68
|
-
import {
|
|
68
|
+
import { ContextStorage } from 'vue-context-storage/components'
|
|
69
69
|
</script>
|
|
70
70
|
```
|
|
71
71
|
|
|
@@ -87,12 +87,12 @@ interface Filters {
|
|
|
87
87
|
const filters = ref<Filters>({
|
|
88
88
|
search: '',
|
|
89
89
|
status: 'active',
|
|
90
|
-
page: 1
|
|
90
|
+
page: 1,
|
|
91
91
|
})
|
|
92
92
|
|
|
93
93
|
// Automatically syncs filters with URL query
|
|
94
94
|
useContextStorageQueryHandler(filters, {
|
|
95
|
-
prefix: 'filters' // URL will be: ?filters[search]=...&filters[status]=...
|
|
95
|
+
prefix: 'filters', // URL will be: ?filters[search]=...&filters[status]=...
|
|
96
96
|
})
|
|
97
97
|
</script>
|
|
98
98
|
```
|
|
@@ -116,7 +116,7 @@ interface TableState {
|
|
|
116
116
|
const state = ref<TableState>({
|
|
117
117
|
page: 1,
|
|
118
118
|
search: '',
|
|
119
|
-
perPage: 25
|
|
119
|
+
perPage: 25,
|
|
120
120
|
})
|
|
121
121
|
|
|
122
122
|
useContextStorageQueryHandler(state, {
|
|
@@ -124,8 +124,8 @@ useContextStorageQueryHandler(state, {
|
|
|
124
124
|
transform: (deserialized, initial) => ({
|
|
125
125
|
page: asNumber(deserialized.page, { fallback: 1 }),
|
|
126
126
|
search: asString(deserialized.search, { fallback: '' }),
|
|
127
|
-
perPage: asNumber(deserialized.perPage, { fallback: 25 })
|
|
128
|
-
})
|
|
127
|
+
perPage: asNumber(deserialized.perPage, { fallback: 25 }),
|
|
128
|
+
}),
|
|
129
129
|
})
|
|
130
130
|
```
|
|
131
131
|
|
|
@@ -144,7 +144,7 @@ Keep empty state in URL to prevent resetting on reload:
|
|
|
144
144
|
```typescript
|
|
145
145
|
useContextStorageQueryHandler(filters, {
|
|
146
146
|
prefix: 'filters',
|
|
147
|
-
preserveEmptyState: true
|
|
147
|
+
preserveEmptyState: true,
|
|
148
148
|
// Empty filters will show as: ?filters
|
|
149
149
|
// Without this option, empty filters would clear the URL completely
|
|
150
150
|
})
|
|
@@ -157,14 +157,11 @@ Customize global behavior:
|
|
|
157
157
|
```typescript
|
|
158
158
|
import { ContextStorageQueryHandler } from 'vue-context-storage'
|
|
159
159
|
|
|
160
|
-
|
|
160
|
+
ContextStorageQueryHandler.configure({
|
|
161
161
|
mode: 'push', // 'replace' (default) or 'push' for history
|
|
162
162
|
preserveUnusedKeys: true, // Keep other query params
|
|
163
|
-
preserveEmptyState: false
|
|
163
|
+
preserveEmptyState: false,
|
|
164
164
|
})
|
|
165
|
-
|
|
166
|
-
// Use in ContextStorageRoot
|
|
167
|
-
<ContextStorageRoot :handlers="[CustomQueryHandler]">
|
|
168
165
|
```
|
|
169
166
|
|
|
170
167
|
## API Reference
|
|
@@ -206,7 +203,7 @@ All transform helpers support nullable and missable options:
|
|
|
206
203
|
asNumber(value, {
|
|
207
204
|
fallback: 0, // Default value
|
|
208
205
|
nullable: false, // Allow null return
|
|
209
|
-
missable: false // Allow undefined return
|
|
206
|
+
missable: false, // Allow undefined return
|
|
210
207
|
})
|
|
211
208
|
```
|
|
212
209
|
|
|
@@ -220,7 +217,7 @@ import type {
|
|
|
220
217
|
ContextStorageHandlerConstructor,
|
|
221
218
|
IContextStorageQueryHandler,
|
|
222
219
|
QueryValue,
|
|
223
|
-
SerializeOptions
|
|
220
|
+
SerializeOptions,
|
|
224
221
|
} from 'vue-context-storage'
|
|
225
222
|
```
|
|
226
223
|
|
|
@@ -235,7 +232,7 @@ import { useContextStorageQueryHandler, asNumber } from 'vue-context-storage'
|
|
|
235
232
|
const pagination = ref({
|
|
236
233
|
page: 1,
|
|
237
234
|
perPage: 25,
|
|
238
|
-
total: 0
|
|
235
|
+
total: 0,
|
|
239
236
|
})
|
|
240
237
|
|
|
241
238
|
useContextStorageQueryHandler(pagination, {
|
|
@@ -243,7 +240,7 @@ useContextStorageQueryHandler(pagination, {
|
|
|
243
240
|
transform: (data, initial) => ({
|
|
244
241
|
page: asNumber(data.page, { fallback: 1 }),
|
|
245
242
|
perPage: asNumber(data.perPage, { fallback: 25 }),
|
|
246
|
-
total: initial.total // Don't sync total from URL
|
|
243
|
+
total: initial.total, // Don't sync total from URL
|
|
247
244
|
})
|
|
248
245
|
})
|
|
249
246
|
```
|
package/package.json
CHANGED
|
@@ -4,12 +4,13 @@ import { ContextStorageHandlerConstructor } from '../handlers'
|
|
|
4
4
|
import { contextStorageCollectionInjectKey } from '../injectionSymbols'
|
|
5
5
|
import { computed, defineComponent, PropType, provide } from 'vue'
|
|
6
6
|
import { useRouter } from 'vue-router'
|
|
7
|
+
import { defaultHandlers } from '../index.ts'
|
|
7
8
|
|
|
8
9
|
export default defineComponent({
|
|
9
10
|
props: {
|
|
10
11
|
handlers: {
|
|
11
12
|
type: Object as PropType<ContextStorageHandlerConstructor[]>,
|
|
12
|
-
|
|
13
|
+
default: () => defaultHandlers,
|
|
13
14
|
},
|
|
14
15
|
},
|
|
15
16
|
setup({ handlers }, { slots }) {
|
package/src/components.ts
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
export { default as ContextStorageActivator } from './components/ContextStorageActivator.vue'
|
|
3
3
|
export { default as ContextStorageCollection } from './components/ContextStorageCollection.vue'
|
|
4
4
|
export { default as ContextStorageProvider } from './components/ContextStorageProvider.vue'
|
|
5
|
-
export { default as
|
|
5
|
+
export { default as ContextStorage } from './components/ContextStorage.vue'
|
package/src/plugin.ts
CHANGED
|
@@ -2,14 +2,14 @@ import type { App, Plugin } from 'vue'
|
|
|
2
2
|
import ContextStorageActivator from './components/ContextStorageActivator.vue'
|
|
3
3
|
import ContextStorageCollection from './components/ContextStorageCollection.vue'
|
|
4
4
|
import ContextStorageProvider from './components/ContextStorageProvider.vue'
|
|
5
|
-
import
|
|
5
|
+
import ContextStorage from './components/ContextStorage.vue'
|
|
6
6
|
|
|
7
7
|
export const VueContextStoragePlugin: Plugin = {
|
|
8
8
|
install(app: App) {
|
|
9
9
|
app.component('ContextStorageActivator', ContextStorageActivator)
|
|
10
10
|
app.component('ContextStorageCollection', ContextStorageCollection)
|
|
11
11
|
app.component('ContextStorageProvider', ContextStorageProvider)
|
|
12
|
-
app.component('
|
|
12
|
+
app.component('ContextStorage', ContextStorage)
|
|
13
13
|
},
|
|
14
14
|
}
|
|
15
15
|
|
|
File without changes
|