@stubber/form-fields 2.0.8 → 2.0.10
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.
|
@@ -12,6 +12,15 @@ export let dynamic_field_type = false;
|
|
|
12
12
|
setContext("dynamic_field_type", dynamic_field_type);
|
|
13
13
|
let fields = [];
|
|
14
14
|
let form_errors = {};
|
|
15
|
+
$: rebuild_fields(initial_form, form);
|
|
16
|
+
const rebuild_fields = (initial_form2, form2) => {
|
|
17
|
+
if (initial_form2.data) {
|
|
18
|
+
form2.update((data) => {
|
|
19
|
+
return { ...data, ...initial_form2.data };
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
fields = build_fields(form2, attachments, dependencies, initial_form2.spec.fields);
|
|
23
|
+
};
|
|
15
24
|
$: validate_form($form);
|
|
16
25
|
const validate_form = async (_) => {
|
|
17
26
|
form_errors = {};
|
|
@@ -24,15 +33,6 @@ const validate_form = async (_) => {
|
|
|
24
33
|
form_errors = { ...form_errors };
|
|
25
34
|
form_valid = Object.keys(form_errors).length === 0;
|
|
26
35
|
};
|
|
27
|
-
$: rebuild_fields(initial_form, form);
|
|
28
|
-
const rebuild_fields = (initial_form2, form2) => {
|
|
29
|
-
if (initial_form2.data) {
|
|
30
|
-
form2.update((data) => {
|
|
31
|
-
return { ...data, ...initial_form2.data };
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
fields = build_fields(form2, attachments, dependencies, initial_form2.spec.fields);
|
|
35
|
-
};
|
|
36
36
|
</script>
|
|
37
37
|
|
|
38
38
|
<div class="flex flex-col gap-y-2">
|
|
@@ -1,17 +1,45 @@
|
|
|
1
|
-
<script>import { cloneDeep } from "lodash-es";
|
|
1
|
+
<script>import { cloneDeep, isEqual } from "lodash-es";
|
|
2
2
|
import { JSONEditor } from "svelte-jsoneditor";
|
|
3
3
|
export let value;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
let jsoneditor;
|
|
5
|
+
$: update_content(value);
|
|
6
|
+
function update_content(new_value) {
|
|
7
|
+
if (jsoneditor === void 0) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const current_content = jsoneditor.get();
|
|
11
|
+
let content = null;
|
|
12
|
+
if (typeof new_value === "string") {
|
|
13
|
+
if ("text" in current_content && current_content.text !== new_value) {
|
|
14
|
+
content = { text: `"${new_value}"` };
|
|
15
|
+
} else if ("json" in current_content) {
|
|
16
|
+
content = { text: new_value };
|
|
17
|
+
}
|
|
18
|
+
} else {
|
|
19
|
+
try {
|
|
20
|
+
const current_json = "json" in current_content ? current_content.json : JSON.parse(current_content.text);
|
|
21
|
+
if (!isEqual(current_json, new_value)) {
|
|
22
|
+
content = { json: cloneDeep(new_value) };
|
|
23
|
+
}
|
|
24
|
+
} catch (e) {
|
|
25
|
+
content = { json: cloneDeep(new_value) };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (content !== null) {
|
|
29
|
+
jsoneditor.update(content);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
8
32
|
function handleChange(new_content) {
|
|
9
|
-
if ("
|
|
33
|
+
if ("text" in new_content && new_content.text !== void 0) {
|
|
34
|
+
try {
|
|
35
|
+
value = JSON.parse(new_content.text);
|
|
36
|
+
} catch (e) {
|
|
37
|
+
value = new_content.text;
|
|
38
|
+
}
|
|
39
|
+
} else if ("json" in new_content && new_content.json !== void 0) {
|
|
10
40
|
value = cloneDeep(new_content.json);
|
|
11
|
-
} else if ("text" in new_content) {
|
|
12
|
-
value = cloneDeep(new_content.text);
|
|
13
41
|
}
|
|
14
42
|
}
|
|
15
43
|
</script>
|
|
16
44
|
|
|
17
|
-
<JSONEditor {
|
|
45
|
+
<JSONEditor bind:this={jsoneditor} onChange={handleChange} {...$$restProps} />
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
|
+
import { type Content } from "svelte-jsoneditor";
|
|
2
3
|
declare const __propDef: {
|
|
3
4
|
props: {
|
|
4
|
-
content?:
|
|
5
|
+
content?: Content;
|
|
5
6
|
selection?: import("svelte-jsoneditor").JSONEditorSelection | undefined;
|
|
6
7
|
readOnly?: boolean;
|
|
7
8
|
indentation?: number | string;
|
|
@@ -31,16 +32,16 @@ declare const __propDef: {
|
|
|
31
32
|
onError?: import("svelte-jsoneditor").OnError;
|
|
32
33
|
onFocus?: import("svelte-jsoneditor").OnFocus;
|
|
33
34
|
onBlur?: import("svelte-jsoneditor").OnBlur;
|
|
34
|
-
get?: () =>
|
|
35
|
-
set?: (newContent:
|
|
36
|
-
update?: (updatedContent:
|
|
35
|
+
get?: () => Content;
|
|
36
|
+
set?: (newContent: Content) => Promise<void>;
|
|
37
|
+
update?: (updatedContent: Content) => Promise<void>;
|
|
37
38
|
patch?: (operations: import("immutable-json-patch").JSONPatchDocument) => Promise<import("svelte-jsoneditor").JSONPatchResult>;
|
|
38
39
|
select?: (newSelection: import("svelte-jsoneditor").JSONEditorSelection | undefined) => Promise<void>;
|
|
39
40
|
expand?: (path: import("immutable-json-patch").JSONPath, callback?: import("svelte-jsoneditor").OnExpand) => Promise<void>;
|
|
40
41
|
collapse?: (path: import("immutable-json-patch").JSONPath, recursive?: boolean) => Promise<void>;
|
|
41
42
|
transform?: (options: import("svelte-jsoneditor").TransformModalOptions) => void;
|
|
42
43
|
validate?: () => import("svelte-jsoneditor").ContentErrors | undefined;
|
|
43
|
-
acceptAutoRepair?: () => Promise<
|
|
44
|
+
acceptAutoRepair?: () => Promise<Content>;
|
|
44
45
|
scrollTo?: (path: import("immutable-json-patch").JSONPath) => Promise<void>;
|
|
45
46
|
findElement?: (path: import("immutable-json-patch").JSONPath) => Element | undefined;
|
|
46
47
|
focus?: () => Promise<void>;
|