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.
@@ -1,121 +1,121 @@
1
- import { COMPONENT_TYPES } from '../../design/constants/componentTypes.js'
2
-
3
- const esc = (value) => String(value ?? '').replace(/"/g, '"')
4
-
5
- function fieldAttrs(component) {
6
- const attrs = []
7
- const label = component.props?.label || ''
8
- const name = component.props?.variableName || ''
9
- if (label) attrs.push(`label="${esc(label)}"`)
10
- if (name) attrs.push(`prop="${esc(name)}"`)
11
- if (component.required) attrs.push('required')
12
- return attrs.join(' ')
13
- }
14
-
15
- function fieldTemplate(component, indent) {
16
- const pad = ' '.repeat(indent)
17
- const attrs = fieldAttrs(component)
18
- const name = component.props?.variableName || ''
19
- const children = []
20
-
21
- switch (component.type) {
22
- case COMPONENT_TYPES.INPUT:
23
- children.push(`${pad} <el-input v-model="formData.${name}" placeholder="${esc(component.props?.placeholder || '')}" />`)
24
- break
25
- case COMPONENT_TYPES.TEXTAREA:
26
- children.push(`${pad} <el-input v-model="formData.${name}" type="textarea" :rows="${component.props?.rows || 3}" placeholder="${esc(component.props?.placeholder || '')}" />`)
27
- break
28
- case COMPONENT_TYPES.INPUT_NUMBER:
29
- children.push(`${pad} <el-input-number v-model="formData.${name}" :min="${component.min ?? 0}" :max="${component.max ?? 100}" />`)
30
- break
31
- case COMPONENT_TYPES.RADIO_GROUP:
32
- ;(component.props?.options || []).forEach((option) => {
33
- children.push(`${pad} <el-radio value="${esc(option.value)}">${esc(option.label)}</el-radio>`)
34
- })
35
- children.unshift(`${pad} <el-radio-group v-model="formData.${name}">`)
36
- children.push(`${pad} </el-radio-group>`)
37
- break
38
- case COMPONENT_TYPES.CHECKBOX_GROUP:
39
- ;(component.props?.options || []).forEach((option) => {
40
- children.push(`${pad} <el-checkbox value="${esc(option.value)}">${esc(option.label)}</el-checkbox>`)
41
- })
42
- children.unshift(`${pad} <el-checkbox-group v-model="formData.${name}">`)
43
- children.push(`${pad} </el-checkbox-group>`)
44
- break
45
- case COMPONENT_TYPES.SELECT:
46
- ;(component.props?.options || []).forEach((option) => {
47
- children.push(`${pad} <el-option label="${esc(option.label)}" value="${esc(option.value)}" />`)
48
- })
49
- children.unshift(`${pad} <el-select v-model="formData.${name}" placeholder="${esc(component.props?.placeholder || '')}">`)
50
- children.push(`${pad} </el-select>`)
51
- break
52
- case COMPONENT_TYPES.SWITCH:
53
- children.push(`${pad} <el-switch v-model="formData.${name}" />`)
54
- break
55
- case COMPONENT_TYPES.DATE_PICKER:
56
- children.push(`${pad} <el-date-picker v-model="formData.${name}" type="date" placeholder="${esc(component.props?.placeholder || '')}" />`)
57
- break
58
- default:
59
- children.push(`${pad} <el-input v-model="formData.${name}" />`)
60
- }
61
-
62
- return `${pad}<el-form-item ${attrs}>\n${children.join('\n')}\n${pad}</el-form-item>`
63
- }
64
-
65
- export function toVueTemplate(components, options = {}) {
66
- const rows = []
67
- ;(components || []).forEach((component) => {
68
- if (component.type === COMPONENT_TYPES.ROW) {
69
- const columns = component.props?.columns || []
70
- rows.push('<el-row :gutter="' + (component.props?.gutter || 20) + '">')
71
- columns.forEach((column, index) => {
72
- rows.push(' <el-col :span="' + (column.span || 12) + '">')
73
- ;(component.children?.[index] || []).forEach((child) => {
74
- rows.push(fieldTemplate(child, 4))
75
- })
76
- rows.push(' </el-col>')
77
- })
78
- rows.push('</el-row>')
79
- } else {
80
- rows.push(fieldTemplate(component, 0))
81
- }
82
- })
83
-
84
- return `<template>
85
- <el-form :model="formData" label-width="${options.labelWidth || '120px'}"${options.size && options.size !== 'default' ? ` size="${options.size}"` : ''}>
86
- ${rows
87
- .join('\n')
88
- .split('\n')
89
- .map((line) => ' ' + line)
90
- .join('\n')}
91
- </el-form>
92
- </template>`
93
- }
94
-
95
- export function toHtml(components, options = {}) {
96
- const rows = []
97
- const field = (component, indent) => {
98
- const pad = ' '.repeat(indent)
99
- const label = esc(component.props?.label || '')
100
- const name = esc(component.props?.variableName || '')
101
- if (component.type === COMPONENT_TYPES.ROW) {
102
- const columns = component.props?.columns || []
103
- rows.push(`${pad}<div class="row">`)
104
- columns.forEach((column, index) => {
105
- rows.push(`${pad} <div class="col-${column.span || 12}">`)
106
- ;(component.children?.[index] || []).forEach((child) => field(child, indent + 4))
107
- rows.push(`${pad} </div>`)
108
- })
109
- rows.push(`${pad}</div>`)
110
- return
111
- }
112
- rows.push(`${pad}<div class="form-item">`)
113
- rows.push(`${pad} <label>${label}${component.required ? ' <em>*</em>' : ''}</label>`)
114
- rows.push(`${pad} <div class="form-item-body" data-field="${name}" data-type="${component.type}"></div>`)
115
- rows.push(`${pad}</div>`)
116
- }
117
- ;(components || []).forEach((component) => field(component, 0))
118
- return `<form class="gb-flow-form"${options.labelWidth ? ` style="--label-width:${options.labelWidth}"` : ''}>
119
- ${rows.join('\n')}
120
- </form>`
1
+ import { COMPONENT_TYPES } from '../../design/constants/componentTypes.js'
2
+
3
+ const esc = (value) => String(value ?? '').replace(/"/g, '&quot;')
4
+
5
+ function fieldAttrs(component) {
6
+ const attrs = []
7
+ const label = component.props?.label || ''
8
+ const name = component.props?.variableName || ''
9
+ if (label) attrs.push(`label="${esc(label)}"`)
10
+ if (name) attrs.push(`prop="${esc(name)}"`)
11
+ if (component.required) attrs.push('required')
12
+ return attrs.join(' ')
13
+ }
14
+
15
+ function fieldTemplate(component, indent) {
16
+ const pad = ' '.repeat(indent)
17
+ const attrs = fieldAttrs(component)
18
+ const name = component.props?.variableName || ''
19
+ const children = []
20
+
21
+ switch (component.type) {
22
+ case COMPONENT_TYPES.INPUT:
23
+ children.push(`${pad} <el-input v-model="formData.${name}" placeholder="${esc(component.props?.placeholder || '')}" />`)
24
+ break
25
+ case COMPONENT_TYPES.TEXTAREA:
26
+ children.push(`${pad} <el-input v-model="formData.${name}" type="textarea" :rows="${component.props?.rows || 3}" placeholder="${esc(component.props?.placeholder || '')}" />`)
27
+ break
28
+ case COMPONENT_TYPES.INPUT_NUMBER:
29
+ children.push(`${pad} <el-input-number v-model="formData.${name}" :min="${component.min ?? 0}" :max="${component.max ?? 100}" />`)
30
+ break
31
+ case COMPONENT_TYPES.RADIO_GROUP:
32
+ ;(component.props?.options || []).forEach((option) => {
33
+ children.push(`${pad} <el-radio value="${esc(option.value)}">${esc(option.label)}</el-radio>`)
34
+ })
35
+ children.unshift(`${pad} <el-radio-group v-model="formData.${name}">`)
36
+ children.push(`${pad} </el-radio-group>`)
37
+ break
38
+ case COMPONENT_TYPES.CHECKBOX_GROUP:
39
+ ;(component.props?.options || []).forEach((option) => {
40
+ children.push(`${pad} <el-checkbox value="${esc(option.value)}">${esc(option.label)}</el-checkbox>`)
41
+ })
42
+ children.unshift(`${pad} <el-checkbox-group v-model="formData.${name}">`)
43
+ children.push(`${pad} </el-checkbox-group>`)
44
+ break
45
+ case COMPONENT_TYPES.SELECT:
46
+ ;(component.props?.options || []).forEach((option) => {
47
+ children.push(`${pad} <el-option label="${esc(option.label)}" value="${esc(option.value)}" />`)
48
+ })
49
+ children.unshift(`${pad} <el-select v-model="formData.${name}" placeholder="${esc(component.props?.placeholder || '')}">`)
50
+ children.push(`${pad} </el-select>`)
51
+ break
52
+ case COMPONENT_TYPES.SWITCH:
53
+ children.push(`${pad} <el-switch v-model="formData.${name}" />`)
54
+ break
55
+ case COMPONENT_TYPES.DATE_PICKER:
56
+ children.push(`${pad} <el-date-picker v-model="formData.${name}" type="date" placeholder="${esc(component.props?.placeholder || '')}" />`)
57
+ break
58
+ default:
59
+ children.push(`${pad} <el-input v-model="formData.${name}" />`)
60
+ }
61
+
62
+ return `${pad}<el-form-item ${attrs}>\n${children.join('\n')}\n${pad}</el-form-item>`
63
+ }
64
+
65
+ export function toVueTemplate(components, options = {}) {
66
+ const rows = []
67
+ ;(components || []).forEach((component) => {
68
+ if (component.type === COMPONENT_TYPES.ROW) {
69
+ const columns = component.props?.columns || []
70
+ rows.push('<el-row :gutter="' + (component.props?.gutter || 20) + '">')
71
+ columns.forEach((column, index) => {
72
+ rows.push(' <el-col :span="' + (column.span || 12) + '">')
73
+ ;(component.children?.[index] || []).forEach((child) => {
74
+ rows.push(fieldTemplate(child, 4))
75
+ })
76
+ rows.push(' </el-col>')
77
+ })
78
+ rows.push('</el-row>')
79
+ } else {
80
+ rows.push(fieldTemplate(component, 0))
81
+ }
82
+ })
83
+
84
+ return `<template>
85
+ <el-form :model="formData" label-width="${options.labelWidth || '120px'}"${options.size && options.size !== 'default' ? ` size="${options.size}"` : ''}>
86
+ ${rows
87
+ .join('\n')
88
+ .split('\n')
89
+ .map((line) => ' ' + line)
90
+ .join('\n')}
91
+ </el-form>
92
+ </template>`
93
+ }
94
+
95
+ export function toHtml(components, options = {}) {
96
+ const rows = []
97
+ const field = (component, indent) => {
98
+ const pad = ' '.repeat(indent)
99
+ const label = esc(component.props?.label || '')
100
+ const name = esc(component.props?.variableName || '')
101
+ if (component.type === COMPONENT_TYPES.ROW) {
102
+ const columns = component.props?.columns || []
103
+ rows.push(`${pad}<div class="row">`)
104
+ columns.forEach((column, index) => {
105
+ rows.push(`${pad} <div class="col-${column.span || 12}">`)
106
+ ;(component.children?.[index] || []).forEach((child) => field(child, indent + 4))
107
+ rows.push(`${pad} </div>`)
108
+ })
109
+ rows.push(`${pad}</div>`)
110
+ return
111
+ }
112
+ rows.push(`${pad}<div class="form-item">`)
113
+ rows.push(`${pad} <label>${label}${component.required ? ' <em>*</em>' : ''}</label>`)
114
+ rows.push(`${pad} <div class="form-item-body" data-field="${name}" data-type="${component.type}"></div>`)
115
+ rows.push(`${pad}</div>`)
116
+ }
117
+ ;(components || []).forEach((component) => field(component, 0))
118
+ return `<form class="gb-flow-form"${options.labelWidth ? ` style="--label-width:${options.labelWidth}"` : ''}>
119
+ ${rows.join('\n')}
120
+ </form>`
121
121
  }
package/src/index.js CHANGED
@@ -1,49 +1,49 @@
1
- import './styles/index.scss'
2
- // 配置项样式必须排在 fc 外壳样式之后,才能覆盖同名选择器
3
- import './styles/config.scss'
4
-
5
- import FormDesigner from './designer/fc/FormDesigner.vue'
6
- import FormViewer from './view/FormViewer.vue'
7
-
8
- export { FormDesigner, FormViewer }
9
-
10
- export { default as FcCanvasField } from './designer/fc/FcCanvasField.vue'
11
-
12
- export * from './core/schema.js'
13
- export * from './core/fileIO.js'
14
- export * from './core/FormVariable.js'
15
- export * from './core/dynamicFormUtils.js'
16
- export * from './core/formVariableTypeSystem.js'
17
-
18
- export {
19
- generateComponentId,
20
- ensureComponentId,
21
- normalizeNumberValue,
22
- isEmpty,
23
- normalizeOptions,
24
- parseWidth,
25
- getFieldName
26
- } from './design/utils/componentUtils.js'
27
-
28
- export {
29
- COMPONENT_TYPES,
30
- COMPONENT_TYPE_LABELS,
31
- OPTION_COMPONENT_TYPES,
32
- DEFAULT_CONFIG,
33
- WIDTH_PRESETS
34
- } from './design/constants/componentTypes.js'
35
-
36
- export { COMPONENT_CATEGORIES } from './design/constants/componentTemplates.js'
37
-
38
- const components = [FormDesigner, FormViewer]
39
-
40
- export const version = '0.1.0'
41
-
42
- export default {
43
- version,
44
- install(app) {
45
- components.forEach((component) => {
46
- if (component.name) app.component(component.name, component)
47
- })
48
- }
1
+ import './styles/index.scss'
2
+ // 配置项样式必须排在 fc 外壳样式之后,才能覆盖同名选择器
3
+ import './styles/config.scss'
4
+
5
+ import FormDesigner from './designer/fc/FormDesigner.vue'
6
+ import FormViewer from './view/FormViewer.vue'
7
+
8
+ export { FormDesigner, FormViewer }
9
+
10
+ export { default as FcCanvasField } from './designer/fc/FcCanvasField.vue'
11
+
12
+ export * from './core/schema.js'
13
+ export * from './core/fileIO.js'
14
+ export * from './core/FormVariable.js'
15
+ export * from './core/dynamicFormUtils.js'
16
+ export * from './core/formVariableTypeSystem.js'
17
+
18
+ export {
19
+ generateComponentId,
20
+ ensureComponentId,
21
+ normalizeNumberValue,
22
+ isEmpty,
23
+ normalizeOptions,
24
+ parseWidth,
25
+ getFieldName
26
+ } from './design/utils/componentUtils.js'
27
+
28
+ export {
29
+ COMPONENT_TYPES,
30
+ COMPONENT_TYPE_LABELS,
31
+ OPTION_COMPONENT_TYPES,
32
+ DEFAULT_CONFIG,
33
+ WIDTH_PRESETS
34
+ } from './design/constants/componentTypes.js'
35
+
36
+ export { COMPONENT_CATEGORIES } from './design/constants/componentTemplates.js'
37
+
38
+ const components = [FormDesigner, FormViewer]
39
+
40
+ export const version = '0.1.0'
41
+
42
+ export default {
43
+ version,
44
+ install(app) {
45
+ components.forEach((component) => {
46
+ if (component.name) app.component(component.name, component)
47
+ })
48
+ }
49
49
  }
@@ -1,102 +1,102 @@
1
- /*! Config item styles adapted from form-create-designer (MIT License, Copyright (c) 2022 xaboy). */
2
- ._fd-config-item {
3
- display: flex;
4
- width: 100%;
5
- flex-direction: column;
6
- font-size: 12px;
7
- color: #666666;
8
- margin-bottom: 10px;
9
- }
10
-
11
- ._fd-ci-head {
12
- display: flex;
13
- justify-content: space-between;
14
- align-items: center;
15
- }
16
-
17
- ._fd-ci-label {
18
- display: flex;
19
- align-items: center;
20
- font-size: 12px;
21
- color: #262626;
22
- }
23
-
24
- ._fd-ci-con {
25
- display: flex;
26
- align-items: center;
27
- justify-content: flex-end;
28
- min-width: 150px;
29
- }
30
-
31
- ._fd-ci-label.is-arrow {
32
- cursor: pointer;
33
- }
34
-
35
- ._fd-ci-append {
36
- display: flex;
37
- flex-direction: column;
38
- background: #F5F5F5;
39
- margin: 5px 3px 3px;
40
- padding: 4px;
41
- }
42
-
43
- ._fd-ci-label i {
44
- font-size: 12px;
45
- font-weight: 600;
46
- }
47
-
48
- ._fd-ci-label i.down {
49
- transform: rotate(-180deg);
50
- }
51
-
52
- ._fd-ci-info {
53
- font-size: 12px;
54
- padding-right: 5px;
55
- }
56
-
57
- /* form-create terminals keep the config grid readable in a 320px panel */
58
- ._fc-r-tab-props ._fd-ci-con {
59
- min-width: 0;
60
- }
61
-
62
- ._fc-r-tab-props ._fd-ci-con .el-input,
63
- ._fc-r-tab-props ._fd-ci-con .el-select {
64
- max-width: 190px;
65
- }
66
-
67
- /* --- column drop zones & nested row box (override fc shell paddings) --- */
68
- .gb-fc-row-box {
69
- padding: 2px !important;
70
- overflow: visible !important;
71
- min-height: 0 !important;
72
- }
73
-
74
- .gb-fc-column {
75
- min-height: 88px;
76
- padding: 6px;
77
- border: 1px dashed #dcdfe6;
78
- border-radius: 4px;
79
- background: #fafafa;
80
- transition: border-color 0.2s ease, background 0.2s ease;
81
- }
82
-
83
- .gb-fc-column:hover {
84
- border-color: #2e73ff;
85
- background: rgba(46, 115, 255, 0.05);
86
- }
87
-
88
- .gb-fc-column.has-child {
89
- border-style: dashed;
90
- border-color: #e4e7ed;
91
- background: #ffffff;
92
- }
93
-
94
- .gb-fc-column.has-child:hover {
95
- border-color: #2e73ff;
96
- }
97
-
98
- .gb-fc-column._fc-child-empty:after {
99
- content: '拖拽组件到此处';
100
- font-family: inherit;
101
- font-size: 12px;
102
- }
1
+ /*! Config item styles adapted from form-create-designer (MIT License, Copyright (c) 2022 xaboy). */
2
+ ._fd-config-item {
3
+ display: flex;
4
+ width: 100%;
5
+ flex-direction: column;
6
+ font-size: 12px;
7
+ color: #666666;
8
+ margin-bottom: 10px;
9
+ }
10
+
11
+ ._fd-ci-head {
12
+ display: flex;
13
+ justify-content: space-between;
14
+ align-items: center;
15
+ }
16
+
17
+ ._fd-ci-label {
18
+ display: flex;
19
+ align-items: center;
20
+ font-size: 12px;
21
+ color: #262626;
22
+ }
23
+
24
+ ._fd-ci-con {
25
+ display: flex;
26
+ align-items: center;
27
+ justify-content: flex-end;
28
+ min-width: 150px;
29
+ }
30
+
31
+ ._fd-ci-label.is-arrow {
32
+ cursor: pointer;
33
+ }
34
+
35
+ ._fd-ci-append {
36
+ display: flex;
37
+ flex-direction: column;
38
+ background: #F5F5F5;
39
+ margin: 5px 3px 3px;
40
+ padding: 4px;
41
+ }
42
+
43
+ ._fd-ci-label i {
44
+ font-size: 12px;
45
+ font-weight: 600;
46
+ }
47
+
48
+ ._fd-ci-label i.down {
49
+ transform: rotate(-180deg);
50
+ }
51
+
52
+ ._fd-ci-info {
53
+ font-size: 12px;
54
+ padding-right: 5px;
55
+ }
56
+
57
+ /* form-create terminals keep the config grid readable in a 320px panel */
58
+ ._fc-r-tab-props ._fd-ci-con {
59
+ min-width: 0;
60
+ }
61
+
62
+ ._fc-r-tab-props ._fd-ci-con .el-input,
63
+ ._fc-r-tab-props ._fd-ci-con .el-select {
64
+ max-width: 190px;
65
+ }
66
+
67
+ /* --- column drop zones & nested row box (override fc shell paddings) --- */
68
+ .gb-fc-row-box {
69
+ padding: 2px !important;
70
+ overflow: visible !important;
71
+ min-height: 0 !important;
72
+ }
73
+
74
+ .gb-fc-column {
75
+ min-height: 88px;
76
+ padding: 6px;
77
+ border: 1px dashed #dcdfe6;
78
+ border-radius: 4px;
79
+ background: #fafafa;
80
+ transition: border-color 0.2s ease, background 0.2s ease;
81
+ }
82
+
83
+ .gb-fc-column:hover {
84
+ border-color: #2e73ff;
85
+ background: rgba(46, 115, 255, 0.05);
86
+ }
87
+
88
+ .gb-fc-column.has-child {
89
+ border-style: dashed;
90
+ border-color: #e4e7ed;
91
+ background: #ffffff;
92
+ }
93
+
94
+ .gb-fc-column.has-child:hover {
95
+ border-color: #2e73ff;
96
+ }
97
+
98
+ .gb-fc-column._fc-child-empty:after {
99
+ content: '拖拽组件到此处';
100
+ font-family: inherit;
101
+ font-size: 12px;
102
+ }