2
2
import { createTrinity } from '#v0/factories/createTrinity'
3
3
4
4
// Composables
5
- import { useRegistrar } from '#v0/composables/useRegistrar '
5
+ import { useRegistry } from '#v0/composables/useRegistry '
6
6
7
7
// Utilities
8
8
import { computed , getCurrentInstance , nextTick , onMounted , reactive , toRef , toValue , watch } from 'vue'
9
9
import { genId } from '#v0/utilities/helpers'
10
10
11
11
// Types
12
12
import type { App , ComputedGetter , ComputedRef , Reactive , Ref } from 'vue'
13
- import type { RegistrarContext , RegistrarTicket } from '#v0/composables/useRegistrar '
13
+ import type { RegistryContext , RegistryTicket } from '#v0/composables/useRegistry '
14
14
import type { ID } from '#v0/types'
15
15
16
- export type GroupTicket = RegistrarTicket & {
16
+ export type GroupTicket = RegistryTicket & {
17
17
disabled : boolean
18
18
value : unknown
19
19
valueIsIndex : boolean
@@ -22,7 +22,7 @@ export type GroupTicket = RegistrarTicket & {
22
22
toggle : ( ) => void
23
23
}
24
24
25
- export type GroupContext = RegistrarContext & {
25
+ export type GroupContext = RegistryContext & {
26
26
selectedItems : ComputedRef < Set < GroupTicket | undefined > >
27
27
selectedIndexes : ComputedRef < Set < number > >
28
28
selectedIds : Reactive < Set < ID > >
@@ -46,13 +46,13 @@ export type GroupOptions = {
46
46
}
47
47
48
48
/**
49
- * Creates a group registrar for managing group items within a specific namespace.
49
+ * Creates a group registry for managing group items within a specific namespace.
50
50
* This function provides a way to register, unregister, and manage group selections,
51
51
* allowing for dynamic group management in applications.
52
52
*
53
53
* @param namespace The namespace for the group context.
54
54
* @param options Optional configuration for the group behavior.
55
- * @template Z The type of the group items managed by the registrar .
55
+ * @template Z The type of the group items managed by the registry .
56
56
* @template E The type of the group context.
57
57
* @returns A tuple containing the inject function, provide function, and the group context.
58
58
*
@@ -65,15 +65,15 @@ export function useGroup<
65
65
namespace : string ,
66
66
options ?: GroupOptions ,
67
67
) {
68
- const [ useRegistrarContext , provideRegistrarContext , registrar ] = useRegistrar < Z , E > ( namespace )
68
+ const [ useRegistryContext , provideRegistryContext , registry ] = useRegistry < Z , E > ( namespace )
69
69
70
70
const catalog = reactive ( new Map < unknown , ID > ( ) )
71
71
const selectedIds = reactive ( new Set < ID > ( ) )
72
72
let initialValue : unknown | unknown [ ] = null
73
73
74
74
const selectedItems = computed ( ( ) => {
75
75
return new Set (
76
- Array . from ( selectedIds ) . map ( id => registrar . collection . get ( id ) ) ,
76
+ Array . from ( selectedIds ) . map ( id => registry . collection . get ( id ) ) ,
77
77
)
78
78
} )
79
79
@@ -94,17 +94,17 @@ export function useGroup<
94
94
}
95
95
96
96
function mandate ( ) {
97
- if ( ! options ?. mandatory || selectedIds . size > 0 || registrar . collection . size === 0 ) return
97
+ if ( ! options ?. mandatory || selectedIds . size > 0 || registry . collection . size === 0 ) return
98
98
99
99
if ( options . mandatory === 'force' ) {
100
- const first = registrar . collection . values ( ) . next ( ) . value
100
+ const first = registry . collection . values ( ) . next ( ) . value
101
101
102
102
if ( first ) selectedIds . add ( first . id )
103
103
104
104
return
105
105
}
106
106
107
- for ( const item of registrar . collection . values ( ) ) {
107
+ for ( const item of registry . collection . values ( ) ) {
108
108
if ( item . disabled ) continue
109
109
selectedIds . add ( item . id )
110
110
@@ -113,7 +113,7 @@ export function useGroup<
113
113
}
114
114
115
115
function reindex ( ) {
116
- registrar . reindex ( )
116
+ registry . reindex ( )
117
117
}
118
118
119
119
function reset ( ) {
@@ -130,7 +130,7 @@ export function useGroup<
130
130
for ( const id of Array . isArray ( ids ) ? ids : [ ids ] ) {
131
131
if ( ! id ) continue
132
132
133
- const item = registrar . collection . get ( id )
133
+ const item = registry . collection . get ( id )
134
134
135
135
if ( ! item || item . disabled ) continue
136
136
@@ -157,14 +157,14 @@ export function useGroup<
157
157
function register ( registrant : Partial < E > , id : ID = genId ( ) ) : Reactive < E > {
158
158
const item : Partial < E > = {
159
159
disabled : false ,
160
- value : registrant ?. value ?? registrar . collection . size ,
160
+ value : registrant ?. value ?? registry . collection . size ,
161
161
valueIsIndex : registrant ?. value == null ,
162
162
isActive : toRef ( ( ) => selectedIds . has ( ticket . id ) ) ,
163
163
toggle : ( ) => toggle ( ticket . id ) ,
164
164
...registrant ,
165
165
}
166
166
167
- const ticket = registrar . register ( item , id )
167
+ const ticket = registry . register ( item , id )
168
168
169
169
catalog . set ( ticket . value , ticket . id )
170
170
@@ -183,7 +183,7 @@ export function useGroup<
183
183
184
184
function unregister ( id : ID ) {
185
185
selectedIds . delete ( id )
186
- registrar . unregister ( id )
186
+ registry . unregister ( id )
187
187
}
188
188
189
189
if ( getCurrentInstance ( ) ) {
@@ -193,7 +193,7 @@ export function useGroup<
193
193
}
194
194
195
195
const context = {
196
- ...registrar ,
196
+ ...registry ,
197
197
selectedItems,
198
198
selectedIndexes,
199
199
selectedIds,
@@ -255,8 +255,8 @@ export function useGroup<
255
255
} )
256
256
}
257
257
258
- return provideRegistrarContext ( model , _context , app )
258
+ return provideRegistryContext ( model , _context , app )
259
259
}
260
260
261
- return createTrinity < Z > ( useRegistrarContext , provideGroupContext , context )
261
+ return createTrinity < Z > ( useRegistryContext , provideGroupContext , context )
262
262
}
0 commit comments