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