tidy up old code
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
const EXCLUDED_CANVAS_TARGETS = '.context-menu, .react-flow__node, .react-flow__edge, .react-flow__controls, .react-flow__minimap, .surface-view-container';
|
||||
const CANVAS_AREA_TARGETS = '.react-flow, .react-flow__renderer, .react-flow__viewport, .react-flow__pane, .react-flow__background, .react-flow__selectionpane';
|
||||
|
||||
function getTargetElement(target: EventTarget | null): Element | null {
|
||||
if (!target) return null;
|
||||
if (typeof (target as Element).closest === 'function') return target as Element;
|
||||
const parent = (target as Node).parentElement;
|
||||
if (parent && typeof parent.closest === 'function') {
|
||||
return parent;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function supportsClosest(target: EventTarget | null): boolean {
|
||||
return !!getTargetElement(target);
|
||||
}
|
||||
|
||||
function matchesClosest(target: EventTarget | null, selector: string): boolean {
|
||||
const element = getTargetElement(target);
|
||||
return !!element && element.closest(selector) !== null;
|
||||
}
|
||||
|
||||
export function isEditableInteractionTarget(target: EventTarget | null): boolean {
|
||||
if (!supportsClosest(target)) return false;
|
||||
if (matchesClosest(target, 'input, textarea, select')) return true;
|
||||
return matchesClosest(target, '[contenteditable="true"]');
|
||||
}
|
||||
|
||||
export function canStartCanvasRightDragZoomTarget(target: EventTarget | null): boolean {
|
||||
if (!supportsClosest(target)) return false;
|
||||
if (isEditableInteractionTarget(target)) return false;
|
||||
if (matchesClosest(target, EXCLUDED_CANVAS_TARGETS)) {
|
||||
return false;
|
||||
}
|
||||
return matchesClosest(target, CANVAS_AREA_TARGETS);
|
||||
}
|
||||
|
||||
export function canOpenCanvasContextMenuTarget(target: EventTarget | null): boolean {
|
||||
if (!supportsClosest(target)) return false;
|
||||
if (isEditableInteractionTarget(target)) return false;
|
||||
if (matchesClosest(target, EXCLUDED_CANVAS_TARGETS)) {
|
||||
return false;
|
||||
}
|
||||
return matchesClosest(target, CANVAS_AREA_TARGETS);
|
||||
}
|
||||
|
||||
export function isSecondaryCanvasContextEvent(event: MouseEvent | null): boolean {
|
||||
if (!event || typeof event.button !== 'number') return false;
|
||||
return event.button === 2 || (event.button === 0 && !!event.ctrlKey);
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
import {
|
||||
canOpenCanvasContextMenuTarget,
|
||||
canStartCanvasRightDragZoomTarget,
|
||||
isEditableInteractionTarget,
|
||||
isSecondaryCanvasContextEvent,
|
||||
} from '../src/canvasInteractionTargets.ts';
|
||||
|
||||
function makeTarget(activeSelectors = []) {
|
||||
const selectorSet = new Set(activeSelectors);
|
||||
return {
|
||||
closest(selector) {
|
||||
const parts = String(selector).split(',').map((part) => part.trim());
|
||||
return parts.some((part) => selectorSet.has(part)) ? {} : null;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
test('editable canvas targets stay editable', () => {
|
||||
const inputTarget = makeTarget(['input']);
|
||||
assert.equal(isEditableInteractionTarget(inputTarget), true);
|
||||
assert.equal(canOpenCanvasContextMenuTarget(inputTarget), false);
|
||||
assert.equal(canStartCanvasRightDragZoomTarget(inputTarget), false);
|
||||
});
|
||||
|
||||
test('empty pane targets allow the custom canvas context menu', () => {
|
||||
const paneTarget = makeTarget(['.react-flow__pane']);
|
||||
assert.equal(canOpenCanvasContextMenuTarget(paneTarget), true);
|
||||
assert.equal(canStartCanvasRightDragZoomTarget(paneTarget), true);
|
||||
});
|
||||
|
||||
test('viewport-level targets also allow the custom canvas context menu', () => {
|
||||
const viewportTarget = makeTarget(['.react-flow__viewport']);
|
||||
assert.equal(canOpenCanvasContextMenuTarget(viewportTarget), true);
|
||||
assert.equal(canStartCanvasRightDragZoomTarget(viewportTarget), true);
|
||||
});
|
||||
|
||||
test('node and surface-view targets do not open the canvas context menu', () => {
|
||||
assert.equal(canOpenCanvasContextMenuTarget(makeTarget(['.react-flow__node', '.react-flow__pane'])), false);
|
||||
assert.equal(canOpenCanvasContextMenuTarget(makeTarget(['.surface-view-container', '.react-flow__pane'])), false);
|
||||
});
|
||||
|
||||
test('secondary canvas context detection includes macOS ctrl-click', () => {
|
||||
assert.equal(isSecondaryCanvasContextEvent({ button: 2, ctrlKey: false }), true);
|
||||
assert.equal(isSecondaryCanvasContextEvent({ button: 0, ctrlKey: true }), true);
|
||||
assert.equal(isSecondaryCanvasContextEvent({ button: 0, ctrlKey: false }), false);
|
||||
});
|
||||
@@ -5,10 +5,6 @@ export default defineConfig({
|
||||
plugins: [react()],
|
||||
server: {
|
||||
host: true,
|
||||
allowedHosts: ["bronchial-lorita-gorgeously.ngrok-free.dev"],
|
||||
hmr:{
|
||||
clientPort: 80,
|
||||
},
|
||||
port: 5173,
|
||||
proxy: {
|
||||
'/nodes': 'http://127.0.0.1:8188',
|
||||
|
||||
Reference in New Issue
Block a user