seat-editor 3.4.7 → 3.5.0

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.
Files changed (108) hide show
  1. package/dist/app/constant.d.ts +1 -1
  2. package/dist/app/graph-view/page.d.ts +1 -0
  3. package/dist/app/graph-view/page.js +343 -0
  4. package/dist/app/graph-view/page.jsx +445 -0
  5. package/dist/app/graph-view-new/constant.d.ts +581 -0
  6. package/dist/app/graph-view-new/constant.js +6973 -0
  7. package/dist/app/graph-view-new/page.d.ts +1 -0
  8. package/dist/app/graph-view-new/page.js +71 -0
  9. package/dist/app/graph-view-new/page.jsx +98 -0
  10. package/dist/app/new-board/page.js +43 -7
  11. package/dist/app/new-board/page.jsx +45 -12
  12. package/dist/components/button-tools/index.js +7 -5
  13. package/dist/components/button-tools/index.jsx +21 -9
  14. package/dist/components/form-tools/label.js +9 -20
  15. package/dist/components/form-tools/label.jsx +38 -28
  16. package/dist/components/form-tools/shape.js +5 -5
  17. package/dist/components/form-tools/shape.jsx +8 -8
  18. package/dist/components/layer-v3/index.js +44 -3
  19. package/dist/components/layer-v3/index.jsx +120 -3
  20. package/dist/components/layer-v4/index.js +3 -2
  21. package/dist/components/layer-v4/index.jsx +3 -2
  22. package/dist/components/layer-v5/constant.d.ts +60 -0
  23. package/dist/components/layer-v5/constant.js +93 -0
  24. package/dist/components/layer-v5/index.d.ts +24 -0
  25. package/dist/components/layer-v5/index.js +927 -0
  26. package/dist/components/layer-v5/index.jsx +1049 -0
  27. package/dist/features/board-v3/index.js +350 -72
  28. package/dist/features/board-v3/index.jsx +369 -75
  29. package/dist/features/board-v3/resize-element.js +5 -0
  30. package/dist/features/board-v3/utils.d.ts +8 -0
  31. package/dist/features/board-v3/utils.js +23 -7
  32. package/dist/features/package/index.d.ts +2 -0
  33. package/dist/features/package/index.js +1 -1
  34. package/dist/features/package/index.jsx +6 -1
  35. package/dist/features/panel/index.d.ts +8 -0
  36. package/dist/features/panel/index.js +160 -38
  37. package/dist/features/panel/index.jsx +173 -46
  38. package/dist/features/panel/polygon.d.ts +2 -0
  39. package/dist/features/panel/polygon.js +44 -0
  40. package/dist/features/panel/polygon.jsx +70 -0
  41. package/dist/features/panel/select-tool.js +3 -0
  42. package/dist/features/panel/select-tool.jsx +3 -0
  43. package/dist/features/panel/selected-group.js +24 -26
  44. package/dist/features/panel/selected-group.jsx +56 -51
  45. package/dist/features/panel/text-tool.js +17 -2
  46. package/dist/features/panel/text-tool.jsx +19 -2
  47. package/dist/features/panel/upload-tool.js +17 -3
  48. package/dist/features/panel/upload-tool.jsx +23 -4
  49. package/dist/features/side-tool/index.js +43 -6
  50. package/dist/features/side-tool/index.jsx +47 -10
  51. package/dist/features/view-only-4/connect-handle.d.ts +13 -0
  52. package/dist/features/view-only-4/connect-handle.js +23 -0
  53. package/dist/features/view-only-4/connect-handle.jsx +30 -0
  54. package/dist/features/view-only-4/connection-layer.d.ts +21 -0
  55. package/dist/features/view-only-4/connection-layer.js +219 -0
  56. package/dist/features/view-only-4/connection-layer.jsx +291 -0
  57. package/dist/features/view-only-4/index.d.ts +99 -0
  58. package/dist/features/view-only-4/index.js +684 -0
  59. package/dist/features/view-only-4/index.jsx +722 -0
  60. package/dist/features/view-only-4/integration-guide.d.ts +0 -0
  61. package/dist/features/view-only-4/integration-guide.js +0 -0
  62. package/dist/features/view-only-4/use-connection-graph.d.ts +41 -0
  63. package/dist/features/view-only-4/use-connection-graph.js +182 -0
  64. package/dist/features/view-only-4/utils.d.ts +74 -0
  65. package/dist/features/view-only-4/utils.js +106 -0
  66. package/dist/features/view-only-5/connect-handle.d.ts +30 -0
  67. package/dist/features/view-only-5/connect-handle.js +88 -0
  68. package/dist/features/view-only-5/connect-handle.jsx +96 -0
  69. package/dist/features/view-only-5/connection-layer.d.ts +34 -0
  70. package/dist/features/view-only-5/connection-layer.js +182 -0
  71. package/dist/features/view-only-5/connection-layer.jsx +265 -0
  72. package/dist/features/view-only-5/index.d.ts +102 -0
  73. package/dist/features/view-only-5/index.js +585 -0
  74. package/dist/features/view-only-5/index.jsx +614 -0
  75. package/dist/features/view-only-5/use-connection-graph.d.ts +57 -0
  76. package/dist/features/view-only-5/use-connection-graph.js +196 -0
  77. package/dist/features/view-only-5/utils.d.ts +52 -0
  78. package/dist/features/view-only-5/utils.js +80 -0
  79. package/dist/features/view-only-6/connect-handle.d.ts +13 -0
  80. package/dist/features/view-only-6/connect-handle.js +20 -0
  81. package/dist/features/view-only-6/connect-handle.jsx +21 -0
  82. package/dist/features/view-only-6/connection-layer.d.ts +22 -0
  83. package/dist/features/view-only-6/connection-layer.js +191 -0
  84. package/dist/features/view-only-6/connection-layer.jsx +244 -0
  85. package/dist/features/view-only-6/index.d.ts +99 -0
  86. package/dist/features/view-only-6/index.js +687 -0
  87. package/dist/features/view-only-6/index.jsx +724 -0
  88. package/dist/features/view-only-6/use-connection-graph.d.ts +26 -0
  89. package/dist/features/view-only-6/use-connection-graph.js +103 -0
  90. package/dist/features/view-only-6/utils.d.ts +66 -0
  91. package/dist/features/view-only-6/utils.js +96 -0
  92. package/dist/features/view-only-7/connect-handle.d.ts +13 -0
  93. package/dist/features/view-only-7/connect-handle.js +23 -0
  94. package/dist/features/view-only-7/connect-handle.jsx +30 -0
  95. package/dist/features/view-only-7/connection-layer.d.ts +22 -0
  96. package/dist/features/view-only-7/connection-layer.js +165 -0
  97. package/dist/features/view-only-7/connection-layer.jsx +217 -0
  98. package/dist/features/view-only-7/index.d.ts +99 -0
  99. package/dist/features/view-only-7/index.js +687 -0
  100. package/dist/features/view-only-7/index.jsx +724 -0
  101. package/dist/features/view-only-7/use-connection-graph.d.ts +26 -0
  102. package/dist/features/view-only-7/use-connection-graph.js +104 -0
  103. package/dist/features/view-only-7/utils.d.ts +69 -0
  104. package/dist/features/view-only-7/utils.js +144 -0
  105. package/dist/index.d.ts +2 -1
  106. package/dist/index.js +2 -1
  107. package/dist/seat-editor.css +1 -1
  108. package/package.json +1 -1
@@ -0,0 +1,724 @@
1
+ "use client";
2
+ import React, { useEffect, useMemo, useRef, useState, useImperativeHandle, useCallback, } from "react";
3
+ import { TransformWrapper, TransformComponent, } from "react-zoom-pan-pinch";
4
+ import { useAppDispatch, useAppSelector } from "../../hooks/use-redux";
5
+ import Layers from "../../components/layer-v5";
6
+ import { getTranslate } from "../board-v3/utils";
7
+ import { Spin } from "antd";
8
+ import { rotatePoint } from "./utils";
9
+ import { renderElements } from "../view-only-4/utils";
10
+ import { useConnectionGraph } from "./use-connection-graph";
11
+ import { ConnectionLayer } from "./connection-layer";
12
+ import { ConnectHandle } from "./connect-handle";
13
+ const LayerView = (props) => {
14
+ const { componentProps, extraComponentProps, onSelectComponent, onDoubleClick,
15
+ // onCurrentStateChange,
16
+ mappingKey, statusKey, defaultBackground, defaultBoundingBox, iconTags, tooltipProps, onRightClick, allowTooltip = true, tableMatchKey, eventMatchTable, ghostAttributes, onDrop, onSwitch, refs, privilegedTags, loadingRender, actionPrivileged = {
17
+ select: true,
18
+ move: true,
19
+ switch: true,
20
+ drop: true,
21
+ rightClick: true,
22
+ double: true,
23
+ }, } = props;
24
+ const widthTooltip = (tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.minWidth) || 168;
25
+ const tableGhost = useRef(null);
26
+ const hoverUnderghostId = useRef(null);
27
+ const transformRef = useRef(null);
28
+ const containerRef = useRef(null);
29
+ const svgRef = useRef(null);
30
+ const hasBoundingBoxRef = useRef(false);
31
+ const [tooltip, setTooltip] = useState({
32
+ x: 0,
33
+ y: 0,
34
+ visible: false,
35
+ });
36
+ const isDragging = useRef(false);
37
+ const [panningGroup, setPanningGroup] = useState(false);
38
+ const [scale, setScale] = useState(1);
39
+ const [selectedTable, setSelectedTable] = useState(null);
40
+ const { components: componentsEditor, extraComponents: extraComponentsEditor, boundingBox: boundingBoxProps, } = useAppSelector((state) => state.board);
41
+ const backgroundColor = useAppSelector((state) => state.board.backgroundColor);
42
+ const { loading } = useAppSelector((state) => state.panel);
43
+ useImperativeHandle(refs, () => ({
44
+ svgRef: svgRef === null || svgRef === void 0 ? void 0 : svgRef.current,
45
+ transformRef: transformRef === null || transformRef === void 0 ? void 0 : transformRef.current,
46
+ containerRef: containerRef === null || containerRef === void 0 ? void 0 : containerRef.current,
47
+ tableGhost: tableGhost === null || tableGhost === void 0 ? void 0 : tableGhost.current,
48
+ hoverUnderghost: originalData({
49
+ id: hoverUnderghostId === null || hoverUnderghostId === void 0 ? void 0 : hoverUnderghostId.current,
50
+ type: "find",
51
+ }),
52
+ }));
53
+ const dispatch = useAppDispatch();
54
+ useEffect(() => {
55
+ if (!loading && (loadingRender === null || loadingRender === void 0 ? void 0 : loadingRender.state)) {
56
+ dispatch({ type: "panel/setLoading", payload: true });
57
+ }
58
+ // check in null
59
+ const isEmptyComponents = (componentProps === null || componentProps === void 0 ? void 0 : componentProps.length) === 0;
60
+ const isEmptyExtraComponents = (extraComponentProps === null || extraComponentProps === void 0 ? void 0 : extraComponentProps.length) === 0;
61
+ // const isEmptyBoundingBox = boundingBox === null;
62
+ if (isEmptyComponents) {
63
+ dispatch({
64
+ type: "board/setNewComponents",
65
+ payload: [],
66
+ });
67
+ setTooltip(Object.assign(Object.assign({}, tooltip), { visible: false }));
68
+ }
69
+ if (isEmptyExtraComponents) {
70
+ dispatch({
71
+ type: "board/setNewExtraComponents",
72
+ payload: [],
73
+ });
74
+ }
75
+ if ((componentProps === null || componentProps === void 0 ? void 0 : componentProps.length) > 0) {
76
+ dispatch({
77
+ type: "board/setNewComponents",
78
+ payload: componentProps,
79
+ });
80
+ setTooltip(Object.assign(Object.assign({}, tooltip), { visible: false }));
81
+ }
82
+ if ((extraComponentProps === null || extraComponentProps === void 0 ? void 0 : extraComponentProps.length) > 0) {
83
+ dispatch({
84
+ type: "board/setNewExtraComponents",
85
+ payload: extraComponentProps,
86
+ });
87
+ }
88
+ if (defaultBackground) {
89
+ dispatch({
90
+ type: "board/setBackgroundColor",
91
+ payload: defaultBackground,
92
+ });
93
+ }
94
+ // if(boundingBoxProps) {
95
+ dispatch({
96
+ type: "board/setBoundingBox",
97
+ payload: defaultBoundingBox,
98
+ });
99
+ // }
100
+ // if (loading) {
101
+ setTimeout(() => {
102
+ dispatch({ type: "panel/setLoading", payload: false });
103
+ }, 1000);
104
+ // }
105
+ }, [
106
+ componentProps,
107
+ extraComponentProps,
108
+ defaultBackground,
109
+ loadingRender === null || loadingRender === void 0 ? void 0 : loadingRender.state,
110
+ props === null || props === void 0 ? void 0 : props.viewOnly,
111
+ defaultBoundingBox,
112
+ ]);
113
+ useEffect(() => {
114
+ setTooltip(Object.assign(Object.assign({}, tooltip), { visible: false }));
115
+ }, [privilegedTags]);
116
+ // useEffect(() => {
117
+ // onCurrentStateChange &&
118
+ // onCurrentStateChange({
119
+ // components: componentsEditor as ComponentProps[],
120
+ // extraComponents: extraComponentsEditor as ComponentProps[],
121
+ // background: backgroundColor,
122
+ // boundingBox: boundingBoxProps,
123
+ // });
124
+ // }, [componentsEditor, extraComponentsEditor, boundingBoxProps]);
125
+ const originalData = ({ id, type, dataParams, }) => {
126
+ let data;
127
+ if (type === "find") {
128
+ data = componentsEditor.find((item) => {
129
+ if (mappingKey && (item === null || item === void 0 ? void 0 : item[mappingKey])) {
130
+ return item[mappingKey].id == id;
131
+ }
132
+ return (item === null || item === void 0 ? void 0 : item.id) == id;
133
+ });
134
+ }
135
+ if (type === "get" && dataParams) {
136
+ const mapped = mappingKey ? dataParams[mappingKey] : undefined;
137
+ data = mapped !== undefined ? mapped : dataParams;
138
+ }
139
+ return data;
140
+ };
141
+ const handleDoubleClick = (items, e) => {
142
+ const find = componentsEditor.find((item) => {
143
+ var _a;
144
+ if (mappingKey && (item === null || item === void 0 ? void 0 : item[mappingKey])) {
145
+ return item[mappingKey].id == ((_a = items[mappingKey]) === null || _a === void 0 ? void 0 : _a.id);
146
+ }
147
+ return (item === null || item === void 0 ? void 0 : item.id) == (items === null || items === void 0 ? void 0 : items.id);
148
+ });
149
+ onDoubleClick && (actionPrivileged === null || actionPrivileged === void 0 ? void 0 : actionPrivileged.double) && onDoubleClick(find);
150
+ const seletedTable = mappingKey ? find[mappingKey] : find;
151
+ setSelectedTable(seletedTable);
152
+ };
153
+ const handleSelectComponent = (items, e) => {
154
+ const find = componentsEditor.find((item) => {
155
+ var _a;
156
+ if (mappingKey && (item === null || item === void 0 ? void 0 : item[mappingKey])) {
157
+ return item[mappingKey].id == ((_a = items[mappingKey]) === null || _a === void 0 ? void 0 : _a.id);
158
+ }
159
+ return (item === null || item === void 0 ? void 0 : item.id) == (items === null || items === void 0 ? void 0 : items.id);
160
+ });
161
+ const rightClick = e.button === 2;
162
+ onRightClick &&
163
+ rightClick &&
164
+ (actionPrivileged === null || actionPrivileged === void 0 ? void 0 : actionPrivileged.rightClick) &&
165
+ onRightClick(e, find);
166
+ onSelectComponent &&
167
+ !rightClick &&
168
+ (actionPrivileged === null || actionPrivileged === void 0 ? void 0 : actionPrivileged.select) &&
169
+ onSelectComponent(find);
170
+ const seletedTable = mappingKey ? find[mappingKey] : find;
171
+ setSelectedTable(seletedTable);
172
+ };
173
+ const boundingBox = useMemo(() => {
174
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
175
+ if (!componentsEditor && (componentsEditor === null || componentsEditor === void 0 ? void 0 : componentsEditor.length) === 0) {
176
+ return { minX: 0, minY: 0, width: 500, height: 500 };
177
+ }
178
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
179
+ componentsEditor === null || componentsEditor === void 0 ? void 0 : componentsEditor.forEach((_, i) => {
180
+ let values = mappingKey ? _[mappingKey] : _;
181
+ if (!values)
182
+ return;
183
+ if (values === null || values === void 0 ? void 0 : values.shape) {
184
+ minX = Math.min(minX, values.x);
185
+ minY = Math.min(minY, values.y);
186
+ maxX = Math.max(maxX, values.x + values.width);
187
+ maxY = Math.max(maxY, values.y + values.height);
188
+ }
189
+ if (i === componentsEditor.length - 1 &&
190
+ (extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor.length) === 0) {
191
+ const centerX = (minX + maxX) / 2;
192
+ const centerY = (minY + maxY) / 2;
193
+ const padding = 20;
194
+ const width = maxX - minX + padding * 2;
195
+ const height = maxY - minY + padding * 2;
196
+ minX = centerX - width / 2;
197
+ minY = centerY - height / 2;
198
+ maxX = maxX - minX + padding * 2;
199
+ maxY = maxY - minY + padding * 2;
200
+ }
201
+ });
202
+ extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor.forEach((values) => {
203
+ var _a, _b, _c, _d, _e;
204
+ if (values === null || values === void 0 ? void 0 : values.shape) {
205
+ minX = Math.min(minX, values.x);
206
+ minY = Math.min(minY, values.y);
207
+ maxX = Math.max(maxX, values.x + values.width);
208
+ maxY = Math.max(maxY, values.y + values.height);
209
+ }
210
+ if ((_a = values === null || values === void 0 ? void 0 : values.shape) === null || _a === void 0 ? void 0 : _a.includes("polygon")) {
211
+ minX = Math.min(minX, (_b = values === null || values === void 0 ? void 0 : values.points) === null || _b === void 0 ? void 0 : _b.reduce((min, point) => Math.min(min, point.x), Infinity));
212
+ minY = Math.min(minY, (_c = values === null || values === void 0 ? void 0 : values.points) === null || _c === void 0 ? void 0 : _c.reduce((min, point) => Math.min(min, point.y), Infinity));
213
+ maxX = Math.max(maxX, (_d = values === null || values === void 0 ? void 0 : values.points) === null || _d === void 0 ? void 0 : _d.reduce((max, point) => Math.max(max, point.x), -Infinity));
214
+ maxY = Math.max(maxY, (_e = values === null || values === void 0 ? void 0 : values.points) === null || _e === void 0 ? void 0 : _e.reduce((max, point) => Math.max(max, point.y), -Infinity));
215
+ }
216
+ });
217
+ let backgroundHasOne = false;
218
+ if ((extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor.length) === 1 &&
219
+ ((_b = (_a = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _a === void 0 ? void 0 : _a.shape) === null || _b === void 0 ? void 0 : _b.includes("background"))) {
220
+ backgroundHasOne = true;
221
+ // console.log({ backgroundHasOne },"shini")
222
+ minX = (_c = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _c === void 0 ? void 0 : _c.x;
223
+ minY = (_d = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _d === void 0 ? void 0 : _d.y;
224
+ maxX = (_e = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _e === void 0 ? void 0 : _e.width;
225
+ maxY = (_f = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _f === void 0 ? void 0 : _f.height;
226
+ }
227
+ const hasBoundingBox = boundingBoxProps;
228
+ // const paddingY =
229
+ // maxY * (props?.viewStyles?.paddingY || 0) +
230
+ // minY * (props?.viewStyles?.paddingY || 0);
231
+ // const paddingX =
232
+ // maxX * (props?.viewStyles?.paddingX || 0) +
233
+ // minX * (props?.viewStyles?.paddingX || 0);
234
+ if (hasBoundingBox) {
235
+ hasBoundingBoxRef.current = true;
236
+ return {
237
+ minX: boundingBoxProps.x - (((_g = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _g === void 0 ? void 0 : _g.paddingLeft) || 0),
238
+ minY: boundingBoxProps.y - (((_h = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _h === void 0 ? void 0 : _h.paddingTop) || 0),
239
+ width: boundingBoxProps.width + (((_j = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _j === void 0 ? void 0 : _j.paddingRight) || 0),
240
+ height: boundingBoxProps.height + (((_k = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _k === void 0 ? void 0 : _k.paddingBottom) || 0),
241
+ };
242
+ }
243
+ // return {
244
+ // minX: minX - paddingX - (minX - paddingX) * 0.5,
245
+ // minY: minY - paddingY * 2,
246
+ // width: maxX + paddingX * 2,
247
+ // height: maxY + paddingY + (maxY + paddingY) * 0.5,
248
+ // };
249
+ // console.log(minX, minY, maxX, maxY, props?.viewStyles, "bounding box");
250
+ return {
251
+ minX: minX - (((_l = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _l === void 0 ? void 0 : _l.paddingLeft) || 0),
252
+ minY: minY - (((_m = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _m === void 0 ? void 0 : _m.paddingTop) || 0),
253
+ width: maxX + (((_o = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _o === void 0 ? void 0 : _o.paddingRight) || 0),
254
+ height: maxY + (((_p = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _p === void 0 ? void 0 : _p.paddingBottom) || 0),
255
+ };
256
+ }, [componentsEditor, extraComponentsEditor, boundingBoxProps]);
257
+ const [fingerCount, setFingerCount] = useState(0);
258
+ useEffect(() => {
259
+ const container = document.getElementById("workspace");
260
+ const handleTouchStart = (e) => {
261
+ const count = e.touches.length;
262
+ setFingerCount(count);
263
+ };
264
+ const handleTouchEnd = () => {
265
+ setFingerCount(0);
266
+ };
267
+ if (container) {
268
+ container.addEventListener("touchstart", handleTouchStart);
269
+ container.addEventListener("touchend", handleTouchEnd);
270
+ }
271
+ return () => {
272
+ if (container) {
273
+ container.removeEventListener("touchstart", handleTouchStart);
274
+ container.removeEventListener("touchend", handleTouchEnd);
275
+ }
276
+ };
277
+ }, []);
278
+ const handleTableEvent = (event, type) => {
279
+ var _a;
280
+ event.preventDefault();
281
+ // cari elemen yg diklik
282
+ const elementTarget = event.target;
283
+ if (!elementTarget)
284
+ return;
285
+ // cari group data-id terdekat
286
+ const group = elementTarget.closest("g[data-id]");
287
+ if (!group)
288
+ return;
289
+ try {
290
+ const tableId = JSON.parse(group.getAttribute("data-id") || "{}");
291
+ const dragEvent = event;
292
+ const dataTransfer = JSON.parse(((_a = dragEvent.dataTransfer) === null || _a === void 0 ? void 0 : _a.getData("application/json")) || "{}");
293
+ const data = {
294
+ targetTable: originalData({ id: tableId, type: "find" }),
295
+ sourceTable: originalData({ dataParams: dataTransfer, type: "get" }),
296
+ };
297
+ // drop from out layout editor
298
+ if (type === "drop") {
299
+ onDrop && (actionPrivileged === null || actionPrivileged === void 0 ? void 0 : actionPrivileged.drop) && onDrop(event, data);
300
+ }
301
+ // cari elemen bentuk (rect / circle / path)
302
+ const shape = group.querySelector("rect") ||
303
+ group.querySelector("circle") ||
304
+ group.querySelector("path");
305
+ if (!shape)
306
+ return;
307
+ }
308
+ catch (err) {
309
+ console.error("Invalid data-id JSON:", err);
310
+ }
311
+ };
312
+ const getSvgCoords = (e) => {
313
+ var _a;
314
+ const svg = svgRef.current;
315
+ const point = svg.createSVGPoint();
316
+ point.x = e.clientX;
317
+ point.y = e.clientY;
318
+ const transformed = point.matrixTransform((_a = svg.getScreenCTM()) === null || _a === void 0 ? void 0 : _a.inverse());
319
+ return { x: transformed.x, y: transformed.y };
320
+ };
321
+ const lastClickRef = useRef(0);
322
+ const clickTimerRef = useRef(null);
323
+ const ignoreNextRef = useRef(false);
324
+ const DOUBLE_DELAY = 250;
325
+ const handlePointerDown = (e) => {
326
+ var _a;
327
+ const svg = svgRef.current;
328
+ if (!e.isPrimary)
329
+ return;
330
+ if (!svg)
331
+ return;
332
+ isDragging.current = false;
333
+ let hasMoved = false;
334
+ const startX = e.clientX;
335
+ const startY = e.clientY;
336
+ const { x, y } = getSvgCoords(e);
337
+ const targetGroup = e.target.closest("g[data-id]");
338
+ if (!targetGroup) {
339
+ setTooltip((prev) => (Object.assign(Object.assign({}, prev), { visible: false })));
340
+ return;
341
+ }
342
+ setPanningGroup(true);
343
+ // clone element yang diklik
344
+ let ghost = targetGroup.cloneNode(true);
345
+ const ghostId = JSON.parse(targetGroup.getAttribute("data-id") || "{}");
346
+ const allowedDrag = (!(props === null || props === void 0 ? void 0 : props.dragTableBlockKey)
347
+ ? true
348
+ : !((_a = props === null || props === void 0 ? void 0 : props.dragTableBlockKey) === null || _a === void 0 ? void 0 : _a.some((_) => {
349
+ const dataRaw = originalData({ id: ghostId, type: "find" });
350
+ return _.value === (dataRaw === null || dataRaw === void 0 ? void 0 : dataRaw[_.key]);
351
+ }))) &&
352
+ (actionPrivileged === null || actionPrivileged === void 0 ? void 0 : actionPrivileged.move) &&
353
+ (actionPrivileged === null || actionPrivileged === void 0 ? void 0 : actionPrivileged.switch);
354
+ if (ghostAttributes) {
355
+ Object.keys(ghostAttributes).forEach((key) => {
356
+ ghost.setAttribute(key, ghostAttributes[key]);
357
+ });
358
+ }
359
+ ghost.setAttribute("opacity", "0.5");
360
+ ghost.setAttribute("pointer-events", "none");
361
+ ghost.setAttribute("stroke-width", "1");
362
+ svg.appendChild(ghost);
363
+ tableGhost.current = ghost;
364
+ const pt = svg.createSVGPoint();
365
+ pt.x = e.clientX;
366
+ pt.y = e.clientY;
367
+ const startBox = getTranslate(targetGroup);
368
+ const groupCTM = targetGroup.getCTM();
369
+ if (!groupCTM) {
370
+ setTooltip((prev) => (Object.assign(Object.assign({}, prev), { visible: false })));
371
+ return;
372
+ }
373
+ const offset = {
374
+ x: x - startBox.x,
375
+ y: y - startBox.y,
376
+ };
377
+ const pointerMoveGhost = (ev) => {
378
+ var _a;
379
+ if (allowedDrag) {
380
+ isDragging.current = true;
381
+ const p = svg.createSVGPoint();
382
+ p.x = ev.clientX;
383
+ p.y = ev.clientY;
384
+ const dx = ev.clientX - startX;
385
+ const dy = ev.clientY - startY;
386
+ const distance = Math.sqrt(dx * dx + dy * dy);
387
+ onPanning(ev);
388
+ if (!hasMoved && distance > 0) {
389
+ // transformRef?.current?.instance
390
+ // only move ghost if the mouse has moved more than 5 pixels
391
+ hasMoved = true;
392
+ isDragging.current = true;
393
+ }
394
+ // ✅ DETEKSI ELEMEN YANG DILEWATI POINTER
395
+ ghost.style.display = "none";
396
+ const elemUnderPointer = document.elementFromPoint(ev.clientX, ev.clientY);
397
+ ghost.style.display = "";
398
+ const hoveredGroup = elemUnderPointer === null || elemUnderPointer === void 0 ? void 0 : elemUnderPointer.closest("g[data-id]");
399
+ const dataHoveredGhostId = JSON.parse((hoveredGroup === null || hoveredGroup === void 0 ? void 0 : hoveredGroup.getAttribute("data-id")) || "{}");
400
+ const dataGhostId = JSON.parse(ghost.getAttribute("data-id") || "{}");
401
+ if (dataHoveredGhostId !== dataGhostId) {
402
+ hoverUnderghostId.current = dataHoveredGhostId;
403
+ }
404
+ const posSVG = p.matrixTransform((_a = svg.getScreenCTM()) === null || _a === void 0 ? void 0 : _a.inverse());
405
+ // posisi awal ghost di bawah kursor tanpa matrix dulu
406
+ const newX = posSVG.x - offset.x;
407
+ const newY = posSVG.y - offset.y;
408
+ ghost.setAttribute("transform", `translate(${newX}, ${newY})`);
409
+ }
410
+ };
411
+ // tampilkan ghost di posisi awal
412
+ pointerMoveGhost(e.nativeEvent);
413
+ const pointerHandleUp = (e) => {
414
+ var _a;
415
+ if (!hasMoved) {
416
+ const dataId = JSON.parse(targetGroup.getAttribute("data-id") || "{}");
417
+ isDragging.current = false;
418
+ const dataGroupEmty = !dataId;
419
+ // TOOLTIP ACTION
420
+ const svgSize = svg.getBoundingClientRect();
421
+ const widthScreeen = svgSize.width;
422
+ const heightScreen = svgSize.height;
423
+ const clientX = e.clientX;
424
+ const clientY = e.clientY;
425
+ const relX = clientX - svgSize.left;
426
+ const relY = clientY - svgSize.top;
427
+ const centerX = widthScreeen / 2;
428
+ const centerY = heightScreen / 2;
429
+ let newX = 0;
430
+ let newY = 0;
431
+ if (relX > centerX) {
432
+ newX = relX - widthTooltip;
433
+ }
434
+ else if (relX < centerX) {
435
+ newX = relX;
436
+ }
437
+ else if (relX === centerX) {
438
+ newX = relX;
439
+ }
440
+ if (relY > centerY) {
441
+ newY = relY;
442
+ }
443
+ else if (relY < centerY) {
444
+ newY = relY;
445
+ }
446
+ else if (relY === centerY) {
447
+ newY = relY;
448
+ }
449
+ const rightClick = e.button === 2 && !dataGroupEmty && allowTooltip;
450
+ setTooltip({
451
+ x: newX / scale,
452
+ y: newY / scale,
453
+ visible: rightClick,
454
+ });
455
+ const findDayaById = originalData({ id: dataId, type: "find" });
456
+ const now = Date.now();
457
+ if (ignoreNextRef.current) {
458
+ ignoreNextRef.current = false;
459
+ return;
460
+ }
461
+ const diff = now - lastClickRef.current;
462
+ if (diff < DOUBLE_DELAY) {
463
+ if (clickTimerRef.current) {
464
+ handleDoubleClick(findDayaById, e);
465
+ clearTimeout(clickTimerRef.current);
466
+ clickTimerRef.current = null;
467
+ }
468
+ ignoreNextRef.current = true;
469
+ lastClickRef.current = 0;
470
+ return;
471
+ }
472
+ lastClickRef.current = now;
473
+ clickTimerRef.current = window.setTimeout(() => {
474
+ handleSelectComponent(findDayaById, e);
475
+ clickTimerRef.current = null;
476
+ }, DOUBLE_DELAY);
477
+ }
478
+ if (isDragging.current && hasMoved && allowedDrag) {
479
+ // drag between group
480
+ // console.log("drag between group");
481
+ const dataHoveredGhost = hoverUnderghostId.current;
482
+ const sourceTable = JSON.parse(targetGroup.getAttribute("data-id") || "{}");
483
+ const data = {
484
+ targetTable: originalData({ id: dataHoveredGhost, type: "find" }),
485
+ sourceTable: originalData({ id: sourceTable, type: "find" }),
486
+ };
487
+ const allowToSwitch = onSwitch && (data === null || data === void 0 ? void 0 : data.sourceTable) && (data === null || data === void 0 ? void 0 : data.targetTable);
488
+ allowToSwitch && onSwitch(e, data);
489
+ ghost.remove();
490
+ isDragging.current = false;
491
+ (_a = tableGhost.current) === null || _a === void 0 ? void 0 : _a.remove();
492
+ tableGhost.current = null;
493
+ hoverUnderghostId.current = null;
494
+ }
495
+ setPanningGroup(false);
496
+ tableGhost.current = null;
497
+ isDragging.current = false;
498
+ window.removeEventListener("pointermove", pointerMoveGhost);
499
+ window.removeEventListener("pointerup", pointerHandleUp);
500
+ };
501
+ window.addEventListener("pointermove", pointerMoveGhost);
502
+ window.addEventListener("pointerup", pointerHandleUp);
503
+ };
504
+ const handleMouseUp = () => {
505
+ var _a;
506
+ // isDragging.current = false;
507
+ (_a = tableGhost.current) === null || _a === void 0 ? void 0 : _a.remove();
508
+ tableGhost.current = null;
509
+ };
510
+ useEffect(() => {
511
+ return () => {
512
+ var _a;
513
+ (_a = tableGhost.current) === null || _a === void 0 ? void 0 : _a.remove();
514
+ };
515
+ }, []);
516
+ const handlePan = (dx, dy) => {
517
+ var _a, _b;
518
+ const instance = (_a = transformRef.current) === null || _a === void 0 ? void 0 : _a.instance;
519
+ const setTransform = (_b = transformRef === null || transformRef === void 0 ? void 0 : transformRef.current) === null || _b === void 0 ? void 0 : _b.setTransform;
520
+ if (!instance)
521
+ return;
522
+ const bounds = instance.bounds;
523
+ const { positionX, positionY, scale } = instance.transformState;
524
+ let x = positionX + dx;
525
+ let y = positionY + dy;
526
+ if (x >= bounds.maxPositionX)
527
+ x = bounds.maxPositionX;
528
+ if (y >= bounds.maxPositionY)
529
+ y = bounds.maxPositionY;
530
+ if (y <= bounds.minPositionY)
531
+ y = bounds.minPositionY;
532
+ if (x <= bounds.minPositionX)
533
+ x = bounds.minPositionX;
534
+ setTransform(x, y, scale, 100, "linear");
535
+ };
536
+ // const instance = transformRef.current?.instance;
537
+ // console.log({ instance })
538
+ const getCoords = (e) => {
539
+ var _a;
540
+ const svg = svgRef.current;
541
+ const instance = (_a = transformRef.current) === null || _a === void 0 ? void 0 : _a.instance;
542
+ if (!svg || !instance)
543
+ return null;
544
+ const { positionX, positionY, scale } = instance.transformState;
545
+ let clientX, clientY;
546
+ if ("touches" in e && e.touches.length > 0) {
547
+ clientX = e.touches[0].clientX;
548
+ clientY = e.touches[0].clientY;
549
+ }
550
+ else if ("clientX" in e) {
551
+ clientX = e.clientX;
552
+ clientY = e.clientY;
553
+ }
554
+ else {
555
+ return null;
556
+ }
557
+ const svgRect = svg.getBoundingClientRect();
558
+ // const viewBox = svg.viewBox.baseVal;
559
+ const xLeft = (clientX - svgRect.left + positionX) / scale;
560
+ const yTop = (clientY - svgRect.top + positionY) / scale;
561
+ const xRight = clientX - svgRect.left + positionX - svgRect.width / scale;
562
+ const yBottom = clientY - svgRect.top + positionY - svgRect.height / scale;
563
+ const minX = svgRect.left + positionX;
564
+ const minY = svgRect.top + positionY;
565
+ const maxX = svgRect.right;
566
+ const maxY = svgRect.bottom;
567
+ return [
568
+ xLeft,
569
+ yTop,
570
+ Math.abs(xRight),
571
+ Math.abs(yBottom),
572
+ minX,
573
+ minY,
574
+ maxX,
575
+ maxY,
576
+ ];
577
+ };
578
+ const onPanning = (e) => {
579
+ const [xLeft, yTop, xRight, yBottom, minX, minY, maxX, maxY] = getCoords(e);
580
+ const edgeThreshold = 100;
581
+ const speedPanning = 50;
582
+ if (scale !== 1) {
583
+ if (xLeft < edgeThreshold)
584
+ handlePan(speedPanning, 0);
585
+ if (xRight < edgeThreshold)
586
+ handlePan(-speedPanning, 0);
587
+ if (yTop < edgeThreshold)
588
+ handlePan(0, speedPanning);
589
+ if (yBottom < edgeThreshold)
590
+ handlePan(0, -speedPanning);
591
+ }
592
+ };
593
+ const hasBoundingBox = hasBoundingBoxRef.current;
594
+ const isValidBoundingBox = Number.isFinite(boundingBox.minX) &&
595
+ Number.isFinite(boundingBox.minY) &&
596
+ Number.isFinite(boundingBox.width) &&
597
+ Number.isFinite(boundingBox.height) &&
598
+ boundingBox.width > 0 &&
599
+ boundingBox.height > 0;
600
+ const viewBox = isValidBoundingBox
601
+ ? `${boundingBox.minX} ${boundingBox.minY} ${boundingBox.width} ${boundingBox.height}`
602
+ : "0 0 1000 1000";
603
+ const getNodeById = useCallback((id) => {
604
+ var _a, _b, _c;
605
+ const comp = componentsEditor.find((item) => {
606
+ if (mappingKey && (item === null || item === void 0 ? void 0 : item[mappingKey]))
607
+ return item[mappingKey].id == id;
608
+ return (item === null || item === void 0 ? void 0 : item.id) == id;
609
+ });
610
+ if (!comp)
611
+ return null;
612
+ const v = mappingKey ? comp[mappingKey] : comp;
613
+ const w = (_a = v.width) !== null && _a !== void 0 ? _a : 100;
614
+ const h = (_b = v.height) !== null && _b !== void 0 ? _b : 50;
615
+ const rotation = (_c = v.rotation) !== null && _c !== void 0 ? _c : 0;
616
+ // Center node relatif ke (0,0) sebelum rotate
617
+ const localCx = w / 2;
618
+ const localCy = h / 2;
619
+ // Apply rotate(rotation, 0, 0) → rotate center sekitar top-left
620
+ const rotated = rotatePoint(localCx, localCy, rotation);
621
+ return {
622
+ id: v.id,
623
+ x: v.x + rotated.x, // center absolut X
624
+ y: v.y + rotated.y, // center absolut Y
625
+ width: w,
626
+ height: h,
627
+ rotation,
628
+ };
629
+ }, [componentsEditor, mappingKey]);
630
+ const graph = useConnectionGraph({
631
+ svgRef,
632
+ getNodeById,
633
+ // onEdgesChange: props.onEdgesChange,
634
+ // keyNode: props.keyNode,
635
+ // mappingKey,
636
+ // tableMatchKey,
637
+ // statusKey,
638
+ });
639
+ return (<div className="relative w-full h-full flex-1" ref={containerRef} style={{
640
+ overflow: "auto",
641
+ WebkitOverflowScrolling: "touch",
642
+ }} {...props.containerProps}>
643
+ {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">
644
+ {(loadingRender === null || loadingRender === void 0 ? void 0 : loadingRender.element) || <Spin />}
645
+ </div>)}
646
+
647
+ {/* {isDragging?.current && (
648
+ <div className="absolute bottom-1/2 left-1 flex gap-4 z-[10]">
649
+ <button className="p-4 bg-gray-400">+</button>
650
+ </div>
651
+ )} */}
652
+
653
+ <TransformWrapper ref={transformRef}
654
+ // disabled={fingerCount === 1 && scale === 1}
655
+ disablePadding={true} centerZoomedOut={true} panning={{
656
+ disabled: panningGroup,
657
+ wheelPanning: true,
658
+ }} wheel={{
659
+ disabled: false,
660
+ }}
661
+ // doubleClick={{
662
+ // disabled: true,
663
+ // }}
664
+ onTransformed={({ state: { scale } }) => setScale(scale)} minScale={1} maxScale={1000} initialScale={1} smooth={true} centerOnInit={true} {...props.transformProps}>
665
+ <TransformComponent wrapperStyle={{
666
+ width: "100%",
667
+ height: "100%",
668
+ // overflow: "visible",
669
+ // pointerEvents: disabled ? "none" : "auto",
670
+ }} contentStyle={{
671
+ width: "100%",
672
+ height: "100%",
673
+ // pointerEvents: disabled ? "none" : "auto",
674
+ }}>
675
+ <svg id="workspace" onContextMenu={(e) => e.preventDefault()} onDrop={(e) => handleTableEvent(e, "drop")} onPointerDown={handlePointerDown} onPointerUp={handleMouseUp} onMouseMove={(e) => graph.onMouseMove(e)} // ← tambah ini
676
+
677
+ // onMouseUp={() => graph.onMouseUp()} // ← tambah ini
678
+ onClick={() => {
679
+ graph.clearSelection();
680
+ if (graph.connecting)
681
+ graph.cancelConnect();
682
+ }} ref={svgRef} width="100%" height="100%"
683
+ // scale={5}
684
+ overflow="hidden" viewBox={viewBox} className={"h-full"} xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid meet" style={{
685
+ background: backgroundColor !== null && backgroundColor !== void 0 ? backgroundColor : defaultBackground,
686
+ display: "block",
687
+ // pointerEvents: disabled ? "none" : "all",
688
+ touchAction: "none",
689
+ userSelect: "none",
690
+ }} {...props.svgProps}>
691
+ <rect width="100%" height="100%" fill="url(#biggrid)"/>
692
+
693
+ {hasBoundingBox && (<defs>
694
+ <clipPath id="contentCrop">
695
+ <rect x={boundingBox.minX} y={boundingBox.minY} width={boundingBox.width} height={boundingBox.height}/>
696
+ </clipPath>
697
+ </defs>)}
698
+ <g id="main-layer" clipPath="url(#contentCrop)">
699
+ <Layers components={[
700
+ ...extraComponentsEditor,
701
+ ...renderElements(componentsEditor, mappingKey, tableMatchKey, statusKey),
702
+ ]} selectedTable={selectedTable} iconTags={iconTags} eventMatchTable={eventMatchTable} privilegedTags={privilegedTags}/>
703
+ </g>
704
+ {/* Connection graph layer */}
705
+ <ConnectionLayer edges={graph.edges} selectedEdge={graph.selectedEdge} connecting={graph.connecting} mousePos={graph.mousePos} getNodeById={getNodeById} onSelectEdge={graph.selectEdge}/>
706
+
707
+ {...renderElements(componentsEditor, mappingKey, tableMatchKey, statusKey).map((item) => {
708
+ var _a, _b, _c, _d;
709
+ const values = item;
710
+ const rotated = rotatePoint(values.width / 2, values.height / 2, (_a = values.rotation) !== null && _a !== void 0 ? _a : 0);
711
+ return (<ConnectHandle key={values.id} cx={values.x + rotated.x} // center absolut X
712
+ cy={values.y + rotated.y} width={(_b = values.width) !== null && _b !== void 0 ? _b : 100} rotation={(_c = values.rotation) !== null && _c !== void 0 ? _c : 0} // ← p
713
+ height={(_d = values.height) !== null && _d !== void 0 ? _d : 50} nodeId={String(values.id)} isConnecting={!!graph.connecting} onStartConnect={graph.startConnect} onEndConnect={graph.endConnect}/>);
714
+ })}
715
+ {/* 🧠 Ghost universal */}
716
+ </svg>
717
+ {tooltip.visible && (<div className={`seat-editor tooltip-container ${tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.className}`} style={Object.assign({ top: tooltip.y, left: tooltip.x, transform: `scale(${1 / scale})`, transformOrigin: "top left", minWidth: widthTooltip + "px" }, tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.style)}>
718
+ {tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.children}
719
+ </div>)}
720
+ </TransformComponent>
721
+ </TransformWrapper>
722
+ </div>);
723
+ };
724
+ export default LayerView;