mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-13 01:21:58 +00:00
feat: Exchange
This commit is contained in:
parent
33750b7fef
commit
ef5a72ea3d
@ -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);
|
||||
|
||||
51
packages/vision-polyfill/src/exchange.ts
Normal file
51
packages/vision-polyfill/src/exchange.ts
Normal 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;
|
||||
// },
|
||||
}
|
||||
@ -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
|
||||
*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user