@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 !== null && doneButtonLabel !== void 0 ? doneButtonLabel : 'Save and be done';
13
+ this.doneButtonLabel = doneButtonLabel ?? 'Save and be done';
14
14
  this.shouldRenderSaveProgressButton =
15
- shouldRenderSaveProgressButton !== null && shouldRenderSaveProgressButton !== void 0 ? shouldRenderSaveProgressButton : true;
16
- this.additionalButtons = additionalButtons !== null && additionalButtons !== void 0 ? 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
- var _a, _b, _c, _d;
41
- const totalPages = (_b = (_a = this.builderSource.pages) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
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 ((_a = this.onSaveAndBeDoneHandler) === null || _a === void 0 ? void 0 : _a.call(this));
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 ((_b = this.router) === null || _b === void 0 ? void 0 : _b.redirect('profile.root'));
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: (_a = options.title) !== null && _a !== void 0 ? _a : 'Loading your form...',
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
- var _a, _b;
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
- })) !== null && _b !== void 0 ? _b : [];
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 && ((_a = this.uploads[name]) === null || _a === void 0 ? void 0 : _a.original) !== value.base64) {
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 ((_a = this.onChangeHandler) === null || _a === void 0 ? void 0 : _a.call(this, { values: this.getValues() }));
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 !== null && title !== void 0 ? title : null);
160
- this.swipeVc.setHeaderSubtitle(subtitle !== null && subtitle !== void 0 ? subtitle : null);
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 ((_a = slides === null || slides === void 0 ? void 0 : slides.map((s) => { var _a; return (_a = s.form) === null || _a === void 0 ? void 0 : _a.controller; })) !== null && _a !== void 0 ? _a : []);
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 = (_a = page.schema.fields) !== null && _a !== void 0 ? _a : {};
30
+ const fields = page.schema.fields ?? {};
32
31
  for (const section of page.sections) {
33
- for (const field of (_b = section.fields) !== null && _b !== void 0 ? _b : []) {
34
- const fieldKey = (_c = field.name) !== null && _c !== void 0 ? _c : field;
35
- const f = (_d = fields[fieldKey]) !== null && _d !== void 0 ? _d : {};
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 !== null && value !== void 0 ? value : {}).filter((k) => {
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 !== null && values !== void 0 ? 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: (_a = this.organizationId) !== null && _a !== void 0 ? _a : 'NO ORG',
74
+ organizationId: this.organizationId ?? 'NO ORG',
76
75
  },
77
76
  });
78
77
  this.completedFormId = completedFormId;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-form-utils",
3
3
  "description": "Support for working with forms and Sprucebot. 📄",
4
- "version": "18.5.38",
4
+ "version": "18.5.40",
5
5
  "skill": {
6
6
  "namespace": "forms"
7
7
  },