neo-register 1.0.7 → 1.0.9
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/frameworkFactory/vueFactory.d.ts +57 -0
- package/dist/function/registerNeoEditorModel.d.ts +0 -1
- package/dist/index.esm.js +132 -133
- 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/main.d.ts +1 -2
- package/dist/utils/index.d.ts +0 -1
- package/package.json +4 -4
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 将 vue2.0 自定义组件包裹成一个 react组件
|
|
3
|
+
*/
|
|
4
|
+
import React from 'react';
|
|
5
|
+
interface VueFactoryProps {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}
|
|
8
|
+
interface VueFactoryState {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}
|
|
11
|
+
export declare function createVue2Component(vueObj: any): {
|
|
12
|
+
new (props: VueFactoryProps, context: any): {
|
|
13
|
+
domRef: React.RefObject<HTMLDivElement>;
|
|
14
|
+
vm: any;
|
|
15
|
+
isUnmount: boolean;
|
|
16
|
+
componentDidMount(): void;
|
|
17
|
+
componentDidUpdate(): void;
|
|
18
|
+
componentWillUnmount(): void;
|
|
19
|
+
resolveNeoProps(): {
|
|
20
|
+
neoData: any;
|
|
21
|
+
neoMSTData: any;
|
|
22
|
+
neoFunc: any;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* reload动作处理
|
|
26
|
+
*/
|
|
27
|
+
reload(): void;
|
|
28
|
+
/**
|
|
29
|
+
* 事件动作处理:
|
|
30
|
+
* 在这里设置自定义组件对外暴露的动作,其他组件可以通过组件动作触发自定义组件的对应动作
|
|
31
|
+
*/
|
|
32
|
+
doAction(action: any, args: object): void;
|
|
33
|
+
render(): React.JSX.Element;
|
|
34
|
+
context: any;
|
|
35
|
+
setState<K extends string | number>(state: VueFactoryState | ((prevState: Readonly<VueFactoryState>, props: Readonly<VueFactoryProps>) => VueFactoryState | Pick<VueFactoryState, K> | null) | Pick<VueFactoryState, K> | null, callback?: (() => void) | undefined): void;
|
|
36
|
+
forceUpdate(callback?: (() => void) | undefined): void;
|
|
37
|
+
readonly props: Readonly<VueFactoryProps> & Readonly<{
|
|
38
|
+
children?: React.ReactNode;
|
|
39
|
+
}>;
|
|
40
|
+
state: Readonly<VueFactoryState>;
|
|
41
|
+
refs: {
|
|
42
|
+
[key: string]: React.ReactInstance;
|
|
43
|
+
};
|
|
44
|
+
shouldComponentUpdate?(nextProps: Readonly<VueFactoryProps>, nextState: Readonly<VueFactoryState>, nextContext: any): boolean;
|
|
45
|
+
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
|
|
46
|
+
getSnapshotBeforeUpdate?(prevProps: Readonly<VueFactoryProps>, prevState: Readonly<VueFactoryState>): any;
|
|
47
|
+
componentWillMount?(): void;
|
|
48
|
+
UNSAFE_componentWillMount?(): void;
|
|
49
|
+
componentWillReceiveProps?(nextProps: Readonly<VueFactoryProps>, nextContext: any): void;
|
|
50
|
+
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<VueFactoryProps>, nextContext: any): void;
|
|
51
|
+
componentWillUpdate?(nextProps: Readonly<VueFactoryProps>, nextState: Readonly<VueFactoryState>, nextContext: any): void;
|
|
52
|
+
UNSAFE_componentWillUpdate?(nextProps: Readonly<VueFactoryProps>, nextState: Readonly<VueFactoryState>, nextContext: any): void;
|
|
53
|
+
};
|
|
54
|
+
contextType?: React.Context<any> | undefined;
|
|
55
|
+
} | undefined;
|
|
56
|
+
export declare function autoConvertVueComponent(component: any): any;
|
|
57
|
+
export {};
|
package/dist/index.esm.js
CHANGED
|
@@ -1,123 +1,6 @@
|
|
|
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
|
-
|
|
121
4
|
// 方便取值的时候能够把上层的取到,但是获取的时候不会全部把所有的数据获取到。
|
|
122
5
|
function cloneObject(target, persistOwnProps = true) {
|
|
123
6
|
const obj = target && target.__super
|
|
@@ -242,17 +125,14 @@ function isEditorModel(EditorModelClass) {
|
|
|
242
125
|
if (!_editorPluginObj.label) {
|
|
243
126
|
console.error(`${consoleTag} / registerNeoEditorModel: 自定义组件注册失败,名称(label)不能为空。`);
|
|
244
127
|
}
|
|
245
|
-
else if (!_editorPluginObj.tags) {
|
|
246
|
-
console.error(`${consoleTag} / registerNeoEditorModel: 自定义组件注册失败,组件分类(tags)不能为空。`);
|
|
247
|
-
}
|
|
248
|
-
else if (!Array.isArray(_editorPluginObj.tags)) {
|
|
128
|
+
else if (_editorPluginObj.tags && !Array.isArray(_editorPluginObj.tags)) {
|
|
249
129
|
console.error(`${consoleTag} / registerNeoEditorModel: 自定义组件注册失败,组件分类(tags)格式异常。`);
|
|
250
130
|
}
|
|
251
131
|
else {
|
|
252
132
|
// 1.设置一个默认 icon
|
|
253
|
-
if (!_editorPluginObj.
|
|
133
|
+
if (!_editorPluginObj.iconSrc) {
|
|
254
134
|
Object.assign(EditorModelClass.prototype, {
|
|
255
|
-
|
|
135
|
+
iconSrc: 'https://neo-widgets.bj.bcebos.com/custom-widget.svg',
|
|
256
136
|
});
|
|
257
137
|
}
|
|
258
138
|
_isEditorModel = true;
|
|
@@ -273,19 +153,11 @@ function isProxy(obj) {
|
|
|
273
153
|
obj.$modelId);
|
|
274
154
|
return (hasMSTProperties || Object.prototype.toString.call(obj) === '[object Proxy]');
|
|
275
155
|
}
|
|
276
|
-
// 自动识别并转换 vue 组件
|
|
277
|
-
function autoConvertVueComponent(component) {
|
|
278
|
-
if (isVueComponent(component)) {
|
|
279
|
-
return createVue2Component(component);
|
|
280
|
-
}
|
|
281
|
-
return component;
|
|
282
|
-
}
|
|
283
156
|
|
|
284
157
|
/**
|
|
285
158
|
* registerNeoEditorModel: 注册 neo-editor 自定义组件模型
|
|
286
159
|
*
|
|
287
160
|
* targetPage 取值说明
|
|
288
|
-
* all: 页面
|
|
289
161
|
* all: 1 全页面
|
|
290
162
|
* indexPage: 2 首页
|
|
291
163
|
* entityListPage: 3 实体列表页
|
|
@@ -307,8 +179,11 @@ function registerNeoEditorModel(curEditorModel, cmpType, options) {
|
|
|
307
179
|
cmpType: curCmpType,
|
|
308
180
|
custom: true,
|
|
309
181
|
tags: curEditorModelObj.tags ?? curOptions.tags ?? ['自定义组件'],
|
|
310
|
-
targetPage: curEditorModelObj.targetPage ??
|
|
311
|
-
|
|
182
|
+
targetPage: curEditorModelObj.targetPage ??
|
|
183
|
+
curOptions.targetPage ?? ['customPage'],
|
|
184
|
+
exposedToDesigner: curEditorModelObj.exposedToDesigner ??
|
|
185
|
+
curOptions.exposedToDesigner ??
|
|
186
|
+
true,
|
|
312
187
|
namespace: curEditorModelObj.namespace ?? curOptions.namespace ?? 'neo-cmp-cli',
|
|
313
188
|
enableDuplicate: curEditorModelObj.enableDuplicate ?? curOptions.enableDuplicate ?? true, // 默认在设计器中允许重复插入
|
|
314
189
|
});
|
|
@@ -341,6 +216,130 @@ function AddCustomEditorModel(cmpType, model) {
|
|
|
341
216
|
return null;
|
|
342
217
|
}
|
|
343
218
|
|
|
219
|
+
/**
|
|
220
|
+
* 将 vue2.0 自定义组件包裹成一个 react组件
|
|
221
|
+
*/
|
|
222
|
+
function createVue2Component(vueObj) {
|
|
223
|
+
if (!vueObj || (typeof vueObj !== 'function' && typeof vueObj !== 'object')) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
class VueFactory extends React.Component {
|
|
227
|
+
domRef;
|
|
228
|
+
vm;
|
|
229
|
+
isUnmount;
|
|
230
|
+
// 指定 contextType 读取当前的 scope context。
|
|
231
|
+
// React 会往上找到最近的 scope Provider,然后使用它的值。
|
|
232
|
+
// static contextType = ScopedContext; // 待支持
|
|
233
|
+
constructor(props, context) {
|
|
234
|
+
super(props);
|
|
235
|
+
this.domRef = React.createRef();
|
|
236
|
+
this.isUnmount = false;
|
|
237
|
+
/*
|
|
238
|
+
// 待支持(自定义组件支持事件动作)
|
|
239
|
+
const scoped = context;
|
|
240
|
+
scoped.registerComponent(this);
|
|
241
|
+
*/
|
|
242
|
+
this.resolveNeoProps = this.resolveNeoProps.bind(this);
|
|
243
|
+
}
|
|
244
|
+
componentDidMount() {
|
|
245
|
+
const { neoData, neoMSTData, neoFunc } = this.resolveNeoProps();
|
|
246
|
+
const { data, ...rest } = (vueObj =
|
|
247
|
+
typeof vueObj === 'function' ? new vueObj() : vueObj);
|
|
248
|
+
const vueData = typeof data === 'function' ? data() : data;
|
|
249
|
+
const curVueData = extendObject(vueData, neoData);
|
|
250
|
+
// 传入的Vue属性
|
|
251
|
+
this.vm = new Vue({
|
|
252
|
+
...rest,
|
|
253
|
+
data: () => curVueData,
|
|
254
|
+
props: extendObject(neoFunc, {
|
|
255
|
+
...(rest.props || {}),
|
|
256
|
+
...neoMSTData,
|
|
257
|
+
}),
|
|
258
|
+
});
|
|
259
|
+
Object.keys(neoFunc).forEach((key) => {
|
|
260
|
+
this.vm.$props[key] = neoFunc[key];
|
|
261
|
+
});
|
|
262
|
+
if (this.domRef.current) {
|
|
263
|
+
this.domRef.current.appendChild(this.vm.$mount().$el);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
componentDidUpdate() {
|
|
267
|
+
if (!this.isUnmount) {
|
|
268
|
+
const { neoData } = this.resolveNeoProps();
|
|
269
|
+
if (this.vm) {
|
|
270
|
+
Object.keys(neoData).forEach((key) => {
|
|
271
|
+
this.vm[key] = neoData[key];
|
|
272
|
+
});
|
|
273
|
+
this.vm.$forceUpdate();
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
componentWillUnmount() {
|
|
278
|
+
this.isUnmount = true;
|
|
279
|
+
/*
|
|
280
|
+
// 待支持
|
|
281
|
+
const scoped = this.context;
|
|
282
|
+
scoped.unRegisterComponent(this);
|
|
283
|
+
*/
|
|
284
|
+
if (this.vm) {
|
|
285
|
+
this.vm.$destroy();
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
resolveNeoProps() {
|
|
289
|
+
let neoFunc = {};
|
|
290
|
+
let neoData = {};
|
|
291
|
+
let neoMSTData = {};
|
|
292
|
+
Object.keys(this.props).forEach((key) => {
|
|
293
|
+
const value = this.props[key];
|
|
294
|
+
if (typeof value === 'function') {
|
|
295
|
+
neoFunc[key] = value;
|
|
296
|
+
}
|
|
297
|
+
else if (isProxy(value)) {
|
|
298
|
+
neoMSTData[key] = value;
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
neoData[key] = value;
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
return { neoData, neoMSTData, neoFunc };
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* reload动作处理
|
|
308
|
+
*/
|
|
309
|
+
reload() {
|
|
310
|
+
if (this.vm && this.vm.reload) {
|
|
311
|
+
this.vm.reload();
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
console.warn('自定义组件暂不支持reload动作。');
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* 事件动作处理:
|
|
319
|
+
* 在这里设置自定义组件对外暴露的动作,其他组件可以通过组件动作触发自定义组件的对应动作
|
|
320
|
+
*/
|
|
321
|
+
doAction(action, args) {
|
|
322
|
+
if (this.vm && this.vm.doAction) {
|
|
323
|
+
this.vm.doAction(action, args);
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
console.warn('自定义组件中不存在 doAction。');
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
render() {
|
|
330
|
+
return React.createElement("div", { ref: this.domRef });
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return VueFactory;
|
|
334
|
+
}
|
|
335
|
+
// 自动识别并转换 vue 组件
|
|
336
|
+
function autoConvertVueComponent(component) {
|
|
337
|
+
if (isVueComponent(component)) {
|
|
338
|
+
return createVue2Component(component);
|
|
339
|
+
}
|
|
340
|
+
return component;
|
|
341
|
+
}
|
|
342
|
+
|
|
344
343
|
/**
|
|
345
344
|
* registerNeoCmp: 根据type类型注册 neo 自定义组件
|
|
346
345
|
*【方法参数说明】
|
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(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 r="[neo-register]";function n(e){return"object"==typeof e&&(e._compiled&&e.components||e.__file&&e.__file.endsWith(".vue"))}var s,i;function c(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)?console.error(`${r} / registerNeoEditorModel: 自定义组件注册失败,组件分类(tags)格式异常。`):(t.iconSrc||Object.assign(e.prototype,{iconSrc:"https://neo-widgets.bj.bcebos.com/custom-widget.svg"}),o=!0):console.error(`${r} / registerNeoEditorModel: 自定义组件注册失败,名称(label)不能为空。`),o}(e)){const n=o||(new e).cmpType;n||console.error(`${r} / registerNeoEditorModel: 自定义组件注册失败,cmpType 不能为空。`);const s=t||{},i=new e;if(Object.assign(e.prototype,{...i,cmpType:n,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(`${r}注册自定义组件模型失败,已存在重名插件(${e})。`);return null}(n,e);o&&(console.info(`${r}触发注册自定义组件模型(${n})事件`),window.postMessage({type:"neo-model-register-event",eventMsg:`${r}注册一个 neo-editor 自定义组件模型`,cmpType:n},"*"))}}}function a(r){if(r&&("function"==typeof r||"object"==typeof r)){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}=r="function"==typeof r?new r:r,a=t("function"==typeof i?i():i,e);this.vm=new o({...c,data:()=>a,props:t(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];var s;"function"==typeof n?e[r]=n:(s=n)&&(s.$treenode||s.$mstObservable||s.$modelType||s.$modelId||"[object Proxy]"===Object.prototype.toString.call(s))?t[r]=n:o[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 u(e){return n(e)?a(e):e}function m(e,o){if(!e)return;const t={cmpType:"",usage:s.renderer,weight:0};var c;if(o&&(c=o,"String"===Object.prototype.toString.call(c).slice(8,-1))?Object.assign(t,{cmpType:o}):Object.assign(t,o),t&&!t.cmpType)console.error(`${r} / registerNeoCmp: 自定义组件注册失败,cmpType 不能为空。`);else{t.framework=t.framework?function(e){let o=i.react;if(!e)return o;let t=e.toLowerCase().trim();switch(t){case"jquery":case"jq":t=i.jquery;break;case"vue2":case"vue 2":case"vue2.0":case"vue 2.0":t=i.vue2;break;case"vue":case"vue3":case"vue 3":case"vue3.0":case"vue 3.0":t=i.vue3,console.error(`${r} 暂不支持 vue3.0 技术栈。`);break;default:t=i.react}return t}(t.framework):n(e)?"vue2":"react",t.usage=function(e){let o=s.renderer;if(!e)return o;let t=e.toLowerCase().trim();switch(t){case"renderer":case"renderers":default:t=s.renderer;break;case"formitem":case"form-item":case"form item":t=s.formitem}return t}(t.usage);const o={renderer:()=>{},formitem:()=>{}},c={react:e=>e,vue2:a,vue3:a}[t.framework](e);if(o[t.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(`${r} / registerNeoCmp: 自定义组件注册失败,已存在重名渲染器(${e})。`);return null}(t.cmpType,{cmpType:t.cmpType,weight:t.weight,usage:t.usage,framework:t.framework,component:c,config:t});e&&(console.info(`${r}触发注册自定义组件(${e})事件`),window.postMessage({type:"neo-cmp-register-event",eventMsg:`${r}注册一个自定义组件`,neoRenderer:{cmpType:e,weight:t.weight,usage:t.usage,config:t}},"*"))}}else console.error(`${r} / registerNeoCmp: 自定义组件注册失败,暂不支持 ${t.usage} 组件类型。`)}}!function(e){e.renderer="renderer",e.formitem="formitem"}(s||(s={})),function(e){e.react="react",e.vue2="vue2",e.vue3="vue3",e.jquery="jquery"}(i||(i={}));export{u as autoConvertVueComponent,a as createVue2Component,m as registerNeoCmp,c 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,{autoConvertVueComponent: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 h},createVue2Component:function(){return b},registerNeoCmp:function(){return j},registerNeoEditorModel:function(){return a}});var r=require("@babel/runtime/helpers/extends"),t=e.n(r);function n(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 i,s,u="[neo-register]";function c(e){return"object"==typeof e&&(e._compiled&&e.components||e.__file&&e.__file.endsWith(".vue"))}function a(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)?console.error(u+" / registerNeoEditorModel: 自定义组件注册失败,组件分类(tags)格式异常。"):(r.iconSrc||Object.assign(e.prototype,{iconSrc:"https://neo-widgets.bj.bcebos.com/custom-widget.svg"}),o=!0):console.error(u+" / registerNeoEditorModel: 自定义组件注册失败,名称(label)不能为空。"),o}(e)){var n,i,s,c,a,p,f,l,m,d,v=o||(new e).cmpType;v||console.error(u+" / registerNeoEditorModel: 自定义组件注册失败,cmpType 不能为空。");var g=r||{},w=new e;if(Object.assign(e.prototype,t()({},w,{cmpType:v,custom:!0,tags:null!=(n=null!=(i=w.tags)?i:g.tags)?n:["自定义组件"],targetPage:null!=(s=null!=(c=w.targetPage)?c:g.targetPage)?s:["customPage"],exposedToDesigner:null==(a=null!=(p=w.exposedToDesigner)?p:g.exposedToDesigner)||a,namespace:null!=(f=null!=(l=w.namespace)?l:g.namespace)?f:"neo-cmp-cli",enableDuplicate:null==(m=null!=(d=w.enableDuplicate)?d:g.enableDuplicate)||m})),window&&window.postMessage){var y=function(e,o){return window&&!window.NEOEditorCustomModels&&(window.NEOEditorCustomModels={}),window.NEOEditorCustomModels[e]?(console.error(u+"注册自定义组件模型失败,已存在重名插件("+e+")。"),null):(window.NEOEditorCustomModels[e]=o,e)}(v,e);y&&(console.info(u+"触发注册自定义组件模型("+v+")事件"),window.postMessage({type:"neo-model-register-event",eventMsg:u+"注册一个 neo-editor 自定义组件模型",cmpType:v},"*"))}}}!function(e){e.renderer="renderer",e.formitem="formitem"}(i||(i={})),function(e){e.react="react",e.vue2="vue2",e.vue3="vue3",e.jquery="jquery"}(s||(s={}));var p=require("@babel/runtime/helpers/objectWithoutPropertiesLoose"),f=e.n(p),l=require("@babel/runtime/helpers/inheritsLoose"),m=e.n(l),d=require("react"),v=e.n(d),g=require("vue"),w=e.n(g),y=["data"];function b(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=v().createRef(),t.isUnmount=!1,t.resolveNeoProps=t.resolveNeoProps.bind(t),t}m()(r,o);var i=r.prototype;return i.componentDidMount=function(){var o=this,r=this.resolveNeoProps(),i=r.neoData,s=r.neoMSTData,u=r.neoFunc,c=e="function"==typeof e?new e:e,a=c.data,p=f()(c,y),l=n("function"==typeof a?a():a,i);this.vm=new(w())(t()({},p,{data:function(){return l},props:n(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)},i.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())}},i.componentWillUnmount=function(){this.isUnmount=!0,this.vm&&this.vm.$destroy()},i.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}},i.reload=function(){this.vm&&this.vm.reload?this.vm.reload():console.warn("自定义组件暂不支持reload动作。")},i.doAction=function(e,o){this.vm&&this.vm.doAction?this.vm.doAction(e,o):console.warn("自定义组件中不存在 doAction。")},i.render=function(){return v().createElement("div",{ref:this.domRef})},r}(v().Component)}function h(e){return c(e)?b(e):e}function j(e,o){if(e){var r,t={cmpType:"",usage:i.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(u+" / registerNeoCmp: 自定义组件注册失败,cmpType 不能为空。");else{t.framework=t.framework?function(e){var o=s.react;if(!e)return o;var r=e.toLowerCase().trim();switch(r){case"jquery":case"jq":r=s.jquery;break;case"vue2":case"vue 2":case"vue2.0":case"vue 2.0":r=s.vue2;break;case"vue":case"vue3":case"vue 3":case"vue3.0":case"vue 3.0":r=s.vue3,console.error(u+" 暂不支持 vue3.0 技术栈。");break;default:r=s.react}return r}(t.framework):c(e)?"vue2":"react",t.usage=function(e){var o=i.renderer;if(!e)return o;var r=e.toLowerCase().trim();switch(r){case"renderer":case"renderers":default:r=i.renderer;break;case"formitem":case"form-item":case"form item":r=i.formitem}return r}(t.usage);var n={react:function(e){return e},vue2:b,vue3:b}[t.framework](e);if({renderer:function(){},formitem:function(){}}[t.usage]){if(window&&window.postMessage){var a=(p=t.cmpType,f={cmpType:t.cmpType,weight:t.weight,usage:t.usage,framework:t.framework,component:n,config:t},window&&!window.NeoCustomCmps&&(window.NeoCustomCmps={}),window.NeoCustomCmps[p]?(console.error(u+" / registerNeoCmp: 自定义组件注册失败,已存在重名渲染器("+p+")。"),null):(window.NeoCustomCmps[p]=f,p));a&&(console.info(u+"触发注册自定义组件("+a+")事件"),window.postMessage({type:"neo-cmp-register-event",eventMsg:u+"注册一个自定义组件",neoRenderer:{cmpType:a,weight:t.weight,usage:t.usage,config:t}},"*"))}}else console.error(u+" / registerNeoCmp: 自定义组件注册失败,暂不支持 "+t.usage+" 组件类型。")}}var p,f}return o}()});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* neo-register v1.0.
|
|
2
|
+
* neo-register v1.0.7
|
|
3
3
|
* author: wibetter
|
|
4
4
|
* build tool: AKFun
|
|
5
|
-
* build time: Fri Nov 21 2025
|
|
5
|
+
* build time: Fri Nov 21 2025 15:04:52 GMT+0800 (中国标准时间)
|
|
6
6
|
* build tool info: https://github.com/wibetter/akfun
|
|
7
7
|
*/
|
package/dist/main.d.ts
CHANGED
|
@@ -7,5 +7,4 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export { registerNeoEditorModel } from './function/registerNeoEditorModel';
|
|
9
9
|
export { registerNeoCmp } from './function/registerNeoCmp';
|
|
10
|
-
export { createVue2Component } from './frameworkFactory/vueFactory';
|
|
11
|
-
export { autoConvertVueComponent } from './utils';
|
|
10
|
+
export { createVue2Component, autoConvertVueComponent } from './frameworkFactory/vueFactory';
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -35,4 +35,3 @@ export declare enum Framework {
|
|
|
35
35
|
export declare function isEditorModel(EditorModelClass: any): boolean;
|
|
36
36
|
export declare function isString(str: any): boolean;
|
|
37
37
|
export declare function isProxy(obj: any): boolean;
|
|
38
|
-
export declare function autoConvertVueComponent(component: any): any;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "neo-register",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.9",
|
|
4
|
+
"description": "Neo 自定义组件注册器(支持 react 和 vue2.0 技术栈),主要用于注册 Neo 自定义组件和自定义组件模型。",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"neo自定义组件注册器",
|
|
7
7
|
"neo自定义组件",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
},
|
|
35
35
|
"repository": {
|
|
36
36
|
"type": "git",
|
|
37
|
-
"url": "https://
|
|
37
|
+
"url": "https://github.com/xsy-neoui/neo-register.git"
|
|
38
38
|
},
|
|
39
39
|
"bugs": {
|
|
40
|
-
"url": "https://github.com/
|
|
40
|
+
"url": "https://github.com/xsy-neoui/neo-register/issues"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"vue": "^2.6.14"
|