seat-editor 1.6.17 → 1.6.19

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.
@@ -147,15 +147,15 @@ const SideTool = ({ dragOnly, deleteAutorized, }) => {
147
147
  dispatch({ type: "board/setFlagChange", payload: true });
148
148
  };
149
149
  const handleRemoveComponent = () => {
150
- if ((selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.shape) !== "background" && !(deleteAutorized === null || deleteAutorized === void 0 ? void 0 : deleteAutorized.component)) {
150
+ const exludedShapes = ["background", "text"];
151
+ if (!exludedShapes.includes(selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.shape) && !(deleteAutorized === null || deleteAutorized === void 0 ? void 0 : deleteAutorized.component)) {
151
152
  message.error("You are not authorized to delete this table.");
152
153
  return;
153
154
  }
154
- if ((selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.shape) === "background" && !(deleteAutorized === null || deleteAutorized === void 0 ? void 0 : deleteAutorized.extraComponent)) {
155
+ if (exludedShapes.includes(selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.shape) && !(deleteAutorized === null || deleteAutorized === void 0 ? void 0 : deleteAutorized.extraComponent)) {
155
156
  message.error("You are not authorized to delete this background.");
156
157
  return;
157
158
  }
158
- const exludedShapes = ["background", "text"];
159
159
  if ((deleteAutorized === null || deleteAutorized === void 0 ? void 0 : deleteAutorized.component) && !exludedShapes.includes(selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.shape)) {
160
160
  dispatch({
161
161
  type: "board/removeComponent",
@@ -73,7 +73,7 @@ const LayerView = (props) => {
73
73
  setSelectedTable(find);
74
74
  };
75
75
  const boundingBox = useMemo(() => {
76
- var _a, _b, _c, _d, _e, _f;
76
+ var _a, _b, _c, _d, _e, _f, _g;
77
77
  if (!componentsEditor && (componentsEditor === null || componentsEditor === void 0 ? void 0 : componentsEditor.length) === 0) {
78
78
  return { minX: 0, minY: 0, width: 500, height: 500 };
79
79
  }
@@ -131,7 +131,7 @@ const LayerView = (props) => {
131
131
  maxX = (_e = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _e === void 0 ? void 0 : _e.width;
132
132
  maxY = (_f = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _f === void 0 ? void 0 : _f.height;
133
133
  }
134
- if ((extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor.length) < 1) {
134
+ if ((extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor.length) < 1 && ["background", "text"].includes((_g = componentsEditor === null || componentsEditor === void 0 ? void 0 : componentsEditor[0]) === null || _g === void 0 ? void 0 : _g.shape)) {
135
135
  minX = minX - minX * 0.5;
136
136
  minY = minY - minY * 0.5;
137
137
  }
@@ -0,0 +1,226 @@
1
+ "use client";
2
+ "use client";
3
+ import { useEffect, useMemo, useRef, useState } from "react";
4
+ import { TransformWrapper, TransformComponent, } from "react-zoom-pan-pinch";
5
+ import { useAppDispatch, useAppSelector } from "../../hooks/use-redux";
6
+ import Layers from "../../components/layer";
7
+ import { isEqual } from "lodash";
8
+ const LayerView = (props) => {
9
+ const { componentProps, extraComponentProps, onSelectComponent, onCurrentStateChange, mappingKey, selectedTableColor, colorMatchKey, statusKey, defaultBackground, } = props;
10
+ const transformRef = useRef(null);
11
+ const containerRef = useRef(null);
12
+ const svgRef = useRef(null);
13
+ const [scale, setScale] = useState(1);
14
+ const [selectedTable, setSelectedTable] = useState(null);
15
+ const { components: componentsEditor, extraComponents: extraComponentsEditor, } = useAppSelector((state) => state.board);
16
+ const backgroundColor = useAppSelector((state) => state.board.backgroundColor);
17
+ const dispatch = useAppDispatch();
18
+ const convertComponentProps = () => {
19
+ let mappingData = componentProps === null || componentProps === void 0 ? void 0 : componentProps.map((item) => {
20
+ if (mappingKey && (item === null || item === void 0 ? void 0 : item[mappingKey])) {
21
+ return Object.assign({}, item === null || item === void 0 ? void 0 : item[mappingKey]);
22
+ }
23
+ return item;
24
+ });
25
+ return mappingData;
26
+ };
27
+ useEffect(() => {
28
+ if (componentProps) {
29
+ if (!isEqual(componentsEditor, convertComponentProps())) {
30
+ let mappingData = componentProps === null || componentProps === void 0 ? void 0 : componentProps.map((item) => {
31
+ if (mappingKey && (item === null || item === void 0 ? void 0 : item[props.mappingKey])) {
32
+ return Object.assign({}, item[props.mappingKey]);
33
+ }
34
+ return item;
35
+ });
36
+ dispatch({
37
+ type: "board/setNewComponents",
38
+ payload: mappingData,
39
+ });
40
+ }
41
+ }
42
+ if (extraComponentsEditor) {
43
+ if (!isEqual(extraComponentsEditor, extraComponentProps)) {
44
+ dispatch({
45
+ type: "board/setNewExtraComponents",
46
+ payload: extraComponentProps,
47
+ });
48
+ }
49
+ }
50
+ if (defaultBackground) {
51
+ dispatch({
52
+ type: "board/setBackgroundColor",
53
+ payload: defaultBackground,
54
+ });
55
+ }
56
+ }, [componentProps, extraComponentProps, defaultBackground]);
57
+ useEffect(() => {
58
+ onCurrentStateChange &&
59
+ onCurrentStateChange({
60
+ components: componentsEditor,
61
+ extraComponents: extraComponentsEditor,
62
+ });
63
+ }, [componentsEditor, extraComponentsEditor]);
64
+ const handleSelectComponent = (items) => {
65
+ const find = componentsEditor.find((item) => {
66
+ if (mappingKey && (item === null || item === void 0 ? void 0 : item[mappingKey])) {
67
+ return item[mappingKey].id === (items === null || items === void 0 ? void 0 : items.id);
68
+ }
69
+ return (item === null || item === void 0 ? void 0 : item.id) === (items === null || items === void 0 ? void 0 : items.id);
70
+ });
71
+ onSelectComponent && onSelectComponent(find);
72
+ setSelectedTable(find);
73
+ };
74
+ const boundingBox = useMemo(() => {
75
+ var _a, _b, _c, _d, _e, _f, _g;
76
+ if (!componentsEditor && (componentsEditor === null || componentsEditor === void 0 ? void 0 : componentsEditor.length) === 0) {
77
+ return { minX: 0, minY: 0, width: 500, height: 500 };
78
+ }
79
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
80
+ componentsEditor === null || componentsEditor === void 0 ? void 0 : componentsEditor.forEach((_) => {
81
+ var _a, _b, _c, _d;
82
+ const hasMappingKey = mappingKey && _[mappingKey];
83
+ let values = hasMappingKey ? _[mappingKey] : _;
84
+ if (!values)
85
+ return;
86
+ if ((_a = values === null || values === void 0 ? void 0 : values.shape) === null || _a === void 0 ? void 0 : _a.includes("square")) {
87
+ minX = Math.min(minX, values.x);
88
+ minY = Math.min(minY, values.y);
89
+ maxX = Math.max(maxX, values.x + values.width);
90
+ maxY = Math.max(maxY, values.y + values.height);
91
+ }
92
+ if ((_b = values === null || values === void 0 ? void 0 : values.shape) === null || _b === void 0 ? void 0 : _b.includes("circle")) {
93
+ minX = Math.min(minX, values.x);
94
+ minY = Math.min(minY, values.y);
95
+ maxX = Math.max(maxX, values.x + values.width);
96
+ maxY = Math.max(maxY, values.y + values.height);
97
+ }
98
+ if ((_c = values === null || values === void 0 ? void 0 : values.shape) === null || _c === void 0 ? void 0 : _c.includes("table-seat-circle")) {
99
+ minX = Math.min(minX, values.x);
100
+ minY = Math.min(minY, values.y);
101
+ maxX = Math.max(maxX, values.x + values.width);
102
+ maxY = Math.max(maxY, values.y + values.height);
103
+ }
104
+ if ((_d = values === null || values === void 0 ? void 0 : values.shape) === null || _d === void 0 ? void 0 : _d.includes("image-table")) {
105
+ minX = Math.min(minX, values.x);
106
+ minY = Math.min(minY, values.y);
107
+ maxX = Math.max(maxX, values.x + values.width);
108
+ maxY = Math.max(maxY, values.y + values.height);
109
+ }
110
+ });
111
+ extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor.forEach((values) => {
112
+ var _a, _b;
113
+ if ((_a = values === null || values === void 0 ? void 0 : values.shape) === null || _a === void 0 ? void 0 : _a.includes("background")) {
114
+ minX = Math.min(minX, values.x);
115
+ minY = Math.min(minY, values.y);
116
+ maxX = Math.max(maxX, values.x + values.width);
117
+ maxY = Math.max(maxY, values.y + values.height);
118
+ }
119
+ if ((_b = values === null || values === void 0 ? void 0 : values.shape) === null || _b === void 0 ? void 0 : _b.includes("text")) {
120
+ minX = Math.min(minX, values.x);
121
+ minY = Math.min(minY, values.y);
122
+ maxX = Math.max(maxX, values.x + values.width);
123
+ maxY = Math.max(maxY, values.y + values.height);
124
+ }
125
+ });
126
+ if ((extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor.length) === 1 &&
127
+ ((_b = (_a = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _a === void 0 ? void 0 : _a.shape) === null || _b === void 0 ? void 0 : _b.includes("background"))) {
128
+ minX = (_c = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _c === void 0 ? void 0 : _c.x;
129
+ minY = (_d = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _d === void 0 ? void 0 : _d.y;
130
+ maxX = (_e = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _e === void 0 ? void 0 : _e.width;
131
+ maxY = (_f = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _f === void 0 ? void 0 : _f.height;
132
+ }
133
+ if ((extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor.length) < 1 && ["background", "text"].includes((_g = componentsEditor === null || componentsEditor === void 0 ? void 0 : componentsEditor[0]) === null || _g === void 0 ? void 0 : _g.shape)) {
134
+ minX = minX - minX * 0.5;
135
+ minY = minY - minY * 0.5;
136
+ }
137
+ return {
138
+ minX,
139
+ minY,
140
+ width: maxX,
141
+ height: maxY,
142
+ };
143
+ }, [componentsEditor, extraComponentsEditor]);
144
+ const renderElements = (elementEditor, mappingKey, colorMatchKey) => {
145
+ return elementEditor === null || elementEditor === void 0 ? void 0 : elementEditor.map((editorItem, i) => {
146
+ var _a, _b, _c, _d;
147
+ const isUsingMapping = mappingKey &&
148
+ typeof editorItem[mappingKey] === "object" &&
149
+ editorItem[mappingKey] !== null;
150
+ const finalProps = isUsingMapping ? editorItem[mappingKey] : editorItem;
151
+ if (colorMatchKey) {
152
+ if (isUsingMapping) {
153
+ return Object.assign(Object.assign({}, finalProps), { fill: (_b = (_a = colorMatchKey.find((item) => item.key == (editorItem === null || editorItem === void 0 ? void 0 : editorItem[statusKey]))) === null || _a === void 0 ? void 0 : _a.color) !== null && _b !== void 0 ? _b : finalProps.fill });
154
+ }
155
+ else {
156
+ return Object.assign(Object.assign({}, finalProps), { fill: (_d = (_c = colorMatchKey.find((item) => item.key == (editorItem === null || editorItem === void 0 ? void 0 : editorItem[statusKey]))) === null || _c === void 0 ? void 0 : _c.color) !== null && _d !== void 0 ? _d : finalProps.fill });
157
+ }
158
+ }
159
+ return finalProps;
160
+ });
161
+ };
162
+ const [fingerCount, setFingerCount] = useState(0);
163
+ useEffect(() => {
164
+ const container = document.getElementById("workspace");
165
+ const handleTouchStart = (e) => {
166
+ const count = e.touches.length;
167
+ setFingerCount(count);
168
+ };
169
+ const handleTouchEnd = () => {
170
+ setFingerCount(0);
171
+ };
172
+ if (container) {
173
+ container.addEventListener("touchstart", handleTouchStart);
174
+ container.addEventListener("touchend", handleTouchEnd);
175
+ }
176
+ return () => {
177
+ if (container) {
178
+ container.removeEventListener("touchstart", handleTouchStart);
179
+ container.removeEventListener("touchend", handleTouchEnd);
180
+ }
181
+ };
182
+ }, []);
183
+ return (<div className="relative w-full h-full flex-1" ref={containerRef} style={{
184
+ height: "100vh",
185
+ overflow: "auto",
186
+ WebkitOverflowScrolling: "touch",
187
+ touchAction: "pan-y",
188
+ }} {...props.containerProps}>
189
+ <TransformWrapper ref={transformRef} {...props.transformProps} disabled={fingerCount === 1 && scale === 1} disablePadding={true}
190
+ // panning={{
191
+ // disabled: false,
192
+ // velocityDisabled: true,
193
+ // }}
194
+ // limitToBounds={false}
195
+ // doubleClick={{ disabled: true }}
196
+ // pinch={{ disabled: false }}
197
+ // wheel={{ disabled: true }}
198
+ // disabled={true}
199
+ // disablePadding={true}
200
+ centerZoomedOut={true} onTransformed={({ state: { scale } }) => setScale(scale)} minScale={1} maxScale={1000} initialScale={1}
201
+ // pinch={{ step: 1 }}
202
+ smooth={true}>
203
+ <TransformComponent wrapperStyle={{
204
+ width: "100%",
205
+ height: "100%",
206
+ overflow: "visible",
207
+ }} contentStyle={{
208
+ width: "100%",
209
+ height: "100%",
210
+ }}>
211
+ <svg {...props.svgProps} id="workspace" ref={svgRef} width="100%" height="100%" viewBox={`${boundingBox.minX} ${boundingBox.minY} ${boundingBox.width} ${boundingBox.height}`} className="h-full" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid meet" style={{
212
+ background: backgroundColor !== null && backgroundColor !== void 0 ? backgroundColor : defaultBackground,
213
+ display: "block",
214
+ pointerEvents: "auto",
215
+ // touchAction: "pan-y",
216
+ }}>
217
+ <Layers mode="view" components={[
218
+ ...((extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor.length) > 0 ? extraComponentsEditor : []),
219
+ ...renderElements(componentsEditor, mappingKey, colorMatchKey),
220
+ ]} onClick={handleSelectComponent} selectedTable={selectedTable} selectedTableColor={selectedTableColor}/>
221
+ </svg>
222
+ </TransformComponent>
223
+ </TransformWrapper>
224
+ </div>);
225
+ };
226
+ export default LayerView;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seat-editor",
3
- "version": "1.6.17",
3
+ "version": "1.6.19",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,69 +0,0 @@
1
- "use client";
2
- import { useEffect, useState } from "react";
3
- import SeatEditor from "../../features/package";
4
- import { constantData } from "../constant";
5
- export default function NewBoard() {
6
- const [initialValue, setInitialValue] = useState([]);
7
- const [extraComponents, setExtraComponents] = useState([]);
8
- const [backgroundColor, setBackgroundColor] = useState("#ffffff");
9
- const [viewOnly, setViewOnly] = useState(true);
10
- useEffect(() => {
11
- setInitialValue(constantData);
12
- setExtraComponents([{
13
- src: "https://d3l3j4e3k9p181.cloudfront.net/dev/5bf923de-2366-4a11-9b8b-e92de0afbf05/3a65cb36-7d85-4c38-9403-a15f94641920/68d45207-d66b-4bb5-92a2-4e5a87715e98/rsvp/1751350513582817819_download (10).jpg",
14
- id: 1747388267450,
15
- x: 0,
16
- y: 0,
17
- shape: "background",
18
- width: 100,
19
- height: 100,
20
- },
21
- {
22
- src: "https://d3l3j4e3k9p181.cloudfront.net/dev/5bf923de-2366-4a11-9b8b-e92de0afbf05/3a65cb36-7d85-4c38-9403-a15f94641920/68d45207-d66b-4bb5-92a2-4e5a87715e98/rsvp/1751350513582817819_download (10).jpg",
23
- id: 1747388267451,
24
- x: 100,
25
- y: 100,
26
- shape: "background",
27
- width: 100,
28
- height: 100,
29
- }]);
30
- }, []);
31
- return (<>
32
- <div className="w-full h-screen flex flex-col relative justify-center">
33
- {/* <div className="w-full h-[1000px] bg-white border-r border-gray-200"> */}
34
- {/* <LayerView
35
- componentProps={initialValue}
36
- mappingKey="properties"
37
- extraComponentProps={[]}
38
- defaultBackground="#ffffff"
39
- // dragOnly={true}
40
- statusKey="status"
41
-
42
- /> */}
43
- {/* </div> */}
44
- <button className="bg-blue-500 text-white px-4 py-2 rounded" onClick={() => setViewOnly(!viewOnly)}>
45
- {viewOnly ? "Edit Mode" : "View Mode"}
46
- </button>
47
- <div className="flex-1 h-full">
48
- <SeatEditor componentProps={initialValue} viewOnly={viewOnly} dragOnly deleteAutorized={{
49
- component: true,
50
- extraComponent: true,
51
- }} mappingKey="properties" onCurrentStateChange={(setState) => {
52
- var _a, _b, _c, _d;
53
- if (((_a = setState === null || setState === void 0 ? void 0 : setState.components) === null || _a === void 0 ? void 0 : _a.length) > 0) {
54
- setInitialValue((_b = setState === null || setState === void 0 ? void 0 : setState.components) !== null && _b !== void 0 ? _b : []);
55
- }
56
- if (setState === null || setState === void 0 ? void 0 : setState.background) {
57
- setBackgroundColor(setState === null || setState === void 0 ? void 0 : setState.backgroundColor);
58
- }
59
- if (((_c = setState === null || setState === void 0 ? void 0 : setState.extraComponents) === null || _c === void 0 ? void 0 : _c.length) > 0) {
60
- setExtraComponents((_d = setState === null || setState === void 0 ? void 0 : setState.extraComponents) !== null && _d !== void 0 ? _d : []);
61
- }
62
- }} extraComponentProps={extraComponents} defaultBackground={backgroundColor}
63
- // dragOnly={true}
64
- statusKey="status"/>
65
- </div>
66
-
67
- </div>
68
- </>);
69
- }