seat-editor 3.2.7 → 3.2.8
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.
|
@@ -11,6 +11,16 @@ export default function NewBoard() {
|
|
|
11
11
|
setInitialValue(data5);
|
|
12
12
|
setExtraComponents(dummyExtra5);
|
|
13
13
|
}, []);
|
|
14
|
+
const handleUploadImage = (file) => {
|
|
15
|
+
const test = new Promise((resolve, reject) => {
|
|
16
|
+
const reader = new FileReader();
|
|
17
|
+
reader.onload = () => resolve(reader.result);
|
|
18
|
+
reader.onerror = reject;
|
|
19
|
+
reader.readAsDataURL(file);
|
|
20
|
+
});
|
|
21
|
+
console.log({ test });
|
|
22
|
+
return test;
|
|
23
|
+
};
|
|
14
24
|
return (<>
|
|
15
25
|
<div className="w-full h-screen flex flex-col relative justify-center">
|
|
16
26
|
<div className="w-full h-[1000px] bg-white border-r border-gray-200">
|
|
@@ -25,12 +35,7 @@ export default function NewBoard() {
|
|
|
25
35
|
<SeatEditor componentProps={initialValue} viewOnly={viewOnly} dragOnly={true} deleteAutorized={{
|
|
26
36
|
component: true,
|
|
27
37
|
extraComponent: true,
|
|
28
|
-
}}
|
|
29
|
-
// action={async (action: any) => {
|
|
30
|
-
// console.log({ action });
|
|
31
|
-
// return null
|
|
32
|
-
// }}
|
|
33
|
-
mappingKey="properties" onCurrentStateChange={(setState) => {
|
|
38
|
+
}} action={handleUploadImage} mappingKey="properties" onCurrentStateChange={(setState) => {
|
|
34
39
|
var _a, _b, _c, _d;
|
|
35
40
|
if (((_a = setState === null || setState === void 0 ? void 0 : setState.components) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
36
41
|
setInitialValue((_b = setState === null || setState === void 0 ? void 0 : setState.components) !== null && _b !== void 0 ? _b : []);
|
|
@@ -23,17 +23,17 @@ const boardSlice = createSlice({
|
|
|
23
23
|
if (currentPointer < totalHistory) {
|
|
24
24
|
state.historyChanges = state.historyChanges.slice(0, currentPointer + 1);
|
|
25
25
|
}
|
|
26
|
-
const component = state.components;
|
|
27
|
-
const extraComponent = state.extraComponents;
|
|
28
|
-
state.historyChanges.push({
|
|
29
|
-
component,
|
|
30
|
-
extraComponent
|
|
31
|
-
});
|
|
32
26
|
if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
|
|
33
27
|
state.historyChanges.shift();
|
|
34
28
|
}
|
|
35
29
|
state.pointer += 1;
|
|
36
30
|
state.components.push(action.payload);
|
|
31
|
+
const component = state.components;
|
|
32
|
+
const extraComponent = state.extraComponents;
|
|
33
|
+
state.historyChanges.push({
|
|
34
|
+
component,
|
|
35
|
+
extraComponent,
|
|
36
|
+
});
|
|
37
37
|
},
|
|
38
38
|
removeComponent: (state, action) => {
|
|
39
39
|
state.components = state.components.filter((component) => (component === null || component === void 0 ? void 0 : component.id) !== action.payload.id);
|
|
@@ -44,7 +44,10 @@ const boardSlice = createSlice({
|
|
|
44
44
|
updateComponent: (state, action) => {
|
|
45
45
|
const index = state.components.findIndex((component) => component.id === action.payload.id);
|
|
46
46
|
const indexExtra = state.extraComponents.findIndex((extraComponent) => extraComponent.id === action.payload.id);
|
|
47
|
-
state.historyChanges.push(
|
|
47
|
+
// state.historyChanges.push({
|
|
48
|
+
// components: [...state.components],
|
|
49
|
+
// extraComponents: [...state.extraComponents],
|
|
50
|
+
// });
|
|
48
51
|
if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
|
|
49
52
|
state.historyChanges.shift();
|
|
50
53
|
}
|
|
@@ -57,18 +60,13 @@ const boardSlice = createSlice({
|
|
|
57
60
|
// Update extraComponent
|
|
58
61
|
state.extraComponents[indexExtra] = Object.assign(Object.assign({}, state.extraComponents[indexExtra]), action.payload);
|
|
59
62
|
}
|
|
63
|
+
// state.historyChanges.push({
|
|
64
|
+
// components: [...state.components],
|
|
65
|
+
// extraComponents: [...state.extraComponents],
|
|
66
|
+
// });
|
|
60
67
|
},
|
|
61
68
|
updateComponentsBulk: (state, action) => {
|
|
62
69
|
const updates = action.payload;
|
|
63
|
-
// Simpan snapshot untuk undo (deep clone lebih aman)
|
|
64
|
-
state.historyChanges.push({
|
|
65
|
-
components: [...state.components],
|
|
66
|
-
extraComponents: [...state.extraComponents],
|
|
67
|
-
});
|
|
68
|
-
if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
|
|
69
|
-
state.historyChanges.shift();
|
|
70
|
-
}
|
|
71
|
-
state.pointer += 1;
|
|
72
70
|
updates.forEach((update) => {
|
|
73
71
|
const index = state.components.findIndex((component) => component.id === update.id);
|
|
74
72
|
const indexExtra = state.extraComponents.findIndex((extra) => extra.id === update.id);
|
|
@@ -79,6 +77,17 @@ const boardSlice = createSlice({
|
|
|
79
77
|
state.extraComponents[indexExtra] = Object.assign(Object.assign({}, state.extraComponents[indexExtra]), update);
|
|
80
78
|
}
|
|
81
79
|
});
|
|
80
|
+
if (state.pointer < state.historyChanges.length - 1) {
|
|
81
|
+
state.historyChanges = state.historyChanges.slice(0, state.pointer + 1);
|
|
82
|
+
}
|
|
83
|
+
state.historyChanges.push({
|
|
84
|
+
components: [...state.components],
|
|
85
|
+
extraComponents: [...state.extraComponents],
|
|
86
|
+
});
|
|
87
|
+
if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
|
|
88
|
+
state.historyChanges.shift();
|
|
89
|
+
}
|
|
90
|
+
state.pointer += 1;
|
|
82
91
|
},
|
|
83
92
|
// updateAllComponents: (state, action) => {
|
|
84
93
|
// const allComponents = action.payload;
|
|
@@ -140,17 +149,17 @@ const boardSlice = createSlice({
|
|
|
140
149
|
if (currentPointer < totalHistory) {
|
|
141
150
|
state.historyChanges = state.historyChanges.slice(0, currentPointer + 1);
|
|
142
151
|
}
|
|
152
|
+
if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
|
|
153
|
+
state.historyChanges.shift();
|
|
154
|
+
}
|
|
155
|
+
state.pointer += 1;
|
|
156
|
+
state.extraComponents.push(action.payload);
|
|
143
157
|
const component = state.components;
|
|
144
158
|
const extraComponent = state.extraComponents;
|
|
145
159
|
state.historyChanges.push({
|
|
146
160
|
components: [...component],
|
|
147
161
|
extraComponents: [...extraComponent],
|
|
148
162
|
});
|
|
149
|
-
if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
|
|
150
|
-
state.historyChanges.shift();
|
|
151
|
-
}
|
|
152
|
-
state.pointer += 1;
|
|
153
|
-
state.extraComponents.push(action.payload);
|
|
154
163
|
},
|
|
155
164
|
setFlagChange: (state, action) => {
|
|
156
165
|
state.flagChange = action.payload;
|
|
@@ -166,7 +175,6 @@ const boardSlice = createSlice({
|
|
|
166
175
|
state.pointer -= 1;
|
|
167
176
|
}
|
|
168
177
|
const prev = state.historyChanges[state.pointer];
|
|
169
|
-
console.log({ prev });
|
|
170
178
|
state.components = current(prev === null || prev === void 0 ? void 0 : prev.components);
|
|
171
179
|
state.extraComponents = current(prev === null || prev === void 0 ? void 0 : prev.extraComponents);
|
|
172
180
|
}
|
|
@@ -192,12 +200,14 @@ const boardSlice = createSlice({
|
|
|
192
200
|
state.extraComponents = extraComponents;
|
|
193
201
|
state.pointer = 0;
|
|
194
202
|
state.backgroundColor = backgroundColor;
|
|
195
|
-
state.historyChanges = [
|
|
203
|
+
state.historyChanges = [
|
|
204
|
+
{
|
|
196
205
|
components,
|
|
197
|
-
extraComponents
|
|
198
|
-
}
|
|
199
|
-
|
|
206
|
+
extraComponents,
|
|
207
|
+
},
|
|
208
|
+
];
|
|
209
|
+
},
|
|
200
210
|
},
|
|
201
211
|
});
|
|
202
|
-
export const { addComponent, removeComponent, updateComponent, setBackgroundColor, removeExtraComponent } = boardSlice.actions;
|
|
212
|
+
export const { addComponent, removeComponent, updateComponent, setBackgroundColor, removeExtraComponent, } = boardSlice.actions;
|
|
203
213
|
export default boardSlice.reducer;
|
|
@@ -35,8 +35,8 @@ const UploadTool = ({ name, type, action, defaultValue, transform }) => {
|
|
|
35
35
|
id: id || new Date().getTime(),
|
|
36
36
|
x: Math.abs(transformState === null || transformState === void 0 ? void 0 : transformState.positionX),
|
|
37
37
|
y: Math.abs(transformState === null || transformState === void 0 ? void 0 : transformState.positionY),
|
|
38
|
-
width: width < 1 ?
|
|
39
|
-
height: height < 1 ?
|
|
38
|
+
width: width < 1 ? 200 : width,
|
|
39
|
+
height: height < 1 ? 200 : height,
|
|
40
40
|
rotation: 0,
|
|
41
41
|
shape: name,
|
|
42
42
|
src,
|
|
@@ -59,24 +59,27 @@ const UploadTool = ({ name, type, action, defaultValue, transform }) => {
|
|
|
59
59
|
if (isEdit) {
|
|
60
60
|
dispatch({
|
|
61
61
|
type: "board/updateComponent",
|
|
62
|
-
payload: Object.assign({}, defaultFormatValue(
|
|
62
|
+
payload: Object.assign({}, defaultFormatValue(defaultValue.width, defaultValue.height, src, Number(defaultValue.id))),
|
|
63
63
|
});
|
|
64
64
|
dispatch({
|
|
65
65
|
type: "panel/setSelectedComponent",
|
|
66
|
-
payload: Object.assign({}, defaultFormatValue(
|
|
66
|
+
payload: Object.assign({}, defaultFormatValue(0, 0, src, Number(defaultValue.id))),
|
|
67
67
|
});
|
|
68
68
|
setDefaultSrc(src);
|
|
69
69
|
dispatch({ type: "board/setFlagChange", payload: true });
|
|
70
70
|
dispatch({ type: "board/setUpdateBy", payload: "global" });
|
|
71
71
|
}
|
|
72
72
|
else {
|
|
73
|
+
const defaultValue = Object.assign({}, defaultFormatValue(0, 0, src));
|
|
73
74
|
dispatch({
|
|
74
|
-
type: "
|
|
75
|
-
|
|
75
|
+
type: type === "component"
|
|
76
|
+
? "board/addComponent"
|
|
77
|
+
: "board/setExtraComponent",
|
|
78
|
+
payload: defaultValue,
|
|
76
79
|
});
|
|
77
80
|
dispatch({
|
|
78
81
|
type: "panel/setSelectedComponent",
|
|
79
|
-
payload:
|
|
82
|
+
payload: defaultValue,
|
|
80
83
|
});
|
|
81
84
|
}
|
|
82
85
|
}
|