@ederzeel/nuxt-schema-form-nightly 0.1.0-29104650.63764c1 → 0.1.0-29104769.df64a23
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 +74 -100
- package/package.json +2 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { Draft2019 } from 'json-schema-library'
|
|
3
3
|
import SComponent from './Component.vue'
|
|
4
|
-
import { ref, computed, h, resolveComponent
|
|
4
|
+
import { ref, computed, h, resolveComponent } from 'vue'
|
|
5
5
|
import type { TableColumn } from '@nuxt/ui'
|
|
6
6
|
import type { Row } from '@tanstack/vue-table'
|
|
7
7
|
|
|
@@ -14,7 +14,7 @@ const props = defineProps<{
|
|
|
14
14
|
description?: string
|
|
15
15
|
jsonSchemaPath: string
|
|
16
16
|
items: PropertiesType
|
|
17
|
-
modelValue: unknown[]
|
|
17
|
+
modelValue: Record<string, unknown>[]
|
|
18
18
|
isRequired: boolean
|
|
19
19
|
minItems?: number
|
|
20
20
|
maxItems?: number
|
|
@@ -22,14 +22,7 @@ const props = defineProps<{
|
|
|
22
22
|
columns?: TableColumn<{}>[]
|
|
23
23
|
editInline?: boolean
|
|
24
24
|
}>()
|
|
25
|
-
|
|
26
|
-
type ColumnItem = {
|
|
27
|
-
key: string
|
|
28
|
-
label?: string
|
|
29
|
-
header?: string
|
|
30
|
-
accessorKey?: string
|
|
31
|
-
class?: string
|
|
32
|
-
}
|
|
25
|
+
const emit = defineEmits(['update:modelValue', 'submit'])
|
|
33
26
|
|
|
34
27
|
type PropertiesType = {
|
|
35
28
|
properties: {
|
|
@@ -37,13 +30,30 @@ type PropertiesType = {
|
|
|
37
30
|
}
|
|
38
31
|
[key: string]: unknown
|
|
39
32
|
}
|
|
40
|
-
const emit = defineEmits(['update:modelValue', 'submit'])
|
|
41
|
-
const onInput = (value: unknown, index: number) => {
|
|
42
|
-
props.modelValue[index] = value
|
|
43
|
-
emit('update:modelValue', props.modelValue)
|
|
44
|
-
}
|
|
45
33
|
|
|
34
|
+
const massActions = [
|
|
35
|
+
[
|
|
36
|
+
{
|
|
37
|
+
label: 'delete',
|
|
38
|
+
click: () => {
|
|
39
|
+
massRemove()
|
|
40
|
+
selectedRows.value = []
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
const selectedRows = ref<{ __id: any }[]>([])
|
|
46
47
|
const schemaObject = ref(new Draft2019(props.items))
|
|
48
|
+
const model = ref<{ open: boolean; index: number; value: Record<string, unknown> }>({
|
|
49
|
+
open: false,
|
|
50
|
+
index: 0,
|
|
51
|
+
value: {}
|
|
52
|
+
})
|
|
53
|
+
const expand = ref({
|
|
54
|
+
openedRows: [],
|
|
55
|
+
row: null
|
|
56
|
+
})
|
|
47
57
|
|
|
48
58
|
const values = computed(() => {
|
|
49
59
|
if (props.modelValue.length > 0) {
|
|
@@ -56,46 +66,6 @@ const values = computed(() => {
|
|
|
56
66
|
return []
|
|
57
67
|
})
|
|
58
68
|
|
|
59
|
-
const add = () => {
|
|
60
|
-
console.log('add')
|
|
61
|
-
emit('update:modelValue', [...props.modelValue, schemaObject.value.getTemplate()])
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const remove = (index: number) => {
|
|
65
|
-
const res = props.modelValue.splice(index, 1)
|
|
66
|
-
emit('update:modelValue', props.modelValue)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const massRemove = () => {
|
|
70
|
-
let res = props.modelValue
|
|
71
|
-
for (const index of selectedRows.value.map(x => x.__id)) {
|
|
72
|
-
res.splice(index, 1)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
emit('update:modelValue', res)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const model = ref({
|
|
79
|
-
open: false,
|
|
80
|
-
index: 0
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
const open = (index: number) => {
|
|
84
|
-
model.value = { open: true, index: index }
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const massActions = [
|
|
88
|
-
[
|
|
89
|
-
{
|
|
90
|
-
label: 'delete',
|
|
91
|
-
click: () => {
|
|
92
|
-
massRemove()
|
|
93
|
-
selectedRows.value = []
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
]
|
|
97
|
-
]
|
|
98
|
-
|
|
99
69
|
const columns = computed<TableColumn<{}>[]>(() => {
|
|
100
70
|
const columns = props.columns ?? []
|
|
101
71
|
if (props.editInline) {
|
|
@@ -175,17 +145,10 @@ function getRowItems(row: Row<{}>) {
|
|
|
175
145
|
]
|
|
176
146
|
}
|
|
177
147
|
|
|
178
|
-
const selectedRows = ref<{ __id: any }[]>([])
|
|
179
|
-
|
|
180
|
-
const expand = ref({
|
|
181
|
-
openedRows: [],
|
|
182
|
-
row: null
|
|
183
|
-
})
|
|
184
|
-
|
|
185
148
|
const options = computed(() => {
|
|
186
149
|
let res: {
|
|
187
150
|
modelValue?: any
|
|
188
|
-
|
|
151
|
+
'onUpdate:modelValue'?: (v: any) => void
|
|
189
152
|
expand?: {
|
|
190
153
|
openedRows: any[]
|
|
191
154
|
row: null
|
|
@@ -195,7 +158,7 @@ const options = computed(() => {
|
|
|
195
158
|
|
|
196
159
|
if (props.edit) {
|
|
197
160
|
res.modelValue = selectedRows.value
|
|
198
|
-
|
|
161
|
+
res['onUpdate:modelValue'] = value => (selectedRows.value = value)
|
|
199
162
|
}
|
|
200
163
|
if (props.editInline) {
|
|
201
164
|
res.expand = expand.value
|
|
@@ -204,6 +167,33 @@ const options = computed(() => {
|
|
|
204
167
|
|
|
205
168
|
return res
|
|
206
169
|
})
|
|
170
|
+
|
|
171
|
+
const open = (index: number) => {
|
|
172
|
+
model.value = { open: true, index: index, value: structuredClone(values.value[index]) }
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const onInput = (value: Record<string, unknown>, index: number) => {
|
|
176
|
+
props.modelValue[index] = value
|
|
177
|
+
emit('update:modelValue', props.modelValue)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const add = () => {
|
|
181
|
+
emit('update:modelValue', [...props.modelValue, schemaObject.value.getTemplate()])
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const remove = (index: number) => {
|
|
185
|
+
props.modelValue.splice(index, 1)
|
|
186
|
+
emit('update:modelValue', props.modelValue)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const massRemove = () => {
|
|
190
|
+
let res = props.modelValue
|
|
191
|
+
for (const index of selectedRows.value.map(x => x.__id)) {
|
|
192
|
+
res.splice(index, 1)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
emit('update:modelValue', res)
|
|
196
|
+
}
|
|
207
197
|
</script>
|
|
208
198
|
|
|
209
199
|
<template>
|
|
@@ -214,15 +204,8 @@ const options = computed(() => {
|
|
|
214
204
|
<div>
|
|
215
205
|
<div class="flex justify-between items-center w-full px-4 py-3">
|
|
216
206
|
<div class="flex gap-1.5 items-center">
|
|
217
|
-
<UButton
|
|
218
|
-
|
|
219
|
-
:disabled="maxItems && values.length >= maxItems"
|
|
220
|
-
@click="add"
|
|
221
|
-
icon="i-heroicons-plus"
|
|
222
|
-
trailing
|
|
223
|
-
color="neutral"
|
|
224
|
-
size="xs"
|
|
225
|
-
/>
|
|
207
|
+
<UButton v-if="edit" :disabled="maxItems && values.length >= maxItems" @click="add" icon="i-heroicons-plus"
|
|
208
|
+
trailing color="neutral" size="xs" />
|
|
226
209
|
</div>
|
|
227
210
|
<div class="flex gap-1.5 items-center">
|
|
228
211
|
<UDropdownMenu v-if="selectedRows.length > 0" :items="massActions">
|
|
@@ -231,21 +214,14 @@ const options = computed(() => {
|
|
|
231
214
|
</div>
|
|
232
215
|
</div>
|
|
233
216
|
<UTable v-bind="options" by="__id" :data="values" :columns="columns" class="flex-1">
|
|
234
|
-
<template #expanded="{ row
|
|
217
|
+
<template #expanded="{ row }">
|
|
218
|
+
{{ row }}
|
|
235
219
|
<div class="p-4">
|
|
236
|
-
{
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
:model-value="row.
|
|
240
|
-
|
|
241
|
-
jsonSchemaPath?.length <= 0 ? `properties.${index}` : `${jsonSchemaPath}[${row.index}]`
|
|
242
|
-
"
|
|
243
|
-
v-bind="items"
|
|
244
|
-
:isRequired="false"
|
|
245
|
-
class="mt-4"
|
|
246
|
-
@update:model-value="(event: unknown) => onInput(event, row.index)"
|
|
247
|
-
@submit="() => emit('submit')"
|
|
248
|
-
/>
|
|
220
|
+
<SComponent :id="id.length <= 0 ? `${row.index}` : `${id}[${row.index}].${items.id}`"
|
|
221
|
+
:model-value="row.original" :json-schema-path="jsonSchemaPath?.length <= 0 ? `properties.${row.index}` : `${jsonSchemaPath}[${row.index}]`
|
|
222
|
+
" v-bind="items" :isRequired="false" class="mt-4"
|
|
223
|
+
@update:model-value="(event: Record<string, unknown>) => onInput(event, row.index)"
|
|
224
|
+
@submit="() => emit('submit')" />
|
|
249
225
|
</div>
|
|
250
226
|
</template>
|
|
251
227
|
</UTable>
|
|
@@ -253,20 +229,18 @@ const options = computed(() => {
|
|
|
253
229
|
<UModal v-model:open="model.open">
|
|
254
230
|
<template #content>
|
|
255
231
|
<UCard>
|
|
256
|
-
<SComponent
|
|
257
|
-
:
|
|
258
|
-
|
|
259
|
-
:
|
|
260
|
-
|
|
261
|
-
"
|
|
262
|
-
v-bind="items"
|
|
263
|
-
:isRequired="false"
|
|
264
|
-
class="mt-4"
|
|
265
|
-
@update:model-value="event => onInput(event, model.index)"
|
|
266
|
-
@submit="() => emit('submit')"
|
|
267
|
-
/>
|
|
232
|
+
<SComponent :id="id.length <= 0 ? `${model.index}` : `${id}[0].${items.id}`" :model-value="model.value"
|
|
233
|
+
:json-schema-path="jsonSchemaPath?.length <= 0 ? `properties.${model.index}` : `${jsonSchemaPath}[${model.index}]`
|
|
234
|
+
" v-bind="items" :isRequired="false" class="mt-4"
|
|
235
|
+
@update:model-value="(event: Record<string, unknown>) => (model.value = event)"
|
|
236
|
+
@submit="() => emit('submit')" />
|
|
268
237
|
<template #footer>
|
|
269
|
-
<UButton
|
|
238
|
+
<UButton @click="
|
|
239
|
+
() => {
|
|
240
|
+
onInput(model.value, model.index)
|
|
241
|
+
model.open = false
|
|
242
|
+
}
|
|
243
|
+
">Save</UButton>
|
|
270
244
|
</template>
|
|
271
245
|
</UCard>
|
|
272
246
|
</template>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ederzeel/nuxt-schema-form-nightly",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-29104769.df64a23",
|
|
4
4
|
"description": "A runtime form generator for nuxt",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"@nuxt/kit": "^3.15.4",
|
|
53
53
|
"@nuxt/module-builder": "^0.8.4",
|
|
54
54
|
"@nuxt/ui": "^3.0.0",
|
|
55
|
+
"@tanstack/vue-table": "^8.21.3",
|
|
55
56
|
"@types/eslint": "^9.6.1",
|
|
56
57
|
"eslint": "^9.19.0",
|
|
57
58
|
"eslint-config-prettier": "^10.0.1",
|