-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5cf256d
commit 7365ae4
Showing
25 changed files
with
678 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,65 @@ | ||
import { ChangeDetectionStrategy, Component, Optional } from '@angular/core'; | ||
import { usePrefix } from '../../../utils'; | ||
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, OnInit, ViewChild } from '@angular/core'; | ||
import { usePrefix } from '@/app/utils'; | ||
import { NodeTitleWidget } from '../node-title/node-title.widget'; | ||
import { Engine } from '../../../core/models'; | ||
import { Cursor, CursorStatus } from '../../../core/models/cursor'; | ||
import { Engine, TreeNode } from '@/app/core/models'; | ||
import { Cursor, CursorStatus } from '@/app/core/models/cursor'; | ||
import { autorun } from '@formily/reactive'; | ||
|
||
@Component({ | ||
selector: 'app-ghost', | ||
standalone: true, | ||
template: ` | ||
@if (cursor.status === CursorStatus.Dragging) { | ||
<div class="{{ prefix }}"> | ||
<div class="{{ prefix }}" #containerRef> | ||
<span style="white-space: nowrap"> | ||
<app-node-title-widget></app-node-title-widget> | ||
<app-node-title-widget [node]="firstNode"></app-node-title-widget> | ||
{{ movingNodes?.length > 1 ? '...' : '' }} | ||
</span> | ||
</div> | ||
} | ||
`, | ||
imports: [NodeTitleWidget], | ||
styleUrls: ['./ghost.widget.less'], | ||
changeDetection: ChangeDetectionStrategy.OnPush | ||
}) | ||
export class GhostWidget { | ||
export class GhostWidget implements OnInit { | ||
@ViewChild('containerRef') containerRef: ElementRef; | ||
|
||
prefix = usePrefix('ghost'); | ||
constructor( | ||
@Optional() public designer: Engine, | ||
@Optional() public cursor: Cursor | ||
) {} | ||
|
||
protected readonly CursorStatus = CursorStatus; | ||
|
||
cursor: Cursor; | ||
|
||
movingNodes: TreeNode[]; | ||
|
||
firstNode: TreeNode; | ||
|
||
constructor( | ||
public designer: Engine, | ||
private cdr: ChangeDetectorRef | ||
) { | ||
this.cursor = this.designer.cursor; | ||
} | ||
|
||
ngOnInit(): void { | ||
window.addEventListener('mousedown', () => { | ||
setTimeout(() => { | ||
this.movingNodes = this.designer.findMovingNodes(); | ||
console.log(this.movingNodes); | ||
this.firstNode = this.movingNodes[0]; | ||
console.log(this.firstNode); | ||
}, 200); | ||
}); | ||
autorun(() => { | ||
// console.log('cursor status>>>', this.cursor.status); | ||
this.cdr.markForCheck(); | ||
const transform = `perspective(1px) translate3d(${ | ||
this.cursor.position?.topClientX - 18 | ||
}px,${this.cursor.position?.topClientY - 12}px,0) scale(0.8)`; | ||
if (!this.containerRef) return; | ||
// console.log('autorun', this.containerRef); | ||
this.containerRef.nativeElement.style.transform = transform; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './drag-drop-driver'; | ||
export * from './mouse-move-driver'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { EventDriver } from '../../shared/event'; | ||
import { Engine } from '../models'; | ||
import { MouseMoveEvent } from '../events/cursor'; | ||
|
||
export class MouseMoveDriver extends EventDriver<Engine> { | ||
request = null; | ||
|
||
onMouseMove = (e: MouseEvent) => { | ||
this.request = requestAnimationFrame(() => { | ||
cancelAnimationFrame(this.request); | ||
this.dispatch( | ||
new MouseMoveEvent({ | ||
clientX: e.clientX, | ||
clientY: e.clientY, | ||
pageX: e.pageX, | ||
pageY: e.pageY, | ||
target: e.target, | ||
view: e.view | ||
}) | ||
); | ||
}); | ||
}; | ||
|
||
override attach() { | ||
this.addEventListener('mousemove', this.onMouseMove, { | ||
mode: 'onlyOne' | ||
}); | ||
} | ||
|
||
override detach() { | ||
this.removeEventListener('mouseover', this.onMouseMove, { | ||
mode: 'onlyOne' | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './useDragDropEffect'; | ||
export * from './useCursorEffect'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Engine } from '../models'; | ||
import { DragMoveEvent, DragStartEvent, DragStopEvent, MouseMoveEvent } from '../events/cursor'; | ||
import { CursorStatus } from '../models/cursor'; | ||
import { requestIdle } from '../../shared/request-idle'; | ||
|
||
export const useCursorEffect = (engine: Engine) => { | ||
engine.subscribeTo(MouseMoveEvent, event => { | ||
engine.cursor.setStatus( | ||
engine.cursor.status === CursorStatus.Dragging || engine.cursor.status === CursorStatus.DragStart | ||
? engine.cursor.status | ||
: CursorStatus.Normal | ||
); | ||
if (engine.cursor.status === CursorStatus.Dragging) return; | ||
engine.cursor.setPosition(event.data); | ||
}); | ||
engine.subscribeTo(DragStartEvent, event => { | ||
engine.cursor.setStatus(CursorStatus.DragStart); | ||
engine.cursor.setDragStartPosition(event.data); | ||
}); | ||
engine.subscribeTo(DragMoveEvent, event => { | ||
engine.cursor.setStatus(CursorStatus.Dragging); | ||
engine.cursor.setPosition(event.data); | ||
}); | ||
engine.subscribeTo(DragStopEvent, event => { | ||
engine.cursor.setStatus(CursorStatus.DragStop); | ||
engine.cursor.setDragEndPosition(event.data); | ||
engine.cursor.setDragStartPosition(null); | ||
requestIdle(() => { | ||
engine.cursor.setStatus(CursorStatus.Normal); | ||
}); | ||
}); | ||
engine.subscribeTo(MouseMoveEvent, event => { | ||
const currentWorkspace = event?.context?.workspace; | ||
if (!currentWorkspace) return; | ||
const operation = currentWorkspace.operation; | ||
if (engine.cursor.status !== CursorStatus.Normal) { | ||
operation.hover.clear(); | ||
return; | ||
} | ||
const target = event.data.target as HTMLElement; | ||
const el = target?.closest?.(` | ||
*[${engine.props.nodeIdAttrName}], | ||
*[${engine.props.outlineNodeIdAttrName}] | ||
`); | ||
if (!el?.getAttribute) { | ||
return; | ||
} | ||
const nodeId = el.getAttribute(engine.props.nodeIdAttrName); | ||
const outlineNodeId = el.getAttribute(engine.props.outlineNodeIdAttrName); | ||
const node = operation.tree.findById(nodeId || outlineNodeId); | ||
if (node) { | ||
operation.hover.setHover(node); | ||
} else { | ||
operation.hover.clear(); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { IEngineContext } from '../../types'; | ||
import { Workspace } from '../../models/workspace'; | ||
|
||
export class AbstractWorkspaceEvent { | ||
data: Workspace; | ||
context: IEngineContext; | ||
constructor(data: Workspace) { | ||
this.data = data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { AbstractWorkspaceEvent } from './AbstractWorkspaceEvent'; | ||
import { ICustomEvent } from '../../../shared/event'; | ||
export class AddWorkspaceEvent extends AbstractWorkspaceEvent implements ICustomEvent { | ||
type = 'add:workspace'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './AddWorkspaceEvent'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.