@speykye/vue-form-engine-adapter-antdv 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/README.md +235 -0
  2. package/package.json +4 -3
package/README.md ADDED
@@ -0,0 +1,235 @@
1
+ # @speykye/vue-form-engine-adapter-antdv
2
+
3
+ Ant Design Vue adapter for Vue Form Engine.
4
+
5
+ > Status: Experimental / 0.x. The API may change before 1.0.
6
+
7
+ This package registers Ant Design Vue field components for `@speykye/vue-form-engine`.
8
+
9
+ It is an adapter package, not a standalone form engine. You should use it together with `@speykye/vue-form-engine` and `ant-design-vue`.
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ pnpm add @speykye/vue-form-engine @speykye/vue-form-engine-adapter-antdv ant-design-vue
15
+ ```
16
+
17
+ Or:
18
+
19
+ ```bash
20
+ npm install @speykye/vue-form-engine @speykye/vue-form-engine-adapter-antdv ant-design-vue
21
+ ```
22
+
23
+ ## Setup
24
+
25
+ ```ts
26
+ import { createApp } from 'vue';
27
+ import Antd from 'ant-design-vue';
28
+ import 'ant-design-vue/dist/reset.css';
29
+
30
+ import App from './App.vue';
31
+ import { createVueFormEngine } from '@speykye/vue-form-engine';
32
+ import { antdvAdapter } from '@speykye/vue-form-engine-adapter-antdv';
33
+
34
+ const app = createApp(App);
35
+
36
+ app.use(Antd);
37
+
38
+ app.use(
39
+ createVueFormEngine({
40
+ plugins: [antdvAdapter()]
41
+ })
42
+ );
43
+
44
+ app.mount('#app');
45
+ ```
46
+
47
+ ## Registered fields
48
+
49
+ This adapter currently registers the following field types:
50
+
51
+ - `input`
52
+ - `textarea`
53
+ - `number`
54
+ - `select`
55
+ - `switch`
56
+
57
+ Example:
58
+
59
+ ```ts
60
+ const schema = {
61
+ sections: [
62
+ {
63
+ title: 'Basic Form',
64
+ items: [
65
+ {
66
+ key: 'username',
67
+ type: 'input',
68
+ label: 'Username',
69
+ placeholder: 'Please enter username'
70
+ },
71
+ {
72
+ key: 'bio',
73
+ type: 'textarea',
74
+ label: 'Bio'
75
+ },
76
+ {
77
+ key: 'age',
78
+ type: 'number',
79
+ label: 'Age'
80
+ },
81
+ {
82
+ key: 'role',
83
+ type: 'select',
84
+ label: 'Role',
85
+ options: [
86
+ { label: 'User', value: 'user' },
87
+ { label: 'Admin', value: 'admin' }
88
+ ]
89
+ },
90
+ {
91
+ key: 'enabled',
92
+ type: 'switch',
93
+ label: 'Enabled'
94
+ }
95
+ ]
96
+ }
97
+ ]
98
+ };
99
+ ```
100
+
101
+ ## Usage with DynamicFormEngine
102
+
103
+ ```vue
104
+ <script setup lang="ts">
105
+ import { ref } from 'vue';
106
+ import type { FormSchema } from '@speykye/vue-form-engine';
107
+
108
+ const model = ref({});
109
+
110
+ const schema: FormSchema = {
111
+ sections: [
112
+ {
113
+ title: 'Account',
114
+ items: [
115
+ {
116
+ key: 'username',
117
+ type: 'input',
118
+ label: 'Username',
119
+ rules: [{ required: true, message: 'Username is required' }]
120
+ },
121
+ {
122
+ key: 'userType',
123
+ type: 'select',
124
+ label: 'User Type',
125
+ options: [
126
+ { label: 'Normal', value: 'normal' },
127
+ { label: 'Enterprise', value: 'enterprise' }
128
+ ]
129
+ },
130
+ {
131
+ key: 'companyName',
132
+ type: 'input',
133
+ label: 'Company Name',
134
+ visibleWhen: {
135
+ deps: ['userType'],
136
+ predicate: model => model.userType === 'enterprise'
137
+ }
138
+ }
139
+ ]
140
+ }
141
+ ],
142
+ hiddenValueStrategy: 'submitVisibleOnly'
143
+ };
144
+
145
+ function handleSubmit(values: Record<string, any>) {
146
+ console.log(values);
147
+ }
148
+ </script>
149
+
150
+ <template>
151
+ <DynamicFormEngine
152
+ v-model="model"
153
+ :schema="schema"
154
+ @submit="handleSubmit"
155
+ />
156
+ </template>
157
+ ```
158
+
159
+ ## Field props
160
+
161
+ Field schema `props` are passed to the underlying Ant Design Vue component where applicable.
162
+
163
+ Example:
164
+
165
+ ```ts
166
+ {
167
+ key: 'username',
168
+ type: 'input',
169
+ label: 'Username',
170
+ props: {
171
+ allowClear: true,
172
+ size: 'large'
173
+ }
174
+ }
175
+ ```
176
+
177
+ ## Custom fields
178
+
179
+ You are not limited to the built-in Ant Design Vue fields.
180
+
181
+ You can still register your own custom fields:
182
+
183
+ ```ts
184
+ formEngine.registerField('captcha', CaptchaField);
185
+ ```
186
+
187
+ Or register a business preset:
188
+
189
+ ```ts
190
+ formEngine.use({
191
+ name: 'business-fields',
192
+ fields: {
193
+ captcha: CaptchaField,
194
+ mapPicker: MapPickerField
195
+ }
196
+ });
197
+ ```
198
+
199
+ ## Custom blocks
200
+
201
+ Custom business blocks are also supported through the main engine:
202
+
203
+ ```ts
204
+ formEngine.registerBlock('invitationCode', InvitationCodeBlock);
205
+ ```
206
+
207
+ Schema example:
208
+
209
+ ```ts
210
+ {
211
+ kind: 'block',
212
+ key: 'invitationCodeBlock',
213
+ type: 'invitationCode',
214
+ props: {
215
+ invitationCodeKey: 'invitationCode',
216
+ invitationVerifiedKey: 'invitationVerified'
217
+ }
218
+ }
219
+ ```
220
+
221
+ ## Peer dependencies
222
+
223
+ This package expects the host application to install:
224
+
225
+ - `vue`
226
+ - `ant-design-vue`
227
+ - `@speykye/vue-form-engine`
228
+
229
+ ## Links
230
+
231
+ - GitHub: https://github.com/speykye/vue-form-engine
232
+
233
+ ## License
234
+
235
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@speykye/vue-form-engine-adapter-antdv",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -13,14 +13,15 @@
13
13
  }
14
14
  },
15
15
  "files": [
16
- "dist"
16
+ "dist",
17
+ "README.md"
17
18
  ],
18
19
  "peerDependencies": {
19
20
  "vue": "^3.5.0",
20
21
  "ant-design-vue": "^4.2.6"
21
22
  },
22
23
  "dependencies": {
23
- "@speykye/vue-form-engine-core": "^0.1.0"
24
+ "@speykye/vue-form-engine-core": "^0.1.1"
24
25
  },
25
26
  "scripts": {
26
27
  "build": "vue-tsc --declaration --emitDeclarationOnly --outDir dist && vite build",