feat: Exchange

This commit is contained in:
弱冠 2020-04-14 11:09:58 +08:00
parent 33750b7fef
commit ef5a72ea3d
3 changed files with 54 additions and 1 deletions

View File

@ -157,7 +157,7 @@ export class Selection {
return nodes;
}
onSelectionChange(fn: () => void): () => void {
onSelectionChange(fn: (ids: string[]) => void): () => void {
this.emitter.on('selectionchange', fn);
return () => {
this.emitter.removeListener('selectionchange', fn);

View File

@ -0,0 +1,51 @@
import { Selection, DocumentModel, Node } from '@ali/lowcode-designer';
import editor from './editor';
let currentSelection: Selection;
// let currentDocument: DocumentModel;
// get selection async
editor.once('designer.ready', () => {
const getSelection = () => {
if (editor.designer.currentSelection) {
currentSelection = editor.designer.currentSelection;
// currentDocument = editor.designer.currentDocument;
currentSelection.onSelectionChange((ids: string[]) => {
// console.log(ids);
// const nodes = ids.map((id: string) => currentDocument.getNode(id));
// console.log(nodes);
});
} else {
console.log('waiting ...');
requestAnimationFrame(getSelection);
}
};
getSelection();
});
export default {
select: (node: Node) => {
if (!node) {
return currentSelection.clear();
}
currentSelection.select(node.id);
},
getSelected: () => {
const nodes = currentSelection.getNodes();
return nodes;
},
// 以下废弃
// hover: (node: Node) => {
// hovering.hover(node);
// },
// getDropping: () => {
// return null;
// },
// onIntoView: (func: (node: any, insertion: Insertion) => any) => {
// currentSelection.onSelectionChange((ids) => {
// console.log(ids);
// });
// return null;
// },
}

View File

@ -8,6 +8,7 @@ import Bus from './bus';
import Symbols from './symbols';
import Skeleton from '@ali/lowcode-editor-skeleton';
import editor from './editor';
import Exchange from './exchange';
function init(container?: Element) {
if (!container) {
@ -44,6 +45,7 @@ export {
HOOKS,
/* Symbol 管理类 */
Symbols,
Exchange,
/**
* VE.init
*