@@ -3,6 +3,7 @@ import { FormKitSchema } from '@formkit/vue'
3
3
import { ref } from ' vue'
4
4
import { useToast } from ' primevue/usetoast'
5
5
import type { ToastMessageOptions } from ' primevue/toast'
6
+ import { useClipboard } from ' @vueuse/core'
6
7
7
8
import { useInputEditorSchema } from ' my-library'
8
9
@@ -12,7 +13,7 @@ const props = defineProps<{
12
13
data: object
13
14
}>()
14
15
15
- const form2 = ref (0 )
16
+ const schemaResultFormKey = ref (0 )
16
17
17
18
const { editorDataToSchema, editorDataToJson, editorDataToCode } = useInputEditorSchema ()
18
19
@@ -28,19 +29,28 @@ const formData = reactive(props.data)
28
29
const data = ref ({})
29
30
30
31
async function submitHandler() {
31
- showMessage (' success' , ' Form Submitted ...' , ' Input creation completed successfully' )
32
- data .value = { value: formData .value }
33
- form2 .value += 1
32
+ showMessage (' success' , ' Form Submitted' , ' Input creation completed successfully ...' )
34
33
35
- console .log (editorDataToJson (formData ))
36
- console .log (editorDataToCode (formData ))
34
+ data .value = { }
35
+ schemaResultFormKey .value += 1
36
+ Object .assign (formData , { ... formData , schemaResultFormKey: schemaResultFormKey .value })
37
37
}
38
38
39
39
async function submitHandler2() {
40
40
41
41
}
42
42
43
43
const schemaResult = computed (() => editorDataToSchema (formData ))
44
+
45
+ const { copy, isSupported } = useClipboard ({})
46
+
47
+ function copyJson() {
48
+ copy (editorDataToJson (formData ))
49
+ }
50
+
51
+ function copyObject() {
52
+ copy (editorDataToCode (formData ))
53
+ }
44
54
</script >
45
55
46
56
<template >
@@ -50,9 +60,9 @@ const schemaResult = computed(() => editorDataToSchema(formData))
50
60
{{ header }}
51
61
</h2 >
52
62
<slot />
53
- <div class =" flex flex-wrap gap-4 " >
54
- <div class =" min-w-30rem basis-1/2 md:basis-1/3" >
55
- <h3 >Create Formkit Prime Input</h3 >
63
+ <div class =" flex flex-wrap gap-8 " >
64
+ <div class =" min-w-40rem basis-1/2 md:basis-1/3" >
65
+ <h3 >Create Formkit Input</h3 >
56
66
<FormKit
57
67
v-model =" formData"
58
68
type =" form"
@@ -64,11 +74,14 @@ const schemaResult = computed(() => editorDataToSchema(formData))
64
74
>
65
75
<FormKitSchema :schema =" formSchema" :data =" formData" />
66
76
</FormKit >
77
+ <pre v-if =" false" >{{ formSchema }}</pre >
67
78
</div >
68
79
<div class =" " >
69
80
<h3 >Generated Formkit Input Preview</h3 >
70
-
71
- <div :key =" form2" >
81
+ <div class =" mb-4" >
82
+ Some changes require to trigger the update of generated input
83
+ </div >
84
+ <div :key =" schemaResultFormKey" >
72
85
<FormKit
73
86
v-model =" data"
74
87
type =" form"
@@ -79,6 +92,10 @@ const schemaResult = computed(() => editorDataToSchema(formData))
79
92
>
80
93
<FormKitSchema :schema =" schemaResult" :data =" data" />
81
94
</FormKit >
95
+ <div class =" mt-4 mb-4" >
96
+ <h3 >Copy Schema to Clipboard - Supported: {{ isSupported }}</h3 >
97
+ <Button label =" Copy as JSON" class =" mr-4" @click =" copyJson" /><Button label =" Copy as Object" @click =" copyObject" />
98
+ </div >
82
99
<h3 >Generated Formkit Schema</h3 >
83
100
<pre >{{ schemaResult }}</pre >
84
101
<h3 >Generated Formkit Data</h3 >
0 commit comments