|
|
@ -39,9 +39,10 @@ type Opts = { |
|
|
// TODO: should we export this type? and if so, we should create 1 type for every event?
|
|
|
// TODO: should we export this type? and if so, we should create 1 type for every event?
|
|
|
export type DragEventProps = { |
|
|
export type DragEventProps = { |
|
|
coords?: { x: number; y: number }; |
|
|
coords?: { x: number; y: number }; |
|
|
|
|
|
originComponent?: Component; |
|
|
|
|
|
originComponentView?: ComponentView; |
|
|
matchedComponent?: Component; |
|
|
matchedComponent?: Component; |
|
|
matchedComponentView?: ComponentView; |
|
|
matchedComponentView?: ComponentView; |
|
|
lastMatchedComponent?: Component; |
|
|
|
|
|
// TODO: draft
|
|
|
// TODO: draft
|
|
|
elGuideInfo?: HTMLElement; |
|
|
elGuideInfo?: HTMLElement; |
|
|
elGuideInfoCnt?: HTMLElement; |
|
|
elGuideInfoCnt?: HTMLElement; |
|
|
@ -87,7 +88,6 @@ 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.lastMatchedComponent = null; |
|
|
|
|
|
let drg = this.dragger; |
|
|
let drg = this.dragger; |
|
|
|
|
|
|
|
|
if (!drg) { |
|
|
if (!drg) { |
|
|
@ -395,13 +395,14 @@ export default { |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const dragStartProps: DragEventProps = { matchedComponent: target }; |
|
|
const dragStartProps: DragEventProps = { originComponent: target, originComponentView: getComponentView(target) }; |
|
|
|
|
|
|
|
|
|
|
|
// TODO: send the guides
|
|
|
this.editor.trigger(`${evName}:drag:start`, dragStartProps); |
|
|
this.editor.trigger(`${evName}:drag:start`, dragStartProps); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
onDrag(mouseEvent: MouseEvent, _dragger: Dragger) { |
|
|
onDrag(mouseEvent: MouseEvent, _dragger: Dragger) { |
|
|
const { guidesTarget, lastMatchedComponent, opts } = this; |
|
|
const { guidesTarget, opts } = this; |
|
|
let guideNearElements = []; |
|
|
let guideNearElements = []; |
|
|
|
|
|
|
|
|
this.updateGuides(guidesTarget); |
|
|
this.updateGuides(guidesTarget); |
|
|
@ -418,34 +419,31 @@ export default { |
|
|
if (matched?.origin) { |
|
|
if (matched?.origin) { |
|
|
matchedComponent = matched.origin; |
|
|
matchedComponent = matched.origin; |
|
|
matchedComponentView = getComponentView(matchedComponent); |
|
|
matchedComponentView = getComponentView(matchedComponent); |
|
|
if (matchedComponent !== lastMatchedComponent) this.lastMatchedComponent = matchedComponent; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const dragMoveProps: DragEventProps = { |
|
|
const dragMoveProps: DragEventProps = { |
|
|
coords: { x, y }, |
|
|
coords: { x, y }, |
|
|
matchedComponent, |
|
|
matchedComponent, |
|
|
matchedComponentView, |
|
|
matchedComponentView, |
|
|
lastMatchedComponent, |
|
|
|
|
|
elGuideInfo, |
|
|
elGuideInfo, |
|
|
elGuideInfoCnt, |
|
|
elGuideInfoCnt, |
|
|
size, |
|
|
size, |
|
|
sizePercent, |
|
|
sizePercent, |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// TODO: send the matched guides
|
|
|
this.editor.trigger(`${evName}:drag:move`, dragMoveProps); |
|
|
this.editor.trigger(`${evName}:drag:move`, dragMoveProps); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
onEnd(ev: Event, _dragger: Dragger, opt = {}) { |
|
|
onEnd(ev: Event, _dragger: Dragger, opt = {}) { |
|
|
const { editor, opts, id, lastMatchedComponent } = this; |
|
|
const { editor, opts, id } = 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()); |
|
|
|
|
|
|
|
|
const dragEndProps: DragEventProps = { lastMatchedComponent }; |
|
|
this.em.trigger(`${evName}:drag:end`, undefined); |
|
|
|
|
|
|
|
|
this.em.trigger(`${evName}:drag:end`, dragEndProps); |
|
|
|
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
hideGuidesInfo() { |
|
|
hideGuidesInfo() { |
|
|
|