@easy-editor/react-renderer 0.0.17 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -1
- package/dist/adapter/index.d.ts +17 -0
- package/dist/{renderer-core/base.d.ts → base.d.ts} +2 -2
- package/dist/component.d.ts +2 -0
- package/dist/components/FaultComponent.d.ts +4 -0
- package/dist/components/NotFoundComponent.d.ts +4 -0
- package/dist/{renderer-core/hoc → hoc}/leaf.d.ts +2 -1
- package/dist/{cjs/index.js → index.cjs} +374 -583
- package/dist/index.d.ts +10 -3
- package/dist/index.js +324 -516
- package/dist/page.d.ts +2 -0
- package/dist/renderer.d.ts +2 -0
- package/dist/setting-renderer/context.d.ts +8 -0
- package/dist/setting-renderer/index.d.ts +8 -0
- package/dist/types.d.ts +7 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/is.d.ts +3 -0
- package/package.json +16 -21
- package/dist/cjs/index.development.js +0 -2734
- package/dist/cjs/index.development.js.map +0 -1
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/index.production.js +0 -2734
- package/dist/cjs/index.production.js.map +0 -1
- package/dist/configure-renderer/context.d.ts +0 -13
- package/dist/configure-renderer/index.d.ts +0 -10
- package/dist/esm/index.development.js +0 -2699
- package/dist/esm/index.development.js.map +0 -1
- package/dist/esm/index.js +0 -2699
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.production.js +0 -2699
- package/dist/esm/index.production.js.map +0 -1
- package/dist/renderer-core/adapter/index.d.ts +0 -17
- package/dist/renderer-core/component.d.ts +0 -2
- package/dist/renderer-core/components/FaultComponent.d.ts +0 -7
- package/dist/renderer-core/components/NotFoundComponent.d.ts +0 -7
- package/dist/renderer-core/index.d.ts +0 -9
- package/dist/renderer-core/page.d.ts +0 -2
- package/dist/renderer-core/renderer.d.ts +0 -2
- package/dist/renderer-core/types.d.ts +0 -187
- package/dist/renderer-core/utils/classnames.d.ts +0 -1
- package/dist/renderer-core/utils/common.d.ts +0 -53
- package/dist/renderer-core/utils/index.d.ts +0 -4
- package/dist/renderer-core/utils/logger.d.ts +0 -5
- /package/dist/{renderer-core/context.d.ts → context.d.ts} +0 -0
- /package/dist/{renderer-core/hoc → hoc}/comp.d.ts +0 -0
- /package/dist/{renderer-core/hoc → hoc}/index.d.ts +0 -0
- /package/dist/{configure-renderer → setting-renderer}/SettingSetter.d.ts +0 -0
- /package/dist/{renderer-core/utils → utils}/hoc.d.ts +0 -0
|
@@ -1,263 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var mobxReact = require('mobx-react');
|
|
4
|
-
var react = require('react');
|
|
5
3
|
var core = require('@easy-editor/core');
|
|
4
|
+
var rendererCore = require('@easy-editor/renderer-core');
|
|
5
|
+
var react = require('react');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
-
|
|
8
|
-
const SettingRendererContext = /*#__PURE__*/react.createContext({});
|
|
9
|
-
const useSettingRendererContext = () => {
|
|
10
|
-
try {
|
|
11
|
-
return react.useContext(SettingRendererContext);
|
|
12
|
-
} catch (error) {
|
|
13
|
-
console.warn('useSettingRendererContext must be used within a SettingRendererContextProvider');
|
|
14
|
-
}
|
|
15
|
-
return {};
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const getSetterInfo = field => {
|
|
19
|
-
const {
|
|
20
|
-
extraProps,
|
|
21
|
-
setter
|
|
22
|
-
} = field;
|
|
23
|
-
const {
|
|
24
|
-
defaultValue
|
|
25
|
-
} = extraProps;
|
|
26
|
-
let setterProps = {};
|
|
27
|
-
let setterType;
|
|
28
|
-
let initialValue = null;
|
|
29
|
-
if (core.isSetterConfig(setter)) {
|
|
30
|
-
setterType = setter.componentName;
|
|
31
|
-
if (setter.props) {
|
|
32
|
-
setterProps = setter.props;
|
|
33
|
-
if (typeof setterProps === 'function') {
|
|
34
|
-
setterProps = setterProps(field);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
if (setter.defaultValue != null) {
|
|
38
|
-
initialValue = setter.defaultValue;
|
|
39
|
-
}
|
|
40
|
-
} else if (setter) {
|
|
41
|
-
setterType = setter;
|
|
42
|
-
}
|
|
43
|
-
if (defaultValue != null && !('defaultValue' in setterProps)) {
|
|
44
|
-
setterProps.defaultValue = defaultValue;
|
|
45
|
-
if (initialValue == null) {
|
|
46
|
-
initialValue = defaultValue;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
if (field.valueState === -1) {
|
|
50
|
-
setterProps.multiValue = true;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// 根据是否支持变量配置做相应的更改
|
|
54
|
-
const supportVariable = field.extraProps?.supportVariable;
|
|
55
|
-
const isUseVariableSetter = supportVariable;
|
|
56
|
-
if (isUseVariableSetter === false) {
|
|
57
|
-
return {
|
|
58
|
-
setterProps,
|
|
59
|
-
initialValue,
|
|
60
|
-
setterType
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
setterProps,
|
|
65
|
-
setterType,
|
|
66
|
-
initialValue
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
const SettingSetter = mobxReact.observer(({
|
|
70
|
-
field,
|
|
71
|
-
children
|
|
72
|
-
}) => {
|
|
73
|
-
const {
|
|
74
|
-
setterManager
|
|
75
|
-
} = useSettingRendererContext();
|
|
76
|
-
const {
|
|
77
|
-
extraProps
|
|
78
|
-
} = field;
|
|
79
|
-
const visible = extraProps?.condition && typeof extraProps.condition === 'function' ? extraProps.condition(field) !== false : true;
|
|
80
|
-
if (!visible) {
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
const {
|
|
84
|
-
setterProps = {},
|
|
85
|
-
setterType,
|
|
86
|
-
initialValue = null
|
|
87
|
-
} = getSetterInfo(field);
|
|
88
|
-
const onChange = extraProps?.onChange;
|
|
89
|
-
const value = field.valueState === -1 ? null : field.getValue();
|
|
90
|
-
const {
|
|
91
|
-
component: SetterComponent,
|
|
92
|
-
props: mixedSetterProps
|
|
93
|
-
} = setterManager.createSetterContent(setterType, setterProps);
|
|
94
|
-
return /*#__PURE__*/jsxRuntime.jsx(SetterComponent, {
|
|
95
|
-
field: field,
|
|
96
|
-
selected: field.top?.getNode(),
|
|
97
|
-
initialValue: initialValue,
|
|
98
|
-
value: value,
|
|
99
|
-
onChange: newVal => {
|
|
100
|
-
field.setValue(newVal);
|
|
101
|
-
onChange?.(field, newVal);
|
|
102
|
-
},
|
|
103
|
-
onInitial: () => {
|
|
104
|
-
if (initialValue == null) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
const value = typeof initialValue === 'function' ? initialValue(field) : initialValue;
|
|
108
|
-
field.setValue(value, true);
|
|
109
|
-
},
|
|
110
|
-
removeProp: () => {
|
|
111
|
-
if (field.name) {
|
|
112
|
-
field.parent.clearPropValue(field.name);
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
...mixedSetterProps,
|
|
116
|
-
children: children
|
|
117
|
-
}, field.id);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
const SettingFieldItem = mobxReact.observer(({
|
|
121
|
-
field
|
|
122
|
-
}) => {
|
|
123
|
-
const {
|
|
124
|
-
customFieldItem
|
|
125
|
-
} = useSettingRendererContext();
|
|
126
|
-
if (customFieldItem) {
|
|
127
|
-
return customFieldItem(field, /*#__PURE__*/jsxRuntime.jsx(SettingSetter, {
|
|
128
|
-
field: field
|
|
129
|
-
}));
|
|
130
|
-
}
|
|
131
|
-
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
132
|
-
className: "space-y-2",
|
|
133
|
-
children: [/*#__PURE__*/jsxRuntime.jsx("label", {
|
|
134
|
-
htmlFor: field.id,
|
|
135
|
-
className: "block text-sm font-medium text-gray-700",
|
|
136
|
-
children: field.title
|
|
137
|
-
}), /*#__PURE__*/jsxRuntime.jsx(SettingSetter, {
|
|
138
|
-
field: field
|
|
139
|
-
})]
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
const SettingFieldGroup = mobxReact.observer(({
|
|
143
|
-
field
|
|
144
|
-
}) => {
|
|
145
|
-
const {
|
|
146
|
-
customFieldGroup
|
|
147
|
-
} = useSettingRendererContext();
|
|
148
|
-
if (customFieldGroup) {
|
|
149
|
-
return customFieldGroup(field, /*#__PURE__*/jsxRuntime.jsx(SettingSetter, {
|
|
150
|
-
field: field,
|
|
151
|
-
children: field.items?.map(item => /*#__PURE__*/jsxRuntime.jsx(SettingFieldView, {
|
|
152
|
-
field: item
|
|
153
|
-
}, item.id))
|
|
154
|
-
}));
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// 如果 field 没有 setter,则理解为其 父级 field 的 items 数据
|
|
158
|
-
if (!field.setter) {
|
|
159
|
-
return field.items?.map(item => /*#__PURE__*/jsxRuntime.jsx(SettingFieldView, {
|
|
160
|
-
field: item
|
|
161
|
-
}, item.id));
|
|
162
|
-
}
|
|
163
|
-
return /*#__PURE__*/jsxRuntime.jsx(SettingSetter, {
|
|
164
|
-
field: field,
|
|
165
|
-
children: field.items?.map(item => /*#__PURE__*/jsxRuntime.jsx(SettingFieldView, {
|
|
166
|
-
field: item
|
|
167
|
-
}, item.id))
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
const SettingFieldView = ({
|
|
171
|
-
field
|
|
172
|
-
}) => {
|
|
173
|
-
if (field.isGroup) {
|
|
174
|
-
return /*#__PURE__*/jsxRuntime.jsx(SettingFieldGroup, {
|
|
175
|
-
field: field
|
|
176
|
-
}, field.id);
|
|
177
|
-
} else {
|
|
178
|
-
return /*#__PURE__*/jsxRuntime.jsx(SettingFieldItem, {
|
|
179
|
-
field: field
|
|
180
|
-
}, field.id);
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
const SettingRender = mobxReact.observer(props => {
|
|
184
|
-
const {
|
|
185
|
-
editor,
|
|
186
|
-
customFieldItem,
|
|
187
|
-
customFieldGroup
|
|
188
|
-
} = props;
|
|
189
|
-
const designer = editor.get('designer');
|
|
190
|
-
const setterManager = editor.get('setterManager');
|
|
191
|
-
const {
|
|
192
|
-
settingsManager
|
|
193
|
-
} = designer;
|
|
194
|
-
const {
|
|
195
|
-
settings
|
|
196
|
-
} = settingsManager;
|
|
197
|
-
const items = settings?.items;
|
|
198
|
-
const ctx = react.useMemo(() => {
|
|
199
|
-
const ctx = {};
|
|
200
|
-
ctx.setterManager = setterManager;
|
|
201
|
-
ctx.settingsManager = settingsManager;
|
|
202
|
-
ctx.customFieldItem = customFieldItem;
|
|
203
|
-
ctx.customFieldGroup = customFieldGroup;
|
|
204
|
-
return ctx;
|
|
205
|
-
}, [setterManager, settingsManager, customFieldItem, customFieldGroup]);
|
|
206
|
-
if (!settings) {
|
|
207
|
-
// 未选中节点,提示选中 或者 显示根节点设置
|
|
208
|
-
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
209
|
-
className: "lc-settings-main",
|
|
210
|
-
children: /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
211
|
-
className: "lc-settings-notice",
|
|
212
|
-
children: /*#__PURE__*/jsxRuntime.jsx("p", {
|
|
213
|
-
children: "Please select a node in canvas"
|
|
214
|
-
})
|
|
215
|
-
})
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// 当节点被锁定,且未开启锁定后容器可设置属性
|
|
220
|
-
if (settings.isLocked) {
|
|
221
|
-
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
222
|
-
className: "lc-settings-main",
|
|
223
|
-
children: /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
224
|
-
className: "lc-settings-notice",
|
|
225
|
-
children: /*#__PURE__*/jsxRuntime.jsx("p", {
|
|
226
|
-
children: "Current node is locked"
|
|
227
|
-
})
|
|
228
|
-
})
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
if (Array.isArray(settings.items) && settings.items.length === 0) {
|
|
232
|
-
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
233
|
-
className: "lc-settings-main",
|
|
234
|
-
children: /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
235
|
-
className: "lc-settings-notice",
|
|
236
|
-
children: /*#__PURE__*/jsxRuntime.jsx("p", {
|
|
237
|
-
children: "No config found for this type of component"
|
|
238
|
-
})
|
|
239
|
-
})
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
if (!settings.isSameComponent) {
|
|
243
|
-
// TODO: future support 获取设置项交集编辑
|
|
244
|
-
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
245
|
-
className: "lc-settings-main",
|
|
246
|
-
children: /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
247
|
-
className: "lc-settings-notice",
|
|
248
|
-
children: /*#__PURE__*/jsxRuntime.jsx("p", {
|
|
249
|
-
children: "Please select same kind of components"
|
|
250
|
-
})
|
|
251
|
-
})
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
return /*#__PURE__*/jsxRuntime.jsx(SettingRendererContext.Provider, {
|
|
255
|
-
value: ctx,
|
|
256
|
-
children: items?.map(item => /*#__PURE__*/jsxRuntime.jsx(SettingFieldView, {
|
|
257
|
-
field: item
|
|
258
|
-
}, item.id))
|
|
259
|
-
});
|
|
260
|
-
});
|
|
7
|
+
var mobxReact = require('mobx-react');
|
|
261
8
|
|
|
262
9
|
class Adapter {
|
|
263
10
|
renderers = {};
|
|
@@ -431,12 +178,12 @@ function baseIsNative(value) {
|
|
|
431
178
|
return pattern.test(toSource(value));
|
|
432
179
|
}
|
|
433
180
|
|
|
434
|
-
function getValue
|
|
181
|
+
function getValue(object, key) {
|
|
435
182
|
return object == null ? undefined : object[key];
|
|
436
183
|
}
|
|
437
184
|
|
|
438
185
|
function getNative(object, key) {
|
|
439
|
-
var value = getValue
|
|
186
|
+
var value = getValue(object, key);
|
|
440
187
|
return baseIsNative(value) ? value : undefined;
|
|
441
188
|
}
|
|
442
189
|
|
|
@@ -857,195 +604,6 @@ function contextFactory() {
|
|
|
857
604
|
return context;
|
|
858
605
|
}
|
|
859
606
|
|
|
860
|
-
const classnames = (...args) => {
|
|
861
|
-
return args.filter(Boolean).join(' ');
|
|
862
|
-
};
|
|
863
|
-
|
|
864
|
-
const logger = core.createLogger('Renderer');
|
|
865
|
-
|
|
866
|
-
const PropTypes2 = true;
|
|
867
|
-
function inSameDomain() {
|
|
868
|
-
try {
|
|
869
|
-
return window.parent !== window && window.parent.location.host === window.location.host;
|
|
870
|
-
} catch (e) {
|
|
871
|
-
return false;
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
function getFileCssName(fileName) {
|
|
875
|
-
if (!fileName) {
|
|
876
|
-
return;
|
|
877
|
-
}
|
|
878
|
-
const name = fileName.replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
879
|
-
return `lce-${name}`.split('-').filter(p => !!p).join('-');
|
|
880
|
-
}
|
|
881
|
-
const isSchema = schema => {
|
|
882
|
-
if (!schema) {
|
|
883
|
-
return false;
|
|
884
|
-
}
|
|
885
|
-
if (schema.componentName === 'Leaf' || schema.componentName === 'Slot') {
|
|
886
|
-
return true;
|
|
887
|
-
}
|
|
888
|
-
if (Array.isArray(schema)) {
|
|
889
|
-
return schema.every(item => isSchema(item));
|
|
890
|
-
}
|
|
891
|
-
const isValidProps = props => {
|
|
892
|
-
if (!props) {
|
|
893
|
-
return false;
|
|
894
|
-
}
|
|
895
|
-
return typeof schema.props === 'object' && !Array.isArray(props);
|
|
896
|
-
};
|
|
897
|
-
return !!(schema.componentName && isValidProps(schema.props));
|
|
898
|
-
};
|
|
899
|
-
const getValue = (obj, path, defaultValue = {}) => {
|
|
900
|
-
if (Array.isArray(obj)) {
|
|
901
|
-
return defaultValue;
|
|
902
|
-
}
|
|
903
|
-
if (!obj || typeof obj !== 'object') {
|
|
904
|
-
return defaultValue;
|
|
905
|
-
}
|
|
906
|
-
const res = path.split('.').reduce((pre, cur) => {
|
|
907
|
-
return pre && pre[cur];
|
|
908
|
-
}, obj);
|
|
909
|
-
if (res === undefined) {
|
|
910
|
-
return defaultValue;
|
|
911
|
-
}
|
|
912
|
-
return res;
|
|
913
|
-
};
|
|
914
|
-
function transformArrayToMap(arr, key, overwrite = true) {
|
|
915
|
-
if (!arr || !Array.isArray(arr)) {
|
|
916
|
-
return {};
|
|
917
|
-
}
|
|
918
|
-
const res = {};
|
|
919
|
-
arr.forEach(item => {
|
|
920
|
-
const curKey = item[key];
|
|
921
|
-
if (item[key] === undefined) {
|
|
922
|
-
return;
|
|
923
|
-
}
|
|
924
|
-
if (res[curKey] && !overwrite) {
|
|
925
|
-
return;
|
|
926
|
-
}
|
|
927
|
-
res[curKey] = item;
|
|
928
|
-
});
|
|
929
|
-
return res;
|
|
930
|
-
}
|
|
931
|
-
const parseData = (schema, self, options = {}) => {
|
|
932
|
-
if (core.isJSExpression(schema)) {
|
|
933
|
-
return parseExpression({
|
|
934
|
-
str: schema,
|
|
935
|
-
self,
|
|
936
|
-
thisRequired: true,
|
|
937
|
-
logScope: options.logScope
|
|
938
|
-
});
|
|
939
|
-
}
|
|
940
|
-
if (typeof schema === 'string') {
|
|
941
|
-
return schema.trim();
|
|
942
|
-
} else if (Array.isArray(schema)) {
|
|
943
|
-
return schema.map(item => parseData(item, self, options));
|
|
944
|
-
} else if (typeof schema === 'function') {
|
|
945
|
-
return schema.bind(self);
|
|
946
|
-
} else if (typeof schema === 'object') {
|
|
947
|
-
if (!schema) {
|
|
948
|
-
return schema;
|
|
949
|
-
}
|
|
950
|
-
const res = {};
|
|
951
|
-
Object.entries(schema).forEach(([key, val]) => {
|
|
952
|
-
if (key.startsWith('__')) {
|
|
953
|
-
return;
|
|
954
|
-
}
|
|
955
|
-
res[key] = parseData(val, self, options);
|
|
956
|
-
});
|
|
957
|
-
return res;
|
|
958
|
-
}
|
|
959
|
-
return schema;
|
|
960
|
-
};
|
|
961
|
-
const isUseLoop = (loop, isDesignMode) => {
|
|
962
|
-
if (!isDesignMode) {
|
|
963
|
-
return true;
|
|
964
|
-
}
|
|
965
|
-
if (!Array.isArray(loop)) {
|
|
966
|
-
return false;
|
|
967
|
-
}
|
|
968
|
-
return loop.length > 0;
|
|
969
|
-
};
|
|
970
|
-
function checkPropTypes(value, name, rule, componentName) {
|
|
971
|
-
let ruleFunction = rule;
|
|
972
|
-
if (typeof rule === 'string') {
|
|
973
|
-
ruleFunction = new Function(`"use strict"; const PropTypes = arguments[0]; return ${rule}`)(PropTypes2);
|
|
974
|
-
}
|
|
975
|
-
if (!ruleFunction || typeof ruleFunction !== 'function') {
|
|
976
|
-
logger.warn('checkPropTypes should have a function type rule argument');
|
|
977
|
-
return true;
|
|
978
|
-
}
|
|
979
|
-
const err = ruleFunction({
|
|
980
|
-
[name]: value
|
|
981
|
-
}, name, componentName, 'prop', null
|
|
982
|
-
);
|
|
983
|
-
if (err) {
|
|
984
|
-
logger.warn(err);
|
|
985
|
-
}
|
|
986
|
-
return !err;
|
|
987
|
-
}
|
|
988
|
-
function transformStringToFunction(str) {
|
|
989
|
-
if (typeof str !== 'string') {
|
|
990
|
-
return str;
|
|
991
|
-
}
|
|
992
|
-
if (inSameDomain() && window.parent.__newFunc) {
|
|
993
|
-
return window.parent.__newFunc(`"use strict"; return ${str}`)();
|
|
994
|
-
} else {
|
|
995
|
-
return new Function(`"use strict"; return ${str}`)();
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
function parseExpression(a, b, c = false) {
|
|
999
|
-
let str;
|
|
1000
|
-
let self;
|
|
1001
|
-
let thisRequired;
|
|
1002
|
-
let logScope;
|
|
1003
|
-
if (typeof a === 'object' && b === undefined) {
|
|
1004
|
-
str = a.str;
|
|
1005
|
-
self = a.self;
|
|
1006
|
-
thisRequired = a.thisRequired;
|
|
1007
|
-
logScope = a.logScope;
|
|
1008
|
-
} else {
|
|
1009
|
-
str = a;
|
|
1010
|
-
self = b;
|
|
1011
|
-
thisRequired = c;
|
|
1012
|
-
}
|
|
1013
|
-
try {
|
|
1014
|
-
const contextArr = ['"use strict";', 'var __self = arguments[0];'];
|
|
1015
|
-
contextArr.push('return ');
|
|
1016
|
-
let tarStr;
|
|
1017
|
-
tarStr = (str.value || '').trim();
|
|
1018
|
-
tarStr = tarStr.replace(/this(\W|$)/g, (_a, b) => `__self${b}`);
|
|
1019
|
-
tarStr = contextArr.join('\n') + tarStr;
|
|
1020
|
-
if (inSameDomain() && window.parent.__newFunc) {
|
|
1021
|
-
return window.parent.__newFunc(tarStr)(self);
|
|
1022
|
-
}
|
|
1023
|
-
const code = `with(${thisRequired ? '{}' : '$scope || {}'}) { ${tarStr} }`;
|
|
1024
|
-
return new Function('$scope', code)(self);
|
|
1025
|
-
} catch (err) {
|
|
1026
|
-
logger.error(`${logScope || ''} parseExpression.error`, err, str, self?.__self ?? self);
|
|
1027
|
-
return undefined;
|
|
1028
|
-
}
|
|
1029
|
-
}
|
|
1030
|
-
function parseThisRequiredExpression(str, self) {
|
|
1031
|
-
return parseExpression(str, self, true);
|
|
1032
|
-
}
|
|
1033
|
-
function isString(str) {
|
|
1034
|
-
return {}.toString.call(str) === '[object String]';
|
|
1035
|
-
}
|
|
1036
|
-
function capitalizeFirstLetter(word) {
|
|
1037
|
-
if (!word || !isString(word) || word.length === 0) {
|
|
1038
|
-
return word;
|
|
1039
|
-
}
|
|
1040
|
-
return word[0].toUpperCase() + word.slice(1);
|
|
1041
|
-
}
|
|
1042
|
-
const isReactClass = obj => {
|
|
1043
|
-
return obj && obj.prototype && (obj.prototype.isReactComponent || obj.prototype instanceof react.Component);
|
|
1044
|
-
};
|
|
1045
|
-
function isReactComponent(obj) {
|
|
1046
|
-
return obj && (isReactClass(obj) || typeof obj === 'function');
|
|
1047
|
-
}
|
|
1048
|
-
|
|
1049
607
|
const excludePropertyNames = ['$$typeof', 'render', 'defaultProps', 'props', 'length', 'prototype', 'name', 'caller', 'callee', 'arguments'];
|
|
1050
608
|
const cloneEnumerableProperty = (target, origin, excludes = excludePropertyNames) => {
|
|
1051
609
|
const compExtraPropertyNames = Object.keys(origin).filter(d => !excludes.includes(d));
|
|
@@ -1065,6 +623,13 @@ const createForwardRefHocElement = (Wrapper, Comp) => {
|
|
|
1065
623
|
return WrapperComponent;
|
|
1066
624
|
};
|
|
1067
625
|
|
|
626
|
+
const isReactClass = obj => {
|
|
627
|
+
return obj && obj.prototype && (obj.prototype.isReactComponent || obj.prototype instanceof react.Component);
|
|
628
|
+
};
|
|
629
|
+
const isReactComponent = obj => {
|
|
630
|
+
return obj && (isReactClass(obj) || typeof obj === 'function');
|
|
631
|
+
};
|
|
632
|
+
|
|
1068
633
|
const patchDidCatch = (Comp, {
|
|
1069
634
|
baseRenderer
|
|
1070
635
|
}) => {
|
|
@@ -1189,19 +754,19 @@ const initRerenderEvent = ({
|
|
|
1189
754
|
if (!container.autoRepaintNode) {
|
|
1190
755
|
return;
|
|
1191
756
|
}
|
|
1192
|
-
logger.log(`${schema.componentName}[${schema.id}] leaf not render in SimulatorRendererView, leaf onPropsChange make rerender`);
|
|
757
|
+
rendererCore.logger.log(`${schema.componentName}[${schema.id}] leaf not render in SimulatorRendererView, leaf onPropsChange make rerender`);
|
|
1193
758
|
debounceRerender();
|
|
1194
759
|
}), leaf?.onChildrenChange?.(() => {
|
|
1195
760
|
if (!container.autoRepaintNode) {
|
|
1196
761
|
return;
|
|
1197
762
|
}
|
|
1198
|
-
logger.log(`${schema.componentName}[${schema.id}] leaf not render in SimulatorRendererView, leaf onChildrenChange make rerender`);
|
|
763
|
+
rendererCore.logger.log(`${schema.componentName}[${schema.id}] leaf not render in SimulatorRendererView, leaf onChildrenChange make rerender`);
|
|
1199
764
|
debounceRerender();
|
|
1200
765
|
}), leaf?.onVisibleChange?.(() => {
|
|
1201
766
|
if (!container.autoRepaintNode) {
|
|
1202
767
|
return;
|
|
1203
768
|
}
|
|
1204
|
-
logger.log(`${schema.componentName}[${schema.id}] leaf not render in SimulatorRendererView, leaf onVisibleChange make rerender`);
|
|
769
|
+
rendererCore.logger.log(`${schema.componentName}[${schema.id}] leaf not render in SimulatorRendererView, leaf onVisibleChange make rerender`);
|
|
1205
770
|
debounceRerender();
|
|
1206
771
|
})]
|
|
1207
772
|
});
|
|
@@ -1286,13 +851,13 @@ const leafWrapper = (Comp, {
|
|
|
1286
851
|
if ('children' in nextProps) {
|
|
1287
852
|
nextState.nodeChildren = nextProps.children;
|
|
1288
853
|
}
|
|
1289
|
-
logger.log(`${this.leaf?.componentName}(${this.leaf?.id}) MinimalRenderUnit Render!`);
|
|
854
|
+
rendererCore.logger.log(`${this.leaf?.componentName}(${this.leaf?.id}) MinimalRenderUnit Render!`);
|
|
1290
855
|
this.setState(nextState);
|
|
1291
856
|
}, 20);
|
|
1292
857
|
constructor(props) {
|
|
1293
858
|
super(props);
|
|
1294
859
|
// 监听以下事件,当变化时更新自己
|
|
1295
|
-
logger.log(`${schema.componentName}[${this.leaf?.id}] leaf render in SimulatorRendererView`);
|
|
860
|
+
rendererCore.logger.log(`${schema.componentName}[${this.leaf?.id}] leaf render in SimulatorRendererView`);
|
|
1296
861
|
componentCacheId && clearRerenderEvent(componentCacheId);
|
|
1297
862
|
this.curEventLeaf = this.leaf;
|
|
1298
863
|
cache.ref.set(componentCacheId, {
|
|
@@ -1377,11 +942,11 @@ const leafWrapper = (Comp, {
|
|
|
1377
942
|
}
|
|
1378
943
|
const ref = cache.ref.get(renderUnitInfo.minimalUnitId);
|
|
1379
944
|
if (!ref) {
|
|
1380
|
-
logger.log('Cant find minimalRenderUnit ref! This make rerender!');
|
|
945
|
+
rendererCore.logger.log('Cant find minimalRenderUnit ref! This make rerender!');
|
|
1381
946
|
container?.rerender();
|
|
1382
947
|
return;
|
|
1383
948
|
}
|
|
1384
|
-
logger.log(`${this.leaf?.componentName}(${this.leaf?.id}) need render, make its minimalRenderUnit ${renderUnitInfo.minimalUnitName}(${renderUnitInfo.minimalUnitId})`);
|
|
949
|
+
rendererCore.logger.log(`${this.leaf?.componentName}(${this.leaf?.id}) need render, make its minimalRenderUnit ${renderUnitInfo.minimalUnitName}(${renderUnitInfo.minimalUnitId})`);
|
|
1385
950
|
ref.makeUnitRender();
|
|
1386
951
|
}
|
|
1387
952
|
getRenderUnitInfo(leaf = this.leaf) {
|
|
@@ -1451,7 +1016,7 @@ const leafWrapper = (Comp, {
|
|
|
1451
1016
|
condition = true
|
|
1452
1017
|
} = this.leaf?.export(core.TRANSFORM_STAGE.RENDER) || {};
|
|
1453
1018
|
const conditionValue = __parseData?.(condition, scope);
|
|
1454
|
-
logger.log(`key is ___condition___, change condition value to [${condition}]`);
|
|
1019
|
+
rendererCore.logger.log(`key is ___condition___, change condition value to [${condition}]`);
|
|
1455
1020
|
// 条件表达式改变
|
|
1456
1021
|
this.setState({
|
|
1457
1022
|
condition: conditionValue
|
|
@@ -1462,7 +1027,7 @@ const leafWrapper = (Comp, {
|
|
|
1462
1027
|
// 如果循坏条件变化,从根节点重新渲染
|
|
1463
1028
|
// 目前多层循坏无法判断需要从哪一层开始渲染,故先粗暴解决
|
|
1464
1029
|
if (key === '___loop___') {
|
|
1465
|
-
logger.log('key is ___loop___, render a page!');
|
|
1030
|
+
rendererCore.logger.log('key is ___loop___, render a page!');
|
|
1466
1031
|
container?.rerender();
|
|
1467
1032
|
// 由于 scope 变化,需要清空缓存,使用新的 scope
|
|
1468
1033
|
cache.component.delete(componentCacheId);
|
|
@@ -1480,7 +1045,7 @@ const leafWrapper = (Comp, {
|
|
|
1480
1045
|
// 当 key 在 this.props 中时,且不存在在计算值中,需要用 newValue 覆盖掉 this.props 的取值
|
|
1481
1046
|
nodeCacheProps[key] = newValue;
|
|
1482
1047
|
}
|
|
1483
|
-
logger.log(`${leaf?.componentName}[${this.leaf?.id}] component trigger onPropsChange!`, nodeProps, nodeCacheProps, key, newValue);
|
|
1048
|
+
rendererCore.logger.log(`${leaf?.componentName}[${this.leaf?.id}] component trigger onPropsChange!`, nodeProps, nodeCacheProps, key, newValue);
|
|
1484
1049
|
this.setState('children' in nodeProps ? {
|
|
1485
1050
|
nodeChildren: nodeProps.children,
|
|
1486
1051
|
nodeProps,
|
|
@@ -1513,7 +1078,7 @@ const leafWrapper = (Comp, {
|
|
|
1513
1078
|
if (this.state.visible === flag) {
|
|
1514
1079
|
return;
|
|
1515
1080
|
}
|
|
1516
|
-
logger.log(`${leaf?.componentName}[${this.leaf?.id}] component trigger onVisibleChange(${flag}) event`);
|
|
1081
|
+
rendererCore.logger.log(`${leaf?.componentName}[${this.leaf?.id}] component trigger onVisibleChange(${flag}) event`);
|
|
1517
1082
|
this.beforeRender(RerenderType.VisibleChanged);
|
|
1518
1083
|
this.setState({
|
|
1519
1084
|
visible: flag
|
|
@@ -1540,7 +1105,7 @@ const leafWrapper = (Comp, {
|
|
|
1540
1105
|
// 缓存二级 children Next 查询筛选组件有问题
|
|
1541
1106
|
// 缓存一级 children Next Tab 组件有问题
|
|
1542
1107
|
const nextChild = getChildren(leaf?.export?.(core.TRANSFORM_STAGE.RENDER), scope, Comp);
|
|
1543
|
-
logger.log(`${schema.componentName}[${this.leaf?.id}] component trigger onChildrenChange event`, nextChild);
|
|
1108
|
+
rendererCore.logger.log(`${schema.componentName}[${this.leaf?.id}] component trigger onChildrenChange event`, nextChild);
|
|
1544
1109
|
this.setState({
|
|
1545
1110
|
nodeChildren: nextChild,
|
|
1546
1111
|
childrenInState: true
|
|
@@ -1594,7 +1159,7 @@ const leafWrapper = (Comp, {
|
|
|
1594
1159
|
__id: this.leaf?.id,
|
|
1595
1160
|
ref: forwardRef
|
|
1596
1161
|
};
|
|
1597
|
-
|
|
1162
|
+
compProps.__inner__ = undefined;
|
|
1598
1163
|
if (this.hasChildren) {
|
|
1599
1164
|
return engine.createElement(Comp, compProps, this.children);
|
|
1600
1165
|
}
|
|
@@ -1609,11 +1174,14 @@ const leafWrapper = (Comp, {
|
|
|
1609
1174
|
return LeafWrapper;
|
|
1610
1175
|
};
|
|
1611
1176
|
|
|
1177
|
+
/**
|
|
1178
|
+
* execute method in schema.lifeCycles with context
|
|
1179
|
+
*/
|
|
1612
1180
|
function executeLifeCycleMethod(context, schema, method, args) {
|
|
1613
|
-
if (!context || !isSchema(schema) || !method) {
|
|
1181
|
+
if (!context || !rendererCore.isSchema(schema) || !method) {
|
|
1614
1182
|
return;
|
|
1615
1183
|
}
|
|
1616
|
-
const lifeCycleMethods = getValue(schema, 'lifeCycles', {});
|
|
1184
|
+
const lifeCycleMethods = rendererCore.getValue(schema, 'lifeCycles', {});
|
|
1617
1185
|
let fn = lifeCycleMethods[method];
|
|
1618
1186
|
if (!fn) {
|
|
1619
1187
|
return;
|
|
@@ -1621,16 +1189,16 @@ function executeLifeCycleMethod(context, schema, method, args) {
|
|
|
1621
1189
|
|
|
1622
1190
|
// TODO: cache
|
|
1623
1191
|
if (core.isJSExpression(fn) || core.isJSFunction(fn)) {
|
|
1624
|
-
fn = parseExpression(fn, context, true);
|
|
1192
|
+
fn = rendererCore.parseExpression(fn, context, true);
|
|
1625
1193
|
}
|
|
1626
1194
|
if (typeof fn !== 'function') {
|
|
1627
|
-
logger.error(`生命周期${method}类型不符`, fn);
|
|
1195
|
+
rendererCore.logger.error(`生命周期${method}类型不符`, fn);
|
|
1628
1196
|
return;
|
|
1629
1197
|
}
|
|
1630
1198
|
try {
|
|
1631
1199
|
return fn.apply(context, args);
|
|
1632
1200
|
} catch (e) {
|
|
1633
|
-
logger.error(`[${schema.componentName}]生命周期${method}出错`, e);
|
|
1201
|
+
rendererCore.logger.error(`[${schema.componentName}]生命周期${method}出错`, e);
|
|
1634
1202
|
}
|
|
1635
1203
|
}
|
|
1636
1204
|
|
|
@@ -1684,7 +1252,7 @@ function baseRendererFactory() {
|
|
|
1684
1252
|
constructor(props) {
|
|
1685
1253
|
super(props);
|
|
1686
1254
|
this.__parseExpression = (str, self) => {
|
|
1687
|
-
return parseExpression({
|
|
1255
|
+
return rendererCore.parseExpression({
|
|
1688
1256
|
str,
|
|
1689
1257
|
self,
|
|
1690
1258
|
logScope: props.componentName
|
|
@@ -1693,7 +1261,7 @@ function baseRendererFactory() {
|
|
|
1693
1261
|
this.__beforeInit(props);
|
|
1694
1262
|
this.__init(props);
|
|
1695
1263
|
this.__afterInit(props);
|
|
1696
|
-
logger.log(`constructor - ${props?.__schema?.fileName}`);
|
|
1264
|
+
rendererCore.logger.log(`constructor - ${props?.__schema?.fileName}`);
|
|
1697
1265
|
}
|
|
1698
1266
|
__beforeInit(props) {}
|
|
1699
1267
|
__init(props) {
|
|
@@ -1708,27 +1276,27 @@ function baseRendererFactory() {
|
|
|
1708
1276
|
}
|
|
1709
1277
|
async getSnapshotBeforeUpdate(...args) {
|
|
1710
1278
|
this.__executeLifeCycleMethod('getSnapshotBeforeUpdate', args);
|
|
1711
|
-
logger.log(`getSnapshotBeforeUpdate - ${this.props?.__schema?.componentName}`);
|
|
1279
|
+
rendererCore.logger.log(`getSnapshotBeforeUpdate - ${this.props?.__schema?.componentName}`);
|
|
1712
1280
|
}
|
|
1713
1281
|
async componentDidMount(...args) {
|
|
1714
1282
|
this.reloadDataSource();
|
|
1715
1283
|
this.__executeLifeCycleMethod('componentDidMount', args);
|
|
1716
|
-
logger.log(`componentDidMount - ${this.props?.__schema?.componentName}`);
|
|
1284
|
+
rendererCore.logger.log(`componentDidMount - ${this.props?.__schema?.componentName}`);
|
|
1717
1285
|
}
|
|
1718
1286
|
async componentDidUpdate(...args) {
|
|
1719
1287
|
this.__executeLifeCycleMethod('componentDidUpdate', args);
|
|
1720
|
-
logger.log(`componentDidUpdate - ${this.props.__schema.componentName}`);
|
|
1288
|
+
rendererCore.logger.log(`componentDidUpdate - ${this.props.__schema.componentName}`);
|
|
1721
1289
|
}
|
|
1722
1290
|
async componentWillUnmount(...args) {
|
|
1723
1291
|
this.__executeLifeCycleMethod('componentWillUnmount', args);
|
|
1724
|
-
logger.log(`componentWillUnmount - ${this.props?.__schema?.componentName}`);
|
|
1292
|
+
rendererCore.logger.log(`componentWillUnmount - ${this.props?.__schema?.componentName}`);
|
|
1725
1293
|
}
|
|
1726
1294
|
async componentDidCatch(...args) {
|
|
1727
1295
|
this.__executeLifeCycleMethod('componentDidCatch', args);
|
|
1728
|
-
logger.warn(args);
|
|
1296
|
+
rendererCore.logger.warn(args);
|
|
1729
1297
|
}
|
|
1730
1298
|
reloadDataSource = () => new Promise((resolve, reject) => {
|
|
1731
|
-
logger.log('reload data source');
|
|
1299
|
+
rendererCore.logger.log('reload data source');
|
|
1732
1300
|
if (!this.__dataHelper) {
|
|
1733
1301
|
return resolve({});
|
|
1734
1302
|
}
|
|
@@ -1801,7 +1369,7 @@ function baseRendererFactory() {
|
|
|
1801
1369
|
value = this.__parseExpression(value, this);
|
|
1802
1370
|
}
|
|
1803
1371
|
if (typeof value !== 'function') {
|
|
1804
|
-
logger.error(`custom method ${key} can not be parsed to a valid function`, value);
|
|
1372
|
+
rendererCore.logger.error(`custom method ${key} can not be parsed to a valid function`, value);
|
|
1805
1373
|
return;
|
|
1806
1374
|
}
|
|
1807
1375
|
this[key] = value.bind(this);
|
|
@@ -1826,7 +1394,7 @@ function baseRendererFactory() {
|
|
|
1826
1394
|
__ctx,
|
|
1827
1395
|
componentName
|
|
1828
1396
|
} = this.props;
|
|
1829
|
-
return parseData(data, ctx || __ctx || this, {
|
|
1397
|
+
return rendererCore.parseData(data, ctx || __ctx || this, {
|
|
1830
1398
|
logScope: componentName
|
|
1831
1399
|
});
|
|
1832
1400
|
};
|
|
@@ -1834,60 +1402,49 @@ function baseRendererFactory() {
|
|
|
1834
1402
|
if (!props) {
|
|
1835
1403
|
return;
|
|
1836
1404
|
}
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
// .then((res: any) => {
|
|
1881
|
-
// if (isEmpty(res)) {
|
|
1882
|
-
// return resolve({})
|
|
1883
|
-
// }
|
|
1884
|
-
// this.setState(res, resolve as () => void)
|
|
1885
|
-
// })
|
|
1886
|
-
// .catch((err: Error) => {
|
|
1887
|
-
// reject(err)
|
|
1888
|
-
// })
|
|
1889
|
-
// })
|
|
1890
|
-
// }
|
|
1405
|
+
const schema = props.__schema || {};
|
|
1406
|
+
const defaultDataSource = {
|
|
1407
|
+
list: []
|
|
1408
|
+
};
|
|
1409
|
+
const dataSource = schema.dataSource || defaultDataSource;
|
|
1410
|
+
const useDataSourceEngine = !!props.__appHelper?.dataSourceEngine;
|
|
1411
|
+
if (useDataSourceEngine) {
|
|
1412
|
+
const dataSourceEngine = props.__appHelper?.dataSourceEngine;
|
|
1413
|
+
// TODO: 优化
|
|
1414
|
+
if (!dataSourceEngine || !dataSourceEngine.createDataSourceEngine) {
|
|
1415
|
+
rendererCore.logger.error('dataSourceEngine is not found in appHelper, please check your configuration');
|
|
1416
|
+
return;
|
|
1417
|
+
}
|
|
1418
|
+
const {
|
|
1419
|
+
createDataSourceEngine
|
|
1420
|
+
} = dataSourceEngine;
|
|
1421
|
+
this.__dataHelper = {
|
|
1422
|
+
updateConfig: updateDataSource => {
|
|
1423
|
+
const {
|
|
1424
|
+
dataSourceMap,
|
|
1425
|
+
reloadDataSource
|
|
1426
|
+
} = createDataSourceEngine(updateDataSource ?? {}, this);
|
|
1427
|
+
this.reloadDataSource = () => new Promise(resolve => {
|
|
1428
|
+
rendererCore.logger.log('reload data source');
|
|
1429
|
+
reloadDataSource().then(() => {
|
|
1430
|
+
resolve({});
|
|
1431
|
+
});
|
|
1432
|
+
});
|
|
1433
|
+
return dataSourceMap;
|
|
1434
|
+
}
|
|
1435
|
+
};
|
|
1436
|
+
this.dataSourceMap = this.__dataHelper.updateConfig(dataSource);
|
|
1437
|
+
} else {
|
|
1438
|
+
const appHelper = props.__appHelper || {};
|
|
1439
|
+
this.__dataHelper = new rendererCore.DataHelper(this, dataSource, appHelper, config => this.__parseData(config));
|
|
1440
|
+
this.dataSourceMap = this.__dataHelper.dataSourceMap;
|
|
1441
|
+
this.reloadDataSource = () => new Promise(resolve => {
|
|
1442
|
+
rendererCore.logger.log('reload data source');
|
|
1443
|
+
this.__dataHelper.reloadDataSource().then(() => {
|
|
1444
|
+
resolve({});
|
|
1445
|
+
});
|
|
1446
|
+
});
|
|
1447
|
+
}
|
|
1891
1448
|
};
|
|
1892
1449
|
|
|
1893
1450
|
/**
|
|
@@ -1896,8 +1453,8 @@ function baseRendererFactory() {
|
|
|
1896
1453
|
* @PRIVATE
|
|
1897
1454
|
*/
|
|
1898
1455
|
__writeCss = props => {
|
|
1899
|
-
const css = getValue(props.__schema, 'css', '');
|
|
1900
|
-
logger.log('create this.styleElement with css', css);
|
|
1456
|
+
const css = rendererCore.getValue(props.__schema, 'css', '');
|
|
1457
|
+
rendererCore.logger.log('create this.styleElement with css', css);
|
|
1901
1458
|
let style = this.__styleElement;
|
|
1902
1459
|
if (!this.__styleElement) {
|
|
1903
1460
|
style = document.createElement('style');
|
|
@@ -1906,7 +1463,7 @@ function baseRendererFactory() {
|
|
|
1906
1463
|
const head = document.head || document.getElementsByTagName('head')[0];
|
|
1907
1464
|
head.appendChild(style);
|
|
1908
1465
|
this.__styleElement = style;
|
|
1909
|
-
logger.log('this.styleElement is created', this.__styleElement);
|
|
1466
|
+
rendererCore.logger.log('this.styleElement is created', this.__styleElement);
|
|
1910
1467
|
}
|
|
1911
1468
|
if (style.innerHTML === css) {
|
|
1912
1469
|
return;
|
|
@@ -1958,7 +1515,7 @@ function baseRendererFactory() {
|
|
|
1958
1515
|
const _children = getSchemaChildren(__schema);
|
|
1959
1516
|
const Comp = this.__getComponentView();
|
|
1960
1517
|
if (!Comp) {
|
|
1961
|
-
logger.log(`${__schema.componentName} is invalid!`);
|
|
1518
|
+
rendererCore.logger.log(`${__schema.componentName} is invalid!`);
|
|
1962
1519
|
}
|
|
1963
1520
|
const parentNodeInfo = {
|
|
1964
1521
|
schema: __schema,
|
|
@@ -1987,7 +1544,7 @@ function baseRendererFactory() {
|
|
|
1987
1544
|
engine
|
|
1988
1545
|
} = this.context || {};
|
|
1989
1546
|
if (!engine) {
|
|
1990
|
-
logger.log('this.context.engine is invalid!');
|
|
1547
|
+
rendererCore.logger.log('this.context.engine is invalid!');
|
|
1991
1548
|
return null;
|
|
1992
1549
|
}
|
|
1993
1550
|
try {
|
|
@@ -2014,22 +1571,22 @@ function baseRendererFactory() {
|
|
|
2014
1571
|
return schema;
|
|
2015
1572
|
}
|
|
2016
1573
|
if (!schema.componentName) {
|
|
2017
|
-
logger.error('The componentName in the schema is invalid, please check the schema: ', schema);
|
|
1574
|
+
rendererCore.logger.error('The componentName in the schema is invalid, please check the schema: ', schema);
|
|
2018
1575
|
return;
|
|
2019
1576
|
}
|
|
2020
|
-
if (!isSchema(schema)) {
|
|
1577
|
+
if (!rendererCore.isSchema(schema)) {
|
|
2021
1578
|
return null;
|
|
2022
1579
|
}
|
|
2023
1580
|
let Comp = components[schema.componentName] || this.props.__container?.components?.[schema.componentName];
|
|
2024
1581
|
|
|
2025
1582
|
// 容器类组件的上下文通过props传递,避免context传递带来的嵌套问题
|
|
2026
|
-
const otherProps = isSchema(schema) ? {
|
|
1583
|
+
const otherProps = rendererCore.isSchema(schema) ? {
|
|
2027
1584
|
__schema: schema,
|
|
2028
1585
|
__appHelper: appHelper,
|
|
2029
1586
|
__components: components
|
|
2030
1587
|
} : {};
|
|
2031
1588
|
if (!Comp) {
|
|
2032
|
-
logger.error(`${schema.componentName} component is not found in components list! component list is:`, components || this.props.__container?.components);
|
|
1589
|
+
rendererCore.logger.error(`${schema.componentName} component is not found in components list! component list is:`, components || this.props.__container?.components);
|
|
2033
1590
|
return engine.createElement(engine.getNotFoundComponent(), {
|
|
2034
1591
|
componentName: schema.componentName,
|
|
2035
1592
|
componentId: schema.id,
|
|
@@ -2042,7 +1599,7 @@ function baseRendererFactory() {
|
|
|
2042
1599
|
if (schema.loop != null) {
|
|
2043
1600
|
const loop = this.__parseData(schema.loop, scope);
|
|
2044
1601
|
if (Array.isArray(loop) && loop.length === 0) return null;
|
|
2045
|
-
const useLoop = isUseLoop(loop, this.__designModeIsDesign);
|
|
1602
|
+
const useLoop = rendererCore.isUseLoop(loop, this.__designModeIsDesign);
|
|
2046
1603
|
if (useLoop) {
|
|
2047
1604
|
return this.__createLoopVirtualDom({
|
|
2048
1605
|
...schema,
|
|
@@ -2096,7 +1653,7 @@ function baseRendererFactory() {
|
|
|
2096
1653
|
const componentInfo = {};
|
|
2097
1654
|
const props = this.__getComponentProps(schema, scope, Comp, {
|
|
2098
1655
|
...componentInfo,
|
|
2099
|
-
props: transformArrayToMap(componentInfo.props, 'name')
|
|
1656
|
+
props: rendererCore.transformArrayToMap(componentInfo.props, 'name')
|
|
2100
1657
|
}) || {};
|
|
2101
1658
|
Comp = this.__getHOCWrappedComponent(Comp, {
|
|
2102
1659
|
schema,
|
|
@@ -2118,7 +1675,7 @@ function baseRendererFactory() {
|
|
|
2118
1675
|
// props.__scope = this.__compScopes[scopeKey]
|
|
2119
1676
|
// }
|
|
2120
1677
|
if (schema?.__ctx?.lceKey) {
|
|
2121
|
-
if (!isSchema(schema)) {
|
|
1678
|
+
if (!rendererCore.isSchema(schema)) {
|
|
2122
1679
|
engine.props?.onCompGetCtx?.(schema, scope);
|
|
2123
1680
|
}
|
|
2124
1681
|
props.key = props.key || `${schema.__ctx.lceKey}_${schema.__ctx.idx || 0}_${idx !== undefined ? idx : ''}`;
|
|
@@ -2191,7 +1748,7 @@ function baseRendererFactory() {
|
|
|
2191
1748
|
Comp,
|
|
2192
1749
|
componentInfo: {
|
|
2193
1750
|
...(componentInfo || {}),
|
|
2194
|
-
props: transformArrayToMap((componentInfo || {}).props, 'name')
|
|
1751
|
+
props: rendererCore.transformArrayToMap((componentInfo || {}).props, 'name')
|
|
2195
1752
|
}
|
|
2196
1753
|
}) || {};
|
|
2197
1754
|
};
|
|
@@ -2239,14 +1796,14 @@ function baseRendererFactory() {
|
|
|
2239
1796
|
Comp,
|
|
2240
1797
|
componentInfo = {}
|
|
2241
1798
|
} = info;
|
|
2242
|
-
const propInfo = getValue(componentInfo.props, path);
|
|
1799
|
+
const propInfo = rendererCore.getValue(componentInfo.props, path);
|
|
2243
1800
|
// FIXME: 将这行逻辑外置,解耦,线上环境不要验证参数,调试环境可以有,通过传参自定义
|
|
2244
1801
|
const propType = propInfo?.extra?.propType;
|
|
2245
1802
|
const checkProps = value => {
|
|
2246
1803
|
if (!propType) {
|
|
2247
1804
|
return value;
|
|
2248
1805
|
}
|
|
2249
|
-
return checkPropTypes(value, path, propType, componentInfo.name) ? value : undefined;
|
|
1806
|
+
return rendererCore.checkPropTypes(value, path, propType, componentInfo.name) ? value : undefined;
|
|
2250
1807
|
};
|
|
2251
1808
|
const parseReactNode = (data, params) => {
|
|
2252
1809
|
if (isEmpty(params)) {
|
|
@@ -2277,16 +1834,16 @@ function baseRendererFactory() {
|
|
|
2277
1834
|
if (core.isJSExpression(props)) {
|
|
2278
1835
|
props = this.__parseExpression(props, scope);
|
|
2279
1836
|
// 只有当变量解析出来为模型结构的时候才会继续解析
|
|
2280
|
-
if (!isSchema(props)) {
|
|
1837
|
+
if (!rendererCore.isSchema(props)) {
|
|
2281
1838
|
return checkProps(props);
|
|
2282
1839
|
}
|
|
2283
1840
|
}
|
|
2284
1841
|
if (core.isJSFunction(props)) {
|
|
2285
|
-
props = transformStringToFunction(props.value);
|
|
1842
|
+
props = rendererCore.transformStringToFunction(props.value);
|
|
2286
1843
|
}
|
|
2287
1844
|
|
|
2288
1845
|
// 兼容通过componentInfo判断的情况
|
|
2289
|
-
if (isSchema(props)) {
|
|
1846
|
+
if (rendererCore.isSchema(props)) {
|
|
2290
1847
|
const isReactNodeFunction = !!(propInfo?.type === 'ReactNode' && propInfo?.props?.type === 'function');
|
|
2291
1848
|
const isMixinReactNodeFunction = !!(propInfo?.type === 'Mixin' && propInfo?.props?.types?.indexOf('ReactNode') > -1 && propInfo?.props?.reactNodeProps?.type === 'function');
|
|
2292
1849
|
let params = null;
|
|
@@ -2389,7 +1946,7 @@ function baseRendererFactory() {
|
|
|
2389
1946
|
...data,
|
|
2390
1947
|
...this.props,
|
|
2391
1948
|
ref: this.__getRef,
|
|
2392
|
-
className: classnames(__schema?.fileName && getFileCssName(__schema.fileName), className, this.props.className),
|
|
1949
|
+
className: rendererCore.classnames(__schema?.fileName && rendererCore.getFileCssName(__schema.fileName), className, this.props.className),
|
|
2393
1950
|
__id: __schema?.id,
|
|
2394
1951
|
...otherProps
|
|
2395
1952
|
}, this.__createDom());
|
|
@@ -2400,7 +1957,7 @@ function baseRendererFactory() {
|
|
|
2400
1957
|
__schema
|
|
2401
1958
|
} = this.props;
|
|
2402
1959
|
const parsedProps = this.__parseData(__schema.props);
|
|
2403
|
-
const className = classnames(`lce-${this.__namespace}`, __schema?.fileName && getFileCssName(__schema.fileName), parsedProps.className, this.props.className);
|
|
1960
|
+
const className = rendererCore.classnames(`lce-${this.__namespace}`, __schema?.fileName && rendererCore.getFileCssName(__schema.fileName), parsedProps.className, this.props.className);
|
|
2404
1961
|
const style = {
|
|
2405
1962
|
...(parsedProps.style || {}),
|
|
2406
1963
|
...(typeof this.props.style === 'object' ? this.props.style : {})
|
|
@@ -2423,13 +1980,13 @@ function baseRendererFactory() {
|
|
|
2423
1980
|
// const builtin = capitalizeFirstLetter(this.__namespace)
|
|
2424
1981
|
// const componentNames = [builtin, ...extraComponents]
|
|
2425
1982
|
const componentNames = [...Object.keys(this.props.__components), ...extraComponents];
|
|
2426
|
-
return !isSchema(schema) || !componentNames.includes(schema?.componentName ?? '');
|
|
1983
|
+
return !rendererCore.isSchema(schema) || !componentNames.includes(schema?.componentName ?? '');
|
|
2427
1984
|
};
|
|
2428
1985
|
get appHelper() {
|
|
2429
1986
|
return this.props.__appHelper;
|
|
2430
1987
|
}
|
|
2431
|
-
get
|
|
2432
|
-
return this.appHelper?.
|
|
1988
|
+
get dataSourceEngine() {
|
|
1989
|
+
return this.appHelper?.dataSourceEngine;
|
|
2433
1990
|
}
|
|
2434
1991
|
get utils() {
|
|
2435
1992
|
return this.appHelper?.utils;
|
|
@@ -2465,7 +2022,7 @@ function componentRendererFactory() {
|
|
|
2465
2022
|
if (this.__checkSchema(__schema)) {
|
|
2466
2023
|
return '自定义组件 schema 结构异常!';
|
|
2467
2024
|
}
|
|
2468
|
-
logger.log(`${CompRenderer.displayName} render - ${__schema.componentName}`);
|
|
2025
|
+
rendererCore.logger.log(`${CompRenderer.displayName} render - ${__schema.componentName}`);
|
|
2469
2026
|
this.__generateCtx({
|
|
2470
2027
|
component: this
|
|
2471
2028
|
});
|
|
@@ -2513,7 +2070,7 @@ function pageRendererFactory() {
|
|
|
2513
2070
|
super.componentDidUpdate?.(prevProps, _prevState, snapshot);
|
|
2514
2071
|
}
|
|
2515
2072
|
setState(state, callback) {
|
|
2516
|
-
logger.log('page set state', state);
|
|
2073
|
+
rendererCore.logger.log('page set state', state);
|
|
2517
2074
|
super.setState(state, callback);
|
|
2518
2075
|
}
|
|
2519
2076
|
render() {
|
|
@@ -2523,7 +2080,7 @@ function pageRendererFactory() {
|
|
|
2523
2080
|
if (this.__checkSchema(__schema)) {
|
|
2524
2081
|
return '页面schema结构异常!';
|
|
2525
2082
|
}
|
|
2526
|
-
logger.log(`${PageRenderer.displayName} render - ${__schema.componentName}`);
|
|
2083
|
+
rendererCore.logger.log(`${PageRenderer.displayName} render - ${__schema.componentName}`);
|
|
2527
2084
|
this.__bindCustomMethods(this.props);
|
|
2528
2085
|
this.__initDataSource(this.props);
|
|
2529
2086
|
this.__generateCtx({
|
|
@@ -2547,7 +2104,7 @@ const FaultComponent = ({
|
|
|
2547
2104
|
componentName = '',
|
|
2548
2105
|
error
|
|
2549
2106
|
}) => {
|
|
2550
|
-
logger.error(`${componentName} 组件渲染异常, 异常原因: ${error?.message || error || '未知'}`);
|
|
2107
|
+
rendererCore.logger.error(`${componentName} 组件渲染异常, 异常原因: ${error?.message || error || '未知'}`);
|
|
2551
2108
|
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
2552
2109
|
role: "alert",
|
|
2553
2110
|
"aria-label": `${componentName} 组件渲染异常`,
|
|
@@ -2569,7 +2126,7 @@ const NotFoundComponent = ({
|
|
|
2569
2126
|
enableStrictNotFoundMode,
|
|
2570
2127
|
children
|
|
2571
2128
|
}) => {
|
|
2572
|
-
logger.warn(`Component ${componentName} not found`);
|
|
2129
|
+
rendererCore.logger.warn(`Component ${componentName} not found`);
|
|
2573
2130
|
if (enableStrictNotFoundMode) {
|
|
2574
2131
|
return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
2575
2132
|
children: `${componentName} Component Not Found`
|
|
@@ -2610,16 +2167,16 @@ function rendererFactory() {
|
|
|
2610
2167
|
constructor(props) {
|
|
2611
2168
|
super(props);
|
|
2612
2169
|
this.state = {};
|
|
2613
|
-
|
|
2170
|
+
rendererCore.logger.log(`entry.constructor - ${props?.schema?.componentName}`);
|
|
2614
2171
|
}
|
|
2615
2172
|
async componentDidMount() {
|
|
2616
|
-
|
|
2173
|
+
rendererCore.logger.log(`entry.componentDidMount - ${this.props.schema && this.props.schema.componentName}`);
|
|
2617
2174
|
}
|
|
2618
2175
|
async componentDidUpdate() {
|
|
2619
|
-
|
|
2176
|
+
rendererCore.logger.log(`entry.componentDidUpdate - ${this.props?.schema?.componentName}`);
|
|
2620
2177
|
}
|
|
2621
2178
|
async componentWillUnmount() {
|
|
2622
|
-
|
|
2179
|
+
rendererCore.logger.log(`entry.componentWillUnmount - ${this.props?.schema?.componentName}`);
|
|
2623
2180
|
}
|
|
2624
2181
|
componentDidCatch(error) {
|
|
2625
2182
|
this.state.engineRenderError = true;
|
|
@@ -2656,11 +2213,11 @@ function rendererFactory() {
|
|
|
2656
2213
|
if (isEmpty(schema)) {
|
|
2657
2214
|
return null;
|
|
2658
2215
|
}
|
|
2659
|
-
if (!isSchema(schema)) {
|
|
2660
|
-
|
|
2216
|
+
if (!rendererCore.isSchema(schema)) {
|
|
2217
|
+
rendererCore.logger.error('The root component name needs to be one of Page、Block、Component, please check the schema: ', schema);
|
|
2661
2218
|
return '模型结构异常';
|
|
2662
2219
|
}
|
|
2663
|
-
|
|
2220
|
+
rendererCore.logger.log('entry.render');
|
|
2664
2221
|
const allComponents = {
|
|
2665
2222
|
...components,
|
|
2666
2223
|
...RENDERER_COMPS
|
|
@@ -2695,40 +2252,274 @@ function rendererFactory() {
|
|
|
2695
2252
|
};
|
|
2696
2253
|
}
|
|
2697
2254
|
|
|
2698
|
-
const
|
|
2255
|
+
const SettingRendererContext = /*#__PURE__*/react.createContext({});
|
|
2256
|
+
const useSettingRendererContext = () => {
|
|
2257
|
+
try {
|
|
2258
|
+
return react.useContext(SettingRendererContext);
|
|
2259
|
+
} catch (error) {
|
|
2260
|
+
console.warn('useSettingRendererContext must be used within a SettingRendererContextProvider');
|
|
2261
|
+
}
|
|
2262
|
+
return {};
|
|
2263
|
+
};
|
|
2264
|
+
|
|
2265
|
+
const getSetterInfo = field => {
|
|
2266
|
+
const {
|
|
2267
|
+
extraProps,
|
|
2268
|
+
setter
|
|
2269
|
+
} = field;
|
|
2270
|
+
const {
|
|
2271
|
+
defaultValue
|
|
2272
|
+
} = extraProps;
|
|
2273
|
+
let setterProps = {};
|
|
2274
|
+
let setterType;
|
|
2275
|
+
let initialValue = null;
|
|
2276
|
+
if (core.isSetterConfig(setter)) {
|
|
2277
|
+
setterType = setter.componentName;
|
|
2278
|
+
if (setter.props) {
|
|
2279
|
+
setterProps = setter.props;
|
|
2280
|
+
if (typeof setterProps === 'function') {
|
|
2281
|
+
setterProps = setterProps(field);
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
if (setter.defaultValue != null) {
|
|
2285
|
+
initialValue = setter.defaultValue;
|
|
2286
|
+
}
|
|
2287
|
+
} else if (setter) {
|
|
2288
|
+
setterType = setter;
|
|
2289
|
+
}
|
|
2290
|
+
if (defaultValue != null && !('defaultValue' in setterProps)) {
|
|
2291
|
+
setterProps.defaultValue = defaultValue;
|
|
2292
|
+
if (initialValue == null) {
|
|
2293
|
+
initialValue = defaultValue;
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2296
|
+
if (field.valueState === -1) {
|
|
2297
|
+
setterProps.multiValue = true;
|
|
2298
|
+
}
|
|
2299
|
+
|
|
2300
|
+
// 根据是否支持变量配置做相应的更改
|
|
2301
|
+
const supportVariable = field.extraProps?.supportVariable;
|
|
2302
|
+
const isUseVariableSetter = supportVariable;
|
|
2303
|
+
if (isUseVariableSetter === false) {
|
|
2304
|
+
return {
|
|
2305
|
+
setterProps,
|
|
2306
|
+
initialValue,
|
|
2307
|
+
setterType
|
|
2308
|
+
};
|
|
2309
|
+
}
|
|
2310
|
+
return {
|
|
2311
|
+
setterProps,
|
|
2312
|
+
setterType,
|
|
2313
|
+
initialValue
|
|
2314
|
+
};
|
|
2315
|
+
};
|
|
2316
|
+
const SettingSetter = mobxReact.observer(({
|
|
2317
|
+
field,
|
|
2318
|
+
children
|
|
2319
|
+
}) => {
|
|
2320
|
+
const {
|
|
2321
|
+
setters
|
|
2322
|
+
} = useSettingRendererContext();
|
|
2323
|
+
const {
|
|
2324
|
+
extraProps
|
|
2325
|
+
} = field;
|
|
2326
|
+
const visible = extraProps?.condition && typeof extraProps.condition === 'function' ? extraProps.condition(field) !== false : true;
|
|
2327
|
+
if (!visible) {
|
|
2328
|
+
return null;
|
|
2329
|
+
}
|
|
2330
|
+
const {
|
|
2331
|
+
setterProps = {},
|
|
2332
|
+
setterType,
|
|
2333
|
+
initialValue = null
|
|
2334
|
+
} = getSetterInfo(field);
|
|
2335
|
+
const onChange = extraProps?.onChange;
|
|
2336
|
+
const value = field.valueState === -1 ? null : field.getValue();
|
|
2337
|
+
const {
|
|
2338
|
+
component: SetterComponent,
|
|
2339
|
+
props: mixedSetterProps
|
|
2340
|
+
} = setters.createSetterContent(setterType, setterProps);
|
|
2341
|
+
return /*#__PURE__*/jsxRuntime.jsx(SetterComponent, {
|
|
2342
|
+
field: field,
|
|
2343
|
+
selected: field.top?.getNode(),
|
|
2344
|
+
initialValue: initialValue,
|
|
2345
|
+
value: value,
|
|
2346
|
+
onChange: newVal => {
|
|
2347
|
+
field.setValue(newVal);
|
|
2348
|
+
onChange?.(field, newVal);
|
|
2349
|
+
},
|
|
2350
|
+
onInitial: () => {
|
|
2351
|
+
if (initialValue == null) {
|
|
2352
|
+
return;
|
|
2353
|
+
}
|
|
2354
|
+
const value = typeof initialValue === 'function' ? initialValue(field) : initialValue;
|
|
2355
|
+
field.setValue(value, true);
|
|
2356
|
+
},
|
|
2357
|
+
removeProp: () => {
|
|
2358
|
+
if (field.name) {
|
|
2359
|
+
field.parent.clearPropValue(field.name);
|
|
2360
|
+
}
|
|
2361
|
+
},
|
|
2362
|
+
...mixedSetterProps,
|
|
2363
|
+
children: children
|
|
2364
|
+
}, field.id);
|
|
2365
|
+
});
|
|
2366
|
+
|
|
2367
|
+
const SettingFieldItem = mobxReact.observer(({
|
|
2368
|
+
field
|
|
2369
|
+
}) => {
|
|
2370
|
+
const {
|
|
2371
|
+
customFieldItem
|
|
2372
|
+
} = useSettingRendererContext();
|
|
2373
|
+
if (customFieldItem) {
|
|
2374
|
+
return customFieldItem(field, /*#__PURE__*/jsxRuntime.jsx(SettingSetter, {
|
|
2375
|
+
field: field
|
|
2376
|
+
}));
|
|
2377
|
+
}
|
|
2378
|
+
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
2379
|
+
className: "space-y-2",
|
|
2380
|
+
children: [/*#__PURE__*/jsxRuntime.jsx("label", {
|
|
2381
|
+
htmlFor: field.id,
|
|
2382
|
+
className: "block text-sm font-medium text-gray-700",
|
|
2383
|
+
children: field.title
|
|
2384
|
+
}), /*#__PURE__*/jsxRuntime.jsx(SettingSetter, {
|
|
2385
|
+
field: field
|
|
2386
|
+
})]
|
|
2387
|
+
});
|
|
2388
|
+
});
|
|
2389
|
+
const SettingFieldGroup = mobxReact.observer(({
|
|
2390
|
+
field
|
|
2391
|
+
}) => {
|
|
2392
|
+
const {
|
|
2393
|
+
customFieldGroup
|
|
2394
|
+
} = useSettingRendererContext();
|
|
2395
|
+
if (customFieldGroup) {
|
|
2396
|
+
return customFieldGroup(field, /*#__PURE__*/jsxRuntime.jsx(SettingSetter, {
|
|
2397
|
+
field: field,
|
|
2398
|
+
children: field.items?.map(item => /*#__PURE__*/jsxRuntime.jsx(SettingFieldView, {
|
|
2399
|
+
field: item
|
|
2400
|
+
}, item.id))
|
|
2401
|
+
}));
|
|
2402
|
+
}
|
|
2403
|
+
|
|
2404
|
+
// 如果 field 没有 setter,则理解为其 父级 field 的 items 数据
|
|
2405
|
+
if (!field.setter) {
|
|
2406
|
+
return field.items?.map(item => /*#__PURE__*/jsxRuntime.jsx(SettingFieldView, {
|
|
2407
|
+
field: item
|
|
2408
|
+
}, item.id));
|
|
2409
|
+
}
|
|
2410
|
+
return /*#__PURE__*/jsxRuntime.jsx(SettingSetter, {
|
|
2411
|
+
field: field,
|
|
2412
|
+
children: field.items?.map(item => /*#__PURE__*/jsxRuntime.jsx(SettingFieldView, {
|
|
2413
|
+
field: item
|
|
2414
|
+
}, item.id))
|
|
2415
|
+
});
|
|
2416
|
+
});
|
|
2417
|
+
const SettingFieldView = ({
|
|
2418
|
+
field
|
|
2419
|
+
}) => {
|
|
2420
|
+
if (field.isGroup) {
|
|
2421
|
+
return /*#__PURE__*/jsxRuntime.jsx(SettingFieldGroup, {
|
|
2422
|
+
field: field
|
|
2423
|
+
}, field.id);
|
|
2424
|
+
} else {
|
|
2425
|
+
return /*#__PURE__*/jsxRuntime.jsx(SettingFieldItem, {
|
|
2426
|
+
field: field
|
|
2427
|
+
}, field.id);
|
|
2428
|
+
}
|
|
2429
|
+
};
|
|
2430
|
+
const SettingRenderer = mobxReact.observer(props => {
|
|
2431
|
+
const {
|
|
2432
|
+
designer,
|
|
2433
|
+
customFieldItem,
|
|
2434
|
+
customFieldGroup
|
|
2435
|
+
} = props;
|
|
2436
|
+
const setters = designer.editor.get('setters');
|
|
2437
|
+
const {
|
|
2438
|
+
settingsManager
|
|
2439
|
+
} = designer;
|
|
2440
|
+
const {
|
|
2441
|
+
settings
|
|
2442
|
+
} = settingsManager;
|
|
2443
|
+
const items = settings?.items;
|
|
2444
|
+
const ctx = react.useMemo(() => {
|
|
2445
|
+
const ctx = {};
|
|
2446
|
+
ctx.setters = setters;
|
|
2447
|
+
ctx.settingsManager = settingsManager;
|
|
2448
|
+
ctx.customFieldItem = customFieldItem;
|
|
2449
|
+
ctx.customFieldGroup = customFieldGroup;
|
|
2450
|
+
return ctx;
|
|
2451
|
+
}, [setters, settingsManager, customFieldItem, customFieldGroup]);
|
|
2452
|
+
if (!settings) {
|
|
2453
|
+
// 未选中节点,提示选中 或者 显示根节点设置
|
|
2454
|
+
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
2455
|
+
className: "lc-settings-main",
|
|
2456
|
+
children: /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
2457
|
+
className: "lc-settings-notice",
|
|
2458
|
+
children: /*#__PURE__*/jsxRuntime.jsx("p", {
|
|
2459
|
+
children: "Please select a node in canvas"
|
|
2460
|
+
})
|
|
2461
|
+
})
|
|
2462
|
+
});
|
|
2463
|
+
}
|
|
2464
|
+
|
|
2465
|
+
// 当节点被锁定,且未开启锁定后容器可设置属性
|
|
2466
|
+
if (settings.isLocked) {
|
|
2467
|
+
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
2468
|
+
className: "lc-settings-main",
|
|
2469
|
+
children: /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
2470
|
+
className: "lc-settings-notice",
|
|
2471
|
+
children: /*#__PURE__*/jsxRuntime.jsx("p", {
|
|
2472
|
+
children: "Current node is locked"
|
|
2473
|
+
})
|
|
2474
|
+
})
|
|
2475
|
+
});
|
|
2476
|
+
}
|
|
2477
|
+
if (Array.isArray(settings.items) && settings.items.length === 0) {
|
|
2478
|
+
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
2479
|
+
className: "lc-settings-main",
|
|
2480
|
+
children: /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
2481
|
+
className: "lc-settings-notice",
|
|
2482
|
+
children: /*#__PURE__*/jsxRuntime.jsx("p", {
|
|
2483
|
+
children: "No config found for this type of component"
|
|
2484
|
+
})
|
|
2485
|
+
})
|
|
2486
|
+
});
|
|
2487
|
+
}
|
|
2488
|
+
if (!settings.isSameComponent) {
|
|
2489
|
+
// TODO: future support 获取设置项交集编辑
|
|
2490
|
+
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
2491
|
+
className: "lc-settings-main",
|
|
2492
|
+
children: /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
2493
|
+
className: "lc-settings-notice",
|
|
2494
|
+
children: /*#__PURE__*/jsxRuntime.jsx("p", {
|
|
2495
|
+
children: "Please select same kind of components"
|
|
2496
|
+
})
|
|
2497
|
+
})
|
|
2498
|
+
});
|
|
2499
|
+
}
|
|
2500
|
+
return /*#__PURE__*/jsxRuntime.jsx(SettingRendererContext.Provider, {
|
|
2501
|
+
value: ctx,
|
|
2502
|
+
children: items?.map(item => /*#__PURE__*/jsxRuntime.jsx(SettingFieldView, {
|
|
2503
|
+
field: item
|
|
2504
|
+
}, item.id))
|
|
2505
|
+
});
|
|
2506
|
+
});
|
|
2699
2507
|
|
|
2700
|
-
exports.DEV = DEV;
|
|
2701
2508
|
exports.RendererContext = RendererContext;
|
|
2702
2509
|
exports.SettingFieldView = SettingFieldView;
|
|
2703
|
-
exports.
|
|
2510
|
+
exports.SettingRenderer = SettingRenderer;
|
|
2704
2511
|
exports.adapter = adapter;
|
|
2705
2512
|
exports.baseRendererFactory = baseRendererFactory;
|
|
2706
|
-
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
2707
|
-
exports.checkPropTypes = checkPropTypes;
|
|
2708
|
-
exports.classnames = classnames;
|
|
2709
2513
|
exports.cloneEnumerableProperty = cloneEnumerableProperty;
|
|
2710
2514
|
exports.compWrapper = compWrapper;
|
|
2711
2515
|
exports.componentRendererFactory = componentRendererFactory;
|
|
2712
2516
|
exports.contextFactory = contextFactory;
|
|
2713
2517
|
exports.createForwardRefHocElement = createForwardRefHocElement;
|
|
2714
2518
|
exports.executeLifeCycleMethod = executeLifeCycleMethod;
|
|
2715
|
-
exports.getFileCssName = getFileCssName;
|
|
2716
2519
|
exports.getSchemaChildren = getSchemaChildren;
|
|
2717
|
-
exports.getValue = getValue;
|
|
2718
|
-
exports.inSameDomain = inSameDomain;
|
|
2719
2520
|
exports.isReactClass = isReactClass;
|
|
2720
2521
|
exports.isReactComponent = isReactComponent;
|
|
2721
|
-
exports.isSchema = isSchema;
|
|
2722
|
-
exports.isString = isString;
|
|
2723
|
-
exports.isUseLoop = isUseLoop;
|
|
2724
2522
|
exports.leafWrapper = leafWrapper;
|
|
2725
|
-
exports.logger = logger;
|
|
2726
2523
|
exports.pageRendererFactory = pageRendererFactory;
|
|
2727
|
-
exports.parseData = parseData;
|
|
2728
|
-
exports.parseExpression = parseExpression;
|
|
2729
|
-
exports.parseThisRequiredExpression = parseThisRequiredExpression;
|
|
2730
2524
|
exports.rendererFactory = rendererFactory;
|
|
2731
|
-
exports.transformArrayToMap = transformArrayToMap;
|
|
2732
|
-
exports.transformStringToFunction = transformStringToFunction;
|
|
2733
2525
|
exports.useRendererContext = useRendererContext;
|
|
2734
|
-
//# sourceMappingURL=index.js.map
|