feat: 🎸 polyfill exchange

vision exchange api
This commit is contained in:
弱冠 2020-04-15 10:15:30 +08:00
parent e49a02e37c
commit 286e7d8f45
2 changed files with 6 additions and 9 deletions

View File

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

View File

@ -1,23 +1,20 @@
import { Selection, DocumentModel, Node } from '@ali/lowcode-designer'; import { Selection, Node } from '@ali/lowcode-designer';
import editor from './editor'; import { editor } from './editor';
let currentSelection: Selection; let currentSelection: Selection;
// let currentDocument: DocumentModel;
// get selection async // get selection async
editor.once('designer.ready', () => { editor.once('designer.ready', () => {
const getSelection = () => { const getSelection = () => {
if (editor.designer.currentSelection) { if (editor.designer.currentSelection) {
currentSelection = editor.designer.currentSelection; currentSelection = editor.designer.currentSelection;
// currentDocument = editor.designer.currentDocument;
currentSelection.onSelectionChange((ids: string[]) => { currentSelection.onSelectionChange(() => {
// console.log(ids); // const nodes = currentSelection.getNodes();
// const nodes = ids.map((id: string) => currentDocument.getNode(id));
// console.log(nodes); // console.log(nodes);
}); });
} else { } else {
console.log('waiting ...'); // console.log('waiting ...');
requestAnimationFrame(getSelection); requestAnimationFrame(getSelection);
} }
}; };