seat-editor 1.1.8 → 1.2.1

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.
@@ -3,7 +3,7 @@ import { dataDummy, dummyImage } from "./constant";
3
3
  const OnlyView = () => {
4
4
  return (<>
5
5
  <div className="w-full h-screen flex relative justify-center items-center">
6
- <LayerView componentProps={dataDummy} mappingKey="properties" extraComponentProps={dummyImage}/>
6
+ <LayerView componentProps={dataDummy} mappingKey="properties" extraComponentProps={dummyImage} statusKey="status"/>
7
7
  </div>
8
8
  </>);
9
9
  };
@@ -7,6 +7,8 @@ interface LayersProps {
7
7
  onMouseDown?: (e: React.MouseEvent, item: any) => void;
8
8
  onMouseUp?: (e: React.MouseEvent) => void;
9
9
  onBlur?: () => void;
10
+ selectedTable?: any;
11
+ selectedTableColor?: string;
10
12
  }
11
- declare const Layers: ({ shadowShape, components, onClick, selectedComponent, activeTool, onMouseDown, onMouseUp, onBlur, }: LayersProps) => import("react").JSX.Element;
13
+ declare const Layers: ({ shadowShape, components, onClick, selectedComponent, selectedTable, activeTool, onMouseDown, onMouseUp, onBlur, selectedTableColor, }: LayersProps) => import("react").JSX.Element;
12
14
  export default Layers;
@@ -1,7 +1,6 @@
1
1
  "use client";
2
2
  import { omit } from "lodash";
3
- const Layers = ({ shadowShape, components, onClick, selectedComponent, activeTool, onMouseDown, onMouseUp, onBlur, }) => {
4
- console.log({ components });
3
+ const Layers = ({ shadowShape, components, onClick, selectedComponent, selectedTable, activeTool, onMouseDown, onMouseUp, onBlur, selectedTableColor, }) => {
5
4
  const renderShadowShape = (item) => {
6
5
  const { id, x, y, width, height, fill, opacity, rotation, shape, fontColor, text, seatFill, labels, } = item;
7
6
  const commonProps = { fill, opacity };
@@ -89,13 +88,11 @@ const Layers = ({ shadowShape, components, onClick, selectedComponent, activeToo
89
88
  onClick: (e) => {
90
89
  e.stopPropagation();
91
90
  onClick(item);
92
- console.log("click", item);
93
91
  },
94
92
  stroke,
95
93
  strokeWidth,
96
94
  onMouseDown: (e) => {
97
95
  e.stopPropagation();
98
- console.log("mouse down", item);
99
96
  onMouseDown === null || onMouseDown === void 0 ? void 0 : onMouseDown(e, item);
100
97
  },
101
98
  onMouseUp: (e) => {
@@ -110,7 +107,7 @@ const Layers = ({ shadowShape, components, onClick, selectedComponent, activeToo
110
107
  switch (shape) {
111
108
  case "square":
112
109
  return (<>
113
- <rect key={id} x={x} y={y} width={width} height={height} opacity={id === (selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.id) ? 0.5 : opacity} {...omit(commonProps, "opacity")} transform={`rotate(${rotation} ${x + width / 2} ${y + height / 2})`}/>
110
+ <rect key={id} x={x} y={y} width={width} height={height} fill={selectedTableColor !== null && selectedTableColor !== void 0 ? selectedTableColor : fill} opacity={id === (selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.id) ? 0.5 : opacity} {...omit(commonProps, "opacity")} transform={`rotate(${rotation} ${x + width / 2} ${y + height / 2})`}/>
114
111
  {labels === null || labels === void 0 ? void 0 : labels.map((_, index) => {
115
112
  var _a, _b, _c, _d;
116
113
  return (<text key={`${id}-label-${index}`} x={x + width / 2 + ((_a = _ === null || _ === void 0 ? void 0 : _.x) !== null && _a !== void 0 ? _a : 0)} y={y + height / 2 + ((_b = _ === null || _ === void 0 ? void 0 : _.y) !== null && _b !== void 0 ? _b : 0)} fill={(_c = _ === null || _ === void 0 ? void 0 : _.fontColor) !== null && _c !== void 0 ? _c : "black"} fontSize={`${(_d = _ === null || _ === void 0 ? void 0 : _.fontSize) !== null && _d !== void 0 ? _d : 10}px`} fontWeight="bold" textAnchor="middle" dominantBaseline="middle" transform={`rotate(${rotation} ${x + width / 2} ${y + height / 2})`}>
@@ -120,7 +117,7 @@ const Layers = ({ shadowShape, components, onClick, selectedComponent, activeToo
120
117
  </>);
121
118
  case "circle":
122
119
  return (<>
123
- <circle key={id} cx={x + width / 2} cy={y + height / 2} r={width / 2} opacity={id === (selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.id) ? 0.5 : opacity} {...omit(commonProps, "opacity")}/>
120
+ <circle key={id} cx={x + width / 2} cy={y + height / 2} r={width / 2} fill={selectedTableColor !== null && selectedTableColor !== void 0 ? selectedTableColor : fill} opacity={id === (selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.id) ? 0.5 : opacity} {...omit(commonProps, "opacity")}/>
124
121
  {labels === null || labels === void 0 ? void 0 : labels.map((_, index) => {
125
122
  var _a, _b, _c, _d;
126
123
  return (<text key={`${id}-label-${index}`} x={x + width / 2 + ((_a = _ === null || _ === void 0 ? void 0 : _.x) !== null && _a !== void 0 ? _a : 0)} y={y + height / 2 + ((_b = _ === null || _ === void 0 ? void 0 : _.y) !== null && _b !== void 0 ? _b : 0)} fill={(_c = _ === null || _ === void 0 ? void 0 : _.fontColor) !== null && _c !== void 0 ? _c : "black"} fontSize={`${(_d = _ === null || _ === void 0 ? void 0 : _.fontSize) !== null && _d !== void 0 ? _d : 10}px`} fontWeight="bold" textAnchor="middle" dominantBaseline="middle" transform={`rotate(${rotation} ${x + width / 2} ${y + height / 2})`}>
@@ -130,7 +127,7 @@ const Layers = ({ shadowShape, components, onClick, selectedComponent, activeToo
130
127
  </>);
131
128
  case "diamond":
132
129
  return (<>
133
- <rect key={id} x={x} y={y} width={width} height={height} transform={`rotate(${rotation}, ${x}, ${y})`} {...commonProps}/>
130
+ <rect key={id} x={x} y={y} width={width} height={height} transform={`rotate(${rotation}, ${x}, ${y})`} {...commonProps} fill={selectedTableColor !== null && selectedTableColor !== void 0 ? selectedTableColor : fill}/>
134
131
  <text x={x + width / 2} y={y + height / 2} fill={fontColor !== null && fontColor !== void 0 ? fontColor : "black"} fontSize={`${fontSize !== null && fontSize !== void 0 ? fontSize : 10}px`} fontWeight="bold" textAnchor="middle" dominantBaseline="middle">
135
132
  {label}
136
133
  </text>
@@ -153,7 +150,7 @@ const Layers = ({ shadowShape, components, onClick, selectedComponent, activeToo
153
150
  return { cx, cy };
154
151
  });
155
152
  return (<g key={id} transform={`rotate(${rotation} ${x + width / 2} ${y + height / 2})`}>
156
- <circle cx={centerX} cy={centerY} r={width - 15} {...commonProps} opacity={id === (selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.id) ? 0.5 : opacity}/>
153
+ <circle cx={centerX} cy={centerY} r={width - 15} fill={selectedTableColor !== null && selectedTableColor !== void 0 ? selectedTableColor : fill} {...commonProps} opacity={id === (selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.id) ? 0.5 : opacity}/>
157
154
  {labels === null || labels === void 0 ? void 0 : labels.map((_, index) => {
158
155
  var _a, _b, _c, _d;
159
156
  return (<text key={`${id}-label-${index}`} x={x + width / 2 + ((_a = _ === null || _ === void 0 ? void 0 : _.x) !== null && _a !== void 0 ? _a : 0)} y={y + height / 2 + ((_b = _ === null || _ === void 0 ? void 0 : _.y) !== null && _b !== void 0 ? _b : 0)} fill={(_c = _ === null || _ === void 0 ? void 0 : _.fontColor) !== null && _c !== void 0 ? _c : "black"} fontSize={`${(_d = _ === null || _ === void 0 ? void 0 : _.fontSize) !== null && _d !== void 0 ? _d : 10}px`} fontWeight="bold" textAnchor="middle" dominantBaseline="middle" transform={`rotate(${rotation} ${x + width / 2} ${y + height / 2})`}>
@@ -185,7 +182,7 @@ const Layers = ({ shadowShape, components, onClick, selectedComponent, activeToo
185
182
  }));
186
183
  return (<g key={id} transform={`rotate(${rotation}, ${x}, ${y})`}>
187
184
  {/* Square Table */}
188
- <rect x={x} y={y} width={width} height={height} {...commonProps}/>
185
+ <rect x={x} y={y} width={width} height={height} {...commonProps} fill={selectedTableColor !== null && selectedTableColor !== void 0 ? selectedTableColor : fill}/>
189
186
  <text x={x + width / 2} y={y + height / 2} fill={fontColor !== null && fontColor !== void 0 ? fontColor : "black"} fontSize={`${fontSize !== null && fontSize !== void 0 ? fontSize : 10}px`} fontWeight="bold" textAnchor="middle" dominantBaseline="middle">
190
187
  {label}
191
188
  </text>
@@ -251,7 +251,7 @@ const BoardTemplate = ({ onSelectComponent }) => {
251
251
  };
252
252
  return (<>
253
253
  <ModalPreview>
254
- <LayerView />
254
+ <LayerView statusKey="status"/>
255
255
  </ModalPreview>
256
256
  <div className="relative w-full h-screen flex-1" ref={containerRef}>
257
257
  <TransformWrapper ref={transformRef} panning={{ disabled: false }} centerZoomedOut={true} onTransformed={({ state: { scale } }) => setScale(scale)} minScale={1} // sangat kecil = bisa zoom out jauh
@@ -3,6 +3,15 @@ export interface TableEditorProps {
3
3
  extraComponentProps: any[];
4
4
  onCurrentStateChange: (state: any) => void;
5
5
  onSelectComponent: (component: any) => void;
6
+ mappingKey?: string;
7
+ selectedTableColor?: string;
8
+ colorMatchKey?: [
9
+ {
10
+ color: string;
11
+ key: string;
12
+ }
13
+ ];
14
+ statusKey: string;
6
15
  }
7
16
  declare const TableEditor: (props: TableEditorProps) => import("react").JSX.Element;
8
17
  export default TableEditor;
@@ -4,6 +4,14 @@ export interface LayerViewProps {
4
4
  onCurrentStateChange?: (state: any) => void;
5
5
  onSelectComponent?: (component: any) => void;
6
6
  mappingKey?: string;
7
+ selectedTableColor?: string;
8
+ colorMatchKey?: [
9
+ {
10
+ color: string;
11
+ key: string;
12
+ }
13
+ ];
14
+ statusKey: string;
7
15
  }
8
16
  declare const LayerView: (props: LayerViewProps) => import("react").JSX.Element;
9
17
  export default LayerView;
@@ -5,13 +5,12 @@ import { TransformWrapper, TransformComponent, } from "react-zoom-pan-pinch";
5
5
  import { useAppDispatch, useAppSelector } from "../../hooks/use-redux";
6
6
  import Layers from "../../components/layer";
7
7
  const LayerView = (props) => {
8
- const { componentProps = [], extraComponentProps = [], onSelectComponent, onCurrentStateChange, mappingKey, } = props;
9
- console.log({ extraComponentProps });
8
+ const { componentProps = [], extraComponentProps = [], onSelectComponent, onCurrentStateChange, mappingKey, selectedTableColor, colorMatchKey, statusKey } = props;
10
9
  const transformRef = useRef(null);
11
10
  const containerRef = useRef(null);
12
- console.log({ mappingKey });
13
11
  const svgRef = useRef(null);
14
12
  const [scale, setScale] = useState(1);
13
+ const [selectedTable, setSelectedTable] = useState(null);
15
14
  const { components: componentsEditor, extraComponents: extraComponentsEditor, } = useAppSelector((state) => state.board);
16
15
  const backgroundColor = useAppSelector((state) => state.board.backgroundColor);
17
16
  const dispatch = useAppDispatch();
@@ -37,7 +36,14 @@ const LayerView = (props) => {
37
36
  });
38
37
  }, [componentsEditor, extraComponentsEditor]);
39
38
  const handleSelectComponent = (items) => {
40
- onSelectComponent(items);
39
+ const find = componentsEditor.find((item) => {
40
+ if (mappingKey && (item === null || item === void 0 ? void 0 : item[mappingKey])) {
41
+ return item[mappingKey].id === (items === null || items === void 0 ? void 0 : items.id);
42
+ }
43
+ return (item === null || item === void 0 ? void 0 : item.id) === (items === null || items === void 0 ? void 0 : items.id);
44
+ });
45
+ onSelectComponent && onSelectComponent(find);
46
+ setSelectedTable(find);
41
47
  };
42
48
  const boundingBox = useMemo(() => {
43
49
  if (!componentsEditor || (componentsEditor === null || componentsEditor === void 0 ? void 0 : componentsEditor.length) === 0) {
@@ -94,17 +100,24 @@ const LayerView = (props) => {
94
100
  };
95
101
  }, [componentsEditor, extraComponentsEditor]);
96
102
  let elementEditor = [...extraComponentsEditor, ...componentsEditor];
97
- console.log({ elementEditor });
98
- function renderElements(elementEditor, mappingKey) {
103
+ const renderElements = (elementEditor, mappingKey, colorMatchKey) => {
99
104
  return elementEditor.map((editorItem, i) => {
100
105
  const isUsingMapping = mappingKey &&
101
106
  typeof editorItem[mappingKey] === "object" &&
102
107
  editorItem[mappingKey] !== null;
103
108
  const finalProps = isUsingMapping ? editorItem[mappingKey] : editorItem;
104
- // Contoh return JSX, bisa diganti sesuai kebutuhan
109
+ if (colorMatchKey) {
110
+ return finalProps.map((item) => {
111
+ const match = colorMatchKey === null || colorMatchKey === void 0 ? void 0 : colorMatchKey.find((key) => key.id === (item === null || item === void 0 ? void 0 : item[statusKey]));
112
+ if (match) {
113
+ return Object.assign(Object.assign({}, item), { properties: Object.assign(Object.assign({}, item.properties), { fill: match.color }) });
114
+ }
115
+ return item;
116
+ });
117
+ }
105
118
  return finalProps;
106
119
  });
107
- }
120
+ };
108
121
  return (<div className="relative w-full h-full flex-1" ref={containerRef}>
109
122
  <TransformWrapper ref={transformRef} panning={{ disabled: false }} centerZoomedOut={true} onTransformed={({ state: { scale } }) => setScale(scale)} minScale={1} maxScale={1000} initialScale={1} pinch={{ step: 1 }} smooth={true} disablePadding>
110
123
  <TransformComponent wrapperStyle={{
@@ -119,7 +132,7 @@ const LayerView = (props) => {
119
132
  background: backgroundColor,
120
133
  display: "block",
121
134
  }}>
122
- <Layers components={renderElements(elementEditor, mappingKey)} onClick={handleSelectComponent}/>
135
+ <Layers components={renderElements(elementEditor, mappingKey, colorMatchKey)} onClick={handleSelectComponent} selectedTable={selectedTable} selectedTableColor={selectedTableColor}/>
123
136
  </svg>
124
137
  </TransformComponent>
125
138
  </TransformWrapper>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seat-editor",
3
- "version": "1.1.8",
3
+ "version": "1.2.1",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",