neo-register 1.0.5 → 1.0.7
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/dist/{src/function → function}/registerNeoEditorModel.d.ts +19 -1
- package/dist/index.esm.js +147 -126
- package/dist/index.esm.min.js +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.LICENSE.txt +2 -2
- package/dist/{src/main.d.ts → main.d.ts} +1 -0
- package/dist/{src/utils → utils}/index.d.ts +1 -1
- package/dist/{src/utils → utils}/object.d.ts +1 -1
- package/docs/EditorItemType.md +856 -0
- package/docs/FormItemType.md +186 -19
- package/docs/NeoCmps.md +100 -0
- package/package.json +2 -2
- package/dist/demo2/entity-detail/index.d.ts +0 -40
- package/dist/demo2/entity-detail/model.d.ts +0 -77
- package/dist/demo2/entity-detail/register.d.ts +0 -1
- package/docs/NeoEntityApiType/xObjectDataApi.md +0 -35
- package/docs/NeoEntityApiType/xObjectDetailApi.md +0 -35
- package/docs/NeoEntityApiType/xObjectEntityList.md +0 -35
- /package/dist/{src/function → function}/registerNeoCmp.d.ts +0 -0
|
@@ -45,7 +45,25 @@ export interface PluginOption {
|
|
|
45
45
|
*/
|
|
46
46
|
propsSchema?: boolean;
|
|
47
47
|
}
|
|
48
|
+
interface RegisterNeoEditorModelOptions {
|
|
49
|
+
targetPage?: string;
|
|
50
|
+
tags?: string[];
|
|
51
|
+
exposedToDesigner?: boolean;
|
|
52
|
+
namespace?: string;
|
|
53
|
+
enableDuplicate?: boolean;
|
|
54
|
+
}
|
|
48
55
|
/**
|
|
49
56
|
* registerNeoEditorModel: 注册 neo-editor 自定义组件模型
|
|
57
|
+
*
|
|
58
|
+
* targetPage 取值说明
|
|
59
|
+
* all: 页面
|
|
60
|
+
* all: 1 全页面
|
|
61
|
+
* indexPage: 2 首页
|
|
62
|
+
* entityListPage: 3 实体列表页
|
|
63
|
+
* entityFormPage: 4 实体表单页
|
|
64
|
+
* entityDetailPage: 5 实体详情页
|
|
65
|
+
* customPage: 6 自定义页面
|
|
66
|
+
* bizPage: 7 业务页面
|
|
50
67
|
*/
|
|
51
|
-
export declare function registerNeoEditorModel(curEditorModel: any, cmpType?: string): void;
|
|
68
|
+
export declare function registerNeoEditorModel(curEditorModel: any, cmpType?: string, options?: RegisterNeoEditorModelOptions): void;
|
|
69
|
+
export {};
|
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,123 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import Vue from 'vue';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* 将 vue2.0 自定义组件包裹成一个 react组件
|
|
6
|
+
*/
|
|
7
|
+
function createVue2Component(vueObj) {
|
|
8
|
+
if (!vueObj || (typeof vueObj !== 'function' && typeof vueObj !== 'object')) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
class VueFactory extends React.Component {
|
|
12
|
+
domRef;
|
|
13
|
+
vm;
|
|
14
|
+
isUnmount;
|
|
15
|
+
// 指定 contextType 读取当前的 scope context。
|
|
16
|
+
// React 会往上找到最近的 scope Provider,然后使用它的值。
|
|
17
|
+
// static contextType = ScopedContext; // 待支持
|
|
18
|
+
constructor(props, context) {
|
|
19
|
+
super(props);
|
|
20
|
+
this.domRef = React.createRef();
|
|
21
|
+
this.isUnmount = false;
|
|
22
|
+
/*
|
|
23
|
+
// 待支持(自定义组件支持事件动作)
|
|
24
|
+
const scoped = context;
|
|
25
|
+
scoped.registerComponent(this);
|
|
26
|
+
*/
|
|
27
|
+
this.resolveNeoProps = this.resolveNeoProps.bind(this);
|
|
28
|
+
}
|
|
29
|
+
componentDidMount() {
|
|
30
|
+
const { neoData, neoMSTData, neoFunc } = this.resolveNeoProps();
|
|
31
|
+
const { data, ...rest } = (vueObj =
|
|
32
|
+
typeof vueObj === 'function' ? new vueObj() : vueObj);
|
|
33
|
+
const vueData = typeof data === 'function' ? data() : data;
|
|
34
|
+
const curVueData = extendObject(vueData, neoData);
|
|
35
|
+
// 传入的Vue属性
|
|
36
|
+
this.vm = new Vue({
|
|
37
|
+
...rest,
|
|
38
|
+
data: () => curVueData,
|
|
39
|
+
props: extendObject(neoFunc, {
|
|
40
|
+
...(rest.props || {}),
|
|
41
|
+
...neoMSTData,
|
|
42
|
+
}),
|
|
43
|
+
});
|
|
44
|
+
Object.keys(neoFunc).forEach((key) => {
|
|
45
|
+
this.vm.$props[key] = neoFunc[key];
|
|
46
|
+
});
|
|
47
|
+
if (this.domRef.current) {
|
|
48
|
+
this.domRef.current.appendChild(this.vm.$mount().$el);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
componentDidUpdate() {
|
|
52
|
+
if (!this.isUnmount) {
|
|
53
|
+
const { neoData } = this.resolveNeoProps();
|
|
54
|
+
if (this.vm) {
|
|
55
|
+
Object.keys(neoData).forEach((key) => {
|
|
56
|
+
this.vm[key] = neoData[key];
|
|
57
|
+
});
|
|
58
|
+
this.vm.$forceUpdate();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
componentWillUnmount() {
|
|
63
|
+
this.isUnmount = true;
|
|
64
|
+
/*
|
|
65
|
+
// 待支持
|
|
66
|
+
const scoped = this.context;
|
|
67
|
+
scoped.unRegisterComponent(this);
|
|
68
|
+
*/
|
|
69
|
+
if (this.vm) {
|
|
70
|
+
this.vm.$destroy();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
resolveNeoProps() {
|
|
74
|
+
let neoFunc = {};
|
|
75
|
+
let neoData = {};
|
|
76
|
+
let neoMSTData = {};
|
|
77
|
+
Object.keys(this.props).forEach((key) => {
|
|
78
|
+
const value = this.props[key];
|
|
79
|
+
if (typeof value === 'function') {
|
|
80
|
+
neoFunc[key] = value;
|
|
81
|
+
}
|
|
82
|
+
else if (isProxy(value)) {
|
|
83
|
+
neoMSTData[key] = value;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
neoData[key] = value;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return { neoData, neoMSTData, neoFunc };
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* reload动作处理
|
|
93
|
+
*/
|
|
94
|
+
reload() {
|
|
95
|
+
if (this.vm && this.vm.reload) {
|
|
96
|
+
this.vm.reload();
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
console.warn('自定义组件暂不支持reload动作。');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* 事件动作处理:
|
|
104
|
+
* 在这里设置自定义组件对外暴露的动作,其他组件可以通过组件动作触发自定义组件的对应动作
|
|
105
|
+
*/
|
|
106
|
+
doAction(action, args) {
|
|
107
|
+
if (this.vm && this.vm.doAction) {
|
|
108
|
+
this.vm.doAction(action, args);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
console.warn('自定义组件中不存在 doAction。');
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
render() {
|
|
115
|
+
return React.createElement("div", { ref: this.domRef });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return VueFactory;
|
|
119
|
+
}
|
|
120
|
+
|
|
4
121
|
// 方便取值的时候能够把上层的取到,但是获取的时候不会全部把所有的数据获取到。
|
|
5
122
|
function cloneObject(target, persistOwnProps = true) {
|
|
6
123
|
const obj = target && target.__super
|
|
@@ -156,23 +273,44 @@ function isProxy(obj) {
|
|
|
156
273
|
obj.$modelId);
|
|
157
274
|
return (hasMSTProperties || Object.prototype.toString.call(obj) === '[object Proxy]');
|
|
158
275
|
}
|
|
276
|
+
// 自动识别并转换 vue 组件
|
|
277
|
+
function autoConvertVueComponent(component) {
|
|
278
|
+
if (isVueComponent(component)) {
|
|
279
|
+
return createVue2Component(component);
|
|
280
|
+
}
|
|
281
|
+
return component;
|
|
282
|
+
}
|
|
159
283
|
|
|
160
284
|
/**
|
|
161
285
|
* registerNeoEditorModel: 注册 neo-editor 自定义组件模型
|
|
286
|
+
*
|
|
287
|
+
* targetPage 取值说明
|
|
288
|
+
* all: 页面
|
|
289
|
+
* all: 1 全页面
|
|
290
|
+
* indexPage: 2 首页
|
|
291
|
+
* entityListPage: 3 实体列表页
|
|
292
|
+
* entityFormPage: 4 实体表单页
|
|
293
|
+
* entityDetailPage: 5 实体详情页
|
|
294
|
+
* customPage: 6 自定义页面
|
|
295
|
+
* bizPage: 7 业务页面
|
|
162
296
|
*/
|
|
163
|
-
function registerNeoEditorModel(curEditorModel, cmpType) {
|
|
297
|
+
function registerNeoEditorModel(curEditorModel, cmpType, options) {
|
|
164
298
|
if (curEditorModel && isEditorModel(curEditorModel)) {
|
|
165
299
|
const curCmpType = cmpType || new curEditorModel().cmpType;
|
|
166
300
|
if (!curCmpType) {
|
|
167
301
|
console.error(`${consoleTag} / registerNeoEditorModel: 自定义组件注册失败,cmpType 不能为空。`);
|
|
168
302
|
}
|
|
169
|
-
const
|
|
303
|
+
const curOptions = options || {};
|
|
304
|
+
const curEditorModelObj = new curEditorModel(); // 注册前进行一次实例化
|
|
170
305
|
Object.assign(curEditorModel.prototype, {
|
|
171
|
-
|
|
172
|
-
exposedToDesigner: curEditorModelObj.exposedToDesigner ?? true,
|
|
173
|
-
namespace: curEditorModelObj.namespace ?? 'neo-cmp-cli',
|
|
174
|
-
enableDuplicate: curEditorModelObj.enableDuplicate ?? true,
|
|
306
|
+
...curEditorModelObj,
|
|
175
307
|
cmpType: curCmpType,
|
|
308
|
+
custom: true,
|
|
309
|
+
tags: curEditorModelObj.tags ?? curOptions.tags ?? ['自定义组件'],
|
|
310
|
+
targetPage: curEditorModelObj.targetPage ?? curOptions.targetPage ?? ['customPage'],
|
|
311
|
+
exposedToDesigner: curEditorModelObj.exposedToDesigner ?? curOptions.exposedToDesigner ?? true,
|
|
312
|
+
namespace: curEditorModelObj.namespace ?? curOptions.namespace ?? 'neo-cmp-cli',
|
|
313
|
+
enableDuplicate: curEditorModelObj.enableDuplicate ?? curOptions.enableDuplicate ?? true, // 默认在设计器中允许重复插入
|
|
176
314
|
});
|
|
177
315
|
// registerEditorModel(curEditorModel); // 不直接注册为 neo-editor 插件
|
|
178
316
|
// 通过 postMessage 告知 neo-editor 注册一个新的插件
|
|
@@ -203,123 +341,6 @@ function AddCustomEditorModel(cmpType, model) {
|
|
|
203
341
|
return null;
|
|
204
342
|
}
|
|
205
343
|
|
|
206
|
-
/**
|
|
207
|
-
* 将 vue2.0 自定义组件包裹成一个 react组件
|
|
208
|
-
*/
|
|
209
|
-
function createVue2Component(vueObj) {
|
|
210
|
-
if (!vueObj || (typeof vueObj !== 'function' && typeof vueObj !== 'object')) {
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
class VueFactory extends React.Component {
|
|
214
|
-
domRef;
|
|
215
|
-
vm;
|
|
216
|
-
isUnmount;
|
|
217
|
-
// 指定 contextType 读取当前的 scope context。
|
|
218
|
-
// React 会往上找到最近的 scope Provider,然后使用它的值。
|
|
219
|
-
// static contextType = ScopedContext; // 待支持
|
|
220
|
-
constructor(props, context) {
|
|
221
|
-
super(props);
|
|
222
|
-
this.domRef = React.createRef();
|
|
223
|
-
this.isUnmount = false;
|
|
224
|
-
/*
|
|
225
|
-
// 待支持(自定义组件支持事件动作)
|
|
226
|
-
const scoped = context;
|
|
227
|
-
scoped.registerComponent(this);
|
|
228
|
-
*/
|
|
229
|
-
this.resolveNeoProps = this.resolveNeoProps.bind(this);
|
|
230
|
-
}
|
|
231
|
-
componentDidMount() {
|
|
232
|
-
const { neoData, neoMSTData, neoFunc } = this.resolveNeoProps();
|
|
233
|
-
const { data, ...rest } = (vueObj =
|
|
234
|
-
typeof vueObj === 'function' ? new vueObj() : vueObj);
|
|
235
|
-
const vueData = typeof data === 'function' ? data() : data;
|
|
236
|
-
const curVueData = extendObject(vueData, neoData);
|
|
237
|
-
// 传入的Vue属性
|
|
238
|
-
this.vm = new Vue({
|
|
239
|
-
...rest,
|
|
240
|
-
data: () => curVueData,
|
|
241
|
-
props: extendObject(neoFunc, {
|
|
242
|
-
...(rest.props || {}),
|
|
243
|
-
...neoMSTData,
|
|
244
|
-
}),
|
|
245
|
-
});
|
|
246
|
-
Object.keys(neoFunc).forEach((key) => {
|
|
247
|
-
this.vm.$props[key] = neoFunc[key];
|
|
248
|
-
});
|
|
249
|
-
if (this.domRef.current) {
|
|
250
|
-
this.domRef.current.appendChild(this.vm.$mount().$el);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
componentDidUpdate() {
|
|
254
|
-
if (!this.isUnmount) {
|
|
255
|
-
const { neoData } = this.resolveNeoProps();
|
|
256
|
-
if (this.vm) {
|
|
257
|
-
Object.keys(neoData).forEach((key) => {
|
|
258
|
-
this.vm[key] = neoData[key];
|
|
259
|
-
});
|
|
260
|
-
this.vm.$forceUpdate();
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
componentWillUnmount() {
|
|
265
|
-
this.isUnmount = true;
|
|
266
|
-
/*
|
|
267
|
-
// 待支持
|
|
268
|
-
const scoped = this.context;
|
|
269
|
-
scoped.unRegisterComponent(this);
|
|
270
|
-
*/
|
|
271
|
-
if (this.vm) {
|
|
272
|
-
this.vm.$destroy();
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
resolveNeoProps() {
|
|
276
|
-
let neoFunc = {};
|
|
277
|
-
let neoData = {};
|
|
278
|
-
let neoMSTData = {};
|
|
279
|
-
Object.keys(this.props).forEach((key) => {
|
|
280
|
-
const value = this.props[key];
|
|
281
|
-
if (typeof value === 'function') {
|
|
282
|
-
neoFunc[key] = value;
|
|
283
|
-
}
|
|
284
|
-
else if (isProxy(value)) {
|
|
285
|
-
neoMSTData[key] = value;
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
neoData[key] = value;
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
return { neoData, neoMSTData, neoFunc };
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* reload动作处理
|
|
295
|
-
*/
|
|
296
|
-
reload() {
|
|
297
|
-
if (this.vm && this.vm.reload) {
|
|
298
|
-
this.vm.reload();
|
|
299
|
-
}
|
|
300
|
-
else {
|
|
301
|
-
console.warn('自定义组件暂不支持reload动作。');
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* 事件动作处理:
|
|
306
|
-
* 在这里设置自定义组件对外暴露的动作,其他组件可以通过组件动作触发自定义组件的对应动作
|
|
307
|
-
*/
|
|
308
|
-
doAction(action, args) {
|
|
309
|
-
if (this.vm && this.vm.doAction) {
|
|
310
|
-
this.vm.doAction(action, args);
|
|
311
|
-
}
|
|
312
|
-
else {
|
|
313
|
-
console.warn('自定义组件中不存在 doAction。');
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
render() {
|
|
317
|
-
return React.createElement("div", { ref: this.domRef });
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
return VueFactory;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
344
|
/**
|
|
324
345
|
* registerNeoCmp: 根据type类型注册 neo 自定义组件
|
|
325
346
|
*【方法参数说明】
|
|
@@ -383,7 +404,7 @@ function registerNeoCmp(newRenderer, rendererOption) {
|
|
|
383
404
|
else {
|
|
384
405
|
// 通过 postMessage 告知 neo 注册一个新的渲染器
|
|
385
406
|
if (window && window.postMessage) {
|
|
386
|
-
const newComponentType =
|
|
407
|
+
const newComponentType = AddNeoCustomCmp(curRendererOption.cmpType, {
|
|
387
408
|
cmpType: curRendererOption.cmpType,
|
|
388
409
|
weight: curRendererOption.weight,
|
|
389
410
|
usage: curRendererOption.usage,
|
|
@@ -408,7 +429,7 @@ function registerNeoCmp(newRenderer, rendererOption) {
|
|
|
408
429
|
}
|
|
409
430
|
}
|
|
410
431
|
}
|
|
411
|
-
function
|
|
432
|
+
function AddNeoCustomCmp(componentType, rendererData) {
|
|
412
433
|
if (window && !window.NeoCustomCmps) {
|
|
413
434
|
window.NeoCustomCmps = {};
|
|
414
435
|
}
|
|
@@ -422,4 +443,4 @@ function AddNeoCustomModel(componentType, rendererData) {
|
|
|
422
443
|
return null;
|
|
423
444
|
}
|
|
424
445
|
|
|
425
|
-
export { createVue2Component, registerNeoCmp, registerNeoEditorModel };
|
|
446
|
+
export { autoConvertVueComponent, createVue2Component, registerNeoCmp, registerNeoEditorModel };
|
package/dist/index.esm.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"react";import o from"vue";function t(
|
|
1
|
+
import e from"react";import o from"vue";function t(t){if(t&&("function"==typeof t||"object"==typeof t)){class n extends e.Component{domRef;vm;isUnmount;constructor(o,t){super(o),this.domRef=e.createRef(),this.isUnmount=!1,this.resolveNeoProps=this.resolveNeoProps.bind(this)}componentDidMount(){const{neoData:e,neoMSTData:n,neoFunc:s}=this.resolveNeoProps(),{data:i,...c}=t="function"==typeof t?new t:t,a=r("function"==typeof i?i():i,e);this.vm=new o({...c,data:()=>a,props:r(s,{...c.props||{},...n})}),Object.keys(s).forEach(e=>{this.vm.$props[e]=s[e]}),this.domRef.current&&this.domRef.current.appendChild(this.vm.$mount().$el)}componentDidUpdate(){if(!this.isUnmount){const{neoData:e}=this.resolveNeoProps();this.vm&&(Object.keys(e).forEach(o=>{this.vm[o]=e[o]}),this.vm.$forceUpdate())}}componentWillUnmount(){this.isUnmount=!0,this.vm&&this.vm.$destroy()}resolveNeoProps(){let e={},o={},t={};return Object.keys(this.props).forEach(r=>{const n=this.props[r];"function"==typeof n?e[r]=n:!function(e){if(!e)return!1;return!!(e.$treenode||e.$mstObservable||e.$modelType||e.$modelId)||"[object Proxy]"===Object.prototype.toString.call(e)}(n)?o[r]=n:t[r]=n}),{neoData:o,neoMSTData:t,neoFunc:e}}reload(){this.vm&&this.vm.reload?this.vm.reload():console.warn("自定义组件暂不支持reload动作。")}doAction(e,o){this.vm&&this.vm.doAction?this.vm.doAction(e,o):console.warn("自定义组件中不存在 doAction。")}render(){return e.createElement("div",{ref:this.domRef})}}return n}}function r(e,o,t=!0){const r=function(e,o=!0){const t=e&&e.__super?Object.create(e.__super,{__super:{value:e.__super,writable:!1,enumerable:!1}}):Object.create(Object.prototype);return o&&e&&Object.keys(e).forEach(o=>t[o]=e[o]),t}(e,t);return o&&Object.keys(o).forEach(e=>r[e]=o[e]),r}const n="[neo-register]";function s(e){return"object"==typeof e&&(e._compiled&&e.components||e.__file&&e.__file.endsWith(".vue"))}var i,c;function a(e){return s(e)?t(e):e}function u(e,o,t){if(e&&function(e){let o=!1;if(!e)return!1;const t=new e;return t.label?t.tags?Array.isArray(t.tags)?(t.icon||Object.assign(e.prototype,{icon:"https://neo-widgets.bj.bcebos.com/custom-widget.svg"}),o=!0):console.error(`${n} / registerNeoEditorModel: 自定义组件注册失败,组件分类(tags)格式异常。`):console.error(`${n} / registerNeoEditorModel: 自定义组件注册失败,组件分类(tags)不能为空。`):console.error(`${n} / registerNeoEditorModel: 自定义组件注册失败,名称(label)不能为空。`),o}(e)){const r=o||(new e).cmpType;r||console.error(`${n} / registerNeoEditorModel: 自定义组件注册失败,cmpType 不能为空。`);const s=t||{},i=new e;if(Object.assign(e.prototype,{...i,cmpType:r,custom:!0,tags:i.tags??s.tags??["自定义组件"],targetPage:i.targetPage??s.targetPage??["customPage"],exposedToDesigner:i.exposedToDesigner??s.exposedToDesigner??!0,namespace:i.namespace??s.namespace??"neo-cmp-cli",enableDuplicate:i.enableDuplicate??s.enableDuplicate??!0}),window&&window.postMessage){const o=function(e,o){window&&!window.NEOEditorCustomModels&&(window.NEOEditorCustomModels={});if(!window.NEOEditorCustomModels[e])return window.NEOEditorCustomModels[e]=o,e;console.error(`${n}注册自定义组件模型失败,已存在重名插件(${e})。`);return null}(r,e);o&&(console.info(`${n}触发注册自定义组件模型(${r})事件`),window.postMessage({type:"neo-model-register-event",eventMsg:`${n}注册一个 neo-editor 自定义组件模型`,cmpType:r},"*"))}}}function m(e,o){if(!e)return;const r={cmpType:"",usage:i.renderer,weight:0};var a;if(o&&(a=o,"String"===Object.prototype.toString.call(a).slice(8,-1))?Object.assign(r,{cmpType:o}):Object.assign(r,o),r&&!r.cmpType)console.error(`${n} / registerNeoCmp: 自定义组件注册失败,cmpType 不能为空。`);else{r.framework=r.framework?function(e){let o=c.react;if(!e)return o;let t=e.toLowerCase().trim();switch(t){case"jquery":case"jq":t=c.jquery;break;case"vue2":case"vue 2":case"vue2.0":case"vue 2.0":t=c.vue2;break;case"vue":case"vue3":case"vue 3":case"vue3.0":case"vue 3.0":t=c.vue3,console.error(`${n} 暂不支持 vue3.0 技术栈。`);break;default:t=c.react}return t}(r.framework):s(e)?"vue2":"react",r.usage=function(e){let o=i.renderer;if(!e)return o;let t=e.toLowerCase().trim();switch(t){case"renderer":case"renderers":default:t=i.renderer;break;case"formitem":case"form-item":case"form item":t=i.formitem}return t}(r.usage);const o={renderer:()=>{},formitem:()=>{}},a={react:e=>e,vue2:t,vue3:t}[r.framework](e);if(o[r.usage]){if(window&&window.postMessage){const e=function(e,o){window&&!window.NeoCustomCmps&&(window.NeoCustomCmps={});if(!window.NeoCustomCmps[e])return window.NeoCustomCmps[e]=o,e;console.error(`${n} / registerNeoCmp: 自定义组件注册失败,已存在重名渲染器(${e})。`);return null}(r.cmpType,{cmpType:r.cmpType,weight:r.weight,usage:r.usage,framework:r.framework,component:a,config:r});e&&(console.info(`${n}触发注册自定义组件(${e})事件`),window.postMessage({type:"neo-cmp-register-event",eventMsg:`${n}注册一个自定义组件`,neoRenderer:{cmpType:e,weight:r.weight,usage:r.usage,config:r}},"*"))}}else console.error(`${n} / registerNeoCmp: 自定义组件注册失败,暂不支持 ${r.usage} 组件类型。`)}}!function(e){e.renderer="renderer",e.formitem="formitem"}(i||(i={})),function(e){e.react="react",e.vue2="vue2",e.vue3="vue3",e.jquery="jquery"}(c||(c={}));export{a as autoConvertVueComponent,t as createVue2Component,m as registerNeoCmp,u as registerNeoEditorModel};
|
package/dist/index.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! For license information please see index.umd.js.LICENSE.txt */
|
|
2
|
-
!function(e,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define([],o):"object"==typeof exports?exports.neoRegister=o():e.neoRegister=o()}(this,function(){return function(){"use strict";var e={n:function(o){var r=o&&o.__esModule?function(){return o.default}:function(){return o};return e.d(r,{a:r}),r},d:function(o,r){for(var t in r)e.o(r,t)&&!e.o(o,t)&&Object.defineProperty(o,t,{enumerable:!0,get:r[t]})},o:function(e,o){return Object.prototype.hasOwnProperty.call(e,o)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},o={};e.r(o),e.d(o,{createVue2Component:function(){return
|
|
2
|
+
!function(e,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define([],o):"object"==typeof exports?exports.neoRegister=o():e.neoRegister=o()}(this,function(){return function(){"use strict";var e={n:function(o){var r=o&&o.__esModule?function(){return o.default}:function(){return o};return e.d(r,{a:r}),r},d:function(o,r){for(var t in r)e.o(r,t)&&!e.o(o,t)&&Object.defineProperty(o,t,{enumerable:!0,get:r[t]})},o:function(e,o){return Object.prototype.hasOwnProperty.call(e,o)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},o={};e.r(o),e.d(o,{autoConvertVueComponent:function(){return b},createVue2Component:function(){return m},registerNeoCmp:function(){return j},registerNeoEditorModel:function(){return h}});var r=require("@babel/runtime/helpers/extends"),t=e.n(r),n=require("@babel/runtime/helpers/objectWithoutPropertiesLoose"),i=e.n(n),s=require("@babel/runtime/helpers/inheritsLoose"),u=e.n(s),c=require("react"),a=e.n(c),p=require("vue"),f=e.n(p),l=["data"];function m(e){if(e&&("function"==typeof e||"object"==typeof e))return function(o){function r(e,r){var t;return(t=o.call(this,e)||this).domRef=void 0,t.vm=void 0,t.isUnmount=void 0,t.domRef=a().createRef(),t.isUnmount=!1,t.resolveNeoProps=t.resolveNeoProps.bind(t),t}u()(r,o);var n=r.prototype;return n.componentDidMount=function(){var o=this,r=this.resolveNeoProps(),n=r.neoData,s=r.neoMSTData,u=r.neoFunc,c=e="function"==typeof e?new e:e,a=c.data,p=i()(c,l),m=d("function"==typeof a?a():a,n);this.vm=new(f())(t()({},p,{data:function(){return m},props:d(u,t()({},p.props||{},s))})),Object.keys(u).forEach(function(e){o.vm.$props[e]=u[e]}),this.domRef.current&&this.domRef.current.appendChild(this.vm.$mount().$el)},n.componentDidUpdate=function(){var e=this;if(!this.isUnmount){var o=this.resolveNeoProps().neoData;this.vm&&(Object.keys(o).forEach(function(r){e.vm[r]=o[r]}),this.vm.$forceUpdate())}},n.componentWillUnmount=function(){this.isUnmount=!0,this.vm&&this.vm.$destroy()},n.resolveNeoProps=function(){var e=this,o={},r={},t={};return Object.keys(this.props).forEach(function(n){var i,s=e.props[n];"function"==typeof s?o[n]=s:(i=s)&&(i.$treenode||i.$mstObservable||i.$modelType||i.$modelId||"[object Proxy]"===Object.prototype.toString.call(i))?t[n]=s:r[n]=s}),{neoData:r,neoMSTData:t,neoFunc:o}},n.reload=function(){this.vm&&this.vm.reload?this.vm.reload():console.warn("自定义组件暂不支持reload动作。")},n.doAction=function(e,o){this.vm&&this.vm.doAction?this.vm.doAction(e,o):console.warn("自定义组件中不存在 doAction。")},n.render=function(){return a().createElement("div",{ref:this.domRef})},r}(a().Component)}function d(e,o,r){void 0===r&&(r=!0);var t=function(e,o){void 0===o&&(o=!0);var r=e&&e.__super?Object.create(e.__super,{__super:{value:e.__super,writable:!1,enumerable:!1}}):Object.create(Object.prototype);return o&&e&&Object.keys(e).forEach(function(o){return r[o]=e[o]}),r}(e,r);return o&&Object.keys(o).forEach(function(e){return t[e]=o[e]}),t}var v,g,w="[neo-register]";function y(e){return"object"==typeof e&&(e._compiled&&e.components||e.__file&&e.__file.endsWith(".vue"))}function b(e){return y(e)?m(e):e}function h(e,o,r){if(e&&function(e){var o=!1;if(!e)return!1;var r=new e;return r.label?r.tags?Array.isArray(r.tags)?(r.icon||Object.assign(e.prototype,{icon:"https://neo-widgets.bj.bcebos.com/custom-widget.svg"}),o=!0):console.error(w+" / registerNeoEditorModel: 自定义组件注册失败,组件分类(tags)格式异常。"):console.error(w+" / registerNeoEditorModel: 自定义组件注册失败,组件分类(tags)不能为空。"):console.error(w+" / registerNeoEditorModel: 自定义组件注册失败,名称(label)不能为空。"),o}(e)){var n,i,s,u,c,a,p,f,l,m,d=o||(new e).cmpType;d||console.error(w+" / registerNeoEditorModel: 自定义组件注册失败,cmpType 不能为空。");var v=r||{},g=new e;if(Object.assign(e.prototype,t()({},g,{cmpType:d,custom:!0,tags:null!=(n=null!=(i=g.tags)?i:v.tags)?n:["自定义组件"],targetPage:null!=(s=null!=(u=g.targetPage)?u:v.targetPage)?s:["customPage"],exposedToDesigner:null==(c=null!=(a=g.exposedToDesigner)?a:v.exposedToDesigner)||c,namespace:null!=(p=null!=(f=g.namespace)?f:v.namespace)?p:"neo-cmp-cli",enableDuplicate:null==(l=null!=(m=g.enableDuplicate)?m:v.enableDuplicate)||l})),window&&window.postMessage){var y=function(e,o){return window&&!window.NEOEditorCustomModels&&(window.NEOEditorCustomModels={}),window.NEOEditorCustomModels[e]?(console.error(w+"注册自定义组件模型失败,已存在重名插件("+e+")。"),null):(window.NEOEditorCustomModels[e]=o,e)}(d,e);y&&(console.info(w+"触发注册自定义组件模型("+d+")事件"),window.postMessage({type:"neo-model-register-event",eventMsg:w+"注册一个 neo-editor 自定义组件模型",cmpType:d},"*"))}}}function j(e,o){if(e){var r,t={cmpType:"",usage:v.renderer,weight:0};if(o&&(r=o,"String"===Object.prototype.toString.call(r).slice(8,-1))?Object.assign(t,{cmpType:o}):Object.assign(t,o),t&&!t.cmpType)console.error(w+" / registerNeoCmp: 自定义组件注册失败,cmpType 不能为空。");else{t.framework=t.framework?function(e){var o=g.react;if(!e)return o;var r=e.toLowerCase().trim();switch(r){case"jquery":case"jq":r=g.jquery;break;case"vue2":case"vue 2":case"vue2.0":case"vue 2.0":r=g.vue2;break;case"vue":case"vue3":case"vue 3":case"vue3.0":case"vue 3.0":r=g.vue3,console.error(w+" 暂不支持 vue3.0 技术栈。");break;default:r=g.react}return r}(t.framework):y(e)?"vue2":"react",t.usage=function(e){var o=v.renderer;if(!e)return o;var r=e.toLowerCase().trim();switch(r){case"renderer":case"renderers":default:r=v.renderer;break;case"formitem":case"form-item":case"form item":r=v.formitem}return r}(t.usage);var n={react:function(e){return e},vue2:m,vue3:m}[t.framework](e);if({renderer:function(){},formitem:function(){}}[t.usage]){if(window&&window.postMessage){var i=(s=t.cmpType,u={cmpType:t.cmpType,weight:t.weight,usage:t.usage,framework:t.framework,component:n,config:t},window&&!window.NeoCustomCmps&&(window.NeoCustomCmps={}),window.NeoCustomCmps[s]?(console.error(w+" / registerNeoCmp: 自定义组件注册失败,已存在重名渲染器("+s+")。"),null):(window.NeoCustomCmps[s]=u,s));i&&(console.info(w+"触发注册自定义组件("+i+")事件"),window.postMessage({type:"neo-cmp-register-event",eventMsg:w+"注册一个自定义组件",neoRenderer:{cmpType:i,weight:t.weight,usage:t.usage,config:t}},"*"))}}else console.error(w+" / registerNeoCmp: 自定义组件注册失败,暂不支持 "+t.usage+" 组件类型。")}}var s,u}return function(e){e.renderer="renderer",e.formitem="formitem"}(v||(v={})),function(e){e.react="react",e.vue2="vue2",e.vue3="vue3",e.jquery="jquery"}(g||(g={})),o}()});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* neo-register v1.0.
|
|
2
|
+
* neo-register v1.0.6
|
|
3
3
|
* author: wibetter
|
|
4
4
|
* build tool: AKFun
|
|
5
|
-
* build time:
|
|
5
|
+
* build time: Fri Nov 21 2025 11:58:48 GMT+0800 (中国标准时间)
|
|
6
6
|
* build tool info: https://github.com/wibetter/akfun
|
|
7
7
|
*/
|
|
@@ -34,5 +34,5 @@ export declare enum Framework {
|
|
|
34
34
|
}
|
|
35
35
|
export declare function isEditorModel(EditorModelClass: any): boolean;
|
|
36
36
|
export declare function isString(str: any): boolean;
|
|
37
|
-
export declare function isObject(obj: any): boolean;
|
|
38
37
|
export declare function isProxy(obj: any): boolean;
|
|
38
|
+
export declare function autoConvertVueComponent(component: any): any;
|
|
@@ -5,4 +5,4 @@ export declare function createObject(superProps?: {
|
|
|
5
5
|
}, properties?: any): object;
|
|
6
6
|
export declare function cloneObject(target: any, persistOwnProps?: boolean): any;
|
|
7
7
|
export declare function extendObject(target: any, src?: any, persistOwnProps?: boolean): any;
|
|
8
|
-
export declare function isObject(obj: any):
|
|
8
|
+
export declare function isObject(obj: any): boolean;
|