seat-editor 1.3.11 → 1.3.12

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.
@@ -95,7 +95,7 @@ const Layers = ({ shadowShape, components, onClick, selectedComponent, selectedT
95
95
  e.stopPropagation();
96
96
  onTouchEnd === null || onTouchEnd === void 0 ? void 0 : onTouchEnd(e);
97
97
  },
98
- ondblclick: (e) => {
98
+ onDoubleClick: (e) => {
99
99
  e.stopPropagation();
100
100
  onClick === null || onClick === void 0 ? void 0 : onClick(item);
101
101
  }
@@ -179,7 +179,7 @@ const Layers = ({ shadowShape, components, onClick, selectedComponent, selectedT
179
179
  return null;
180
180
  }
181
181
  };
182
- return (_jsxs("g", { children: [components === null || components === void 0 ? void 0 : components.map(renderShape), shadowShape === null || shadowShape === void 0 ? void 0 : shadowShape.map(renderShadowShape), selectedComponent && (_jsxs(_Fragment, { children: [["square", "circle", "diamond", "text",].includes(selectedComponent.shape) && (_jsxs("g", { children: [_jsx("rect", { x: selectedComponent.x - 25, y: selectedComponent.y - 25, width: 20, height: 20, fill: "black", stroke: "white", strokeWidth: "2", transform: `scale(${selectedComponent.scale})`, onMouseDown: (e) => {
182
+ return (_jsxs("g", { children: [components === null || components === void 0 ? void 0 : components.map(renderShape), shadowShape === null || shadowShape === void 0 ? void 0 : shadowShape.map(renderShadowShape), selectedComponent && (_jsxs(_Fragment, { children: [["square", "circle", "diamond", "text", "background", "image-table"].includes(selectedComponent.shape) && (_jsxs("g", { children: [_jsx("rect", { x: selectedComponent.x - 25, y: selectedComponent.y - 25, width: 20, height: 20, fill: "black", stroke: "white", strokeWidth: "2", transform: `scale(${selectedComponent.scale})`, onMouseDown: (e) => {
183
183
  e.stopPropagation();
184
184
  onMouseDown(e, selectedComponent, "top-left");
185
185
  }, onTouchStart: (e) => {
@@ -7,6 +7,7 @@ export interface InitialState {
7
7
  backgroundColor: string;
8
8
  themeColor: string;
9
9
  extraComponents: Component[];
10
+ flagChange: boolean;
10
11
  }
11
12
  export declare const addComponent: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "board/addComponent">, removeComponent: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "board/removeComponent">, updateComponent: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "board/updateComponent">, setBackgroundColor: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "board/setBackgroundColor">, removeExtraComponent: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "board/removeExtraComponent">;
12
13
  declare const _default: import("redux").Reducer<InitialState>;
@@ -3,7 +3,8 @@ const initialState = {
3
3
  components: [],
4
4
  backgroundColor: "#FFFFFF",
5
5
  themeColor: "#4A90E2",
6
- extraComponents: []
6
+ extraComponents: [],
7
+ flagChange: false
7
8
  };
8
9
  const boardSlice = createSlice({
9
10
  name: "board",
@@ -42,6 +43,9 @@ const boardSlice = createSlice({
42
43
  setExtraComponent: (state, action) => {
43
44
  state.extraComponents.push(action.payload);
44
45
  },
46
+ setFlagChange: (state, action) => {
47
+ state.flagChange = action.payload;
48
+ },
45
49
  },
46
50
  });
47
51
  export const { addComponent, removeComponent, updateComponent, setBackgroundColor, removeExtraComponent } = boardSlice.actions;
@@ -7,6 +7,7 @@ import Layers from "../../components/layer";
7
7
  import { throttle } from "lodash";
8
8
  import ModalPreview from "../../components/modal-preview";
9
9
  import LayerView from "../view";
10
+ import { isEqual, debounce } from "lodash";
10
11
  const BoardTemplate = ({ onSelectComponent }) => {
11
12
  const dispatch = useAppDispatch();
12
13
  const theme = useAppSelector((state) => state.theme);
@@ -21,13 +22,64 @@ const BoardTemplate = ({ onSelectComponent }) => {
21
22
  const [moveComponent, setMoveComponent] = useState(false);
22
23
  const [scale, setScale] = useState(1);
23
24
  const activeTool = useAppSelector((state) => state.tool.active);
24
- const { components, extraComponents } = useAppSelector((state) => state.board);
25
+ const { components: componentsProps, extraComponents: extraComponentsProps, flagChange } = useAppSelector((state) => state.board);
25
26
  const isTouching = useRef(false);
26
27
  const [isDragging, setIsDragging] = useState(false);
27
28
  const [resizeDirection, setResizeDirection] = useState(null);
28
29
  const backgroundColor = useAppSelector((state) => state.board.backgroundColor);
29
- const selectedComponent = useAppSelector((state) => state.panel.selectedComponent);
30
+ const selectedComponentProps = useAppSelector((state) => state.panel.selectedComponent);
30
31
  const screenCTMRef = useRef(null);
32
+ const dragIndex = useRef(null);
33
+ const [componentsState, setComponentsState] = useState([]);
34
+ const [extraComponentsState, setExtraComponentsState] = useState([]);
35
+ const [selectedComponent, setSelectedComponent] = useState(null);
36
+ const isSyncingFromRedux = useRef(false);
37
+ const debouncedSyncToReduxSelected = useRef(debounce((data) => {
38
+ throttledDispatch(data);
39
+ }, 300)).current;
40
+ const debouncedSyncComponents = useRef(debounce((data) => {
41
+ dispatch({
42
+ type: "board/setNewComponents",
43
+ payload: data,
44
+ });
45
+ }, 300));
46
+ const debouncedSyncExtraComponents = useRef(debounce((data) => {
47
+ dispatch({
48
+ type: "board/setNewExtraComponents",
49
+ payload: data,
50
+ });
51
+ }, 300));
52
+ // Redux → Local
53
+ useEffect(() => {
54
+ if (flagChange) {
55
+ if (!isEqual(componentsProps, componentsState)) {
56
+ isSyncingFromRedux.current = true;
57
+ setComponentsState(componentsProps);
58
+ }
59
+ if (!isEqual(extraComponentsProps, extraComponentsState)) {
60
+ isSyncingFromRedux.current = true;
61
+ setExtraComponentsState(extraComponentsProps);
62
+ }
63
+ if (!isEqual(selectedComponentProps, selectedComponent)) {
64
+ isSyncingFromRedux.current = true;
65
+ setSelectedComponent(selectedComponentProps);
66
+ }
67
+ dispatch({ type: "board/setFlagChange", payload: false });
68
+ }
69
+ }, [componentsProps, extraComponentsProps, selectedComponentProps]);
70
+ // Local → Redux
71
+ useEffect(() => {
72
+ if (isSyncingFromRedux.current) {
73
+ isSyncingFromRedux.current = false;
74
+ return;
75
+ }
76
+ if (!isEqual(componentsState, componentsProps)) {
77
+ debouncedSyncComponents.current(componentsState);
78
+ }
79
+ if (!isEqual(extraComponentsState, extraComponentsProps)) {
80
+ debouncedSyncExtraComponents.current(extraComponentsState);
81
+ }
82
+ }, [componentsState, extraComponentsState]);
31
83
  const handleAddComponent = (shape) => {
32
84
  dispatch({
33
85
  type: activeTool === "text"
@@ -35,6 +87,13 @@ const BoardTemplate = ({ onSelectComponent }) => {
35
87
  : "board/addComponent",
36
88
  payload: Object.assign(Object.assign({}, shape), { fill: theme === null || theme === void 0 ? void 0 : theme.primaryColor }),
37
89
  });
90
+ const payload = Object.assign(Object.assign({}, shape), { fill: theme === null || theme === void 0 ? void 0 : theme.primaryColor });
91
+ if (activeTool === "text") {
92
+ setExtraComponentsState((prev) => [...prev, payload]);
93
+ }
94
+ else {
95
+ setComponentsState((prev) => [...prev, payload]);
96
+ }
38
97
  };
39
98
  const getSvgCoords = (e) => {
40
99
  var _a;
@@ -69,7 +128,8 @@ const BoardTemplate = ({ onSelectComponent }) => {
69
128
  if (e) {
70
129
  dispatch({ type: "panel/setShow", payload: false });
71
130
  setMoveComponent(true);
72
- dispatch({ type: "panel/setSelectedComponent", payload: item });
131
+ // dispatch({ type: "panel/setSelectedComponent", payload: null });
132
+ // setSelectedComponent(null)
73
133
  const rectBox = (e === null || e === void 0 ? void 0 : e.target).getBoundingClientRect();
74
134
  setDragOffset({
75
135
  x: e.clientX - rectBox.left,
@@ -82,6 +142,8 @@ const BoardTemplate = ({ onSelectComponent }) => {
82
142
  if (activeTool === "select") {
83
143
  setMoveComponent(false);
84
144
  dispatch({ type: "panel/setShow", payload: false });
145
+ dispatch({ type: "panel/setSelectedComponent", payload: null });
146
+ setSelectedComponent(null);
85
147
  setIsDragging(false);
86
148
  setResizeDirection(null);
87
149
  }
@@ -155,15 +217,34 @@ const BoardTemplate = ({ onSelectComponent }) => {
155
217
  !isTouching.current &&
156
218
  !resizeDirection) {
157
219
  const workspaceRect = e.currentTarget.getBoundingClientRect();
158
- const newX = e.clientX - workspaceRect.left - dragOffset.x;
159
- const newY = e.clientY - workspaceRect.top - dragOffset.y;
220
+ const newX = e.clientX - workspaceRect.left - (dragOffset === null || dragOffset === void 0 ? void 0 : dragOffset.x);
221
+ const newY = e.clientY - workspaceRect.top - (dragOffset === null || dragOffset === void 0 ? void 0 : dragOffset.y);
160
222
  let newPosition = {
161
223
  x: newX,
162
224
  y: newY,
163
225
  };
164
- throttledDispatch(Object.assign(Object.assign({}, (typeof selectedComponent === "object" && selectedComponent !== null
165
- ? selectedComponent
166
- : {})), { x: newPosition.x, y: newPosition.y }));
226
+ requestAnimationFrame(() => {
227
+ setComponentsState((prev) => {
228
+ return prev.map((component) => {
229
+ if (component.id === selectedComponent.id) {
230
+ return Object.assign(Object.assign({}, component), { x: newPosition.x, y: newPosition.y });
231
+ }
232
+ return component;
233
+ });
234
+ });
235
+ setExtraComponentsState((prev) => {
236
+ return prev.map((component) => {
237
+ if (component.id === selectedComponent.id) {
238
+ return Object.assign(Object.assign({}, component), { x: newPosition.x, y: newPosition.y });
239
+ }
240
+ return component;
241
+ });
242
+ });
243
+ setSelectedComponent((prev) => {
244
+ return Object.assign(Object.assign({}, prev), { x: newPosition.x, y: newPosition.y });
245
+ });
246
+ });
247
+ debouncedSyncToReduxSelected(Object.assign(Object.assign({}, selectedComponent), newPosition));
167
248
  return;
168
249
  }
169
250
  if (activeTool === "select" && resizeDirection) {
@@ -212,7 +293,7 @@ const BoardTemplate = ({ onSelectComponent }) => {
212
293
  break;
213
294
  }
214
295
  }
215
- else if (['table-seat-circle', 'table-seat-square'].includes(selectedComponent.shape)) {
296
+ else if (["table-seat-circle", "table-seat-square"].includes(selectedComponent.shape)) {
216
297
  switch (resizeDirection) {
217
298
  case "top-left":
218
299
  newShape.width = width + (x - currentX);
@@ -238,16 +319,41 @@ const BoardTemplate = ({ onSelectComponent }) => {
238
319
  break;
239
320
  }
240
321
  }
241
- throttledDispatch(Object.assign(Object.assign({}, (typeof selectedComponent === "object" && selectedComponent !== null
242
- ? selectedComponent
243
- : {})), newShape));
322
+ // updateComponentRef({
323
+ // ...(typeof selectedComponent === "object" && selectedComponent !== null
324
+ // ? selectedComponent
325
+ // : {}),
326
+ // ...newShape,
327
+ // });
328
+ requestAnimationFrame(() => {
329
+ setComponentsState((prev) => {
330
+ return prev.map((component) => {
331
+ if (component.id === selectedComponent.id) {
332
+ return Object.assign(Object.assign({}, component), newShape);
333
+ }
334
+ return component;
335
+ });
336
+ });
337
+ setExtraComponentsState((prev) => {
338
+ return prev.map((component) => {
339
+ if (component.id === selectedComponent.id) {
340
+ return Object.assign(Object.assign({}, component), newShape);
341
+ }
342
+ return component;
343
+ });
344
+ });
345
+ setSelectedComponent(newShape);
346
+ });
347
+ debouncedSyncToReduxSelected(newShape);
244
348
  }
245
349
  };
246
350
  const handleSelectComponent = (items) => {
247
351
  if (activeTool === "select" && !isDragging) {
248
352
  setIsDragging(false);
249
353
  onSelectComponent && onSelectComponent(items);
354
+ setSelectedComponent(items);
250
355
  dispatch({ type: "panel/setSelectedComponent", payload: items });
356
+ // selectedComponentRef.current = items;
251
357
  dispatch({ type: "panel/setShow", payload: true });
252
358
  }
253
359
  };
@@ -259,6 +365,8 @@ const BoardTemplate = ({ onSelectComponent }) => {
259
365
  });
260
366
  const handleUnSelectComponent = () => {
261
367
  dispatch({ type: "panel/setSelectedComponent", payload: null });
368
+ setSelectedComponent(null);
369
+ // selectedComponentRef.current = null;
262
370
  };
263
371
  const handleTouchStart = (e, items, direction) => {
264
372
  var _a, _b, _c, _d;
@@ -269,6 +377,8 @@ const BoardTemplate = ({ onSelectComponent }) => {
269
377
  // dispatch({ type: "panel/setSelectedComponent", payload: item });
270
378
  onSelectComponent && onSelectComponent(items);
271
379
  dispatch({ type: "panel/setSelectedComponent", payload: items });
380
+ setSelectedComponent(items);
381
+ // selectedComponentRef.current = items;
272
382
  const touch = e.touches[0];
273
383
  const svg = e.currentTarget.ownerSVGElement;
274
384
  const pt = svg.createSVGPoint();
@@ -282,6 +392,10 @@ const BoardTemplate = ({ onSelectComponent }) => {
282
392
  x: cursorpt.x - items.x,
283
393
  y: cursorpt.y - items.y,
284
394
  });
395
+ // dragOffset.current = {
396
+ // x: cursorpt.x - items.x,
397
+ // y: cursorpt.y - items.y
398
+ // }
285
399
  }
286
400
  else if (activeTool === "select" && direction) {
287
401
  setResizeDirection(direction);
@@ -301,10 +415,17 @@ const BoardTemplate = ({ onSelectComponent }) => {
301
415
  x: cursorpt.x - items.x,
302
416
  y: cursorpt.y - items.y,
303
417
  });
418
+ // dragOffset.current = {
419
+ // x: cursorpt.x - items.x,
420
+ // y: cursorpt.y - items.y
421
+ // }
304
422
  }
305
423
  };
306
424
  const handleTouchMove = (e) => {
307
- if (activeTool === "select" && moveComponent && isTouching.current && !resizeDirection) {
425
+ if (activeTool === "select" &&
426
+ moveComponent &&
427
+ isTouching.current &&
428
+ !resizeDirection) {
308
429
  setIsDragging(true);
309
430
  const touch = e.touches[0];
310
431
  const svg = e.currentTarget.ownerSVGElement;
@@ -314,11 +435,37 @@ const BoardTemplate = ({ onSelectComponent }) => {
314
435
  pt.x = touch.clientX;
315
436
  pt.y = touch.clientY;
316
437
  const cursorpt = pt.matrixTransform(screenCTMRef.current);
317
- throttledDispatch(Object.assign(Object.assign({}, (typeof selectedComponent === "object" && selectedComponent !== null
318
- ? selectedComponent
319
- : {})), { x: cursorpt.x - dragOffset.x, y: cursorpt.y - dragOffset.y }));
438
+ requestAnimationFrame(() => {
439
+ setComponentsState((prev) => {
440
+ return prev.map((component) => {
441
+ if (component.id === selectedComponent.id) {
442
+ 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) });
443
+ }
444
+ return component;
445
+ });
446
+ });
447
+ setExtraComponentsState((prev) => {
448
+ return prev.map((component) => {
449
+ if (component.id === selectedComponent.id) {
450
+ 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) });
451
+ }
452
+ return component;
453
+ });
454
+ });
455
+ 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) }));
456
+ });
457
+ // updateComponentRef({
458
+ // ...(typeof selectedComponent === "object" && selectedComponent !== null
459
+ // ? selectedComponent
460
+ // : {}),
461
+ // x: cursorpt.x - dragOffset?.current.x,
462
+ // y: cursorpt.y - dragOffset?.current.y,
463
+ // });
320
464
  }
321
- else if (activeTool === "select" && moveComponent && isTouching.current && resizeDirection) {
465
+ else if (activeTool === "select" &&
466
+ moveComponent &&
467
+ isTouching.current &&
468
+ resizeDirection) {
322
469
  setIsDragging(true);
323
470
  const touch = e.touches[0];
324
471
  const svg = e.currentTarget.ownerSVGElement;
@@ -367,9 +514,32 @@ const BoardTemplate = ({ onSelectComponent }) => {
367
514
  default:
368
515
  break;
369
516
  }
370
- throttledDispatch(Object.assign(Object.assign({}, (typeof selectedComponent === "object" && selectedComponent !== null
371
- ? selectedComponent
372
- : {})), newShape));
517
+ // updateComponentRef({
518
+ // ...(typeof selectedComponent === "object" && selectedComponent !== null
519
+ // ? selectedComponent
520
+ // : {}),
521
+ // ...newShape,
522
+ // });
523
+ requestAnimationFrame(() => {
524
+ setComponentsState((prev) => {
525
+ return prev.map((component) => {
526
+ if (component.id === selectedComponent.id) {
527
+ return Object.assign(Object.assign({}, component), newShape);
528
+ }
529
+ return component;
530
+ });
531
+ });
532
+ setExtraComponentsState((prev) => {
533
+ return prev.map((component) => {
534
+ if (component.id === selectedComponent.id) {
535
+ return Object.assign(Object.assign({}, component), newShape);
536
+ }
537
+ return component;
538
+ });
539
+ });
540
+ setSelectedComponent(Object.assign(Object.assign({}, selectedComponent), newShape));
541
+ });
542
+ debouncedSyncToReduxSelected(newShape);
373
543
  }
374
544
  };
375
545
  const handleTouchEnd = () => {
@@ -391,6 +561,6 @@ const BoardTemplate = ({ onSelectComponent }) => {
391
561
  }, onMouseLeave: handleMouseLeave, xmlns: "http://www.w3.org/2000/svg", preserveAspectRatio: "xMidYMid meet", style: {
392
562
  background: backgroundColor,
393
563
  display: "block",
394
- }, children: _jsx(Layers, { shadowShape: shadowShape, components: [...extraComponents, ...components], onClick: handleSelectComponent, onMouseDown: handleMouseDown, onMouseUp: handleMouseUp, onBlur: handleUnSelectComponent, selectedComponent: selectedComponent, activeTool: activeTool, onTouchStart: (e, item, direction) => handleTouchStart(e, item, direction), onTouchMove: (e) => handleTouchMove(e), onTouchEnd: handleTouchEnd }) }) }) }) })] }));
564
+ }, children: _jsx(Layers, { shadowShape: shadowShape, components: [...extraComponentsState, ...componentsState], onClick: handleSelectComponent, onMouseDown: handleMouseDown, onMouseUp: handleMouseUp, onBlur: handleUnSelectComponent, selectedComponent: selectedComponent, activeTool: activeTool, onTouchStart: (e, item, direction) => handleTouchStart(e, item, direction), onTouchMove: (e) => handleTouchMove(e), onTouchEnd: handleTouchEnd }) }) }) }) })] }));
395
565
  };
396
566
  export default BoardTemplate;
@@ -47,6 +47,7 @@ const ControlPanels = (props) => {
47
47
  type: "panel/updateSelectedComponent",
48
48
  payload: Object.assign(Object.assign({}, (selectedComponent || {})), allValues),
49
49
  });
50
+ dispatch({ type: "board/setFlagChange", payload: true });
50
51
  };
51
52
  const renderFormPanel = () => {
52
53
  switch (tool.active) {
@@ -69,6 +69,7 @@ const UploadTool = ({ name, type, action, responseMapping, }) => {
69
69
  src: srcFromResponse,
70
70
  },
71
71
  });
72
+ dispatch({ type: "board/setFlagChange", payload: true });
72
73
  message.success(`${info.file.name} uploaded successfully.`);
73
74
  };
74
75
  // Set img src AFTER onload
@@ -101,6 +102,7 @@ const UploadTool = ({ name, type, action, responseMapping, }) => {
101
102
  src: img.src,
102
103
  },
103
104
  });
105
+ dispatch({ type: "board/setFlagChange", payload: true });
104
106
  message.success(`${info.file.name} uploaded successfully.`);
105
107
  };
106
108
  // Set img src AFTER onload
@@ -107,6 +107,7 @@ const SideTool = ({ dragOnly }) => {
107
107
  type: "board/removeExtraComponent",
108
108
  payload: selectedComponent,
109
109
  });
110
+ dispatch({ type: "board/setFlagChange", payload: true });
110
111
  };
111
112
  const handleDuplicateComponent = () => {
112
113
  const newComponent = Object.assign(Object.assign({}, selectedComponent), { x: selectedComponent.x + 20, y: selectedComponent.y + 20, id: Date.now() });
@@ -1,12 +1,11 @@
1
1
  "use client";
2
2
  import { configureStore } from "@reduxjs/toolkit";
3
3
  import { rootReducer } from "./rootReducer";
4
- import { logger } from "redux-logger";
5
4
  import { middleware } from "./middleware";
6
5
  import { FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER } from "redux-persist";
7
- if (process.env.NODE_ENV === "development") {
8
- middleware.push(logger);
9
- }
6
+ // if(process.env.NODE_ENV === "development") {
7
+ // middleware.push(logger);
8
+ // }
10
9
  // const rootPersistReducer = persistReducer<RootState>(rootPersistConfig, rootReducer);
11
10
  export const store = configureStore({
12
11
  reducer: rootReducer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seat-editor",
3
- "version": "1.3.11",
3
+ "version": "1.3.12",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",