seat-editor 3.3.35 → 3.3.37

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 (83) hide show
  1. package/dist/app/constant.d.ts +3 -0
  2. package/dist/app/constant.js +2 -0
  3. package/dist/app/layout.d.ts +1 -1
  4. package/dist/app/layout.js +22 -0
  5. package/dist/app/new-board/page.d.ts +1 -1
  6. package/dist/app/new-board/page.js +58 -0
  7. package/dist/app/old-board/page.d.ts +1 -2
  8. package/dist/app/old-board/page.js +377 -0
  9. package/dist/app/only-view/chair.d.ts +1 -1
  10. package/dist/app/only-view/chair.js +2 -10
  11. package/dist/app/only-view/page.d.ts +1 -1
  12. package/dist/app/only-view/page.js +226 -0
  13. package/dist/app/only-view/user.d.ts +1 -1
  14. package/dist/app/only-view/user.js +2 -10
  15. package/dist/app/page.d.ts +1 -1
  16. package/dist/app/page.js +8 -0
  17. package/dist/app/test/page.d.ts +1 -2
  18. package/dist/app/test/page.js +43 -0
  19. package/dist/app/v2/page.d.ts +1 -1
  20. package/dist/app/v2/page.js +8 -0
  21. package/dist/components/button-tools/index.d.ts +1 -1
  22. package/dist/components/button-tools/index.js +11 -0
  23. package/dist/components/form-tools/label.d.ts +1 -1
  24. package/dist/components/form-tools/label.js +21 -0
  25. package/dist/components/form-tools/shape.d.ts +1 -1
  26. package/dist/components/form-tools/shape.js +69 -0
  27. package/dist/components/input/number-indicator.d.ts +1 -1
  28. package/dist/components/input/number-indicator.js +27 -0
  29. package/dist/components/joystick/index.d.ts +1 -2
  30. package/dist/components/joystick/index.js +48 -0
  31. package/dist/components/layer/index.d.ts +1 -1
  32. package/dist/components/layer/index.js +295 -0
  33. package/dist/components/layer-v2/index.d.ts +1 -1
  34. package/dist/components/layer-v2/index.js +282 -0
  35. package/dist/components/layer-v3/index.d.ts +1 -1
  36. package/dist/components/layer-v3/index.js +483 -0
  37. package/dist/components/layer-v4/index.d.ts +1 -1
  38. package/dist/components/layer-v4/index.js +924 -0
  39. package/dist/components/lib/index.d.ts +1 -1
  40. package/dist/components/lib/index.js +28 -0
  41. package/dist/components/modal-preview/index.d.ts +1 -1
  42. package/dist/components/modal-preview/index.js +10 -0
  43. package/dist/features/board/index.d.ts +1 -1
  44. package/dist/features/board/index.js +666 -0
  45. package/dist/features/board-v2/index.d.ts +1 -2
  46. package/dist/features/board-v2/index.js +807 -0
  47. package/dist/features/board-v3/icons.js +16 -0
  48. package/dist/features/board-v3/index.d.ts +1 -1
  49. package/dist/features/board-v3/index.js +1587 -0
  50. package/dist/features/navbar/index.d.ts +1 -1
  51. package/dist/features/navbar/index.js +6 -0
  52. package/dist/features/package/index.d.ts +1 -1
  53. package/dist/features/package/index.js +166 -0
  54. package/dist/features/panel/index.d.ts +1 -1
  55. package/dist/features/panel/index.js +243 -0
  56. package/dist/features/panel/select-tool.d.ts +1 -1
  57. package/dist/features/panel/select-tool.js +57 -0
  58. package/dist/features/panel/selected-group.d.ts +1 -1
  59. package/dist/features/panel/selected-group.js +35 -0
  60. package/dist/features/panel/square-circle-tool.d.ts +1 -1
  61. package/dist/features/panel/square-circle-tool.js +8 -0
  62. package/dist/features/panel/table-seat-circle.d.ts +1 -1
  63. package/dist/features/panel/table-seat-circle.js +9 -0
  64. package/dist/features/panel/table-seat-square.d.ts +1 -1
  65. package/dist/features/panel/table-seat-square.js +9 -0
  66. package/dist/features/panel/text-tool.d.ts +1 -1
  67. package/dist/features/panel/text-tool.js +22 -0
  68. package/dist/features/panel/upload-tool.d.ts +1 -1
  69. package/dist/features/panel/upload-tool.js +150 -0
  70. package/dist/features/side-tool/index.d.ts +1 -1
  71. package/dist/features/side-tool/index.js +365 -0
  72. package/dist/features/view-only/index.d.ts +1 -1
  73. package/dist/features/view-only/index.js +198 -0
  74. package/dist/features/view-only-2/index.d.ts +84 -14
  75. package/dist/features/view-only-2/index.js +558 -0
  76. package/dist/features/view-only-3/index.d.ts +1 -1
  77. package/dist/features/view-only-3/index.js +577 -0
  78. package/dist/provider/antd-provider.js +43 -0
  79. package/dist/provider/redux-provider.d.ts +1 -1
  80. package/dist/provider/redux-provider.js +7 -0
  81. package/dist/provider/store-provider.d.ts +1 -1
  82. package/dist/provider/store-provider.js +9 -0
  83. package/package.json +1 -1
@@ -0,0 +1,666 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { useCallback, useEffect, useRef, useState } from "react";
4
+ import { TransformWrapper, TransformComponent, MiniMap, } from "react-zoom-pan-pinch";
5
+ import { useAppSelector, useAppDispatch } from "../../hooks/use-redux";
6
+ import Layers from "../../components/layer";
7
+ import { throttle } from "lodash";
8
+ import ModalPreview from "../../components/modal-preview";
9
+ import LayerView from "../view-only";
10
+ import { isEqual, debounce } from "lodash";
11
+ import { ZoomIn, ZoomOut } from "lucide-react";
12
+ import { Button } from "antd";
13
+ const BoardTemplate = ({ onSelectComponent }) => {
14
+ const dispatch = useAppDispatch();
15
+ const theme = useAppSelector((state) => state.theme);
16
+ const transformRef = useRef(null);
17
+ const containerRef = useRef(null);
18
+ const [widthBoard, setWidthBoard] = useState(0);
19
+ const [heightBoard, setHeightBoard] = useState(0);
20
+ const svgRef = useRef(null);
21
+ const [shadowShape, setShadowShape] = useState([]);
22
+ const [startPoint, setStartPoint] = useState(null);
23
+ const [dragOffset, setDragOffset] = useState({ x: 0, y: 0 });
24
+ // const [moveComponent, setMoveComponent] = useState(false);
25
+ const [scale, setScale] = useState(1);
26
+ const activeTool = useAppSelector((state) => state.tool.active);
27
+ const grid = useAppSelector((state) => state.tool.grid);
28
+ const { components: componentsProps, extraComponents: extraComponentsProps, flagChange, } = useAppSelector((state) => state.board);
29
+ const isTouching = useRef(false);
30
+ useEffect(() => {
31
+ var _a;
32
+ if (activeTool !== ((_a = shadowShape[0]) === null || _a === void 0 ? void 0 : _a.shape)) {
33
+ setShadowShape([]);
34
+ }
35
+ }, [activeTool]);
36
+ // const [isDragging, setIsDragging] = useState(false);
37
+ const [resizeDirection, setResizeDirection] = useState(null);
38
+ const backgroundColor = useAppSelector((state) => state.board.backgroundColor);
39
+ const selectedComponentProps = useAppSelector((state) => state.panel.selectedComponent);
40
+ const screenCTMRef = useRef(null);
41
+ const dragIndex = useRef(null);
42
+ const [componentsState, setComponentsState] = useState([]);
43
+ const [extraComponentsState, setExtraComponentsState] = useState([]);
44
+ const [selectedComponent, setSelectedComponent] = useState(null);
45
+ const isSyncingFromRedux = useRef(false);
46
+ const startPos = useRef({ x: 0, y: 0 });
47
+ const isDragging = useRef(false);
48
+ const moveComponent = useRef(false);
49
+ const debouncedSyncToReduxSelected = useRef(debounce((data) => {
50
+ throttledDispatch(data);
51
+ }, 300)).current;
52
+ const debouncedSyncComponents = useRef(debounce((data) => {
53
+ dispatch({
54
+ type: "board/setNewComponents",
55
+ payload: data,
56
+ });
57
+ }, 300));
58
+ const debouncedSyncExtraComponents = useRef(debounce((data) => {
59
+ dispatch({
60
+ type: "board/setNewExtraComponents",
61
+ payload: data,
62
+ });
63
+ }, 300));
64
+ // Redux → Local
65
+ useEffect(() => {
66
+ if (flagChange) {
67
+ if (!isEqual(componentsProps, componentsState)) {
68
+ isSyncingFromRedux.current = true;
69
+ setComponentsState(componentsProps !== null && componentsProps !== void 0 ? componentsProps : []);
70
+ }
71
+ if (!isEqual(extraComponentsProps, extraComponentsState)) {
72
+ isSyncingFromRedux.current = true;
73
+ setExtraComponentsState(extraComponentsProps !== null && extraComponentsProps !== void 0 ? extraComponentsProps : []);
74
+ }
75
+ if (!isEqual(selectedComponentProps, selectedComponent)) {
76
+ isSyncingFromRedux.current = true;
77
+ setSelectedComponent(selectedComponentProps !== null && selectedComponentProps !== void 0 ? selectedComponentProps : []);
78
+ }
79
+ dispatch({ type: "board/setFlagChange", payload: false });
80
+ }
81
+ }, [
82
+ componentsProps,
83
+ extraComponentsProps,
84
+ selectedComponentProps,
85
+ flagChange,
86
+ ]);
87
+ // Local → Redux
88
+ useEffect(() => {
89
+ if (isSyncingFromRedux.current) {
90
+ isSyncingFromRedux.current = false;
91
+ return;
92
+ }
93
+ if (!isEqual(componentsState, componentsProps) &&
94
+ !isEqual(componentsState, [])) {
95
+ debouncedSyncComponents.current(componentsState);
96
+ }
97
+ if (!isEqual(extraComponentsState, extraComponentsProps) && !isEqual(extraComponentsState, [])) {
98
+ debouncedSyncExtraComponents.current(extraComponentsState);
99
+ }
100
+ }, [componentsState, extraComponentsState]);
101
+ const handleAddComponent = (shape) => {
102
+ dispatch({
103
+ type: activeTool === "text"
104
+ ? "board/setExtraComponent"
105
+ : "board/addComponent",
106
+ payload: Object.assign(Object.assign({}, shape), { fill: theme === null || theme === void 0 ? void 0 : theme.primaryColor }),
107
+ });
108
+ const payload = Object.assign(Object.assign({}, shape), { fill: theme === null || theme === void 0 ? void 0 : theme.primaryColor });
109
+ if (activeTool === "text") {
110
+ setExtraComponentsState((prev) => [...prev, payload]);
111
+ }
112
+ else {
113
+ setComponentsState((prev) => [...prev, payload]);
114
+ }
115
+ };
116
+ const getSvgCoords = (e) => {
117
+ var _a;
118
+ const svg = svgRef.current;
119
+ const point = svg.createSVGPoint();
120
+ point.x = e.clientX;
121
+ point.y = e.clientY;
122
+ const transformed = point.matrixTransform((_a = svg.getScreenCTM()) === null || _a === void 0 ? void 0 : _a.inverse());
123
+ return { x: transformed.x, y: transformed.y };
124
+ };
125
+ const createShape = (x, y, fill) => ({
126
+ x,
127
+ y,
128
+ width: 50,
129
+ height: 50,
130
+ shape: activeTool,
131
+ id: Date.now(),
132
+ fill,
133
+ rotation: activeTool === "diamond" ? 45 : 0,
134
+ seatCount: activeTool === "table-seat-circle" ? 6 : 0,
135
+ openSpace: activeTool === "table-seat-circle" ? 0 : undefined,
136
+ seatFill: activeTool === "table-seat-circle" ? "#DADADA" : undefined,
137
+ text: activeTool === "text" ? "Text" : "",
138
+ fontColor: activeTool === "text" ? "#DADADA" : undefined,
139
+ });
140
+ const handleMouseDown = (e, item, direction) => {
141
+ if (activeTool === "select" && item && !direction) {
142
+ startPos.current = { x: e.clientX, y: e.clientY };
143
+ const rectBox = (e === null || e === void 0 ? void 0 : e.target).getBoundingClientRect();
144
+ setDragOffset({
145
+ x: e.clientX - rectBox.left + ((item === null || item === void 0 ? void 0 : item.strokeWidth) || 0),
146
+ y: e.clientY - rectBox.top + ((item === null || item === void 0 ? void 0 : item.strokeWidth) || 0),
147
+ });
148
+ const handleMouseMove = (event) => {
149
+ const dx = Math.abs(event.clientX - startPos.current.x);
150
+ const dy = Math.abs(event.clientY - startPos.current.y);
151
+ if (dx > 1 || dy > 1) {
152
+ if (!moveComponent.current && item) {
153
+ dispatch({ type: "panel/setSelectedComponent", payload: item });
154
+ setSelectedComponent(item);
155
+ }
156
+ moveComponent.current = true;
157
+ }
158
+ };
159
+ const handleMouseUp = () => {
160
+ document.removeEventListener("mousemove", handleMouseMove);
161
+ document.removeEventListener("mouseup", handleMouseUp);
162
+ if (moveComponent.current) {
163
+ moveComponent.current = false;
164
+ }
165
+ else {
166
+ isDragging.current = true;
167
+ moveComponent.current = false;
168
+ setResizeDirection(direction);
169
+ if (item) {
170
+ dispatch({ type: "panel/setSelectedComponent", payload: item });
171
+ dispatch({ type: "panel/setShow", payload: true });
172
+ setSelectedComponent(item);
173
+ }
174
+ }
175
+ };
176
+ // Pasang ke `document` agar global
177
+ document.addEventListener("mousemove", handleMouseMove);
178
+ document.addEventListener("mouseup", handleMouseUp);
179
+ }
180
+ if (activeTool === "select" && direction) {
181
+ setResizeDirection(direction);
182
+ }
183
+ };
184
+ const handleMouseEnter = () => {
185
+ if (![
186
+ "square",
187
+ "circle",
188
+ "diamond",
189
+ "table-seat-circle",
190
+ "table-seat-square",
191
+ "text",
192
+ ].includes(activeTool))
193
+ return;
194
+ };
195
+ const handleMouseLeave = () => {
196
+ if (![
197
+ "square",
198
+ "circle",
199
+ "diamond",
200
+ "table-seat-circle",
201
+ "table-seat-square",
202
+ "text",
203
+ ].includes(activeTool))
204
+ return;
205
+ setShadowShape([]);
206
+ };
207
+ const handleMouseClick = (e) => {
208
+ if (activeTool === "select" && selectedComponent) {
209
+ handleUnSelectComponent();
210
+ return;
211
+ }
212
+ if (![
213
+ "square",
214
+ "circle",
215
+ "diamond",
216
+ "table-seat-circle",
217
+ "table-seat-square",
218
+ "text",
219
+ ].includes(activeTool)) {
220
+ return;
221
+ }
222
+ const { x, y } = getSvgCoords(e);
223
+ setStartPoint({ x, y });
224
+ handleAddComponent(createShape(x, y, theme === null || theme === void 0 ? void 0 : theme.primaryColor));
225
+ };
226
+ const throttledDispatch = useCallback(throttle((component) => {
227
+ // dispatch({
228
+ // type: "board/updateComponent",
229
+ // payload: component,
230
+ // });
231
+ dispatch({
232
+ type: "panel/updateSelectedComponent",
233
+ payload: component,
234
+ });
235
+ }, 16), // 16ms ≈ 60fps
236
+ [dispatch]);
237
+ const handleMouseMove = (e) => {
238
+ if ([
239
+ "square",
240
+ "circle",
241
+ "diamond",
242
+ "table-seat-circle",
243
+ "table-seat-square",
244
+ "text",
245
+ "ruler",
246
+ ].includes(activeTool)) {
247
+ const { x, y } = getSvgCoords(e);
248
+ setShadowShape([createShape(x, y, theme === null || theme === void 0 ? void 0 : theme.primaryColor)]);
249
+ return;
250
+ }
251
+ if (activeTool === "select" &&
252
+ selectedComponent &&
253
+ moveComponent.current &&
254
+ dragOffset &&
255
+ // !isTouching.current &&
256
+ !resizeDirection) {
257
+ const workspaceRect = e.currentTarget.getBoundingClientRect();
258
+ const newX = e.clientX - workspaceRect.left - (dragOffset === null || dragOffset === void 0 ? void 0 : dragOffset.x);
259
+ const newY = e.clientY - workspaceRect.top - (dragOffset === null || dragOffset === void 0 ? void 0 : dragOffset.y);
260
+ let newPosition = {
261
+ x: newX / scale,
262
+ y: newY / scale,
263
+ };
264
+ requestAnimationFrame(() => {
265
+ setComponentsState((prev) => {
266
+ return prev.map((component) => {
267
+ if (component.id === selectedComponent.id) {
268
+ return Object.assign(Object.assign({}, component), { x: newPosition.x, y: newPosition.y });
269
+ }
270
+ return component;
271
+ });
272
+ });
273
+ setExtraComponentsState((prev) => {
274
+ return prev.map((component) => {
275
+ if (component.id === selectedComponent.id) {
276
+ return Object.assign(Object.assign({}, component), { x: newPosition.x, y: newPosition.y });
277
+ }
278
+ return component;
279
+ });
280
+ });
281
+ setSelectedComponent((prev) => {
282
+ return Object.assign(Object.assign({}, prev), { x: newPosition.x, y: newPosition.y });
283
+ });
284
+ });
285
+ debouncedSyncToReduxSelected(Object.assign(Object.assign({}, selectedComponent), newPosition));
286
+ return;
287
+ }
288
+ if (activeTool === "select" && resizeDirection) {
289
+ const workspaceRect = e.currentTarget.getBoundingClientRect();
290
+ const currentX = e.clientX - workspaceRect.left;
291
+ const currentY = e.clientY - workspaceRect.top;
292
+ const { x, y, width, height } = selectedComponent;
293
+ let newShape = Object.assign({}, selectedComponent);
294
+ if (!["table-seat-circle", "table-seat-square"].includes(selectedComponent.shape)) {
295
+ switch (resizeDirection) {
296
+ case "top-left":
297
+ newShape.width = width + (x - currentX);
298
+ newShape.height = height + (y - currentY);
299
+ newShape.x = currentX;
300
+ newShape.y = currentY;
301
+ break;
302
+ case "top-right":
303
+ newShape.width = currentX - newShape.x;
304
+ newShape.height = newShape.height + (newShape.y - currentY);
305
+ newShape.y = currentY;
306
+ break;
307
+ case "bottom-left":
308
+ newShape.width += newShape.x - currentX;
309
+ newShape.height = currentY - newShape.y;
310
+ newShape.x = currentX;
311
+ break;
312
+ case "bottom-right":
313
+ newShape.width = currentX - newShape.x;
314
+ newShape.height = currentY - newShape.y;
315
+ break;
316
+ case "left-center":
317
+ newShape.width += newShape.x - currentX;
318
+ newShape.x = currentX;
319
+ break;
320
+ case "right-center":
321
+ newShape.width = currentX - newShape.x;
322
+ break;
323
+ case "top-center":
324
+ newShape.height += newShape.y - currentY;
325
+ newShape.y = currentY;
326
+ break;
327
+ case "bottom-center":
328
+ newShape.height = currentY - newShape.y;
329
+ break;
330
+ default:
331
+ break;
332
+ }
333
+ }
334
+ else if (["table-seat-circle", "table-seat-square"].includes(selectedComponent.shape)) {
335
+ switch (resizeDirection) {
336
+ case "top-left":
337
+ newShape.width = width + (x - currentX);
338
+ newShape.height = height + (y - currentY);
339
+ newShape.x = currentX;
340
+ newShape.y = currentY;
341
+ break;
342
+ case "top-right":
343
+ newShape.width = currentX - newShape.x;
344
+ newShape.height = newShape.height + (newShape.y - currentY);
345
+ newShape.y = currentY;
346
+ break;
347
+ case "bottom-left":
348
+ newShape.width += newShape.x - currentX;
349
+ newShape.height = currentY - newShape.y;
350
+ newShape.x = currentX;
351
+ break;
352
+ case "bottom-right":
353
+ newShape.width = currentX - newShape.x;
354
+ newShape.height = currentY - newShape.y;
355
+ break;
356
+ default:
357
+ break;
358
+ }
359
+ }
360
+ // updateComponentRef({
361
+ // ...(typeof selectedComponent === "object" && selectedComponent !== null
362
+ // ? selectedComponent
363
+ // : {}),
364
+ // ...newShape,
365
+ // });
366
+ requestAnimationFrame(() => {
367
+ setComponentsState((prev) => {
368
+ return prev.map((component) => {
369
+ if (component.id === selectedComponent.id) {
370
+ return Object.assign(Object.assign({}, component), newShape);
371
+ }
372
+ return component;
373
+ });
374
+ });
375
+ setExtraComponentsState((prev) => {
376
+ return prev.map((component) => {
377
+ if (component.id === selectedComponent.id) {
378
+ return Object.assign(Object.assign({}, component), newShape);
379
+ }
380
+ return component;
381
+ });
382
+ });
383
+ setSelectedComponent(newShape);
384
+ });
385
+ debouncedSyncToReduxSelected(newShape);
386
+ }
387
+ };
388
+ const handleMouseUp = () => {
389
+ if (activeTool === "select" && selectedComponent && isDragging.current) {
390
+ setResizeDirection(null);
391
+ }
392
+ };
393
+ useEffect(() => {
394
+ if (containerRef.current) {
395
+ setWidthBoard(containerRef.current.offsetWidth);
396
+ setHeightBoard(containerRef.current.offsetHeight);
397
+ }
398
+ });
399
+ const handleUnSelectComponent = () => {
400
+ dispatch({ type: "panel/setSelectedComponent", payload: null });
401
+ setSelectedComponent(null);
402
+ dispatch({ type: "panel/setShow", payload: true });
403
+ };
404
+ const handleTouchStart = (e, items, direction) => {
405
+ var _a, _b, _c, _d;
406
+ if (activeTool === "select" && !direction && items) {
407
+ // dispatch({ type: "panel/setShow", payload: false });
408
+ // setMoveComponent(true);
409
+ moveComponent.current = true;
410
+ isTouching.current = true;
411
+ // dispatch({ type: "panel/setSelectedComponent", payload: item });
412
+ onSelectComponent && onSelectComponent(items);
413
+ dispatch({ type: "panel/setSelectedComponent", payload: items });
414
+ setSelectedComponent(items);
415
+ // selectedComponentRef.current = items;
416
+ const touch = e.touches[0];
417
+ const svg = e.currentTarget.ownerSVGElement;
418
+ const pt = svg.createSVGPoint();
419
+ if (!svg)
420
+ return;
421
+ pt.x = touch.clientX;
422
+ pt.y = touch.clientY;
423
+ const cursorpt = pt.matrixTransform((_a = svg.getScreenCTM()) === null || _a === void 0 ? void 0 : _a.inverse());
424
+ screenCTMRef.current = ((_b = svg.getScreenCTM()) === null || _b === void 0 ? void 0 : _b.inverse()) || null;
425
+ setDragOffset({
426
+ x: cursorpt.x - items.x,
427
+ y: cursorpt.y - items.y,
428
+ });
429
+ // dragOffset.current = {
430
+ // x: cursorpt.x - items.x,
431
+ // y: cursorpt.y - items.y
432
+ // }
433
+ }
434
+ else if (activeTool === "select" && direction) {
435
+ setResizeDirection(direction);
436
+ // setIsDragging(true);
437
+ // setMoveComponent(true);
438
+ moveComponent.current = true;
439
+ isDragging.current = true;
440
+ isTouching.current = true;
441
+ const touch = e.touches[0];
442
+ const svg = e.currentTarget.ownerSVGElement;
443
+ const pt = svg.createSVGPoint();
444
+ if (!svg)
445
+ return;
446
+ pt.x = touch.clientX;
447
+ pt.y = touch.clientY;
448
+ const cursorpt = pt.matrixTransform((_c = svg.getScreenCTM()) === null || _c === void 0 ? void 0 : _c.inverse());
449
+ screenCTMRef.current = ((_d = svg.getScreenCTM()) === null || _d === void 0 ? void 0 : _d.inverse()) || null;
450
+ setDragOffset({
451
+ x: cursorpt.x - items.x,
452
+ y: cursorpt.y - items.y,
453
+ });
454
+ // dragOffset.current = {
455
+ // x: cursorpt.x - items.x,
456
+ // y: cursorpt.y - items.y
457
+ // }
458
+ }
459
+ };
460
+ const handleTouchMove = (e) => {
461
+ if (activeTool === "select" &&
462
+ moveComponent &&
463
+ isTouching.current &&
464
+ !resizeDirection) {
465
+ isDragging.current = true;
466
+ moveComponent.current = true;
467
+ const touch = e.touches[0];
468
+ const svg = e.currentTarget.ownerSVGElement;
469
+ if (!svg)
470
+ return;
471
+ const pt = svg.createSVGPoint();
472
+ pt.x = touch.clientX;
473
+ pt.y = touch.clientY;
474
+ const cursorpt = pt.matrixTransform(screenCTMRef.current);
475
+ requestAnimationFrame(() => {
476
+ if ((selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.shape) != "background") {
477
+ setComponentsState((prev) => {
478
+ return prev.map((component) => {
479
+ if (component.id === selectedComponent.id) {
480
+ return Object.assign(Object.assign({}, component), { x: cursorpt.x - (dragOffset === null || dragOffset === void 0 ? void 0 : dragOffset.x), y: cursorpt.y - (dragOffset === null || dragOffset === void 0 ? void 0 : dragOffset.y) });
481
+ }
482
+ return component;
483
+ });
484
+ });
485
+ }
486
+ if ((selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.shape) == "background") {
487
+ setExtraComponentsState((prev) => {
488
+ return prev.map((component) => {
489
+ if (component.id === selectedComponent.id) {
490
+ return Object.assign(Object.assign({}, component), { x: cursorpt.x - (dragOffset === null || dragOffset === void 0 ? void 0 : dragOffset.x), y: cursorpt.y - (dragOffset === null || dragOffset === void 0 ? void 0 : dragOffset.y) });
491
+ }
492
+ return component;
493
+ });
494
+ });
495
+ }
496
+ setSelectedComponent(Object.assign(Object.assign({}, selectedComponent), { x: cursorpt.x - (dragOffset === null || dragOffset === void 0 ? void 0 : dragOffset.x), y: cursorpt.y - (dragOffset === null || dragOffset === void 0 ? void 0 : dragOffset.y) }));
497
+ });
498
+ // updateComponentRef({
499
+ // ...(typeof selectedComponent === "object" && selectedComponent !== null
500
+ // ? selectedComponent
501
+ // : {}),
502
+ // x: cursorpt.x - dragOffset?.current.x,
503
+ // y: cursorpt.y - dragOffset?.current.y,
504
+ // });
505
+ }
506
+ else if (activeTool === "select" &&
507
+ moveComponent.current &&
508
+ isTouching.current &&
509
+ resizeDirection) {
510
+ // setIsDragging(true);
511
+ isDragging.current = true;
512
+ const touch = e.touches[0];
513
+ const svg = e.currentTarget.ownerSVGElement;
514
+ if (!svg)
515
+ return;
516
+ const pt = svg.createSVGPoint();
517
+ pt.x = touch.clientX;
518
+ pt.y = touch.clientY;
519
+ const cursorpt = pt.matrixTransform(screenCTMRef.current);
520
+ let newShape = Object.assign({}, selectedComponent);
521
+ switch (resizeDirection) {
522
+ case "top-left":
523
+ newShape.width = newShape.width + (newShape.x - cursorpt.x);
524
+ newShape.height = newShape.height + (newShape.y - cursorpt.y);
525
+ newShape.x = cursorpt.x;
526
+ newShape.y = cursorpt.y;
527
+ break;
528
+ case "top-right":
529
+ newShape.width = cursorpt.x - newShape.x;
530
+ newShape.height = newShape.height + (newShape.y - cursorpt.y);
531
+ newShape.y = cursorpt.y;
532
+ break;
533
+ case "bottom-left":
534
+ newShape.width = newShape.width + (newShape.x - cursorpt.x);
535
+ newShape.height = cursorpt.y - newShape.y;
536
+ newShape.x = cursorpt.x;
537
+ break;
538
+ case "bottom-right":
539
+ newShape.width = cursorpt.x - newShape.x;
540
+ newShape.height = cursorpt.y - newShape.y;
541
+ break;
542
+ case "top-center":
543
+ newShape.height = newShape.height + (newShape.y - cursorpt.y);
544
+ newShape.y = cursorpt.y;
545
+ break;
546
+ case "bottom-center":
547
+ newShape.height = cursorpt.y - newShape.y;
548
+ break;
549
+ case "right-center":
550
+ newShape.width = cursorpt.x - newShape.x;
551
+ break;
552
+ case "left-center":
553
+ newShape.width = newShape.width + (newShape.x - cursorpt.x);
554
+ newShape.x = cursorpt.x;
555
+ break;
556
+ default:
557
+ break;
558
+ }
559
+ // updateComponentRef({
560
+ // ...(typeof selectedComponent === "object" && selectedComponent !== null
561
+ // ? selectedComponent
562
+ // : {}),
563
+ // ...newShape,
564
+ // });
565
+ requestAnimationFrame(() => {
566
+ setComponentsState((prev) => {
567
+ return prev.map((component) => {
568
+ if (component.id === selectedComponent.id) {
569
+ return Object.assign(Object.assign({}, component), newShape);
570
+ }
571
+ return component;
572
+ });
573
+ });
574
+ setExtraComponentsState((prev) => {
575
+ return prev.map((component) => {
576
+ if (component.id === selectedComponent.id) {
577
+ return Object.assign(Object.assign({}, component), newShape);
578
+ }
579
+ return component;
580
+ });
581
+ });
582
+ setSelectedComponent(Object.assign(Object.assign({}, selectedComponent), newShape));
583
+ });
584
+ debouncedSyncToReduxSelected(newShape);
585
+ }
586
+ };
587
+ const handleTouchEnd = () => {
588
+ // setMoveComponent(false);
589
+ // setIsDragging(false);
590
+ moveComponent.current = false;
591
+ isDragging.current = false;
592
+ isTouching.current = false;
593
+ setResizeDirection(null);
594
+ };
595
+ const getCursorStyle = () => {
596
+ if (activeTool === "select" && moveComponent.current) {
597
+ return "grabbing";
598
+ }
599
+ else if (activeTool === "select" && resizeDirection) {
600
+ return "grab";
601
+ }
602
+ else if (activeTool === "grab") {
603
+ return "grab";
604
+ }
605
+ else if (activeTool === "ruler") {
606
+ return "crosshair";
607
+ }
608
+ };
609
+ const renderMiniMap = () => {
610
+ return (_jsx(MiniMap, { width: 250, height: 250, children: _jsx("div", { className: "w-full h-full", children: _jsx("svg", { id: "workspace", width: "100%", height: "100%", viewBox: `0 0 ${widthBoard} ${heightBoard}`, className: "h-screen w-full", xmlns: "http://www.w3.org/2000/svg", preserveAspectRatio: "xMidYMid meet", style: {
611
+ background: "#f5f5f5",
612
+ display: "block",
613
+ }, children: _jsx(Layers, { shadowShape: shadowShape, components: [...extraComponentsState, ...componentsState], activeTool: activeTool,
614
+ // onClick={handleSelectComponent}
615
+ // onMouseDown={handleMouseDown}
616
+ // onMouseUp={handleMouseUp}
617
+ // onBlur={handleUnSelectComponent}
618
+ selectedComponent: selectedComponent }) }) }) }));
619
+ };
620
+ const handelZoomIn = () => {
621
+ var _a;
622
+ if (activeTool !== "grab") {
623
+ dispatch({
624
+ type: "tool/setActiveTool",
625
+ payload: "grab",
626
+ });
627
+ }
628
+ (_a = transformRef.current) === null || _a === void 0 ? void 0 : _a.zoomIn();
629
+ };
630
+ const handleZoomOut = () => {
631
+ var _a;
632
+ if (activeTool !== "grab") {
633
+ dispatch({
634
+ type: "tool/setActiveTool",
635
+ payload: "grab",
636
+ });
637
+ }
638
+ (_a = transformRef.current) === null || _a === void 0 ? void 0 : _a.zoomOut();
639
+ };
640
+ // activeTool === "select" &&
641
+ // moveComponent &&
642
+ // isTouching.current &&
643
+ // !resizeDirection
644
+ return (_jsxs(_Fragment, { children: [_jsx(ModalPreview, { children: _jsx(LayerView, { statusKey: "status" }) }), _jsxs("div", { className: "relative w-full h-screen flex-1 overflow-hidden", ref: containerRef, children: [_jsx("div", { className: "absolute bottom-5 left-1/2 transform -translate-x-1/2 z-10", children: _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { icon: _jsx(ZoomIn, {}), onClick: handelZoomIn }), _jsx(Button, { icon: _jsx(ZoomOut, {}), onClick: handleZoomOut })] }) }), _jsxs(TransformWrapper, { ref: transformRef, panning: { disabled: activeTool === "select" }, centerZoomedOut: true, onTransformed: ({ state: { scale } }) => setScale(scale), minScale: 1, maxScale: 1000, initialScale: 1, pinch: { step: 1 }, smooth: true, doubleClick: { step: 1, disabled: activeTool === "select" }, disablePadding: true, children: [scale > 1 && (_jsx("div", { className: "absolute bottom-[60px] left-1/2 transform -translate-x-1/2 z-10", children: renderMiniMap() })), _jsx(TransformComponent, { wrapperStyle: {
645
+ width: "100%",
646
+ height: "100%",
647
+ overflow: "hidden",
648
+ }, contentStyle: {
649
+ width: "100%",
650
+ height: "100%",
651
+ }, children: _jsxs("svg", { id: "workspace", ref: svgRef, width: "100%", height: "100%", viewBox: `0 0 ${widthBoard} ${heightBoard}`, className: "h-screen", onMouseUp: handleMouseUp, onMouseMove: handleMouseMove, onMouseEnter: handleMouseEnter, onClick: (e) => {
652
+ e.stopPropagation();
653
+ handleMouseClick(e);
654
+ }, onMouseLeave: handleMouseLeave, xmlns: "http://www.w3.org/2000/svg", preserveAspectRatio: "xMidYMid meet", style: {
655
+ background: backgroundColor,
656
+ display: "block",
657
+ cursor: activeTool === "ruler" ? "crosshair" : "auto",
658
+ }, children: [_jsx(Layers, { shadowShape: shadowShape, components: [...extraComponentsState, ...componentsState], style: {
659
+ cursor: getCursorStyle(),
660
+ },
661
+ // onClick={handleSelectComponent}
662
+ onMouseDown: handleMouseDown,
663
+ // onMouseUp={handleMouseUp}
664
+ onBlur: handleUnSelectComponent, selectedComponent: selectedComponent, activeTool: activeTool, onTouchStart: (e, item, direction) => handleTouchStart(e, item, direction), onTouchMove: (e) => handleTouchMove(e), onTouchEnd: handleTouchEnd }), activeTool === "ruler" && (_jsxs(_Fragment, { children: [_jsxs("g", { id: "horizontal-ruler", children: [_jsx("rect", { x: "0", y: "0", width: window.innerWidth, height: "30", fill: "#e0e0e0" }), _jsx("g", { stroke: "#888", "font-size": "10", "text-anchor": "middle", children: Array.from({ length: window.innerWidth / 50 }, (_, i) => (_jsxs("g", { children: [_jsx("line", { x1: i * 50, y1: "0", x2: i * 50, y2: "10" }), _jsx("text", { x: i * 50, y: "15", children: i * 50 })] }, i))) })] }), _jsxs("g", { id: "vertical-ruler", children: [_jsx("rect", { x: "0", y: "0", width: "30", height: window.innerHeight, fill: "#e0e0e0" }), _jsx("g", { stroke: "#888", "font-size": "10", "text-anchor": "middle", children: Array.from({ length: window.innerHeight / 10 }, (_, i) => (_jsxs("g", { children: [_jsx("line", { x1: "0", y1: i * 50, x2: "10", y2: i * 50 }), _jsx("text", { x: "15", y: i * 50, children: i * 50 })] }, i))) })] })] })), grid && (_jsxs("g", { stroke: "#ddd", strokeWidth: 0.5, children: [Array.from({ length: widthBoard / 10 }, (_, i) => (_jsx("line", { x1: i * 10, y1: 0, x2: i * 10, y2: heightBoard }, `v-${i}`))), Array.from({ length: heightBoard / 10 }, (_, i) => (_jsx("line", { x1: 0, y1: i * 10, x2: widthBoard, y2: i * 10 }, `h-${i}`)))] }))] }) })] })] })] }));
665
+ };
666
+ export default BoardTemplate;
@@ -1,8 +1,7 @@
1
- import React from "react";
2
1
  interface BoardTemplateProps {
3
2
  onSelectComponent?: (items: any) => void;
4
3
  mappingKey?: string;
5
4
  viewOnly?: boolean;
6
5
  }
7
- declare const BoardTemplate: ({ onSelectComponent, viewOnly }: BoardTemplateProps) => React.JSX.Element;
6
+ declare const BoardTemplate: ({ onSelectComponent, viewOnly }: BoardTemplateProps) => import("react/jsx-runtime").JSX.Element;
8
7
  export default BoardTemplate;