linear-react-components-ui 0.4.77-beta.25 → 0.4.77-beta.27
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/.eslintrc.json +2 -0
- package/.vscode/settings.json +2 -2
- package/babel.config.json +11 -0
- package/lib/@types/Align.d.ts +3 -0
- package/lib/@types/ButtonTypes.d.ts +3 -0
- package/lib/@types/ColorStyles.d.ts +3 -0
- package/lib/@types/DataCombo.d.ts +3 -0
- package/lib/@types/Icon.d.ts +5 -0
- package/lib/@types/LabelStyles.d.ts +3 -0
- package/lib/@types/Period.d.ts +6 -0
- package/lib/@types/PermissionAttr.d.ts +14 -0
- package/lib/@types/PointerEvents.d.ts +3 -0
- package/lib/@types/Position.d.ts +3 -0
- package/lib/@types/PositionAlert.d.ts +3 -0
- package/lib/@types/Size.d.ts +3 -0
- package/lib/@types/SizePixels.d.ts +3 -0
- package/lib/@types/StorageMock.d.ts +5 -0
- package/lib/alerts/AlertContainer.d.ts +16 -0
- package/lib/alerts/AlertProvider.d.ts +7 -0
- package/lib/alerts/AlertProvider.js +1 -1
- package/lib/alerts/BaseAlert.d.ts +7 -0
- package/lib/alerts/Message.d.ts +7 -0
- package/lib/alerts/helpers.d.ts +7 -0
- package/lib/alerts/index.d.ts +6 -0
- package/lib/alerts/types.d.ts +48 -0
- package/lib/alerts/withAlert.d.ts +7 -0
- package/lib/alerts/withAlert.js +5 -3
- package/lib/avatar/index.d.ts +12 -0
- package/lib/avatar/types.d.ts +31 -0
- package/lib/badge/index.d.ts +6 -0
- package/lib/badge/types.d.ts +13 -0
- package/lib/buttons/ActivateButton.d.ts +9 -0
- package/lib/buttons/AddButton.d.ts +9 -0
- package/lib/buttons/Button.d.ts +12 -0
- package/lib/buttons/ButtonGroups.d.ts +8 -0
- package/lib/buttons/CancelButton.d.ts +9 -0
- package/lib/buttons/DangerButton.d.ts +9 -0
- package/lib/buttons/DefaultButton.d.ts +12 -0
- package/lib/buttons/DefaultButton.js +5 -3
- package/lib/buttons/DestroyButton.d.ts +9 -0
- package/lib/buttons/EditButton.d.ts +9 -0
- package/lib/buttons/InactivateButton.d.ts +9 -0
- package/lib/buttons/InfoButton.d.ts +9 -0
- package/lib/buttons/PrimaryButton.d.ts +9 -0
- package/lib/buttons/RestoreButton.d.ts +9 -0
- package/lib/buttons/SaveButton.d.ts +9 -0
- package/lib/buttons/SuccessButton.d.ts +9 -0
- package/lib/buttons/WarningButton.d.ts +9 -0
- package/lib/buttons/button_container/index.d.ts +12 -0
- package/lib/buttons/index.d.ts +21 -0
- package/lib/buttons/split_button/index.d.ts +9 -0
- package/lib/buttons/split_button/index.js +22 -2
- package/lib/buttons/types.d.ts +44 -0
- package/lib/calendar/DangerCalendar.d.ts +7 -0
- package/lib/calendar/InfoCalendar.d.ts +7 -0
- package/lib/calendar/PrimaryCalendar.d.ts +7 -0
- package/lib/calendar/SuccessCalendar.d.ts +7 -0
- package/lib/calendar/WarningCalendar.d.ts +7 -0
- package/lib/calendar/base/Day.d.ts +7 -0
- package/lib/calendar/base/Month.d.ts +7 -0
- package/lib/calendar/base/Week.d.ts +7 -0
- package/lib/calendar/base/helpers.d.ts +62 -0
- package/lib/calendar/base/helpers.js +1 -1
- package/lib/calendar/base/index.d.ts +7 -0
- package/lib/calendar/index.d.ts +10 -0
- package/lib/calendar/types.d.ts +25 -0
- package/lib/checkbox/Label.d.ts +11 -0
- package/lib/checkbox/index.d.ts +13 -0
- package/lib/checkbox/index.js +1 -1
- package/lib/checkbox/types.d.ts +42 -0
- package/lib/dialog/Alert.d.ts +6 -0
- package/lib/dialog/Custom.d.ts +6 -0
- package/lib/dialog/Custom.js +4 -4
- package/lib/dialog/Error.d.ts +6 -0
- package/lib/dialog/Information.d.ts +6 -0
- package/lib/dialog/Question.d.ts +6 -0
- package/lib/dialog/Warning.d.ts +6 -0
- package/lib/dialog/base/Content.d.ts +6 -0
- package/lib/dialog/base/Footer.d.ts +6 -0
- package/lib/dialog/base/Header.d.ts +6 -0
- package/lib/dialog/base/index.d.ts +6 -0
- package/lib/dialog/form/index.d.ts +6 -0
- package/lib/dialog/index.d.ts +10 -0
- package/lib/dialog/types.d.ts +68 -0
- package/lib/drawer/Content.d.ts +7 -0
- package/lib/drawer/Drawer.d.ts +7 -0
- package/lib/drawer/Drawer.js +1 -1
- package/lib/drawer/Header.d.ts +7 -0
- package/lib/drawer/helpers.d.ts +7 -0
- package/lib/drawer/index.d.ts +9 -0
- package/lib/drawer/types.d.ts +34 -0
- package/lib/dropdown/Popup.d.ts +6 -0
- package/lib/dropdown/Popup.js +4 -2
- package/lib/dropdown/helper.d.ts +4 -0
- package/lib/dropdown/types.d.ts +43 -0
- package/lib/dropdown/withDropdown.d.ts +10 -0
- package/lib/dropdown/withDropdown.js +3 -1
- package/lib/fieldset/index.d.ts +8 -0
- package/lib/fieldset/index.js +1 -1
- package/lib/fieldset/types.d.ts +28 -0
- package/lib/form/Field.d.ts +6 -0
- package/lib/form/Field.js +11 -38
- package/lib/form/FieldArray.d.ts +6 -0
- package/lib/form/FieldArray.js +18 -48
- package/lib/form/FieldNumber.d.ts +6 -0
- package/lib/form/FieldNumber.js +2 -26
- package/lib/form/FieldPeriod.d.ts +6 -0
- package/lib/form/FieldPeriod.js +18 -40
- package/lib/form/helpers.d.ts +11 -0
- package/lib/form/helpers.js +10 -16
- package/lib/form/index.d.ts +9 -0
- package/lib/form/index.js +50 -85
- package/lib/form/types.d.ts +168 -0
- package/lib/{treetable/types.d.js → form/types.js} +0 -0
- package/lib/form/withFieldHOC.d.ts +6 -0
- package/lib/form/withFieldHOC.js +38 -118
- package/lib/form/withFormSecurity.d.ts +7 -0
- package/lib/form/withFormSecurity.js +13 -34
- package/lib/gridlayout/GridCol.d.ts +6 -0
- package/lib/gridlayout/GridRow.d.ts +6 -0
- package/lib/gridlayout/index.d.ts +5 -0
- package/lib/gridlayout/types.d.ts +20 -0
- package/lib/icons/helper.d.ts +560 -0
- package/lib/icons/index.d.ts +8 -0
- package/lib/icons/types.d.ts +28 -0
- package/lib/index.d.ts +35 -0
- package/lib/inputs/base/InputTextBase.d.ts +8 -0
- package/lib/inputs/base/InputTextBase.js +2 -2
- package/lib/inputs/base/helpers.d.ts +14 -0
- package/lib/inputs/base/helpers.js +1 -1
- package/lib/inputs/base/types.d.ts +68 -0
- package/lib/inputs/color/index.d.ts +7 -0
- package/lib/inputs/color/types.d.ts +14 -0
- package/lib/inputs/date/Dialog.d.ts +10 -0
- package/lib/inputs/date/Dropdown.d.ts +10 -0
- package/lib/inputs/date/helpers.d.ts +14 -0
- package/lib/inputs/date/index.d.ts +10 -0
- package/lib/inputs/date/types.d.ts +53 -0
- package/lib/inputs/inputHOC.d.ts +11 -0
- package/lib/inputs/mask/BaseMask.d.ts +12 -0
- package/lib/inputs/mask/Cnpj.d.ts +12 -0
- package/lib/inputs/mask/Cnpj.js +3 -1
- package/lib/inputs/mask/Cpf.d.ts +12 -0
- package/lib/inputs/mask/Cpf.js +5 -2
- package/lib/inputs/mask/Phone.d.ts +9 -0
- package/lib/inputs/mask/ZipCode.d.ts +9 -0
- package/lib/inputs/mask/helpers.d.ts +14 -0
- package/lib/inputs/mask/imaskHOC.d.ts +14 -0
- package/lib/inputs/mask/imaskHOC.js +9 -10
- package/lib/inputs/mask/index.d.ts +11 -0
- package/lib/inputs/mask/types.d.ts +66 -0
- package/lib/inputs/multiSelect/ActionButtons.d.ts +10 -0
- package/lib/inputs/multiSelect/Dropdown.d.ts +10 -0
- package/lib/inputs/multiSelect/helper.d.ts +9 -0
- package/lib/inputs/multiSelect/index.d.ts +10 -0
- package/lib/inputs/multiSelect/index.js +6 -3
- package/lib/inputs/multiSelect/types.d.ts +49 -0
- package/lib/inputs/number/BaseNumber.d.ts +12 -0
- package/lib/inputs/number/BaseNumber.js +1 -1
- package/lib/inputs/number/Currency.d.ts +12 -0
- package/lib/inputs/number/Decimal.d.ts +12 -0
- package/lib/inputs/number/format_number.d.ts +4 -0
- package/lib/inputs/number/index.d.ts +14 -0
- package/lib/inputs/number/types.d.ts +30 -0
- package/lib/inputs/period/Dialog.d.ts +11 -0
- package/lib/inputs/period/Dropdown.d.ts +11 -0
- package/lib/inputs/period/PeriodList.d.ts +11 -0
- package/lib/inputs/period/helper.d.ts +19 -0
- package/lib/inputs/period/index.d.ts +11 -0
- package/lib/inputs/period/index.js +7 -5
- package/lib/inputs/period/types.d.ts +58 -0
- package/lib/inputs/search/index.d.ts +11 -0
- package/lib/inputs/search/index.js +0 -3
- package/lib/inputs/select/ActionButtons.d.ts +11 -0
- package/lib/inputs/select/Dropdown.d.ts +11 -0
- package/lib/inputs/select/helper.d.ts +25 -0
- package/lib/inputs/select/index.d.ts +10 -0
- package/lib/inputs/select/index.js +3 -1
- package/lib/inputs/select/multiple/Selecteds.d.ts +10 -0
- package/lib/inputs/select/multiple/index.d.ts +10 -0
- package/lib/inputs/select/simple/index.d.ts +10 -0
- package/lib/inputs/select/simple/index.js +19 -1
- package/lib/inputs/select/types.d.ts +98 -0
- package/lib/inputs/text/index.d.ts +11 -0
- package/lib/inputs/text/types.d.ts +25 -0
- package/lib/inputs/textarea/index.d.ts +9 -0
- package/lib/inputs/textarea/types.d.ts +13 -0
- package/lib/inputs/types.d.ts +146 -0
- package/lib/internals/colorStyles.d.ts +9 -0
- package/lib/internals/constants.d.ts +11 -0
- package/lib/internals/types.d.ts +21 -0
- package/lib/internals/withTooltip.d.ts +11 -0
- package/lib/labelMessages/index.d.ts +7 -0
- package/lib/labelMessages/types.d.ts +18 -0
- package/lib/labels/DangerLabel.d.ts +9 -0
- package/lib/labels/DefaultLabel.d.ts +12 -0
- package/lib/labels/DefaultLabel.js +1 -1
- package/lib/labels/InfoLabel.d.ts +9 -0
- package/lib/labels/PrimaryLabel.d.ts +9 -0
- package/lib/labels/SuccessLabel.d.ts +9 -0
- package/lib/labels/WarningLabel.d.ts +9 -0
- package/lib/labels/index.d.ts +13 -0
- package/lib/labels/label_container/index.d.ts +12 -0
- package/lib/labels/types.d.ts +24 -0
- package/lib/list/Header.d.ts +7 -0
- package/lib/list/Item.d.ts +7 -0
- package/lib/list/Item.js +8 -6
- package/lib/list/Separator.d.ts +3 -0
- package/lib/list/helpers.d.ts +12 -0
- package/lib/list/helpers.js +8 -3
- package/lib/list/index.d.ts +10 -0
- package/lib/list/index.js +87 -18
- package/lib/list/types.d.ts +64 -0
- package/lib/menus/float/MenuItem.d.ts +7 -0
- package/lib/menus/float/helpers.d.ts +7 -0
- package/lib/menus/float/index.d.ts +8 -0
- package/lib/menus/float/types.d.ts +27 -0
- package/lib/menus/index.d.ts +6 -0
- package/lib/menus/sidenav/ExpandMenu.d.ts +10 -0
- package/lib/menus/sidenav/MenuLink.d.ts +13 -0
- package/lib/menus/sidenav/NavMenuGroup.d.ts +10 -0
- package/lib/menus/sidenav/NavMenuItem.d.ts +13 -0
- package/lib/menus/sidenav/NavMenuItem.js +1 -1
- package/lib/menus/sidenav/NavSubMenuItem.d.ts +10 -0
- package/lib/menus/sidenav/NavSubMenuItem.js +1 -1
- package/lib/menus/sidenav/helpers.d.ts +12 -0
- package/lib/menus/sidenav/index.d.ts +14 -0
- package/lib/menus/sidenav/popup_menu_search/EmptyList.d.ts +10 -0
- package/lib/menus/sidenav/popup_menu_search/index.d.ts +10 -0
- package/lib/menus/sidenav/types.d.ts +82 -0
- package/lib/noPermission/index.d.ts +3 -0
- package/lib/panel/Content.d.ts +8 -0
- package/lib/panel/DangerPanel.d.ts +8 -0
- package/lib/panel/Default.d.ts +8 -0
- package/lib/panel/Default.js +1 -1
- package/lib/panel/Header.d.ts +8 -0
- package/lib/panel/InfoPanel.d.ts +8 -0
- package/lib/panel/PrimaryPanel.d.ts +8 -0
- package/lib/panel/SuccessPanel.d.ts +8 -0
- package/lib/panel/ToolBar.d.ts +8 -0
- package/lib/panel/WarningPanel.d.ts +8 -0
- package/lib/panel/helpers.d.ts +4 -0
- package/lib/panel/index.d.ts +13 -0
- package/lib/panel/types.d.ts +4 -0
- package/lib/permissionValidations.d.ts +14 -0
- package/lib/permissionValidations.js +14 -12
- package/lib/popover/PopoverText.d.ts +8 -0
- package/lib/popover/PopoverTitle.d.ts +8 -0
- package/lib/popover/index.d.ts +13 -0
- package/lib/popover/types.d.ts +21 -0
- package/lib/progress/Bar.d.ts +6 -0
- package/lib/progress/index.d.ts +7 -0
- package/lib/progress/types.d.ts +37 -0
- package/lib/radio/index.d.ts +12 -0
- package/lib/radio/index.js +1 -1
- package/lib/radio/types.d.ts +18 -0
- package/lib/skeleton/SkeletonContainer.d.ts +7 -0
- package/lib/skeleton/SkeletonContainer.js +0 -13
- package/lib/skeleton/index.d.ts +8 -0
- package/lib/skeleton/index.js +6 -25
- package/lib/skeleton/types.d.ts +21 -0
- package/lib/skeleton/types.js +5 -0
- package/lib/spinner/SpinnerLoading.d.ts +7 -0
- package/lib/spinner/index.d.ts +7 -0
- package/lib/spinner/types.d.ts +20 -0
- package/lib/split/Split.d.ts +6 -0
- package/lib/split/SplitSide.d.ts +6 -0
- package/lib/split/helpers.d.ts +10 -0
- package/lib/split/index.d.ts +5 -0
- package/lib/split/types.d.ts +34 -0
- package/lib/table/Body.d.ts +6 -0
- package/lib/table/Header.d.ts +6 -0
- package/lib/table/Header.js +34 -6
- package/lib/table/HeaderColumn.d.ts +6 -0
- package/lib/table/HeaderColumn.js +1 -1
- package/lib/table/Row.d.ts +6 -0
- package/lib/table/Row.js +4 -9
- package/lib/table/RowColumn.d.ts +6 -0
- package/lib/table/RowColumn.js +2 -2
- package/lib/table/helpers.d.ts +8 -0
- package/lib/table/index.d.ts +11 -0
- package/lib/table/types.d.ts +84 -0
- package/lib/tabs/DropdownItems.d.ts +9 -0
- package/lib/tabs/Menu.d.ts +9 -0
- package/lib/tabs/MenuItems.d.ts +9 -0
- package/lib/tabs/MenuItems.js +1 -1
- package/lib/tabs/Panel.d.ts +9 -0
- package/lib/tabs/Panel.js +1 -1
- package/lib/tabs/index.d.ts +10 -0
- package/lib/tabs/tabHelpers.d.ts +21 -0
- package/lib/tabs/types.d.ts +63 -0
- package/lib/toolbar/ButtonBar.d.ts +10 -0
- package/lib/toolbar/LabelBar.d.ts +10 -0
- package/lib/toolbar/LabelBar.js +1 -1
- package/lib/toolbar/Separator.d.ts +3 -0
- package/lib/toolbar/ToolBarGroup.d.ts +10 -0
- package/lib/toolbar/helpers.d.ts +10 -0
- package/lib/toolbar/index.d.ts +14 -0
- package/lib/toolbar/index.js +2 -3
- package/lib/toolbar/types.d.ts +43 -0
- package/lib/tooltip/index.d.ts +6 -0
- package/lib/tooltip/types.d.ts +16 -0
- package/lib/treeview/Header.d.ts +7 -0
- package/lib/treeview/Node.d.ts +7 -0
- package/lib/treeview/Node.js +30 -18
- package/lib/treeview/constants.d.ts +7 -0
- package/lib/treeview/constants.js +0 -1
- package/lib/treeview/index.d.ts +9 -0
- package/lib/treeview/index.js +28 -21
- package/lib/treeview/types.d.ts +104 -0
- package/lib/types-3c6f1c20.d.ts +46 -0
- package/lib/uitour/helpers.d.ts +8 -0
- package/lib/uitour/index.d.ts +6 -0
- package/lib/uitour/index.js +11 -28
- package/lib/uitour/types.d.ts +30 -0
- package/lib/uitour/types.js +5 -0
- package/package.json +15 -5
- package/tsconfig.json +24 -9
- package/tsup.config.ts +10 -0
- package/images.d.ts +0 -3
- package/lib/alerts/alert.spec.js +0 -137
- package/lib/assets/styles/treetable.scss +0 -100
- package/lib/avatar/avatar.spec.js +0 -192
- package/lib/badge/badge.spec.js +0 -127
- package/lib/buttons/buttons.spec.js +0 -504
- package/lib/calendar/calendar.spec.js +0 -173
- package/lib/checkbox/checkbox.spec.js +0 -216
- package/lib/dialog/dialog.spec.js +0 -492
- package/lib/drawer/Drawer.spec.js +0 -261
- package/lib/dropdown/dropdown.spec.js +0 -181
- package/lib/fieldset/fieldset.spec.js +0 -329
- package/lib/form/form.spec.js +0 -295
- package/lib/gridlayout/gridLayout.spec.js +0 -169
- package/lib/icons/icons.spec.js +0 -86
- package/lib/inputs/base/base.spec.js +0 -691
- package/lib/inputs/color/color_input.spec.js +0 -174
- package/lib/inputs/date/date.spec.js +0 -352
- package/lib/inputs/mask/input_mask.spec.js +0 -584
- package/lib/inputs/number/numberfield.spec.js +0 -216
- package/lib/inputs/search/search_input.spec.js +0 -215
- package/lib/inputs/select/select.spec.js +0 -408
- package/lib/inputs/text/textfield.spec.js +0 -215
- package/lib/inputs/textarea/textarea.spec.js +0 -59
- package/lib/labelMessages/labelMessages.spec.js +0 -176
- package/lib/labels/label.spec.js +0 -162
- package/lib/list/list.spec.js +0 -739
- package/lib/menus/float/float-menu.spec.js +0 -227
- package/lib/menus/sidenav/sidenav.spec.js +0 -383
- package/lib/panel/panel.spec.js +0 -216
- package/lib/popover/popover.spec.js +0 -146
- package/lib/progress/progress.spec.js +0 -94
- package/lib/radio/radio.spec.js +0 -191
- package/lib/spinner/spinner.spec.js +0 -156
- package/lib/split/split.spec.js +0 -168
- package/lib/table/table.spec.js +0 -353
- package/lib/tabs/tabs.spec.js +0 -314
- package/lib/toolbar/toolbar.spec.js +0 -394
- package/lib/tooltip/tooltip.spec.js +0 -222
- package/lib/treetable/Body.js +0 -64
- package/lib/treetable/Header.js +0 -37
- package/lib/treetable/Row.js +0 -317
- package/lib/treetable/helpers.js +0 -51
- package/lib/treetable/index.js +0 -35
- package/lib/treeview/treeview.spec.js +0 -289
- package/lib/uitour/uitour.spec.js +0 -176
package/lib/form/index.js
CHANGED
|
@@ -27,8 +27,6 @@ exports.default = void 0;
|
|
|
27
27
|
|
|
28
28
|
var _react = _interopRequireWildcard(require("react"));
|
|
29
29
|
|
|
30
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
31
|
-
|
|
32
30
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
33
31
|
|
|
34
32
|
var _helpers = require("./helpers");
|
|
@@ -76,12 +74,12 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
76
74
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
77
75
|
|
|
78
76
|
var Form = function Form(_ref) {
|
|
79
|
-
var
|
|
77
|
+
var _ref$submitOnPressEnt = _ref.submitOnPressEnterKey,
|
|
78
|
+
submitOnPressEnterKey = _ref$submitOnPressEnt === void 0 ? true : _ref$submitOnPressEnt,
|
|
80
79
|
dataSource = _ref.dataSource,
|
|
81
80
|
securityBeforeUnload = _ref.securityBeforeUnload,
|
|
82
81
|
handlerReset = _ref.handlerReset,
|
|
83
82
|
handlerSubmit = _ref.handlerSubmit,
|
|
84
|
-
children = _ref.children,
|
|
85
83
|
handlerValidates = _ref.handlerValidates,
|
|
86
84
|
style = _ref.style,
|
|
87
85
|
customClass = _ref.customClass,
|
|
@@ -92,7 +90,8 @@ var Form = function Form(_ref) {
|
|
|
92
90
|
externalFieldErrors = _ref.externalFieldErrors,
|
|
93
91
|
onSubmit = _ref.onSubmit,
|
|
94
92
|
skeletonize = _ref.skeletonize,
|
|
95
|
-
disabled = _ref.disabled
|
|
93
|
+
disabled = _ref.disabled,
|
|
94
|
+
children = _ref.children;
|
|
96
95
|
|
|
97
96
|
var _useState = (0, _react.useState)(dataSource),
|
|
98
97
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -121,8 +120,10 @@ var Form = function Form(_ref) {
|
|
|
121
120
|
var validatorsArray = !(validators instanceof Array) ? [validators] : validators;
|
|
122
121
|
var errors = [];
|
|
123
122
|
validatorsArray.forEach(function (validator) {
|
|
124
|
-
|
|
125
|
-
|
|
123
|
+
if (typeof validator === 'function') {
|
|
124
|
+
var result = validator(fieldValue);
|
|
125
|
+
if (result) errors = [].concat(_toConsumableArray(errors), [result]);
|
|
126
|
+
}
|
|
126
127
|
});
|
|
127
128
|
return errors;
|
|
128
129
|
};
|
|
@@ -148,25 +149,9 @@ var Form = function Form(_ref) {
|
|
|
148
149
|
|
|
149
150
|
var onFieldChange = function onFieldChange(event) {
|
|
150
151
|
var target = event.target;
|
|
151
|
-
(
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
var newData = _extends({}, data);
|
|
155
|
-
|
|
156
|
-
if (context && context.onChangedData) {
|
|
157
|
-
var onChangedData = context.onChangedData;
|
|
158
|
-
|
|
159
|
-
if (!_lodash.default.isEqual(newData, originalData)) {
|
|
160
|
-
onChangedData(true);
|
|
161
|
-
} else {
|
|
162
|
-
onChangedData(false);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
setData(newData); // TODO - Usar debounce para evitar chamada a cada letra digitada
|
|
167
|
-
|
|
168
|
-
if (onValidateForm) onValidateForm(checkIsValid(newData, false));
|
|
169
|
-
if (onDataChange) onDataChange(newData);
|
|
152
|
+
setData(function (prevState) {
|
|
153
|
+
return (0, _helpers.changeValue)(prevState, target);
|
|
154
|
+
});
|
|
170
155
|
};
|
|
171
156
|
|
|
172
157
|
var onValidate = function onValidate(fieldName, fieldValue, validators) {
|
|
@@ -201,13 +186,14 @@ var Form = function Form(_ref) {
|
|
|
201
186
|
};
|
|
202
187
|
|
|
203
188
|
var onBeforeUnload = function onBeforeUnload(e) {
|
|
204
|
-
e
|
|
189
|
+
var event = e;
|
|
190
|
+
event.preventDefault();
|
|
205
191
|
|
|
206
192
|
if (_lodash.default.isEqual(data, originalData)) {
|
|
207
193
|
return;
|
|
208
194
|
}
|
|
209
195
|
|
|
210
|
-
|
|
196
|
+
event.returnValue = true;
|
|
211
197
|
};
|
|
212
198
|
|
|
213
199
|
var submitOnEnter = function submitOnEnter(event) {
|
|
@@ -217,31 +203,16 @@ var Form = function Form(_ref) {
|
|
|
217
203
|
}
|
|
218
204
|
};
|
|
219
205
|
|
|
220
|
-
var getContextValue = function getContextValue() {
|
|
221
|
-
return {
|
|
222
|
-
skeletonize: skeletonize,
|
|
223
|
-
handlerFieldChange: onFieldChange,
|
|
224
|
-
handlerFieldValidade: onValidate,
|
|
225
|
-
handlerStoreValidators: function handlerStoreValidators(fieldName, fieldValidates) {
|
|
226
|
-
fieldsValidators.current = _extends({}, fieldsValidators.current, _defineProperty({}, fieldName, fieldValidates));
|
|
227
|
-
},
|
|
228
|
-
handlerRemoveValidators: onRemoveFieldValidators,
|
|
229
|
-
data: data,
|
|
230
|
-
fieldErrors: fieldErrors,
|
|
231
|
-
externalFieldErrors: externalFieldErrors
|
|
232
|
-
};
|
|
233
|
-
};
|
|
234
|
-
|
|
235
206
|
var formProps = function formProps() {
|
|
236
207
|
var propsForm = null;
|
|
237
208
|
|
|
238
209
|
if (!disabled) {
|
|
239
210
|
propsForm = {
|
|
240
|
-
onSubmit: function onSubmit(
|
|
241
|
-
return
|
|
211
|
+
onSubmit: function onSubmit(event) {
|
|
212
|
+
return event.preventDefault();
|
|
242
213
|
},
|
|
243
|
-
onKeyPress: function onKeyPress(
|
|
244
|
-
return submitOnEnter(
|
|
214
|
+
onKeyPress: function onKeyPress(event) {
|
|
215
|
+
return submitOnEnter(event);
|
|
245
216
|
}
|
|
246
217
|
};
|
|
247
218
|
}
|
|
@@ -250,10 +221,24 @@ var Form = function Form(_ref) {
|
|
|
250
221
|
};
|
|
251
222
|
|
|
252
223
|
(0, _react.useEffect)(function () {
|
|
224
|
+
if (!_lodash.default.isEmpty(context)) {
|
|
225
|
+
var onChangedData = context.onChangedData;
|
|
226
|
+
|
|
227
|
+
if (!_lodash.default.isEqual(data, originalData)) {
|
|
228
|
+
onChangedData(true);
|
|
229
|
+
} else {
|
|
230
|
+
onChangedData(false);
|
|
231
|
+
}
|
|
232
|
+
} // TODO - Usar debounce para evitar chamada a cada letra digitada
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
if (onDataChange) onDataChange(data);
|
|
236
|
+
if (onValidateForm) onValidateForm(checkIsValid(data, false));
|
|
237
|
+
|
|
253
238
|
if (!disabled) {
|
|
254
239
|
handlerSubmit(onFormSubmit);
|
|
255
240
|
if (handlerReset) handlerReset(onReset);
|
|
256
|
-
if (handlerValidates) handlerValidates(checkIsValid);
|
|
241
|
+
if (handlerValidates) handlerValidates(checkIsValid(data));
|
|
257
242
|
}
|
|
258
243
|
}, [data]);
|
|
259
244
|
(0, _react.useEffect)(function () {
|
|
@@ -269,7 +254,9 @@ var Form = function Form(_ref) {
|
|
|
269
254
|
(0, _react.useEffect)(function () {
|
|
270
255
|
if (!disabled) {
|
|
271
256
|
if (submitOnPressEnterKey !== submitFormOnEnter || dataSource !== originalData) {
|
|
272
|
-
setData(
|
|
257
|
+
setData(function (prevState) {
|
|
258
|
+
return !_lodash.default.isEqual(data, dataSource) ? dataSource : prevState;
|
|
259
|
+
});
|
|
273
260
|
setOriginalData(function (prevState) {
|
|
274
261
|
return prevState || dataSource;
|
|
275
262
|
});
|
|
@@ -277,8 +264,20 @@ var Form = function Form(_ref) {
|
|
|
277
264
|
}
|
|
278
265
|
}
|
|
279
266
|
}, [submitOnPressEnterKey, dataSource]);
|
|
267
|
+
var contextValues = {
|
|
268
|
+
skeletonize: skeletonize,
|
|
269
|
+
handlerFieldChange: onFieldChange,
|
|
270
|
+
handlerFieldValidade: onValidate,
|
|
271
|
+
handlerStoreValidators: function handlerStoreValidators(fieldName, fieldValidates) {
|
|
272
|
+
fieldsValidators.current = _extends({}, fieldsValidators.current, _defineProperty({}, fieldName, fieldValidates));
|
|
273
|
+
},
|
|
274
|
+
handlerRemoveValidators: onRemoveFieldValidators,
|
|
275
|
+
data: data,
|
|
276
|
+
fieldErrors: fieldErrors,
|
|
277
|
+
externalFieldErrors: externalFieldErrors
|
|
278
|
+
};
|
|
280
279
|
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(_helpers.FormContext.Provider, {
|
|
281
|
-
value:
|
|
280
|
+
value: contextValues
|
|
282
281
|
}, /*#__PURE__*/_react.default.createElement("form", _extends({
|
|
283
282
|
style: style
|
|
284
283
|
}, formProps(), {
|
|
@@ -288,45 +287,11 @@ var Form = function Form(_ref) {
|
|
|
288
287
|
zIndex: "99999999",
|
|
289
288
|
title: securityTitle || 'Dados Alterados',
|
|
290
289
|
text: securityText || 'Você possui dados alterados, confirma o fechamento?',
|
|
291
|
-
visible:
|
|
290
|
+
visible: !_lodash.default.isEmpty(context) && context.showQuestion,
|
|
292
291
|
onConfirmClick: context ? context.onConfirmClick : function () {},
|
|
293
292
|
onUnconfirmClick: context ? context.onUnconfirmClick : function () {}
|
|
294
293
|
}));
|
|
295
294
|
};
|
|
296
295
|
|
|
297
|
-
Form.propTypes = {
|
|
298
|
-
dataSource: _propTypes.default.object.isRequired,
|
|
299
|
-
children: _propTypes.default.any.isRequired,
|
|
300
|
-
onSubmit: _propTypes.default.func.isRequired,
|
|
301
|
-
handlerSubmit: _propTypes.default.func.isRequired,
|
|
302
|
-
handlerReset: _propTypes.default.func,
|
|
303
|
-
handlerValidates: _propTypes.default.func,
|
|
304
|
-
onValidateForm: _propTypes.default.func,
|
|
305
|
-
submitOnPressEnterKey: _propTypes.default.bool,
|
|
306
|
-
style: _propTypes.default.object,
|
|
307
|
-
customClass: _propTypes.default.string,
|
|
308
|
-
onDataChange: _propTypes.default.func,
|
|
309
|
-
securityBeforeUnload: _propTypes.default.bool,
|
|
310
|
-
securityTitle: _propTypes.default.string,
|
|
311
|
-
securityText: _propTypes.default.string,
|
|
312
|
-
externalFieldErrors: _propTypes.default.object,
|
|
313
|
-
skeletonize: _propTypes.default.bool,
|
|
314
|
-
disabled: _propTypes.default.bool
|
|
315
|
-
};
|
|
316
|
-
Form.defaultProps = {
|
|
317
|
-
onValidateForm: undefined,
|
|
318
|
-
submitOnPressEnterKey: true,
|
|
319
|
-
style: {},
|
|
320
|
-
handlerReset: undefined,
|
|
321
|
-
handlerValidates: undefined,
|
|
322
|
-
customClass: '',
|
|
323
|
-
onDataChange: undefined,
|
|
324
|
-
securityBeforeUnload: false,
|
|
325
|
-
securityTitle: null,
|
|
326
|
-
securityText: null,
|
|
327
|
-
externalFieldErrors: {},
|
|
328
|
-
skeletonize: false,
|
|
329
|
-
disabled: false
|
|
330
|
-
};
|
|
331
296
|
var _default = Form;
|
|
332
297
|
exports.default = _default;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { ReactNode, CSSProperties, ChangeEvent, ComponentType, MouseEventHandler } from 'react';
|
|
2
|
+
|
|
3
|
+
declare type Validator = (value: string) => string | undefined;
|
|
4
|
+
declare type PeriodValidator = (value: {
|
|
5
|
+
initialData: string;
|
|
6
|
+
finalData: string;
|
|
7
|
+
}) => string | undefined;
|
|
8
|
+
declare type OnFielChangeEvent = Event & {
|
|
9
|
+
target: HTMLInputElement;
|
|
10
|
+
};
|
|
11
|
+
interface IFormProps {
|
|
12
|
+
dataSource: object;
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
onSubmit: (data: object) => void;
|
|
15
|
+
handlerSubmit: (value: () => void) => void;
|
|
16
|
+
handlerReset?: (value: () => void) => void;
|
|
17
|
+
handlerValidates?: (value: any) => void;
|
|
18
|
+
onValidateForm?: (value: boolean) => void;
|
|
19
|
+
submitOnPressEnterKey?: boolean;
|
|
20
|
+
style?: CSSProperties;
|
|
21
|
+
customClass?: string;
|
|
22
|
+
onDataChange?: (data: object) => void;
|
|
23
|
+
securityBeforeUnload?: boolean;
|
|
24
|
+
securityTitle?: string;
|
|
25
|
+
securityText?: string;
|
|
26
|
+
externalFieldErrors?: object;
|
|
27
|
+
skeletonize?: boolean;
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
}
|
|
30
|
+
interface IFieldProps extends WithFieldProps {
|
|
31
|
+
data?: object;
|
|
32
|
+
dataSource?: object;
|
|
33
|
+
name: string;
|
|
34
|
+
value?: string;
|
|
35
|
+
label?: string;
|
|
36
|
+
handlerFieldChange?: (event: ChangeEvent) => ChangeEvent;
|
|
37
|
+
handlerFieldValidade?: (name: string, value: string, validatorsArray: Validator[] | Validator) => void;
|
|
38
|
+
component: ComponentType<any>;
|
|
39
|
+
componentType?: 'Radio' | 'Checkbox';
|
|
40
|
+
onChange?: (event: ChangeEvent) => ChangeEvent;
|
|
41
|
+
onBlur?: () => void;
|
|
42
|
+
validators?: Validator | Validator[];
|
|
43
|
+
fieldErrors?: {
|
|
44
|
+
[name: string]: string[];
|
|
45
|
+
};
|
|
46
|
+
externalFieldErrors?: {
|
|
47
|
+
[name: string]: string[];
|
|
48
|
+
};
|
|
49
|
+
externalMessagesErrors?: string[];
|
|
50
|
+
fieldId?: string;
|
|
51
|
+
scale?: number;
|
|
52
|
+
required?: boolean;
|
|
53
|
+
idKey?: string;
|
|
54
|
+
descriptionKey?: string;
|
|
55
|
+
showClearButton?: boolean;
|
|
56
|
+
gridLayout?: string;
|
|
57
|
+
}
|
|
58
|
+
interface CustomEvent {
|
|
59
|
+
target: {
|
|
60
|
+
value: string[];
|
|
61
|
+
name: string;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
interface IFieldArrayProps extends WithFieldProps {
|
|
65
|
+
data?: object;
|
|
66
|
+
dataSource?: object;
|
|
67
|
+
name: string;
|
|
68
|
+
handlerFieldChange?: (event: CustomEvent) => void;
|
|
69
|
+
fieldErrors?: {
|
|
70
|
+
[name: string]: string[];
|
|
71
|
+
};
|
|
72
|
+
component?: ComponentType<any>;
|
|
73
|
+
validators?: Validator | Validator[];
|
|
74
|
+
valuePropName?: string;
|
|
75
|
+
changePropName?: string;
|
|
76
|
+
handlerSelecionados?: (ids: string[]) => void;
|
|
77
|
+
label?: string;
|
|
78
|
+
skipLabel?: boolean;
|
|
79
|
+
bordered?: boolean;
|
|
80
|
+
cols?: string;
|
|
81
|
+
labelContainerStyle?: object;
|
|
82
|
+
externalMessagesErrors?: string[];
|
|
83
|
+
idKey?: string;
|
|
84
|
+
descriptionKey?: string;
|
|
85
|
+
showClearButton?: boolean;
|
|
86
|
+
gridLayout?: string;
|
|
87
|
+
multiple?: boolean;
|
|
88
|
+
disabled?: boolean;
|
|
89
|
+
}
|
|
90
|
+
declare type PeriodChangeEvent = {
|
|
91
|
+
initial: string;
|
|
92
|
+
final: string;
|
|
93
|
+
};
|
|
94
|
+
declare type PeriodFieldChangeEvent = {
|
|
95
|
+
target: {
|
|
96
|
+
name: string;
|
|
97
|
+
value: string;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
interface IFieldPeriodProps extends WithFieldProps {
|
|
101
|
+
data?: object;
|
|
102
|
+
nameDateInitial: string;
|
|
103
|
+
nameDateFinal: string;
|
|
104
|
+
handlerFieldChange?: (event: PeriodFieldChangeEvent) => PeriodFieldChangeEvent;
|
|
105
|
+
label?: string;
|
|
106
|
+
component?: ComponentType<any>;
|
|
107
|
+
onBlur?: () => void;
|
|
108
|
+
validators?: PeriodValidator | PeriodValidator[];
|
|
109
|
+
fieldErrors?: {
|
|
110
|
+
[name: string]: string[];
|
|
111
|
+
};
|
|
112
|
+
externalMessagesErrors?: string[];
|
|
113
|
+
handlerFieldValidade?: (name: string, value: object, validatorsArray: PeriodValidator[] | PeriodValidator) => void;
|
|
114
|
+
onChange?: (event: PeriodChangeEvent) => PeriodChangeEvent;
|
|
115
|
+
}
|
|
116
|
+
interface FormContextProps {
|
|
117
|
+
skeletonize?: boolean;
|
|
118
|
+
handlerFieldChange: (event: OnFielChangeEvent) => void;
|
|
119
|
+
handlerFieldValidade: (name: string, value: string, validatorsArray: Validator[] | Validator) => void;
|
|
120
|
+
handlerStoreValidators: (fieldName: string, fieldValidates: object) => void;
|
|
121
|
+
handlerRemoveValidators: (fieldName: string) => void;
|
|
122
|
+
data: object;
|
|
123
|
+
fieldErrors: object;
|
|
124
|
+
externalFieldErrors?: object;
|
|
125
|
+
}
|
|
126
|
+
interface WithFieldProps {
|
|
127
|
+
name: string;
|
|
128
|
+
handlerStoreValidators?: (name: string, validators: Validator | Validator[]) => void;
|
|
129
|
+
handlerRemoveValidators?: (name: string) => void;
|
|
130
|
+
validators?: Validator | Validator[] | PeriodValidator | PeriodValidator[];
|
|
131
|
+
}
|
|
132
|
+
interface IWithFieldContext {
|
|
133
|
+
handlerSetValidatorFromComponent: (validator: Validator | Validator[]) => void;
|
|
134
|
+
}
|
|
135
|
+
interface IWithFormSecurity {
|
|
136
|
+
handlerClose?: () => void;
|
|
137
|
+
onClick?: MouseEventHandler;
|
|
138
|
+
children?: ReactNode;
|
|
139
|
+
}
|
|
140
|
+
interface IFormSecurityContext {
|
|
141
|
+
onChangedData: (value: boolean) => void;
|
|
142
|
+
showQuestion: boolean;
|
|
143
|
+
onConfirmClick: () => void;
|
|
144
|
+
onUnconfirmClick: () => void;
|
|
145
|
+
setSecurityBeforeUnload: (value: boolean) => void;
|
|
146
|
+
securityBeforeUnload?: boolean;
|
|
147
|
+
}
|
|
148
|
+
interface IOnBlurParams {
|
|
149
|
+
name: string;
|
|
150
|
+
data?: object;
|
|
151
|
+
validators?: Validator | Validator[];
|
|
152
|
+
onBlur?: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
153
|
+
handlerFieldValidade?: (name: string, value: string, validatorsArray: Validator[] | Validator) => void;
|
|
154
|
+
handlerFieldChange?: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
155
|
+
validatorFromComponent?: Validator | Validator[];
|
|
156
|
+
}
|
|
157
|
+
interface IGetErrorMessagesParams {
|
|
158
|
+
name: string;
|
|
159
|
+
fieldErrors?: {
|
|
160
|
+
[name: string]: string[];
|
|
161
|
+
};
|
|
162
|
+
externalFieldErrors?: {
|
|
163
|
+
[name: string]: string[];
|
|
164
|
+
};
|
|
165
|
+
externalMessagesErrors?: string[];
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export { CustomEvent, FormContextProps, IFieldArrayProps, IFieldPeriodProps, IFieldProps, IFormProps, IFormSecurityContext, IGetErrorMessagesParams, IOnBlurParams, IWithFieldContext, IWithFormSecurity, OnFielChangeEvent, PeriodChangeEvent, PeriodValidator, Validator, WithFieldProps };
|
|
File without changes
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React__default from 'react';
|
|
2
|
+
import { WithFieldProps } from './types.js';
|
|
3
|
+
|
|
4
|
+
declare const withFieldHOC: <ComponentProps extends WithFieldProps>(WrappedComponent: React__default.ComponentType<ComponentProps>) => React__default.ForwardRefExoticComponent<React__default.PropsWithoutRef<ComponentProps> & React__default.RefAttributes<HTMLElement>>;
|
|
5
|
+
|
|
6
|
+
export { withFieldHOC as default };
|
package/lib/form/withFieldHOC.js
CHANGED
|
@@ -9,141 +9,61 @@ exports.default = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
11
11
|
|
|
12
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
|
-
|
|
14
12
|
var _helpers = require("./helpers");
|
|
15
13
|
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
14
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
15
|
|
|
20
16
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
17
|
|
|
22
18
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
23
19
|
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
27
|
-
|
|
28
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
29
|
-
|
|
30
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
31
|
-
|
|
32
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
20
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
33
21
|
|
|
34
|
-
function
|
|
22
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
35
23
|
|
|
36
|
-
function
|
|
24
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
37
25
|
|
|
38
|
-
function
|
|
26
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
39
27
|
|
|
40
|
-
function
|
|
28
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
41
29
|
|
|
42
|
-
function
|
|
30
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
43
31
|
|
|
44
|
-
function withFieldHOC(WrappedComponent) {
|
|
45
|
-
var
|
|
46
|
-
|
|
32
|
+
var withFieldHOC = function withFieldHOC(WrappedComponent) {
|
|
33
|
+
var EnhancedComponent = function EnhancedComponent(props) {
|
|
34
|
+
var name = props.name,
|
|
35
|
+
validators = props.validators,
|
|
36
|
+
handlerStoreValidators = props.handlerStoreValidators,
|
|
37
|
+
handlerRemoveValidators = props.handlerRemoveValidators;
|
|
47
38
|
|
|
48
|
-
var
|
|
39
|
+
var _useState = (0, _react.useState)(undefined),
|
|
40
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
41
|
+
validatorFromComponent = _useState2[0],
|
|
42
|
+
setValidatorFromComponent = _useState2[1];
|
|
49
43
|
|
|
50
|
-
function
|
|
51
|
-
var
|
|
44
|
+
var updateValidators = function updateValidators() {
|
|
45
|
+
var validatorsArray = (0, _helpers.getValidatorsArray)(validators, validatorFromComponent);
|
|
46
|
+
if (validatorsArray && handlerStoreValidators) handlerStoreValidators(name, validatorsArray);
|
|
47
|
+
};
|
|
52
48
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
configurable: true,
|
|
58
|
-
enumerable: true,
|
|
59
|
-
writable: true,
|
|
60
|
-
value: function value() {
|
|
61
|
-
return {
|
|
62
|
-
handlerSetValidatorFromComponent: function handlerSetValidatorFromComponent(validatorFromComponent) {
|
|
63
|
-
_this.setState({
|
|
64
|
-
validatorFromComponent: validatorFromComponent
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
Object.defineProperty(_assertThisInitialized(_this), "updateValidators", {
|
|
71
|
-
configurable: true,
|
|
72
|
-
enumerable: true,
|
|
73
|
-
writable: true,
|
|
74
|
-
value: function value() {
|
|
75
|
-
var _this$props = _this.props,
|
|
76
|
-
name = _this$props.name,
|
|
77
|
-
validators = _this$props.validators,
|
|
78
|
-
handlerStoreValidators = _this$props.handlerStoreValidators;
|
|
79
|
-
var validatorFromComponent = _this.state.validatorFromComponent;
|
|
80
|
-
var validatorsArray = (0, _helpers.getValidatorsArray)(validators, validatorFromComponent);
|
|
81
|
-
if (validatorsArray) handlerStoreValidators(name, validatorsArray);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
_this.state = {
|
|
85
|
-
validatorFromComponent: undefined
|
|
49
|
+
(0, _react.useEffect)(function () {
|
|
50
|
+
updateValidators();
|
|
51
|
+
return function () {
|
|
52
|
+
if (validators && handlerRemoveValidators) handlerRemoveValidators(name);
|
|
86
53
|
};
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
}, {
|
|
96
|
-
key: "componentDidUpdate",
|
|
97
|
-
value: function componentDidUpdate(prevProps) {
|
|
98
|
-
// Update field validators only if receives validators after mounted or
|
|
99
|
-
// the validators change
|
|
100
|
-
// There are situation in that fields are mounted first than the criteria to be available.
|
|
101
|
-
// One example about it, is a validators that depend another field
|
|
102
|
-
var validators = prevProps.validators;
|
|
103
|
-
|
|
104
|
-
if (!validators || validators !== this.props.validators) {
|
|
105
|
-
this.updateValidators();
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}, {
|
|
109
|
-
key: "componentWillUnmount",
|
|
110
|
-
value: function componentWillUnmount() {
|
|
111
|
-
var _this$props2 = this.props,
|
|
112
|
-
name = _this$props2.name,
|
|
113
|
-
validators = _this$props2.validators,
|
|
114
|
-
handlerRemoveValidators = _this$props2.handlerRemoveValidators;
|
|
115
|
-
if (validators) handlerRemoveValidators(name);
|
|
116
|
-
}
|
|
117
|
-
}, {
|
|
118
|
-
key: "render",
|
|
119
|
-
value: function render() {
|
|
120
|
-
return /*#__PURE__*/_react.default.createElement(_helpers.withFieldContext.Provider, {
|
|
121
|
-
value: this.getContextValues()
|
|
122
|
-
}, /*#__PURE__*/_react.default.createElement(WrappedComponent, this.props));
|
|
123
|
-
}
|
|
124
|
-
}], [{
|
|
125
|
-
key: "defaultProps",
|
|
126
|
-
get: function get() {
|
|
127
|
-
return {
|
|
128
|
-
validators: undefined
|
|
129
|
-
};
|
|
54
|
+
}, []);
|
|
55
|
+
(0, _react.useEffect)(function () {
|
|
56
|
+
updateValidators();
|
|
57
|
+
}, [validators]);
|
|
58
|
+
var contextValues = {
|
|
59
|
+
handlerSetValidatorFromComponent: function handlerSetValidatorFromComponent(validator) {
|
|
60
|
+
setValidatorFromComponent(validator);
|
|
130
61
|
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
Object.defineProperty(FieldHOC, "propTypes", {
|
|
137
|
-
configurable: true,
|
|
138
|
-
enumerable: true,
|
|
139
|
-
writable: true,
|
|
140
|
-
value: {
|
|
141
|
-
name: _propTypes.default.string.isRequired,
|
|
142
|
-
validators: _propTypes.default.any,
|
|
143
|
-
handlerStoreValidators: _propTypes.default.func.isRequired,
|
|
144
|
-
handlerRemoveValidators: _propTypes.default.func.isRequired
|
|
145
|
-
}
|
|
146
|
-
});
|
|
62
|
+
};
|
|
63
|
+
return /*#__PURE__*/_react.default.createElement(_helpers.withFieldContext.Provider, {
|
|
64
|
+
value: contextValues
|
|
65
|
+
}, /*#__PURE__*/_react.default.createElement(WrappedComponent, props));
|
|
66
|
+
};
|
|
147
67
|
|
|
148
68
|
function forwardRef(props, ref) {
|
|
149
69
|
return /*#__PURE__*/_react.default.createElement(_helpers.FormContext.Consumer, null, function (_ref) {
|
|
@@ -155,7 +75,7 @@ function withFieldHOC(WrappedComponent) {
|
|
|
155
75
|
handlerStoreValidators = _ref.handlerStoreValidators,
|
|
156
76
|
handlerRemoveValidators = _ref.handlerRemoveValidators,
|
|
157
77
|
skeletonize = _ref.skeletonize;
|
|
158
|
-
return /*#__PURE__*/_react.default.createElement(
|
|
78
|
+
return /*#__PURE__*/_react.default.createElement(EnhancedComponent, _extends({}, props, {
|
|
159
79
|
skeletonize: skeletonize,
|
|
160
80
|
handlerFieldChange: handlerFieldChange,
|
|
161
81
|
handlerFieldValidade: handlerFieldValidade,
|
|
@@ -170,7 +90,7 @@ function withFieldHOC(WrappedComponent) {
|
|
|
170
90
|
}
|
|
171
91
|
|
|
172
92
|
return /*#__PURE__*/_react.default.forwardRef(forwardRef);
|
|
173
|
-
}
|
|
93
|
+
};
|
|
174
94
|
|
|
175
95
|
var _default = withFieldHOC;
|
|
176
96
|
exports.default = _default;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React__default from 'react';
|
|
2
|
+
import { IFormSecurityContext, IWithFormSecurity } from './types.js';
|
|
3
|
+
|
|
4
|
+
declare const FormSecurityContext: React__default.Context<IFormSecurityContext>;
|
|
5
|
+
declare const withFormSecurity: <ComponentProps extends IWithFormSecurity>(WrappedComponent: React__default.ComponentType<ComponentProps>) => (props: ComponentProps) => JSX.Element;
|
|
6
|
+
|
|
7
|
+
export { FormSecurityContext, withFormSecurity as default };
|