@ederzeel/nuxt-schema-form-nightly 0.1.0-29151062.0dca838 → 0.1.0-29160727.428eb4d
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.
- package/dist/runtime/components/Array.vue +1 -0
- package/dist/runtime/components/Component.vue +3 -0
- package/dist/runtime/components/Form.vue +28 -8
- package/dist/runtime/components/Object.vue +2 -0
- package/dist/runtime/components/array/ArrayObject.vue +79 -44
- package/dist/runtime/index.css +1 -0
- package/package.json +3 -2
|
@@ -35,6 +35,7 @@ export type SComponentProps = {
|
|
|
35
35
|
editInline?: boolean
|
|
36
36
|
columns?: TableColumn<{}>[]
|
|
37
37
|
validateFields?: (fields: string[]) => Promise<boolean>
|
|
38
|
+
setHidden?: (value: boolean) => void
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
const props = withDefaults(defineProps<SComponentProps>(), { id: '', jsonSchemaPath: '' })
|
|
@@ -142,6 +143,7 @@ const Render = () => {
|
|
|
142
143
|
isRequired: props.isRequired,
|
|
143
144
|
jsonSchemaPath: `${props.jsonSchemaPath}.${props.id}`,
|
|
144
145
|
onSubmit,
|
|
146
|
+
setHidden: props.setHidden,
|
|
145
147
|
modelValue: value.value as Record<string, unknown>,
|
|
146
148
|
'onUpdate:modelValue': (v: Record<string, unknown>) => {
|
|
147
149
|
value.value = v
|
|
@@ -163,6 +165,7 @@ const Render = () => {
|
|
|
163
165
|
editInline: props.editInline,
|
|
164
166
|
jsonSchemaPath: `${props.jsonSchemaPath}.${props.id}`,
|
|
165
167
|
onSubmit,
|
|
168
|
+
setHidden: props.setHidden,
|
|
166
169
|
modelValue: value.value as unknown[],
|
|
167
170
|
'onUpdate:modelValue': (v: unknown) => {
|
|
168
171
|
value.value = v as unknown[]
|
|
@@ -58,19 +58,39 @@ const submit = () => {
|
|
|
58
58
|
defineExpose({
|
|
59
59
|
submit
|
|
60
60
|
})
|
|
61
|
+
const isHidden = ref(false)
|
|
62
|
+
const setHidden = (value: boolean) => (isHidden.value = value)
|
|
61
63
|
</script>
|
|
62
64
|
|
|
63
65
|
<template>
|
|
64
66
|
<div>
|
|
65
67
|
<!-- {{ formRef ? formRef.errors : undefined }} -->
|
|
66
|
-
<
|
|
67
|
-
<
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
<div id="test-teleport" class="top-0 w-full h-full">
|
|
69
|
+
<UForm
|
|
70
|
+
class="overflow-auto bg-white"
|
|
71
|
+
ref="formRef"
|
|
72
|
+
:state="value"
|
|
73
|
+
:schema="formValidationSchema"
|
|
74
|
+
autocomplete="on"
|
|
75
|
+
@submit="onSubmit"
|
|
76
|
+
v-show="!isHidden"
|
|
77
|
+
>
|
|
78
|
+
<SComponent
|
|
79
|
+
v-model="value"
|
|
80
|
+
v-bind="schema"
|
|
81
|
+
:validate-fields="validateFields"
|
|
82
|
+
:setHidden="setHidden"
|
|
83
|
+
@submit="submit"
|
|
84
|
+
:isRequired="true"
|
|
85
|
+
/>
|
|
86
|
+
<slot />
|
|
70
87
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
88
|
+
<div class="mt-4 flex gap-2 justify-end">
|
|
89
|
+
<slot name="submit">
|
|
90
|
+
<UButton class="btn mt-4" type="submit"> Submit </UButton>
|
|
91
|
+
</slot>
|
|
92
|
+
</div>
|
|
93
|
+
</UForm>
|
|
94
|
+
</div>
|
|
75
95
|
</div>
|
|
76
96
|
</template>
|
|
@@ -10,6 +10,7 @@ const props = defineProps<{
|
|
|
10
10
|
modelValue: Record<string, unknown>
|
|
11
11
|
required?: string[]
|
|
12
12
|
isRequired: boolean
|
|
13
|
+
setHidden?: (value: boolean) => void
|
|
13
14
|
}>()
|
|
14
15
|
|
|
15
16
|
type PropertiesType = {
|
|
@@ -34,6 +35,7 @@ const onInput = (value: unknown, key: string) => {
|
|
|
34
35
|
:json-schema-path="jsonSchemaPath?.length <= 0 ? `properties.${key}` : `${jsonSchemaPath}.properties.${key}`"
|
|
35
36
|
v-bind="options"
|
|
36
37
|
:isRequired="required ? required.includes(key) : false"
|
|
38
|
+
:setHidden="setHidden"
|
|
37
39
|
class="mt-4"
|
|
38
40
|
@update:model-value="(event: unknown) => onInput(event, key)"
|
|
39
41
|
@submit="() => emit('submit')"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { compileSchema } from 'json-schema-library'
|
|
3
3
|
import SComponent from '../Component.vue'
|
|
4
|
-
import { ref, computed, h, resolveComponent } from 'vue'
|
|
4
|
+
import { ref, toRaw, computed, h, resolveComponent } from 'vue'
|
|
5
5
|
import type { TableColumn } from '@nuxt/ui'
|
|
6
6
|
import type { Row } from '@tanstack/vue-table'
|
|
7
7
|
import type { PropertiesType } from '../../types'
|
|
@@ -23,6 +23,7 @@ const props = defineProps<{
|
|
|
23
23
|
columns?: TableColumn<{}>[]
|
|
24
24
|
editInline?: boolean
|
|
25
25
|
required?: string[]
|
|
26
|
+
setHidden?: (value: boolean) => void
|
|
26
27
|
}>()
|
|
27
28
|
const emit = defineEmits(['update:modelValue', 'submit'])
|
|
28
29
|
|
|
@@ -40,10 +41,9 @@ const massActions = [
|
|
|
40
41
|
|
|
41
42
|
const selectedRows = ref<{ __id: any }[]>([])
|
|
42
43
|
const schemaObject = ref(compileSchema(props.items))
|
|
43
|
-
const model = ref<{
|
|
44
|
-
open: false,
|
|
44
|
+
const model = ref<{ index: number; value: Record<string, unknown> | undefined }>({
|
|
45
45
|
index: 0,
|
|
46
|
-
value:
|
|
46
|
+
value: undefined
|
|
47
47
|
})
|
|
48
48
|
const expand = ref({
|
|
49
49
|
openedRows: [],
|
|
@@ -52,7 +52,7 @@ const expand = ref({
|
|
|
52
52
|
|
|
53
53
|
const values = computed(() => {
|
|
54
54
|
if (props.modelValue.length > 0) {
|
|
55
|
-
return props.modelValue.map((x, i) => ({ ...x, __id: i }))
|
|
55
|
+
return toRaw(props.modelValue).map((x, i) => ({ ...x, __id: i }))
|
|
56
56
|
} else if (props.minItems && props.minItems > 0) {
|
|
57
57
|
const template = schemaObject.value.getData()
|
|
58
58
|
return [...Array(props.minItems)].map((_, i) => ({ ...template, __id: i }))
|
|
@@ -61,8 +61,36 @@ const values = computed(() => {
|
|
|
61
61
|
return []
|
|
62
62
|
})
|
|
63
63
|
|
|
64
|
+
type Entries<T> = {
|
|
65
|
+
[K in keyof T]: [K, T[K]]
|
|
66
|
+
}[keyof T][]
|
|
67
|
+
|
|
68
|
+
const geneateColumnsFromSchema = (items: PropertiesType): TableColumn<{}>[] => {
|
|
69
|
+
if (!items.properties) return []
|
|
70
|
+
const res: TableColumn<{}>[] = (Object.entries(items.properties) as [string, PropertiesType][]).map(
|
|
71
|
+
([key, value]): TableColumn<{}, unknown[]> => {
|
|
72
|
+
if (value.type === 'array') {
|
|
73
|
+
return {
|
|
74
|
+
header: value.title || key,
|
|
75
|
+
accessorKey: key,
|
|
76
|
+
cell: ({ getValue }) => {
|
|
77
|
+
return getValue().length
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
header: value.title || key,
|
|
83
|
+
accessorKey: key
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
) as TableColumn<{}>[]
|
|
87
|
+
|
|
88
|
+
return res
|
|
89
|
+
}
|
|
90
|
+
|
|
64
91
|
const columns = computed<TableColumn<{}>[]>(() => {
|
|
65
|
-
|
|
92
|
+
console.log(geneateColumnsFromSchema(props.items))
|
|
93
|
+
const columns = props.columns ? Array.from(props.columns) : geneateColumnsFromSchema(props.items)
|
|
66
94
|
|
|
67
95
|
if (props.editInline) {
|
|
68
96
|
columns.unshift({
|
|
@@ -80,21 +108,12 @@ const columns = computed<TableColumn<{}>[]>(() => {
|
|
|
80
108
|
onClick: () => row.toggleExpanded()
|
|
81
109
|
})
|
|
82
110
|
})
|
|
83
|
-
|
|
84
|
-
if (!props.columns && props.items.type === 'object') {
|
|
85
|
-
for (const column of Object.keys(props?.items?.properties).map<TableColumn<{}>>(x => ({
|
|
86
|
-
header: x,
|
|
87
|
-
accessorKey: x,
|
|
88
|
-
cell: ({ row }) => row.getValue(x)
|
|
89
|
-
}))) {
|
|
90
|
-
columns.push(column)
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
111
|
}
|
|
94
112
|
|
|
95
113
|
if (props.edit) {
|
|
96
114
|
columns.push({
|
|
97
115
|
id: 'actions',
|
|
116
|
+
rowClass: 'text-right',
|
|
98
117
|
cell: ({ row }) => {
|
|
99
118
|
return h(
|
|
100
119
|
'div',
|
|
@@ -165,6 +184,9 @@ const options = computed(() => {
|
|
|
165
184
|
})
|
|
166
185
|
|
|
167
186
|
const open = (index: number) => {
|
|
187
|
+
console.log('click')
|
|
188
|
+
console.log(values.value[index])
|
|
189
|
+
if (props.setHidden) props.setHidden(true)
|
|
168
190
|
model.value = { open: true, index: index, value: structuredClone(values.value[index]) }
|
|
169
191
|
}
|
|
170
192
|
|
|
@@ -190,6 +212,9 @@ const massRemove = () => {
|
|
|
190
212
|
|
|
191
213
|
emit('update:modelValue', res)
|
|
192
214
|
}
|
|
215
|
+
|
|
216
|
+
const setHiddenSelf = (value: boolean) => (hidden.value = value)
|
|
217
|
+
const hidden = ref(false)
|
|
193
218
|
</script>
|
|
194
219
|
|
|
195
220
|
<template>
|
|
@@ -235,34 +260,44 @@ const massRemove = () => {
|
|
|
235
260
|
</template>
|
|
236
261
|
</UTable>
|
|
237
262
|
</div>
|
|
238
|
-
<
|
|
239
|
-
<
|
|
240
|
-
<
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
:
|
|
245
|
-
|
|
263
|
+
<Teleport to="#test-teleport">
|
|
264
|
+
<div v-if="model.value" v-show="!hidden" class="overflow-auto bg-white" style="background-color: white">
|
|
265
|
+
<SComponent
|
|
266
|
+
:id="id.length <= 0 ? `${model.index}` : `${id}[0]`"
|
|
267
|
+
:model-value="model.value"
|
|
268
|
+
:json-schema-path="
|
|
269
|
+
jsonSchemaPath?.length <= 0 ? `properties.${model.index}` : `${jsonSchemaPath}[${model.index}]`
|
|
270
|
+
"
|
|
271
|
+
v-bind="items"
|
|
272
|
+
:isRequired="false"
|
|
273
|
+
class="mt-4"
|
|
274
|
+
:setHidden="setHiddenSelf"
|
|
275
|
+
@update:model-value="(event: Record<string, unknown>) => (model.value = event)"
|
|
276
|
+
@submit="() => emit('submit')"
|
|
277
|
+
/>
|
|
278
|
+
<div class="mt-4 flex gap-2 justify-end">
|
|
279
|
+
<UButton
|
|
280
|
+
@click="
|
|
281
|
+
() => {
|
|
282
|
+
onInput(model.value, model.index)
|
|
283
|
+
if (props.setHidden) props.setHidden(false)
|
|
284
|
+
model.value = undefined
|
|
285
|
+
}
|
|
246
286
|
"
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
@
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
>
|
|
263
|
-
</template>
|
|
264
|
-
</UCard>
|
|
265
|
-
</template>
|
|
266
|
-
</UModal>
|
|
287
|
+
>Save</UButton
|
|
288
|
+
>
|
|
289
|
+
<UButton
|
|
290
|
+
variant="outline"
|
|
291
|
+
@click="
|
|
292
|
+
() => {
|
|
293
|
+
if (props.setHidden) props.setHidden(false)
|
|
294
|
+
model.value = undefined
|
|
295
|
+
}
|
|
296
|
+
"
|
|
297
|
+
>Cancle</UButton
|
|
298
|
+
>
|
|
299
|
+
</div>
|
|
300
|
+
</div>
|
|
301
|
+
</Teleport>
|
|
267
302
|
</div>
|
|
268
303
|
</template>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@source "./components";
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ederzeel/nuxt-schema-form-nightly",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-29160727.428eb4d",
|
|
4
4
|
"description": "A runtime form generator for nuxt",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
8
|
"types": "./dist/module.d.ts",
|
|
9
9
|
"import": "./dist/module.mjs",
|
|
10
|
-
"require": "./dist/module.cjs"
|
|
10
|
+
"require": "./dist/module.cjs",
|
|
11
|
+
"style": "./dist/runtime/index.css"
|
|
11
12
|
},
|
|
12
13
|
"./utils/*": {
|
|
13
14
|
"types": "./dist/runtime/utils/*.d.ts",
|