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