@woodger/antd 0.1.1 → 0.1.3
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/dist/affix/Affix.svelte +12 -4
- package/dist/affix/affix.types.d.ts +3 -2
- package/dist/alert/Alert.svelte +22 -14
- package/dist/alert/alert.types.d.ts +12 -11
- package/dist/anchor/Anchor.svelte +5 -2
- package/dist/anchor/AnchorLink.svelte +4 -1
- package/dist/anchor/anchor.types.d.ts +10 -9
- package/dist/app/App.svelte +2 -1
- package/dist/app/app.types.d.ts +3 -2
- package/dist/auto-complete/AutoComplete.svelte +209 -43
- package/dist/auto-complete/auto-complete.types.d.ts +34 -3
- package/dist/avatar/Avatar.svelte +46 -32
- package/dist/avatar/AvatarGroup.svelte +34 -11
- package/dist/avatar/AvatarGroupOverflow.svelte +27 -8
- package/dist/avatar/AvatarGroupOverflow.svelte.d.ts +2 -0
- package/dist/avatar/avatar-group-context.d.ts +10 -0
- package/dist/avatar/avatar-group-context.js +11 -0
- package/dist/avatar/avatar-group.engine.d.ts +13 -4
- package/dist/avatar/avatar-group.engine.js +18 -0
- package/dist/avatar/avatar-group.types.d.ts +11 -5
- package/dist/avatar/avatar.component.d.ts +7 -0
- package/dist/avatar/avatar.component.js +4 -0
- package/dist/avatar/avatar.types.d.ts +6 -4
- package/dist/badge/Badge.svelte +37 -17
- package/dist/badge/BadgeRibbon.svelte +26 -21
- package/dist/badge/badge-ribbon.dom.d.ts +2 -4
- package/dist/badge/badge-ribbon.dom.js +14 -10
- package/dist/badge/badge-ribbon.types.d.ts +12 -11
- package/dist/badge/badge-style.dom.d.ts +2 -2
- package/dist/badge/badge-style.dom.js +9 -5
- package/dist/badge/badge-style.engine.d.ts +5 -0
- package/dist/badge/badge-style.engine.js +9 -2
- package/dist/badge/badge.component.d.ts +7 -0
- package/dist/badge/badge.component.js +4 -0
- package/dist/badge/badge.engine.js +1 -1
- package/dist/badge/badge.types.d.ts +15 -11
- package/dist/border-beam/BorderBeam.svelte +9 -5
- package/dist/border-beam/border-beam.engine.d.ts +2 -2
- package/dist/border-beam/border-beam.engine.js +7 -12
- package/dist/border-beam/border-beam.types.d.ts +4 -3
- package/dist/breadcrumb/Breadcrumb.svelte +9 -3
- package/dist/breadcrumb/BreadcrumbEntry.svelte +6 -19
- package/dist/breadcrumb/breadcrumb.engine.d.ts +5 -2
- package/dist/breadcrumb/breadcrumb.engine.js +25 -2
- package/dist/breadcrumb/breadcrumb.types.d.ts +30 -18
- package/dist/button/Button.svelte +35 -10
- package/dist/button/ButtonLabel.svelte +23 -0
- package/dist/button/ButtonLabel.svelte.d.ts +13 -0
- package/dist/button/button.engine.d.ts +6 -0
- package/dist/button/button.engine.js +35 -0
- package/dist/button/button.types.d.ts +11 -8
- package/dist/calendar/CalendarCore.svelte +26 -18
- package/dist/calendar/calendar.component.d.ts +7 -0
- package/dist/calendar/calendar.component.js +4 -0
- package/dist/calendar/calendar.types.d.ts +8 -7
- package/dist/card/Card.svelte +61 -19
- package/dist/card/CardGrid.svelte +4 -1
- package/dist/card/CardMeta.svelte +4 -1
- package/dist/card/card-semantic.engine.d.ts +1 -1
- package/dist/card/card-semantic.engine.js +2 -2
- package/dist/card/card.component.d.ts +9 -0
- package/dist/card/card.component.js +5 -0
- package/dist/card/card.engine.d.ts +2 -0
- package/dist/card/card.engine.js +7 -0
- package/dist/card/card.types.d.ts +19 -19
- package/dist/carousel/Carousel.svelte +11 -5
- package/dist/carousel/carousel-settings.engine.d.ts +1 -1
- package/dist/carousel/carousel.types.d.ts +4 -3
- package/dist/cascader/Cascader.svelte +8 -3
- package/dist/cascader/Cascader.svelte.d.ts +13 -13
- package/dist/cascader/CascaderColumns.svelte +25 -27
- package/dist/cascader/CascaderColumns.svelte.d.ts +9 -7
- package/dist/cascader/CascaderCore.svelte +814 -133
- package/dist/cascader/CascaderCore.svelte.d.ts +14 -14
- package/dist/cascader/CascaderPanel.svelte +9 -3
- package/dist/cascader/CascaderPanel.svelte.d.ts +13 -13
- package/dist/cascader/cascader.component.d.ts +17 -0
- package/dist/cascader/cascader.component.js +9 -0
- package/dist/cascader/cascader.dom.d.ts +1 -1
- package/dist/cascader/cascader.dom.js +2 -2
- package/dist/cascader/cascader.engine.d.ts +51 -24
- package/dist/cascader/cascader.engine.js +69 -6
- package/dist/cascader/cascader.types.d.ts +132 -43
- package/dist/checkbox/Checkbox.svelte +19 -10
- package/dist/checkbox/CheckboxGroup.svelte +14 -6
- package/dist/checkbox/checkbox-group.types.d.ts +7 -4
- package/dist/checkbox/checkbox.component.d.ts +7 -0
- package/dist/checkbox/checkbox.component.js +4 -0
- package/dist/checkbox/checkbox.types.d.ts +15 -13
- package/dist/collapse/Collapse.svelte +43 -11
- package/dist/collapse/CollapseItemView.svelte +5 -4
- package/dist/collapse/CollapsePanel.svelte +35 -3
- package/dist/collapse/CollapsePanel.svelte.d.ts +3 -0
- package/dist/collapse/collapse-context.d.ts +5 -1
- package/dist/collapse/collapse.engine.d.ts +5 -5
- package/dist/collapse/collapse.types.d.ts +20 -14
- package/dist/color-picker/ColorPicker.svelte +171 -110
- package/dist/color-picker/ColorPickerPresets.svelte +9 -4
- package/dist/color-picker/color-picker-alignment.dom.d.ts +17 -0
- package/dist/color-picker/color-picker-alignment.dom.js +144 -0
- package/dist/color-picker/color-picker.types.d.ts +14 -13
- package/dist/component-refs.types.d.ts +45 -0
- package/dist/component-refs.types.js +1 -0
- package/dist/component.types.d.ts +13 -0
- package/dist/component.types.js +1 -0
- package/dist/config-provider/ConfigProvider.svelte +18 -6
- package/dist/config-provider/ConfigProvider.svelte.d.ts +2 -0
- package/dist/config-provider/config-context.d.ts +7 -0
- package/dist/config-provider/config-context.js +1 -0
- package/dist/config-provider/config-provider.component.d.ts +6 -0
- package/dist/config-provider/config-provider.component.js +10 -1
- package/dist/descriptions/Descriptions.svelte +22 -13
- package/dist/descriptions/DescriptionsCell.svelte +19 -19
- package/dist/descriptions/DescriptionsCell.svelte.d.ts +2 -1
- package/dist/descriptions/descriptions-semantic.engine.d.ts +2 -2
- package/dist/descriptions/descriptions-semantic.engine.js +2 -2
- package/dist/descriptions/descriptions.types.d.ts +13 -13
- package/dist/dialog/dialog-container.model.svelte.d.ts +1 -1
- package/dist/dialog/dialog-container.model.svelte.js +14 -2
- package/dist/dialog/dialog-focus.dom.d.ts +3 -1
- package/dist/dialog/dialog-focus.dom.js +8 -7
- package/dist/divider/Divider.svelte +24 -14
- package/dist/divider/divider.types.d.ts +6 -5
- package/dist/drawer/Drawer.svelte +35 -19
- package/dist/drawer/DrawerPanel.svelte +8 -6
- package/dist/drawer/drawer-ancestor-clip.dom.d.ts +15 -0
- package/dist/drawer/drawer-ancestor-clip.dom.js +145 -0
- package/dist/drawer/drawer-clip-plane.dom.d.ts +22 -0
- package/dist/drawer/drawer-clip-plane.dom.js +100 -0
- package/dist/drawer/drawer-clip-shape.dom.d.ts +5 -0
- package/dist/drawer/drawer-clip-shape.dom.js +52 -0
- package/dist/drawer/drawer-clip-style.dom.d.ts +34 -0
- package/dist/drawer/drawer-clip-style.dom.js +190 -0
- package/dist/drawer/drawer-layout.dom.d.ts +6 -0
- package/dist/drawer/drawer-layout.dom.js +240 -0
- package/dist/drawer/drawer-overflow.dom.d.ts +9 -0
- package/dist/drawer/drawer-overflow.dom.js +249 -0
- package/dist/drawer/drawer-overflow.engine.d.ts +54 -0
- package/dist/drawer/drawer-overflow.engine.js +205 -0
- package/dist/drawer/drawer-panel.engine.d.ts +3 -2
- package/dist/drawer/drawer-panel.engine.js +4 -5
- package/dist/drawer/drawer-svg-clip.dom.d.ts +9 -0
- package/dist/drawer/drawer-svg-clip.dom.js +394 -0
- package/dist/drawer/drawer.dom.d.ts +2 -0
- package/dist/drawer/drawer.dom.js +16 -6
- package/dist/drawer/drawer.types.d.ts +22 -21
- package/dist/dropdown/Dropdown.svelte +131 -26
- package/dist/dropdown/dropdown-position.dom.d.ts +3 -1
- package/dist/dropdown/dropdown-position.dom.js +18 -7
- package/dist/dropdown/dropdown.engine.d.ts +10 -7
- package/dist/dropdown/dropdown.engine.js +29 -13
- package/dist/dropdown/dropdown.types.d.ts +7 -6
- package/dist/empty/Empty.svelte +17 -11
- package/dist/empty/empty.types.d.ts +9 -8
- package/dist/flex/Flex.svelte +26 -9
- package/dist/flex/flex.types.d.ts +2 -1
- package/dist/float-button/FloatButton.svelte +24 -13
- package/dist/float-button/FloatButtonBackTop.svelte +6 -6
- package/dist/float-button/FloatButtonGroup.svelte +26 -24
- package/dist/float-button/float-button-context.d.ts +2 -1
- package/dist/float-button/float-button.component.d.ts +9 -0
- package/dist/float-button/float-button.component.js +5 -0
- package/dist/float-button/float-button.types.d.ts +10 -8
- package/dist/form/Form.svelte +241 -42
- package/dist/form/Form.svelte.d.ts +4 -4
- package/dist/form/FormErrorList.svelte +19 -69
- package/dist/form/FormItem.svelte +296 -71
- package/dist/form/FormItem.svelte.d.ts +34 -6
- package/dist/form/FormItemControlBinding.svelte +68 -0
- package/dist/form/FormItemControlBinding.svelte.d.ts +10 -0
- package/dist/form/FormItemMessages.svelte +142 -0
- package/dist/form/FormItemMessages.svelte.d.ts +23 -0
- package/dist/form/FormItemTooltip.svelte +2 -2
- package/dist/form/FormList.svelte +49 -4
- package/dist/form/FormMessageMotion.svelte +133 -0
- package/dist/form/FormMessageMotion.svelte.d.ts +18 -0
- package/dist/form/FormProvider.svelte +9 -0
- package/dist/form/FormProvider.svelte.d.ts +4 -0
- package/dist/form/form-context.d.ts +24 -6
- package/dist/form/form-context.js +18 -0
- package/dist/form/form-control.engine.d.ts +2 -0
- package/dist/form/form-control.engine.js +13 -0
- package/dist/form/form-error-list-state.svelte.d.ts +21 -0
- package/dist/form/form-error-list-state.svelte.js +77 -0
- package/dist/form/form-error-list.engine.js +3 -1
- package/dist/form/form-error-list.types.d.ts +3 -2
- package/dist/form/form-field.dom.js +27 -4
- package/dist/form/form-internal.d.ts +33 -8
- package/dist/form/form-internal.js +2 -0
- package/dist/form/form-item-status.d.ts +2 -1
- package/dist/form/form-item-status.js +3 -1
- package/dist/form/form-list-context.d.ts +4 -0
- package/dist/form/form-list-context.js +3 -0
- package/dist/form/form-list.types.d.ts +5 -2
- package/dist/form/form-no-style.engine.d.ts +6 -5
- package/dist/form/form-provider-context.d.ts +13 -0
- package/dist/form/form-provider-context.js +74 -0
- package/dist/form/form-ref.engine.d.ts +5 -0
- package/dist/form/form-ref.engine.js +43 -0
- package/dist/form/form-store.engine.d.ts +3 -1
- package/dist/form/form-store.engine.js +25 -3
- package/dist/form/form-update.engine.d.ts +29 -0
- package/dist/form/form-update.engine.js +40 -0
- package/dist/form/form-watch.svelte.d.ts +25 -0
- package/dist/form/form-watch.svelte.js +56 -0
- package/dist/form/form.component.d.ts +28 -0
- package/dist/form/form.component.js +25 -0
- package/dist/form/form.model.svelte.d.ts +25 -3
- package/dist/form/form.model.svelte.js +764 -191
- package/dist/form/form.types.d.ts +135 -24
- package/dist/form/validation-message.engine.d.ts +17 -3
- package/dist/form/validation-message.engine.js +39 -2
- package/dist/form/validation-messages.types.d.ts +11 -0
- package/dist/form/validation-nested.engine.d.ts +5 -4
- package/dist/form/validation.engine.d.ts +8 -6
- package/dist/form/validation.engine.js +2 -2
- package/dist/grid/Col.svelte +18 -21
- package/dist/grid/Row.svelte +13 -15
- package/dist/grid/grid.engine.d.ts +4 -1
- package/dist/grid/grid.engine.js +15 -3
- package/dist/grid/grid.svelte.d.ts +7 -0
- package/dist/grid/grid.svelte.js +30 -0
- package/dist/grid/grid.types.d.ts +5 -2
- package/dist/image/Image.svelte +148 -58
- package/dist/image/ImagePreview.svelte +284 -137
- package/dist/image/ImagePreview.svelte.d.ts +11 -2
- package/dist/image/ImagePreviewGroup.svelte +40 -7
- package/dist/image/ImagePreviewIcons.svelte +18 -0
- package/dist/image/ImagePreviewIcons.svelte.d.ts +29 -0
- package/dist/image/ImageProgress.svelte +87 -0
- package/dist/image/ImageProgress.svelte.d.ts +14 -0
- package/dist/image/image-group-context.d.ts +2 -1
- package/dist/image/image-prefix.engine.js +4 -0
- package/dist/image/image-preview-group.types.d.ts +9 -8
- package/dist/image/image-preview-motion.dom.d.ts +16 -0
- package/dist/image/image-preview-motion.dom.js +72 -0
- package/dist/image/image-semantic.engine.d.ts +40 -0
- package/dist/image/image-semantic.engine.js +57 -0
- package/dist/image/image.component.d.ts +7 -0
- package/dist/image/image.component.js +4 -0
- package/dist/image/image.types.d.ts +86 -12
- package/dist/index.d.ts +58 -48
- package/dist/index.js +26 -21
- package/dist/input/Input.svelte +76 -55
- package/dist/input/InputOTP.svelte +14 -9
- package/dist/input/InputPassword.svelte +15 -27
- package/dist/input/InputSearch.svelte +45 -19
- package/dist/input/TextArea.svelte +30 -32
- package/dist/input/input-otp.types.d.ts +12 -9
- package/dist/input/input-password.types.d.ts +6 -6
- package/dist/input/input-search.types.d.ts +8 -8
- package/dist/input/input-value.svelte.d.ts +7 -0
- package/dist/input/input-value.svelte.js +21 -0
- package/dist/input/input.component.d.ts +13 -0
- package/dist/input/input.component.js +12 -0
- package/dist/input/input.types.d.ts +13 -8
- package/dist/input/textarea.types.d.ts +12 -8
- package/dist/input-number/InputNumberAction.svelte +2 -2
- package/dist/input-number/InputNumberControl.svelte +36 -23
- package/dist/input-number/input-number.types.d.ts +16 -16
- package/dist/layout/Layout.svelte +7 -3
- package/dist/layout/LayoutPart.svelte +9 -3
- package/dist/layout/LayoutSider.svelte +27 -17
- package/dist/layout/layout.component.d.ts +13 -0
- package/dist/layout/layout.component.js +7 -0
- package/dist/layout/layout.types.d.ts +6 -5
- package/dist/listy/Listy.svelte +20 -14
- package/dist/listy/ListyGroupHeader.svelte +8 -2
- package/dist/listy/ListyGroupHeader.svelte.d.ts +2 -1
- package/dist/listy/ListyRaw.svelte +7 -9
- package/dist/listy/ListyVirtual.svelte +5 -2
- package/dist/listy/listy.types.d.ts +13 -10
- package/dist/masonry/Masonry.svelte +32 -20
- package/dist/masonry/MasonryItem.svelte +0 -1
- package/dist/masonry/masonry.types.d.ts +8 -7
- package/dist/mentions/Mentions.svelte +44 -9
- package/dist/mentions/MentionsListbox.svelte +2 -1
- package/dist/mentions/mentions.component.d.ts +7 -0
- package/dist/mentions/mentions.component.js +4 -0
- package/dist/mentions/mentions.engine.d.ts +35 -0
- package/dist/mentions/mentions.engine.js +7 -0
- package/dist/mentions/mentions.types.d.ts +12 -8
- package/dist/menu/Menu.svelte +13 -6
- package/dist/menu/MenuItem.svelte +23 -14
- package/dist/menu/MenuItemTooltip.svelte +2 -1
- package/dist/menu/MenuList.svelte +7 -4
- package/dist/menu/MenuSubMenu.svelte +109 -32
- package/dist/menu/menu-motion.engine.js +3 -28
- package/dist/menu/menu-motion.svelte.d.ts +1 -7
- package/dist/menu/menu-motion.svelte.js +1 -33
- package/dist/menu/menu-popup-align.dom.d.ts +1 -1
- package/dist/menu/menu-popup-align.engine.d.ts +2 -2
- package/dist/menu/menu-popup-align.engine.js +1 -4
- package/dist/menu/menu-semantic.engine.d.ts +8 -8
- package/dist/menu/menu-semantic.engine.js +16 -6
- package/dist/menu/menu.engine.d.ts +5 -1
- package/dist/menu/menu.engine.js +15 -0
- package/dist/menu/menu.types.d.ts +25 -22
- package/dist/message/MessageHolder.svelte +9 -6
- package/dist/message/MessageNotice.svelte +12 -9
- package/dist/message/MessageNotice.svelte.d.ts +2 -1
- package/dist/message/message-semantic.engine.d.ts +1 -1
- package/dist/message/message.model.svelte.d.ts +2 -1
- package/dist/message/message.model.svelte.js +2 -1
- package/dist/message/message.types.d.ts +12 -10
- package/dist/modal/Modal.svelte +229 -57
- package/dist/modal/ModalConfirmation.svelte +9 -10
- package/dist/modal/ModalFooterScope.svelte +15 -0
- package/dist/modal/ModalFooterScope.svelte.d.ts +7 -0
- package/dist/modal/modal-close.engine.d.ts +1 -1
- package/dist/modal/modal-layout.engine.d.ts +1 -1
- package/dist/modal/modal-layout.engine.js +20 -3
- package/dist/modal/modal-motion.dom.d.ts +1 -0
- package/dist/modal/modal-motion.dom.js +21 -5
- package/dist/modal/modal-named-motion.dom.d.ts +1 -1
- package/dist/modal/modal-named-motion.dom.js +1 -2
- package/dist/modal/modal-semantic.engine.d.ts +8 -7
- package/dist/modal/modal-semantic.engine.js +2 -2
- package/dist/modal/modal.types.d.ts +27 -18
- package/dist/motion/collapse-motion.engine.d.ts +3 -0
- package/dist/motion/collapse-motion.engine.js +31 -0
- package/dist/motion/css-motion.svelte.d.ts +7 -0
- package/dist/motion/css-motion.svelte.js +35 -0
- package/dist/notice/notice-queue.model.svelte.js +4 -0
- package/dist/notice/notice-semantic.engine.d.ts +10 -7
- package/dist/notice/notice-semantic.engine.js +9 -4
- package/dist/notification/NotificationHolder.svelte +7 -5
- package/dist/notification/NotificationList.svelte +5 -2
- package/dist/notification/NotificationList.svelte.d.ts +2 -1
- package/dist/notification/NotificationNotice.svelte +16 -18
- package/dist/notification/NotificationNotice.svelte.d.ts +2 -1
- package/dist/notification/notification.model.svelte.d.ts +2 -1
- package/dist/notification/notification.types.d.ts +12 -9
- package/dist/pagination/Pagination.svelte +90 -18
- package/dist/pagination/PaginationControl.svelte +2 -0
- package/dist/pagination/pagination.types.d.ts +19 -14
- package/dist/picker/DatePicker.svelte +9 -1
- package/dist/picker/DatePicker.svelte.d.ts +4 -4
- package/dist/picker/DatePickerCalendar.svelte +15 -12
- package/dist/picker/DatePickerCalendar.svelte.d.ts +2 -2
- package/dist/picker/DatePickerTimePanel.svelte +5 -1
- package/dist/picker/DatePickerTimePanel.svelte.d.ts +2 -4
- package/dist/picker/PickerTimeColumn.svelte +27 -12
- package/dist/picker/PickerTimeColumn.svelte.d.ts +3 -0
- package/dist/picker/PickerTimePanel.svelte +16 -0
- package/dist/picker/PickerTimePanel.svelte.d.ts +3 -0
- package/dist/picker/RangePicker.svelte +3 -1
- package/dist/picker/RangePickerCore.svelte +874 -363
- package/dist/picker/RangePickerCore.svelte.d.ts +1 -0
- package/dist/picker/SinglePicker.svelte +684 -309
- package/dist/picker/SinglePicker.svelte.d.ts +1 -0
- package/dist/picker/TimePicker.svelte +3 -1
- package/dist/picker/TimeRangePicker.svelte +2 -0
- package/dist/picker/date-picker-semantic.engine.d.ts +7 -6
- package/dist/picker/date-picker-semantic.engine.js +5 -4
- package/dist/picker/date-picker.types.d.ts +58 -30
- package/dist/picker/picker-adapter-props.engine.d.ts +2 -0
- package/dist/picker/picker-adapter-props.engine.js +4 -0
- package/dist/picker/picker-mask-input.model.svelte.js +9 -5
- package/dist/picker/picker-panel-updates.d.ts +6 -0
- package/dist/picker/picker-panel-updates.js +33 -0
- package/dist/picker/picker-popup-portal.dom.d.ts +49 -0
- package/dist/picker/picker-popup-portal.dom.js +49 -0
- package/dist/picker/picker-popup.dom.d.ts +14 -2
- package/dist/picker/picker-popup.dom.js +153 -40
- package/dist/picker/picker-popup.model.svelte.d.ts +33 -8
- package/dist/picker/picker-popup.model.svelte.js +149 -19
- package/dist/picker/picker-prefix.engine.js +4 -1
- package/dist/picker/picker-style.engine.d.ts +27 -0
- package/dist/picker/picker-style.engine.js +64 -0
- package/dist/picker/picker-time-scroll.model.svelte.d.ts +16 -0
- package/dist/picker/picker-time-scroll.model.svelte.js +31 -0
- package/dist/picker/range-picker-interaction.engine.d.ts +3 -2
- package/dist/picker/range-picker-interaction.engine.js +10 -4
- package/dist/picker/range-picker-popup.dom.d.ts +2 -0
- package/dist/picker/range-picker-popup.dom.js +47 -0
- package/dist/picker/range-picker.types.d.ts +13 -6
- package/dist/picker/time-picker-column.dom.d.ts +6 -1
- package/dist/picker/time-picker-column.dom.js +27 -3
- package/dist/picker/time-picker-props.engine.js +3 -2
- package/dist/picker/time-picker-semantic.engine.d.ts +6 -2
- package/dist/picker/time-picker-semantic.engine.js +32 -18
- package/dist/picker/time-picker.component.d.ts +4 -1
- package/dist/picker/time-picker.component.js +3 -1
- package/dist/picker/time-picker.types.d.ts +28 -24
- package/dist/picker/time-range-picker-semantic.engine.d.ts +2 -0
- package/dist/picker/time-range-picker-semantic.engine.js +6 -8
- package/dist/picker/time-range-picker.types.d.ts +5 -4
- package/dist/popconfirm/Popconfirm.svelte +48 -12
- package/dist/popconfirm/popconfirm.types.d.ts +17 -11
- package/dist/popover/Popover.svelte +65 -42
- package/dist/popover/popover.types.d.ts +19 -12
- package/dist/popup/PopupContentContext.svelte +14 -0
- package/dist/popup/PopupContentContext.svelte.d.ts +7 -0
- package/dist/popup/overlay-motion.css +86 -3
- package/dist/popup/overlay-portal-alignment.dom.d.ts +34 -0
- package/dist/popup/overlay-portal-alignment.dom.js +166 -0
- package/dist/popup/overlay-semantic.engine.d.ts +16 -15
- package/dist/popup/overlay-semantic.engine.js +5 -6
- package/dist/popup/popup-container.model.svelte.d.ts +4 -1
- package/dist/popup/popup-container.model.svelte.js +7 -2
- package/dist/popup/popup-css-motion.dom.d.ts +24 -0
- package/dist/{tree-select/tree-select-motion.dom.js → popup/popup-css-motion.dom.js} +13 -3
- package/dist/popup/popup-css-motion.model.svelte.d.ts +25 -0
- package/dist/popup/popup-css-motion.model.svelte.js +73 -0
- package/dist/popup/popup-geometry.dom.d.ts +16 -0
- package/dist/popup/popup-geometry.dom.js +97 -0
- package/dist/popup/popup-plane.engine.d.ts +6 -0
- package/dist/popup/popup-plane.engine.js +18 -0
- package/dist/popup/popup-portal-fit.dom.d.ts +3 -0
- package/dist/popup/popup-portal-fit.dom.js +81 -0
- package/dist/popup/popup-portal-projection.dom.d.ts +52 -0
- package/dist/popup/popup-portal-projection.dom.js +208 -0
- package/dist/popup/popup-position.engine.d.ts +5 -3
- package/dist/popup/popup.dom.d.ts +7 -1
- package/dist/popup/popup.dom.js +69 -22
- package/dist/popup/select-popup-motion.engine.d.ts +4 -0
- package/dist/popup/select-popup-motion.engine.js +18 -0
- package/dist/progress/Progress.svelte +58 -28
- package/dist/progress/ProgressCircle.svelte +40 -22
- package/dist/progress/ProgressCircle.svelte.d.ts +2 -1
- package/dist/progress/progress-circle.engine.d.ts +1 -1
- package/dist/progress/progress.types.d.ts +6 -5
- package/dist/qr-code/QRCode.svelte +12 -8
- package/dist/qr-code/qrcode.types.d.ts +10 -9
- package/dist/radio/Radio.svelte +19 -10
- package/dist/radio/RadioGroup.svelte +14 -6
- package/dist/radio/radio.component.d.ts +9 -0
- package/dist/radio/radio.component.js +5 -0
- package/dist/radio/radio.types.d.ts +20 -18
- package/dist/rate/Rate.svelte +8 -4
- package/dist/rate/rate.types.d.ts +5 -4
- package/dist/render-content.engine.d.ts +9 -0
- package/dist/render-content.engine.js +21 -0
- package/dist/result/Result.svelte +19 -13
- package/dist/result/result.types.d.ts +11 -10
- package/dist/segmented/Segmented.svelte +28 -15
- package/dist/segmented/segmented.engine.js +2 -1
- package/dist/segmented/segmented.types.d.ts +11 -11
- package/dist/select/Select.svelte +309 -69
- package/dist/select/select-editor-focus.dom.d.ts +14 -0
- package/dist/select/select-editor-focus.dom.js +51 -0
- package/dist/select/select-icons.engine.d.ts +2 -0
- package/dist/select/select-icons.engine.js +17 -8
- package/dist/select/select-mouse-boundary.dom.d.ts +7 -0
- package/dist/select/select-mouse-boundary.dom.js +57 -0
- package/dist/select/select-semantic.engine.d.ts +2 -2
- package/dist/select/select-style.engine.d.ts +2 -2
- package/dist/select/select-style.engine.js +24 -2
- package/dist/select/select-token.engine.d.ts +4 -0
- package/dist/select/select-token.engine.js +13 -0
- package/dist/select/select.types.d.ts +35 -12
- package/dist/skeleton/Skeleton.svelte +25 -15
- package/dist/skeleton/SkeletonElement.svelte +16 -8
- package/dist/skeleton/skeleton.types.d.ts +11 -10
- package/dist/slider/SliderRange.svelte +35 -53
- package/dist/slider/SliderSingle.svelte +58 -73
- package/dist/slider/SliderTooltip.svelte +322 -0
- package/dist/slider/SliderTooltip.svelte.d.ts +18 -0
- package/dist/slider/slider-handle.dom.d.ts +5 -0
- package/dist/slider/slider-handle.dom.js +60 -0
- package/dist/slider/slider-range.engine.d.ts +4 -2
- package/dist/slider/slider-range.engine.js +15 -0
- package/dist/slider/slider-range.types.d.ts +10 -8
- package/dist/slider/slider-semantic.engine.d.ts +1 -1
- package/dist/slider/slider-semantic.engine.js +2 -6
- package/dist/slider/slider.types.d.ts +5 -3
- package/dist/space/Space.svelte +35 -16
- package/dist/space/SpaceAddon.svelte +11 -5
- package/dist/space/SpaceCompact.svelte +7 -2
- package/dist/space/SpaceCompactItem.svelte +4 -1
- package/dist/space/space-compact.types.d.ts +6 -6
- package/dist/space/space.component.d.ts +9 -0
- package/dist/space/space.component.js +5 -0
- package/dist/space/space.engine.d.ts +5 -1
- package/dist/space/space.engine.js +32 -7
- package/dist/space/space.types.d.ts +15 -12
- package/dist/spin/Spin.svelte +25 -14
- package/dist/spin/spin.types.d.ts +5 -3
- package/dist/splitter/Splitter.svelte +15 -14
- package/dist/splitter/SplitterArrow.svelte.d.ts +1 -1
- package/dist/splitter/SplitterBar.svelte +2 -1
- package/dist/splitter/SplitterPanel.svelte +14 -2
- package/dist/splitter/SplitterPanel.svelte.d.ts +2 -1
- package/dist/splitter/SplitterPanelDeclaration.svelte +20 -0
- package/dist/splitter/SplitterPanelDeclaration.svelte.d.ts +4 -0
- package/dist/splitter/SplitterPanelDeclarations.svelte +16 -0
- package/dist/splitter/SplitterPanelDeclarations.svelte.d.ts +10 -0
- package/dist/splitter/SplitterRoot.svelte +18 -0
- package/dist/splitter/SplitterRoot.svelte.d.ts +4 -0
- package/dist/splitter/splitter-panel-context.d.ts +10 -0
- package/dist/splitter/splitter-panel-context.js +11 -0
- package/dist/splitter/splitter.component.d.ts +7 -0
- package/dist/splitter/splitter.component.js +6 -0
- package/dist/splitter/splitter.engine.d.ts +6 -1
- package/dist/splitter/splitter.engine.js +18 -0
- package/dist/splitter/splitter.types.d.ts +13 -10
- package/dist/statistic/Statistic.svelte +25 -12
- package/dist/statistic/statistic.component.d.ts +7 -0
- package/dist/statistic/statistic.component.js +4 -0
- package/dist/statistic/statistic.types.d.ts +6 -4
- package/dist/steps/StepIcon.svelte +4 -2
- package/dist/steps/StepIcon.svelte.d.ts +2 -1
- package/dist/steps/StepItem.svelte +12 -16
- package/dist/steps/Steps.svelte +9 -9
- package/dist/steps/steps-data.engine.d.ts +5 -4
- package/dist/steps/steps-expanded.types.d.ts +2 -1
- package/dist/steps/steps-icon-context.d.ts +2 -1
- package/dist/steps/steps.types.d.ts +4 -3
- package/dist/style/inline-style-layers.engine.d.ts +11 -0
- package/dist/style/inline-style-layers.engine.js +120 -0
- package/dist/style/inline-style.engine.d.ts +4 -0
- package/dist/style/inline-style.engine.js +17 -9
- package/dist/style/inline-style.types.d.ts +12 -0
- package/dist/style/inline-style.types.js +1 -0
- package/dist/style/semantic-style.engine.d.ts +18 -12
- package/dist/style/semantic-style.engine.js +15 -9
- package/dist/styles.css +1 -0
- package/dist/styles.css.d.ts +1 -0
- package/dist/switch/Switch.svelte +17 -9
- package/dist/switch/switch.types.d.ts +14 -12
- package/dist/table/Table.svelte +30 -21
- package/dist/table/Table.svelte.d.ts +4 -2
- package/dist/table/TableColumn.svelte +20 -0
- package/dist/table/TableColumn.svelte.d.ts +25 -0
- package/dist/table/TableColumnDeclarations.svelte +18 -0
- package/dist/table/TableColumnDeclarations.svelte.d.ts +10 -0
- package/dist/table/TableColumnGroup.svelte +31 -0
- package/dist/table/TableColumnGroup.svelte.d.ts +25 -0
- package/dist/table/TableRoot.svelte +55 -0
- package/dist/table/TableRoot.svelte.d.ts +29 -0
- package/dist/table/table-cell.engine.d.ts +14 -14
- package/dist/table/table-column-declarations.svelte.d.ts +22 -0
- package/dist/table/table-column-declarations.svelte.js +45 -0
- package/dist/table/table-semantic.engine.d.ts +18 -6
- package/dist/table/table-semantic.engine.js +14 -14
- package/dist/table/table.component.d.ts +10 -2
- package/dist/table/table.component.js +4 -1
- package/dist/table/table.types.d.ts +55 -25
- package/dist/tabs/Tabs.svelte +35 -18
- package/dist/tabs/TabsNav.svelte +33 -18
- package/dist/tabs/TabsNav.svelte.d.ts +2 -1
- package/dist/tabs/TabsOverflow.svelte +98 -122
- package/dist/tabs/TabsOverflow.svelte.d.ts +2 -1
- package/dist/tabs/TabsPanel.svelte +10 -5
- package/dist/tabs/TabsPanel.svelte.d.ts +4 -3
- package/dist/tabs/tabs-more-alignment.dom.d.ts +32 -0
- package/dist/tabs/tabs-more-alignment.dom.js +158 -0
- package/dist/tabs/tabs-more.dom.d.ts +69 -13
- package/dist/tabs/tabs-more.dom.js +76 -65
- package/dist/tabs/tabs-motion.dom.d.ts +2 -1
- package/dist/tabs/tabs-motion.dom.js +2 -1
- package/dist/tabs/tabs-motion.types.d.ts +4 -3
- package/dist/tabs/tabs-nav.types.d.ts +6 -7
- package/dist/tabs/tabs-semantic.engine.d.ts +18 -12
- package/dist/tabs/tabs-semantic.engine.js +70 -19
- package/dist/tabs/tabs.types.d.ts +35 -29
- package/dist/tag/CheckableTag.svelte +8 -4
- package/dist/tag/CheckableTagGroup.svelte +42 -32
- package/dist/tag/CheckableTagGroup.svelte.d.ts +12 -12
- package/dist/tag/Tag.svelte +14 -20
- package/dist/tag/tag-style.dom.d.ts +3 -1
- package/dist/tag/tag-style.dom.js +19 -1
- package/dist/tag/tag.component.d.ts +10 -0
- package/dist/tag/tag.component.js +5 -0
- package/dist/tag/tag.types.d.ts +30 -27
- package/dist/theme/theme-context.svelte.d.ts +2 -0
- package/dist/theme/theme-context.svelte.js +6 -1
- package/dist/timeline/Timeline.svelte +13 -5
- package/dist/timeline/timeline.engine.js +3 -1
- package/dist/timeline/timeline.types.d.ts +7 -6
- package/dist/tooltip/Tooltip.svelte +18 -10
- package/dist/tooltip/TooltipPopup.svelte +44 -22
- package/dist/tooltip/TooltipUniqueContent.svelte +3 -6
- package/dist/tooltip/TooltipUniqueContent.svelte.d.ts +0 -1
- package/dist/tooltip/TooltipUniquePopup.svelte +1 -1
- package/dist/tooltip/tooltip-popup.types.d.ts +6 -0
- package/dist/tooltip/tooltip.engine.d.ts +58 -2
- package/dist/tooltip/tooltip.engine.js +54 -27
- package/dist/tooltip/tooltip.types.d.ts +38 -13
- package/dist/tour/Tour.svelte +37 -14
- package/dist/tour/TourPanel.svelte +13 -12
- package/dist/tour/TourPanel.svelte.d.ts +2 -1
- package/dist/tour/tour.engine.d.ts +7 -2
- package/dist/tour/tour.engine.js +58 -11
- package/dist/tour/tour.types.d.ts +20 -19
- package/dist/transfer/Transfer.svelte +44 -36
- package/dist/transfer/TransferAction.svelte +6 -7
- package/dist/transfer/TransferAction.svelte.d.ts +3 -2
- package/dist/transfer/TransferCheckbox.svelte +9 -3
- package/dist/transfer/TransferCheckbox.svelte.d.ts +2 -1
- package/dist/transfer/TransferList.svelte +18 -0
- package/dist/transfer/TransferList.svelte.d.ts +45 -0
- package/dist/transfer/TransferOperation.svelte +43 -0
- package/dist/transfer/TransferOperation.svelte.d.ts +4 -0
- package/dist/transfer/TransferPagination.svelte +3 -1
- package/dist/transfer/TransferSearch.svelte +44 -0
- package/dist/transfer/TransferSearch.svelte.d.ts +4 -0
- package/dist/transfer/TransferSection.svelte +42 -30
- package/dist/transfer/TransferSection.svelte.d.ts +2 -4
- package/dist/transfer/transfer-style.engine.d.ts +7 -0
- package/dist/transfer/transfer-style.engine.js +33 -0
- package/dist/transfer/transfer.component.d.ts +12 -0
- package/dist/transfer/transfer.component.js +6 -0
- package/dist/transfer/transfer.types.d.ts +44 -4
- package/dist/tree/Tree.svelte +8 -5
- package/dist/tree/TreeMotion.svelte +5 -1
- package/dist/tree/tree-motion.dom.js +12 -3
- package/dist/tree/tree-motion.types.d.ts +4 -3
- package/dist/tree/tree-semantic.engine.d.ts +9 -2
- package/dist/tree/tree-semantic.engine.js +37 -3
- package/dist/tree/tree.component.d.ts +10 -0
- package/dist/tree/tree.component.js +5 -0
- package/dist/tree/tree.types.d.ts +8 -6
- package/dist/tree-select/TreeSelectControl.svelte +127 -89
- package/dist/tree-select/tree-select-align.engine.d.ts +2 -6
- package/dist/tree-select/tree-select-align.engine.js +1 -18
- package/dist/tree-select/tree-select-motion-frame.dom.d.ts +2 -5
- package/dist/tree-select/tree-select-semantic.engine.d.ts +6 -6
- package/dist/tree-select/tree-select-semantic.engine.js +50 -25
- package/dist/tree-select/tree-select-token.engine.d.ts +1 -3
- package/dist/tree-select/tree-select-token.engine.js +1 -13
- package/dist/tree-select/tree-select.types.d.ts +9 -5
- package/dist/types.d.ts +5 -2
- package/dist/typography/TypographyEditable.svelte +11 -5
- package/dist/typography/TypographyEditable.svelte.d.ts +3 -2
- package/dist/typography/TypographyElement.svelte +13 -7
- package/dist/typography/TypographyElement.svelte.d.ts +3 -2
- package/dist/typography/TypographyTooltip.svelte +19 -8
- package/dist/typography/typography-semantic.engine.d.ts +9 -2
- package/dist/typography/typography-semantic.engine.js +15 -4
- package/dist/typography/typography.component.d.ts +13 -0
- package/dist/typography/typography.component.js +7 -0
- package/dist/typography/typography.types.d.ts +8 -7
- package/dist/upload/Upload.svelte +44 -4
- package/dist/upload/Upload.svelte.d.ts +1 -1
- package/dist/upload/UploadDragger.svelte +3 -2
- package/dist/upload/UploadDragger.svelte.d.ts +4 -4
- package/dist/upload/UploadList.svelte.d.ts +1 -1
- package/dist/upload/UploadListItem.svelte +52 -11
- package/dist/upload/upload.component.d.ts +9 -0
- package/dist/upload/upload.component.js +5 -0
- package/dist/upload/upload.engine.d.ts +8 -2
- package/dist/upload/upload.engine.js +80 -4
- package/dist/upload/upload.types.d.ts +2 -1
- package/dist/utils/declaration-order.svelte.d.ts +12 -0
- package/dist/utils/declaration-order.svelte.js +53 -0
- package/dist/vendor/compute-scroll-into-view.d.ts +3 -1
- package/dist/vendor/compute-scroll-into-view.js +3 -2
- package/dist/vendor/date-picker-prefix.css.js +2 -2
- package/dist/vendor/dropdown-motion.css +105 -0
- package/dist/vendor/image-prefix.css.js +3 -3
- package/dist/vendor/image.css +16 -2
- package/dist/vendor/tree-select-popup-motion.css +112 -112
- package/dist/vendor/tree-select-popup-motion.css.js +2 -2
- package/dist/version.d.ts +2 -0
- package/dist/version.js +3 -0
- package/dist/watermark/Watermark.svelte +8 -6
- package/dist/watermark/watermark.types.d.ts +3 -2
- package/package.json +15 -4
- package/readme.md +2 -2
- package/dist/picker/time-range-picker-popup.dom.d.ts +0 -2
- package/dist/picker/time-range-picker-popup.dom.js +0 -42
- package/dist/tree-select/tree-select-motion-css.engine.d.ts +0 -2
- package/dist/tree-select/tree-select-motion-css.engine.js +0 -11
- package/dist/tree-select/tree-select-motion.dom.d.ts +0 -18
- package/dist/tree-select/tree-select-motion.engine.d.ts +0 -2
- package/dist/tree-select/tree-select-motion.engine.js +0 -5
|
@@ -4,9 +4,18 @@ import { tick, untrack } from 'svelte';
|
|
|
4
4
|
import { FormValidationError } from './FormValidationError';
|
|
5
5
|
import { setFormHooks } from './form-internal';
|
|
6
6
|
import { focusFormField, getFormFieldElement, scrollFormField } from './form-field.dom';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { readFormControlValue } from './form-control.engine';
|
|
8
|
+
import { copyValidationMessages, mergeValidationMessages, snapshotValidationMessages, validationMessageTexts } from './validation-message.engine';
|
|
9
|
+
import { containsFormPath, copyFormValue, formNamePath, getFormValue, hasFormValue, mergeFormValues, sameFormPath, sameFormValue, setFormValue } from './form-store.engine';
|
|
9
10
|
import { validateFieldValue, resolveValidationRules } from './validation.engine';
|
|
11
|
+
// A snapshot fed back through Form.fields does not replace the running validator.
|
|
12
|
+
const fieldSnapshotOrigin = Symbol('ant-design-form-field-snapshot');
|
|
13
|
+
/** Matches configured event names without treating false as a trigger. */
|
|
14
|
+
function allowsValidationTrigger(triggers, event) {
|
|
15
|
+
return typeof triggers === 'string'
|
|
16
|
+
? triggers !== '' && triggers === event
|
|
17
|
+
: triggers !== false && triggers.includes(event);
|
|
18
|
+
}
|
|
10
19
|
/** Preserves numeric path segments, including infinities and the strict equality rule for NaN. */
|
|
11
20
|
function fieldSelectionKey(path) {
|
|
12
21
|
if (path.some(part => typeof part === 'number' && Number.isNaN(part))) {
|
|
@@ -46,18 +55,29 @@ function selectNamedFields(names, bindings) {
|
|
|
46
55
|
* validation cannot replace errors for newer values.
|
|
47
56
|
*/
|
|
48
57
|
export function createForm({ initialValues, rules = {} }) {
|
|
49
|
-
const
|
|
58
|
+
const modelDefaults = copyFormValue(initialValues);
|
|
59
|
+
let defaults = modelDefaults;
|
|
50
60
|
let valuesRevision = $state(0);
|
|
51
61
|
let validationSequence = 0;
|
|
52
62
|
let latestValidationRun = 0;
|
|
63
|
+
let submissionRevision = 0;
|
|
64
|
+
let mountedForms = 0;
|
|
65
|
+
let storeLifetime = 0;
|
|
66
|
+
let restoreDefaultsOnMount = false;
|
|
53
67
|
let registrationOrder = 0;
|
|
54
|
-
let
|
|
68
|
+
let fieldMountOrder = 0;
|
|
55
69
|
let values = $state(copyFormValue(defaults));
|
|
56
70
|
let resetKey = $state.raw({});
|
|
57
71
|
// At teardown Svelte reads the previous $state; the registry stores up-to-date registrations.
|
|
58
72
|
const fieldRegistry = new Set();
|
|
73
|
+
const pendingRemovals = [];
|
|
59
74
|
const validationDelays = new Map();
|
|
60
75
|
const messageProviders = new Set();
|
|
76
|
+
const callbackProviders = new Set();
|
|
77
|
+
const storeListeners = new Set();
|
|
78
|
+
const resetObservers = new Map();
|
|
79
|
+
let storeSnapshot;
|
|
80
|
+
const controlDrivenFields = new WeakSet();
|
|
61
81
|
let fields = $state.raw([]);
|
|
62
82
|
let isSubmitting = $state(false);
|
|
63
83
|
let submissionError = $state.raw();
|
|
@@ -65,16 +85,30 @@ export function createForm({ initialValues, rules = {} }) {
|
|
|
65
85
|
function fieldPath(field) {
|
|
66
86
|
return formNamePath(field.registration?.name ?? field.path);
|
|
67
87
|
}
|
|
68
|
-
//
|
|
88
|
+
// A new editor can register before its predecessor releases a persistent field record.
|
|
69
89
|
function findField(name) {
|
|
70
|
-
|
|
90
|
+
let unmounted;
|
|
91
|
+
for (const field of fields) {
|
|
92
|
+
if (!sameFormPath(fieldPath(field), name)) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (field.registration) {
|
|
96
|
+
return field;
|
|
97
|
+
}
|
|
98
|
+
unmounted ??= field;
|
|
99
|
+
}
|
|
100
|
+
return unmounted;
|
|
101
|
+
}
|
|
102
|
+
// A name can refer to multiple editors. The mount key identifies the emitting registration.
|
|
103
|
+
function findFieldByMountKey(mountKey) {
|
|
104
|
+
return fields.find((field) => field.registration?.mountKey === mountKey);
|
|
71
105
|
}
|
|
72
106
|
// Copies the arrays so that the listener does not change the metadata in the repository.
|
|
73
|
-
function fieldMeta(field) {
|
|
107
|
+
function fieldMeta(field, path = fieldPath(field)) {
|
|
108
|
+
const messages = snapshotValidationMessages(field.errors, field.warnings);
|
|
74
109
|
return {
|
|
75
|
-
name: [...
|
|
76
|
-
validated: field.validated,
|
|
77
|
-
warnings: [...(field.warnings ?? [])]
|
|
110
|
+
name: [...path], touched: field.touched, validating: field.validating,
|
|
111
|
+
validated: field.validated, ...messages
|
|
78
112
|
};
|
|
79
113
|
}
|
|
80
114
|
// Publishes only a new state or signal to remove registration.
|
|
@@ -136,22 +170,73 @@ export function createForm({ initialValues, rules = {} }) {
|
|
|
136
170
|
? rules[path[0]] : undefined)
|
|
137
171
|
?? [];
|
|
138
172
|
}
|
|
173
|
+
// Falsy defined initial values count, even when the field has never been touched.
|
|
174
|
+
function isValidationDirty(field, path = fieldPath(field)) {
|
|
175
|
+
return field.dirty || field.touched || field.registration?.initialValue !== undefined
|
|
176
|
+
|| getFormValue(defaults, path) !== undefined;
|
|
177
|
+
}
|
|
178
|
+
// Follow the live paths and stop at pristine fields. Visit each registration once even in cycles.
|
|
179
|
+
function dependentFields(names) {
|
|
180
|
+
const byDependency = new Map();
|
|
181
|
+
for (const field of fields) {
|
|
182
|
+
for (const path of field.registration?.dependencies ?? []) {
|
|
183
|
+
const key = fieldSelectionKey(formNamePath(path));
|
|
184
|
+
const group = byDependency.get(key);
|
|
185
|
+
if (group) {
|
|
186
|
+
group.push(field);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
byDependency.set(key, [field]);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const visited = new Set();
|
|
194
|
+
const result = [];
|
|
195
|
+
for (const name of names) {
|
|
196
|
+
visit(formNamePath(name));
|
|
197
|
+
}
|
|
198
|
+
return result;
|
|
199
|
+
// Preserve the registration and path at the time an edit traverses the graph.
|
|
200
|
+
function visit(namePath) {
|
|
201
|
+
const list = byDependency.get(fieldSelectionKey(namePath));
|
|
202
|
+
if (!list) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
for (const field of list) {
|
|
206
|
+
if (visited.has(field)) {
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
visited.add(field);
|
|
210
|
+
const path = fieldPath(field);
|
|
211
|
+
if (path.length && isValidationDirty(field, path)) {
|
|
212
|
+
result.push({ path, field });
|
|
213
|
+
visit(path);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
139
218
|
function rootErrors(entries) {
|
|
140
219
|
return Object.fromEntries(entries.filter((field) => field.name.length === 1)
|
|
141
220
|
.map((field) => [field.name[0], [...field.errors]]));
|
|
142
221
|
}
|
|
143
222
|
function getFieldsError(names) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
223
|
+
if (names) {
|
|
224
|
+
return names.map(name => {
|
|
225
|
+
const path = formNamePath(name);
|
|
226
|
+
const field = findField(path);
|
|
227
|
+
const messages = snapshotValidationMessages(field?.errors, field?.warnings);
|
|
228
|
+
return { name: path, ...messages };
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
return fields.map(field => ({
|
|
232
|
+
name: fieldPath(field),
|
|
233
|
+
...snapshotValidationMessages(field.errors, field.warnings)
|
|
234
|
+
}));
|
|
235
|
+
}
|
|
236
|
+
// Reads one message list so error and warning accessors keep separate reactive dependencies.
|
|
237
|
+
function getFieldMessages(name, kind) {
|
|
238
|
+
const field = findField(name);
|
|
239
|
+
return field?.[kind] ?? [];
|
|
155
240
|
}
|
|
156
241
|
function isFieldTouched(name) {
|
|
157
242
|
return fields.some((field) => containsFormPath(name, fieldPath(field)) && field.touched);
|
|
@@ -192,18 +277,14 @@ export function createForm({ initialValues, rules = {} }) {
|
|
|
192
277
|
lists.push(path);
|
|
193
278
|
continue;
|
|
194
279
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
name: [...path],
|
|
201
|
-
validated: field.validated
|
|
202
|
-
} : null;
|
|
203
|
-
if (!filter || filter(meta)) {
|
|
204
|
-
const currentValue = getFormValue(values, path);
|
|
205
|
-
result = setFormValue(result, path, currentValue);
|
|
280
|
+
if (filter) {
|
|
281
|
+
const meta = field ? fieldMeta(field, path) : null;
|
|
282
|
+
if (!filter(meta)) {
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
206
285
|
}
|
|
286
|
+
const currentValue = getFormValue(values, path);
|
|
287
|
+
result = setFormValue(result, path, currentValue);
|
|
207
288
|
}
|
|
208
289
|
for (const path of lists) {
|
|
209
290
|
if (!getFormValue(result, path)) {
|
|
@@ -228,7 +309,77 @@ export function createForm({ initialValues, rules = {} }) {
|
|
|
228
309
|
const selected = names ? selectNamedFields(names, bindings) : bindings;
|
|
229
310
|
return projectFieldValues(selected, select);
|
|
230
311
|
}
|
|
231
|
-
//
|
|
312
|
+
// All mounted observers can read the same projection without subscribing to validation metadata.
|
|
313
|
+
const watchValues = $derived(getFieldsValue());
|
|
314
|
+
// Share one immutable root per write without copying the store when there are no observers.
|
|
315
|
+
function readStoreSnapshot() {
|
|
316
|
+
if (storeListeners.size) {
|
|
317
|
+
storeSnapshot ??= untrack(() => ({ ...values }));
|
|
318
|
+
return storeSnapshot;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
// Predicates run in store order. Reads in a predicate cannot subscribe the writer's effect.
|
|
322
|
+
function notifyStoreUpdate(previous, update) {
|
|
323
|
+
if (!previous) {
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
const current = readStoreSnapshot();
|
|
327
|
+
if (current) {
|
|
328
|
+
const listeners = [...storeListeners];
|
|
329
|
+
untrack(() => {
|
|
330
|
+
for (const listener of listeners) {
|
|
331
|
+
listener(previous, current, update);
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
// The last attached Form owns callbacks for this model until its registration is released.
|
|
337
|
+
function currentCallbackProvider() {
|
|
338
|
+
return [...callbackProviders].at(-1);
|
|
339
|
+
}
|
|
340
|
+
// Build both arguments from one field snapshot, including current indexed paths in lists.
|
|
341
|
+
function publishFieldsChange(names, owner = currentCallbackProvider()) {
|
|
342
|
+
if (!names.length || !owner) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
untrack(() => {
|
|
346
|
+
if (owner !== currentCallbackProvider()) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
const onFieldsChange = owner()?.onFieldsChange;
|
|
350
|
+
if (!onFieldsChange) {
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
const allFields = [];
|
|
354
|
+
const changedFields = [];
|
|
355
|
+
for (const { path, field } of fieldBindings()) {
|
|
356
|
+
const value = getFormValue(values, path);
|
|
357
|
+
const snapshot = { ...fieldMeta(field, path), value: copyFormValue(value) };
|
|
358
|
+
Object.defineProperty(snapshot, fieldSnapshotOrigin, { value: true });
|
|
359
|
+
allFields.push(snapshot);
|
|
360
|
+
if (names.some((name) => sameFormPath(name, path))) {
|
|
361
|
+
changedFields.push(snapshot);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
if (changedFields.length) {
|
|
365
|
+
onFieldsChange(changedFields, allFields);
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
// The edited path can include data outside the projection of mounted fields, such as a list row.
|
|
370
|
+
function publishValueChange(name, dependencies) {
|
|
371
|
+
untrack(() => {
|
|
372
|
+
const onValuesChange = currentCallbackProvider()?.()?.onValuesChange;
|
|
373
|
+
if (onValuesChange) {
|
|
374
|
+
const value = getFormValue(values, name);
|
|
375
|
+
const changed = setFormValue({}, name, value);
|
|
376
|
+
const all = setFormValue(getFieldsValue(), name, value);
|
|
377
|
+
onValuesChange(changed, all);
|
|
378
|
+
}
|
|
379
|
+
publishFieldsChange([name, ...dependencies]);
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
// Releases a waiting debounce timer or dependency frame when its field is superseded.
|
|
232
383
|
function cancelValidationDelay(field) {
|
|
233
384
|
const cancel = validationDelays.get(field);
|
|
234
385
|
if (!cancel) {
|
|
@@ -237,22 +388,36 @@ export function createForm({ initialValues, rules = {} }) {
|
|
|
237
388
|
cancel();
|
|
238
389
|
return true;
|
|
239
390
|
}
|
|
240
|
-
//
|
|
391
|
+
// Resolves true when the scheduled wait elapses, or false when the owner cancels it.
|
|
241
392
|
function delayValidation(field, delay) {
|
|
242
393
|
return new Promise((resolve) => {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
394
|
+
let cancel;
|
|
395
|
+
function finish(elapsed) {
|
|
396
|
+
if (validationDelays.get(field) === cancel) {
|
|
397
|
+
validationDelays.delete(field);
|
|
398
|
+
}
|
|
399
|
+
resolve(elapsed);
|
|
400
|
+
}
|
|
401
|
+
if (delay === 'frame' && typeof requestAnimationFrame === 'function'
|
|
402
|
+
&& typeof cancelAnimationFrame === 'function') {
|
|
403
|
+
const frame = requestAnimationFrame(() => finish(true));
|
|
404
|
+
cancel = () => {
|
|
405
|
+
cancelAnimationFrame(frame);
|
|
406
|
+
finish(false);
|
|
407
|
+
};
|
|
408
|
+
validationDelays.set(field, cancel);
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
const timer = setTimeout(() => finish(true), delay === 'frame' ? 0 : delay);
|
|
412
|
+
cancel = () => {
|
|
248
413
|
clearTimeout(timer);
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
414
|
+
finish(false);
|
|
415
|
+
};
|
|
416
|
+
validationDelays.set(field, cancel);
|
|
252
417
|
});
|
|
253
418
|
}
|
|
254
419
|
// Runs selected checks at the same time and rejects an outdated shot.
|
|
255
|
-
async function validate(selected, validateOnly = false,
|
|
420
|
+
async function validate(selected, { source, validateOnly = false, trigger, changedList }) {
|
|
256
421
|
if (!validateOnly) {
|
|
257
422
|
for (const field of selected) {
|
|
258
423
|
if (cancelValidationDelay(field)) {
|
|
@@ -266,13 +431,18 @@ export function createForm({ initialValues, rules = {} }) {
|
|
|
266
431
|
const validationRun = ++validationSequence;
|
|
267
432
|
// Promises share freshness tracking. validateOnly leaves the visible validation's field.run unchanged.
|
|
268
433
|
latestValidationRun = validationRun;
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
hasRules
|
|
274
|
-
|
|
275
|
-
|
|
434
|
+
const publishesChanges = source !== 'refresh' || changedList !== undefined;
|
|
435
|
+
const callbacks = publishesChanges ? currentCallbackProvider() : undefined;
|
|
436
|
+
const entries = selected.map((field) => {
|
|
437
|
+
const hasRules = fieldRules(field).length > 0;
|
|
438
|
+
const publishes = Boolean(callbacks && hasRules && (!changedList || changedList === field));
|
|
439
|
+
const event = source === 'control' ? trigger : field === changedList ? 'onChange' : undefined;
|
|
440
|
+
const debounced = source === 'refresh' || (source === 'control' && !!event);
|
|
441
|
+
return {
|
|
442
|
+
field, path: fieldPath(field), run: field.run, hasRules, publishes, event,
|
|
443
|
+
delay: debounced ? field.registration?.validateDebounce : undefined
|
|
444
|
+
};
|
|
445
|
+
});
|
|
276
446
|
if (!validateOnly) {
|
|
277
447
|
for (const { field, hasRules } of entries) {
|
|
278
448
|
if (!hasRules) {
|
|
@@ -283,13 +453,45 @@ export function createForm({ initialValues, rules = {} }) {
|
|
|
283
453
|
}
|
|
284
454
|
field.run = validationRun;
|
|
285
455
|
field.validating = true;
|
|
456
|
+
if (source === 'control' || source === 'dependency' || field === changedList) {
|
|
457
|
+
field.errors = [];
|
|
458
|
+
}
|
|
286
459
|
field.warnings = [];
|
|
287
460
|
field.dirty = true;
|
|
288
461
|
field.validated = false;
|
|
289
462
|
notifyFieldMeta(field);
|
|
290
463
|
}
|
|
291
464
|
}
|
|
292
|
-
|
|
465
|
+
let results;
|
|
466
|
+
try {
|
|
467
|
+
if (callbacks) {
|
|
468
|
+
const started = entries.filter((entry) => entry.publishes).map(({ path }) => path);
|
|
469
|
+
publishFieldsChange(started, callbacks);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
finally {
|
|
473
|
+
// A throwing listener must not leave validation pending forever.
|
|
474
|
+
results = await Promise.all(entries.map(validateEntry));
|
|
475
|
+
}
|
|
476
|
+
if ((callbacks || storeListeners.size) && valuesRevision === snapshotRevision) {
|
|
477
|
+
const validatedPaths = [];
|
|
478
|
+
const completed = [];
|
|
479
|
+
for (const [index, entry] of entries.entries()) {
|
|
480
|
+
const { field, path, run, hasRules, publishes } = entry;
|
|
481
|
+
if (hasRules && !results[index].cancelled && field.run === (validateOnly ? run : validationRun)
|
|
482
|
+
&& fields.includes(field) && sameFormPath(path, fieldPath(field))) {
|
|
483
|
+
validatedPaths.push(path);
|
|
484
|
+
if (publishes)
|
|
485
|
+
completed.push(path);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
if (storeListeners.size && (validatedPaths.length || entries.every(entry => !entry.hasRules))) {
|
|
489
|
+
notifyStoreUpdate(readStoreSnapshot(), { type: 'validateFinish', names: validatedPaths });
|
|
490
|
+
}
|
|
491
|
+
if (callbacks && valuesRevision === snapshotRevision) {
|
|
492
|
+
publishFieldsChange(completed, callbacks);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
293
495
|
const nextErrors = results.filter((field) => field.errors.length);
|
|
294
496
|
const outOfDate = latestValidationRun !== validationRun || valuesRevision !== snapshotRevision
|
|
295
497
|
|| results.some((result) => result.cancelled)
|
|
@@ -299,12 +501,27 @@ export function createForm({ initialValues, rules = {} }) {
|
|
|
299
501
|
throw new FormValidationError(snapshot, rootErrors(nextErrors), outOfDate, nextErrors);
|
|
300
502
|
}
|
|
301
503
|
return snapshot;
|
|
302
|
-
//
|
|
303
|
-
// the
|
|
304
|
-
async function validateEntry({ field, path, hasRules, delay }) {
|
|
504
|
+
// A control event publishes pending metadata before the control finishes its own handler.
|
|
505
|
+
// Dependent rule factories run after the UI has had a frame to apply changes from the edit.
|
|
506
|
+
async function validateEntry({ field, path, hasRules, delay, event }) {
|
|
305
507
|
if (!hasRules) {
|
|
306
508
|
return { name: path, errors: [], warnings: [] };
|
|
307
509
|
}
|
|
510
|
+
if (source === 'dependency') {
|
|
511
|
+
if (!isCurrent(field, path)) {
|
|
512
|
+
return cancelledEntry(field, path);
|
|
513
|
+
}
|
|
514
|
+
const elapsed = await delayValidation(field, 'frame');
|
|
515
|
+
if (!elapsed || !isCurrent(field, path)) {
|
|
516
|
+
return cancelledEntry(field, path);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
else if (source === 'control') {
|
|
520
|
+
await tick();
|
|
521
|
+
if (!isCurrent(field, path)) {
|
|
522
|
+
return cancelledEntry(field, path);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
308
525
|
let rules;
|
|
309
526
|
try {
|
|
310
527
|
rules = resolveValidationRules(fieldRules(field), form);
|
|
@@ -316,6 +533,9 @@ export function createForm({ initialValues, rules = {} }) {
|
|
|
316
533
|
}
|
|
317
534
|
throw error;
|
|
318
535
|
}
|
|
536
|
+
if (event) {
|
|
537
|
+
rules = rules.filter(({ validateTrigger }) => !validateTrigger || allowsValidationTrigger(validateTrigger, event));
|
|
538
|
+
}
|
|
319
539
|
const messageContext = {
|
|
320
540
|
name: path.map(String).join('.'),
|
|
321
541
|
variables: { label: path.map(String).join('.'), ...field.registration?.messageVariables },
|
|
@@ -323,14 +543,12 @@ export function createForm({ initialValues, rules = {} }) {
|
|
|
323
543
|
};
|
|
324
544
|
const validateFirst = field.registration?.validateFirst;
|
|
325
545
|
if (delay) {
|
|
546
|
+
if (!isCurrent(field, path)) {
|
|
547
|
+
return cancelledEntry(field, path);
|
|
548
|
+
}
|
|
326
549
|
const elapsed = await delayValidation(field, delay);
|
|
327
|
-
if (!elapsed || field
|
|
328
|
-
|
|
329
|
-
if (field.run === validationRun) {
|
|
330
|
-
field.validating = false;
|
|
331
|
-
notifyFieldMeta(field);
|
|
332
|
-
}
|
|
333
|
-
return { name: path, errors: [], warnings: [], cancelled: true };
|
|
550
|
+
if (!elapsed || !isCurrent(field, path)) {
|
|
551
|
+
return cancelledEntry(field, path);
|
|
334
552
|
}
|
|
335
553
|
}
|
|
336
554
|
const value = getFormValue(snapshot, path);
|
|
@@ -338,13 +556,26 @@ export function createForm({ initialValues, rules = {} }) {
|
|
|
338
556
|
if (!validateOnly && field.run === validationRun) {
|
|
339
557
|
field.validating = false;
|
|
340
558
|
if (valuesRevision === snapshotRevision && sameFormPath(path, fieldPath(field))) {
|
|
341
|
-
field.errors = messages.errors;
|
|
342
|
-
field.warnings = messages.warnings;
|
|
559
|
+
field.errors = copyValidationMessages(messages.errors);
|
|
560
|
+
field.warnings = copyValidationMessages(messages.warnings);
|
|
343
561
|
field.validated = true;
|
|
344
562
|
}
|
|
345
563
|
notifyFieldMeta(field);
|
|
346
564
|
}
|
|
347
|
-
return { name: path, ...messages };
|
|
565
|
+
return { name: path, ...snapshotValidationMessages(messages.errors, messages.warnings) };
|
|
566
|
+
}
|
|
567
|
+
// A pending timer or frame cannot continue with another value or a reassigned list row.
|
|
568
|
+
function isCurrent(field, path) {
|
|
569
|
+
return field.run === validationRun && valuesRevision === snapshotRevision
|
|
570
|
+
&& fieldRegistry.has(field) && sameFormPath(path, fieldPath(field));
|
|
571
|
+
}
|
|
572
|
+
// Only clear the pending flag if a newer check has not claimed this field.
|
|
573
|
+
function cancelledEntry(field, path) {
|
|
574
|
+
if (field.run === validationRun) {
|
|
575
|
+
field.validating = false;
|
|
576
|
+
notifyFieldMeta(field);
|
|
577
|
+
}
|
|
578
|
+
return { name: path, errors: [], warnings: [], cancelled: true };
|
|
348
579
|
}
|
|
349
580
|
}
|
|
350
581
|
// Selects registered fields, descendants of the prefix or obvious paths.
|
|
@@ -364,28 +595,111 @@ export function createForm({ initialValues, rules = {} }) {
|
|
|
364
595
|
}
|
|
365
596
|
}
|
|
366
597
|
if (settings?.dirty) {
|
|
367
|
-
selected = selected.filter((field) => field
|
|
368
|
-
|| field.registration?.initialValue !== undefined
|
|
369
|
-
|| getFormValue(defaults, fieldPath(field)) !== undefined);
|
|
598
|
+
selected = selected.filter((field) => isValidationDirty(field));
|
|
370
599
|
}
|
|
371
|
-
return validate(selected, settings?.validateOnly);
|
|
600
|
+
return validate(selected, { source: 'explicit', validateOnly: settings?.validateOnly });
|
|
372
601
|
}
|
|
373
|
-
//
|
|
374
|
-
function
|
|
375
|
-
|
|
602
|
+
// Automatic checks keep validation errors in the model; programming errors still surface.
|
|
603
|
+
function validateAutomatically(selected, request) {
|
|
604
|
+
void validate(selected, request).catch((error) => {
|
|
605
|
+
if (!(error instanceof FormValidationError)) {
|
|
606
|
+
throw error;
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
// A declared event or dependency opts a binding into the control validation path.
|
|
611
|
+
function usesControlValidation(field) {
|
|
612
|
+
const registration = field.registration;
|
|
613
|
+
return controlDrivenFields.has(field) || registration?.validateTrigger !== undefined
|
|
614
|
+
|| registration?.dependencies !== undefined;
|
|
615
|
+
}
|
|
616
|
+
// Checks the field's event configuration before individual rules are filtered.
|
|
617
|
+
function validateControlEvent(field, trigger, sharedPath) {
|
|
618
|
+
const triggers = field.registration?.validateTrigger ?? 'onChange';
|
|
619
|
+
if (!allowsValidationTrigger(triggers, trigger) || !fieldRules(field).length) {
|
|
376
620
|
return;
|
|
377
621
|
}
|
|
378
|
-
const selected = fields.filter((
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
622
|
+
const selected = sharedPath === undefined ? [field] : fields.filter((candidate) => sameFormPath(sharedPath, fieldPath(candidate)));
|
|
623
|
+
validateAutomatically(selected, { source: 'control', trigger });
|
|
624
|
+
}
|
|
625
|
+
// Dispatches through the originating editor and reports when it must receive the committed value.
|
|
626
|
+
function handleFieldEvent(mountKey, event, args) {
|
|
627
|
+
const field = findFieldByMountKey(mountKey);
|
|
628
|
+
const registration = field?.registration;
|
|
629
|
+
if (!field || !registration) {
|
|
630
|
+
return false;
|
|
631
|
+
}
|
|
632
|
+
const name = fieldPath(field);
|
|
633
|
+
const writesValue = event === (registration.trigger ?? 'onChange');
|
|
634
|
+
controlDrivenFields.add(field);
|
|
635
|
+
if (writesValue) {
|
|
636
|
+
applyControlValue(field, name, () => {
|
|
637
|
+
const extract = registration.getValueFromEvent;
|
|
638
|
+
if (extract) {
|
|
639
|
+
return extract(...args);
|
|
383
640
|
}
|
|
641
|
+
return readFormControlValue(registration.valuePropName ?? 'value', args);
|
|
384
642
|
});
|
|
385
643
|
}
|
|
644
|
+
validateControlEvent(field, event, name);
|
|
645
|
+
return writesValue;
|
|
646
|
+
}
|
|
647
|
+
// Returns the affected paths so a control edit can include them in its field-change callback.
|
|
648
|
+
function startDependentValidation(names) {
|
|
649
|
+
const dependents = untrack(() => dependentFields(names));
|
|
650
|
+
if (dependents.length) {
|
|
651
|
+
validateAutomatically(dependents.map(({ field }) => field), { source: 'dependency' });
|
|
652
|
+
}
|
|
653
|
+
return dependents.map(({ path }) => path);
|
|
654
|
+
}
|
|
655
|
+
// Dependent fields enter validation before either value-change callback sees the new store.
|
|
656
|
+
function publishControlEdit(name, previous) {
|
|
657
|
+
notifyStoreUpdate(previous, { type: 'valueUpdate', source: 'internal', names: [name] });
|
|
658
|
+
const dependents = startDependentValidation([name]);
|
|
659
|
+
notifyStoreUpdate(previous, { type: 'dependenciesUpdate', names: [name, ...dependents] });
|
|
660
|
+
publishValueChange(name, dependents);
|
|
661
|
+
}
|
|
662
|
+
// Compatibility for manually wired fields, including list paths that change after a flush.
|
|
663
|
+
function revalidateTouched({ explicitTouch = false, changedList } = {}) {
|
|
664
|
+
if (isSubmitting) {
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
const selected = fields.filter((field) => {
|
|
668
|
+
if (field === changedList) {
|
|
669
|
+
return allowsValidationTrigger(field.registration?.validateTrigger ?? 'onChange', 'onChange');
|
|
670
|
+
}
|
|
671
|
+
return field.touched && (explicitTouch || !usesControlValidation(field));
|
|
672
|
+
});
|
|
673
|
+
if (selected.length) {
|
|
674
|
+
validateAutomatically(selected, { source: 'refresh', changedList });
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
function markTouched(field) {
|
|
678
|
+
field.touched = true;
|
|
679
|
+
field.dirty = true;
|
|
680
|
+
notifyFieldMeta(field);
|
|
681
|
+
}
|
|
682
|
+
// Touch precedes extraction and normalization. Validation uses the value committed by this edit.
|
|
683
|
+
function applyControlValue(field, name, readValue) {
|
|
684
|
+
markTouched(field);
|
|
685
|
+
const previous = getFormValue(values, name);
|
|
686
|
+
const value = readValue();
|
|
687
|
+
const normalize = field.registration?.normalize;
|
|
688
|
+
// Keep the old root while preserving field identities for the synchronous normalizer.
|
|
689
|
+
const nextValue = normalize ? normalize(value, previous, { ...values }) : value;
|
|
690
|
+
if (previous === nextValue) {
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
const previousStore = readStoreSnapshot();
|
|
694
|
+
const next = setFormValue(values, name, nextValue);
|
|
695
|
+
updateValues(next);
|
|
696
|
+
valuesRevision++;
|
|
697
|
+
submissionError = undefined;
|
|
698
|
+
publishControlEdit(name, previousStore);
|
|
386
699
|
}
|
|
387
700
|
// Updates the current proxy keys by saving the model’s reader links.
|
|
388
701
|
function updateValues(next) {
|
|
702
|
+
storeSnapshot = undefined;
|
|
389
703
|
// Svelte lists inherited names only in the presence of own property in the original target.
|
|
390
704
|
if (Object.keys(next).some((name) => !Object.hasOwn(values, name)
|
|
391
705
|
&& Object.hasOwn(Object.prototype, name))) {
|
|
@@ -400,6 +714,69 @@ export function createForm({ initialValues, rules = {} }) {
|
|
|
400
714
|
values[name] = next[name];
|
|
401
715
|
}
|
|
402
716
|
}
|
|
717
|
+
// A field batch applies values and metadata in the caller's order without validating.
|
|
718
|
+
function applyFieldUpdates(updates, controlled) {
|
|
719
|
+
const previousStore = readStoreSnapshot();
|
|
720
|
+
for (const update of updates) {
|
|
721
|
+
const { name, ...data } = update;
|
|
722
|
+
const hasValue = 'value' in data;
|
|
723
|
+
if (hasValue) {
|
|
724
|
+
const next = setFormValue(values, name, data.value);
|
|
725
|
+
const changed = !sameFormValue(values, next);
|
|
726
|
+
// Equal controlled echoes can read their data from the store itself.
|
|
727
|
+
if (!controlled || changed) {
|
|
728
|
+
updateValues(next);
|
|
729
|
+
}
|
|
730
|
+
else {
|
|
731
|
+
storeSnapshot = undefined;
|
|
732
|
+
}
|
|
733
|
+
if (changed) {
|
|
734
|
+
valuesRevision++;
|
|
735
|
+
submissionError = undefined;
|
|
736
|
+
for (const field of fields) {
|
|
737
|
+
if (containsFormPath(name, fieldPath(field))) {
|
|
738
|
+
cancelValidationDelay(field);
|
|
739
|
+
field.run = ++validationSequence;
|
|
740
|
+
const wasValidating = field.validating;
|
|
741
|
+
field.validating = false;
|
|
742
|
+
if (wasValidating)
|
|
743
|
+
notifyFieldMeta(field);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
const keepValidator = controlled && Object.hasOwn(update, fieldSnapshotOrigin);
|
|
749
|
+
for (const field of fields) {
|
|
750
|
+
if (!sameFormPath(name, fieldPath(field))
|
|
751
|
+
|| (!field.registration && !fieldRules(field).length)) {
|
|
752
|
+
continue;
|
|
753
|
+
}
|
|
754
|
+
if ('touched' in update)
|
|
755
|
+
field.touched = !!update.touched;
|
|
756
|
+
if ('validating' in update && !keepValidator) {
|
|
757
|
+
cancelValidationDelay(field);
|
|
758
|
+
field.run = ++validationSequence;
|
|
759
|
+
field.validating = !!update.validating;
|
|
760
|
+
field.validated = !field.validating;
|
|
761
|
+
}
|
|
762
|
+
if ('errorMessages' in update) {
|
|
763
|
+
field.errors = copyValidationMessages(update.errorMessages ?? []);
|
|
764
|
+
}
|
|
765
|
+
else if ('errors' in update) {
|
|
766
|
+
field.errors = [...(update.errors ?? [])];
|
|
767
|
+
}
|
|
768
|
+
if ('warningMessages' in update) {
|
|
769
|
+
field.warnings = copyValidationMessages(update.warningMessages ?? []);
|
|
770
|
+
}
|
|
771
|
+
else if ('warnings' in update) {
|
|
772
|
+
field.warnings = [...(update.warnings ?? [])];
|
|
773
|
+
}
|
|
774
|
+
field.dirty = true;
|
|
775
|
+
notifyFieldMeta(field);
|
|
776
|
+
}
|
|
777
|
+
notifyStoreUpdate(previousStore, { type: 'setField', name, hasValue });
|
|
778
|
+
}
|
|
779
|
+
}
|
|
403
780
|
// Purifies the result of the field and deprives the previous verification of the right to publish.
|
|
404
781
|
function clearField(field) {
|
|
405
782
|
cancelValidationDelay(field);
|
|
@@ -409,6 +786,197 @@ export function createForm({ initialValues, rules = {} }) {
|
|
|
409
786
|
field.run = ++validationSequence;
|
|
410
787
|
notifyFieldMeta(field);
|
|
411
788
|
}
|
|
789
|
+
// Resets flags and messages and releases work owned by the previous field lifetime.
|
|
790
|
+
function resetFieldMetadata(field) {
|
|
791
|
+
cancelValidationDelay(field);
|
|
792
|
+
field.errors = undefined;
|
|
793
|
+
field.warnings = undefined;
|
|
794
|
+
field.touched = false;
|
|
795
|
+
field.dirty = false;
|
|
796
|
+
field.validating = false;
|
|
797
|
+
field.validated = false;
|
|
798
|
+
field.run = ++validationSequence;
|
|
799
|
+
}
|
|
800
|
+
/** Clears each field's metadata immediately before that field's reset callback. */
|
|
801
|
+
function resetBindings(selected, includeObservers) {
|
|
802
|
+
const targets = selected.map(field => ({
|
|
803
|
+
order: field.mountOrder ?? 0,
|
|
804
|
+
field
|
|
805
|
+
}));
|
|
806
|
+
if (includeObservers) {
|
|
807
|
+
for (const [order, reset] of resetObservers) {
|
|
808
|
+
targets.push({ order, reset });
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
targets.sort((first, second) => first.order - second.order);
|
|
812
|
+
for (const target of targets) {
|
|
813
|
+
if ('field' in target) {
|
|
814
|
+
const { field } = target;
|
|
815
|
+
resetFieldMetadata(field);
|
|
816
|
+
notifyFieldMeta(field);
|
|
817
|
+
field.registration?.onReset?.();
|
|
818
|
+
}
|
|
819
|
+
else {
|
|
820
|
+
target.reset();
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
// Discard after the Svelte flush so sibling registrations and keyed list moves are visible.
|
|
825
|
+
function scheduleFieldRemoval(registration) {
|
|
826
|
+
if (registration.preserve !== false) {
|
|
827
|
+
return;
|
|
828
|
+
}
|
|
829
|
+
const path = formNamePath(registration.name);
|
|
830
|
+
const resolvePath = registration.isListField ? registration.getRemovalPath : () => path;
|
|
831
|
+
if (!resolvePath) {
|
|
832
|
+
return;
|
|
833
|
+
}
|
|
834
|
+
if (!pendingRemovals.length) {
|
|
835
|
+
queueMicrotask(discardUnmountedValues);
|
|
836
|
+
}
|
|
837
|
+
pendingRemovals.push({ resolvePath, isListField: registration.isListField });
|
|
838
|
+
}
|
|
839
|
+
// A restored parent represents its whole initial value, including nested list entries.
|
|
840
|
+
function discardUnmountedValues() {
|
|
841
|
+
const removals = pendingRemovals.splice(0);
|
|
842
|
+
if (!removals.length) {
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
const mountedPaths = new Set();
|
|
846
|
+
for (const field of fieldRegistry) {
|
|
847
|
+
if (field.registration) {
|
|
848
|
+
mountedPaths.add(fieldSelectionKey(fieldPath(field)));
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
const updates = new Map();
|
|
852
|
+
for (const { resolvePath, isListField } of removals) {
|
|
853
|
+
const path = resolvePath((name) => getFormValue(values, name));
|
|
854
|
+
if (!path?.length) {
|
|
855
|
+
continue;
|
|
856
|
+
}
|
|
857
|
+
const key = fieldSelectionKey(path);
|
|
858
|
+
if (mountedPaths.has(key)) {
|
|
859
|
+
continue;
|
|
860
|
+
}
|
|
861
|
+
const value = isListField ? undefined : getFormValue(defaults, path);
|
|
862
|
+
if (!Object.is(getFormValue(values, path), value)) {
|
|
863
|
+
updates.set(key, { path, value });
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
let next = values;
|
|
867
|
+
const restored = [];
|
|
868
|
+
const ordered = [...updates.values()].sort((first, second) => first.path.length - second.path.length);
|
|
869
|
+
for (const { path, value } of ordered) {
|
|
870
|
+
if (!restored.some((parent) => containsFormPath(parent, path))) {
|
|
871
|
+
next = setFormValue(next, path, value, true);
|
|
872
|
+
restored.push(path);
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
if (next === values) {
|
|
876
|
+
return;
|
|
877
|
+
}
|
|
878
|
+
const previous = readStoreSnapshot();
|
|
879
|
+
updateValues(next);
|
|
880
|
+
valuesRevision++;
|
|
881
|
+
submissionError = undefined;
|
|
882
|
+
notifyStoreUpdate(previous, { type: 'remove', names: restored });
|
|
883
|
+
if (mountedForms) {
|
|
884
|
+
const names = ordered.map(({ path }) => path);
|
|
885
|
+
const dependents = startDependentValidation(names);
|
|
886
|
+
notifyStoreUpdate(previous, { type: 'dependenciesUpdate', names: [...names, ...dependents] });
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
// Clearing the last owner invalidates work from that attachment and defers defaults until remount.
|
|
890
|
+
function clearDetachedForm() {
|
|
891
|
+
storeLifetime++;
|
|
892
|
+
pendingRemovals.length = 0;
|
|
893
|
+
latestValidationRun = ++validationSequence;
|
|
894
|
+
for (const field of fieldRegistry) {
|
|
895
|
+
resetFieldMetadata(field);
|
|
896
|
+
}
|
|
897
|
+
storeSnapshot = undefined;
|
|
898
|
+
values = {};
|
|
899
|
+
valuesRevision++;
|
|
900
|
+
submissionRevision++;
|
|
901
|
+
isSubmitting = false;
|
|
902
|
+
submissionError = undefined;
|
|
903
|
+
restoreDefaultsOnMount = true;
|
|
904
|
+
}
|
|
905
|
+
// Form defaults take priority on reset. Connecting a model fills gaps beneath its current store.
|
|
906
|
+
function setInitialValues(initial, seed) {
|
|
907
|
+
defaults = initial === undefined ? modelDefaults : mergeFormValues(modelDefaults, initial);
|
|
908
|
+
if (!seed) {
|
|
909
|
+
return;
|
|
910
|
+
}
|
|
911
|
+
untrack(() => {
|
|
912
|
+
if (initial === undefined && !restoreDefaultsOnMount) {
|
|
913
|
+
return;
|
|
914
|
+
}
|
|
915
|
+
restoreDefaultsOnMount = false;
|
|
916
|
+
const next = mergeFormValues(defaults, values);
|
|
917
|
+
if (!sameFormValue(values, next)) {
|
|
918
|
+
updateValues(next);
|
|
919
|
+
valuesRevision++;
|
|
920
|
+
}
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
let submit = wrapSubmission(submitWithFinish);
|
|
924
|
+
/** Each read keeps its delegate when a caller wraps the callback-based submission method. */
|
|
925
|
+
function wrapSubmission(run) {
|
|
926
|
+
function submit(onFinish) {
|
|
927
|
+
if (typeof onFinish === 'function') {
|
|
928
|
+
return run.call(form, onFinish);
|
|
929
|
+
}
|
|
930
|
+
const provider = currentCallbackProvider();
|
|
931
|
+
const attachedSubmit = provider?.()?.submit;
|
|
932
|
+
if (attachedSubmit) {
|
|
933
|
+
attachedSubmit();
|
|
934
|
+
}
|
|
935
|
+
else {
|
|
936
|
+
void run.call(form, () => { });
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
return submit;
|
|
940
|
+
}
|
|
941
|
+
async function submitWithFinish(onFinish) {
|
|
942
|
+
if (isSubmitting) {
|
|
943
|
+
return { status: 'busy' };
|
|
944
|
+
}
|
|
945
|
+
const callbacks = currentCallbackProvider();
|
|
946
|
+
const revision = ++submissionRevision;
|
|
947
|
+
isSubmitting = true;
|
|
948
|
+
submissionError = undefined;
|
|
949
|
+
for (const field of fields) {
|
|
950
|
+
field.touched = true;
|
|
951
|
+
notifyFieldMeta(field);
|
|
952
|
+
}
|
|
953
|
+
try {
|
|
954
|
+
const result = await validateFields();
|
|
955
|
+
if (revision !== submissionRevision) {
|
|
956
|
+
const error = new FormValidationError(result, {}, true);
|
|
957
|
+
return { status: 'invalid', error };
|
|
958
|
+
}
|
|
959
|
+
if (callbacks && callbacks === currentCallbackProvider()) {
|
|
960
|
+
callbacks()?.onProviderFinish?.(result);
|
|
961
|
+
}
|
|
962
|
+
await onFinish(result);
|
|
963
|
+
return { status: 'success' };
|
|
964
|
+
}
|
|
965
|
+
catch (error) {
|
|
966
|
+
if (error instanceof FormValidationError) {
|
|
967
|
+
return { status: 'invalid', error };
|
|
968
|
+
}
|
|
969
|
+
if (revision === submissionRevision) {
|
|
970
|
+
submissionError = error;
|
|
971
|
+
}
|
|
972
|
+
return { status: 'failed', error };
|
|
973
|
+
}
|
|
974
|
+
finally {
|
|
975
|
+
if (revision === submissionRevision) {
|
|
976
|
+
isSubmitting = false;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
}
|
|
412
980
|
const form = {
|
|
413
981
|
get values() {
|
|
414
982
|
void valuesRevision;
|
|
@@ -416,7 +984,10 @@ export function createForm({ initialValues, rules = {} }) {
|
|
|
416
984
|
},
|
|
417
985
|
get errors() {
|
|
418
986
|
return rootErrors(fields.filter((field) => field.errors !== undefined)
|
|
419
|
-
.map(
|
|
987
|
+
.map(field => ({
|
|
988
|
+
name: fieldPath(field),
|
|
989
|
+
errors: validationMessageTexts(field.errors ?? [])
|
|
990
|
+
})));
|
|
420
991
|
},
|
|
421
992
|
get isSubmitting() {
|
|
422
993
|
return isSubmitting;
|
|
@@ -432,13 +1003,11 @@ export function createForm({ initialValues, rules = {} }) {
|
|
|
432
1003
|
getFieldsError,
|
|
433
1004
|
// An unknown path returns an empty list, like a field without errors.
|
|
434
1005
|
getFieldError(name) {
|
|
435
|
-
|
|
436
|
-
return field?.errors ?? [];
|
|
1006
|
+
return validationMessageTexts(getFieldMessages(name, 'errors'));
|
|
437
1007
|
},
|
|
438
1008
|
// Warnings are read separately from the errors that block submitted.
|
|
439
1009
|
getFieldWarning(name) {
|
|
440
|
-
|
|
441
|
-
return field?.warnings ?? [];
|
|
1010
|
+
return validationMessageTexts(getFieldMessages(name, 'warnings'));
|
|
442
1011
|
},
|
|
443
1012
|
getFieldInstance(name) {
|
|
444
1013
|
const registration = controlRegistration(name);
|
|
@@ -468,11 +1037,34 @@ export function createForm({ initialValues, rules = {} }) {
|
|
|
468
1037
|
return field ? resolveValidationRules(fieldRules(field), form)
|
|
469
1038
|
.some((rule) => rule.required && !rule.warningOnly) : false;
|
|
470
1039
|
},
|
|
1040
|
+
changeFieldValue(name, value, trigger = 'onChange') {
|
|
1041
|
+
const field = ensureField(name);
|
|
1042
|
+
controlDrivenFields.add(field);
|
|
1043
|
+
applyControlValue(field, name, () => value);
|
|
1044
|
+
validateControlEvent(field, trigger);
|
|
1045
|
+
},
|
|
1046
|
+
validateFieldOn(name, trigger) {
|
|
1047
|
+
const field = findField(name);
|
|
1048
|
+
if (field) {
|
|
1049
|
+
controlDrivenFields.add(field);
|
|
1050
|
+
validateControlEvent(field, trigger);
|
|
1051
|
+
}
|
|
1052
|
+
},
|
|
471
1053
|
setFieldValue(name, value) {
|
|
1054
|
+
const previous = readStoreSnapshot();
|
|
472
1055
|
if (Object.is(getFormValue(values, name), value)) {
|
|
473
1056
|
const field = findField(name);
|
|
474
1057
|
if (field)
|
|
475
1058
|
field.dirty = true;
|
|
1059
|
+
// An explicit undefined entry can suppress a default when a Form attaches later.
|
|
1060
|
+
if (value === undefined && !hasFormValue(values, formNamePath(name))) {
|
|
1061
|
+
const next = setFormValue(values, name, value);
|
|
1062
|
+
updateValues(next);
|
|
1063
|
+
valuesRevision++;
|
|
1064
|
+
}
|
|
1065
|
+
// Even equal writes publish a fresh store root to predicates.
|
|
1066
|
+
storeSnapshot = undefined;
|
|
1067
|
+
notifyStoreUpdate(previous, { type: 'setField', name, hasValue: true });
|
|
476
1068
|
return;
|
|
477
1069
|
}
|
|
478
1070
|
updateValues(setFormValue(values, name, value));
|
|
@@ -485,9 +1077,11 @@ export function createForm({ initialValues, rules = {} }) {
|
|
|
485
1077
|
}
|
|
486
1078
|
valuesRevision++;
|
|
487
1079
|
submissionError = undefined;
|
|
1080
|
+
notifyStoreUpdate(previous, { type: 'setField', name, hasValue: true });
|
|
488
1081
|
revalidateTouched();
|
|
489
1082
|
},
|
|
490
1083
|
setFieldsValue(next) {
|
|
1084
|
+
const previous = readStoreSnapshot();
|
|
491
1085
|
const merged = mergeFormValues(values, next);
|
|
492
1086
|
for (const field of fields) {
|
|
493
1087
|
const path = fieldPath(field);
|
|
@@ -495,9 +1089,7 @@ export function createForm({ initialValues, rules = {} }) {
|
|
|
495
1089
|
field.dirty = true;
|
|
496
1090
|
field.validated = true;
|
|
497
1091
|
}
|
|
498
|
-
const
|
|
499
|
-
const provided = parent !== null && typeof parent === 'object'
|
|
500
|
-
&& path.length > 0 && Object.hasOwn(parent, path[path.length - 1]);
|
|
1092
|
+
const provided = hasFormValue(next, path);
|
|
501
1093
|
if (!Object.is(getFormValue(values, path), getFormValue(merged, path))
|
|
502
1094
|
|| provided) {
|
|
503
1095
|
clearField(field);
|
|
@@ -506,61 +1098,21 @@ export function createForm({ initialValues, rules = {} }) {
|
|
|
506
1098
|
updateValues(merged);
|
|
507
1099
|
valuesRevision++;
|
|
508
1100
|
submissionError = undefined;
|
|
1101
|
+
notifyStoreUpdate(previous, { type: 'valueUpdate', source: 'external' });
|
|
509
1102
|
revalidateTouched();
|
|
510
1103
|
},
|
|
511
1104
|
setFields(updates) {
|
|
512
|
-
|
|
513
|
-
const { name, ...data } = update;
|
|
514
|
-
if ('value' in data) {
|
|
515
|
-
const next = setFormValue(values, name, data.value);
|
|
516
|
-
const changed = !sameFormValue(values, next);
|
|
517
|
-
updateValues(next);
|
|
518
|
-
if (changed) {
|
|
519
|
-
valuesRevision++;
|
|
520
|
-
submissionError = undefined;
|
|
521
|
-
for (const field of fields) {
|
|
522
|
-
if (containsFormPath(name, fieldPath(field))) {
|
|
523
|
-
cancelValidationDelay(field);
|
|
524
|
-
field.run = ++validationSequence;
|
|
525
|
-
const wasValidating = field.validating;
|
|
526
|
-
field.validating = false;
|
|
527
|
-
if (wasValidating)
|
|
528
|
-
notifyFieldMeta(field);
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
for (const field of fields) {
|
|
534
|
-
if (!sameFormPath(name, fieldPath(field))
|
|
535
|
-
|| (!field.registration && !fieldRules(field).length)) {
|
|
536
|
-
continue;
|
|
537
|
-
}
|
|
538
|
-
if ('touched' in update)
|
|
539
|
-
field.touched = !!update.touched;
|
|
540
|
-
if ('validating' in update) {
|
|
541
|
-
cancelValidationDelay(field);
|
|
542
|
-
field.run = ++validationSequence;
|
|
543
|
-
field.validating = !!update.validating;
|
|
544
|
-
field.validated = !field.validating;
|
|
545
|
-
}
|
|
546
|
-
if ('errors' in update)
|
|
547
|
-
field.errors = [...(update.errors ?? [])];
|
|
548
|
-
if ('warnings' in update)
|
|
549
|
-
field.warnings = [...(update.warnings ?? [])];
|
|
550
|
-
field.dirty = true;
|
|
551
|
-
notifyFieldMeta(field);
|
|
552
|
-
}
|
|
553
|
-
}
|
|
1105
|
+
applyFieldUpdates(updates, false);
|
|
554
1106
|
},
|
|
555
1107
|
touchField(name) {
|
|
556
1108
|
const field = ensureField(name);
|
|
557
|
-
field
|
|
558
|
-
|
|
559
|
-
notifyFieldMeta(field);
|
|
560
|
-
revalidateTouched();
|
|
1109
|
+
markTouched(field);
|
|
1110
|
+
revalidateTouched({ explicitTouch: true });
|
|
561
1111
|
},
|
|
562
1112
|
resetFields(names) {
|
|
1113
|
+
const previous = readStoreSnapshot();
|
|
563
1114
|
if (names?.length === 0) {
|
|
1115
|
+
notifyStoreUpdate(previous, { type: 'reset', names });
|
|
564
1116
|
return;
|
|
565
1117
|
}
|
|
566
1118
|
const selected = names ? fields.filter((field) => names.some((name) => sameFormPath(name, fieldPath(field)))) : [...fields];
|
|
@@ -570,9 +1122,8 @@ export function createForm({ initialValues, rules = {} }) {
|
|
|
570
1122
|
next = setFormValue(next, name, getFormValue(defaults, name));
|
|
571
1123
|
}
|
|
572
1124
|
}
|
|
573
|
-
//
|
|
574
|
-
|
|
575
|
-
const initialFields = [...selected].sort((first, second) => (first.initialValueOrder ?? 0) - (second.initialValueOrder ?? 0));
|
|
1125
|
+
// React Field applies declared defaults in mount order.
|
|
1126
|
+
const initialFields = [...selected].sort((first, second) => (first.mountOrder ?? 0) - (second.mountOrder ?? 0));
|
|
576
1127
|
for (const field of initialFields) {
|
|
577
1128
|
const registration = field.registration;
|
|
578
1129
|
const path = fieldPath(field);
|
|
@@ -593,51 +1144,21 @@ export function createForm({ initialValues, rules = {} }) {
|
|
|
593
1144
|
}
|
|
594
1145
|
else {
|
|
595
1146
|
valuesRevision++;
|
|
1147
|
+
storeSnapshot = undefined;
|
|
596
1148
|
values = next;
|
|
597
1149
|
resetKey = {};
|
|
598
1150
|
}
|
|
599
|
-
for (const field of selected) {
|
|
600
|
-
cancelValidationDelay(field);
|
|
601
|
-
field.errors = undefined;
|
|
602
|
-
field.warnings = undefined;
|
|
603
|
-
field.touched = false;
|
|
604
|
-
field.dirty = false;
|
|
605
|
-
field.validating = false;
|
|
606
|
-
field.validated = false;
|
|
607
|
-
field.run = ++validationSequence;
|
|
608
|
-
notifyFieldMeta(field);
|
|
609
|
-
}
|
|
610
1151
|
submissionError = undefined;
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
1152
|
+
const includeObservers = !names || names.some(name => sameFormPath(name, []));
|
|
1153
|
+
resetBindings(selected, includeObservers);
|
|
1154
|
+
notifyStoreUpdate(previous, { type: 'reset', names });
|
|
614
1155
|
},
|
|
615
1156
|
validateFields,
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
submissionError = undefined;
|
|
622
|
-
for (const field of fields) {
|
|
623
|
-
field.touched = true;
|
|
624
|
-
notifyFieldMeta(field);
|
|
625
|
-
}
|
|
626
|
-
try {
|
|
627
|
-
const result = await validateFields();
|
|
628
|
-
await onFinish(result);
|
|
629
|
-
return { status: 'success' };
|
|
630
|
-
}
|
|
631
|
-
catch (error) {
|
|
632
|
-
if (error instanceof FormValidationError) {
|
|
633
|
-
return { status: 'invalid', error };
|
|
634
|
-
}
|
|
635
|
-
submissionError = error;
|
|
636
|
-
return { status: 'failed', error };
|
|
637
|
-
}
|
|
638
|
-
finally {
|
|
639
|
-
isSubmitting = false;
|
|
640
|
-
}
|
|
1157
|
+
get submit() {
|
|
1158
|
+
return submit;
|
|
1159
|
+
},
|
|
1160
|
+
set submit(run) {
|
|
1161
|
+
submit = wrapSubmission(run);
|
|
641
1162
|
}
|
|
642
1163
|
};
|
|
643
1164
|
// Applies initialValue only to the missing value, without subscribing to the store.
|
|
@@ -653,29 +1174,78 @@ export function createForm({ initialValues, rules = {} }) {
|
|
|
653
1174
|
get resetKey() {
|
|
654
1175
|
return resetKey;
|
|
655
1176
|
},
|
|
1177
|
+
setInitialValues,
|
|
1178
|
+
attachForm(getClearOnDestroy) {
|
|
1179
|
+
mountedForms++;
|
|
1180
|
+
return () => {
|
|
1181
|
+
mountedForms--;
|
|
1182
|
+
if (!mountedForms && getClearOnDestroy()) {
|
|
1183
|
+
clearDetachedForm();
|
|
1184
|
+
}
|
|
1185
|
+
};
|
|
1186
|
+
},
|
|
656
1187
|
registerValidateMessages(getMessages) {
|
|
657
1188
|
messageProviders.add(getMessages);
|
|
658
1189
|
return () => { messageProviders.delete(getMessages); };
|
|
659
1190
|
},
|
|
1191
|
+
registerCallbacks(getCallbacks) {
|
|
1192
|
+
callbackProviders.add(getCallbacks);
|
|
1193
|
+
return () => { callbackProviders.delete(getCallbacks); };
|
|
1194
|
+
},
|
|
1195
|
+
subscribeStoreUpdates(listener) {
|
|
1196
|
+
storeListeners.add(listener);
|
|
1197
|
+
return () => {
|
|
1198
|
+
storeListeners.delete(listener);
|
|
1199
|
+
if (!storeListeners.size)
|
|
1200
|
+
storeSnapshot = undefined;
|
|
1201
|
+
};
|
|
1202
|
+
},
|
|
1203
|
+
registerResetObserver(reset) {
|
|
1204
|
+
const order = ++fieldMountOrder;
|
|
1205
|
+
resetObservers.set(order, reset);
|
|
1206
|
+
return () => { resetObservers.delete(order); };
|
|
1207
|
+
},
|
|
1208
|
+
setControlledFields: (updates) => applyFieldUpdates(updates, true),
|
|
1209
|
+
getWatchValues: () => watchValues,
|
|
1210
|
+
getFieldMessages,
|
|
660
1211
|
getFieldMeta(name) {
|
|
661
1212
|
const field = findField(name);
|
|
662
1213
|
return field ? fieldMeta(field) : undefined;
|
|
663
1214
|
},
|
|
1215
|
+
handleFieldBlur(name) {
|
|
1216
|
+
const field = ensureField(name);
|
|
1217
|
+
if (usesControlValidation(field)) {
|
|
1218
|
+
validateControlEvent(field, 'onBlur');
|
|
1219
|
+
}
|
|
1220
|
+
else {
|
|
1221
|
+
markTouched(field);
|
|
1222
|
+
revalidateTouched();
|
|
1223
|
+
}
|
|
1224
|
+
},
|
|
1225
|
+
handleFieldEvent,
|
|
664
1226
|
initializeField: initializeFieldValue,
|
|
665
1227
|
initializeList: initializeFieldValue,
|
|
666
1228
|
markFieldMounted(mountKey) {
|
|
667
|
-
const field =
|
|
1229
|
+
const field = findFieldByMountKey(mountKey);
|
|
668
1230
|
if (field)
|
|
669
|
-
field.
|
|
1231
|
+
field.mountOrder = ++fieldMountOrder;
|
|
670
1232
|
},
|
|
671
1233
|
changeList(name, next) {
|
|
1234
|
+
const previous = readStoreSnapshot();
|
|
672
1235
|
updateValues(setFormValue(values, name, next));
|
|
673
1236
|
valuesRevision++;
|
|
674
1237
|
submissionError = undefined;
|
|
675
1238
|
const list = ensureField(name);
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
1239
|
+
if (list.registration?.validateTrigger === undefined) {
|
|
1240
|
+
clearField(list);
|
|
1241
|
+
}
|
|
1242
|
+
else {
|
|
1243
|
+
// With explicit triggers, an edit retains the manual result until validation runs again.
|
|
1244
|
+
cancelValidationDelay(list);
|
|
1245
|
+
list.run = ++validationSequence;
|
|
1246
|
+
list.validating = false;
|
|
1247
|
+
}
|
|
1248
|
+
markTouched(list);
|
|
679
1249
|
for (const field of fields) {
|
|
680
1250
|
if (field !== list && containsFormPath(name, fieldPath(field))) {
|
|
681
1251
|
cancelValidationDelay(field);
|
|
@@ -684,39 +1254,39 @@ export function createForm({ initialValues, rules = {} }) {
|
|
|
684
1254
|
notifyFieldMeta(field);
|
|
685
1255
|
}
|
|
686
1256
|
}
|
|
1257
|
+
publishControlEdit(name, previous);
|
|
687
1258
|
// The names of keyed rows will be updated with flush; the metadata remains with the previous line instance.
|
|
688
|
-
void tick().then(revalidateTouched);
|
|
1259
|
+
void tick().then(() => revalidateTouched({ changedList: list }));
|
|
689
1260
|
},
|
|
690
1261
|
registerField(registration) {
|
|
691
1262
|
return untrack(() => {
|
|
692
1263
|
initializeFieldValue(registration.name, registration.initialValue);
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
const registered = field;
|
|
1264
|
+
const registeredLifetime = storeLifetime;
|
|
1265
|
+
const available = fields.find(field => !field.registration && sameFormPath(fieldPath(field), registration.name));
|
|
1266
|
+
const registered = available ?? addField(registration.name);
|
|
697
1267
|
registered.registration = registration;
|
|
698
1268
|
registered.registrationOrder = ++registrationOrder;
|
|
699
|
-
registered.
|
|
1269
|
+
registered.mountOrder = ++fieldMountOrder;
|
|
700
1270
|
registered.metaCache = undefined;
|
|
701
1271
|
if (registered.touched || registered.validating || registered.validated
|
|
702
1272
|
|| registered.errors?.length || registered.warnings?.length) {
|
|
703
1273
|
notifyFieldMeta(registered);
|
|
704
1274
|
}
|
|
1275
|
+
if (registration.initialValue !== undefined) {
|
|
1276
|
+
notifyStoreUpdate(readStoreSnapshot(), {
|
|
1277
|
+
type: 'valueUpdate', source: 'internal', names: [registration.name]
|
|
1278
|
+
});
|
|
1279
|
+
}
|
|
705
1280
|
return () => {
|
|
1281
|
+
controlDrivenFields.delete(registered);
|
|
706
1282
|
notifyFieldMeta(registered, true);
|
|
707
1283
|
if (cancelValidationDelay(registered)) {
|
|
708
1284
|
registered.run = ++validationSequence;
|
|
709
1285
|
registered.validating = false;
|
|
710
1286
|
}
|
|
711
1287
|
if (registered.persistent) {
|
|
712
|
-
if (registration.rules !== undefined) {
|
|
713
|
-
registered
|
|
714
|
-
registered.errors = undefined;
|
|
715
|
-
registered.warnings = undefined;
|
|
716
|
-
registered.touched = false;
|
|
717
|
-
registered.dirty = false;
|
|
718
|
-
registered.validating = false;
|
|
719
|
-
registered.validated = false;
|
|
1288
|
+
if (registration.rules !== undefined || registration.preserve === false) {
|
|
1289
|
+
resetFieldMetadata(registered);
|
|
720
1290
|
}
|
|
721
1291
|
registered.registration = undefined;
|
|
722
1292
|
}
|
|
@@ -725,6 +1295,9 @@ export function createForm({ initialValues, rules = {} }) {
|
|
|
725
1295
|
fieldRegistry.delete(registered);
|
|
726
1296
|
fields = [...fieldRegistry];
|
|
727
1297
|
}
|
|
1298
|
+
if (registeredLifetime === storeLifetime) {
|
|
1299
|
+
scheduleFieldRemoval(registration);
|
|
1300
|
+
}
|
|
728
1301
|
};
|
|
729
1302
|
});
|
|
730
1303
|
}
|