@ederzeel/nuxt-schema-form-nightly 0.1.0-29150768.3ab740d → 0.1.0-29160663.c20ef12

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.
@@ -10,7 +10,7 @@ const props = defineProps<{
10
10
  title?: string
11
11
  description?: string
12
12
  jsonSchemaPath: string
13
- items: PropertiesType
13
+ items: PropertiesType & { required?: string[] }
14
14
  isRequired: boolean
15
15
  minItems?: number
16
16
  maxItems?: number
@@ -19,6 +19,7 @@ const props = defineProps<{
19
19
  editInline?: boolean
20
20
  modelValue: unknown[]
21
21
  required?: string[]
22
+ setHidden?: (value: boolean) => void
22
23
  }>()
23
24
 
24
25
  const emit = defineEmits(['update:modelValue', 'submit'])
@@ -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
- <UForm ref="formRef" :state="value" :schema="formValidationSchema" autocomplete="on" @submit="onSubmit">
67
- <SComponent v-model="value" v-bind="schema" :validate-fields="validateFields" @submit="submit"
68
- :isRequired="true" />
69
- <slot />
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
- <slot name="submit">
72
- <UButton class="btn mt-4" type="submit"> Submit </UButton>
73
- </slot>
74
- </UForm>
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>
@@ -8,8 +8,9 @@ const props = defineProps<{
8
8
  jsonSchemaPath: string
9
9
  properties: PropertiesType
10
10
  modelValue: Record<string, unknown>
11
- required: string[]
11
+ required?: string[]
12
12
  isRequired: boolean
13
+ setHidden?: (value: boolean) => void
13
14
  }>()
14
15
 
15
16
  type PropertiesType = {
@@ -33,7 +34,8 @@ const onInput = (value: unknown, key: string) => {
33
34
  :model-value="modelValue[key]"
34
35
  :json-schema-path="jsonSchemaPath?.length <= 0 ? `properties.${key}` : `${jsonSchemaPath}.properties.${key}`"
35
36
  v-bind="options"
36
- :isRequired="required.includes(key)"
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<{ open: boolean; index: number; value: Record<string, unknown> }>({
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
- const columns = props.columns ? Array.from(props.columns) : []
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,16 +108,6 @@ 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) {
@@ -165,6 +183,9 @@ const options = computed(() => {
165
183
  })
166
184
 
167
185
  const open = (index: number) => {
186
+ console.log('click')
187
+ console.log(values.value[index])
188
+ if (props.setHidden) props.setHidden(true)
168
189
  model.value = { open: true, index: index, value: structuredClone(values.value[index]) }
169
190
  }
170
191
 
@@ -190,6 +211,9 @@ const massRemove = () => {
190
211
 
191
212
  emit('update:modelValue', res)
192
213
  }
214
+
215
+ const setHiddenSelf = (value: boolean) => (hidden.value = value)
216
+ const hidden = ref(false)
193
217
  </script>
194
218
 
195
219
  <template>
@@ -235,34 +259,44 @@ const massRemove = () => {
235
259
  </template>
236
260
  </UTable>
237
261
  </div>
238
- <UModal v-model:open="model.open">
239
- <template #content>
240
- <UCard>
241
- <SComponent
242
- :id="id.length <= 0 ? `${model.index}` : `${id}[0]`"
243
- :model-value="model.value"
244
- :json-schema-path="
245
- jsonSchemaPath?.length <= 0 ? `properties.${model.index}` : `${jsonSchemaPath}[${model.index}]`
262
+ <Teleport to="#test-teleport">
263
+ <div v-if="model.value" v-show="!hidden" class="overflow-auto bg-white" style="background-color: white">
264
+ <SComponent
265
+ :id="id.length <= 0 ? `${model.index}` : `${id}[0]`"
266
+ :model-value="model.value"
267
+ :json-schema-path="
268
+ jsonSchemaPath?.length <= 0 ? `properties.${model.index}` : `${jsonSchemaPath}[${model.index}]`
269
+ "
270
+ v-bind="items"
271
+ :isRequired="false"
272
+ class="mt-4"
273
+ :setHidden="setHiddenSelf"
274
+ @update:model-value="(event: Record<string, unknown>) => (model.value = event)"
275
+ @submit="() => emit('submit')"
276
+ />
277
+ <div class="mt-4 flex gap-2 justify-end">
278
+ <UButton
279
+ @click="
280
+ () => {
281
+ onInput(model.value, model.index)
282
+ if (props.setHidden) props.setHidden(false)
283
+ model.value = undefined
284
+ }
246
285
  "
247
- v-bind="items"
248
- :isRequired="false"
249
- class="mt-4"
250
- @update:model-value="(event: Record<string, unknown>) => (model.value = event)"
251
- @submit="() => emit('submit')"
252
- />
253
- <template #footer>
254
- <UButton
255
- @click="
256
- () => {
257
- onInput(model.value, model.index)
258
- model.open = false
259
- }
260
- "
261
- >Save</UButton
262
- >
263
- </template>
264
- </UCard>
265
- </template>
266
- </UModal>
286
+ >Save</UButton
287
+ >
288
+ <UButton
289
+ variant="outline"
290
+ @click="
291
+ () => {
292
+ if (props.setHidden) props.setHidden(false)
293
+ model.value = undefined
294
+ }
295
+ "
296
+ >Cancle</UButton
297
+ >
298
+ </div>
299
+ </div>
300
+ </Teleport>
267
301
  </div>
268
302
  </template>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ederzeel/nuxt-schema-form-nightly",
3
- "version": "0.1.0-29150768.3ab740d",
3
+ "version": "0.1.0-29160663.c20ef12",
4
4
  "description": "A runtime form generator for nuxt",
5
5
  "type": "module",
6
6
  "exports": {