feat:修改插件挂载方式

This commit is contained in:
下羊 2020-03-27 19:31:03 +08:00
parent 89112cea35
commit 6ae17cf5f1
4 changed files with 34 additions and 21 deletions

View File

@ -11,6 +11,7 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
import Debug from 'debug'; import Debug from 'debug';
import { EventEmitter } from 'events'; import { EventEmitter } from 'events';
import store from 'store'; import store from 'store';
import pluginFactory from './pluginFactory';
import * as editorUtils from './utils'; import * as editorUtils from './utils';
var registShortCuts = editorUtils.registShortCuts, var registShortCuts = editorUtils.registShortCuts,
transformToPromise = editorUtils.transformToPromise, transformToPromise = editorUtils.transformToPromise,
@ -76,7 +77,12 @@ var Editor = /*#__PURE__*/function (_EventEmitter) {
_this.locale = void 0; _this.locale = void 0;
_this.hooksFuncs = void 0; _this.hooksFuncs = void 0;
_this.config = config; _this.config = config;
_this.components = components; _this.components = {};
Object.entries(components).forEach(function (_ref) {
var key = _ref[0],
value = _ref[1];
_this.components[key] = pluginFactory(value);
});
_this.utils = _extends({}, editorUtils, {}, utils); _this.utils = _extends({}, editorUtils, {}, utils);
instance = _assertThisInitialized(_this); instance = _assertThisInitialized(_this);
return _this; return _this;
@ -87,11 +93,11 @@ var Editor = /*#__PURE__*/function (_EventEmitter) {
_proto.init = function init() { _proto.init = function init() {
var _this2 = this; var _this2 = this;
var _ref = this.config || {}, var _ref2 = this.config || {},
hooks = _ref.hooks, hooks = _ref2.hooks,
_ref$shortCuts = _ref.shortCuts, _ref2$shortCuts = _ref2.shortCuts,
shortCuts = _ref$shortCuts === void 0 ? [] : _ref$shortCuts, shortCuts = _ref2$shortCuts === void 0 ? [] : _ref2$shortCuts,
lifeCycles = _ref.lifeCycles; lifeCycles = _ref2.lifeCycles;
this.locale = store.get('lowcode-editor-locale') || 'zh-CN'; // this.messages = this.messagesSet[this.locale]; this.locale = store.get('lowcode-editor-locale') || 'zh-CN'; // this.messages = this.messagesSet[this.locale];
// this.i18n = generateI18n(this.locale, this.messages); // this.i18n = generateI18n(this.locale, this.messages);
@ -246,10 +252,10 @@ var Editor = /*#__PURE__*/function (_EventEmitter) {
return; return;
} }
var _ref2 = plugin.props || {}, var _ref3 = plugin.props || {},
visible = _ref2.visible, visible = _ref3.visible,
disabled = _ref2.disabled, disabled = _ref3.disabled,
marked = _ref2.marked; marked = _ref3.marked;
res[plugin.pluginKey] = { res[plugin.pluginKey] = {
visible: typeof visible === 'boolean' ? visible : true, visible: typeof visible === 'boolean' ? visible : true,

View File

@ -11,6 +11,8 @@ import {
PluginSet, PluginSet,
} from './definitions'; } from './definitions';
import pluginFactory from './pluginFactory';
import * as editorUtils from './utils'; import * as editorUtils from './utils';
const { registShortCuts, transformToPromise, unRegistShortCuts } = editorUtils; const { registShortCuts, transformToPromise, unRegistShortCuts } = editorUtils;
@ -92,7 +94,10 @@ export default class Editor extends EventEmitter {
constructor(config: EditorConfig, components: PluginClassSet, utils?: Utils) { constructor(config: EditorConfig, components: PluginClassSet, utils?: Utils) {
super(); super();
this.config = config; this.config = config;
this.components = components; this.components = {};
Object.entries(components).forEach(([key, value]): void => {
this.components[key] = pluginFactory(value);
});
this.utils = { ...editorUtils, ...utils }; this.utils = { ...editorUtils, ...utils };
instance = this; instance = this;
} }

View File

@ -10,6 +10,8 @@
"@ali/lowcode-plugin-save": "0.0.1", "@ali/lowcode-plugin-save": "0.0.1",
"@ali/lowcode-plugin-designer": "0.0.1", "@ali/lowcode-plugin-designer": "0.0.1",
"@ali/lowcode-plugin-components-pane": "0.0.1", "@ali/lowcode-plugin-components-pane": "0.0.1",
"@ali/lowcode-plugin-outline-tree": "0.0.0",
"@ali/lowcode-plugin-settings": "0.0.0",
"@alifd/next": "^1.x", "@alifd/next": "^1.x",
"@alife/theme-lowcode-dark": "^0.1.0", "@alife/theme-lowcode-dark": "^0.1.0",
"@alife/theme-lowcode-light": "^0.1.0", "@alife/theme-lowcode-light": "^0.1.0",

View File

@ -1,19 +1,19 @@
import componentsPane from '@ali/lowcode-plugin-components-pane'; import componentsPane from '@ali/lowcode-plugin-components-pane';
import Settings from '../../../plugin-settings'; import settings from '@ali/lowcode-plugin-settings';
import undoRedo from '@ali/lowcode-plugin-undo-redo'; import undoRedo from '@ali/lowcode-plugin-undo-redo';
import Designer from '../plugins/designer'; import designer from '../plugins/designer';
import logo from '@ali/lowcode-plugin-logo'; import logo from '@ali/lowcode-plugin-logo';
import save from '@ali/lowcode-plugin-save'; import save from '@ali/lowcode-plugin-save';
import OutlineTree from '../../../plugin-outline-tree'; import outlineTree from '@ali/lowcode-plugin-outline-tree';
import { PluginFactory } from '@ali/lowcode-editor-core'; import { PluginFactory } from '@ali/lowcode-editor-core';
export default { export default {
logo: PluginFactory(logo), logo,
save: PluginFactory(save), save,
designer: PluginFactory(Designer), designer,
settings: PluginFactory(Settings), settings,
outlineTree: PluginFactory(OutlineTree), outlineTree,
undoRedo: PluginFactory(undoRedo), undoRedo,
componentsPane: PluginFactory(componentsPane) componentsPane
}; };