seat-editor 3.2.27 → 3.3.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.
@@ -216,7 +216,10 @@ const TouchScrollDetect = () => {
216
216
  ]} eventMatchTable={[
217
217
  {
218
218
  event: "mouseenter",
219
- properties: { strokeWidth: 5, filter: "drop-shadow(0px 0px 5px red)" },
219
+ properties: {
220
+ strokeWidth: 5,
221
+ filter: "drop-shadow(0px 0px 5px red)",
222
+ },
220
223
  },
221
224
  {
222
225
  event: "dragenter",
@@ -1,9 +1,11 @@
1
1
  "use client";
2
2
  import { isEmpty, omit } from "lodash";
3
3
  import { arcByDirection, distributeWithSpacing, rectToPolygonNodes, rectToPolygonPoints, } from "./utils";
4
+ import { useAppSelector } from "@/hooks/use-redux";
4
5
  const Layers = ({ components, selectedComponent, activeTool, selectionLines, }) => {
5
6
  var _a;
6
7
  const hasPoints = selectionLines && !isEmpty(selectionLines === null || selectionLines === void 0 ? void 0 : selectionLines.points);
8
+ const lockBackground = useAppSelector((state) => state.tool.lockBackground);
7
9
  const renderShape = (item) => {
8
10
  var _a, _b, _c, _d, _e, _f;
9
11
  const { id, x, y, width, height, fill, opacity, rotation = 0, shape, text, stroke, strokeWidth, labels, fontSize, fontColor, label, seatFill, src, points, seatPositions, radius = 0, } = item;
@@ -532,7 +534,9 @@ const Layers = ({ components, selectedComponent, activeTool, selectionLines, })
532
534
  </g>);
533
535
  case "image-table":
534
536
  case "background":
535
- return (<g key={id} id={id} data-id={id} transform={`translate(${x}, ${y})`}>
537
+ return (<g key={id} id={id} data-id={id} transform={`translate(${x}, ${y})`} style={{
538
+ pointerEvents: lockBackground ? "none" : "auto",
539
+ }}>
536
540
  <g transform={`rotate(${rotation}, 0, 0)`}>
537
541
  <image href={src} width={width} height={height} {...commonProps}/>
538
542
  <g transform={`rotate(${-rotation}, ${width / 2}, ${height / 2})`}>
@@ -552,7 +556,7 @@ const Layers = ({ components, selectedComponent, activeTool, selectionLines, })
552
556
  </g>
553
557
  </g>);
554
558
  case "bounding-box": {
555
- return (<g key={id} transform={`translate(${x}, ${y})`} data-id={id}>
559
+ return (<g key={id} transform={`translate(${x}, ${y})`} data-bounding-box={id}>
556
560
  <rect width={width} height={height} fill="none" stroke="#3b82f6" strokeWidth={1} strokeDasharray="6 4" pointerEvents="none"/>
557
561
  </g>);
558
562
  }
@@ -1,4 +1,3 @@
1
- import { Position } from "@/dto/table";
2
1
  export declare const tagsDummy: (name: string, icon: string) => ({
3
2
  gap: string;
4
3
  key: string;
@@ -40,7 +39,7 @@ export declare const tagsDummy: (name: string, icon: string) => ({
40
39
  symbol: {
41
40
  value: string;
42
41
  gap: number;
43
- position: Position;
42
+ position: string;
44
43
  };
45
44
  fontWeight?: undefined;
46
45
  textDecoration?: undefined;
@@ -51,9 +51,10 @@ export const tagsDummy = (name, icon) => [
51
51
  symbol: {
52
52
  value: "+1",
53
53
  gap: 1,
54
- position: "right-top", // right | right-top | right-bottom | left | left-top | left-bottom | top | bottom
54
+ position: "right-top"
55
55
  },
56
56
  },
57
+ // as Position, // right | right-top | right-bottom | left | left-top | left-bottom | top | bottom
57
58
  // {
58
59
  // type: "text",
59
60
  // value: "23:00",
@@ -7,6 +7,7 @@ export interface InitialState {
7
7
  backgroundColor: string;
8
8
  themeColor: string;
9
9
  extraComponents: Component[];
10
+ boundingBox: Component | null;
10
11
  flagChange: boolean;
11
12
  historyChanges: any[];
12
13
  pointer: number;
@@ -5,6 +5,7 @@ const initialState = {
5
5
  backgroundColor: "#FFFFFF",
6
6
  themeColor: "#4A90E2",
7
7
  extraComponents: [],
8
+ boundingBox: null,
8
9
  flagChange: false,
9
10
  historyChanges: [],
10
11
  pointer: 0,
@@ -35,9 +36,13 @@ const boardSlice = createSlice({
35
36
  state.components.push(action.payload);
36
37
  const component = state.components;
37
38
  const extraComponent = state.extraComponents;
39
+ const boundingBox = state.boundingBox;
40
+ const backgroundColor = state.backgroundColor;
38
41
  state.historyChanges.push({
39
42
  component,
40
43
  extraComponent,
44
+ boundingBox,
45
+ backgroundColor,
41
46
  });
42
47
  },
43
48
  removeComponent: (state, action) => {
@@ -64,6 +69,8 @@ const boardSlice = createSlice({
64
69
  state.historyChanges.push({
65
70
  components: [...state.components],
66
71
  extraComponents: [...state.extraComponents],
72
+ boundingBox: state.boundingBox,
73
+ backgroundColor: state.backgroundColor,
67
74
  });
68
75
  if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
69
76
  state.historyChanges.shift();
@@ -88,6 +95,8 @@ const boardSlice = createSlice({
88
95
  state.historyChanges.push({
89
96
  components: [...state.components],
90
97
  extraComponents: [...state.extraComponents],
98
+ boundingBox: state.boundingBox,
99
+ backgroundColor: state.backgroundColor,
91
100
  });
92
101
  if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
93
102
  state.historyChanges.shift();
@@ -102,14 +111,34 @@ const boardSlice = createSlice({
102
111
  state.components[index] = Object.assign(Object.assign({}, state.components[index]), component);
103
112
  }
104
113
  });
105
- state.historyChanges.push(state.components);
114
+ state.historyChanges.push({
115
+ components: [...state.components],
116
+ extraComponents: [...state.extraComponents],
117
+ boundingBox: state.boundingBox,
118
+ backgroundColor: state.backgroundColor,
119
+ });
106
120
  if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
107
121
  state.historyChanges.shift();
108
122
  }
109
123
  state.pointer += 1;
110
124
  },
111
125
  setBackgroundColor: (state, action) => {
126
+ const currentPointer = state.pointer;
127
+ const totalHistory = state.historyChanges.length;
128
+ if (currentPointer < totalHistory) {
129
+ state.historyChanges = state.historyChanges.slice(0, currentPointer + 1);
130
+ }
131
+ if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
132
+ state.historyChanges.shift();
133
+ }
134
+ state.pointer += 1;
112
135
  state.backgroundColor = action.payload;
136
+ state.historyChanges.push({
137
+ components: [...state.components],
138
+ extraComponents: [...state.extraComponents],
139
+ boundingBox: state.boundingBox,
140
+ backgroundColor: state.backgroundColor,
141
+ });
113
142
  },
114
143
  setNewComponents: (state, action) => {
115
144
  const currentPointer = state.pointer;
@@ -121,6 +150,8 @@ const boardSlice = createSlice({
121
150
  state.historyChanges.push({
122
151
  components: [...state.components],
123
152
  extraComponents: [...state.extraComponents],
153
+ boundingBox: state.boundingBox,
154
+ backgroundColor: state.backgroundColor,
124
155
  });
125
156
  if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
126
157
  state.historyChanges.shift();
@@ -136,6 +167,8 @@ const boardSlice = createSlice({
136
167
  state.historyChanges.push({
137
168
  components: [...state.components],
138
169
  extraComponents: [...state.extraComponents],
170
+ boundingBox: state.boundingBox,
171
+ backgroundColor: state.backgroundColor,
139
172
  });
140
173
  if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
141
174
  state.historyChanges.shift();
@@ -159,13 +192,15 @@ const boardSlice = createSlice({
159
192
  state.historyChanges.push({
160
193
  components: [...component],
161
194
  extraComponents: [...extraComponent],
195
+ boundingBox: state.boundingBox,
196
+ backgroundColor: state.backgroundColor,
162
197
  });
163
198
  },
164
199
  setFlagChange: (state, action) => {
165
200
  state.flagChange = action.payload;
166
201
  },
167
202
  undoHistory: (state) => {
168
- var _a, _b, _c, _d;
203
+ var _a, _b, _c, _d, _e, _f, _g, _h;
169
204
  if (state.pointer > 1) {
170
205
  const lengthHistory = state.historyChanges.length;
171
206
  if (lengthHistory === state.pointer) {
@@ -177,10 +212,14 @@ const boardSlice = createSlice({
177
212
  const prev = state.historyChanges[state.pointer];
178
213
  state.components = current(prev === null || prev === void 0 ? void 0 : prev.components);
179
214
  state.extraComponents = current(prev === null || prev === void 0 ? void 0 : prev.extraComponents);
215
+ state.boundingBox = current(prev === null || prev === void 0 ? void 0 : prev.boundingBox);
216
+ state.backgroundColor = prev === null || prev === void 0 ? void 0 : prev.backgroundColor;
180
217
  }
181
218
  else if (state.pointer === 1) {
182
219
  state.components = current((_b = (_a = state.historyChanges) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.components);
183
220
  state.extraComponents = current((_d = (_c = state.historyChanges) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.extraComponents);
221
+ state.boundingBox = (_f = (_e = state.historyChanges) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.boundingBox;
222
+ state.backgroundColor = (_h = (_g = state.historyChanges) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.backgroundColor;
184
223
  state.pointer = 0;
185
224
  }
186
225
  state.updateBy = "global";
@@ -190,23 +229,45 @@ const boardSlice = createSlice({
190
229
  const next = state.historyChanges[state.pointer + 1];
191
230
  state.components = current(next === null || next === void 0 ? void 0 : next.components);
192
231
  state.extraComponents = current(next === null || next === void 0 ? void 0 : next.extraComponents);
232
+ state.boundingBox = current(next === null || next === void 0 ? void 0 : next.boundingBox);
193
233
  state.pointer += 1;
194
234
  state.updateBy = "global";
195
235
  }
196
236
  },
197
237
  setInitialValue: (state, action) => {
198
- const { components, extraComponents, backgroundColor } = action.payload;
238
+ const { components, extraComponents, backgroundColor, boundingBox } = action.payload;
199
239
  state.components = components;
200
240
  state.extraComponents = extraComponents;
201
241
  state.pointer = 0;
202
242
  state.backgroundColor = backgroundColor;
243
+ state.boundingBox = boundingBox;
203
244
  state.historyChanges = [
204
245
  {
205
246
  components,
206
247
  extraComponents,
248
+ boundingBox,
249
+ backgroundColor,
207
250
  },
208
251
  ];
209
252
  },
253
+ setBoundingBox: (state, action) => {
254
+ const currentPointer = state.pointer;
255
+ const totalHistory = state.historyChanges.length;
256
+ if (currentPointer < totalHistory) {
257
+ state.historyChanges = state.historyChanges.slice(0, currentPointer + 1);
258
+ }
259
+ if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
260
+ state.historyChanges.shift();
261
+ }
262
+ state.pointer += 1;
263
+ state.boundingBox = action.payload;
264
+ state.historyChanges.push({
265
+ components: [...state.components],
266
+ extraComponents: [...state.extraComponents],
267
+ boundingBox: state.boundingBox,
268
+ backgroundColor: state.backgroundColor,
269
+ });
270
+ },
210
271
  },
211
272
  });
212
273
  export const { addComponent, removeComponent, updateComponent, setBackgroundColor, removeExtraComponent, } = boardSlice.actions;
@@ -66,7 +66,7 @@ const BoardTemplate = ({ refs, loadingRender }) => {
66
66
  //polygon
67
67
  const polygonElementRef = useRef([]);
68
68
  const isOnMakePolygonRef = useRef(false);
69
- const { components: componentsProps, extraComponents: extraComponentsProps, flagChange, updateBy, isShowTagType } = useAppSelector((state) => state.board);
69
+ const { components: componentsProps, extraComponents: extraComponentsProps, boundingBox, flagChange, updateBy, isShowTagType, } = useAppSelector((state) => state.board);
70
70
  const { selectionLines } = useAppSelector((state) => state.panel);
71
71
  const [selectedLines, setSelectedLines] = useState(null);
72
72
  useEffect(() => {
@@ -148,12 +148,13 @@ const BoardTemplate = ({ refs, loadingRender }) => {
148
148
  ["background", "text"].includes((_g = componentsProps === null || componentsProps === void 0 ? void 0 : componentsProps[0]) === null || _g === void 0 ? void 0 : _g.shape)) {
149
149
  minX = minX;
150
150
  minY = minY;
151
+ maxX = maxX;
152
+ maxY = maxY;
151
153
  }
152
- const hasBoundingBox = extraComponentsProps === null || extraComponentsProps === void 0 ? void 0 : extraComponentsProps.some((item) => { var _a; return (_a = item === null || item === void 0 ? void 0 : item.shape) === null || _a === void 0 ? void 0 : _a.includes("bounding-box"); });
154
+ const hasBoundingBox = !isEmpty(boundingBox);
153
155
  if (hasBoundingBox) {
154
- const findBoundingBox = extraComponentsProps.find((item) => { var _a; return (_a = item === null || item === void 0 ? void 0 : item.shape) === null || _a === void 0 ? void 0 : _a.includes("bounding-box"); });
155
- minX = findBoundingBox.x;
156
- minY = findBoundingBox.y;
156
+ minX = boundingBox.x;
157
+ minY = boundingBox.y;
157
158
  }
158
159
  if ((minX !== Infinity || minY !== Infinity) && !activeTool) {
159
160
  (_h = transformRef.current) === null || _h === void 0 ? void 0 : _h.setTransform(-minX, -minY, scale);
@@ -478,11 +479,6 @@ const BoardTemplate = ({ refs, loadingRender }) => {
478
479
  if (downAtResizePosition) {
479
480
  onResizeSelectionRef.current = true;
480
481
  }
481
- // targetGroup?.removeAttribute("transform");
482
- const mousePositionInGroup = {
483
- x: x - (box === null || box === void 0 ? void 0 : box.x),
484
- y: y - (box === null || box === void 0 ? void 0 : box.y),
485
- };
486
482
  const offset = {
487
483
  x: x - initialXG,
488
484
  y: y - initialYG,
@@ -504,6 +500,10 @@ const BoardTemplate = ({ refs, loadingRender }) => {
504
500
  type: "panel/setSelectedComponent",
505
501
  payload: newPolygon,
506
502
  });
503
+ dispatch({
504
+ type: "panel/setSelectedGroup",
505
+ payload: null
506
+ });
507
507
  isOnMakePolygonRef.current = true;
508
508
  }
509
509
  // const selectionLines = svgRef.current?.querySelector(
@@ -527,7 +527,7 @@ const BoardTemplate = ({ refs, loadingRender }) => {
527
527
  var _a, _b;
528
528
  const dx = pos.x - x;
529
529
  const dy = pos.y - y;
530
- const { g, inner, element } = getAttributeElement(svg, activeId);
530
+ const { inner, element } = getAttributeElement(svg, activeId);
531
531
  const angleDeg = getRotation(inner.transform.baseVal); // 0–360
532
532
  const angleRad = (angleDeg * Math.PI) / 180;
533
533
  const cos = Math.cos(-angleRad);
@@ -636,7 +636,7 @@ const BoardTemplate = ({ refs, loadingRender }) => {
636
636
  const allID = (_a = dataElementSelectionGroupRef.current) === null || _a === void 0 ? void 0 : _a.map((el) => el.id);
637
637
  const allDataRealSelection = (_b = [
638
638
  ...componentsState,
639
- ...extraComponentsState,
639
+ ...(lockBackground ? [] : extraComponentsState),
640
640
  ]) === null || _b === void 0 ? void 0 : _b.filter((el) => allID.includes(el.id));
641
641
  const allGroupsAttribute = getAttributeElements(svg, allID);
642
642
  const resultSelection = resizeBox({
@@ -644,12 +644,12 @@ const BoardTemplate = ({ refs, loadingRender }) => {
644
644
  dx,
645
645
  dy,
646
646
  rotate: 0,
647
- handle: resizeSide,
647
+ handle: resizeSide
648
648
  });
649
649
  updateSelectionBox(svg, resultSelection);
650
650
  const scaleX = resultSelection.width / oldSel.width;
651
651
  const scaleY = resultSelection.height / oldSel.height;
652
- allGroupsAttribute.forEach(({ g, element, inner, seatGroup, seats }, i) => {
652
+ allGroupsAttribute.forEach(({ g, element, seatGroup, seats }, i) => {
653
653
  var _a, _b;
654
654
  const activeId = JSON.parse(g === null || g === void 0 ? void 0 : g.getAttribute("data-id"));
655
655
  const elementOld = allDataRealSelection === null || allDataRealSelection === void 0 ? void 0 : allDataRealSelection.find((el) => el.id == activeId);
@@ -713,7 +713,7 @@ const BoardTemplate = ({ refs, loadingRender }) => {
713
713
  const allID = (_a = dataElementSelectionGroupRef.current) === null || _a === void 0 ? void 0 : _a.map((el) => el.id);
714
714
  const allDataRealSelection = (_b = [
715
715
  ...componentsState,
716
- ...extraComponentsState,
716
+ ...(lockBackground ? [] : extraComponentsState),
717
717
  ]) === null || _b === void 0 ? void 0 : _b.filter((el) => allID.includes(el.id));
718
718
  allDataRealSelection.forEach((item) => {
719
719
  const { g } = getAttributeElement(svg, item.id);
@@ -770,10 +770,13 @@ const BoardTemplate = ({ refs, loadingRender }) => {
770
770
  .map((d) => `${d}`);
771
771
  if (selectedIds.length === 0)
772
772
  return;
773
- const selectedComps = (_b = [...componentsState, ...extraComponentsState]
773
+ const selectedComps = (_b = [
774
+ ...componentsState,
775
+ ...(lockBackground ? [] : extraComponentsState),
776
+ ]
774
777
  .filter((c) => selectedIds.map(String).includes(String(c.id)))) === null || _b === void 0 ? void 0 : _b.map((item) => {
775
778
  const { g } = getAttributeElement(svg, item.id);
776
- const { x, y } = getTranslate(g);
779
+ // const { x, y } = getTranslate(g);
777
780
  const box = getGlobalBBox(svg, g);
778
781
  return Object.assign(Object.assign({}, item), {
779
782
  // x: box.x,
@@ -864,7 +867,7 @@ const BoardTemplate = ({ refs, loadingRender }) => {
864
867
  dx,
865
868
  dy,
866
869
  rotate: 0,
867
- handle: resizeSide,
870
+ handle: resizeSide
868
871
  });
869
872
  updateSelectionGuides(svg, resultSelection, {
870
873
  vLeft: "v-left",
@@ -1104,6 +1107,10 @@ const BoardTemplate = ({ refs, loadingRender }) => {
1104
1107
  type: "panel/setSelectedComponent",
1105
1108
  payload: newDataComponent,
1106
1109
  });
1110
+ dispatch({
1111
+ type: "panel/setSelectedGroup",
1112
+ payload: null
1113
+ });
1107
1114
  }
1108
1115
  //POLYGON
1109
1116
  const isInitialPolyGon = activeTool === "polygon" && (selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.shape) === "polygon";
@@ -1138,6 +1145,10 @@ const BoardTemplate = ({ refs, loadingRender }) => {
1138
1145
  type: "panel/setSelectedComponent",
1139
1146
  payload: newPoints,
1140
1147
  });
1148
+ dispatch({
1149
+ type: "panel/setSelectedGroup",
1150
+ payload: null
1151
+ });
1141
1152
  polygonElementRef.current = newPoints;
1142
1153
  }
1143
1154
  }
@@ -1159,6 +1170,10 @@ const BoardTemplate = ({ refs, loadingRender }) => {
1159
1170
  type: "panel/setSelectedComponent",
1160
1171
  payload: newDataComponent,
1161
1172
  });
1173
+ dispatch({
1174
+ type: "panel/setSelectedGroup",
1175
+ payload: null
1176
+ });
1162
1177
  //LOGIC FOR SET SHOW
1163
1178
  dispatch({ type: "panel/setShow", payload: false });
1164
1179
  }
@@ -1246,6 +1261,10 @@ const BoardTemplate = ({ refs, loadingRender }) => {
1246
1261
  type: "panel/setSelectedComponent",
1247
1262
  payload: findById,
1248
1263
  });
1264
+ dispatch({
1265
+ type: "panel/setSelectedGroup",
1266
+ payload: null
1267
+ });
1249
1268
  }
1250
1269
  }
1251
1270
  //LOGIC FOR SET SHOW
@@ -1268,6 +1287,10 @@ const BoardTemplate = ({ refs, loadingRender }) => {
1268
1287
  type: "panel/setSelectedComponent",
1269
1288
  payload: newSelectedComponent,
1270
1289
  });
1290
+ dispatch({
1291
+ type: "panel/setSelectedGroup",
1292
+ payload: null
1293
+ });
1271
1294
  updateComponentAttribute(newSelectedComponent);
1272
1295
  //LOGIC FOR SET SHOW
1273
1296
  dispatch({ type: "panel/setShow", payload: false });
@@ -1322,7 +1345,10 @@ const BoardTemplate = ({ refs, loadingRender }) => {
1322
1345
  if (isInitialCreateBoundingBox) {
1323
1346
  const ghost = svg.querySelector("#ghost-element-create");
1324
1347
  const getBBox = getGlobalBBox(svg, ghost);
1325
- addComponents(Object.assign(Object.assign({}, getBBox), { id: `${Date.now()}`, shape: "bounding-box", fill: "transparent" }));
1348
+ dispatch({
1349
+ type: "board/setBoundingBox",
1350
+ payload: Object.assign(Object.assign({}, getBBox), { id: `${Date.now()}`, shape: "bounding-box", fill: "transparent" }),
1351
+ });
1326
1352
  (_m = (_l = svgRef.current) === null || _l === void 0 ? void 0 : _l.querySelectorAll("#ghost-element-create")) === null || _m === void 0 ? void 0 : _m.forEach((el) => el.remove());
1327
1353
  }
1328
1354
  //RESIZE SELECTION BOX UP
@@ -1555,6 +1581,7 @@ const BoardTemplate = ({ refs, loadingRender }) => {
1555
1581
  ...extraComponentsState,
1556
1582
  ...componentsState,
1557
1583
  polygonElementRef === null || polygonElementRef === void 0 ? void 0 : polygonElementRef.current,
1584
+ ...(!isEmpty(boundingBox) ? [boundingBox] : []),
1558
1585
  ]}
1559
1586
  // style={{
1560
1587
  // cursor: getCursorStyle(),
@@ -9,7 +9,7 @@ export declare const resizeElementSelection: ({ selectionStart, currentSelection
9
9
  width: number;
10
10
  height: number;
11
11
  };
12
- export declare function resizeBox({ box, dx, dy, rotate, handle, }: {
12
+ export declare function resizeBox({ box, dx, dy, rotate, handle }: {
13
13
  box: {
14
14
  x: number;
15
15
  y: number;
@@ -43,7 +43,7 @@ export const resizeElementSelection = ({ selectionStart, currentSelection, rotat
43
43
  height,
44
44
  };
45
45
  };
46
- export function resizeBox({ box, dx, dy, rotate, handle, }) {
46
+ export function resizeBox({ box, dx, dy, rotate, handle }) {
47
47
  // 1. mouse → local
48
48
  const local = toLocalDelta(dx, dy, rotate);
49
49
  // 2. scale
@@ -144,6 +144,7 @@ export function getAnchorByHandle(handle, box) {
144
144
  }
145
145
  import { isEqual } from "lodash";
146
146
  import { arcByDirection, distributeWithSpacing, rectToPolygonNodes, } from "../../components/layer-v3/utils";
147
+ import { MIN_HEIGHT, MIN_WIDTH } from "./constant";
147
148
  export const resizeSeatSquare = ({ seatsPositions, r = 10, openSpace, newElement, seats, seatGroup, }) => {
148
149
  let top = [];
149
150
  let left = [];
@@ -969,8 +970,8 @@ export function applyResizeToSvgElement(element, group, resize, component) {
969
970
  case "rect":
970
971
  case "image": {
971
972
  updateSvgAttrs(element, {
972
- width: resize.width,
973
- height: resize.height,
973
+ width: resize.width < 60 ? 60 : resize.width,
974
+ height: resize.height < MIN_HEIGHT ? MIN_HEIGHT : resize.height,
974
975
  // fill: component.fill,
975
976
  });
976
977
  updateSvgAttrs(group, {
@@ -979,11 +980,13 @@ export function applyResizeToSvgElement(element, group, resize, component) {
979
980
  break;
980
981
  }
981
982
  case "circle": {
982
- const r = Math.min(resize.width, resize.height) / 2;
983
+ const width = resize.width < MIN_WIDTH ? MIN_WIDTH : resize.width;
984
+ const height = resize.height < MIN_HEIGHT ? MIN_HEIGHT : resize.height;
985
+ const r = Math.min(width, height) / 2;
983
986
  updateSvgAttrs(element, {
984
987
  r,
985
- cx: resize.width / 2,
986
- cy: resize.height / 2,
988
+ cx: width / 2,
989
+ cy: height / 2,
987
990
  // fill: component.fill,
988
991
  });
989
992
  group.setAttribute("transform", `translate(${resize.x}, ${resize.y})`);
@@ -7,6 +7,7 @@ export interface TableEditorProps {
7
7
  components: PropertiesProps[];
8
8
  extraComponents: PropertiesProps[];
9
9
  background: string;
10
+ boundingBox: PropertiesProps | null;
10
11
  }) => void;
11
12
  onSelectComponent?: (component: PropertiesProps) => void;
12
13
  mappingKey?: string;
@@ -19,6 +20,7 @@ export interface TableEditorProps {
19
20
  ];
20
21
  statusKey: string;
21
22
  defaultBackground?: string;
23
+ defaultBoundingBox?: PropertiesProps;
22
24
  action?: (file: File) => Promise<string>;
23
25
  responseMapping?: {
24
26
  status: string;
@@ -10,7 +10,7 @@ const TableEditor = (props) => {
10
10
  var _a;
11
11
  const [initialValue, setInitialValue] = useState(null);
12
12
  const { componentProps, extraComponentProps, onCurrentStateChange, dragOnly, mappingKey, viewOnly, deleteAutorized, refs, } = props;
13
- const { components, extraComponents, backgroundColor } = useAppSelector((state) => state.board);
13
+ const { components, extraComponents, backgroundColor, boundingBox } = useAppSelector((state) => state.board);
14
14
  const dispatch = useAppDispatch();
15
15
  const refsBoard = useRef(null);
16
16
  useImperativeHandle(refs, () => {
@@ -61,6 +61,7 @@ const TableEditor = (props) => {
61
61
  components: matchInitialValueWithComponents,
62
62
  extraComponents,
63
63
  background: backgroundColor,
64
+ boundingBox,
64
65
  });
65
66
  }
66
67
  };
@@ -99,6 +100,7 @@ const TableEditor = (props) => {
99
100
  components: mappingData,
100
101
  extraComponents: extraComponentProps,
101
102
  backgroundColor: props === null || props === void 0 ? void 0 : props.defaultBackground,
103
+ boundingBox: (props === null || props === void 0 ? void 0 : props.defaultBoundingBox) || null,
102
104
  },
103
105
  });
104
106
  // dispatch({
@@ -11,12 +11,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  import { useState, useEffect } from "react";
12
12
  import { Upload, Image, Button } from "antd";
13
13
  import { InboxOutlined, LoadingOutlined } from "@ant-design/icons";
14
- import { useAppDispatch } from "../../hooks/use-redux";
14
+ import { useAppDispatch, useAppSelector } from "../../hooks/use-redux";
15
15
  import SectionLabel from "../../components/form-tools/label";
16
16
  import SectionShape from "../../components/form-tools/shape";
17
17
  const { Dragger } = Upload;
18
18
  const UploadTool = ({ name, type, action, defaultValue, transform }) => {
19
19
  var _a, _b, _c;
20
+ const selectedComponent = useAppSelector((state) => state.panel.selectedComponent);
20
21
  const transformState = (_a = transform === null || transform === void 0 ? void 0 : transform.instance) === null || _a === void 0 ? void 0 : _a.transformState;
21
22
  const [defaultSrc, setDefaultSrc] = useState(null);
22
23
  const [isEdit, setIsEdit] = useState(false);
@@ -28,13 +29,20 @@ const UploadTool = ({ name, type, action, defaultValue, transform }) => {
28
29
  setLoading(false);
29
30
  }
30
31
  }, [defaultValue]);
32
+ useEffect(() => {
33
+ if (selectedComponent && selectedComponent.shape === name) {
34
+ setDefaultSrc(selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.src);
35
+ setIsEdit(true);
36
+ setLoading(false);
37
+ }
38
+ }, [selectedComponent]);
31
39
  const dispatch = useAppDispatch();
32
40
  const widthWorkspace = ((_b = document === null || document === void 0 ? void 0 : document.getElementById("workspace")) === null || _b === void 0 ? void 0 : _b.clientWidth) || 0;
33
41
  const heightWorkspace = ((_c = document === null || document === void 0 ? void 0 : document.getElementById("workspace")) === null || _c === void 0 ? void 0 : _c.clientHeight) || 0;
34
- const defaultFormatValue = (width, height, src, id) => ({
42
+ const defaultFormatValue = (width, height, src, id, x, y) => ({
35
43
  id: id || new Date().getTime(),
36
- x: Math.abs(transformState === null || transformState === void 0 ? void 0 : transformState.positionX),
37
- y: Math.abs(transformState === null || transformState === void 0 ? void 0 : transformState.positionY),
44
+ x: x || Math.abs(transformState === null || transformState === void 0 ? void 0 : transformState.positionX),
45
+ y: y || Math.abs(transformState === null || transformState === void 0 ? void 0 : transformState.positionY),
38
46
  width: width < 1 ? 200 : width,
39
47
  height: height < 1 ? 200 : height,
40
48
  rotation: 0,
@@ -59,11 +67,11 @@ const UploadTool = ({ name, type, action, defaultValue, transform }) => {
59
67
  if (isEdit) {
60
68
  dispatch({
61
69
  type: "board/updateComponent",
62
- payload: Object.assign({}, defaultFormatValue(defaultValue.width, defaultValue.height, src, Number(defaultValue.id))),
70
+ payload: Object.assign({}, defaultFormatValue(selectedComponent.width, selectedComponent.height, src, Number(selectedComponent.id), selectedComponent.x, selectedComponent.y)),
63
71
  });
64
72
  dispatch({
65
73
  type: "panel/setSelectedComponent",
66
- payload: Object.assign({}, defaultFormatValue(0, 0, src, Number(defaultValue.id))),
74
+ payload: Object.assign({}, defaultFormatValue(selectedComponent.width, selectedComponent.height, src, Number(selectedComponent.id), selectedComponent.x, selectedComponent.y)),
67
75
  });
68
76
  setDefaultSrc(src);
69
77
  dispatch({ type: "board/setFlagChange", payload: true });
@@ -94,11 +102,11 @@ const UploadTool = ({ name, type, action, defaultValue, transform }) => {
94
102
  if (isEdit) {
95
103
  dispatch({
96
104
  type: "board/updateComponent",
97
- payload: Object.assign({}, defaultFormatValue(width, height, img.src, Number(defaultValue.id))),
105
+ payload: Object.assign({}, defaultFormatValue(selectedComponent.width, selectedComponent.height, img.src, Number(selectedComponent.id), selectedComponent.x, selectedComponent.y)),
98
106
  });
99
107
  dispatch({
100
108
  type: "panel/setSelectedComponent",
101
- payload: Object.assign({}, defaultFormatValue(width, height, srcFromResponse || img.src, Number(defaultValue.id))),
109
+ payload: Object.assign({}, defaultFormatValue(selectedComponent.width, selectedComponent.height, img.src, Number(selectedComponent.id), selectedComponent.x, selectedComponent.y)),
102
110
  });
103
111
  setDefaultSrc(img.src);
104
112
  dispatch({ type: "board/setFlagChange", payload: true });
@@ -23,7 +23,7 @@ const LayerView = (props) => {
23
23
  const [panningGroup, setPanningGroup] = useState(false);
24
24
  const [scale, setScale] = useState(1);
25
25
  const [selectedTable, setSelectedTable] = useState(null);
26
- const { components: componentsEditor, extraComponents: extraComponentsEditor, } = useAppSelector((state) => state.board);
26
+ const { components: componentsEditor, extraComponents: extraComponentsEditor, boundingBox: boundingBoxProps } = useAppSelector((state) => state.board);
27
27
  const backgroundColor = useAppSelector((state) => state.board.backgroundColor);
28
28
  const { loading } = useAppSelector((state) => state.panel);
29
29
  useImperativeHandle(refs, () => ({
@@ -38,7 +38,7 @@ const LayerView = (props) => {
38
38
  }));
39
39
  const dispatch = useAppDispatch();
40
40
  useEffect(() => {
41
- if ((!loading && !(loadingRender === null || loadingRender === void 0 ? void 0 : loadingRender.state))) {
41
+ if ((!loading && (loadingRender === null || loadingRender === void 0 ? void 0 : loadingRender.state))) {
42
42
  dispatch({ type: "panel/setLoading", payload: true });
43
43
  }
44
44
  if ((componentProps === null || componentProps === void 0 ? void 0 : componentProps.length) > 0) {
@@ -169,8 +169,10 @@ const LayerView = (props) => {
169
169
  ["background", "text"].includes((_g = componentsEditor === null || componentsEditor === void 0 ? void 0 : componentsEditor[0]) === null || _g === void 0 ? void 0 : _g.shape)) {
170
170
  minX = minX;
171
171
  minY = minY;
172
+ maxX = maxX;
173
+ maxY = maxY;
172
174
  }
173
- const hasBoundingBox = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor.some((item) => { var _a; return (_a = item === null || item === void 0 ? void 0 : item.shape) === null || _a === void 0 ? void 0 : _a.includes("bounding-box"); });
175
+ const hasBoundingBox = boundingBoxProps;
174
176
  // const paddingY =
175
177
  // maxY * (props?.viewStyles?.paddingY || 0) +
176
178
  // minY * (props?.viewStyles?.paddingY || 0);
@@ -178,13 +180,12 @@ const LayerView = (props) => {
178
180
  // maxX * (props?.viewStyles?.paddingX || 0) +
179
181
  // minX * (props?.viewStyles?.paddingX || 0);
180
182
  if (hasBoundingBox) {
181
- const findBoundingBox = extraComponentsEditor.find((item) => { var _a; return (_a = item === null || item === void 0 ? void 0 : item.shape) === null || _a === void 0 ? void 0 : _a.includes("bounding-box"); });
182
183
  hasBoundingBoxRef.current = true;
183
184
  return {
184
- minX: findBoundingBox.x,
185
- minY: findBoundingBox.y,
186
- width: findBoundingBox.width,
187
- height: findBoundingBox.height,
185
+ minX: boundingBoxProps.x,
186
+ minY: boundingBoxProps.y,
187
+ width: boundingBoxProps.width,
188
+ height: boundingBoxProps.height,
188
189
  };
189
190
  }
190
191
  // return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seat-editor",
3
- "version": "3.2.27",
3
+ "version": "3.3.0",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",