@stubber/form-fields 2.0.10 → 2.0.12
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,32 +1,31 @@
|
|
|
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 content = typeof value === "string" ? { text: value } : { json: cloneDeep(value) };
|
|
5
5
|
$: update_content(value);
|
|
6
6
|
function update_content(new_value) {
|
|
7
|
-
|
|
7
|
+
let new_content = null;
|
|
8
|
+
if (new_value === void 0) {
|
|
8
9
|
return;
|
|
9
10
|
}
|
|
10
|
-
const current_content = jsoneditor.get();
|
|
11
|
-
let content = null;
|
|
12
11
|
if (typeof new_value === "string") {
|
|
13
|
-
if ("text" in
|
|
14
|
-
|
|
15
|
-
} else if ("json" in
|
|
16
|
-
|
|
12
|
+
if ("text" in content && content.text !== new_value) {
|
|
13
|
+
new_content = { text: `"${new_value}"` };
|
|
14
|
+
} else if ("json" in content) {
|
|
15
|
+
new_content = { text: new_value };
|
|
17
16
|
}
|
|
18
|
-
} else {
|
|
17
|
+
} else if (new_value !== void 0) {
|
|
19
18
|
try {
|
|
20
|
-
const current_json = "json" in
|
|
19
|
+
const current_json = "json" in content ? content.json : JSON.parse(content.text);
|
|
21
20
|
if (!isEqual(current_json, new_value)) {
|
|
22
|
-
|
|
21
|
+
new_content = { json: cloneDeep(new_value) };
|
|
23
22
|
}
|
|
24
23
|
} catch (e) {
|
|
25
|
-
|
|
24
|
+
new_content = { json: cloneDeep(new_value) };
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
|
-
if (
|
|
29
|
-
|
|
27
|
+
if (new_content !== null) {
|
|
28
|
+
content = new_content;
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
31
|
function handleChange(new_content) {
|
|
@@ -42,4 +41,4 @@ function handleChange(new_content) {
|
|
|
42
41
|
}
|
|
43
42
|
</script>
|
|
44
43
|
|
|
45
|
-
<JSONEditor bind:
|
|
44
|
+
<JSONEditor bind:content onChange={handleChange} {...$$restProps} />
|