@woodger/antd 0.1.1 → 0.1.2
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 +5 -2
- package/dist/alert/Alert.svelte +5 -2
- package/dist/anchor/Anchor.svelte +5 -2
- package/dist/auto-complete/AutoComplete.svelte +3 -2
- package/dist/avatar/Avatar.svelte +3 -2
- package/dist/avatar/AvatarGroup.svelte +3 -1
- package/dist/avatar/avatar.component.d.ts +7 -0
- package/dist/avatar/avatar.component.js +4 -0
- package/dist/badge/Badge.svelte +3 -2
- package/dist/badge/BadgeRibbon.svelte +3 -2
- package/dist/badge/badge.component.d.ts +7 -0
- package/dist/badge/badge.component.js +4 -0
- package/dist/border-beam/BorderBeam.svelte +5 -3
- package/dist/breadcrumb/Breadcrumb.svelte +5 -2
- package/dist/button/Button.svelte +7 -4
- package/dist/calendar/CalendarCore.svelte +3 -1
- package/dist/calendar/calendar.component.d.ts +7 -0
- package/dist/calendar/calendar.component.js +4 -0
- package/dist/card/Card.svelte +6 -3
- package/dist/card/card.component.d.ts +9 -0
- package/dist/card/card.component.js +5 -0
- package/dist/carousel/Carousel.svelte +6 -3
- package/dist/cascader/CascaderCore.svelte +8 -2
- package/dist/cascader/cascader.component.d.ts +11 -0
- package/dist/cascader/cascader.component.js +9 -0
- package/dist/cascader/cascader.types.d.ts +8 -0
- package/dist/checkbox/Checkbox.svelte +9 -4
- package/dist/checkbox/CheckboxGroup.svelte +6 -3
- package/dist/checkbox/checkbox-group.types.d.ts +2 -0
- package/dist/checkbox/checkbox.component.d.ts +7 -0
- package/dist/checkbox/checkbox.component.js +4 -0
- package/dist/collapse/Collapse.svelte +5 -2
- package/dist/collapse/collapse.engine.d.ts +1 -1
- package/dist/color-picker/ColorPicker.svelte +6 -3
- package/dist/color-picker/ColorPickerPresets.svelte +5 -3
- 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 +6 -4
- 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 +5 -2
- package/dist/drawer/Drawer.svelte +3 -2
- package/dist/dropdown/Dropdown.svelte +9 -5
- package/dist/empty/Empty.svelte +5 -2
- package/dist/flex/Flex.svelte +5 -2
- package/dist/float-button/FloatButton.svelte +6 -3
- package/dist/float-button/FloatButtonGroup.svelte +6 -3
- package/dist/float-button/float-button.component.d.ts +9 -0
- package/dist/float-button/float-button.component.js +5 -0
- package/dist/form/Form.svelte +237 -42
- package/dist/form/Form.svelte.d.ts +4 -4
- package/dist/form/FormErrorList.svelte +19 -69
- package/dist/form/FormItem.svelte +271 -62
- package/dist/form/FormItem.svelte.d.ts +31 -5
- 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/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 +32 -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 +728 -179
- package/dist/form/form.types.d.ts +117 -11
- 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 +4 -6
- package/dist/grid/Row.svelte +7 -4
- package/dist/grid/grid.svelte.d.ts +7 -0
- package/dist/grid/grid.svelte.js +30 -0
- package/dist/image/Image.svelte +147 -58
- package/dist/image/ImagePreview.svelte +280 -137
- package/dist/image/ImagePreview.svelte.d.ts +10 -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 +84 -0
- package/dist/image/ImageProgress.svelte.d.ts +13 -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 +8 -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 +39 -0
- package/dist/image/image-semantic.engine.js +61 -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 +84 -11
- package/dist/index.d.ts +51 -41
- package/dist/index.js +24 -19
- package/dist/input/Input.svelte +6 -3
- package/dist/input/InputOTP.svelte +5 -2
- package/dist/input/InputPassword.svelte +5 -1
- package/dist/input/InputSearch.svelte +6 -3
- package/dist/input/TextArea.svelte +6 -3
- package/dist/input/input.component.d.ts +13 -0
- package/dist/input/input.component.js +12 -0
- package/dist/input-number/InputNumberControl.svelte +5 -2
- package/dist/layout/Layout.svelte +5 -2
- package/dist/layout/LayoutPart.svelte +7 -2
- package/dist/layout/LayoutSider.svelte +5 -2
- package/dist/layout/layout.component.d.ts +13 -0
- package/dist/layout/layout.component.js +7 -0
- package/dist/listy/Listy.svelte +3 -2
- package/dist/masonry/Masonry.svelte +5 -3
- package/dist/mentions/Mentions.svelte +3 -2
- package/dist/mentions/mentions.component.d.ts +7 -0
- package/dist/mentions/mentions.component.js +4 -0
- package/dist/menu/Menu.svelte +7 -2
- package/dist/message/MessageHolder.svelte +3 -1
- package/dist/modal/Modal.svelte +112 -14
- package/dist/modal/ModalFooterScope.svelte +15 -0
- package/dist/modal/ModalFooterScope.svelte.d.ts +7 -0
- 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 +1 -1
- package/dist/modal/modal.types.d.ts +3 -1
- package/dist/notification/NotificationHolder.svelte +3 -1
- package/dist/pagination/Pagination.svelte +3 -2
- package/dist/picker/DatePicker.svelte.d.ts +1 -1
- package/dist/picker/RangePickerCore.svelte +3 -1
- package/dist/picker/SinglePicker.svelte +3 -1
- package/dist/picker/picker-popup.model.svelte.d.ts +3 -1
- package/dist/picker/time-picker.component.d.ts +4 -1
- package/dist/picker/time-picker.component.js +3 -1
- package/dist/popconfirm/Popconfirm.svelte +6 -1
- package/dist/popconfirm/popconfirm.types.d.ts +2 -0
- package/dist/popover/Popover.svelte +31 -13
- package/dist/popover/popover.types.d.ts +2 -0
- 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-geometry.dom.d.ts +8 -0
- package/dist/popup/popup-geometry.dom.js +29 -0
- package/dist/popup/popup.dom.d.ts +3 -0
- package/dist/popup/popup.dom.js +3 -1
- package/dist/progress/Progress.svelte +5 -2
- package/dist/progress/progress-circle.engine.d.ts +1 -1
- package/dist/qr-code/QRCode.svelte +5 -3
- package/dist/radio/Radio.svelte +9 -4
- package/dist/radio/RadioGroup.svelte +6 -3
- package/dist/radio/radio.component.d.ts +9 -0
- package/dist/radio/radio.component.js +5 -0
- package/dist/rate/Rate.svelte +3 -2
- package/dist/result/Result.svelte +5 -2
- package/dist/segmented/Segmented.svelte +5 -2
- package/dist/select/Select.svelte +3 -2
- package/dist/select/select-style.engine.d.ts +1 -1
- package/dist/skeleton/Skeleton.svelte +5 -2
- package/dist/skeleton/SkeletonElement.svelte +5 -2
- package/dist/slider/SliderRange.svelte +9 -41
- package/dist/slider/SliderSingle.svelte +35 -30
- package/dist/slider/SliderTooltip.svelte +224 -0
- package/dist/slider/SliderTooltip.svelte.d.ts +17 -0
- package/dist/space/Space.svelte +6 -3
- package/dist/space/SpaceAddon.svelte +6 -3
- package/dist/space/SpaceCompact.svelte +5 -2
- package/dist/space/space.component.d.ts +9 -0
- package/dist/space/space.component.js +5 -0
- package/dist/spin/Spin.svelte +5 -2
- package/dist/splitter/Splitter.svelte +6 -3
- package/dist/splitter/SplitterArrow.svelte.d.ts +1 -1
- package/dist/statistic/Statistic.svelte +5 -3
- package/dist/statistic/statistic.component.d.ts +7 -0
- package/dist/statistic/statistic.component.js +4 -0
- package/dist/steps/Steps.svelte +5 -2
- package/dist/styles.css +1 -0
- package/dist/styles.css.d.ts +1 -0
- package/dist/switch/Switch.svelte +5 -2
- package/dist/table/Table.svelte +3 -2
- package/dist/table/table-cell.engine.d.ts +6 -6
- package/dist/table/table.types.d.ts +2 -0
- package/dist/tabs/Tabs.svelte +6 -4
- package/dist/tag/CheckableTag.svelte +3 -1
- package/dist/tag/CheckableTagGroup.svelte +3 -1
- package/dist/tag/Tag.svelte +3 -1
- package/dist/tag/tag.component.d.ts +10 -0
- package/dist/tag/tag.component.js +5 -0
- package/dist/theme/theme-context.svelte.d.ts +2 -0
- package/dist/theme/theme-context.svelte.js +6 -1
- package/dist/timeline/Timeline.svelte +5 -2
- package/dist/tooltip/Tooltip.svelte +16 -7
- package/dist/tooltip/TooltipPopup.svelte +22 -6
- package/dist/tooltip/tooltip-popup.types.d.ts +6 -0
- package/dist/tooltip/tooltip.types.d.ts +16 -0
- package/dist/tour/Tour.svelte +3 -1
- package/dist/transfer/Transfer.svelte +3 -1
- package/dist/transfer/TransferCheckbox.svelte +3 -1
- package/dist/transfer/TransferPagination.svelte +3 -1
- package/dist/tree/Tree.svelte +3 -2
- package/dist/tree/tree.component.d.ts +10 -0
- package/dist/tree/tree.component.js +5 -0
- package/dist/tree-select/TreeSelectControl.svelte +5 -4
- package/dist/types.d.ts +2 -2
- package/dist/typography/TypographyEditable.svelte +5 -2
- package/dist/typography/TypographyElement.svelte +6 -3
- package/dist/typography/TypographyTooltip.svelte +19 -8
- package/dist/typography/typography.component.d.ts +13 -0
- package/dist/typography/typography.component.js +7 -0
- 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/vendor/compute-scroll-into-view.d.ts +3 -1
- package/dist/vendor/compute-scroll-into-view.js +3 -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/version.d.ts +2 -0
- package/dist/version.js +3 -0
- package/package.json +15 -4
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
2
|
+
import type { FormItemControl } from './form.types';
|
|
3
|
+
type $$ComponentProps = {
|
|
4
|
+
control: Snippet<[FormItemControl]>;
|
|
5
|
+
valueProps: Readonly<Record<string, unknown>>;
|
|
6
|
+
onEvent: (event: string, args: readonly unknown[]) => boolean;
|
|
7
|
+
};
|
|
8
|
+
declare const FormItemControlBinding: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
9
|
+
type FormItemControlBinding = ReturnType<typeof FormItemControlBinding>;
|
|
10
|
+
export default FormItemControlBinding;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
// Renders the connected list after the editor and holds the measured spacing until exit.
|
|
3
|
+
import { onDestroy, type Snippet } from 'svelte';
|
|
4
|
+
import type { ClassValue } from 'svelte/elements';
|
|
5
|
+
import { useForm } from './form-context';
|
|
6
|
+
import { buildFormErrorList } from './form-error-list.engine';
|
|
7
|
+
import { useDelayedFormMessages, useFormErrorList } from './form-error-list-state.svelte';
|
|
8
|
+
import type { FormValidationMessage } from './validation-messages.types';
|
|
9
|
+
import FormMessageMotion from './FormMessageMotion.svelte';
|
|
10
|
+
import NoFormItemBinding from './NoFormItemBinding.svelte';
|
|
11
|
+
|
|
12
|
+
let {
|
|
13
|
+
prefix, scope, messages, extraId, help, extra, item, itemClass, itemStyle,
|
|
14
|
+
margin = $bindable(0), withHelp = $bindable()
|
|
15
|
+
}: {
|
|
16
|
+
prefix: string;
|
|
17
|
+
scope?: string;
|
|
18
|
+
messages: {
|
|
19
|
+
readonly errors: readonly FormValidationMessage[];
|
|
20
|
+
readonly warnings: readonly FormValidationMessage[];
|
|
21
|
+
readonly descriptionId?: string;
|
|
22
|
+
};
|
|
23
|
+
extraId?: string;
|
|
24
|
+
help?: Snippet;
|
|
25
|
+
extra?: Snippet;
|
|
26
|
+
item?: HTMLDivElement;
|
|
27
|
+
itemClass: ClassValue;
|
|
28
|
+
itemStyle?: string;
|
|
29
|
+
margin?: number;
|
|
30
|
+
withHelp?: boolean;
|
|
31
|
+
} = $props();
|
|
32
|
+
|
|
33
|
+
const form = useForm();
|
|
34
|
+
// The item's help class and the connected list have separate clear windows.
|
|
35
|
+
const itemErrors = useDelayedFormMessages(() => messages.errors, false);
|
|
36
|
+
const itemWarnings = useDelayedFormMessages(() => messages.warnings, false);
|
|
37
|
+
const listErrors = useDelayedFormMessages(itemErrors, false);
|
|
38
|
+
const listWarnings = useDelayedFormMessages(itemWarnings, false);
|
|
39
|
+
const list = useFormErrorList(
|
|
40
|
+
() => ({ errors: listErrors(), warnings: listWarnings() }),
|
|
41
|
+
releaseMargin
|
|
42
|
+
);
|
|
43
|
+
const visibleHelp = $derived(Boolean(itemErrors().length || itemWarnings().length));
|
|
44
|
+
const hasMessages = $derived(Boolean(messages.errors.length || messages.warnings.length));
|
|
45
|
+
const role = $derived(messages.errors.length ? 'alert' : 'status');
|
|
46
|
+
const accessibleEntries = $derived.by(() => {
|
|
47
|
+
const current = buildFormErrorList(messages);
|
|
48
|
+
const statusByKey = new Map(current.map(({ key, status }) => [key, status]));
|
|
49
|
+
return statusByKey;
|
|
50
|
+
});
|
|
51
|
+
let extraHeight = $state(0);
|
|
52
|
+
let helpElement = $state<HTMLDivElement>();
|
|
53
|
+
let helpHeight = $state(0);
|
|
54
|
+
const reservedHelp = $derived(list.rendered ? helpHeight : 0);
|
|
55
|
+
const minHeight = $derived(margin || reservedHelp
|
|
56
|
+
? margin + (extra ? extraHeight : 0) + reservedHelp : undefined);
|
|
57
|
+
|
|
58
|
+
$effect.pre(() => {
|
|
59
|
+
if (!help) {
|
|
60
|
+
helpHeight = 0;
|
|
61
|
+
}
|
|
62
|
+
else if (hasMessages && helpElement) {
|
|
63
|
+
// Blur can replace fallback help while a pointer is still down on the next control.
|
|
64
|
+
helpHeight = helpElement.clientHeight;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
$effect(() => { withHelp = visibleHelp; });
|
|
69
|
+
|
|
70
|
+
$effect(() => {
|
|
71
|
+
if (!item || !visibleHelp) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Local styles and the prefix can change the computed margin of the live item.
|
|
76
|
+
void itemStyle;
|
|
77
|
+
void itemClass;
|
|
78
|
+
void scope;
|
|
79
|
+
const computed = item.ownerDocument.defaultView?.getComputedStyle(item).marginBottom;
|
|
80
|
+
margin = computed ? Number.parseInt(computed, 10) || 0 : 0;
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
/** A field that was shown again while leaving still needs its current spacing. */
|
|
84
|
+
function releaseMargin(shown: boolean) {
|
|
85
|
+
if (!shown && !visibleHelp) margin = 0;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
onDestroy(() => {
|
|
89
|
+
withHelp = undefined;
|
|
90
|
+
margin = 0;
|
|
91
|
+
});
|
|
92
|
+
</script>
|
|
93
|
+
|
|
94
|
+
{#if list.rendered || help && !hasMessages || extra}
|
|
95
|
+
<div
|
|
96
|
+
class={`${prefix}-item-additional`}
|
|
97
|
+
data-ant-form-prefix={scope}
|
|
98
|
+
style:min-height={minHeight === undefined ? undefined : `${minHeight}px`}
|
|
99
|
+
>
|
|
100
|
+
{#if list.rendered}
|
|
101
|
+
<FormMessageMotion
|
|
102
|
+
kind="holder"
|
|
103
|
+
{prefix}
|
|
104
|
+
{scope}
|
|
105
|
+
id={hasMessages ? messages.descriptionId : undefined}
|
|
106
|
+
role={hasMessages ? role : undefined}
|
|
107
|
+
ariaHidden={!hasMessages}
|
|
108
|
+
visible={list.visible}
|
|
109
|
+
onFinish={list.finishHolder}
|
|
110
|
+
class={[`${prefix}-item-explain`, `${prefix}-item-explain-connected`, form?.classNames?.help]}
|
|
111
|
+
style={form?.styles?.help}
|
|
112
|
+
>
|
|
113
|
+
{#each list.entries as entry (entry.key)}
|
|
114
|
+
<FormMessageMotion
|
|
115
|
+
kind="message"
|
|
116
|
+
{prefix}
|
|
117
|
+
{scope}
|
|
118
|
+
visible={entry.visible}
|
|
119
|
+
ariaHidden={!entry.visible || accessibleEntries.get(entry.key) !== entry.status}
|
|
120
|
+
onFinish={(shown) => list.finishMessage(entry.key, shown)}
|
|
121
|
+
class={[
|
|
122
|
+
entry.status && `${prefix}-item-explain-${entry.status}`, form?.classNames?.helpItem
|
|
123
|
+
]}
|
|
124
|
+
style={form?.styles?.helpItem}
|
|
125
|
+
>{#if typeof entry.content === 'function'}
|
|
126
|
+
<NoFormItemBinding>{@render entry.content()}</NoFormItemBinding>
|
|
127
|
+
{:else}{entry.content}{/if}</FormMessageMotion>
|
|
128
|
+
{/each}
|
|
129
|
+
</FormMessageMotion>
|
|
130
|
+
{/if}
|
|
131
|
+
{#if help && !hasMessages}
|
|
132
|
+
<div id={messages.descriptionId} data-ant-form-prefix={scope} bind:this={helpElement}
|
|
133
|
+
class={[`${prefix}-item-extra`, form?.classNames?.help]} style={form?.styles?.help}
|
|
134
|
+
>{@render help()}</div>
|
|
135
|
+
{/if}
|
|
136
|
+
{#if extra}
|
|
137
|
+
<div id={extraId} data-ant-form-prefix={scope} bind:clientHeight={extraHeight}
|
|
138
|
+
class={[`${prefix}-item-extra`, form?.classNames?.extra]} style={form?.styles?.extra}
|
|
139
|
+
>{@render extra()}</div>
|
|
140
|
+
{/if}
|
|
141
|
+
</div>
|
|
142
|
+
{/if}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
2
|
+
import type { ClassValue } from 'svelte/elements';
|
|
3
|
+
import type { FormValidationMessage } from './validation-messages.types';
|
|
4
|
+
type $$ComponentProps = {
|
|
5
|
+
prefix: string;
|
|
6
|
+
scope?: string;
|
|
7
|
+
messages: {
|
|
8
|
+
readonly errors: readonly FormValidationMessage[];
|
|
9
|
+
readonly warnings: readonly FormValidationMessage[];
|
|
10
|
+
readonly descriptionId?: string;
|
|
11
|
+
};
|
|
12
|
+
extraId?: string;
|
|
13
|
+
help?: Snippet;
|
|
14
|
+
extra?: Snippet;
|
|
15
|
+
item?: HTMLDivElement;
|
|
16
|
+
itemClass: ClassValue;
|
|
17
|
+
itemStyle?: string;
|
|
18
|
+
margin?: number;
|
|
19
|
+
withHelp?: boolean;
|
|
20
|
+
};
|
|
21
|
+
declare const FormItemMessages: import("svelte").Component<$$ComponentProps, {}, "margin" | "withHelp">;
|
|
22
|
+
type FormItemMessages = ReturnType<typeof FormItemMessages>;
|
|
23
|
+
export default FormItemMessages;
|
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
import { provideFormList, useFormList } from './form-list-context';
|
|
7
7
|
import { changeFormList, syncFormListKeys } from './form-list.engine';
|
|
8
8
|
import { formNamePath } from './form-store.engine';
|
|
9
|
-
import type {
|
|
9
|
+
import type { FormRemovalPath } from './form-internal';
|
|
10
|
+
import type { FormListMeta, FormListOperation, FormListProps } from './form-list.types';
|
|
11
|
+
import { richValidationMessages, validationMessageTexts } from './validation-message.engine';
|
|
10
12
|
|
|
11
13
|
let { name, initialValue, rules, children, prefixCls }: FormListProps = $props();
|
|
12
14
|
const form = useForm();
|
|
@@ -36,19 +38,56 @@
|
|
|
36
38
|
)));
|
|
37
39
|
// React map skips holes. each receives a dense list of positions that exist.
|
|
38
40
|
let fields = $derived(values.flatMap((_, index) => ({ name: index, key: keys.keys[index] })));
|
|
39
|
-
|
|
40
|
-
errors
|
|
41
|
+
const meta = $derived.by<FormListMeta>(() => {
|
|
42
|
+
const errors = form.getFieldMessages(prefixName, 'errors');
|
|
43
|
+
const warnings = form.getFieldMessages(prefixName, 'warnings');
|
|
44
|
+
const errorMessages = richValidationMessages(errors);
|
|
45
|
+
const warningMessages = richValidationMessages(warnings);
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
errors: validationMessageTexts(errors),
|
|
49
|
+
warnings: validationMessageTexts(warnings),
|
|
50
|
+
...(errorMessages && { errorMessages }),
|
|
51
|
+
...(warningMessages && { warningMessages })
|
|
52
|
+
};
|
|
41
53
|
});
|
|
42
54
|
let fieldResetKey = $state.raw<object>({});
|
|
43
55
|
let resetKey = $derived({ form: form.resetKey, field: fieldResetKey });
|
|
44
56
|
|
|
57
|
+
// A row's index may change after registration. Skip rows already removed by a list operation.
|
|
58
|
+
function captureRemovalPath(relative: readonly (string | number)[]): FormRemovalPath {
|
|
59
|
+
const resolveParent = parent?.captureRemovalPath(formNamePath(name));
|
|
60
|
+
const [position, ...rest] = relative;
|
|
61
|
+
const rowKey = typeof position === 'number' ? keys.keys[position] : undefined;
|
|
62
|
+
|
|
63
|
+
return (readValue) => {
|
|
64
|
+
const listPath = resolveParent ? resolveParent(readValue) : prefixName;
|
|
65
|
+
if (!listPath) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (typeof position !== 'number') {
|
|
69
|
+
return [...listPath, ...relative];
|
|
70
|
+
}
|
|
71
|
+
if (rowKey === undefined) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const index = keys.keys.indexOf(rowKey);
|
|
76
|
+
const rows = readValue(listPath);
|
|
77
|
+
if (index >= 0 && Array.isArray(rows) && Object.hasOwn(rows, index)) {
|
|
78
|
+
return [...listPath, index, ...rest];
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
45
83
|
provideFormList({
|
|
46
84
|
get prefixCls() {
|
|
47
85
|
return config.getPrefixCls('form', prefixCls);
|
|
48
86
|
},
|
|
49
87
|
get prefixName() {
|
|
50
88
|
return prefixName;
|
|
51
|
-
}
|
|
89
|
+
},
|
|
90
|
+
captureRemovalPath
|
|
52
91
|
});
|
|
53
92
|
|
|
54
93
|
$effect.pre(() => form.registerField?.({
|
|
@@ -58,6 +97,12 @@
|
|
|
58
97
|
get rules() {
|
|
59
98
|
return rules;
|
|
60
99
|
},
|
|
100
|
+
get validateTrigger() {
|
|
101
|
+
return form.validateTrigger;
|
|
102
|
+
},
|
|
103
|
+
get preserve() {
|
|
104
|
+
return form.preserve;
|
|
105
|
+
},
|
|
61
106
|
get initialValue() {
|
|
62
107
|
return initialValue;
|
|
63
108
|
},
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { CssMotionConfig, CssMotionEvent } from '../motion/css-motion.types';
|
|
3
|
+
|
|
4
|
+
/** Rows start at zero height and opacity before the connected holder opens. */
|
|
5
|
+
function collapsed() {
|
|
6
|
+
return { height: 0, opacity: 0 };
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** scrollHeight includes the text even while the row is collapsed. */
|
|
10
|
+
function expanded(node: HTMLDivElement) {
|
|
11
|
+
return { height: node.scrollHeight, opacity: 1 };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** The leave starts at the rendered height, including any interrupted entry. */
|
|
15
|
+
function leaving(node: HTMLDivElement) {
|
|
16
|
+
return { height: node.offsetHeight };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** A fading row can still be reducing its height. */
|
|
20
|
+
function heightFinished(_node: HTMLDivElement, event: CssMotionEvent) {
|
|
21
|
+
return 'deadline' in event || ('propertyName' in event && event.propertyName === 'height');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const collapse: CssMotionConfig<HTMLDivElement> = {
|
|
25
|
+
onAppearStart: collapsed,
|
|
26
|
+
onAppearActive: expanded,
|
|
27
|
+
onAppearEnd: heightFinished,
|
|
28
|
+
onEnterStart: collapsed,
|
|
29
|
+
onEnterActive: expanded,
|
|
30
|
+
onEnterEnd: heightFinished,
|
|
31
|
+
onLeaveStart: leaving,
|
|
32
|
+
onLeaveActive: collapsed,
|
|
33
|
+
onLeaveEnd: heightFinished
|
|
34
|
+
};
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
<script lang="ts">
|
|
38
|
+
// Applies the connected Form help phases to the actual holder or row without adding a wrapper.
|
|
39
|
+
import type { Snippet } from 'svelte';
|
|
40
|
+
import type { ClassValue } from 'svelte/elements';
|
|
41
|
+
import { on } from 'svelte/events';
|
|
42
|
+
import { createCssMotion, type CssMotionState } from '../motion/css-motion.dom';
|
|
43
|
+
import { serializeInlineStyleLayers } from '../style/inline-style.engine';
|
|
44
|
+
import { useDesignTokenContext } from '../theme/theme-context.svelte';
|
|
45
|
+
|
|
46
|
+
interface MotionOptions {
|
|
47
|
+
name: string;
|
|
48
|
+
visible: boolean;
|
|
49
|
+
enabled: boolean;
|
|
50
|
+
onFinish: (shown: boolean) => void;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let {
|
|
54
|
+
kind, prefix, scope, visible, onFinish, id, role, ariaHidden,
|
|
55
|
+
class: className, style, children
|
|
56
|
+
}: {
|
|
57
|
+
kind: 'holder' | 'message';
|
|
58
|
+
prefix: string;
|
|
59
|
+
scope?: string;
|
|
60
|
+
visible: boolean;
|
|
61
|
+
onFinish: (shown: boolean) => void;
|
|
62
|
+
id?: string;
|
|
63
|
+
role?: 'alert' | 'status';
|
|
64
|
+
ariaHidden?: boolean;
|
|
65
|
+
class: ClassValue;
|
|
66
|
+
style?: string;
|
|
67
|
+
children: Snippet;
|
|
68
|
+
} = $props();
|
|
69
|
+
|
|
70
|
+
const theme = useDesignTokenContext();
|
|
71
|
+
let motionName = $derived(`${prefix}-show-help${kind === 'message' ? '-item' : ''}`);
|
|
72
|
+
let painted = $state.raw<CssMotionState>({});
|
|
73
|
+
|
|
74
|
+
/** The action is destroyed with its element, including when a field changes layout. */
|
|
75
|
+
function connect(node: HTMLDivElement, initial: MotionOptions) {
|
|
76
|
+
const view = node.ownerDocument.defaultView;
|
|
77
|
+
if (!view) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const reduced = view.matchMedia('(prefers-reduced-motion: reduce)');
|
|
82
|
+
const motion = createCssMotion(view, () => node, (state) => { painted = state; });
|
|
83
|
+
const configuration = kind === 'message' ? collapse : undefined;
|
|
84
|
+
let options = initial;
|
|
85
|
+
|
|
86
|
+
/** A motion setting update settles the current phase when it disables transitions. */
|
|
87
|
+
function sync() {
|
|
88
|
+
motion.sync({
|
|
89
|
+
present: true,
|
|
90
|
+
visible: options.visible,
|
|
91
|
+
enabled: options.enabled && !reduced.matches,
|
|
92
|
+
settleOnCutoff: true,
|
|
93
|
+
motion: {
|
|
94
|
+
...configuration,
|
|
95
|
+
motionName: options.name,
|
|
96
|
+
motionDeadline: 500,
|
|
97
|
+
motionLeaveImmediately: !initial.visible,
|
|
98
|
+
onVisibleChanged: options.onFinish
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const disconnect = [
|
|
104
|
+
on(reduced, 'change', sync),
|
|
105
|
+
on(node, 'transitionend', motion.end),
|
|
106
|
+
on(node, 'animationend', motion.end)
|
|
107
|
+
];
|
|
108
|
+
sync();
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
/** Use the latest classes and callbacks without moving the node. */
|
|
112
|
+
update(next: MotionOptions) {
|
|
113
|
+
options = next;
|
|
114
|
+
sync();
|
|
115
|
+
},
|
|
116
|
+
/** Invalidates frames and callbacks when the field or row is removed. */
|
|
117
|
+
destroy() {
|
|
118
|
+
motion.destroy();
|
|
119
|
+
for (const remove of disconnect) remove();
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
</script>
|
|
124
|
+
|
|
125
|
+
<div
|
|
126
|
+
{id}
|
|
127
|
+
{role}
|
|
128
|
+
aria-hidden={ariaHidden || undefined}
|
|
129
|
+
data-ant-form-prefix={scope}
|
|
130
|
+
class={[className, painted.className]}
|
|
131
|
+
style={serializeInlineStyleLayers([style, painted.style])}
|
|
132
|
+
use:connect={{ name: motionName, visible, enabled: theme.state.token.motion, onFinish }}
|
|
133
|
+
>{@render children()}</div>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { ClassValue } from 'svelte/elements';
|
|
3
|
+
type $$ComponentProps = {
|
|
4
|
+
kind: 'holder' | 'message';
|
|
5
|
+
prefix: string;
|
|
6
|
+
scope?: string;
|
|
7
|
+
visible: boolean;
|
|
8
|
+
onFinish: (shown: boolean) => void;
|
|
9
|
+
id?: string;
|
|
10
|
+
role?: 'alert' | 'status';
|
|
11
|
+
ariaHidden?: boolean;
|
|
12
|
+
class: ClassValue;
|
|
13
|
+
style?: string;
|
|
14
|
+
children: Snippet;
|
|
15
|
+
};
|
|
16
|
+
declare const FormMessageMotion: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
17
|
+
type FormMessageMotion = ReturnType<typeof FormMessageMotion>;
|
|
18
|
+
export default FormMessageMotion;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { provideFormProvider } from './form-provider-context';
|
|
3
|
+
import type { FormProviderProps } from './form.types';
|
|
4
|
+
|
|
5
|
+
let props: FormProviderProps = $props();
|
|
6
|
+
provideFormProvider(() => props);
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
{@render props.children?.()}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import type { FormFieldRegistration } from './form-internal';
|
|
2
|
-
import type { FormFeedbackIcons, FormRequiredMark, FormSemanticSlots, FormTooltipProps } from './form.types';
|
|
2
|
+
import type { FormFeedbackIcons, FormRef, FormRequiredMark, FormSemanticSlots, FormTooltipProps, FormValidateTrigger } from './form.types';
|
|
3
3
|
import type { FormValidateStatus } from './form-error-list.types';
|
|
4
|
-
import type { FormFieldMeta } from './form.model.svelte';
|
|
4
|
+
import type { FormFieldMeta, FormInstance } from './form.model.svelte';
|
|
5
5
|
import type { ColProps } from '../grid/grid.types';
|
|
6
6
|
import type { NamePath } from './form-store.engine';
|
|
7
7
|
import type { Variant } from '../types';
|
|
8
|
-
import type { FormRule } from './validation.engine';
|
|
8
|
+
import type { FormRule, FormValues } from './validation.engine';
|
|
9
|
+
import type { FormValidationMessage } from './validation-messages.types';
|
|
10
|
+
import type { ValidationMessages } from './validation-nested.engine';
|
|
9
11
|
export interface FormContext {
|
|
12
|
+
readonly model: FormInstance<FormValues>;
|
|
13
|
+
readonly ref: FormRef<FormValues> | undefined;
|
|
10
14
|
readonly variant?: Variant;
|
|
11
15
|
readonly disabled: boolean;
|
|
12
16
|
readonly submitting: boolean;
|
|
@@ -21,13 +25,15 @@ export interface FormContext {
|
|
|
21
25
|
readonly styles?: FormSemanticSlots;
|
|
22
26
|
readonly tooltip?: FormTooltipProps;
|
|
23
27
|
readonly feedbackIcons?: FormFeedbackIcons;
|
|
28
|
+
readonly validateTrigger?: FormValidateTrigger;
|
|
29
|
+
readonly preserve?: boolean;
|
|
24
30
|
readonly resetKey?: object;
|
|
25
|
-
|
|
26
|
-
getFieldWarning(name: NamePath): readonly string[];
|
|
31
|
+
getFieldMessages(name: NamePath, kind: keyof ValidationMessages): readonly FormValidationMessage[];
|
|
27
32
|
getFieldMeta(name: NamePath): (Pick<FormFieldMeta, 'touched' | 'validating'> & Partial<Pick<FormFieldMeta, 'validated'>>) | undefined;
|
|
28
33
|
isFieldRequired(name: NamePath): boolean;
|
|
29
34
|
hasRequiredRules(rules: readonly FormRule[]): boolean;
|
|
30
|
-
|
|
35
|
+
handleFieldBlur(name: NamePath): void;
|
|
36
|
+
handleFieldEvent(mountKey: symbol, event: string, args: readonly unknown[]): boolean;
|
|
31
37
|
registerField?(field: FormFieldRegistration): (() => void) | undefined;
|
|
32
38
|
markFieldMounted(mountKey: symbol): void;
|
|
33
39
|
getFieldValue(name: NamePath): unknown;
|
|
@@ -48,7 +54,19 @@ export interface FormFieldContext {
|
|
|
48
54
|
registerControl?(getInstance: () => unknown): () => void;
|
|
49
55
|
onBlur(): void;
|
|
50
56
|
}
|
|
57
|
+
/** A reactive reference to the model of the nearest Form. */
|
|
58
|
+
export interface FormInstanceRef<Values extends FormValues> {
|
|
59
|
+
readonly current: FormInstance<Values> | undefined;
|
|
60
|
+
/** The nearest Form's imperative handle after it mounts. */
|
|
61
|
+
readonly ref?: FormRef<Values>;
|
|
62
|
+
}
|
|
63
|
+
/** Captures the nearest Form during component initialization and follows model replacement. */
|
|
64
|
+
export declare function useFormInstance<Values extends FormValues = FormValues>(): FormInstanceRef<Values>;
|
|
65
|
+
/** Publishes the form context owned by this component. */
|
|
51
66
|
export declare function provideForm(form: FormContext): void;
|
|
67
|
+
/** Reads form settings with the effective disabled state of the nearest ConfigProvider. */
|
|
52
68
|
export declare function useForm(): FormContext | undefined;
|
|
69
|
+
/** Sets the field association for the controls in this scope. */
|
|
53
70
|
export declare function provideFormField(field: FormFieldContext | undefined): void;
|
|
71
|
+
/** Reads field attributes and keeps a control registration until it unmounts. */
|
|
54
72
|
export declare function useFormField(getInstance?: () => unknown): FormFieldContext | undefined;
|
|
@@ -1,10 +1,26 @@
|
|
|
1
|
+
// Shares field behavior and the live model of the nearest Form with descendant controls.
|
|
1
2
|
import { getContext, onDestroy, onMount, setContext } from 'svelte';
|
|
2
3
|
import { useConfig } from '../config-provider/config-context';
|
|
3
4
|
const formKey = Symbol('ant-design-form');
|
|
4
5
|
const fieldKey = Symbol('ant-design-form-field');
|
|
6
|
+
/** Captures the nearest Form during component initialization and follows model replacement. */
|
|
7
|
+
export function useFormInstance() {
|
|
8
|
+
// The context erases the schema. Both getters use the caller's schema for the nearest Form.
|
|
9
|
+
const context = getContext(formKey);
|
|
10
|
+
return {
|
|
11
|
+
get current() {
|
|
12
|
+
return context?.model;
|
|
13
|
+
},
|
|
14
|
+
get ref() {
|
|
15
|
+
return context?.ref;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** Publishes the form context owned by this component. */
|
|
5
20
|
export function provideForm(form) {
|
|
6
21
|
setContext(formKey, form);
|
|
7
22
|
}
|
|
23
|
+
/** Reads form settings with the effective disabled state of the nearest ConfigProvider. */
|
|
8
24
|
export function useForm() {
|
|
9
25
|
const parent = getContext(formKey);
|
|
10
26
|
if (!parent) {
|
|
@@ -17,9 +33,11 @@ export function useForm() {
|
|
|
17
33
|
});
|
|
18
34
|
return form;
|
|
19
35
|
}
|
|
36
|
+
/** Sets the field association for the controls in this scope. */
|
|
20
37
|
export function provideFormField(field) {
|
|
21
38
|
setContext(fieldKey, field);
|
|
22
39
|
}
|
|
40
|
+
/** Reads field attributes and keeps a control registration until it unmounts. */
|
|
23
41
|
export function useFormField(getInstance) {
|
|
24
42
|
const parent = getContext(fieldKey);
|
|
25
43
|
const config = useConfig();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Reads values from editor callbacks. Native event targets can expose value through their prototype.
|
|
2
|
+
/** Uses the target's configured prop when present, or the first callback argument itself. */
|
|
3
|
+
export function readFormControlValue(valuePropName, args) {
|
|
4
|
+
const input = args[0];
|
|
5
|
+
if (input === null || (typeof input !== 'object' && typeof input !== 'function')) {
|
|
6
|
+
return input;
|
|
7
|
+
}
|
|
8
|
+
const target = Reflect.get(input, 'target');
|
|
9
|
+
if (target !== null && typeof target === 'object' && valuePropName in target) {
|
|
10
|
+
return Reflect.get(target, valuePropName);
|
|
11
|
+
}
|
|
12
|
+
return input;
|
|
13
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { FormErrorListProps } from './form-error-list.types';
|
|
2
|
+
import { type FormErrorMotionEntity } from './form-error-list.engine';
|
|
3
|
+
type ErrorListMessages = NonNullable<FormErrorListProps['errors']>;
|
|
4
|
+
/** Clears after 10 ms. Connected fields can expose nonempty messages in the current update. */
|
|
5
|
+
export declare function useDelayedFormMessages(read: () => ErrorListMessages, deferNonempty: boolean): () => readonly (string | number | boolean | import("svelte").Snippet<[]> | {
|
|
6
|
+
readonly text: string;
|
|
7
|
+
readonly content: import("svelte").Snippet;
|
|
8
|
+
} | import("svelte").Snippet<[]> | readonly import("..").RenderEmptyContent[] | null | undefined)[];
|
|
9
|
+
type MessageInput = Pick<FormErrorListProps, 'help' | 'helpStatus' | 'errors' | 'warnings'>;
|
|
10
|
+
/** Keeps the holder and keyed rows until their own motion completes. */
|
|
11
|
+
export declare function useFormErrorList(read: () => MessageInput, onVisibleChanged?: (shown: boolean) => void): {
|
|
12
|
+
/** The holder is open while any delayed message remains. */
|
|
13
|
+
readonly visible: boolean;
|
|
14
|
+
/** The mounted holder can outlive its visible messages during exit. */
|
|
15
|
+
readonly rendered: boolean;
|
|
16
|
+
/** SSR reads the message list after child fields have rendered and reported their metadata. */
|
|
17
|
+
readonly entries: FormErrorMotionEntity[];
|
|
18
|
+
finishHolder: (shown: boolean) => void;
|
|
19
|
+
finishMessage: (key: string, shown: boolean) => void;
|
|
20
|
+
};
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Retains Form messages across brief validation gaps and owns the lifetime of leaving entries.
|
|
2
|
+
import { onDestroy, onMount, untrack } from 'svelte';
|
|
3
|
+
import { buildFormErrorList, reconcileFormErrorList } from './form-error-list.engine';
|
|
4
|
+
/** Clears after 10 ms. Connected fields can expose nonempty messages in the current update. */
|
|
5
|
+
export function useDelayedFormMessages(read, deferNonempty) {
|
|
6
|
+
let retained = $state.raw(deferNonempty ? untrack(read) : []);
|
|
7
|
+
$effect(() => {
|
|
8
|
+
const next = [...read()];
|
|
9
|
+
if (!deferNonempty) {
|
|
10
|
+
if (next.length) {
|
|
11
|
+
retained = next;
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (!untrack(() => retained.length)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const timer = setTimeout(() => { retained = next; }, next.length ? 0 : 10);
|
|
19
|
+
return () => clearTimeout(timer);
|
|
20
|
+
});
|
|
21
|
+
// Connected descriptions use the latest nonempty slice before the next timer.
|
|
22
|
+
return () => {
|
|
23
|
+
if (deferNonempty) {
|
|
24
|
+
return retained;
|
|
25
|
+
}
|
|
26
|
+
const current = read();
|
|
27
|
+
return current.length ? current : retained;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** Keeps the holder and keyed rows until their own motion completes. */
|
|
31
|
+
export function useFormErrorList(read, onVisibleChanged) {
|
|
32
|
+
const messages = $derived(buildFormErrorList(read()));
|
|
33
|
+
const visible = $derived(messages.length > 0);
|
|
34
|
+
const initialEntries = $derived(reconcileFormErrorList([], messages));
|
|
35
|
+
let mounted = $state(false);
|
|
36
|
+
let rendered = $state(false);
|
|
37
|
+
let entries = $state.raw([]);
|
|
38
|
+
let active = true;
|
|
39
|
+
$effect.pre(() => {
|
|
40
|
+
const current = messages;
|
|
41
|
+
untrack(() => {
|
|
42
|
+
entries = reconcileFormErrorList(entries, current);
|
|
43
|
+
if (current.length)
|
|
44
|
+
rendered = true;
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
onMount(() => { mounted = true; });
|
|
48
|
+
onDestroy(() => { active = false; });
|
|
49
|
+
/** A superseded transition cannot remove the current holder or notify its owner. */
|
|
50
|
+
function finishHolder(shown) {
|
|
51
|
+
if (!active || shown !== visible) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (!shown) {
|
|
55
|
+
rendered = false;
|
|
56
|
+
entries = [];
|
|
57
|
+
}
|
|
58
|
+
onVisibleChanged?.(shown);
|
|
59
|
+
}
|
|
60
|
+
/** Keep an entry with the same key if it returned while leaving. */
|
|
61
|
+
function finishMessage(key, shown) {
|
|
62
|
+
if (!active || shown) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
entries = entries.filter((entry) => entry.key !== key || entry.visible);
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
/** The holder is open while any delayed message remains. */
|
|
69
|
+
get visible() { return visible; },
|
|
70
|
+
/** The mounted holder can outlive its visible messages during exit. */
|
|
71
|
+
get rendered() { return mounted ? rendered : visible; },
|
|
72
|
+
/** SSR reads the message list after child fields have rendered and reported their metadata. */
|
|
73
|
+
get entries() { return mounted ? entries : initialEntries; },
|
|
74
|
+
finishHolder,
|
|
75
|
+
finishMessage
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
export function buildFormErrorList({ help, helpStatus, errors = [], warnings = [] }) {
|
|
3
3
|
// Forms a key on the prefix and content. The repeat counter is used after the construction of the
|
|
4
4
|
// list.
|
|
5
|
-
function entity(
|
|
5
|
+
function entity(message, prefix, index = 0, status) {
|
|
6
|
+
const content = message !== null && typeof message === 'object'
|
|
7
|
+
&& !Array.isArray(message) && 'content' in message ? message.content : message;
|
|
6
8
|
return { content, key: typeof content === 'string' ? content : `${prefix}-${index}`, status };
|
|
7
9
|
}
|
|
8
10
|
const messages = help !== undefined && help !== null
|