litos-ui 0.23.1 → 0.24.0
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/lib/base.d.ts +3 -2
- package/lib/base.js +11 -8
- package/lib/button/index.d.ts +21 -5
- package/lib/button/index.js +115 -62
- package/lib/button/index.less_inline.js +2 -3
- package/lib/button/style.js +1 -2
- package/lib/calendar/index.js +22 -24
- package/lib/calendar/index.less_inline.js +1 -2
- package/lib/calendar/langs.js +1 -2
- package/lib/card/index.js +8 -9
- package/lib/card/index.less_inline.js +1 -2
- package/lib/carousel/index.js +10 -11
- package/lib/carousel/index.less_inline.js +1 -2
- package/lib/carousel/item.js +1 -2
- package/lib/carousel/item.less_inline.js +1 -2
- package/lib/carousel/timer.js +1 -2
- package/lib/check/check.d.ts +40 -8
- package/lib/check/check.js +200 -65
- package/lib/check/check.less_inline.js +2 -3
- package/lib/check/checkbox.js +2 -3
- package/lib/check/checkbox.less_inline.js +2 -3
- package/lib/check/checkbox_group.js +1 -2
- package/lib/check/index.d.ts +28 -8
- package/lib/check/index.js +151 -46
- package/lib/check/index.less_inline.js +1 -2
- package/lib/check/radio.js +2 -3
- package/lib/check/radio.less_inline.js +1 -2
- package/lib/check/radio_group.js +2 -3
- package/lib/collapse/index.d.ts +12 -4
- package/lib/collapse/index.js +80 -46
- package/lib/collapse/index.less_inline.js +2 -3
- package/lib/collapse/item.d.ts +35 -9
- package/lib/collapse/item.js +219 -57
- package/lib/collapse/item.less_inline.js +2 -3
- package/lib/collapse/types.d.ts +17 -3
- package/lib/color_picker/index.d.ts +4 -2
- package/lib/color_picker/index.js +26 -17
- package/lib/color_picker/index.less_inline.js +1 -2
- package/lib/date_picker/index.d.ts +5 -1
- package/lib/date_picker/index.js +39 -23
- package/lib/date_picker/index.less_inline.js +1 -2
- package/lib/date_picker_ori/index.d.ts +7 -2
- package/lib/date_picker_ori/index.js +123 -47
- package/lib/date_picker_ori/index.less_inline.js +1 -2
- package/lib/description_panel/index.js +2 -10
- package/lib/description_panel/index.less_inline.js +1 -2
- package/lib/dialog/dialog_box.js +28 -29
- package/lib/dialog/dialog_container.css_inline.js +1 -2
- package/lib/dialog/dialog_container.js +13 -14
- package/lib/dialog/dialog_container_style.js +1 -2
- package/lib/dialog/index.js +1 -2
- package/lib/dropdown/index.d.ts +39 -0
- package/lib/dropdown/index.js +98 -0
- package/lib/entries/base.js +1 -2
- package/lib/entries/button.js +5 -6
- package/lib/entries/calendar.js +5 -6
- package/lib/entries/card.js +5 -6
- package/lib/entries/carousel-item.js +5 -6
- package/lib/entries/carousel.js +5 -6
- package/lib/entries/checkbox-group.js +5 -6
- package/lib/entries/checkbox.js +5 -6
- package/lib/entries/collapse-item.d.ts +0 -1
- package/lib/entries/collapse-item.js +6 -6
- package/lib/entries/collapse.d.ts +0 -1
- package/lib/entries/collapse.js +11 -6
- package/lib/entries/color-picker.js +5 -6
- package/lib/entries/date-picker-ori.js +5 -6
- package/lib/entries/date-picker.js +5 -6
- package/lib/entries/description-panel.js +5 -6
- package/lib/entries/dialog-box.js +1 -2
- package/lib/entries/dialog-container.js +5 -6
- package/lib/entries/dialog.js +1 -2
- package/lib/entries/dropdown.d.ts +2 -0
- package/lib/entries/dropdown.js +1 -0
- package/lib/entries/form-item.js +5 -6
- package/lib/entries/form.js +5 -6
- package/lib/entries/icon-arrow-down.js +5 -6
- package/lib/entries/icon-arrow-left.js +5 -6
- package/lib/entries/icon-arrow-right.js +5 -6
- package/lib/entries/icon-arrow-up.js +5 -6
- package/lib/entries/icon-base.js +5 -6
- package/lib/entries/icon-calendar.js +5 -6
- package/lib/entries/icon-caret-bottom.js +5 -6
- package/lib/entries/icon-caret-top.js +5 -6
- package/lib/entries/icon-close-filled.js +5 -6
- package/lib/entries/icon-close.js +5 -6
- package/lib/entries/icon-copy.js +5 -6
- package/lib/entries/icon-d-arrow-left.js +5 -6
- package/lib/entries/icon-d-arrow-right.js +5 -6
- package/lib/entries/icon-delete.js +5 -6
- package/lib/entries/icon-eye-outline.js +5 -6
- package/lib/entries/icon-font-icon.js +5 -6
- package/lib/entries/icon-info.js +5 -6
- package/lib/entries/icon-loading.js +5 -6
- package/lib/entries/icon-minus.js +5 -6
- package/lib/entries/icon-moon.js +5 -6
- package/lib/entries/icon-more.js +5 -6
- package/lib/entries/icon-picture.js +5 -6
- package/lib/entries/icon-plus.js +5 -6
- package/lib/entries/icon-reduction.js +5 -6
- package/lib/entries/icon-refresh-left.js +5 -6
- package/lib/entries/icon-refresh-right.js +5 -6
- package/lib/entries/icon-refresh.js +5 -6
- package/lib/entries/icon-search.js +5 -6
- package/lib/entries/icon-select.js +5 -6
- package/lib/entries/icon-sort.js +5 -6
- package/lib/entries/icon-success.js +5 -6
- package/lib/entries/icon-sun.js +5 -6
- package/lib/entries/icon-theme-default.js +5 -6
- package/lib/entries/icon-warn.js +5 -6
- package/lib/entries/icon-zoom-in.js +5 -6
- package/lib/entries/icon-zoom-out.js +5 -6
- package/lib/entries/image-preview.js +5 -6
- package/lib/entries/image.js +5 -6
- package/lib/entries/input-number.js +5 -6
- package/lib/entries/input.js +5 -6
- package/lib/entries/list.js +5 -6
- package/lib/entries/loading.js +1 -2
- package/lib/entries/mask.js +5 -6
- package/lib/entries/md-input.js +5 -6
- package/lib/entries/menu.js +5 -6
- package/lib/entries/message.js +1 -2
- package/lib/entries/modal-box.js +1 -2
- package/lib/entries/modal.js +5 -6
- package/lib/entries/notification-box.js +1 -2
- package/lib/entries/notification.js +1 -2
- package/lib/entries/page-header.js +5 -6
- package/lib/entries/pagination.js +5 -6
- package/lib/entries/polygon.js +5 -6
- package/lib/entries/popconfirm.js +1 -2
- package/lib/entries/popover.js +1 -2
- package/lib/entries/qrcode.js +5 -6
- package/lib/entries/radio-group.js +5 -6
- package/lib/entries/radio.js +5 -6
- package/lib/entries/select-ori.js +5 -6
- package/lib/entries/select.js +5 -6
- package/lib/entries/space.js +5 -6
- package/lib/entries/switch.js +5 -6
- package/lib/entries/tabbar-item.js +5 -6
- package/lib/entries/tabbar.js +5 -6
- package/lib/entries/table.js +5 -6
- package/lib/entries/tabs.js +1 -2
- package/lib/entries/tag.js +5 -6
- package/lib/entries/theme-color.js +5 -6
- package/lib/entries/theme.js +5 -6
- package/lib/entries/transition.js +1 -2
- package/lib/entries/upload.js +5 -6
- package/lib/entries/utils.js +1 -3
- package/lib/form/accessibility.d.ts +15 -0
- package/lib/form/accessibility.js +56 -0
- package/lib/form/autocomplete.d.ts +21 -0
- package/lib/form/autocomplete.js +59 -0
- package/lib/form/context.d.ts +157 -0
- package/lib/form/context.js +88 -0
- package/lib/form/form_inner.d.ts +99 -24
- package/lib/form/form_inner.js +424 -72
- package/lib/form/form_item.d.ts +35 -11
- package/lib/form/form_item.js +210 -78
- package/lib/form/form_item.less_inline.js +2 -3
- package/lib/form/form_item_style.d.ts +3 -0
- package/lib/form/form_item_style.js +7 -0
- package/lib/form/index.d.ts +69 -15
- package/lib/form/index.js +501 -101
- package/lib/form/index.less_inline.js +1 -2
- package/lib/form/owner.d.ts +78 -0
- package/lib/form/owner.js +138 -0
- package/lib/form/style.d.ts +3 -0
- package/lib/form/style.js +7 -0
- package/lib/icon/arrow_down.js +1 -2
- package/lib/icon/arrow_left.js +1 -2
- package/lib/icon/arrow_right.js +1 -2
- package/lib/icon/arrow_up.js +1 -2
- package/lib/icon/base.js +1 -2
- package/lib/icon/calendar.js +1 -2
- package/lib/icon/caret_bottom.js +1 -2
- package/lib/icon/caret_top.js +1 -2
- package/lib/icon/close.js +1 -2
- package/lib/icon/close_filled.js +1 -2
- package/lib/icon/copy.js +1 -2
- package/lib/icon/d_arrow_left.js +1 -2
- package/lib/icon/d_arrow_right.js +1 -2
- package/lib/icon/delete.js +1 -2
- package/lib/icon/eye_outline.js +1 -2
- package/lib/icon/font_icon.js +1 -2
- package/lib/icon/icon_style.js +1 -2
- package/lib/icon/index.less_inline.js +1 -2
- package/lib/icon/info.js +1 -2
- package/lib/icon/loading.js +1 -2
- package/lib/icon/minus.js +1 -2
- package/lib/icon/moon.js +1 -2
- package/lib/icon/more.js +1 -2
- package/lib/icon/picture.js +1 -2
- package/lib/icon/plus.js +1 -2
- package/lib/icon/reduction.js +1 -2
- package/lib/icon/refresh.js +1 -2
- package/lib/icon/refresh_left.js +1 -2
- package/lib/icon/refresh_right.js +1 -2
- package/lib/icon/search.js +1 -2
- package/lib/icon/select.js +1 -2
- package/lib/icon/sort.js +1 -2
- package/lib/icon/success.js +1 -2
- package/lib/icon/sun.js +1 -2
- package/lib/icon/theme_default.js +1 -2
- package/lib/icon/warn.js +1 -2
- package/lib/icon/zoom_in.js +1 -2
- package/lib/icon/zoom_out.js +1 -2
- package/lib/image/image_preview.js +1 -2
- package/lib/image/image_preview.less_inline.js +1 -2
- package/lib/image/index.js +1 -2
- package/lib/image/index.less_inline.js +1 -2
- package/lib/index.d.ts +2 -1
- package/lib/index.js +91 -91
- package/lib/input/index.d.ts +14 -0
- package/lib/input/index.js +126 -31
- package/lib/input/index.less_inline.js +2 -3
- package/lib/input/input_inner.less_inline.js +1 -2
- package/lib/input/style.d.ts +1 -0
- package/lib/input/style.js +5 -7
- package/lib/input_number/index.d.ts +7 -0
- package/lib/input_number/index.js +70 -48
- package/lib/input_number/index.less_inline.js +1 -2
- package/lib/input_number/style.js +1 -2
- package/lib/list/index.js +4 -5
- package/lib/list/index.less_inline.js +1 -2
- package/lib/loading/index.js +1 -2
- package/lib/mask/index.js +2 -7
- package/lib/mask/index.less_inline.js +1 -2
- package/lib/md_input/index.d.ts +11 -2
- package/lib/md_input/index.js +63 -27
- package/lib/md_input/index.less_inline.js +2 -3
- package/lib/menu/index.js +2 -7
- package/lib/menu/index.less_inline.js +1 -2
- package/lib/message/index.js +1 -2
- package/lib/modal/index.js +15 -16
- package/lib/modal/index.less_inline.js +1 -2
- package/lib/modal/modal_box.js +24 -25
- package/lib/notification/index.js +15 -29
- package/lib/notification/index.less_inline.js +1 -2
- package/lib/notification/notification_box.js +2 -3
- package/lib/notification/placement.js +1 -2
- package/lib/notification/style.js +1 -2
- package/lib/page_header/index.js +1 -2
- package/lib/page_header/index.less_inline.js +1 -2
- package/lib/pagination/index.js +2 -7
- package/lib/pagination/index.less_inline.js +1 -2
- package/lib/polygon/index.js +1 -2
- package/lib/polygon/index.less_inline.js +1 -2
- package/lib/qrcode/index.js +1 -2
- package/lib/qrcode/index.less_inline.js +1 -2
- package/lib/select/index.d.ts +19 -2
- package/lib/select/index.js +128 -74
- package/lib/select/index.less_inline.js +1 -2
- package/lib/select_ori/index.d.ts +9 -1
- package/lib/select_ori/index.js +36 -24
- package/lib/select_ori/index.less_inline.js +1 -2
- package/lib/space/index.js +1 -2
- package/lib/space/index.less_inline.js +1 -2
- package/lib/styles/animation/index.css_inline.js +1 -2
- package/lib/styles/animation/index.js +1 -2
- package/lib/styles/mask/index.css_inline.js +1 -2
- package/lib/styles/mask/index.js +1 -2
- package/lib/switch/index.d.ts +6 -0
- package/lib/switch/index.js +31 -16
- package/lib/switch/index.less_inline.js +1 -2
- package/lib/tabbar/index.js +1 -2
- package/lib/tabbar/index.less_inline.js +1 -2
- package/lib/tabbar/item.js +1 -2
- package/lib/tabbar/item.less_inline.js +1 -2
- package/lib/table/index.js +1 -2
- package/lib/table/index.less_inline.js +1 -2
- package/lib/tabs/index.js +1 -2
- package/lib/tag/index.d.ts +11 -3
- package/lib/tag/index.js +25 -24
- package/lib/tag/index.less_inline.js +2 -3
- package/lib/theme/appearance.d.ts +5 -0
- package/lib/theme/appearance.js +34 -0
- package/lib/theme/index.js +83 -39
- package/lib/theme/index.less_inline.js +1 -2
- package/lib/theme/theme_color.js +1 -2
- package/lib/upload/index.js +28 -41
- package/lib/upload/index.less_inline.js +2 -3
- package/lib/upload/style.js +1 -2
- package/lib/utils/clickoutside.js +1 -2
- package/lib/utils/event.js +1 -2
- package/lib/utils/index.d.ts +27 -6
- package/lib/utils/index.js +26 -6
- package/lib/utils/popover.js +7 -16
- package/lib/utils/transition.js +1 -2
- package/package.json +16 -13
- package/styles/dark.css +10 -2
- package/styles/dropdown.css +46 -0
- package/styles/reset.css +0 -1
- package/styles/select.css +5 -0
- package/styles/themes/apple.css +47 -0
- package/styles/{theme-coral.css → themes/coral.css} +5 -3
- package/styles/themes/deep-sea-blue.css +12 -0
- package/styles/themes/gamboge.css +15 -0
- package/styles/{theme-jade.css → themes/jade.css} +5 -3
- package/styles/themes/lotus-seed.css +12 -0
- package/styles/{theme-tangerine.css → themes/tangerine.css} +5 -3
- package/styles/themes.css +8 -0
- package/styles/vars.css +8 -2
- package/types/preact.d.ts +42 -0
- package/lib/form/types.d.ts +0 -7
- package/lib/utils/context_provide.d.ts +0 -10
- package/lib/utils/context_provide.js +0 -22
- package/lib/utils/locale.d.ts +0 -6
- package/lib/utils/locale.js +0 -34
- package/lib/utils/signal_types.d.ts +0 -5
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// src/components/form/autocomplete.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
let t = e?.toLowerCase();
|
|
4
|
+
return t === "on" || t === "off" ? t : void 0;
|
|
5
|
+
}
|
|
6
|
+
var t = class {
|
|
7
|
+
host;
|
|
8
|
+
owner;
|
|
9
|
+
publish;
|
|
10
|
+
observer;
|
|
11
|
+
observedOwner;
|
|
12
|
+
assigned = /* @__PURE__ */ new Map();
|
|
13
|
+
constructor(e, t, n) {
|
|
14
|
+
this.host = e, this.owner = t, this.publish = n;
|
|
15
|
+
}
|
|
16
|
+
start() {
|
|
17
|
+
this.observer || (this.observer = new MutationObserver((e) => {
|
|
18
|
+
this.readAuthoredChanges(e), this.refresh();
|
|
19
|
+
}), this.observe(), this.refresh());
|
|
20
|
+
}
|
|
21
|
+
observe(e) {
|
|
22
|
+
this.observer.disconnect(), this.observer.observe(this.host, {
|
|
23
|
+
childList: !0,
|
|
24
|
+
subtree: !0,
|
|
25
|
+
attributes: !0,
|
|
26
|
+
attributeFilter: ["autocomplete"]
|
|
27
|
+
}), e && !this.host.contains(e) && this.observer.observe(e, {
|
|
28
|
+
attributes: !0,
|
|
29
|
+
attributeFilter: ["autocomplete"]
|
|
30
|
+
}), this.observedOwner = e;
|
|
31
|
+
}
|
|
32
|
+
readAuthoredChanges(e) {
|
|
33
|
+
for (let t of e) t.type === "attributes" && this.assigned.delete(t.target);
|
|
34
|
+
}
|
|
35
|
+
refresh() {
|
|
36
|
+
this.readAuthoredChanges(this.observer?.takeRecords() ?? []);
|
|
37
|
+
let { form: t, ownsForm: n } = this.owner();
|
|
38
|
+
this.observer && t !== this.observedOwner && this.observe(t);
|
|
39
|
+
let r = e(this.host.getAttribute("autocomplete"));
|
|
40
|
+
n && t && (r === void 0 ? t.removeAttribute("autocomplete") : t.getAttribute("autocomplete") !== r && t.setAttribute("autocomplete", r));
|
|
41
|
+
let i = r ?? e(t?.getAttribute("autocomplete") ?? null);
|
|
42
|
+
if (this.observer) {
|
|
43
|
+
let e = new Set([...this.host.querySelectorAll("input,textarea,select")].filter((e) => e.closest("l-form") === this.host));
|
|
44
|
+
for (let [t, n] of this.assigned) e.has(t) && i !== void 0 || (t.getAttribute("autocomplete") === n && t.removeAttribute("autocomplete"), this.assigned.delete(t));
|
|
45
|
+
if (i !== void 0) for (let t of e) {
|
|
46
|
+
let e = t.getAttribute("autocomplete");
|
|
47
|
+
(e === null || e === this.assigned.get(t)) && (e !== i && t.setAttribute("autocomplete", i), this.assigned.set(t, i));
|
|
48
|
+
}
|
|
49
|
+
this.observer.takeRecords();
|
|
50
|
+
}
|
|
51
|
+
this.publish(i);
|
|
52
|
+
}
|
|
53
|
+
stop() {
|
|
54
|
+
this.readAuthoredChanges(this.observer?.takeRecords() ?? []), this.observer?.disconnect(), this.observer = void 0, this.observedOwner = void 0;
|
|
55
|
+
for (let [e, t] of this.assigned) e.getAttribute("autocomplete") === t && e.removeAttribute("autocomplete");
|
|
56
|
+
this.assigned.clear();
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
export { t as FormAutocomplete, e as normalizeFormAutocomplete };
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 表单内部的无依赖通信协议,不负责发现字段或管理原生 form 所有权。
|
|
3
|
+
* 当前调用:tests/form-context.test.mjs;tests/form-lifecycle.fixture.html 通过
|
|
4
|
+
* scripts/check-form-owner.mjs 提供的 /context.js 加载本模块。
|
|
5
|
+
* 生产 Form/FormItem/FormInner/CheckGroup 已通过 T356 使用本协议,无旧 signal 并行链路。
|
|
6
|
+
* vite.config.ts 将本文件排除出独立入口扫描,不是供使用者导入的公共组件入口。
|
|
7
|
+
*/
|
|
8
|
+
/** 上下文提供者类别;provideFormContext 与 requestFormContext 用它匹配最近的同类祖先。 */
|
|
9
|
+
export type FormContextKind = "form" | "item" | "group";
|
|
10
|
+
/**
|
|
11
|
+
* 配置快照:由提供者读取、配置更新事件传递、resolveFieldContext 合并。
|
|
12
|
+
* 生产中分别来自 Form、FormItem 和 Group;协议测试和浏览器样例同时覆盖。
|
|
13
|
+
* 仅含行为配置;标签尺寸等纯样式优先通过 CSS 变量继承。
|
|
14
|
+
*/
|
|
15
|
+
export interface FormContextSnapshot {
|
|
16
|
+
/** 未设置时继承;false 是明确的局部覆盖,不等于缺省。 */
|
|
17
|
+
readonly innerBlock?: boolean;
|
|
18
|
+
/** 自身或上级禁用来源;最终有效禁用取所有来源的逻辑或。 */
|
|
19
|
+
readonly disabled?: boolean;
|
|
20
|
+
readonly autocomplete?: "on" | "off";
|
|
21
|
+
readonly required?: boolean;
|
|
22
|
+
/** FormItem 提供的后备字段名,不能当成控件显式设置的 name。 */
|
|
23
|
+
readonly prop?: string;
|
|
24
|
+
/** CheckGroup 的当前选中 token,由普通配置通知同步成员。 */
|
|
25
|
+
readonly values?: readonly string[];
|
|
26
|
+
readonly multiple?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** 错误展示通知;实际有效性变化使用独立的 nativeValidity 事件。 */
|
|
29
|
+
export interface FormFieldValidity {
|
|
30
|
+
readonly valid: boolean;
|
|
31
|
+
readonly message?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface NativeFieldValidity extends FormFieldValidity {
|
|
34
|
+
readonly flags: Readonly<ValidityStateFlags>;
|
|
35
|
+
readonly constraintMessage?: string;
|
|
36
|
+
readonly willValidate: boolean;
|
|
37
|
+
readonly duringReset?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** 当前业务值快照;由已登记字段的 getSnapshot 返回,不是原生 FormData 提交条目。 */
|
|
40
|
+
export interface FormFieldSnapshot {
|
|
41
|
+
readonly name?: string;
|
|
42
|
+
readonly value: unknown;
|
|
43
|
+
/** 自身或上级禁用来源;最终有效禁用取所有来源的逻辑或。 */
|
|
44
|
+
readonly disabled?: boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 字段登记适配接口;createFormContextProvider 以这个对象的身份去重。
|
|
48
|
+
* 由 FormInner/FormItem 提供稳定实例,协议测试及浏览器样例同时覆盖。
|
|
49
|
+
* 改名或改值时调用 getSnapshot 读取新状态,不另存一份持续同步的业务值缓存。
|
|
50
|
+
*/
|
|
51
|
+
export interface FormContextField {
|
|
52
|
+
/** 定向配置/有效性事件的接收目标,通常为字段宿主元素。 */
|
|
53
|
+
readonly target: EventTarget;
|
|
54
|
+
/** 由未来表单数据收集调用;登记期间始终返回当前 name、value 和自身禁用状态。 */
|
|
55
|
+
getSnapshot(): FormFieldSnapshot;
|
|
56
|
+
}
|
|
57
|
+
/** 最小提供者契约;provideFormContext 对外响应此对象,requestFormContext 将其返回给字段。 */
|
|
58
|
+
export interface FormContextProvider {
|
|
59
|
+
/** 字段初始化/重新关联时读取;返回新副本或不可变快照,而非共享可变状态源。 */
|
|
60
|
+
getSnapshot(): Readonly<FormContextSnapshot>;
|
|
61
|
+
/** 字段挂载时登记,返回可重复调用的注销函数;移动/断开前由调用方执行注销。 */
|
|
62
|
+
registerField(field: FormContextField): () => void;
|
|
63
|
+
fieldNameChanged?(field: FormContextField, name: string | undefined, previousName?: string): void;
|
|
64
|
+
fieldValidityCleared?(field: FormContextField): void;
|
|
65
|
+
fieldValueChanged?(field: FormContextField): void;
|
|
66
|
+
/** 组成员的值或有效禁用改变时,组需要重新计算提交值。 */
|
|
67
|
+
fieldStateChanged?(): void;
|
|
68
|
+
/** 组根据当前值决定成员的选中状态。 */
|
|
69
|
+
getFieldChecked?(target: EventTarget): boolean;
|
|
70
|
+
/** 用户操作组成员时,由组应用选中状态。 */
|
|
71
|
+
requestFieldChecked?(target: EventTarget, checked: boolean): void;
|
|
72
|
+
/** 单选组的成员供方向键导航使用。 */
|
|
73
|
+
getRadioMembers?(): readonly EventTarget[];
|
|
74
|
+
/** 用户编辑完成后,由表单按当前值校验该字段及依赖它的字段。 */
|
|
75
|
+
validateInput?(field: FormContextField): void;
|
|
76
|
+
}
|
|
77
|
+
/** createFormContextProvider 的返回接口;供宿主更新配置、通知错误并在销毁时清理登记。 */
|
|
78
|
+
export interface ManagedFormContextProvider extends FormContextProvider {
|
|
79
|
+
registerField(field: FormContextField, initializeValidity?: () => void): () => boolean;
|
|
80
|
+
/** 宿主读取当前字段列表的副本,不向外暴露内部 Set。 */
|
|
81
|
+
getFields(): readonly FormContextField[];
|
|
82
|
+
getFieldsByName(name: string): readonly FormContextField[];
|
|
83
|
+
updateFieldName(field: FormContextField, name: string | undefined): boolean;
|
|
84
|
+
/** 宿主属性变化时整体替换配置并通知字段,使已移除的配置恢复继承。 */
|
|
85
|
+
updateConfiguration(snapshot: Readonly<FormContextSnapshot>): void;
|
|
86
|
+
/** 校验协调方调用;仅向当前仍登记的字段发送有效性通知,不执行校验规则。 */
|
|
87
|
+
notifyValidity(field: FormContextField, validity: Readonly<FormFieldValidity>): void;
|
|
88
|
+
/** 宿主销毁时清空登记;请求监听器须另调用 provideFormContext 返回的清理函数移除。 */
|
|
89
|
+
dispose(): void;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 为单个 Form/FormItem/Group 创建最小字段集合及配置快照管理器。
|
|
93
|
+
* 由生产 Form/FormItem/CheckGroup 及协议测试、生命周期样例创建并持有。
|
|
94
|
+
* 不发现 DOM 所有权、不提供通用订阅系统;字段负责登记与注销,宿主负责 dispose。
|
|
95
|
+
* 重复登记同一字段只保留一项;旧注销函数不会误删后一次登记。
|
|
96
|
+
*/
|
|
97
|
+
export declare function createFormContextProvider(initialSnapshot?: Readonly<FormContextSnapshot>): ManagedFormContextProvider;
|
|
98
|
+
/** 本模块事件名;由提供/请求函数及定向通知函数使用,测试和未来字段监听方按此绑定。 */
|
|
99
|
+
export declare const FORM_CONTEXT_EVENTS: {
|
|
100
|
+
readonly request: "l-form-context-request";
|
|
101
|
+
readonly configuration: "l-form-context-configuration";
|
|
102
|
+
readonly validity: "l-form-context-validity";
|
|
103
|
+
readonly nativeValidity: "l-form-field-validity-change";
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* 在宿主安装某一类别的上下文响应监听器;当前由协议测试和浏览器样例调用。
|
|
107
|
+
* 由 Form/FormItem/Group 初始化时调用,销毁时执行返回的清理函数。
|
|
108
|
+
* 请求沿冒泡及 composed 路径传播,最近同类提供者响应后停止后续传播;宿主自己
|
|
109
|
+
* 请求同类上下文时跳过自身。此函数不扫描 DOM、不推断 owner,也不自动登记字段。
|
|
110
|
+
*/
|
|
111
|
+
export declare function provideFormContext(target: EventTarget, kind: FormContextKind, provider: FormContextProvider): () => void;
|
|
112
|
+
/**
|
|
113
|
+
* 从字段目标同步请求最近同类上下文;当前测试验证包装节点、移动及 Shadow DOM 路径。
|
|
114
|
+
* 由控件/上下文消费者挂载或重新关联时调用,找不到时返回 undefined。
|
|
115
|
+
* 返回提供者不等于已登记;调用方还需 registerField,并在移动前清理旧登记。
|
|
116
|
+
* 本函数不持有提供者或安装长期监听器。
|
|
117
|
+
*/
|
|
118
|
+
export declare function requestFormContext(target: EventTarget, kind: FormContextKind): FormContextProvider | undefined;
|
|
119
|
+
/**
|
|
120
|
+
* 向单个字段目标发送配置副本;createFormContextProvider.updateConfiguration 内部调用。
|
|
121
|
+
* 字段监听 FORM_CONTEXT_EVENTS.configuration 后重新计算配置;事件不冒泡、不跨树,
|
|
122
|
+
* 不是父级向整棵子树广播,也不会自动修改控件属性或 DOM。
|
|
123
|
+
*/
|
|
124
|
+
export declare function notifyFormConfiguration(target: EventTarget, snapshot: Readonly<FormContextSnapshot>): void;
|
|
125
|
+
/**
|
|
126
|
+
* 向字段或 FormItem 发送错误展示状态。提供者 notifyValidity 调用此函数。
|
|
127
|
+
* 事件不冒泡、不跨树,只更新视图。实际有效性由字段同步。
|
|
128
|
+
*/
|
|
129
|
+
export declare function notifyFormValidity(target: EventTarget, validity: Readonly<FormFieldValidity>): void;
|
|
130
|
+
/** resolveFieldContext 的计算结果;未来由控件应用到名称、布局和交互状态,不反写显式配置。 */
|
|
131
|
+
export interface ResolvedFieldContext {
|
|
132
|
+
readonly name?: string;
|
|
133
|
+
readonly innerBlock: boolean;
|
|
134
|
+
readonly disabled: boolean;
|
|
135
|
+
readonly required: boolean;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* 纯函数合并本地与上级配置;当前由单元测试和浏览器样例使用,由字段配置更新入口调用。
|
|
139
|
+
* innerBlock/required 优先级为本地 > Group > FormItem > Form,明确的 false 可以覆盖。
|
|
140
|
+
* disabled 对所有来源取逻辑或,本地 false 不能解除父级禁用;自身禁用需另行保存,
|
|
141
|
+
* 才能在父级解除禁用后恢复。fieldset 的有效禁用由后续原生回调另外叠加。
|
|
142
|
+
* 显式 name(含空字符串)优先于 item.prop;传 undefined 表示移除覆盖并恢复继承。
|
|
143
|
+
* 不把继承名称写回显式 name。增删配置或移动后传入全新快照,不合并陈旧结果。
|
|
144
|
+
*/
|
|
145
|
+
export declare function resolveFieldContext(local: Readonly<FormContextSnapshot> & {
|
|
146
|
+
readonly name?: string;
|
|
147
|
+
}, contexts?: {
|
|
148
|
+
readonly form?: Readonly<FormContextSnapshot>;
|
|
149
|
+
readonly item?: Readonly<FormContextSnapshot>;
|
|
150
|
+
readonly group?: Readonly<FormContextSnapshot>;
|
|
151
|
+
}): ResolvedFieldContext;
|
|
152
|
+
/**
|
|
153
|
+
* 将 HTML 布尔配置转为三态输入,供 attributeChanged 的配置读取入口使用。
|
|
154
|
+
* 生产 FormInner/FormItem 及单元测试调用:移除属性为 undefined(继承),空值/属性名为 true,
|
|
155
|
+
* 忽略大小写和首尾空白的 false 为 false;其他字符串保持 true,不等同原生布尔属性解析。
|
|
156
|
+
*/
|
|
157
|
+
export declare function readFormBooleanAttribute(value: string | null): boolean | undefined;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// src/components/form/context.ts
|
|
2
|
+
function e(e = {}) {
|
|
3
|
+
let t = { ...e }, n = /* @__PURE__ */ new Map(), r;
|
|
4
|
+
function o(e, t) {
|
|
5
|
+
if (!t || !r) return;
|
|
6
|
+
let n = r.get(t);
|
|
7
|
+
n?.delete(e), n?.size === 0 && r.delete(t);
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
getSnapshot: () => ({ ...t }),
|
|
11
|
+
getFields: () => [...n.keys()],
|
|
12
|
+
getFieldsByName: (e) => [...r?.get(e) ?? []],
|
|
13
|
+
registerField(e, t) {
|
|
14
|
+
let r = {
|
|
15
|
+
name: n.get(e)?.name,
|
|
16
|
+
validityNotified: !1
|
|
17
|
+
};
|
|
18
|
+
return n.set(e, r), t && queueMicrotask(() => {
|
|
19
|
+
n.get(e) === r && !r.validityNotified && t();
|
|
20
|
+
}), () => n.get(e) === r && (o(e, r.name), n.delete(e));
|
|
21
|
+
},
|
|
22
|
+
updateFieldName(e, t) {
|
|
23
|
+
let i = n.get(e), a = t || void 0;
|
|
24
|
+
if (!i || i.name === a) return !1;
|
|
25
|
+
if (o(e, i.name), i.name = a, a) {
|
|
26
|
+
r ??= /* @__PURE__ */ new Map();
|
|
27
|
+
let t = r.get(a);
|
|
28
|
+
t || (t = /* @__PURE__ */ new Set(), r.set(a, t)), t.add(e);
|
|
29
|
+
}
|
|
30
|
+
return !0;
|
|
31
|
+
},
|
|
32
|
+
updateConfiguration(e) {
|
|
33
|
+
t = { ...e };
|
|
34
|
+
let r = [...n.keys()];
|
|
35
|
+
for (let e of r) n.has(e) && i(e.target, t);
|
|
36
|
+
},
|
|
37
|
+
notifyValidity(e, t) {
|
|
38
|
+
let r = n.get(e);
|
|
39
|
+
r && (r.validityNotified = !0, a(e.target, t));
|
|
40
|
+
},
|
|
41
|
+
dispose() {
|
|
42
|
+
n.clear(), r?.clear();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
var t = {
|
|
47
|
+
request: "l-form-context-request",
|
|
48
|
+
configuration: "l-form-context-configuration",
|
|
49
|
+
validity: "l-form-context-validity",
|
|
50
|
+
nativeValidity: "l-form-field-validity-change"
|
|
51
|
+
};
|
|
52
|
+
function n(e, n, r) {
|
|
53
|
+
let i = (t) => {
|
|
54
|
+
let i = t.detail;
|
|
55
|
+
i && i.kind === n && i.requester !== e && !i.provider && (i.provider = r, t.stopImmediatePropagation());
|
|
56
|
+
};
|
|
57
|
+
return e.addEventListener(t.request, i), () => e.removeEventListener(t.request, i);
|
|
58
|
+
}
|
|
59
|
+
function r(e, n) {
|
|
60
|
+
let r = {
|
|
61
|
+
kind: n,
|
|
62
|
+
requester: e
|
|
63
|
+
};
|
|
64
|
+
return e.dispatchEvent(new CustomEvent(t.request, {
|
|
65
|
+
detail: r,
|
|
66
|
+
bubbles: !0,
|
|
67
|
+
composed: !0
|
|
68
|
+
})), r.provider;
|
|
69
|
+
}
|
|
70
|
+
function i(e, n) {
|
|
71
|
+
e.dispatchEvent(new CustomEvent(t.configuration, { detail: { ...n } }));
|
|
72
|
+
}
|
|
73
|
+
function a(e, n) {
|
|
74
|
+
e.dispatchEvent(new CustomEvent(t.validity, { detail: { ...n } }));
|
|
75
|
+
}
|
|
76
|
+
function o(e, t = {}) {
|
|
77
|
+
let { form: n, item: r, group: i } = t;
|
|
78
|
+
return {
|
|
79
|
+
name: e.name ?? r?.prop,
|
|
80
|
+
innerBlock: e.innerBlock ?? i?.innerBlock ?? r?.innerBlock ?? n?.innerBlock ?? !1,
|
|
81
|
+
disabled: !!(e.disabled || i?.disabled || r?.disabled || n?.disabled),
|
|
82
|
+
required: e.required ?? i?.required ?? r?.required ?? n?.required ?? !1
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function s(e) {
|
|
86
|
+
if (e !== null) return e.trim().toLowerCase() !== "false";
|
|
87
|
+
}
|
|
88
|
+
export { t as FORM_CONTEXT_EVENTS, e as createFormContextProvider, i as notifyFormConfiguration, a as notifyFormValidity, n as provideFormContext, s as readFormBooleanAttribute, r as requestFormContext, o as resolveFieldContext };
|
package/lib/form/form_inner.d.ts
CHANGED
|
@@ -1,47 +1,122 @@
|
|
|
1
|
-
import type { Signal } from "../utils/signal_types";
|
|
2
1
|
import BaseComponent from "../base";
|
|
3
|
-
import
|
|
2
|
+
import { type NativeFieldControl } from "./accessibility";
|
|
3
|
+
import type { FormContextField, FormContextProvider } from "./context";
|
|
4
|
+
/** 原生表单控件公共基类;所有权由 FormOwner 维护,上下文只使用普通请求/定向事件。 */
|
|
4
5
|
export default class FormInner<T = Record<string, any>> extends BaseComponent<T> {
|
|
6
|
+
#private;
|
|
7
|
+
static formAssociated: boolean;
|
|
8
|
+
protected readonly internals: ElementInternals;
|
|
5
9
|
_disabled: boolean;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
private
|
|
10
|
-
private
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
private
|
|
16
|
-
private
|
|
17
|
-
private
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
10
|
+
protected dirtyValue: boolean;
|
|
11
|
+
private applyingDefault;
|
|
12
|
+
private applyingFormReset;
|
|
13
|
+
private valueInitialized;
|
|
14
|
+
private ownDisabled;
|
|
15
|
+
private nativeDisabled;
|
|
16
|
+
private contextDisabled;
|
|
17
|
+
protected contextRequired: boolean;
|
|
18
|
+
private explicitName?;
|
|
19
|
+
private effectiveName?;
|
|
20
|
+
private syncedNameAttribute;
|
|
21
|
+
private reflectingDisabled;
|
|
22
|
+
private connecting;
|
|
23
|
+
private unregister;
|
|
24
|
+
protected groupContext?: FormContextProvider;
|
|
25
|
+
private formContext?;
|
|
26
|
+
private itemContext?;
|
|
27
|
+
private manualValidity;
|
|
28
|
+
private manualMessage;
|
|
29
|
+
private businessMessage?;
|
|
30
|
+
private nativeValidity?;
|
|
31
|
+
private displayedValidityMessage?;
|
|
32
|
+
private itemPresentation?;
|
|
33
|
+
private accessibilityControl?;
|
|
34
|
+
private fieldAccessibility?;
|
|
35
|
+
private accessibilityObserver?;
|
|
36
|
+
protected readonly contextField: FormContextField;
|
|
37
|
+
constructor(delegatesFocus?: boolean);
|
|
38
|
+
get nativeValueEnabled(): boolean;
|
|
39
|
+
/** 组成员由组统一提交/收集,Check 覆盖此标志。 */
|
|
40
|
+
get grouped(): boolean;
|
|
41
|
+
get valueSnapshot(): any;
|
|
42
|
+
/** @internal 由选中状态决定必填的控件可提供结果。 */
|
|
43
|
+
get requiredSelection(): boolean | undefined;
|
|
44
|
+
get form(): HTMLFormElement | null;
|
|
45
|
+
get labels(): NodeList;
|
|
46
|
+
get validity(): ValidityState;
|
|
47
|
+
get validationMessage(): string;
|
|
48
|
+
/** @internal 原生约束和手动错误的提示,独立于业务规则的 customError。 */
|
|
49
|
+
get constraintValidationMessage(): string | undefined;
|
|
50
|
+
get willValidate(): boolean;
|
|
51
|
+
checkValidity(): boolean;
|
|
52
|
+
reportValidity(): boolean;
|
|
53
|
+
setValidity(flags?: ValidityStateFlags, message?: string, anchor?: HTMLElement): void;
|
|
24
54
|
get name(): string | undefined;
|
|
25
55
|
set name(value: string | undefined);
|
|
56
|
+
get autocomplete(): string;
|
|
57
|
+
set autocomplete(value: string | null | undefined);
|
|
26
58
|
get value(): any;
|
|
27
59
|
set value(value: any);
|
|
28
60
|
setValue(value: any): void;
|
|
61
|
+
protected notifyFieldValueChanged(): void;
|
|
29
62
|
getValue(): any;
|
|
63
|
+
/** 默认值来源于 value attribute;程序赋值/用户输入不再捕获为重置基线。 */
|
|
64
|
+
get defaultValue(): any;
|
|
65
|
+
set defaultValue(value: any);
|
|
66
|
+
protected get intrinsicDefaultValue(): any;
|
|
67
|
+
protected parseDefaultValue(value: string | null): any;
|
|
68
|
+
protected formatDefaultValue(value: any): string;
|
|
69
|
+
/** 默认同步走派生 setter 更新 UI,但不把控件标记为已编辑,也不伪造用户事件。 */
|
|
70
|
+
protected applyDefaultValue(): void;
|
|
71
|
+
protected copyValue(value: any): any;
|
|
30
72
|
static get observedAttributes(): string[];
|
|
31
73
|
protected attributeChanged(name: string, oldValue: string, newValue: string): void;
|
|
32
74
|
protected attributeChange(_name: string, _oldValue: string, _newValue: string): void;
|
|
33
75
|
connectedCallback(): void;
|
|
34
76
|
disconnectedCallback(): void;
|
|
77
|
+
private unbindContexts;
|
|
78
|
+
refreshFormContext(): void;
|
|
79
|
+
protected validateInput(): void;
|
|
80
|
+
private bindContexts;
|
|
81
|
+
private configurationChanged;
|
|
82
|
+
private validityChanged;
|
|
83
|
+
/** @internal 表单已执行的规则结果,与外部提示和手动 setValidity 分开。 */
|
|
84
|
+
applyBusinessValidity(message?: string): void;
|
|
85
|
+
protected refreshConfiguration(): void;
|
|
35
86
|
isDisabled(): boolean;
|
|
36
87
|
get disabled(): boolean;
|
|
37
88
|
set disabled(value: boolean);
|
|
38
89
|
setDisabled(value: boolean): void;
|
|
90
|
+
private applyDisabled;
|
|
39
91
|
getName(): string | undefined;
|
|
92
|
+
protected configurationApplied(): void;
|
|
40
93
|
protected disabledChange(): void;
|
|
41
94
|
protected innerBlockChange(_innerBlock: boolean): void;
|
|
42
|
-
protected validResult(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
95
|
+
protected validResult(message?: string): void;
|
|
96
|
+
/** @internal 单一编辑控件才可作为行标签的聚焦目标。 */
|
|
97
|
+
get formItemControl(): NativeFieldControl | undefined;
|
|
98
|
+
/** @internal 行标签和错误随控件归属变化。 */
|
|
99
|
+
setFormItemPresentation(owner: HTMLElement, label?: string, error?: string, groupError?: string): void;
|
|
100
|
+
protected get fallbackAccessibleName(): string | undefined;
|
|
101
|
+
private syncFieldAccessibility;
|
|
102
|
+
/** 原生 owner 的每次变化都重新登记,不缓存首次 owner。 */
|
|
103
|
+
formAssociatedCallback(_form: HTMLFormElement | null): void;
|
|
104
|
+
formDisabledCallback(disabled: boolean): void;
|
|
105
|
+
protected serializeFormValue(): string | File | FormData | null;
|
|
106
|
+
/** 字段可拒绝保存和重放历史状态,同时继续参与提交和原生自动填充。 */
|
|
107
|
+
protected get formStateRestorationEnabled(): boolean;
|
|
108
|
+
protected get acceptsAutocompleteText(): boolean;
|
|
109
|
+
/** Safari 16.4 基线使用版本化字符串;显式 null 禁止保存该字段的恢复 state。 */
|
|
110
|
+
protected serializeFormState(): string | null;
|
|
111
|
+
protected syncNativeValue(): void;
|
|
112
|
+
protected syncAutocomplete(): void;
|
|
113
|
+
formResetCallback(): void;
|
|
114
|
+
formStateRestoreCallback(state: string | File | FormData | null, mode: "restore" | "autocomplete"): void;
|
|
115
|
+
/** 将宿主约束显式应用到探测用原生 input,不让 Shadow DOM input 变成第二个字段。 */
|
|
116
|
+
protected get nativeBadInput(): boolean;
|
|
117
|
+
protected get nativeValueMissing(): boolean | undefined;
|
|
118
|
+
protected get nativeSubmissionError(): string | undefined;
|
|
119
|
+
protected get nativeConstraintValues(): readonly unknown[];
|
|
120
|
+
protected syncNativeValidity(manualAnchor?: HTMLElement): void;
|
|
46
121
|
reset(): void;
|
|
47
122
|
}
|