amis-editor 4.1.0-beta.1 → 4.1.0-beta.20
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/component/Breadcrumb.d.ts +23 -2
- package/dist/component/Editor.d.ts +19 -0
- package/dist/component/Panel/RenderersPanel.d.ts +1 -2
- package/dist/component/RegionWrapper.d.ts +14 -7
- package/dist/component/RendererThumb.d.ts +5 -5
- package/dist/component/VRenderer.d.ts +4 -0
- package/dist/component/base/SearchCustomRendererPanel.d.ts +15 -0
- package/dist/component/base/SearchPanel.d.ts +83 -0
- package/dist/component/base/SearchRendererPanel.d.ts +2 -42
- package/dist/exports.min.js +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.min.js +1 -1
- package/dist/manager.d.ts +14 -3
- package/dist/plugin/Card.d.ts +1 -0
- package/dist/plugin/Cards.d.ts +1 -0
- package/dist/plugin/Carousel.d.ts +1 -0
- package/dist/plugin/Chart.d.ts +1 -0
- package/dist/plugin/Collapse.d.ts +1 -0
- package/dist/plugin/Custom.d.ts +3 -0
- package/dist/plugin/CustomRegion.d.ts +43 -0
- package/dist/plugin/Flex.d.ts +1 -0
- package/dist/plugin/Form/Control.d.ts +1 -0
- package/dist/plugin/Form/Form.d.ts +19 -3
- package/dist/plugin/Form/InputURL.d.ts +1 -0
- package/dist/plugin/Grid.d.ts +1 -0
- package/dist/plugin/HBox.d.ts +1 -0
- package/dist/plugin/Json.d.ts +1 -0
- package/dist/plugin/List.d.ts +1 -0
- package/dist/plugin/Mapping.d.ts +1 -0
- package/dist/plugin/Markdown.d.ts +1 -0
- package/dist/plugin/Nav.d.ts +1 -0
- package/dist/plugin/Panel/Outline.d.ts +8 -0
- package/dist/plugin/Progress.d.ts +1 -0
- package/dist/plugin/QRCode.d.ts +1 -0
- package/dist/plugin/Reset.d.ts +0 -1
- package/dist/plugin/Service.d.ts +1 -0
- package/dist/plugin/Sparkline.d.ts +1 -0
- package/dist/plugin/Status.d.ts +1 -0
- package/dist/plugin/Steps.d.ts +1 -0
- package/dist/plugin/Submit.d.ts +0 -1
- package/dist/plugin/TableView.d.ts +1 -0
- package/dist/plugin/Tasks.d.ts +1 -0
- package/dist/plugin/TooltipWrapper.d.ts +1 -0
- package/dist/plugin/Video.d.ts +1 -0
- package/dist/plugin/WebComponent.d.ts +1 -0
- package/dist/plugin/Wizard.d.ts +11 -2
- package/dist/plugin/Wrapper.d.ts +1 -0
- package/dist/plugin.d.ts +2 -2
- package/dist/store/editor.d.ts +20 -2
- package/dist/store/node.d.ts +6 -0
- package/dist/style.css +1 -1
- package/dist/util.d.ts +7 -2
- package/package.json +6 -3
- package/src/component/schemaTpl.tsx +2155 -0
- package/src/plugin/Alert.tsx +87 -0
- package/src/plugin/AnchorNav.tsx +233 -0
- package/src/plugin/Audio.tsx +161 -0
- package/src/plugin/Avatar.tsx +77 -0
- package/src/plugin/Breadcrumb.tsx +107 -0
- package/src/plugin/Button.tsx +283 -0
- package/src/plugin/ButtonGroup.tsx +88 -0
- package/src/plugin/ButtonToolbar.tsx +89 -0
- package/src/plugin/CRUD.tsx +1832 -0
- package/src/plugin/Card.tsx +290 -0
- package/src/plugin/Cards.tsx +315 -0
- package/src/plugin/Carousel.tsx +386 -0
- package/src/plugin/Chart.tsx +218 -0
- package/src/plugin/CodeView.tsx +60 -0
- package/src/plugin/Collapse.tsx +143 -0
- package/src/plugin/CollapseGroup.tsx +167 -0
- package/src/plugin/Container.tsx +44 -0
- package/src/plugin/Custom.tsx +128 -0
- package/src/plugin/CustomRegion.tsx +150 -0
- package/src/plugin/Date.tsx +81 -0
- package/src/plugin/Datetime.tsx +75 -0
- package/src/plugin/Dialog.tsx +178 -0
- package/src/plugin/Divider.tsx +36 -0
- package/src/plugin/Drawer.tsx +217 -0
- package/src/plugin/DropDownButton.tsx +234 -0
- package/src/plugin/Each.tsx +152 -0
- package/src/plugin/ErrorRenderer.tsx +15 -0
- package/src/plugin/Flex.tsx +156 -0
- package/src/plugin/Form/ButtonGroupSelect.tsx +86 -0
- package/src/plugin/Form/ButtonToolbar.tsx +121 -0
- package/src/plugin/Form/ChainedSelect.tsx +70 -0
- package/src/plugin/Form/Checkbox.tsx +87 -0
- package/src/plugin/Form/Checkboxes.tsx +167 -0
- package/src/plugin/Form/CodeEditor.tsx +91 -0
- package/src/plugin/Form/Combo.tsx +582 -0
- package/src/plugin/Form/ConditionBuilder.tsx +324 -0
- package/src/plugin/Form/Control.tsx +139 -0
- package/src/plugin/Form/DiffEditor.tsx +117 -0
- package/src/plugin/Form/FieldSet.tsx +175 -0
- package/src/plugin/Form/Form.tsx +692 -0
- package/src/plugin/Form/Formula.tsx +91 -0
- package/src/plugin/Form/Group.tsx +300 -0
- package/src/plugin/Form/Hidden.tsx +56 -0
- package/src/plugin/Form/InputArray.tsx +228 -0
- package/src/plugin/Form/InputCity.tsx +93 -0
- package/src/plugin/Form/InputColor.tsx +123 -0
- package/src/plugin/Form/InputDate.tsx +175 -0
- package/src/plugin/Form/InputDateRange.tsx +225 -0
- package/src/plugin/Form/InputDateTime.tsx +183 -0
- package/src/plugin/Form/InputDateTimeRange.tsx +221 -0
- package/src/plugin/Form/InputEmail.tsx +33 -0
- package/src/plugin/Form/InputExcel.tsx +85 -0
- package/src/plugin/Form/InputFile.tsx +228 -0
- package/src/plugin/Form/InputGroup.tsx +105 -0
- package/src/plugin/Form/InputImage.tsx +277 -0
- package/src/plugin/Form/InputKV.tsx +72 -0
- package/src/plugin/Form/InputMonth.tsx +35 -0
- package/src/plugin/Form/InputMonthRange.tsx +195 -0
- package/src/plugin/Form/InputNumber.tsx +97 -0
- package/src/plugin/Form/InputPassword.tsx +33 -0
- package/src/plugin/Form/InputQuarter.tsx +35 -0
- package/src/plugin/Form/InputQuarterRange.tsx +195 -0
- package/src/plugin/Form/InputRange.tsx +121 -0
- package/src/plugin/Form/InputRating.tsx +78 -0
- package/src/plugin/Form/InputRepeat.tsx +69 -0
- package/src/plugin/Form/InputRichText.tsx +197 -0
- package/src/plugin/Form/InputSubForm.tsx +198 -0
- package/src/plugin/Form/InputTable.tsx +434 -0
- package/src/plugin/Form/InputTag.tsx +81 -0
- package/src/plugin/Form/InputText.tsx +186 -0
- package/src/plugin/Form/InputTime.tsx +95 -0
- package/src/plugin/Form/InputTree.tsx +240 -0
- package/src/plugin/Form/InputURL.tsx +34 -0
- package/src/plugin/Form/InputYear.tsx +35 -0
- package/src/plugin/Form/Item.tsx +325 -0
- package/src/plugin/Form/ListSelect.tsx +84 -0
- package/src/plugin/Form/LocationPicker.tsx +75 -0
- package/src/plugin/Form/MatrixCheckboxes.tsx +147 -0
- package/src/plugin/Form/NestedSelect.tsx +222 -0
- package/src/plugin/Form/Picker.tsx +217 -0
- package/src/plugin/Form/Radios.tsx +130 -0
- package/src/plugin/Form/Select.tsx +216 -0
- package/src/plugin/Form/Static.tsx +335 -0
- package/src/plugin/Form/Switch.tsx +116 -0
- package/src/plugin/Form/TabsTransfer.tsx +270 -0
- package/src/plugin/Form/Textarea.tsx +94 -0
- package/src/plugin/Form/Transfer.tsx +379 -0
- package/src/plugin/Form/TreeSelect.tsx +263 -0
- package/src/plugin/Form/UUID.tsx +48 -0
- package/src/plugin/Grid.tsx +799 -0
- package/src/plugin/HBox.tsx +727 -0
- package/src/plugin/IFrame.tsx +72 -0
- package/src/plugin/Image.tsx +318 -0
- package/src/plugin/Images.tsx +238 -0
- package/src/plugin/Json.tsx +76 -0
- package/src/plugin/Link.tsx +95 -0
- package/src/plugin/List.tsx +278 -0
- package/src/plugin/ListItem.tsx +233 -0
- package/src/plugin/Log.tsx +52 -0
- package/src/plugin/Mapping.tsx +156 -0
- package/src/plugin/Markdown.tsx +47 -0
- package/src/plugin/Nav.tsx +186 -0
- package/src/plugin/Operation.tsx +97 -0
- package/src/plugin/Others/Action.tsx +428 -0
- package/src/plugin/Others/BasicToolbar.tsx +591 -0
- package/src/plugin/Others/DataDebug.tsx +134 -0
- package/src/plugin/Others/TableCell.tsx +480 -0
- package/src/plugin/Others/Unknown.tsx +37 -0
- package/src/plugin/Page.tsx +308 -0
- package/src/plugin/Panel/AvailableRenderers.tsx +41 -0
- package/src/plugin/Panel/Code.tsx +44 -0
- package/src/plugin/Panel/Name.tsx +26 -0
- package/src/plugin/Panel/Outline.tsx +40 -0
- package/src/plugin/Panel.tsx +243 -0
- package/src/plugin/Plain.tsx +91 -0
- package/src/plugin/Progress.tsx +132 -0
- package/src/plugin/Property.tsx +139 -0
- package/src/plugin/QRCode.tsx +98 -0
- package/src/plugin/Reset.tsx +23 -0
- package/src/plugin/Service.tsx +167 -0
- package/src/plugin/Sparkline.tsx +40 -0
- package/src/plugin/Status.tsx +78 -0
- package/src/plugin/Steps.tsx +140 -0
- package/src/plugin/Submit.tsx +23 -0
- package/src/plugin/Table.tsx +440 -0
- package/src/plugin/TableView.tsx +711 -0
- package/src/plugin/Tabs.tsx +364 -0
- package/src/plugin/Tasks.tsx +276 -0
- package/src/plugin/Time.tsx +75 -0
- package/src/plugin/TooltipWrapper.tsx +193 -0
- package/src/plugin/Tpl.tsx +162 -0
- package/src/plugin/Video.tsx +160 -0
- package/src/plugin/WebComponent.tsx +56 -0
- package/src/plugin/Wizard.tsx +743 -0
- package/src/plugin/Wrapper.tsx +107 -0
- package/src/plugin.ts +1046 -0
- package/dist/150a58f3318ca7541ed9.png +0 -0
- package/dist/471adb97c322b226e589.png +0 -0
- package/dist/4de5f42360bc5946c3c2.png +0 -0
- package/dist/4e9968bba3855f088fed.png +0 -0
- package/dist/7f09c38ebc687fea847a.png +0 -0
- package/dist/c94073576487510314ea.png +0 -0
@@ -0,0 +1,727 @@
|
|
1
|
+
import {Button} from 'amis';
|
2
|
+
import React from 'react';
|
3
|
+
import {registerEditorPlugin} from '../manager';
|
4
|
+
import {
|
5
|
+
BaseEventContext,
|
6
|
+
BasePlugin,
|
7
|
+
ContextMenuEventContext,
|
8
|
+
ContextMenuItem,
|
9
|
+
PluginEvent,
|
10
|
+
RendererJSONSchemaResolveEventContext,
|
11
|
+
VRendererConfig,
|
12
|
+
ResizeMoveEventContext
|
13
|
+
} from '../plugin';
|
14
|
+
import {defaultValue, getSchemaTpl} from '../component/schemaTpl';
|
15
|
+
import {EditorNodeType} from '../store/node';
|
16
|
+
import {Schema} from 'amis/lib/types';
|
17
|
+
import {VRenderer} from '../component/VRenderer';
|
18
|
+
import {RegionWrapper as Region} from '../component/RegionWrapper';
|
19
|
+
import {JSONChangeInArray, JSONPipeIn, repeatArray} from '../util';
|
20
|
+
import {Icon} from '../icons/index';
|
21
|
+
|
22
|
+
export class HBoxPlugin extends BasePlugin {
|
23
|
+
// 关联渲染器名字
|
24
|
+
rendererName = 'hbox';
|
25
|
+
$schema = '/schemas/HBoxSchema.json';
|
26
|
+
disabledRendererPlugin = true; // 组件面板不显示
|
27
|
+
|
28
|
+
// 组件名称
|
29
|
+
name = 'HBox';
|
30
|
+
isBaseComponent = true;
|
31
|
+
icon = 'fa fa-columns';
|
32
|
+
description =
|
33
|
+
'用来实现左右排版布局,默认平均分配,可以通过 columnClassName 配置某列的宽度。';
|
34
|
+
docLink = '/amis/zh-CN/components/hbox';
|
35
|
+
tags = ['容器'];
|
36
|
+
scaffold = {
|
37
|
+
type: 'hbox',
|
38
|
+
gap: 'base',
|
39
|
+
columns: [
|
40
|
+
{
|
41
|
+
body: []
|
42
|
+
},
|
43
|
+
{
|
44
|
+
body: []
|
45
|
+
}
|
46
|
+
]
|
47
|
+
};
|
48
|
+
previewSchema = {
|
49
|
+
type: 'hbox',
|
50
|
+
columns: [
|
51
|
+
{
|
52
|
+
type: 'tpl',
|
53
|
+
tpl: '固定宽度<br />w-xs',
|
54
|
+
columnClassName: 'bg-primary w-xs'
|
55
|
+
},
|
56
|
+
{
|
57
|
+
type: 'tpl',
|
58
|
+
tpl: '自动填满',
|
59
|
+
columnClassName: 'bg-success'
|
60
|
+
}
|
61
|
+
]
|
62
|
+
};
|
63
|
+
|
64
|
+
panelTitle = 'HBox';
|
65
|
+
panelBodyCreator = (context: BaseEventContext) => [
|
66
|
+
getSchemaTpl('tabs', [
|
67
|
+
{
|
68
|
+
title: '常规',
|
69
|
+
body: [
|
70
|
+
getSchemaTpl('fieldSet', {
|
71
|
+
title: '插入',
|
72
|
+
collapsable: false,
|
73
|
+
body: [
|
74
|
+
{
|
75
|
+
type: 'wrapper',
|
76
|
+
size: 'none',
|
77
|
+
className: 'grid grid-cols-2 gap-4 mb-4',
|
78
|
+
body: [
|
79
|
+
{
|
80
|
+
children: (
|
81
|
+
<Button
|
82
|
+
size="sm"
|
83
|
+
onClick={() => this.insertRowAfter(context.node)}
|
84
|
+
>
|
85
|
+
<Icon className="icon" icon="arrow-to-bottom" />
|
86
|
+
<span>下方插入新行</span>
|
87
|
+
</Button>
|
88
|
+
)
|
89
|
+
},
|
90
|
+
{
|
91
|
+
children: (
|
92
|
+
<Button
|
93
|
+
size="sm"
|
94
|
+
onClick={() => this.insertRowBefore(context.node)}
|
95
|
+
>
|
96
|
+
<Icon className="icon" icon="top-arrow-to-top" />
|
97
|
+
<span>上方插入新行</span>
|
98
|
+
</Button>
|
99
|
+
)
|
100
|
+
}
|
101
|
+
]
|
102
|
+
},
|
103
|
+
|
104
|
+
{
|
105
|
+
label: '列数',
|
106
|
+
name: 'columns',
|
107
|
+
type: 'select',
|
108
|
+
pipeIn: (value: any) =>
|
109
|
+
Array.isArray(value) ? value.length : undefined,
|
110
|
+
pipeOut: (value: any, origin: any) => {
|
111
|
+
if (Array.isArray(origin)) {
|
112
|
+
if (origin.length > value) {
|
113
|
+
origin = origin.concat();
|
114
|
+
origin.splice(value - 1, origin.length - value);
|
115
|
+
} else {
|
116
|
+
origin = origin.concat(
|
117
|
+
repeatArray(
|
118
|
+
{
|
119
|
+
body: []
|
120
|
+
},
|
121
|
+
value - origin.length
|
122
|
+
)
|
123
|
+
);
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
return origin;
|
128
|
+
},
|
129
|
+
options: repeatArray(null, 12).map((_, index) => ({
|
130
|
+
label: `${index + 1}`,
|
131
|
+
value: index + 1
|
132
|
+
}))
|
133
|
+
}
|
134
|
+
]
|
135
|
+
}),
|
136
|
+
|
137
|
+
{
|
138
|
+
type: 'list-select',
|
139
|
+
name: 'gap',
|
140
|
+
label: '列间距',
|
141
|
+
size: 'sm',
|
142
|
+
clearable: true,
|
143
|
+
tiled: true,
|
144
|
+
options: [
|
145
|
+
{
|
146
|
+
label: '极小',
|
147
|
+
value: 'xs'
|
148
|
+
},
|
149
|
+
{
|
150
|
+
label: '小',
|
151
|
+
value: 'sm'
|
152
|
+
},
|
153
|
+
{
|
154
|
+
label: '正常',
|
155
|
+
value: 'base'
|
156
|
+
},
|
157
|
+
{
|
158
|
+
label: '中',
|
159
|
+
value: 'md'
|
160
|
+
},
|
161
|
+
{
|
162
|
+
label: '大',
|
163
|
+
value: 'lg'
|
164
|
+
}
|
165
|
+
]
|
166
|
+
},
|
167
|
+
|
168
|
+
{
|
169
|
+
name: 'columns',
|
170
|
+
label: '列集合',
|
171
|
+
type: 'combo',
|
172
|
+
scaffold: {
|
173
|
+
body: []
|
174
|
+
},
|
175
|
+
minLength: 1,
|
176
|
+
multiple: true,
|
177
|
+
// draggable: true,
|
178
|
+
draggableTip: '',
|
179
|
+
items: [
|
180
|
+
{
|
181
|
+
type: 'tpl',
|
182
|
+
tpl: '<span class="label label-default">列${index | plus}</span>',
|
183
|
+
columnClassName: 'no-grow v-middle'
|
184
|
+
},
|
185
|
+
getSchemaTpl('className', {
|
186
|
+
name: 'columnClassName',
|
187
|
+
labelRemark: '',
|
188
|
+
label: ''
|
189
|
+
})
|
190
|
+
]
|
191
|
+
},
|
192
|
+
getSchemaTpl('fieldSet', {
|
193
|
+
title: '水平对齐',
|
194
|
+
collapsable: false,
|
195
|
+
body: [
|
196
|
+
{
|
197
|
+
type: 'button-group-select',
|
198
|
+
name: 'align',
|
199
|
+
size: 'sm',
|
200
|
+
label: false,
|
201
|
+
tiled: true,
|
202
|
+
pipeIn: defaultValue('left'),
|
203
|
+
options: [
|
204
|
+
{
|
205
|
+
value: 'left',
|
206
|
+
label: '左对齐'
|
207
|
+
},
|
208
|
+
{
|
209
|
+
value: 'center',
|
210
|
+
label: '中间对齐'
|
211
|
+
},
|
212
|
+
{
|
213
|
+
value: 'right',
|
214
|
+
label: '右对齐'
|
215
|
+
},
|
216
|
+
{
|
217
|
+
value: 'between',
|
218
|
+
label: '两端对齐'
|
219
|
+
}
|
220
|
+
]
|
221
|
+
}
|
222
|
+
]
|
223
|
+
}),
|
224
|
+
|
225
|
+
getSchemaTpl('fieldSet', {
|
226
|
+
title: '垂直对齐',
|
227
|
+
collapsable: false,
|
228
|
+
body: [
|
229
|
+
{
|
230
|
+
type: 'button-group-select',
|
231
|
+
name: 'valign',
|
232
|
+
size: 'sm',
|
233
|
+
label: false,
|
234
|
+
tiled: true,
|
235
|
+
pipeIn: defaultValue('top'),
|
236
|
+
options: [
|
237
|
+
{
|
238
|
+
value: 'top',
|
239
|
+
label: '顶部对齐'
|
240
|
+
},
|
241
|
+
{
|
242
|
+
value: 'middle',
|
243
|
+
label: '中间对齐'
|
244
|
+
},
|
245
|
+
{
|
246
|
+
value: 'bottom',
|
247
|
+
label: '底部对齐'
|
248
|
+
},
|
249
|
+
{
|
250
|
+
value: 'between',
|
251
|
+
label: '两端对齐'
|
252
|
+
}
|
253
|
+
]
|
254
|
+
}
|
255
|
+
]
|
256
|
+
})
|
257
|
+
]
|
258
|
+
},
|
259
|
+
{
|
260
|
+
title: '外观',
|
261
|
+
body: [
|
262
|
+
getSchemaTpl('className'),
|
263
|
+
getSchemaTpl('subFormItemMode'),
|
264
|
+
getSchemaTpl('subFormHorizontalMode'),
|
265
|
+
getSchemaTpl('subFormHorizontal')
|
266
|
+
]
|
267
|
+
},
|
268
|
+
{
|
269
|
+
title: '显隐',
|
270
|
+
body: [getSchemaTpl('visible')]
|
271
|
+
}
|
272
|
+
])
|
273
|
+
];
|
274
|
+
|
275
|
+
vRendererConfig: VRendererConfig = {
|
276
|
+
regions: {
|
277
|
+
body: {
|
278
|
+
key: 'body',
|
279
|
+
label: '内容区',
|
280
|
+
placeholder: '列',
|
281
|
+
wrapperResolve: (dom: HTMLElement) => dom
|
282
|
+
}
|
283
|
+
},
|
284
|
+
panelTitle: '列',
|
285
|
+
panelBodyCreator: (context: BaseEventContext) => {
|
286
|
+
return [
|
287
|
+
getSchemaTpl('tabs', [
|
288
|
+
{
|
289
|
+
title: '常规',
|
290
|
+
body: [
|
291
|
+
getSchemaTpl('fieldSet', {
|
292
|
+
title: '插入',
|
293
|
+
collapsable: false,
|
294
|
+
body: [
|
295
|
+
{
|
296
|
+
type: 'wrapper',
|
297
|
+
size: 'none',
|
298
|
+
className: 'grid grid-cols-2 gap-4',
|
299
|
+
body: [
|
300
|
+
{
|
301
|
+
children: (
|
302
|
+
<Button
|
303
|
+
size="sm"
|
304
|
+
onClick={() =>
|
305
|
+
this.insertRowAfter(context.node.host)
|
306
|
+
}
|
307
|
+
>
|
308
|
+
<Icon className="icon" icon="arrow-to-bottom" />
|
309
|
+
<span>下方插入新行</span>
|
310
|
+
</Button>
|
311
|
+
)
|
312
|
+
},
|
313
|
+
{
|
314
|
+
children: (
|
315
|
+
<Button
|
316
|
+
size="sm"
|
317
|
+
onClick={() =>
|
318
|
+
this.insertRowBefore(context.node.host)
|
319
|
+
}
|
320
|
+
>
|
321
|
+
<Icon className="icon" icon="top-arrow-to-top" />
|
322
|
+
<span>上方插入新行</span>
|
323
|
+
</Button>
|
324
|
+
)
|
325
|
+
},
|
326
|
+
{
|
327
|
+
children: (
|
328
|
+
<Button
|
329
|
+
size="sm"
|
330
|
+
onClick={() => this.insertColumnBefore(context)}
|
331
|
+
>
|
332
|
+
<Icon className="icon" icon="left-arrow-to-left" />
|
333
|
+
<span>左侧插入新列</span>
|
334
|
+
</Button>
|
335
|
+
)
|
336
|
+
},
|
337
|
+
{
|
338
|
+
children: (
|
339
|
+
<Button
|
340
|
+
size="sm"
|
341
|
+
onClick={() => this.insertColumnAfter(context)}
|
342
|
+
>
|
343
|
+
<Icon className="icon" icon="arrow-to-right" />
|
344
|
+
<span>右侧插入新列</span>
|
345
|
+
</Button>
|
346
|
+
)
|
347
|
+
}
|
348
|
+
]
|
349
|
+
}
|
350
|
+
]
|
351
|
+
}),
|
352
|
+
|
353
|
+
getSchemaTpl('fieldSet', {
|
354
|
+
title: '宽度设置',
|
355
|
+
collapsable: false,
|
356
|
+
body: [
|
357
|
+
{
|
358
|
+
type: 'button-group-select',
|
359
|
+
name: 'width',
|
360
|
+
size: 'sm',
|
361
|
+
label: false,
|
362
|
+
pipeIn: (value: any) =>
|
363
|
+
value && value !== 'auto' ? 'manual' : value || '',
|
364
|
+
pipeOut: (value: any) =>
|
365
|
+
value === 'manual' ? '20%' : value,
|
366
|
+
options: [
|
367
|
+
{
|
368
|
+
value: '',
|
369
|
+
label: '适配宽度'
|
370
|
+
},
|
371
|
+
{
|
372
|
+
value: 'auto',
|
373
|
+
label: '适配内容'
|
374
|
+
},
|
375
|
+
{
|
376
|
+
value: 'manual',
|
377
|
+
label: '手动'
|
378
|
+
}
|
379
|
+
],
|
380
|
+
description:
|
381
|
+
'<% if (this.width && this.width !== "auto") {%>请按住高亮框右侧方块拖动调整宽度<%}%>'
|
382
|
+
}
|
383
|
+
]
|
384
|
+
}),
|
385
|
+
|
386
|
+
getSchemaTpl('fieldSet', {
|
387
|
+
title: '垂直对齐',
|
388
|
+
collapsable: false,
|
389
|
+
body: [
|
390
|
+
{
|
391
|
+
type: 'button-group-select',
|
392
|
+
name: 'valign',
|
393
|
+
size: 'sm',
|
394
|
+
label: false,
|
395
|
+
tiled: true,
|
396
|
+
clearable: true,
|
397
|
+
options: [
|
398
|
+
{
|
399
|
+
value: 'top',
|
400
|
+
label: '顶部对齐'
|
401
|
+
},
|
402
|
+
{
|
403
|
+
value: 'middle',
|
404
|
+
label: '中间对齐'
|
405
|
+
},
|
406
|
+
{
|
407
|
+
value: 'bottom',
|
408
|
+
label: '底部对齐'
|
409
|
+
},
|
410
|
+
{
|
411
|
+
value: 'between',
|
412
|
+
label: '两端对齐'
|
413
|
+
}
|
414
|
+
]
|
415
|
+
}
|
416
|
+
]
|
417
|
+
})
|
418
|
+
]
|
419
|
+
},
|
420
|
+
{
|
421
|
+
title: '外观',
|
422
|
+
body: [
|
423
|
+
getSchemaTpl('className', {
|
424
|
+
name: 'columnClassName',
|
425
|
+
label: '列 CSS 类名',
|
426
|
+
description: '可以添加宽度类样式调整宽度,默认宽度为平均分配。'
|
427
|
+
})
|
428
|
+
]
|
429
|
+
}
|
430
|
+
])
|
431
|
+
];
|
432
|
+
}
|
433
|
+
};
|
434
|
+
|
435
|
+
vWrapperResolve = (dom: HTMLElement) => dom;
|
436
|
+
overrides = {
|
437
|
+
renderColumn: function (this: any, node: Schema, index: number) {
|
438
|
+
const dom = this.super(node, index);
|
439
|
+
const info = this.props.$$editor;
|
440
|
+
|
441
|
+
if (info && node.$$id) {
|
442
|
+
const plugin: HBoxPlugin = info.plugin as any;
|
443
|
+
const region = plugin.vRendererConfig?.regions?.body;
|
444
|
+
if (!region) {
|
445
|
+
return dom;
|
446
|
+
}
|
447
|
+
|
448
|
+
return (
|
449
|
+
<VRenderer
|
450
|
+
key={node.$$id}
|
451
|
+
plugin={info.plugin}
|
452
|
+
renderer={info.renderer}
|
453
|
+
$schema="" // /schemas/GridColumn.json
|
454
|
+
hostId={info.id}
|
455
|
+
memberIndex={index}
|
456
|
+
name={`第${index + 1}列`}
|
457
|
+
id={node.$$id}
|
458
|
+
draggable={false}
|
459
|
+
schemaPath={`${info.schemaPath}/hbox/${index}`}
|
460
|
+
wrapperResolve={plugin.vWrapperResolve}
|
461
|
+
path={`${this.props.$path}/${index}`} // 好像没啥用
|
462
|
+
data={this.props.data} // 好像没啥用
|
463
|
+
widthMutable
|
464
|
+
>
|
465
|
+
{region ? (
|
466
|
+
<Region
|
467
|
+
key={region.key}
|
468
|
+
preferTag={region.preferTag}
|
469
|
+
name={region.key}
|
470
|
+
label={region.label}
|
471
|
+
regionConfig={region}
|
472
|
+
placeholder={region.placeholder}
|
473
|
+
editorStore={plugin.manager.store}
|
474
|
+
manager={plugin.manager}
|
475
|
+
children={dom}
|
476
|
+
wrapperResolve={region.wrapperResolve}
|
477
|
+
rendererName={info.renderer.name}
|
478
|
+
/>
|
479
|
+
) : (
|
480
|
+
dom
|
481
|
+
)}
|
482
|
+
</VRenderer>
|
483
|
+
);
|
484
|
+
}
|
485
|
+
return dom;
|
486
|
+
}
|
487
|
+
};
|
488
|
+
|
489
|
+
// buildEditorPanel(context: BaseEventContext, panels: Array<BasicPanelItem>) {
|
490
|
+
// super.buildEditorPanel(context, panels);
|
491
|
+
// const parent = context.node.parent?.host as EditorNodeType;
|
492
|
+
|
493
|
+
// if (
|
494
|
+
// parent?.info?.plugin === this &&
|
495
|
+
// (this.vRendererConfig.panelControls ||
|
496
|
+
// this.vRendererConfig.panelControlsCreator)
|
497
|
+
// ) {
|
498
|
+
// panels.push({
|
499
|
+
// key: 'grid',
|
500
|
+
// order: 100,
|
501
|
+
// icon: this.vRendererConfig.panelIcon || 'fa fa-tablet',
|
502
|
+
// title: this.vRendererConfig.panelTitle || '格子',
|
503
|
+
// render: this.manager.makeSchemaFormRender({
|
504
|
+
// body: this.vRendererConfig.panelControlsCreator
|
505
|
+
// ? this.vRendererConfig.panelControlsCreator(context)
|
506
|
+
// : this.vRendererConfig.panelControls!
|
507
|
+
// })
|
508
|
+
// });
|
509
|
+
// }
|
510
|
+
// }
|
511
|
+
|
512
|
+
afterResolveJsonSchema(
|
513
|
+
event: PluginEvent<RendererJSONSchemaResolveEventContext>
|
514
|
+
) {
|
515
|
+
const context = event.context;
|
516
|
+
const parent = context.node.parent?.host as EditorNodeType;
|
517
|
+
|
518
|
+
if (parent?.info?.plugin === this) {
|
519
|
+
event.setData('/schemas/HBoxColumn.json');
|
520
|
+
}
|
521
|
+
}
|
522
|
+
|
523
|
+
buildEditorContextMenu(
|
524
|
+
context: ContextMenuEventContext,
|
525
|
+
menus: Array<ContextMenuItem>
|
526
|
+
) {
|
527
|
+
if (context.selections.length || context.info?.plugin !== this) {
|
528
|
+
return;
|
529
|
+
}
|
530
|
+
|
531
|
+
if (context.node.isVitualRenderer) {
|
532
|
+
menus.push('|');
|
533
|
+
|
534
|
+
menus.push({
|
535
|
+
label: '左侧插入一列',
|
536
|
+
onSelect: () => this.insertColumnBefore(context)
|
537
|
+
});
|
538
|
+
|
539
|
+
menus.push({
|
540
|
+
label: '右侧插入一列',
|
541
|
+
onSelect: () => this.insertColumnAfter(context)
|
542
|
+
});
|
543
|
+
|
544
|
+
menus.push('|');
|
545
|
+
|
546
|
+
menus.push({
|
547
|
+
label: '上方插入一行',
|
548
|
+
onSelect: () => this.insertRowBefore(context.node.host)
|
549
|
+
});
|
550
|
+
|
551
|
+
menus.push({
|
552
|
+
label: '下方插入一行',
|
553
|
+
onSelect: () => this.insertRowAfter(context.node.host)
|
554
|
+
});
|
555
|
+
} else {
|
556
|
+
menus.push('|');
|
557
|
+
|
558
|
+
menus.push({
|
559
|
+
label: '上方插入一行',
|
560
|
+
onSelect: () => this.insertRowBefore(context.node)
|
561
|
+
});
|
562
|
+
|
563
|
+
menus.push({
|
564
|
+
label: '下方插入一行',
|
565
|
+
onSelect: () => this.insertRowAfter(context.node)
|
566
|
+
});
|
567
|
+
}
|
568
|
+
}
|
569
|
+
|
570
|
+
onWidthChangeStart(
|
571
|
+
event: PluginEvent<
|
572
|
+
ResizeMoveEventContext,
|
573
|
+
{
|
574
|
+
onMove(e: MouseEvent): void;
|
575
|
+
onEnd(e: MouseEvent): void;
|
576
|
+
}
|
577
|
+
>
|
578
|
+
) {
|
579
|
+
const context = event.context;
|
580
|
+
const node = context.node;
|
581
|
+
if (node.info?.plugin !== this) {
|
582
|
+
return;
|
583
|
+
}
|
584
|
+
const host = node.host;
|
585
|
+
if (!host || host.info?.plugin !== this) {
|
586
|
+
return;
|
587
|
+
}
|
588
|
+
|
589
|
+
const dom = context.dom;
|
590
|
+
const parent = dom.parentElement as HTMLElement;
|
591
|
+
if (!parent) {
|
592
|
+
return;
|
593
|
+
}
|
594
|
+
const resizer = context.resizer;
|
595
|
+
const frameRect = parent.getBoundingClientRect();
|
596
|
+
let columns = host.schema.columns;
|
597
|
+
const index = node.index;
|
598
|
+
let finalWidth = columns[index].width;
|
599
|
+
const rect = dom.getBoundingClientRect();
|
600
|
+
|
601
|
+
event.setData({
|
602
|
+
onMove: (e: MouseEvent) => {
|
603
|
+
const width = e.pageX - rect.left;
|
604
|
+
const percent = (finalWidth = `${Math.max(
|
605
|
+
1,
|
606
|
+
Math.min(99, Math.round((100 * width) / frameRect.width))
|
607
|
+
)}%`);
|
608
|
+
columns = columns.concat();
|
609
|
+
columns[index] = {
|
610
|
+
...columns[index],
|
611
|
+
width: percent
|
612
|
+
};
|
613
|
+
resizer.setAttribute('data-value', percent);
|
614
|
+
|
615
|
+
host.updateState({
|
616
|
+
columns
|
617
|
+
});
|
618
|
+
requestAnimationFrame(() => {
|
619
|
+
node.calculateHighlightBox();
|
620
|
+
});
|
621
|
+
},
|
622
|
+
onEnd: () => {
|
623
|
+
host.updateState({}, true);
|
624
|
+
resizer.removeAttribute('data-value');
|
625
|
+
node.updateSchema({
|
626
|
+
width: finalWidth
|
627
|
+
});
|
628
|
+
requestAnimationFrame(() => {
|
629
|
+
node.calculateHighlightBox();
|
630
|
+
});
|
631
|
+
}
|
632
|
+
});
|
633
|
+
}
|
634
|
+
|
635
|
+
insertRowAfter(node: EditorNodeType) {
|
636
|
+
if (node.info?.plugin !== this) {
|
637
|
+
return;
|
638
|
+
}
|
639
|
+
const store = this.manager.store;
|
640
|
+
const schema = store.schema;
|
641
|
+
const id = node.id;
|
642
|
+
store.traceableSetSchema(
|
643
|
+
JSONChangeInArray(schema, id, (arr: any[], node: any, index: number) => {
|
644
|
+
arr.splice(
|
645
|
+
index + 1,
|
646
|
+
0,
|
647
|
+
JSONPipeIn({
|
648
|
+
type: 'hbox',
|
649
|
+
align: node.align,
|
650
|
+
valign: node.valign,
|
651
|
+
columns: node.columns.map((column: any) => ({
|
652
|
+
body: [],
|
653
|
+
width: column?.width
|
654
|
+
}))
|
655
|
+
})
|
656
|
+
);
|
657
|
+
})
|
658
|
+
);
|
659
|
+
}
|
660
|
+
insertRowBefore(node: EditorNodeType) {
|
661
|
+
if (node.info?.plugin !== this) {
|
662
|
+
return;
|
663
|
+
}
|
664
|
+
const store = this.manager.store;
|
665
|
+
const id = node.id;
|
666
|
+
const schema = store.schema;
|
667
|
+
store.traceableSetSchema(
|
668
|
+
JSONChangeInArray(schema, id, (arr: any[], node: any, index: number) => {
|
669
|
+
arr.splice(
|
670
|
+
index,
|
671
|
+
0,
|
672
|
+
JSONPipeIn({
|
673
|
+
type: 'hbox',
|
674
|
+
align: node.align,
|
675
|
+
valign: node.valign,
|
676
|
+
columns: node.columns.map((column: any) => ({
|
677
|
+
body: [],
|
678
|
+
width: column?.width
|
679
|
+
}))
|
680
|
+
})
|
681
|
+
);
|
682
|
+
})
|
683
|
+
);
|
684
|
+
}
|
685
|
+
insertColumnBefore(context: BaseEventContext) {
|
686
|
+
const node = context.node;
|
687
|
+
if (node.info?.plugin !== this) {
|
688
|
+
return;
|
689
|
+
}
|
690
|
+
const store = this.manager.store;
|
691
|
+
const schema = store.schema;
|
692
|
+
const id = context.id;
|
693
|
+
store.traceableSetSchema(
|
694
|
+
JSONChangeInArray(schema, id, (arr: any[], node: any, index: number) => {
|
695
|
+
arr.splice(
|
696
|
+
index,
|
697
|
+
0,
|
698
|
+
JSONPipeIn({
|
699
|
+
body: []
|
700
|
+
})
|
701
|
+
);
|
702
|
+
})
|
703
|
+
);
|
704
|
+
}
|
705
|
+
insertColumnAfter(context: BaseEventContext) {
|
706
|
+
const node = context.node;
|
707
|
+
if (node.info?.plugin !== this) {
|
708
|
+
return;
|
709
|
+
}
|
710
|
+
const id = context.id;
|
711
|
+
const store = this.manager.store;
|
712
|
+
const schema = store.schema;
|
713
|
+
store.traceableSetSchema(
|
714
|
+
JSONChangeInArray(schema, id, (arr: any[], node: any, index: number) => {
|
715
|
+
arr.splice(
|
716
|
+
index + 1,
|
717
|
+
0,
|
718
|
+
JSONPipeIn({
|
719
|
+
body: []
|
720
|
+
})
|
721
|
+
);
|
722
|
+
})
|
723
|
+
);
|
724
|
+
}
|
725
|
+
}
|
726
|
+
|
727
|
+
registerEditorPlugin(HBoxPlugin);
|