@bagelink/vue 1.4.134 → 1.4.139

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.
@@ -67,20 +67,29 @@ export type OpenEndedPath<T> =
67
67
  : never
68
68
  : never
69
69
 
70
+ // Helper type to check if a type has ONLY index signature (no specific keys)
71
+ type HasOnlyIndexSignature<T> = T extends Record<string, any>
72
+ ? string extends keyof T
73
+ ? Record<string, never> extends Pick<T, Exclude<keyof T, string | number>>
74
+ ? true // Only index signature, no specific keys
75
+ : false // Has specific keys
76
+ : false
77
+ : false
78
+
79
+ // Helper type to get paths for index signature properties
80
+ type IndexSignaturePaths<T> = {
81
+ [K in keyof T]: T[K] extends { [key: string]: any }
82
+ ? T[K] extends { [key: string]: infer V }
83
+ ? `${K & string}.${string}`
84
+ : never
85
+ : never
86
+ }[keyof T]
87
+
70
88
  // Enhanced Path type that allows flexibility for nested open-ended objects
71
89
  export type Path<T, PO extends PathsOptions = DefaultPathsOptions> =
72
90
  FieldVal<T, _Path<T, PO>> extends Array<any>
73
91
  ? LiteralStringUnion<_Path<T, PO>>
74
- : _Path<T, PO> | (
75
- // Allow nested paths for properties that have index signatures
76
- keyof T extends infer K ?
77
- K extends keyof T ?
78
- T[K] extends { [key: string]: any } ?
79
- `${K & string}.${string}`
80
- : never
81
- : never
82
- : never
83
- )
92
+ : _Path<T, PO> | IndexSignaturePaths<T> | `${keyof T & string}.more_info.${string}`
84
93
 
85
94
  // Smart field value type that preserves type information when possible
86
95
  export type SmartFieldVal<T, P extends Path<T>> =
@@ -164,18 +173,23 @@ export interface ElementField<
164
173
  children?: ElementField<T, PO>[]
165
174
  }
166
175
 
176
+ // Helper type to extract all possible BaseBagelField types for valid paths
177
+ type ValidBaseBagelField<T, PO extends PathsOptions = DefaultPathsOptions> = {
178
+ [P in Path<T, PO>]: BaseBagelField<T, P, PO>
179
+ }[Path<T, PO>]
180
+
167
181
  export type SchemaChild<
168
182
  T,
169
183
  P extends Path<T, PO>,
170
184
  PO extends PathsOptions = DefaultPathsOptions,
171
- > = Field<T, PO> | ElementField<T, PO> | VNode | VNodeFn<T, P> | string | BaseBagelField<T, P, PO>
185
+ > = Field<T, PO> | ElementField<T, PO> | VNode | VNodeFn<T, P> | string | ValidBaseBagelField<T, PO>
172
186
 
173
187
  export interface BaseBagelField<
174
188
  T,
175
189
  P extends Path<T, PO>,
176
190
  PO extends PathsOptions = DefaultPathsOptions,
177
191
  > {
178
- '$el'?: any
192
+ '$el'?: string | any
179
193
  'id'?: P
180
194
  'label'?: string
181
195
  'placeholder'?: string
@@ -12,11 +12,15 @@ import type {
12
12
  Attributes,
13
13
  BglFormSchemaT,
14
14
  FieldByP,
15
- SchemaChild,
16
15
  ShallowBglFormSchemaT,
17
16
  UploadInputProps
18
17
  } from '../types/BagelForm'
19
18
 
19
+ // Import ValidBaseBagelField from the types file
20
+ type ValidBaseBagelField<T, PO extends import('type-fest/source/paths').PathsOptions = import('type-fest/source/paths').DefaultPathsOptions> = {
21
+ [P in Path<T, PO>]: BaseBagelField<T, P, PO>
22
+ }[Path<T, PO>]
23
+
20
24
  // Local type definitions for internal use only
21
25
  interface IconType { name: string }
22
26
  interface AutoFillField { name: string }
@@ -70,6 +74,11 @@ export interface RichTextOptions<T, P extends Path<T>> extends InputOptions<T, P
70
74
  height?: number | string
71
75
  }
72
76
 
77
+ export interface TelInputOptions<T, P extends Path<T>> extends InputOptions<T, P> {
78
+ pattern?: string
79
+ autocomplete?: AutoFillField
80
+ }
81
+
73
82
  export function getBaseField<T, P extends Path<T, PO>, PO extends PathsOptions = DefaultPathsOptions>(
74
83
  id?: P,
75
84
  labelOrRest: string | Partial<BaseBagelField<T, P>> = {},
@@ -308,8 +317,8 @@ export function frmRow<
308
317
  T,
309
318
  PO extends PathsOptions = DefaultPathsOptions,
310
319
  >(
311
- ...children: SchemaChild<T, Path<T, PO>, PO>[]
312
- ): { $el: string, class: string, children: SchemaChild<T, Path<T, PO>, PO>[] } {
320
+ ...children: Array<BaseBagelField<T, any, PO>>
321
+ ): { $el: string, class: string, children: Array<BaseBagelField<T, any, PO>> } {
313
322
  return {
314
323
  $el: 'div',
315
324
  class: 'flex gap-1 m_block align-items-end',
@@ -406,16 +415,25 @@ export function telField<
406
415
  >(
407
416
  id?: P,
408
417
  label?: string,
409
- options?: { [key: string]: any }
418
+ options?: TelInputOptions<T, P>
410
419
  ): BaseBagelField<T, P, PO> {
411
420
  return {
412
421
  $el: 'tel',
413
422
  id,
414
423
  label,
415
- vIf: options?.vIf,
416
- attrs: options,
417
424
  class: options?.class,
425
+ required: options?.required,
426
+ placeholder: options?.placeholder,
427
+ helptext: options?.helptext,
428
+ disabled: options?.disabled,
429
+ defaultValue: options?.defaultValue,
430
+ vIf: options?.vIf,
418
431
  transform: options?.transform,
432
+ attrs: {
433
+ ...options?.attrs,
434
+ pattern: options?.pattern,
435
+ autocomplete: options?.autocomplete,
436
+ },
419
437
  }
420
438
  }
421
439
 
@@ -517,6 +535,77 @@ export function arrField<
517
535
  // })
518
536
  // }
519
537
 
538
+ // Schema builder function that provides type context
539
+ export function createSchema<T, PO extends PathsOptions = DefaultPathsOptions>() {
540
+ return {
541
+ txtField: <P extends Path<T, PO>>(
542
+ id?: P,
543
+ label?: string,
544
+ options?: TextInputOptions<T, P>
545
+ ) => txtField<T, P, PO>(id, label, options),
546
+
547
+ selectField: <P extends Path<T, PO>>(
548
+ id?: P,
549
+ label?: string,
550
+ options?: any,
551
+ fieldOptions?: SlctInputOptions<T, P>
552
+ ) => selectField<T, P, PO>(id, label, options, fieldOptions),
553
+
554
+ dateField: <P extends Path<T, PO>>(
555
+ id?: P,
556
+ label?: string,
557
+ options?: DateOptions<T, P>
558
+ ) => dateField<T, P, PO>(id, label, options),
559
+
560
+ telField: <P extends Path<T, PO>>(
561
+ id?: P,
562
+ label?: string,
563
+ options?: TelInputOptions<T, P>
564
+ ) => telField<T, P, PO>(id, label, options),
565
+
566
+ frmRow: (
567
+ ...children: Array<BaseBagelField<T, any, PO>>
568
+ ) => frmRow<T, PO>(...children),
569
+
570
+ // Add other field functions as needed
571
+ numField: <P extends Path<T, PO>>(
572
+ id?: P,
573
+ label?: string,
574
+ options?: NumFieldOptions<T, P>
575
+ ) => numField<T, P, PO>(id, label, options),
576
+
577
+ checkField: <P extends Path<T, PO>>(
578
+ id?: P,
579
+ label?: string,
580
+ options?: CheckInputOptions<T, P>
581
+ ) => checkField<T, P, PO>(id, label, options),
582
+
583
+ emailField: <P extends Path<T, PO>>(
584
+ id?: P,
585
+ label?: string,
586
+ options?: EmailInputOptions<T, P>
587
+ ) => emailField<T, P, PO>(id, label, options),
588
+
589
+ uploadField: <P extends Path<T, PO>>(
590
+ id?: P,
591
+ label?: string,
592
+ options?: UploadOptions<T, P>
593
+ ) => uploadField<T, P, PO>(id, label, options),
594
+
595
+ rangeField: <P extends Path<T, PO>>(
596
+ id?: P,
597
+ label?: string,
598
+ options?: RangeOptions<T, P>
599
+ ) => rangeField<T, P, PO>(id, label, options),
600
+
601
+ colorField: <P extends Path<T, PO>>(
602
+ id?: P,
603
+ label?: string,
604
+ options?: { [key: string]: any }
605
+ ) => colorField<T, P, PO>(id, label, options),
606
+ }
607
+ }
608
+
520
609
  export function useForm() {
521
610
  return {
522
611
  txtField,
@@ -534,6 +623,7 @@ export function useForm() {
534
623
  arrField,
535
624
  richText,
536
625
  findBglFieldById,
537
- getBaseField
626
+ getBaseField,
627
+ createSchema
538
628
  }
539
629
  }
@@ -62,7 +62,7 @@ export function bindAttrs<T, P extends Path<T>>(
62
62
  // TODO: Fix this so that you don't have to return a fn for other on* event handlers
63
63
  if (!attrs) return {}
64
64
 
65
- const exclude = ['class', 'onClick'] as const
65
+ const exclude = ['class', 'onClick', '$el'] as const
66
66
  const arr = Object.entries(attrs)
67
67
  .filter(([key]) => !exclude.includes(key as typeof exclude[number]))
68
68
  .map(([key, value]) => [