forked from alibaba/lowcode-plugins
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.tsx
More file actions
79 lines (64 loc) · 1.83 KB
/
index.tsx
File metadata and controls
79 lines (64 loc) · 1.83 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
import { TransformedComponentMetadata, FieldConfig } from '@alilc/lowcode-types';
import { v4 as uuidv4 } from 'uuid';
import { material } from '@alilc/lowcode-engine';
function addonCombine(metadata: TransformedComponentMetadata) {
const { componentName, configure = {} } = metadata;
const isRoot: boolean = componentName === 'Page' || componentName === 'Component';
if (isRoot) {
return metadata;
}
let advancedGroup: FieldConfig | undefined;
const refItem: FieldConfig = {
title: {
label: 'refId',
tip: '用于获取组件实例,调用物料内部方法',
icon: '',
},
name: 'ref',
setter: {
componentName: 'StringSetter',
},
defaultValue: () => {
const uuid = uuidv4().replace('-', '').substring(0, 8);
return `${componentName.toLowerCase()}-${uuid}`;
},
extraProps: {
display: 'block',
supportVariable: false,
},
};
if (!configure.combined) {
configure.combined = [];
}
advancedGroup = configure.combined?.filter(d => d.name === '#advanced')[0];
if (!advancedGroup) {
advancedGroup = {
name: '#advanced',
title: { type: 'i18n', 'zh-CN': '高级', 'en-US': 'Advanced' },
items: [
refItem,
],
};
configure.combined.push(advancedGroup);
}
if (!advancedGroup.items) {
advancedGroup.items = [refItem];
}
const advanceItems: FieldConfig[] = advancedGroup.items || [];
if (!advanceItems || !advanceItems.length || !advanceItems?.filter(d => d.name === 'ref').length) {
advanceItems.push(refItem);
}
return {
...metadata,
configure,
};
}
const SetRefPropPlugin = () => {
return {
init() {
material.registerMetadataTransducer(addonCombine, 110, 'register-ref-prop');
},
};
};
SetRefPropPlugin.pluginName = 'SetRefPropPlugin';
export default SetRefPropPlugin;