Skip to content

Commit 916a232

Browse files
committed
fix: fix parameters undo logic
1 parent 055d380 commit 916a232

File tree

2 files changed

+58
-31
lines changed

2 files changed

+58
-31
lines changed

src/js/app.js

+27
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
MESSAGE_COPY_ERROR
4040
} from "./constants/messages";
4141
import { saveWorkflow } from "./workflows/saveWorkflow";
42+
import {setInputValueInElement, setSelectValueInElement} from "./layout/inputs"
4243

4344
export let app;
4445

@@ -92,6 +93,11 @@ export let app;
9293
return { boxId, size };
9394
});
9495
},
96+
defaultParamsElements() {
97+
return this.elements.map(({ boxId, defaultParams }) => {
98+
return { boxId, defaultParams };
99+
});
100+
},
95101
dataElements() {
96102
return this.dataTest;
97103
},
@@ -229,6 +235,27 @@ export let app;
229235
}
230236
}
231237
},
238+
239+
/**
240+
* watch parameters of elements
241+
* on direct changes, nothing changes (mechanic operation)
242+
* only apply changes on undo-redo
243+
*/
244+
defaultParamsElements: {
245+
deep: true,
246+
handler(newValue, oldValue) {
247+
const difference = findDifferenceBy(
248+
newValue,
249+
oldValue,
250+
"defaultParams"
251+
);
252+
for (const box of difference) {
253+
setSelectValueInElement(box);
254+
setInputValueInElement(box);
255+
}
256+
}
257+
},
258+
232259
/**
233260
* watch moved elements
234261
* on direct move operation, nothing changes (mechanic operation)

src/js/layout/inputs.js

+31-31
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,21 @@ export const closeSelects = () => {
4545
* @param {string} boxId
4646
* @param {object} defaultParams
4747
*/
48-
// export const setSelectValueInElement = ({ boxId, defaultParams }) => {
49-
// for (const [key, { value }] of Object.entries(
50-
// defaultParams[Types.SELECT.type]
51-
// )) {
52-
// // we need to precise paper root because of the minimap duplicate elements
53-
// const el = $(
54-
// `${INTERFACE_ROOT} foreignObject[boxId="${boxId}"] .select[name="${key}"] ${Types.SELECT.tag}`
55-
// );
56-
// if (el.find(":selected").val() != value) {
57-
// $(el)
58-
// .val(value)
59-
// .trigger("change.select2");
60-
// }
61-
// }
62-
// };
48+
export const setSelectValueInElement = ({ boxId, defaultParams }) => {
49+
for (const [key, { value }] of Object.entries(
50+
defaultParams[Types.SELECT.type]
51+
)) {
52+
// we need to precise paper root because of the minimap duplicate elements
53+
const el = $(
54+
`${INTERFACE_ROOT} foreignObject[boxId="${boxId}"] .select[name="${key}"] ${Types.SELECT.tag}`
55+
);
56+
if (el.find(":selected").val() != value) {
57+
$(el)
58+
.val(value)
59+
.trigger("change.select2");
60+
}
61+
}
62+
};
6363

6464
/**
6565
* set input value in DOM
@@ -68,22 +68,22 @@ export const closeSelects = () => {
6868
* @param {string} type
6969
* @param {object} defaultParams
7070
*/
71-
// export const setInputValueInElement = ({
72-
// boxId,
73-
// type: boxName,
74-
// defaultParams
75-
// }) => {
76-
// for (const [key, { value }] of Object.entries(
77-
// defaultParams[Types.NUMBER.type]
78-
// )) {
79-
// // we need to precise paper root because of the minimap duplicate elements
80-
// const el = $(
81-
// `${INTERFACE_ROOT} foreignObject[boxId="${boxId}"] ${Types.NUMBER.tag}[name="${key}"]`
82-
// );
83-
// el.val(value);
84-
// checkInputValue(el, { boxId, boxName });
85-
// }
86-
// };
71+
export const setInputValueInElement = ({
72+
boxId,
73+
type: boxName,
74+
defaultParams
75+
}) => {
76+
for (const [key, { value }] of Object.entries(
77+
defaultParams[Types.NUMBER.type]
78+
)) {
79+
// we need to precise paper root because of the minimap duplicate elements
80+
const el = $(
81+
`${INTERFACE_ROOT} foreignObject[boxId="${boxId}"] ${Types.NUMBER.tag}[name="${key}"]`
82+
);
83+
el.val(value);
84+
checkInputValue(el, { boxId, boxName });
85+
}
86+
};
8787

8888
/**
8989
* reset value of input or select element

0 commit comments

Comments
 (0)