@stubber/form-fields 1.7.10 → 2.0.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/dist/{fields2 → form-fields}/sub/currency-field.svelte +2 -3
- package/dist/{fields2 → form-fields}/sub/select-field.svelte +6 -3
- package/dist/{fields2 → form-fields}/utils.d.ts +1 -0
- package/dist/{fields2 → form-fields}/utils.js +9 -1
- package/dist/utils/input_regex_mask.d.ts +3 -0
- package/dist/utils/input_regex_mask.js +25 -0
- package/package.json +4 -8
- package/dist/Field.svelte +0 -36
- package/dist/Field.svelte.d.ts +0 -33
- package/dist/Form.svelte +0 -34
- package/dist/Form.svelte.d.ts +0 -31
- package/dist/NullFieldWrapper.svelte +0 -6
- package/dist/NullFieldWrapper.svelte.d.ts +0 -27
- package/dist/fields/component_parts/arraybuilder/FieldWrapper.svelte +0 -74
- package/dist/fields/component_parts/arraybuilder/FieldWrapper.svelte.d.ts +0 -31
- package/dist/fields/component_parts/fieldbuilder/FieldWrapper.svelte +0 -8
- package/dist/fields/component_parts/fieldbuilder/FieldWrapper.svelte.d.ts +0 -27
- package/dist/fields/components/AgGrid.svelte +0 -46
- package/dist/fields/components/AgGrid.svelte.d.ts +0 -20
- package/dist/fields/components/Arraybuilder.svelte +0 -98
- package/dist/fields/components/Arraybuilder.svelte.d.ts +0 -27
- package/dist/fields/components/Checkbox.svelte +0 -89
- package/dist/fields/components/Checkbox.svelte.d.ts +0 -25
- package/dist/fields/components/CheckboxAutocomplete.svelte +0 -95
- package/dist/fields/components/CheckboxAutocomplete.svelte.d.ts +0 -25
- package/dist/fields/components/Code.svelte +0 -133
- package/dist/fields/components/Code.svelte.d.ts +0 -18
- package/dist/fields/components/Contactselector.svelte +0 -71
- package/dist/fields/components/Contactselector.svelte.d.ts +0 -27
- package/dist/fields/components/Currency.svelte +0 -264
- package/dist/fields/components/Currency.svelte.d.ts +0 -25
- package/dist/fields/components/Dataindication.svelte +0 -31
- package/dist/fields/components/Dataindication.svelte.d.ts +0 -25
- package/dist/fields/components/Date.svelte +0 -97
- package/dist/fields/components/Date.svelte.d.ts +0 -25
- package/dist/fields/components/Datetime.svelte +0 -97
- package/dist/fields/components/Datetime.svelte.d.ts +0 -25
- package/dist/fields/components/Email.svelte +0 -125
- package/dist/fields/components/Email.svelte.d.ts +0 -25
- package/dist/fields/components/Fieldbuilder.svelte +0 -343
- package/dist/fields/components/Fieldbuilder.svelte.d.ts +0 -27
- package/dist/fields/components/Fieldsbuilder.svelte +0 -122
- package/dist/fields/components/Fieldsbuilder.svelte.d.ts +0 -27
- package/dist/fields/components/File.svelte +0 -231
- package/dist/fields/components/File.svelte.d.ts +0 -27
- package/dist/fields/components/Heading.svelte +0 -17
- package/dist/fields/components/Heading.svelte.d.ts +0 -25
- package/dist/fields/components/Hidden.svelte +0 -7
- package/dist/fields/components/Hidden.svelte.d.ts +0 -25
- package/dist/fields/components/Hiddenlocation.svelte +0 -28
- package/dist/fields/components/Hiddenlocation.svelte.d.ts +0 -25
- package/dist/fields/components/Html.svelte +0 -13
- package/dist/fields/components/Html.svelte.d.ts +0 -25
- package/dist/fields/components/Jsoneditor.svelte +0 -133
- package/dist/fields/components/Jsoneditor.svelte.d.ts +0 -25
- package/dist/fields/components/Map.svelte +0 -192
- package/dist/fields/components/Map.svelte.d.ts +0 -27
- package/dist/fields/components/Multicheckbox.svelte +0 -77
- package/dist/fields/components/Multicheckbox.svelte.d.ts +0 -25
- package/dist/fields/components/Multistep.svelte +0 -86
- package/dist/fields/components/Multistep.svelte.d.ts +0 -27
- package/dist/fields/components/Note.svelte +0 -92
- package/dist/fields/components/Note.svelte.d.ts +0 -25
- package/dist/fields/components/Number.svelte +0 -119
- package/dist/fields/components/Number.svelte.d.ts +0 -25
- package/dist/fields/components/Objectbuilder.svelte +0 -154
- package/dist/fields/components/Objectbuilder.svelte.d.ts +0 -27
- package/dist/fields/components/Qrcodescanner.svelte +0 -196
- package/dist/fields/components/Qrcodescanner.svelte.d.ts +0 -25
- package/dist/fields/components/Radio.svelte +0 -117
- package/dist/fields/components/Radio.svelte.d.ts +0 -25
- package/dist/fields/components/Renderfield.svelte +0 -58
- package/dist/fields/components/Renderfield.svelte.d.ts +0 -27
- package/dist/fields/components/Screenrecorder.svelte +0 -276
- package/dist/fields/components/Screenrecorder.svelte.d.ts +0 -27
- package/dist/fields/components/Screenshot.svelte +0 -269
- package/dist/fields/components/Screenshot.svelte.d.ts +0 -27
- package/dist/fields/components/Scrollandreaddisplay.svelte +0 -122
- package/dist/fields/components/Scrollandreaddisplay.svelte.d.ts +0 -25
- package/dist/fields/components/Section.svelte +0 -87
- package/dist/fields/components/Section.svelte.d.ts +0 -27
- package/dist/fields/components/Select.svelte +0 -161
- package/dist/fields/components/Select.svelte.d.ts +0 -31
- package/dist/fields/components/Selectresource.svelte +0 -57
- package/dist/fields/components/Selectresource.svelte.d.ts +0 -27
- package/dist/fields/components/Signature.svelte +0 -152
- package/dist/fields/components/Signature.svelte.d.ts +0 -27
- package/dist/fields/components/Slider.svelte +0 -101
- package/dist/fields/components/Slider.svelte.d.ts +0 -25
- package/dist/fields/components/SmartText.svelte +0 -351
- package/dist/fields/components/SmartText.svelte.d.ts +0 -25
- package/dist/fields/components/Telephone.svelte +0 -156
- package/dist/fields/components/Telephone.svelte.d.ts +0 -25
- package/dist/fields/components/Text.svelte +0 -107
- package/dist/fields/components/Text.svelte.d.ts +0 -25
- package/dist/fields/components/Voicenote.svelte +0 -267
- package/dist/fields/components/Voicenote.svelte.d.ts +0 -27
- package/dist/fields/components/index.d.ts +0 -84
- package/dist/fields/components/index.js +0 -85
- package/dist/fields/definitions/all.json +0 -38
- package/dist/fields/definitions/arraybuilder.json +0 -39
- package/dist/fields/definitions/checkbox.json +0 -44
- package/dist/fields/definitions/code.json +0 -15
- package/dist/fields/definitions/contactselector.json +0 -15
- package/dist/fields/definitions/currency.json +0 -42
- package/dist/fields/definitions/dataindication.json +0 -16
- package/dist/fields/definitions/date.json +0 -16
- package/dist/fields/definitions/datetime.json +0 -15
- package/dist/fields/definitions/email.json +0 -16
- package/dist/fields/definitions/fieldbuilder.json +0 -64
- package/dist/fields/definitions/fieldsbuilder.json +0 -38
- package/dist/fields/definitions/file.json +0 -42
- package/dist/fields/definitions/grid.json +0 -47
- package/dist/fields/definitions/heading.json +0 -38
- package/dist/fields/definitions/hidden.json +0 -89
- package/dist/fields/definitions/hiddenlocation.json +0 -15
- package/dist/fields/definitions/html.json +0 -34
- package/dist/fields/definitions/index.d.ts +0 -90
- package/dist/fields/definitions/index.js +0 -99
- package/dist/fields/definitions/jsoneditor.json +0 -33
- package/dist/fields/definitions/map.json +0 -36
- package/dist/fields/definitions/multicheckbox.json +0 -47
- package/dist/fields/definitions/multistep.json +0 -35
- package/dist/fields/definitions/note.json +0 -16
- package/dist/fields/definitions/number.json +0 -42
- package/dist/fields/definitions/objectbuilder.json +0 -39
- package/dist/fields/definitions/placeholder.json +0 -15
- package/dist/fields/definitions/qrcodescanner.json +0 -16
- package/dist/fields/definitions/radio.json +0 -47
- package/dist/fields/definitions/renderfield.json +0 -36
- package/dist/fields/definitions/richtext.json +0 -16
- package/dist/fields/definitions/screenrecorder.json +0 -42
- package/dist/fields/definitions/screenshot.json +0 -42
- package/dist/fields/definitions/scrollandreaddisplay.json +0 -49
- package/dist/fields/definitions/section.json +0 -50
- package/dist/fields/definitions/select.json +0 -47
- package/dist/fields/definitions/selectresource.json +0 -48
- package/dist/fields/definitions/signature.json +0 -16
- package/dist/fields/definitions/slider.json +0 -78
- package/dist/fields/definitions/smarttext.json +0 -101
- package/dist/fields/definitions/telephone.json +0 -16
- package/dist/fields/definitions/text.json +0 -35
- package/dist/fields/definitions/validfieldtype.json +0 -220
- package/dist/fields/definitions/voicenote.json +0 -43
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -3
- package/dist/thirdparty/mapbox/GeoCoder.svelte +0 -10
- package/dist/thirdparty/mapbox/GeoCoder.svelte.d.ts +0 -27
- package/dist/thirdparty/mapbox/Map.svelte +0 -30
- package/dist/thirdparty/mapbox/Map.svelte.d.ts +0 -22
- package/dist/thirdparty/mapbox/MapMarker.svelte +0 -13
- package/dist/thirdparty/mapbox/MapMarker.svelte.d.ts +0 -33
- package/dist/utils/createField.d.ts +0 -6
- package/dist/utils/createField.js +0 -33
- package/dist/utils/createForm.d.ts +0 -1
- package/dist/utils/createForm.js +0 -501
- package/dist/utils/index.d.ts +0 -18
- package/dist/utils/index.js +0 -126
- package/dist/utils/syncing.d.ts +0 -11
- package/dist/utils/syncing.js +0 -134
- /package/dist/{fields2 → form-fields}/FieldExprToggle.svelte +0 -0
- /package/dist/{fields2 → form-fields}/FieldExprToggle.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/FieldLabel.svelte +0 -0
- /package/dist/{fields2 → form-fields}/FieldLabel.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/FieldMessage.svelte +0 -0
- /package/dist/{fields2 → form-fields}/FieldMessage.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/Form.svelte +0 -0
- /package/dist/{fields2 → form-fields}/Form.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/fileserver.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/fileserver.js +0 -0
- /package/dist/{fields2 → form-fields}/form-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/form-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/index.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/index.js +0 -0
- /package/dist/{fields2 → form-fields}/interfaces.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/interfaces.js +0 -0
- /package/dist/{fields2 → form-fields}/sub/array-builder-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/array-builder-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/checkbox-autocomplete.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/checkbox-autocomplete.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/checkbox-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/checkbox-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/code-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/code-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/contact-selector-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/contact-selector-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/currency-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/data-indication-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/data-indication-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/date-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/date-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/date-time-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/date-time-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/email-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/email-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/field-builder-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/field-builder-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/file-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/file-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/grid-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/grid-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/heading-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/heading-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/hidden-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/hidden-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/hidden-location-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/hidden-location-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/html-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/html-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/json-editor-bound.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/json-editor-bound.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/jsoneditor-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/jsoneditor-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/map-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/map-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/multi-checkbox-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/multi-checkbox-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/multistep-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/multistep-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/note-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/note-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/number-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/number-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/object-builder-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/object-builder-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/qr-code-scanner-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/qr-code-scanner-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/radio-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/radio-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/screenrecorder-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/screenrecorder-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/screenshot-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/screenshot-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/scroll-and-read-display-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/scroll-and-read-display-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/section-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/section-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/select-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/selectresource-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/selectresource-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/signature-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/signature-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/slider-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/slider-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/smart-text-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/smart-text-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/telephone-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/telephone-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/text-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/text-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/sub/voicenote-field.svelte +0 -0
- /package/dist/{fields2 → form-fields}/sub/voicenote-field.svelte.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/validations/validate_field.d.ts +0 -0
- /package/dist/{fields2 → form-fields}/validations/validate_field.js +0 -0
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { syncStoreToStore } from "../../utils/syncing";
|
|
3
|
-
import { deepEqual } from "fast-equals";
|
|
4
|
-
import _ from "lodash-es";
|
|
5
|
-
import { onMount } from "svelte";
|
|
6
|
-
import { writable } from "svelte/store";
|
|
7
|
-
|
|
8
|
-
import { Label } from "@stubber/ui/label";
|
|
9
|
-
import { Checkbox } from "@stubber/ui/checkbox";
|
|
10
|
-
|
|
11
|
-
export let field;
|
|
12
|
-
|
|
13
|
-
const internal = writable();
|
|
14
|
-
let outer;
|
|
15
|
-
|
|
16
|
-
$: state_key = $field.state?.state_key;
|
|
17
|
-
$: label = $field.spec?.title;
|
|
18
|
-
$: hide_label = $field.spec?.hide_label;
|
|
19
|
-
$: isValid = !$field.state?.validation || $field.state?.validation?.valid;
|
|
20
|
-
$: validationMessage = $field.state?.validation?.message;
|
|
21
|
-
$: displaytext = $field.spec?.params?.displaytext || "";
|
|
22
|
-
$: checkedvalue =
|
|
23
|
-
$field.spec?.params?.checkedvalue !== undefined ? $field.spec?.params?.checkedvalue : true;
|
|
24
|
-
$: uncheckedvalue =
|
|
25
|
-
$field.spec?.params?.uncheckedvalue !== undefined ? $field.spec?.params?.uncheckedvalue : false;
|
|
26
|
-
|
|
27
|
-
function handleScroll() {
|
|
28
|
-
let scroll_percentage = Math.ceil(
|
|
29
|
-
(outer?.scrollTop * 100) / (outer?.scrollHeight - outer.clientHeight)
|
|
30
|
-
);
|
|
31
|
-
if (outer?.scrollHeight - outer.clientHeight === 0) scroll_percentage = 100;
|
|
32
|
-
if (!$internal.scrolled_to_bottom) $internal.scrolled_to_bottom = scroll_percentage >= 99;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
onMount(() => {
|
|
36
|
-
// set field values that aren't set yet
|
|
37
|
-
let f = _.cloneDeep($field);
|
|
38
|
-
let checked = deepEqual(f?.data?.base, checkedvalue);
|
|
39
|
-
let initial_data = {
|
|
40
|
-
...f?.data,
|
|
41
|
-
base: checked ? checkedvalue : uncheckedvalue,
|
|
42
|
-
};
|
|
43
|
-
if (!f?.spec?.without_value_details) initial_data.base_label = label;
|
|
44
|
-
let initial_state_internal = {
|
|
45
|
-
...f?.state?.internal,
|
|
46
|
-
checked,
|
|
47
|
-
scrolled_to_bottom: checked,
|
|
48
|
-
};
|
|
49
|
-
_.set(f, "data", initial_data);
|
|
50
|
-
_.set(f, "state.internal", initial_state_internal);
|
|
51
|
-
if (!deepEqual(f, $field)) $field = f;
|
|
52
|
-
|
|
53
|
-
syncStoreToStore(
|
|
54
|
-
field,
|
|
55
|
-
internal,
|
|
56
|
-
(a, b) => {
|
|
57
|
-
let _clone = _.cloneDeep(a.state?.internal) || {};
|
|
58
|
-
|
|
59
|
-
// get parts from data
|
|
60
|
-
_clone.checked = deepEqual(a?.data?.base, checkedvalue);
|
|
61
|
-
if (_clone.checked) _clone.scrolled_to_bottom = true;
|
|
62
|
-
|
|
63
|
-
// set field state if changed
|
|
64
|
-
if (!deepEqual(a?.state?.internal, _clone)) {
|
|
65
|
-
$field.state.internal = _clone;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return _clone;
|
|
69
|
-
},
|
|
70
|
-
(a, b) => {
|
|
71
|
-
let _clone = _.cloneDeep(a) || {};
|
|
72
|
-
// update the state
|
|
73
|
-
_.set(_clone, "state.internal", _.cloneDeep(b));
|
|
74
|
-
// update the data
|
|
75
|
-
_.set(_clone, "data.base", b?.checked ? checkedvalue : uncheckedvalue);
|
|
76
|
-
return _clone;
|
|
77
|
-
}
|
|
78
|
-
);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
$: if (outer) handleScroll();
|
|
82
|
-
</script>
|
|
83
|
-
|
|
84
|
-
{#if $internal}
|
|
85
|
-
<div class="flex flex-col w-full text-surface-900 my-2">
|
|
86
|
-
<!-- div with inner shadow -->
|
|
87
|
-
<div
|
|
88
|
-
bind:this={outer}
|
|
89
|
-
class="border max-h-[300px] overflow-y-scroll shadow-inner rounded-md"
|
|
90
|
-
on:scroll={handleScroll}
|
|
91
|
-
>
|
|
92
|
-
<div class="p-6 px-2">
|
|
93
|
-
{@html displaytext}
|
|
94
|
-
</div>
|
|
95
|
-
</div>
|
|
96
|
-
<div
|
|
97
|
-
class="{!$internal.scrolled_to_bottom
|
|
98
|
-
? 'opacity-20'
|
|
99
|
-
: ''} flex space-x-3 relative mt-2 items-center {!isValid
|
|
100
|
-
? 'border-b border-warning-500'
|
|
101
|
-
: ''}"
|
|
102
|
-
>
|
|
103
|
-
<Checkbox
|
|
104
|
-
disabled={!$internal.scrolled_to_bottom}
|
|
105
|
-
on:keydown={(e) => {
|
|
106
|
-
if (e.key === "Enter") {
|
|
107
|
-
e.preventDefault();
|
|
108
|
-
}
|
|
109
|
-
}}
|
|
110
|
-
id="input_{state_key}"
|
|
111
|
-
name={state_key}
|
|
112
|
-
bind:checked={$internal.checked}
|
|
113
|
-
/>
|
|
114
|
-
<Label for="input_{state_key}" class="block {hide_label ? 'hidden' : ''}">
|
|
115
|
-
{label}
|
|
116
|
-
</Label>
|
|
117
|
-
</div>
|
|
118
|
-
{#if validationMessage}
|
|
119
|
-
<Label class={!isValid ? `text-danger-500` : `text-success-500`}>{validationMessage}</Label>
|
|
120
|
-
{/if}
|
|
121
|
-
</div>
|
|
122
|
-
{/if}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/** @typedef {typeof __propDef.props} ScrollandreaddisplayProps */
|
|
2
|
-
/** @typedef {typeof __propDef.events} ScrollandreaddisplayEvents */
|
|
3
|
-
/** @typedef {typeof __propDef.slots} ScrollandreaddisplaySlots */
|
|
4
|
-
export default class Scrollandreaddisplay extends SvelteComponent<{
|
|
5
|
-
field: any;
|
|
6
|
-
}, {
|
|
7
|
-
[evt: string]: CustomEvent<any>;
|
|
8
|
-
}, {}> {
|
|
9
|
-
}
|
|
10
|
-
export type ScrollandreaddisplayProps = typeof __propDef.props;
|
|
11
|
-
export type ScrollandreaddisplayEvents = typeof __propDef.events;
|
|
12
|
-
export type ScrollandreaddisplaySlots = typeof __propDef.slots;
|
|
13
|
-
import { SvelteComponent } from "svelte";
|
|
14
|
-
declare const __propDef: {
|
|
15
|
-
props: {
|
|
16
|
-
field: any;
|
|
17
|
-
};
|
|
18
|
-
events: {
|
|
19
|
-
[evt: string]: CustomEvent<any>;
|
|
20
|
-
};
|
|
21
|
-
slots: {};
|
|
22
|
-
exports?: undefined;
|
|
23
|
-
bindings?: undefined;
|
|
24
|
-
};
|
|
25
|
-
export {};
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import * as Accordion from "@stubber/ui/accordion";
|
|
3
|
-
import { Label } from "@stubber/ui/label";
|
|
4
|
-
import Field from "../../Field.svelte";
|
|
5
|
-
import * as utils from "../../utils/index.js";
|
|
6
|
-
|
|
7
|
-
export let form;
|
|
8
|
-
export let field;
|
|
9
|
-
|
|
10
|
-
let collapsed = $field.spec?.params?.collapsed ?? false;
|
|
11
|
-
|
|
12
|
-
$: state_key = $field?.state?.state_key;
|
|
13
|
-
$: label = $field?.spec?.title;
|
|
14
|
-
$: hide_label = $field?.spec?.hide_label;
|
|
15
|
-
$: isValid = !$field.state?.validation || $field.state?.validation?.valid;
|
|
16
|
-
$: validationMessage = $field.state?.validation?.message;
|
|
17
|
-
$: collapsible = $field.spec?.params?.collapsible ?? false;
|
|
18
|
-
$: fields = utils.getFieldsToRender($field.spec?.fields);
|
|
19
|
-
|
|
20
|
-
$: allChildrenConditionsChecked = Object.values($form?.state || {})
|
|
21
|
-
?.filter((s) => s && s.parent_field_state_key === state_key)
|
|
22
|
-
?.reduce((acc, child_state) => {
|
|
23
|
-
if (!child_state?.conditions_checked) acc = false;
|
|
24
|
-
return acc;
|
|
25
|
-
}, true);
|
|
26
|
-
|
|
27
|
-
$: section_class = $field.spec?.params?.section_class ?? "pl-4";
|
|
28
|
-
$: label_class = $field.spec?.params?.label_class ?? "font-regular text-sm";
|
|
29
|
-
|
|
30
|
-
// Hook the Accordion's value up to collapse logic
|
|
31
|
-
let accordionValue = collapsed ? "" : "item-1";
|
|
32
|
-
|
|
33
|
-
function handleValueChange(value) {
|
|
34
|
-
// console.log("Accordion value changed to:", value);
|
|
35
|
-
collapsed = value !== "item-1";
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Debug: Track changes in your reactive variables.
|
|
39
|
-
// $: console.log("allChildrenConditionsChecked =>", allChildrenConditionsChecked);
|
|
40
|
-
// $: console.log("collapsed =>", collapsed);
|
|
41
|
-
// $: console.log("accordionValue =>", accordionValue);
|
|
42
|
-
</script>
|
|
43
|
-
|
|
44
|
-
<div class="fade-container {!allChildrenConditionsChecked ? 'fade-hidden' : ''}">
|
|
45
|
-
<Accordion.Root
|
|
46
|
-
bind:value={accordionValue}
|
|
47
|
-
on:valueChange={handleValueChange}
|
|
48
|
-
type="single"
|
|
49
|
-
{collapsible}
|
|
50
|
-
class="flex flex-col w-full text-surface-900"
|
|
51
|
-
>
|
|
52
|
-
<Accordion.Item value="item-1">
|
|
53
|
-
<Accordion.Trigger class="flex items-center justify-between py-1">
|
|
54
|
-
<Label for="input_{state_key}" class="block {label_class} {hide_label ? 'hidden' : ''}">
|
|
55
|
-
{label}
|
|
56
|
-
</Label>
|
|
57
|
-
</Accordion.Trigger>
|
|
58
|
-
<Accordion.Content class="{section_class} -pl-4 pt-2">
|
|
59
|
-
{#if fields}
|
|
60
|
-
{#each fields as initial_field_spec (initial_field_spec.__key)}
|
|
61
|
-
<Field {form} {initial_field_spec} parent_field={field} />
|
|
62
|
-
{/each}
|
|
63
|
-
{/if}
|
|
64
|
-
|
|
65
|
-
{#if validationMessage}
|
|
66
|
-
<Label class={!isValid ? `text-danger-500` : `text-success-500`}
|
|
67
|
-
>{validationMessage}</Label
|
|
68
|
-
>
|
|
69
|
-
{/if}
|
|
70
|
-
</Accordion.Content>
|
|
71
|
-
</Accordion.Item>
|
|
72
|
-
</Accordion.Root>
|
|
73
|
-
</div>
|
|
74
|
-
|
|
75
|
-
<style>
|
|
76
|
-
/*
|
|
77
|
-
1. .fade-container: By default visible, but transitions changes in opacity.
|
|
78
|
-
2. .fade-hidden: Sets opacity to 0, so it fades out over 0.3s.
|
|
79
|
-
*/
|
|
80
|
-
.fade-container {
|
|
81
|
-
transition: opacity 0.5s ease-in-out;
|
|
82
|
-
opacity: 1; /* fully visible by default */
|
|
83
|
-
}
|
|
84
|
-
.fade-hidden {
|
|
85
|
-
opacity: 0; /* hidden via fade */
|
|
86
|
-
}
|
|
87
|
-
</style>
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/** @typedef {typeof __propDef.props} SectionProps */
|
|
2
|
-
/** @typedef {typeof __propDef.events} SectionEvents */
|
|
3
|
-
/** @typedef {typeof __propDef.slots} SectionSlots */
|
|
4
|
-
export default class Section extends SvelteComponent<{
|
|
5
|
-
form: any;
|
|
6
|
-
field: any;
|
|
7
|
-
}, {
|
|
8
|
-
[evt: string]: CustomEvent<any>;
|
|
9
|
-
}, {}> {
|
|
10
|
-
}
|
|
11
|
-
export type SectionProps = typeof __propDef.props;
|
|
12
|
-
export type SectionEvents = typeof __propDef.events;
|
|
13
|
-
export type SectionSlots = typeof __propDef.slots;
|
|
14
|
-
import { SvelteComponent } from "svelte";
|
|
15
|
-
declare const __propDef: {
|
|
16
|
-
props: {
|
|
17
|
-
form: any;
|
|
18
|
-
field: any;
|
|
19
|
-
};
|
|
20
|
-
events: {
|
|
21
|
-
[evt: string]: CustomEvent<any>;
|
|
22
|
-
};
|
|
23
|
-
slots: {};
|
|
24
|
-
exports?: undefined;
|
|
25
|
-
bindings?: undefined;
|
|
26
|
-
};
|
|
27
|
-
export {};
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { onMount, tick } from "svelte";
|
|
3
|
-
import { createState } from "cmdk-sv";
|
|
4
|
-
import { Label } from "@stubber/ui/label";
|
|
5
|
-
import * as Command from "@stubber/ui/command";
|
|
6
|
-
import * as Popover from "@stubber/ui/popover";
|
|
7
|
-
import { Button } from "@stubber/ui/button";
|
|
8
|
-
import { debounce, isArray, isEqual } from "lodash-es";
|
|
9
|
-
|
|
10
|
-
export let field;
|
|
11
|
-
|
|
12
|
-
// instead of contactselector and resourceselector being separate components,
|
|
13
|
-
// form fields should expose this through form.dependencies so people can dynamically load things as they whish.
|
|
14
|
-
// for now though, contactselector and resourceselector just tie into this function
|
|
15
|
-
export let load_options;
|
|
16
|
-
|
|
17
|
-
$: state_key = $field.state?.state_key;
|
|
18
|
-
$: label = $field.spec?.title;
|
|
19
|
-
$: hide_label = $field.spec?.hide_label;
|
|
20
|
-
$: isValid = !$field.state?.validation || $field.state?.validation?.valid;
|
|
21
|
-
$: validationMessage = $field.state?.validation?.message;
|
|
22
|
-
let items = [];
|
|
23
|
-
|
|
24
|
-
$: {
|
|
25
|
-
if (isArray($field.spec?.params?.options)) {
|
|
26
|
-
items = $field.spec?.params?.options?.map((o, index) => {
|
|
27
|
-
let { label, value } = o || {};
|
|
28
|
-
let _value = value !== undefined ? value : label;
|
|
29
|
-
let _label = label ?? value;
|
|
30
|
-
let _key = `${state_key}${label}${index}`;
|
|
31
|
-
return { _key, _label, _value };
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
onMount(() => {
|
|
37
|
-
if ($field.data.base && !$field.spec?.without_value_details) {
|
|
38
|
-
// If the field has a base value, we need to find the corresponding label
|
|
39
|
-
const item = items.find((i) => isEqual(i._value, $field.data.base));
|
|
40
|
-
if (item) {
|
|
41
|
-
$field.data.base_label = item._label;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
function simpleSetSelected(item_key) {
|
|
47
|
-
const item = items.find((i) => i._key === item_key);
|
|
48
|
-
if (!item) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
field.update((f) => {
|
|
53
|
-
f.data.base = item?._value;
|
|
54
|
-
if (!f.spec?.without_value_details) {
|
|
55
|
-
f.data.base_label = item?._label;
|
|
56
|
-
}
|
|
57
|
-
return f;
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
let open = false;
|
|
62
|
-
let loading = false;
|
|
63
|
-
|
|
64
|
-
$: dropdownLabel =
|
|
65
|
-
items.find((i) => isEqual(i._value, $field.data.base))?._label ??
|
|
66
|
-
$field.data?.base_label ??
|
|
67
|
-
"Select...";
|
|
68
|
-
// We want to refocus the trigger button when the user selects
|
|
69
|
-
// an item from the list so users can continue navigating the
|
|
70
|
-
// rest of the form with the keyboard.
|
|
71
|
-
function closeAndFocusTrigger(triggerId) {
|
|
72
|
-
open = false;
|
|
73
|
-
tick().then(() => {
|
|
74
|
-
document.getElementById(triggerId)?.focus();
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const state = createState();
|
|
79
|
-
|
|
80
|
-
let last_search = undefined;
|
|
81
|
-
const handle_search = async (search) => {
|
|
82
|
-
if (search === last_search) return;
|
|
83
|
-
last_search = search;
|
|
84
|
-
|
|
85
|
-
if (load_options) {
|
|
86
|
-
loading = true;
|
|
87
|
-
const remote_results = await load_options($state.search);
|
|
88
|
-
loading = false;
|
|
89
|
-
|
|
90
|
-
items = remote_results.map((o, index) => {
|
|
91
|
-
let { label, value } = o || {};
|
|
92
|
-
let _value = value !== undefined ? value : label;
|
|
93
|
-
let _label = label ?? value;
|
|
94
|
-
let _key = `${state_key}${label}${index}`;
|
|
95
|
-
return { _key, _label, _value };
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
let debounced_handle_search = null;
|
|
101
|
-
if (load_options) {
|
|
102
|
-
debounced_handle_search = debounce(handle_search, 300);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
$: if (load_options && $state.search !== undefined) {
|
|
106
|
-
debounced_handle_search($state.search);
|
|
107
|
-
}
|
|
108
|
-
</script>
|
|
109
|
-
|
|
110
|
-
<div class="flex flex-col w-full text-surface-900 my-2">
|
|
111
|
-
<Label for="input_{state_key}" class="block py-2 {hide_label ? 'hidden' : ''}">
|
|
112
|
-
{label}
|
|
113
|
-
</Label>
|
|
114
|
-
<Popover.Root bind:open let:ids>
|
|
115
|
-
<Popover.Trigger asChild let:builder>
|
|
116
|
-
<Button
|
|
117
|
-
builders={[builder]}
|
|
118
|
-
variant="outline"
|
|
119
|
-
role="combobox"
|
|
120
|
-
aria-expanded={open}
|
|
121
|
-
class="w-full border-input bg-white bg-opacity-[15] ring-offset-background placeholder:text-muted-foreground focus-visible:ring-ring flex h-10 rounded-md border px-3 py-2 text-sm file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 justify-between"
|
|
122
|
-
style="box-shadow: inset 0px 16px 16px -16px rgba(0, 0, 0, 0.1333);"
|
|
123
|
-
>
|
|
124
|
-
{dropdownLabel}
|
|
125
|
-
<i class="fas fa-sort ml-2 h-4 w-4 shrink-0 opacity-50" />
|
|
126
|
-
</Button>
|
|
127
|
-
</Popover.Trigger>
|
|
128
|
-
<Popover.Content sameWidth class="p-0 z-[100]">
|
|
129
|
-
<Command.Root shouldFilter={!load_options} {state}>
|
|
130
|
-
<Command.Input class="border-none outline-none focus:ring-0" placeholder="Search..." />
|
|
131
|
-
<Command.List>
|
|
132
|
-
{#if loading}
|
|
133
|
-
<Command.Loading class="py-6 text-sm text-center">Loading…</Command.Loading>
|
|
134
|
-
{:else}
|
|
135
|
-
<Command.Empty>No results found.</Command.Empty>
|
|
136
|
-
|
|
137
|
-
{#each items as item}
|
|
138
|
-
<Command.Item
|
|
139
|
-
value={item._key}
|
|
140
|
-
onSelect={(item_key) => {
|
|
141
|
-
simpleSetSelected(item_key);
|
|
142
|
-
closeAndFocusTrigger(ids.trigger);
|
|
143
|
-
}}
|
|
144
|
-
class={$field.data.base === item._value ? "bg-primary-100" : ""}
|
|
145
|
-
>
|
|
146
|
-
{item._label}
|
|
147
|
-
</Command.Item>
|
|
148
|
-
{/each}
|
|
149
|
-
{/if}
|
|
150
|
-
</Command.List>
|
|
151
|
-
</Command.Root>
|
|
152
|
-
</Popover.Content>
|
|
153
|
-
</Popover.Root>
|
|
154
|
-
|
|
155
|
-
<!-- slot used by ContactSelector to place a create button above the validation error -->
|
|
156
|
-
<slot />
|
|
157
|
-
|
|
158
|
-
{#if validationMessage}
|
|
159
|
-
<Label class={!isValid ? `text-danger-500` : `text-success-500`}>{validationMessage}</Label>
|
|
160
|
-
{/if}
|
|
161
|
-
</div>
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/** @typedef {typeof __propDef.props} SelectProps */
|
|
2
|
-
/** @typedef {typeof __propDef.events} SelectEvents */
|
|
3
|
-
/** @typedef {typeof __propDef.slots} SelectSlots */
|
|
4
|
-
export default class Select extends SvelteComponent<{
|
|
5
|
-
field: any;
|
|
6
|
-
load_options: any;
|
|
7
|
-
}, {
|
|
8
|
-
[evt: string]: CustomEvent<any>;
|
|
9
|
-
}, {
|
|
10
|
-
default: {};
|
|
11
|
-
}> {
|
|
12
|
-
}
|
|
13
|
-
export type SelectProps = typeof __propDef.props;
|
|
14
|
-
export type SelectEvents = typeof __propDef.events;
|
|
15
|
-
export type SelectSlots = typeof __propDef.slots;
|
|
16
|
-
import { SvelteComponent } from "svelte";
|
|
17
|
-
declare const __propDef: {
|
|
18
|
-
props: {
|
|
19
|
-
field: any;
|
|
20
|
-
load_options: any;
|
|
21
|
-
};
|
|
22
|
-
events: {
|
|
23
|
-
[evt: string]: CustomEvent<any>;
|
|
24
|
-
};
|
|
25
|
-
slots: {
|
|
26
|
-
default: {};
|
|
27
|
-
};
|
|
28
|
-
exports?: undefined;
|
|
29
|
-
bindings?: undefined;
|
|
30
|
-
};
|
|
31
|
-
export {};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { onMount } from "svelte";
|
|
3
|
-
import _ from "lodash-es";
|
|
4
|
-
|
|
5
|
-
import Select from "./Select.svelte";
|
|
6
|
-
|
|
7
|
-
export let form;
|
|
8
|
-
export let field;
|
|
9
|
-
|
|
10
|
-
$: resource_name = $field.spec?.params?.resource_name;
|
|
11
|
-
|
|
12
|
-
let dependencies = form.dependencies;
|
|
13
|
-
let clienthub = dependencies?.clienthub;
|
|
14
|
-
let stubber = dependencies?.stubber;
|
|
15
|
-
let socket = clienthub?.socket;
|
|
16
|
-
let stubref = stubber?.stubref;
|
|
17
|
-
let orguuid = stubber?.orguuid;
|
|
18
|
-
|
|
19
|
-
onMount(() => {});
|
|
20
|
-
|
|
21
|
-
const load_options = async (search_term) => {
|
|
22
|
-
if (!clienthub) return [];
|
|
23
|
-
|
|
24
|
-
const details = {
|
|
25
|
-
resource_name,
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
details.params = structuredClone($field.spec.params) || {};
|
|
29
|
-
// add required/dynamic params (orguuid, stubref, input, and limit)
|
|
30
|
-
details.params.orguuid = orguuid;
|
|
31
|
-
details.params.stubref = stubref;
|
|
32
|
-
details.params.input = search_term;
|
|
33
|
-
if (details.params.limit === undefined) {
|
|
34
|
-
details.params.limit = 50;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return new Promise((resolve, reject) => {
|
|
38
|
-
socket.emit("request", { type: "resource", details }, (res) => {
|
|
39
|
-
if (res.success) {
|
|
40
|
-
const resources = res.payload?.[resource_name] || [];
|
|
41
|
-
// console.log("Loaded resources:", resources);
|
|
42
|
-
const result = resources.map((resource) => ({
|
|
43
|
-
value: resource,
|
|
44
|
-
label:
|
|
45
|
-
resource[$field.spec?.params?.label || $field.spec.label] ?? resource._default_label,
|
|
46
|
-
}));
|
|
47
|
-
resolve(result);
|
|
48
|
-
} else {
|
|
49
|
-
console.error("Failed to load resource:", res);
|
|
50
|
-
resolve([]);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
</script>
|
|
56
|
-
|
|
57
|
-
<Select {field} {load_options} />
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/** @typedef {typeof __propDef.props} SelectresourceProps */
|
|
2
|
-
/** @typedef {typeof __propDef.events} SelectresourceEvents */
|
|
3
|
-
/** @typedef {typeof __propDef.slots} SelectresourceSlots */
|
|
4
|
-
export default class Selectresource extends SvelteComponent<{
|
|
5
|
-
form: any;
|
|
6
|
-
field: any;
|
|
7
|
-
}, {
|
|
8
|
-
[evt: string]: CustomEvent<any>;
|
|
9
|
-
}, {}> {
|
|
10
|
-
}
|
|
11
|
-
export type SelectresourceProps = typeof __propDef.props;
|
|
12
|
-
export type SelectresourceEvents = typeof __propDef.events;
|
|
13
|
-
export type SelectresourceSlots = typeof __propDef.slots;
|
|
14
|
-
import { SvelteComponent } from "svelte";
|
|
15
|
-
declare const __propDef: {
|
|
16
|
-
props: {
|
|
17
|
-
form: any;
|
|
18
|
-
field: any;
|
|
19
|
-
};
|
|
20
|
-
events: {
|
|
21
|
-
[evt: string]: CustomEvent<any>;
|
|
22
|
-
};
|
|
23
|
-
slots: {};
|
|
24
|
-
exports?: undefined;
|
|
25
|
-
bindings?: undefined;
|
|
26
|
-
};
|
|
27
|
-
export {};
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import SignaturePad from "signature_pad";
|
|
3
|
-
import _ from "lodash-es";
|
|
4
|
-
import { onMount } from "svelte";
|
|
5
|
-
import { deepEqual } from "fast-equals";
|
|
6
|
-
import { writable } from "svelte/store";
|
|
7
|
-
import { syncStoreToStore } from "../../utils/syncing";
|
|
8
|
-
|
|
9
|
-
import { Label } from "@stubber/ui/label";
|
|
10
|
-
import { Button } from "@stubber/ui/button";
|
|
11
|
-
|
|
12
|
-
export let form;
|
|
13
|
-
export let field;
|
|
14
|
-
|
|
15
|
-
const internal = writable({});
|
|
16
|
-
|
|
17
|
-
$: state_key = $field.state?.state_key;
|
|
18
|
-
$: label = $field.spec?.title;
|
|
19
|
-
$: hide_label = $field.spec?.hide_label;
|
|
20
|
-
|
|
21
|
-
$: isValid = !$field.state?.validation || $field.state?.validation?.valid;
|
|
22
|
-
$: validationMessage = $field.state?.validation?.message;
|
|
23
|
-
|
|
24
|
-
let canvasContainer;
|
|
25
|
-
let pad;
|
|
26
|
-
let signaturePad;
|
|
27
|
-
|
|
28
|
-
onMount(() => {
|
|
29
|
-
// set field values that aren't set yet
|
|
30
|
-
let f = _.cloneDeep($field);
|
|
31
|
-
|
|
32
|
-
let initial_value = f?.data?.base ?? {
|
|
33
|
-
data: [],
|
|
34
|
-
file: undefined,
|
|
35
|
-
};
|
|
36
|
-
let initial_data = {
|
|
37
|
-
...f?.data,
|
|
38
|
-
base: initial_value,
|
|
39
|
-
};
|
|
40
|
-
let initial_state_internal = {
|
|
41
|
-
value: initial_value,
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
_.set(f, "data", initial_data);
|
|
45
|
-
_.set(f, "state.internal", initial_state_internal);
|
|
46
|
-
if (!deepEqual(f, $field)) $field = f;
|
|
47
|
-
|
|
48
|
-
//init signature pad
|
|
49
|
-
signaturePad = new SignaturePad(pad);
|
|
50
|
-
signaturePad.addEventListener("endStroke", handleStroke);
|
|
51
|
-
setTimeout(() => {
|
|
52
|
-
let d = _.isArray($field.data?.base?.data) ? $field.data?.base?.data : [];
|
|
53
|
-
signaturePad.fromData(d);
|
|
54
|
-
}, 0);
|
|
55
|
-
|
|
56
|
-
syncStoreToStore(
|
|
57
|
-
field,
|
|
58
|
-
internal,
|
|
59
|
-
(a, b) => {
|
|
60
|
-
let _clone = _.cloneDeep(a.state?.internal) || {};
|
|
61
|
-
|
|
62
|
-
// get parts from data
|
|
63
|
-
_clone.value = a?.data?.base;
|
|
64
|
-
_clone.file = a?.data?.base?.file;
|
|
65
|
-
|
|
66
|
-
// set field state if changed
|
|
67
|
-
if (!deepEqual(a?.state?.internal, _clone)) {
|
|
68
|
-
$field.state.internal = _clone;
|
|
69
|
-
//update signature pad
|
|
70
|
-
let d = _.isArray(_clone.value) ? _clone.value : [];
|
|
71
|
-
signaturePad.fromData(d);
|
|
72
|
-
}
|
|
73
|
-
return _clone;
|
|
74
|
-
},
|
|
75
|
-
(a, b) => {
|
|
76
|
-
let _clone = _.cloneDeep(a) || {};
|
|
77
|
-
// update the state
|
|
78
|
-
_.set(_clone, "state.internal", _.cloneDeep(b));
|
|
79
|
-
// update the data
|
|
80
|
-
_.set(_clone, "data.base", b?.value);
|
|
81
|
-
return _clone;
|
|
82
|
-
}
|
|
83
|
-
);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
async function uploadFile() {
|
|
87
|
-
const fileURI = signaturePad.toDataURL();
|
|
88
|
-
const fileBlob = await (await fetch(fileURI)).blob();
|
|
89
|
-
const filesForm = new FormData();
|
|
90
|
-
filesForm.append(label, fileBlob);
|
|
91
|
-
let upload_res = await form.uploadFiles(null, filesForm);
|
|
92
|
-
let { uploaded_files } = upload_res;
|
|
93
|
-
if (uploaded_files?.length) {
|
|
94
|
-
if ($internal.value.file && $internal.value.file.fileuuid) {
|
|
95
|
-
form.removeAttachment($internal.value.file);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
$internal.value.file = uploaded_files[0];
|
|
99
|
-
form.appendAttachment(uploaded_files[0]);
|
|
100
|
-
} else {
|
|
101
|
-
console.warn("Failed to upload file");
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return true;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const debounced_upload = _.debounce(uploadFile, 1000);
|
|
108
|
-
|
|
109
|
-
function clear() {
|
|
110
|
-
signaturePad.clear();
|
|
111
|
-
$field.data.base = {
|
|
112
|
-
data: null,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function handleStroke() {
|
|
117
|
-
const data = signaturePad.toData();
|
|
118
|
-
let comparison = _.cloneDeep($internal);
|
|
119
|
-
comparison.value.data = _.cloneDeep(data);
|
|
120
|
-
comparison.upload = true;
|
|
121
|
-
|
|
122
|
-
if (!deepEqual(comparison, $internal)) {
|
|
123
|
-
$internal = comparison;
|
|
124
|
-
debounced_upload();
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
$: canvasWidth = canvasContainer?.clientWidth;
|
|
129
|
-
</script>
|
|
130
|
-
|
|
131
|
-
{#if $internal}
|
|
132
|
-
<div class="flex flex-col w-full text-surface-900">
|
|
133
|
-
<Label for="input_{state_key}" class=" {hide_label ? 'hidden' : ''}">
|
|
134
|
-
{label}
|
|
135
|
-
</Label>
|
|
136
|
-
<div bind:this={canvasContainer}>
|
|
137
|
-
<canvas
|
|
138
|
-
bind:this={pad}
|
|
139
|
-
id="signature-pad"
|
|
140
|
-
class="signature-pad mt-2 rounded-md border"
|
|
141
|
-
width={canvasWidth}
|
|
142
|
-
height={200}
|
|
143
|
-
/>
|
|
144
|
-
<div class="mt-1">
|
|
145
|
-
<Button variant="ghost" on:click={clear} type="button">Clear</Button>
|
|
146
|
-
</div>
|
|
147
|
-
</div>
|
|
148
|
-
{#if validationMessage}
|
|
149
|
-
<Label class={!isValid ? `text-danger-500` : `text-success-500`}>{validationMessage}</Label>
|
|
150
|
-
{/if}
|
|
151
|
-
</div>
|
|
152
|
-
{/if}
|