gbformdesign 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.
- package/LICENSE +21 -21
- package/README.md +84 -84
- package/dist/gbformdesign.css +1 -1
- package/dist/gbformdesign.js +1146 -1051
- package/dist/gbformdesign.js.map +1 -1
- package/dist/gbformdesign.umd.cjs +6 -6
- package/dist/gbformdesign.umd.cjs.map +1 -1
- package/package.json +58 -57
- package/src/core/FormVariable.js +328 -328
- package/src/core/dynamicFormUtils.js +139 -139
- package/src/core/fileIO.js +90 -90
- package/src/core/formVariableTypeSystem.js +327 -327
- package/src/core/index.js +26 -26
- package/src/core/schema.js +192 -192
- package/src/design/composables/useDefaultValue.js +55 -55
- package/src/design/constants/componentTemplates.js +181 -190
- package/src/design/constants/componentTypes.js +70 -70
- package/src/design/utils/componentUtils.js +75 -75
- package/src/designer/fc/FcCanvasField.vue +277 -276
- package/src/designer/fc/FcJsonPanel.vue +113 -113
- package/src/designer/fc/FcPreviewDialog.vue +62 -62
- package/src/designer/fc/FcPropsPanel.vue +373 -373
- package/src/designer/fc/FormDesigner.vue +633 -633
- package/src/designer/fc/codegen.js +120 -120
- package/src/index.js +48 -48
- package/src/styles/config.scss +102 -102
- package/src/styles/fc/designer.css +837 -837
- package/src/styles/fc/icon.css +1053 -1053
- package/src/styles/index.scss +4 -4
- package/src/view/FormField.vue +301 -301
- package/src/view/FormViewer.vue +216 -216
- package/src/view/composables/useFormValidation.js +201 -201
|
@@ -1,277 +1,278 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div
|
|
3
|
-
class="_fc-draggable-item _fd-drag-item gb-fc-item"
|
|
4
|
-
:class="{
|
|
5
|
-
'is-active': activeId === component.id,
|
|
6
|
-
'is-hidden': component.hidden,
|
|
7
|
-
'drag-over-top': dragOver === path.join('.') + ':top',
|
|
8
|
-
'drag-over-bottom': dragOver === path.join('.') + ':bottom'
|
|
9
|
-
}"
|
|
10
|
-
@dragover.prevent="onDragOver"
|
|
11
|
-
@dragenter.prevent
|
|
12
|
-
@dragleave="onDragLeave"
|
|
13
|
-
@drop.stop.prevent="onDrop"
|
|
14
|
-
>
|
|
15
|
-
<template v-if="isRow">
|
|
16
|
-
<div class="_fd-draggable-drag _fd-drag-box gb-fc-row-box">
|
|
17
|
-
<el-row :gutter="component.props?.gutter || 20">
|
|
18
|
-
<el-col
|
|
19
|
-
v-for="(column, colIndex) in columnCount"
|
|
20
|
-
:key="colIndex"
|
|
21
|
-
:span="component.props?.columns?.[colIndex]?.span || 12"
|
|
22
|
-
>
|
|
23
|
-
<div
|
|
24
|
-
class="gb-fc-column"
|
|
25
|
-
:class="{
|
|
26
|
-
'_fc-child-empty': !(component.children?.[colIndex] || []).length,
|
|
27
|
-
'has-child': (component.children?.[colIndex] || []).length
|
|
28
|
-
}"
|
|
29
|
-
@dragover.prevent.stop="onColumnDragOver(colIndex)"
|
|
30
|
-
@drop.stop.prevent="onColumnDrop(colIndex, $event)"
|
|
31
|
-
>
|
|
32
|
-
<FcCanvasField
|
|
33
|
-
v-for="(child, childIndex) in component.children?.[colIndex] || []"
|
|
34
|
-
:key="child.id || childIndex"
|
|
35
|
-
:component="child"
|
|
36
|
-
:path="[...path, 'children', colIndex, childIndex]"
|
|
37
|
-
:form-data="formData"
|
|
38
|
-
:form-rules="formRules"
|
|
39
|
-
:active-id="activeId"
|
|
40
|
-
:depth="depth + 1"
|
|
41
|
-
/>
|
|
42
|
-
</div>
|
|
43
|
-
</el-col>
|
|
44
|
-
</el-row>
|
|
45
|
-
</div>
|
|
46
|
-
</template>
|
|
47
|
-
<FormField
|
|
48
|
-
v-else
|
|
49
|
-
:component="component"
|
|
50
|
-
:form-data="formData"
|
|
51
|
-
:form-rules="formRules"
|
|
52
|
-
:readonly="true"
|
|
53
|
-
/>
|
|
54
|
-
|
|
55
|
-
<div class="gb-fc-mask" @click.stop="ops.active(component, path)">
|
|
56
|
-
<div class="gb-fc-tools">
|
|
57
|
-
<i
|
|
58
|
-
class="gb-fc-tool gb-fc-tool--handle"
|
|
59
|
-
:title="'拖拽' + (component.props?.label || component.type)"
|
|
60
|
-
draggable="true"
|
|
61
|
-
@dragstart.stop="onDragStart"
|
|
62
|
-
@dragend="onDragEnd"
|
|
63
|
-
>
|
|
64
|
-
<
|
|
65
|
-
</i>
|
|
66
|
-
<i class="gb-fc-tool" :title="'复制'" @click.stop="ops.copy(path)">
|
|
67
|
-
<
|
|
68
|
-
</i>
|
|
69
|
-
<i class="gb-fc-tool gb-fc-tool--danger" :title="'删除'" @click.stop="ops.remove(path)">
|
|
70
|
-
<
|
|
71
|
-
</i>
|
|
72
|
-
</div>
|
|
73
|
-
</div>
|
|
74
|
-
</div>
|
|
75
|
-
</template>
|
|
76
|
-
|
|
77
|
-
<script setup>
|
|
78
|
-
import { computed, inject } from 'vue'
|
|
79
|
-
import
|
|
80
|
-
import
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
)
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
event.dataTransfer.
|
|
110
|
-
event.dataTransfer.setData('
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
event.
|
|
133
|
-
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
&.is-active > .
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
&.drag-over-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
border
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
class="_fc-draggable-item _fd-drag-item gb-fc-item"
|
|
4
|
+
:class="{
|
|
5
|
+
'is-active': activeId === component.id,
|
|
6
|
+
'is-hidden': component.hidden,
|
|
7
|
+
'drag-over-top': dragOver === path.join('.') + ':top',
|
|
8
|
+
'drag-over-bottom': dragOver === path.join('.') + ':bottom'
|
|
9
|
+
}"
|
|
10
|
+
@dragover.prevent="onDragOver"
|
|
11
|
+
@dragenter.prevent
|
|
12
|
+
@dragleave="onDragLeave"
|
|
13
|
+
@drop.stop.prevent="onDrop"
|
|
14
|
+
>
|
|
15
|
+
<template v-if="isRow">
|
|
16
|
+
<div class="_fd-draggable-drag _fd-drag-box gb-fc-row-box">
|
|
17
|
+
<el-row :gutter="component.props?.gutter || 20">
|
|
18
|
+
<el-col
|
|
19
|
+
v-for="(column, colIndex) in columnCount"
|
|
20
|
+
:key="colIndex"
|
|
21
|
+
:span="component.props?.columns?.[colIndex]?.span || 12"
|
|
22
|
+
>
|
|
23
|
+
<div
|
|
24
|
+
class="gb-fc-column"
|
|
25
|
+
:class="{
|
|
26
|
+
'_fc-child-empty': !(component.children?.[colIndex] || []).length,
|
|
27
|
+
'has-child': (component.children?.[colIndex] || []).length
|
|
28
|
+
}"
|
|
29
|
+
@dragover.prevent.stop="onColumnDragOver(colIndex)"
|
|
30
|
+
@drop.stop.prevent="onColumnDrop(colIndex, $event)"
|
|
31
|
+
>
|
|
32
|
+
<FcCanvasField
|
|
33
|
+
v-for="(child, childIndex) in component.children?.[colIndex] || []"
|
|
34
|
+
:key="child.id || childIndex"
|
|
35
|
+
:component="child"
|
|
36
|
+
:path="[...path, 'children', colIndex, childIndex]"
|
|
37
|
+
:form-data="formData"
|
|
38
|
+
:form-rules="formRules"
|
|
39
|
+
:active-id="activeId"
|
|
40
|
+
:depth="depth + 1"
|
|
41
|
+
/>
|
|
42
|
+
</div>
|
|
43
|
+
</el-col>
|
|
44
|
+
</el-row>
|
|
45
|
+
</div>
|
|
46
|
+
</template>
|
|
47
|
+
<FormField
|
|
48
|
+
v-else
|
|
49
|
+
:component="component"
|
|
50
|
+
:form-data="formData"
|
|
51
|
+
:form-rules="formRules"
|
|
52
|
+
:readonly="true"
|
|
53
|
+
/>
|
|
54
|
+
|
|
55
|
+
<div class="gb-fc-mask" @click.stop="ops.active(component, path)">
|
|
56
|
+
<div class="gb-fc-tools">
|
|
57
|
+
<i
|
|
58
|
+
class="gb-fc-tool gb-fc-tool--handle"
|
|
59
|
+
:title="'拖拽' + (component.props?.label || component.type)"
|
|
60
|
+
draggable="true"
|
|
61
|
+
@dragstart.stop="onDragStart"
|
|
62
|
+
@dragend="onDragEnd"
|
|
63
|
+
>
|
|
64
|
+
<Rank style="width: 14px; height: 14px" />
|
|
65
|
+
</i>
|
|
66
|
+
<i class="gb-fc-tool" :title="'复制'" @click.stop="ops.copy(path)">
|
|
67
|
+
<CopyDocument style="width: 14px; height: 14px" />
|
|
68
|
+
</i>
|
|
69
|
+
<i class="gb-fc-tool gb-fc-tool--danger" :title="'删除'" @click.stop="ops.remove(path)">
|
|
70
|
+
<Close style="width: 14px; height: 14px" />
|
|
71
|
+
</i>
|
|
72
|
+
</div>
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
</template>
|
|
76
|
+
|
|
77
|
+
<script setup>
|
|
78
|
+
import { computed, inject } from 'vue'
|
|
79
|
+
import { Close, CopyDocument, Rank } from 'gbicons'
|
|
80
|
+
import FormField from '../../view/FormField.vue'
|
|
81
|
+
import { COMPONENT_TYPES } from '../../design/constants/componentTypes.js'
|
|
82
|
+
|
|
83
|
+
defineOptions({ name: 'FcCanvasField' })
|
|
84
|
+
|
|
85
|
+
const props = defineProps({
|
|
86
|
+
component: { type: Object, required: true },
|
|
87
|
+
path: { type: Array, required: true },
|
|
88
|
+
formData: { type: Object, required: true },
|
|
89
|
+
formRules: { type: Object, required: true },
|
|
90
|
+
activeId: { type: String, default: '' },
|
|
91
|
+
depth: { type: Number, default: 0 }
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
const ops = inject('fcCanvasOps')
|
|
95
|
+
const dragOver = inject('fcDragOver')
|
|
96
|
+
|
|
97
|
+
const isRow = computed(() => props.component.type === COMPONENT_TYPES.ROW)
|
|
98
|
+
const columnCount = computed(() => props.component.props?.columns?.length || 2)
|
|
99
|
+
const isEmptyRow = computed(() =>
|
|
100
|
+
(props.component.children || []).every((column) => !column || column.length === 0)
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
const dragPayload = {
|
|
104
|
+
kind: 'existing',
|
|
105
|
+
path: props.path
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const onDragStart = (event) => {
|
|
109
|
+
event.dataTransfer.effectAllowed = 'move'
|
|
110
|
+
event.dataTransfer.setData('application/x-gb-field', JSON.stringify(dragPayload))
|
|
111
|
+
event.dataTransfer.setData('text/plain', 'gb-field')
|
|
112
|
+
ops.startDrag(props.path)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const onDragEnd = () => {
|
|
116
|
+
ops.endDrag()
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const onDragOver = (event) => {
|
|
120
|
+
event.preventDefault()
|
|
121
|
+
const rect = event.currentTarget.getBoundingClientRect()
|
|
122
|
+
const position = event.clientY - rect.top < rect.height / 2 ? 'top' : 'bottom'
|
|
123
|
+
dragOver.value = props.path.join('.') + ':' + position
|
|
124
|
+
event.dataTransfer.dropEffect = 'move'
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const onDragLeave = () => {
|
|
128
|
+
if (dragOver.value?.startsWith(props.path.join('.'))) dragOver.value = ''
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const onDrop = (event) => {
|
|
132
|
+
event.preventDefault()
|
|
133
|
+
event.stopPropagation()
|
|
134
|
+
const position = dragOver.value?.endsWith(':top') ? 'top' : 'bottom'
|
|
135
|
+
const payload = readPayload(event)
|
|
136
|
+
dragOver.value = ''
|
|
137
|
+
if (!payload) return
|
|
138
|
+
ops.dropAt(payload, { path: props.path, position })
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const onColumnDragOver = (colIndex) => {
|
|
142
|
+
dragOver.value = props.path.join('.') + ':col' + colIndex
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const onColumnDrop = (colIndex, event) => {
|
|
146
|
+
const payload = readPayload(event)
|
|
147
|
+
dragOver.value = ''
|
|
148
|
+
if (!payload) return
|
|
149
|
+
ops.dropAt(payload, { path: props.path, column: colIndex })
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const readPayload = (event) => {
|
|
153
|
+
const raw = event?.dataTransfer?.getData('application/x-gb-field')
|
|
154
|
+
if (raw) {
|
|
155
|
+
try {
|
|
156
|
+
return JSON.parse(raw)
|
|
157
|
+
} catch {
|
|
158
|
+
return null
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return ops.getDragPayload()
|
|
162
|
+
}
|
|
163
|
+
</script>
|
|
164
|
+
|
|
165
|
+
<style lang="scss">
|
|
166
|
+
.gb-fc-item {
|
|
167
|
+
position: relative;
|
|
168
|
+
padding: 4px 0;
|
|
169
|
+
|
|
170
|
+
&:hover {
|
|
171
|
+
> .gb-fc-mask {
|
|
172
|
+
display: block;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
&.is-active > ._fd-draggable-drag,
|
|
177
|
+
&.is-active > .form-viewer {
|
|
178
|
+
outline: 1px solid #2e73ff;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
&.is-hidden {
|
|
182
|
+
opacity: 0.55;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
&.drag-over-top::before,
|
|
186
|
+
&.drag-over-bottom::after {
|
|
187
|
+
content: '';
|
|
188
|
+
position: absolute;
|
|
189
|
+
left: 0;
|
|
190
|
+
right: 0;
|
|
191
|
+
height: 2px;
|
|
192
|
+
background: #2e73ff;
|
|
193
|
+
z-index: 3;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
&.drag-over-top::before {
|
|
197
|
+
top: -1px;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
&.drag-over-bottom::after {
|
|
201
|
+
bottom: -1px;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.gb-fc-mask {
|
|
206
|
+
display: none;
|
|
207
|
+
position: absolute;
|
|
208
|
+
inset: 4px 0;
|
|
209
|
+
z-index: 2;
|
|
210
|
+
cursor: pointer;
|
|
211
|
+
|
|
212
|
+
&::after {
|
|
213
|
+
content: '';
|
|
214
|
+
position: absolute;
|
|
215
|
+
inset: 0;
|
|
216
|
+
border: 1px solid #2e73ff;
|
|
217
|
+
background: rgba(46, 115, 255, 0.03);
|
|
218
|
+
pointer-events: none;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
.gb-fc-tools {
|
|
223
|
+
position: absolute;
|
|
224
|
+
right: 2px;
|
|
225
|
+
top: 2px;
|
|
226
|
+
z-index: 3;
|
|
227
|
+
display: flex;
|
|
228
|
+
align-items: center;
|
|
229
|
+
gap: 2px;
|
|
230
|
+
background: #fff;
|
|
231
|
+
border: 1px solid #2e73ff;
|
|
232
|
+
border-radius: 3px;
|
|
233
|
+
box-shadow: 0 2px 8px rgba(46, 115, 255, 0.25);
|
|
234
|
+
padding: 2px;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
.gb-fc-tool {
|
|
238
|
+
display: inline-flex;
|
|
239
|
+
align-items: center;
|
|
240
|
+
justify-content: center;
|
|
241
|
+
width: 20px;
|
|
242
|
+
height: 20px;
|
|
243
|
+
color: #2e73ff;
|
|
244
|
+
cursor: pointer;
|
|
245
|
+
border-radius: 3px;
|
|
246
|
+
|
|
247
|
+
&:hover {
|
|
248
|
+
background: rgba(46, 115, 255, 0.12);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
&--handle {
|
|
252
|
+
cursor: move;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
&--danger:hover {
|
|
256
|
+
background: rgba(245, 74, 74, 0.12);
|
|
257
|
+
color: #f54a4a;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
.gb-fc-column {
|
|
262
|
+
min-height: 60px;
|
|
263
|
+
border: 1px dashed transparent;
|
|
264
|
+
transition: border-color 0.2s ease;
|
|
265
|
+
|
|
266
|
+
&.has-child {
|
|
267
|
+
border-color: transparent;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
&:hover {
|
|
271
|
+
border-color: #c0c4cc;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
.gb-fc-row-box {
|
|
276
|
+
padding: 4px;
|
|
277
|
+
}
|
|
277
278
|
</style>
|