pixel-react 1.13.89 → 1.13.90
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/README.md +75 -75
- package/lib/_virtual/_commonjsHelpers.js +26 -1
- package/lib/_virtual/_commonjsHelpers.js.map +1 -1
- package/lib/_virtual/immutable.es.js +7 -0
- package/lib/_virtual/immutable.es.js.map +1 -0
- package/lib/_virtual/index10.js +2 -2
- package/lib/_virtual/index11.js +2 -2
- package/lib/_virtual/index14.js +4 -0
- package/lib/_virtual/index14.js.map +1 -0
- package/lib/_virtual/react-is.development2.js +4 -0
- package/lib/_virtual/react-is.development2.js.map +1 -0
- package/lib/_virtual/react-is.production.min2.js +4 -0
- package/lib/_virtual/react-is.production.min2.js.map +1 -0
- package/lib/assets/icons/spinner.svg.js +1 -1
- package/lib/assets/icons/spinner.svg.js.map +1 -1
- package/lib/components/DatePicker/DatePicker.js +4 -1
- package/lib/components/DatePicker/DatePicker.js.map +1 -1
- package/lib/components/Drawer/Drawer.js +2 -1
- package/lib/components/Drawer/Drawer.js.map +1 -1
- package/lib/components/Excel/ExcelFile/ExcelFile.d.ts +1 -0
- package/lib/components/Excel/ExcelFile/ExcelFile.js +4 -2
- package/lib/components/Excel/ExcelFile/ExcelFile.js.map +1 -1
- package/lib/components/Excel/ExcelFile/ExcelFileComponents/Spreadsheet.d.ts +1 -0
- package/lib/components/Excel/ExcelFile/ExcelFileComponents/Spreadsheet.js +4 -3
- package/lib/components/Excel/ExcelFile/ExcelFileComponents/Spreadsheet.js.map +1 -1
- package/lib/index.cjs +7029 -2517
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/node_modules/draft-js/lib/AtomicBlockUtils.js +1 -1
- package/lib/node_modules/draft-js/lib/BlockMapBuilder.js +1 -1
- package/lib/node_modules/draft-js/lib/BlockTree.js +1 -1
- package/lib/node_modules/draft-js/lib/CharacterMetadata.js +1 -1
- package/lib/node_modules/draft-js/lib/CompositeDraftDecorator.js +1 -1
- package/lib/node_modules/draft-js/lib/ContentBlock.js +1 -1
- package/lib/node_modules/draft-js/lib/ContentBlockNode.js +1 -1
- package/lib/node_modules/draft-js/lib/ContentState.js +1 -1
- package/lib/node_modules/draft-js/lib/ContentStateInlineStyle.js +1 -1
- package/lib/node_modules/draft-js/lib/DOMObserver.js +1 -1
- package/lib/node_modules/draft-js/lib/DefaultDraftBlockRenderMap.js +1 -1
- package/lib/node_modules/draft-js/lib/DraftEditorBlockNode.react.js +1 -1
- package/lib/node_modules/draft-js/lib/DraftEditorNode.react.js +1 -1
- package/lib/node_modules/draft-js/lib/DraftEntity.js +1 -1
- package/lib/node_modules/draft-js/lib/DraftEntityInstance.js +1 -1
- package/lib/node_modules/draft-js/lib/DraftModifier.js +1 -1
- package/lib/node_modules/draft-js/lib/DraftPasteProcessor.js +1 -1
- package/lib/node_modules/draft-js/lib/EditorBidiService.js +1 -1
- package/lib/node_modules/draft-js/lib/EditorState.js +1 -1
- package/lib/node_modules/draft-js/lib/SelectionState.js +1 -1
- package/lib/node_modules/draft-js/lib/applyEntityToContentState.js +1 -1
- package/lib/node_modules/draft-js/lib/convertFromHTMLToContentBlocks.js +1 -1
- package/lib/node_modules/draft-js/lib/convertFromRawToDraftState.js +1 -1
- package/lib/node_modules/draft-js/lib/createCharacterList.js +1 -1
- package/lib/node_modules/draft-js/lib/decodeInlineStyleRanges.js +1 -1
- package/lib/node_modules/draft-js/lib/insertFragmentIntoContentState.js +1 -1
- package/lib/node_modules/draft-js/lib/insertTextIntoContentState.js +1 -1
- package/lib/node_modules/draft-js/lib/modifyBlockForContentState.js +1 -1
- package/lib/node_modules/draft-js/lib/moveBlockInContentState.js +1 -1
- package/lib/node_modules/draft-js/lib/randomizeBlockMapKeys.js +1 -1
- package/lib/node_modules/draft-js/lib/removeRangeFromContentState.js +1 -1
- package/lib/node_modules/draft-js/lib/splitBlockInContentState.js +1 -1
- package/lib/node_modules/{immutable → draft-js/node_modules/immutable}/dist/immutable.js +1 -1
- package/lib/node_modules/draft-js/node_modules/immutable/dist/immutable.js.map +1 -0
- package/lib/node_modules/hoist-non-react-statics/dist/hoist-non-react-statics.cjs.js +1 -1
- package/lib/node_modules/hoist-non-react-statics/node_modules/react-is/cjs/react-is.development.js +175 -0
- package/lib/node_modules/hoist-non-react-statics/node_modules/react-is/cjs/react-is.development.js.map +1 -0
- package/lib/node_modules/hoist-non-react-statics/node_modules/react-is/cjs/react-is.production.min.js +125 -0
- package/lib/node_modules/hoist-non-react-statics/node_modules/react-is/cjs/react-is.production.min.js.map +1 -0
- package/lib/node_modules/{react-is → hoist-non-react-statics/node_modules/react-is}/index.js +1 -1
- package/lib/node_modules/hoist-non-react-statics/node_modules/react-is/index.js.map +1 -0
- package/lib/node_modules/immutable/dist/immutable.es.js +4829 -0
- package/lib/node_modules/immutable/dist/immutable.es.js.map +1 -0
- package/lib/node_modules/js-beautify/js/src/css/beautifier.js +1 -1
- package/lib/node_modules/js-beautify/js/src/css/index.js +1 -1
- package/lib/node_modules/js-beautify/js/src/css/options.js +1 -1
- package/lib/node_modules/js-beautify/js/src/html/beautifier.js +1 -1
- package/lib/node_modules/js-beautify/js/src/html/index.js +1 -1
- package/lib/node_modules/js-beautify/js/src/html/options.js +1 -1
- package/lib/node_modules/libphonenumber-js/metadata.min.json.js +12 -12
- package/lib/node_modules/libphonenumber-js/metadata.min.json.js.map +1 -1
- package/lib/node_modules/prop-types/factoryWithTypeCheckers.js +1 -1
- package/lib/node_modules/prop-types/index.js +1 -1
- package/lib/node_modules/{react-is → prop-types/node_modules/react-is}/cjs/react-is.development.js +1 -1
- package/lib/node_modules/prop-types/node_modules/react-is/cjs/react-is.development.js.map +1 -0
- package/lib/node_modules/{react-is → prop-types/node_modules/react-is}/cjs/react-is.production.min.js +1 -1
- package/lib/node_modules/prop-types/node_modules/react-is/cjs/react-is.production.min.js.map +1 -0
- package/lib/node_modules/prop-types/node_modules/react-is/index.js +18 -0
- package/lib/node_modules/prop-types/node_modules/react-is/index.js.map +1 -0
- package/lib/node_modules/react-day-picker/dist/esm/DayPicker.js +17 -112
- package/lib/node_modules/react-day-picker/dist/esm/DayPicker.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/UI.js +9 -31
- package/lib/node_modules/react-day-picker/dist/esm/UI.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/classes/CalendarDay.js +6 -9
- package/lib/node_modules/react-day-picker/dist/esm/classes/CalendarDay.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/classes/CalendarMonth.js +1 -6
- package/lib/node_modules/react-day-picker/dist/esm/classes/CalendarMonth.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/classes/CalendarWeek.js +1 -5
- package/lib/node_modules/react-day-picker/dist/esm/classes/CalendarWeek.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/classes/DateLib.js +51 -55
- package/lib/node_modules/react-day-picker/dist/esm/classes/DateLib.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/Chevron.js +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/Chevron.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/Day.js +4 -4
- package/lib/node_modules/react-day-picker/dist/esm/components/Day.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/DayButton.js +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/DayButton.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/Dropdown.js +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/Dropdown.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/DropdownNav.js +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/DropdownNav.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/Footer.js +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/Footer.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/Month.js +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/Month.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/MonthCaption.js +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/MonthCaption.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/MonthGrid.js +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/MonthGrid.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/Months.js +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/Months.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/MonthsDropdown.js +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/MonthsDropdown.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/Nav.js +6 -16
- package/lib/node_modules/react-day-picker/dist/esm/components/Nav.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/NextMonthButton.js +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/NextMonthButton.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/Option.js +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/Option.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/PreviousMonthButton.js +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/PreviousMonthButton.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/Root.js +2 -7
- package/lib/node_modules/react-day-picker/dist/esm/components/Root.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/Select.js +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/Select.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/Week.js +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/Week.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/WeekNumber.js +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/WeekNumber.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/WeekNumberHeader.js +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/WeekNumberHeader.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/Weekday.js +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/Weekday.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/Weekdays.js +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/Weekdays.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/Weeks.js +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/Weeks.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/YearsDropdown.js +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/components/YearsDropdown.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/formatters/formatCaption.js +2 -7
- package/lib/node_modules/react-day-picker/dist/esm/formatters/formatCaption.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/formatters/formatDay.js +2 -7
- package/lib/node_modules/react-day-picker/dist/esm/formatters/formatDay.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/formatters/formatMonthDropdown.js +2 -6
- package/lib/node_modules/react-day-picker/dist/esm/formatters/formatMonthDropdown.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/formatters/formatWeekNumber.js +5 -11
- package/lib/node_modules/react-day-picker/dist/esm/formatters/formatWeekNumber.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/formatters/formatWeekNumberHeader.js +2 -3
- package/lib/node_modules/react-day-picker/dist/esm/formatters/formatWeekNumberHeader.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/formatters/formatWeekdayName.js +2 -7
- package/lib/node_modules/react-day-picker/dist/esm/formatters/formatWeekdayName.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/formatters/formatYearDropdown.js +1 -5
- package/lib/node_modules/react-day-picker/dist/esm/formatters/formatYearDropdown.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/helpers/calculateFocusTarget.js +19 -46
- package/lib/node_modules/react-day-picker/dist/esm/helpers/calculateFocusTarget.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/helpers/endOfBroadcastWeek.js +1 -7
- package/lib/node_modules/react-day-picker/dist/esm/helpers/endOfBroadcastWeek.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getBroadcastWeeksInMonth.js +1 -8
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getBroadcastWeeksInMonth.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getClassNamesForModifiers.js +0 -12
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getClassNamesForModifiers.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getComponents.js +0 -10
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getComponents.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getDataAttributes.js +2 -11
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getDataAttributes.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getDates.js +2 -13
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getDates.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getDays.js +1 -4
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getDays.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getDefaultClassNames.js +2 -9
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getDefaultClassNames.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getDisplayMonths.js +0 -10
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getDisplayMonths.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getFocusableDate.js +2 -17
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getFocusableDate.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getFormatters.js +1 -7
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getFormatters.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getInitialMonth.js +3 -13
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getInitialMonth.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getMonthOptions.js +1 -15
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getMonthOptions.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getMonths.js +8 -17
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getMonths.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getNavMonth.js +1 -7
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getNavMonth.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getNextFocus.js +7 -20
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getNextFocus.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getNextMonth.js +6 -13
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getNextMonth.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getPreviousMonth.js +5 -13
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getPreviousMonth.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getStyleForModifiers.js +0 -11
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getStyleForModifiers.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getWeekdays.js +6 -9
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getWeekdays.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getWeeks.js +1 -6
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getWeeks.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getYearOptions.js +1 -13
- package/lib/node_modules/react-day-picker/dist/esm/helpers/getYearOptions.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/helpers/startOfBroadcastWeek.js +1 -8
- package/lib/node_modules/react-day-picker/dist/esm/helpers/startOfBroadcastWeek.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/helpers/useControlledValue.js +6 -10
- package/lib/node_modules/react-day-picker/dist/esm/helpers/useControlledValue.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/labels/labelDayButton.js +5 -9
- package/lib/node_modules/react-day-picker/dist/esm/labels/labelDayButton.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/labels/labelGrid.js +3 -7
- package/lib/node_modules/react-day-picker/dist/esm/labels/labelGrid.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/labels/labelGridcell.js +3 -7
- package/lib/node_modules/react-day-picker/dist/esm/labels/labelGridcell.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/labels/labelMonthDropdown.js +1 -3
- package/lib/node_modules/react-day-picker/dist/esm/labels/labelMonthDropdown.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/labels/labelNav.js +1 -2
- package/lib/node_modules/react-day-picker/dist/esm/labels/labelNav.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/labels/labelNext.js +3 -5
- package/lib/node_modules/react-day-picker/dist/esm/labels/labelNext.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/labels/labelPrevious.js +3 -5
- package/lib/node_modules/react-day-picker/dist/esm/labels/labelPrevious.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/labels/labelWeekNumber.js +1 -4
- package/lib/node_modules/react-day-picker/dist/esm/labels/labelWeekNumber.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/labels/labelWeekNumberHeader.js +1 -3
- package/lib/node_modules/react-day-picker/dist/esm/labels/labelWeekNumberHeader.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/labels/labelWeekday.js +1 -5
- package/lib/node_modules/react-day-picker/dist/esm/labels/labelWeekday.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/labels/labelYearDropdown.js +1 -3
- package/lib/node_modules/react-day-picker/dist/esm/labels/labelYearDropdown.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/selection/useMulti.js +0 -9
- package/lib/node_modules/react-day-picker/dist/esm/selection/useMulti.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/selection/useRange.js +2 -10
- package/lib/node_modules/react-day-picker/dist/esm/selection/useRange.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/selection/useSingle.js +0 -9
- package/lib/node_modules/react-day-picker/dist/esm/selection/useSingle.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/useCalendar.js +1 -9
- package/lib/node_modules/react-day-picker/dist/esm/useCalendar.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/useDayPicker.js +6 -4
- package/lib/node_modules/react-day-picker/dist/esm/useDayPicker.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/useFocus.js +1 -14
- package/lib/node_modules/react-day-picker/dist/esm/useFocus.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/{helpers/createGetModifiers.js → useGetModifiers.js} +7 -13
- package/lib/node_modules/react-day-picker/dist/esm/useGetModifiers.js.map +1 -0
- package/lib/node_modules/react-day-picker/dist/esm/useSelection.js +0 -10
- package/lib/node_modules/react-day-picker/dist/esm/useSelection.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/utils/addToRange.js +8 -10
- package/lib/node_modules/react-day-picker/dist/esm/utils/addToRange.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/utils/dateMatchModifiers.js +15 -5
- package/lib/node_modules/react-day-picker/dist/esm/utils/dateMatchModifiers.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/utils/rangeContainsDayOfWeek.js +9 -7
- package/lib/node_modules/react-day-picker/dist/esm/utils/rangeContainsDayOfWeek.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/utils/rangeContainsModifiers.js +14 -5
- package/lib/node_modules/react-day-picker/dist/esm/utils/rangeContainsModifiers.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/utils/rangeIncludesDate.js +3 -7
- package/lib/node_modules/react-day-picker/dist/esm/utils/rangeIncludesDate.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/utils/rangeOverlaps.js +2 -6
- package/lib/node_modules/react-day-picker/dist/esm/utils/rangeOverlaps.js.map +1 -1
- package/lib/node_modules/react-day-picker/dist/esm/utils/typeguards.js +6 -19
- package/lib/node_modules/react-day-picker/dist/esm/utils/typeguards.js.map +1 -1
- package/lib/node_modules/react-draft-wysiwyg/dist/react-draft-wysiwyg.js +2 -2
- package/lib/node_modules/react-draft-wysiwyg/dist/react-draft-wysiwyg.js.map +1 -1
- package/lib/node_modules/react-hook-form/dist/index.esm.js +1609 -1661
- package/lib/node_modules/react-hook-form/dist/index.esm.js.map +1 -1
- package/lib/node_modules/webrtc-adapter/src/js/common_shim.js +1 -1
- package/lib/node_modules/webrtc-adapter/src/js/common_shim.js.map +1 -1
- package/lib/node_modules/webrtc-adapter/src/js/utils.js +4 -6
- package/lib/node_modules/webrtc-adapter/src/js/utils.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +107 -107
- package/lib/node_modules/immutable/dist/immutable.js.map +0 -1
- package/lib/node_modules/react-day-picker/dist/esm/helpers/createGetModifiers.js.map +0 -1
- package/lib/node_modules/react-day-picker/dist/esm/useAnimation.js +0 -158
- package/lib/node_modules/react-day-picker/dist/esm/useAnimation.js.map +0 -1
- package/lib/node_modules/react-is/cjs/react-is.development.js.map +0 -1
- package/lib/node_modules/react-is/cjs/react-is.production.min.js.map +0 -1
- package/lib/node_modules/react-is/index.js.map +0 -1
@@ -1,4 +1,3 @@
|
|
1
|
-
import * as React from 'react';
|
2
1
|
import React__default from 'react';
|
3
2
|
|
4
3
|
var isCheckBoxInput = (element) => element.type === 'checkbox';
|
@@ -107,6 +106,7 @@ var set = (object, path, value) => {
|
|
107
106
|
object[key] = newValue;
|
108
107
|
object = object[key];
|
109
108
|
}
|
109
|
+
return object;
|
110
110
|
};
|
111
111
|
|
112
112
|
const EVENTS = {
|
@@ -217,7 +217,42 @@ var getProxyFormState = (formState, control, localProxyFormState, isRoot = true)
|
|
217
217
|
return result;
|
218
218
|
};
|
219
219
|
|
220
|
-
|
220
|
+
var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
|
221
|
+
|
222
|
+
var shouldRenderFormState = (formStateData, _proxyFormState, updateFormState, isRoot) => {
|
223
|
+
updateFormState(formStateData);
|
224
|
+
const { name, ...formState } = formStateData;
|
225
|
+
return (isEmptyObject(formState) ||
|
226
|
+
Object.keys(formState).length >= Object.keys(_proxyFormState).length ||
|
227
|
+
Object.keys(formState).find((key) => _proxyFormState[key] ===
|
228
|
+
(!isRoot || VALIDATION_MODE.all)));
|
229
|
+
};
|
230
|
+
|
231
|
+
var convertToArrayPayload = (value) => (Array.isArray(value) ? value : [value]);
|
232
|
+
|
233
|
+
var shouldSubscribeByName = (name, signalName, exact) => !name ||
|
234
|
+
!signalName ||
|
235
|
+
name === signalName ||
|
236
|
+
convertToArrayPayload(name).some((currentName) => currentName &&
|
237
|
+
(exact
|
238
|
+
? currentName === signalName
|
239
|
+
: currentName.startsWith(signalName) ||
|
240
|
+
signalName.startsWith(currentName)));
|
241
|
+
|
242
|
+
function useSubscribe(props) {
|
243
|
+
const _props = React__default.useRef(props);
|
244
|
+
_props.current = props;
|
245
|
+
React__default.useEffect(() => {
|
246
|
+
const subscription = !props.disabled &&
|
247
|
+
_props.current.subject &&
|
248
|
+
_props.current.subject.subscribe({
|
249
|
+
next: _props.current.next,
|
250
|
+
});
|
251
|
+
return () => {
|
252
|
+
subscription && subscription.unsubscribe();
|
253
|
+
};
|
254
|
+
}, [props.disabled]);
|
255
|
+
}
|
221
256
|
|
222
257
|
/**
|
223
258
|
* This custom hook allows you to subscribe to each form state, and isolate the re-render at the custom hook level. It has its scope in terms of form state subscription, so it would not affect other useFormState and useForm. Using this hook can reduce the re-render impact on large and complex form application.
|
@@ -253,6 +288,7 @@ function useFormState(props) {
|
|
253
288
|
const methods = useFormContext();
|
254
289
|
const { control = methods.control, disabled, name, exact } = props || {};
|
255
290
|
const [formState, updateFormState] = React__default.useState(control._formState);
|
291
|
+
const _mounted = React__default.useRef(true);
|
256
292
|
const _localProxyFormState = React__default.useRef({
|
257
293
|
isDirty: false,
|
258
294
|
isLoading: false,
|
@@ -263,20 +299,25 @@ function useFormState(props) {
|
|
263
299
|
isValid: false,
|
264
300
|
errors: false,
|
265
301
|
});
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
302
|
+
const _name = React__default.useRef(name);
|
303
|
+
_name.current = name;
|
304
|
+
useSubscribe({
|
305
|
+
disabled,
|
306
|
+
next: (value) => _mounted.current &&
|
307
|
+
shouldSubscribeByName(_name.current, value.name, exact) &&
|
308
|
+
shouldRenderFormState(value, _localProxyFormState.current, control._updateFormState) &&
|
309
|
+
updateFormState({
|
310
|
+
...control._formState,
|
311
|
+
...value,
|
312
|
+
}),
|
313
|
+
subject: control._subjects.state,
|
314
|
+
});
|
278
315
|
React__default.useEffect(() => {
|
279
|
-
|
316
|
+
_mounted.current = true;
|
317
|
+
_localProxyFormState.current.isValid && control._updateValid(true);
|
318
|
+
return () => {
|
319
|
+
_mounted.current = false;
|
320
|
+
};
|
280
321
|
}, [control]);
|
281
322
|
return React__default.useMemo(() => getProxyFormState(formState, control, _localProxyFormState.current, false), [formState, control]);
|
282
323
|
}
|
@@ -314,17 +355,18 @@ var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) =>
|
|
314
355
|
function useWatch(props) {
|
315
356
|
const methods = useFormContext();
|
316
357
|
const { control = methods.control, name, defaultValue, disabled, exact, } = props || {};
|
317
|
-
const
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
358
|
+
const _name = React__default.useRef(name);
|
359
|
+
_name.current = name;
|
360
|
+
useSubscribe({
|
361
|
+
disabled,
|
362
|
+
subject: control._subjects.values,
|
363
|
+
next: (formState) => {
|
364
|
+
if (shouldSubscribeByName(_name.current, formState.name, exact)) {
|
365
|
+
updateValue(cloneObject(generateWatchOutput(_name.current, control._names, formState.values || control._formValues, false, defaultValue)));
|
366
|
+
}
|
323
367
|
},
|
324
|
-
|
325
|
-
|
326
|
-
updateValue(generateWatchOutput(name, control._names, formState.values || control._formValues, false, _defaultValue.current)),
|
327
|
-
}), [name, control, disabled, exact]);
|
368
|
+
});
|
369
|
+
const [value, updateValue] = React__default.useState(control._getWatch(name, defaultValue));
|
328
370
|
React__default.useEffect(() => control._removeUnmounted());
|
329
371
|
return value;
|
330
372
|
}
|
@@ -368,7 +410,6 @@ function useController(props) {
|
|
368
410
|
name,
|
369
411
|
exact: true,
|
370
412
|
});
|
371
|
-
const _props = React__default.useRef(props);
|
372
413
|
const _registerProps = React__default.useRef(control.register(name, {
|
373
414
|
...props.rules,
|
374
415
|
value,
|
@@ -396,49 +437,47 @@ function useController(props) {
|
|
396
437
|
get: () => get(formState.errors, name),
|
397
438
|
},
|
398
439
|
}), [formState, name]);
|
399
|
-
const onChange = React__default.useCallback((event) => _registerProps.current.onChange({
|
400
|
-
target: {
|
401
|
-
value: getEventValue(event),
|
402
|
-
name: name,
|
403
|
-
},
|
404
|
-
type: EVENTS.CHANGE,
|
405
|
-
}), [name]);
|
406
|
-
const onBlur = React__default.useCallback(() => _registerProps.current.onBlur({
|
407
|
-
target: {
|
408
|
-
value: get(control._formValues, name),
|
409
|
-
name: name,
|
410
|
-
},
|
411
|
-
type: EVENTS.BLUR,
|
412
|
-
}), [name, control._formValues]);
|
413
|
-
const ref = React__default.useCallback((elm) => {
|
414
|
-
const field = get(control._fields, name);
|
415
|
-
if (field && elm) {
|
416
|
-
field._f.ref = {
|
417
|
-
focus: () => elm.focus(),
|
418
|
-
select: () => elm.select(),
|
419
|
-
setCustomValidity: (message) => elm.setCustomValidity(message),
|
420
|
-
reportValidity: () => elm.reportValidity(),
|
421
|
-
};
|
422
|
-
}
|
423
|
-
}, [control._fields, name]);
|
424
440
|
const field = React__default.useMemo(() => ({
|
425
441
|
name,
|
426
442
|
value,
|
427
443
|
...(isBoolean(disabled) || formState.disabled
|
428
444
|
? { disabled: formState.disabled || disabled }
|
429
445
|
: {}),
|
430
|
-
onChange
|
431
|
-
|
432
|
-
|
433
|
-
|
446
|
+
onChange: (event) => _registerProps.current.onChange({
|
447
|
+
target: {
|
448
|
+
value: getEventValue(event),
|
449
|
+
name: name,
|
450
|
+
},
|
451
|
+
type: EVENTS.CHANGE,
|
452
|
+
}),
|
453
|
+
onBlur: () => _registerProps.current.onBlur({
|
454
|
+
target: {
|
455
|
+
value: get(control._formValues, name),
|
456
|
+
name: name,
|
457
|
+
},
|
458
|
+
type: EVENTS.BLUR,
|
459
|
+
}),
|
460
|
+
ref: (elm) => {
|
461
|
+
const field = get(control._fields, name);
|
462
|
+
if (field && elm) {
|
463
|
+
field._f.ref = {
|
464
|
+
focus: () => elm.focus(),
|
465
|
+
select: () => elm.select(),
|
466
|
+
setCustomValidity: (message) => elm.setCustomValidity(message),
|
467
|
+
reportValidity: () => elm.reportValidity(),
|
468
|
+
};
|
469
|
+
}
|
470
|
+
},
|
471
|
+
}), [
|
472
|
+
name,
|
473
|
+
control._formValues,
|
474
|
+
disabled,
|
475
|
+
formState.disabled,
|
476
|
+
value,
|
477
|
+
control._fields,
|
478
|
+
]);
|
434
479
|
React__default.useEffect(() => {
|
435
480
|
const _shouldUnregisterField = control._options.shouldUnregister || shouldUnregister;
|
436
|
-
control.register(name, {
|
437
|
-
..._props.current.rules,
|
438
|
-
...(isBoolean(_props.current.disabled)
|
439
|
-
? { disabled: _props.current.disabled }
|
440
|
-
: {}),
|
441
|
-
});
|
442
481
|
const updateMounted = (name, value) => {
|
443
482
|
const field = get(control._fields, name);
|
444
483
|
if (field && field._f) {
|
@@ -463,8 +502,9 @@ function useController(props) {
|
|
463
502
|
};
|
464
503
|
}, [name, control, isArrayField, shouldUnregister]);
|
465
504
|
React__default.useEffect(() => {
|
466
|
-
control.
|
505
|
+
control._updateDisabledField({
|
467
506
|
disabled,
|
507
|
+
fields: control._fields,
|
468
508
|
name,
|
469
509
|
});
|
470
510
|
}, [disabled, name, control]);
|
@@ -644,70 +684,67 @@ var appendErrors = (name, validateAllFieldCriteria, errors, type, message) => va
|
|
644
684
|
}
|
645
685
|
: {};
|
646
686
|
|
647
|
-
var
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
observer.next && observer.next(value);
|
654
|
-
}
|
655
|
-
};
|
656
|
-
const subscribe = (observer) => {
|
657
|
-
_observers.push(observer);
|
658
|
-
return {
|
659
|
-
unsubscribe: () => {
|
660
|
-
_observers = _observers.filter((o) => o !== observer);
|
661
|
-
},
|
662
|
-
};
|
663
|
-
};
|
664
|
-
const unsubscribe = () => {
|
665
|
-
_observers = [];
|
666
|
-
};
|
667
|
-
return {
|
668
|
-
get observers() {
|
669
|
-
return _observers;
|
670
|
-
},
|
671
|
-
next,
|
672
|
-
subscribe,
|
673
|
-
unsubscribe,
|
674
|
-
};
|
687
|
+
var generateId = () => {
|
688
|
+
const d = typeof performance === 'undefined' ? Date.now() : performance.now() * 1000;
|
689
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
690
|
+
const r = (Math.random() * 16 + d) % 16 | 0;
|
691
|
+
return (c == 'x' ? r : (r & 0x3) | 0x8).toString(16);
|
692
|
+
});
|
675
693
|
};
|
676
694
|
|
677
|
-
var
|
695
|
+
var getFocusFieldName = (name, index, options = {}) => options.shouldFocus || isUndefined(options.shouldFocus)
|
696
|
+
? options.focusName ||
|
697
|
+
`${name}.${isUndefined(options.focusIndex) ? index : options.focusIndex}.`
|
698
|
+
: '';
|
678
699
|
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
if (
|
697
|
-
const
|
698
|
-
if (
|
699
|
-
(
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
700
|
+
var getValidationModes = (mode) => ({
|
701
|
+
isOnSubmit: !mode || mode === VALIDATION_MODE.onSubmit,
|
702
|
+
isOnBlur: mode === VALIDATION_MODE.onBlur,
|
703
|
+
isOnChange: mode === VALIDATION_MODE.onChange,
|
704
|
+
isOnAll: mode === VALIDATION_MODE.all,
|
705
|
+
isOnTouch: mode === VALIDATION_MODE.onTouched,
|
706
|
+
});
|
707
|
+
|
708
|
+
var isWatched = (name, _names, isBlurEvent) => !isBlurEvent &&
|
709
|
+
(_names.watchAll ||
|
710
|
+
_names.watch.has(name) ||
|
711
|
+
[..._names.watch].some((watchName) => name.startsWith(watchName) &&
|
712
|
+
/^\.\w+/.test(name.slice(watchName.length))));
|
713
|
+
|
714
|
+
const iterateFieldsByAction = (fields, action, fieldsNames, abortEarly) => {
|
715
|
+
for (const key of fieldsNames || Object.keys(fields)) {
|
716
|
+
const field = get(fields, key);
|
717
|
+
if (field) {
|
718
|
+
const { _f, ...currentField } = field;
|
719
|
+
if (_f) {
|
720
|
+
if (_f.refs && _f.refs[0] && action(_f.refs[0], key) && !abortEarly) {
|
721
|
+
return true;
|
722
|
+
}
|
723
|
+
else if (_f.ref && action(_f.ref, _f.name) && !abortEarly) {
|
724
|
+
return true;
|
725
|
+
}
|
726
|
+
else {
|
727
|
+
if (iterateFieldsByAction(currentField, action)) {
|
728
|
+
break;
|
729
|
+
}
|
730
|
+
}
|
731
|
+
}
|
732
|
+
else if (isObject(currentField)) {
|
733
|
+
if (iterateFieldsByAction(currentField, action)) {
|
734
|
+
break;
|
735
|
+
}
|
704
736
|
}
|
705
737
|
}
|
706
738
|
}
|
707
|
-
return
|
708
|
-
}
|
739
|
+
return;
|
740
|
+
};
|
709
741
|
|
710
|
-
var
|
742
|
+
var updateFieldArrayRootError = (errors, error, name) => {
|
743
|
+
const fieldArrayErrors = convertToArrayPayload(get(errors, name));
|
744
|
+
set(fieldArrayErrors, 'root', error[name]);
|
745
|
+
set(errors, name, fieldArrayErrors);
|
746
|
+
return errors;
|
747
|
+
};
|
711
748
|
|
712
749
|
var isFileInput = (element) => element.type === 'file';
|
713
750
|
|
@@ -722,532 +759,812 @@ var isHTMLElement = (value) => {
|
|
722
759
|
(owner && owner.defaultView ? owner.defaultView.HTMLElement : HTMLElement));
|
723
760
|
};
|
724
761
|
|
725
|
-
var
|
762
|
+
var isMessage = (value) => isString(value);
|
726
763
|
|
727
764
|
var isRadioInput = (element) => element.type === 'radio';
|
728
765
|
|
729
|
-
var
|
730
|
-
|
731
|
-
var live = (ref) => isHTMLElement(ref) && ref.isConnected;
|
766
|
+
var isRegex = (value) => value instanceof RegExp;
|
732
767
|
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
return
|
768
|
+
const defaultResult = {
|
769
|
+
value: false,
|
770
|
+
isValid: false,
|
771
|
+
};
|
772
|
+
const validResult = { value: true, isValid: true };
|
773
|
+
var getCheckboxValue = (options) => {
|
774
|
+
if (Array.isArray(options)) {
|
775
|
+
if (options.length > 1) {
|
776
|
+
const values = options
|
777
|
+
.filter((option) => option && option.checked && !option.disabled)
|
778
|
+
.map((option) => option.value);
|
779
|
+
return { value: values, isValid: !!values.length };
|
745
780
|
}
|
781
|
+
return options[0].checked && !options[0].disabled
|
782
|
+
? // @ts-expect-error expected to work in the browser
|
783
|
+
options[0].attributes && !isUndefined(options[0].attributes.value)
|
784
|
+
? isUndefined(options[0].value) || options[0].value === ''
|
785
|
+
? validResult
|
786
|
+
: { value: options[0].value, isValid: true }
|
787
|
+
: validResult
|
788
|
+
: defaultResult;
|
746
789
|
}
|
747
|
-
return
|
748
|
-
}
|
749
|
-
function unset(object, path) {
|
750
|
-
const paths = Array.isArray(path)
|
751
|
-
? path
|
752
|
-
: isKey(path)
|
753
|
-
? [path]
|
754
|
-
: stringToPath(path);
|
755
|
-
const childObject = paths.length === 1 ? object : baseGet(object, paths);
|
756
|
-
const index = paths.length - 1;
|
757
|
-
const key = paths[index];
|
758
|
-
if (childObject) {
|
759
|
-
delete childObject[key];
|
760
|
-
}
|
761
|
-
if (index !== 0 &&
|
762
|
-
((isObject(childObject) && isEmptyObject(childObject)) ||
|
763
|
-
(Array.isArray(childObject) && isEmptyArray(childObject)))) {
|
764
|
-
unset(object, paths.slice(0, -1));
|
765
|
-
}
|
766
|
-
return object;
|
767
|
-
}
|
790
|
+
return defaultResult;
|
791
|
+
};
|
768
792
|
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
return true;
|
773
|
-
}
|
774
|
-
}
|
775
|
-
return false;
|
793
|
+
const defaultReturn = {
|
794
|
+
isValid: false,
|
795
|
+
value: null,
|
776
796
|
};
|
797
|
+
var getRadioValue = (options) => Array.isArray(options)
|
798
|
+
? options.reduce((previous, option) => option && option.checked && !option.disabled
|
799
|
+
? {
|
800
|
+
isValid: true,
|
801
|
+
value: option.value,
|
802
|
+
}
|
803
|
+
: previous, defaultReturn)
|
804
|
+
: defaultReturn;
|
777
805
|
|
778
|
-
function
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
806
|
+
function getValidateError(result, ref, type = 'validate') {
|
807
|
+
if (isMessage(result) ||
|
808
|
+
(Array.isArray(result) && result.every(isMessage)) ||
|
809
|
+
(isBoolean(result) && !result)) {
|
810
|
+
return {
|
811
|
+
type,
|
812
|
+
message: isMessage(result) ? result : '',
|
813
|
+
ref,
|
814
|
+
};
|
815
|
+
}
|
816
|
+
}
|
817
|
+
|
818
|
+
var getValueAndMessage = (validationData) => isObject(validationData) && !isRegex(validationData)
|
819
|
+
? validationData
|
820
|
+
: {
|
821
|
+
value: validationData,
|
822
|
+
message: '',
|
823
|
+
};
|
824
|
+
|
825
|
+
var validateField = async (field, disabledFieldNames, formValues, validateAllFieldCriteria, shouldUseNativeValidation, isFieldArray) => {
|
826
|
+
const { ref, refs, required, maxLength, minLength, min, max, pattern, validate, name, valueAsNumber, mount, } = field._f;
|
827
|
+
const inputValue = get(formValues, name);
|
828
|
+
if (!mount || disabledFieldNames.has(name)) {
|
829
|
+
return {};
|
830
|
+
}
|
831
|
+
const inputRef = refs ? refs[0] : ref;
|
832
|
+
const setCustomValidity = (message) => {
|
833
|
+
if (shouldUseNativeValidation && inputRef.reportValidity) {
|
834
|
+
inputRef.setCustomValidity(isBoolean(message) ? '' : message || '');
|
835
|
+
inputRef.reportValidity();
|
836
|
+
}
|
837
|
+
};
|
838
|
+
const error = {};
|
839
|
+
const isRadio = isRadioInput(ref);
|
840
|
+
const isCheckBox = isCheckBoxInput(ref);
|
841
|
+
const isRadioOrCheckbox = isRadio || isCheckBox;
|
842
|
+
const isEmpty = ((valueAsNumber || isFileInput(ref)) &&
|
843
|
+
isUndefined(ref.value) &&
|
844
|
+
isUndefined(inputValue)) ||
|
845
|
+
(isHTMLElement(ref) && ref.value === '') ||
|
846
|
+
inputValue === '' ||
|
847
|
+
(Array.isArray(inputValue) && !inputValue.length);
|
848
|
+
const appendErrorsCurry = appendErrors.bind(null, name, validateAllFieldCriteria, error);
|
849
|
+
const getMinMaxMessage = (exceedMax, maxLengthMessage, minLengthMessage, maxType = INPUT_VALIDATION_RULES.maxLength, minType = INPUT_VALIDATION_RULES.minLength) => {
|
850
|
+
const message = exceedMax ? maxLengthMessage : minLengthMessage;
|
851
|
+
error[name] = {
|
852
|
+
type: exceedMax ? maxType : minType,
|
853
|
+
message,
|
854
|
+
ref,
|
855
|
+
...appendErrorsCurry(exceedMax ? maxType : minType, message),
|
856
|
+
};
|
857
|
+
};
|
858
|
+
if (isFieldArray
|
859
|
+
? !Array.isArray(inputValue) || !inputValue.length
|
860
|
+
: required &&
|
861
|
+
((!isRadioOrCheckbox && (isEmpty || isNullOrUndefined(inputValue))) ||
|
862
|
+
(isBoolean(inputValue) && !inputValue) ||
|
863
|
+
(isCheckBox && !getCheckboxValue(refs).isValid) ||
|
864
|
+
(isRadio && !getRadioValue(refs).isValid))) {
|
865
|
+
const { value, message } = isMessage(required)
|
866
|
+
? { value: !!required, message: required }
|
867
|
+
: getValueAndMessage(required);
|
868
|
+
if (value) {
|
869
|
+
error[name] = {
|
870
|
+
type: INPUT_VALIDATION_RULES.required,
|
871
|
+
message,
|
872
|
+
ref: inputRef,
|
873
|
+
...appendErrorsCurry(INPUT_VALIDATION_RULES.required, message),
|
874
|
+
};
|
875
|
+
if (!validateAllFieldCriteria) {
|
876
|
+
setCustomValidity(message);
|
877
|
+
return error;
|
789
878
|
}
|
790
879
|
}
|
791
880
|
}
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
(
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
881
|
+
if (!isEmpty && (!isNullOrUndefined(min) || !isNullOrUndefined(max))) {
|
882
|
+
let exceedMax;
|
883
|
+
let exceedMin;
|
884
|
+
const maxOutput = getValueAndMessage(max);
|
885
|
+
const minOutput = getValueAndMessage(min);
|
886
|
+
if (!isNullOrUndefined(inputValue) && !isNaN(inputValue)) {
|
887
|
+
const valueNumber = ref.valueAsNumber ||
|
888
|
+
(inputValue ? +inputValue : inputValue);
|
889
|
+
if (!isNullOrUndefined(maxOutput.value)) {
|
890
|
+
exceedMax = valueNumber > maxOutput.value;
|
891
|
+
}
|
892
|
+
if (!isNullOrUndefined(minOutput.value)) {
|
893
|
+
exceedMin = valueNumber < minOutput.value;
|
894
|
+
}
|
895
|
+
}
|
896
|
+
else {
|
897
|
+
const valueDate = ref.valueAsDate || new Date(inputValue);
|
898
|
+
const convertTimeToDate = (time) => new Date(new Date().toDateString() + ' ' + time);
|
899
|
+
const isTime = ref.type == 'time';
|
900
|
+
const isWeek = ref.type == 'week';
|
901
|
+
if (isString(maxOutput.value) && inputValue) {
|
902
|
+
exceedMax = isTime
|
903
|
+
? convertTimeToDate(inputValue) > convertTimeToDate(maxOutput.value)
|
904
|
+
: isWeek
|
905
|
+
? inputValue > maxOutput.value
|
906
|
+
: valueDate > new Date(maxOutput.value);
|
907
|
+
}
|
908
|
+
if (isString(minOutput.value) && inputValue) {
|
909
|
+
exceedMin = isTime
|
910
|
+
? convertTimeToDate(inputValue) < convertTimeToDate(minOutput.value)
|
911
|
+
: isWeek
|
912
|
+
? inputValue < minOutput.value
|
913
|
+
: valueDate < new Date(minOutput.value);
|
914
|
+
}
|
915
|
+
}
|
916
|
+
if (exceedMax || exceedMin) {
|
917
|
+
getMinMaxMessage(!!exceedMax, maxOutput.message, minOutput.message, INPUT_VALIDATION_RULES.max, INPUT_VALIDATION_RULES.min);
|
918
|
+
if (!validateAllFieldCriteria) {
|
919
|
+
setCustomValidity(error[name].message);
|
920
|
+
return error;
|
921
|
+
}
|
922
|
+
}
|
923
|
+
}
|
924
|
+
if ((maxLength || minLength) &&
|
925
|
+
!isEmpty &&
|
926
|
+
(isString(inputValue) || (isFieldArray && Array.isArray(inputValue)))) {
|
927
|
+
const maxLengthOutput = getValueAndMessage(maxLength);
|
928
|
+
const minLengthOutput = getValueAndMessage(minLength);
|
929
|
+
const exceedMax = !isNullOrUndefined(maxLengthOutput.value) &&
|
930
|
+
inputValue.length > +maxLengthOutput.value;
|
931
|
+
const exceedMin = !isNullOrUndefined(minLengthOutput.value) &&
|
932
|
+
inputValue.length < +minLengthOutput.value;
|
933
|
+
if (exceedMax || exceedMin) {
|
934
|
+
getMinMaxMessage(exceedMax, maxLengthOutput.message, minLengthOutput.message);
|
935
|
+
if (!validateAllFieldCriteria) {
|
936
|
+
setCustomValidity(error[name].message);
|
937
|
+
return error;
|
938
|
+
}
|
939
|
+
}
|
940
|
+
}
|
941
|
+
if (pattern && !isEmpty && isString(inputValue)) {
|
942
|
+
const { value: patternValue, message } = getValueAndMessage(pattern);
|
943
|
+
if (isRegex(patternValue) && !inputValue.match(patternValue)) {
|
944
|
+
error[name] = {
|
945
|
+
type: INPUT_VALIDATION_RULES.pattern,
|
946
|
+
message,
|
947
|
+
ref,
|
948
|
+
...appendErrorsCurry(INPUT_VALIDATION_RULES.pattern, message),
|
949
|
+
};
|
950
|
+
if (!validateAllFieldCriteria) {
|
951
|
+
setCustomValidity(message);
|
952
|
+
return error;
|
953
|
+
}
|
954
|
+
}
|
955
|
+
}
|
956
|
+
if (validate) {
|
957
|
+
if (isFunction(validate)) {
|
958
|
+
const result = await validate(inputValue, formValues);
|
959
|
+
const validateError = getValidateError(result, inputRef);
|
960
|
+
if (validateError) {
|
961
|
+
error[name] = {
|
962
|
+
...validateError,
|
963
|
+
...appendErrorsCurry(INPUT_VALIDATION_RULES.validate, validateError.message),
|
964
|
+
};
|
965
|
+
if (!validateAllFieldCriteria) {
|
966
|
+
setCustomValidity(validateError.message);
|
967
|
+
return error;
|
805
968
|
}
|
806
|
-
|
807
|
-
|
969
|
+
}
|
970
|
+
}
|
971
|
+
else if (isObject(validate)) {
|
972
|
+
let validationResult = {};
|
973
|
+
for (const key in validate) {
|
974
|
+
if (!isEmptyObject(validationResult) && !validateAllFieldCriteria) {
|
975
|
+
break;
|
976
|
+
}
|
977
|
+
const validateError = getValidateError(await validate[key](inputValue, formValues), inputRef, key);
|
978
|
+
if (validateError) {
|
979
|
+
validationResult = {
|
980
|
+
...validateError,
|
981
|
+
...appendErrorsCurry(key, validateError.message),
|
982
|
+
};
|
983
|
+
setCustomValidity(validateError.message);
|
984
|
+
if (validateAllFieldCriteria) {
|
985
|
+
error[name] = validationResult;
|
986
|
+
}
|
808
987
|
}
|
809
988
|
}
|
810
|
-
|
811
|
-
|
989
|
+
if (!isEmptyObject(validationResult)) {
|
990
|
+
error[name] = {
|
991
|
+
ref: inputRef,
|
992
|
+
...validationResult,
|
993
|
+
};
|
994
|
+
if (!validateAllFieldCriteria) {
|
995
|
+
return error;
|
996
|
+
}
|
812
997
|
}
|
813
998
|
}
|
814
999
|
}
|
815
|
-
|
1000
|
+
setCustomValidity(true);
|
1001
|
+
return error;
|
1002
|
+
};
|
1003
|
+
|
1004
|
+
var appendAt = (data, value) => [
|
1005
|
+
...data,
|
1006
|
+
...convertToArrayPayload(value),
|
1007
|
+
];
|
1008
|
+
|
1009
|
+
var fillEmptyArray = (value) => Array.isArray(value) ? value.map(() => undefined) : undefined;
|
1010
|
+
|
1011
|
+
function insert(data, index, value) {
|
1012
|
+
return [
|
1013
|
+
...data.slice(0, index),
|
1014
|
+
...convertToArrayPayload(value),
|
1015
|
+
...data.slice(index),
|
1016
|
+
];
|
816
1017
|
}
|
817
|
-
var getDirtyFields = (defaultValues, formValues) => getDirtyFieldsFromDefaultValues(defaultValues, formValues, markFieldsDirty(formValues));
|
818
1018
|
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
};
|
823
|
-
const validResult = { value: true, isValid: true };
|
824
|
-
var getCheckboxValue = (options) => {
|
825
|
-
if (Array.isArray(options)) {
|
826
|
-
if (options.length > 1) {
|
827
|
-
const values = options
|
828
|
-
.filter((option) => option && option.checked && !option.disabled)
|
829
|
-
.map((option) => option.value);
|
830
|
-
return { value: values, isValid: !!values.length };
|
831
|
-
}
|
832
|
-
return options[0].checked && !options[0].disabled
|
833
|
-
? // @ts-expect-error expected to work in the browser
|
834
|
-
options[0].attributes && !isUndefined(options[0].attributes.value)
|
835
|
-
? isUndefined(options[0].value) || options[0].value === ''
|
836
|
-
? validResult
|
837
|
-
: { value: options[0].value, isValid: true }
|
838
|
-
: validResult
|
839
|
-
: defaultResult;
|
1019
|
+
var moveArrayAt = (data, from, to) => {
|
1020
|
+
if (!Array.isArray(data)) {
|
1021
|
+
return [];
|
840
1022
|
}
|
841
|
-
|
1023
|
+
if (isUndefined(data[to])) {
|
1024
|
+
data[to] = undefined;
|
1025
|
+
}
|
1026
|
+
data.splice(to, 0, data.splice(from, 1)[0]);
|
1027
|
+
return data;
|
842
1028
|
};
|
843
1029
|
|
844
|
-
var
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
? NaN
|
849
|
-
: value
|
850
|
-
? +value
|
851
|
-
: value
|
852
|
-
: valueAsDate && isString(value)
|
853
|
-
? new Date(value)
|
854
|
-
: setValueAs
|
855
|
-
? setValueAs(value)
|
856
|
-
: value;
|
857
|
-
|
858
|
-
const defaultReturn = {
|
859
|
-
isValid: false,
|
860
|
-
value: null,
|
861
|
-
};
|
862
|
-
var getRadioValue = (options) => Array.isArray(options)
|
863
|
-
? options.reduce((previous, option) => option && option.checked && !option.disabled
|
864
|
-
? {
|
865
|
-
isValid: true,
|
866
|
-
value: option.value,
|
867
|
-
}
|
868
|
-
: previous, defaultReturn)
|
869
|
-
: defaultReturn;
|
1030
|
+
var prependAt = (data, value) => [
|
1031
|
+
...convertToArrayPayload(value),
|
1032
|
+
...convertToArrayPayload(data),
|
1033
|
+
];
|
870
1034
|
|
871
|
-
function
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
return getRadioValue(_f.refs).value;
|
878
|
-
}
|
879
|
-
if (isMultipleSelect(ref)) {
|
880
|
-
return [...ref.selectedOptions].map(({ value }) => value);
|
881
|
-
}
|
882
|
-
if (isCheckBoxInput(ref)) {
|
883
|
-
return getCheckboxValue(_f.refs).value;
|
1035
|
+
function removeAtIndexes(data, indexes) {
|
1036
|
+
let i = 0;
|
1037
|
+
const temp = [...data];
|
1038
|
+
for (const index of indexes) {
|
1039
|
+
temp.splice(index - i, 1);
|
1040
|
+
i++;
|
884
1041
|
}
|
885
|
-
return
|
1042
|
+
return compact(temp).length ? temp : [];
|
886
1043
|
}
|
1044
|
+
var removeArrayAt = (data, index) => isUndefined(index)
|
1045
|
+
? []
|
1046
|
+
: removeAtIndexes(data, convertToArrayPayload(index).sort((a, b) => a - b));
|
887
1047
|
|
888
|
-
var
|
889
|
-
|
890
|
-
for (const name of fieldsNames) {
|
891
|
-
const field = get(_fields, name);
|
892
|
-
field && set(fields, name, field._f);
|
893
|
-
}
|
894
|
-
return {
|
895
|
-
criteriaMode,
|
896
|
-
names: [...fieldsNames],
|
897
|
-
fields,
|
898
|
-
shouldUseNativeValidation,
|
899
|
-
};
|
900
|
-
};
|
901
|
-
|
902
|
-
var isRegex = (value) => value instanceof RegExp;
|
903
|
-
|
904
|
-
var getRuleValue = (rule) => isUndefined(rule)
|
905
|
-
? rule
|
906
|
-
: isRegex(rule)
|
907
|
-
? rule.source
|
908
|
-
: isObject(rule)
|
909
|
-
? isRegex(rule.value)
|
910
|
-
? rule.value.source
|
911
|
-
: rule.value
|
912
|
-
: rule;
|
913
|
-
|
914
|
-
var getValidationModes = (mode) => ({
|
915
|
-
isOnSubmit: !mode || mode === VALIDATION_MODE.onSubmit,
|
916
|
-
isOnBlur: mode === VALIDATION_MODE.onBlur,
|
917
|
-
isOnChange: mode === VALIDATION_MODE.onChange,
|
918
|
-
isOnAll: mode === VALIDATION_MODE.all,
|
919
|
-
isOnTouch: mode === VALIDATION_MODE.onTouched,
|
920
|
-
});
|
921
|
-
|
922
|
-
const ASYNC_FUNCTION = 'AsyncFunction';
|
923
|
-
var hasPromiseValidation = (fieldReference) => !!fieldReference &&
|
924
|
-
!!fieldReference.validate &&
|
925
|
-
!!((isFunction(fieldReference.validate) &&
|
926
|
-
fieldReference.validate.constructor.name === ASYNC_FUNCTION) ||
|
927
|
-
(isObject(fieldReference.validate) &&
|
928
|
-
Object.values(fieldReference.validate).find((validateFunction) => validateFunction.constructor.name === ASYNC_FUNCTION)));
|
929
|
-
|
930
|
-
var hasValidation = (options) => options.mount &&
|
931
|
-
(options.required ||
|
932
|
-
options.min ||
|
933
|
-
options.max ||
|
934
|
-
options.maxLength ||
|
935
|
-
options.minLength ||
|
936
|
-
options.pattern ||
|
937
|
-
options.validate);
|
938
|
-
|
939
|
-
var isWatched = (name, _names, isBlurEvent) => !isBlurEvent &&
|
940
|
-
(_names.watchAll ||
|
941
|
-
_names.watch.has(name) ||
|
942
|
-
[..._names.watch].some((watchName) => name.startsWith(watchName) &&
|
943
|
-
/^\.\w+/.test(name.slice(watchName.length))));
|
944
|
-
|
945
|
-
const iterateFieldsByAction = (fields, action, fieldsNames, abortEarly) => {
|
946
|
-
for (const key of fieldsNames || Object.keys(fields)) {
|
947
|
-
const field = get(fields, key);
|
948
|
-
if (field) {
|
949
|
-
const { _f, ...currentField } = field;
|
950
|
-
if (_f) {
|
951
|
-
if (_f.refs && _f.refs[0] && action(_f.refs[0], key) && !abortEarly) {
|
952
|
-
return true;
|
953
|
-
}
|
954
|
-
else if (_f.ref && action(_f.ref, _f.name) && !abortEarly) {
|
955
|
-
return true;
|
956
|
-
}
|
957
|
-
else {
|
958
|
-
if (iterateFieldsByAction(currentField, action)) {
|
959
|
-
break;
|
960
|
-
}
|
961
|
-
}
|
962
|
-
}
|
963
|
-
else if (isObject(currentField)) {
|
964
|
-
if (iterateFieldsByAction(currentField, action)) {
|
965
|
-
break;
|
966
|
-
}
|
967
|
-
}
|
968
|
-
}
|
969
|
-
}
|
970
|
-
return;
|
1048
|
+
var swapArrayAt = (data, indexA, indexB) => {
|
1049
|
+
[data[indexA], data[indexB]] = [data[indexB], data[indexA]];
|
971
1050
|
};
|
972
1051
|
|
973
|
-
function
|
974
|
-
const
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
name,
|
979
|
-
};
|
1052
|
+
function baseGet(object, updatePath) {
|
1053
|
+
const length = updatePath.slice(0, -1).length;
|
1054
|
+
let index = 0;
|
1055
|
+
while (index < length) {
|
1056
|
+
object = isUndefined(object) ? index++ : object[updatePath[index++]];
|
980
1057
|
}
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
return { name };
|
988
|
-
}
|
989
|
-
if (foundError && foundError.type) {
|
990
|
-
return {
|
991
|
-
name: fieldName,
|
992
|
-
error: foundError,
|
993
|
-
};
|
1058
|
+
return object;
|
1059
|
+
}
|
1060
|
+
function isEmptyArray(obj) {
|
1061
|
+
for (const key in obj) {
|
1062
|
+
if (obj.hasOwnProperty(key) && !isUndefined(obj[key])) {
|
1063
|
+
return false;
|
994
1064
|
}
|
995
|
-
names.pop();
|
996
1065
|
}
|
997
|
-
return
|
998
|
-
name,
|
999
|
-
};
|
1066
|
+
return true;
|
1000
1067
|
}
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
!signalName ||
|
1013
|
-
name === signalName ||
|
1014
|
-
convertToArrayPayload(name).some((currentName) => currentName &&
|
1015
|
-
(exact
|
1016
|
-
? currentName === signalName
|
1017
|
-
: currentName.startsWith(signalName) ||
|
1018
|
-
signalName.startsWith(currentName)));
|
1019
|
-
|
1020
|
-
var skipValidation = (isBlurEvent, isTouched, isSubmitted, reValidateMode, mode) => {
|
1021
|
-
if (mode.isOnAll) {
|
1022
|
-
return false;
|
1023
|
-
}
|
1024
|
-
else if (!isSubmitted && mode.isOnTouch) {
|
1025
|
-
return !(isTouched || isBlurEvent);
|
1026
|
-
}
|
1027
|
-
else if (isSubmitted ? reValidateMode.isOnBlur : mode.isOnBlur) {
|
1028
|
-
return !isBlurEvent;
|
1029
|
-
}
|
1030
|
-
else if (isSubmitted ? reValidateMode.isOnChange : mode.isOnChange) {
|
1031
|
-
return isBlurEvent;
|
1068
|
+
function unset(object, path) {
|
1069
|
+
const paths = Array.isArray(path)
|
1070
|
+
? path
|
1071
|
+
: isKey(path)
|
1072
|
+
? [path]
|
1073
|
+
: stringToPath(path);
|
1074
|
+
const childObject = paths.length === 1 ? object : baseGet(object, paths);
|
1075
|
+
const index = paths.length - 1;
|
1076
|
+
const key = paths[index];
|
1077
|
+
if (childObject) {
|
1078
|
+
delete childObject[key];
|
1032
1079
|
}
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
var updateFieldArrayRootError = (errors, error, name) => {
|
1039
|
-
const fieldArrayErrors = convertToArrayPayload(get(errors, name));
|
1040
|
-
set(fieldArrayErrors, 'root', error[name]);
|
1041
|
-
set(errors, name, fieldArrayErrors);
|
1042
|
-
return errors;
|
1043
|
-
};
|
1044
|
-
|
1045
|
-
var isMessage = (value) => isString(value);
|
1046
|
-
|
1047
|
-
function getValidateError(result, ref, type = 'validate') {
|
1048
|
-
if (isMessage(result) ||
|
1049
|
-
(Array.isArray(result) && result.every(isMessage)) ||
|
1050
|
-
(isBoolean(result) && !result)) {
|
1051
|
-
return {
|
1052
|
-
type,
|
1053
|
-
message: isMessage(result) ? result : '',
|
1054
|
-
ref,
|
1055
|
-
};
|
1080
|
+
if (index !== 0 &&
|
1081
|
+
((isObject(childObject) && isEmptyObject(childObject)) ||
|
1082
|
+
(Array.isArray(childObject) && isEmptyArray(childObject)))) {
|
1083
|
+
unset(object, paths.slice(0, -1));
|
1056
1084
|
}
|
1085
|
+
return object;
|
1057
1086
|
}
|
1058
1087
|
|
1059
|
-
var
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
message: '',
|
1064
|
-
};
|
1088
|
+
var updateAt = (fieldValues, index, value) => {
|
1089
|
+
fieldValues[index] = value;
|
1090
|
+
return fieldValues;
|
1091
|
+
};
|
1065
1092
|
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1093
|
+
/**
|
1094
|
+
* A custom hook that exposes convenient methods to perform operations with a list of dynamic inputs that need to be appended, updated, removed etc. • [Demo](https://codesandbox.io/s/react-hook-form-usefieldarray-ssugn) • [Video](https://youtu.be/4MrbfGSFY2A)
|
1095
|
+
*
|
1096
|
+
* @remarks
|
1097
|
+
* [API](https://react-hook-form.com/docs/usefieldarray) • [Demo](https://codesandbox.io/s/react-hook-form-usefieldarray-ssugn)
|
1098
|
+
*
|
1099
|
+
* @param props - useFieldArray props
|
1100
|
+
*
|
1101
|
+
* @returns methods - functions to manipulate with the Field Arrays (dynamic inputs) {@link UseFieldArrayReturn}
|
1102
|
+
*
|
1103
|
+
* @example
|
1104
|
+
* ```tsx
|
1105
|
+
* function App() {
|
1106
|
+
* const { register, control, handleSubmit, reset, trigger, setError } = useForm({
|
1107
|
+
* defaultValues: {
|
1108
|
+
* test: []
|
1109
|
+
* }
|
1110
|
+
* });
|
1111
|
+
* const { fields, append } = useFieldArray({
|
1112
|
+
* control,
|
1113
|
+
* name: "test"
|
1114
|
+
* });
|
1115
|
+
*
|
1116
|
+
* return (
|
1117
|
+
* <form onSubmit={handleSubmit(data => console.log(data))}>
|
1118
|
+
* {fields.map((item, index) => (
|
1119
|
+
* <input key={item.id} {...register(`test.${index}.firstName`)} />
|
1120
|
+
* ))}
|
1121
|
+
* <button type="button" onClick={() => append({ firstName: "bill" })}>
|
1122
|
+
* append
|
1123
|
+
* </button>
|
1124
|
+
* <input type="submit" />
|
1125
|
+
* </form>
|
1126
|
+
* );
|
1127
|
+
* }
|
1128
|
+
* ```
|
1129
|
+
*/
|
1130
|
+
function useFieldArray(props) {
|
1131
|
+
const methods = useFormContext();
|
1132
|
+
const { control = methods.control, name, keyName = 'id', shouldUnregister, rules, } = props;
|
1133
|
+
const [fields, setFields] = React__default.useState(control._getFieldArray(name));
|
1134
|
+
const ids = React__default.useRef(control._getFieldArray(name).map(generateId));
|
1135
|
+
const _fieldIds = React__default.useRef(fields);
|
1136
|
+
const _name = React__default.useRef(name);
|
1137
|
+
const _actioned = React__default.useRef(false);
|
1138
|
+
_name.current = name;
|
1139
|
+
_fieldIds.current = fields;
|
1140
|
+
control._names.array.add(name);
|
1141
|
+
rules &&
|
1142
|
+
control.register(name, rules);
|
1143
|
+
useSubscribe({
|
1144
|
+
next: ({ values, name: fieldArrayName, }) => {
|
1145
|
+
if (fieldArrayName === _name.current || !fieldArrayName) {
|
1146
|
+
const fieldValues = get(values, _name.current);
|
1147
|
+
if (Array.isArray(fieldValues)) {
|
1148
|
+
setFields(fieldValues);
|
1149
|
+
ids.current = fieldValues.map(generateId);
|
1150
|
+
}
|
1151
|
+
}
|
1152
|
+
},
|
1153
|
+
subject: control._subjects.array,
|
1154
|
+
});
|
1155
|
+
const updateValues = React__default.useCallback((updatedFieldArrayValues) => {
|
1156
|
+
_actioned.current = true;
|
1157
|
+
control._updateFieldArray(name, updatedFieldArrayValues);
|
1158
|
+
}, [control, name]);
|
1159
|
+
const append = (value, options) => {
|
1160
|
+
const appendValue = convertToArrayPayload(cloneObject(value));
|
1161
|
+
const updatedFieldArrayValues = appendAt(control._getFieldArray(name), appendValue);
|
1162
|
+
control._names.focus = getFocusFieldName(name, updatedFieldArrayValues.length - 1, options);
|
1163
|
+
ids.current = appendAt(ids.current, appendValue.map(generateId));
|
1164
|
+
updateValues(updatedFieldArrayValues);
|
1165
|
+
setFields(updatedFieldArrayValues);
|
1166
|
+
control._updateFieldArray(name, updatedFieldArrayValues, appendAt, {
|
1167
|
+
argA: fillEmptyArray(value),
|
1168
|
+
});
|
1078
1169
|
};
|
1079
|
-
const
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
(
|
1087
|
-
|
1088
|
-
|
1089
|
-
const appendErrorsCurry = appendErrors.bind(null, name, validateAllFieldCriteria, error);
|
1090
|
-
const getMinMaxMessage = (exceedMax, maxLengthMessage, minLengthMessage, maxType = INPUT_VALIDATION_RULES.maxLength, minType = INPUT_VALIDATION_RULES.minLength) => {
|
1091
|
-
const message = exceedMax ? maxLengthMessage : minLengthMessage;
|
1092
|
-
error[name] = {
|
1093
|
-
type: exceedMax ? maxType : minType,
|
1094
|
-
message,
|
1095
|
-
ref,
|
1096
|
-
...appendErrorsCurry(exceedMax ? maxType : minType, message),
|
1097
|
-
};
|
1170
|
+
const prepend = (value, options) => {
|
1171
|
+
const prependValue = convertToArrayPayload(cloneObject(value));
|
1172
|
+
const updatedFieldArrayValues = prependAt(control._getFieldArray(name), prependValue);
|
1173
|
+
control._names.focus = getFocusFieldName(name, 0, options);
|
1174
|
+
ids.current = prependAt(ids.current, prependValue.map(generateId));
|
1175
|
+
updateValues(updatedFieldArrayValues);
|
1176
|
+
setFields(updatedFieldArrayValues);
|
1177
|
+
control._updateFieldArray(name, updatedFieldArrayValues, prependAt, {
|
1178
|
+
argA: fillEmptyArray(value),
|
1179
|
+
});
|
1098
1180
|
};
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
}
|
1121
|
-
}
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1181
|
+
const remove = (index) => {
|
1182
|
+
const updatedFieldArrayValues = removeArrayAt(control._getFieldArray(name), index);
|
1183
|
+
ids.current = removeArrayAt(ids.current, index);
|
1184
|
+
updateValues(updatedFieldArrayValues);
|
1185
|
+
setFields(updatedFieldArrayValues);
|
1186
|
+
!Array.isArray(get(control._fields, name)) &&
|
1187
|
+
set(control._fields, name, undefined);
|
1188
|
+
control._updateFieldArray(name, updatedFieldArrayValues, removeArrayAt, {
|
1189
|
+
argA: index,
|
1190
|
+
});
|
1191
|
+
};
|
1192
|
+
const insert$1 = (index, value, options) => {
|
1193
|
+
const insertValue = convertToArrayPayload(cloneObject(value));
|
1194
|
+
const updatedFieldArrayValues = insert(control._getFieldArray(name), index, insertValue);
|
1195
|
+
control._names.focus = getFocusFieldName(name, index, options);
|
1196
|
+
ids.current = insert(ids.current, index, insertValue.map(generateId));
|
1197
|
+
updateValues(updatedFieldArrayValues);
|
1198
|
+
setFields(updatedFieldArrayValues);
|
1199
|
+
control._updateFieldArray(name, updatedFieldArrayValues, insert, {
|
1200
|
+
argA: index,
|
1201
|
+
argB: fillEmptyArray(value),
|
1202
|
+
});
|
1203
|
+
};
|
1204
|
+
const swap = (indexA, indexB) => {
|
1205
|
+
const updatedFieldArrayValues = control._getFieldArray(name);
|
1206
|
+
swapArrayAt(updatedFieldArrayValues, indexA, indexB);
|
1207
|
+
swapArrayAt(ids.current, indexA, indexB);
|
1208
|
+
updateValues(updatedFieldArrayValues);
|
1209
|
+
setFields(updatedFieldArrayValues);
|
1210
|
+
control._updateFieldArray(name, updatedFieldArrayValues, swapArrayAt, {
|
1211
|
+
argA: indexA,
|
1212
|
+
argB: indexB,
|
1213
|
+
}, false);
|
1214
|
+
};
|
1215
|
+
const move = (from, to) => {
|
1216
|
+
const updatedFieldArrayValues = control._getFieldArray(name);
|
1217
|
+
moveArrayAt(updatedFieldArrayValues, from, to);
|
1218
|
+
moveArrayAt(ids.current, from, to);
|
1219
|
+
updateValues(updatedFieldArrayValues);
|
1220
|
+
setFields(updatedFieldArrayValues);
|
1221
|
+
control._updateFieldArray(name, updatedFieldArrayValues, moveArrayAt, {
|
1222
|
+
argA: from,
|
1223
|
+
argB: to,
|
1224
|
+
}, false);
|
1225
|
+
};
|
1226
|
+
const update = (index, value) => {
|
1227
|
+
const updateValue = cloneObject(value);
|
1228
|
+
const updatedFieldArrayValues = updateAt(control._getFieldArray(name), index, updateValue);
|
1229
|
+
ids.current = [...updatedFieldArrayValues].map((item, i) => !item || i === index ? generateId() : ids.current[i]);
|
1230
|
+
updateValues(updatedFieldArrayValues);
|
1231
|
+
setFields([...updatedFieldArrayValues]);
|
1232
|
+
control._updateFieldArray(name, updatedFieldArrayValues, updateAt, {
|
1233
|
+
argA: index,
|
1234
|
+
argB: updateValue,
|
1235
|
+
}, true, false);
|
1236
|
+
};
|
1237
|
+
const replace = (value) => {
|
1238
|
+
const updatedFieldArrayValues = convertToArrayPayload(cloneObject(value));
|
1239
|
+
ids.current = updatedFieldArrayValues.map(generateId);
|
1240
|
+
updateValues([...updatedFieldArrayValues]);
|
1241
|
+
setFields([...updatedFieldArrayValues]);
|
1242
|
+
control._updateFieldArray(name, [...updatedFieldArrayValues], (data) => data, {}, true, false);
|
1243
|
+
};
|
1244
|
+
React__default.useEffect(() => {
|
1245
|
+
control._state.action = false;
|
1246
|
+
isWatched(name, control._names) &&
|
1247
|
+
control._subjects.state.next({
|
1248
|
+
...control._formState,
|
1249
|
+
});
|
1250
|
+
if (_actioned.current &&
|
1251
|
+
(!getValidationModes(control._options.mode).isOnSubmit ||
|
1252
|
+
control._formState.isSubmitted)) {
|
1253
|
+
if (control._options.resolver) {
|
1254
|
+
control._executeSchema([name]).then((result) => {
|
1255
|
+
const error = get(result.errors, name);
|
1256
|
+
const existingError = get(control._formState.errors, name);
|
1257
|
+
if (existingError
|
1258
|
+
? (!error && existingError.type) ||
|
1259
|
+
(error &&
|
1260
|
+
(existingError.type !== error.type ||
|
1261
|
+
existingError.message !== error.message))
|
1262
|
+
: error && error.type) {
|
1263
|
+
error
|
1264
|
+
? set(control._formState.errors, name, error)
|
1265
|
+
: unset(control._formState.errors, name);
|
1266
|
+
control._subjects.state.next({
|
1267
|
+
errors: control._formState.errors,
|
1268
|
+
});
|
1269
|
+
}
|
1270
|
+
});
|
1148
1271
|
}
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1272
|
+
else {
|
1273
|
+
const field = get(control._fields, name);
|
1274
|
+
if (field &&
|
1275
|
+
field._f &&
|
1276
|
+
!(getValidationModes(control._options.reValidateMode).isOnSubmit &&
|
1277
|
+
getValidationModes(control._options.mode).isOnSubmit)) {
|
1278
|
+
validateField(field, control._names.disabled, control._formValues, control._options.criteriaMode === VALIDATION_MODE.all, control._options.shouldUseNativeValidation, true).then((error) => !isEmptyObject(error) &&
|
1279
|
+
control._subjects.state.next({
|
1280
|
+
errors: updateFieldArrayRootError(control._formState.errors, error, name),
|
1281
|
+
}));
|
1282
|
+
}
|
1155
1283
|
}
|
1156
1284
|
}
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1285
|
+
control._subjects.values.next({
|
1286
|
+
name,
|
1287
|
+
values: { ...control._formValues },
|
1288
|
+
});
|
1289
|
+
control._names.focus &&
|
1290
|
+
iterateFieldsByAction(control._fields, (ref, key) => {
|
1291
|
+
if (control._names.focus &&
|
1292
|
+
key.startsWith(control._names.focus) &&
|
1293
|
+
ref.focus) {
|
1294
|
+
ref.focus();
|
1295
|
+
return 1;
|
1296
|
+
}
|
1297
|
+
return;
|
1298
|
+
});
|
1299
|
+
control._names.focus = '';
|
1300
|
+
control._updateValid();
|
1301
|
+
_actioned.current = false;
|
1302
|
+
}, [fields, name, control]);
|
1303
|
+
React__default.useEffect(() => {
|
1304
|
+
!get(control._formValues, name) && control._updateFieldArray(name);
|
1305
|
+
return () => {
|
1306
|
+
(control._options.shouldUnregister || shouldUnregister) &&
|
1307
|
+
control.unregister(name);
|
1308
|
+
};
|
1309
|
+
}, [name, control, keyName, shouldUnregister]);
|
1310
|
+
return {
|
1311
|
+
swap: React__default.useCallback(swap, [updateValues, name, control]),
|
1312
|
+
move: React__default.useCallback(move, [updateValues, name, control]),
|
1313
|
+
prepend: React__default.useCallback(prepend, [updateValues, name, control]),
|
1314
|
+
append: React__default.useCallback(append, [updateValues, name, control]),
|
1315
|
+
remove: React__default.useCallback(remove, [updateValues, name, control]),
|
1316
|
+
insert: React__default.useCallback(insert$1, [updateValues, name, control]),
|
1317
|
+
update: React__default.useCallback(update, [updateValues, name, control]),
|
1318
|
+
replace: React__default.useCallback(replace, [updateValues, name, control]),
|
1319
|
+
fields: React__default.useMemo(() => fields.map((field, index) => ({
|
1320
|
+
...field,
|
1321
|
+
[keyName]: ids.current[index] || generateId(),
|
1322
|
+
})), [fields, keyName]),
|
1323
|
+
};
|
1324
|
+
}
|
1325
|
+
|
1326
|
+
var createSubject = () => {
|
1327
|
+
let _observers = [];
|
1328
|
+
const next = (value) => {
|
1329
|
+
for (const observer of _observers) {
|
1330
|
+
observer.next && observer.next(value);
|
1163
1331
|
}
|
1332
|
+
};
|
1333
|
+
const subscribe = (observer) => {
|
1334
|
+
_observers.push(observer);
|
1335
|
+
return {
|
1336
|
+
unsubscribe: () => {
|
1337
|
+
_observers = _observers.filter((o) => o !== observer);
|
1338
|
+
},
|
1339
|
+
};
|
1340
|
+
};
|
1341
|
+
const unsubscribe = () => {
|
1342
|
+
_observers = [];
|
1343
|
+
};
|
1344
|
+
return {
|
1345
|
+
get observers() {
|
1346
|
+
return _observers;
|
1347
|
+
},
|
1348
|
+
next,
|
1349
|
+
subscribe,
|
1350
|
+
unsubscribe,
|
1351
|
+
};
|
1352
|
+
};
|
1353
|
+
|
1354
|
+
var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
|
1355
|
+
|
1356
|
+
function deepEqual(object1, object2) {
|
1357
|
+
if (isPrimitive(object1) || isPrimitive(object2)) {
|
1358
|
+
return object1 === object2;
|
1164
1359
|
}
|
1165
|
-
if ((
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1360
|
+
if (isDateObject(object1) && isDateObject(object2)) {
|
1361
|
+
return object1.getTime() === object2.getTime();
|
1362
|
+
}
|
1363
|
+
const keys1 = Object.keys(object1);
|
1364
|
+
const keys2 = Object.keys(object2);
|
1365
|
+
if (keys1.length !== keys2.length) {
|
1366
|
+
return false;
|
1367
|
+
}
|
1368
|
+
for (const key of keys1) {
|
1369
|
+
const val1 = object1[key];
|
1370
|
+
if (!keys2.includes(key)) {
|
1371
|
+
return false;
|
1372
|
+
}
|
1373
|
+
if (key !== 'ref') {
|
1374
|
+
const val2 = object2[key];
|
1375
|
+
if ((isDateObject(val1) && isDateObject(val2)) ||
|
1376
|
+
(isObject(val1) && isObject(val2)) ||
|
1377
|
+
(Array.isArray(val1) && Array.isArray(val2))
|
1378
|
+
? !deepEqual(val1, val2)
|
1379
|
+
: val1 !== val2) {
|
1380
|
+
return false;
|
1179
1381
|
}
|
1180
1382
|
}
|
1181
1383
|
}
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1384
|
+
return true;
|
1385
|
+
}
|
1386
|
+
|
1387
|
+
var isMultipleSelect = (element) => element.type === `select-multiple`;
|
1388
|
+
|
1389
|
+
var isRadioOrCheckbox = (ref) => isRadioInput(ref) || isCheckBoxInput(ref);
|
1390
|
+
|
1391
|
+
var live = (ref) => isHTMLElement(ref) && ref.isConnected;
|
1392
|
+
|
1393
|
+
var objectHasFunction = (data) => {
|
1394
|
+
for (const key in data) {
|
1395
|
+
if (isFunction(data[key])) {
|
1396
|
+
return true;
|
1195
1397
|
}
|
1196
1398
|
}
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1399
|
+
return false;
|
1400
|
+
};
|
1401
|
+
|
1402
|
+
function markFieldsDirty(data, fields = {}) {
|
1403
|
+
const isParentNodeArray = Array.isArray(data);
|
1404
|
+
if (isObject(data) || isParentNodeArray) {
|
1405
|
+
for (const key in data) {
|
1406
|
+
if (Array.isArray(data[key]) ||
|
1407
|
+
(isObject(data[key]) && !objectHasFunction(data[key]))) {
|
1408
|
+
fields[key] = Array.isArray(data[key]) ? [] : {};
|
1409
|
+
markFieldsDirty(data[key], fields[key]);
|
1410
|
+
}
|
1411
|
+
else if (!isNullOrUndefined(data[key])) {
|
1412
|
+
fields[key] = true;
|
1210
1413
|
}
|
1211
1414
|
}
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1415
|
+
}
|
1416
|
+
return fields;
|
1417
|
+
}
|
1418
|
+
function getDirtyFieldsFromDefaultValues(data, formValues, dirtyFieldsFromValues) {
|
1419
|
+
const isParentNodeArray = Array.isArray(data);
|
1420
|
+
if (isObject(data) || isParentNodeArray) {
|
1421
|
+
for (const key in data) {
|
1422
|
+
if (Array.isArray(data[key]) ||
|
1423
|
+
(isObject(data[key]) && !objectHasFunction(data[key]))) {
|
1424
|
+
if (isUndefined(formValues) ||
|
1425
|
+
isPrimitive(dirtyFieldsFromValues[key])) {
|
1426
|
+
dirtyFieldsFromValues[key] = Array.isArray(data[key])
|
1427
|
+
? markFieldsDirty(data[key], [])
|
1428
|
+
: { ...markFieldsDirty(data[key]) };
|
1217
1429
|
}
|
1218
|
-
|
1219
|
-
|
1220
|
-
validationResult = {
|
1221
|
-
...validateError,
|
1222
|
-
...appendErrorsCurry(key, validateError.message),
|
1223
|
-
};
|
1224
|
-
setCustomValidity(validateError.message);
|
1225
|
-
if (validateAllFieldCriteria) {
|
1226
|
-
error[name] = validationResult;
|
1227
|
-
}
|
1430
|
+
else {
|
1431
|
+
getDirtyFieldsFromDefaultValues(data[key], isNullOrUndefined(formValues) ? {} : formValues[key], dirtyFieldsFromValues[key]);
|
1228
1432
|
}
|
1229
1433
|
}
|
1230
|
-
|
1231
|
-
|
1232
|
-
ref: inputRef,
|
1233
|
-
...validationResult,
|
1234
|
-
};
|
1235
|
-
if (!validateAllFieldCriteria) {
|
1236
|
-
return error;
|
1237
|
-
}
|
1434
|
+
else {
|
1435
|
+
dirtyFieldsFromValues[key] = !deepEqual(data[key], formValues[key]);
|
1238
1436
|
}
|
1239
1437
|
}
|
1240
1438
|
}
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1439
|
+
return dirtyFieldsFromValues;
|
1440
|
+
}
|
1441
|
+
var getDirtyFields = (defaultValues, formValues) => getDirtyFieldsFromDefaultValues(defaultValues, formValues, markFieldsDirty(formValues));
|
1244
1442
|
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1443
|
+
var getFieldValueAs = (value, { valueAsNumber, valueAsDate, setValueAs }) => isUndefined(value)
|
1444
|
+
? value
|
1445
|
+
: valueAsNumber
|
1446
|
+
? value === ''
|
1447
|
+
? NaN
|
1448
|
+
: value
|
1449
|
+
? +value
|
1450
|
+
: value
|
1451
|
+
: valueAsDate && isString(value)
|
1452
|
+
? new Date(value)
|
1453
|
+
: setValueAs
|
1454
|
+
? setValueAs(value)
|
1455
|
+
: value;
|
1456
|
+
|
1457
|
+
function getFieldValue(_f) {
|
1458
|
+
const ref = _f.ref;
|
1459
|
+
if (isFileInput(ref)) {
|
1460
|
+
return ref.files;
|
1461
|
+
}
|
1462
|
+
if (isRadioInput(ref)) {
|
1463
|
+
return getRadioValue(_f.refs).value;
|
1464
|
+
}
|
1465
|
+
if (isMultipleSelect(ref)) {
|
1466
|
+
return [...ref.selectedOptions].map(({ value }) => value);
|
1467
|
+
}
|
1468
|
+
if (isCheckBoxInput(ref)) {
|
1469
|
+
return getCheckboxValue(_f.refs).value;
|
1470
|
+
}
|
1471
|
+
return getFieldValueAs(isUndefined(ref.value) ? _f.ref.value : ref.value, _f);
|
1472
|
+
}
|
1473
|
+
|
1474
|
+
var getResolverOptions = (fieldsNames, _fields, criteriaMode, shouldUseNativeValidation) => {
|
1475
|
+
const fields = {};
|
1476
|
+
for (const name of fieldsNames) {
|
1477
|
+
const field = get(_fields, name);
|
1478
|
+
field && set(fields, name, field._f);
|
1479
|
+
}
|
1480
|
+
return {
|
1481
|
+
criteriaMode,
|
1482
|
+
names: [...fieldsNames],
|
1483
|
+
fields,
|
1484
|
+
shouldUseNativeValidation,
|
1485
|
+
};
|
1249
1486
|
};
|
1250
|
-
|
1487
|
+
|
1488
|
+
var getRuleValue = (rule) => isUndefined(rule)
|
1489
|
+
? rule
|
1490
|
+
: isRegex(rule)
|
1491
|
+
? rule.source
|
1492
|
+
: isObject(rule)
|
1493
|
+
? isRegex(rule.value)
|
1494
|
+
? rule.value.source
|
1495
|
+
: rule.value
|
1496
|
+
: rule;
|
1497
|
+
|
1498
|
+
const ASYNC_FUNCTION = 'AsyncFunction';
|
1499
|
+
var hasPromiseValidation = (fieldReference) => !!fieldReference &&
|
1500
|
+
!!fieldReference.validate &&
|
1501
|
+
!!((isFunction(fieldReference.validate) &&
|
1502
|
+
fieldReference.validate.constructor.name === ASYNC_FUNCTION) ||
|
1503
|
+
(isObject(fieldReference.validate) &&
|
1504
|
+
Object.values(fieldReference.validate).find((validateFunction) => validateFunction.constructor.name === ASYNC_FUNCTION)));
|
1505
|
+
|
1506
|
+
var hasValidation = (options) => options.mount &&
|
1507
|
+
(options.required ||
|
1508
|
+
options.min ||
|
1509
|
+
options.max ||
|
1510
|
+
options.maxLength ||
|
1511
|
+
options.minLength ||
|
1512
|
+
options.pattern ||
|
1513
|
+
options.validate);
|
1514
|
+
|
1515
|
+
function schemaErrorLookup(errors, _fields, name) {
|
1516
|
+
const error = get(errors, name);
|
1517
|
+
if (error || isKey(name)) {
|
1518
|
+
return {
|
1519
|
+
error,
|
1520
|
+
name,
|
1521
|
+
};
|
1522
|
+
}
|
1523
|
+
const names = name.split('.');
|
1524
|
+
while (names.length) {
|
1525
|
+
const fieldName = names.join('.');
|
1526
|
+
const field = get(_fields, fieldName);
|
1527
|
+
const foundError = get(errors, fieldName);
|
1528
|
+
if (field && !Array.isArray(field) && name !== fieldName) {
|
1529
|
+
return { name };
|
1530
|
+
}
|
1531
|
+
if (foundError && foundError.type) {
|
1532
|
+
return {
|
1533
|
+
name: fieldName,
|
1534
|
+
error: foundError,
|
1535
|
+
};
|
1536
|
+
}
|
1537
|
+
names.pop();
|
1538
|
+
}
|
1539
|
+
return {
|
1540
|
+
name,
|
1541
|
+
};
|
1542
|
+
}
|
1543
|
+
|
1544
|
+
var skipValidation = (isBlurEvent, isTouched, isSubmitted, reValidateMode, mode) => {
|
1545
|
+
if (mode.isOnAll) {
|
1546
|
+
return false;
|
1547
|
+
}
|
1548
|
+
else if (!isSubmitted && mode.isOnTouch) {
|
1549
|
+
return !(isTouched || isBlurEvent);
|
1550
|
+
}
|
1551
|
+
else if (isSubmitted ? reValidateMode.isOnBlur : mode.isOnBlur) {
|
1552
|
+
return !isBlurEvent;
|
1553
|
+
}
|
1554
|
+
else if (isSubmitted ? reValidateMode.isOnChange : mode.isOnChange) {
|
1555
|
+
return isBlurEvent;
|
1556
|
+
}
|
1557
|
+
return true;
|
1558
|
+
};
|
1559
|
+
|
1560
|
+
var unsetEmptyArray = (ref, name) => !compact(get(ref, name)).length && unset(ref, name);
|
1561
|
+
|
1562
|
+
const defaultOptions = {
|
1563
|
+
mode: VALIDATION_MODE.onSubmit,
|
1564
|
+
reValidateMode: VALIDATION_MODE.onChange,
|
1565
|
+
shouldFocusError: true,
|
1566
|
+
};
|
1567
|
+
function createFormControl(props = {}) {
|
1251
1568
|
let _options = {
|
1252
1569
|
...defaultOptions,
|
1253
1570
|
...props,
|
@@ -1255,7 +1572,6 @@ function createFormControl(props = {}) {
|
|
1255
1572
|
let _formState = {
|
1256
1573
|
submitCount: 0,
|
1257
1574
|
isDirty: false,
|
1258
|
-
isReady: false,
|
1259
1575
|
isLoading: isFunction(_options.defaultValues),
|
1260
1576
|
isValidating: false,
|
1261
1577
|
isSubmitted: false,
|
@@ -1268,7 +1584,7 @@ function createFormControl(props = {}) {
|
|
1268
1584
|
errors: _options.errors || {},
|
1269
1585
|
disabled: _options.disabled || false,
|
1270
1586
|
};
|
1271
|
-
|
1587
|
+
let _fields = {};
|
1272
1588
|
let _defaultValues = isObject(_options.defaultValues) || isObject(_options.values)
|
1273
1589
|
? cloneObject(_options.defaultValues || _options.values) || {}
|
1274
1590
|
: {};
|
@@ -1298,25 +1614,22 @@ function createFormControl(props = {}) {
|
|
1298
1614
|
isValid: false,
|
1299
1615
|
errors: false,
|
1300
1616
|
};
|
1301
|
-
let _proxySubscribeFormState = {
|
1302
|
-
..._proxyFormState,
|
1303
|
-
};
|
1304
1617
|
const _subjects = {
|
1618
|
+
values: createSubject(),
|
1305
1619
|
array: createSubject(),
|
1306
1620
|
state: createSubject(),
|
1307
1621
|
};
|
1622
|
+
const validationModeBeforeSubmit = getValidationModes(_options.mode);
|
1623
|
+
const validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
|
1308
1624
|
const shouldDisplayAllAssociatedErrors = _options.criteriaMode === VALIDATION_MODE.all;
|
1309
1625
|
const debounce = (callback) => (wait) => {
|
1310
1626
|
clearTimeout(timer);
|
1311
1627
|
timer = setTimeout(callback, wait);
|
1312
1628
|
};
|
1313
|
-
const
|
1314
|
-
if (!_options.disabled &&
|
1315
|
-
(_proxyFormState.isValid ||
|
1316
|
-
_proxySubscribeFormState.isValid ||
|
1317
|
-
shouldUpdateValid)) {
|
1629
|
+
const _updateValid = async (shouldUpdateValid) => {
|
1630
|
+
if (!_options.disabled && (_proxyFormState.isValid || shouldUpdateValid)) {
|
1318
1631
|
const isValid = _options.resolver
|
1319
|
-
? isEmptyObject((await
|
1632
|
+
? isEmptyObject((await _executeSchema()).errors)
|
1320
1633
|
: await executeBuiltInValidation(_fields, true);
|
1321
1634
|
if (isValid !== _formState.isValid) {
|
1322
1635
|
_subjects.state.next({
|
@@ -1327,10 +1640,7 @@ function createFormControl(props = {}) {
|
|
1327
1640
|
};
|
1328
1641
|
const _updateIsValidating = (names, isValidating) => {
|
1329
1642
|
if (!_options.disabled &&
|
1330
|
-
(_proxyFormState.isValidating ||
|
1331
|
-
_proxyFormState.validatingFields ||
|
1332
|
-
_proxySubscribeFormState.isValidating ||
|
1333
|
-
_proxySubscribeFormState.validatingFields)) {
|
1643
|
+
(_proxyFormState.isValidating || _proxyFormState.validatingFields)) {
|
1334
1644
|
(names || Array.from(_names.mount)).forEach((name) => {
|
1335
1645
|
if (name) {
|
1336
1646
|
isValidating
|
@@ -1344,7 +1654,7 @@ function createFormControl(props = {}) {
|
|
1344
1654
|
});
|
1345
1655
|
}
|
1346
1656
|
};
|
1347
|
-
const
|
1657
|
+
const _updateFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndState = true) => {
|
1348
1658
|
if (args && method && !_options.disabled) {
|
1349
1659
|
_state.action = true;
|
1350
1660
|
if (shouldUpdateFieldsAndState && Array.isArray(get(_fields, name))) {
|
@@ -1357,14 +1667,13 @@ function createFormControl(props = {}) {
|
|
1357
1667
|
shouldSetValues && set(_formState.errors, name, errors);
|
1358
1668
|
unsetEmptyArray(_formState.errors, name);
|
1359
1669
|
}
|
1360
|
-
if (
|
1361
|
-
_proxySubscribeFormState.touchedFields) &&
|
1670
|
+
if (_proxyFormState.touchedFields &&
|
1362
1671
|
shouldUpdateFieldsAndState &&
|
1363
1672
|
Array.isArray(get(_formState.touchedFields, name))) {
|
1364
1673
|
const touchedFields = method(get(_formState.touchedFields, name), args.argA, args.argB);
|
1365
1674
|
shouldSetValues && set(_formState.touchedFields, name, touchedFields);
|
1366
1675
|
}
|
1367
|
-
if (_proxyFormState.dirtyFields
|
1676
|
+
if (_proxyFormState.dirtyFields) {
|
1368
1677
|
_formState.dirtyFields = getDirtyFields(_defaultValues, _formValues);
|
1369
1678
|
}
|
1370
1679
|
_subjects.state.next({
|
@@ -1401,7 +1710,7 @@ function createFormControl(props = {}) {
|
|
1401
1710
|
shouldSkipSetValueAs
|
1402
1711
|
? set(_formValues, name, shouldSkipSetValueAs ? defaultValue : getFieldValue(field._f))
|
1403
1712
|
: setFieldValue(name, defaultValue);
|
1404
|
-
_state.mount &&
|
1713
|
+
_state.mount && _updateValid();
|
1405
1714
|
}
|
1406
1715
|
};
|
1407
1716
|
const updateTouchAndDirty = (name, fieldValue, isBlurEvent, shouldDirty, shouldRender) => {
|
@@ -1411,22 +1720,24 @@ function createFormControl(props = {}) {
|
|
1411
1720
|
name,
|
1412
1721
|
};
|
1413
1722
|
if (!_options.disabled) {
|
1723
|
+
const disabledField = !!(get(_fields, name) &&
|
1724
|
+
get(_fields, name)._f &&
|
1725
|
+
get(_fields, name)._f.disabled);
|
1414
1726
|
if (!isBlurEvent || shouldDirty) {
|
1415
|
-
if (_proxyFormState.isDirty
|
1727
|
+
if (_proxyFormState.isDirty) {
|
1416
1728
|
isPreviousDirty = _formState.isDirty;
|
1417
1729
|
_formState.isDirty = output.isDirty = _getDirty();
|
1418
1730
|
shouldUpdateField = isPreviousDirty !== output.isDirty;
|
1419
1731
|
}
|
1420
|
-
const isCurrentFieldPristine = deepEqual(get(_defaultValues, name), fieldValue);
|
1421
|
-
isPreviousDirty = !!get(_formState.dirtyFields, name);
|
1422
|
-
isCurrentFieldPristine
|
1732
|
+
const isCurrentFieldPristine = disabledField || deepEqual(get(_defaultValues, name), fieldValue);
|
1733
|
+
isPreviousDirty = !!(!disabledField && get(_formState.dirtyFields, name));
|
1734
|
+
isCurrentFieldPristine || disabledField
|
1423
1735
|
? unset(_formState.dirtyFields, name)
|
1424
1736
|
: set(_formState.dirtyFields, name, true);
|
1425
1737
|
output.dirtyFields = _formState.dirtyFields;
|
1426
1738
|
shouldUpdateField =
|
1427
1739
|
shouldUpdateField ||
|
1428
|
-
(
|
1429
|
-
_proxySubscribeFormState.dirtyFields) &&
|
1740
|
+
(_proxyFormState.dirtyFields &&
|
1430
1741
|
isPreviousDirty !== !isCurrentFieldPristine);
|
1431
1742
|
}
|
1432
1743
|
if (isBlurEvent) {
|
@@ -1436,8 +1747,7 @@ function createFormControl(props = {}) {
|
|
1436
1747
|
output.touchedFields = _formState.touchedFields;
|
1437
1748
|
shouldUpdateField =
|
1438
1749
|
shouldUpdateField ||
|
1439
|
-
(
|
1440
|
-
_proxySubscribeFormState.touchedFields) &&
|
1750
|
+
(_proxyFormState.touchedFields &&
|
1441
1751
|
isPreviousFieldTouched !== isBlurEvent);
|
1442
1752
|
}
|
1443
1753
|
}
|
@@ -1447,7 +1757,7 @@ function createFormControl(props = {}) {
|
|
1447
1757
|
};
|
1448
1758
|
const shouldRenderByError = (name, isValid, error, fieldState) => {
|
1449
1759
|
const previousFieldError = get(_formState.errors, name);
|
1450
|
-
const shouldUpdateValid =
|
1760
|
+
const shouldUpdateValid = _proxyFormState.isValid &&
|
1451
1761
|
isBoolean(isValid) &&
|
1452
1762
|
_formState.isValid !== isValid;
|
1453
1763
|
if (_options.delayError && error) {
|
@@ -1477,14 +1787,14 @@ function createFormControl(props = {}) {
|
|
1477
1787
|
_subjects.state.next(updatedFormState);
|
1478
1788
|
}
|
1479
1789
|
};
|
1480
|
-
const
|
1790
|
+
const _executeSchema = async (name) => {
|
1481
1791
|
_updateIsValidating(name, true);
|
1482
1792
|
const result = await _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
|
1483
1793
|
_updateIsValidating(name);
|
1484
1794
|
return result;
|
1485
1795
|
};
|
1486
1796
|
const executeSchemaAndUpdateState = async (names) => {
|
1487
|
-
const { errors } = await
|
1797
|
+
const { errors } = await _executeSchema(names);
|
1488
1798
|
if (names) {
|
1489
1799
|
for (const name of names) {
|
1490
1800
|
const error = get(errors, name);
|
@@ -1557,1034 +1867,689 @@ function createFormControl(props = {}) {
|
|
1557
1867
|
? { [names]: defaultValue }
|
1558
1868
|
: defaultValue),
|
1559
1869
|
}, isGlobal, defaultValue);
|
1560
|
-
const _getFieldArray = (name) => compact(get(_state.mount ? _formValues : _defaultValues, name, _options.shouldUnregister ? get(_defaultValues, name, []) : []));
|
1561
|
-
const setFieldValue = (name, value, options = {}) => {
|
1562
|
-
const field = get(_fields, name);
|
1563
|
-
let fieldValue = value;
|
1564
|
-
if (field) {
|
1565
|
-
const fieldReference = field._f;
|
1566
|
-
if (fieldReference) {
|
1567
|
-
!fieldReference.disabled &&
|
1568
|
-
set(_formValues, name, getFieldValueAs(value, fieldReference));
|
1569
|
-
fieldValue =
|
1570
|
-
isHTMLElement(fieldReference.ref) && isNullOrUndefined(value)
|
1571
|
-
? ''
|
1572
|
-
: value;
|
1573
|
-
if (isMultipleSelect(fieldReference.ref)) {
|
1574
|
-
[...fieldReference.ref.options].forEach((optionRef) => (optionRef.selected = fieldValue.includes(optionRef.value)));
|
1575
|
-
}
|
1576
|
-
else if (fieldReference.refs) {
|
1577
|
-
if (isCheckBoxInput(fieldReference.ref)) {
|
1578
|
-
fieldReference.refs.
|
1579
|
-
|
1580
|
-
|
1581
|
-
|
1582
|
-
|
1583
|
-
|
1584
|
-
|
1585
|
-
|
1586
|
-
|
1587
|
-
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
1591
|
-
|
1592
|
-
|
1593
|
-
|
1594
|
-
|
1595
|
-
fieldReference.ref.
|
1596
|
-
|
1597
|
-
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
1601
|
-
name,
|
1602
|
-
values: cloneObject(_formValues),
|
1603
|
-
});
|
1604
|
-
}
|
1605
|
-
}
|
1606
|
-
}
|
1607
|
-
}
|
1608
|
-
(options.shouldDirty || options.shouldTouch) &&
|
1609
|
-
updateTouchAndDirty(name, fieldValue, options.shouldTouch, options.shouldDirty, true);
|
1610
|
-
options.shouldValidate && trigger(name);
|
1611
|
-
};
|
1612
|
-
const setValues = (name, value, options) => {
|
1613
|
-
for (const fieldKey in value) {
|
1614
|
-
if (!value.hasOwnProperty(fieldKey)) {
|
1615
|
-
return;
|
1616
|
-
}
|
1617
|
-
const fieldValue = value[fieldKey];
|
1618
|
-
const fieldName = `${name}.${fieldKey}`;
|
1619
|
-
const field = get(_fields, fieldName);
|
1620
|
-
(_names.array.has(name) ||
|
1621
|
-
isObject(fieldValue) ||
|
1622
|
-
(field && !field._f)) &&
|
1623
|
-
!isDateObject(fieldValue)
|
1624
|
-
? setValues(fieldName, fieldValue, options)
|
1625
|
-
: setFieldValue(fieldName, fieldValue, options);
|
1626
|
-
}
|
1627
|
-
};
|
1628
|
-
const setValue = (name, value, options = {}) => {
|
1629
|
-
const field = get(_fields, name);
|
1630
|
-
const isFieldArray = _names.array.has(name);
|
1631
|
-
const cloneValue = cloneObject(value);
|
1632
|
-
set(_formValues, name, cloneValue);
|
1633
|
-
if (isFieldArray) {
|
1634
|
-
_subjects.array.next({
|
1635
|
-
name,
|
1636
|
-
values: cloneObject(_formValues),
|
1637
|
-
});
|
1638
|
-
if ((_proxyFormState.isDirty ||
|
1639
|
-
_proxyFormState.dirtyFields ||
|
1640
|
-
_proxySubscribeFormState.isDirty ||
|
1641
|
-
_proxySubscribeFormState.dirtyFields) &&
|
1642
|
-
options.shouldDirty) {
|
1643
|
-
_subjects.state.next({
|
1644
|
-
name,
|
1645
|
-
dirtyFields: getDirtyFields(_defaultValues, _formValues),
|
1646
|
-
isDirty: _getDirty(name, cloneValue),
|
1647
|
-
});
|
1648
|
-
}
|
1649
|
-
}
|
1650
|
-
else {
|
1651
|
-
field && !field._f && !isNullOrUndefined(cloneValue)
|
1652
|
-
? setValues(name, cloneValue, options)
|
1653
|
-
: setFieldValue(name, cloneValue, options);
|
1654
|
-
}
|
1655
|
-
isWatched(name, _names) && _subjects.state.next({ ..._formState });
|
1656
|
-
_subjects.state.next({
|
1657
|
-
name: _state.mount ? name : undefined,
|
1658
|
-
values: cloneObject(_formValues),
|
1659
|
-
});
|
1660
|
-
};
|
1661
|
-
const onChange = async (event) => {
|
1662
|
-
_state.mount = true;
|
1663
|
-
const target = event.target;
|
1664
|
-
let name = target.name;
|
1665
|
-
let isFieldValueUpdated = true;
|
1666
|
-
const field = get(_fields, name);
|
1667
|
-
const _updateIsFieldValueUpdated = (fieldValue) => {
|
1668
|
-
isFieldValueUpdated =
|
1669
|
-
Number.isNaN(fieldValue) ||
|
1670
|
-
(isDateObject(fieldValue) && isNaN(fieldValue.getTime())) ||
|
1671
|
-
deepEqual(fieldValue, get(_formValues, name, fieldValue));
|
1672
|
-
};
|
1673
|
-
const validationModeBeforeSubmit = getValidationModes(_options.mode);
|
1674
|
-
const validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
|
1675
|
-
if (field) {
|
1676
|
-
let error;
|
1677
|
-
let isValid;
|
1678
|
-
const fieldValue = target.type
|
1679
|
-
? getFieldValue(field._f)
|
1680
|
-
: getEventValue(event);
|
1681
|
-
const isBlurEvent = event.type === EVENTS.BLUR || event.type === EVENTS.FOCUS_OUT;
|
1682
|
-
const shouldSkipValidation = (!hasValidation(field._f) &&
|
1683
|
-
!_options.resolver &&
|
1684
|
-
!get(_formState.errors, name) &&
|
1685
|
-
!field._f.deps) ||
|
1686
|
-
skipValidation(isBlurEvent, get(_formState.touchedFields, name), _formState.isSubmitted, validationModeAfterSubmit, validationModeBeforeSubmit);
|
1687
|
-
const watched = isWatched(name, _names, isBlurEvent);
|
1688
|
-
set(_formValues, name, fieldValue);
|
1689
|
-
if (isBlurEvent) {
|
1690
|
-
field._f.onBlur && field._f.onBlur(event);
|
1691
|
-
delayErrorCallback && delayErrorCallback(0);
|
1692
|
-
}
|
1693
|
-
else if (field._f.onChange) {
|
1694
|
-
field._f.onChange(event);
|
1695
|
-
}
|
1696
|
-
const fieldState = updateTouchAndDirty(name, fieldValue, isBlurEvent);
|
1697
|
-
const shouldRender = !isEmptyObject(fieldState) || watched;
|
1698
|
-
!isBlurEvent &&
|
1699
|
-
_subjects.state.next({
|
1700
|
-
name,
|
1701
|
-
type: event.type,
|
1702
|
-
values: cloneObject(_formValues),
|
1703
|
-
});
|
1704
|
-
if (shouldSkipValidation) {
|
1705
|
-
if (_proxyFormState.isValid || _proxySubscribeFormState.isValid) {
|
1706
|
-
if (_options.mode === 'onBlur') {
|
1707
|
-
if (isBlurEvent) {
|
1708
|
-
_setValid();
|
1709
|
-
}
|
1710
|
-
}
|
1711
|
-
else if (!isBlurEvent) {
|
1712
|
-
_setValid();
|
1713
|
-
}
|
1714
|
-
}
|
1715
|
-
return (shouldRender &&
|
1716
|
-
_subjects.state.next({ name, ...(watched ? {} : fieldState) }));
|
1717
|
-
}
|
1718
|
-
!isBlurEvent && watched && _subjects.state.next({ ..._formState });
|
1719
|
-
if (_options.resolver) {
|
1720
|
-
const { errors } = await _runSchema([name]);
|
1721
|
-
_updateIsFieldValueUpdated(fieldValue);
|
1722
|
-
if (isFieldValueUpdated) {
|
1723
|
-
const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
|
1724
|
-
const errorLookupResult = schemaErrorLookup(errors, _fields, previousErrorLookupResult.name || name);
|
1725
|
-
error = errorLookupResult.error;
|
1726
|
-
name = errorLookupResult.name;
|
1727
|
-
isValid = isEmptyObject(errors);
|
1728
|
-
}
|
1729
|
-
}
|
1730
|
-
else {
|
1731
|
-
_updateIsValidating([name], true);
|
1732
|
-
error = (await validateField(field, _names.disabled, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
|
1733
|
-
_updateIsValidating([name]);
|
1734
|
-
_updateIsFieldValueUpdated(fieldValue);
|
1735
|
-
if (isFieldValueUpdated) {
|
1736
|
-
if (error) {
|
1737
|
-
isValid = false;
|
1738
|
-
}
|
1739
|
-
else if (_proxyFormState.isValid ||
|
1740
|
-
_proxySubscribeFormState.isValid) {
|
1741
|
-
isValid = await executeBuiltInValidation(_fields, true);
|
1742
|
-
}
|
1743
|
-
}
|
1744
|
-
}
|
1745
|
-
if (isFieldValueUpdated) {
|
1746
|
-
field._f.deps &&
|
1747
|
-
trigger(field._f.deps);
|
1748
|
-
shouldRenderByError(name, isValid, error, fieldState);
|
1749
|
-
}
|
1750
|
-
}
|
1751
|
-
};
|
1752
|
-
const _focusInput = (ref, key) => {
|
1753
|
-
if (get(_formState.errors, key) && ref.focus) {
|
1754
|
-
ref.focus();
|
1755
|
-
return 1;
|
1756
|
-
}
|
1757
|
-
return;
|
1758
|
-
};
|
1759
|
-
const trigger = async (name, options = {}) => {
|
1760
|
-
let isValid;
|
1761
|
-
let validationResult;
|
1762
|
-
const fieldNames = convertToArrayPayload(name);
|
1763
|
-
if (_options.resolver) {
|
1764
|
-
const errors = await executeSchemaAndUpdateState(isUndefined(name) ? name : fieldNames);
|
1765
|
-
isValid = isEmptyObject(errors);
|
1766
|
-
validationResult = name
|
1767
|
-
? !fieldNames.some((name) => get(errors, name))
|
1768
|
-
: isValid;
|
1769
|
-
}
|
1770
|
-
else if (name) {
|
1771
|
-
validationResult = (await Promise.all(fieldNames.map(async (fieldName) => {
|
1772
|
-
const field = get(_fields, fieldName);
|
1773
|
-
return await executeBuiltInValidation(field && field._f ? { [fieldName]: field } : field);
|
1774
|
-
}))).every(Boolean);
|
1775
|
-
!(!validationResult && !_formState.isValid) && _setValid();
|
1776
|
-
}
|
1777
|
-
else {
|
1778
|
-
validationResult = isValid = await executeBuiltInValidation(_fields);
|
1779
|
-
}
|
1780
|
-
_subjects.state.next({
|
1781
|
-
...(!isString(name) ||
|
1782
|
-
((_proxyFormState.isValid || _proxySubscribeFormState.isValid) &&
|
1783
|
-
isValid !== _formState.isValid)
|
1784
|
-
? {}
|
1785
|
-
: { name }),
|
1786
|
-
...(_options.resolver || !name ? { isValid } : {}),
|
1787
|
-
errors: _formState.errors,
|
1788
|
-
});
|
1789
|
-
options.shouldFocus &&
|
1790
|
-
!validationResult &&
|
1791
|
-
iterateFieldsByAction(_fields, _focusInput, name ? fieldNames : _names.mount);
|
1792
|
-
return validationResult;
|
1793
|
-
};
|
1794
|
-
const getValues = (fieldNames) => {
|
1795
|
-
const values = {
|
1796
|
-
...(_state.mount ? _formValues : _defaultValues),
|
1797
|
-
};
|
1798
|
-
return isUndefined(fieldNames)
|
1799
|
-
? values
|
1800
|
-
: isString(fieldNames)
|
1801
|
-
? get(values, fieldNames)
|
1802
|
-
: fieldNames.map((name) => get(values, name));
|
1803
|
-
};
|
1804
|
-
const getFieldState = (name, formState) => ({
|
1805
|
-
invalid: !!get((formState || _formState).errors, name),
|
1806
|
-
isDirty: !!get((formState || _formState).dirtyFields, name),
|
1807
|
-
error: get((formState || _formState).errors, name),
|
1808
|
-
isValidating: !!get(_formState.validatingFields, name),
|
1809
|
-
isTouched: !!get((formState || _formState).touchedFields, name),
|
1810
|
-
});
|
1811
|
-
const clearErrors = (name) => {
|
1812
|
-
name &&
|
1813
|
-
convertToArrayPayload(name).forEach((inputName) => unset(_formState.errors, inputName));
|
1814
|
-
_subjects.state.next({
|
1815
|
-
errors: name ? _formState.errors : {},
|
1816
|
-
});
|
1817
|
-
};
|
1818
|
-
const setError = (name, error, options) => {
|
1819
|
-
const ref = (get(_fields, name, { _f: {} })._f || {}).ref;
|
1820
|
-
const currentError = get(_formState.errors, name) || {};
|
1821
|
-
// Don't override existing error messages elsewhere in the object tree.
|
1822
|
-
const { ref: currentRef, message, type, ...restOfErrorTree } = currentError;
|
1823
|
-
set(_formState.errors, name, {
|
1824
|
-
...restOfErrorTree,
|
1825
|
-
...error,
|
1826
|
-
ref,
|
1827
|
-
});
|
1828
|
-
_subjects.state.next({
|
1829
|
-
name,
|
1830
|
-
errors: _formState.errors,
|
1831
|
-
isValid: false,
|
1832
|
-
});
|
1833
|
-
options && options.shouldFocus && ref && ref.focus && ref.focus();
|
1834
|
-
};
|
1835
|
-
const watch = (name, defaultValue) => isFunction(name)
|
1836
|
-
? _subjects.state.subscribe({
|
1837
|
-
next: (payload) => name(_getWatch(undefined, defaultValue), payload),
|
1838
|
-
})
|
1839
|
-
: _getWatch(name, defaultValue, true);
|
1840
|
-
const _subscribe = (props) => _subjects.state.subscribe({
|
1841
|
-
next: (formState) => {
|
1842
|
-
if (shouldSubscribeByName(props.name, formState.name, props.exact) &&
|
1843
|
-
shouldRenderFormState(formState, props.formState || _proxyFormState, _setFormState, props.reRenderRoot)) {
|
1844
|
-
props.callback({
|
1845
|
-
values: { ..._formValues },
|
1846
|
-
..._formState,
|
1847
|
-
...formState,
|
1848
|
-
});
|
1849
|
-
}
|
1850
|
-
},
|
1851
|
-
}).unsubscribe;
|
1852
|
-
const subscribe = (props) => {
|
1853
|
-
_state.mount = true;
|
1854
|
-
_proxySubscribeFormState = {
|
1855
|
-
..._proxySubscribeFormState,
|
1856
|
-
...props.formState,
|
1857
|
-
};
|
1858
|
-
return _subscribe({
|
1859
|
-
...props,
|
1860
|
-
formState: _proxySubscribeFormState,
|
1861
|
-
});
|
1862
|
-
};
|
1863
|
-
const unregister = (name, options = {}) => {
|
1864
|
-
for (const fieldName of name ? convertToArrayPayload(name) : _names.mount) {
|
1865
|
-
_names.mount.delete(fieldName);
|
1866
|
-
_names.array.delete(fieldName);
|
1867
|
-
if (!options.keepValue) {
|
1868
|
-
unset(_fields, fieldName);
|
1869
|
-
unset(_formValues, fieldName);
|
1870
|
-
}
|
1871
|
-
!options.keepError && unset(_formState.errors, fieldName);
|
1872
|
-
!options.keepDirty && unset(_formState.dirtyFields, fieldName);
|
1873
|
-
!options.keepTouched && unset(_formState.touchedFields, fieldName);
|
1874
|
-
!options.keepIsValidating &&
|
1875
|
-
unset(_formState.validatingFields, fieldName);
|
1876
|
-
!_options.shouldUnregister &&
|
1877
|
-
!options.keepDefaultValue &&
|
1878
|
-
unset(_defaultValues, fieldName);
|
1879
|
-
}
|
1880
|
-
_subjects.state.next({
|
1881
|
-
values: cloneObject(_formValues),
|
1882
|
-
});
|
1883
|
-
_subjects.state.next({
|
1884
|
-
..._formState,
|
1885
|
-
...(!options.keepDirty ? {} : { isDirty: _getDirty() }),
|
1886
|
-
});
|
1887
|
-
!options.keepIsValid && _setValid();
|
1888
|
-
};
|
1889
|
-
const _setDisabledField = ({ disabled, name, }) => {
|
1890
|
-
if ((isBoolean(disabled) && _state.mount) ||
|
1891
|
-
!!disabled ||
|
1892
|
-
_names.disabled.has(name)) {
|
1893
|
-
disabled ? _names.disabled.add(name) : _names.disabled.delete(name);
|
1894
|
-
}
|
1895
|
-
};
|
1896
|
-
const register = (name, options = {}) => {
|
1897
|
-
let field = get(_fields, name);
|
1898
|
-
const disabledIsDefined = isBoolean(options.disabled) || isBoolean(_options.disabled);
|
1899
|
-
set(_fields, name, {
|
1900
|
-
...(field || {}),
|
1901
|
-
_f: {
|
1902
|
-
...(field && field._f ? field._f : { ref: { name } }),
|
1903
|
-
name,
|
1904
|
-
mount: true,
|
1905
|
-
...options,
|
1906
|
-
},
|
1907
|
-
});
|
1908
|
-
_names.mount.add(name);
|
1909
|
-
if (field) {
|
1910
|
-
_setDisabledField({
|
1911
|
-
disabled: isBoolean(options.disabled)
|
1912
|
-
? options.disabled
|
1913
|
-
: _options.disabled,
|
1914
|
-
name,
|
1915
|
-
});
|
1916
|
-
}
|
1917
|
-
else {
|
1918
|
-
updateValidAndValue(name, true, options.value);
|
1919
|
-
}
|
1920
|
-
return {
|
1921
|
-
...(disabledIsDefined
|
1922
|
-
? { disabled: options.disabled || _options.disabled }
|
1923
|
-
: {}),
|
1924
|
-
...(_options.progressive
|
1925
|
-
? {
|
1926
|
-
required: !!options.required,
|
1927
|
-
min: getRuleValue(options.min),
|
1928
|
-
max: getRuleValue(options.max),
|
1929
|
-
minLength: getRuleValue(options.minLength),
|
1930
|
-
maxLength: getRuleValue(options.maxLength),
|
1931
|
-
pattern: getRuleValue(options.pattern),
|
1932
|
-
}
|
1933
|
-
: {}),
|
1934
|
-
name,
|
1935
|
-
onChange,
|
1936
|
-
onBlur: onChange,
|
1937
|
-
ref: (ref) => {
|
1938
|
-
if (ref) {
|
1939
|
-
register(name, options);
|
1940
|
-
field = get(_fields, name);
|
1941
|
-
const fieldRef = isUndefined(ref.value)
|
1942
|
-
? ref.querySelectorAll
|
1943
|
-
? ref.querySelectorAll('input,select,textarea')[0] || ref
|
1944
|
-
: ref
|
1945
|
-
: ref;
|
1946
|
-
const radioOrCheckbox = isRadioOrCheckbox(fieldRef);
|
1947
|
-
const refs = field._f.refs || [];
|
1948
|
-
if (radioOrCheckbox
|
1949
|
-
? refs.find((option) => option === fieldRef)
|
1950
|
-
: fieldRef === field._f.ref) {
|
1951
|
-
return;
|
1952
|
-
}
|
1953
|
-
set(_fields, name, {
|
1954
|
-
_f: {
|
1955
|
-
...field._f,
|
1956
|
-
...(radioOrCheckbox
|
1957
|
-
? {
|
1958
|
-
refs: [
|
1959
|
-
...refs.filter(live),
|
1960
|
-
fieldRef,
|
1961
|
-
...(Array.isArray(get(_defaultValues, name)) ? [{}] : []),
|
1962
|
-
],
|
1963
|
-
ref: { type: fieldRef.type, name },
|
1964
|
-
}
|
1965
|
-
: { ref: fieldRef }),
|
1966
|
-
},
|
1967
|
-
});
|
1968
|
-
updateValidAndValue(name, false, undefined, fieldRef);
|
1969
|
-
}
|
1970
|
-
else {
|
1971
|
-
field = get(_fields, name, {});
|
1972
|
-
if (field._f) {
|
1973
|
-
field._f.mount = false;
|
1974
|
-
}
|
1975
|
-
(_options.shouldUnregister || options.shouldUnregister) &&
|
1976
|
-
!(isNameInFieldArray(_names.array, name) && _state.action) &&
|
1977
|
-
_names.unMount.add(name);
|
1978
|
-
}
|
1979
|
-
},
|
1980
|
-
};
|
1981
|
-
};
|
1982
|
-
const _focusError = () => _options.shouldFocusError &&
|
1983
|
-
iterateFieldsByAction(_fields, _focusInput, _names.mount);
|
1984
|
-
const _disableForm = (disabled) => {
|
1985
|
-
if (isBoolean(disabled)) {
|
1986
|
-
_subjects.state.next({ disabled });
|
1987
|
-
iterateFieldsByAction(_fields, (ref, name) => {
|
1988
|
-
const currentField = get(_fields, name);
|
1989
|
-
if (currentField) {
|
1990
|
-
ref.disabled = currentField._f.disabled || disabled;
|
1991
|
-
if (Array.isArray(currentField._f.refs)) {
|
1992
|
-
currentField._f.refs.forEach((inputRef) => {
|
1993
|
-
inputRef.disabled = currentField._f.disabled || disabled;
|
1994
|
-
});
|
1995
|
-
}
|
1996
|
-
}
|
1997
|
-
}, 0, false);
|
1998
|
-
}
|
1999
|
-
};
|
2000
|
-
const handleSubmit = (onValid, onInvalid) => async (e) => {
|
2001
|
-
let onValidError = undefined;
|
2002
|
-
if (e) {
|
2003
|
-
e.preventDefault && e.preventDefault();
|
2004
|
-
e.persist &&
|
2005
|
-
e.persist();
|
2006
|
-
}
|
2007
|
-
let fieldValues = cloneObject(_formValues);
|
2008
|
-
_subjects.state.next({
|
2009
|
-
isSubmitting: true,
|
2010
|
-
});
|
2011
|
-
if (_options.resolver) {
|
2012
|
-
const { errors, values } = await _runSchema();
|
2013
|
-
_formState.errors = errors;
|
2014
|
-
fieldValues = values;
|
2015
|
-
}
|
2016
|
-
else {
|
2017
|
-
await executeBuiltInValidation(_fields);
|
2018
|
-
}
|
2019
|
-
if (_names.disabled.size) {
|
2020
|
-
for (const name of _names.disabled) {
|
2021
|
-
set(fieldValues, name, undefined);
|
2022
|
-
}
|
2023
|
-
}
|
2024
|
-
unset(_formState.errors, 'root');
|
2025
|
-
if (isEmptyObject(_formState.errors)) {
|
2026
|
-
_subjects.state.next({
|
2027
|
-
errors: {},
|
2028
|
-
});
|
2029
|
-
try {
|
2030
|
-
await onValid(fieldValues, e);
|
2031
|
-
}
|
2032
|
-
catch (error) {
|
2033
|
-
onValidError = error;
|
2034
|
-
}
|
2035
|
-
}
|
2036
|
-
else {
|
2037
|
-
if (onInvalid) {
|
2038
|
-
await onInvalid({ ..._formState.errors }, e);
|
2039
|
-
}
|
2040
|
-
_focusError();
|
2041
|
-
setTimeout(_focusError);
|
2042
|
-
}
|
2043
|
-
_subjects.state.next({
|
2044
|
-
isSubmitted: true,
|
2045
|
-
isSubmitting: false,
|
2046
|
-
isSubmitSuccessful: isEmptyObject(_formState.errors) && !onValidError,
|
2047
|
-
submitCount: _formState.submitCount + 1,
|
2048
|
-
errors: _formState.errors,
|
2049
|
-
});
|
2050
|
-
if (onValidError) {
|
2051
|
-
throw onValidError;
|
2052
|
-
}
|
2053
|
-
};
|
2054
|
-
const resetField = (name, options = {}) => {
|
2055
|
-
if (get(_fields, name)) {
|
2056
|
-
if (isUndefined(options.defaultValue)) {
|
2057
|
-
setValue(name, cloneObject(get(_defaultValues, name)));
|
2058
|
-
}
|
2059
|
-
else {
|
2060
|
-
setValue(name, options.defaultValue);
|
2061
|
-
set(_defaultValues, name, cloneObject(options.defaultValue));
|
2062
|
-
}
|
2063
|
-
if (!options.keepTouched) {
|
2064
|
-
unset(_formState.touchedFields, name);
|
2065
|
-
}
|
2066
|
-
if (!options.keepDirty) {
|
2067
|
-
unset(_formState.dirtyFields, name);
|
2068
|
-
_formState.isDirty = options.defaultValue
|
2069
|
-
? _getDirty(name, cloneObject(get(_defaultValues, name)))
|
2070
|
-
: _getDirty();
|
2071
|
-
}
|
2072
|
-
if (!options.keepError) {
|
2073
|
-
unset(_formState.errors, name);
|
2074
|
-
_proxyFormState.isValid && _setValid();
|
2075
|
-
}
|
2076
|
-
_subjects.state.next({ ..._formState });
|
2077
|
-
}
|
2078
|
-
};
|
2079
|
-
const _reset = (formValues, keepStateOptions = {}) => {
|
2080
|
-
const updatedValues = formValues ? cloneObject(formValues) : _defaultValues;
|
2081
|
-
const cloneUpdatedValues = cloneObject(updatedValues);
|
2082
|
-
const isEmptyResetValues = isEmptyObject(formValues);
|
2083
|
-
const values = isEmptyResetValues ? _defaultValues : cloneUpdatedValues;
|
2084
|
-
if (!keepStateOptions.keepDefaultValues) {
|
2085
|
-
_defaultValues = updatedValues;
|
2086
|
-
}
|
2087
|
-
if (!keepStateOptions.keepValues) {
|
2088
|
-
if (keepStateOptions.keepDirtyValues) {
|
2089
|
-
const fieldsToCheck = new Set([
|
2090
|
-
..._names.mount,
|
2091
|
-
...Object.keys(getDirtyFields(_defaultValues, _formValues)),
|
2092
|
-
]);
|
2093
|
-
for (const fieldName of Array.from(fieldsToCheck)) {
|
2094
|
-
get(_formState.dirtyFields, fieldName)
|
2095
|
-
? set(values, fieldName, get(_formValues, fieldName))
|
2096
|
-
: setValue(fieldName, get(values, fieldName));
|
2097
|
-
}
|
2098
|
-
}
|
2099
|
-
else {
|
2100
|
-
if (isWeb && isUndefined(formValues)) {
|
2101
|
-
for (const name of _names.mount) {
|
2102
|
-
const field = get(_fields, name);
|
2103
|
-
if (field && field._f) {
|
2104
|
-
const fieldReference = Array.isArray(field._f.refs)
|
2105
|
-
? field._f.refs[0]
|
2106
|
-
: field._f.ref;
|
2107
|
-
if (isHTMLElement(fieldReference)) {
|
2108
|
-
const form = fieldReference.closest('form');
|
2109
|
-
if (form) {
|
2110
|
-
form.reset();
|
2111
|
-
break;
|
2112
|
-
}
|
2113
|
-
}
|
2114
|
-
}
|
2115
|
-
}
|
2116
|
-
}
|
2117
|
-
for (const fieldName of _names.mount) {
|
2118
|
-
setValue(fieldName, get(values, fieldName));
|
2119
|
-
}
|
2120
|
-
}
|
2121
|
-
_formValues = cloneObject(values);
|
2122
|
-
_subjects.array.next({
|
2123
|
-
values: { ...values },
|
2124
|
-
});
|
2125
|
-
_subjects.state.next({
|
2126
|
-
values: { ...values },
|
2127
|
-
});
|
2128
|
-
}
|
2129
|
-
_names = {
|
2130
|
-
mount: keepStateOptions.keepDirtyValues ? _names.mount : new Set(),
|
2131
|
-
unMount: new Set(),
|
2132
|
-
array: new Set(),
|
2133
|
-
disabled: new Set(),
|
2134
|
-
watch: new Set(),
|
2135
|
-
watchAll: false,
|
2136
|
-
focus: '',
|
2137
|
-
};
|
2138
|
-
_state.mount =
|
2139
|
-
!_proxyFormState.isValid ||
|
2140
|
-
!!keepStateOptions.keepIsValid ||
|
2141
|
-
!!keepStateOptions.keepDirtyValues;
|
2142
|
-
_state.watch = !!_options.shouldUnregister;
|
2143
|
-
_subjects.state.next({
|
2144
|
-
submitCount: keepStateOptions.keepSubmitCount
|
2145
|
-
? _formState.submitCount
|
2146
|
-
: 0,
|
2147
|
-
isDirty: isEmptyResetValues
|
2148
|
-
? false
|
2149
|
-
: keepStateOptions.keepDirty
|
2150
|
-
? _formState.isDirty
|
2151
|
-
: !!(keepStateOptions.keepDefaultValues &&
|
2152
|
-
!deepEqual(formValues, _defaultValues)),
|
2153
|
-
isSubmitted: keepStateOptions.keepIsSubmitted
|
2154
|
-
? _formState.isSubmitted
|
2155
|
-
: false,
|
2156
|
-
dirtyFields: isEmptyResetValues
|
2157
|
-
? {}
|
2158
|
-
: keepStateOptions.keepDirtyValues
|
2159
|
-
? keepStateOptions.keepDefaultValues && _formValues
|
2160
|
-
? getDirtyFields(_defaultValues, _formValues)
|
2161
|
-
: _formState.dirtyFields
|
2162
|
-
: keepStateOptions.keepDefaultValues && formValues
|
2163
|
-
? getDirtyFields(_defaultValues, formValues)
|
2164
|
-
: keepStateOptions.keepDirty
|
2165
|
-
? _formState.dirtyFields
|
2166
|
-
: {},
|
2167
|
-
touchedFields: keepStateOptions.keepTouched
|
2168
|
-
? _formState.touchedFields
|
2169
|
-
: {},
|
2170
|
-
errors: keepStateOptions.keepErrors ? _formState.errors : {},
|
2171
|
-
isSubmitSuccessful: keepStateOptions.keepIsSubmitSuccessful
|
2172
|
-
? _formState.isSubmitSuccessful
|
2173
|
-
: false,
|
2174
|
-
isSubmitting: false,
|
2175
|
-
});
|
2176
|
-
};
|
2177
|
-
const reset = (formValues, keepStateOptions) => _reset(isFunction(formValues)
|
2178
|
-
? formValues(_formValues)
|
2179
|
-
: formValues, keepStateOptions);
|
2180
|
-
const setFocus = (name, options = {}) => {
|
2181
|
-
const field = get(_fields, name);
|
2182
|
-
const fieldReference = field && field._f;
|
2183
|
-
if (fieldReference) {
|
2184
|
-
const fieldRef = fieldReference.refs
|
2185
|
-
? fieldReference.refs[0]
|
2186
|
-
: fieldReference.ref;
|
2187
|
-
if (fieldRef.focus) {
|
2188
|
-
fieldRef.focus();
|
2189
|
-
options.shouldSelect &&
|
2190
|
-
isFunction(fieldRef.select) &&
|
2191
|
-
fieldRef.select();
|
2192
|
-
}
|
2193
|
-
}
|
2194
|
-
};
|
2195
|
-
const _setFormState = (updatedFormState) => {
|
2196
|
-
_formState = {
|
2197
|
-
..._formState,
|
2198
|
-
...updatedFormState,
|
2199
|
-
};
|
2200
|
-
};
|
2201
|
-
const _resetDefaultValues = () => isFunction(_options.defaultValues) &&
|
2202
|
-
_options.defaultValues().then((values) => {
|
2203
|
-
reset(values, _options.resetOptions);
|
2204
|
-
_subjects.state.next({
|
2205
|
-
isLoading: false,
|
2206
|
-
});
|
2207
|
-
});
|
2208
|
-
const methods = {
|
2209
|
-
control: {
|
2210
|
-
register,
|
2211
|
-
unregister,
|
2212
|
-
getFieldState,
|
2213
|
-
handleSubmit,
|
2214
|
-
setError,
|
2215
|
-
_subscribe,
|
2216
|
-
_runSchema,
|
2217
|
-
_getWatch,
|
2218
|
-
_getDirty,
|
2219
|
-
_setValid,
|
2220
|
-
_setFieldArray,
|
2221
|
-
_setDisabledField,
|
2222
|
-
_setErrors,
|
2223
|
-
_getFieldArray,
|
2224
|
-
_reset,
|
2225
|
-
_resetDefaultValues,
|
2226
|
-
_removeUnmounted,
|
2227
|
-
_disableForm,
|
2228
|
-
_subjects,
|
2229
|
-
_proxyFormState,
|
2230
|
-
get _fields() {
|
2231
|
-
return _fields;
|
2232
|
-
},
|
2233
|
-
get _formValues() {
|
2234
|
-
return _formValues;
|
2235
|
-
},
|
2236
|
-
get _state() {
|
2237
|
-
return _state;
|
2238
|
-
},
|
2239
|
-
set _state(value) {
|
2240
|
-
_state = value;
|
2241
|
-
},
|
2242
|
-
get _defaultValues() {
|
2243
|
-
return _defaultValues;
|
2244
|
-
},
|
2245
|
-
get _names() {
|
2246
|
-
return _names;
|
2247
|
-
},
|
2248
|
-
set _names(value) {
|
2249
|
-
_names = value;
|
2250
|
-
},
|
2251
|
-
get _formState() {
|
2252
|
-
return _formState;
|
2253
|
-
},
|
2254
|
-
get _options() {
|
2255
|
-
return _options;
|
2256
|
-
},
|
2257
|
-
set _options(value) {
|
2258
|
-
_options = {
|
2259
|
-
..._options,
|
2260
|
-
...value,
|
2261
|
-
};
|
2262
|
-
},
|
2263
|
-
},
|
2264
|
-
subscribe,
|
2265
|
-
trigger,
|
2266
|
-
register,
|
2267
|
-
handleSubmit,
|
2268
|
-
watch,
|
2269
|
-
setValue,
|
2270
|
-
getValues,
|
2271
|
-
reset,
|
2272
|
-
resetField,
|
2273
|
-
clearErrors,
|
2274
|
-
unregister,
|
2275
|
-
setError,
|
2276
|
-
setFocus,
|
2277
|
-
getFieldState,
|
2278
|
-
};
|
2279
|
-
return {
|
2280
|
-
...methods,
|
2281
|
-
formControl: methods,
|
2282
|
-
};
|
2283
|
-
}
|
2284
|
-
|
2285
|
-
var generateId = () => {
|
2286
|
-
const d = typeof performance === 'undefined' ? Date.now() : performance.now() * 1000;
|
2287
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
2288
|
-
const r = (Math.random() * 16 + d) % 16 | 0;
|
2289
|
-
return (c == 'x' ? r : (r & 0x3) | 0x8).toString(16);
|
2290
|
-
});
|
2291
|
-
};
|
2292
|
-
|
2293
|
-
var getFocusFieldName = (name, index, options = {}) => options.shouldFocus || isUndefined(options.shouldFocus)
|
2294
|
-
? options.focusName ||
|
2295
|
-
`${name}.${isUndefined(options.focusIndex) ? index : options.focusIndex}.`
|
2296
|
-
: '';
|
2297
|
-
|
2298
|
-
var appendAt = (data, value) => [
|
2299
|
-
...data,
|
2300
|
-
...convertToArrayPayload(value),
|
2301
|
-
];
|
2302
|
-
|
2303
|
-
var fillEmptyArray = (value) => Array.isArray(value) ? value.map(() => undefined) : undefined;
|
2304
|
-
|
2305
|
-
function insert(data, index, value) {
|
2306
|
-
return [
|
2307
|
-
...data.slice(0, index),
|
2308
|
-
...convertToArrayPayload(value),
|
2309
|
-
...data.slice(index),
|
2310
|
-
];
|
2311
|
-
}
|
2312
|
-
|
2313
|
-
var moveArrayAt = (data, from, to) => {
|
2314
|
-
if (!Array.isArray(data)) {
|
2315
|
-
return [];
|
2316
|
-
}
|
2317
|
-
if (isUndefined(data[to])) {
|
2318
|
-
data[to] = undefined;
|
2319
|
-
}
|
2320
|
-
data.splice(to, 0, data.splice(from, 1)[0]);
|
2321
|
-
return data;
|
2322
|
-
};
|
2323
|
-
|
2324
|
-
var prependAt = (data, value) => [
|
2325
|
-
...convertToArrayPayload(value),
|
2326
|
-
...convertToArrayPayload(data),
|
2327
|
-
];
|
2328
|
-
|
2329
|
-
function removeAtIndexes(data, indexes) {
|
2330
|
-
let i = 0;
|
2331
|
-
const temp = [...data];
|
2332
|
-
for (const index of indexes) {
|
2333
|
-
temp.splice(index - i, 1);
|
2334
|
-
i++;
|
2335
|
-
}
|
2336
|
-
return compact(temp).length ? temp : [];
|
2337
|
-
}
|
2338
|
-
var removeArrayAt = (data, index) => isUndefined(index)
|
2339
|
-
? []
|
2340
|
-
: removeAtIndexes(data, convertToArrayPayload(index).sort((a, b) => a - b));
|
2341
|
-
|
2342
|
-
var swapArrayAt = (data, indexA, indexB) => {
|
2343
|
-
[data[indexA], data[indexB]] = [data[indexB], data[indexA]];
|
2344
|
-
};
|
2345
|
-
|
2346
|
-
var updateAt = (fieldValues, index, value) => {
|
2347
|
-
fieldValues[index] = value;
|
2348
|
-
return fieldValues;
|
2349
|
-
};
|
2350
|
-
|
2351
|
-
/**
|
2352
|
-
* A custom hook that exposes convenient methods to perform operations with a list of dynamic inputs that need to be appended, updated, removed etc. • [Demo](https://codesandbox.io/s/react-hook-form-usefieldarray-ssugn) • [Video](https://youtu.be/4MrbfGSFY2A)
|
2353
|
-
*
|
2354
|
-
* @remarks
|
2355
|
-
* [API](https://react-hook-form.com/docs/usefieldarray) • [Demo](https://codesandbox.io/s/react-hook-form-usefieldarray-ssugn)
|
2356
|
-
*
|
2357
|
-
* @param props - useFieldArray props
|
2358
|
-
*
|
2359
|
-
* @returns methods - functions to manipulate with the Field Arrays (dynamic inputs) {@link UseFieldArrayReturn}
|
2360
|
-
*
|
2361
|
-
* @example
|
2362
|
-
* ```tsx
|
2363
|
-
* function App() {
|
2364
|
-
* const { register, control, handleSubmit, reset, trigger, setError } = useForm({
|
2365
|
-
* defaultValues: {
|
2366
|
-
* test: []
|
2367
|
-
* }
|
2368
|
-
* });
|
2369
|
-
* const { fields, append } = useFieldArray({
|
2370
|
-
* control,
|
2371
|
-
* name: "test"
|
2372
|
-
* });
|
2373
|
-
*
|
2374
|
-
* return (
|
2375
|
-
* <form onSubmit={handleSubmit(data => console.log(data))}>
|
2376
|
-
* {fields.map((item, index) => (
|
2377
|
-
* <input key={item.id} {...register(`test.${index}.firstName`)} />
|
2378
|
-
* ))}
|
2379
|
-
* <button type="button" onClick={() => append({ firstName: "bill" })}>
|
2380
|
-
* append
|
2381
|
-
* </button>
|
2382
|
-
* <input type="submit" />
|
2383
|
-
* </form>
|
2384
|
-
* );
|
2385
|
-
* }
|
2386
|
-
* ```
|
2387
|
-
*/
|
2388
|
-
function useFieldArray(props) {
|
2389
|
-
const methods = useFormContext();
|
2390
|
-
const { control = methods.control, name, keyName = 'id', shouldUnregister, rules, } = props;
|
2391
|
-
const [fields, setFields] = React__default.useState(control._getFieldArray(name));
|
2392
|
-
const ids = React__default.useRef(control._getFieldArray(name).map(generateId));
|
2393
|
-
const _fieldIds = React__default.useRef(fields);
|
2394
|
-
const _name = React__default.useRef(name);
|
2395
|
-
const _actioned = React__default.useRef(false);
|
2396
|
-
_name.current = name;
|
2397
|
-
_fieldIds.current = fields;
|
2398
|
-
control._names.array.add(name);
|
2399
|
-
rules &&
|
2400
|
-
control.register(name, rules);
|
2401
|
-
React__default.useEffect(() => control._subjects.array.subscribe({
|
2402
|
-
next: ({ values, name: fieldArrayName, }) => {
|
2403
|
-
if (fieldArrayName === _name.current || !fieldArrayName) {
|
2404
|
-
const fieldValues = get(values, _name.current);
|
2405
|
-
if (Array.isArray(fieldValues)) {
|
2406
|
-
setFields(fieldValues);
|
2407
|
-
ids.current = fieldValues.map(generateId);
|
1870
|
+
const _getFieldArray = (name) => compact(get(_state.mount ? _formValues : _defaultValues, name, _options.shouldUnregister ? get(_defaultValues, name, []) : []));
|
1871
|
+
const setFieldValue = (name, value, options = {}) => {
|
1872
|
+
const field = get(_fields, name);
|
1873
|
+
let fieldValue = value;
|
1874
|
+
if (field) {
|
1875
|
+
const fieldReference = field._f;
|
1876
|
+
if (fieldReference) {
|
1877
|
+
!fieldReference.disabled &&
|
1878
|
+
set(_formValues, name, getFieldValueAs(value, fieldReference));
|
1879
|
+
fieldValue =
|
1880
|
+
isHTMLElement(fieldReference.ref) && isNullOrUndefined(value)
|
1881
|
+
? ''
|
1882
|
+
: value;
|
1883
|
+
if (isMultipleSelect(fieldReference.ref)) {
|
1884
|
+
[...fieldReference.ref.options].forEach((optionRef) => (optionRef.selected = fieldValue.includes(optionRef.value)));
|
1885
|
+
}
|
1886
|
+
else if (fieldReference.refs) {
|
1887
|
+
if (isCheckBoxInput(fieldReference.ref)) {
|
1888
|
+
fieldReference.refs.length > 1
|
1889
|
+
? fieldReference.refs.forEach((checkboxRef) => (!checkboxRef.defaultChecked || !checkboxRef.disabled) &&
|
1890
|
+
(checkboxRef.checked = Array.isArray(fieldValue)
|
1891
|
+
? !!fieldValue.find((data) => data === checkboxRef.value)
|
1892
|
+
: fieldValue === checkboxRef.value))
|
1893
|
+
: fieldReference.refs[0] &&
|
1894
|
+
(fieldReference.refs[0].checked = !!fieldValue);
|
1895
|
+
}
|
1896
|
+
else {
|
1897
|
+
fieldReference.refs.forEach((radioRef) => (radioRef.checked = radioRef.value === fieldValue));
|
1898
|
+
}
|
1899
|
+
}
|
1900
|
+
else if (isFileInput(fieldReference.ref)) {
|
1901
|
+
fieldReference.ref.value = '';
|
1902
|
+
}
|
1903
|
+
else {
|
1904
|
+
fieldReference.ref.value = fieldValue;
|
1905
|
+
if (!fieldReference.ref.type) {
|
1906
|
+
_subjects.values.next({
|
1907
|
+
name,
|
1908
|
+
values: { ..._formValues },
|
1909
|
+
});
|
1910
|
+
}
|
2408
1911
|
}
|
2409
1912
|
}
|
2410
|
-
}
|
2411
|
-
|
2412
|
-
|
2413
|
-
|
2414
|
-
|
2415
|
-
|
2416
|
-
|
2417
|
-
|
2418
|
-
|
2419
|
-
|
2420
|
-
|
2421
|
-
|
2422
|
-
|
2423
|
-
|
2424
|
-
|
1913
|
+
}
|
1914
|
+
(options.shouldDirty || options.shouldTouch) &&
|
1915
|
+
updateTouchAndDirty(name, fieldValue, options.shouldTouch, options.shouldDirty, true);
|
1916
|
+
options.shouldValidate && trigger(name);
|
1917
|
+
};
|
1918
|
+
const setValues = (name, value, options) => {
|
1919
|
+
for (const fieldKey in value) {
|
1920
|
+
const fieldValue = value[fieldKey];
|
1921
|
+
const fieldName = `${name}.${fieldKey}`;
|
1922
|
+
const field = get(_fields, fieldName);
|
1923
|
+
(_names.array.has(name) ||
|
1924
|
+
isObject(fieldValue) ||
|
1925
|
+
(field && !field._f)) &&
|
1926
|
+
!isDateObject(fieldValue)
|
1927
|
+
? setValues(fieldName, fieldValue, options)
|
1928
|
+
: setFieldValue(fieldName, fieldValue, options);
|
1929
|
+
}
|
1930
|
+
};
|
1931
|
+
const setValue = (name, value, options = {}) => {
|
1932
|
+
const field = get(_fields, name);
|
1933
|
+
const isFieldArray = _names.array.has(name);
|
1934
|
+
const cloneValue = cloneObject(value);
|
1935
|
+
set(_formValues, name, cloneValue);
|
1936
|
+
if (isFieldArray) {
|
1937
|
+
_subjects.array.next({
|
1938
|
+
name,
|
1939
|
+
values: { ..._formValues },
|
1940
|
+
});
|
1941
|
+
if ((_proxyFormState.isDirty || _proxyFormState.dirtyFields) &&
|
1942
|
+
options.shouldDirty) {
|
1943
|
+
_subjects.state.next({
|
1944
|
+
name,
|
1945
|
+
dirtyFields: getDirtyFields(_defaultValues, _formValues),
|
1946
|
+
isDirty: _getDirty(name, cloneValue),
|
1947
|
+
});
|
1948
|
+
}
|
1949
|
+
}
|
1950
|
+
else {
|
1951
|
+
field && !field._f && !isNullOrUndefined(cloneValue)
|
1952
|
+
? setValues(name, cloneValue, options)
|
1953
|
+
: setFieldValue(name, cloneValue, options);
|
1954
|
+
}
|
1955
|
+
isWatched(name, _names) && _subjects.state.next({ ..._formState });
|
1956
|
+
_subjects.values.next({
|
1957
|
+
name: _state.mount ? name : undefined,
|
1958
|
+
values: { ..._formValues },
|
2425
1959
|
});
|
2426
1960
|
};
|
2427
|
-
const
|
2428
|
-
|
2429
|
-
const
|
2430
|
-
|
2431
|
-
|
2432
|
-
|
2433
|
-
|
2434
|
-
|
2435
|
-
|
1961
|
+
const onChange = async (event) => {
|
1962
|
+
_state.mount = true;
|
1963
|
+
const target = event.target;
|
1964
|
+
let name = target.name;
|
1965
|
+
let isFieldValueUpdated = true;
|
1966
|
+
const field = get(_fields, name);
|
1967
|
+
const getCurrentFieldValue = () => target.type ? getFieldValue(field._f) : getEventValue(event);
|
1968
|
+
const _updateIsFieldValueUpdated = (fieldValue) => {
|
1969
|
+
isFieldValueUpdated =
|
1970
|
+
Number.isNaN(fieldValue) ||
|
1971
|
+
(isDateObject(fieldValue) && isNaN(fieldValue.getTime())) ||
|
1972
|
+
deepEqual(fieldValue, get(_formValues, name, fieldValue));
|
1973
|
+
};
|
1974
|
+
if (field) {
|
1975
|
+
let error;
|
1976
|
+
let isValid;
|
1977
|
+
const fieldValue = getCurrentFieldValue();
|
1978
|
+
const isBlurEvent = event.type === EVENTS.BLUR || event.type === EVENTS.FOCUS_OUT;
|
1979
|
+
const shouldSkipValidation = (!hasValidation(field._f) &&
|
1980
|
+
!_options.resolver &&
|
1981
|
+
!get(_formState.errors, name) &&
|
1982
|
+
!field._f.deps) ||
|
1983
|
+
skipValidation(isBlurEvent, get(_formState.touchedFields, name), _formState.isSubmitted, validationModeAfterSubmit, validationModeBeforeSubmit);
|
1984
|
+
const watched = isWatched(name, _names, isBlurEvent);
|
1985
|
+
set(_formValues, name, fieldValue);
|
1986
|
+
if (isBlurEvent) {
|
1987
|
+
field._f.onBlur && field._f.onBlur(event);
|
1988
|
+
delayErrorCallback && delayErrorCallback(0);
|
1989
|
+
}
|
1990
|
+
else if (field._f.onChange) {
|
1991
|
+
field._f.onChange(event);
|
1992
|
+
}
|
1993
|
+
const fieldState = updateTouchAndDirty(name, fieldValue, isBlurEvent, false);
|
1994
|
+
const shouldRender = !isEmptyObject(fieldState) || watched;
|
1995
|
+
!isBlurEvent &&
|
1996
|
+
_subjects.values.next({
|
1997
|
+
name,
|
1998
|
+
type: event.type,
|
1999
|
+
values: { ..._formValues },
|
2000
|
+
});
|
2001
|
+
if (shouldSkipValidation) {
|
2002
|
+
if (_proxyFormState.isValid) {
|
2003
|
+
if (_options.mode === 'onBlur' && isBlurEvent) {
|
2004
|
+
_updateValid();
|
2005
|
+
}
|
2006
|
+
else if (!isBlurEvent) {
|
2007
|
+
_updateValid();
|
2008
|
+
}
|
2009
|
+
}
|
2010
|
+
return (shouldRender &&
|
2011
|
+
_subjects.state.next({ name, ...(watched ? {} : fieldState) }));
|
2012
|
+
}
|
2013
|
+
!isBlurEvent && watched && _subjects.state.next({ ..._formState });
|
2014
|
+
if (_options.resolver) {
|
2015
|
+
const { errors } = await _executeSchema([name]);
|
2016
|
+
_updateIsFieldValueUpdated(fieldValue);
|
2017
|
+
if (isFieldValueUpdated) {
|
2018
|
+
const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
|
2019
|
+
const errorLookupResult = schemaErrorLookup(errors, _fields, previousErrorLookupResult.name || name);
|
2020
|
+
error = errorLookupResult.error;
|
2021
|
+
name = errorLookupResult.name;
|
2022
|
+
isValid = isEmptyObject(errors);
|
2023
|
+
}
|
2024
|
+
}
|
2025
|
+
else {
|
2026
|
+
_updateIsValidating([name], true);
|
2027
|
+
error = (await validateField(field, _names.disabled, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
|
2028
|
+
_updateIsValidating([name]);
|
2029
|
+
_updateIsFieldValueUpdated(fieldValue);
|
2030
|
+
if (isFieldValueUpdated) {
|
2031
|
+
if (error) {
|
2032
|
+
isValid = false;
|
2033
|
+
}
|
2034
|
+
else if (_proxyFormState.isValid) {
|
2035
|
+
isValid = await executeBuiltInValidation(_fields, true);
|
2036
|
+
}
|
2037
|
+
}
|
2038
|
+
}
|
2039
|
+
if (isFieldValueUpdated) {
|
2040
|
+
field._f.deps &&
|
2041
|
+
trigger(field._f.deps);
|
2042
|
+
shouldRenderByError(name, isValid, error, fieldState);
|
2043
|
+
}
|
2044
|
+
}
|
2045
|
+
};
|
2046
|
+
const _focusInput = (ref, key) => {
|
2047
|
+
if (get(_formState.errors, key) && ref.focus) {
|
2048
|
+
ref.focus();
|
2049
|
+
return 1;
|
2050
|
+
}
|
2051
|
+
return;
|
2052
|
+
};
|
2053
|
+
const trigger = async (name, options = {}) => {
|
2054
|
+
let isValid;
|
2055
|
+
let validationResult;
|
2056
|
+
const fieldNames = convertToArrayPayload(name);
|
2057
|
+
if (_options.resolver) {
|
2058
|
+
const errors = await executeSchemaAndUpdateState(isUndefined(name) ? name : fieldNames);
|
2059
|
+
isValid = isEmptyObject(errors);
|
2060
|
+
validationResult = name
|
2061
|
+
? !fieldNames.some((name) => get(errors, name))
|
2062
|
+
: isValid;
|
2063
|
+
}
|
2064
|
+
else if (name) {
|
2065
|
+
validationResult = (await Promise.all(fieldNames.map(async (fieldName) => {
|
2066
|
+
const field = get(_fields, fieldName);
|
2067
|
+
return await executeBuiltInValidation(field && field._f ? { [fieldName]: field } : field);
|
2068
|
+
}))).every(Boolean);
|
2069
|
+
!(!validationResult && !_formState.isValid) && _updateValid();
|
2070
|
+
}
|
2071
|
+
else {
|
2072
|
+
validationResult = isValid = await executeBuiltInValidation(_fields);
|
2073
|
+
}
|
2074
|
+
_subjects.state.next({
|
2075
|
+
...(!isString(name) ||
|
2076
|
+
(_proxyFormState.isValid && isValid !== _formState.isValid)
|
2077
|
+
? {}
|
2078
|
+
: { name }),
|
2079
|
+
...(_options.resolver || !name ? { isValid } : {}),
|
2080
|
+
errors: _formState.errors,
|
2436
2081
|
});
|
2082
|
+
options.shouldFocus &&
|
2083
|
+
!validationResult &&
|
2084
|
+
iterateFieldsByAction(_fields, _focusInput, name ? fieldNames : _names.mount);
|
2085
|
+
return validationResult;
|
2437
2086
|
};
|
2438
|
-
const
|
2439
|
-
const
|
2440
|
-
|
2441
|
-
|
2442
|
-
|
2443
|
-
|
2444
|
-
|
2445
|
-
|
2446
|
-
|
2087
|
+
const getValues = (fieldNames) => {
|
2088
|
+
const values = {
|
2089
|
+
...(_state.mount ? _formValues : _defaultValues),
|
2090
|
+
};
|
2091
|
+
return isUndefined(fieldNames)
|
2092
|
+
? values
|
2093
|
+
: isString(fieldNames)
|
2094
|
+
? get(values, fieldNames)
|
2095
|
+
: fieldNames.map((name) => get(values, name));
|
2096
|
+
};
|
2097
|
+
const getFieldState = (name, formState) => ({
|
2098
|
+
invalid: !!get((formState || _formState).errors, name),
|
2099
|
+
isDirty: !!get((formState || _formState).dirtyFields, name),
|
2100
|
+
error: get((formState || _formState).errors, name),
|
2101
|
+
isValidating: !!get(_formState.validatingFields, name),
|
2102
|
+
isTouched: !!get((formState || _formState).touchedFields, name),
|
2103
|
+
});
|
2104
|
+
const clearErrors = (name) => {
|
2105
|
+
name &&
|
2106
|
+
convertToArrayPayload(name).forEach((inputName) => unset(_formState.errors, inputName));
|
2107
|
+
_subjects.state.next({
|
2108
|
+
errors: name ? _formState.errors : {},
|
2447
2109
|
});
|
2448
2110
|
};
|
2449
|
-
const
|
2450
|
-
const
|
2451
|
-
const
|
2452
|
-
|
2453
|
-
|
2454
|
-
|
2455
|
-
|
2456
|
-
|
2457
|
-
|
2458
|
-
|
2111
|
+
const setError = (name, error, options) => {
|
2112
|
+
const ref = (get(_fields, name, { _f: {} })._f || {}).ref;
|
2113
|
+
const currentError = get(_formState.errors, name) || {};
|
2114
|
+
// Don't override existing error messages elsewhere in the object tree.
|
2115
|
+
const { ref: currentRef, message, type, ...restOfErrorTree } = currentError;
|
2116
|
+
set(_formState.errors, name, {
|
2117
|
+
...restOfErrorTree,
|
2118
|
+
...error,
|
2119
|
+
ref,
|
2120
|
+
});
|
2121
|
+
_subjects.state.next({
|
2122
|
+
name,
|
2123
|
+
errors: _formState.errors,
|
2124
|
+
isValid: false,
|
2459
2125
|
});
|
2126
|
+
options && options.shouldFocus && ref && ref.focus && ref.focus();
|
2460
2127
|
};
|
2461
|
-
const
|
2462
|
-
|
2463
|
-
|
2464
|
-
|
2465
|
-
|
2466
|
-
|
2467
|
-
|
2468
|
-
|
2469
|
-
|
2470
|
-
|
2471
|
-
|
2472
|
-
|
2473
|
-
|
2474
|
-
|
2475
|
-
|
2476
|
-
|
2477
|
-
|
2478
|
-
|
2479
|
-
|
2480
|
-
|
2481
|
-
|
2482
|
-
|
2483
|
-
|
2484
|
-
|
2485
|
-
|
2486
|
-
|
2487
|
-
|
2488
|
-
|
2489
|
-
|
2490
|
-
|
2491
|
-
argB: updateValue,
|
2492
|
-
}, true, false);
|
2128
|
+
const watch = (name, defaultValue) => isFunction(name)
|
2129
|
+
? _subjects.values.subscribe({
|
2130
|
+
next: (payload) => name(_getWatch(undefined, defaultValue), payload),
|
2131
|
+
})
|
2132
|
+
: _getWatch(name, defaultValue, true);
|
2133
|
+
const unregister = (name, options = {}) => {
|
2134
|
+
for (const fieldName of name ? convertToArrayPayload(name) : _names.mount) {
|
2135
|
+
_names.mount.delete(fieldName);
|
2136
|
+
_names.array.delete(fieldName);
|
2137
|
+
if (!options.keepValue) {
|
2138
|
+
unset(_fields, fieldName);
|
2139
|
+
unset(_formValues, fieldName);
|
2140
|
+
}
|
2141
|
+
!options.keepError && unset(_formState.errors, fieldName);
|
2142
|
+
!options.keepDirty && unset(_formState.dirtyFields, fieldName);
|
2143
|
+
!options.keepTouched && unset(_formState.touchedFields, fieldName);
|
2144
|
+
!options.keepIsValidating &&
|
2145
|
+
unset(_formState.validatingFields, fieldName);
|
2146
|
+
!_options.shouldUnregister &&
|
2147
|
+
!options.keepDefaultValue &&
|
2148
|
+
unset(_defaultValues, fieldName);
|
2149
|
+
}
|
2150
|
+
_subjects.values.next({
|
2151
|
+
values: { ..._formValues },
|
2152
|
+
});
|
2153
|
+
_subjects.state.next({
|
2154
|
+
..._formState,
|
2155
|
+
...(!options.keepDirty ? {} : { isDirty: _getDirty() }),
|
2156
|
+
});
|
2157
|
+
!options.keepIsValid && _updateValid();
|
2493
2158
|
};
|
2494
|
-
const
|
2495
|
-
|
2496
|
-
|
2497
|
-
|
2498
|
-
|
2499
|
-
|
2159
|
+
const _updateDisabledField = ({ disabled, name, field, fields, }) => {
|
2160
|
+
if ((isBoolean(disabled) && _state.mount) ||
|
2161
|
+
!!disabled ||
|
2162
|
+
_names.disabled.has(name)) {
|
2163
|
+
disabled ? _names.disabled.add(name) : _names.disabled.delete(name);
|
2164
|
+
updateTouchAndDirty(name, getFieldValue(field ? field._f : get(fields, name)._f), false, false, true);
|
2165
|
+
}
|
2500
2166
|
};
|
2501
|
-
|
2502
|
-
|
2503
|
-
|
2504
|
-
|
2505
|
-
|
2167
|
+
const register = (name, options = {}) => {
|
2168
|
+
let field = get(_fields, name);
|
2169
|
+
const disabledIsDefined = isBoolean(options.disabled) || isBoolean(_options.disabled);
|
2170
|
+
set(_fields, name, {
|
2171
|
+
...(field || {}),
|
2172
|
+
_f: {
|
2173
|
+
...(field && field._f ? field._f : { ref: { name } }),
|
2174
|
+
name,
|
2175
|
+
mount: true,
|
2176
|
+
...options,
|
2177
|
+
},
|
2178
|
+
});
|
2179
|
+
_names.mount.add(name);
|
2180
|
+
if (field) {
|
2181
|
+
_updateDisabledField({
|
2182
|
+
field,
|
2183
|
+
disabled: isBoolean(options.disabled)
|
2184
|
+
? options.disabled
|
2185
|
+
: _options.disabled,
|
2186
|
+
name,
|
2506
2187
|
});
|
2507
|
-
|
2508
|
-
|
2509
|
-
|
2510
|
-
|
2511
|
-
|
2512
|
-
|
2513
|
-
|
2514
|
-
|
2515
|
-
|
2516
|
-
|
2517
|
-
|
2518
|
-
|
2519
|
-
|
2520
|
-
|
2521
|
-
|
2522
|
-
|
2523
|
-
|
2524
|
-
|
2525
|
-
|
2188
|
+
}
|
2189
|
+
else {
|
2190
|
+
updateValidAndValue(name, true, options.value);
|
2191
|
+
}
|
2192
|
+
return {
|
2193
|
+
...(disabledIsDefined
|
2194
|
+
? { disabled: options.disabled || _options.disabled }
|
2195
|
+
: {}),
|
2196
|
+
...(_options.progressive
|
2197
|
+
? {
|
2198
|
+
required: !!options.required,
|
2199
|
+
min: getRuleValue(options.min),
|
2200
|
+
max: getRuleValue(options.max),
|
2201
|
+
minLength: getRuleValue(options.minLength),
|
2202
|
+
maxLength: getRuleValue(options.maxLength),
|
2203
|
+
pattern: getRuleValue(options.pattern),
|
2204
|
+
}
|
2205
|
+
: {}),
|
2206
|
+
name,
|
2207
|
+
onChange,
|
2208
|
+
onBlur: onChange,
|
2209
|
+
ref: (ref) => {
|
2210
|
+
if (ref) {
|
2211
|
+
register(name, options);
|
2212
|
+
field = get(_fields, name);
|
2213
|
+
const fieldRef = isUndefined(ref.value)
|
2214
|
+
? ref.querySelectorAll
|
2215
|
+
? ref.querySelectorAll('input,select,textarea')[0] || ref
|
2216
|
+
: ref
|
2217
|
+
: ref;
|
2218
|
+
const radioOrCheckbox = isRadioOrCheckbox(fieldRef);
|
2219
|
+
const refs = field._f.refs || [];
|
2220
|
+
if (radioOrCheckbox
|
2221
|
+
? refs.find((option) => option === fieldRef)
|
2222
|
+
: fieldRef === field._f.ref) {
|
2223
|
+
return;
|
2224
|
+
}
|
2225
|
+
set(_fields, name, {
|
2226
|
+
_f: {
|
2227
|
+
...field._f,
|
2228
|
+
...(radioOrCheckbox
|
2229
|
+
? {
|
2230
|
+
refs: [
|
2231
|
+
...refs.filter(live),
|
2232
|
+
fieldRef,
|
2233
|
+
...(Array.isArray(get(_defaultValues, name)) ? [{}] : []),
|
2234
|
+
],
|
2235
|
+
ref: { type: fieldRef.type, name },
|
2236
|
+
}
|
2237
|
+
: { ref: fieldRef }),
|
2238
|
+
},
|
2239
|
+
});
|
2240
|
+
updateValidAndValue(name, false, undefined, fieldRef);
|
2241
|
+
}
|
2242
|
+
else {
|
2243
|
+
field = get(_fields, name, {});
|
2244
|
+
if (field._f) {
|
2245
|
+
field._f.mount = false;
|
2246
|
+
}
|
2247
|
+
(_options.shouldUnregister || options.shouldUnregister) &&
|
2248
|
+
!(isNameInFieldArray(_names.array, name) && _state.action) &&
|
2249
|
+
_names.unMount.add(name);
|
2250
|
+
}
|
2251
|
+
},
|
2252
|
+
};
|
2253
|
+
};
|
2254
|
+
const _focusError = () => _options.shouldFocusError &&
|
2255
|
+
iterateFieldsByAction(_fields, _focusInput, _names.mount);
|
2256
|
+
const _disableForm = (disabled) => {
|
2257
|
+
if (isBoolean(disabled)) {
|
2258
|
+
_subjects.state.next({ disabled });
|
2259
|
+
iterateFieldsByAction(_fields, (ref, name) => {
|
2260
|
+
const currentField = get(_fields, name);
|
2261
|
+
if (currentField) {
|
2262
|
+
ref.disabled = currentField._f.disabled || disabled;
|
2263
|
+
if (Array.isArray(currentField._f.refs)) {
|
2264
|
+
currentField._f.refs.forEach((inputRef) => {
|
2265
|
+
inputRef.disabled = currentField._f.disabled || disabled;
|
2526
2266
|
});
|
2527
2267
|
}
|
2528
|
-
}
|
2268
|
+
}
|
2269
|
+
}, 0, false);
|
2270
|
+
}
|
2271
|
+
};
|
2272
|
+
const handleSubmit = (onValid, onInvalid) => async (e) => {
|
2273
|
+
let onValidError = undefined;
|
2274
|
+
if (e) {
|
2275
|
+
e.preventDefault && e.preventDefault();
|
2276
|
+
e.persist && e.persist();
|
2277
|
+
}
|
2278
|
+
let fieldValues = cloneObject(_formValues);
|
2279
|
+
if (_names.disabled.size) {
|
2280
|
+
for (const name of _names.disabled) {
|
2281
|
+
set(fieldValues, name, undefined);
|
2282
|
+
}
|
2283
|
+
}
|
2284
|
+
_subjects.state.next({
|
2285
|
+
isSubmitting: true,
|
2286
|
+
});
|
2287
|
+
if (_options.resolver) {
|
2288
|
+
const { errors, values } = await _executeSchema();
|
2289
|
+
_formState.errors = errors;
|
2290
|
+
fieldValues = values;
|
2291
|
+
}
|
2292
|
+
else {
|
2293
|
+
await executeBuiltInValidation(_fields);
|
2294
|
+
}
|
2295
|
+
unset(_formState.errors, 'root');
|
2296
|
+
if (isEmptyObject(_formState.errors)) {
|
2297
|
+
_subjects.state.next({
|
2298
|
+
errors: {},
|
2299
|
+
});
|
2300
|
+
try {
|
2301
|
+
await onValid(fieldValues, e);
|
2302
|
+
}
|
2303
|
+
catch (error) {
|
2304
|
+
onValidError = error;
|
2305
|
+
}
|
2306
|
+
}
|
2307
|
+
else {
|
2308
|
+
if (onInvalid) {
|
2309
|
+
await onInvalid({ ..._formState.errors }, e);
|
2310
|
+
}
|
2311
|
+
_focusError();
|
2312
|
+
setTimeout(_focusError);
|
2313
|
+
}
|
2314
|
+
_subjects.state.next({
|
2315
|
+
isSubmitted: true,
|
2316
|
+
isSubmitting: false,
|
2317
|
+
isSubmitSuccessful: isEmptyObject(_formState.errors) && !onValidError,
|
2318
|
+
submitCount: _formState.submitCount + 1,
|
2319
|
+
errors: _formState.errors,
|
2320
|
+
});
|
2321
|
+
if (onValidError) {
|
2322
|
+
throw onValidError;
|
2323
|
+
}
|
2324
|
+
};
|
2325
|
+
const resetField = (name, options = {}) => {
|
2326
|
+
if (get(_fields, name)) {
|
2327
|
+
if (isUndefined(options.defaultValue)) {
|
2328
|
+
setValue(name, cloneObject(get(_defaultValues, name)));
|
2329
|
+
}
|
2330
|
+
else {
|
2331
|
+
setValue(name, options.defaultValue);
|
2332
|
+
set(_defaultValues, name, cloneObject(options.defaultValue));
|
2333
|
+
}
|
2334
|
+
if (!options.keepTouched) {
|
2335
|
+
unset(_formState.touchedFields, name);
|
2336
|
+
}
|
2337
|
+
if (!options.keepDirty) {
|
2338
|
+
unset(_formState.dirtyFields, name);
|
2339
|
+
_formState.isDirty = options.defaultValue
|
2340
|
+
? _getDirty(name, cloneObject(get(_defaultValues, name)))
|
2341
|
+
: _getDirty();
|
2342
|
+
}
|
2343
|
+
if (!options.keepError) {
|
2344
|
+
unset(_formState.errors, name);
|
2345
|
+
_proxyFormState.isValid && _updateValid();
|
2346
|
+
}
|
2347
|
+
_subjects.state.next({ ..._formState });
|
2348
|
+
}
|
2349
|
+
};
|
2350
|
+
const _reset = (formValues, keepStateOptions = {}) => {
|
2351
|
+
const updatedValues = formValues ? cloneObject(formValues) : _defaultValues;
|
2352
|
+
const cloneUpdatedValues = cloneObject(updatedValues);
|
2353
|
+
const isEmptyResetValues = isEmptyObject(formValues);
|
2354
|
+
const values = isEmptyResetValues ? _defaultValues : cloneUpdatedValues;
|
2355
|
+
if (!keepStateOptions.keepDefaultValues) {
|
2356
|
+
_defaultValues = updatedValues;
|
2357
|
+
}
|
2358
|
+
if (!keepStateOptions.keepValues) {
|
2359
|
+
if (keepStateOptions.keepDirtyValues) {
|
2360
|
+
const fieldsToCheck = new Set([
|
2361
|
+
..._names.mount,
|
2362
|
+
...Object.keys(getDirtyFields(_defaultValues, _formValues)),
|
2363
|
+
]);
|
2364
|
+
for (const fieldName of Array.from(fieldsToCheck)) {
|
2365
|
+
get(_formState.dirtyFields, fieldName)
|
2366
|
+
? set(values, fieldName, get(_formValues, fieldName))
|
2367
|
+
: setValue(fieldName, get(values, fieldName));
|
2368
|
+
}
|
2529
2369
|
}
|
2530
2370
|
else {
|
2531
|
-
|
2532
|
-
|
2533
|
-
|
2534
|
-
|
2535
|
-
|
2536
|
-
|
2537
|
-
|
2538
|
-
|
2539
|
-
|
2371
|
+
if (isWeb && isUndefined(formValues)) {
|
2372
|
+
for (const name of _names.mount) {
|
2373
|
+
const field = get(_fields, name);
|
2374
|
+
if (field && field._f) {
|
2375
|
+
const fieldReference = Array.isArray(field._f.refs)
|
2376
|
+
? field._f.refs[0]
|
2377
|
+
: field._f.ref;
|
2378
|
+
if (isHTMLElement(fieldReference)) {
|
2379
|
+
const form = fieldReference.closest('form');
|
2380
|
+
if (form) {
|
2381
|
+
form.reset();
|
2382
|
+
break;
|
2383
|
+
}
|
2384
|
+
}
|
2385
|
+
}
|
2386
|
+
}
|
2540
2387
|
}
|
2388
|
+
_fields = {};
|
2541
2389
|
}
|
2390
|
+
_formValues = _options.shouldUnregister
|
2391
|
+
? keepStateOptions.keepDefaultValues
|
2392
|
+
? cloneObject(_defaultValues)
|
2393
|
+
: {}
|
2394
|
+
: cloneObject(values);
|
2395
|
+
_subjects.array.next({
|
2396
|
+
values: { ...values },
|
2397
|
+
});
|
2398
|
+
_subjects.values.next({
|
2399
|
+
values: { ...values },
|
2400
|
+
});
|
2542
2401
|
}
|
2543
|
-
|
2544
|
-
|
2545
|
-
|
2402
|
+
_names = {
|
2403
|
+
mount: keepStateOptions.keepDirtyValues ? _names.mount : new Set(),
|
2404
|
+
unMount: new Set(),
|
2405
|
+
array: new Set(),
|
2406
|
+
disabled: new Set(),
|
2407
|
+
watch: new Set(),
|
2408
|
+
watchAll: false,
|
2409
|
+
focus: '',
|
2410
|
+
};
|
2411
|
+
_state.mount =
|
2412
|
+
!_proxyFormState.isValid ||
|
2413
|
+
!!keepStateOptions.keepIsValid ||
|
2414
|
+
!!keepStateOptions.keepDirtyValues;
|
2415
|
+
_state.watch = !!_options.shouldUnregister;
|
2416
|
+
_subjects.state.next({
|
2417
|
+
submitCount: keepStateOptions.keepSubmitCount
|
2418
|
+
? _formState.submitCount
|
2419
|
+
: 0,
|
2420
|
+
isDirty: isEmptyResetValues
|
2421
|
+
? false
|
2422
|
+
: keepStateOptions.keepDirty
|
2423
|
+
? _formState.isDirty
|
2424
|
+
: !!(keepStateOptions.keepDefaultValues &&
|
2425
|
+
!deepEqual(formValues, _defaultValues)),
|
2426
|
+
isSubmitted: keepStateOptions.keepIsSubmitted
|
2427
|
+
? _formState.isSubmitted
|
2428
|
+
: false,
|
2429
|
+
dirtyFields: isEmptyResetValues
|
2430
|
+
? {}
|
2431
|
+
: keepStateOptions.keepDirtyValues
|
2432
|
+
? keepStateOptions.keepDefaultValues && _formValues
|
2433
|
+
? getDirtyFields(_defaultValues, _formValues)
|
2434
|
+
: _formState.dirtyFields
|
2435
|
+
: keepStateOptions.keepDefaultValues && formValues
|
2436
|
+
? getDirtyFields(_defaultValues, formValues)
|
2437
|
+
: keepStateOptions.keepDirty
|
2438
|
+
? _formState.dirtyFields
|
2439
|
+
: {},
|
2440
|
+
touchedFields: keepStateOptions.keepTouched
|
2441
|
+
? _formState.touchedFields
|
2442
|
+
: {},
|
2443
|
+
errors: keepStateOptions.keepErrors ? _formState.errors : {},
|
2444
|
+
isSubmitSuccessful: keepStateOptions.keepIsSubmitSuccessful
|
2445
|
+
? _formState.isSubmitSuccessful
|
2446
|
+
: false,
|
2447
|
+
isSubmitting: false,
|
2546
2448
|
});
|
2547
|
-
|
2548
|
-
|
2549
|
-
|
2550
|
-
|
2551
|
-
|
2552
|
-
|
2553
|
-
|
2554
|
-
|
2555
|
-
|
2556
|
-
|
2557
|
-
|
2558
|
-
|
2559
|
-
|
2560
|
-
|
2561
|
-
|
2562
|
-
|
2563
|
-
|
2564
|
-
|
2565
|
-
|
2566
|
-
|
2567
|
-
|
2568
|
-
|
2569
|
-
|
2570
|
-
control._options.shouldUnregister || shouldUnregister
|
2571
|
-
? control.unregister(name)
|
2572
|
-
: updateMounted(name, false);
|
2449
|
+
};
|
2450
|
+
const reset = (formValues, keepStateOptions) => _reset(isFunction(formValues)
|
2451
|
+
? formValues(_formValues)
|
2452
|
+
: formValues, keepStateOptions);
|
2453
|
+
const setFocus = (name, options = {}) => {
|
2454
|
+
const field = get(_fields, name);
|
2455
|
+
const fieldReference = field && field._f;
|
2456
|
+
if (fieldReference) {
|
2457
|
+
const fieldRef = fieldReference.refs
|
2458
|
+
? fieldReference.refs[0]
|
2459
|
+
: fieldReference.ref;
|
2460
|
+
if (fieldRef.focus) {
|
2461
|
+
fieldRef.focus();
|
2462
|
+
options.shouldSelect &&
|
2463
|
+
isFunction(fieldRef.select) &&
|
2464
|
+
fieldRef.select();
|
2465
|
+
}
|
2466
|
+
}
|
2467
|
+
};
|
2468
|
+
const _updateFormState = (updatedFormState) => {
|
2469
|
+
_formState = {
|
2470
|
+
..._formState,
|
2471
|
+
...updatedFormState,
|
2573
2472
|
};
|
2574
|
-
}
|
2473
|
+
};
|
2474
|
+
const _resetDefaultValues = () => isFunction(_options.defaultValues) &&
|
2475
|
+
_options.defaultValues().then((values) => {
|
2476
|
+
reset(values, _options.resetOptions);
|
2477
|
+
_subjects.state.next({
|
2478
|
+
isLoading: false,
|
2479
|
+
});
|
2480
|
+
});
|
2575
2481
|
return {
|
2576
|
-
|
2577
|
-
|
2578
|
-
|
2579
|
-
|
2580
|
-
|
2581
|
-
|
2582
|
-
|
2583
|
-
|
2584
|
-
|
2585
|
-
|
2586
|
-
|
2587
|
-
|
2482
|
+
control: {
|
2483
|
+
register,
|
2484
|
+
unregister,
|
2485
|
+
getFieldState,
|
2486
|
+
handleSubmit,
|
2487
|
+
setError,
|
2488
|
+
_executeSchema,
|
2489
|
+
_getWatch,
|
2490
|
+
_getDirty,
|
2491
|
+
_updateValid,
|
2492
|
+
_removeUnmounted,
|
2493
|
+
_updateFieldArray,
|
2494
|
+
_updateDisabledField,
|
2495
|
+
_getFieldArray,
|
2496
|
+
_reset,
|
2497
|
+
_resetDefaultValues,
|
2498
|
+
_updateFormState,
|
2499
|
+
_disableForm,
|
2500
|
+
_subjects,
|
2501
|
+
_proxyFormState,
|
2502
|
+
_setErrors,
|
2503
|
+
get _fields() {
|
2504
|
+
return _fields;
|
2505
|
+
},
|
2506
|
+
get _formValues() {
|
2507
|
+
return _formValues;
|
2508
|
+
},
|
2509
|
+
get _state() {
|
2510
|
+
return _state;
|
2511
|
+
},
|
2512
|
+
set _state(value) {
|
2513
|
+
_state = value;
|
2514
|
+
},
|
2515
|
+
get _defaultValues() {
|
2516
|
+
return _defaultValues;
|
2517
|
+
},
|
2518
|
+
get _names() {
|
2519
|
+
return _names;
|
2520
|
+
},
|
2521
|
+
set _names(value) {
|
2522
|
+
_names = value;
|
2523
|
+
},
|
2524
|
+
get _formState() {
|
2525
|
+
return _formState;
|
2526
|
+
},
|
2527
|
+
set _formState(value) {
|
2528
|
+
_formState = value;
|
2529
|
+
},
|
2530
|
+
get _options() {
|
2531
|
+
return _options;
|
2532
|
+
},
|
2533
|
+
set _options(value) {
|
2534
|
+
_options = {
|
2535
|
+
..._options,
|
2536
|
+
...value,
|
2537
|
+
};
|
2538
|
+
},
|
2539
|
+
},
|
2540
|
+
trigger,
|
2541
|
+
register,
|
2542
|
+
handleSubmit,
|
2543
|
+
watch,
|
2544
|
+
setValue,
|
2545
|
+
getValues,
|
2546
|
+
reset,
|
2547
|
+
resetField,
|
2548
|
+
clearErrors,
|
2549
|
+
unregister,
|
2550
|
+
setError,
|
2551
|
+
setFocus,
|
2552
|
+
getFieldState,
|
2588
2553
|
};
|
2589
2554
|
}
|
2590
2555
|
|
@@ -2634,55 +2599,27 @@ function useForm(props = {}) {
|
|
2634
2599
|
validatingFields: {},
|
2635
2600
|
errors: props.errors || {},
|
2636
2601
|
disabled: props.disabled || false,
|
2637
|
-
isReady: false,
|
2638
2602
|
defaultValues: isFunction(props.defaultValues)
|
2639
2603
|
? undefined
|
2640
2604
|
: props.defaultValues,
|
2641
2605
|
});
|
2642
2606
|
if (!_formControl.current) {
|
2643
2607
|
_formControl.current = {
|
2644
|
-
...
|
2608
|
+
...createFormControl(props),
|
2645
2609
|
formState,
|
2646
2610
|
};
|
2647
|
-
if (props.formControl &&
|
2648
|
-
props.defaultValues &&
|
2649
|
-
!isFunction(props.defaultValues)) {
|
2650
|
-
props.formControl.reset(props.defaultValues, props.resetOptions);
|
2651
|
-
}
|
2652
2611
|
}
|
2653
2612
|
const control = _formControl.current.control;
|
2654
2613
|
control._options = props;
|
2655
|
-
|
2656
|
-
|
2657
|
-
|
2658
|
-
|
2659
|
-
|
2660
|
-
|
2661
|
-
|
2662
|
-
|
2663
|
-
isReady: true,
|
2664
|
-
}));
|
2665
|
-
control._formState.isReady = true;
|
2666
|
-
return sub;
|
2667
|
-
}, [control]);
|
2614
|
+
useSubscribe({
|
2615
|
+
subject: control._subjects.state,
|
2616
|
+
next: (value) => {
|
2617
|
+
if (shouldRenderFormState(value, control._proxyFormState, control._updateFormState, true)) {
|
2618
|
+
updateFormState({ ...control._formState });
|
2619
|
+
}
|
2620
|
+
},
|
2621
|
+
});
|
2668
2622
|
React__default.useEffect(() => control._disableForm(props.disabled), [control, props.disabled]);
|
2669
|
-
React__default.useEffect(() => {
|
2670
|
-
if (props.mode) {
|
2671
|
-
control._options.mode = props.mode;
|
2672
|
-
}
|
2673
|
-
if (props.reValidateMode) {
|
2674
|
-
control._options.reValidateMode = props.reValidateMode;
|
2675
|
-
}
|
2676
|
-
if (props.errors && !isEmptyObject(props.errors)) {
|
2677
|
-
control._setErrors(props.errors);
|
2678
|
-
}
|
2679
|
-
}, [control, props.errors, props.mode, props.reValidateMode]);
|
2680
|
-
React__default.useEffect(() => {
|
2681
|
-
props.shouldUnregister &&
|
2682
|
-
control._subjects.state.next({
|
2683
|
-
values: control._getWatch(),
|
2684
|
-
});
|
2685
|
-
}, [control, props.shouldUnregister]);
|
2686
2623
|
React__default.useEffect(() => {
|
2687
2624
|
if (control._proxyFormState.isDirty) {
|
2688
2625
|
const isDirty = control._getDirty();
|
@@ -2702,10 +2639,15 @@ function useForm(props = {}) {
|
|
2702
2639
|
else {
|
2703
2640
|
control._resetDefaultValues();
|
2704
2641
|
}
|
2705
|
-
}, [
|
2642
|
+
}, [props.values, control]);
|
2643
|
+
React__default.useEffect(() => {
|
2644
|
+
if (props.errors) {
|
2645
|
+
control._setErrors(props.errors);
|
2646
|
+
}
|
2647
|
+
}, [props.errors, control]);
|
2706
2648
|
React__default.useEffect(() => {
|
2707
2649
|
if (!control._state.mount) {
|
2708
|
-
control.
|
2650
|
+
control._updateValid();
|
2709
2651
|
control._state.mount = true;
|
2710
2652
|
}
|
2711
2653
|
if (control._state.watch) {
|
@@ -2714,9 +2656,15 @@ function useForm(props = {}) {
|
|
2714
2656
|
}
|
2715
2657
|
control._removeUnmounted();
|
2716
2658
|
});
|
2659
|
+
React__default.useEffect(() => {
|
2660
|
+
props.shouldUnregister &&
|
2661
|
+
control._subjects.values.next({
|
2662
|
+
values: control._getWatch(),
|
2663
|
+
});
|
2664
|
+
}, [props.shouldUnregister, control]);
|
2717
2665
|
_formControl.current.formState = getProxyFormState(formState, control);
|
2718
2666
|
return _formControl.current;
|
2719
2667
|
}
|
2720
2668
|
|
2721
|
-
export { Controller, Form, FormProvider, appendErrors,
|
2669
|
+
export { Controller, Form, FormProvider, appendErrors, get, set, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch };
|
2722
2670
|
//# sourceMappingURL=index.esm.js.map
|