seat-editor 3.2.3 → 3.2.5

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.
@@ -1,25 +1,26 @@
1
1
  "use client";
2
2
  import { useEffect, useState } from "react";
3
3
  import SeatEditor from "../../features/package";
4
- import { data4 } from "../constant";
5
- import { dummyImage } from "../only-view/page";
4
+ import { data5, dummyExtra5 } from "../constant";
6
5
  export default function NewBoard() {
7
6
  const [initialValue, setInitialValue] = useState([]);
8
7
  const [extraComponents, setExtraComponents] = useState([]);
9
8
  const [backgroundColor, setBackgroundColor] = useState("#000000");
10
- const [viewOnly, setViewOnly] = useState(true);
9
+ const [viewOnly, setViewOnly] = useState(false);
11
10
  useEffect(() => {
12
- setInitialValue(data4);
13
- setExtraComponents(dummyImage);
11
+ setInitialValue(data5);
12
+ setExtraComponents(dummyExtra5);
14
13
  }, []);
15
14
  return (<>
16
15
  <div className="w-full h-screen flex flex-col relative justify-center">
17
16
  <div className="w-full h-[1000px] bg-white border-r border-gray-200">
18
17
 
19
18
  </div>
20
- <button className="bg-blue-500 text-white px-4 py-2 rounded" onClick={() => setViewOnly(!viewOnly)}>
19
+ {/* <button className="bg-blue-500 text-white px-4 py-2 rounded"
20
+ onClick={() => setViewOnly(!viewOnly)}
21
+ >
21
22
  {viewOnly ? "Edit Mode ddd" : "View Mode"}
22
- </button>
23
+ </button> */}
23
24
  <div className="flex-1 h-full">
24
25
  <SeatEditor componentProps={initialValue} viewOnly={viewOnly} dragOnly={true} deleteAutorized={{
25
26
  component: true,
@@ -6,7 +6,7 @@ const Layers = ({ components, selectedComponent, activeTool, selectionLines, })
6
6
  const hasPoints = selectionLines && !isEmpty(selectionLines === null || selectionLines === void 0 ? void 0 : selectionLines.points);
7
7
  const renderShape = (item) => {
8
8
  var _a, _b, _c, _d, _e, _f;
9
- const { id, x, y, width, height, fill, opacity, rotation = 0, shape, text, stroke, strokeWidth, labels, fontSize, fontColor, label, seatFill, src, points, seatPositions, radius, } = item;
9
+ const { id, x, y, width, height, fill, opacity, rotation = 0, shape, text, stroke, strokeWidth, labels, fontSize, fontColor, label, seatFill, src, points, seatPositions, radius = 10, } = item;
10
10
  const commonProps = {
11
11
  fill,
12
12
  opacity,
@@ -440,7 +440,7 @@ const Layers = ({ components, selectedComponent, activeTool, selectionLines, })
440
440
  const spacingWidth = availableWidth / seatCountTopBottom;
441
441
  const spacingHeight = availableHeight / seatCountLeftRight;
442
442
  const topSeats = distributeWithSpacing({
443
- start: 0,
443
+ start: x,
444
444
  length: width,
445
445
  count: top,
446
446
  radius: seatRadius,
@@ -453,7 +453,7 @@ const Layers = ({ components, selectedComponent, activeTool, selectionLines, })
453
453
  id: "top",
454
454
  }));
455
455
  const bottomSeats = distributeWithSpacing({
456
- start: 0,
456
+ start: x,
457
457
  length: width,
458
458
  count: bottom,
459
459
  radius: seatRadius,
@@ -472,7 +472,7 @@ const Layers = ({ components, selectedComponent, activeTool, selectionLines, })
472
472
  radius: seatRadius,
473
473
  spacing: spacingHeight,
474
474
  }).map((cy) => ({
475
- x: -seatSizeLR.w,
475
+ x: x - seatSizeLR.w,
476
476
  y: y + cy - seatSizeLR.h / 2,
477
477
  width: seatSizeLR.w,
478
478
  height: seatSizeLR.h,
@@ -485,7 +485,7 @@ const Layers = ({ components, selectedComponent, activeTool, selectionLines, })
485
485
  radius: seatRadius,
486
486
  spacing: spacingHeight,
487
487
  }).map((cy) => ({
488
- x: width,
488
+ x: x + width,
489
489
  y: y + cy - seatSizeLR.h / 2,
490
490
  width: seatSizeLR.w,
491
491
  height: seatSizeLR.h,
@@ -18,6 +18,21 @@ const boardSlice = createSlice({
18
18
  state.updateBy = action.payload;
19
19
  },
20
20
  addComponent: (state, action) => {
21
+ const currentPointer = state.pointer;
22
+ const totalHistory = state.historyChanges.length;
23
+ if (currentPointer < totalHistory) {
24
+ state.historyChanges = state.historyChanges.slice(0, currentPointer + 1);
25
+ }
26
+ const component = state.components;
27
+ const extraComponent = state.extraComponents;
28
+ state.historyChanges.push({
29
+ component,
30
+ extraComponent
31
+ });
32
+ if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
33
+ state.historyChanges.shift();
34
+ }
35
+ state.pointer += 1;
21
36
  state.components.push(action.payload);
22
37
  },
23
38
  removeComponent: (state, action) => {
@@ -43,14 +58,47 @@ const boardSlice = createSlice({
43
58
  state.extraComponents[indexExtra] = Object.assign(Object.assign({}, state.extraComponents[indexExtra]), action.payload);
44
59
  }
45
60
  },
46
- updateAllComponents: (state, action) => {
47
- [...state.components, ...state.extraComponents].forEach((component) => {
48
- const updatedComponent = action.payload.find((comp) => comp.id === component.id);
49
- if (updatedComponent) {
50
- Object.assign(component, Object.assign(Object.assign({}, component), updatedComponent));
61
+ updateComponentsBulk: (state, action) => {
62
+ const updates = action.payload;
63
+ // Simpan snapshot untuk undo (deep clone lebih aman)
64
+ state.historyChanges.push({
65
+ components: [...state.components],
66
+ extraComponents: [...state.extraComponents],
67
+ });
68
+ if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
69
+ state.historyChanges.shift();
70
+ }
71
+ state.pointer += 1;
72
+ updates.forEach((update) => {
73
+ const index = state.components.findIndex((component) => component.id === update.id);
74
+ const indexExtra = state.extraComponents.findIndex((extra) => extra.id === update.id);
75
+ if (index !== -1) {
76
+ state.components[index] = Object.assign(Object.assign({}, state.components[index]), update);
77
+ }
78
+ else if (indexExtra !== -1) {
79
+ state.extraComponents[indexExtra] = Object.assign(Object.assign({}, state.extraComponents[indexExtra]), update);
51
80
  }
52
81
  });
53
82
  },
83
+ // updateAllComponents: (state, action) => {
84
+ // const allComponents = action.payload;
85
+ // forEach(allComponents, (component) => {
86
+ // const index = state.components.findIndex(
87
+ // (c) => c.id === component.id
88
+ // );
89
+ // if (index !== -1) {
90
+ // state.components[index] = {
91
+ // ...state.components[index],
92
+ // ...component,
93
+ // };
94
+ // }
95
+ // });
96
+ // state.historyChanges.push(state.components);
97
+ // if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
98
+ // state.historyChanges.shift();
99
+ // }
100
+ // state.pointer += 1
101
+ // },
54
102
  setBackgroundColor: (state, action) => {
55
103
  state.backgroundColor = action.payload;
56
104
  },
@@ -61,22 +109,54 @@ const boardSlice = createSlice({
61
109
  state.historyChanges = state.historyChanges.slice(0, currentPointer + 1);
62
110
  }
63
111
  state.components = action.payload;
64
- state.historyChanges.push(state.components);
112
+ state.historyChanges.push({
113
+ components: [...state.components],
114
+ extraComponents: [...state.extraComponents],
115
+ });
65
116
  if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
66
117
  state.historyChanges.shift();
67
118
  }
68
119
  state.pointer += 1;
69
120
  },
70
121
  setNewExtraComponents: (state, action) => {
122
+ const currentPointer = state.pointer;
123
+ const totalHistory = state.historyChanges.length;
124
+ if (currentPointer < totalHistory) {
125
+ state.historyChanges = state.historyChanges.slice(0, currentPointer + 1);
126
+ }
127
+ state.historyChanges.push({
128
+ components: [...state.components],
129
+ extraComponents: [...state.extraComponents],
130
+ });
131
+ if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
132
+ state.historyChanges.shift();
133
+ }
134
+ state.pointer += 1;
71
135
  state.extraComponents = action.payload;
72
136
  },
73
137
  setExtraComponent: (state, action) => {
138
+ const currentPointer = state.pointer;
139
+ const totalHistory = state.historyChanges.length;
140
+ if (currentPointer < totalHistory) {
141
+ state.historyChanges = state.historyChanges.slice(0, currentPointer + 1);
142
+ }
143
+ const component = state.components;
144
+ const extraComponent = state.extraComponents;
145
+ state.historyChanges.push({
146
+ components: [...component],
147
+ extraComponents: [...extraComponent],
148
+ });
149
+ if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
150
+ state.historyChanges.shift();
151
+ }
152
+ state.pointer += 1;
74
153
  state.extraComponents.push(action.payload);
75
154
  },
76
155
  setFlagChange: (state, action) => {
77
156
  state.flagChange = action.payload;
78
157
  },
79
158
  undoHistory: (state) => {
159
+ var _a, _b, _c, _d;
80
160
  if (state.pointer > 1) {
81
161
  const lengthHistory = state.historyChanges.length;
82
162
  if (lengthHistory === state.pointer) {
@@ -86,20 +166,37 @@ const boardSlice = createSlice({
86
166
  state.pointer -= 1;
87
167
  }
88
168
  const prev = state.historyChanges[state.pointer];
89
- state.components = current(prev);
169
+ console.log({ prev });
170
+ state.components = current(prev === null || prev === void 0 ? void 0 : prev.components);
171
+ state.extraComponents = current(prev === null || prev === void 0 ? void 0 : prev.extraComponents);
90
172
  }
91
173
  else if (state.pointer === 1) {
92
- state.components = current(state.historyChanges[0]);
174
+ state.components = current((_b = (_a = state.historyChanges) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.components);
175
+ state.extraComponents = current((_d = (_c = state.historyChanges) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.extraComponents);
93
176
  state.pointer = 0;
94
177
  }
178
+ state.updateBy = "global";
95
179
  },
96
180
  redoHistory: (state) => {
97
181
  if (state.pointer < state.historyChanges.length - 1) {
98
182
  const next = state.historyChanges[state.pointer + 1];
99
- state.components = current(next);
183
+ state.components = current(next === null || next === void 0 ? void 0 : next.components);
184
+ state.extraComponents = current(next === null || next === void 0 ? void 0 : next.extraComponents);
100
185
  state.pointer += 1;
186
+ state.updateBy = "global";
101
187
  }
102
188
  },
189
+ setInitialValue: (state, action) => {
190
+ const { components, extraComponents, backgroundColor } = action.payload;
191
+ state.components = components;
192
+ state.extraComponents = extraComponents;
193
+ state.pointer = 0;
194
+ state.backgroundColor = backgroundColor;
195
+ state.historyChanges = [{
196
+ components,
197
+ extraComponents
198
+ }];
199
+ }
103
200
  },
104
201
  });
105
202
  export const { addComponent, removeComponent, updateComponent, setBackgroundColor, removeExtraComponent } = boardSlice.actions;
@@ -156,14 +156,13 @@ const BoardTemplate = ({ refs }) => {
156
156
  minY = findBoundingBox.y;
157
157
  }
158
158
  if ((minX !== Infinity || minY !== Infinity) && !activeTool) {
159
- console.log("minX", minX, "minY", minY, "maxX", maxX, "maxY", maxY, "Haduhhh");
160
159
  (_h = transformRef.current) === null || _h === void 0 ? void 0 : _h.setTransform(-minX, -minY, scale);
161
160
  setHasInitialzed(true);
162
161
  }
163
162
  }, [componentsProps, extraComponentsProps]);
164
163
  const queueUpdateComponents = (data) => {
165
164
  dispatch({
166
- type: "board/setNewComponents",
165
+ type: "board/updateComponentsBulk",
167
166
  payload: data,
168
167
  });
169
168
  };
@@ -181,10 +180,6 @@ const BoardTemplate = ({ refs }) => {
181
180
  }, 1000));
182
181
  // Redux → Local
183
182
  useEffect(() => {
184
- console.log({
185
- flagChange,
186
- updateBy
187
- }, "haduuhhh");
188
183
  if (flagChange && updateBy === "global") {
189
184
  if (!isEqual(selectedComponentProps, selectedComponent)) {
190
185
  isSyncingFromRedux.current = true;
@@ -213,29 +208,31 @@ const BoardTemplate = ({ refs }) => {
213
208
  const updatedExtra = updateSingleComponent(extraComponentsState, component, setExtraComponentsState);
214
209
  if (updatedExtra) {
215
210
  dispatch({ type: "board/setUpdateBy", payload: "local" });
216
- queueUpdateExtraComponents(updatedExtra);
217
- debouncedSyncExtraComponents.current(updatedExtra);
211
+ queueUpdateComponents(updatedExtra);
218
212
  }
219
213
  };
220
214
  const updateComponentsAttribute = (components) => {
221
215
  if (!components.length)
222
216
  return;
223
- const isExtra = components === null || components === void 0 ? void 0 : components.filter((item) => (item === null || item === void 0 ? void 0 : item.shape) === "polygon");
224
- if (isExtra) {
225
- const nextExtra = updateManyComponents(extraComponentsState, components, setExtraComponentsState);
226
- dispatch({ type: "board/setUpdateBy", payload: "local" });
227
- queueUpdateComponents(nextExtra);
228
- }
217
+ // const isExtra = components?.filter((item) => item?.shape === "polygon");
218
+ // if (isExtra) {
219
+ // const nextExtra = updateManyComponents(
220
+ // extraComponentsState,
221
+ // components,
222
+ // setExtraComponentsState
223
+ // );
224
+ // dispatch({ type: "board/setUpdateBy", payload: "local" });
225
+ // queueUpdateComponents(nextExtra);
226
+ // }
229
227
  const nextComponents = updateManyComponents(componentsState, components, setComponentsState);
230
228
  dispatch({ type: "board/setUpdateBy", payload: "local" });
231
- queueUpdateExtraComponents(nextComponents);
229
+ // queueUpdateExtraComponents(nextComponents);
232
230
  };
233
231
  const addComponents = (component) => {
234
232
  const index = extraComponentsState.findIndex((c) => (c === null || c === void 0 ? void 0 : c.shape) === "bounding-box");
235
233
  const nextExtraComponents = index !== -1
236
234
  ? extraComponentsState.map((item, i) => i === index ? component : item)
237
235
  : [...extraComponentsState, component];
238
- console.log({ nextExtraComponents });
239
236
  setExtraComponentsState(nextExtraComponents);
240
237
  dispatch({
241
238
  type: "board/setNewExtraComponents",
@@ -293,8 +290,44 @@ const BoardTemplate = ({ refs }) => {
293
290
  dispatch({ type: "panel/setShow", payload: false });
294
291
  dataElementSelectionGroupRef.current = [];
295
292
  };
293
+ const stillHoldShift = useRef(false);
294
+ useEffect(() => {
295
+ var _a, _b;
296
+ if (stillHoldShift.current && dataElementSelectionGroupRef.current) {
297
+ const selectionLines = (_a = svgRef.current) === null || _a === void 0 ? void 0 : _a.querySelector("#selection-lines");
298
+ selectionLines === null || selectionLines === void 0 ? void 0 : selectionLines.setAttribute("pointer-events", "none");
299
+ }
300
+ if (!stillHoldShift.current && dataElementSelectionGroupRef.current) {
301
+ const selectionLines = (_b = svgRef.current) === null || _b === void 0 ? void 0 : _b.querySelector("#selection-lines");
302
+ selectionLines === null || selectionLines === void 0 ? void 0 : selectionLines.setAttribute("pointer-events", "all");
303
+ }
304
+ }, [stillHoldShift.current, dataElementSelectionGroupRef.current]);
305
+ useEffect(() => {
306
+ const handleKeyDown = (e) => {
307
+ var _a, _b;
308
+ // setPressedKey(e.key);
309
+ const selectionLines = (_a = svgRef.current) === null || _a === void 0 ? void 0 : _a.querySelector("#selection-lines");
310
+ (_b = svgRef.current) === null || _b === void 0 ? void 0 : _b.querySelector("#selection-lines");
311
+ if (e.key === "Shift") {
312
+ stillHoldShift.current = true;
313
+ selectionLines === null || selectionLines === void 0 ? void 0 : selectionLines.setAttribute("pointer-events", "none");
314
+ }
315
+ };
316
+ const handleKeyUp = () => {
317
+ var _a;
318
+ const selectionLines = (_a = svgRef.current) === null || _a === void 0 ? void 0 : _a.querySelector("#selection-lines");
319
+ stillHoldShift.current = false;
320
+ selectionLines === null || selectionLines === void 0 ? void 0 : selectionLines.setAttribute("pointer-events", "all");
321
+ };
322
+ window.addEventListener("keydown", handleKeyDown);
323
+ window.addEventListener("keyup", handleKeyUp);
324
+ return () => {
325
+ window.removeEventListener("keydown", handleKeyDown);
326
+ window.removeEventListener("keyup", handleKeyUp);
327
+ };
328
+ }, [dataElementSelectionGroupRef.current]);
296
329
  const handlePointerDown = (e) => {
297
- var _a, _b, _c, _d, _e, _f;
330
+ var _a, _b, _c, _d, _e, _f, _g;
298
331
  const shiftActive = e.shiftKey;
299
332
  const svg = svgRef.current;
300
333
  if (!e.isPrimary)
@@ -344,6 +377,7 @@ const BoardTemplate = ({ refs }) => {
344
377
  if (targetRotate) {
345
378
  isRotatingRef.current = true;
346
379
  }
380
+ const targetSelectionBox = e.target.closest("g[id='selection-lines']");
347
381
  // RESIZE
348
382
  const targetGroup = e.target.closest("g[data-id]");
349
383
  const targetPointPolygon = e.target.closest("circle[data-point]");
@@ -357,8 +391,16 @@ const BoardTemplate = ({ refs }) => {
357
391
  const { g } = getAttributeElement(svg, activeId);
358
392
  if (targetGroup && shiftActive) {
359
393
  const findById = [...componentsState, ...extraComponentsState].find((comp) => comp.id == activeId);
360
- const dataSelection = [...dataElementSelectionGroupRef.current, findById];
361
- dataElementSelectionGroupRef.current = dataSelection;
394
+ const currentSelection = (_e = dataElementSelectionGroupRef.current) !== null && _e !== void 0 ? _e : [];
395
+ const alreadySelected = currentSelection.some((comp) => comp.id == activeId);
396
+ let newSelection;
397
+ if (alreadySelected) {
398
+ newSelection = currentSelection.filter((comp) => comp.id != activeId);
399
+ }
400
+ else {
401
+ newSelection = [...currentSelection, findById];
402
+ }
403
+ dataElementSelectionGroupRef.current = newSelection;
362
404
  }
363
405
  const box = getGlobalBBox(svg, g);
364
406
  const { x: initialXG, y: initialYG } = getTranslate(g);
@@ -367,7 +409,7 @@ const BoardTemplate = ({ refs }) => {
367
409
  const hitPoint = document.elementFromPoint(clientX, clientY);
368
410
  // CHECK FOR HIT ON SVG FOR SELECTION BOX
369
411
  // MAKE AND UNMAKE SELECTION BOX START ------
370
- const hadSelectionBox = ((_e = dataElementSelectionGroupRef.current) === null || _e === void 0 ? void 0 : _e.length) > 0 && !isSingleSelection;
412
+ const hadSelectionBox = ((_f = dataElementSelectionGroupRef.current) === null || _f === void 0 ? void 0 : _f.length) > 0 && !isSingleSelection;
371
413
  const downInSelectionBox = hadSelectionBox && (hitPoint === null || hitPoint === void 0 ? void 0 : hitPoint.nodeName) !== "svg";
372
414
  const downOutSelectionBox = hadSelectionBox && (hitPoint === null || hitPoint === void 0 ? void 0 : hitPoint.nodeName) === "svg";
373
415
  const downBeforeHasSelectionBox = !downInSelectionBox &&
@@ -404,7 +446,7 @@ const BoardTemplate = ({ refs }) => {
404
446
  shape: nameShapeSelectionBoxGhost,
405
447
  id: idSelectionBoxGhost,
406
448
  });
407
- (_f = svgRef.current) === null || _f === void 0 ? void 0 : _f.appendChild(boxSelection);
449
+ (_g = svgRef.current) === null || _g === void 0 ? void 0 : _g.appendChild(boxSelection);
408
450
  }
409
451
  // MAKE AND UNMAKE SELECTION BOX END ------
410
452
  // RESIZE SELECTION BOX
@@ -417,16 +459,22 @@ const BoardTemplate = ({ refs }) => {
417
459
  !downOutSelectionBox &&
418
460
  isInSelectionTarget &&
419
461
  !isSingleSelection &&
420
- !isInTargetElement && !isInitialCreateBoundingBox;
421
- const downAtResizePositionAndHasSelectionBox = downAtResizePosition && hadSelectionBox && !isRotateSelectionBox && !isInitialCreateBoundingBox;
462
+ !isInTargetElement &&
463
+ !isInitialCreateBoundingBox;
464
+ const downAtResizePositionAndHasSelectionBox = downAtResizePosition &&
465
+ hadSelectionBox &&
466
+ !isRotateSelectionBox &&
467
+ !isInitialCreateBoundingBox;
422
468
  const isMightResizeElement = !isEmpty(selectedComponent) &&
423
469
  downAtResizePosition &&
424
470
  downAtResizePosition &&
425
- !hadSelectionBox && !isInitialCreateBoundingBox;
471
+ !hadSelectionBox &&
472
+ !isInitialCreateBoundingBox;
426
473
  const isMightMove = activeId &&
427
474
  !targetPointPolygon &&
428
475
  isInTargetElement &&
429
- !isMightResizeElement && !isInitialCreateBoundingBox;
476
+ !isMightResizeElement &&
477
+ !isInitialCreateBoundingBox;
430
478
  const isMightMoveOneElementSelection = isSingleSelection && !isMightResizeElement && !isInitialCreateBoundingBox;
431
479
  if (downOutResizePositionAndInSelectionBox) {
432
480
  onMoveSelectionBoxRef.current = true;
@@ -20,7 +20,7 @@ export interface TableEditorProps {
20
20
  ];
21
21
  statusKey: string;
22
22
  defaultBackground?: string;
23
- action?: (file: UploadFile<File>, type: string, defaultValue: PropertiesProps) => Promise<PropertiesProps>;
23
+ action?: (file: UploadFile<File>, type: string, defaultValue: PropertiesProps) => Promise<string>;
24
24
  responseMapping?: {
25
25
  status: string;
26
26
  message: string;
@@ -80,7 +80,9 @@ const TableEditor = (props) => {
80
80
  return mappingData;
81
81
  };
82
82
  useEffect(() => {
83
- if (!isEqual(components, convertComponentProps()) && componentProps) {
83
+ const initialComponent = !isEqual(components, convertComponentProps()) && componentProps;
84
+ const initialExtraComponent = !isEqual(extraComponents, extraComponentProps) && extraComponentProps;
85
+ if (initialComponent || initialExtraComponent) {
84
86
  let mappingData = componentProps === null || componentProps === void 0 ? void 0 : componentProps.map((item) => {
85
87
  if (mappingKey && (item === null || item === void 0 ? void 0 : item[props.mappingKey])) {
86
88
  return Object.assign({}, item[props.mappingKey]);
@@ -91,25 +93,33 @@ const TableEditor = (props) => {
91
93
  setInitialValue(componentProps);
92
94
  }
93
95
  dispatch({
94
- type: "board/setNewComponents",
95
- payload: mappingData,
96
- });
97
- dispatch({ type: "board/setFlagChange", payload: true });
98
- }
99
- if (!isEqual(extraComponents, extraComponentProps) && extraComponentProps) {
100
- dispatch({
101
- type: "board/setNewExtraComponents",
102
- payload: extraComponentProps,
103
- });
104
- dispatch({ type: "board/setFlagChange", payload: true });
105
- }
106
- if (props === null || props === void 0 ? void 0 : props.defaultBackground) {
107
- dispatch({
108
- type: "board/setBackgroundColor",
109
- payload: props === null || props === void 0 ? void 0 : props.defaultBackground,
96
+ type: "board/setInitialValue",
97
+ payload: {
98
+ components: mappingData,
99
+ extraComponents: extraComponentProps,
100
+ backgroundColor: props === null || props === void 0 ? void 0 : props.defaultBackground,
101
+ },
110
102
  });
103
+ // dispatch({
104
+ // type: "board/setNewComponents",
105
+ // payload: mappingData,
106
+ // });
111
107
  dispatch({ type: "board/setFlagChange", payload: true });
112
108
  }
109
+ // if (!isEqual(extraComponents, extraComponentProps) && extraComponentProps) {
110
+ // dispatch({
111
+ // type: "board/setNewExtraComponents",
112
+ // payload: extraComponentProps,
113
+ // });
114
+ // dispatch({ type: "board/setFlagChange", payload: true });
115
+ // }
116
+ // if (props?.defaultBackground) {
117
+ // dispatch({
118
+ // type: "board/setBackgroundColor",
119
+ // payload: props?.defaultBackground,
120
+ // });
121
+ // dispatch({ type: "board/setFlagChange", payload: true });
122
+ // }
113
123
  }, [componentProps, extraComponentProps, props === null || props === void 0 ? void 0 : props.defaultBackground]);
114
124
  return (<>
115
125
  <div className="w-full h-screen flex relative">
@@ -118,7 +128,7 @@ const TableEditor = (props) => {
118
128
  </div>) : (<div key={`${viewOnly}`} className="w-full h-full flex relative">
119
129
  <SideTool dragOnly={dragOnly} deleteAutorized={deleteAutorized}/>
120
130
  <Board key={`${viewOnly}`} refs={refsBoard}/>
121
- <ControlPanels action={props.action} responseMapping={props.responseMapping}/>
131
+ <ControlPanels action={props.action}/>
122
132
  </div>)}
123
133
  </div>
124
134
  </>);
@@ -1,13 +1,7 @@
1
1
  import { UploadFile } from "antd";
2
2
  import { PropertiesProps } from "../../dto/table";
3
3
  interface ControlPanelsProps {
4
- action?: (file: UploadFile<File>, type: string, defaultValue: PropertiesProps) => Promise<PropertiesProps>;
5
- responseMapping?: {
6
- status: string;
7
- message: string;
8
- data: string;
9
- src: string;
10
- };
4
+ action?: (file: UploadFile<File>, type: string, defaultValue: PropertiesProps) => Promise<string>;
11
5
  }
12
6
  declare const ControlPanels: (props: ControlPanelsProps) => import("react").JSX.Element;
13
7
  export default ControlPanels;
@@ -25,7 +25,7 @@ import { SEAT_SHAPES } from "../../utils/constant";
25
25
  import { adjustHeightWidthForSeatShape, getSeatCount, getSeatPosition, isSeatShape, } from "./utils";
26
26
  import SeatSquare from "./table-seat-square";
27
27
  const ControlPanels = (props) => {
28
- const { action, responseMapping } = props;
28
+ const { action } = props;
29
29
  const dispatch = useAppDispatch();
30
30
  const theme = useAppSelector((state) => state.theme);
31
31
  const tool = useAppSelector((state) => state.tool);
@@ -43,6 +43,7 @@ const ControlPanels = (props) => {
43
43
  let values = Form.useWatch([], form);
44
44
  useEffect(() => {
45
45
  if (selectedComponent) {
46
+ console.log("selectedComponent", selectedComponent);
46
47
  const isDifferentId = (selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.id) !== (values === null || values === void 0 ? void 0 : values.id) || !(values === null || values === void 0 ? void 0 : values.id);
47
48
  const isSameIdAndSameDimensions = (selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.id) === (values === null || values === void 0 ? void 0 : values.id) &&
48
49
  (selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.height) === (values === null || values === void 0 ? void 0 : values.height) &&
@@ -55,6 +56,7 @@ const ControlPanels = (props) => {
55
56
  form.setFieldsValue(selectedComponent);
56
57
  }
57
58
  else if (selectedGroup) {
59
+ console.log("selectedGroup", selectedGroup);
58
60
  if (show)
59
61
  setOpen(true);
60
62
  if (!show)
@@ -74,11 +76,23 @@ const ControlPanels = (props) => {
74
76
  const isSameOpacity = isSameAllByKey(selectedGroup, "opacity");
75
77
  const isSampeRotation = isSameAllByKey(selectedGroup, "rotation");
76
78
  const isSameStrokeWidth = isSameAllByKey(selectedGroup, "strokeWidth");
77
- form.setFieldsValue(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (isSameAllWidth ? { width: selectedGroup[0].width } : {})), (isSameAllHeight ? { height: selectedGroup[0].height } : {})), (isSameX ? { x: selectedGroup[0].x } : {})), (isSameY ? { y: selectedGroup[0].y } : {})), (isSameFill ? { fill: selectedGroup[0].fill } : {})), (isSameStroke ? { stroke: selectedGroup[0].stroke } : {})), (isSameOpacity ? { opacity: selectedGroup[0].opacity } : {})), (isSampeRotation ? { rotation: selectedGroup[0].rotation } : {})), (isSameStrokeWidth
79
+ console.log({
80
+ isSameAllWidth,
81
+ isSameAllHeight,
82
+ isSameX,
83
+ isSameY,
84
+ isSameFill,
85
+ isSameStroke,
86
+ isSameOpacity,
87
+ isSampeRotation,
88
+ isSameStrokeWidth,
89
+ });
90
+ form.setFieldsValue(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (isSameAllWidth ? { width: selectedGroup[0].width } : undefined)), (isSameAllHeight ? { height: selectedGroup[0].height } : undefined)), (isSameX ? { x: selectedGroup[0].x } : undefined)), (isSameY ? { y: selectedGroup[0].y } : undefined)), (isSameFill ? { fill: selectedGroup[0].fill } : undefined)), (isSameStroke ? { stroke: selectedGroup[0].stroke } : undefined)), (isSameOpacity ? { opacity: selectedGroup[0].opacity } : undefined)), (isSampeRotation ? { rotation: selectedGroup[0].rotation } : undefined)), (isSameStrokeWidth
78
91
  ? { strokeWidth: selectedGroup[0].strokeWidth }
79
92
  : {})));
80
93
  }
81
94
  else {
95
+ console.log("selectedGroup", selectedGroup);
82
96
  setOpen(false);
83
97
  }
84
98
  }, [selectedComponent, selectedGroup, show]);
@@ -129,6 +143,8 @@ const ControlPanels = (props) => {
129
143
  type: "board/updateAllComponents",
130
144
  payload: data,
131
145
  });
146
+ dispatch({ type: "board/setFlagChange", payload: true });
147
+ dispatch({ type: "board/setUpdateBy", payload: "global" });
132
148
  }, 300));
133
149
  const debouncedSyncForm = useRef(debounce(() => {
134
150
  dispatch({ type: "board/setFlagChange", payload: true });
@@ -147,11 +163,12 @@ const ControlPanels = (props) => {
147
163
  const newElement = Object.assign(Object.assign(Object.assign({}, findElement), values), { x: (_a = values.x) !== null && _a !== void 0 ? _a : findElement.x, y: (_b = values.y) !== null && _b !== void 0 ? _b : findElement.y, width: isAdjustSize ? forceSize.width : (_c = values.width) !== null && _c !== void 0 ? _c : findElement.width, height: isAdjustSize
148
164
  ? forceSize.height
149
165
  : (_d = values.height) !== null && _d !== void 0 ? _d : findElement.height });
150
- const { g, element } = getAttributeElement((_e = svgRef === null || svgRef === void 0 ? void 0 : svgRef.current) === null || _e === void 0 ? void 0 : _e[1], id);
166
+ const svg = (_f = (_e = svgRef === null || svgRef === void 0 ? void 0 : svgRef.current) === null || _e === void 0 ? void 0 : _e[1]) !== null && _f !== void 0 ? _f : (_g = svgRef === null || svgRef === void 0 ? void 0 : svgRef.current) === null || _g === void 0 ? void 0 : _g[0];
167
+ const { g, element } = getAttributeElement(svg, id);
151
168
  applyResizeToSvgElement(element, g, newElement);
152
- const getBBox = getGlobalBBox((_f = svgRef === null || svgRef === void 0 ? void 0 : svgRef.current) === null || _f === void 0 ? void 0 : _f[1], g);
169
+ const getBBox = getGlobalBBox(svg, g);
153
170
  debouncedSyncSelectedSelectionLines.current(Object.assign({}, getBBox));
154
- updateSelectionBox((_g = svgRef === null || svgRef === void 0 ? void 0 : svgRef.current) === null || _g === void 0 ? void 0 : _g[1], getBBox);
171
+ updateSelectionBox(svg, getBBox);
155
172
  };
156
173
  const handleChangeComponent = (values, allValues) => {
157
174
  const { shape } = allValues, restProps = __rest(allValues, ["shape"]);
@@ -159,10 +176,6 @@ const ControlPanels = (props) => {
159
176
  if (selectedComponent) {
160
177
  updateElement(allValues.id, values);
161
178
  debouncedSyncComponents.current(Object.assign(Object.assign({}, (selectedComponent || {})), newValues));
162
- // debouncedSyncSelectedComponents.current({
163
- // ...(selectedComponent || {}),
164
- // ...newValues,
165
- // });
166
179
  }
167
180
  if ((selectedGroup === null || selectedGroup === void 0 ? void 0 : selectedGroup.length) > 0) {
168
181
  const { width, height, x, y, fill, stroke, opacity, rotation, strokeWidth, } = newValues;
@@ -203,7 +216,7 @@ const ControlPanels = (props) => {
203
216
  const renderFormPanel = () => {
204
217
  switch (tool.active) {
205
218
  case "select":
206
- return (<SelectToolForm action={action} responseMapping={responseMapping}/>);
219
+ return (<SelectToolForm action={action}/>);
207
220
  case "square":
208
221
  case "circle":
209
222
  return <SquareToolForm />;
@@ -212,9 +225,9 @@ const ControlPanels = (props) => {
212
225
  case "table-seat-square":
213
226
  return <SeatSquare />;
214
227
  case "image-table":
215
- return (<UploadTool name={tool.active} type="component" action={action} responseMapping={responseMapping}/>);
228
+ return (<UploadTool name={tool.active} type="component" action={action}/>);
216
229
  case "background":
217
- return (<UploadTool name={tool.active} type="background" action={action} responseMapping={responseMapping}/>);
230
+ return (<UploadTool name={tool.active} type="background" action={action}/>);
218
231
  default:
219
232
  return null;
220
233
  }
@@ -1,6 +1,5 @@
1
- declare const SelectToolForm: ({ title, action, responseMapping }: {
1
+ declare const SelectToolForm: ({ title, action }: {
2
2
  title?: string;
3
3
  action: any;
4
- responseMapping: any;
5
4
  }) => import("react").JSX.Element;
6
5
  export default SelectToolForm;