amis-editor 4.1.0-beta.1 → 4.1.0-beta.19

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