amis-editor 4.1.0-beta.4 → 4.2.0-beta.3

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