@saltcorn/builder 0.7.3 → 0.7.4-beta.0
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.
package/package.json
CHANGED
|
@@ -58,7 +58,6 @@ import {
|
|
|
58
58
|
} from "./elements/utils";
|
|
59
59
|
import { InitNewElement, Library } from "./Library";
|
|
60
60
|
import { RenderNode } from "./RenderNode";
|
|
61
|
-
import { isEqual } from "lodash";
|
|
62
61
|
const { Provider } = optionsCtx;
|
|
63
62
|
|
|
64
63
|
/**
|
|
@@ -389,47 +388,11 @@ const Builder = ({ options, layout, mode }) => {
|
|
|
389
388
|
const [previews, setPreviews] = useState({});
|
|
390
389
|
const [uploadedFiles, setUploadedFiles] = useState([]);
|
|
391
390
|
const nodekeys = useRef([]);
|
|
392
|
-
const [saveTimeout, setSaveTimeout] = useState(false);
|
|
393
391
|
const [isSaving, setIsSaving] = useState(false);
|
|
394
|
-
const [savedData, setSavedData] = useState(false);
|
|
395
|
-
const doSave = (query) => {
|
|
396
|
-
if (!query.serialize) return;
|
|
397
392
|
|
|
398
|
-
const data = craftToSaltcorn(JSON.parse(query.serialize()));
|
|
399
|
-
const urlroot = options.page_id ? "pageedit" : "viewedit";
|
|
400
|
-
if (savedData === false) {
|
|
401
|
-
//do not save on first call
|
|
402
|
-
setSavedData(data.layout);
|
|
403
|
-
setIsSaving(false);
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
if (isEqual(savedData, data.layout)) return;
|
|
407
|
-
setSavedData(data.layout);
|
|
408
|
-
|
|
409
|
-
fetch(`/${urlroot}/savebuilder/${options.page_id || options.view_id}`, {
|
|
410
|
-
method: "POST", // or 'PUT'
|
|
411
|
-
headers: {
|
|
412
|
-
"Content-Type": "application/json",
|
|
413
|
-
"CSRF-Token": options.csrfToken,
|
|
414
|
-
},
|
|
415
|
-
body: JSON.stringify(data),
|
|
416
|
-
}).then(() => {
|
|
417
|
-
setIsSaving(false);
|
|
418
|
-
});
|
|
419
|
-
};
|
|
420
|
-
const nodesChange = (query) => {
|
|
421
|
-
if (saveTimeout) clearTimeout(saveTimeout);
|
|
422
|
-
setIsSaving(true);
|
|
423
|
-
setSaveTimeout(
|
|
424
|
-
setTimeout(() => {
|
|
425
|
-
doSave(query);
|
|
426
|
-
setSaveTimeout(false);
|
|
427
|
-
}, 500)
|
|
428
|
-
);
|
|
429
|
-
};
|
|
430
393
|
return (
|
|
431
394
|
<ErrorBoundary>
|
|
432
|
-
<Editor onRender={RenderNode}
|
|
395
|
+
<Editor onRender={RenderNode}>
|
|
433
396
|
<Provider value={options}>
|
|
434
397
|
<PreviewCtx.Provider
|
|
435
398
|
value={{ previews, setPreviews, uploadedFiles, setUploadedFiles }}
|
|
@@ -437,7 +400,10 @@ const Builder = ({ options, layout, mode }) => {
|
|
|
437
400
|
<div className="row" style={{ marginTop: "-5px" }}>
|
|
438
401
|
<div className="col-sm-auto left-builder-col">
|
|
439
402
|
<div className="componets-and-library-accordion toolbox-card">
|
|
440
|
-
<InitNewElement
|
|
403
|
+
<InitNewElement
|
|
404
|
+
nodekeys={nodekeys}
|
|
405
|
+
setIsSaving={setIsSaving}
|
|
406
|
+
/>
|
|
441
407
|
<Accordion>
|
|
442
408
|
<div className="card mt-1" accordiontitle="Components">
|
|
443
409
|
{{
|
|
@@ -4,7 +4,13 @@
|
|
|
4
4
|
* @subcategory components
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import React, {
|
|
7
|
+
import React, {
|
|
8
|
+
useEffect,
|
|
9
|
+
useContext,
|
|
10
|
+
useState,
|
|
11
|
+
Fragment,
|
|
12
|
+
useRef,
|
|
13
|
+
} from "react";
|
|
8
14
|
import { useEditor, useNode } from "@craftjs/core";
|
|
9
15
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
10
16
|
import { faPlus, faTimes } from "@fortawesome/free-solid-svg-icons";
|
|
@@ -13,10 +19,11 @@ import faIcons from "./elements/faicons";
|
|
|
13
19
|
import { craftToSaltcorn, layoutToNodes } from "./storage";
|
|
14
20
|
import optionsCtx from "./context";
|
|
15
21
|
import { WrapElem } from "./Toolbox";
|
|
22
|
+
import { isEqual } from "lodash";
|
|
16
23
|
|
|
17
24
|
/**
|
|
18
|
-
*
|
|
19
|
-
* @param {object[]} xs
|
|
25
|
+
*
|
|
26
|
+
* @param {object[]} xs
|
|
20
27
|
* @returns {object[]}
|
|
21
28
|
*/
|
|
22
29
|
const twoByTwos = (xs) => {
|
|
@@ -67,10 +74,38 @@ export /**
|
|
|
67
74
|
* @subcategory components
|
|
68
75
|
* @namespace
|
|
69
76
|
*/
|
|
70
|
-
const InitNewElement = ({ nodekeys }) => {
|
|
77
|
+
const InitNewElement = ({ nodekeys, setIsSaving }) => {
|
|
78
|
+
const [saveTimeout, setSaveTimeout] = useState(false);
|
|
79
|
+
const savedData = useRef(false);
|
|
71
80
|
const { actions, query, connectors } = useEditor((state, query) => {
|
|
72
81
|
return {};
|
|
73
82
|
});
|
|
83
|
+
const options = useContext(optionsCtx);
|
|
84
|
+
const doSave = (query) => {
|
|
85
|
+
if (!query.serialize) return;
|
|
86
|
+
|
|
87
|
+
const data = craftToSaltcorn(JSON.parse(query.serialize()));
|
|
88
|
+
const urlroot = options.page_id ? "pageedit" : "viewedit";
|
|
89
|
+
if (savedData.current === false) {
|
|
90
|
+
//do not save on first call
|
|
91
|
+
savedData.current = JSON.stringify(data.layout);
|
|
92
|
+
setIsSaving(false);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (isEqual(savedData.current, JSON.stringify(data.layout))) return;
|
|
96
|
+
savedData.current = JSON.stringify(data.layout);
|
|
97
|
+
|
|
98
|
+
fetch(`/${urlroot}/savebuilder/${options.page_id || options.view_id}`, {
|
|
99
|
+
method: "POST", // or 'PUT'
|
|
100
|
+
headers: {
|
|
101
|
+
"Content-Type": "application/json",
|
|
102
|
+
"CSRF-Token": options.csrfToken,
|
|
103
|
+
},
|
|
104
|
+
body: JSON.stringify(data),
|
|
105
|
+
}).then(() => {
|
|
106
|
+
setIsSaving(false);
|
|
107
|
+
});
|
|
108
|
+
};
|
|
74
109
|
const onNodesChange = (arg, arg1) => {
|
|
75
110
|
const nodes = arg.getSerializedNodes();
|
|
76
111
|
const newNodeIds = [];
|
|
@@ -98,6 +133,14 @@ const InitNewElement = ({ nodekeys }) => {
|
|
|
98
133
|
actions.selectNode(id);
|
|
99
134
|
}
|
|
100
135
|
}
|
|
136
|
+
if (saveTimeout) clearTimeout(saveTimeout);
|
|
137
|
+
setIsSaving(true);
|
|
138
|
+
setSaveTimeout(
|
|
139
|
+
setTimeout(() => {
|
|
140
|
+
doSave(query);
|
|
141
|
+
setSaveTimeout(false);
|
|
142
|
+
}, 500)
|
|
143
|
+
);
|
|
101
144
|
};
|
|
102
145
|
useEffect(() => {
|
|
103
146
|
const nodes = query.getSerializedNodes();
|
|
@@ -111,7 +111,7 @@ const OrFormula = ({ setProp, isFormula, node, nodekey, children }) => {
|
|
|
111
111
|
});
|
|
112
112
|
};
|
|
113
113
|
let errorString = false;
|
|
114
|
-
if (isFormula[nodekey]) {
|
|
114
|
+
if (mode === "show" && isFormula[nodekey]) {
|
|
115
115
|
try {
|
|
116
116
|
Function("return " + node[nodekey]);
|
|
117
117
|
} catch (error) {
|