seat-editor 3.6.38 → 3.6.40

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.
@@ -6,6 +6,7 @@ import { COLORS_SECTION, data, NODE_PROPERTIES } from "./constant";
6
6
  import { Button } from "antd";
7
7
  import { useMemo, useState } from "react";
8
8
  import { selection } from "./selection";
9
+ import { isEmpty } from "lodash";
9
10
  export default function GraphView() {
10
11
  const [isConnecting, setIsConnecting] = useState(false);
11
12
  const [actionPrivileged, setActionPrivileged] = useState({
@@ -18,7 +19,7 @@ export default function GraphView() {
18
19
  selection: false,
19
20
  selectNode: false,
20
21
  connectingNode: true,
21
- dragTransferTable: false
22
+ dragTransferTable: false,
22
23
  });
23
24
  const [isSelectNode, setIsSelectNode] = useState(false);
24
25
  const [sections, setSections] = useState([
@@ -109,7 +110,7 @@ export default function GraphView() {
109
110
  {
110
111
  key: "dragTransferTable",
111
112
  name: "Drag Transfer Table",
112
- }
113
+ },
113
114
  ];
114
115
  const [dataDrag, setDataDrag] = useState(null);
115
116
  console.log({ dataDrag });
@@ -143,15 +144,15 @@ export default function GraphView() {
143
144
  setDataDrag(null);
144
145
  }
145
146
  };
146
- const [edges, setEdges] = useState([]);
147
+ const [edges, setEdges] = useState(NODE_PROPERTIES);
147
148
  console.log({ edges });
148
149
  return (_jsx("div", { className: "w-full h-screen flex relative", children: _jsxs("div", { className: "flex", children: [_jsx("div", { className: "absolute top-0 left-0 z-10 flex gap-2", children: priviledged.map((item) => (_jsx(Button, { type: actionPrivileged[item.key] ? "primary" : "default", htmlType: "button", onClick: () => {
149
150
  setActionPrivileged((prev) => (Object.assign(Object.assign({}, prev), { [item.key]: !prev[item.key] })));
150
- }, children: item.name }, item.key))) }), _jsx(LayerView, { componentProps: componentSection, statusKey: "section", defaultBackground: "#1e2d4a", mappingKey: "properties", keyNode: "nodes", onEdgesChange: (edges) => {
151
- setEdges(edges);
152
- }, initialEdges: NODE_PROPERTIES, isConnectEdge: isConnecting, isSelectNode: isSelectNode, connectionMatchKey: {
151
+ }, children: item.name }, item.key))) }), _jsx(LayerView, { componentProps: componentSection, statusKey: "section", defaultBackground: "#1e2d4a", mappingKey: "properties", keyNode: "nodes", onEdgesChange: (edgesd) => {
152
+ // setEdges(edgesd);
153
+ }, initialEdges: isEmpty(edges) ? NODE_PROPERTIES : edges, isConnectEdge: isConnecting, isSelectNode: isSelectNode, connectionMatchKey: {
153
154
  key: "use_checking_availability",
154
- value: 0
155
+ value: 0,
155
156
  }, onTableMainConnection: (e) => {
156
157
  console.log({ e });
157
158
  },
@@ -187,6 +188,6 @@ export default function GraphView() {
187
188
  }, showConnection: true, groupSelection: {
188
189
  colorGroupSelection: COLORS_SECTION,
189
190
  dataKey: "uuid_table",
190
- selection: selection
191
+ selection: selection,
191
192
  } }), _jsxs("div", { className: "w-1/5 p-4", onMouseMove: handleMouseMove, onMouseLeave: handleMouseLeave, children: [_jsx("div", { id: "table" }), _jsxs("div", { className: "rounded-lg bg-white p-4", children: [_jsx("h1", { className: "text-2xl font-bold", children: "Section" }), sections.map((section) => (_jsxs("div", { className: clsx("font-bold text-white rounded-md p-2 cursor-pointer", sectionActive === section.id && "!bg-blue-500"), style: { backgroundColor: section.color }, onClick: () => setSectionActive(section.id), children: [_jsx("h2", { className: "text-lg", children: section.name }), section.items.length > 0 && (_jsx("ul", { className: "list-disc pl-5 bg-opacity-50 bg-white p-2 rounded ", children: section.items.map((item) => (_jsx("li", { children: item.name }, item.id))) }))] }, section.id)))] })] }), _jsx("div", { className: "w-1/5 p-4", children: _jsx("div", { className: "rounded-lg bg-white p-4", children: _jsx("h1", { className: "text-2xl font-bold", children: "Nodes" }) }) })] }) }));
192
193
  }
@@ -5,6 +5,7 @@ import { COLORS_SECTION, data, NODE_PROPERTIES } from "./constant";
5
5
  import { Button } from "antd";
6
6
  import { useMemo, useState } from "react";
7
7
  import { selection } from "./selection";
8
+ import { isEmpty } from "lodash";
8
9
  export default function GraphView() {
9
10
  const [isConnecting, setIsConnecting] = useState(false);
10
11
  const [actionPrivileged, setActionPrivileged] = useState({
@@ -17,7 +18,7 @@ export default function GraphView() {
17
18
  selection: false,
18
19
  selectNode: false,
19
20
  connectingNode: true,
20
- dragTransferTable: false
21
+ dragTransferTable: false,
21
22
  });
22
23
  const [isSelectNode, setIsSelectNode] = useState(false);
23
24
  const [sections, setSections] = useState([
@@ -108,7 +109,7 @@ export default function GraphView() {
108
109
  {
109
110
  key: "dragTransferTable",
110
111
  name: "Drag Transfer Table",
111
- }
112
+ },
112
113
  ];
113
114
  const [dataDrag, setDataDrag] = useState(null);
114
115
  console.log({ dataDrag });
@@ -142,7 +143,7 @@ export default function GraphView() {
142
143
  setDataDrag(null);
143
144
  }
144
145
  };
145
- const [edges, setEdges] = useState([]);
146
+ const [edges, setEdges] = useState(NODE_PROPERTIES);
146
147
  console.log({ edges });
147
148
  return (<div className="w-full h-screen flex relative">
148
149
  <div className="flex">
@@ -153,11 +154,11 @@ export default function GraphView() {
153
154
  {item.name}
154
155
  </Button>))}
155
156
  </div>
156
- <LayerView componentProps={componentSection} statusKey="section" defaultBackground="#1e2d4a" mappingKey="properties" keyNode="nodes" onEdgesChange={(edges) => {
157
- setEdges(edges);
158
- }} initialEdges={NODE_PROPERTIES} isConnectEdge={isConnecting} isSelectNode={isSelectNode} connectionMatchKey={{
157
+ <LayerView componentProps={componentSection} statusKey="section" defaultBackground="#1e2d4a" mappingKey="properties" keyNode="nodes" onEdgesChange={(edgesd) => {
158
+ // setEdges(edgesd);
159
+ }} initialEdges={isEmpty(edges) ? NODE_PROPERTIES : edges} isConnectEdge={isConnecting} isSelectNode={isSelectNode} connectionMatchKey={{
159
160
  key: "use_checking_availability",
160
- value: 0
161
+ value: 0,
161
162
  }} onTableMainConnection={(e) => {
162
163
  console.log({ e });
163
164
  }}
@@ -193,7 +194,7 @@ export default function GraphView() {
193
194
  }} showConnection={true} groupSelection={{
194
195
  colorGroupSelection: COLORS_SECTION,
195
196
  dataKey: "uuid_table",
196
- selection: selection
197
+ selection: selection,
197
198
  }}/>
198
199
  <div className="w-1/5 p-4" onMouseMove={handleMouseMove} onMouseLeave={handleMouseLeave}>
199
200
  <div id="table"/>
@@ -161,102 +161,109 @@ export const useConnectionGraph = ({ svgRef, onEdgesChange, keyNode, mappingKey,
161
161
  return () => window.removeEventListener("keydown", onKey);
162
162
  }, [deleteSelectedEdge, cancelConnect, cancelDragAnchor, clearSelection]);
163
163
  // ── onEdgesChange ────────────────────────────────────────────────
164
- useEffect(() => {
164
+ const onUpdateEdges = () => {
165
165
  const sourceToTargets = new Map();
166
166
  edges.forEach((e) => {
167
167
  if (!sourceToTargets.has(e.from))
168
168
  sourceToTargets.set(e.from, []);
169
169
  sourceToTargets.get(e.from).push(e.to);
170
170
  });
171
- const isNotEqual = !isEqual(edges, initialEdges);
172
- if (isNotEqual) {
173
- onEdgesChange === null || onEdgesChange === void 0 ? void 0 : onEdgesChange(edges);
174
- }
175
- }, [edges, onEdgesChange]);
176
- // initialize edges
171
+ onEdgesChange === null || onEdgesChange === void 0 ? void 0 : onEdgesChange(edges);
172
+ };
173
+ const hasInitialEdges = useRef(false);
174
+ // 1. useEffect Inisialisasi: Jalankan HANYA jika belum diinisialisasi
175
+ useEffect(() => {
176
+ // Jika sudah pernah inisialisasi atau data belum siap, jangan jalankan lagi
177
+ if (hasInitialEdges.current || !(initialEdges === null || initialEdges === void 0 ? void 0 : initialEdges.length) || !components)
178
+ return;
179
+ const allElements = components === null || components === void 0 ? void 0 : components.map((table) => {
180
+ if (mappingKey && (table === null || table === void 0 ? void 0 : table[mappingKey])) {
181
+ return Object.assign({}, table === null || table === void 0 ? void 0 : table[mappingKey]);
182
+ }
183
+ return Object.assign({}, table);
184
+ });
185
+ const transformAllEdges = initialEdges === null || initialEdges === void 0 ? void 0 : initialEdges.map((edge) => {
186
+ var _a, _b;
187
+ const fromElement = allElements === null || allElements === void 0 ? void 0 : allElements.find((el) => { var _a; return ((_a = el === null || el === void 0 ? void 0 : el[groupSelection === null || groupSelection === void 0 ? void 0 : groupSelection.dataKey]) !== null && _a !== void 0 ? _a : el.id) === edge.from; });
188
+ if (!fromElement)
189
+ return null;
190
+ const { x: fromX, y: fromY, rotation: fromRotation, width: fromWidth, height: fromHeight } = fromElement;
191
+ const fromRotated = rotatePoint(fromWidth / 2, fromHeight / 2, fromRotation !== null && fromRotation !== void 0 ? fromRotation : 0);
192
+ const fromCx = fromX + fromRotated.x;
193
+ const fromCy = fromY + fromRotated.y;
194
+ let fromLx = 0, 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 (edge.fromPos.name === "right") {
202
+ fromLx = fromHw;
203
+ fromLy = 0;
204
+ }
205
+ else if (edge.fromPos.name === "bottom") {
206
+ fromLx = 0;
207
+ fromLy = fromHh;
208
+ }
209
+ else if (edge.fromPos.name === "left") {
210
+ fromLx = -fromHw;
211
+ fromLy = 0;
212
+ }
213
+ const rad = ((fromRotation !== null && fromRotation !== void 0 ? fromRotation : 0) * 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) => { var _a; return ((_a = el === null || el === void 0 ? void 0 : el[groupSelection === null || groupSelection === void 0 ? void 0 : groupSelection.dataKey]) !== null && _a !== void 0 ? _a : 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, toLy = 0;
227
+ const toHw = toWidth / 2;
228
+ const toHh = toHeight / 2;
229
+ if (edge.toPos.name === "top") {
230
+ toLx = 0;
231
+ toLy = -toHh;
232
+ }
233
+ else if (edge.toPos.name === "right") {
234
+ toLx = toHw;
235
+ toLy = 0;
236
+ }
237
+ else if (edge.toPos.name === "bottom") {
238
+ toLx = 0;
239
+ toLy = toHh;
240
+ }
241
+ else if (edge.toPos.name === "left") {
242
+ toLx = -toHw;
243
+ toLy = 0;
244
+ }
245
+ const rad2 = ((toRotation !== null && toRotation !== void 0 ? toRotation : 0) * Math.PI) / 180;
246
+ const toPos = {
247
+ x: toCx + toLx * Math.cos(rad2) - toLy * Math.sin(rad2),
248
+ y: toCy + toLx * Math.sin(rad2) + toLy * Math.cos(rad2),
249
+ name: edge.toPos.name,
250
+ };
251
+ return Object.assign(Object.assign({}, edge), { from: (_a = fromElement === null || fromElement === void 0 ? void 0 : fromElement[groupSelection === null || groupSelection === void 0 ? void 0 : groupSelection.dataKey]) !== null && _a !== void 0 ? _a : fromElement.id, to: (_b = toElement === null || toElement === void 0 ? void 0 : toElement[groupSelection === null || groupSelection === void 0 ? void 0 : groupSelection.dataKey]) !== null && _b !== void 0 ? _b : toElement.id, fromPos,
252
+ toPos });
253
+ });
254
+ const filteredEdges = transformAllEdges === null || transformAllEdges === void 0 ? void 0 : transformAllEdges.filter((el) => el !== null);
255
+ // Tandai bahwa inisialisasi sukses sebelum setEdges agar useEffect kedua tidak kaget
256
+ hasInitialEdges.current = true;
257
+ setEdges(filteredEdges);
258
+ }, [initialEdges, components, groupSelection, mappingKey]); // Hapus 'edges' dari sini
259
+ // 2. useEffect Trigger Perubahan: Hanya kirim ke parent jika user memicu perubahan baru
177
260
  useEffect(() => {
178
- if (!isEqual(initialEdges, edges) && components) {
179
- //process initial edges
180
- const allElements = components === null || components === void 0 ? void 0 : components.map((table) => {
181
- if (mappingKey && (table === null || table === void 0 ? void 0 : table[mappingKey])) {
182
- return Object.assign({}, table === null || table === void 0 ? void 0 : table[mappingKey]);
183
- }
184
- return Object.assign({}, table);
185
- });
186
- const transformAllEdges = initialEdges === null || initialEdges === void 0 ? void 0 : initialEdges.map((edge) => {
187
- var _a, _b;
188
- const fromElement = allElements === null || allElements === void 0 ? void 0 : allElements.find((el) => { var _a; return ((_a = el === null || el === void 0 ? void 0 : el[groupSelection === null || groupSelection === void 0 ? void 0 : groupSelection.dataKey]) !== null && _a !== void 0 ? _a : el.id) === edge.from; });
189
- if (!fromElement)
190
- return null;
191
- const { x: fromX, y: fromY, rotation: fromRotation, width: fromWidth, height: fromHeight, } = fromElement;
192
- const fromRotated = rotatePoint(fromWidth / 2, fromHeight / 2, fromRotation !== null && fromRotation !== void 0 ? fromRotation : 0);
193
- const fromCx = fromX + fromRotated.x;
194
- const fromCy = fromY + fromRotated.y;
195
- let fromLx = 0;
196
- let fromLy = 0;
197
- const fromHw = fromWidth / 2;
198
- const fromHh = fromHeight / 2;
199
- if (edge.fromPos.name === "top") {
200
- fromLx = 0;
201
- fromLy = -fromHh;
202
- }
203
- else if (edge.fromPos.name === "right") {
204
- fromLx = fromHw;
205
- fromLy = 0;
206
- }
207
- else if (edge.fromPos.name === "bottom") {
208
- fromLx = 0;
209
- fromLy = fromHh;
210
- }
211
- else if (edge.fromPos.name === "left") {
212
- fromLx = -fromHw;
213
- fromLy = 0;
214
- }
215
- const rad = (fromRotation * Math.PI) / 180;
216
- const fromPos = {
217
- x: fromCx + fromLx * Math.cos(rad) - fromLy * Math.sin(rad),
218
- y: fromCy + fromLx * Math.sin(rad) + fromLy * Math.cos(rad),
219
- name: edge.fromPos.name,
220
- };
221
- const toElement = allElements === null || allElements === void 0 ? void 0 : allElements.find((el) => { var _a; return ((_a = el === null || el === void 0 ? void 0 : el[groupSelection === null || groupSelection === void 0 ? void 0 : groupSelection.dataKey]) !== null && _a !== void 0 ? _a : el.id) === edge.to; });
222
- if (!toElement)
223
- return null;
224
- const { x: toX, y: toY, rotation: toRotation, width: toWidth, height: toHeight, } = toElement;
225
- const toRotated = rotatePoint(toWidth / 2, toHeight / 2, toRotation !== null && toRotation !== void 0 ? toRotation : 0);
226
- const toCx = toX + toRotated.x;
227
- const toCy = toY + toRotated.y;
228
- let toLx = 0;
229
- let toLy = 0;
230
- const toHw = toWidth / 2;
231
- const toHh = toHeight / 2;
232
- if (edge.toPos.name === "top") {
233
- toLx = 0;
234
- toLy = -toHh;
235
- }
236
- else if (edge.toPos.name === "right") {
237
- toLx = toHw;
238
- toLy = 0;
239
- }
240
- else if (edge.toPos.name === "bottom") {
241
- toLx = 0;
242
- toLy = toHh;
243
- }
244
- else if (edge.toPos.name === "left") {
245
- toLx = -toHw;
246
- toLy = 0;
247
- }
248
- const rad2 = (toRotation * Math.PI) / 180;
249
- const toPos = {
250
- x: toCx + toLx * Math.cos(rad2) - toLy * Math.sin(rad2),
251
- y: toCy + toLx * Math.sin(rad2) + toLy * Math.cos(rad2),
252
- name: edge.toPos.name,
253
- };
254
- return Object.assign(Object.assign({}, edge), { from: (_a = fromElement === null || fromElement === void 0 ? void 0 : fromElement[groupSelection === null || groupSelection === void 0 ? void 0 : groupSelection.dataKey]) !== null && _a !== void 0 ? _a : fromElement.id, to: (_b = toElement === null || toElement === void 0 ? void 0 : toElement[groupSelection === null || groupSelection === void 0 ? void 0 : groupSelection.dataKey]) !== null && _b !== void 0 ? _b : toElement.id, fromPos,
255
- toPos });
256
- });
257
- setEdges(transformAllEdges === null || transformAllEdges === void 0 ? void 0 : transformAllEdges.filter((el) => el !== null));
261
+ // Hanya panggil onUpdateEdges jika inisialisasi awal sudah selesai
262
+ // DAN data edges saat ini memang berbeda dari initialEdges bawaan parent
263
+ if (hasInitialEdges.current && !isEqual(edges, initialEdges)) {
264
+ onUpdateEdges === null || onUpdateEdges === void 0 ? void 0 : onUpdateEdges();
258
265
  }
259
- }, [initialEdges, components, groupSelection, edges]);
266
+ }, [edges]);
260
267
  return {
261
268
  edges,
262
269
  setEdges,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seat-editor",
3
- "version": "3.6.38",
3
+ "version": "3.6.40",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",