@sprucelabs/spruce-form-utils 18.5.38 → 18.5.40
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.
|
@@ -10,10 +10,10 @@ class FormPlayerCardViewController extends heartwood_view_controllers_1.Abstract
|
|
|
10
10
|
this.uploads = {};
|
|
11
11
|
const { onChange, isBusy, id, onSaveAndBeDone, doneButtonLabel, shouldRenderSaveProgressButton, additionalButtons, ...builderSource } = options;
|
|
12
12
|
this.builderSource = (0, heartwood_view_controllers_1.removeUniversalViewOptions)(builderSource);
|
|
13
|
-
this.doneButtonLabel = doneButtonLabel
|
|
13
|
+
this.doneButtonLabel = doneButtonLabel ?? 'Save and be done';
|
|
14
14
|
this.shouldRenderSaveProgressButton =
|
|
15
|
-
shouldRenderSaveProgressButton
|
|
16
|
-
this.additionalButtons = additionalButtons
|
|
15
|
+
shouldRenderSaveProgressButton ?? true;
|
|
16
|
+
this.additionalButtons = additionalButtons ?? [];
|
|
17
17
|
this.onSaveAndBeDoneHandler = onSaveAndBeDone;
|
|
18
18
|
this.swipeVc = this.SwipeVc(id, this.builderSource);
|
|
19
19
|
if (!options.pages || isBusy) {
|
|
@@ -37,9 +37,8 @@ class FormPlayerCardViewController extends heartwood_view_controllers_1.Abstract
|
|
|
37
37
|
this.updateFooter();
|
|
38
38
|
}
|
|
39
39
|
renderFooter() {
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
const currentPage = (_d = (_c = this.swipeVc) === null || _c === void 0 ? void 0 : _c.getPresentSlide()) !== null && _d !== void 0 ? _d : 0;
|
|
40
|
+
const totalPages = this.builderSource.pages?.length ?? 0;
|
|
41
|
+
const currentPage = this.swipeVc?.getPresentSlide() ?? 0;
|
|
43
42
|
const buttons = [...this.additionalButtons];
|
|
44
43
|
if (this.shouldRenderSaveProgressButton) {
|
|
45
44
|
buttons.push({
|
|
@@ -76,24 +75,22 @@ class FormPlayerCardViewController extends heartwood_view_controllers_1.Abstract
|
|
|
76
75
|
});
|
|
77
76
|
}
|
|
78
77
|
async handleClickSaveAndDone() {
|
|
79
|
-
var _a, _b;
|
|
80
78
|
if (this.onSaveAndBeDoneHandler) {
|
|
81
|
-
await
|
|
79
|
+
await this.onSaveAndBeDoneHandler?.();
|
|
82
80
|
return;
|
|
83
81
|
}
|
|
84
82
|
await this.alert({
|
|
85
83
|
message: `Progress saved, lets get outa here! 🚀`,
|
|
86
84
|
style: 'success',
|
|
87
85
|
});
|
|
88
|
-
await
|
|
86
|
+
await this.router?.redirect('profile.root');
|
|
89
87
|
}
|
|
90
88
|
async handleClickNext() {
|
|
91
89
|
await this.swipeVc.jumpToSlide(this.swipeVc.getPresentSlide() + 1);
|
|
92
90
|
}
|
|
93
91
|
renderHeader(options) {
|
|
94
|
-
var _a;
|
|
95
92
|
return {
|
|
96
|
-
title:
|
|
93
|
+
title: options.title ?? 'Loading your form...',
|
|
97
94
|
subtitle: options.subtitle,
|
|
98
95
|
};
|
|
99
96
|
}
|
|
@@ -101,8 +98,7 @@ class FormPlayerCardViewController extends heartwood_view_controllers_1.Abstract
|
|
|
101
98
|
this.swipeVc.setIsBusy(isLoading);
|
|
102
99
|
}
|
|
103
100
|
renderSlides(options) {
|
|
104
|
-
|
|
105
|
-
const slides = (_b = (_a = options.pages) === null || _a === void 0 ? void 0 : _a.map(({ title, ...form }) => {
|
|
101
|
+
const slides = options.pages?.map(({ title, ...form }) => {
|
|
106
102
|
const formVc = this.Controller('form', {
|
|
107
103
|
...form,
|
|
108
104
|
shouldShowSubmitControls: false,
|
|
@@ -114,16 +110,15 @@ class FormPlayerCardViewController extends heartwood_view_controllers_1.Abstract
|
|
|
114
110
|
title,
|
|
115
111
|
form: formVc.render(),
|
|
116
112
|
};
|
|
117
|
-
})
|
|
113
|
+
}) ?? [];
|
|
118
114
|
return slides;
|
|
119
115
|
}
|
|
120
116
|
async handleFormChange(formVc) {
|
|
121
|
-
var _a;
|
|
122
117
|
const schema = formVc.getSchema();
|
|
123
118
|
for (const [name, field] of Object.entries(schema.fields)) {
|
|
124
119
|
if (field.type === 'image' && formVc.isFieldRendering(name)) {
|
|
125
120
|
const value = formVc.getValue(name);
|
|
126
|
-
if (value &&
|
|
121
|
+
if (value && this.uploads[name]?.original !== value.base64) {
|
|
127
122
|
const file = await this.uploader.upload(value);
|
|
128
123
|
this.uploads[name] = {
|
|
129
124
|
original: value.base64,
|
|
@@ -135,9 +130,8 @@ class FormPlayerCardViewController extends heartwood_view_controllers_1.Abstract
|
|
|
135
130
|
await this.optionallyInvokeChangeHandler();
|
|
136
131
|
}
|
|
137
132
|
async optionallyInvokeChangeHandler() {
|
|
138
|
-
var _a;
|
|
139
133
|
if (!this.shouldIgnoreChanges) {
|
|
140
|
-
await
|
|
134
|
+
await this.onChangeHandler?.({ values: this.getValues() });
|
|
141
135
|
}
|
|
142
136
|
}
|
|
143
137
|
getHasCriticalError() {
|
|
@@ -156,8 +150,8 @@ class FormPlayerCardViewController extends heartwood_view_controllers_1.Abstract
|
|
|
156
150
|
const { router, ...source } = options;
|
|
157
151
|
const { title, subtitle } = this.renderHeader(source);
|
|
158
152
|
this.router = router;
|
|
159
|
-
this.swipeVc.setHeaderTitle(title
|
|
160
|
-
this.swipeVc.setHeaderSubtitle(subtitle
|
|
153
|
+
this.swipeVc.setHeaderTitle(title ?? null);
|
|
154
|
+
this.swipeVc.setHeaderSubtitle(subtitle ?? null);
|
|
161
155
|
if (source.pages) {
|
|
162
156
|
this.swipeVc.setSections(this.renderSlides(source));
|
|
163
157
|
}
|
|
@@ -198,9 +192,9 @@ class FormPlayerCardViewController extends heartwood_view_controllers_1.Abstract
|
|
|
198
192
|
return values;
|
|
199
193
|
}
|
|
200
194
|
getFormVcs() {
|
|
201
|
-
var _a;
|
|
202
195
|
const slides = this.swipeVc.getSlides();
|
|
203
|
-
return (
|
|
196
|
+
return (slides?.map((s) => s.form?.controller) ??
|
|
197
|
+
[]);
|
|
204
198
|
}
|
|
205
199
|
getFormVc(idx) {
|
|
206
200
|
const formVc = this.getFormVcs()[idx];
|
|
@@ -23,16 +23,15 @@ function validateOptions(pages, values) {
|
|
|
23
23
|
}
|
|
24
24
|
const formCompletionCalculator = {
|
|
25
25
|
calculate(pages, values) {
|
|
26
|
-
var _a, _b, _c, _d;
|
|
27
26
|
validateOptions(pages, values);
|
|
28
27
|
const requiredFields = [];
|
|
29
28
|
let totalFields = 0;
|
|
30
29
|
for (const page of pages) {
|
|
31
|
-
const fields =
|
|
30
|
+
const fields = page.schema.fields ?? {};
|
|
32
31
|
for (const section of page.sections) {
|
|
33
|
-
for (const field of
|
|
34
|
-
const fieldKey =
|
|
35
|
-
const f =
|
|
32
|
+
for (const field of section.fields ?? []) {
|
|
33
|
+
const fieldKey = field.name ?? field;
|
|
34
|
+
const f = fields[fieldKey] ?? {};
|
|
36
35
|
if (f.isRequired) {
|
|
37
36
|
totalFields++;
|
|
38
37
|
requiredFields.push(fieldKey);
|
|
@@ -45,7 +44,7 @@ const formCompletionCalculator = {
|
|
|
45
44
|
}
|
|
46
45
|
let totalAnswered = 0;
|
|
47
46
|
for (const value of values) {
|
|
48
|
-
totalAnswered += Object.keys(value
|
|
47
|
+
totalAnswered += Object.keys(value ?? {}).filter((k) => {
|
|
49
48
|
return !!value[k] && requiredFields.indexOf(k) !== -1;
|
|
50
49
|
}).length;
|
|
51
50
|
}
|
|
@@ -36,7 +36,7 @@ class RemoteFormCardViewController extends heartwood_view_controllers_1.Abstract
|
|
|
36
36
|
this.organizationId = target.organizationId;
|
|
37
37
|
await this.playerVc.load({
|
|
38
38
|
...form,
|
|
39
|
-
values: values
|
|
39
|
+
values: values ?? [],
|
|
40
40
|
router: this.router,
|
|
41
41
|
});
|
|
42
42
|
return results;
|
|
@@ -62,7 +62,6 @@ class RemoteFormCardViewController extends heartwood_view_controllers_1.Abstract
|
|
|
62
62
|
async handlePlayerChange() {
|
|
63
63
|
clearTimeout(this.saveDebounceTimeout);
|
|
64
64
|
this.saveDebounceTimeout = setTimeout(async () => {
|
|
65
|
-
var _a;
|
|
66
65
|
try {
|
|
67
66
|
const client = await this.connectToApi();
|
|
68
67
|
const [{ completedFormId }] = await client.emitAndFlattenResponses('forms.update-completed-form::v2021_07_02', {
|
|
@@ -72,7 +71,7 @@ class RemoteFormCardViewController extends heartwood_view_controllers_1.Abstract
|
|
|
72
71
|
},
|
|
73
72
|
target: {
|
|
74
73
|
completedFormId: this.completedFormId,
|
|
75
|
-
organizationId:
|
|
74
|
+
organizationId: this.organizationId ?? 'NO ORG',
|
|
76
75
|
},
|
|
77
76
|
});
|
|
78
77
|
this.completedFormId = completedFormId;
|