-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.jsx
276 lines (257 loc) · 8.04 KB
/
index.jsx
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
import init, { editor, project, material, setters, config } from '@alifd/lowcode-preset-plugin';
import mergeWith from 'lodash/mergeWith';
import AssetsExplorePlugin from '../lowcode/plugins/assets-explore/index';
const queryObject = new URLSearchParams(window.location.search);
const fullbackMeta = 'default' || '';
let platform = queryObject.get('platform') || '';
let metaType = queryObject.get('metaType') || platform || '';
const metaPathMap = {"meta":"/Users/mark.ck/Workspace/opensource/lowcode/3d-materials/.tmp/meta.js"};
const key = metaType ? `meta.${metaType}` : 'meta';
if (!metaPathMap[key]) {
console.warn(`[@alifd/build-plugin-lowcode] metaType can only in [${Object.keys(metaPathMap)}], current metaType is ${key}, fullback to ${fullbackMeta || 'default'}.`);
metaType = fullbackMeta === 'default' ? '' : fullbackMeta;
}
const isNewEngineVersion = !!material;
const devMode = !!true;
const baseLibrary = 'react';
const basePackages = [
{
package: 'moment',
version: '2.24.0',
urls: ['https://g.alicdn.com/mylib/moment/2.24.0/min/moment.min.js'],
library: 'moment',
},
{
package: "lodash",
library: "_",
urls: [
"https://g.alicdn.com/platform/c/lodash/4.6.1/lodash.min.js"
]
},
{
title: 'fusion组件库',
package: '@alifd/next',
version: '1.25.23',
urls: [
'https://g.alicdn.com/code/lib/alifd__next/1.25.23/next.min.css',
'https://g.alicdn.com/code/lib/alifd__next/1.25.23/next-with-locales.min.js',
],
library: 'Next',
},
{
package: 'antd',
version: '4.17.3',
urls: [
'https://g.alicdn.com/code/lib/antd/4.17.3/antd.min.js',
'https://g.alicdn.com/code/lib/antd/4.17.3/antd.min.css',
],
library: 'antd',
},
];
if (baseLibrary === 'rax') {
basePackages.push({
title: 'meet',
package: '@alifd/meet',
version: 'meet@2.4.2-beta.6',
urls: [
'https://mc-fusion.alibaba-inc.com/unpkg/@alifd/meet@2.4.2-beta.6/umd/meet.lowcode.js',
'https://mc-fusion.alibaba-inc.com/unpkg/@alifd/meet@2.4.2-beta.6/umd/meet.min.css',
],
library: 'Meet',
});
}
const assets = {
packages: []
};
let assetsName = './assets-dev.json';
const setterMap = {
};
const presetConfig = {"pluginConfig":{"logo":{"logo":"https://cdn.npmmirror.com/npmmirror-logo.png"}}};
const customPlugins = [
AssetsExplorePlugin
];
const type = 'component';
if (devMode && type !== 'setter') {
assets.packages.push({
"package": "@alilc/3d-materials",
"version": "0.1.0",
"library": "BizComps",
"urls": ["/view.js"],
"editUrls": ["/view.js"],
"advancedUrls": {"default":["./default.view.js"]},
});
assets.groupList = ["精选组件","原子组件"];
assets.sort = {
"groupList": ["精选组件","原子组件"],
"categoryList": ["基础元素","布局容器类","表格类","表单详情类","帮助类","对话框类","业务类","通用","引导","信息输入","信息展示","信息反馈"]
};
assets.ignoreComponents = {};
assets.components = [{
exportName: 'Alilc3dMaterialsMeta',
url: metaType ? `/meta.${metaType}.js` : '/meta.js',
}];
}
const schema = getPageSchema() || {
componentName: 'Page',
id: 'node_dockcviv8fo1',
props: {
ref: 'outterView',
style: {
height: '100%',
},
},
fileName: 'lowcode',
dataSource: {
list: [],
},
state: {
text: 'outter',
isShowDialog: false,
},
css: 'body {font-size: 12px;} .botton{width:100px;color:#ff00ff}',
lifeCycles: {
componentDidMount: {
type: 'JSFunction',
value: "function() {\n console.log('did mount');\n }",
},
componentWillUnmount: {
type: 'JSFunction',
value: "function() {\n console.log('will umount');\n }",
},
},
methods: {
testFunc: {
type: 'JSFunction',
value: "function() {\n console.log('test func');\n }",
},
onClick: {
type: 'JSFunction',
value: 'function() {\n this.setState({\n isShowDialog: true\n })\n }',
},
closeDialog: {
type: 'JSFunction',
value: 'function() {\n this.setState({\n isShowDialog: false\n })\n }',
},
},
children: [],
};
const LCE_CONTAINER = document.getElementById('lce-container');
init(() => {
return {
name: 'editor-init',
async init() {
if (typeof setterMap === 'object' && Object.keys(setterMap).length) {
setters.registerSetter(setterMap);
}
if (!devMode) {
const devAssets = await (await fetch(assetsName)).json();
const packages = devAssets.packages;
assets.packages = assets.packages.concat(packages);
assets.components = devAssets.components.map(item => {
if (item.advancedUrls && metaType && item.advancedUrls[metaType] && item.advancedUrls[metaType].length) {
item.url = item.advancedUrls[metaType][0];
} else if (item.urls && metaType && item.urls[metaType]) {
item.url = item.urls[metaType];
}
return item;
});
assets.groupList = devAssets.groupList;
} else {
const extraAssets = [];
const builtinAssets = [];
extraAssets && await handleExtraAssets(assets, extraAssets);
builtinAssets && await handleExtraAssets(assets, builtinAssets);
}
// Overwrite the same library in basePackages
const packagesMap = new Map();
const sortedKeys = [...new Set(
[...basePackages, ...assets.packages].map((item) => {
const { library } = item;
packagesMap.set(library, item);
return library;
})
)];
assets.packages = sortedKeys.map((key) => packagesMap.get(key));
assets.packages = assets.packages.map(item => {
if (item.editUrls && item.editUrls.length) {
item.renderUrls = item.urls;
item.urls = item.editUrls;
}
return item;
})
if (baseLibrary && baseLibrary === 'rax') {
if (isNewEngineVersion) {
config.set('renderEnv', 'rax');
config.set('simulatorUrl', undefined);
} else {
editor.set('renderEnv', 'rax');
project.onRendererReady(() => {
editor.get('designer').currentDocument.simulator._iframe.onload = () => {
editor.get('designer').currentDocument.simulator.set('device', 'phone');
}
});
}
}
if (isNewEngineVersion) {
material.setAssets(assets);
project.openDocument(schema);
} else {
editor.setAssets(assets);
project.open(schema);
}
},
}
}, customPlugins || [], LCE_CONTAINER, {
...presetConfig
});
function getPageSchema() {
const schema = JSON.parse(
window.localStorage.getItem('projectSchema') || '{}'
);
const pageSchema = schema?.componentsTree?.[0];
return pageSchema;
};
async function handleExtraAssets(assets, extraAssets) {
if (extraAssets && Array.isArray(extraAssets) && extraAssets.length) {
const baseSchemas = await Promise.all(
extraAssets.map(async (url) => {
if (typeof url === 'object') {
return url;
} else {
try {
return (await fetch(url)).json();
} catch (e) {
console.error(`get assets data from builtin assets ${url} failed: `, e);
return {};
}
}
})
);
baseSchemas.forEach((item) => {
const _assets = {
...item,
packages: item.packages || [item.package],
components: item.components,
componentList: (item.componentList || []).map((comp) => {
if (comp.children) {
comp.children = comp.children.map((snippet) => {
if (!snippet.sort) {
snippet.sort = {
category: comp.title,
group: '原子组件',
};
}
return snippet;
});
}
return comp;
}),
};
mergeWith(assets, _assets, (objValue, srcValue) => {
if (Array.isArray(objValue) && Array.isArray(srcValue)) {
return srcValue.concat(objValue);
}
});
});
}
}