@stubber/form-fields 1.7.7 → 1.7.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.
|
@@ -19,14 +19,6 @@ import { append_attachment, remove_attachment, uploadFiles } from "../fileserver
|
|
|
19
19
|
export let fieldStore;
|
|
20
20
|
$: validation_result = $fieldStore.validation_result;
|
|
21
21
|
$: validation_type = validation_result?.type;
|
|
22
|
-
function parse_string_value(value) {
|
|
23
|
-
if (value === "true") return true;
|
|
24
|
-
if (value === "false") return false;
|
|
25
|
-
if (value !== "" && !isNaN(Number(value))) {
|
|
26
|
-
return Number(value);
|
|
27
|
-
}
|
|
28
|
-
return value;
|
|
29
|
-
}
|
|
30
22
|
async function handle_files_select(e) {
|
|
31
23
|
const { acceptedFiles, fileRejections } = e.detail;
|
|
32
24
|
if (limit_remaining < acceptedFiles.length) {
|
|
@@ -65,7 +57,7 @@ async function handle_files_select(e) {
|
|
|
65
57
|
];
|
|
66
58
|
selected_files = [];
|
|
67
59
|
}
|
|
68
|
-
let uploaded_files = [];
|
|
60
|
+
let uploaded_files = Array.isArray($fieldStore.value) ? $fieldStore.value : [];
|
|
69
61
|
let failed_files = [];
|
|
70
62
|
let selected_files = [];
|
|
71
63
|
$: update_fieldStore(uploaded_files);
|
|
@@ -91,46 +83,44 @@ function remove_file(item) {
|
|
|
91
83
|
</script>
|
|
92
84
|
|
|
93
85
|
<FieldLabel {fieldStore} />
|
|
94
|
-
<div class="w-full flex
|
|
86
|
+
<div class="flex w-full flex-col {validation_type == 'error' ? 'border-b border-warning-500' : ''}">
|
|
95
87
|
<Dropzone on:drop={handle_files_select} disabled={limit_remaining <= 0}>
|
|
96
|
-
<div class="flex
|
|
88
|
+
<div class="flex h-full flex-col justify-center rounded-sm text-center">
|
|
97
89
|
<div>
|
|
98
90
|
<p class=" text-surface-800">Drop files to upload</p>
|
|
99
91
|
<p class=" text-surface-800">
|
|
100
92
|
Or click <span
|
|
101
|
-
class="text-primary-500 hover:text-primary-400 hover:underline
|
|
93
|
+
class="cursor-pointer text-primary-500 hover:text-primary-400 hover:underline"
|
|
102
94
|
>here</span
|
|
103
95
|
>
|
|
104
96
|
to browse
|
|
105
97
|
</p>
|
|
106
98
|
{#if limit_remaining <= 0}
|
|
107
|
-
<p class="text-field text-danger-600
|
|
99
|
+
<p class="text-field text-sm italic text-danger-600">
|
|
108
100
|
You have reached the maximum number of files allowed
|
|
109
101
|
</p>
|
|
110
102
|
{/if}
|
|
111
103
|
</div>
|
|
112
104
|
</div>
|
|
113
105
|
</Dropzone>
|
|
114
|
-
<div class="w-full
|
|
106
|
+
<div class="mt-2 flex w-full flex-col gap-2">
|
|
115
107
|
{#each all_files as item}
|
|
116
|
-
<div class="w-full flex
|
|
108
|
+
<div class="flex w-full flex-row items-center gap-2">
|
|
117
109
|
{#if item.is_uploaded}
|
|
118
|
-
<div class="
|
|
119
|
-
<i class="fa fa-check
|
|
110
|
+
<div class="flex h-6 w-6 items-center justify-center text-success-500">
|
|
111
|
+
<i class="fa fa-check" />
|
|
120
112
|
</div>
|
|
121
113
|
{:else if item.is_failed}
|
|
122
|
-
<div class="
|
|
114
|
+
<div class="flex h-6 w-6 items-center justify-center text-danger-400">
|
|
123
115
|
<i class="fa-regular fa-triangle-exclamation" />
|
|
124
|
-
<p class="hidden md:block text-fluid-md">Failed</p>
|
|
125
116
|
</div>
|
|
126
117
|
{:else}
|
|
127
|
-
<div class="
|
|
128
|
-
<p class="hidden md:block text-fluid-md" />
|
|
118
|
+
<div class="flex h-6 w-6 items-center justify-center text-surface-500">
|
|
129
119
|
<i class="fa fa-pulse fa-spinner" />
|
|
130
120
|
</div>
|
|
131
121
|
{/if}
|
|
132
|
-
<div class="
|
|
133
|
-
<p class="text-surface-800
|
|
122
|
+
<div class="flex-1 truncate rounded-sm border border-surface-200 py-1 pl-2">
|
|
123
|
+
<p class="text-surface-800">
|
|
134
124
|
{item?.filename}
|
|
135
125
|
</p>
|
|
136
126
|
</div>
|
|
@@ -138,11 +128,13 @@ function remove_file(item) {
|
|
|
138
128
|
type="button"
|
|
139
129
|
variant="destructive"
|
|
140
130
|
size="icon"
|
|
141
|
-
class="
|
|
131
|
+
class="h-8 w-8 shrink-0"
|
|
142
132
|
on:click={() => {
|
|
143
133
|
remove_file(item);
|
|
144
134
|
}}
|
|
145
|
-
|
|
135
|
+
>
|
|
136
|
+
<i class="fa-solid fa-x text-xs" />
|
|
137
|
+
</Button>
|
|
146
138
|
</div>
|
|
147
139
|
{/each}
|
|
148
140
|
</div>
|
|
@@ -43,10 +43,10 @@ export let fieldStore;
|
|
|
43
43
|
function onInput(e) {
|
|
44
44
|
const new_value = e.target.value;
|
|
45
45
|
let parsedValue = parseFloat(new_value);
|
|
46
|
-
if (!isNaN(parsedValue)) {
|
|
46
|
+
if (!isNaN(parsedValue) && parsedValue.toString() === new_value) {
|
|
47
47
|
$fieldStore.value = parsedValue;
|
|
48
48
|
} else {
|
|
49
|
-
$fieldStore.value =
|
|
49
|
+
$fieldStore.value = new_value;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
function onBlur() {
|
|
@@ -68,10 +68,10 @@ function onBlur() {
|
|
|
68
68
|
|
|
69
69
|
<FieldLabel {fieldStore} />
|
|
70
70
|
<Input
|
|
71
|
+
id={$fieldStore.id}
|
|
71
72
|
value={$fieldStore.value}
|
|
72
73
|
on:input={onInput}
|
|
73
74
|
on:blur={onBlur}
|
|
74
|
-
type="number"
|
|
75
75
|
aria-invalid={$fieldStore.validation_result?.type == "error" ? true : undefined}
|
|
76
76
|
/>
|
|
77
77
|
<FieldMessage {fieldStore} />
|