@sitecore-jss/sitecore-jss-forms 16.0.0-canary.8 → 16.0.1

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/LICENSE.txt CHANGED
@@ -1,202 +1,202 @@
1
-
2
- Apache License
3
- Version 2.0, January 2004
4
- http://www.apache.org/licenses/
5
-
6
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
-
8
- 1. Definitions.
9
-
10
- "License" shall mean the terms and conditions for use, reproduction,
11
- and distribution as defined by Sections 1 through 9 of this document.
12
-
13
- "Licensor" shall mean the copyright owner or entity authorized by
14
- the copyright owner that is granting the License.
15
-
16
- "Legal Entity" shall mean the union of the acting entity and all
17
- other entities that control, are controlled by, or are under common
18
- control with that entity. For the purposes of this definition,
19
- "control" means (i) the power, direct or indirect, to cause the
20
- direction or management of such entity, whether by contract or
21
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
- outstanding shares, or (iii) beneficial ownership of such entity.
23
-
24
- "You" (or "Your") shall mean an individual or Legal Entity
25
- exercising permissions granted by this License.
26
-
27
- "Source" form shall mean the preferred form for making modifications,
28
- including but not limited to software source code, documentation
29
- source, and configuration files.
30
-
31
- "Object" form shall mean any form resulting from mechanical
32
- transformation or translation of a Source form, including but
33
- not limited to compiled object code, generated documentation,
34
- and conversions to other media types.
35
-
36
- "Work" shall mean the work of authorship, whether in Source or
37
- Object form, made available under the License, as indicated by a
38
- copyright notice that is included in or attached to the work
39
- (an example is provided in the Appendix below).
40
-
41
- "Derivative Works" shall mean any work, whether in Source or Object
42
- form, that is based on (or derived from) the Work and for which the
43
- editorial revisions, annotations, elaborations, or other modifications
44
- represent, as a whole, an original work of authorship. For the purposes
45
- of this License, Derivative Works shall not include works that remain
46
- separable from, or merely link (or bind by name) to the interfaces of,
47
- the Work and Derivative Works thereof.
48
-
49
- "Contribution" shall mean any work of authorship, including
50
- the original version of the Work and any modifications or additions
51
- to that Work or Derivative Works thereof, that is intentionally
52
- submitted to Licensor for inclusion in the Work by the copyright owner
53
- or by an individual or Legal Entity authorized to submit on behalf of
54
- the copyright owner. For the purposes of this definition, "submitted"
55
- means any form of electronic, verbal, or written communication sent
56
- to the Licensor or its representatives, including but not limited to
57
- communication on electronic mailing lists, source code control systems,
58
- and issue tracking systems that are managed by, or on behalf of, the
59
- Licensor for the purpose of discussing and improving the Work, but
60
- excluding communication that is conspicuously marked or otherwise
61
- designated in writing by the copyright owner as "Not a Contribution."
62
-
63
- "Contributor" shall mean Licensor and any individual or Legal Entity
64
- on behalf of whom a Contribution has been received by Licensor and
65
- subsequently incorporated within the Work.
66
-
67
- 2. Grant of Copyright License. Subject to the terms and conditions of
68
- this License, each Contributor hereby grants to You a perpetual,
69
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
- copyright license to reproduce, prepare Derivative Works of,
71
- publicly display, publicly perform, sublicense, and distribute the
72
- Work and such Derivative Works in Source or Object form.
73
-
74
- 3. Grant of Patent License. Subject to the terms and conditions of
75
- this License, each Contributor hereby grants to You a perpetual,
76
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
- (except as stated in this section) patent license to make, have made,
78
- use, offer to sell, sell, import, and otherwise transfer the Work,
79
- where such license applies only to those patent claims licensable
80
- by such Contributor that are necessarily infringed by their
81
- Contribution(s) alone or by combination of their Contribution(s)
82
- with the Work to which such Contribution(s) was submitted. If You
83
- institute patent litigation against any entity (including a
84
- cross-claim or counterclaim in a lawsuit) alleging that the Work
85
- or a Contribution incorporated within the Work constitutes direct
86
- or contributory patent infringement, then any patent licenses
87
- granted to You under this License for that Work shall terminate
88
- as of the date such litigation is filed.
89
-
90
- 4. Redistribution. You may reproduce and distribute copies of the
91
- Work or Derivative Works thereof in any medium, with or without
92
- modifications, and in Source or Object form, provided that You
93
- meet the following conditions:
94
-
95
- (a) You must give any other recipients of the Work or
96
- Derivative Works a copy of this License; and
97
-
98
- (b) You must cause any modified files to carry prominent notices
99
- stating that You changed the files; and
100
-
101
- (c) You must retain, in the Source form of any Derivative Works
102
- that You distribute, all copyright, patent, trademark, and
103
- attribution notices from the Source form of the Work,
104
- excluding those notices that do not pertain to any part of
105
- the Derivative Works; and
106
-
107
- (d) If the Work includes a "NOTICE" text file as part of its
108
- distribution, then any Derivative Works that You distribute must
109
- include a readable copy of the attribution notices contained
110
- within such NOTICE file, excluding those notices that do not
111
- pertain to any part of the Derivative Works, in at least one
112
- of the following places: within a NOTICE text file distributed
113
- as part of the Derivative Works; within the Source form or
114
- documentation, if provided along with the Derivative Works; or,
115
- within a display generated by the Derivative Works, if and
116
- wherever such third-party notices normally appear. The contents
117
- of the NOTICE file are for informational purposes only and
118
- do not modify the License. You may add Your own attribution
119
- notices within Derivative Works that You distribute, alongside
120
- or as an addendum to the NOTICE text from the Work, provided
121
- that such additional attribution notices cannot be construed
122
- as modifying the License.
123
-
124
- You may add Your own copyright statement to Your modifications and
125
- may provide additional or different license terms and conditions
126
- for use, reproduction, or distribution of Your modifications, or
127
- for any such Derivative Works as a whole, provided Your use,
128
- reproduction, and distribution of the Work otherwise complies with
129
- the conditions stated in this License.
130
-
131
- 5. Submission of Contributions. Unless You explicitly state otherwise,
132
- any Contribution intentionally submitted for inclusion in the Work
133
- by You to the Licensor shall be under the terms and conditions of
134
- this License, without any additional terms or conditions.
135
- Notwithstanding the above, nothing herein shall supersede or modify
136
- the terms of any separate license agreement you may have executed
137
- with Licensor regarding such Contributions.
138
-
139
- 6. Trademarks. This License does not grant permission to use the trade
140
- names, trademarks, service marks, or product names of the Licensor,
141
- except as required for reasonable and customary use in describing the
142
- origin of the Work and reproducing the content of the NOTICE file.
143
-
144
- 7. Disclaimer of Warranty. Unless required by applicable law or
145
- agreed to in writing, Licensor provides the Work (and each
146
- Contributor provides its Contributions) on an "AS IS" BASIS,
147
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
- implied, including, without limitation, any warranties or conditions
149
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
- PARTICULAR PURPOSE. You are solely responsible for determining the
151
- appropriateness of using or redistributing the Work and assume any
152
- risks associated with Your exercise of permissions under this License.
153
-
154
- 8. Limitation of Liability. In no event and under no legal theory,
155
- whether in tort (including negligence), contract, or otherwise,
156
- unless required by applicable law (such as deliberate and grossly
157
- negligent acts) or agreed to in writing, shall any Contributor be
158
- liable to You for damages, including any direct, indirect, special,
159
- incidental, or consequential damages of any character arising as a
160
- result of this License or out of the use or inability to use the
161
- Work (including but not limited to damages for loss of goodwill,
162
- work stoppage, computer failure or malfunction, or any and all
163
- other commercial damages or losses), even if such Contributor
164
- has been advised of the possibility of such damages.
165
-
166
- 9. Accepting Warranty or Additional Liability. While redistributing
167
- the Work or Derivative Works thereof, You may choose to offer,
168
- and charge a fee for, acceptance of support, warranty, indemnity,
169
- or other liability obligations and/or rights consistent with this
170
- License. However, in accepting such obligations, You may act only
171
- on Your own behalf and on Your sole responsibility, not on behalf
172
- of any other Contributor, and only if You agree to indemnify,
173
- defend, and hold each Contributor harmless for any liability
174
- incurred by, or claims asserted against, such Contributor by reason
175
- of your accepting any such warranty or additional liability.
176
-
177
- END OF TERMS AND CONDITIONS
178
-
179
- APPENDIX: How to apply the Apache License to your work.
180
-
181
- To apply the Apache License to your work, attach the following
182
- boilerplate notice, with the fields enclosed by brackets "[]"
183
- replaced with your own identifying information. (Don't include
184
- the brackets!) The text should be enclosed in the appropriate
185
- comment syntax for the file format. We also recommend that a
186
- file or class name and description of purpose be included on the
187
- same "printed page" as the copyright notice for easier
188
- identification within third-party archives.
189
-
190
- Copyright [yyyy] [name of copyright owner]
191
-
192
- Licensed under the Apache License, Version 2.0 (the "License");
193
- you may not use this file except in compliance with the License.
194
- You may obtain a copy of the License at
195
-
196
- http://www.apache.org/licenses/LICENSE-2.0
197
-
198
- Unless required by applicable law or agreed to in writing, software
199
- distributed under the License is distributed on an "AS IS" BASIS,
200
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
- See the License for the specific language governing permissions and
202
- limitations under the License.
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Sitecore JavaScript Services Forms
2
-
3
- This module is provided as a part of Sitecore JavaScript Services. It contains the APIs for Sitecore Forms integration.
4
-
5
- Consult the [Sitecore JSS documentation](https://jss.sitecore.net) for further details.
6
-
1
+ # Sitecore JavaScript Services Forms
2
+
3
+ This module is provided as a part of Sitecore JavaScript Services. It contains the APIs for Sitecore Forms integration.
4
+
5
+ Consult the [Sitecore JSS documentation](https://jss.sitecore.net) for further details.
6
+
package/dist/FormField.js CHANGED
@@ -1,17 +1,30 @@
1
1
  "use strict";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ /**
5
+ * @param {any} object
6
+ */
3
7
  function instanceOfFormField(object) {
4
8
  return 'model' in object;
5
9
  }
6
10
  exports.instanceOfFormField = instanceOfFormField;
11
+ /**
12
+ * @param {FormField} object
13
+ */
7
14
  function instanceOfValueFormField(object) {
8
15
  return 'indexField' in object;
9
16
  }
10
17
  exports.instanceOfValueFormField = instanceOfValueFormField;
18
+ /**
19
+ * @param {FormField} object
20
+ */
11
21
  function instanceOfButtonFormField(object) {
12
22
  return 'buttonField' in object;
13
23
  }
14
24
  exports.instanceOfButtonFormField = instanceOfButtonFormField;
25
+ /**
26
+ * @param {FormField} object
27
+ */
15
28
  function instanceOfFormFieldSection(object) {
16
29
  return 'fields' in object;
17
30
  }
@@ -23,10 +23,15 @@ var EventIds;
23
23
  EventIds["FieldCompleted"] = "2ca692cb-bdb2-4c9d-a3b5-917b3656c46a";
24
24
  EventIds["FieldError"] = "ea27aca5-432f-424a-b000-26ba5f8ae60a";
25
25
  })(EventIds || (EventIds = {}));
26
+ /**
27
+ * @param {RequestInit} [options]
28
+ */
26
29
  function createFetchBasedTrackerFetcher(options) {
27
- return function (formData, endpoint) { return fetch(endpoint, __assign({ body: JSON.stringify(formData), method: 'post',
28
- // IMPORTANT: Sitecore forms relies on cookies for some state management, so credentials must be included.
29
- credentials: 'include' }, options)); };
30
+ return function (formData, endpoint) {
31
+ return fetch(endpoint, __assign({ body: JSON.stringify(formData), method: 'post',
32
+ // IMPORTANT: Sitecore forms relies on cookies for some state management, so credentials must be included.
33
+ credentials: 'include' }, options));
34
+ };
30
35
  }
31
36
  exports.createFetchBasedTrackerFetcher = createFetchBasedTrackerFetcher;
32
37
  var FormTracker = /** @class */ (function () {
@@ -35,7 +40,12 @@ var FormTracker = /** @class */ (function () {
35
40
  this._fetcher = options.fetcher || createFetchBasedTrackerFetcher();
36
41
  this._endpoint = options.endpoint;
37
42
  }
38
- /** Should be called prior to pushing any events, and again whenever new form schema data is received */
43
+ /**
44
+ * Should be called prior to pushing any events, and again whenever new form schema data is received
45
+ * @param {string} formId
46
+ * @param {string} formSessionId
47
+ * @param {string} enableTracking
48
+ */
39
49
  FormTracker.prototype.setFormData = function (formId, formSessionId, enableTracking) {
40
50
  this._formId = formId;
41
51
  this._formSessionId = formSessionId;
@@ -56,9 +66,12 @@ var FormTracker = /** @class */ (function () {
56
66
  return;
57
67
  }
58
68
  var blurredAtTick = new Date().getTime();
59
- var duration = trackableField.focusedAtTick ? Math.round((blurredAtTick - trackableField.focusedAtTick) / 1000) : 0;
69
+ var duration = trackableField.focusedAtTick
70
+ ? Math.round((blurredAtTick - trackableField.focusedAtTick) / 1000)
71
+ : 0;
60
72
  trackableField.focusedAtTick = undefined;
61
- var fieldChanged = this._currentField && this._currentField.fieldIdField.value !== trackableField.fieldIdField.value;
73
+ var fieldChanged = this._currentField &&
74
+ this._currentField.fieldIdField.value !== trackableField.fieldIdField.value;
62
75
  if (fieldChanged) {
63
76
  this._startTrackingField(field, value);
64
77
  duration = 0;
@@ -16,16 +16,27 @@ var JssFormData = /** @class */ (function () {
16
16
  function JssFormData() {
17
17
  this.data = new Array();
18
18
  }
19
- /** Appends a new key/value to the form data. Value will be added to any existing value that may exist. */
19
+ /**
20
+ * Appends a new key/value to the form data. Value will be added to any existing value that may exist.
21
+ * @param {string} key
22
+ * @param {string | File} value
23
+ */
20
24
  JssFormData.prototype.append = function (key, value) {
21
25
  this.data.push({ key: key, value: value });
22
26
  };
23
- /** Sets a key/value, removing any existing value(s) set for that key. */
27
+ /**
28
+ * Sets a key/value, removing any existing value(s) set for that key.
29
+ * @param {string} key
30
+ * @param {string | File} value
31
+ */
24
32
  JssFormData.prototype.set = function (key, value) {
25
33
  this.data = this.data.filter(function (entry) { return entry.key !== key; });
26
34
  this.append(key, value);
27
35
  };
28
- /** Merges form data from a client-side state store (i.e. the user-specified values), overwriting any existing values for the keys */
36
+ /**
37
+ * Merges form data from a client-side state store (i.e. the user-specified values), overwriting any existing values for the keys
38
+ * @param {Object} values
39
+ */
29
40
  JssFormData.prototype.mergeOverwritingExisting = function (values) {
30
41
  var _this = this;
31
42
  Object.keys(values).forEach(function (key) {
@@ -49,12 +60,16 @@ var JssFormData = /** @class */ (function () {
49
60
  }
50
61
  });
51
62
  };
52
- /** Gets all key/values in the store. Duplicate keys with different values are possible. */
63
+ /**
64
+ * Gets all key/values in the store. Duplicate keys with different values are possible.
65
+ * @returns {Object} data
66
+ */
53
67
  JssFormData.prototype.get = function () {
54
68
  return __spreadArrays(this.data);
55
69
  };
56
70
  /**
57
71
  * Converts the store into a FormData that can be POST-ed with fetch as multipart/form-data.
72
+ * @returns {FormData} form data
58
73
  */
59
74
  JssFormData.prototype.toMultipartFormData = function () {
60
75
  var formData = new FormData();
@@ -63,9 +78,13 @@ var JssFormData = /** @class */ (function () {
63
78
  };
64
79
  /**
65
80
  * Converts the store into a URL-encoded string suitable to POST as application/x-www-form-urlencoded.
81
+ * @returns {string} url encoded form data
66
82
  */
67
83
  JssFormData.prototype.toUrlEncodedFormData = function () {
68
- return this.data.map(function (entry) { return encodeURIComponent(entry.key) + "=" + encodeURIComponent(entry.value.toString()); }).join('&').replace(/%20/g, '+');
84
+ return this.data
85
+ .map(function (entry) { return encodeURIComponent(entry.key) + "=" + encodeURIComponent(entry.value.toString()); })
86
+ .join('&')
87
+ .replace(/%20/g, '+');
69
88
  };
70
89
  return JssFormData;
71
90
  }());
package/dist/ViewModel.js CHANGED
@@ -1,10 +1,16 @@
1
1
  "use strict";
2
2
  /** The model for a given field's data elements */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ /**
5
+ * @param {ViewModel} object
6
+ */
4
7
  function instanceOfInputViewModel(object) {
5
8
  return 'value' in object;
6
9
  }
7
10
  exports.instanceOfInputViewModel = instanceOfInputViewModel;
11
+ /**
12
+ * @param {ViewModel} object
13
+ */
8
14
  function instanceOfListViewModel(object) {
9
15
  return 'items' in object;
10
16
  }
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var ViewModel_1 = require("./ViewModel");
4
- /** Retrieves the current value of a form field from the form model returned from the JSON API */
4
+ /** Retrieves the current value of a form field from the form model returned from the JSON API
5
+ * @param {FormField} field
6
+ * @returns {string | string[] | boolean} field value
7
+ */
5
8
  function getFieldValueFromModel(field) {
6
9
  if (ViewModel_1.instanceOfListViewModel(field.model)) {
7
10
  // field state from API view-model items (list fields with possible multi-select)
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- // tslint:disable:max-line-length
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  var FormField_1 = require("./FormField");
5
4
  var getFieldValueFromModel_1 = require("./getFieldValueFromModel");
@@ -7,8 +6,9 @@ var JssFormData_1 = require("./JssFormData");
7
6
  var ViewModel_1 = require("./ViewModel");
8
7
  /**
9
8
  * Serializes a Sitecore Form data into a format ready to POST to the server.
10
- * @param form The form schema data from the server
11
- * @param submitButtonName The name of the submit button that was clicked. Excludes other buttons from serialization. If not passed, all buttons are serialized.
9
+ * @param {SitecoreForm} form The form schema data from the server
10
+ * @param {SerializeFormOptions} [options]
11
+ * @returns {JssFormData} form data
12
12
  */
13
13
  function serializeForm(form, options) {
14
14
  if (!options) {
@@ -26,6 +26,11 @@ function serializeForm(form, options) {
26
26
  return result;
27
27
  }
28
28
  exports.serializeForm = serializeForm;
29
+ /**
30
+ * @param {JssFormData} result
31
+ * @param {Array<FormField<any>>} fields
32
+ * @param {SerializeFormOptions} options
33
+ */
29
34
  function pushFields(result, fields, options) {
30
35
  fields.forEach(function (field) {
31
36
  if (FormField_1.instanceOfButtonFormField(field) &&
@@ -35,14 +40,14 @@ function pushFields(result, fields, options) {
35
40
  pushField(result, field.navigationStepField);
36
41
  }
37
42
  else if (FormField_1.instanceOfValueFormField(field)) {
43
+ pushField(result, field.indexField);
44
+ pushField(result, field.fieldIdField);
38
45
  if (field.valueField.name.endsWith('.Files')) {
39
46
  var fileUploadField = field;
40
- if (!fileUploadField.originalValue && !fileUploadField.model.files) {
47
+ if (!fileUploadField.model.files) {
41
48
  return;
42
49
  }
43
50
  }
44
- pushField(result, field.indexField);
45
- pushField(result, field.fieldIdField);
46
51
  // get stored value (i.e. if a multistep form)
47
52
  if (ViewModel_1.instanceOfInputViewModel(field.model) && options.fieldValueParser) {
48
53
  var fieldValue = options.fieldValueParser(field);
@@ -59,10 +64,20 @@ function pushFields(result, fields, options) {
59
64
  }
60
65
  });
61
66
  }
67
+ /**
68
+ * @param {JssFormData} result
69
+ * @param {HtmlFormField} field
70
+ * @param {string} [overrideValue]
71
+ */
62
72
  function pushField(result, field, overrideValue) {
63
73
  // the '' fallback prevents serializing 'null' as a string for empty field values ;)
64
74
  return pushFieldValue(result, field.name, overrideValue || field.value || '');
65
75
  }
76
+ /**
77
+ * @param {JssFormData} result
78
+ * @param {string} fieldName
79
+ * @param {string} fieldValue
80
+ */
66
81
  function pushFieldValue(result, fieldName, fieldValue) {
67
82
  if (!fieldName) {
68
83
  throw new Error('Field had no name');
@@ -11,14 +11,24 @@ var __assign = (this && this.__assign) || function () {
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
+ /**
15
+ * @param {RequestInit} [options]
16
+ */
14
17
  function createFetchBasedFormFetcher(options) {
15
- return function (formData, endpoint) { return fetch(endpoint, __assign({ body: formData.toMultipartFormData(), method: 'post',
16
- // IMPORTANT: Sitecore forms relies on cookies for some state management, so credentials must be included.
17
- credentials: 'include' }, options))
18
- .then(function (res) { return res.json(); })
19
- .then(function (res) { return res; }); };
18
+ return function (formData, endpoint) {
19
+ return fetch(endpoint, __assign({ body: formData.toMultipartFormData(), method: 'post',
20
+ // IMPORTANT: Sitecore forms relies on cookies for some state management, so credentials must be included.
21
+ credentials: 'include' }, options))
22
+ .then(function (res) { return res.json(); })
23
+ .then(function (res) { return res; });
24
+ };
20
25
  }
21
26
  exports.createFetchBasedFormFetcher = createFetchBasedFormFetcher;
27
+ /**
28
+ * @param {JssFormData} formData
29
+ * @param {string} endpoint
30
+ * @param {FormSubmitOptions} [options]
31
+ */
22
32
  function submitForm(formData, endpoint, options) {
23
33
  options = options || {};
24
34
  if (!options.fetcher) {
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@sitecore-jss/sitecore-jss-forms",
3
- "version": "16.0.0-canary.8",
3
+ "version": "16.0.1",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "build": "npm run clean && tsc",
7
7
  "clean": "del-cli dist types",
8
- "lint": "tslint -p . -c ../../tslint.json \"src/**/*.ts\"",
8
+ "lint": "eslint ./src/**/*.ts",
9
9
  "test": "mocha --require ts-node/register \"./src/**/*.test.ts\"",
10
10
  "prepublishOnly": "npm run build",
11
11
  "coverage": "nyc --require ts-node/register npm test"
@@ -29,11 +29,12 @@
29
29
  "@types/mocha": "^5.2.5",
30
30
  "@types/node": "^10.12.0",
31
31
  "@types/url-parse": "1.1.0",
32
- "axios": "^0.18.1",
32
+ "axios": "^0.21.1",
33
33
  "axios-mock-adapter": "^1.15.0",
34
34
  "chai": "^4.2.0",
35
35
  "chai-string": "^1.5.0",
36
36
  "del-cli": "^1.1.0",
37
+ "eslint": "^7.15.0",
37
38
  "mocha": "^8.1.3",
38
39
  "sinon": "^7.5.0",
39
40
  "ts-node": "^8.4.1",
@@ -41,9 +42,9 @@
41
42
  "typescript": "^3.6.3"
42
43
  },
43
44
  "dependencies": {
44
- "@sitecore-jss/sitecore-jss": "^16.0.0-canary.8"
45
+ "@sitecore-jss/sitecore-jss": "^16.0.1"
45
46
  },
46
47
  "description": "",
47
48
  "types": "types/index.d.ts",
48
- "gitHead": "be22a453049c318e28e73343974f371cc0300c7d"
49
+ "gitHead": "29ff3559b0c3d263ba4c84a3cfab4f1b980d9272"
49
50
  }
@@ -3,20 +3,32 @@ import { InputViewModel, TitleFieldViewModel, ViewModel, FieldViewModel } from '
3
3
  export interface FormField<TViewModel extends ViewModel = ViewModel> {
4
4
  model: TViewModel;
5
5
  }
6
+ /**
7
+ * @param {any} object
8
+ */
6
9
  export declare function instanceOfFormField<T extends ViewModel>(object: any): object is FormField<T>;
7
10
  export interface ValueFormField<TViewModel extends InputViewModel = InputViewModel> extends FormField<TViewModel> {
8
11
  indexField: HtmlFormField;
9
12
  fieldIdField: HtmlFormField;
10
13
  valueField: HtmlFormField;
11
14
  }
15
+ /**
16
+ * @param {FormField} object
17
+ */
12
18
  export declare function instanceOfValueFormField(object: FormField<any>): object is ValueFormField<any>;
13
19
  export interface ButtonFormField extends FormField<TitleFieldViewModel> {
14
20
  navigationButtonsField: HtmlFormField;
15
21
  navigationStepField: HtmlFormField;
16
22
  buttonField: HtmlFormField;
17
23
  }
24
+ /**
25
+ * @param {FormField} object
26
+ */
18
27
  export declare function instanceOfButtonFormField(object: FormField): object is ButtonFormField;
19
28
  export interface FormFieldSection extends FormField<FieldViewModel> {
20
29
  fields: FormField[];
21
30
  }
31
+ /**
32
+ * @param {FormField} object
33
+ */
22
34
  export declare function instanceOfFormFieldSection(object: FormField): object is FormFieldSection;
@@ -11,11 +11,14 @@ export interface TrackingEvent {
11
11
  duration: number;
12
12
  fieldName: string;
13
13
  }
14
- export declare type TrackerFetcher = (formData: TrackingEvent[], endpoint: string) => Promise<{}> | void;
14
+ export declare type TrackerFetcher = (formData: TrackingEvent[], endpoint: string) => Promise<any> | void;
15
15
  export interface FormTrackerOptions {
16
16
  endpoint: string;
17
17
  fetcher?: TrackerFetcher;
18
18
  }
19
+ /**
20
+ * @param {RequestInit} [options]
21
+ */
19
22
  export declare function createFetchBasedTrackerFetcher(options?: RequestInit): TrackerFetcher;
20
23
  export declare class FormTracker {
21
24
  private _currentField;
@@ -25,7 +28,12 @@ export declare class FormTracker {
25
28
  private _fetcher;
26
29
  private _endpoint;
27
30
  constructor(options: FormTrackerOptions);
28
- /** Should be called prior to pushing any events, and again whenever new form schema data is received */
31
+ /**
32
+ * Should be called prior to pushing any events, and again whenever new form schema data is received
33
+ * @param {string} formId
34
+ * @param {string} formSessionId
35
+ * @param {string} enableTracking
36
+ */
29
37
  setFormData(formId: string, formSessionId: string, enableTracking: boolean): void;
30
38
  onFocusField(field: ValueFormField, value: string | string[]): void;
31
39
  onBlurField(field: ValueFormField, value: string | string[], validationErrors?: string[]): void;
@@ -5,25 +5,41 @@
5
5
  */
6
6
  export declare class JssFormData {
7
7
  private data;
8
- /** Appends a new key/value to the form data. Value will be added to any existing value that may exist. */
8
+ /**
9
+ * Appends a new key/value to the form data. Value will be added to any existing value that may exist.
10
+ * @param {string} key
11
+ * @param {string | File} value
12
+ */
9
13
  append(key: string, value: string | File): void;
10
- /** Sets a key/value, removing any existing value(s) set for that key. */
14
+ /**
15
+ * Sets a key/value, removing any existing value(s) set for that key.
16
+ * @param {string} key
17
+ * @param {string | File} value
18
+ */
11
19
  set(key: string, value: string | File): void;
12
- /** Merges form data from a client-side state store (i.e. the user-specified values), overwriting any existing values for the keys */
20
+ /**
21
+ * Merges form data from a client-side state store (i.e. the user-specified values), overwriting any existing values for the keys
22
+ * @param {Object} values
23
+ */
13
24
  mergeOverwritingExisting(values: {
14
25
  [key: string]: string | string[] | boolean | File[];
15
26
  }): void;
16
- /** Gets all key/values in the store. Duplicate keys with different values are possible. */
27
+ /**
28
+ * Gets all key/values in the store. Duplicate keys with different values are possible.
29
+ * @returns {Object} data
30
+ */
17
31
  get(): {
18
32
  key: string;
19
33
  value: FormDataEntryValue;
20
34
  }[];
21
35
  /**
22
36
  * Converts the store into a FormData that can be POST-ed with fetch as multipart/form-data.
37
+ * @returns {FormData} form data
23
38
  */
24
39
  toMultipartFormData(): FormData;
25
40
  /**
26
41
  * Converts the store into a URL-encoded string suitable to POST as application/x-www-form-urlencoded.
42
+ * @returns {string} url encoded form data
27
43
  */
28
44
  toUrlEncodedFormData(): string;
29
45
  }
@@ -28,6 +28,9 @@ export interface InputViewModel extends TitleFieldViewModel {
28
28
  isTrackingEnabled: boolean;
29
29
  value: string | boolean;
30
30
  }
31
+ /**
32
+ * @param {ViewModel} object
33
+ */
31
34
  export declare function instanceOfInputViewModel(object: ViewModel): object is InputViewModel;
32
35
  export interface DateInputViewModel extends InputViewModel {
33
36
  min?: string;
@@ -54,6 +57,9 @@ export interface StringInputViewModel extends InputViewModel {
54
57
  export interface MultiLineStringInputViewModel extends StringInputViewModel {
55
58
  rows?: number;
56
59
  }
60
+ /**
61
+ * @param {ViewModel} object
62
+ */
57
63
  export declare function instanceOfListViewModel(object: ViewModel): object is ListViewModel;
58
64
  export interface ListViewModel extends InputViewModel {
59
65
  items: ListFieldItem[];
@@ -1,3 +1,6 @@
1
1
  import { FormField } from './FormField';
2
- /** Retrieves the current value of a form field from the form model returned from the JSON API */
3
- export declare function getFieldValueFromModel(field: FormField<any>): string | boolean | string[];
2
+ /** Retrieves the current value of a form field from the form model returned from the JSON API
3
+ * @param {FormField} field
4
+ * @returns {string | string[] | boolean} field value
5
+ */
6
+ export declare function getFieldValueFromModel(field: FormField): string | boolean | string[];
package/types/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export { FormModel } from './FormModel';
4
4
  export { HtmlFormField } from './HtmlFormField';
5
5
  export { serializeForm, SerializeFormOptions } from './serializeForm';
6
6
  export { ViewModel, ValidationDataModel, TextViewModel, FieldViewModel, InputViewModel, FileInputViewModel, StringInputViewModel, MultiLineStringInputViewModel, DateInputViewModel, NumberInputViewModel, TitleFieldViewModel, ListFieldItem, ListViewModel, DropdownListViewModel, ListBoxViewModel, instanceOfListViewModel, instanceOfInputViewModel, } from './ViewModel';
7
- export { submitForm, createFetchBasedFormFetcher, FormSubmitOptions, FormFetcher } from './submitForm';
7
+ export { submitForm, createFetchBasedFormFetcher, FormSubmitOptions, FormFetcher, } from './submitForm';
8
8
  export { getFieldValueFromModel } from './getFieldValueFromModel';
9
- export { FormTracker, FormTrackerOptions, TrackingEvent, createFetchBasedTrackerFetcher, TrackerFetcher } from './FormTracker';
9
+ export { FormTracker, FormTrackerOptions, TrackingEvent, createFetchBasedTrackerFetcher, TrackerFetcher, } from './FormTracker';
10
10
  export { FormResult, FieldValidationErrors } from './FormResult';
@@ -7,7 +7,8 @@ export interface SerializeFormOptions {
7
7
  }
8
8
  /**
9
9
  * Serializes a Sitecore Form data into a format ready to POST to the server.
10
- * @param form The form schema data from the server
11
- * @param submitButtonName The name of the submit button that was clicked. Excludes other buttons from serialization. If not passed, all buttons are serialized.
10
+ * @param {SitecoreForm} form The form schema data from the server
11
+ * @param {SerializeFormOptions} [options]
12
+ * @returns {JssFormData} form data
12
13
  */
13
14
  export declare function serializeForm(form: SitecoreForm, options?: SerializeFormOptions): JssFormData;
@@ -4,5 +4,13 @@ export declare type FormFetcher = (formData: JssFormData, endpoint: string) => P
4
4
  export interface FormSubmitOptions {
5
5
  fetcher?: FormFetcher;
6
6
  }
7
+ /**
8
+ * @param {RequestInit} [options]
9
+ */
7
10
  export declare function createFetchBasedFormFetcher(options?: RequestInit): FormFetcher;
11
+ /**
12
+ * @param {JssFormData} formData
13
+ * @param {string} endpoint
14
+ * @param {FormSubmitOptions} [options]
15
+ */
8
16
  export declare function submitForm(formData: JssFormData, endpoint: string, options?: FormSubmitOptions): Promise<FormResult>;