Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
"test:watch": "vitest",
"prepublishOnly": "pnpm build"
},
"dependencies": {
"element-source": "^0.0.3"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this package is 7 years old contains one relevant function:

let getReactDebugSource = function (element: any) {
    for (var key in element) {
        if (key.startsWith('__reactInternalInstance$')) {
            return element[key]._debugSource;
        }
    }
    return null;
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexgorbatchev could you clarify what you mean?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean IMO this dependency is not necessary.

},
"peerDependencies": {
"react": ">=18.0.0",
"react-dom": ">=18.0.0"
Expand Down
32 changes: 12 additions & 20 deletions package/src/components/page-toolbar-css/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ import {
requestAction,
} from "../../utils/sync";
import { getReactComponentName } from "../../utils/react-detection";
import {
getSourceLocation,
findNearestComponentSource,
formatSourceLocation,
} from "../../utils/source-location";
import { resolveSource, formatStackFrame } from "element-source";
import {
freeze as freezeAll,
unfreeze as unfreezeAll,
Expand Down Expand Up @@ -300,14 +296,10 @@ function getActiveButtonStyle(
};
}

function detectSourceFile(element: Element): string | undefined {
const result = getSourceLocation(element as HTMLElement);
const loc = result.found ? result : findNearestComponentSource(element as HTMLElement);
if (loc.found && loc.source) {
return formatSourceLocation(loc.source, "path");
}
return undefined;
}
const detectSourceFile = async (element: Element): Promise<string | undefined> => {
const source = await resolveSource(element);
return source ? formatStackFrame(source) : undefined;
};

function generateOutput(
annotations: Annotation[],
Expand Down Expand Up @@ -1410,7 +1402,7 @@ export function PageFeedbackToolbarCSS({
}, [isFrozen, freezeAnimations, unfreezeAnimations]);

// Create pending annotation from cmd+shift+click multi-select
const createMultiSelectPendingAnnotation = useCallback(() => {
const createMultiSelectPendingAnnotation = useCallback(async () => {
if (pendingMultiSelectElements.length === 0) return;

const firstItem = pendingMultiSelectElements[0];
Expand Down Expand Up @@ -1448,7 +1440,7 @@ export function PageFeedbackToolbarCSS({
cssClasses: getElementClasses(firstEl),
nearbyText: getNearbyText(firstEl),
reactComponents: firstItem.reactComponents,
sourceFile: detectSourceFile(firstEl),
sourceFile: await detectSourceFile(firstEl),
});
} else {
// Multiple elements - multi-select annotation
Expand Down Expand Up @@ -1507,7 +1499,7 @@ export function PageFeedbackToolbarCSS({
nearbyElements: getNearbyElements(firstEl),
cssClasses: getElementClasses(firstEl),
nearbyText: getNearbyText(firstEl),
sourceFile: detectSourceFile(firstEl),
sourceFile: await detectSourceFile(firstEl),
});
}

Expand Down Expand Up @@ -1635,7 +1627,7 @@ export function PageFeedbackToolbarCSS({
useEffect(() => {
if (!isActive) return;

const handleClick = (e: MouseEvent) => {
const handleClick = async (e: MouseEvent) => {
if (justFinishedDragRef.current) {
justFinishedDragRef.current = false;
return;
Expand Down Expand Up @@ -1765,7 +1757,7 @@ export function PageFeedbackToolbarCSS({
computedStylesObj,
nearbyElements: getNearbyElements(elementUnder),
reactComponents: reactComponents ?? undefined,
sourceFile: detectSourceFile(elementUnder),
sourceFile: await detectSourceFile(elementUnder),
targetElement: elementUnder, // Store for live position queries
});
setHoverInfo(null);
Expand Down Expand Up @@ -2106,7 +2098,7 @@ export function PageFeedbackToolbarCSS({
useEffect(() => {
if (!isActive) return;

const handleMouseUp = (e: MouseEvent) => {
const handleMouseUp = async (e: MouseEvent) => {
const wasDragging = isDragging;
const dragStart = dragStartRef.current;

Expand Down Expand Up @@ -2215,7 +2207,7 @@ export function PageFeedbackToolbarCSS({
nearbyElements: getNearbyElements(firstElement),
cssClasses: getElementClasses(firstElement),
nearbyText: getNearbyText(firstElement),
sourceFile: detectSourceFile(firstElement),
sourceFile: await detectSourceFile(firstElement),
});
} else {
// No elements selected, but allow annotation on empty area
Expand Down
1 change: 0 additions & 1 deletion package/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./element-identification";
export * from "./storage";
export * from "./source-location";
export * from "./sync";
Loading