This commit is contained in:
kangwei 2020-04-16 03:39:07 +08:00
parent a064b93aff
commit 688d86956d
29 changed files with 178 additions and 237 deletions

View File

@ -13,7 +13,7 @@
"build": "lerna run build --stream", "build": "lerna run build --stream",
"clean": "rm -rf ./packages/*/lib ./packages/*/es ./packages/*/dist ./packages/*/build", "clean": "rm -rf ./packages/*/lib ./packages/*/es ./packages/*/dist ./packages/*/build",
"commit": "git-cz", "commit": "git-cz",
"pub": "lerna publish", "pub": "lerna publish --cd-version patch",
"setup": "./scripts/setup.sh", "setup": "./scripts/setup.sh",
"start": "lerna exec --scope @ali/lowcode-vision-polyfill -- npm start", "start": "lerna exec --scope @ali/lowcode-vision-polyfill -- npm start",
"test": "lerna run test --stream", "test": "lerna run test --stream",

View File

@ -124,11 +124,11 @@ export class Designer {
selectionDispose(); selectionDispose();
selectionDispose = undefined; selectionDispose = undefined;
} }
this.postEvent('selection-change', this.currentSelection); this.postEvent('selection.change', this.currentSelection);
if (this.currentSelection) { if (this.currentSelection) {
const currentSelection = this.currentSelection; const currentSelection = this.currentSelection;
selectionDispose = currentSelection.onSelectionChange(() => { selectionDispose = currentSelection.onSelectionChange(() => {
this.postEvent('selection-change', currentSelection); this.postEvent('selection.change', currentSelection);
}); });
} }
}; };
@ -147,9 +147,9 @@ export class Designer {
} }
}; };
this.project.onCurrentDocumentChange(() => { this.project.onCurrentDocumentChange(() => {
this.postEvent('current-document-change', this.currentDocument); this.postEvent('current-document.change', this.currentDocument);
this.postEvent('selection-change', this.currentSelection); this.postEvent('selection.change', this.currentSelection);
this.postEvent('history-change', this.currentHistory); this.postEvent('history.change', this.currentHistory);
setupSelection(); setupSelection();
setupHistory(); setupHistory();
}); });

View File

@ -142,7 +142,7 @@ export class Project {
doc.suspense(); doc.suspense();
} }
}); });
this.emitter.emit('current-document-change', actived); this.emitter.emit('current-document.change', actived);
} }
closeOthers(opened: DocumentModel) { closeOthers(opened: DocumentModel) {
@ -154,9 +154,9 @@ export class Project {
} }
onCurrentDocumentChange(fn: (doc: DocumentModel) => void): () => void { onCurrentDocumentChange(fn: (doc: DocumentModel) => void): () => void {
this.emitter.on('current-document-change', fn); this.emitter.on('current-document.change', fn);
return () => { return () => {
this.emitter.removeListener('current-document-change', fn); this.emitter.removeListener('current-document.change', fn);
}; };
} }
// 通知标记删除,需要告知服务端 // 通知标记删除,需要告知服务端

View File

@ -21,6 +21,7 @@
"author": "xiayang.xy", "author": "xiayang.xy",
"dependencies": { "dependencies": {
"@alifd/next": "1.x", "@alifd/next": "1.x",
"@ali/lowcode-globals": "^0.9.1",
"debug": "^4.1.1", "debug": "^4.1.1",
"events": "^3.1.0", "events": "^3.1.0",
"intl-messageformat": "^8.3.1", "intl-messageformat": "^8.3.1",
@ -31,6 +32,7 @@
"whatwg-fetch": "^3.0.0" "whatwg-fetch": "^3.0.0"
}, },
"devDependencies": { "devDependencies": {
"@types/store": "^2.0.2",
"@alib/build-scripts": "^0.1.3", "@alib/build-scripts": "^0.1.3",
"@types/lodash": "^4.14.149", "@types/lodash": "^4.14.149",
"@types/react": "^16.9.13", "@types/react": "^16.9.13",

View File

@ -0,0 +1,45 @@
import store from 'store';
declare global {
interface Window {
__isDebug?: boolean;
__newFunc?: (funcStr: string) => (...args: any[]) => any;
}
}
// 根据url参数设置debug选项
const debugRegRes = /_?debug=(.*?)(&|$)/.exec(location.search);
if (debugRegRes && debugRegRes[1]) {
// eslint-disable-next-line no-underscore-dangle
window.__isDebug = true;
// @ts-ignore
store.storage.write('debug', debugRegRes[1] === 'true' ? '*' : debugRegRes[1]);
} else {
// eslint-disable-next-line no-underscore-dangle
window.__isDebug = false;
store.remove('debug');
}
// 重要用于矫正画布执行new Function的window对象上下文
// eslint-disable-next-line no-underscore-dangle
window.__newFunc = (funContext: string): ((...args: any[]) => any) => {
// eslint-disable-next-line no-new-func
return new Function(funContext) as (...args: any[]) => any;
};
// 关闭浏览器前提醒,只有产生过交互才会生效
window.onbeforeunload = function(e: Event): string | void {
const ev = e || window.event;
// 本地调试不生效
if (location.href.indexOf('localhost') > 0) {
return;
}
const msg = '您确定要离开此页面吗?';
ev.cancelBubble = true;
ev.returnValue = true;
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
return msg;
};

View File

@ -1,6 +1,6 @@
import Debug from 'debug';
import { EventEmitter } from 'events'; import { EventEmitter } from 'events';
import store from 'store'; import store from 'store';
import { IocContext, RegisterOptions } from '@ali/lowcode-globals';
import { import {
EditorConfig, EditorConfig,
HooksConfig, HooksConfig,
@ -17,58 +17,21 @@ import * as editorUtils from './utils';
const { registShortCuts, transformToPromise, unRegistShortCuts } = editorUtils; const { registShortCuts, transformToPromise, unRegistShortCuts } = editorUtils;
declare global {
interface Window {
__isDebug?: boolean;
__newFunc?: (funcStr: string) => (...args: any[]) => any;
}
}
// 根据url参数设置debug选项
const debugRegRes = /_?debug=(.*?)(&|$)/.exec(location.search);
if (debugRegRes && debugRegRes[1]) {
// eslint-disable-next-line no-underscore-dangle
window.__isDebug = true;
store.storage.write('debug', debugRegRes[1] === 'true' ? '*' : debugRegRes[1]);
} else {
// eslint-disable-next-line no-underscore-dangle
window.__isDebug = false;
store.remove('debug');
}
// 重要用于矫正画布执行new Function的window对象上下文
// eslint-disable-next-line no-underscore-dangle
window.__newFunc = (funContext: string): ((...args: any[]) => any) => {
// eslint-disable-next-line no-new-func
return new Function(funContext) as (...args: any[]) => any;
};
// 关闭浏览器前提醒,只有产生过交互才会生效
window.onbeforeunload = function(e: Event): string | void {
const ev = e || window.event;
// 本地调试不生效
if (location.href.indexOf('localhost') > 0) {
return;
}
const msg = '您确定要离开此页面吗?';
ev.cancelBubble = true;
ev.returnValue = true;
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
return msg;
};
let instance: Editor; let instance: Editor;
const debug = Debug('editor');
EventEmitter.defaultMaxListeners = 100; EventEmitter.defaultMaxListeners = 100;
export interface HooksFuncs { export interface HooksFuncs {
[idx: number]: (msg: string, handler: (...args: []) => void) => void; [idx: number]: (msg: string, handler: (...args: []) => void) => void;
} }
export type KeyType = Function | Symbol | string;
export type ClassType = Function | (new (...args: any[]) => any);
export interface GetOptions {
forceNew?: boolean;
sourceCls?: ClassType;
}
export default class Editor extends EventEmitter { export default class Editor extends EventEmitter {
static getInstance = (config: EditorConfig, components: PluginClassSet, utils?: Utils): Editor => { static getInstance = (config: EditorConfig, components: PluginClassSet, utils?: Utils): Editor => {
if (!instance) { if (!instance) {
@ -89,6 +52,10 @@ export default class Editor extends EventEmitter {
} }
readonly utils: Utils; readonly utils: Utils;
/**
* Ioc Container
*/
readonly context = new IocContext();
pluginStatus?: PluginStatusSet; pluginStatus?: PluginStatusSet;
@ -100,35 +67,32 @@ export default class Editor extends EventEmitter {
constructor(readonly config: EditorConfig = {}, readonly componentsMap: PluginClassSet = {}, utils?: Utils) { constructor(readonly config: EditorConfig = {}, readonly componentsMap: PluginClassSet = {}, utils?: Utils) {
super(); super();
this.utils = ({ ...editorUtils, ...utils } as any); this.utils = { ...editorUtils, ...utils } as any;
instance = this; instance = this;
} }
init(): Promise<any> { async init(): Promise<any> {
const { hooks, shortCuts = [], lifeCycles } = this.config || {}; const { hooks, shortCuts = [], lifeCycles } = this.config || {};
this.locale = store.get('lowcode-editor-locale') || 'zh-CN'; this.locale = store.get('lowcode-editor-locale') || 'zh-CN';
// this.messages = this.messagesSet[this.locale];
// this.i18n = generateI18n(this.locale, this.messages);
this.pluginStatus = this.initPluginStatus(); this.pluginStatus = this.initPluginStatus();
this.initHooks(hooks || []); this.initHooks(hooks || []);
this.emit('editor.beforeInit'); this.emit('editor.beforeInit');
const init = (lifeCycles && lifeCycles.init) || ((): void => {}); const init = (lifeCycles && lifeCycles.init) || ((): void => {});
// 用户可以通过设置extensions.init自定义初始化流程 // 用户可以通过设置extensions.init自定义初始化流程
return transformToPromise(init(this)) try {
.then((): boolean => { await transformToPromise(init(this));
// 注册快捷键 // 注册快捷键
registShortCuts(shortCuts, this); registShortCuts(shortCuts, this);
this.emit('editor.afterInit'); this.emit('editor.afterInit');
return true; return true;
}) }
.catch((err): void => { catch (err) {
console.error(err); console.error(err);
}); }
} }
destroy(): void { destroy(): void {
debug('destroy');
try { try {
const { hooks = [], shortCuts = [], lifeCycles = {} } = this.config; const { hooks = [], shortCuts = [], lifeCycles = {} } = this.config;
unRegistShortCuts(shortCuts); unRegistShortCuts(shortCuts);
@ -141,23 +105,20 @@ export default class Editor extends EventEmitter {
} }
} }
get(key: string): any { get<T = undefined, KeyOrType = any>(keyOrType: KeyOrType, opt?: GetOptions) {
return (this as any)[key]; return this.context.get<T, KeyOrType>(keyOrType, opt);
} }
set(key: string | object, val: any): void { has(keyOrType: KeyType): boolean {
if (typeof key === 'string') { return this.context.has(keyOrType);
if (['init', 'destroy', 'get', 'set', 'batchOn', 'batchOff', 'batchOnce'].includes(key)) {
console.error('init, destroy, get, set, batchOn, batchOff, batchOnce is private attribute');
return;
} }
// FIXME! set to plugins, not to this
(this as any)[key] = val; set(key: KeyType, data: any): void {
} else if (typeof key === 'object') { this.context.register(data, key);
Object.keys(key).forEach((item): void => {
(this as any)[item] = (key as any)[item];
});
} }
register(data: any, key?: KeyType, options?: RegisterOptions): void {
this.context.register(data, key, options);
} }
batchOn(events: string[], lisenter: (...args: any[]) => void): void { batchOn(events: string[], lisenter: (...args: any[]) => void): void {

View File

@ -30,6 +30,7 @@
"@recore/obx": "^1.0.8", "@recore/obx": "^1.0.8",
"@recore/obx-react": "^1.0.7", "@recore/obx-react": "^1.0.7",
"classnames": "^2.2.6", "classnames": "^2.2.6",
"power-di": "^2.2.4",
"react": "^16", "react": "^16",
"react-dom": "^16.7.0" "react-dom": "^16.7.0"
}, },

View File

@ -1,2 +1,3 @@
export * from './setter'; export * from './setter';
export * from './transducer'; export * from './transducer';
export * from './ioc-context';

View File

@ -0,0 +1,4 @@
import { IocContext } from 'power-di';
export * from 'power-di';
export const globalContext = IocContext.DefaultInstance;

View File

@ -23,7 +23,8 @@
"@ali/iceluna-addon-component-list": "^1.0.11", "@ali/iceluna-addon-component-list": "^1.0.11",
"@ali/iceluna-comp-material-show": "^1.0.10", "@ali/iceluna-comp-material-show": "^1.0.10",
"@ali/iceluna-sdk": "^1.0.6-beta.6", "@ali/iceluna-sdk": "^1.0.6-beta.6",
"@ali/lowcode-editor-core": "0.8.0", "@ali/lowcode-editor-core": "^0.8.4",
"@ali/lowcode-designer": "^0.9.1",
"@alifd/next": "^1.19.19", "@alifd/next": "^1.19.19",
"react": "^16.8.1" "react": "^16.8.1"
}, },

View File

@ -2,6 +2,7 @@ import React, { PureComponent } from 'react';
import { Icon, Search, Select } from '@alifd/next'; import { Icon, Search, Select } from '@alifd/next';
import MaterialShow from '@ali/iceluna-comp-material-show'; import MaterialShow from '@ali/iceluna-comp-material-show';
import { PluginProps } from '@ali/lowcode-editor-core'; import { PluginProps } from '@ali/lowcode-editor-core';
import { Designer } from '@ali/lowcode-designer';
import './index.scss'; import './index.scss';
@ -42,7 +43,7 @@ export default class ComponentListPlugin extends PureComponent<
componentDidMount(): void { componentDidMount(): void {
const { editor } = this.props; const { editor } = this.props;
if (editor.assets) { if (editor.get('assets')) {
this.initComponentList(); this.initComponentList();
} else { } else {
editor.once('editor.ready', this.initComponentList); editor.once('editor.ready', this.initComponentList);
@ -72,7 +73,7 @@ export default class ComponentListPlugin extends PureComponent<
initComponentList = (): void => { initComponentList = (): void => {
const { editor } = this.props; const { editor } = this.props;
const assets = editor.assets || {}; const assets = editor.get('assets') || {};
const list: string[] = []; const list: string[] = [];
const libs: LibrayInfo[] = []; const libs: LibrayInfo[] = [];
Object.values(assets.packages).forEach((item): void => { Object.values(assets.packages).forEach((item): void => {
@ -100,10 +101,9 @@ export default class ComponentListPlugin extends PureComponent<
editor.set('dndHelper', { editor.set('dndHelper', {
handleResourceDragStart: function(ev, tagName, schema) { handleResourceDragStart: function(ev, tagName, schema) {
// 物料面板中组件snippet的dragStart回调 const designer = editor.get(Designer);
// ev: 原始的domEventtagName: 组件的描述文案schema: snippet的schema if (designer) {
if (editor.designer) { designer.dragon.boost(
editor.designer.dragon.boost(
{ {
type: 'nodedata', type: 'nodedata',
data: schema, data: schema,

View File

@ -57,7 +57,7 @@ export default class DesignerPlugin extends PureComponent<PluginProps, DesignerP
handleDesignerMount = (designer: Designer): void => { handleDesignerMount = (designer: Designer): void => {
const { editor } = this.props; const { editor } = this.props;
editor.set('designer', designer); editor.set(Designer, designer);
editor.emit('designer.ready', designer); editor.emit('designer.ready', designer);
const schema = editor.get('schema'); const schema = editor.get('schema');
if (schema) { if (schema) {
@ -82,7 +82,7 @@ export default class DesignerPlugin extends PureComponent<PluginProps, DesignerP
onMount={this.handleDesignerMount} onMount={this.handleDesignerMount}
className="lowcode-plugin-designer" className="lowcode-plugin-designer"
eventPipe={editor} eventPipe={editor}
designer={editor.get('designer')} designer={editor.get(Designer)}
componentMetadatas={componentMetadatas} componentMetadatas={componentMetadatas}
simulatorProps={{ simulatorProps={{
library, library,

View File

@ -16,6 +16,7 @@
"dependencies": { "dependencies": {
"@ali/lowcode-designer": "^0.9.1", "@ali/lowcode-designer": "^0.9.1",
"@ali/lowcode-globals": "^0.9.1", "@ali/lowcode-globals": "^0.9.1",
"@ali/lowcode-editor-core": "^0.8.4",
"@alifd/next": "^1.19.16", "@alifd/next": "^1.19.16",
"classnames": "^2.2.6", "classnames": "^2.2.6",
"react": "^16", "react": "^16",

View File

@ -17,6 +17,7 @@ import {
contains, contains,
Node, Node,
} from '@ali/lowcode-designer'; } from '@ali/lowcode-designer';
import { Editor } from '@ali/lowcode-editor-core';
import { Tree } from './tree'; import { Tree } from './tree';
import TreeNode from './tree-node'; import TreeNode from './tree-node';
import { IndentTrack } from './helper/indent-track'; import { IndentTrack } from './helper/indent-track';
@ -130,15 +131,16 @@ export class OutlineMain implements ISensor, IScrollBoard, IScrollable {
readonly id = uniqueId('outline'); readonly id = uniqueId('outline');
private fixed = false; private fixed = false;
constructor(readonly editor: any, at?: string) { constructor(readonly editor: Editor, at?: string) {
let inited = false; let inited = false;
const setup = () => { const setup = () => {
if (inited) { if (inited) {
return false; return false;
} }
inited = true; inited = true;
if (editor.designer) { const designer = editor.get(Designer);
this.setupDesigner(editor.designer); if (designer) {
this.setupDesigner(designer);
} else { } else {
editor.once('designer.mount', (designer: Designer) => { editor.once('designer.mount', (designer: Designer) => {
this.setupDesigner(designer); this.setupDesigner(designer);
@ -151,7 +153,6 @@ export class OutlineMain implements ISensor, IScrollBoard, IScrollable {
setup(); setup();
} else { } else {
editor.on('skeleton.panel.show', (key: string) => { editor.on('skeleton.panel.show', (key: string) => {
console.info('show', key);
if (key === at) { if (key === at) {
setup(); setup();
if (this.master) { if (this.master) {
@ -160,7 +161,10 @@ export class OutlineMain implements ISensor, IScrollBoard, IScrollable {
this.fixed = true; this.fixed = true;
} }
document.documentElement.classList.add('lowcode-has-fixed-tree'); document.documentElement.classList.add('lowcode-has-fixed-tree');
} else { }
});
editor.on('skeleton.panel.hide', (key: string) => {
if (key === at) {
document.documentElement.classList.remove('lowcode-has-fixed-tree'); document.documentElement.classList.remove('lowcode-has-fixed-tree');
if (this.master) { if (this.master) {
this.master.unFixed(this); this.master.unFixed(this);

View File

@ -6,7 +6,7 @@ import './index.scss';
const SamplePreview = ({ editor }: PluginProps) => { const SamplePreview = ({ editor }: PluginProps) => {
const handleClick = () => { const handleClick = () => {
const designer = editor.get('designer') as Designer; const designer = editor.get(Designer);
console.info('save schema:', designer.schema); console.info('save schema:', designer.schema);
localStorage.setItem('lce-dev-store', JSON.stringify(designer.schema)); localStorage.setItem('lce-dev-store', JSON.stringify(designer.schema));
window.open('./preview.html', 'preview'); window.open('./preview.html', 'preview');

View File

@ -1,28 +0,0 @@
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
<a name="0.8.3"></a>
## [0.8.3](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-plugin-sample-save@0.8.2...@ali/lowcode-plugin-sample-save@0.8.3) (2020-03-30)
**Note:** Version bump only for package @ali/lowcode-plugin-sample-save
<a name="0.8.2"></a>
## 0.8.2 (2020-03-30)
**Note:** Version bump only for package @ali/lowcode-plugin-sample-save
<a name="0.8.1"></a>
## 0.8.1 (2020-03-30)
**Note:** Version bump only for package @ali/lowcode-plugin-sample-save

View File

@ -1,3 +0,0 @@
## todo
Sample save plugin

View File

@ -1,9 +0,0 @@
{
"plugins": [
"build-plugin-component",
"build-plugin-fusion",
["build-plugin-moment-locales", {
"locales": ["zh-cn"]
}]
]
}

View File

@ -1,37 +0,0 @@
{
"name": "@ali/lowcode-plugin-sample-save",
"version": "0.8.3",
"description": "alibaba lowcode editor sample save plugin",
"files": [
"es",
"lib"
],
"main": "lib/index.js",
"module": "es/index.js",
"scripts": {
"build": "build-scripts build --skip-demo",
"test": "ava",
"test:snapshot": "ava --update-snapshots"
},
"keywords": [
"lowcode",
"editor"
],
"author": "xiayang.xy",
"dependencies": {
"@ali/lowcode-editor-core": "^0.8.4",
"@alifd/next": "^1.x",
"react": "^16.8.1"
},
"devDependencies": {
"@alib/build-scripts": "^0.1.3",
"@types/react": "^16.9.13",
"@types/react-dom": "^16.9.4",
"build-plugin-component": "^0.2.7-1",
"build-plugin-fusion": "^0.1.0",
"build-plugin-moment-locales": "^0.1.0"
},
"publishConfig": {
"registry": "https://registry.npm.alibaba-inc.com"
}
}

View File

@ -1,3 +0,0 @@
.lowcode-plugin-save {
padding: 10px 4px;
}

View File

@ -1,21 +0,0 @@
import React from 'react';
import { Button } from '@alifd/next';
import { PluginProps } from '@ali/lowcode-editor-core';
import './index.scss';
const Save: React.FC<PluginProps> = (props): React.ReactElement => {
const handleClick = (): void => {
console.log('save data:', props.editor.designer.currentDocument.schema);
console.log('save data json:', JSON.stringify(props.editor.designer.currentDocument.schema));
};
return (
<div className="lowcode-plugin-save">
<Button type="primary" onClick={handleClick}>
</Button>
</div>
);
};
export default Save;

View File

@ -1,9 +0,0 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "lib"
},
"include": [
"./src/"
]
}

View File

@ -3,6 +3,7 @@ import { uniqueId } from '@ali/lowcode-globals';
import { ComponentMeta, Node, Designer, Selection } from '@ali/lowcode-designer'; import { ComponentMeta, Node, Designer, Selection } from '@ali/lowcode-designer';
import { TitleContent, FieldExtraProps, SetterType, CustomView, FieldConfig, isCustomView } from '@ali/lowcode-globals'; import { TitleContent, FieldExtraProps, SetterType, CustomView, FieldConfig, isCustomView } from '@ali/lowcode-globals';
import { getTreeMaster } from '@ali/lowcode-plugin-outline-pane'; import { getTreeMaster } from '@ali/lowcode-plugin-outline-pane';
import Editor from '@ali/lowcode-editor-core';
export interface SettingTarget { export interface SettingTarget {
// 所设置的节点集,至少一个 // 所设置的节点集,至少一个
@ -323,10 +324,10 @@ export class SettingsMain implements SettingTarget {
private _designer?: Designer; private _designer?: Designer;
get designer() { get designer() {
return this._designer || this.editor.designer; return this._designer || this.editor.get(Designer);
} }
constructor(readonly editor: any) { constructor(readonly editor: Editor) {
const setupSelection = (selection?: Selection) => { const setupSelection = (selection?: Selection) => {
if (selection) { if (selection) {
if (!this._designer) { if (!this._designer) {
@ -337,20 +338,21 @@ export class SettingsMain implements SettingTarget {
this.setup([]); this.setup([]);
} }
}; };
editor.on('designer.selection-change', setupSelection); editor.on('designer.selection.change', setupSelection);
const connectTree = (designer: any) => { const connectTree = (designer: any) => {
getTreeMaster(designer).onceEnableBuiltin(() => { getTreeMaster(designer).onceEnableBuiltin(() => {
this.emitter.emit('outline-visible'); this.emitter.emit('outline-visible');
}); });
} }
if (editor.designer) { const designer = editor.get(Designer);
connectTree(editor.designer); if (designer) {
setupSelection(editor.designer.currentSelection); connectTree(designer);
setupSelection(designer.currentSelection);
} else { } else {
editor.once('designer.mount', connectTree); editor.once('designer.mount', connectTree);
} }
this.disposeListener = () => { this.disposeListener = () => {
editor.removeListener('designer.selection-change', setupSelection); editor.removeListener('designer.selection.change', setupSelection);
}; };
} }

View File

@ -21,6 +21,7 @@
"dependencies": { "dependencies": {
"@ali/lowcode-editor-core": "^0.8.4", "@ali/lowcode-editor-core": "^0.8.4",
"@ali/lowcode-editor-skeleton": "^0.8.5", "@ali/lowcode-editor-skeleton": "^0.8.5",
"@ali/lowcode-designer": "^0.9.1",
"react": "^16.8.1", "react": "^16.8.1",
"react-dom": "^16.8.1" "react-dom": "^16.8.1"
}, },

View File

@ -1,10 +1,11 @@
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import './index.scss'; import './index.scss';
import { PluginProps } from '@ali/lowcode-editor-core'; import Editor, { PluginProps } from '@ali/lowcode-editor-core';
import { TopIcon } from '@ali/lowcode-editor-skeleton'; import { TopIcon } from '@ali/lowcode-editor-skeleton';
import { Designer } from '@ali/lowcode-designer';
export interface IProps { export interface IProps {
editor: any; editor: Editor;
logo?: string; logo?: string;
} }
@ -33,12 +34,13 @@ export default class UndoRedo extends PureComponent<
const { editor } = this.props; const { editor } = this.props;
editor.on('designer.history-change', this.handleHistoryChange); editor.on('designer.history-change', this.handleHistoryChange);
if (editor.designer) { const designer = editor.get(Designer);
this.history = editor.designer?.currentHistory; if (designer) {
this.history = designer.currentHistory;
this.updateState(this.history?.getState() || 0); this.updateState(this.history?.getState() || 0);
} else { } else {
editor.once('designer.ready', (): void => { editor.once('designer.ready', (): void => {
this.history = editor.designer?.currentHistory; this.history = editor.get(Designer)?.currentHistory;
this.updateState(this.history?.getState() || 0); this.updateState(this.history?.getState() || 0);
}); });
} }
@ -57,7 +59,7 @@ export default class UndoRedo extends PureComponent<
init = (): void => { init = (): void => {
const { editor } = this.props; const { editor } = this.props;
this.history = editor.designer?.currentHistory; this.history = editor.get(Designer)?.currentHistory;
this.updateState(this.history?.getState() || 0); this.updateState(this.history?.getState() || 0);
editor.on('designer.history-change', (history: any): void => { editor.on('designer.history-change', (history: any): void => {

View File

@ -5,16 +5,20 @@ import DesignerView from '@ali/lowcode-plugin-designer';
import { registerSetters } from '@ali/lowcode-setters'; import { registerSetters } from '@ali/lowcode-setters';
import { Skeleton } from './skeleton/skeleton'; import { Skeleton } from './skeleton/skeleton';
import { Designer } from 'designer/src/designer'; import { Designer } from 'designer/src/designer';
import { globalContext } from 'globals/src/di';
registerSetters(); registerSetters();
export const editor = new Editor(); export const editor = new Editor();
globalContext.register(editor, Editor);
export const skeleton = new Skeleton(editor); export const skeleton = new Skeleton();
export const designer = new Designer({editor}); console.info(skeleton.editor);
editor.set('designer', designer) export const designer = new Designer({ eventPipe: editor });
editor.set(Designer, designer);
skeleton.mainArea.add({ skeleton.mainArea.add({
name: 'designer', name: 'designer',
@ -36,8 +40,8 @@ skeleton.leftArea.add({
}, },
content: OutlinePane, content: OutlinePane,
panelProps: { panelProps: {
area: 'leftFixedArea' area: 'leftFixedArea',
} },
}); });
// editor-core // editor-core

View File

@ -1,3 +1,5 @@
import { Editor } from '@ali/lowcode-editor-core';
import { inject } from '@ali/lowcode-globals';
import { import {
DockConfig, DockConfig,
PanelConfig, PanelConfig,
@ -9,7 +11,6 @@ import {
isPanelDockConfig, isPanelDockConfig,
isPanelConfig, isPanelConfig,
} from './types'; } from './types';
import Editor from '@ali/lowcode-editor-core';
import Panel, { isPanel } from './panel'; import Panel, { isPanel } from './panel';
import WidgetContainer from './widget-container'; import WidgetContainer from './widget-container';
import Area from './area'; import Area from './area';
@ -19,6 +20,17 @@ import Dock from './dock';
import { Stage, StageConfig } from './stage'; import { Stage, StageConfig } from './stage';
import { isValidElement } from 'react'; import { isValidElement } from 'react';
export enum SkeletonEvents {
PANEL_DOCK_ACTIVE = 'skeleton.panel-dock.active',
PANEL_DOCK_UNACTIVE = 'skeleton.panel-dock.unactive',
PANEL_SHOW = 'skeleton.panel.show',
PANEL_HIDE = 'skeleton.panel.hide',
WIDGET_SHOW = 'skeleton.widget.show',
WIDGET_HIDE = 'skeleton.widget.hide',
}
console.log(inject);
export class Skeleton { export class Skeleton {
private panels = new Map<string, Panel>(); private panels = new Map<string, Panel>();
private containers = new Map<string, WidgetContainer<any>>(); private containers = new Map<string, WidgetContainer<any>>();
@ -31,7 +43,10 @@ export class Skeleton {
readonly mainArea: Area<WidgetConfig | PanelConfig, Widget | Panel>; readonly mainArea: Area<WidgetConfig | PanelConfig, Widget | Panel>;
readonly bottomArea: Area<PanelConfig, Panel>; readonly bottomArea: Area<PanelConfig, Panel>;
readonly stages: Area<StageConfig, Stage>; readonly stages: Area<StageConfig, Stage>;
constructor(readonly editor: Editor) {
@inject() public editor: Editor;
constructor() {
this.leftArea = new Area( this.leftArea = new Area(
this, this,
'leftArea', 'leftArea',
@ -174,6 +189,10 @@ export class Skeleton {
}) })
} }
postEvent(event: SkeletonEvents, ...args: any[]) {
this.editor.emit(event, ...args);
}
createWidget(config: IWidgetBaseConfig | IWidget) { createWidget(config: IWidgetBaseConfig | IWidget) {
if (isWidget(config)) { if (isWidget(config)) {
return config; return config;

View File

@ -7,6 +7,7 @@ import { composeTitle } from './utils';
import WidgetContainer from './widget-container'; import WidgetContainer from './widget-container';
import Panel from './panel'; import Panel from './panel';
import { IWidget } from './widget'; import { IWidget } from './widget';
import { SkeletonEvents } from './skeleton';
export function DockView({ title, icon, description, size, className, onClick }: DockProps) { export function DockView({ title, icon, description, size, className, onClick }: DockProps) {
return ( return (
@ -34,9 +35,9 @@ export class PanelDockView extends Component<DockProps & { dock: PanelDock }> {
if (dock.actived !== this.lastActived) { if (dock.actived !== this.lastActived) {
this.lastActived = dock.actived; this.lastActived = dock.actived;
if (this.lastActived) { if (this.lastActived) {
dock.skeleton.editor.emit('skeleton.panel-dock.active', dock.name, dock); dock.skeleton.postEvent(SkeletonEvents.PANEL_DOCK_ACTIVE, dock.name, dock);
} else { } else {
dock.skeleton.editor.emit('skeleton.panel-dock.unactive', dock.name, dock); dock.skeleton.postEvent(SkeletonEvents.PANEL_DOCK_UNACTIVE, dock.name, dock);
} }
} }
} }
@ -78,9 +79,9 @@ export class TitledPanelView extends Component<{ panel: Panel }> {
if (currentVisible !== this.lastVisible) { if (currentVisible !== this.lastVisible) {
this.lastVisible = currentVisible; this.lastVisible = currentVisible;
if (this.lastVisible) { if (this.lastVisible) {
panel.skeleton.editor.emit('skeleton.panel.show', panel.name, panel); panel.skeleton.postEvent(SkeletonEvents.PANEL_SHOW, panel.name, panel);
} else { } else {
panel.skeleton.editor.emit('skeleton.panel.hide', panel.name, panel); panel.skeleton.postEvent(SkeletonEvents.PANEL_HIDE, panel.name, panel);
} }
} }
} }
@ -118,9 +119,9 @@ export class PanelView extends Component<{ panel: Panel }> {
if (currentVisible !== this.lastVisible) { if (currentVisible !== this.lastVisible) {
this.lastVisible = currentVisible; this.lastVisible = currentVisible;
if (this.lastVisible) { if (this.lastVisible) {
panel.skeleton.editor.emit('skeleton.panel.show', panel.name, panel); panel.skeleton.postEvent(SkeletonEvents.PANEL_SHOW, panel.name, panel);
} else { } else {
panel.skeleton.editor.emit('skeleton.panel.hide', panel.name, panel); panel.skeleton.postEvent(SkeletonEvents.PANEL_HIDE, panel.name, panel);
} }
} }
} }
@ -215,9 +216,9 @@ export class WidgetView extends Component<{ widget: IWidget }> {
if (currentVisible !== this.lastVisible) { if (currentVisible !== this.lastVisible) {
this.lastVisible = currentVisible; this.lastVisible = currentVisible;
if (this.lastVisible) { if (this.lastVisible) {
widget.skeleton.editor.emit('skeleton.widget.show', widget.name, widget); widget.skeleton.postEvent(SkeletonEvents.WIDGET_SHOW, widget.name, widget);
} else { } else {
widget.skeleton.editor.emit('skeleton.widget.hide', widget.name, widget); widget.skeleton.postEvent(SkeletonEvents.WIDGET_SHOW, widget.name, widget);
} }
} }
} }

View File

@ -16,6 +16,7 @@
// "noEmit": true, // "noEmit": true,
// Enable strictest settings like strictNullChecks & noImplicitAny. // Enable strictest settings like strictNullChecks & noImplicitAny.
"strict": true, "strict": true,
"strictPropertyInitialization": false,
// Allow default imports from modules with no default export. This does not affect code emit, just typechecking. // Allow default imports from modules with no default export. This does not affect code emit, just typechecking.
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
// Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. // Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'.
@ -26,6 +27,7 @@
"importHelpers": true, "importHelpers": true,
// Enables experimental support for ES7 decorators. // Enables experimental support for ES7 decorators.
"experimentalDecorators": true, "experimentalDecorators": true,
"emitDecoratorMetadata": true,
// Generates corresponding .map file. // Generates corresponding .map file.
"sourceMap": true, "sourceMap": true,
// Disallow inconsistently-cased references to the same file. // Disallow inconsistently-cased references to the same file.