@@ -3,6 +3,7 @@ import { FormKitSchema } from '@formkit/vue'
33import { ref } from ' vue'
44import { useToast } from ' primevue/usetoast'
55import type { ToastMessageOptions } from ' primevue/toast'
6+ import { useClipboard } from ' @vueuse/core'
67
78import { useInputEditorSchema } from ' my-library'
89
@@ -12,7 +13,7 @@ const props = defineProps<{
1213 data: object
1314}>()
1415
15- const form2 = ref (0 )
16+ const schemaResultFormKey = ref (0 )
1617
1718const { editorDataToSchema, editorDataToJson, editorDataToCode } = useInputEditorSchema ()
1819
@@ -28,19 +29,28 @@ const formData = reactive(props.data)
2829const data = ref ({})
2930
3031async 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 ...' )
3433
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 })
3737}
3838
3939async function submitHandler2() {
4040
4141}
4242
4343const 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+ }
4454 </script >
4555
4656<template >
@@ -50,9 +60,9 @@ const schemaResult = computed(() => editorDataToSchema(formData))
5060 {{ header }}
5161 </h2 >
5262 <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 >
5666 <FormKit
5767 v-model =" formData"
5868 type =" form"
@@ -64,11 +74,14 @@ const schemaResult = computed(() => editorDataToSchema(formData))
6474 >
6575 <FormKitSchema :schema =" formSchema" :data =" formData" />
6676 </FormKit >
77+ <pre v-if =" false" >{{ formSchema }}</pre >
6778 </div >
6879 <div class =" " >
6980 <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" >
7285 <FormKit
7386 v-model =" data"
7487 type =" form"
@@ -79,6 +92,10 @@ const schemaResult = computed(() => editorDataToSchema(formData))
7992 >
8093 <FormKitSchema :schema =" schemaResult" :data =" data" />
8194 </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 >
8299 <h3 >Generated Formkit Schema</h3 >
83100 <pre >{{ schemaResult }}</pre >
84101 <h3 >Generated Formkit Data</h3 >
0 commit comments