fuma 0.4.8 → 0.4.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.
package/dist/ui/form/Form.svelte
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
ReturnData extends Record<string, unknown> = FormDataInput<Shape>,
|
|
8
8
|
Data extends FormDataInput<Shape> = FormDataInput<Shape>
|
|
9
9
|
"
|
|
10
|
-
>import { createEventDispatcher, onMount } from "svelte";
|
|
10
|
+
>import { createEventDispatcher, onMount, tick } from "svelte";
|
|
11
11
|
import { fade } from "svelte/transition";
|
|
12
12
|
import { page } from "$app/stores";
|
|
13
13
|
import { contextContainer } from "../context.js";
|
|
@@ -36,8 +36,6 @@ export let options = {};
|
|
|
36
36
|
let dataInput = initData(fields);
|
|
37
37
|
export { dataInput as data };
|
|
38
38
|
let data = dataInput;
|
|
39
|
-
$:
|
|
40
|
-
$isDirty ? dataInput = data : data = dataInput;
|
|
41
39
|
export function set(key, value) {
|
|
42
40
|
isDirty.set(true);
|
|
43
41
|
data[key] = value;
|
|
@@ -66,6 +64,13 @@ const { enhance, setError } = useForm({
|
|
|
66
64
|
});
|
|
67
65
|
const { handleInput, isDirty } = useHandleInput({ model, setError });
|
|
68
66
|
onMount(lookupValueFromParams);
|
|
67
|
+
isDirty.subscribe(async (_isDirty) => {
|
|
68
|
+
await tick();
|
|
69
|
+
if (isDirty)
|
|
70
|
+
dataInput = data;
|
|
71
|
+
else
|
|
72
|
+
data = dataInput;
|
|
73
|
+
});
|
|
69
74
|
function lookupValueFromParams() {
|
|
70
75
|
fields.flat().forEach(({ key }) => {
|
|
71
76
|
if (data[key])
|
|
@@ -24,12 +24,9 @@ export let value = _value || jsonParse($page.url.searchParams.get(key), []);
|
|
|
24
24
|
let dropdown;
|
|
25
25
|
$:
|
|
26
26
|
_options = parseOptions(options);
|
|
27
|
-
function
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
goto($urlParam.with({ [key]: JSON.stringify(value) }), { replaceState: true, noScroll: true });
|
|
27
|
+
async function writeUrl() {
|
|
28
|
+
const url = value?.length ? $urlParam.with({ [key]: JSON.stringify(value) }) : $urlParam.without(key);
|
|
29
|
+
return goto(url, { replaceState: true, noScroll: true });
|
|
33
30
|
}
|
|
34
31
|
function handleReset() {
|
|
35
32
|
dropdown.hide();
|
|
@@ -40,7 +37,7 @@ function handleReset() {
|
|
|
40
37
|
|
|
41
38
|
<input type="hidden" name={key} value={JSON.stringify(value)} />
|
|
42
39
|
|
|
43
|
-
<DropDown bind:this={dropdown} tippyProps={{
|
|
40
|
+
<DropDown bind:this={dropdown} tippyProps={{ onHidden: writeUrl }} classWrapper="mb-[-2px]">
|
|
44
41
|
<div class="join" class:ml-2={value?.length} slot="activator">
|
|
45
42
|
<button class="btn indicator join-item btn-sm {btnClass || ''}">
|
|
46
43
|
<slot name="label">
|