@bagelink/vue 1.3.3 → 1.3.7

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.
@@ -1,6 +1,6 @@
1
1
  body>div ::-webkit-scrollbar {
2
- width: 0.5em;
3
- height: 0.5rem;
2
+ width: var(--bgl-scrollbar-size);
3
+ height: var(--bgl-scrollbar-size);
4
4
  }
5
5
 
6
6
  body>div ::-webkit-scrollbar-track {}
@@ -33,6 +33,7 @@
33
33
  --bgl-selection-bg: var(--bgl-blue-dark);
34
34
  --bgl-selection-color: var(--bgl-white);
35
35
  --bgl-scrollbar-thumb: var(--bgl-gray);
36
+ --bgl-scrollbar-size: 0.5rem;
36
37
  --pill-btn-color: var(--bgl-white);
37
38
  --pill-btn-bg: var(--placeholder-color);
38
39
  --bgl-selected: var(--bgl-gray-light);
@@ -6,7 +6,12 @@ import type { PathsOptions, DefaultPathsOptions } from 'type-fest/source/paths'
6
6
  import type { VNode } from 'vue'
7
7
  import type { ComponentExposed } from 'vue-component-type-helpers'
8
8
 
9
- export type AttributeValue = string | number | boolean | undefined | { [key: string]: any }
9
+ export type AttributeValue =
10
+ | string
11
+ | number
12
+ | boolean
13
+ | undefined
14
+ | { [key: string]: any }
10
15
 
11
16
  export type AttributeFn<T, P extends Path<T>> = (
12
17
  field: FieldVal<T, P>,
@@ -17,10 +22,10 @@ export interface Attributes<T, P extends Path<T>> {
17
22
  [key: string]: AttributeValue | AttributeFn<T, P>
18
23
  }
19
24
 
20
- export type BagelFieldOptions<T, P extends Path<T>> = (
21
- string
25
+ export type BagelFieldOptions<T, P extends Path<T>> =
26
+ | string
22
27
  | (
23
- {
28
+ | {
24
29
  label?: string
25
30
  value: string | number
26
31
  }
@@ -30,54 +35,55 @@ export type BagelFieldOptions<T, P extends Path<T>> = (
30
35
  | { [key: string]: any }
31
36
  )[]
32
37
  | ((val?: FieldVal<T, P>, rowData?: T) => void)
33
- )
34
38
 
35
- export type VIfType<T, P extends Path<T>> = (
36
- string |
37
- boolean |
38
- ((val?: FieldVal<T, P>, rowData?: T) => boolean)
39
- )
39
+ export type VIfType<T, P extends Path<T>> =
40
+ | string
41
+ | boolean
42
+ | ((val?: FieldVal<T, P>, rowData?: T) => boolean)
40
43
 
41
44
  export type ValidationFn<T, P extends Path<T>> = (
42
45
  val?: FieldVal<T, P>,
43
- rowData?: T,
46
+ rowData?: T
44
47
  ) => string | undefined
45
48
 
46
49
  export interface ShallowPathsOptions extends PathsOptions {
47
50
  maxRecursionDepth: 1
48
51
  }
49
52
 
50
- export type _Path<T, PathsOpts extends PathsOptions = DefaultPathsOptions> = (
51
- ToString<
52
- Paths<
53
- OmitIndexSignature<T>,
54
- PathsOpts
55
- >
56
- >
57
- )
58
-
59
- export type Path<T, PathsOpts extends PathsOptions = DefaultPathsOptions> = (
60
- FieldVal<T, _Path<T, PathsOpts>> extends Array<any> ?
61
- LiteralStringUnion<_Path<T, PathsOpts>> :
62
- _Path<T, PathsOpts>
63
- )
53
+ export type _Path<
54
+ T,
55
+ PO extends PathsOptions = DefaultPathsOptions,
56
+ > = ToString<Paths<OmitIndexSignature<T>, PO>>
57
+
58
+ export type Path<T, PO extends PathsOptions = DefaultPathsOptions> =
59
+ FieldVal<T, _Path<T, PO>> extends Array<any>
60
+ ? LiteralStringUnion<_Path<T, PO>>
61
+ : _Path<T, PO>
64
62
 
65
63
  /** The value type at path P in object T. */
66
64
  // Fall back to unknown if type resolution fails
67
- export type FieldVal<T, P extends Path<T>> = (
68
- unknown extends Get<T, P> ?
69
- unknown :
70
- Get<T, P>
71
- )
65
+ export type FieldVal<T, P extends Path<T>> =
66
+ unknown extends Get<T, P> ? unknown : Get<T, P>
72
67
 
73
68
  /** If path P in T is an array, this gives the array's element type. */
74
69
  export type ArrayFieldVal<T, P extends Path<T>> = IterableElement<Get<T, P>>
75
70
 
76
- export type VNodeFn<T, P extends Path<T>> = (props: { row?: T, field: BaseBagelField<T, P> }) => VNode
77
-
78
- export type SchemaChild<T, P extends Path<T>> = Field<T> | VNode | VNodeFn<T, P> | string
79
-
80
- export interface BaseBagelField<T, P extends Path<T>> {
71
+ export type VNodeFn<T, P extends Path<T>> = (props: {
72
+ row?: T
73
+ field: BaseBagelField<T, P>
74
+ }) => VNode
75
+
76
+ export type SchemaChild<
77
+ T,
78
+ P extends Path<T, PO>,
79
+ PO extends PathsOptions = DefaultPathsOptions,
80
+ > = Field<T, PO> | VNode | VNodeFn<T, P> | string
81
+
82
+ export interface BaseBagelField<
83
+ T,
84
+ P extends Path<T, PO>,
85
+ PO extends PathsOptions = DefaultPathsOptions,
86
+ > {
81
87
  '$el'?: any
82
88
  'id'?: P
83
89
  'label'?: string
@@ -88,8 +94,8 @@ export interface BaseBagelField<T, P extends Path<T>> {
88
94
  'disabled'?: boolean
89
95
  'helptext'?: string
90
96
  'options'?: BagelFieldOptions<T, P>
91
- 'children'?: SchemaChild<T, P>[]
92
- 'slots'?: { [key: string]: SchemaChild<T, P>[] }
97
+ 'children'?: SchemaChild<T, P, PO>[]
98
+ 'slots'?: { [key: string]: SchemaChild<T, P, PO>[] }
93
99
  'defaultValue'?: any
94
100
  'vIf'?: VIfType<T, P>
95
101
  'v-if'?: VIfType<T, P>
@@ -98,30 +104,61 @@ export interface BaseBagelField<T, P extends Path<T>> {
98
104
  'validate'?: ValidationFn<T, P>
99
105
  }
100
106
 
101
- export type _MappedBaseBagelField<T> = {
102
- [P in Path<T>]: BaseBagelField<T, P>
107
+ export type _MappedBaseBagelField<
108
+ T,
109
+ PO extends PathsOptions = DefaultPathsOptions,
110
+ > = {
111
+ [P in Path<T, PO>]: BaseBagelField<T, P, PO>
103
112
  }
104
113
 
105
- export type MappedBaseBagelFieldP<T, P extends Path<T>> = _MappedBaseBagelField<T>[P]
106
-
107
- export type FieldByP<T, P extends Path<T>> = MappedBaseBagelFieldP<T, P>
108
-
109
- export type Field<T, PathsOpts extends PathsOptions = DefaultPathsOptions> = (
110
- MappedBaseBagelFieldP<T, Path<T, PathsOpts>>
111
- )
112
-
113
- export type BglFieldT<T> = Field<T>
114
-
115
- export type BglFormSchemaT<T, PathsOpts extends PathsOptions = DefaultPathsOptions> = Field<T, PathsOpts>[]
116
-
117
- export type ShallowBglFormSchemaT<T, PathsOpts extends PathsOptions = ShallowPathsOptions> = Field<T, PathsOpts>[]
118
-
119
- export interface InputBagelField<T, P extends Path<T>> extends BaseBagelField<T, P> {
114
+ export type MappedBaseBagelFieldP<
115
+ T,
116
+ P extends Path<T, PO>,
117
+ PO extends PathsOptions = DefaultPathsOptions,
118
+ > = _MappedBaseBagelField<T, PO>[P]
119
+
120
+ export type FieldByP<
121
+ T,
122
+ P extends Path<T, PO>,
123
+ PO extends PathsOptions = DefaultPathsOptions,
124
+ > = MappedBaseBagelFieldP<T, P, PO>
125
+
126
+ export type Field<
127
+ T,
128
+ PO extends PathsOptions = DefaultPathsOptions,
129
+ > = MappedBaseBagelFieldP<T, Path<T, PO>, PO>
130
+
131
+ export type BglFieldT<
132
+ T,
133
+ PO extends PathsOptions = DefaultPathsOptions,
134
+ > = Field<T, PO>
135
+
136
+ export type BglFormSchemaT<
137
+ T,
138
+ PO extends PathsOptions = DefaultPathsOptions,
139
+ > = Field<T, PO>[]
140
+
141
+ export type ShallowBglFormSchemaT<
142
+ T,
143
+ PO extends PathsOptions = ShallowPathsOptions,
144
+ > = Field<T, PO>[]
145
+
146
+ export interface InputBagelField<
147
+ T,
148
+ P extends Path<T, PO>,
149
+ PO extends PathsOptions = ShallowPathsOptions
150
+ >
151
+ extends BaseBagelField<T, P, PO> {
120
152
  $el: 'text' | ComponentExposed<typeof TextInput>
121
153
  type?: string
122
154
  }
123
155
 
124
- export interface SelectBagelField<T, P extends Path<T>> extends BaseBagelField<T, P> {
156
+ export interface SelectBagelField<
157
+ T,
158
+ P extends Path<T, PO>,
159
+ PO extends PathsOptions = ShallowPathsOptions,
160
+ >
161
+ extends BaseBagelField<T, P, PO> {
125
162
  $el: 'select' | ComponentExposed<typeof SelectInput>
126
163
  type?: string
127
164
  }
@@ -1,6 +1,10 @@
1
1
  import type { ArrayFieldVal, Attributes, BaseBagelField, BglFormSchemaT, FieldByP, IconType, InputBagelField, Option, Path, SchemaChild, SelectBagelField, ShallowBglFormSchemaT, UploadInputProps } from '@bagelink/vue'
2
+ import type { DefaultPathsOptions, PathsOptions } from 'type-fest/source/paths'
2
3
 
3
- interface InputOptions<T, P extends Path<T>> extends Partial<BaseBagelField<T, P>> {
4
+ interface InputOptions<
5
+ T,
6
+ P extends Path<T>
7
+ > extends Partial<BaseBagelField<T, P>> {
4
8
  defaultValue?: string | number
5
9
  autocomplete?: AutoFillField
6
10
  }
@@ -40,22 +44,33 @@ interface NumFieldOptions<T, K extends Path<T>> extends InputOptions<T, K> {
40
44
  useGrouping?: boolean
41
45
  }
42
46
 
43
- type RichTextOptions<T, P extends Path<T>> = InputOptions<T, P>
47
+ type RichTextOptions<
48
+ T,
49
+ P extends Path<T>
50
+ > = InputOptions<T, P>
44
51
 
45
- export function getBaseField<T, P extends Path<T>>(
52
+ export function getBaseField<
53
+ T,
54
+ P extends Path<T, PO>,
55
+ PO extends PathsOptions = DefaultPathsOptions,
56
+ >(
46
57
  id?: P,
47
58
  labelOrRest: string | Partial<BaseBagelField<T, P>> = {},
48
59
  rest: Partial<BaseBagelField<T, P>> = {}
49
- ): BaseBagelField<T, P> {
60
+ ): BaseBagelField<T, P, PO> {
50
61
  if (typeof labelOrRest === 'object') return { id, ...labelOrRest }
51
62
  return { id, label: labelOrRest, ...rest }
52
63
  }
53
64
 
54
- export function richText<T, P extends Path<T>>(
65
+ export function richText<
66
+ T,
67
+ P extends Path<T, PO>,
68
+ PO extends PathsOptions = DefaultPathsOptions,
69
+ >(
55
70
  id?: P,
56
71
  label?: string,
57
72
  options?: RichTextOptions<T, P>,
58
- ): BaseBagelField<T, P> {
73
+ ): BaseBagelField<T, P, PO> {
59
74
  return {
60
75
  $el: 'richtext',
61
76
  class: options?.class,
@@ -70,11 +85,15 @@ export function richText<T, P extends Path<T>>(
70
85
  }
71
86
  }
72
87
 
73
- export function txtField<T, P extends Path<T>>(
88
+ export function txtField<
89
+ T,
90
+ P extends Path<T, PO>,
91
+ PO extends PathsOptions = DefaultPathsOptions,
92
+ >(
74
93
  id?: P,
75
94
  label?: string,
76
95
  options?: TextInputOptions<T, P>,
77
- ): InputBagelField<T, P> {
96
+ ): InputBagelField<T, P, PO> {
78
97
  return {
79
98
  $el: 'text',
80
99
  id,
@@ -101,12 +120,16 @@ export function txtField<T, P extends Path<T>>(
101
120
  }
102
121
  }
103
122
 
104
- export function selectField<T, P extends Path<T>>(
123
+ export function selectField<
124
+ T,
125
+ P extends Path<T, PO>,
126
+ PO extends PathsOptions = DefaultPathsOptions,
127
+ >(
105
128
  id?: P,
106
129
  label?: string,
107
130
  options?: Option[] | (() => Option[]),
108
131
  config?: SlctInputOptions<T, P>,
109
- ): SelectBagelField<T, P> {
132
+ ): SelectBagelField<T, P, PO> {
110
133
  return {
111
134
  $el: 'select',
112
135
  id,
@@ -134,11 +157,15 @@ interface CheckInputOptions<T, K extends Path<T>> extends InputOptions<T, K> {
134
157
  value?: string
135
158
  }
136
159
 
137
- export function checkField<T, P extends Path<T>>(
160
+ export function checkField<
161
+ T,
162
+ P extends Path<T, PO>,
163
+ PO extends PathsOptions = DefaultPathsOptions,
164
+ >(
138
165
  id?: P,
139
166
  label?: string,
140
167
  options?: CheckInputOptions<T, P>,
141
- ): BaseBagelField<T, P> {
168
+ ): BaseBagelField<T, P, PO> {
142
169
  return {
143
170
  $el: 'check',
144
171
  class: options?.class,
@@ -151,14 +178,21 @@ export function checkField<T, P extends Path<T>>(
151
178
  }
152
179
  }
153
180
 
154
- interface EmailInputOptions<T, P extends Path<T>> extends InputOptions<T, P> {
181
+ interface EmailInputOptions<
182
+ T,
183
+ P extends Path<T>
184
+ > extends InputOptions<T, P> {
155
185
  autocorrect?: boolean
156
186
  serverValidate?: boolean
157
187
  preventFakeEmails?: boolean
158
188
  pattern?: string
159
189
  }
160
190
 
161
- export function emailField<T, P extends Path<T>>(id?: P, label?: string, options?: EmailInputOptions<T, P>): BaseBagelField<T, P> {
191
+ export function emailField<
192
+ T,
193
+ P extends Path<T, PO>,
194
+ PO extends PathsOptions = DefaultPathsOptions,
195
+ >(id?: P, label?: string, options?: EmailInputOptions<T, P>): BaseBagelField<T, P, PO> {
162
196
  return {
163
197
  $el: 'email',
164
198
  id,
@@ -175,11 +209,15 @@ export function emailField<T, P extends Path<T>>(id?: P, label?: string, options
175
209
  }
176
210
  }
177
211
 
178
- export function dateField<T, P extends Path<T>>(
212
+ export function dateField<
213
+ T,
214
+ P extends Path<T, PO>,
215
+ PO extends PathsOptions = DefaultPathsOptions,
216
+ >(
179
217
  id?: P,
180
218
  label?: string,
181
219
  options?: DateOptions<T, P>,
182
- ): BaseBagelField<T, P> {
220
+ ): BaseBagelField<T, P, PO> {
183
221
  return {
184
222
  $el: 'date',
185
223
  class: options?.class,
@@ -200,11 +238,15 @@ export function dateField<T, P extends Path<T>>(
200
238
  }
201
239
  }
202
240
 
203
- export function numField<T, P extends Path<T>>(
241
+ export function numField<
242
+ T,
243
+ P extends Path<T, PO>,
244
+ PO extends PathsOptions = DefaultPathsOptions,
245
+ >(
204
246
  id?: P,
205
247
  label?: string,
206
248
  options?: NumFieldOptions<T, P>,
207
- ): BaseBagelField<T, P> {
249
+ ): BaseBagelField<T, P, PO> {
208
250
  return {
209
251
  $el: 'number',
210
252
  class: options?.class,
@@ -229,9 +271,13 @@ export function numField<T, P extends Path<T>>(
229
271
  }
230
272
  }
231
273
 
232
- export function frmRow<T, P extends Path<T>>(
233
- ...children: SchemaChild<T, P>[]
234
- ): FieldByP<T, P> {
274
+ export function frmRow<
275
+ T,
276
+ P extends Path<T, PO>,
277
+ PO extends PathsOptions = DefaultPathsOptions,
278
+ >(
279
+ ...children: SchemaChild<T, P, PO>[]
280
+ ): FieldByP<T, P, PO> {
235
281
  return {
236
282
  $el: 'div',
237
283
  class: 'flex gap-1 m_block align-items-end',
@@ -241,11 +287,15 @@ export function frmRow<T, P extends Path<T>>(
241
287
 
242
288
  export interface UploadOptions<T, K extends Path<T>> extends Omit<UploadInputProps, 'id'>, InputOptions<T, K> {}
243
289
 
244
- export function uploadField<T, P extends Path<T>>(
290
+ export function uploadField<
291
+ T,
292
+ P extends Path<T, PO>,
293
+ PO extends PathsOptions = DefaultPathsOptions,
294
+ >(
245
295
  id?: P,
246
296
  label?: string,
247
297
  options?: UploadOptions<T, P>
248
- ): BaseBagelField<T, P> {
298
+ ): BaseBagelField<T, P, PO> {
249
299
  return {
250
300
  $el: 'upload',
251
301
  id,
@@ -266,11 +316,15 @@ interface RangeOptions<T, K extends Path<T>> extends InputOptions<T, K> {
266
316
  formatValue?: (value: number) => string
267
317
  }
268
318
 
269
- export function rangeField<T, P extends Path<T>>(
319
+ export function rangeField<
320
+ T,
321
+ P extends Path<T, PO>,
322
+ PO extends PathsOptions = DefaultPathsOptions,
323
+ >(
270
324
  id?: P,
271
325
  label?: string,
272
326
  options?: RangeOptions <T, P>
273
- ): BaseBagelField<T, P> {
327
+ ): BaseBagelField<T, P, PO> {
274
328
  return {
275
329
  $el: 'range',
276
330
  id,
@@ -306,11 +360,15 @@ export function bglForm<T>(idOrField?: string | FieldByP<T, Path<T>>, ...schema:
306
360
  }
307
361
  }
308
362
 
309
- export function telField<T, P extends Path<T>>(
363
+ export function telField<
364
+ T,
365
+ P extends Path<T, PO>,
366
+ PO extends PathsOptions = DefaultPathsOptions,
367
+ >(
310
368
  id?: P,
311
369
  label?: string,
312
370
  options?: { [key: string]: any }
313
- ): BaseBagelField<T, P> {
371
+ ): BaseBagelField<T, P, PO> {
314
372
  return {
315
373
  $el: 'tel',
316
374
  id,
@@ -321,11 +379,15 @@ export function telField<T, P extends Path<T>>(
321
379
  }
322
380
  }
323
381
 
324
- export function colorField<T, P extends Path<T>>(
382
+ export function colorField<
383
+ T,
384
+ P extends Path<T, PO>,
385
+ PO extends PathsOptions = DefaultPathsOptions,
386
+ >(
325
387
  id?: P,
326
388
  label?: string,
327
389
  options?: { [key: string]: any }
328
- ): BaseBagelField<T, P> {
390
+ ): BaseBagelField<T, P, PO> {
329
391
  return {
330
392
  $el: 'color',
331
393
  id,
@@ -357,12 +419,16 @@ export interface ArrayFieldOptions<T, K extends Path<T>> extends InputOptions<T,
357
419
 
358
420
  export type ArrayType = 'number' | 'text'
359
421
 
360
- export function arrField<T, P extends Path<T>>(
422
+ export function arrField<
423
+ T,
424
+ P extends Path<T, PO>,
425
+ PO extends PathsOptions = DefaultPathsOptions,
426
+ >(
361
427
  id: P,
362
428
  label: string,
363
429
  schemaOrType: BglFormSchemaT<ArrayFieldVal<T, P>> | ArrayType,
364
430
  options?: ArrayFieldOptions<T, P>
365
- ): BaseBagelField<T, P> {
431
+ ): BaseBagelField<T, P, PO> {
366
432
  const attrs: Attributes<T, P> = { delete: true, add: true, ...options }
367
433
 
368
434
  if (typeof schemaOrType === 'string') {
@@ -400,23 +466,7 @@ export function arrField<T, P extends Path<T>>(
400
466
  // })
401
467
  // }
402
468
 
403
- export function useForm(): {
404
- txtField: typeof txtField
405
- selectField: typeof selectField
406
- checkField: typeof checkField
407
- dateField: typeof dateField
408
- numField: typeof numField
409
- frmRow: typeof frmRow
410
- uploadField: typeof uploadField
411
- rangeField: typeof rangeField
412
- bglForm: typeof bglForm
413
- telField: typeof telField
414
- colorField: typeof colorField
415
- arrField: typeof arrField
416
- richText: typeof richText
417
- findBglFieldById: typeof findBglFieldById
418
- getBaseField: typeof getBaseField
419
- } {
469
+ export function useForm() {
420
470
  return {
421
471
  txtField,
422
472
  selectField,