seat-editor 3.4.8 → 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 (145) 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/layout.d.ts +1 -1
  11. package/dist/app/new-board/page.d.ts +1 -1
  12. package/dist/app/new-board/page.js +43 -7
  13. package/dist/app/new-board/page.jsx +45 -12
  14. package/dist/app/old-board/page.d.ts +1 -2
  15. package/dist/app/only-view/chair.d.ts +1 -1
  16. package/dist/app/only-view/chair.js +2 -10
  17. package/dist/app/only-view/page.d.ts +1 -1
  18. package/dist/app/only-view/user.d.ts +1 -1
  19. package/dist/app/only-view/user.js +2 -10
  20. package/dist/app/page.d.ts +1 -1
  21. package/dist/app/test/page.d.ts +1 -2
  22. package/dist/app/v2/page.d.ts +1 -1
  23. package/dist/components/button-tools/index.d.ts +1 -1
  24. package/dist/components/button-tools/index.js +7 -5
  25. package/dist/components/button-tools/index.jsx +21 -9
  26. package/dist/components/form-tools/label.d.ts +1 -1
  27. package/dist/components/form-tools/label.js +9 -20
  28. package/dist/components/form-tools/label.jsx +38 -28
  29. package/dist/components/form-tools/shape.d.ts +1 -1
  30. package/dist/components/form-tools/shape.js +5 -5
  31. package/dist/components/form-tools/shape.jsx +8 -8
  32. package/dist/components/input/number-indicator.d.ts +1 -1
  33. package/dist/components/joystick/index.d.ts +1 -2
  34. package/dist/components/layer/index.d.ts +1 -1
  35. package/dist/components/layer-v2/index.d.ts +1 -1
  36. package/dist/components/layer-v3/index.d.ts +1 -1
  37. package/dist/components/layer-v3/index.js +44 -3
  38. package/dist/components/layer-v3/index.jsx +120 -3
  39. package/dist/components/layer-v4/index.d.ts +1 -1
  40. package/dist/components/layer-v5/constant.d.ts +60 -0
  41. package/dist/components/layer-v5/constant.js +93 -0
  42. package/dist/components/layer-v5/index.d.ts +24 -0
  43. package/dist/components/layer-v5/index.js +927 -0
  44. package/dist/components/layer-v5/index.jsx +1049 -0
  45. package/dist/components/lib/index.d.ts +1 -1
  46. package/dist/components/modal-preview/index.d.ts +1 -1
  47. package/dist/features/board/index.d.ts +1 -1
  48. package/dist/features/board-v2/index.d.ts +1 -2
  49. package/dist/features/board-v3/index.d.ts +1 -1
  50. package/dist/features/board-v3/index.js +350 -72
  51. package/dist/features/board-v3/index.jsx +369 -75
  52. package/dist/features/board-v3/resize-element.js +5 -0
  53. package/dist/features/board-v3/utils.d.ts +8 -0
  54. package/dist/features/board-v3/utils.js +23 -7
  55. package/dist/features/navbar/index.d.ts +1 -1
  56. package/dist/features/package/index.d.ts +3 -1
  57. package/dist/features/package/index.js +1 -1
  58. package/dist/features/package/index.jsx +6 -1
  59. package/dist/features/panel/index.d.ts +9 -1
  60. package/dist/features/panel/index.js +160 -38
  61. package/dist/features/panel/index.jsx +173 -46
  62. package/dist/features/panel/polygon.d.ts +2 -0
  63. package/dist/features/panel/polygon.js +44 -0
  64. package/dist/features/panel/polygon.jsx +70 -0
  65. package/dist/features/panel/select-tool.d.ts +1 -1
  66. package/dist/features/panel/select-tool.js +3 -0
  67. package/dist/features/panel/select-tool.jsx +3 -0
  68. package/dist/features/panel/selected-group.d.ts +1 -1
  69. package/dist/features/panel/selected-group.js +24 -26
  70. package/dist/features/panel/selected-group.jsx +56 -51
  71. package/dist/features/panel/square-circle-tool.d.ts +1 -1
  72. package/dist/features/panel/table-seat-circle.d.ts +1 -1
  73. package/dist/features/panel/table-seat-square.d.ts +1 -1
  74. package/dist/features/panel/text-tool.d.ts +1 -1
  75. package/dist/features/panel/text-tool.js +17 -2
  76. package/dist/features/panel/text-tool.jsx +19 -2
  77. package/dist/features/panel/upload-tool.d.ts +1 -1
  78. package/dist/features/panel/upload-tool.js +17 -3
  79. package/dist/features/panel/upload-tool.jsx +23 -4
  80. package/dist/features/side-tool/index.d.ts +1 -1
  81. package/dist/features/side-tool/index.js +43 -6
  82. package/dist/features/side-tool/index.jsx +47 -10
  83. package/dist/features/view-only/index.d.ts +1 -1
  84. package/dist/features/view-only-2/index.d.ts +1 -1
  85. package/dist/features/view-only-3/index.d.ts +1 -1
  86. package/dist/features/view-only-4/connect-handle.d.ts +13 -0
  87. package/dist/features/view-only-4/connect-handle.js +23 -0
  88. package/dist/features/view-only-4/connect-handle.jsx +30 -0
  89. package/dist/features/view-only-4/connection-layer.d.ts +21 -0
  90. package/dist/features/view-only-4/connection-layer.js +219 -0
  91. package/dist/features/view-only-4/connection-layer.jsx +291 -0
  92. package/dist/features/view-only-4/index.d.ts +99 -0
  93. package/dist/features/view-only-4/index.js +684 -0
  94. package/dist/features/view-only-4/index.jsx +722 -0
  95. package/dist/features/view-only-4/integration-guide.d.ts +0 -0
  96. package/dist/features/view-only-4/integration-guide.js +0 -0
  97. package/dist/features/view-only-4/use-connection-graph.d.ts +41 -0
  98. package/dist/features/view-only-4/use-connection-graph.js +182 -0
  99. package/dist/features/view-only-4/utils.d.ts +74 -0
  100. package/dist/features/view-only-4/utils.js +106 -0
  101. package/dist/features/view-only-5/connect-handle.d.ts +30 -0
  102. package/dist/features/view-only-5/connect-handle.js +88 -0
  103. package/dist/features/view-only-5/connect-handle.jsx +96 -0
  104. package/dist/features/view-only-5/connection-layer.d.ts +34 -0
  105. package/dist/features/view-only-5/connection-layer.js +182 -0
  106. package/dist/features/view-only-5/connection-layer.jsx +265 -0
  107. package/dist/features/view-only-5/index.d.ts +102 -0
  108. package/dist/features/view-only-5/index.js +585 -0
  109. package/dist/features/view-only-5/index.jsx +614 -0
  110. package/dist/features/view-only-5/use-connection-graph.d.ts +57 -0
  111. package/dist/features/view-only-5/use-connection-graph.js +196 -0
  112. package/dist/features/view-only-5/utils.d.ts +52 -0
  113. package/dist/features/view-only-5/utils.js +80 -0
  114. package/dist/features/view-only-6/connect-handle.d.ts +13 -0
  115. package/dist/features/view-only-6/connect-handle.js +20 -0
  116. package/dist/features/view-only-6/connect-handle.jsx +21 -0
  117. package/dist/features/view-only-6/connection-layer.d.ts +22 -0
  118. package/dist/features/view-only-6/connection-layer.js +191 -0
  119. package/dist/features/view-only-6/connection-layer.jsx +244 -0
  120. package/dist/features/view-only-6/index.d.ts +99 -0
  121. package/dist/features/view-only-6/index.js +687 -0
  122. package/dist/features/view-only-6/index.jsx +724 -0
  123. package/dist/features/view-only-6/use-connection-graph.d.ts +26 -0
  124. package/dist/features/view-only-6/use-connection-graph.js +103 -0
  125. package/dist/features/view-only-6/utils.d.ts +66 -0
  126. package/dist/features/view-only-6/utils.js +96 -0
  127. package/dist/features/view-only-7/connect-handle.d.ts +13 -0
  128. package/dist/features/view-only-7/connect-handle.js +23 -0
  129. package/dist/features/view-only-7/connect-handle.jsx +30 -0
  130. package/dist/features/view-only-7/connection-layer.d.ts +22 -0
  131. package/dist/features/view-only-7/connection-layer.js +165 -0
  132. package/dist/features/view-only-7/connection-layer.jsx +217 -0
  133. package/dist/features/view-only-7/index.d.ts +99 -0
  134. package/dist/features/view-only-7/index.js +687 -0
  135. package/dist/features/view-only-7/index.jsx +724 -0
  136. package/dist/features/view-only-7/use-connection-graph.d.ts +26 -0
  137. package/dist/features/view-only-7/use-connection-graph.js +104 -0
  138. package/dist/features/view-only-7/utils.d.ts +69 -0
  139. package/dist/features/view-only-7/utils.js +144 -0
  140. package/dist/index.d.ts +2 -1
  141. package/dist/index.js +2 -1
  142. package/dist/provider/redux-provider.d.ts +1 -1
  143. package/dist/provider/store-provider.d.ts +1 -1
  144. package/dist/seat-editor.css +1 -1
  145. package/package.json +1 -1
@@ -0,0 +1,585 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useMemo, useRef, useState, useImperativeHandle, useCallback, } from "react";
4
+ import { TransformWrapper, TransformComponent, } from "react-zoom-pan-pinch";
5
+ import { useAppDispatch, useAppSelector } from "../../hooks/use-redux";
6
+ import Layers from "../../components/layer-v5";
7
+ import { createTableGhost, getGlobalBBox, } from "../board-v3/utils";
8
+ import { Spin } from "antd";
9
+ import { rotatePoint, renderElements } from "./utils";
10
+ import { useConnectionGraph } from "./use-connection-graph";
11
+ import { ConnectionLayer } from "./connection-layer";
12
+ import { ConnectHandle } from "./connect-handle";
13
+ import { getAttributeElement } from "../board-v3/resize-element";
14
+ const LayerView = (props) => {
15
+ const { componentProps, extraComponentProps, onSelectComponent, onDoubleClick, 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
+ }, isConnectEdge = true, isSelectNode = true, onMakeSelection } = 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 dataElementSelectionGroupRef = useRef([]);
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
+ if ((componentProps === null || componentProps === void 0 ? void 0 : componentProps.length) === 0) {
59
+ dispatch({ type: "board/setNewComponents", payload: [] });
60
+ setTooltip(Object.assign(Object.assign({}, tooltip), { visible: false }));
61
+ }
62
+ if ((extraComponentProps === null || extraComponentProps === void 0 ? void 0 : extraComponentProps.length) === 0) {
63
+ dispatch({ type: "board/setNewExtraComponents", payload: [] });
64
+ }
65
+ if ((componentProps === null || componentProps === void 0 ? void 0 : componentProps.length) > 0) {
66
+ dispatch({ type: "board/setNewComponents", payload: componentProps });
67
+ setTooltip(Object.assign(Object.assign({}, tooltip), { visible: false }));
68
+ }
69
+ if ((extraComponentProps === null || extraComponentProps === void 0 ? void 0 : extraComponentProps.length) > 0) {
70
+ dispatch({
71
+ type: "board/setNewExtraComponents",
72
+ payload: extraComponentProps,
73
+ });
74
+ }
75
+ if (defaultBackground) {
76
+ dispatch({
77
+ type: "board/setBackgroundColor",
78
+ payload: defaultBackground,
79
+ });
80
+ }
81
+ dispatch({ type: "board/setBoundingBox", payload: defaultBoundingBox });
82
+ setTimeout(() => {
83
+ dispatch({ type: "panel/setLoading", payload: false });
84
+ }, 1000);
85
+ }, [
86
+ componentProps,
87
+ extraComponentProps,
88
+ defaultBackground,
89
+ loadingRender === null || loadingRender === void 0 ? void 0 : loadingRender.state,
90
+ props === null || props === void 0 ? void 0 : props.viewOnly,
91
+ defaultBoundingBox,
92
+ ]);
93
+ useEffect(() => {
94
+ setTooltip(Object.assign(Object.assign({}, tooltip), { visible: false }));
95
+ }, [privilegedTags]);
96
+ const originalData = ({ id, type, dataParams, }) => {
97
+ let data;
98
+ if (type === "find") {
99
+ data = componentsEditor.find((item) => {
100
+ if (mappingKey && (item === null || item === void 0 ? void 0 : item[mappingKey]))
101
+ return item[mappingKey].id == id;
102
+ return (item === null || item === void 0 ? void 0 : item.id) == id;
103
+ });
104
+ }
105
+ if (type === "get" && dataParams) {
106
+ const mapped = mappingKey ? dataParams[mappingKey] : undefined;
107
+ data = mapped !== undefined ? mapped : dataParams;
108
+ }
109
+ return data;
110
+ };
111
+ const handleDoubleClick = (items, e) => {
112
+ const find = componentsEditor.find((item) => {
113
+ var _a;
114
+ if (mappingKey && (item === null || item === void 0 ? void 0 : item[mappingKey]))
115
+ return item[mappingKey].id == ((_a = items[mappingKey]) === null || _a === void 0 ? void 0 : _a.id);
116
+ return (item === null || item === void 0 ? void 0 : item.id) == (items === null || items === void 0 ? void 0 : items.id);
117
+ });
118
+ onDoubleClick && (actionPrivileged === null || actionPrivileged === void 0 ? void 0 : actionPrivileged.double) && onDoubleClick(find);
119
+ setSelectedTable(mappingKey ? find[mappingKey] : find);
120
+ };
121
+ const handleSelectComponent = (items, e) => {
122
+ const find = componentsEditor.find((item) => {
123
+ var _a;
124
+ if (mappingKey && (item === null || item === void 0 ? void 0 : item[mappingKey]))
125
+ return item[mappingKey].id == ((_a = items[mappingKey]) === null || _a === void 0 ? void 0 : _a.id);
126
+ return (item === null || item === void 0 ? void 0 : item.id) == (items === null || items === void 0 ? void 0 : items.id);
127
+ });
128
+ const rightClick = e.button === 2;
129
+ onRightClick &&
130
+ rightClick &&
131
+ (actionPrivileged === null || actionPrivileged === void 0 ? void 0 : actionPrivileged.rightClick) &&
132
+ onRightClick(e, find);
133
+ onSelectComponent &&
134
+ !rightClick &&
135
+ (actionPrivileged === null || actionPrivileged === void 0 ? void 0 : actionPrivileged.select) &&
136
+ onSelectComponent(find);
137
+ setSelectedTable(mappingKey ? find[mappingKey] : find);
138
+ };
139
+ const boundingBox = useMemo(() => {
140
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
141
+ if (!componentsEditor && (componentsEditor === null || componentsEditor === void 0 ? void 0 : componentsEditor.length) === 0) {
142
+ return { minX: 0, minY: 0, width: 500, height: 500 };
143
+ }
144
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
145
+ componentsEditor === null || componentsEditor === void 0 ? void 0 : componentsEditor.forEach((_, i) => {
146
+ let values = mappingKey ? _[mappingKey] : _;
147
+ if (!values)
148
+ return;
149
+ if (values === null || values === void 0 ? void 0 : values.shape) {
150
+ minX = Math.min(minX, values.x);
151
+ minY = Math.min(minY, values.y);
152
+ maxX = Math.max(maxX, values.x + values.width);
153
+ maxY = Math.max(maxY, values.y + values.height);
154
+ }
155
+ if (i === componentsEditor.length - 1 &&
156
+ (extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor.length) === 0) {
157
+ const centerX = (minX + maxX) / 2;
158
+ const centerY = (minY + maxY) / 2;
159
+ const padding = 20;
160
+ const width = maxX - minX + padding * 2;
161
+ const height = maxY - minY + padding * 2;
162
+ minX = centerX - width / 2;
163
+ minY = centerY - height / 2;
164
+ maxX = maxX - minX + padding * 2;
165
+ maxY = maxY - minY + padding * 2;
166
+ }
167
+ });
168
+ extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor.forEach((values) => {
169
+ var _a, _b, _c, _d, _e;
170
+ if (values === null || values === void 0 ? void 0 : values.shape) {
171
+ minX = Math.min(minX, values.x);
172
+ minY = Math.min(minY, values.y);
173
+ maxX = Math.max(maxX, values.x + values.width);
174
+ maxY = Math.max(maxY, values.y + values.height);
175
+ }
176
+ if ((_a = values === null || values === void 0 ? void 0 : values.shape) === null || _a === void 0 ? void 0 : _a.includes("polygon")) {
177
+ minX = Math.min(minX, (_b = values === null || values === void 0 ? void 0 : values.points) === null || _b === void 0 ? void 0 : _b.reduce((min, p) => Math.min(min, p.x), Infinity));
178
+ minY = Math.min(minY, (_c = values === null || values === void 0 ? void 0 : values.points) === null || _c === void 0 ? void 0 : _c.reduce((min, p) => Math.min(min, p.y), Infinity));
179
+ maxX = Math.max(maxX, (_d = values === null || values === void 0 ? void 0 : values.points) === null || _d === void 0 ? void 0 : _d.reduce((max, p) => Math.max(max, p.x), -Infinity));
180
+ maxY = Math.max(maxY, (_e = values === null || values === void 0 ? void 0 : values.points) === null || _e === void 0 ? void 0 : _e.reduce((max, p) => Math.max(max, p.y), -Infinity));
181
+ }
182
+ });
183
+ if ((extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor.length) === 1 &&
184
+ ((_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"))) {
185
+ minX = extraComponentsEditor[0].x;
186
+ minY = extraComponentsEditor[0].y;
187
+ maxX = extraComponentsEditor[0].width;
188
+ maxY = extraComponentsEditor[0].height;
189
+ }
190
+ if (boundingBoxProps) {
191
+ hasBoundingBoxRef.current = true;
192
+ return {
193
+ minX: boundingBoxProps.x - (((_c = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _c === void 0 ? void 0 : _c.paddingLeft) || 0),
194
+ minY: boundingBoxProps.y - (((_d = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _d === void 0 ? void 0 : _d.paddingTop) || 0),
195
+ width: boundingBoxProps.width + (((_e = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _e === void 0 ? void 0 : _e.paddingRight) || 0),
196
+ height: boundingBoxProps.height + (((_f = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _f === void 0 ? void 0 : _f.paddingBottom) || 0),
197
+ };
198
+ }
199
+ return {
200
+ minX: minX - (((_g = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _g === void 0 ? void 0 : _g.paddingLeft) || 0),
201
+ minY: minY - (((_h = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _h === void 0 ? void 0 : _h.paddingTop) || 0),
202
+ width: maxX + (((_j = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _j === void 0 ? void 0 : _j.paddingRight) || 0),
203
+ height: maxY + (((_k = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _k === void 0 ? void 0 : _k.paddingBottom) || 0),
204
+ };
205
+ }, [componentsEditor, extraComponentsEditor, boundingBoxProps]);
206
+ const [fingerCount, setFingerCount] = useState(0);
207
+ useEffect(() => {
208
+ const container = document.getElementById("workspace");
209
+ const handleTouchStart = (e) => setFingerCount(e.touches.length);
210
+ const handleTouchEnd = () => setFingerCount(0);
211
+ if (container) {
212
+ container.addEventListener("touchstart", handleTouchStart);
213
+ container.addEventListener("touchend", handleTouchEnd);
214
+ }
215
+ return () => {
216
+ if (container) {
217
+ container.removeEventListener("touchstart", handleTouchStart);
218
+ container.removeEventListener("touchend", handleTouchEnd);
219
+ }
220
+ };
221
+ }, []);
222
+ const handleTableEvent = (event, type) => {
223
+ var _a;
224
+ event.preventDefault();
225
+ const elementTarget = event.target;
226
+ if (!elementTarget)
227
+ return;
228
+ const group = elementTarget.closest("g[data-id]");
229
+ if (!group)
230
+ return;
231
+ try {
232
+ const tableId = JSON.parse(group.getAttribute("data-id") || "{}");
233
+ const dragEvent = event;
234
+ const dataTransfer = JSON.parse(((_a = dragEvent.dataTransfer) === null || _a === void 0 ? void 0 : _a.getData("application/json")) || "{}");
235
+ const data = {
236
+ targetTable: originalData({ id: tableId, type: "find" }),
237
+ sourceTable: originalData({ dataParams: dataTransfer, type: "get" }),
238
+ };
239
+ if (type === "drop")
240
+ onDrop && (actionPrivileged === null || actionPrivileged === void 0 ? void 0 : actionPrivileged.drop) && onDrop(event, data);
241
+ }
242
+ catch (err) {
243
+ console.error("Invalid data-id JSON:", err);
244
+ }
245
+ };
246
+ const getSvgCoords = (e) => {
247
+ var _a;
248
+ const svg = svgRef.current;
249
+ const point = svg.createSVGPoint();
250
+ point.x = e.clientX;
251
+ point.y = e.clientY;
252
+ const transformed = point.matrixTransform((_a = svg.getScreenCTM()) === null || _a === void 0 ? void 0 : _a.inverse());
253
+ return { x: transformed.x, y: transformed.y };
254
+ };
255
+ const lastClickRef = useRef(0);
256
+ const clickTimerRef = useRef(null);
257
+ const ignoreNextRef = useRef(false);
258
+ const DOUBLE_DELAY = 250;
259
+ const handlePointerDown = (e) => {
260
+ var _a;
261
+ console.log("handlePointerDown", e);
262
+ const svg = svgRef.current;
263
+ if (!e.isPrimary || !svg)
264
+ return;
265
+ isDragging.current = false;
266
+ let hasMoved = false;
267
+ const startX = e.clientX;
268
+ const startY = e.clientY;
269
+ const { x, y } = getSvgCoords(e);
270
+ const targetGroup = e.target.closest("g[data-id]");
271
+ const { clientX, clientY } = e;
272
+ const hitPoint = document.elementFromPoint(clientX, clientY);
273
+ const makeSelection = (hitPoint === null || hitPoint === void 0 ? void 0 : hitPoint.nodeName) === "svg";
274
+ if (makeSelection) {
275
+ const boxSelection = createTableGhost({
276
+ x,
277
+ y,
278
+ width: 1,
279
+ height: 1,
280
+ fill: "transparent",
281
+ shape: "selection-box",
282
+ id: "selection-box-ghost",
283
+ });
284
+ (_a = svgRef.current) === null || _a === void 0 ? void 0 : _a.appendChild(boxSelection);
285
+ }
286
+ setPanningGroup(true);
287
+ // if (!targetGroup) {
288
+ // setTooltip((prev) => ({ ...prev, visible: false }));
289
+ // return;
290
+ // }
291
+ // let ghost = targetGroup.cloneNode(true) as SVGGElement;
292
+ // const ghostId = JSON.parse(targetGroup.getAttribute("data-id") || "{}");
293
+ // const allowedDrag =
294
+ // (!props?.dragTableBlockKey
295
+ // ? true
296
+ // : !props?.dragTableBlockKey?.some((_) => {
297
+ // const dataRaw: any = originalData({ id: ghostId, type: "find" });
298
+ // return _.value === dataRaw?.[_.key];
299
+ // })) &&
300
+ // actionPrivileged?.move &&
301
+ // actionPrivileged?.switch;
302
+ // if (ghostAttributes) {
303
+ // Object.keys(ghostAttributes).forEach((key) =>
304
+ // ghost.setAttribute(key, ghostAttributes[key])
305
+ // );
306
+ // }
307
+ // ghost.setAttribute("opacity", "0.5");
308
+ // ghost.setAttribute("pointer-events", "none");
309
+ // ghost.setAttribute("stroke-width", "1");
310
+ // svg.appendChild(ghost);
311
+ // tableGhost.current = ghost;
312
+ // const startBox = getTranslate(targetGroup);
313
+ // const groupCTM = targetGroup.getCTM();
314
+ // if (!groupCTM) {
315
+ // setTooltip((prev) => ({ ...prev, visible: false }));
316
+ // return;
317
+ // }
318
+ // const offset = { x: x - startBox.x, y: y - startBox.y };
319
+ const pointerMoveGhost = (ev) => {
320
+ // console.log({ makeSelection });
321
+ // if (allowedDrag) {
322
+ // isDragging.current = true;
323
+ // const p = svg.createSVGPoint();
324
+ // p.x = ev.clientX;
325
+ // p.y = ev.clientY;
326
+ // const dx = ev.clientX - startX;
327
+ // const dy = ev.clientY - startY;
328
+ // onPanning(ev);
329
+ // if (!hasMoved && Math.sqrt(dx * dx + dy * dy) > 0) {
330
+ // hasMoved = true;
331
+ // }
332
+ // ghost.style.display = "none";
333
+ // const elemUnderPointer = document.elementFromPoint(
334
+ // ev.clientX,
335
+ // ev.clientY
336
+ // );
337
+ // ghost.style.display = "";
338
+ // const hoveredGroup = elemUnderPointer?.closest(
339
+ // "g[data-id]"
340
+ // ) as SVGGElement | null;
341
+ // const dataHoveredGhostId = JSON.parse(
342
+ // hoveredGroup?.getAttribute("data-id") || "{}"
343
+ // );
344
+ // const dataGhostId = JSON.parse(ghost.getAttribute("data-id") || "{}");
345
+ // if (dataHoveredGhostId !== dataGhostId)
346
+ // hoverUnderghostId.current = dataHoveredGhostId;
347
+ // const posSVG = p.matrixTransform(svg.getScreenCTM()?.inverse());
348
+ // ghost.setAttribute(
349
+ // "transform",
350
+ // `translate(${posSVG.x - offset.x}, ${posSVG.y - offset.y})`
351
+ // );
352
+ // }
353
+ const pt = svg.createSVGPoint();
354
+ pt.x = ev.clientX;
355
+ pt.y = ev.clientY;
356
+ const pos = pt.matrixTransform(svg.getScreenCTM().inverse());
357
+ const onMakeSelectionBox = (ev) => {
358
+ var _a, _b;
359
+ let selectionBoxGhost = svg.querySelector("#selection-box-ghost");
360
+ const selX = Math.min(pos.x, x);
361
+ const selY = Math.min(pos.y, y);
362
+ const selW = Math.abs(pos.x - x);
363
+ const selH = Math.abs(pos.y - y);
364
+ selectionBoxGhost === null || selectionBoxGhost === void 0 ? void 0 : selectionBoxGhost.setAttribute("x", String(selX));
365
+ selectionBoxGhost === null || selectionBoxGhost === void 0 ? void 0 : selectionBoxGhost.setAttribute("y", String(selY));
366
+ selectionBoxGhost === null || selectionBoxGhost === void 0 ? void 0 : selectionBoxGhost.setAttribute("width", String(selW));
367
+ selectionBoxGhost === null || selectionBoxGhost === void 0 ? void 0 : selectionBoxGhost.setAttribute("height", String(selH));
368
+ // FIND ALL COMPONENTS INSIDE SELECTION BOX
369
+ const allGroups = (_a = svgRef.current) === null || _a === void 0 ? void 0 : _a.querySelectorAll("g[data-id]");
370
+ const selLeft = selX;
371
+ const selTop = selY;
372
+ const selectedIds = [...allGroups]
373
+ .map((g) => JSON === null || JSON === void 0 ? void 0 : JSON.parse((g === null || g === void 0 ? void 0 : g.getAttribute("data-id")) || "{}"))
374
+ .filter((d) => {
375
+ const { element } = getAttributeElement(svg, d);
376
+ const box = getGlobalBBox(svg, element);
377
+ return ((box === null || box === void 0 ? void 0 : box.x) < selLeft + selW &&
378
+ (box === null || box === void 0 ? void 0 : box.x) + box.width > selLeft &&
379
+ (box === null || box === void 0 ? void 0 : box.y) < selTop + selH &&
380
+ (box === null || box === void 0 ? void 0 : box.y) + box.height > selTop);
381
+ })
382
+ .map((d) => `${d}`);
383
+ if (selectedIds.length === 0)
384
+ return;
385
+ const selectedComps = (_b = renderedElements
386
+ .filter((c) => selectedIds.map(String).includes(String(c.id)))) === null || _b === void 0 ? void 0 : _b.map((item) => {
387
+ const { g } = getAttributeElement(svg, String(item.id));
388
+ // const { x, y } = getTranslate(g);
389
+ const box = getGlobalBBox(svg, g);
390
+ return Object.assign(Object.assign({}, item), {
391
+ // x: box.x,
392
+ // y: box.y,
393
+ width: box.width, height: box.height });
394
+ });
395
+ dataElementSelectionGroupRef.current = selectedComps;
396
+ };
397
+ if (makeSelection)
398
+ onMakeSelectionBox(ev);
399
+ };
400
+ pointerMoveGhost(e.nativeEvent);
401
+ const pointerHandleUp = (e) => {
402
+ var _a, _b;
403
+ if (targetGroup) {
404
+ const dataId = JSON.parse(targetGroup.getAttribute("data-id") || "{}");
405
+ isDragging.current = false;
406
+ const svgSize = svg.getBoundingClientRect();
407
+ const relX = e.clientX - svgSize.left;
408
+ const relY = e.clientY - svgSize.top;
409
+ const centerX = svgSize.width / 2;
410
+ const centerY = svgSize.height / 2;
411
+ const newX = relX > centerX ? relX - widthTooltip : relX;
412
+ const newY = relY > centerY ? relY : relY;
413
+ const rightClick = e.button === 2 && !!dataId && allowTooltip;
414
+ setTooltip({ x: newX / scale, y: newY / scale, visible: rightClick });
415
+ const findDayaById = originalData({ id: dataId, type: "find" });
416
+ const now = Date.now();
417
+ if (ignoreNextRef.current) {
418
+ ignoreNextRef.current = false;
419
+ return;
420
+ }
421
+ const diff = now - lastClickRef.current;
422
+ if (diff < DOUBLE_DELAY) {
423
+ if (clickTimerRef.current) {
424
+ handleDoubleClick(findDayaById, e);
425
+ clearTimeout(clickTimerRef.current);
426
+ clickTimerRef.current = null;
427
+ }
428
+ ignoreNextRef.current = true;
429
+ lastClickRef.current = 0;
430
+ return;
431
+ }
432
+ lastClickRef.current = now;
433
+ clickTimerRef.current = window.setTimeout(() => {
434
+ handleSelectComponent(findDayaById, e);
435
+ clickTimerRef.current = null;
436
+ }, DOUBLE_DELAY);
437
+ }
438
+ if (makeSelection) {
439
+ const allTableInSelection = (_a = dataElementSelectionGroupRef.current) === null || _a === void 0 ? void 0 : _a.map((d) => d.id);
440
+ const filterTableInSelection = componentProps === null || componentProps === void 0 ? void 0 : componentProps.filter((item) => { var _a, _b; return ((_a = item === null || item === void 0 ? void 0 : item[mappingKey]) === null || _a === void 0 ? void 0 : _a.id) && (allTableInSelection === null || allTableInSelection === void 0 ? void 0 : allTableInSelection.includes((_b = item === null || item === void 0 ? void 0 : item[mappingKey]) === null || _b === void 0 ? void 0 : _b.id)); });
441
+ onMakeSelection && onMakeSelection(filterTableInSelection);
442
+ (_b = svg.querySelector("#selection-box-ghost")) === null || _b === void 0 ? void 0 : _b.remove();
443
+ }
444
+ setPanningGroup(false);
445
+ tableGhost.current = null;
446
+ isDragging.current = false;
447
+ window.removeEventListener("pointermove", pointerMoveGhost);
448
+ window.removeEventListener("pointerup", pointerHandleUp);
449
+ };
450
+ window.addEventListener("pointermove", pointerMoveGhost);
451
+ window.addEventListener("pointerup", pointerHandleUp);
452
+ };
453
+ const handleMouseUp = () => {
454
+ var _a;
455
+ (_a = tableGhost.current) === null || _a === void 0 ? void 0 : _a.remove();
456
+ tableGhost.current = null;
457
+ };
458
+ useEffect(() => {
459
+ return () => {
460
+ var _a;
461
+ (_a = tableGhost.current) === null || _a === void 0 ? void 0 : _a.remove();
462
+ };
463
+ }, []);
464
+ const handlePan = (dx, dy) => {
465
+ var _a, _b;
466
+ const instance = (_a = transformRef.current) === null || _a === void 0 ? void 0 : _a.instance;
467
+ const setTransform = (_b = transformRef === null || transformRef === void 0 ? void 0 : transformRef.current) === null || _b === void 0 ? void 0 : _b.setTransform;
468
+ if (!instance)
469
+ return;
470
+ const { bounds } = instance;
471
+ const { positionX, positionY, scale } = instance.transformState;
472
+ let x = Math.max(bounds.minPositionX, Math.min(bounds.maxPositionX, positionX + dx));
473
+ let y = Math.max(bounds.minPositionY, Math.min(bounds.maxPositionY, positionY + dy));
474
+ setTransform(x, y, scale, 100, "linear");
475
+ };
476
+ const getCoords = (e) => {
477
+ var _a;
478
+ const svg = svgRef.current;
479
+ const instance = (_a = transformRef.current) === null || _a === void 0 ? void 0 : _a.instance;
480
+ if (!svg || !instance)
481
+ return null;
482
+ const { positionX, positionY, scale } = instance.transformState;
483
+ let clientX, clientY;
484
+ if ("touches" in e && e.touches.length > 0) {
485
+ clientX = e.touches[0].clientX;
486
+ clientY = e.touches[0].clientY;
487
+ }
488
+ else if ("clientX" in e) {
489
+ clientX = e.clientX;
490
+ clientY = e.clientY;
491
+ }
492
+ else
493
+ return null;
494
+ const svgRect = svg.getBoundingClientRect();
495
+ return [
496
+ (clientX - svgRect.left + positionX) / scale,
497
+ (clientY - svgRect.top + positionY) / scale,
498
+ Math.abs(clientX - svgRect.left + positionX - svgRect.width / scale),
499
+ Math.abs(clientY - svgRect.top + positionY - svgRect.height / scale),
500
+ ];
501
+ };
502
+ const onPanning = (e) => {
503
+ const coords = getCoords(e);
504
+ if (!coords)
505
+ return;
506
+ const [xLeft, yTop, xRight, yBottom] = coords;
507
+ const edgeThreshold = 100;
508
+ const speedPanning = 50;
509
+ if (scale !== 1) {
510
+ if (xLeft < edgeThreshold)
511
+ handlePan(speedPanning, 0);
512
+ if (xRight < edgeThreshold)
513
+ handlePan(-speedPanning, 0);
514
+ if (yTop < edgeThreshold)
515
+ handlePan(0, speedPanning);
516
+ if (yBottom < edgeThreshold)
517
+ handlePan(0, -speedPanning);
518
+ }
519
+ };
520
+ // ─── Node helper ──────────────────────────────────────────────────────────
521
+ const getNodeById = useCallback((id) => {
522
+ var _a, _b, _c;
523
+ const comp = componentsEditor.find((item) => {
524
+ if (mappingKey && (item === null || item === void 0 ? void 0 : item[mappingKey]))
525
+ return item[mappingKey].id == id;
526
+ return (item === null || item === void 0 ? void 0 : item.id) == id;
527
+ });
528
+ if (!comp)
529
+ return null;
530
+ const v = mappingKey ? comp[mappingKey] : comp;
531
+ const w = (_a = v.width) !== null && _a !== void 0 ? _a : 100;
532
+ const h = (_b = v.height) !== null && _b !== void 0 ? _b : 50;
533
+ const rotation = (_c = v.rotation) !== null && _c !== void 0 ? _c : 0;
534
+ const rotated = rotatePoint(w / 2, h / 2, rotation);
535
+ return {
536
+ id: String(v.id),
537
+ x: v.x + rotated.x,
538
+ y: v.y + rotated.y,
539
+ width: w,
540
+ height: h,
541
+ rotation,
542
+ };
543
+ }, [componentsEditor, mappingKey]);
544
+ // ─── Connection graph ─────────────────────────────────────────────────────
545
+ const graph = useConnectionGraph({
546
+ svgRef,
547
+ getNodeById,
548
+ onEdgesChange: props.onEdgesChange,
549
+ keyNode: props.keyNode,
550
+ mappingKey,
551
+ tableMatchKey,
552
+ statusKey,
553
+ });
554
+ // ─── Render ───────────────────────────────────────────────────────────────
555
+ const hasBoundingBox = hasBoundingBoxRef.current;
556
+ const isValidBoundingBox = Number.isFinite(boundingBox.minX) &&
557
+ Number.isFinite(boundingBox.minY) &&
558
+ Number.isFinite(boundingBox.width) &&
559
+ Number.isFinite(boundingBox.height) &&
560
+ boundingBox.width > 0 &&
561
+ boundingBox.height > 0;
562
+ const viewBox = isValidBoundingBox
563
+ ? `${boundingBox.minX} ${boundingBox.minY} ${boundingBox.width} ${boundingBox.height}`
564
+ : "0 0 1000 1000";
565
+ const renderedElements = useMemo(() => renderElements(componentsEditor, mappingKey, tableMatchKey, statusKey), [componentsEditor, mappingKey, tableMatchKey, statusKey]);
566
+ return (_jsxs("div", Object.assign({ className: "relative w-full h-full flex-1", ref: containerRef, style: { overflow: "auto", WebkitOverflowScrolling: "touch" } }, props.containerProps, { children: [loading && (_jsx("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", children: (loadingRender === null || loadingRender === void 0 ? void 0 : loadingRender.element) || _jsx(Spin, {}) })), _jsx(TransformWrapper, Object.assign({ ref: transformRef, disablePadding: true, centerZoomedOut: true, panning: { disabled: panningGroup, wheelPanning: true }, wheel: { disabled: false }, onTransformed: ({ state: { scale } }) => setScale(scale), minScale: 1, maxScale: 1000, initialScale: 1, smooth: true, centerOnInit: true }, props.transformProps, { children: _jsxs(TransformComponent, { wrapperStyle: { width: "100%", height: "100%" }, contentStyle: { width: "100%", height: "100%" }, children: [_jsxs("svg", Object.assign({ id: "workspace", ref: svgRef, width: "100%", height: "100%", overflow: "hidden", viewBox: viewBox, className: "h-full", xmlns: "http://www.w3.org/2000/svg", preserveAspectRatio: "xMidYMid meet", onContextMenu: (e) => e.preventDefault(), onDrop: (e) => handleTableEvent(e, "drop"), onPointerDown: handlePointerDown, onPointerUp: handleMouseUp, onMouseMove: (e) => graph.onMouseMove(e), onMouseUp: () => graph.onMouseUp(), onClick: (e) => {
567
+ // if (!graph.draggingAnchor) graph.clearSelection();
568
+ // if (graph.connecting) graph.cancelConnect();
569
+ }, style: {
570
+ background: backgroundColor !== null && backgroundColor !== void 0 ? backgroundColor : defaultBackground,
571
+ display: "block",
572
+ touchAction: "none",
573
+ userSelect: "none",
574
+ } }, props.svgProps, { children: [_jsx("rect", { width: "100%", height: "100%", fill: "url(#biggrid)" }), hasBoundingBox && (_jsx("defs", { children: _jsx("clipPath", { id: "contentCrop", children: _jsx("rect", { x: boundingBox.minX, y: boundingBox.minY, width: boundingBox.width, height: boundingBox.height }) }) })), _jsx("g", { id: "main-layer", clipPath: "url(#contentCrop)", children: _jsx(Layers, { components: [...extraComponentsEditor, ...renderedElements], selectedTable: selectedTable, iconTags: iconTags, eventMatchTable: eventMatchTable, privilegedTags: privilegedTags }) }), _jsx(ConnectionLayer, { edges: graph.edges, selectedEdge: graph.selectedEdge, connecting: graph.connecting, draggingAnchor: graph.draggingAnchor, mousePos: graph.mousePos, getNodeById: getNodeById, onSelectEdge: graph.selectEdge, onDeleteEdge: graph.deleteEdge, onStartDragWaypoint: graph.startDragWaypoint, onInsertWaypoint: graph.insertWaypoint, onRemoveWaypoint: graph.removeWaypoint, onStartDragAnchor: graph.startDragAnchor, isConnectEdge: isConnectEdge, selectedNodeId: graph.selectedNode, isSelectNode: isSelectNode }), renderedElements.map((item) => {
575
+ var _a, _b, _c, _d;
576
+ const rotated = rotatePoint(item.width / 2, item.height / 2, (_a = item.rotation) !== null && _a !== void 0 ? _a : 0);
577
+ return (_jsx(ConnectHandle, { cx: item.x + rotated.x, cy: item.y + rotated.y, width: (_b = item.width) !== null && _b !== void 0 ? _b : 100, height: (_c = item.height) !== null && _c !== void 0 ? _c : 50, rotation: (_d = item.rotation) !== null && _d !== void 0 ? _d : 0, nodeId: String(item.id), isConnecting: !!graph.connecting, isDraggingAnchor: !!graph.draggingAnchor, onStartConnect: (nodeId, clickPos) => graph.startConnect(nodeId, clickPos), onEndConnect: (nodeId, clickPos) => {
578
+ if (graph.draggingAnchor)
579
+ graph.updateAnchor(nodeId, clickPos);
580
+ else
581
+ graph.endConnect(nodeId, clickPos);
582
+ }, isConnectEdge: isConnectEdge, onSelectNode: graph.selectNode, isSelectNode: isSelectNode, onSelectEdge: graph.selectEdge, edges: graph.edges }, item.id));
583
+ })] })), tooltip.visible && (_jsx("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), children: tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.children }))] }) }))] })));
584
+ };
585
+ export default LayerView;