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