Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve absolute mode #6450

Open
wants to merge 35 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2f906bf
feat: enhance typing for ComponentDrag and Dragger, adding optional p…
itscarlosrufo Mar 12, 2025
61d5862
feat: add customizable styles for drag guides and containers in Compo…
itscarlosrufo Mar 12, 2025
8170d8d
feat: enhance drag event handling with improved coordinate tracking
itscarlosrufo Mar 17, 2025
3f6d2c6
feat: add drag spot type and enhance drag event handling in Component…
itscarlosrufo Mar 19, 2025
44d4d9e
feat: add default options for command execution and simplify Componen…
itscarlosrufo Mar 20, 2025
1da500d
fix: cleanup
itscarlosrufo Mar 20, 2025
ee5a0e6
feat: enhance ComponentDrag with customizable style options and impro…
itscarlosrufo Mar 20, 2025
d7c7f53
feat: update addStyle method to return style options and enhance drag…
itscarlosrufo Mar 21, 2025
121ba81
feat: enhance drag event handling with structured event properties an…
itscarlosrufo Mar 24, 2025
9d018ab
feat: add run and stop command tests
itscarlosrufo Mar 24, 2025
cd6a3c6
test: improve command run and stop tests with objectContaining assert…
itscarlosrufo Mar 24, 2025
cfe84e6
test: update command run and stop tests to use expect.not.objectConta…
itscarlosrufo Mar 24, 2025
9197b29
test: simplify assertions in run and stop command tests by removing u…
itscarlosrufo Mar 24, 2025
c423197
test: skip run and stop command tests for default options and add TOD…
itscarlosrufo Mar 24, 2025
4d52617
refactor: rename drag event properties for clarity and consistency
itscarlosrufo Mar 24, 2025
ad339b1
refactor: update drag event properties to include origin component an…
itscarlosrufo Mar 25, 2025
06289a7
refactor: enhance drag event properties to include origin guides and …
itscarlosrufo Mar 25, 2025
8207260
refactor: remove drag event type and clean up default options in conf…
itscarlosrufo Mar 25, 2025
a4d9ab5
feat: add types
itscarlosrufo Mar 26, 2025
0df14a4
refactor: improve guide rendering logic and enhance drag event proper…
itscarlosrufo Mar 26, 2025
e46af1d
refactor: update addStyle type definition to accept component and sty…
itscarlosrufo Mar 26, 2025
f3a06c1
refactor: streamline guide rendering logic and separate matched guide…
itscarlosrufo Mar 26, 2025
2d53092
refactor: remove unused guidesTarget variable and optimize guide rend…
itscarlosrufo Mar 26, 2025
7a10510
refactor: optimize guide rendering performance and enhance drag event…
itscarlosrufo Mar 27, 2025
81bef19
Merge branch 'dev' into carlos/505-improve-grapesjs-absolute-mode
itscarlosrufo Mar 27, 2025
650c1b4
refactor: simplify guide target retrieval and enhance type safety in …
itscarlosrufo Mar 27, 2025
4ab6900
fix: recalculate guides to prevent issues with initial drag position
itscarlosrufo Mar 27, 2025
50e529b
refactor: enhance guide matching logic to improve accuracy during dra…
itscarlosrufo Mar 27, 2025
caa7e8b
refactor: rename guide matching functions for clarity and consistency
itscarlosrufo Mar 27, 2025
407454d
refactor: clean up deprecated properties in ComponentDrag and improve…
itscarlosrufo Mar 27, 2025
72e1208
refactor: update command test expectations
itscarlosrufo Mar 27, 2025
acca8e0
refactor: improve command option handling and test clarity
itscarlosrufo Mar 28, 2025
387a87f
refactor: remove unused default options and enhance guide matching ty…
itscarlosrufo Mar 28, 2025
1ee0411
refactor: clarify guide matching type definitions by specifying units…
itscarlosrufo Mar 28, 2025
699bcfa
refactor: enhance guide matching logic to include complementary types
itscarlosrufo Mar 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: enhance drag event properties to include origin guides and …
…matched guides
itscarlosrufo committed Mar 25, 2025
commit 06289a787f979aec40b45ebe8863eb073f3aea15
47 changes: 22 additions & 25 deletions packages/core/src/commands/view/ComponentDrag.ts
Original file line number Diff line number Diff line change
@@ -41,13 +41,10 @@ export type DragEventProps = {
coords?: { x: number; y: number };
originComponent?: Component;
originComponentView?: ComponentView;
originGuides?: any;
matchedComponent?: Component;
matchedComponentView?: ComponentView;
// TODO: draft
elGuideInfo?: HTMLElement;
elGuideInfoCnt?: HTMLElement;
size?: number;
sizePercent?: number;
matchedGuides?: any;
};

const evName = 'dmode';
@@ -355,7 +352,7 @@ export default {
},

onStart(event: Event) {
const { target, editor, isTran, opts } = this;
const { target, editor, isTran, opts, guidesTarget } = this;
const { Canvas } = editor;
const style = target.getStyle();
const position = 'absolute';
@@ -395,43 +392,41 @@ export default {
});
}

const dragStartProps: DragEventProps = { originComponent: target, originComponentView: getComponentView(target) };
const originComponent = target;
const originComponentView = getComponentView(originComponent);
const guidesTargetActive = guidesTarget;
const originGuides = this.renderGuideInfo(guidesTargetActive);

const dragStartProps: DragEventProps = {
originComponent,
originComponentView,
originGuides,
};

// TODO: send the guides
this.editor.trigger(`${evName}:drag:start`, dragStartProps);
},

onDrag(mouseEvent: MouseEvent, _dragger: Dragger) {
const { guidesTarget, opts } = this;
let guideNearElements = [];
let matchedGuides = [];
const guidesTargetActive = guidesTarget.filter((item: any) => item.active) ?? [];

this.updateGuides(guidesTarget);
opts?.debug && guidesTarget.forEach((item: any) => this.renderGuide(item));
opts?.guidesInfo && (guideNearElements = this.renderGuideInfo(guidesTarget.filter((item: any) => item.active)));
opts?.guidesInfo && (matchedGuides = this.renderGuideInfo(guidesTargetActive));
opts?.onDrag && opts.onDrag(this._getDragData());

const { x, y } = mouseEvent;
const guideNearElement = guideNearElements[0] ?? {};
const { size, sizePercent, matched, elGuideInfo, elGuideInfoCnt } = guideNearElement;
let matchedComponent = undefined;
let matchedComponentView = undefined;

if (matched?.origin) {
matchedComponent = matched.origin;
matchedComponentView = getComponentView(matchedComponent);
}
let matchedComponent = matchedGuides[0]?.matched.origin;
let matchedComponentView = getComponentView(matchedComponent);

const dragMoveProps: DragEventProps = {
coords: { x, y },
matchedComponent,
matchedComponentView,
elGuideInfo,
elGuideInfoCnt,
size,
sizePercent,
matchedGuides,
};

// TODO: send the matched guides
this.editor.trigger(`${evName}:drag:move`, dragMoveProps);
},

@@ -459,7 +454,7 @@ export default {
renderGuideInfo(guides: Guide[] = []) {
const { guidesStatic } = this;
this.hideGuidesInfo();
return guides.map((item) => {
const guidesData = guides.map((item) => {
const { origin, x } = item;
const rectOrigin = this.getElementPos(origin);
const axis = isUndefined(x) ? 'y' : 'x';
@@ -530,6 +525,8 @@ export default {

return guideNearElement;
});

return guidesData.filter(Boolean);
},

toggleDrag(enable: boolean) {