Skip to content

Commit fdb3975

Browse files
authored
refactor: consolidate types, extract toolbar positioning, fix SolidJS… (#245)
1 parent 24f5632 commit fdb3975

File tree

19 files changed

+473
-414
lines changed

19 files changed

+473
-414
lines changed

packages/cli/src/utils/transform.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,11 @@ const transformVite = (
545545
if (!force) {
546546
const indexPath = findIndexHtml(projectRoot);
547547
if (indexPath) {
548-
const existingResult = checkExistingInstallation(indexPath, agent, reactGrabAlreadyConfigured);
548+
const existingResult = checkExistingInstallation(
549+
indexPath,
550+
agent,
551+
reactGrabAlreadyConfigured,
552+
);
549553
if (existingResult) return existingResult;
550554
}
551555
}
@@ -559,7 +563,11 @@ const transformVite = (
559563
}
560564

561565
if (!force) {
562-
const existingResult = checkExistingInstallation(entryPath, agent, reactGrabAlreadyConfigured);
566+
const existingResult = checkExistingInstallation(
567+
entryPath,
568+
agent,
569+
reactGrabAlreadyConfigured,
570+
);
563571
if (existingResult) return existingResult;
564572
}
565573

@@ -594,7 +602,11 @@ const transformWebpack = (
594602
}
595603

596604
if (!force) {
597-
const existingResult = checkExistingInstallation(entryPath, agent, reactGrabAlreadyConfigured);
605+
const existingResult = checkExistingInstallation(
606+
entryPath,
607+
agent,
608+
reactGrabAlreadyConfigured,
609+
);
598610
if (existingResult) return existingResult;
599611
}
600612

packages/cli/test/transform.test.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,7 @@ import ReactDOM from "react-dom/client";`;
480480

481481
mockExistsSync.mockImplementation((path) => {
482482
const pathStr = String(path);
483-
return (
484-
pathStr.endsWith("index.html") || pathStr.endsWith("main.tsx")
485-
);
483+
return pathStr.endsWith("index.html") || pathStr.endsWith("main.tsx");
486484
});
487485
mockReadFileSync.mockImplementation((path) => {
488486
if (String(path).endsWith("index.html")) return indexWithReactGrab;
@@ -512,22 +510,14 @@ import ReactDOM from "react-dom/client";`;
512510

513511
mockExistsSync.mockImplementation((path) => {
514512
const pathStr = String(path);
515-
return (
516-
pathStr.endsWith("index.html") || pathStr.endsWith("main.tsx")
517-
);
513+
return pathStr.endsWith("index.html") || pathStr.endsWith("main.tsx");
518514
});
519515
mockReadFileSync.mockImplementation((path) => {
520516
if (String(path).endsWith("index.html")) return indexWithReactGrab;
521517
return `import React from "react";`;
522518
});
523519

524-
const result = previewTransform(
525-
"/test",
526-
"vite",
527-
"unknown",
528-
"cursor",
529-
true,
530-
);
520+
const result = previewTransform("/test", "vite", "unknown", "cursor", true);
531521

532522
expect(result.success).toBe(true);
533523
expect(result.newContent).toContain("@react-grab/cursor");

packages/react-grab/e2e/edge-cases.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ test.describe("Edge Cases", () => {
325325
test("should handle elements outside viewport", async ({ reactGrab }) => {
326326
await reactGrab.activate();
327327
await reactGrab.scrollPage(1000);
328-
await reactGrab.page.waitForTimeout(200);
328+
await reactGrab.page.waitForTimeout(500);
329329

330330
await reactGrab.hoverElement("[data-testid='footer']");
331331
await reactGrab.waitForSelectionBox();

packages/react-grab/e2e/fixtures.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ const createReactGrabPageObject = (page: Page): ReactGrabPageObject => {
312312
const hoverElement = async (selector: string) => {
313313
const element = page.locator(selector).first();
314314
await element.hover({ force: true });
315-
await page.waitForTimeout(100);
315+
await page.waitForTimeout(250);
316316
};
317317

318318
const clickElement = async (selector: string) => {
@@ -362,7 +362,8 @@ const createReactGrabPageObject = (page: Page): ReactGrabPageObject => {
362362
const state = api?.getState();
363363
return state?.isSelectionBoxVisible || state?.targetElement !== null;
364364
},
365-
{ timeout: 2000 },
365+
undefined,
366+
{ timeout: 10_000 },
366367
);
367368
};
368369

@@ -378,6 +379,7 @@ const createReactGrabPageObject = (page: Page): ReactGrabPageObject => {
378379
).__REACT_GRAB__;
379380
return api?.getState()?.selectionFilePath !== null;
380381
},
382+
undefined,
381383
{ timeout: 5000 },
382384
);
383385
};
@@ -608,7 +610,31 @@ const createReactGrabPageObject = (page: Page): ReactGrabPageObject => {
608610
const enterPromptMode = async (selector: string) => {
609611
await activate();
610612
await hoverElement(selector);
611-
await waitForSelectionBox();
613+
const isSelected = await page
614+
.waitForFunction(
615+
() => {
616+
const api = (
617+
window as {
618+
__REACT_GRAB__?: {
619+
getState: () => {
620+
isSelectionBoxVisible: boolean;
621+
targetElement: unknown;
622+
};
623+
};
624+
}
625+
).__REACT_GRAB__;
626+
const state = api?.getState();
627+
return state?.isSelectionBoxVisible || state?.targetElement !== null;
628+
},
629+
undefined,
630+
{ timeout: 2000 },
631+
)
632+
.then(() => true)
633+
.catch(() => false);
634+
if (!isSelected) {
635+
await hoverElement(selector);
636+
await waitForSelectionBox();
637+
}
612638
await rightClickElement(selector);
613639
await clickContextMenuItem("Edit");
614640
await waitForPromptMode(true);
@@ -1820,6 +1846,7 @@ const createReactGrabPageObject = (page: Page): ReactGrabPageObject => {
18201846
const api = (window as { __REACT_GRAB__?: unknown }).__REACT_GRAB__;
18211847
return api !== undefined;
18221848
},
1849+
undefined,
18231850
{ timeout: 5000 },
18241851
);
18251852
};
@@ -2494,6 +2521,7 @@ export const test = base.extend<{ reactGrab: ReactGrabPageObject }>({
24942521
const api = (window as { __REACT_GRAB__?: unknown }).__REACT_GRAB__;
24952522
return api !== undefined;
24962523
},
2524+
undefined,
24972525
{ timeout: PAGE_SETUP_API_TIMEOUT_MS },
24982526
);
24992527
};

packages/react-grab/src/components/context-menu.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from "solid-js";
1010
import type { Component } from "solid-js";
1111
import type {
12+
Position,
1213
OverlayBounds,
1314
ContextMenuAction,
1415
ContextMenuActionContext,
@@ -30,7 +31,7 @@ import { createMenuHighlight } from "../utils/create-menu-highlight.js";
3031
import { suppressMenuEvent } from "../utils/suppress-menu-event.js";
3132

3233
interface ContextMenuProps {
33-
position: { x: number; y: number } | null;
34+
position: Position | null;
3435
selectionBounds: OverlayBounds | null;
3536
tagName?: string;
3637
componentName?: string;

0 commit comments

Comments
 (0)