vue-context-storage 0.1.9 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/index.d.ts +414 -14
  2. package/dist/index.js +93 -71
  3. package/package.json +73 -83
  4. package/dist/collection.d.cts +0 -22
  5. package/dist/collection.d.ts +0 -22
  6. package/dist/handlers/query/helpers.d.cts +0 -45
  7. package/dist/handlers/query/helpers.d.ts +0 -45
  8. package/dist/handlers/query/index.d.cts +0 -31
  9. package/dist/handlers/query/index.d.ts +0 -31
  10. package/dist/handlers/query/transform-helpers.d.cts +0 -123
  11. package/dist/handlers/query/transform-helpers.d.ts +0 -123
  12. package/dist/handlers/query/types.d.cts +0 -103
  13. package/dist/handlers/query/types.d.ts +0 -103
  14. package/dist/handlers.d.cts +0 -15
  15. package/dist/handlers.d.ts +0 -15
  16. package/dist/index.cjs +0 -571
  17. package/dist/index.cjs.map +0 -1
  18. package/dist/index.d.cts +0 -14
  19. package/dist/index.js.map +0 -1
  20. package/dist/injectionSymbols.d.cts +0 -7
  21. package/dist/injectionSymbols.d.ts +0 -7
  22. package/dist/symbols.d.cts +0 -4
  23. package/dist/symbols.d.ts +0 -4
  24. package/src/collection.ts +0 -71
  25. package/src/components/ContextStorage.vue +0 -23
  26. package/src/components/ContextStorageActivator.vue +0 -20
  27. package/src/components/ContextStorageCollection.vue +0 -92
  28. package/src/components/ContextStorageProvider.vue +0 -38
  29. package/src/components.ts +0 -5
  30. package/src/handlers/query/helpers.ts +0 -134
  31. package/src/handlers/query/index.ts +0 -355
  32. package/src/handlers/query/transform-helpers.ts +0 -309
  33. package/src/handlers/query/types.ts +0 -125
  34. package/src/handlers.ts +0 -18
  35. package/src/index.ts +0 -44
  36. package/src/injectionSymbols.ts +0 -15
  37. package/src/plugin.ts +0 -16
  38. package/src/shims-vue.d.ts +0 -5
  39. package/src/symbols.ts +0 -4
@@ -1,125 +0,0 @@
1
- import { LocationQueryValue } from 'vue-router'
2
- import { MaybeRefOrGetter, UnwrapNestedRefs, WatchHandle } from 'vue'
3
- import { ContextStorageHandler, RegisterBaseOptions } from '../../handlers.ts'
4
-
5
- export type QueryValue = LocationQueryValue | LocationQueryValue[]
6
-
7
- // A recursive type that transforms all properties to CustomType
8
- export type DeepTransformValuesToLocationQueryValue<T> = {
9
- [K in keyof T]?: T[K] extends object // Check if the property is an object
10
- ? // Exclude Array from being treated as an object for recursion
11
- T[K] extends Array<any>
12
- ? QueryValue // Arrays will just become the CustomType (or you could handle them differently)
13
- : DeepTransformValuesToLocationQueryValue<T[K]> // Recursively apply the type to nested objects
14
- : QueryValue // Non-object (leaf) properties get the CustomType
15
- }
16
-
17
- interface QueryHandlerSharedOptions {
18
- /**
19
- * Default: false
20
- *
21
- * If enabled - empty state will be preserved in query.
22
- *
23
- * Useful, when you have default values, and want to preserve empty state in query.
24
- * @example
25
- * ```
26
- * Options: {preserveEmptyState: true, prefix: 'filters'}
27
- *
28
- * When filters are empty we will get this in query string:
29
- *
30
- * /list?filters
31
- *
32
- * After page reload state will be not restored to default
33
- * ```
34
- *
35
- * @example
36
- * ```
37
- * Options: {preserveEmptyState: false, prefix: 'filters'}
38
- *
39
- * When filters are empty we will get this in query string:
40
- *
41
- * /list
42
- *
43
- * After page reload state will be restored to default
44
- * ```
45
- *
46
- * @example
47
- * ```
48
- * Options: {preserveEmptyState: true}
49
- *
50
- * When filters are empty we will get this in query string:
51
- *
52
- * /list?_
53
- *
54
- * After page reload state will be not restored to default.
55
- * Underscore (_) is default value for emptyPlaceholder option
56
- * ```
57
- */
58
- preserveEmptyState?: boolean
59
-
60
- /**
61
- * Default: true
62
- *
63
- * If transform option is not passed, ref will be merged with query only by keys that exists in ref.
64
- */
65
- mergeOnlyExistingKeysWithoutTransform?: boolean
66
- }
67
-
68
- export interface QueryHandlerBaseOptions extends QueryHandlerSharedOptions {
69
- /**
70
- * Default: replace
71
- *
72
- * Vue-router navigate mode.
73
- * Use push if you want to add new query to history.
74
- * Use replace if you want to replace current query without adding to history.
75
- */
76
- mode?: 'replace' | 'push'
77
-
78
- /**
79
- * Default: _
80
- *
81
- * Placeholder for empty state, used when preserveEmptyState is true and all ref values are empty.
82
- */
83
- emptyPlaceholder?: string
84
-
85
- /**
86
- * Default: false
87
- *
88
- * If enabled - unused keys will be preserved in query.
89
- * Unused keys are keys, that are not exists in ref.
90
- */
91
- preserveUnusedKeys?: boolean
92
- }
93
-
94
- export interface RegisterQueryHandlerBaseOptions<T> extends QueryHandlerSharedOptions {
95
- /**
96
- * Prefix in query string.
97
- *
98
- * @example
99
- * ```
100
- * filters, table-1[filters], table-2[filters]
101
- * ```
102
- */
103
- prefix?: string
104
- transform?: (
105
- deserialized: DeepTransformValuesToLocationQueryValue<UnwrapNestedRefs<T>>,
106
- initialData: T,
107
- ) => UnwrapNestedRefs<T>
108
- }
109
-
110
- export interface RegisterQueryHandlerOptions<T>
111
- extends RegisterBaseOptions, RegisterQueryHandlerBaseOptions<T> {}
112
-
113
- export interface IContextStorageQueryHandler extends ContextStorageHandler {
114
- register: <T extends Record<string, unknown>>(
115
- data: MaybeRefOrGetter<T>,
116
- options: RegisterQueryHandlerOptions<T>,
117
- ) => () => void
118
- }
119
-
120
- export interface ContextStorageQueryRegisteredItem<T extends Record<string, unknown>> {
121
- data: MaybeRefOrGetter<T>
122
- initialData: T
123
- options: RegisterQueryHandlerOptions<T>
124
- watchHandle: WatchHandle
125
- }
package/src/handlers.ts DELETED
@@ -1,18 +0,0 @@
1
- import type { InjectionKey, MaybeRefOrGetter } from 'vue'
2
-
3
- export interface ContextStorageHandlerConstructor {
4
- new (): ContextStorageHandler
5
- getInitialStateResolver?: () => () => Record<string, unknown>
6
- }
7
-
8
- export interface RegisterBaseOptions {
9
- causer: string
10
- uid: number
11
- }
12
-
13
- export interface ContextStorageHandler {
14
- register: (data: MaybeRefOrGetter, options: RegisterBaseOptions) => () => void
15
- setInitialState?: (state: Record<string, unknown>) => void
16
- setEnabled?: (enabled: boolean, initial: boolean) => void
17
- getInjectionKey(): InjectionKey<ContextStorageHandler>
18
- }
package/src/index.ts DELETED
@@ -1,44 +0,0 @@
1
- // Core exports
2
- import { ContextStorageQueryHandler } from './handlers/query'
3
- import type { ContextStorageHandlerConstructor } from './handlers'
4
-
5
- export { default as ContextStorageActivator } from './components/ContextStorageActivator.vue'
6
- export { default as ContextStorageCollection } from './components/ContextStorageCollection.vue'
7
- export { default as ContextStorageProvider } from './components/ContextStorageProvider.vue'
8
- export { default as ContextStorage } from './components/ContextStorage.vue'
9
-
10
- export type {
11
- ContextStorageHandler,
12
- ContextStorageHandlerConstructor,
13
- RegisterBaseOptions,
14
- } from './handlers'
15
-
16
- export { ContextStorageQueryHandler, useContextStorageQueryHandler } from './handlers/query'
17
-
18
- // Query helpers
19
- export { deserializeParams, serializeParams } from './handlers/query/helpers.ts'
20
- export type { SerializeOptions } from './handlers/query/helpers.ts'
21
-
22
- // Query transform helpers
23
- export {
24
- asArray,
25
- asBoolean,
26
- asNumber,
27
- asNumberArray,
28
- asString,
29
- transform,
30
- } from './handlers/query/transform-helpers.ts'
31
-
32
- // Injection symbols
33
- export {
34
- contextStorageCollectionInjectKey,
35
- contextStorageCollectionItemInjectKey,
36
- contextStorageHandlersInjectKey,
37
- contextStorageQueryHandlerInjectKey,
38
- } from './injectionSymbols'
39
-
40
- // Symbols
41
- export { collection, collectionItem, contextStorageQueryHandler, handlers } from './symbols'
42
-
43
- export const defaultHandlers: ContextStorageHandlerConstructor[] = [ContextStorageQueryHandler]
44
- export type { QueryValue, IContextStorageQueryHandler } from './handlers/query/types'
@@ -1,15 +0,0 @@
1
- import { ContextStorageCollection, ContextStorageCollectionItem } from './collection'
2
- import { ContextStorageQueryHandler } from './handlers/query'
3
- import { collection, collectionItem, contextStorageQueryHandler, handlers } from './symbols'
4
- import { InjectionKey } from 'vue'
5
-
6
- export const contextStorageCollectionInjectKey: InjectionKey<ContextStorageCollection> = collection
7
- export const contextStorageCollectionItemInjectKey: InjectionKey<ContextStorageCollectionItem> =
8
- collectionItem
9
- export const contextStorageHandlersInjectKey: InjectionKey<
10
- ContextStorageCollectionItem['handlers']
11
- > = handlers
12
-
13
- export const contextStorageQueryHandlerInjectKey: InjectionKey<
14
- InstanceType<typeof ContextStorageQueryHandler>
15
- > = contextStorageQueryHandler
package/src/plugin.ts DELETED
@@ -1,16 +0,0 @@
1
- import type { App, Plugin } from 'vue'
2
- import ContextStorageActivator from './components/ContextStorageActivator.vue'
3
- import ContextStorageCollection from './components/ContextStorageCollection.vue'
4
- import ContextStorageProvider from './components/ContextStorageProvider.vue'
5
- import ContextStorage from './components/ContextStorage.vue'
6
-
7
- export const VueContextStoragePlugin: Plugin = {
8
- install(app: App) {
9
- app.component('ContextStorageActivator', ContextStorageActivator)
10
- app.component('ContextStorageCollection', ContextStorageCollection)
11
- app.component('ContextStorageProvider', ContextStorageProvider)
12
- app.component('ContextStorage', ContextStorage)
13
- },
14
- }
15
-
16
- export default VueContextStoragePlugin
@@ -1,5 +0,0 @@
1
- declare module '*.vue' {
2
- import type { DefineComponent } from 'vue'
3
- const component: DefineComponent<{}, {}, any>
4
- export default component
5
- }
package/src/symbols.ts DELETED
@@ -1,4 +0,0 @@
1
- export const collection: unique symbol = Symbol('context-storage-collection')
2
- export const collectionItem: unique symbol = Symbol('context-storage-collection-item')
3
- export const handlers: unique symbol = Symbol('context-storage-handlers')
4
- export const contextStorageQueryHandler: unique symbol = Symbol('context-storage-query-handler')