seat-editor 3.2.4 → 3.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,24 +1,26 @@
1
1
  "use client";
2
2
  import { useEffect, useState } from "react";
3
3
  import SeatEditor from "../../features/package";
4
- import { data4 } from "../constant";
4
+ import { data5, dummyExtra5 } from "../constant";
5
5
  export default function NewBoard() {
6
6
  const [initialValue, setInitialValue] = useState([]);
7
7
  const [extraComponents, setExtraComponents] = useState([]);
8
8
  const [backgroundColor, setBackgroundColor] = useState("#000000");
9
9
  const [viewOnly, setViewOnly] = useState(false);
10
10
  useEffect(() => {
11
- setInitialValue(data4);
12
- setExtraComponents([]);
11
+ setInitialValue(data5);
12
+ setExtraComponents(dummyExtra5);
13
13
  }, []);
14
14
  return (<>
15
15
  <div className="w-full h-screen flex flex-col relative justify-center">
16
16
  <div className="w-full h-[1000px] bg-white border-r border-gray-200">
17
17
 
18
18
  </div>
19
- <button className="bg-blue-500 text-white px-4 py-2 rounded" onClick={() => setViewOnly(!viewOnly)}>
19
+ {/* <button className="bg-blue-500 text-white px-4 py-2 rounded"
20
+ onClick={() => setViewOnly(!viewOnly)}
21
+ >
20
22
  {viewOnly ? "Edit Mode ddd" : "View Mode"}
21
- </button>
23
+ </button> */}
22
24
  <div className="flex-1 h-full">
23
25
  <SeatEditor componentProps={initialValue} viewOnly={viewOnly} dragOnly={true} deleteAutorized={{
24
26
  component: true,
@@ -59,7 +59,7 @@ const boardSlice = createSlice({
59
59
  }
60
60
  },
61
61
  updateComponentsBulk: (state, action) => {
62
- const updates = action.payload; // array of components
62
+ const updates = action.payload;
63
63
  // Simpan snapshot untuk undo (deep clone lebih aman)
64
64
  state.historyChanges.push({
65
65
  components: [...state.components],
@@ -119,6 +119,19 @@ const boardSlice = createSlice({
119
119
  state.pointer += 1;
120
120
  },
121
121
  setNewExtraComponents: (state, action) => {
122
+ const currentPointer = state.pointer;
123
+ const totalHistory = state.historyChanges.length;
124
+ if (currentPointer < totalHistory) {
125
+ state.historyChanges = state.historyChanges.slice(0, currentPointer + 1);
126
+ }
127
+ state.historyChanges.push({
128
+ components: [...state.components],
129
+ extraComponents: [...state.extraComponents],
130
+ });
131
+ if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
132
+ state.historyChanges.shift();
133
+ }
134
+ state.pointer += 1;
122
135
  state.extraComponents = action.payload;
123
136
  },
124
137
  setExtraComponent: (state, action) => {
@@ -153,14 +166,16 @@ const boardSlice = createSlice({
153
166
  state.pointer -= 1;
154
167
  }
155
168
  const prev = state.historyChanges[state.pointer];
169
+ console.log({ prev });
156
170
  state.components = current(prev === null || prev === void 0 ? void 0 : prev.components);
157
171
  state.extraComponents = current(prev === null || prev === void 0 ? void 0 : prev.extraComponents);
158
172
  }
159
173
  else if (state.pointer === 1) {
160
174
  state.components = current((_b = (_a = state.historyChanges) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.components);
161
- state.components = current((_d = (_c = state.historyChanges) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.extraComponents);
175
+ state.extraComponents = current((_d = (_c = state.historyChanges) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.extraComponents);
162
176
  state.pointer = 0;
163
177
  }
178
+ state.updateBy = "global";
164
179
  },
165
180
  redoHistory: (state) => {
166
181
  if (state.pointer < state.historyChanges.length - 1) {
@@ -168,8 +183,20 @@ const boardSlice = createSlice({
168
183
  state.components = current(next === null || next === void 0 ? void 0 : next.components);
169
184
  state.extraComponents = current(next === null || next === void 0 ? void 0 : next.extraComponents);
170
185
  state.pointer += 1;
186
+ state.updateBy = "global";
171
187
  }
172
188
  },
189
+ setInitialValue: (state, action) => {
190
+ const { components, extraComponents, backgroundColor } = action.payload;
191
+ state.components = components;
192
+ state.extraComponents = extraComponents;
193
+ state.pointer = 0;
194
+ state.backgroundColor = backgroundColor;
195
+ state.historyChanges = [{
196
+ components,
197
+ extraComponents
198
+ }];
199
+ }
173
200
  },
174
201
  });
175
202
  export const { addComponent, removeComponent, updateComponent, setBackgroundColor, removeExtraComponent } = boardSlice.actions;
@@ -208,7 +208,7 @@ const BoardTemplate = ({ refs }) => {
208
208
  const updatedExtra = updateSingleComponent(extraComponentsState, component, setExtraComponentsState);
209
209
  if (updatedExtra) {
210
210
  dispatch({ type: "board/setUpdateBy", payload: "local" });
211
- queueUpdateComponents(updatedComponents);
211
+ queueUpdateComponents(updatedExtra);
212
212
  }
213
213
  };
214
214
  const updateComponentsAttribute = (components) => {
@@ -1,6 +1,5 @@
1
1
  import { RefsType } from "../board-v3";
2
2
  import { PropertiesProps } from "@/dto/table";
3
- import { UploadFile } from "antd";
4
3
  export interface TableEditorProps {
5
4
  componentProps: PropertiesProps[];
6
5
  extraComponentProps: PropertiesProps[];
@@ -20,7 +19,7 @@ export interface TableEditorProps {
20
19
  ];
21
20
  statusKey: string;
22
21
  defaultBackground?: string;
23
- action?: (file: UploadFile<File>, type: string, defaultValue: PropertiesProps) => Promise<PropertiesProps>;
22
+ action?: (file: File) => Promise<string>;
24
23
  responseMapping?: {
25
24
  status: string;
26
25
  message: string;
@@ -7,6 +7,7 @@ import { useAppDispatch, useAppSelector } from "../../hooks/use-redux";
7
7
  import { isEqual } from "lodash";
8
8
  import LayerView from "../view-only";
9
9
  const TableEditor = (props) => {
10
+ var _a;
10
11
  const [initialValue, setInitialValue] = useState(null);
11
12
  const { componentProps, extraComponentProps, onCurrentStateChange, dragOnly, mappingKey, viewOnly, deleteAutorized, refs, } = props;
12
13
  const { components, extraComponents, backgroundColor } = useAppSelector((state) => state.board);
@@ -29,7 +30,7 @@ const TableEditor = (props) => {
29
30
  }
30
31
  dispatch({
31
32
  type: "tool/setActiveTool",
32
- payload: ""
33
+ payload: "",
33
34
  });
34
35
  if (viewOnly) {
35
36
  dispatch({ type: "board/setFlagChange", payload: true });
@@ -80,7 +81,9 @@ const TableEditor = (props) => {
80
81
  return mappingData;
81
82
  };
82
83
  useEffect(() => {
83
- if (!isEqual(components, convertComponentProps()) && componentProps) {
84
+ const initialComponent = !isEqual(components, convertComponentProps()) && componentProps;
85
+ const initialExtraComponent = !isEqual(extraComponents, extraComponentProps) && extraComponentProps;
86
+ if (initialComponent || initialExtraComponent) {
84
87
  let mappingData = componentProps === null || componentProps === void 0 ? void 0 : componentProps.map((item) => {
85
88
  if (mappingKey && (item === null || item === void 0 ? void 0 : item[props.mappingKey])) {
86
89
  return Object.assign({}, item[props.mappingKey]);
@@ -91,25 +94,33 @@ const TableEditor = (props) => {
91
94
  setInitialValue(componentProps);
92
95
  }
93
96
  dispatch({
94
- type: "board/setNewComponents",
95
- payload: mappingData,
96
- });
97
- dispatch({ type: "board/setFlagChange", payload: true });
98
- }
99
- if (!isEqual(extraComponents, extraComponentProps) && extraComponentProps) {
100
- dispatch({
101
- type: "board/setNewExtraComponents",
102
- payload: extraComponentProps,
103
- });
104
- dispatch({ type: "board/setFlagChange", payload: true });
105
- }
106
- if (props === null || props === void 0 ? void 0 : props.defaultBackground) {
107
- dispatch({
108
- type: "board/setBackgroundColor",
109
- payload: props === null || props === void 0 ? void 0 : props.defaultBackground,
97
+ type: "board/setInitialValue",
98
+ payload: {
99
+ components: mappingData,
100
+ extraComponents: extraComponentProps,
101
+ backgroundColor: props === null || props === void 0 ? void 0 : props.defaultBackground,
102
+ },
110
103
  });
104
+ // dispatch({
105
+ // type: "board/setNewComponents",
106
+ // payload: mappingData,
107
+ // });
111
108
  dispatch({ type: "board/setFlagChange", payload: true });
112
109
  }
110
+ // if (!isEqual(extraComponents, extraComponentProps) && extraComponentProps) {
111
+ // dispatch({
112
+ // type: "board/setNewExtraComponents",
113
+ // payload: extraComponentProps,
114
+ // });
115
+ // dispatch({ type: "board/setFlagChange", payload: true });
116
+ // }
117
+ // if (props?.defaultBackground) {
118
+ // dispatch({
119
+ // type: "board/setBackgroundColor",
120
+ // payload: props?.defaultBackground,
121
+ // });
122
+ // dispatch({ type: "board/setFlagChange", payload: true });
123
+ // }
113
124
  }, [componentProps, extraComponentProps, props === null || props === void 0 ? void 0 : props.defaultBackground]);
114
125
  return (<>
115
126
  <div className="w-full h-screen flex relative">
@@ -118,7 +129,7 @@ const TableEditor = (props) => {
118
129
  </div>) : (<div key={`${viewOnly}`} className="w-full h-full flex relative">
119
130
  <SideTool dragOnly={dragOnly} deleteAutorized={deleteAutorized}/>
120
131
  <Board key={`${viewOnly}`} refs={refsBoard}/>
121
- <ControlPanels action={props.action} responseMapping={props.responseMapping}/>
132
+ <ControlPanels action={props.action} transform={(_a = refsBoard === null || refsBoard === void 0 ? void 0 : refsBoard.current) === null || _a === void 0 ? void 0 : _a.transformRef}/>
122
133
  </div>)}
123
134
  </div>
124
135
  </>);
@@ -1,13 +1,6 @@
1
- import { UploadFile } from "antd";
2
- import { PropertiesProps } from "../../dto/table";
3
1
  interface ControlPanelsProps {
4
- action?: (file: UploadFile<File>, type: string, defaultValue: PropertiesProps) => Promise<PropertiesProps>;
5
- responseMapping?: {
6
- status: string;
7
- message: string;
8
- data: string;
9
- src: string;
10
- };
2
+ action?: (file: File) => Promise<string>;
3
+ transform?: any;
11
4
  }
12
5
  declare const ControlPanels: (props: ControlPanelsProps) => import("react").JSX.Element;
13
6
  export default ControlPanels;
@@ -25,7 +25,7 @@ import { SEAT_SHAPES } from "../../utils/constant";
25
25
  import { adjustHeightWidthForSeatShape, getSeatCount, getSeatPosition, isSeatShape, } from "./utils";
26
26
  import SeatSquare from "./table-seat-square";
27
27
  const ControlPanels = (props) => {
28
- const { action, responseMapping } = props;
28
+ const { action, transform } = props;
29
29
  const dispatch = useAppDispatch();
30
30
  const theme = useAppSelector((state) => state.theme);
31
31
  const tool = useAppSelector((state) => state.tool);
@@ -216,7 +216,7 @@ const ControlPanels = (props) => {
216
216
  const renderFormPanel = () => {
217
217
  switch (tool.active) {
218
218
  case "select":
219
- return (<SelectToolForm action={action} responseMapping={responseMapping}/>);
219
+ return (<SelectToolForm action={action} tranform={transform}/>);
220
220
  case "square":
221
221
  case "circle":
222
222
  return <SquareToolForm />;
@@ -225,9 +225,9 @@ const ControlPanels = (props) => {
225
225
  case "table-seat-square":
226
226
  return <SeatSquare />;
227
227
  case "image-table":
228
- return (<UploadTool name={tool.active} type="component" action={action} responseMapping={responseMapping}/>);
228
+ return (<UploadTool name={tool.active} type="component" action={action} transform={transform}/>);
229
229
  case "background":
230
- return (<UploadTool name={tool.active} type="background" action={action} responseMapping={responseMapping}/>);
230
+ return (<UploadTool name={tool.active} type="background" action={action} transform={transform}/>);
231
231
  default:
232
232
  return null;
233
233
  }
@@ -1,6 +1,6 @@
1
- declare const SelectToolForm: ({ title, action, responseMapping }: {
1
+ declare const SelectToolForm: ({ title, action, tranform }: {
2
2
  title?: string;
3
3
  action: any;
4
- responseMapping: any;
4
+ tranform: any;
5
5
  }) => import("react").JSX.Element;
6
6
  export default SelectToolForm;
@@ -6,7 +6,7 @@ import SeatSquare from "./table-seat-square";
6
6
  import UploadTool from "./upload-tool";
7
7
  import TextTool from "./text-tool";
8
8
  import SelectedGroup from "./selected-group";
9
- const SelectToolForm = ({ title = "Title", action, responseMapping }) => {
9
+ const SelectToolForm = ({ title = "Title", action, tranform }) => {
10
10
  const components = useAppSelector((state) => state.board.components);
11
11
  const selectedComponent = useAppSelector((state) => state.panel.selectedComponent);
12
12
  const extraComponents = useAppSelector((state) => state.board.extraComponents);
@@ -47,9 +47,9 @@ const SelectToolForm = ({ title = "Title", action, responseMapping }) => {
47
47
  return <SeatSquare />;
48
48
  case "image-table":
49
49
  case "background":
50
- return (<UploadTool action={action} responseMapping={responseMapping} name={selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.shape} defaultValue={selectedComponent} type={(selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.shape) === "background"
50
+ return (<UploadTool action={action} name={selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.shape} defaultValue={selectedComponent} type={(selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.shape) === "background"
51
51
  ? "background"
52
- : "component"}/>);
52
+ : "component"} transform={tranform}/>);
53
53
  case "text":
54
54
  return <TextTool />;
55
55
  default:
@@ -1,16 +1,10 @@
1
- import { UploadFile } from "antd";
2
1
  import { PropertiesProps } from "@/dto/table";
3
2
  interface UploadToolProps {
4
3
  name: string;
5
4
  type?: "component" | "background" | "assets";
6
- action?: (file: UploadFile<File>, type: string, defaultValue: PropertiesProps) => Promise<PropertiesProps>;
7
- responseMapping?: {
8
- status: string;
9
- message: string;
10
- data: string;
11
- src: string;
12
- };
5
+ action?: (file: File) => Promise<string>;
13
6
  defaultValue?: PropertiesProps;
7
+ transform?: any;
14
8
  }
15
- declare const UploadTool: ({ name, type, action, responseMapping, defaultValue, }: UploadToolProps) => import("react").JSX.Element;
9
+ declare const UploadTool: ({ name, type, action, defaultValue, transform }: UploadToolProps) => import("react").JSX.Element;
16
10
  export default UploadTool;
@@ -10,28 +10,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  import { useState, useEffect } from "react";
12
12
  import { Upload, Image, Button } from "antd";
13
- import { InboxOutlined } from "@ant-design/icons";
13
+ import { InboxOutlined, LoadingOutlined } from "@ant-design/icons";
14
14
  import { useAppDispatch } 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
- const UploadTool = ({ name, type, action, responseMapping, defaultValue, }) => {
19
- var _a, _b;
18
+ const UploadTool = ({ name, type, action, defaultValue, transform }) => {
19
+ var _a, _b, _c;
20
+ const transformState = (_a = transform === null || transform === void 0 ? void 0 : transform.instance) === null || _a === void 0 ? void 0 : _a.transformState;
20
21
  const [defaultSrc, setDefaultSrc] = useState(null);
21
22
  const [isEdit, setIsEdit] = useState(false);
23
+ const [loading, setLoading] = useState(false);
22
24
  useEffect(() => {
23
25
  if (defaultValue) {
24
26
  setDefaultSrc(defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.src);
25
27
  setIsEdit(true);
28
+ setLoading(false);
26
29
  }
27
30
  }, [defaultValue]);
28
31
  const dispatch = useAppDispatch();
29
- const widthWorkspace = ((_a = document === null || document === void 0 ? void 0 : document.getElementById("workspace")) === null || _a === void 0 ? void 0 : _a.clientWidth) || 0;
30
- const heightWorkspace = ((_b = document === null || document === void 0 ? void 0 : document.getElementById("workspace")) === null || _b === void 0 ? void 0 : _b.clientHeight) || 0;
32
+ const widthWorkspace = ((_b = document === null || document === void 0 ? void 0 : document.getElementById("workspace")) === null || _b === void 0 ? void 0 : _b.clientWidth) || 0;
33
+ const heightWorkspace = ((_c = document === null || document === void 0 ? void 0 : document.getElementById("workspace")) === null || _c === void 0 ? void 0 : _c.clientHeight) || 0;
31
34
  const defaultFormatValue = (width, height, src, id) => ({
32
35
  id: id || new Date().getTime(),
33
- x: 0,
34
- y: 0,
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),
35
38
  width: width < 1 ? 100 : width,
36
39
  height: height < 1 ? 100 : height,
37
40
  rotation: 0,
@@ -44,7 +47,7 @@ const UploadTool = ({ name, type, action, responseMapping, defaultValue, }) => {
44
47
  maxCount: 1,
45
48
  showUploadList: false,
46
49
  onChange: (info) => __awaiter(void 0, void 0, void 0, function* () {
47
- console.log({ info });
50
+ setLoading(true);
48
51
  if (info.file) {
49
52
  const file = info.file;
50
53
  const img = new window.Image();
@@ -52,7 +55,30 @@ const UploadTool = ({ name, type, action, responseMapping, defaultValue, }) => {
52
55
  try {
53
56
  // ⬇️ IF ada custom action (upload ke server)
54
57
  if (action) {
55
- yield action(file, type, defaultValue);
58
+ const src = yield action(file);
59
+ if (isEdit) {
60
+ dispatch({
61
+ type: "board/updateComponent",
62
+ payload: Object.assign({}, defaultFormatValue(widthWorkspace, heightWorkspace, src, Number(defaultValue.id))),
63
+ });
64
+ dispatch({
65
+ type: "panel/setSelectedComponent",
66
+ payload: Object.assign({}, defaultFormatValue(widthWorkspace, heightWorkspace, src, Number(defaultValue.id))),
67
+ });
68
+ setDefaultSrc(src);
69
+ dispatch({ type: "board/setFlagChange", payload: true });
70
+ dispatch({ type: "board/setUpdateBy", payload: "global" });
71
+ }
72
+ else {
73
+ dispatch({
74
+ type: "board/addComponent",
75
+ payload: Object.assign({}, defaultFormatValue(widthWorkspace, heightWorkspace, src)),
76
+ });
77
+ dispatch({
78
+ type: "panel/setSelectedComponent",
79
+ payload: Object.assign({}, defaultFormatValue(widthWorkspace, heightWorkspace, src)),
80
+ });
81
+ }
56
82
  }
57
83
  // ⬇️ IF local upload
58
84
  else {
@@ -64,14 +90,12 @@ const UploadTool = ({ name, type, action, responseMapping, defaultValue, }) => {
64
90
  const height = img.height * scale;
65
91
  if (isEdit) {
66
92
  dispatch({
67
- type: type === "component"
68
- ? "board/updateComponent"
69
- : "board/updateExtraComponent",
93
+ type: "board/updateComponent",
70
94
  payload: Object.assign({}, defaultFormatValue(width, height, img.src, Number(defaultValue.id))),
71
95
  });
72
96
  dispatch({
73
97
  type: "panel/setSelectedComponent",
74
- payload: Object.assign({}, defaultFormatValue(width, height, srcFromResponse, Number(defaultValue.id))),
98
+ payload: Object.assign({}, defaultFormatValue(width, height, srcFromResponse || img.src, Number(defaultValue.id))),
75
99
  });
76
100
  setDefaultSrc(img.src);
77
101
  dispatch({ type: "board/setFlagChange", payload: true });
@@ -85,6 +109,7 @@ const UploadTool = ({ name, type, action, responseMapping, defaultValue, }) => {
85
109
  payload: Object.assign({}, defaultFormatValue(width, height, img.src)),
86
110
  });
87
111
  }
112
+ setDefaultSrc(img.src);
88
113
  dispatch({ type: "board/setFlagChange", payload: true });
89
114
  dispatch({ type: "board/setUpdateBy", payload: "global" });
90
115
  // message.success(`${info.file.name} uploaded successfully.`);
@@ -111,16 +136,20 @@ const UploadTool = ({ name, type, action, responseMapping, defaultValue, }) => {
111
136
  Edit
112
137
  </Button>
113
138
  </>) : (<Dragger beforeUpload={() => false} {...propsUpload}>
114
- <p className="ant-upload-drag-icon">
115
- <InboxOutlined />
116
- </p>
117
- <p className="ant-upload-text">
118
- Click or drag file to this area to upload
119
- </p>
120
- <p className="ant-upload-hint">
121
- Support for a single or bulk upload. Strictly prohibited from
122
- uploading company data or other banned files.
123
- </p>
139
+ {loading ? (<div className="w-full flex flex-col items-center gap-2 max-h-[200px]">
140
+ <LoadingOutlined />
141
+ </div>) : (<>
142
+ <p className="ant-upload-drag-icon">
143
+ <InboxOutlined />
144
+ </p>
145
+ <p className="ant-upload-text">
146
+ Click or drag file to this area to upload
147
+ </p>
148
+ <p className="ant-upload-hint">
149
+ Support for a single or bulk upload. Strictly prohibited from
150
+ uploading company data or other banned files.
151
+ </p>
152
+ </>)}
124
153
  </Dragger>)}
125
154
 
126
155
  <SectionShape allowChangeShape={type === "component"}/>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seat-editor",
3
- "version": "3.2.4",
3
+ "version": "3.2.6",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",