seat-editor 3.5.16 → 3.5.17
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.
|
@@ -92,7 +92,8 @@ export default function NewBoard() {
|
|
|
92
92
|
if (setState === null || setState === void 0 ? void 0 : setState.extraComponents) {
|
|
93
93
|
setExtraComponents((_c = setState.extraComponents) !== null && _c !== void 0 ? _c : []);
|
|
94
94
|
}
|
|
95
|
-
}, extraComponentProps: extraComponents,
|
|
95
|
+
}, extraComponentProps: extraComponents,
|
|
96
|
+
// defaultBackground={backgroundColor}
|
|
96
97
|
// dragOnly={true}
|
|
97
98
|
statusKey: "status",
|
|
98
99
|
// action={async (action: any) => {
|
|
@@ -100,7 +100,8 @@ export default function NewBoard() {
|
|
|
100
100
|
if (setState === null || setState === void 0 ? void 0 : setState.extraComponents) {
|
|
101
101
|
setExtraComponents((_c = setState.extraComponents) !== null && _c !== void 0 ? _c : []);
|
|
102
102
|
}
|
|
103
|
-
}} extraComponentProps={extraComponents}
|
|
103
|
+
}} extraComponentProps={extraComponents}
|
|
104
|
+
// defaultBackground={backgroundColor}
|
|
104
105
|
// dragOnly={true}
|
|
105
106
|
statusKey="status"
|
|
106
107
|
// action={async (action: any) => {
|
|
@@ -2,6 +2,12 @@ export interface Component {
|
|
|
2
2
|
id: string;
|
|
3
3
|
[key: string]: any;
|
|
4
4
|
}
|
|
5
|
+
export interface HistoryEntry {
|
|
6
|
+
components: Component[];
|
|
7
|
+
extraComponents: Component[];
|
|
8
|
+
boundingBox: any;
|
|
9
|
+
backgroundColor: string;
|
|
10
|
+
}
|
|
5
11
|
export interface InitialState {
|
|
6
12
|
components: Component[];
|
|
7
13
|
backgroundColor: string;
|
|
@@ -9,7 +15,7 @@ export interface InitialState {
|
|
|
9
15
|
extraComponents: Component[];
|
|
10
16
|
boundingBox: any;
|
|
11
17
|
flagChange: boolean;
|
|
12
|
-
historyChanges:
|
|
18
|
+
historyChanges: HistoryEntry[];
|
|
13
19
|
pointer: number;
|
|
14
20
|
updateBy: "global" | "local";
|
|
15
21
|
isShowTagType: "default" | "type-1" | "type-2";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createSlice, current } from "@reduxjs/toolkit";
|
|
2
2
|
import { forEach } from "lodash";
|
|
3
|
+
const MAX_HISTORY_CHANGES = 20;
|
|
3
4
|
const initialState = {
|
|
4
5
|
components: [],
|
|
5
6
|
backgroundColor: "#FFFFFF",
|
|
@@ -12,7 +13,26 @@ const initialState = {
|
|
|
12
13
|
updateBy: "global",
|
|
13
14
|
isShowTagType: "default",
|
|
14
15
|
};
|
|
15
|
-
|
|
16
|
+
// ─── Helper ──────────────────────────────────────────────────────────────────
|
|
17
|
+
const pushHistory = (state) => {
|
|
18
|
+
if (state.pointer < state.historyChanges.length - 1) {
|
|
19
|
+
state.historyChanges = state.historyChanges.slice(0, state.pointer + 1);
|
|
20
|
+
}
|
|
21
|
+
state.historyChanges.push({
|
|
22
|
+
components: [...state.components],
|
|
23
|
+
extraComponents: [...state.extraComponents],
|
|
24
|
+
boundingBox: state.boundingBox,
|
|
25
|
+
backgroundColor: state.backgroundColor,
|
|
26
|
+
});
|
|
27
|
+
if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
|
|
28
|
+
state.historyChanges.shift();
|
|
29
|
+
state.pointer = MAX_HISTORY_CHANGES - 1;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
state.pointer = state.historyChanges.length - 1;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
// ─── Slice ───────────────────────────────────────────────────────────────────
|
|
16
36
|
const boardSlice = createSlice({
|
|
17
37
|
name: "board",
|
|
18
38
|
initialState,
|
|
@@ -23,65 +43,34 @@ const boardSlice = createSlice({
|
|
|
23
43
|
setUpdateBy: (state, action) => {
|
|
24
44
|
state.updateBy = action.payload;
|
|
25
45
|
},
|
|
46
|
+
setFlagChange: (state, action) => {
|
|
47
|
+
state.flagChange = action.payload;
|
|
48
|
+
},
|
|
26
49
|
addComponent: (state, action) => {
|
|
27
|
-
const currentPointer = state.pointer;
|
|
28
|
-
const totalHistory = state.historyChanges.length;
|
|
29
|
-
if (currentPointer < totalHistory) {
|
|
30
|
-
state.historyChanges = state.historyChanges.slice(0, currentPointer + 1);
|
|
31
|
-
}
|
|
32
|
-
if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
|
|
33
|
-
state.historyChanges.shift();
|
|
34
|
-
}
|
|
35
|
-
state.pointer += 1;
|
|
36
50
|
state.components.push(action.payload);
|
|
37
|
-
|
|
38
|
-
const extraComponent = state.extraComponents;
|
|
39
|
-
const boundingBox = state.boundingBox;
|
|
40
|
-
const backgroundColor = state.backgroundColor;
|
|
41
|
-
state.historyChanges.push({
|
|
42
|
-
component,
|
|
43
|
-
extraComponent,
|
|
44
|
-
boundingBox,
|
|
45
|
-
backgroundColor,
|
|
46
|
-
});
|
|
51
|
+
pushHistory(state);
|
|
47
52
|
},
|
|
48
53
|
removeComponent: (state, action) => {
|
|
49
|
-
state.components = state.components.filter((
|
|
54
|
+
state.components = state.components.filter((c) => c.id !== action.payload.id);
|
|
50
55
|
},
|
|
51
56
|
removeExtraComponent: (state, action) => {
|
|
52
|
-
state.extraComponents = state.extraComponents.filter((
|
|
57
|
+
state.extraComponents = state.extraComponents.filter((c) => c.id !== action.payload.id);
|
|
53
58
|
},
|
|
54
59
|
updateComponent: (state, action) => {
|
|
55
|
-
const index = state.components.findIndex((
|
|
56
|
-
const indexExtra = state.extraComponents.findIndex((
|
|
57
|
-
// state.historyChanges.push({
|
|
58
|
-
// components: [...state.components],
|
|
59
|
-
// extraComponents: [...state.extraComponents],
|
|
60
|
-
// });
|
|
60
|
+
const index = state.components.findIndex((c) => String(c.id) === String(action.payload.id));
|
|
61
|
+
const indexExtra = state.extraComponents.findIndex((e) => String(e.id) === String(action.payload.id));
|
|
61
62
|
if (index !== -1) {
|
|
62
|
-
// Update component biasa
|
|
63
63
|
state.components[index] = Object.assign(Object.assign({}, state.components[index]), action.payload);
|
|
64
64
|
}
|
|
65
65
|
else if (indexExtra !== -1) {
|
|
66
|
-
// Update extraComponent
|
|
67
66
|
state.extraComponents[indexExtra] = Object.assign(Object.assign({}, state.extraComponents[indexExtra]), action.payload);
|
|
68
67
|
}
|
|
69
|
-
state
|
|
70
|
-
components: [...state.components],
|
|
71
|
-
extraComponents: [...state.extraComponents],
|
|
72
|
-
boundingBox: state.boundingBox,
|
|
73
|
-
backgroundColor: state.backgroundColor,
|
|
74
|
-
});
|
|
75
|
-
if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
|
|
76
|
-
state.historyChanges.shift();
|
|
77
|
-
}
|
|
78
|
-
state.pointer += 1;
|
|
68
|
+
pushHistory(state);
|
|
79
69
|
},
|
|
80
70
|
updateComponentsBulk: (state, action) => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
const indexExtra = state.extraComponents.findIndex((extra) => extra.id == update.id);
|
|
71
|
+
action.payload.forEach((update) => {
|
|
72
|
+
const index = state.components.findIndex((c) => c.id == update.id);
|
|
73
|
+
const indexExtra = state.extraComponents.findIndex((e) => e.id == update.id);
|
|
85
74
|
if (index !== -1) {
|
|
86
75
|
state.components[index] = Object.assign(Object.assign({}, state.components[index]), update);
|
|
87
76
|
}
|
|
@@ -89,185 +78,75 @@ const boardSlice = createSlice({
|
|
|
89
78
|
state.extraComponents[indexExtra] = Object.assign(Object.assign({}, state.extraComponents[indexExtra]), update);
|
|
90
79
|
}
|
|
91
80
|
});
|
|
92
|
-
|
|
93
|
-
state.historyChanges = state.historyChanges.slice(0, state.pointer + 1);
|
|
94
|
-
}
|
|
95
|
-
state.historyChanges.push({
|
|
96
|
-
components: [...state.components],
|
|
97
|
-
extraComponents: [...state.extraComponents],
|
|
98
|
-
boundingBox: state.boundingBox,
|
|
99
|
-
backgroundColor: state.backgroundColor,
|
|
100
|
-
});
|
|
101
|
-
if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
|
|
102
|
-
state.historyChanges.shift();
|
|
103
|
-
}
|
|
104
|
-
state.pointer += 1;
|
|
81
|
+
pushHistory(state);
|
|
105
82
|
},
|
|
106
83
|
updateSelectedGroupComponent: (state, action) => {
|
|
107
|
-
|
|
108
|
-
forEach(allComponents, (component) => {
|
|
84
|
+
forEach(action.payload, (component) => {
|
|
109
85
|
const index = state.components.findIndex((c) => c.id == component.id);
|
|
110
86
|
if (index !== -1) {
|
|
111
87
|
state.components[index] = Object.assign(Object.assign({}, state.components[index]), component);
|
|
112
88
|
}
|
|
113
89
|
});
|
|
114
|
-
state
|
|
115
|
-
components: [...state.components],
|
|
116
|
-
extraComponents: [...state.extraComponents],
|
|
117
|
-
boundingBox: state.boundingBox,
|
|
118
|
-
backgroundColor: state.backgroundColor,
|
|
119
|
-
});
|
|
120
|
-
if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
|
|
121
|
-
state.historyChanges.shift();
|
|
122
|
-
}
|
|
123
|
-
state.pointer += 1;
|
|
90
|
+
pushHistory(state);
|
|
124
91
|
},
|
|
125
92
|
setBackgroundColor: (state, action) => {
|
|
126
|
-
const currentPointer = state.pointer;
|
|
127
|
-
const totalHistory = state.historyChanges.length;
|
|
128
|
-
if (currentPointer < totalHistory) {
|
|
129
|
-
state.historyChanges = state.historyChanges.slice(0, currentPointer + 1);
|
|
130
|
-
}
|
|
131
|
-
if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
|
|
132
|
-
state.historyChanges.shift();
|
|
133
|
-
}
|
|
134
|
-
state.pointer += 1;
|
|
135
93
|
state.backgroundColor = action.payload;
|
|
136
|
-
state
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
});
|
|
94
|
+
pushHistory(state);
|
|
95
|
+
},
|
|
96
|
+
setBoundingBox: (state, action) => {
|
|
97
|
+
state.boundingBox = action.payload;
|
|
98
|
+
pushHistory(state);
|
|
142
99
|
},
|
|
143
100
|
setNewComponents: (state, action) => {
|
|
144
|
-
const currentPointer = state.pointer;
|
|
145
|
-
const totalHistory = state.historyChanges.length;
|
|
146
|
-
if (currentPointer < totalHistory) {
|
|
147
|
-
state.historyChanges = state.historyChanges.slice(0, currentPointer + 1);
|
|
148
|
-
}
|
|
149
101
|
state.components = action.payload;
|
|
150
|
-
state
|
|
151
|
-
components: [...state.components],
|
|
152
|
-
extraComponents: [...state.extraComponents],
|
|
153
|
-
boundingBox: state.boundingBox,
|
|
154
|
-
backgroundColor: state.backgroundColor,
|
|
155
|
-
});
|
|
156
|
-
if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
|
|
157
|
-
state.historyChanges.shift();
|
|
158
|
-
}
|
|
159
|
-
state.pointer += 1;
|
|
102
|
+
pushHistory(state);
|
|
160
103
|
},
|
|
161
104
|
setNewExtraComponents: (state, action) => {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
|
|
168
|
-
state.historyChanges.shift();
|
|
169
|
-
}
|
|
170
|
-
state.pointer += 1;
|
|
171
|
-
state.extraComponents = action.payload.filter((item) => item.shape) || [];
|
|
172
|
-
state.historyChanges.push({
|
|
173
|
-
components: [...state.components],
|
|
174
|
-
extraComponents: [...state.extraComponents],
|
|
175
|
-
boundingBox: state.boundingBox,
|
|
176
|
-
backgroundColor: state.backgroundColor,
|
|
177
|
-
});
|
|
105
|
+
var _a;
|
|
106
|
+
state.extraComponents =
|
|
107
|
+
(_a = action.payload.filter((item) => item.shape)) !== null && _a !== void 0 ? _a : [];
|
|
108
|
+
pushHistory(state);
|
|
178
109
|
},
|
|
179
110
|
setExtraComponent: (state, action) => {
|
|
180
|
-
const currentPointer = state.pointer;
|
|
181
|
-
const totalHistory = state.historyChanges.length;
|
|
182
|
-
if (currentPointer < totalHistory) {
|
|
183
|
-
state.historyChanges = state.historyChanges.slice(0, currentPointer + 1);
|
|
184
|
-
}
|
|
185
|
-
if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
|
|
186
|
-
state.historyChanges.shift();
|
|
187
|
-
}
|
|
188
|
-
state.pointer += 1;
|
|
189
111
|
state.extraComponents.push(action.payload);
|
|
190
|
-
|
|
191
|
-
const extraComponent = state.extraComponents;
|
|
192
|
-
state.historyChanges.push({
|
|
193
|
-
components: [...component],
|
|
194
|
-
extraComponents: [...extraComponent],
|
|
195
|
-
boundingBox: state.boundingBox,
|
|
196
|
-
backgroundColor: state.backgroundColor,
|
|
197
|
-
});
|
|
198
|
-
},
|
|
199
|
-
setFlagChange: (state, action) => {
|
|
200
|
-
state.flagChange = action.payload;
|
|
112
|
+
pushHistory(state);
|
|
201
113
|
},
|
|
114
|
+
// ─── Undo / Redo ─────────────────────────────────────────────────────────
|
|
202
115
|
undoHistory: (state) => {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
const prev = state.historyChanges[state.pointer];
|
|
213
|
-
state.components = prev === null || prev === void 0 ? void 0 : prev.components;
|
|
214
|
-
state.extraComponents = prev === null || prev === void 0 ? void 0 : prev.extraComponents;
|
|
215
|
-
state.boundingBox = prev === null || prev === void 0 ? void 0 : prev.boundingBox;
|
|
216
|
-
state.backgroundColor = prev === null || prev === void 0 ? void 0 : prev.backgroundColor;
|
|
217
|
-
}
|
|
218
|
-
else if (state.pointer === 1) {
|
|
219
|
-
state.components = (_b = (_a = state.historyChanges) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.components;
|
|
220
|
-
state.extraComponents = (_d = (_c = state.historyChanges) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.extraComponents;
|
|
221
|
-
state.boundingBox = (_f = (_e = state.historyChanges) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.boundingBox;
|
|
222
|
-
state.backgroundColor = (_h = (_g = state.historyChanges) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.backgroundColor;
|
|
223
|
-
state.pointer = 0;
|
|
224
|
-
}
|
|
116
|
+
if (state.pointer <= 0)
|
|
117
|
+
return;
|
|
118
|
+
state.pointer -= 1;
|
|
119
|
+
const prev = state.historyChanges[state.pointer];
|
|
120
|
+
state.components = prev.components;
|
|
121
|
+
state.extraComponents = prev.extraComponents;
|
|
122
|
+
state.boundingBox = prev.boundingBox;
|
|
123
|
+
state.backgroundColor = prev.backgroundColor;
|
|
225
124
|
state.updateBy = "global";
|
|
226
125
|
},
|
|
227
126
|
redoHistory: (state) => {
|
|
228
|
-
if (state.pointer
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
127
|
+
if (state.pointer >= state.historyChanges.length - 1)
|
|
128
|
+
return;
|
|
129
|
+
state.pointer += 1;
|
|
130
|
+
const next = state.historyChanges[state.pointer];
|
|
131
|
+
state.components = current(next.components);
|
|
132
|
+
state.extraComponents = current(next.extraComponents);
|
|
133
|
+
state.boundingBox = next.boundingBox;
|
|
134
|
+
state.backgroundColor = next.backgroundColor;
|
|
135
|
+
state.updateBy = "global";
|
|
236
136
|
},
|
|
237
137
|
setInitialValue: (state, action) => {
|
|
138
|
+
var _a;
|
|
238
139
|
const { components, extraComponents, backgroundColor, boundingBox } = action.payload;
|
|
239
140
|
state.components = components;
|
|
240
|
-
state.extraComponents =
|
|
241
|
-
|
|
141
|
+
state.extraComponents =
|
|
142
|
+
(_a = extraComponents === null || extraComponents === void 0 ? void 0 : extraComponents.filter((item) => item.shape)) !== null && _a !== void 0 ? _a : [];
|
|
242
143
|
state.backgroundColor = backgroundColor;
|
|
243
144
|
state.boundingBox = boundingBox;
|
|
145
|
+
state.pointer = 0;
|
|
244
146
|
state.historyChanges = [
|
|
245
|
-
{
|
|
246
|
-
components,
|
|
247
|
-
extraComponents,
|
|
248
|
-
boundingBox,
|
|
249
|
-
backgroundColor,
|
|
250
|
-
},
|
|
147
|
+
{ components, extraComponents, boundingBox, backgroundColor },
|
|
251
148
|
];
|
|
252
149
|
},
|
|
253
|
-
setBoundingBox: (state, action) => {
|
|
254
|
-
const currentPointer = state.pointer;
|
|
255
|
-
const totalHistory = state.historyChanges.length;
|
|
256
|
-
if (currentPointer < totalHistory) {
|
|
257
|
-
state.historyChanges = state.historyChanges.slice(0, currentPointer + 1);
|
|
258
|
-
}
|
|
259
|
-
if (state.historyChanges.length > MAX_HISTORY_CHANGES) {
|
|
260
|
-
state.historyChanges.shift();
|
|
261
|
-
}
|
|
262
|
-
state.pointer += 1;
|
|
263
|
-
state.boundingBox = action.payload;
|
|
264
|
-
state.historyChanges.push({
|
|
265
|
-
components: [...state.components],
|
|
266
|
-
extraComponents: [...state.extraComponents],
|
|
267
|
-
boundingBox: state.boundingBox,
|
|
268
|
-
backgroundColor: state.backgroundColor,
|
|
269
|
-
});
|
|
270
|
-
},
|
|
271
150
|
},
|
|
272
151
|
});
|
|
273
152
|
export const { addComponent, removeComponent, updateComponent, setBackgroundColor, removeExtraComponent, } = boardSlice.actions;
|