forked from alibaba/lowcode-materials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeta.ts
More file actions
415 lines (399 loc) · 12.2 KB
/
meta.ts
File metadata and controls
415 lines (399 loc) · 12.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
module.exports = {
group: '原子组件',
componentName: 'Dialog',
title: '对话框',
docUrl: '',
screenshot: '',
npm: {
package: '@alifd/next',
version: '{{version}}',
exportName: 'Dialog',
main: '',
destructuring: true,
subName: '',
},
props: [
{
name: 'id',
propType: 'string',
},
{
name: 'visible',
propType: {
type: 'oneOfType',
value: ['JSExpression', 'bool'],
},
description: '是否显示',
defaultValue: false,
},
{
name: 'title',
propType: {
type: 'oneOfType',
value: ['string', 'node'],
},
description: '标题',
},
{
name: 'children',
propType: {
type: 'oneOfType',
value: [
'bool',
{
type: 'instanceOf',
value: 'node',
},
],
},
description: '内容',
},
{
name: 'footer',
propType: {
type: 'oneOfType',
value: ['bool'],
},
description: '底部按钮',
},
{
name: 'footerAlign',
propType: {
type: 'oneOf',
value: ['left', 'center', 'right'],
},
description: '操作对齐方式',
defaultValue: 'right',
},
{
name: 'closeable',
propType: {
type: 'oneOf',
value: ['close', 'mask', 'esc,close', 'close,esc,mask', 'esc'],
},
description: '关闭方式',
defaultValue: 'esc,close',
},
{
name: 'onClose',
propType: 'func',
description:
'对话框关闭时触发的回调函数\n@param {String} trigger 关闭触发行为的描述字符串\n@param {Object} event 关闭时事件对象',
},
{
name: 'hasMask',
propType: 'bool',
description: '是否显示遮罩',
defaultValue: true,
},
{
name: 'animation',
propType: {
type: 'oneOfType',
value: ['object', 'bool'],
},
description:
'显示隐藏时动画的播放方式\n@property {String} in 进场动画\n@property {String} out 出场动画',
},
{
name: 'autoFocus',
propType: 'bool',
description: '是否获得焦点',
defaultValue: false,
},
{
name: 'isFullScreen',
propType: 'bool',
description: '是否全屏',
defaultValue: false,
},
{
name: 'style',
propType: 'object',
},
],
configure: {
component: {
isContainer: true,
isModal: true,
rootSelector: 'div.next-dialog',
nestingRule: {
parentWhitelist: ['Page'],
},
},
props: [
{
name: 'title',
title: '标题',
setter: 'StringSetter',
supportVariable: true,
initialValue: '标题',
},
{
name: 'visible',
title: '是否显示',
setter: 'BoolSetter',
supportVariable: true,
initialValue: false,
},
{
name: 'hasMask',
title: '显示遮罩',
setter: 'BoolSetter',
supportVariable: true,
initialValue: true,
},
{
name: 'closeMode',
title: '关闭方式',
setter: {
componentName: 'SelectSetter',
mutiple: true,
props: {
options: [
{
title: 'close',
value: 'close',
},
{
title: 'mask',
value: 'mask',
},
{
title: 'esc',
value: 'esc',
},
],
},
},
initialValue: ['esc', 'close'],
},
{
name: 'autoFocus',
title: '自动聚焦',
setter: 'BoolSetter',
supportVariable: true,
initialValue: false,
},
{
name: 'buttons',
title: '底部按钮配置',
type: 'group',
extraProps: {
display: 'block',
},
items: [
{
name: 'footer',
title: '是否显示',
setter: 'BoolSetter',
supportVariable: true,
initialValue: true,
},
{
name: 'footerAlign',
title: '对齐方式',
initialValue: 'right',
condition: (target) => {
return target.parent.getPropValue('footer');
},
setter: {
componentName: 'RadioGroupSetter',
initialValue: 'right',
props: {
options: [
{
title: 'left',
value: 'left',
},
{
title: 'center',
value: 'center',
},
{
title: 'right',
value: 'right',
},
],
},
},
},
{
name: 'footerActions',
title: '排列方式',
initialValue: ['ok', 'cancel'],
condition: (target) => {
return target.parent.getPropValue('footer');
},
setter: {
componentName: 'SelectSetter',
initialValue: ['ok', 'cancel'],
props: {
options: [
{
title: 'ok, cancel',
value: ['ok', 'cancel'],
},
{
title: 'cancel, ok',
value: ['cancel', 'ok'],
},
{
title: 'cancel',
value: ['cancel'],
},
{
title: 'ok',
value: ['ok'],
},
],
},
},
},
],
},
],
supports: {
events: ['onOk', 'onCancel', 'onClose'],
style: true,
},
advanced: {
callbacks: {
// 与 next-page 的 onNodeAdd 一模一样
onNodeAdd: (dragment, currentNode) => {
// 拖入的组件为 P、Block、Slot(把NextPage拖入到面板里时,NextPage的Slot也会触发onNodeAdd事件) 时,不进行包裹
// 拖入的组件 isModal为true时(例如drawer dialog 这类有单独组件树结构的),不进行包裹
if (
!dragment ||
['NextP', 'NextBlock', 'Slot'].includes(dragment.componentName) ||
(dragment.componentMeta.isModal && dragment.componentMeta.isModal())
) {
console.log(
`[${dragment.componentName}] doesn\'n need to wrap with NextBlock > NextBlockCell`,
);
return;
}
const NextPProps = {
wrap: false,
type: 'body2',
verAlign: 'middle',
textSpacing: true,
align: 'left',
};
if (
[
'Form',
'ResponsiveGrid',
'Box',
'Card',
'List',
'Message',
'Slider',
'NextTable',
].includes(dragment.componentName) ||
dragment.getPropValue('isFillContainer')
) {
NextPProps.full = true;
}
const layoutPSchema = {
componentName: 'NextP',
title: '段落',
props: NextPProps,
children: [dragment.exportSchema()],
};
// 为目标元素包裹一层 Block
const layoutBlockNode = (len) =>
currentNode.document.createNode({
componentName: 'NextBlock',
title: '区块',
props: {
childTotalColumns: len || 12,
},
children: [
{
componentName: 'NextBlockCell',
title: '子区块',
props: {
isAutoContainer: true,
colSpan: 12,
rowSpan: 1,
},
children: [layoutPSchema],
},
],
});
const dropLocation = dragment.document.canvas.dropLocation;
if (!dropLocation) {
// 没有 dropLocation 一般是 slot, slot 元素不用特殊处理 不做任何包裹
return;
}
const dropTarget = dropLocation.target;
const dropTargetName = dropLocation.target.componentName || '';
// 找到要拖入进去的节点 ID
const targetId = (dropLocation && dropLocation.target.id) || '';
// 找到要拖入进去的节点
let slotTarget =
currentNode.slots.length > 0 && currentNode.slots.find((item) => item.id === targetId);
const layoutPNode = currentNode.document.createNode(layoutPSchema);
// 是否为 aside slot
const isAsideSlot = slotTarget && ['aside'].indexOf(slotTarget._slotFor.key) > -1;
// 是否为需要被 P 包裹的 Slot
const isNeedPSlot =
slotTarget && ['header', 'footer', 'nav'].indexOf(slotTarget._slotFor.key) > -1;
const wrapWithBlock = (dragment, node, dropTargetName, blockLen) => {
setTimeout(() => {
console.log(
`[${dragment.componentName}] to [${dropTargetName}] need to wrap with NextBlock > NextBlockCell > NextP [from NextPage2]`,
);
const newNode = node.document.createNode(layoutBlockNode(blockLen).exportSchema());
node.insertBefore(newNode, dragment, false);
dragment.remove(false);
newNode.children.get(0).children.get(0).children.get(0).select();
}, 1);
};
const wrapWithP = (dragment, node, dropTargetName) => {
setTimeout(() => {
// const dragmentTarget = dropTarget;
// 要拖入的地方如果是 NextP 那就 不再自动包裹 P了
if (dropTargetName === 'NextP') {
console.log(
`[${dragment.componentName}] to [${dropTargetName}] does't need to wrap with NextP. [from NextPage3]`,
);
return;
}
console.log(
`[${dragment.componentName}] to [${dropTargetName}] need to wrap with NextP [from NextPage3]`,
);
const newNode = node.document.createNode(Object.assign(layoutPNode.exportSchema()));
node.insertBefore(newNode, dragment, false);
dragment.remove(false);
newNode.children.get(0).select();
}, 1);
};
// 需要包裹 Block BlockCell P 的情况:
// 1. 组件拖入到 NextPage,的直接子元素下(不包括slot), 此时Block宽度为12
if (['NextPage'].includes(dropTargetName) && currentNode.children.has(dragment)) {
wrapWithBlock(dragment, currentNode, dropTargetName, 12);
// 需要包裹 Block BlockCell P 的情况:
// 2. 组件拖入到 NextPage 的 aside slot, 的直接子元素下 (不包括slot下的进一步内容),此时Block宽度为1
} else if (isAsideSlot && slotTarget && slotTarget.children.has(dragment)) {
wrapWithBlock(dragment, slotTarget, dropTargetName, 1);
// 需要包裹 P 的情况:
// 1. 如果是处于,开启了自然布局模式的容器组件中 (或者Tab里)
// 这里的Tab主要是给纪元epoch使用的,因为他们用到了 @ali/vc-deep 的TabLayout组件,没办法在这个组件上再增加属性 isAutoContainer
} else if (dropTarget.getPropValue('isAutoContainer') || dropTargetName === 'Tab.Item') {
wrapWithP(dragment, dropTarget, dropTargetName);
// 需要包裹 P 的情况:
// 2. 如果是处于,Page 的 nav header footer 中
} else if (isNeedPSlot && slotTarget) {
wrapWithP(dragment, slotTarget, dropTargetName);
}
// 其他维持原状,不进行其他设置
},
},
},
},
icon: '',
category: '布局容器类',
snippets: require('./snippets'),
};