@stubber/form-fields 2.0.11 → 2.0.13
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,17 +1,24 @@
|
|
|
1
1
|
<script>import { cloneDeep, isEqual } from "lodash-es";
|
|
2
2
|
import { JSONEditor } from "svelte-jsoneditor";
|
|
3
3
|
export let value;
|
|
4
|
-
let
|
|
4
|
+
let jsoneditor;
|
|
5
5
|
$: update_content(value);
|
|
6
6
|
function update_content(new_value) {
|
|
7
7
|
let new_content = null;
|
|
8
|
+
if (new_value === void 0) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (!jsoneditor) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const content = jsoneditor.get();
|
|
8
15
|
if (typeof new_value === "string") {
|
|
9
16
|
if ("text" in content && content.text !== new_value) {
|
|
10
|
-
new_content = { text:
|
|
17
|
+
new_content = { text: new_value };
|
|
11
18
|
} else if ("json" in content) {
|
|
12
19
|
new_content = { text: new_value };
|
|
13
20
|
}
|
|
14
|
-
} else {
|
|
21
|
+
} else if (new_value !== void 0) {
|
|
15
22
|
try {
|
|
16
23
|
const current_json = "json" in content ? content.json : JSON.parse(content.text);
|
|
17
24
|
if (!isEqual(current_json, new_value)) {
|
|
@@ -22,7 +29,8 @@ function update_content(new_value) {
|
|
|
22
29
|
}
|
|
23
30
|
}
|
|
24
31
|
if (new_content !== null) {
|
|
25
|
-
content
|
|
32
|
+
console.log("update_content set content to", new_content);
|
|
33
|
+
jsoneditor.set(new_content);
|
|
26
34
|
}
|
|
27
35
|
}
|
|
28
36
|
function handleChange(new_content) {
|
|
@@ -35,7 +43,8 @@ function handleChange(new_content) {
|
|
|
35
43
|
} else if ("json" in new_content && new_content.json !== void 0) {
|
|
36
44
|
value = cloneDeep(new_content.json);
|
|
37
45
|
}
|
|
46
|
+
console.log("handleChange set value to", value);
|
|
38
47
|
}
|
|
39
48
|
</script>
|
|
40
49
|
|
|
41
|
-
<JSONEditor bind:
|
|
50
|
+
<JSONEditor bind:this={jsoneditor} onChange={handleChange} {...$$restProps} />
|