seat-editor 1.6.25 → 1.6.27

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.
package/dist/app/page.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import Board from "../features/board";
2
+ import Board from "../features/board-v2";
3
3
  import SideTool from "../features/side-tool";
4
4
  import ControlPanels from "../features/panel";
5
5
  const TableEditor = () => {
package/dist/app/page.jsx CHANGED
@@ -1,4 +1,4 @@
1
- import Board from "../features/board";
1
+ import Board from "../features/board-v2";
2
2
  import SideTool from "../features/side-tool";
3
3
  import ControlPanels from "../features/panel";
4
4
  const TableEditor = () => {
@@ -139,6 +139,7 @@ const BoardTemplate = ({ onSelectComponent, viewOnly }) => {
139
139
  seatFill: activeTool === "table-seat-circle" ? "#DADADA" : undefined,
140
140
  text: activeTool === "text" ? "Text" : "",
141
141
  fontColor: activeTool === "text" ? "#DADADA" : undefined,
142
+ points: [],
142
143
  });
143
144
  const getCoords = (e) => {
144
145
  const svgRect = svgRef.current.getBoundingClientRect();
@@ -746,7 +747,35 @@ const BoardTemplate = ({ onSelectComponent, viewOnly }) => {
746
747
  // moveComponent &&
747
748
  // isTouching.current &&
748
749
  // !resizeDirection
749
- return (_jsxs(_Fragment, { children: [_jsx(ModalPreview, { children: _jsx(LayerView, { statusKey: "status" }) }), _jsxs("div", { className: "relative w-full h-screen flex-1 overflow-hidden", ref: containerRef, children: [_jsx("div", { className: "absolute bottom-5 left-1/2 transform -translate-x-1/2 z-10", children: _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { icon: _jsx(ZoomIn, {}), onClick: handelZoomIn }), _jsx(Button, { icon: _jsx(ZoomOut, {}), onClick: handleZoomOut })] }) }), _jsxs(TransformWrapper, { ref: transformRef, panning: { disabled: ["node", "select"].includes(activeTool) }, centerZoomedOut: true, onTransformed: ({ state: { scale } }) => setScale(scale), minScale: 1, maxScale: 1000, initialScale: 1, pinch: { step: 1 }, smooth: true, doubleClick: { step: 1, disabled: activeTool === "select" }, disablePadding: true, children: [scale > 1 && (_jsx("div", { className: "absolute bottom-[60px] left-1/2 transform -translate-x-1/2 z-10", children: renderMiniMap() })), _jsx(TransformComponent, { wrapperStyle: {
750
+ const [nodes, setNodes] = useState([
751
+ { x: 80, y: 40 },
752
+ { x: 220, y: 40 },
753
+ { x: 260, y: 160 },
754
+ { x: 40, y: 160 },
755
+ ]);
756
+ const addNode = () => {
757
+ if (nodes.length < 30) {
758
+ const midIndex = Math.floor(nodes.length / 2);
759
+ const prev = nodes[midIndex - 1];
760
+ const curr = nodes[midIndex];
761
+ const newNode = {
762
+ x: (prev.x + curr.x) / 2,
763
+ y: (prev.y + curr.y) / 2,
764
+ };
765
+ const newNodes = [...nodes];
766
+ newNodes.splice(midIndex, 0, newNode);
767
+ setNodes(newNodes);
768
+ }
769
+ };
770
+ const removeNode = () => {
771
+ if (nodes.length > 3) {
772
+ const midIndex = Math.floor(nodes.length / 2);
773
+ const newNodes = [...nodes];
774
+ newNodes.splice(midIndex, 1);
775
+ setNodes(newNodes);
776
+ }
777
+ };
778
+ return (_jsxs(_Fragment, { children: [_jsx(ModalPreview, { children: _jsx(LayerView, { statusKey: "status" }) }), _jsxs("div", { className: "relative w-full h-screen flex-1 overflow-hidden", ref: containerRef, children: [_jsx("div", { className: "absolute bottom-5 left-1/2 transform -translate-x-1/2 z-10", children: _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { icon: _jsx(ZoomIn, {}), onClick: handelZoomIn }), _jsx(Button, { icon: _jsx(ZoomOut, {}), onClick: handleZoomOut }), _jsx(Button, { onClick: addNode, children: "Add Node" }), _jsx(Button, { onClick: removeNode, children: "Remove Node" })] }) }), _jsxs(TransformWrapper, { ref: transformRef, panning: { disabled: ["node", "select"].includes(activeTool) }, centerZoomedOut: true, onTransformed: ({ state: { scale } }) => setScale(scale), minScale: 1, maxScale: 1000, initialScale: 1, pinch: { step: 1 }, smooth: true, doubleClick: { step: 1, disabled: activeTool === "select" }, disablePadding: true, children: [scale > 1 && (_jsx("div", { className: "absolute bottom-[60px] left-1/2 transform -translate-x-1/2 z-10", children: renderMiniMap() })), _jsx(TransformComponent, { wrapperStyle: {
750
779
  width: "100%",
751
780
  height: "100%",
752
781
  overflow: "hidden",
@@ -773,6 +802,6 @@ const BoardTemplate = ({ onSelectComponent, viewOnly }) => {
773
802
  onMouseDown: handleMouseDown,
774
803
  // onMouseUp={handleMouseUp}
775
804
  // onBlur={handleUnSelectComponent}
776
- selectedComponent: selectedComponent, activeTool: activeTool, onTouchStart: handleMouseDown }), activeTool === "ruler" && (_jsxs(_Fragment, { children: [_jsxs("g", { id: "horizontal-ruler", children: [_jsx("rect", { x: "0", y: "0", width: window.innerWidth, height: "30", fill: "#e0e0e0" }), _jsx("g", { stroke: "#888", "font-size": "10", "text-anchor": "middle", children: Array.from({ length: window.innerWidth / 50 }, (_, i) => (_jsxs("g", { children: [_jsx("line", { x1: i * 50, y1: "0", x2: i * 50, y2: "10" }), _jsx("text", { x: i * 50, y: "15", children: i * 50 })] }, i))) })] }), _jsxs("g", { id: "vertical-ruler", children: [_jsx("rect", { x: "0", y: "0", width: "30", height: window.innerHeight, fill: "#e0e0e0" }), _jsx("g", { stroke: "#888", "font-size": "10", "text-anchor": "middle", children: Array.from({ length: window.innerHeight / 10 }, (_, i) => (_jsxs("g", { children: [_jsx("line", { x1: "0", y1: i * 50, x2: "10", y2: i * 50 }), _jsx("text", { x: "15", y: i * 50, children: i * 50 })] }, i))) })] })] })), grid && (_jsxs("g", { stroke: "#ddd", strokeWidth: 0.5, children: [Array.from({ length: widthBoard / 10 }, (_, i) => (_jsx("line", { x1: i * 10, y1: 0, x2: i * 10, y2: heightBoard }, `v-${i}`))), Array.from({ length: heightBoard / 10 }, (_, i) => (_jsx("line", { x1: 0, y1: i * 10, x2: widthBoard, y2: i * 10 }, `h-${i}`)))] }))] }) })] })] })] }));
805
+ selectedComponent: selectedComponent, activeTool: activeTool, onTouchStart: handleMouseDown }), _jsx("polygon", { points: nodes.map(n => `${n.x},${n.y}`).join(" "), fill: "lightblue", stroke: "black" }), nodes.map((node, index) => (_jsx("circle", { cx: node.x, cy: node.y, r: 5, fill: "red" }, index))), activeTool === "ruler" && (_jsxs(_Fragment, { children: [_jsxs("g", { id: "horizontal-ruler", children: [_jsx("rect", { x: "0", y: "0", width: window.innerWidth, height: "30", fill: "#e0e0e0" }), _jsx("g", { stroke: "#888", "font-size": "10", "text-anchor": "middle", children: Array.from({ length: window.innerWidth / 50 }, (_, i) => (_jsxs("g", { children: [_jsx("line", { x1: i * 50, y1: "0", x2: i * 50, y2: "10" }), _jsx("text", { x: i * 50, y: "15", children: i * 50 })] }, i))) })] }), _jsxs("g", { id: "vertical-ruler", children: [_jsx("rect", { x: "0", y: "0", width: "30", height: window.innerHeight, fill: "#e0e0e0" }), _jsx("g", { stroke: "#888", "font-size": "10", "text-anchor": "middle", children: Array.from({ length: window.innerHeight / 10 }, (_, i) => (_jsxs("g", { children: [_jsx("line", { x1: "0", y1: i * 50, x2: "10", y2: i * 50 }), _jsx("text", { x: "15", y: i * 50, children: i * 50 })] }, i))) })] })] })), grid && (_jsxs("g", { stroke: "#ddd", strokeWidth: 0.5, children: [Array.from({ length: widthBoard / 10 }, (_, i) => (_jsx("line", { x1: i * 10, y1: 0, x2: i * 10, y2: heightBoard }, `v-${i}`))), Array.from({ length: heightBoard / 10 }, (_, i) => (_jsx("line", { x1: 0, y1: i * 10, x2: widthBoard, y2: i * 10 }, `h-${i}`)))] }))] }) })] })] })] }));
777
806
  };
778
807
  export default BoardTemplate;
@@ -138,6 +138,7 @@ const BoardTemplate = ({ onSelectComponent, viewOnly }) => {
138
138
  seatFill: activeTool === "table-seat-circle" ? "#DADADA" : undefined,
139
139
  text: activeTool === "text" ? "Text" : "",
140
140
  fontColor: activeTool === "text" ? "#DADADA" : undefined,
141
+ points: [],
141
142
  });
142
143
  const getCoords = (e) => {
143
144
  const svgRect = svgRef.current.getBoundingClientRect();
@@ -751,6 +752,34 @@ const BoardTemplate = ({ onSelectComponent, viewOnly }) => {
751
752
  // moveComponent &&
752
753
  // isTouching.current &&
753
754
  // !resizeDirection
755
+ const [nodes, setNodes] = useState([
756
+ { x: 80, y: 40 },
757
+ { x: 220, y: 40 },
758
+ { x: 260, y: 160 },
759
+ { x: 40, y: 160 },
760
+ ]);
761
+ const addNode = () => {
762
+ if (nodes.length < 30) {
763
+ const midIndex = Math.floor(nodes.length / 2);
764
+ const prev = nodes[midIndex - 1];
765
+ const curr = nodes[midIndex];
766
+ const newNode = {
767
+ x: (prev.x + curr.x) / 2,
768
+ y: (prev.y + curr.y) / 2,
769
+ };
770
+ const newNodes = [...nodes];
771
+ newNodes.splice(midIndex, 0, newNode);
772
+ setNodes(newNodes);
773
+ }
774
+ };
775
+ const removeNode = () => {
776
+ if (nodes.length > 3) {
777
+ const midIndex = Math.floor(nodes.length / 2);
778
+ const newNodes = [...nodes];
779
+ newNodes.splice(midIndex, 1);
780
+ setNodes(newNodes);
781
+ }
782
+ };
754
783
  return (<>
755
784
  <ModalPreview>
756
785
  <LayerView statusKey="status"/>
@@ -760,6 +789,8 @@ const BoardTemplate = ({ onSelectComponent, viewOnly }) => {
760
789
  <div className="flex gap-2">
761
790
  <Button icon={<ZoomIn />} onClick={handelZoomIn}/>
762
791
  <Button icon={<ZoomOut />} onClick={handleZoomOut}/>
792
+ <Button onClick={addNode}>Add Node</Button>
793
+ <Button onClick={removeNode}>Remove Node</Button>
763
794
  </div>
764
795
  </div>
765
796
  <TransformWrapper ref={transformRef} panning={{ disabled: ["node", "select"].includes(activeTool) }} centerZoomedOut={true} onTransformed={({ state: { scale } }) => setScale(scale)} minScale={1} // sangat kecil = bisa zoom out jauh
@@ -797,6 +828,9 @@ const BoardTemplate = ({ onSelectComponent, viewOnly }) => {
797
828
  // onMouseUp={handleMouseUp}
798
829
  // onBlur={handleUnSelectComponent}
799
830
  selectedComponent={selectedComponent} activeTool={activeTool} onTouchStart={handleMouseDown}/>
831
+ <polygon points={nodes.map(n => `${n.x},${n.y}`).join(" ")} fill="lightblue" stroke="black"/>
832
+ {/* Nodes */}
833
+ {nodes.map((node, index) => (<circle key={index} cx={node.x} cy={node.y} r={5} fill="red"/>))}
800
834
  {activeTool === "ruler" && (<>
801
835
  <g id="horizontal-ruler">
802
836
  <rect x="0" y="0" width={window.innerWidth} height="30" fill="#e0e0e0"/>
@@ -77,7 +77,7 @@ const LayerView = (props) => {
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
  }
80
- let minX = 1000, minY = 1000, maxX = -1000, maxY = -1000;
80
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
81
81
  componentsEditor === null || componentsEditor === void 0 ? void 0 : componentsEditor.forEach((_) => {
82
82
  var _a, _b, _c, _d;
83
83
  const hasMappingKey = mappingKey && _[mappingKey];
@@ -76,7 +76,7 @@ const LayerView = (props) => {
76
76
  if (!componentsEditor && (componentsEditor === null || componentsEditor === void 0 ? void 0 : componentsEditor.length) === 0) {
77
77
  return { minX: 0, minY: 0, width: 500, height: 500 };
78
78
  }
79
- let minX = 1000, minY = 1000, maxX = -1000, maxY = -1000;
79
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
80
80
  componentsEditor === null || componentsEditor === void 0 ? void 0 : componentsEditor.forEach((_) => {
81
81
  var _a, _b, _c, _d;
82
82
  const hasMappingKey = mappingKey && _[mappingKey];
@@ -0,0 +1,19 @@
1
+ export interface LayerViewProps {
2
+ componentProps?: any[];
3
+ extraComponentProps?: any[];
4
+ onCurrentStateChange?: (state: any) => void;
5
+ onSelectComponent?: (component: any) => void;
6
+ mappingKey?: string;
7
+ selectedTableColor?: string;
8
+ colorMatchKey?: {
9
+ color: string;
10
+ key: string;
11
+ }[];
12
+ statusKey: string;
13
+ defaultBackground?: string;
14
+ transformProps?: any;
15
+ containerProps?: any;
16
+ svgProps?: any;
17
+ }
18
+ declare const LayerView: (props: LayerViewProps) => import("react/jsx-runtime").JSX.Element;
19
+ export default LayerView;
@@ -0,0 +1,178 @@
1
+ "use client";
2
+ "use client";
3
+ import { jsx as _jsx } from "react/jsx-runtime";
4
+ import { useEffect, useMemo, useRef, useState } from "react";
5
+ import { useAppDispatch, useAppSelector } from "../../hooks/use-redux";
6
+ import Layers from "../../components/layer";
7
+ const LayerView = (props) => {
8
+ const { componentProps, extraComponentProps, onSelectComponent, onCurrentStateChange, mappingKey, selectedTableColor, colorMatchKey, statusKey, defaultBackground, } = props;
9
+ const transformRef = useRef(null);
10
+ const containerRef = useRef(null);
11
+ const svgRef = useRef(null);
12
+ const [scale, setScale] = useState(1);
13
+ const [selectedTable, setSelectedTable] = useState(null);
14
+ const { components: componentsEditor, extraComponents: extraComponentsEditor, } = useAppSelector((state) => state.board);
15
+ const backgroundColor = useAppSelector((state) => state.board.backgroundColor);
16
+ const dispatch = useAppDispatch();
17
+ useEffect(() => {
18
+ if ((componentProps === null || componentProps === void 0 ? void 0 : componentProps.length) > 0) {
19
+ dispatch({
20
+ type: "board/setNewComponents",
21
+ payload: componentProps,
22
+ });
23
+ }
24
+ if ((extraComponentProps === null || extraComponentProps === void 0 ? void 0 : extraComponentProps.length) > 0) {
25
+ dispatch({
26
+ type: "board/setNewExtraComponents",
27
+ payload: extraComponentProps,
28
+ });
29
+ }
30
+ if (defaultBackground) {
31
+ dispatch({
32
+ type: "board/setBackgroundColor",
33
+ payload: defaultBackground,
34
+ });
35
+ }
36
+ }, [componentProps, extraComponentProps, defaultBackground]);
37
+ useEffect(() => {
38
+ onCurrentStateChange &&
39
+ onCurrentStateChange({
40
+ components: componentsEditor,
41
+ extraComponents: extraComponentsEditor,
42
+ });
43
+ }, [componentsEditor, extraComponentsEditor]);
44
+ const handleSelectComponent = (items) => {
45
+ const find = componentsEditor.find((item) => {
46
+ if (mappingKey && (item === null || item === void 0 ? void 0 : item[mappingKey])) {
47
+ return item[mappingKey].id === (items === null || items === void 0 ? void 0 : items.id);
48
+ }
49
+ return (item === null || item === void 0 ? void 0 : item.id) === (items === null || items === void 0 ? void 0 : items.id);
50
+ });
51
+ onSelectComponent && onSelectComponent(find);
52
+ setSelectedTable(find);
53
+ };
54
+ const boundingBox = useMemo(() => {
55
+ var _a, _b, _c, _d, _e, _f, _g;
56
+ if (!componentsEditor && (componentsEditor === null || componentsEditor === void 0 ? void 0 : componentsEditor.length) === 0) {
57
+ return { minX: 0, minY: 0, width: 500, height: 500 };
58
+ }
59
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
60
+ componentsEditor === null || componentsEditor === void 0 ? void 0 : componentsEditor.forEach((_) => {
61
+ var _a, _b, _c, _d;
62
+ let values = mappingKey ? _[mappingKey] : _;
63
+ if (!values)
64
+ return;
65
+ if ((_a = values === null || values === void 0 ? void 0 : values.shape) === null || _a === void 0 ? void 0 : _a.includes("square")) {
66
+ minX = Math.min(minX, values.x);
67
+ minY = Math.min(minY, values.y);
68
+ maxX = Math.max(maxX, values.x + values.width);
69
+ maxY = Math.max(maxY, values.y + values.height);
70
+ }
71
+ if ((_b = values === null || values === void 0 ? void 0 : values.shape) === null || _b === void 0 ? void 0 : _b.includes("circle")) {
72
+ minX = Math.min(minX, values.x);
73
+ minY = Math.min(minY, values.y);
74
+ maxX = Math.max(maxX, values.x + values.width);
75
+ maxY = Math.max(maxY, values.y + values.height);
76
+ }
77
+ if ((_c = values === null || values === void 0 ? void 0 : values.shape) === null || _c === void 0 ? void 0 : _c.includes("table-seat-circle")) {
78
+ minX = Math.min(minX, values.x);
79
+ minY = Math.min(minY, values.y);
80
+ maxX = Math.max(maxX, values.x + values.width);
81
+ maxY = Math.max(maxY, values.y + values.height);
82
+ }
83
+ if ((_d = values === null || values === void 0 ? void 0 : values.shape) === null || _d === void 0 ? void 0 : _d.includes("image-table")) {
84
+ minX = Math.min(minX, values.x);
85
+ minY = Math.min(minY, values.y);
86
+ maxX = Math.max(maxX, values.x + values.width);
87
+ maxY = Math.max(maxY, values.y + values.height);
88
+ }
89
+ });
90
+ extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor.forEach((values) => {
91
+ var _a, _b;
92
+ if ((_a = values === null || values === void 0 ? void 0 : values.shape) === null || _a === void 0 ? void 0 : _a.includes("background")) {
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 ((_b = values === null || values === void 0 ? void 0 : values.shape) === null || _b === void 0 ? void 0 : _b.includes("text")) {
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
+ });
105
+ let backgroundHasOne = false;
106
+ if ((extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor.length) === 1 && ((_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"))) {
107
+ backgroundHasOne = true;
108
+ minX = (_c = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _c === void 0 ? void 0 : _c.x;
109
+ minY = (_d = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _d === void 0 ? void 0 : _d.y;
110
+ maxX = (_e = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _e === void 0 ? void 0 : _e.width;
111
+ maxY = (_f = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _f === void 0 ? void 0 : _f.height;
112
+ }
113
+ 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)) {
114
+ minX = minX - minX * 0.5;
115
+ minY = minY - minY * 0.5;
116
+ }
117
+ return {
118
+ minX: backgroundHasOne ? minX : minX - minX * 0.5,
119
+ minY: backgroundHasOne ? minY : minY - minY * 0.5,
120
+ width: maxX,
121
+ height: maxY,
122
+ };
123
+ }, [componentsEditor, extraComponentsEditor]);
124
+ const renderElements = (elementEditor, mappingKey, colorMatchKey) => {
125
+ return elementEditor.map((editorItem, i) => {
126
+ var _a, _b, _c, _d;
127
+ const isUsingMapping = mappingKey &&
128
+ typeof editorItem[mappingKey] === "object" &&
129
+ editorItem[mappingKey] !== null;
130
+ const finalProps = isUsingMapping ? editorItem[mappingKey] : editorItem;
131
+ if (colorMatchKey) {
132
+ if (isUsingMapping) {
133
+ 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 });
134
+ }
135
+ else {
136
+ 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 });
137
+ }
138
+ }
139
+ return finalProps;
140
+ });
141
+ };
142
+ const [fingerCount, setFingerCount] = useState(0);
143
+ useEffect(() => {
144
+ const container = document.getElementById("workspace");
145
+ const handleTouchStart = (e) => {
146
+ const count = e.touches.length;
147
+ setFingerCount(count);
148
+ };
149
+ const handleTouchEnd = () => {
150
+ setFingerCount(0);
151
+ };
152
+ if (container) {
153
+ container.addEventListener("touchstart", handleTouchStart);
154
+ container.addEventListener("touchend", handleTouchEnd);
155
+ }
156
+ return () => {
157
+ if (container) {
158
+ container.removeEventListener("touchstart", handleTouchStart);
159
+ container.removeEventListener("touchend", handleTouchEnd);
160
+ }
161
+ };
162
+ }, []);
163
+ return (_jsx("div", Object.assign({ className: "relative w-full h-full flex-1", ref: containerRef, style: {
164
+ height: "100vh",
165
+ overflow: "auto",
166
+ WebkitOverflowScrolling: "touch",
167
+ touchAction: "pan-y",
168
+ } }, props.containerProps, { children: _jsx("svg", Object.assign({}, 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: {
169
+ background: backgroundColor !== null && backgroundColor !== void 0 ? backgroundColor : defaultBackground,
170
+ display: "block",
171
+ pointerEvents: "auto",
172
+ // touchAction: "pan-y",
173
+ }, children: _jsx(Layers, { mode: "view", components: [
174
+ ...extraComponentsEditor,
175
+ ...renderElements(componentsEditor, mappingKey, colorMatchKey),
176
+ ], onClick: handleSelectComponent, selectedTable: selectedTable, selectedTableColor: selectedTableColor }) })) })));
177
+ };
178
+ export default LayerView;
@@ -0,0 +1,217 @@
1
+ "use client";
2
+ "use client";
3
+ import { useEffect, useMemo, useRef, useState } from "react";
4
+ import { useAppDispatch, useAppSelector } from "../../hooks/use-redux";
5
+ import Layers from "../../components/layer";
6
+ const LayerView = (props) => {
7
+ const { componentProps, extraComponentProps, onSelectComponent, onCurrentStateChange, mappingKey, selectedTableColor, colorMatchKey, statusKey, defaultBackground, } = props;
8
+ const transformRef = useRef(null);
9
+ const containerRef = useRef(null);
10
+ const svgRef = useRef(null);
11
+ const [scale, setScale] = useState(1);
12
+ const [selectedTable, setSelectedTable] = useState(null);
13
+ const { components: componentsEditor, extraComponents: extraComponentsEditor, } = useAppSelector((state) => state.board);
14
+ const backgroundColor = useAppSelector((state) => state.board.backgroundColor);
15
+ const dispatch = useAppDispatch();
16
+ useEffect(() => {
17
+ if ((componentProps === null || componentProps === void 0 ? void 0 : componentProps.length) > 0) {
18
+ dispatch({
19
+ type: "board/setNewComponents",
20
+ payload: componentProps,
21
+ });
22
+ }
23
+ if ((extraComponentProps === null || extraComponentProps === void 0 ? void 0 : extraComponentProps.length) > 0) {
24
+ dispatch({
25
+ type: "board/setNewExtraComponents",
26
+ payload: extraComponentProps,
27
+ });
28
+ }
29
+ if (defaultBackground) {
30
+ dispatch({
31
+ type: "board/setBackgroundColor",
32
+ payload: defaultBackground,
33
+ });
34
+ }
35
+ }, [componentProps, extraComponentProps, defaultBackground]);
36
+ useEffect(() => {
37
+ onCurrentStateChange &&
38
+ onCurrentStateChange({
39
+ components: componentsEditor,
40
+ extraComponents: extraComponentsEditor,
41
+ });
42
+ }, [componentsEditor, extraComponentsEditor]);
43
+ const handleSelectComponent = (items) => {
44
+ const find = componentsEditor.find((item) => {
45
+ if (mappingKey && (item === null || item === void 0 ? void 0 : item[mappingKey])) {
46
+ return item[mappingKey].id === (items === null || items === void 0 ? void 0 : items.id);
47
+ }
48
+ return (item === null || item === void 0 ? void 0 : item.id) === (items === null || items === void 0 ? void 0 : items.id);
49
+ });
50
+ onSelectComponent && onSelectComponent(find);
51
+ setSelectedTable(find);
52
+ };
53
+ const boundingBox = useMemo(() => {
54
+ var _a, _b, _c, _d, _e, _f, _g;
55
+ if (!componentsEditor && (componentsEditor === null || componentsEditor === void 0 ? void 0 : componentsEditor.length) === 0) {
56
+ return { minX: 0, minY: 0, width: 500, height: 500 };
57
+ }
58
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
59
+ componentsEditor === null || componentsEditor === void 0 ? void 0 : componentsEditor.forEach((_) => {
60
+ var _a, _b, _c, _d;
61
+ let values = mappingKey ? _[mappingKey] : _;
62
+ if (!values)
63
+ return;
64
+ if ((_a = values === null || values === void 0 ? void 0 : values.shape) === null || _a === void 0 ? void 0 : _a.includes("square")) {
65
+ minX = Math.min(minX, values.x);
66
+ minY = Math.min(minY, values.y);
67
+ maxX = Math.max(maxX, values.x + values.width);
68
+ maxY = Math.max(maxY, values.y + values.height);
69
+ }
70
+ if ((_b = values === null || values === void 0 ? void 0 : values.shape) === null || _b === void 0 ? void 0 : _b.includes("circle")) {
71
+ minX = Math.min(minX, values.x);
72
+ minY = Math.min(minY, values.y);
73
+ maxX = Math.max(maxX, values.x + values.width);
74
+ maxY = Math.max(maxY, values.y + values.height);
75
+ }
76
+ if ((_c = values === null || values === void 0 ? void 0 : values.shape) === null || _c === void 0 ? void 0 : _c.includes("table-seat-circle")) {
77
+ minX = Math.min(minX, values.x);
78
+ minY = Math.min(minY, values.y);
79
+ maxX = Math.max(maxX, values.x + values.width);
80
+ maxY = Math.max(maxY, values.y + values.height);
81
+ }
82
+ if ((_d = values === null || values === void 0 ? void 0 : values.shape) === null || _d === void 0 ? void 0 : _d.includes("image-table")) {
83
+ minX = Math.min(minX, values.x);
84
+ minY = Math.min(minY, values.y);
85
+ maxX = Math.max(maxX, values.x + values.width);
86
+ maxY = Math.max(maxY, values.y + values.height);
87
+ }
88
+ });
89
+ extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor.forEach((values) => {
90
+ var _a, _b;
91
+ if ((_a = values === null || values === void 0 ? void 0 : values.shape) === null || _a === void 0 ? void 0 : _a.includes("background")) {
92
+ minX = Math.min(minX, values.x);
93
+ minY = Math.min(minY, values.y);
94
+ maxX = Math.max(maxX, values.x + values.width);
95
+ maxY = Math.max(maxY, values.y + values.height);
96
+ }
97
+ if ((_b = values === null || values === void 0 ? void 0 : values.shape) === null || _b === void 0 ? void 0 : _b.includes("text")) {
98
+ minX = Math.min(minX, values.x);
99
+ minY = Math.min(minY, values.y);
100
+ maxX = Math.max(maxX, values.x + values.width);
101
+ maxY = Math.max(maxY, values.y + values.height);
102
+ }
103
+ });
104
+ let backgroundHasOne = false;
105
+ if ((extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor.length) === 1 && ((_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"))) {
106
+ backgroundHasOne = true;
107
+ minX = (_c = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _c === void 0 ? void 0 : _c.x;
108
+ minY = (_d = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _d === void 0 ? void 0 : _d.y;
109
+ maxX = (_e = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _e === void 0 ? void 0 : _e.width;
110
+ maxY = (_f = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _f === void 0 ? void 0 : _f.height;
111
+ }
112
+ 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)) {
113
+ minX = minX - minX * 0.5;
114
+ minY = minY - minY * 0.5;
115
+ }
116
+ return {
117
+ minX: backgroundHasOne ? minX : minX - minX * 0.5,
118
+ minY: backgroundHasOne ? minY : minY - minY * 0.5,
119
+ width: maxX,
120
+ height: maxY,
121
+ };
122
+ }, [componentsEditor, extraComponentsEditor]);
123
+ const renderElements = (elementEditor, mappingKey, colorMatchKey) => {
124
+ return elementEditor.map((editorItem, i) => {
125
+ var _a, _b, _c, _d;
126
+ const isUsingMapping = mappingKey &&
127
+ typeof editorItem[mappingKey] === "object" &&
128
+ editorItem[mappingKey] !== null;
129
+ const finalProps = isUsingMapping ? editorItem[mappingKey] : editorItem;
130
+ if (colorMatchKey) {
131
+ if (isUsingMapping) {
132
+ 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 });
133
+ }
134
+ else {
135
+ 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 });
136
+ }
137
+ }
138
+ return finalProps;
139
+ });
140
+ };
141
+ const [fingerCount, setFingerCount] = useState(0);
142
+ useEffect(() => {
143
+ const container = document.getElementById("workspace");
144
+ const handleTouchStart = (e) => {
145
+ const count = e.touches.length;
146
+ setFingerCount(count);
147
+ };
148
+ const handleTouchEnd = () => {
149
+ setFingerCount(0);
150
+ };
151
+ if (container) {
152
+ container.addEventListener("touchstart", handleTouchStart);
153
+ container.addEventListener("touchend", handleTouchEnd);
154
+ }
155
+ return () => {
156
+ if (container) {
157
+ container.removeEventListener("touchstart", handleTouchStart);
158
+ container.removeEventListener("touchend", handleTouchEnd);
159
+ }
160
+ };
161
+ }, []);
162
+ return (<div className="relative w-full h-full flex-1" ref={containerRef} style={{
163
+ height: "100vh",
164
+ overflow: "auto",
165
+ WebkitOverflowScrolling: "touch",
166
+ touchAction: "pan-y",
167
+ }} {...props.containerProps}>
168
+ {/* <TransformWrapper
169
+ ref={transformRef}
170
+ {...props.transformProps}
171
+ disabled={fingerCount === 1 && scale === 1}
172
+ disablePadding={true}
173
+ // panning={{
174
+ // disabled: false,
175
+ // velocityDisabled: true,
176
+ // }}
177
+ // limitToBounds={false}
178
+ // doubleClick={{ disabled: true }}
179
+ // pinch={{ disabled: false }}
180
+ // wheel={{ disabled: true }}
181
+ // disabled={true}
182
+ // disablePadding={true}
183
+ centerZoomedOut={true}
184
+ onTransformed={({ state: { scale } }) => setScale(scale)}
185
+ minScale={1}
186
+ maxScale={1000}
187
+ initialScale={1}
188
+ // pinch={{ step: 1 }}
189
+ smooth={true}
190
+ >
191
+ <TransformComponent
192
+ wrapperStyle={{
193
+ width: "100%",
194
+ height: "100%",
195
+ overflow: "visible",
196
+ }}
197
+ contentStyle={{
198
+ width: "100%",
199
+ height: "100%",
200
+ }}
201
+ > */}
202
+ <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={{
203
+ background: backgroundColor !== null && backgroundColor !== void 0 ? backgroundColor : defaultBackground,
204
+ display: "block",
205
+ pointerEvents: "auto",
206
+ // touchAction: "pan-y",
207
+ }}>
208
+ <Layers mode="view" components={[
209
+ ...extraComponentsEditor,
210
+ ...renderElements(componentsEditor, mappingKey, colorMatchKey),
211
+ ]} onClick={handleSelectComponent} selectedTable={selectedTable} selectedTableColor={selectedTableColor}/>
212
+ </svg>
213
+ {/* </TransformComponent>
214
+ </TransformWrapper> */}
215
+ </div>);
216
+ };
217
+ export default LayerView;
package/dist/index.d.ts CHANGED
@@ -3,5 +3,6 @@ import Board from "./features/board";
3
3
  import SideTool from "./features/side-tool";
4
4
  import ControlPanels from "./features/panel";
5
5
  import LayerView, { type LayerViewProps } from "./features/view-only";
6
+ import LayerView2, { type LayerViewProps as LayerViewProps2 } from "./features/view-only-2";
6
7
  import TableEditor from "./features/package";
7
- export { StoreProvider as ProviderSeatEditor, Board, SideTool, ControlPanels, LayerView, LayerViewProps, TableEditor as SeatEditor };
8
+ export { StoreProvider as ProviderSeatEditor, Board, SideTool, ControlPanels, LayerView, LayerView2, LayerViewProps2, LayerViewProps, TableEditor as SeatEditor };
package/dist/index.js CHANGED
@@ -3,5 +3,6 @@ import Board from "./features/board";
3
3
  import SideTool from "./features/side-tool";
4
4
  import ControlPanels from "./features/panel";
5
5
  import LayerView from "./features/view-only";
6
+ import LayerView2 from "./features/view-only-2";
6
7
  import TableEditor from "./features/package";
7
- export { StoreProvider as ProviderSeatEditor, Board, SideTool, ControlPanels, LayerView, TableEditor as SeatEditor };
8
+ export { StoreProvider as ProviderSeatEditor, Board, SideTool, ControlPanels, LayerView, LayerView2, TableEditor as SeatEditor };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seat-editor",
3
- "version": "1.6.25",
3
+ "version": "1.6.27",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",