seat-editor 3.6.26 → 3.6.28

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.
@@ -28,7 +28,7 @@ const LayerView = (props) => {
28
28
  selectNode: false,
29
29
  connectingNode: false,
30
30
  dragTransferTable: false,
31
- }, onMakeSelection, groupSelection, onHoldTable } = props;
31
+ }, onMakeSelection, groupSelection, onHoldTable, showConnection, connectionMatchKey } = props;
32
32
  const widthTooltip = (tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.minWidth) || 168;
33
33
  const tableGhost = useRef(null);
34
34
  const hoverUnderghostId = useRef(null);
@@ -287,7 +287,7 @@ const LayerView = (props) => {
287
287
  const downInOutSelection = hadSelection && makeSelection && e.button !== 2;
288
288
  const unSelectAll = hadSelection && e.button === 2 && targetGroup && !targetSelectionGroup;
289
289
  const hasSelectionDownOutSelection = !targetSelectionGroup && targetGroup && hadSelection;
290
- if (downOutTable) {
290
+ if (downOutTable || (!targetGroup && !targetSelectionGroup)) {
291
291
  if (graph.connecting) {
292
292
  graph.cancelConnect();
293
293
  }
@@ -617,11 +617,12 @@ const LayerView = (props) => {
617
617
  };
618
618
  // ─── Node helper ──────────────────────────────────────────────────────────
619
619
  const getNodeById = useCallback((id) => {
620
- var _a, _b, _c;
620
+ var _a, _b, _c, _d;
621
621
  const comp = componentsEditor.find((item) => {
622
+ var _a, _b, _c;
622
623
  if (mappingKey && (item === null || item === void 0 ? void 0 : item[mappingKey]))
623
- return item[mappingKey].id == id;
624
- return (item === null || item === void 0 ? void 0 : item.id) == id;
624
+ return (_b = (_a = item[mappingKey]) === null || _a === void 0 ? void 0 : _a[groupSelection === null || groupSelection === void 0 ? void 0 : groupSelection.dataKey]) !== null && _b !== void 0 ? _b : item[mappingKey].id == id;
625
+ return (_c = item === null || item === void 0 ? void 0 : item[groupSelection === null || groupSelection === void 0 ? void 0 : groupSelection.dataKey]) !== null && _c !== void 0 ? _c : item.id == id;
625
626
  });
626
627
  if (!comp)
627
628
  return null;
@@ -631,7 +632,7 @@ const LayerView = (props) => {
631
632
  const rotation = (_c = v.rotation) !== null && _c !== void 0 ? _c : 0;
632
633
  const rotated = rotatePoint(w / 2, h / 2, rotation);
633
634
  return {
634
- id: String(v.id),
635
+ id: (_d = v === null || v === void 0 ? void 0 : v[groupSelection === null || groupSelection === void 0 ? void 0 : groupSelection.dataKey]) !== null && _d !== void 0 ? _d : String(v.id),
635
636
  x: v.x + rotated.x,
636
637
  y: v.y + rotated.y,
637
638
  width: w,
@@ -648,6 +649,7 @@ const LayerView = (props) => {
648
649
  mappingKey,
649
650
  tableMatchKey,
650
651
  statusKey,
652
+ initialEdges: props === null || props === void 0 ? void 0 : props.initialEdges,
651
653
  });
652
654
  // ─── Render ───────────────────────────────────────────────────────────────
653
655
  const hasBoundingBox = hasBoundingBoxRef.current;
@@ -660,7 +662,7 @@ const LayerView = (props) => {
660
662
  const viewBox = isValidBoundingBox
661
663
  ? `${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)}`
662
664
  : "0 0 1000 1000";
663
- const renderedElements = useMemo(() => renderElements(componentsEditor, mappingKey, tableMatchKey, graph.connecting, groupSelection), [
665
+ const renderedElements = useMemo(() => renderElements(componentsEditor, mappingKey, tableMatchKey, graph.connecting, groupSelection, graph.edges, connectionMatchKey), [
664
666
  componentsEditor,
665
667
  mappingKey,
666
668
  tableMatchKey,
@@ -669,6 +671,8 @@ const LayerView = (props) => {
669
671
  groupSelection === null || groupSelection === void 0 ? void 0 : groupSelection.selection,
670
672
  groupSelection === null || groupSelection === void 0 ? void 0 : groupSelection.dataKey,
671
673
  groupSelection === null || groupSelection === void 0 ? void 0 : groupSelection.colorGroupSelection,
674
+ graph.edges,
675
+ connectionMatchKey
672
676
  ]);
673
677
  return (<div className="relative w-full h-full flex-1" ref={containerRef} style={{ overflow: "auto", WebkitOverflowScrolling: "touch" }} {...props.containerProps}>
674
678
  {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">
@@ -702,19 +706,19 @@ const LayerView = (props) => {
702
706
  eventMatchTable={eventMatchTable} privilegedTags={privilegedTags} selectionLines={selectedLines}/>
703
707
  </g>
704
708
 
705
- <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}/>
709
+ <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} showConnection={showConnection} renderedElements={renderedElements} groupSelection={groupSelection} connectionMatchKey={connectionMatchKey}/>
706
710
 
707
711
  {renderedElements.map((item) => {
708
- var _a, _b, _c, _d;
712
+ var _a, _b, _c, _d, _e;
709
713
  const rotated = rotatePoint(item.width / 2, item.height / 2, (_a = item.rotation) !== null && _a !== void 0 ? _a : 0);
710
714
  return (<ConnectHandle key={item.id}
711
715
  // isAnchor={true}
712
- 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) => {
716
+ 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={(_e = item === null || item === void 0 ? void 0 : item[groupSelection === null || groupSelection === void 0 ? void 0 : groupSelection.dataKey]) !== null && _e !== void 0 ? _e : String(item.id)} isConnecting={!!graph.connecting} isDraggingAnchor={!!graph.draggingAnchor} onStartConnect={(nodeId, clickPos) => graph.startConnect(nodeId, clickPos)} onEndConnect={(nodeId, clickPos) => {
713
717
  if (graph.draggingAnchor)
714
718
  graph.updateAnchor(nodeId, clickPos);
715
719
  else
716
720
  graph.endConnect(nodeId, clickPos);
717
- }} isConnectEdge={actionPrivileged.connectingNode} onSelectNode={graph.selectNode} isSelectNode={actionPrivileged.selectNode} onSelectEdge={graph.selectEdge} edges={graph.edges}/>);
721
+ }} isConnectEdge={actionPrivileged.connectingNode} onSelectNode={graph.selectNode} isSelectNode={actionPrivileged.selectNode} onSelectEdge={graph.selectEdge} edges={graph.edges} showConnection={showConnection}/>);
718
722
  })}
719
723
  </svg>
720
724
 
@@ -11,8 +11,10 @@ export type UseConnectionGraphOptions = {
11
11
  mappingKey?: string;
12
12
  tableMatchKey?: TableMatchKey[];
13
13
  statusKey?: string;
14
+ showConnection?: boolean;
15
+ initialEdges?: EdgeType[];
14
16
  };
15
- export declare const useConnectionGraph: ({ svgRef, getNodeById, onEdgesChange, keyNode, mappingKey, tableMatchKey, statusKey, }: UseConnectionGraphOptions) => {
17
+ export declare const useConnectionGraph: ({ svgRef, onEdgesChange, keyNode, mappingKey, initialEdges, }: UseConnectionGraphOptions) => {
16
18
  edges: EdgeType[];
17
19
  setEdges: React.Dispatch<React.SetStateAction<EdgeType[]>>;
18
20
  selectedEdge: string;
@@ -22,6 +24,7 @@ export declare const useConnectionGraph: ({ svgRef, getNodeById, onEdgesChange,
22
24
  fromPos: {
23
25
  x: number;
24
26
  y: number;
27
+ name: string;
25
28
  };
26
29
  };
27
30
  draggingAnchor: DraggingAnchor;
@@ -32,16 +35,19 @@ export declare const useConnectionGraph: ({ svgRef, getNodeById, onEdgesChange,
32
35
  startConnect: (fromId: string, fromPos: {
33
36
  x: number;
34
37
  y: number;
38
+ name: string;
35
39
  }) => void;
36
40
  endConnect: (toId: string, toPos: {
37
41
  x: number;
38
42
  y: number;
43
+ name: string;
39
44
  }) => void;
40
45
  cancelConnect: () => void;
41
46
  startDragAnchor: (e: React.MouseEvent, edgeId: string, side: "from" | "to") => void;
42
47
  updateAnchor: (targetNodeId: string, newPos: {
43
48
  x: number;
44
49
  y: number;
50
+ name: string;
45
51
  }) => void;
46
52
  cancelDragAnchor: () => void;
47
53
  startDragWaypoint: (e: React.MouseEvent, edgeId: string, index: number) => void;
@@ -1,8 +1,8 @@
1
1
  // use-connection-graph.ts
2
2
  import { useCallback, useEffect, useRef, useState } from "react";
3
- import { snap } from "./utils";
3
+ import { rotatePoint, snap } from "./utils";
4
4
  import { useAppSelector } from "../../hooks/use-redux";
5
- export const useConnectionGraph = ({ svgRef, getNodeById, onEdgesChange, keyNode, mappingKey, tableMatchKey, statusKey, }) => {
5
+ export const useConnectionGraph = ({ svgRef, onEdgesChange, keyNode, mappingKey, initialEdges, }) => {
6
6
  const components = useAppSelector((state) => state.board.components);
7
7
  const [edges, setEdges] = useState([]);
8
8
  const [selectedEdge, setSelectedEdge] = useState(null);
@@ -124,7 +124,7 @@ export const useConnectionGraph = ({ svgRef, getNodeById, onEdgesChange, keyNode
124
124
  return Object.assign(Object.assign({}, ed), { waypoints: ed.waypoints.filter((_, i) => i !== index) });
125
125
  }));
126
126
  }, []);
127
- // __ Select Table
127
+ // __ Select Table
128
128
  const selectNode = useCallback((nodeId) => setSelectedNode(nodeId), []);
129
129
  // ── Select / delete ──────────────────────────────────────────────
130
130
  const selectEdge = useCallback((id) => setSelectedEdge(id), []);
@@ -168,6 +168,93 @@ export const useConnectionGraph = ({ svgRef, getNodeById, onEdgesChange, keyNode
168
168
  });
169
169
  onEdgesChange === null || onEdgesChange === void 0 ? void 0 : onEdgesChange(edges, result);
170
170
  }, [edges]);
171
+ // initialize edges
172
+ useEffect(() => {
173
+ var _a;
174
+ if (initialEdges) {
175
+ //process initial edges
176
+ const allElements = components === null || components === void 0 ? void 0 : components.map((table) => {
177
+ if (mappingKey && (table === null || table === void 0 ? void 0 : table[mappingKey])) {
178
+ return Object.assign({}, table);
179
+ }
180
+ return Object.assign({}, table);
181
+ });
182
+ // const findSourceTarget = allElements?.find(
183
+ // (el) => el.id === connecting.fromId
184
+ // );
185
+ const transformAllEdges = (_a = initialEdges === null || initialEdges === void 0 ? void 0 : initialEdges.filter((edge) => (edge === null || edge === void 0 ? void 0 : edge.status) === 1)) === null || _a === void 0 ? void 0 : _a.map((edge) => {
186
+ const fromElement = allElements === null || allElements === void 0 ? void 0 : allElements.find((el) => el.id === edge.from);
187
+ if (!fromElement)
188
+ return null;
189
+ const { x: fromX, y: fromY, rotation: fromRotation, width: fromWidth, height: fromHeight, } = fromElement;
190
+ const fromRotated = rotatePoint(fromWidth / 2, fromHeight / 2, fromRotation !== null && fromRotation !== void 0 ? fromRotation : 0);
191
+ const fromCx = fromX + fromRotated.x;
192
+ const fromCy = fromY + fromRotated.y;
193
+ let fromLx = 0;
194
+ let fromLy = 0;
195
+ const fromHw = fromWidth / 2;
196
+ const fromHh = fromHeight / 2;
197
+ if (edge.fromPos.name === "top") {
198
+ fromLx = 0;
199
+ fromLy = -fromHh;
200
+ }
201
+ else if (connecting.fromPos.name === "right") {
202
+ fromLx = fromHw;
203
+ fromLy = 0;
204
+ }
205
+ else if (connecting.fromPos.name === "bottom") {
206
+ fromLx = 0;
207
+ fromLy = fromHh;
208
+ }
209
+ else if (connecting.fromPos.name === "left") {
210
+ fromLx = -fromHw;
211
+ fromLy = 0;
212
+ }
213
+ const rad = (fromRotation * Math.PI) / 180;
214
+ const fromPos = {
215
+ x: fromCx + fromLx * Math.cos(rad) - fromLy * Math.sin(rad),
216
+ y: fromCy + fromLx * Math.sin(rad) + fromLy * Math.cos(rad),
217
+ name: edge.fromPos.name,
218
+ };
219
+ const toElement = allElements === null || allElements === void 0 ? void 0 : allElements.find((el) => el.id === edge.to);
220
+ if (!toElement)
221
+ return null;
222
+ const { x: toX, y: toY, rotation: toRotation, width: toWidth, height: toHeight, } = toElement;
223
+ const toRotated = rotatePoint(toWidth / 2, toHeight / 2, toRotation !== null && toRotation !== void 0 ? toRotation : 0);
224
+ const toCx = toX + toRotated.x;
225
+ const toCy = toY + toRotated.y;
226
+ let toLx = 0;
227
+ let toLy = 0;
228
+ const toHw = toWidth / 2;
229
+ const toHh = toHeight / 2;
230
+ if (edge.toPos.name === "top") {
231
+ toLx = 0;
232
+ toLy = -toHh;
233
+ }
234
+ else if (edge.toPos.name === "right") {
235
+ toLx = toHw;
236
+ toLy = 0;
237
+ }
238
+ else if (edge.toPos.name === "bottom") {
239
+ toLx = 0;
240
+ toLy = toHh;
241
+ }
242
+ else if (edge.toPos.name === "left") {
243
+ toLx = -toHw;
244
+ toLy = 0;
245
+ }
246
+ const rad2 = (toRotation * Math.PI) / 180;
247
+ const toPos = {
248
+ x: toCx + toLx * Math.cos(rad2) - toLy * Math.sin(rad2),
249
+ y: toCy + toLx * Math.sin(rad2) + toLy * Math.cos(rad2),
250
+ name: edge.toPos.name,
251
+ };
252
+ return Object.assign(Object.assign({}, edge), { from: fromElement.id, to: toElement.id, fromPos,
253
+ toPos });
254
+ });
255
+ setEdges(transformAllEdges === null || transformAllEdges === void 0 ? void 0 : transformAllEdges.filter((el) => el !== null));
256
+ }
257
+ }, [initialEdges]);
171
258
  return {
172
259
  edges,
173
260
  setEdges,
@@ -191,6 +278,6 @@ export const useConnectionGraph = ({ svgRef, getNodeById, onEdgesChange, keyNode
191
278
  clearSelection,
192
279
  onMouseMove,
193
280
  onMouseUp,
194
- selectNode
281
+ selectNode,
195
282
  };
196
283
  };
@@ -10,15 +10,18 @@ export type EdgeType = {
10
10
  fromPos?: {
11
11
  x: number;
12
12
  y: number;
13
+ name: string;
13
14
  };
14
15
  toPos?: {
15
16
  x: number;
16
17
  y: number;
18
+ name: string;
17
19
  };
18
20
  waypoints: {
19
21
  x: number;
20
22
  y: number;
21
23
  }[];
24
+ status?: number;
22
25
  };
23
26
  export type NodeType = {
24
27
  id: string;
@@ -59,4 +62,7 @@ export declare const renderElements: (elementEditor: ComponentProps[], mappingKe
59
62
  colorGroupSelection: string[];
60
63
  dataKey: string;
61
64
  selection: Record<number, string[]>;
65
+ }, edges?: EdgeType[], connectionMatchKey?: {
66
+ key: string;
67
+ value: string | number;
62
68
  }) => ComponentProps[];
@@ -71,7 +71,11 @@ const findIndexByValue = (obj, targetValue) => {
71
71
  const foundEntry = Object.entries(obj).find(([_, values]) => values.includes(targetValue));
72
72
  return foundEntry ? Number(foundEntry[0]) : undefined;
73
73
  };
74
- export const renderElements = (elementEditor, mappingKey, tableMatchKey, connecting, groupSelection) => {
74
+ export const renderElements = (elementEditor, mappingKey, tableMatchKey, connecting, groupSelection, edges, connectionMatchKey) => {
75
+ var _a;
76
+ const allIDFromIdConnection = ((_a = edges === null || edges === void 0 ? void 0 : edges.filter((edge) => edge.from === (connecting === null || connecting === void 0 ? void 0 : connecting.fromId) || edge.to === (connecting === null || connecting === void 0 ? void 0 : connecting.fromId)
77
+ //bikin ed.to di merge dengan ed.from
78
+ )) === null || _a === void 0 ? void 0 : _a.map((edge) => edge.to === (connecting === null || connecting === void 0 ? void 0 : connecting.fromId) ? edge.from : edge.to)) || [];
75
79
  return elementEditor.map((editorItem) => {
76
80
  var _a, _b;
77
81
  const isUsingMapping = mappingKey &&
@@ -84,9 +88,10 @@ export const renderElements = (elementEditor, mappingKey, tableMatchKey, connect
84
88
  if (hasKey)
85
89
  return item.value == (editorItem === null || editorItem === void 0 ? void 0 : editorItem[item.key]);
86
90
  });
87
- // console.log({ finalProps })
88
91
  const findIndexSelection = findIndexByValue(groupSelection === null || groupSelection === void 0 ? void 0 : groupSelection.selection, finalProps === null || finalProps === void 0 ? void 0 : finalProps[groupSelection === null || groupSelection === void 0 ? void 0 : groupSelection.dataKey]);
89
92
  let fill = finalProps === null || finalProps === void 0 ? void 0 : finalProps.fill;
93
+ let stroke = finalProps === null || finalProps === void 0 ? void 0 : finalProps.stroke;
94
+ let seatFill = finalProps === null || finalProps === void 0 ? void 0 : finalProps.seatFill;
90
95
  if (findIndexSelection !== undefined) {
91
96
  fill = groupSelection === null || groupSelection === void 0 ? void 0 : groupSelection.colorGroupSelection[findIndexSelection];
92
97
  }
@@ -94,13 +99,20 @@ export const renderElements = (elementEditor, mappingKey, tableMatchKey, connect
94
99
  fill = (_b = tableMatch === null || tableMatch === void 0 ? void 0 : tableMatch.properties) === null || _b === void 0 ? void 0 : _b.fill;
95
100
  }
96
101
  if ((connecting === null || connecting === void 0 ? void 0 : connecting.fromId) == (finalProps === null || finalProps === void 0 ? void 0 : finalProps.id)) {
97
- fill = "#7239EA";
102
+ fill = "#F8F5FF";
103
+ stroke = "#5014D0";
104
+ }
105
+ if ((allIDFromIdConnection === null || allIDFromIdConnection === void 0 ? void 0 : allIDFromIdConnection.includes(finalProps === null || finalProps === void 0 ? void 0 : finalProps.id)) && (connecting === null || connecting === void 0 ? void 0 : connecting.fromId) !== (finalProps === null || finalProps === void 0 ? void 0 : finalProps.id)) {
106
+ fill = "#EEF6FF";
107
+ stroke = "#3E97FF";
108
+ seatFill = "#3E97FF";
109
+ }
110
+ finalProps = Object.assign(Object.assign(Object.assign({}, finalProps), tableMatch === null || tableMatch === void 0 ? void 0 : tableMatch.properties), { fill: fill, stroke, className: tableMatch === null || tableMatch === void 0 ? void 0 : tableMatch.className, element: tableMatch === null || tableMatch === void 0 ? void 0 : tableMatch.element });
111
+ }
112
+ if (connectionMatchKey) {
113
+ if (!(finalProps === null || finalProps === void 0 ? void 0 : finalProps[connectionMatchKey.key])) {
114
+ finalProps = Object.assign(Object.assign({}, finalProps), { [connectionMatchKey.key]: editorItem === null || editorItem === void 0 ? void 0 : editorItem[connectionMatchKey.key] });
98
115
  }
99
- // fill =
100
- // connecting?.fromId == finalProps?.id
101
- // ? "#7239EA"
102
- // : tableMatch?.properties?.fill ?? finalProps?.fill;
103
- 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 });
104
116
  }
105
117
  return finalProps;
106
118
  });
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "seat-editor",
3
- "version": "3.6.26",
3
+ "version": "3.6.28",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
+ "publishConfig": {
8
+ "registry": "https://registry.npmjs.org/"
9
+ },
7
10
  "files": [
8
11
  "dist"
9
12
  ],