envoc-form 5.0.3 → 5.0.6

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.
Files changed (145) hide show
  1. package/README.md +163 -20
  2. package/es/ConfirmBaseForm/ConfirmBaseForm.js +2 -2
  3. package/es/DatePicker/DatePickerGroup.js +2 -2
  4. package/es/FieldArray/FieldArray.js +4 -4
  5. package/es/File/FileGroup.js +3 -3
  6. package/es/Form/Form.js +2 -2
  7. package/es/Group.js +3 -3
  8. package/es/Input/CheckboxGroup.d.ts +6 -0
  9. package/es/Input/CheckboxGroup.js +14 -0
  10. package/es/Input/CheckboxInputGroup.d.ts +13 -0
  11. package/es/Input/CheckboxInputGroup.js +41 -0
  12. package/es/Input/IconInputGroup.js +2 -2
  13. package/es/Input/InputGroup.js +2 -2
  14. package/es/Input/MoneyInputGroup.js +2 -2
  15. package/es/Input/NumberInputGroup.js +2 -2
  16. package/es/Input/PhoneNumberInputGroup.js +2 -2
  17. package/es/Input/StringInputGroup.js +2 -2
  18. package/es/Select/SelectGroup.js +3 -3
  19. package/es/StandardFormActions.js +3 -3
  20. package/es/SubmitFormButton.js +2 -2
  21. package/es/TextArea/TextAreaGroup.js +2 -2
  22. package/es/index.d.ts +2 -0
  23. package/es/index.js +1 -0
  24. package/lib/ConfirmBaseForm/ConfirmBaseForm.js +2 -5
  25. package/lib/DatePicker/DatePickerGroup.js +2 -2
  26. package/lib/FieldArray/FieldArray.js +4 -4
  27. package/lib/File/FileGroup.js +3 -3
  28. package/lib/Form/Form.js +2 -2
  29. package/lib/Group.js +3 -3
  30. package/lib/Input/CheckboxGroup.d.ts +6 -0
  31. package/lib/Input/CheckboxGroup.js +20 -0
  32. package/lib/Input/CheckboxInputGroup.d.ts +13 -0
  33. package/lib/Input/CheckboxInputGroup.js +46 -0
  34. package/lib/Input/IconInputGroup.js +2 -2
  35. package/lib/Input/InputGroup.js +2 -2
  36. package/lib/Input/MoneyInputGroup.js +2 -2
  37. package/lib/Input/NumberInputGroup.js +2 -2
  38. package/lib/Input/PhoneNumberInputGroup.js +2 -2
  39. package/lib/Input/StringInputGroup.js +2 -2
  40. package/lib/Select/SelectGroup.js +3 -3
  41. package/lib/StandardFormActions.js +3 -3
  42. package/lib/SubmitFormButton.js +2 -2
  43. package/lib/TextArea/TextAreaGroup.js +2 -2
  44. package/lib/index.d.ts +2 -0
  45. package/lib/index.js +3 -1
  46. package/package.json +111 -111
  47. package/src/AddressInput/AddressInput.test.tsx +27 -27
  48. package/src/AddressInput/AddressInput.tsx +82 -82
  49. package/src/AddressInput/UsStates.ts +55 -55
  50. package/src/AddressInput/__snapshots__/AddressInput.test.tsx.snap +182 -182
  51. package/src/ConfirmBaseForm/ConfirmBaseForm.test.tsx +24 -24
  52. package/src/ConfirmBaseForm/ConfirmBaseForm.tsx +74 -74
  53. package/src/ConfirmBaseForm/__snapshots__/ConfirmBaseForm.test.tsx.snap +23 -23
  54. package/src/ConfirmDeleteForm/ConfirmDeleteForm.test.tsx +24 -24
  55. package/src/ConfirmDeleteForm/ConfirmDeleteForm.tsx +87 -87
  56. package/src/ConfirmDeleteForm/__snapshots__/ConfirmDeleteForm.test.tsx.snap +25 -25
  57. package/src/DatePicker/DatePicker.test.tsx +48 -48
  58. package/src/DatePicker/DatePickerGroup.tsx +109 -115
  59. package/src/DatePicker/DatePickerHelper.ts +4 -4
  60. package/src/DatePicker/StringDateOnlyPickerGroup.tsx +28 -28
  61. package/src/DatePicker/StringDatePickerGroup.tsx +20 -20
  62. package/src/DatePicker/__snapshots__/DatePicker.test.tsx.snap +152 -152
  63. package/src/Field/CustomFieldInputProps.ts +10 -10
  64. package/src/Field/CustomFieldMetaProps.ts +5 -5
  65. package/src/Field/Field.tsx +113 -113
  66. package/src/Field/FieldErrorScrollTarget.tsx +12 -12
  67. package/src/Field/FieldNameContext.ts +6 -6
  68. package/src/Field/FieldSection.tsx +18 -18
  69. package/src/Field/InjectedFieldProps.ts +8 -8
  70. package/src/Field/StandAloneInput.tsx +55 -55
  71. package/src/Field/useStandardField.ts +125 -125
  72. package/src/FieldArray/FieldArray.tsx +154 -154
  73. package/src/File/FileGroup.test.tsx +35 -35
  74. package/src/File/FileGroup.tsx +82 -85
  75. package/src/File/FileList.tsx +21 -21
  76. package/src/File/__snapshots__/FileGroup.test.tsx.snap +34 -34
  77. package/src/File/humanFileSize.ts +8 -8
  78. package/src/Form/FocusError.tsx +55 -55
  79. package/src/Form/Form.test.tsx +14 -14
  80. package/src/Form/Form.tsx +234 -237
  81. package/src/Form/FormBasedPreventNavigation.tsx +56 -56
  82. package/src/Form/LegacyFormBasedPreventNavigation.tsx +77 -77
  83. package/src/Form/NewFormBasedPreventNavigation.tsx +59 -59
  84. package/src/Form/ServerErrorContext.ts +18 -18
  85. package/src/Form/__snapshots__/Form.test.tsx.snap +10 -10
  86. package/src/FormActions.tsx +47 -47
  87. package/src/FormDefaults.ts +2 -2
  88. package/src/Group.tsx +62 -62
  89. package/src/Input/CheckboxGroup.tsx +60 -0
  90. package/src/Input/CheckboxInputGroup.tsx +78 -0
  91. package/src/Input/IconInputGroup.tsx +54 -54
  92. package/src/Input/InputGroup.tsx +66 -72
  93. package/src/Input/MoneyInputGroup.tsx +47 -50
  94. package/src/Input/NumberInputGroup.tsx +45 -48
  95. package/src/Input/PhoneNumberInputGroup.tsx +45 -45
  96. package/src/Input/StringInputGroup.tsx +50 -53
  97. package/src/Input/__Tests__/CheckboxInputGroup.test.tsx +26 -0
  98. package/src/Input/__Tests__/IconInputGroup.test.tsx +35 -35
  99. package/src/Input/__Tests__/MoneyInputGroup.test.tsx +37 -37
  100. package/src/Input/__Tests__/NumberInputGroup.test.tsx +35 -35
  101. package/src/Input/__Tests__/PhoneNumberInputGroup.test.tsx +36 -36
  102. package/src/Input/__Tests__/StringInputGroup.test.tsx +27 -27
  103. package/src/Input/__Tests__/__snapshots__/CheckboxInputGroup.test.tsx.snap +33 -0
  104. package/src/Input/__Tests__/__snapshots__/IconInputGroup.test.tsx.snap +32 -32
  105. package/src/Input/__Tests__/__snapshots__/MoneyInputGroup.test.tsx.snap +34 -34
  106. package/src/Input/__Tests__/__snapshots__/NumberInputGroup.test.tsx.snap +32 -32
  107. package/src/Input/__Tests__/__snapshots__/PhoneNumberInputGroup.test.tsx.snap +33 -33
  108. package/src/Input/__Tests__/__snapshots__/StringInputGroup.test.tsx.snap +31 -31
  109. package/src/Normalization/NormalizationFunction.ts +4 -4
  110. package/src/Normalization/normalizers.ts +44 -44
  111. package/src/Select/BooleanSelectGroup.tsx +28 -28
  112. package/src/Select/NumberSelectGroup.tsx +16 -16
  113. package/src/Select/SelectGroup.tsx +124 -124
  114. package/src/Select/SelectGroupPropsHelper.ts +4 -4
  115. package/src/Select/StringSelectGroup.tsx +16 -16
  116. package/src/Select/__tests__/BooleanSelectGroup.test.tsx +35 -35
  117. package/src/Select/__tests__/NumberSelectGroup.test.tsx +87 -87
  118. package/src/Select/__tests__/StringSelectGroup.test.tsx +89 -89
  119. package/src/Select/__tests__/__snapshots__/BooleanSelectGroup.test.tsx.snap +98 -98
  120. package/src/Select/__tests__/__snapshots__/NumberSelectGroup.test.tsx.snap +195 -195
  121. package/src/Select/__tests__/__snapshots__/StringSelectGroup.test.tsx.snap +195 -195
  122. package/src/StandardFormActions.tsx +41 -41
  123. package/src/SubmitFormButton.tsx +54 -54
  124. package/src/TextArea/TextAreaGroup.tsx +64 -64
  125. package/src/Validation/ValidatedApiResult.ts +8 -8
  126. package/src/Validation/ValidationError.ts +6 -6
  127. package/src/Validation/ValidationFunction.ts +4 -4
  128. package/src/Validation/validators.test.tsx +81 -81
  129. package/src/Validation/validators.ts +97 -97
  130. package/src/__Tests__/FormTestBase.tsx +65 -64
  131. package/src/__Tests__/RealisticForm.test.tsx +82 -82
  132. package/src/__Tests__/StandardFormActions.test.tsx +17 -17
  133. package/src/__Tests__/SubmitFormButton.test.tsx +17 -17
  134. package/src/__Tests__/__snapshots__/StandardFormActions.test.tsx.snap +27 -27
  135. package/src/__Tests__/__snapshots__/SubmitFormButton.test.tsx.snap +20 -20
  136. package/src/__Tests__/index.ts +3 -3
  137. package/src/_variables.scss +11 -11
  138. package/src/index.ts +156 -153
  139. package/src/react-app-env.d.ts +1 -1
  140. package/src/setupTests.ts +1 -1
  141. package/src/utils/objectContainsNonSerializableProperty.test.tsx +49 -49
  142. package/src/utils/objectContainsNonSerializableProperty.ts +17 -17
  143. package/src/utils/objectToFormData.test.tsx +76 -76
  144. package/src/utils/objectToFormData.ts +105 -105
  145. package/src/utils/typeChecks.ts +18 -18
@@ -1,105 +1,105 @@
1
- // Original: https://github.com/therealparmesh/object-to-formdata/blob/master/src/index.js
2
- // With Multiple Form File Fix: https://github.com/therealparmesh/object-to-formdata/pull/94/files
3
- import {
4
- isArray,
5
- isBlob,
6
- isBoolean,
7
- isDate,
8
- isFile,
9
- isNull,
10
- isObject,
11
- isUndefined,
12
- } from './typeChecks';
13
-
14
- // TODO: make all of these optional?
15
- export interface ObjectToFormDataCfgProps {
16
- indices: boolean;
17
- dotNotation: boolean;
18
- allowEmptyArrays: boolean;
19
- noFileListBrackets: boolean;
20
- nullsAsUndefineds?: boolean;
21
- booleansAsIntegers?: boolean;
22
- }
23
-
24
- // 'pre' is not provided until this function recursively calls itself when 'obj' is an array or object
25
- const serialize = (
26
- obj: any,
27
- cfg: ObjectToFormDataCfgProps,
28
- fd?: FormData,
29
- pre?: string
30
- ) => {
31
- cfg = cfg || {};
32
-
33
- cfg.indices = isUndefined(cfg.indices) ? false : cfg.indices;
34
-
35
- cfg.nullsAsUndefineds = isUndefined(cfg.nullsAsUndefineds)
36
- ? false
37
- : cfg.nullsAsUndefineds;
38
-
39
- cfg.booleansAsIntegers = isUndefined(cfg.booleansAsIntegers)
40
- ? false
41
- : cfg.booleansAsIntegers;
42
-
43
- cfg.allowEmptyArrays = isUndefined(cfg.allowEmptyArrays)
44
- ? false
45
- : cfg.allowEmptyArrays;
46
-
47
- //reverse of normal because we want a different default
48
- cfg.dotNotation = isUndefined(cfg.dotNotation) ? true : cfg.dotNotation;
49
-
50
- fd = fd || new FormData();
51
-
52
- if (isUndefined(obj)) {
53
- return fd;
54
- } else if (isNull(obj) && !!pre) {
55
- if (!cfg.nullsAsUndefineds) {
56
- fd.append(pre, '');
57
- }
58
- } else if (isBoolean(obj) && !!pre) {
59
- if (cfg.booleansAsIntegers) {
60
- fd.append(pre, obj ? '1' : '0');
61
- } else {
62
- fd.append(pre, obj);
63
- }
64
- } else if (isDate(obj) && !!pre) {
65
- fd.append(pre, obj.toISOString());
66
- } else if (isArray(obj)) {
67
- if (obj.length) {
68
- obj.forEach((value: any, index: number) => {
69
- let key;
70
- if (cfg.noFileListBrackets && isFile(value)) {
71
- key = pre;
72
- } else {
73
- key = pre + '[' + (cfg.indices ? index : '') + ']';
74
- }
75
- serialize(value, cfg, fd, key);
76
- });
77
- } else if (cfg.allowEmptyArrays) {
78
- fd.append(pre + '[]', '');
79
- }
80
- } else if (isObject(obj) && !isFile(obj) && !isBlob(obj)) {
81
- Object.keys(obj).forEach((prop) => {
82
- const value = obj[prop];
83
-
84
- if (isArray(value)) {
85
- while (prop.length > 2 && prop.lastIndexOf('[]') === prop.length - 2) {
86
- prop = prop.substring(0, prop.length - 2);
87
- }
88
- }
89
-
90
- const key = pre
91
- ? cfg.dotNotation
92
- ? pre + '.' + prop
93
- : pre + '[' + prop + ']'
94
- : prop;
95
-
96
- serialize(value, cfg, fd, key);
97
- });
98
- } else if (!!pre) {
99
- fd.append(pre, obj);
100
- }
101
-
102
- return fd;
103
- };
104
-
105
- export default serialize;
1
+ // Original: https://github.com/therealparmesh/object-to-formdata/blob/master/src/index.js
2
+ // With Multiple Form File Fix: https://github.com/therealparmesh/object-to-formdata/pull/94/files
3
+ import {
4
+ isArray,
5
+ isBlob,
6
+ isBoolean,
7
+ isDate,
8
+ isFile,
9
+ isNull,
10
+ isObject,
11
+ isUndefined,
12
+ } from './typeChecks';
13
+
14
+ // TODO: make all of these optional?
15
+ export interface ObjectToFormDataCfgProps {
16
+ indices: boolean;
17
+ dotNotation: boolean;
18
+ allowEmptyArrays: boolean;
19
+ noFileListBrackets: boolean;
20
+ nullsAsUndefineds?: boolean;
21
+ booleansAsIntegers?: boolean;
22
+ }
23
+
24
+ // 'pre' is not provided until this function recursively calls itself when 'obj' is an array or object
25
+ const serialize = (
26
+ obj: any,
27
+ cfg: ObjectToFormDataCfgProps,
28
+ fd?: FormData,
29
+ pre?: string
30
+ ) => {
31
+ cfg = cfg || {};
32
+
33
+ cfg.indices = isUndefined(cfg.indices) ? false : cfg.indices;
34
+
35
+ cfg.nullsAsUndefineds = isUndefined(cfg.nullsAsUndefineds)
36
+ ? false
37
+ : cfg.nullsAsUndefineds;
38
+
39
+ cfg.booleansAsIntegers = isUndefined(cfg.booleansAsIntegers)
40
+ ? false
41
+ : cfg.booleansAsIntegers;
42
+
43
+ cfg.allowEmptyArrays = isUndefined(cfg.allowEmptyArrays)
44
+ ? false
45
+ : cfg.allowEmptyArrays;
46
+
47
+ //reverse of normal because we want a different default
48
+ cfg.dotNotation = isUndefined(cfg.dotNotation) ? true : cfg.dotNotation;
49
+
50
+ fd = fd || new FormData();
51
+
52
+ if (isUndefined(obj)) {
53
+ return fd;
54
+ } else if (isNull(obj) && !!pre) {
55
+ if (!cfg.nullsAsUndefineds) {
56
+ fd.append(pre, '');
57
+ }
58
+ } else if (isBoolean(obj) && !!pre) {
59
+ if (cfg.booleansAsIntegers) {
60
+ fd.append(pre, obj ? '1' : '0');
61
+ } else {
62
+ fd.append(pre, obj);
63
+ }
64
+ } else if (isDate(obj) && !!pre) {
65
+ fd.append(pre, obj.toISOString());
66
+ } else if (isArray(obj)) {
67
+ if (obj.length) {
68
+ obj.forEach((value: any, index: number) => {
69
+ let key;
70
+ if (cfg.noFileListBrackets && isFile(value)) {
71
+ key = pre;
72
+ } else {
73
+ key = pre + '[' + (cfg.indices ? index : '') + ']';
74
+ }
75
+ serialize(value, cfg, fd, key);
76
+ });
77
+ } else if (cfg.allowEmptyArrays) {
78
+ fd.append(pre + '[]', '');
79
+ }
80
+ } else if (isObject(obj) && !isFile(obj) && !isBlob(obj)) {
81
+ Object.keys(obj).forEach((prop) => {
82
+ const value = obj[prop];
83
+
84
+ if (isArray(value)) {
85
+ while (prop.length > 2 && prop.lastIndexOf('[]') === prop.length - 2) {
86
+ prop = prop.substring(0, prop.length - 2);
87
+ }
88
+ }
89
+
90
+ const key = pre
91
+ ? cfg.dotNotation
92
+ ? pre + '.' + prop
93
+ : pre + '[' + prop + ']'
94
+ : prop;
95
+
96
+ serialize(value, cfg, fd, key);
97
+ });
98
+ } else if (!!pre) {
99
+ fd.append(pre, obj);
100
+ }
101
+
102
+ return fd;
103
+ };
104
+
105
+ export default serialize;
@@ -1,18 +1,18 @@
1
- export const isUndefined = (value: any) => value === undefined;
2
- export const isNull = (value: any) => value === null;
3
- export const isBoolean = (value: any) => typeof value === 'boolean';
4
- export const isObject = (value: any) => value === Object(value);
5
- export const isArray = (value: any) => Array.isArray(value);
6
- export const isDate = (value: any) => value instanceof Date;
7
-
8
- export const isBlob = (value: any) =>
9
- value &&
10
- typeof value.size === 'number' &&
11
- typeof value.type === 'string' &&
12
- typeof value.slice === 'function';
13
-
14
- export const isFile = (value: any) =>
15
- isBlob(value) &&
16
- typeof value.name === 'string' &&
17
- (typeof value.lastModifiedDate === 'object' ||
18
- typeof value.lastModified === 'number');
1
+ export const isUndefined = (value: any) => value === undefined;
2
+ export const isNull = (value: any) => value === null;
3
+ export const isBoolean = (value: any) => typeof value === 'boolean';
4
+ export const isObject = (value: any) => value === Object(value);
5
+ export const isArray = (value: any) => Array.isArray(value);
6
+ export const isDate = (value: any) => value instanceof Date;
7
+
8
+ export const isBlob = (value: any) =>
9
+ value &&
10
+ typeof value.size === 'number' &&
11
+ typeof value.type === 'string' &&
12
+ typeof value.slice === 'function';
13
+
14
+ export const isFile = (value: any) =>
15
+ isBlob(value) &&
16
+ typeof value.name === 'string' &&
17
+ (typeof value.lastModifiedDate === 'object' ||
18
+ typeof value.lastModified === 'number');