@stubber/form-fields 1.4.6 → 1.5.0
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/README.md +61 -295
- package/dist/fields2/FieldLabel.svelte +8 -0
- package/dist/fields2/FieldLabel.svelte.d.ts +20 -0
- package/dist/fields2/FieldMessage.svelte +16 -0
- package/dist/fields2/FieldMessage.svelte.d.ts +20 -0
- package/dist/fields2/Form.svelte +29 -0
- package/dist/fields2/Form.svelte.d.ts +23 -0
- package/dist/fields2/fileserver.d.ts +15 -0
- package/dist/fields2/fileserver.js +52 -0
- package/dist/fields2/form-field.svelte +10 -0
- package/dist/fields2/form-field.svelte.d.ts +20 -0
- package/dist/fields2/interfaces.d.ts +207 -0
- package/dist/fields2/interfaces.js +82 -0
- package/dist/fields2/sub/array-builder-field.svelte +110 -0
- package/dist/fields2/sub/array-builder-field.svelte.d.ts +27 -0
- package/dist/fields2/sub/checkbox-autocomplete.svelte +56 -0
- package/dist/fields2/sub/checkbox-autocomplete.svelte.d.ts +27 -0
- package/dist/fields2/sub/checkbox-field.svelte +41 -0
- package/dist/fields2/sub/checkbox-field.svelte.d.ts +28 -0
- package/dist/fields2/sub/code-field.svelte +146 -0
- package/dist/fields2/sub/code-field.svelte.d.ts +27 -0
- package/dist/fields2/sub/contact-selector-field.svelte +84 -0
- package/dist/fields2/sub/contact-selector-field.svelte.d.ts +30 -0
- package/dist/fields2/sub/currency-field.svelte +197 -0
- package/dist/fields2/sub/currency-field.svelte.d.ts +29 -0
- package/dist/fields2/sub/data-indication-field.svelte +19 -0
- package/dist/fields2/sub/data-indication-field.svelte.d.ts +23 -0
- package/dist/fields2/sub/date-field.svelte +31 -0
- package/dist/fields2/sub/date-field.svelte.d.ts +23 -0
- package/dist/fields2/sub/date-time-field.svelte +31 -0
- package/dist/fields2/sub/date-time-field.svelte.d.ts +23 -0
- package/dist/fields2/sub/email-field.svelte +40 -0
- package/dist/fields2/sub/email-field.svelte.d.ts +23 -0
- package/dist/fields2/sub/field-builder-field.svelte +525 -0
- package/dist/fields2/sub/field-builder-field.svelte.d.ts +23 -0
- package/dist/fields2/sub/file-field.svelte +150 -0
- package/dist/fields2/sub/file-field.svelte.d.ts +27 -0
- package/dist/fields2/sub/grid-field.svelte +54 -0
- package/dist/fields2/sub/grid-field.svelte.d.ts +30 -0
- package/dist/fields2/sub/heading-field.svelte +28 -0
- package/dist/fields2/sub/heading-field.svelte.d.ts +28 -0
- package/dist/fields2/sub/hidden-field.svelte +142 -0
- package/dist/fields2/sub/hidden-field.svelte.d.ts +37 -0
- package/dist/fields2/sub/hidden-location-field.svelte +23 -0
- package/dist/fields2/sub/hidden-location-field.svelte.d.ts +23 -0
- package/dist/fields2/sub/html-field.svelte +22 -0
- package/dist/fields2/sub/html-field.svelte.d.ts +27 -0
- package/dist/fields2/sub/json-editor-bound.svelte +17 -0
- package/dist/fields2/sub/json-editor-bound.svelte.d.ts +65 -0
- package/dist/fields2/sub/jsoneditor-field.svelte +23 -0
- package/dist/fields2/sub/jsoneditor-field.svelte.d.ts +27 -0
- package/dist/fields2/sub/map-field.svelte +144 -0
- package/dist/fields2/sub/map-field.svelte.d.ts +28 -0
- package/dist/fields2/sub/multi-checkbox-field.svelte +83 -0
- package/dist/fields2/sub/multi-checkbox-field.svelte.d.ts +34 -0
- package/dist/fields2/sub/multistep-field.svelte +70 -0
- package/dist/fields2/sub/multistep-field.svelte.d.ts +24 -0
- package/dist/fields2/sub/note-field.svelte +18 -0
- package/dist/fields2/sub/note-field.svelte.d.ts +23 -0
- package/dist/fields2/sub/number-field.svelte +77 -0
- package/dist/fields2/sub/number-field.svelte.d.ts +29 -0
- package/dist/fields2/sub/object-builder-field.svelte +123 -0
- package/dist/fields2/sub/object-builder-field.svelte.d.ts +28 -0
- package/dist/fields2/sub/qr-code-scanner-field.svelte +86 -0
- package/dist/fields2/sub/qr-code-scanner-field.svelte.d.ts +23 -0
- package/dist/fields2/sub/radio-field.svelte +69 -0
- package/dist/fields2/sub/radio-field.svelte.d.ts +30 -0
- package/dist/fields2/sub/screenrecorder-field.svelte +182 -0
- package/dist/fields2/sub/screenrecorder-field.svelte.d.ts +27 -0
- package/dist/fields2/sub/screenshot-field.svelte +165 -0
- package/dist/fields2/sub/screenshot-field.svelte.d.ts +26 -0
- package/dist/fields2/sub/scroll-and-read-display-field.svelte +92 -0
- package/dist/fields2/sub/scroll-and-read-display-field.svelte.d.ts +29 -0
- package/dist/fields2/sub/section-field.svelte +27 -0
- package/dist/fields2/sub/section-field.svelte.d.ts +26 -0
- package/dist/fields2/sub/select-field.svelte +138 -0
- package/dist/fields2/sub/select-field.svelte.d.ts +34 -0
- package/dist/fields2/sub/selectresource-field.svelte +69 -0
- package/dist/fields2/sub/selectresource-field.svelte.d.ts +29 -0
- package/dist/fields2/sub/signature-field.svelte +84 -0
- package/dist/fields2/sub/signature-field.svelte.d.ts +23 -0
- package/dist/fields2/sub/slider-field.svelte +28 -0
- package/dist/fields2/sub/slider-field.svelte.d.ts +28 -0
- package/dist/fields2/sub/smart-text-field.svelte +245 -0
- package/dist/fields2/sub/smart-text-field.svelte.d.ts +36 -0
- package/dist/fields2/sub/telephone-field.svelte +68 -0
- package/dist/fields2/sub/telephone-field.svelte.d.ts +26 -0
- package/dist/fields2/sub/text-field.svelte +46 -0
- package/dist/fields2/sub/text-field.svelte.d.ts +27 -0
- package/dist/fields2/sub/voicenote-field.svelte +161 -0
- package/dist/fields2/sub/voicenote-field.svelte.d.ts +26 -0
- package/dist/fields2/utils.d.ts +9 -0
- package/dist/fields2/utils.js +116 -0
- package/dist/fields2/validations/validate_field.d.ts +11 -0
- package/dist/fields2/validations/validate_field.js +121 -0
- package/package.json +6 -9
package/README.md
CHANGED
|
@@ -10,300 +10,6 @@ pnpm install
|
|
|
10
10
|
pnpm run dev
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
## Quick start
|
|
14
|
-
|
|
15
|
-
Use this as a quick demo
|
|
16
|
-
|
|
17
|
-
```
|
|
18
|
-
<script>
|
|
19
|
-
import { Form } from 'stubber-form-fields-pkg';
|
|
20
|
-
|
|
21
|
-
let initial_form = {
|
|
22
|
-
spec: {
|
|
23
|
-
fields: {
|
|
24
|
-
fullname: {
|
|
25
|
-
fieldtype: "text"
|
|
26
|
-
},
|
|
27
|
-
gender: {
|
|
28
|
-
fieldtype: "select",
|
|
29
|
-
params: {
|
|
30
|
-
options: [
|
|
31
|
-
{
|
|
32
|
-
label: "Male",
|
|
33
|
-
value: "male"
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
label: "Female",
|
|
37
|
-
value: "female"
|
|
38
|
-
}
|
|
39
|
-
]
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
let form;
|
|
47
|
-
|
|
48
|
-
</script>
|
|
49
|
-
|
|
50
|
-
<Form
|
|
51
|
-
bind:form
|
|
52
|
-
{initial_form}
|
|
53
|
-
/>
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
## Form
|
|
57
|
-
|
|
58
|
-
- Can render a list of fields
|
|
59
|
-
- All fields in a form have access to the state and data of other fields in the form
|
|
60
|
-
- `initial_form` can be passed as a prop to this component to initialize the stores with some data
|
|
61
|
-
- All props from this component are passed down to child components
|
|
62
|
-
|
|
63
|
-
### props
|
|
64
|
-
|
|
65
|
-
#### initial_form
|
|
66
|
-
|
|
67
|
-
- Use to initialize the form
|
|
68
|
-
|
|
69
|
-
```
|
|
70
|
-
{
|
|
71
|
-
"spec": {
|
|
72
|
-
"test": {
|
|
73
|
-
"fieldtype": "text"
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
"data": {
|
|
77
|
-
"test": "Hi there"
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
#### form
|
|
83
|
-
|
|
84
|
-
- use this to bind to the internal store
|
|
85
|
-
|
|
86
|
-
#### field_wrapper
|
|
87
|
-
|
|
88
|
-
- Use to render fields differently
|
|
89
|
-
- Below is the default wrapper as a guideline
|
|
90
|
-
|
|
91
|
-
```
|
|
92
|
-
<script>
|
|
93
|
-
// fieldWrapper
|
|
94
|
-
export let fieldcomponent;
|
|
95
|
-
</script>
|
|
96
|
-
|
|
97
|
-
<svelte:component this={fieldcomponent} {...$$props} />
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
#### dependencies
|
|
101
|
-
|
|
102
|
-
- Many fields require extra dependencies that you can pass via this prop
|
|
103
|
-
|
|
104
|
-
## Concepts
|
|
105
|
-
|
|
106
|
-
There are a few concepts to be aware of when using this library
|
|
107
|
-
|
|
108
|
-
### Field definition
|
|
109
|
-
|
|
110
|
-
This is the JSON object, primarily as it comes from the template
|
|
111
|
-
|
|
112
|
-
#### common settings
|
|
113
|
-
|
|
114
|
-
- `name`
|
|
115
|
-
- always gets set to the key of the object and cannot be overwritten
|
|
116
|
-
- `fieldtype`
|
|
117
|
-
- sets the field component to render in the form
|
|
118
|
-
- default value is`'text'`
|
|
119
|
-
- `description`
|
|
120
|
-
- use to describe what the field is there for
|
|
121
|
-
- default value is`''`
|
|
122
|
-
- `title`
|
|
123
|
-
- use to set the label of the field
|
|
124
|
-
- default value is a human readable form of `[name]`
|
|
125
|
-
- `hide_label`
|
|
126
|
-
- set to `true` if you don't want the field to show a label
|
|
127
|
-
- default value is`false`
|
|
128
|
-
- `details.keyname`
|
|
129
|
-
- use to set where in `data` to write the field value to
|
|
130
|
-
- default value is `[name]`
|
|
131
|
-
- `details.datapath`
|
|
132
|
-
- use to nest the value deeper inside `data`
|
|
133
|
-
- default value is `''`
|
|
134
|
-
- `initvalue.default`
|
|
135
|
-
- use to set the value of the field if the field value is not yet set
|
|
136
|
-
- `initvalue.override`
|
|
137
|
-
- use to set the value of the field regardless of if the field value is set or not
|
|
138
|
-
- `conditions`
|
|
139
|
-
- use to conditionally render a field
|
|
140
|
-
- array of jsonata expressions that evaluate using the fieldContext
|
|
141
|
-
- default value is `[]`
|
|
142
|
-
|
|
143
|
-
```
|
|
144
|
-
// example conditions
|
|
145
|
-
[
|
|
146
|
-
"form.data.gender = 'male'"
|
|
147
|
-
]
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
- `validations`
|
|
151
|
-
- use to ensure a valid field value
|
|
152
|
-
- default value is `{}`
|
|
153
|
-
|
|
154
|
-
```
|
|
155
|
-
// example validations
|
|
156
|
-
{
|
|
157
|
-
"is_required_validation": {
|
|
158
|
-
"validationtype": "required",
|
|
159
|
-
"valid_message": "Looks good!",
|
|
160
|
-
"invalid_message": "This field is required"
|
|
161
|
-
},
|
|
162
|
-
"passes_regex_check": {
|
|
163
|
-
"validationtype": "regex",
|
|
164
|
-
"params": {
|
|
165
|
-
"regex": "regex here"
|
|
166
|
-
},
|
|
167
|
-
"invalid_message": "something is wrong"
|
|
168
|
-
},
|
|
169
|
-
"jsonata_check": {
|
|
170
|
-
"validationtype": "jsonata",
|
|
171
|
-
"params": {
|
|
172
|
-
"jsonata": "field.data = 5"
|
|
173
|
-
},
|
|
174
|
-
"invalid_message": "something is wrong"
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
- `fields`
|
|
180
|
-
- Nest multiple fields under this field
|
|
181
|
-
- `params` is where any field-specific settings are set
|
|
182
|
-
|
|
183
|
-
### fieldtypes
|
|
184
|
-
|
|
185
|
-
#### arraybuilder
|
|
186
|
-
|
|
187
|
-
- `params.new_entry_field`
|
|
188
|
-
- this is a fieldspec for how new entries are added to the array
|
|
189
|
-
- `details.keyname` and `details.datapath` don't function in the new_entry_field
|
|
190
|
-
|
|
191
|
-
#### checkbox
|
|
192
|
-
|
|
193
|
-
- `params.checkedvalue`
|
|
194
|
-
- this is the value that the field will be set to if the box is checked
|
|
195
|
-
- default value is `true`
|
|
196
|
-
- `params.uncheckedvalue`
|
|
197
|
-
- this is the value that the field will be set to if the box is not checked
|
|
198
|
-
- default value is `false`
|
|
199
|
-
|
|
200
|
-
#### currency
|
|
201
|
-
|
|
202
|
-
- `params.currency`
|
|
203
|
-
- set the currency of the field
|
|
204
|
-
- `params.currency_whitelist`
|
|
205
|
-
- set array of currencies that can be selected
|
|
206
|
-
- `params.currency_blacklist`
|
|
207
|
-
- set array of currencies that cannot be selected
|
|
208
|
-
|
|
209
|
-
#### dataindication
|
|
210
|
-
|
|
211
|
-
#### date
|
|
212
|
-
|
|
213
|
-
#### datetime
|
|
214
|
-
|
|
215
|
-
#### file
|
|
216
|
-
|
|
217
|
-
#### hidden
|
|
218
|
-
|
|
219
|
-
#### jsoneditor
|
|
220
|
-
|
|
221
|
-
- `params.readonly`
|
|
222
|
-
- Shows a non-editable jsoneditor
|
|
223
|
-
|
|
224
|
-
#### map
|
|
225
|
-
|
|
226
|
-
#### multistep
|
|
227
|
-
|
|
228
|
-
#### note
|
|
229
|
-
|
|
230
|
-
#### radio
|
|
231
|
-
|
|
232
|
-
- `params.options`
|
|
233
|
-
- set the options here
|
|
234
|
-
|
|
235
|
-
```
|
|
236
|
-
[
|
|
237
|
-
{
|
|
238
|
-
"label": "Red"
|
|
239
|
-
},
|
|
240
|
-
{
|
|
241
|
-
"label": "Green",
|
|
242
|
-
"value": "green"
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
"label": "Blue",
|
|
246
|
-
"value": {
|
|
247
|
-
"hello": "world"
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
]
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
#### renderfield
|
|
254
|
-
|
|
255
|
-
- `params.dynamic_fieldspec`
|
|
256
|
-
- Set the fieldspec here with values as jsonata expressions
|
|
257
|
-
|
|
258
|
-
#### richtext
|
|
259
|
-
|
|
260
|
-
#### scrollandreaddisplay
|
|
261
|
-
|
|
262
|
-
- `params.displaytext`
|
|
263
|
-
- Set the text that should be displayed and scrolled through
|
|
264
|
-
|
|
265
|
-
#### section
|
|
266
|
-
|
|
267
|
-
#### select
|
|
268
|
-
|
|
269
|
-
- `params.options`
|
|
270
|
-
- set the select options here
|
|
271
|
-
|
|
272
|
-
```
|
|
273
|
-
[
|
|
274
|
-
{
|
|
275
|
-
"label": "Red"
|
|
276
|
-
},
|
|
277
|
-
{
|
|
278
|
-
"label": "Green",
|
|
279
|
-
"value": "green"
|
|
280
|
-
},
|
|
281
|
-
{
|
|
282
|
-
"label": "Blue",
|
|
283
|
-
"value": {
|
|
284
|
-
"hello": "world"
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
]
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
#### signature
|
|
291
|
-
|
|
292
|
-
#### telephone
|
|
293
|
-
|
|
294
|
-
#### text
|
|
295
|
-
|
|
296
|
-
### Dependencies
|
|
297
|
-
|
|
298
|
-
The dependencies prop is used by certain fields that only function with third party services. All the optional dependencies are listed below.
|
|
299
|
-
|
|
300
|
-
- `file.upload_url`
|
|
301
|
-
- Where files should be uploaded to (e.g. `/api/file-server/upload`)
|
|
302
|
-
- `map.mapboxAccessToken`
|
|
303
|
-
- Access token for mapbox account
|
|
304
|
-
- `map.mapboxStylesheetUrl`
|
|
305
|
-
- Stylesheet url for maps
|
|
306
|
-
|
|
307
13
|
# Publishing
|
|
308
14
|
|
|
309
15
|
We use [semantic-release](https://github.com/semantic-release/semantic-release) to automate the versioning and package publishing process. To publish a new version of the package, follow these steps:
|
|
@@ -326,4 +32,64 @@ fix: fix button color
|
|
|
326
32
|
|
|
327
33
|
See default ruleset [here](https://github.com/semantic-release/commit-analyzer/blob/master/lib/default-release-rules.js)
|
|
328
34
|
|
|
329
|
-
|
|
35
|
+
Conversion Progress:
|
|
36
|
+
|
|
37
|
+
| Component | TS DONE | TESTS DONE |
|
|
38
|
+
| -------------------- | ---------- | ---------- |
|
|
39
|
+
| AgGrid | x | |
|
|
40
|
+
| Arraybuilder | x | |
|
|
41
|
+
| Checkbox | x | |
|
|
42
|
+
| CheckboxAutocomplete | x | |
|
|
43
|
+
| Code | x | |
|
|
44
|
+
| Contactselector | x | |
|
|
45
|
+
| Currency | x | |
|
|
46
|
+
| Dataindication | x | |
|
|
47
|
+
| Date | x | |
|
|
48
|
+
| Datetime | x | |
|
|
49
|
+
| Email | x | |
|
|
50
|
+
| Fieldbuilder | x | |
|
|
51
|
+
| Fieldsbuilder | deprecated | |
|
|
52
|
+
| File | x | |
|
|
53
|
+
| Heading | x | |
|
|
54
|
+
| Hidden | x | |
|
|
55
|
+
| Hiddenlocation | x | |
|
|
56
|
+
| Html | x | |
|
|
57
|
+
| Jsoneditor | x | |
|
|
58
|
+
| Map | x | |
|
|
59
|
+
| Multicheckbox | x | |
|
|
60
|
+
| Multistep | x | |
|
|
61
|
+
| Note | x | |
|
|
62
|
+
| Number | x | |
|
|
63
|
+
| Objectbuilder | x | |
|
|
64
|
+
| Qrcodescanner | x | |
|
|
65
|
+
| Radio | x | |
|
|
66
|
+
| Renderfield | deprecated | |
|
|
67
|
+
| Screenrecorder | x | |
|
|
68
|
+
| Screenshot | x | |
|
|
69
|
+
| Scrollandreaddisplay | x | |
|
|
70
|
+
| Section | x | |
|
|
71
|
+
| Select | x | |
|
|
72
|
+
| Selectresource | x | |
|
|
73
|
+
| Signature | x | |
|
|
74
|
+
| Slider | x | |
|
|
75
|
+
| SmartText | x | |
|
|
76
|
+
| Telephone | x | |
|
|
77
|
+
| Text | x | |
|
|
78
|
+
| Voicenote | x | |
|
|
79
|
+
|
|
80
|
+
Generate Features
|
|
81
|
+
|
|
82
|
+
| Feature | TS DONE | TESTS DONE |
|
|
83
|
+
| --------------------- | ------- | ---------- |
|
|
84
|
+
| hide_label | x | |
|
|
85
|
+
| init_value | x | |
|
|
86
|
+
| without_value_details | x | |
|
|
87
|
+
| attachments | x | |
|
|
88
|
+
| fieldbuilder support | x | |
|
|
89
|
+
|
|
90
|
+
## TS Refactor
|
|
91
|
+
|
|
92
|
+
For now src/lib/fields2 exports a refactored and rewritten form fields implementation.
|
|
93
|
+
The existing implementation is still present for now, but will be removed in future.
|
|
94
|
+
|
|
95
|
+
This allows us to slowly switch editor/squared over to the new implementation without breaking everything at once.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { Writable } from "svelte/store";
|
|
3
|
+
import type { IBuiltField } from "./interfaces";
|
|
4
|
+
declare const __propDef: {
|
|
5
|
+
props: {
|
|
6
|
+
fieldStore: Writable<IBuiltField>;
|
|
7
|
+
};
|
|
8
|
+
events: {
|
|
9
|
+
[evt: string]: CustomEvent<any>;
|
|
10
|
+
};
|
|
11
|
+
slots: {};
|
|
12
|
+
exports?: {} | undefined;
|
|
13
|
+
bindings?: string | undefined;
|
|
14
|
+
};
|
|
15
|
+
export type FieldLabelProps = typeof __propDef.props;
|
|
16
|
+
export type FieldLabelEvents = typeof __propDef.events;
|
|
17
|
+
export type FieldLabelSlots = typeof __propDef.slots;
|
|
18
|
+
export default class FieldLabel extends SvelteComponent<FieldLabelProps, FieldLabelEvents, FieldLabelSlots> {
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<script>import { Label } from "@stubber/ui/label";
|
|
2
|
+
import { get, startCase } from "lodash-es";
|
|
3
|
+
import { get_field_help_message } from "./utils";
|
|
4
|
+
export let fieldStore;
|
|
5
|
+
$: validation_result = $fieldStore.validation_result;
|
|
6
|
+
$: type = validation_result?.type;
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<Label
|
|
10
|
+
id="message-{$fieldStore.id}"
|
|
11
|
+
class="ml-2 text-xs {!$fieldStore.validation_result ? 'invisible' : ''} {type == 'error'
|
|
12
|
+
? 'text-red-500'
|
|
13
|
+
: 'text-muted-foreground'}"
|
|
14
|
+
>
|
|
15
|
+
{$fieldStore.validation_result?.message}
|
|
16
|
+
</Label>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { IBuiltField } from "./interfaces";
|
|
3
|
+
import type { Writable } from "svelte/store";
|
|
4
|
+
declare const __propDef: {
|
|
5
|
+
props: {
|
|
6
|
+
fieldStore: Writable<IBuiltField>;
|
|
7
|
+
};
|
|
8
|
+
events: {
|
|
9
|
+
[evt: string]: CustomEvent<any>;
|
|
10
|
+
};
|
|
11
|
+
slots: {};
|
|
12
|
+
exports?: {} | undefined;
|
|
13
|
+
bindings?: string | undefined;
|
|
14
|
+
};
|
|
15
|
+
export type FieldMessageProps = typeof __propDef.props;
|
|
16
|
+
export type FieldMessageEvents = typeof __propDef.events;
|
|
17
|
+
export type FieldMessageSlots = typeof __propDef.slots;
|
|
18
|
+
export default class FieldMessage extends SvelteComponent<FieldMessageProps, FieldMessageEvents, FieldMessageSlots> {
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<script>import { get as getStoreValue } from "svelte/store";
|
|
2
|
+
import FormField from "./form-field.svelte";
|
|
3
|
+
import { build_fields } from "./utils";
|
|
4
|
+
import { validate_field } from "./validations/validate_field";
|
|
5
|
+
export let initial_form;
|
|
6
|
+
export let form;
|
|
7
|
+
export let attachments;
|
|
8
|
+
export let dependencies = void 0;
|
|
9
|
+
if (initial_form.data) {
|
|
10
|
+
form.update((data) => {
|
|
11
|
+
return { ...data, ...initial_form.data };
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
const fields = build_fields(form, attachments, dependencies, initial_form.spec.fields);
|
|
15
|
+
$: {
|
|
16
|
+
validate_form($form);
|
|
17
|
+
}
|
|
18
|
+
const validate_form = async (_) => {
|
|
19
|
+
for (const fieldStore of fields) {
|
|
20
|
+
await validate_field(form, fieldStore);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<div class="flex flex-col gap-y-1">
|
|
26
|
+
{#each fields as fieldStore (getStoreValue(fieldStore).id)}
|
|
27
|
+
<FormField {fieldStore} />
|
|
28
|
+
{/each}
|
|
29
|
+
</div>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import { type Writable } from "svelte/store";
|
|
3
|
+
import type { IFormDependencies, IInitialForm } from "./interfaces";
|
|
4
|
+
declare const __propDef: {
|
|
5
|
+
props: {
|
|
6
|
+
initial_form: IInitialForm;
|
|
7
|
+
form: Writable<any>;
|
|
8
|
+
attachments: Writable<any>;
|
|
9
|
+
dependencies?: IFormDependencies | undefined;
|
|
10
|
+
};
|
|
11
|
+
events: {
|
|
12
|
+
[evt: string]: CustomEvent<any>;
|
|
13
|
+
};
|
|
14
|
+
slots: {};
|
|
15
|
+
exports?: {} | undefined;
|
|
16
|
+
bindings?: string | undefined;
|
|
17
|
+
};
|
|
18
|
+
export type FormProps = typeof __propDef.props;
|
|
19
|
+
export type FormEvents = typeof __propDef.events;
|
|
20
|
+
export type FormSlots = typeof __propDef.slots;
|
|
21
|
+
export default class Form extends SvelteComponent<FormProps, FormEvents, FormSlots> {
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Writable } from "svelte/store";
|
|
2
|
+
import type { IFormDependencies } from "./interfaces";
|
|
3
|
+
export declare const uploadFiles: (files: File[], dependencies?: IFormDependencies) => Promise<{
|
|
4
|
+
uploaded_files: UploadedFile[];
|
|
5
|
+
failed_files: File[];
|
|
6
|
+
} | undefined>;
|
|
7
|
+
export declare const append_attachment: (UploadedFile: UploadedFile, attachment_store: Writable<UploadedFile[]>) => void;
|
|
8
|
+
export declare const remove_attachment: (fileuuid: string, attachment_store: Writable<UploadedFile[]>) => void;
|
|
9
|
+
export interface UploadedFile {
|
|
10
|
+
fileuuid: string;
|
|
11
|
+
filename: string;
|
|
12
|
+
originalname: string;
|
|
13
|
+
contentType: string;
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// export interface ExtendedFile extends File {
|
|
2
|
+
// path?: string; //for webkitdirectory, dont know svelte-file-dropzone has this apparently
|
|
3
|
+
// filename?: string; //from fileserver after upload
|
|
4
|
+
// }
|
|
5
|
+
export const uploadFiles = async (files, dependencies) => {
|
|
6
|
+
if (!dependencies?.file?.upload_url)
|
|
7
|
+
return;
|
|
8
|
+
const url = dependencies.file.upload_url;
|
|
9
|
+
const filesForm = new FormData();
|
|
10
|
+
if (!files?.length)
|
|
11
|
+
return;
|
|
12
|
+
files.forEach((file) => {
|
|
13
|
+
filesForm.append(file.name, file);
|
|
14
|
+
});
|
|
15
|
+
//send request
|
|
16
|
+
let resJSON;
|
|
17
|
+
try {
|
|
18
|
+
let res = await fetch(url, {
|
|
19
|
+
method: "POST",
|
|
20
|
+
body: filesForm,
|
|
21
|
+
});
|
|
22
|
+
// resJSON = await utils.rawResToJSON(res);
|
|
23
|
+
if (res.ok) {
|
|
24
|
+
resJSON = await res.json();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
console.warn(err);
|
|
29
|
+
}
|
|
30
|
+
let uploaded_files = resJSON?.data?.uploaded_files ?? [];
|
|
31
|
+
let failed_files = files.filter((f) => !uploaded_files.find((uf) => uf.filename === f.name));
|
|
32
|
+
return {
|
|
33
|
+
uploaded_files,
|
|
34
|
+
failed_files,
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export const append_attachment = (UploadedFile, attachment_store) => {
|
|
38
|
+
attachment_store.update((atts) => {
|
|
39
|
+
if (!atts)
|
|
40
|
+
atts = [];
|
|
41
|
+
atts.push(UploadedFile);
|
|
42
|
+
return atts;
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
export const remove_attachment = (fileuuid, attachment_store) => {
|
|
46
|
+
attachment_store.update((atts) => {
|
|
47
|
+
if (!atts)
|
|
48
|
+
atts = [];
|
|
49
|
+
atts = atts.filter((att) => att.fileuuid !== fileuuid);
|
|
50
|
+
return atts;
|
|
51
|
+
});
|
|
52
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<script>import { component_for } from "./interfaces";
|
|
2
|
+
export let fieldStore;
|
|
3
|
+
const component = component_for($fieldStore);
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
{#if !$fieldStore.hidden}
|
|
7
|
+
<div class="w-full">
|
|
8
|
+
<svelte:component this={component} {fieldStore} />
|
|
9
|
+
</div>
|
|
10
|
+
{/if}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import { type IBuiltField } from "./interfaces";
|
|
3
|
+
import type { Writable } from "svelte/store";
|
|
4
|
+
declare const __propDef: {
|
|
5
|
+
props: {
|
|
6
|
+
fieldStore: Writable<IBuiltField>;
|
|
7
|
+
};
|
|
8
|
+
events: {
|
|
9
|
+
[evt: string]: CustomEvent<any>;
|
|
10
|
+
};
|
|
11
|
+
slots: {};
|
|
12
|
+
exports?: {} | undefined;
|
|
13
|
+
bindings?: string | undefined;
|
|
14
|
+
};
|
|
15
|
+
export type FormFieldProps = typeof __propDef.props;
|
|
16
|
+
export type FormFieldEvents = typeof __propDef.events;
|
|
17
|
+
export type FormFieldSlots = typeof __propDef.slots;
|
|
18
|
+
export default class FormField extends SvelteComponent<FormFieldProps, FormFieldEvents, FormFieldSlots> {
|
|
19
|
+
}
|
|
20
|
+
export {};
|