@bagelink/vue 0.0.1145 → 0.0.1151

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 (53) hide show
  1. package/dist/components/DataPreview.vue.d.ts +12 -35
  2. package/dist/components/DataPreview.vue.d.ts.map +1 -1
  3. package/dist/components/DataTable/DataTable.vue.d.ts +1 -1
  4. package/dist/components/DataTable/DataTable.vue.d.ts.map +1 -1
  5. package/dist/components/DataTable/useTableData.d.ts +10 -2
  6. package/dist/components/DataTable/useTableData.d.ts.map +1 -1
  7. package/dist/components/Draggable/Draggable.vue.d.ts +45 -0
  8. package/dist/components/Draggable/Draggable.vue.d.ts.map +1 -0
  9. package/dist/components/Draggable/index.d.ts +5 -0
  10. package/dist/components/Draggable/index.d.ts.map +1 -0
  11. package/dist/components/Draggable/useDraggable.d.ts +31 -0
  12. package/dist/components/Draggable/useDraggable.d.ts.map +1 -0
  13. package/dist/components/Draggable/vDraggable.d.ts +4 -0
  14. package/dist/components/Draggable/vDraggable.d.ts.map +1 -0
  15. package/dist/components/ListView.vue.d.ts.map +1 -1
  16. package/dist/components/form/BagelForm.vue.d.ts.map +1 -1
  17. package/dist/components/form/FieldArray.vue.d.ts.map +1 -1
  18. package/dist/components/form/index.d.ts +0 -1
  19. package/dist/components/form/index.d.ts.map +1 -1
  20. package/dist/components/form/inputs/FileUpload.vue.d.ts +3 -0
  21. package/dist/components/form/inputs/FileUpload.vue.d.ts.map +1 -1
  22. package/dist/components/form/inputs/NumberInput.vue.d.ts.map +1 -1
  23. package/dist/components/form/inputs/Upload/UploadInput.vue.d.ts +3 -0
  24. package/dist/components/form/inputs/Upload/UploadInput.vue.d.ts.map +1 -1
  25. package/dist/components/index.d.ts +2 -0
  26. package/dist/components/index.d.ts.map +1 -1
  27. package/dist/composables/useSchemaField.d.ts +15 -0
  28. package/dist/composables/useSchemaField.d.ts.map +1 -0
  29. package/dist/index.cjs +1256 -802
  30. package/dist/index.mjs +1258 -804
  31. package/dist/style.css +272 -285
  32. package/package.json +1 -1
  33. package/src/components/DataPreview.vue +45 -116
  34. package/src/components/DataTable/DataTable.vue +18 -12
  35. package/src/components/DataTable/useTableData.ts +50 -16
  36. package/src/components/Draggable/Draggable.vue +64 -0
  37. package/src/components/Draggable/index.ts +4 -0
  38. package/src/components/Draggable/useDraggable.ts +632 -0
  39. package/src/components/Draggable/vDraggable.ts +17 -0
  40. package/src/components/ListView.vue +6 -2
  41. package/src/components/Pill.vue +1 -1
  42. package/src/components/form/BagelForm.vue +16 -101
  43. package/src/components/form/FieldArray.vue +45 -17
  44. package/src/components/form/index.ts +0 -1
  45. package/src/components/form/inputs/FileUpload.vue +10 -6
  46. package/src/components/form/inputs/NumberInput.vue +3 -1
  47. package/src/components/form/inputs/RichText/index.vue +1 -1
  48. package/src/components/form/inputs/Upload/UploadInput.vue +12 -7
  49. package/src/components/index.ts +5 -1
  50. package/src/composables/useSchemaField.ts +193 -0
  51. package/src/styles/text.css +15 -11
  52. package/src/components/form/BglField.vue +0 -132
  53. package/src/components/form/BglForm.vue +0 -157
@@ -1,132 +0,0 @@
1
- <script setup lang="ts" generic="T extends Record<string, any>">
2
- import type { Field, BagelFormState } from '@bagelink/vue'
3
- import {
4
- CheckInput,
5
- DateInput,
6
- FieldArray,
7
-
8
- FileUpload,
9
- RichText,
10
- SelectInput,
11
- TextInput,
12
- ToggleInput,
13
- bindAttrs,
14
- classify,
15
- NumberInput,
16
- UploadInput,
17
-
18
- BglForm
19
- } from '@bagelink/vue'
20
- import { inject } from 'vue'
21
- import TabsNav from '../layout/TabsNav.vue'
22
- import { FORM_STATE_KEY, provideBagelFormState } from './useBagelFormState'
23
-
24
- const props = defineProps<{
25
- field: Field<T>
26
- fieldID?: string
27
- modelValue?: any
28
- parentPath?: string
29
- }>()
30
-
31
- const emit = defineEmits<{
32
- 'update:modelValue': [value: any]
33
- }>()
34
-
35
- const formState = inject<BagelFormState<T>>(FORM_STATE_KEY) ?? provideBagelFormState(props.modelValue)
36
-
37
- const customAttrs = $ref<{ [key: string]: any }>({})
38
-
39
- const is = $computed(() => {
40
- if (props.field.$el === 'text') return TextInput
41
- if (props.field.$el === 'textarea') {
42
- customAttrs.multiline = true
43
- return TextInput
44
- }
45
- if (props.field.$el === 'number') return NumberInput
46
- if (props.field.$el === 'array') return FieldArray
47
- if (props.field.$el === 'select') return SelectInput
48
- if (props.field.$el === 'toggle') return ToggleInput
49
- if (props.field.$el === 'check') return CheckInput
50
- if (props.field.$el === 'richtext') return RichText
51
- if (props.field.$el === 'upload') return UploadInput
52
- if (props.field.$el === 'file') return FileUpload
53
- if (props.field.$el === 'date') return DateInput
54
- if (props.field.$el === 'tabs') return TabsNav
55
- if (props.field.$el === 'bglform') return BglForm
56
- return props.field.$el ?? 'div'
57
- })
58
-
59
- const fieldData = $computed({
60
- get: () => {
61
- if (!props.fieldID) return props.field.defaultValue ?? (props.field.$el === 'form' ? {} : '')
62
- const value = formState.getFieldData(props.fieldID)
63
- if (props.field.$el === 'form' && !value) return {}
64
- return value ?? ''
65
- },
66
- set: (val: any) => {
67
- if (!props.fieldID) return
68
- const currentValue = formState.getFieldData(props.fieldID)
69
- if (JSON.stringify(val) === JSON.stringify(currentValue)) return
70
-
71
- emit('update:modelValue', val)
72
- if (props.field.onUpdate) {
73
- props.field.onUpdate(val, currentValue)
74
- }
75
- formState.updateField(props.fieldID, val)
76
- }
77
- })
78
-
79
- const vIf = $computed(() => {
80
- if (props.field['v-if'] === undefined && props.field.vIf === undefined) return true
81
- if (typeof props.field['v-if'] === 'boolean' || typeof props.field.vIf === 'boolean') return props.field['v-if']
82
- if (typeof props.field['v-if'] === 'string' || typeof props.field.vIf === 'string') return true
83
- if (typeof props.field['v-if'] === 'function') return props.field['v-if'](fieldData, formState.data.value as T)
84
- if (typeof props.field.vIf === 'function') return props.field.vIf(fieldData, formState.data.value as T)
85
- return true
86
- })
87
-
88
- // const computedFieldData = $computed(
89
- // () => props.field.transform?.(fieldData, formState.data.value as T) ?? fieldData
90
- // )
91
-
92
- const computedOptions = $computed(
93
- () => bindAttrs({ options: props.field.options }, fieldData, formState.data.value).options
94
- )
95
-
96
- const computedAttrs = $computed(() => {
97
- const attrs = { ...customAttrs, ...props.field.attrs }
98
- return bindAttrs(attrs, fieldData, formState.data.value)
99
- })
100
-
101
- const computedClass = $computed(
102
- () => classify(fieldData, formState.data.value, props.field.class, props.field.attrs?.class)
103
- )
104
- </script>
105
-
106
- <template>
107
- <component
108
- v-bind="computedAttrs"
109
- :is="is"
110
- v-if="vIf"
111
- v-model="fieldData"
112
- :fieldID="props.fieldID"
113
- :required="field.required"
114
- :class="computedClass"
115
- :label="field.label"
116
- :placeholder="field.placeholder || field.label"
117
- :defaultValue="field.defaultValue"
118
- :disabled="field.disabled"
119
- :options="computedOptions"
120
- :helptext="field.helptext"
121
- >
122
- <template v-for="(child, ii) in field.children" :key="ii">
123
- <BglField
124
- v-if="(typeof child !== 'string')"
125
- :fieldID="[props.fieldID, child.id].filter(Boolean).join('.')"
126
- :field="child"
127
- :parent-path="props.fieldID"
128
- />
129
- <span v-else>{{ child }}</span>
130
- </template>
131
- </component>
132
- </template>
@@ -1,157 +0,0 @@
1
- <script lang="ts" setup>
2
- import type { BglFormSchemaFnT } from '@bagelink/vue'
3
- import type { BagelFormState } from './useBagelFormState'
4
- import { BglField, Title, useBglSchema, useModal } from '@bagelink/vue'
5
- import { inject, useSlots, watch } from 'vue'
6
- import { FORM_STATE_KEY, provideBagelFormState } from './useBagelFormState'
7
-
8
- export type FormStatus = 'idle' | 'loading' | 'success' | 'error'
9
-
10
- const props = withDefaults(
11
- defineProps<{
12
- label?: string
13
- fieldID?: string
14
- schema: BglFormSchemaFnT<any>
15
- modelValue?: { [key: string]: any }
16
- onDelete?: (id: string) => void
17
- onSubmit?: (data: any) => void
18
- status?: FormStatus
19
- tag?: 'template' | 'form'
20
- }>(),
21
- {
22
- modelValue: () => ({}),
23
- tag: 'form',
24
- },
25
- )
26
-
27
- const emit = defineEmits(['update:modelValue', 'submit', 'dirty'])
28
-
29
- const slots = useSlots() as any
30
- const { showModal } = useModal()
31
-
32
- // Check if we're a nested form
33
- const existingFormState = inject<BagelFormState | undefined>(FORM_STATE_KEY)
34
- const isNested = Boolean(existingFormState && props.fieldID)
35
-
36
- // Only provide new form state if we're not nested
37
- const { data, isDirty } = isNested
38
- ? existingFormState!
39
- : provideBagelFormState(props.modelValue)
40
-
41
- let emitDirty = $ref(false)
42
-
43
- if (!isNested) {
44
- watch(() => props.modelValue, (newVal) => {
45
- if (emitDirty) {
46
- emitDirty = false
47
- return
48
- }
49
- data.value = newVal
50
- }, { deep: true, immediate: true })
51
-
52
- watch(() => data.value, (newVal) => {
53
- if (emitDirty) return
54
- emitDirty = true
55
- emit('dirty')
56
- emit('update:modelValue', newVal)
57
- }, { deep: true })
58
- }
59
-
60
- const form = $ref<HTMLFormElement>()
61
-
62
- function validateForm() {
63
- setTimeout(() => form?.reportValidity(), 300)
64
- if (!form) return false
65
- return form.reportValidity()
66
- }
67
-
68
- function clearForm() {
69
- if (!isNested) {
70
- data.value = {}
71
- }
72
- }
73
-
74
- watch(
75
- () => props.status,
76
- (status) => {
77
- if (status === 'success' && !isNested) {
78
- isDirty.value = false
79
- clearForm()
80
- }
81
- },
82
- { immediate: true },
83
- )
84
-
85
- function runSubmit() {
86
- const isValid = validateForm()
87
- if (!isValid) return
88
- emit('submit', { ...data.value })
89
- if (!isNested) {
90
- isDirty.value = false
91
- }
92
- }
93
-
94
- const i18nT = (val: string) => val
95
-
96
- function deleteItem() {
97
- showModal(
98
- {
99
- class: 'small-modal',
100
- title: i18nT('Are you sure?'),
101
- actions: [
102
- {
103
- value: 'Confirm',
104
- color: 'red',
105
- onClick: () => props.onDelete?.(data.value.id),
106
- },
107
- { value: 'Cancel', color: 'gray' },
108
- ],
109
- },
110
- { default: i18nT('form.deleteMessage') },
111
- )
112
- }
113
-
114
- const computedSchema = $computed(() => useBglSchema({ schema: props.schema }))
115
-
116
- defineExpose({
117
- submit: runSubmit,
118
- validateForm,
119
- deleteItem,
120
- isDirty,
121
- clearForm,
122
- })
123
- </script>
124
-
125
- <template>
126
- <template v-if="tag === 'template'">
127
- <BglField
128
- v-for="(field, i) in computedSchema"
129
- :key="field.id || `${i}p`"
130
- :fieldID="field.id"
131
- :field="field"
132
- />
133
- <slot name="submit" :submit="runSubmit" :isDirty="isDirty" :validateForm="validateForm" />
134
- </template>
135
- <form
136
- v-else-if="!slots.success || status !== 'success'"
137
- ref="form"
138
- @submit.prevent="runSubmit"
139
- >
140
- <Title v-if="label" tag="h4" :label="label" />
141
- <BglField
142
- v-for="(field, i) in computedSchema"
143
- :key="field.id || `${i}p`"
144
- :fieldID="field.id"
145
- :field="field"
146
- />
147
- <slot name="submit" :submit="runSubmit" :isDirty="isDirty" :validateForm="validateForm" />
148
- </form>
149
- <slot v-if="status === 'success'" name="success" />
150
- <slot v-if="status === 'error'" name="error" />
151
- </template>
152
-
153
- <style>
154
- .del-top {
155
- transform: translateY(-2.6rem);
156
- }
157
- </style>