Skip to content

Commit be8ff8c

Browse files
committed
feat(schema): editor output tuning
1 parent c4226b6 commit be8ff8c

File tree

8 files changed

+668
-628
lines changed

8 files changed

+668
-628
lines changed

dev/components/app/AppTopbar.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ const items = ref([
119119
<template #center>
120120
<div class="text-lg">
121121
<span class="text-yellow-600 font-bold">New: </span>
122-
<router-link to="/samples/repeater" class="">
123-
<span class="">Repeater</span>
122+
<router-link to="/samples/inputEditor" class="">
123+
<span class="">Prime Input Editor</span>
124124
</router-link>
125125
</div>
126126
</template>

dev/components/demo/PrimeSchemaEditor.vue

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { FormKitSchema } from '@formkit/vue'
33
import { ref } from 'vue'
44
import { useToast } from 'primevue/usetoast'
55
import type { ToastMessageOptions } from 'primevue/toast'
6+
import { useClipboard } from '@vueuse/core'
67
78
import { 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
1718
const { editorDataToSchema, editorDataToJson, editorDataToCode } = useInputEditorSchema()
1819
@@ -28,19 +29,28 @@ const formData = reactive(props.data)
2829
const data = ref({})
2930
3031
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 ...')
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
3939
async function submitHandler2() {
4040
4141
}
4242
4343
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+
}
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>

dev/pages/inputs/InputText.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const schema
2727
label: 'Icon Right (Disabled)',
2828
help: 'Right Icon Demo',
2929
icon: 'pi pi-check',
30+
iconPosition: 'right',
3031
disabled: true,
3132
},
3233

dev/pages/samples/InputEditor.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
<script setup lang='ts'>
2-
import { useInputEditorSchema } from 'my-library'
2+
import { useFormKitSchema, useInputEditorSchema } from 'my-library'
33
44
const { editorSchema, schemaToEditorData } = useInputEditorSchema()
5+
const { addListGroupFunctions } = useFormKitSchema()
56
6-
const data1 = reactive(schemaToEditorData({
7+
const data = reactive(schemaToEditorData({
78
$formkit: 'primeInputText',
89
name: 'field',
9-
label: 'Some Label',
10-
help: 'Help Text.',
10+
options: [{ label: 'Option 1', value: 'option1' }, { label: 'Option 2', value: 'option2' }],
1111
}))
1212
13-
const data = JSON.parse('{"$formkit":"primeInputText","name":"field2","label":"Some Label","help":"Help Text."}')
13+
addListGroupFunctions(data)
1414
</script>
1515

1616
<template>
17-
<div>
17+
<div class="ml-2">
1818
<PrimeSchemaEditor
19-
header="Prime Input Editor" :schema="editorSchema" :data="data"
19+
header="Prime Input Editor" :schema="editorSchema()" :data="data"
2020
/>
2121
</div>
2222
</template>

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@
8888
"primevue": "^3.52.0"
8989
},
9090
"devDependencies": {
91-
"@antfu/eslint-config": "2.16.2",
91+
"@antfu/eslint-config": "2.17.0",
9292
"@formkit/core": "^1.6.2",
93-
"@types/node": "^20.12.10",
94-
"@unocss/preset-icons": "0.59.4",
95-
"@unocss/preset-uno": "0.59.4",
93+
"@types/node": "^20.12.11",
94+
"@unocss/preset-icons": "0.60.0",
95+
"@unocss/preset-uno": "0.60.0",
9696
"@vitejs/plugin-vue": "^5.0.4",
9797
"@vitest/coverage-v8": "^1.6.0",
9898
"@vitest/ui": "^1.6.0",
@@ -116,7 +116,7 @@
116116
"tslib": "^2.6.2",
117117
"typescript": "^5.4.5",
118118
"unbuild": "2.0.0",
119-
"unocss": "0.59.4",
119+
"unocss": "0.60.0",
120120
"unplugin-auto-import": "^0.17.5",
121121
"unplugin-vue-components": "^0.27.0",
122122
"vanilla-jsoneditor": "^0.23.3",

0 commit comments

Comments
 (0)