seat-editor 3.6.7 → 3.6.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@ import React, { useEffect, useMemo, useRef, useState, useImperativeHandle, useCa
3
3
  import { TransformWrapper, TransformComponent, } from "react-zoom-pan-pinch";
4
4
  import { useAppDispatch, useAppSelector } from "../../hooks/use-redux";
5
5
  import Layers from "../../components/layer-v5";
6
- import { createTableGhost, getGlobalBBox, } from "../board-v3/utils";
6
+ import { createTableGhost, getGlobalBBox, getTranslate, } from "../board-v3/utils";
7
7
  import { Spin } from "antd";
8
8
  import { rotatePoint, renderElements } from "./utils";
9
9
  import { useConnectionGraph } from "./use-connection-graph";
@@ -12,14 +12,22 @@ import { ConnectHandle } from "./connect-handle";
12
12
  import { getAttributeElement } from "../board-v3/resize-element";
13
13
  const LayerView = (props) => {
14
14
  var _a, _b, _c, _d;
15
- const { componentProps, extraComponentProps, onSelectComponent, onDoubleClick, mappingKey, statusKey, defaultBackground, defaultBoundingBox, iconTags, tooltipProps, onRightClick, allowTooltip = true, tableMatchKey, eventMatchTable, ghostAttributes, onDrop, onSwitch, refs, privilegedTags, loadingRender, actionPrivileged = {
15
+ const { componentProps, extraComponentProps, onSelectComponent, onDoubleClick, mappingKey, statusKey, defaultBackground, defaultBoundingBox,
16
+ // iconTags,
17
+ tooltipProps, onRightClick, allowTooltip = true, tableMatchKey, eventMatchTable, ghostAttributes, onDrop, onSwitch, refs, privilegedTags, loadingRender, actionPrivileged = {
16
18
  select: true,
17
19
  move: true,
18
20
  switch: true,
19
21
  drop: true,
20
22
  rightClick: true,
21
23
  double: true,
22
- }, isConnectEdge = true, isSelectNode = true, onMakeSelection } = props;
24
+ selection: true,
25
+ grapConnection: true,
26
+ viewGraph: true,
27
+ dragTable: true,
28
+ selectNode: true,
29
+ connectingNode: true
30
+ }, onMakeSelection, } = props;
23
31
  const widthTooltip = (tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.minWidth) || 168;
24
32
  const tableGhost = useRef(null);
25
33
  const hoverUnderghostId = useRef(null);
@@ -37,6 +45,7 @@ const LayerView = (props) => {
37
45
  const [scale, setScale] = useState(1);
38
46
  const [selectedTable, setSelectedTable] = useState(null);
39
47
  const dataElementSelectionGroupRef = useRef([]);
48
+ const [selectedLines, setSelectedLines] = useState(null);
40
49
  const { components: componentsEditor, extraComponents: extraComponentsEditor, boundingBox: boundingBoxProps, } = useAppSelector((state) => state.board);
41
50
  const backgroundColor = useAppSelector((state) => state.board.backgroundColor);
42
51
  const { loading } = useAppSelector((state) => state.panel);
@@ -108,6 +117,10 @@ const LayerView = (props) => {
108
117
  }
109
118
  return data;
110
119
  };
120
+ const handleUnSelectComponent = () => {
121
+ setSelectedLines(null);
122
+ dataElementSelectionGroupRef.current = [];
123
+ };
111
124
  const handleDoubleClick = (items, e) => {
112
125
  const find = componentsEditor.find((item) => {
113
126
  var _a;
@@ -203,46 +216,31 @@ const LayerView = (props) => {
203
216
  height: maxY,
204
217
  };
205
218
  }, [componentsEditor, extraComponentsEditor, boundingBoxProps]);
206
- const [fingerCount, setFingerCount] = useState(0);
207
- useEffect(() => {
208
- const container = document.getElementById("workspace");
209
- const handleTouchStart = (e) => setFingerCount(e.touches.length);
210
- const handleTouchEnd = () => setFingerCount(0);
211
- if (container) {
212
- container.addEventListener("touchstart", handleTouchStart);
213
- container.addEventListener("touchend", handleTouchEnd);
214
- }
215
- return () => {
216
- if (container) {
217
- container.removeEventListener("touchstart", handleTouchStart);
218
- container.removeEventListener("touchend", handleTouchEnd);
219
- }
220
- };
221
- }, []);
222
- const handleTableEvent = (event, type) => {
223
- var _a;
224
- event.preventDefault();
225
- const elementTarget = event.target;
226
- if (!elementTarget)
227
- return;
228
- const group = elementTarget.closest("g[data-id]");
229
- if (!group)
230
- return;
231
- try {
232
- const tableId = JSON.parse(group.getAttribute("data-id") || "{}");
233
- const dragEvent = event;
234
- const dataTransfer = JSON.parse(((_a = dragEvent.dataTransfer) === null || _a === void 0 ? void 0 : _a.getData("application/json")) || "{}");
235
- const data = {
236
- targetTable: originalData({ id: tableId, type: "find" }),
237
- sourceTable: originalData({ dataParams: dataTransfer, type: "get" }),
238
- };
239
- if (type === "drop")
240
- onDrop && (actionPrivileged === null || actionPrivileged === void 0 ? void 0 : actionPrivileged.drop) && onDrop(event, data);
241
- }
242
- catch (err) {
243
- console.error("Invalid data-id JSON:", err);
244
- }
245
- };
219
+ // const handleTableEvent = (
220
+ // event: React.MouseEvent<SVGSVGElement>,
221
+ // type: EventHandleType
222
+ // ) => {
223
+ // event.preventDefault();
224
+ // const elementTarget = event.target as SVGElement | null;
225
+ // if (!elementTarget) return;
226
+ // const group = elementTarget.closest("g[data-id]");
227
+ // if (!group) return;
228
+ // try {
229
+ // const tableId = JSON.parse(group.getAttribute("data-id") || "{}");
230
+ // const dragEvent = event as React.DragEvent<SVGSVGElement>;
231
+ // const dataTransfer = JSON.parse(
232
+ // dragEvent.dataTransfer?.getData("application/json") || "{}"
233
+ // );
234
+ // // const data = {
235
+ // // targetTable: originalData({ id: tableId, type: "find" }),
236
+ // // sourceTable: originalData({ dataParams: dataTransfer, type: "get" }),
237
+ // // };
238
+ // // if (type === "drop")
239
+ // // onDrop && actionPrivileged?.drop && onDrop(event, data);
240
+ // } catch (err) {
241
+ // console.error("Invalid data-id JSON:", err);
242
+ // }
243
+ // };
246
244
  const getSvgCoords = (e) => {
247
245
  var _a;
248
246
  const svg = svgRef.current;
@@ -256,9 +254,13 @@ const LayerView = (props) => {
256
254
  const clickTimerRef = useRef(null);
257
255
  const ignoreNextRef = useRef(false);
258
256
  const DOUBLE_DELAY = 250;
257
+ useEffect(() => {
258
+ if (!(actionPrivileged === null || actionPrivileged === void 0 ? void 0 : actionPrivileged.selection)) {
259
+ setSelectedLines(null);
260
+ }
261
+ }, [actionPrivileged]);
259
262
  const handlePointerDown = (e) => {
260
- var _a;
261
- console.log("handlePointerDown", e);
263
+ var _a, _b, _c;
262
264
  const svg = svgRef.current;
263
265
  if (!e.isPrimary || !svg)
264
266
  return;
@@ -270,7 +272,15 @@ const LayerView = (props) => {
270
272
  const targetGroup = e.target.closest("g[data-id]");
271
273
  const { clientX, clientY } = e;
272
274
  const hitPoint = document.elementFromPoint(clientX, clientY);
273
- const makeSelection = (hitPoint === null || hitPoint === void 0 ? void 0 : hitPoint.nodeName) === "svg";
275
+ const downOutTable = (hitPoint === null || hitPoint === void 0 ? void 0 : hitPoint.nodeName) === "svg";
276
+ const makeSelection = downOutTable && (actionPrivileged === null || actionPrivileged === void 0 ? void 0 : actionPrivileged.selection);
277
+ const hadSelection = dataElementSelectionGroupRef.current.length > 0;
278
+ const downInOutSelection = hadSelection && makeSelection;
279
+ if (downOutTable) {
280
+ if (graph.connecting) {
281
+ graph.cancelConnect();
282
+ }
283
+ }
274
284
  if (makeSelection) {
275
285
  const boxSelection = createTableGhost({
276
286
  x,
@@ -283,78 +293,72 @@ const LayerView = (props) => {
283
293
  });
284
294
  (_a = svgRef.current) === null || _a === void 0 ? void 0 : _a.appendChild(boxSelection);
285
295
  }
296
+ if (downInOutSelection) {
297
+ handleUnSelectComponent();
298
+ }
286
299
  setPanningGroup(true);
287
- // if (!targetGroup) {
288
- // setTooltip((prev) => ({ ...prev, visible: false }));
289
- // return;
290
- // }
291
- // let ghost = targetGroup.cloneNode(true) as SVGGElement;
292
- // const ghostId = JSON.parse(targetGroup.getAttribute("data-id") || "{}");
293
- // const allowedDrag =
294
- // (!props?.dragTableBlockKey
295
- // ? true
296
- // : !props?.dragTableBlockKey?.some((_) => {
297
- // const dataRaw: any = originalData({ id: ghostId, type: "find" });
298
- // return _.value === dataRaw?.[_.key];
299
- // })) &&
300
- // actionPrivileged?.move &&
301
- // actionPrivileged?.switch;
302
- // if (ghostAttributes) {
303
- // Object.keys(ghostAttributes).forEach((key) =>
304
- // ghost.setAttribute(key, ghostAttributes[key])
305
- // );
306
- // }
307
- // ghost.setAttribute("opacity", "0.5");
308
- // ghost.setAttribute("pointer-events", "none");
309
- // ghost.setAttribute("stroke-width", "1");
310
- // svg.appendChild(ghost);
311
- // tableGhost.current = ghost;
312
- // const startBox = getTranslate(targetGroup);
313
- // const groupCTM = targetGroup.getCTM();
314
- // if (!groupCTM) {
315
- // setTooltip((prev) => ({ ...prev, visible: false }));
316
- // return;
317
- // }
318
- // const offset = { x: x - startBox.x, y: y - startBox.y };
300
+ if (!targetGroup) {
301
+ setTooltip((prev) => (Object.assign(Object.assign({}, prev), { visible: false })));
302
+ return;
303
+ }
304
+ let ghost = targetGroup.cloneNode(true);
305
+ const ghostId = JSON.parse(targetGroup.getAttribute("data-id") || "{}");
306
+ const allowedDrag = (!(props === null || props === void 0 ? void 0 : props.dragTableBlockKey)
307
+ ? true
308
+ : !((_b = props === null || props === void 0 ? void 0 : props.dragTableBlockKey) === null || _b === void 0 ? void 0 : _b.some((_) => {
309
+ const dataRaw = originalData({ id: ghostId, type: "find" });
310
+ return _.value === (dataRaw === null || dataRaw === void 0 ? void 0 : dataRaw[_.key]);
311
+ }))) &&
312
+ (actionPrivileged === null || actionPrivileged === void 0 ? void 0 : actionPrivileged.dragTable);
313
+ if (ghostAttributes) {
314
+ Object.keys(ghostAttributes).forEach((key) => ghost.setAttribute(key, ghostAttributes[key]));
315
+ }
316
+ if (allowedDrag) {
317
+ (_c = e.dataTransfer) === null || _c === void 0 ? void 0 : _c.setData("application/json", JSON.stringify(ghostId));
318
+ const dataRaw = originalData({ id: ghostId, type: "find" });
319
+ (actionPrivileged === null || actionPrivileged === void 0 ? void 0 : actionPrivileged.dragTable) && (props === null || props === void 0 ? void 0 : props.onDragTable) && props.onDragTable(e, dataRaw);
320
+ }
321
+ ghost.setAttribute("opacity", "0.5");
322
+ ghost.setAttribute("pointer-events", "none");
323
+ ghost.setAttribute("stroke-width", "1");
324
+ svg.appendChild(ghost);
325
+ tableGhost.current = ghost;
326
+ const startBox = getTranslate(targetGroup);
327
+ const groupCTM = targetGroup.getCTM();
328
+ if (!groupCTM) {
329
+ setTooltip((prev) => (Object.assign(Object.assign({}, prev), { visible: false })));
330
+ return;
331
+ }
332
+ const offset = { x: x - startBox.x, y: y - startBox.y };
319
333
  const pointerMoveGhost = (ev) => {
320
- // console.log({ makeSelection });
321
- // if (allowedDrag) {
322
- // isDragging.current = true;
323
- // const p = svg.createSVGPoint();
324
- // p.x = ev.clientX;
325
- // p.y = ev.clientY;
326
- // const dx = ev.clientX - startX;
327
- // const dy = ev.clientY - startY;
328
- // onPanning(ev);
329
- // if (!hasMoved && Math.sqrt(dx * dx + dy * dy) > 0) {
330
- // hasMoved = true;
331
- // }
332
- // ghost.style.display = "none";
333
- // const elemUnderPointer = document.elementFromPoint(
334
- // ev.clientX,
335
- // ev.clientY
336
- // );
337
- // ghost.style.display = "";
338
- // const hoveredGroup = elemUnderPointer?.closest(
339
- // "g[data-id]"
340
- // ) as SVGGElement | null;
341
- // const dataHoveredGhostId = JSON.parse(
342
- // hoveredGroup?.getAttribute("data-id") || "{}"
343
- // );
344
- // const dataGhostId = JSON.parse(ghost.getAttribute("data-id") || "{}");
345
- // if (dataHoveredGhostId !== dataGhostId)
346
- // hoverUnderghostId.current = dataHoveredGhostId;
347
- // const posSVG = p.matrixTransform(svg.getScreenCTM()?.inverse());
348
- // ghost.setAttribute(
349
- // "transform",
350
- // `translate(${posSVG.x - offset.x}, ${posSVG.y - offset.y})`
351
- // );
352
- // }
334
+ var _a;
335
+ if (allowedDrag) {
336
+ isDragging.current = true;
337
+ const p = svg.createSVGPoint();
338
+ p.x = ev.clientX;
339
+ p.y = ev.clientY;
340
+ const dx = ev.clientX - startX;
341
+ const dy = ev.clientY - startY;
342
+ onPanning(ev);
343
+ if (!hasMoved && Math.sqrt(dx * dx + dy * dy) > 0) {
344
+ hasMoved = true;
345
+ }
346
+ ghost.style.display = "none";
347
+ const elemUnderPointer = document.elementFromPoint(ev.clientX, ev.clientY);
348
+ ghost.style.display = "";
349
+ const hoveredGroup = elemUnderPointer === null || elemUnderPointer === void 0 ? void 0 : elemUnderPointer.closest("g[data-id]");
350
+ const dataHoveredGhostId = JSON.parse((hoveredGroup === null || hoveredGroup === void 0 ? void 0 : hoveredGroup.getAttribute("data-id")) || "{}");
351
+ const dataGhostId = JSON.parse(ghost.getAttribute("data-id") || "{}");
352
+ if (dataHoveredGhostId !== dataGhostId)
353
+ hoverUnderghostId.current = dataHoveredGhostId;
354
+ const posSVG = p.matrixTransform((_a = svg.getScreenCTM()) === null || _a === void 0 ? void 0 : _a.inverse());
355
+ ghost.setAttribute("transform", `translate(${posSVG.x - offset.x}, ${posSVG.y - offset.y})`);
356
+ }
353
357
  const pt = svg.createSVGPoint();
354
358
  pt.x = ev.clientX;
355
359
  pt.y = ev.clientY;
356
360
  const pos = pt.matrixTransform(svg.getScreenCTM().inverse());
357
- const onMakeSelectionBox = (ev) => {
361
+ const onMakeSelectionBox = () => {
358
362
  var _a, _b;
359
363
  let selectionBoxGhost = svg.querySelector("#selection-box-ghost");
360
364
  const selX = Math.min(pos.x, x);
@@ -395,11 +399,11 @@ const LayerView = (props) => {
395
399
  dataElementSelectionGroupRef.current = selectedComps;
396
400
  };
397
401
  if (makeSelection)
398
- onMakeSelectionBox(ev);
402
+ onMakeSelectionBox();
399
403
  };
400
404
  pointerMoveGhost(e.nativeEvent);
401
405
  const pointerHandleUp = (e) => {
402
- var _a, _b;
406
+ var _a, _b, _c;
403
407
  if (targetGroup) {
404
408
  const dataId = JSON.parse(targetGroup.getAttribute("data-id") || "{}");
405
409
  isDragging.current = false;
@@ -435,11 +439,46 @@ const LayerView = (props) => {
435
439
  clickTimerRef.current = null;
436
440
  }, DOUBLE_DELAY);
437
441
  }
438
- if (makeSelection) {
439
- const allTableInSelection = (_a = dataElementSelectionGroupRef.current) === null || _a === void 0 ? void 0 : _a.map((d) => d.id);
440
- const filterTableInSelection = componentProps === null || componentProps === void 0 ? void 0 : componentProps.filter((item) => { var _a, _b; return ((_a = item === null || item === void 0 ? void 0 : item[mappingKey]) === null || _a === void 0 ? void 0 : _a.id) && (allTableInSelection === null || allTableInSelection === void 0 ? void 0 : allTableInSelection.includes((_b = item === null || item === void 0 ? void 0 : item[mappingKey]) === null || _b === void 0 ? void 0 : _b.id)); });
442
+ if (makeSelection && ((_a = dataElementSelectionGroupRef.current) === null || _a === void 0 ? void 0 : _a.length) > 0) {
443
+ const allTableInSelection = (_b = dataElementSelectionGroupRef.current) === null || _b === void 0 ? void 0 : _b.map((d) => d.id);
444
+ const filterTableInSelection = componentProps === null || componentProps === void 0 ? void 0 : componentProps.filter((item) => {
445
+ var _a, _b;
446
+ return ((_a = item === null || item === void 0 ? void 0 : item[mappingKey]) === null || _a === void 0 ? void 0 : _a.id) &&
447
+ (allTableInSelection === null || allTableInSelection === void 0 ? void 0 : allTableInSelection.includes((_b = item === null || item === void 0 ? void 0 : item[mappingKey]) === null || _b === void 0 ? void 0 : _b.id));
448
+ });
441
449
  onMakeSelection && onMakeSelection(filterTableInSelection);
442
- (_b = svg.querySelector("#selection-box-ghost")) === null || _b === void 0 ? void 0 : _b.remove();
450
+ let xs = [];
451
+ let ys = [];
452
+ let x2 = [];
453
+ let y2 = [];
454
+ dataElementSelectionGroupRef.current.forEach((element) => {
455
+ const activeId = element.id;
456
+ const { g } = getAttributeElement(svg, String(activeId));
457
+ const { x, y } = getTranslate(g);
458
+ const { width, height } = getGlobalBBox(svg, g);
459
+ xs.push(x);
460
+ ys.push(y);
461
+ x2.push(x + width);
462
+ y2.push(y + height);
463
+ });
464
+ const selectionBox = {
465
+ x: Math.min(...xs),
466
+ y: Math.min(...ys),
467
+ width: Math.max(...x2) - Math.min(...xs),
468
+ height: Math.max(...y2) - Math.min(...ys),
469
+ stroke: "red",
470
+ shape: "selection-box",
471
+ fill: "transparent",
472
+ id: `${Date.now()}`,
473
+ rotation: 0,
474
+ };
475
+ function hasInvalidNumber(obj) {
476
+ return Object.values(obj).some((v) => typeof v === "number" && !Number.isFinite(v));
477
+ }
478
+ if (!hasInvalidNumber(selectionBox)) {
479
+ setSelectedLines(selectionBox);
480
+ }
481
+ (_c = svg.querySelector("#selection-box-ghost")) === null || _c === void 0 ? void 0 : _c.remove();
443
482
  }
444
483
  setPanningGroup(false);
445
484
  tableGhost.current = null;
@@ -562,7 +601,7 @@ const LayerView = (props) => {
562
601
  const viewBox = isValidBoundingBox
563
602
  ? `${boundingBox.minX - (((_a = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _a === void 0 ? void 0 : _a.paddingLeft) || 0)} ${boundingBox.minY - (((_b = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _b === void 0 ? void 0 : _b.paddingTop) || 0)} ${boundingBox.width + (((_c = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _c === void 0 ? void 0 : _c.paddingRight) || 0)} ${boundingBox.height + (((_d = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _d === void 0 ? void 0 : _d.paddingBottom) || 0)}`
564
603
  : "0 0 1000 1000";
565
- const renderedElements = useMemo(() => renderElements(componentsEditor, mappingKey, tableMatchKey, statusKey), [componentsEditor, mappingKey, tableMatchKey, statusKey]);
604
+ const renderedElements = useMemo(() => renderElements(componentsEditor, mappingKey, tableMatchKey, graph.connecting), [componentsEditor, mappingKey, tableMatchKey, statusKey, graph.connecting]);
566
605
  return (<div className="relative w-full h-full flex-1" ref={containerRef} style={{ overflow: "auto", WebkitOverflowScrolling: "touch" }} {...props.containerProps}>
567
606
  {loading && (<div className="absolute z-10 top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-opacity-50 bg-white w-full h-full flex items-center justify-center">
568
607
  {(loadingRender === null || loadingRender === void 0 ? void 0 : loadingRender.element) || <Spin />}
@@ -570,7 +609,9 @@ const LayerView = (props) => {
570
609
 
571
610
  <TransformWrapper ref={transformRef} disablePadding={true} centerZoomedOut={true} panning={{ disabled: panningGroup, wheelPanning: true }} wheel={{ disabled: false }} onTransformed={({ state: { scale } }) => setScale(scale)} minScale={1} maxScale={1000} initialScale={1} smooth={true} centerOnInit={true} {...props.transformProps}>
572
611
  <TransformComponent wrapperStyle={{ width: "100%", height: "100%" }} contentStyle={{ width: "100%", height: "100%" }}>
573
- <svg id="workspace" ref={svgRef} width="100%" height="100%" overflow="hidden" viewBox={viewBox} className="h-full" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid meet" onContextMenu={(e) => e.preventDefault()} onDrop={(e) => handleTableEvent(e, "drop")} onPointerDown={handlePointerDown} onPointerUp={handleMouseUp} onMouseMove={(e) => graph.onMouseMove(e)} onMouseUp={() => graph.onMouseUp()} onClick={(e) => {
612
+ <svg id="workspace" ref={svgRef} width="100%" height="100%" overflow="hidden" viewBox={viewBox} className="h-full" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid meet" onContextMenu={(e) => e.preventDefault()}
613
+ // onDrop={(e) => handleTableEvent(e, "drop")}
614
+ onPointerDown={handlePointerDown} onPointerUp={handleMouseUp} onMouseMove={(e) => graph.onMouseMove(e)} onMouseUp={() => graph.onMouseUp()} onClick={(e) => {
574
615
  // if (!graph.draggingAnchor) graph.clearSelection();
575
616
  // if (graph.connecting) graph.cancelConnect();
576
617
  }} style={{
@@ -588,20 +629,24 @@ const LayerView = (props) => {
588
629
  </defs>)}
589
630
 
590
631
  <g id="main-layer" clipPath="url(#contentCrop)">
591
- <Layers components={[...extraComponentsEditor, ...renderedElements]} selectedTable={selectedTable} iconTags={iconTags} eventMatchTable={eventMatchTable} privilegedTags={privilegedTags}/>
632
+ <Layers components={[...extraComponentsEditor, ...renderedElements]} selectedTable={selectedTable}
633
+ // iconTags={iconTags}
634
+ eventMatchTable={eventMatchTable} privilegedTags={privilegedTags} selectionLines={selectedLines}/>
592
635
  </g>
593
636
 
594
- <ConnectionLayer edges={graph.edges} selectedEdge={graph.selectedEdge} connecting={graph.connecting} draggingAnchor={graph.draggingAnchor} mousePos={graph.mousePos} getNodeById={getNodeById} onSelectEdge={graph.selectEdge} onDeleteEdge={graph.deleteEdge} onStartDragWaypoint={graph.startDragWaypoint} onInsertWaypoint={graph.insertWaypoint} onRemoveWaypoint={graph.removeWaypoint} onStartDragAnchor={graph.startDragAnchor} isConnectEdge={isConnectEdge} selectedNodeId={graph.selectedNode} isSelectNode={isSelectNode}/>
637
+ <ConnectionLayer edges={graph.edges} selectedEdge={graph.selectedEdge} connecting={graph.connecting} draggingAnchor={graph.draggingAnchor} mousePos={graph.mousePos} getNodeById={getNodeById} onSelectEdge={graph.selectEdge} onDeleteEdge={graph.deleteEdge} onStartDragWaypoint={graph.startDragWaypoint} onInsertWaypoint={graph.insertWaypoint} onRemoveWaypoint={graph.removeWaypoint} onStartDragAnchor={graph.startDragAnchor} isConnectEdge={actionPrivileged.connectingNode} selectedNodeId={graph.selectedNode}/>
595
638
 
596
639
  {renderedElements.map((item) => {
597
640
  var _a, _b, _c, _d;
598
641
  const rotated = rotatePoint(item.width / 2, item.height / 2, (_a = item.rotation) !== null && _a !== void 0 ? _a : 0);
599
- return (<ConnectHandle key={item.id} cx={item.x + rotated.x} cy={item.y + rotated.y} width={(_b = item.width) !== null && _b !== void 0 ? _b : 100} height={(_c = item.height) !== null && _c !== void 0 ? _c : 50} rotation={(_d = item.rotation) !== null && _d !== void 0 ? _d : 0} nodeId={String(item.id)} isConnecting={!!graph.connecting} isDraggingAnchor={!!graph.draggingAnchor} onStartConnect={(nodeId, clickPos) => graph.startConnect(nodeId, clickPos)} onEndConnect={(nodeId, clickPos) => {
642
+ return (<ConnectHandle key={item.id}
643
+ // isAnchor={true}
644
+ connecting={graph.connecting} cx={item.x + rotated.x} cy={item.y + rotated.y} width={(_b = item.width) !== null && _b !== void 0 ? _b : 100} height={(_c = item.height) !== null && _c !== void 0 ? _c : 50} rotation={(_d = item.rotation) !== null && _d !== void 0 ? _d : 0} nodeId={String(item.id)} isConnecting={!!graph.connecting} isDraggingAnchor={!!graph.draggingAnchor} onStartConnect={(nodeId, clickPos) => graph.startConnect(nodeId, clickPos)} onEndConnect={(nodeId, clickPos) => {
600
645
  if (graph.draggingAnchor)
601
646
  graph.updateAnchor(nodeId, clickPos);
602
647
  else
603
648
  graph.endConnect(nodeId, clickPos);
604
- }} isConnectEdge={isConnectEdge} onSelectNode={graph.selectNode} isSelectNode={isSelectNode} onSelectEdge={graph.selectEdge} edges={graph.edges}/>);
649
+ }} isConnectEdge={actionPrivileged.connectingNode} onSelectNode={graph.selectNode} isSelectNode={actionPrivileged.selectNode} onSelectEdge={graph.selectEdge} edges={graph.edges}/>);
605
650
  })}
606
651
  </svg>
607
652
 
@@ -49,7 +49,7 @@ export const useConnectionGraph = ({ svgRef, getNodeById, onEdgesChange, keyNode
49
49
  },
50
50
  ];
51
51
  });
52
- setConnecting(null);
52
+ // setConnecting(null);
53
53
  }, [connecting]);
54
54
  const cancelConnect = useCallback(() => setConnecting(null), []);
55
55
  // ── Drag endpoint ────────────────────────────────────────────────
@@ -49,4 +49,10 @@ export declare const buildPath: (points: {
49
49
  x: number;
50
50
  y: number;
51
51
  }[]) => string;
52
- export declare const renderElements: (elementEditor: ComponentProps[], mappingKey?: string, tableMatchKey?: TableMatchKey[], statusKey?: string) => ComponentProps[];
52
+ export declare const renderElements: (elementEditor: ComponentProps[], mappingKey?: string, tableMatchKey?: TableMatchKey[], connecting?: {
53
+ fromId: string;
54
+ fromPos: {
55
+ x: number;
56
+ y: number;
57
+ };
58
+ } | null) => ComponentProps[];
@@ -38,13 +38,15 @@ export const buildPath = (points) => {
38
38
  if (points.length < 2)
39
39
  return "";
40
40
  const start = points[0];
41
+ if (!start)
42
+ return "";
41
43
  const end = points[points.length - 1];
42
44
  if (points.length === 2) {
43
45
  // Quadratic bezier — 1 control point di tengah, digeser tegak lurus
44
- const mx = (start.x + end.x) / 2;
45
- const my = (start.y + end.y) / 2;
46
- const dx = end.x - start.x;
47
- const dy = end.y - start.y;
46
+ const mx = ((start === null || start === void 0 ? void 0 : start.x) + (end === null || end === void 0 ? void 0 : end.x)) / 2;
47
+ const my = ((start === null || start === void 0 ? void 0 : start.y) + (end === null || end === void 0 ? void 0 : end.y)) / 2;
48
+ const dx = end.x - (start === null || start === void 0 ? void 0 : start.x);
49
+ const dy = end.y - (start === null || start === void 0 ? void 0 : start.y);
48
50
  const dist = Math.sqrt(dx * dx + dy * dy);
49
51
  const bend = Math.min(dist * 0.35, 80);
50
52
  // Control point tegak lurus dari midpoint
@@ -65,15 +67,21 @@ export const buildPath = (points) => {
65
67
  return d;
66
68
  };
67
69
  // ─── renderElements ──────────────────────────────────────────────────────────
68
- export const renderElements = (elementEditor, mappingKey, tableMatchKey, statusKey) => {
70
+ export const renderElements = (elementEditor, mappingKey, tableMatchKey, connecting) => {
69
71
  return elementEditor.map((editorItem) => {
72
+ var _a;
70
73
  const isUsingMapping = mappingKey &&
71
74
  typeof editorItem[mappingKey] === "object" &&
72
75
  editorItem[mappingKey] !== null;
73
76
  let finalProps = isUsingMapping ? editorItem[mappingKey] : editorItem;
74
77
  if (tableMatchKey) {
75
- const tableMatch = tableMatchKey.find((item) => item.key == (editorItem === null || editorItem === void 0 ? void 0 : editorItem[statusKey]));
76
- finalProps = Object.assign(Object.assign(Object.assign({}, finalProps), tableMatch === null || tableMatch === void 0 ? void 0 : tableMatch.properties), { className: tableMatch === null || tableMatch === void 0 ? void 0 : tableMatch.className });
78
+ const tableMatch = tableMatchKey.find((item) => {
79
+ const hasKey = Object.keys(editorItem).some((key) => key == item.key);
80
+ if (hasKey)
81
+ return item.value == (editorItem === null || editorItem === void 0 ? void 0 : editorItem[item.key]);
82
+ });
83
+ const fill = (connecting === null || connecting === void 0 ? void 0 : connecting.fromId) == (finalProps === null || finalProps === void 0 ? void 0 : finalProps.id) ? "#7239EA" : (_a = tableMatch === null || tableMatch === void 0 ? void 0 : tableMatch.properties.fill) !== null && _a !== void 0 ? _a : finalProps === null || finalProps === void 0 ? void 0 : finalProps.fill;
84
+ finalProps = Object.assign(Object.assign(Object.assign({}, finalProps), tableMatch === null || tableMatch === void 0 ? void 0 : tableMatch.properties), { fill: fill, className: tableMatch === null || tableMatch === void 0 ? void 0 : tableMatch.className, element: tableMatch === null || tableMatch === void 0 ? void 0 : tableMatch.element });
77
85
  }
78
86
  return finalProps;
79
87
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seat-editor",
3
- "version": "3.6.7",
3
+ "version": "3.6.9",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",