1- import { obx , makeObservable , IEventBus , createModuleEventBus } from '@felce/lowcode-editor-core' ;
1+ import { IEventBus , createModuleEventBus , makeObservable , obx } from '@felce/lowcode-editor-core' ;
22import {
3- IPublicTypeDragNodeObject ,
4- IPublicTypeDragAnyObject ,
5- IPublicEnumDragObjectType ,
6- IPublicTypeDragNodeDataObject ,
73 IPublicModelDragObject ,
8- IPublicModelNode ,
94 IPublicModelDragon ,
105 IPublicModelLocateEvent ,
6+ IPublicModelNode ,
117 IPublicModelSensor ,
128} from '@felce/lowcode-types' ;
13- import { setNativeSelection , cursor } from '@felce/lowcode-utils' ;
9+ import { cursor , isDragNodeObject , setNativeSelection } from '@felce/lowcode-utils' ;
1410import { INode , Node } from '../document' ;
1511import { ISimulatorHost , isSimulatorHost } from '../simulator' ;
16- import { IDesigner } from './designer' ;
1712import { makeEventsHandler } from '../utils/misc' ;
13+ import { IDesigner } from './designer' ;
1814
1915export interface ILocateEvent extends IPublicModelLocateEvent {
2016 readonly type : 'LocateEvent' ;
@@ -25,31 +21,6 @@ export interface ILocateEvent extends IPublicModelLocateEvent {
2521 sensor ?: IPublicModelSensor ;
2622}
2723
28- /**
29- * @deprecated use same function in @felce/lowcode-utils
30- */
31- export function isDragNodeObject ( obj : any ) : obj is IPublicTypeDragNodeObject {
32- return obj && obj . type === IPublicEnumDragObjectType . Node ;
33- }
34-
35- /**
36- * @deprecated use same function in @felce/lowcode-utils
37- */
38- export function isDragNodeDataObject ( obj : any ) : obj is IPublicTypeDragNodeDataObject {
39- return obj && obj . type === IPublicEnumDragObjectType . NodeData ;
40- }
41-
42- /**
43- * @deprecated use same function in @felce/lowcode-utils
44- */
45- export function isDragAnyObject ( obj : any ) : obj is IPublicTypeDragAnyObject {
46- return (
47- obj &&
48- obj . type !== IPublicEnumDragObjectType . NodeData &&
49- obj . type !== IPublicEnumDragObjectType . Node
50- ) ;
51- }
52-
5324export function isLocateEvent ( e : any ) : e is ILocateEvent {
5425 return e && e . type === 'LocateEvent' ;
5526}
@@ -88,7 +59,7 @@ export function setShaken(e: any) {
8859 e . shaken = true ;
8960}
9061
91- function getSourceSensor ( dragObject : IPublicModelDragObject ) : ISimulatorHost | null {
62+ function getSourceSensor ( dragObject : IPublicModelDragObject < INode > ) : ISimulatorHost | null {
9263 if ( ! isDragNodeObject ( dragObject ) ) {
9364 return null ;
9465 }
@@ -144,7 +115,7 @@ export class Dragon implements IDragon {
144115 * @param shell container element
145116 * @param boost boost got a drag object
146117 */
147- from ( shell : Element , boost : ( e : MouseEvent ) => IPublicModelDragObject | null ) {
118+ from ( shell : Element , boost : ( e : MouseEvent ) => IPublicModelDragObject < INode > | null ) {
148119 const mousedown = ( e : MouseEvent ) => {
149120 // ESC or RightClick
150121 if ( e . which === 3 || e . button === 2 ) {
@@ -172,7 +143,7 @@ export class Dragon implements IDragon {
172143 * @param boostEvent 拖拽初始时事件
173144 */
174145 boost (
175- dragObject : IPublicModelDragObject ,
146+ dragObject : IPublicModelDragObject < INode > ,
176147 boostEvent : MouseEvent | DragEvent ,
177148 fromRglNode ?: INode | IPublicModelNode ,
178149 ) {
@@ -257,7 +228,7 @@ export class Dragon implements IDragon {
257228 /* istanbul ignore next */
258229 if ( isRGL ) {
259230 // 禁止被拖拽元素的阻断
260- const nodeInst = dragObject . nodes [ 0 ] . getDOMNode ( ) ;
231+ const nodeInst = dragObject . nodes ?. [ 0 ] ? .getDOMNode ( ) ;
261232 if ( nodeInst && nodeInst . style ) {
262233 this . nodeInstPointerEvents = true ;
263234 nodeInst . style . pointerEvents = 'none' ;
@@ -275,7 +246,7 @@ export class Dragon implements IDragon {
275246 this . emitter . emit ( 'rgl.add.placeholder' , {
276247 rglNode,
277248 fromRglNode,
278- node : locateEvent . dragObject ?. nodes [ 0 ] ,
249+ node : locateEvent . dragObject ?. nodes ?. [ 0 ] ,
279250 event : e ,
280251 } ) ;
281252 designer . clearLocation ( ) ;
@@ -349,7 +320,7 @@ export class Dragon implements IDragon {
349320 const over = ( e ?: any ) => {
350321 // 禁止被拖拽元素的阻断
351322 if ( this . nodeInstPointerEvents ) {
352- const nodeInst = dragObject . nodes [ 0 ] . getDOMNode ( ) ;
323+ const nodeInst = dragObject . nodes ?. [ 0 ] ? .getDOMNode ( ) ;
353324 if ( nodeInst && nodeInst . style ) {
354325 nodeInst . style . pointerEvents = '' ;
355326 }
@@ -361,7 +332,7 @@ export class Dragon implements IDragon {
361332 const { isRGL, rglNode } = getRGL ( e ) ;
362333 /* istanbul ignore next */
363334 if ( isRGL && this . _canDrop && this . _dragging ) {
364- const tarNode = dragObject . nodes [ 0 ] ;
335+ const tarNode = dragObject . nodes ?. [ 0 ] ;
365336 if ( rglNode . id !== tarNode . id ) {
366337 // 避免死循环
367338 this . emitter . emit ( 'rgl.drop' , {
@@ -489,6 +460,7 @@ export class Dragon implements IDragon {
489460 } else if ( e . sensor ) {
490461 sensor = e . sensor ;
491462 } else if ( sourceSensor ) {
463+ // FIXME: 这里为什么会把simulator拿过来?
492464 sensor = sourceSensor ;
493465 }
494466 }
@@ -640,7 +612,7 @@ export class Dragon implements IDragon {
640612 } ;
641613 }
642614
643- onDragend ( func : ( x : { dragObject : IPublicModelDragObject ; copy : boolean } ) => any ) {
615+ onDragend ( func : ( x : { dragObject : IPublicModelDragObject < INode > ; copy : boolean } ) => any ) {
644616 this . emitter . on ( 'dragend' , func ) ;
645617 return ( ) => {
646618 this . emitter . removeListener ( 'dragend' , func ) ;
0 commit comments