|
|
@ -4,7 +4,6 @@ import type { CommandObject } from './CommandAbstract'; |
|
|
import type Editor from '../../editor'; |
|
|
import type Editor from '../../editor'; |
|
|
import type Component from '../../dom_components/model/Component'; |
|
|
import type Component from '../../dom_components/model/Component'; |
|
|
import type EditorModel from '../../editor/model/Editor'; |
|
|
import type EditorModel from '../../editor/model/Editor'; |
|
|
import { CanvasSpotBuiltInTypes } from '../../canvas/model/CanvasSpot'; |
|
|
|
|
|
|
|
|
|
|
|
type Rect = { left: number; width: number; top: number; height: number }; |
|
|
type Rect = { left: number; width: number; top: number; height: number }; |
|
|
type OrigRect = { left: number; width: number; top: number; height: number; rect: Rect }; |
|
|
type OrigRect = { left: number; width: number; top: number; height: number; rect: Rect }; |
|
|
@ -35,6 +34,17 @@ type Opts = { |
|
|
addStyle?: () => Record<string, unknown>; |
|
|
addStyle?: () => Record<string, unknown>; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// TODO: should we export this type? and if so, we should create 1 type for every event?
|
|
|
|
|
|
export type DragEventProps = { |
|
|
|
|
|
coords?: { x: number; y: number }; |
|
|
|
|
|
matchedEl?: Component; |
|
|
|
|
|
lastMatchedEl?: Component; |
|
|
|
|
|
elGuideInfo?: HTMLElement; |
|
|
|
|
|
elGuideInfoCnt?: HTMLElement; |
|
|
|
|
|
size?: number; |
|
|
|
|
|
sizePercent?: number; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
const evName = 'dmode'; |
|
|
const evName = 'dmode'; |
|
|
|
|
|
|
|
|
export default { |
|
|
export default { |
|
|
@ -73,6 +83,7 @@ export default { |
|
|
this.guidesContainer = this.getGuidesContainer(); |
|
|
this.guidesContainer = this.getGuidesContainer(); |
|
|
this.guidesTarget = this.getGuidesTarget(); |
|
|
this.guidesTarget = this.getGuidesTarget(); |
|
|
this.guidesStatic = this.getGuidesStatic(); |
|
|
this.guidesStatic = this.getGuidesStatic(); |
|
|
|
|
|
this.lastMatchedEl = null; |
|
|
let drg = this.dragger; |
|
|
let drg = this.dragger; |
|
|
|
|
|
|
|
|
if (!drg) { |
|
|
if (!drg) { |
|
|
@ -380,20 +391,13 @@ export default { |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this.editor.trigger(`${evName}:drag:start`, { |
|
|
const dragStartProps: DragEventProps = { matchedEl: target }; |
|
|
coords: { x: 0, y: 0 }, // TODO: pass the real coords
|
|
|
|
|
|
targetEl: event.target, |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
this.em.Canvas.addSpot({ |
|
|
this.editor.trigger(`${evName}:drag:start`, dragStartProps); |
|
|
type: CanvasSpotBuiltInTypes.Drag, |
|
|
|
|
|
component: target, |
|
|
|
|
|
componentView: target.view, |
|
|
|
|
|
}); |
|
|
|
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
onDrag(mouseEvent: MouseEvent, _dragger: Dragger) { |
|
|
onDrag(mouseEvent: MouseEvent, _dragger: Dragger) { |
|
|
const { guidesTarget, opts } = this; |
|
|
const { guidesTarget, lastMatchedEl, opts } = this; |
|
|
let guideNearElements = []; |
|
|
let guideNearElements = []; |
|
|
|
|
|
|
|
|
this.updateGuides(guidesTarget); |
|
|
this.updateGuides(guidesTarget); |
|
|
@ -404,37 +408,37 @@ export default { |
|
|
const { x, y } = mouseEvent; |
|
|
const { x, y } = mouseEvent; |
|
|
const guideNearElement = guideNearElements[0] ?? {}; |
|
|
const guideNearElement = guideNearElements[0] ?? {}; |
|
|
const { size, sizePercent, matched, elGuideInfo, elGuideInfoCnt } = guideNearElement; |
|
|
const { size, sizePercent, matched, elGuideInfo, elGuideInfoCnt } = guideNearElement; |
|
|
const matchedEl = matched?.origin; |
|
|
let matchedEl = undefined; |
|
|
// TODO: revisit event props
|
|
|
|
|
|
this.editor.trigger(`${evName}:drag:move`, { |
|
|
if (matched?.origin) { |
|
|
|
|
|
matchedEl = matched.origin; |
|
|
|
|
|
if (matchedEl !== lastMatchedEl) this.lastMatchedEl = matchedEl; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const dragMoveProps: DragEventProps = { |
|
|
coords: { x, y }, |
|
|
coords: { x, y }, |
|
|
matchedEl, |
|
|
matchedEl, |
|
|
|
|
|
lastMatchedEl, |
|
|
elGuideInfo, |
|
|
elGuideInfo, |
|
|
elGuideInfoCnt, |
|
|
elGuideInfoCnt, |
|
|
size, |
|
|
size, |
|
|
sizePercent, |
|
|
sizePercent, |
|
|
}); |
|
|
}; |
|
|
|
|
|
|
|
|
// TODO: add the spot to the canvas to show the origin?
|
|
|
this.editor.trigger(`${evName}:drag:move`, dragMoveProps); |
|
|
// if (matchedEl) {
|
|
|
|
|
|
// this.em.Canvas.addSpot({
|
|
|
|
|
|
// type: CanvasSpotBuiltInTypes.Drag,
|
|
|
|
|
|
// });
|
|
|
|
|
|
// }
|
|
|
|
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
onEnd(ev: Event, _dragger: Dragger, opt = {}) { |
|
|
onEnd(ev: Event, _dragger: Dragger, opt = {}) { |
|
|
const { editor, opts, id } = this; |
|
|
const { editor, opts, id, lastMatchedEl } = this; |
|
|
opts?.onEnd?.(ev, opt, { event: ev, ...opt, ...this._getDragData() }); |
|
|
opts?.onEnd?.(ev, opt, { event: ev, ...opt, ...this._getDragData() }); |
|
|
editor.stopCommand(id); |
|
|
editor.stopCommand(id); |
|
|
this.hideGuidesInfo(); |
|
|
this.hideGuidesInfo(); |
|
|
|
|
|
|
|
|
this.em.trigger(`${evName}:end`, this.getEventOpts()); |
|
|
this.em.trigger(`${evName}:end`, this.getEventOpts()); |
|
|
this.em.trigger(`${evName}:drag:end`, undefined); |
|
|
|
|
|
this.em.Canvas.removeSpots({ |
|
|
const dragEndProps: DragEventProps = { lastMatchedEl }; |
|
|
type: CanvasSpotBuiltInTypes.Drag, |
|
|
|
|
|
component: this.target, |
|
|
this.em.trigger(`${evName}:drag:end`, dragEndProps); |
|
|
}); |
|
|
|
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
hideGuidesInfo() { |
|
|
hideGuidesInfo() { |
|
|
|