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
package/lib/form/index.js
CHANGED
|
@@ -1,25 +1,267 @@
|
|
|
1
|
-
import e from "../
|
|
2
|
-
import
|
|
3
|
-
import i from "
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { kebabToCamel as e, parseAttrValue as t, unitNumberStr as n } from "../utils/index.js";
|
|
2
|
+
import r from "./style.js";
|
|
3
|
+
import i from "../base.js";
|
|
4
|
+
import a from "./form_inner.js";
|
|
5
|
+
import o from "./form_item.js";
|
|
6
|
+
import { FormOwner as s, listenFormSubmit as c } from "./owner.js";
|
|
7
|
+
import { FormAutocomplete as l, normalizeFormAutocomplete as u } from "./autocomplete.js";
|
|
8
|
+
import { FORM_CONTEXT_EVENTS as d, createFormContextProvider as f, provideFormContext as p } from "./context.js";
|
|
9
|
+
import { $one as m, formatClass as h, off as g, on as _ } from "utilane/browser";
|
|
10
|
+
import { Validator as v } from "utilane";
|
|
11
|
+
// src/components/form/index.ts
|
|
12
|
+
var y = () => !0, b = () => !1, x = new WeakSet([y, b]);
|
|
13
|
+
function S(e) {
|
|
14
|
+
if (e instanceof a) return e.valueSnapshot;
|
|
15
|
+
if (e instanceof HTMLInputElement) {
|
|
16
|
+
if (e.type === "checkbox") return e.checked;
|
|
17
|
+
if (e.type === "file") return e.multiple ? Array.from(e.files ?? []) : e.files?.item(0) ?? null;
|
|
18
|
+
}
|
|
19
|
+
return e instanceof HTMLSelectElement && e.multiple ? Array.from(e.selectedOptions, ({ value: e }) => e) : e.value;
|
|
20
|
+
}
|
|
21
|
+
function C(e, t) {
|
|
22
|
+
return Object.hasOwn(e.rules, t) ? e.rules[t] : [];
|
|
23
|
+
}
|
|
24
|
+
function w(e) {
|
|
25
|
+
for (let t of e) {
|
|
26
|
+
let e = t.rule;
|
|
27
|
+
if (typeof e != "function" || x.has(e)) continue;
|
|
28
|
+
let n = function(t) {
|
|
29
|
+
let n = e.call(this, t);
|
|
30
|
+
if (n && typeof n.then == "function") throw Promise.resolve(n).catch(() => {}), TypeError("校验规则必须同步返回布尔值,不支持 Promise。");
|
|
31
|
+
return !!n;
|
|
32
|
+
};
|
|
33
|
+
x.add(n), t.rule = n;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function T({ rule: e }) {
|
|
37
|
+
return e === "required" || e === y || e === b;
|
|
38
|
+
}
|
|
39
|
+
function E(e, t, n, r, i) {
|
|
40
|
+
w(r);
|
|
41
|
+
let a = i === void 0 ? "required" : i ? y : b, o = /* @__PURE__ */ new Map();
|
|
42
|
+
try {
|
|
43
|
+
for (let e of r) T(e) && e.rule !== a && (o.set(e, e.rule), e.rule = a);
|
|
44
|
+
e.validateKey(t, n[t], n);
|
|
45
|
+
} finally {
|
|
46
|
+
for (let [e, t] of o) e.rule === a && (e.rule = t);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function D(e) {
|
|
50
|
+
return Object.getOwnPropertyDescriptor(HTMLFormElement.prototype, "elements").get.call(e);
|
|
51
|
+
}
|
|
52
|
+
var O = class extends v {
|
|
53
|
+
onSchemaRemoved;
|
|
54
|
+
setSchemas(e) {
|
|
55
|
+
this.dependentsBySource = /* @__PURE__ */ new Map();
|
|
56
|
+
let t;
|
|
57
|
+
try {
|
|
58
|
+
t = super.setSchemas(e);
|
|
59
|
+
} catch (e) {
|
|
60
|
+
for (let [e, t] of Object.entries(this.rules)) this.indexDependencies({
|
|
61
|
+
key: e,
|
|
62
|
+
rules: t
|
|
63
|
+
});
|
|
64
|
+
throw e;
|
|
65
|
+
}
|
|
66
|
+
let n = new Map(t.map((e) => [e.key, e]));
|
|
67
|
+
for (let e of n.values()) this.indexDependencies(e);
|
|
68
|
+
return t;
|
|
69
|
+
}
|
|
70
|
+
setSchema(e) {
|
|
71
|
+
let t = Object.hasOwn(this.rules, e.key) ? this.rules[e.key] : [], n = super.setSchema(e);
|
|
72
|
+
return this.removeDependencies(n.key, t), this.indexDependencies(n), n;
|
|
73
|
+
}
|
|
74
|
+
addSchema(e) {
|
|
75
|
+
let t = super.addSchema(e);
|
|
76
|
+
return this.indexDependencies(t), t;
|
|
77
|
+
}
|
|
78
|
+
removeSchema(e) {
|
|
79
|
+
this.replaceRules(e, []), this.onSchemaRemoved?.(e);
|
|
80
|
+
}
|
|
81
|
+
replaceRules(e, t) {
|
|
82
|
+
this.removeDependencies(e, C(this, e)), super.removeSchema(e), t.length !== 0 && (this.rules[e] = t, this.indexDependencies({
|
|
83
|
+
key: e,
|
|
84
|
+
rules: t
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
indexDependencies({ key: e, rules: t }) {
|
|
88
|
+
for (let { sameKey: n } of t) {
|
|
89
|
+
if (n === void 0 || n === e) continue;
|
|
90
|
+
let t = this.dependentsBySource.get(n);
|
|
91
|
+
t || (t = /* @__PURE__ */ new Set(), this.dependentsBySource.set(n, t)), t.add(e);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
removeDependencies(e, t) {
|
|
95
|
+
for (let { sameKey: n } of t) {
|
|
96
|
+
if (n === void 0) continue;
|
|
97
|
+
let t = this.dependentsBySource.get(n);
|
|
98
|
+
t?.delete(e), t?.size === 0 && this.dependentsBySource.delete(n);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
getInputValidationFields(e) {
|
|
102
|
+
let t = [...this.dependentsBySource.get(e) ?? []];
|
|
103
|
+
return Object.hasOwn(this.rules, e) && t.unshift(e), t;
|
|
104
|
+
}
|
|
105
|
+
}, k = class extends i {
|
|
9
106
|
static baseName = "form";
|
|
10
107
|
validator;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
108
|
+
errorMessages = Object.create(null);
|
|
109
|
+
errorRevision = 0;
|
|
110
|
+
displayRevisions = /* @__PURE__ */ new Map();
|
|
111
|
+
businessErrors = /* @__PURE__ */ new Map();
|
|
112
|
+
displayedBusinessErrors = /* @__PURE__ */ new Set();
|
|
113
|
+
nativeFeedback = /* @__PURE__ */ new Map();
|
|
114
|
+
pendingNativeReports = /* @__PURE__ */ new Map();
|
|
115
|
+
itemRules = /* @__PURE__ */ new Map();
|
|
116
|
+
nativeOwner = new s(this, () => (this.nativeFeedback.size && queueMicrotask(this.reconcileNativeFeedback), [...this.fields(), ...this.querySelectorAll("button, l-button")]));
|
|
117
|
+
fieldContext = f();
|
|
118
|
+
autocompleteConfiguration = new l(this, () => (this.nativeOwner.refreshPending(), {
|
|
119
|
+
form: this.nativeOwner.form,
|
|
120
|
+
ownsForm: this.nativeOwner.ownsForm
|
|
121
|
+
}), (e) => this.fieldContext.updateConfiguration({
|
|
122
|
+
innerBlock: this._state.innerBlock,
|
|
123
|
+
disabled: this._state.disabled,
|
|
124
|
+
autocomplete: e
|
|
125
|
+
}));
|
|
126
|
+
locallyClearedFields = /* @__PURE__ */ new Set();
|
|
127
|
+
disposeContext;
|
|
128
|
+
provider = {
|
|
129
|
+
getSnapshot: () => this.fieldContext.getSnapshot(),
|
|
130
|
+
registerField: (e) => {
|
|
131
|
+
e.target instanceof a && this.nativeOwner.scheduleRefresh();
|
|
132
|
+
let t = this.fieldContext.registerField(e, () => this.initializeFieldValidity(e));
|
|
133
|
+
return this.fieldContext.updateFieldName(e, this.fieldName(e)), () => {
|
|
134
|
+
t() && (this.locallyClearedFields.delete(e), e.target instanceof o ? this.replaceItemRules(e.target) : e.target instanceof a && (!this.isDataField(e.target) || e.target.form !== this.nativeOwner.form) && this.invalidateBusinessRules(e.target.name));
|
|
135
|
+
};
|
|
136
|
+
},
|
|
137
|
+
fieldNameChanged: (e, t, n) => {
|
|
138
|
+
e.target instanceof a && this.invalidateBusinessRules(n), this.fieldContext.updateFieldName(e, t) && this.initializeFieldValidity(e, t);
|
|
139
|
+
},
|
|
140
|
+
fieldValidityCleared: (e) => {
|
|
141
|
+
let t = this.fieldName(e);
|
|
142
|
+
t && this.errorMessages[t] && this.locallyClearedFields.add(e);
|
|
143
|
+
},
|
|
144
|
+
fieldValueChanged: ({ target: e }) => {
|
|
145
|
+
this.businessErrors.size && e instanceof a && this.isDataField(e) && e.form === this.nativeOwner.form && this.invalidateBusinessRules(e.name);
|
|
146
|
+
},
|
|
147
|
+
validateInput: ({ target: e }) => {
|
|
148
|
+
e instanceof a && this.validateInput(e);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
listeningForm;
|
|
152
|
+
stopNativeSubmit;
|
|
153
|
+
resetScope = {};
|
|
154
|
+
validationRoot;
|
|
155
|
+
get nativeForm() {
|
|
156
|
+
return this.nativeOwner.refreshPending(), this.nativeOwner.form;
|
|
157
|
+
}
|
|
158
|
+
get disabled() {
|
|
159
|
+
return this._state.disabled;
|
|
160
|
+
}
|
|
161
|
+
get autocomplete() {
|
|
162
|
+
return u(this.getAttribute("autocomplete")) ?? "";
|
|
163
|
+
}
|
|
164
|
+
set autocomplete(e) {
|
|
165
|
+
e == null || e === "" ? this.removeAttribute("autocomplete") : this.setAttribute("autocomplete", e);
|
|
166
|
+
}
|
|
167
|
+
set disabled(e) {
|
|
168
|
+
e ? this.setAttribute("disabled", "") : this.removeAttribute("disabled");
|
|
169
|
+
}
|
|
170
|
+
fields() {
|
|
171
|
+
return Array.from(this.querySelectorAll("*")).filter((e) => e instanceof a && e.closest("l-form") === this);
|
|
172
|
+
}
|
|
173
|
+
nativeReset = (e) => {
|
|
174
|
+
if (e.target !== this.listeningForm) return;
|
|
175
|
+
let t = this.resetScope, n = this.errorRevision;
|
|
176
|
+
setTimeout(() => {
|
|
177
|
+
if (!e.defaultPrevented && this.isConnected && this.resetScope === t) {
|
|
178
|
+
this.clearPresentation(n);
|
|
179
|
+
for (let [e, t] of this.businessErrors) t.revision <= n && this.updateBusinessErrors({}, [e]);
|
|
180
|
+
}
|
|
181
|
+
}, 0);
|
|
182
|
+
};
|
|
183
|
+
validationField(e) {
|
|
184
|
+
if (!(e instanceof a || e instanceof HTMLInputElement || e instanceof HTMLSelectElement || e instanceof HTMLTextAreaElement) || !this.listeningForm || e.form !== this.listeningForm || !e.isConnected) return;
|
|
185
|
+
let t = e.closest("l-form");
|
|
186
|
+
if (t === this || !t && this.nativeOwner.ownsForm) return e;
|
|
187
|
+
}
|
|
188
|
+
nativeInvalid = (e) => {
|
|
189
|
+
let t = this.validationField(e.target);
|
|
190
|
+
t && this.updateNativeFeedback(t, !0, e.type === "invalid");
|
|
191
|
+
};
|
|
192
|
+
nativeValidityChanged = (e) => {
|
|
193
|
+
if (e.detail?.duringReset) return;
|
|
194
|
+
let t = this.validationField(e.target);
|
|
195
|
+
t && this.updateNativeFeedback(t);
|
|
196
|
+
};
|
|
197
|
+
nativeInput = (e) => {
|
|
198
|
+
let t = this.validationField(e.target);
|
|
199
|
+
t && !(t instanceof a) && (this.updateNativeFeedback(t), this.validateInput(t));
|
|
200
|
+
};
|
|
201
|
+
updateNativeFeedback(e, t = !1, n = !1) {
|
|
202
|
+
let r = this.nativeFeedback.get(e);
|
|
203
|
+
if (!r && (!t || !e.willValidate)) return;
|
|
204
|
+
let i = e.closest("l-form-item"), s = e.name || (i instanceof o ? i.getAttribute("prop") : null) || void 0, c = n || !!r?.fromInvalid, l = e.willValidate ? e instanceof a ? e.constraintValidationMessage ?? (c && e.validationMessage || void 0) : e.validationMessage || void 0 : void 0, u = {
|
|
205
|
+
name: s,
|
|
206
|
+
item: i instanceof o && i.closest("l-form") === this ? i : void 0,
|
|
207
|
+
message: l,
|
|
208
|
+
revision: t || !r ? ++this.errorRevision : r.revision,
|
|
209
|
+
fromInvalid: c
|
|
210
|
+
};
|
|
211
|
+
this.nativeFeedback.set(e, u), (u.message !== r?.message || u.item !== r?.item || u.name !== r?.name) && this.notifyNativeFeedback(e, r, u);
|
|
212
|
+
}
|
|
213
|
+
notifyNativeFeedback(e, t, n) {
|
|
214
|
+
if (t?.message || n?.message) {
|
|
215
|
+
if (this._state.emitError) for (let e of /* @__PURE__ */ new Set([t?.name, n?.name])) {
|
|
216
|
+
if (!e || this.pendingNativeReports.has(e)) continue;
|
|
217
|
+
let t = {};
|
|
218
|
+
this.pendingNativeReports.set(e, t), queueMicrotask(() => {
|
|
219
|
+
if (this.pendingNativeReports.get(e) !== t || (this.pendingNativeReports.delete(e), !this.isConnected || !this._state.emitError)) return;
|
|
220
|
+
let n = this.businessErrors.get(e)?.message ?? this.nativeMessageForName(e);
|
|
221
|
+
this.setValidateErrors({ [e]: n }, [e]);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
else for (let r of this.fieldContext.getFields()) (r.target === e || r.target === t?.item || r.target === n?.item) && this.notifyFieldError(r);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
nativeMessageForName(e) {
|
|
228
|
+
for (let [t, n] of this.nativeFeedback) {
|
|
229
|
+
if (n.name !== e) continue;
|
|
230
|
+
let r = this.activeNativeMessage(t, n);
|
|
231
|
+
if (r) return r;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
activeNativeMessage(e, t) {
|
|
235
|
+
if (t.message && this.validationField(e) && e.willValidate) return e instanceof a ? t.message : e.validationMessage || void 0;
|
|
236
|
+
}
|
|
237
|
+
setEmitError(e) {
|
|
238
|
+
if (this._state.emitError === e) return;
|
|
239
|
+
this._state.emitError = e, this.pendingNativeReports.clear();
|
|
240
|
+
let t = /* @__PURE__ */ new Set();
|
|
241
|
+
for (let [n, r] of this.nativeFeedback) r.message && this.validationField(n) && (t.add(n), r.item && t.add(r.item), e && this.activeNativeMessage(n, r) && this.notifyNativeFeedback(n, void 0, r));
|
|
242
|
+
for (let e of this.fieldContext.getFields()) t.has(e.target) && !this.locallyClearedFields.has(e) && this.notifyFieldError(e);
|
|
243
|
+
}
|
|
244
|
+
reconcileNativeFeedback = () => {
|
|
245
|
+
for (let [e, t] of this.nativeFeedback) this.validationField(e) ? e.closest("l-form-item") !== (t.item ?? null) && this.updateNativeFeedback(e) : (this.nativeFeedback.delete(e), this.notifyNativeFeedback(e, t));
|
|
246
|
+
};
|
|
247
|
+
listenNativeForm() {
|
|
248
|
+
let e = this.nativeForm;
|
|
249
|
+
e !== this.listeningForm && (this.stopNativeSubmit?.(), this.listeningForm?.removeEventListener("reset", this.nativeReset, !0), this.resetScope = {}, this.listeningForm = e, this.stopNativeSubmit = e && c(e, this, this.nativeOwner.ownsForm, () => this.submit()), e?.addEventListener("reset", this.nativeReset, !0));
|
|
250
|
+
}
|
|
15
251
|
constructor() {
|
|
16
252
|
super(), this.version = 2, this._state = {
|
|
17
253
|
inline: !1,
|
|
254
|
+
innerBlock: !1,
|
|
255
|
+
disabled: !1,
|
|
18
256
|
labelPosition: "right",
|
|
19
257
|
labelWidth: "80px",
|
|
20
258
|
novalidate: !1,
|
|
21
259
|
emitError: !1
|
|
22
|
-
}
|
|
260
|
+
};
|
|
261
|
+
let e = new O([]);
|
|
262
|
+
e.onSchemaRemoved = (t) => {
|
|
263
|
+
this.validator === e && this.revalidateChangedRules([t]);
|
|
264
|
+
}, this.validator = e;
|
|
23
265
|
}
|
|
24
266
|
static get observedAttributes() {
|
|
25
267
|
return [
|
|
@@ -29,31 +271,42 @@ var d = class extends e {
|
|
|
29
271
|
"novalidate",
|
|
30
272
|
"label-width",
|
|
31
273
|
"label-height",
|
|
32
|
-
"emit-error"
|
|
274
|
+
"emit-error",
|
|
275
|
+
"disabled",
|
|
276
|
+
"autocomplete"
|
|
33
277
|
];
|
|
34
278
|
}
|
|
35
|
-
attributeChanged(
|
|
36
|
-
switch (
|
|
279
|
+
attributeChanged(r, i, a) {
|
|
280
|
+
switch (r) {
|
|
37
281
|
case "label-position":
|
|
38
282
|
this._state.labelPosition = a;
|
|
39
283
|
break;
|
|
40
284
|
case "inner-block":
|
|
41
|
-
|
|
42
|
-
this.
|
|
285
|
+
case "disabled":
|
|
286
|
+
this._state[e(r)] = t(a, !1, r), this.autocompleteConfiguration.refresh();
|
|
287
|
+
break;
|
|
288
|
+
case "autocomplete":
|
|
289
|
+
this.autocompleteConfiguration.refresh();
|
|
43
290
|
break;
|
|
44
291
|
case "label-width":
|
|
45
292
|
case "label-height":
|
|
46
|
-
this._state[
|
|
293
|
+
this._state[e(r)] = n(a);
|
|
294
|
+
break;
|
|
295
|
+
case "novalidate":
|
|
296
|
+
this._state.novalidate = t(a, !1, r), this._state.novalidate && this.updateBusinessErrors({}, this.businessErrors.keys());
|
|
297
|
+
break;
|
|
298
|
+
case "emit-error":
|
|
299
|
+
this.setEmitError(t(a, !1, r));
|
|
47
300
|
break;
|
|
48
301
|
default:
|
|
49
|
-
let
|
|
50
|
-
this._state[
|
|
302
|
+
let i = t(a, !1, r);
|
|
303
|
+
this._state[e(r)] = i;
|
|
51
304
|
}
|
|
52
305
|
}
|
|
53
306
|
updateDOM(e) {
|
|
54
307
|
if (e.has("label-position") || e.has("inline")) {
|
|
55
|
-
let e =
|
|
56
|
-
e && (e.className =
|
|
308
|
+
let e = m(".l-form", this.root);
|
|
309
|
+
e && (e.className = h([
|
|
57
310
|
"l-form",
|
|
58
311
|
this._state.inline ? "l-form-inline" : void 0,
|
|
59
312
|
`l-form--${this._state.labelPosition}`
|
|
@@ -62,130 +315,277 @@ var d = class extends e {
|
|
|
62
315
|
e.has("label-width") && (this._state.labelWidth ? this.style.setProperty("--l-form-label-width", this._state.labelWidth) : this.style.removeProperty("--l-form-label-width")), e.has("label-height") && (this._state.labelHeight ? this.style.setProperty("--l-form-label-height", this._state.labelHeight) : this.style.removeProperty("--l-form-label-height"));
|
|
63
316
|
}
|
|
64
317
|
connectedCallback() {
|
|
65
|
-
|
|
318
|
+
if (Object.prototype.hasOwnProperty.call(this, "autocomplete")) {
|
|
319
|
+
let e = this.autocomplete;
|
|
320
|
+
delete this.autocomplete, this.autocomplete = e;
|
|
321
|
+
}
|
|
322
|
+
this.disposeContext = p(this, "form", this.provider), super.connectedCallback(), this.nativeOwner.start(), this.listenNativeForm(), this.autocompleteConfiguration.start();
|
|
323
|
+
for (let e of this.querySelectorAll("*")) (e instanceof a || e instanceof o) && e.closest("l-form") === this && e.refreshFormContext();
|
|
66
324
|
}
|
|
67
325
|
afterInit() {
|
|
68
|
-
|
|
326
|
+
_(this, "form-rule-change", this.ruleChange), _(this, "input", this.nativeInput), this.addEventListener("focusout", this.nativeInvalid), this.addEventListener("change", this.nativeValidityChanged), this.validationRoot = this.getRootNode(), this.validationRoot.addEventListener("invalid", this.nativeInvalid, !0), this.validationRoot.addEventListener(d.nativeValidity, this.nativeValidityChanged, !0);
|
|
69
327
|
}
|
|
70
328
|
disconnectedCallback() {
|
|
71
|
-
this.
|
|
329
|
+
this.autocompleteConfiguration.stop();
|
|
330
|
+
for (let e of this.itemRules.keys()) this.replaceItemRules(e);
|
|
331
|
+
this.businessErrors.clear(), this.nativeFeedback.clear(), this.pendingNativeReports.clear(), this.disposeContext?.(), this.disposeContext = void 0, this.fieldContext.dispose(), this.locallyClearedFields.clear(), this.stopNativeSubmit?.(), this.stopNativeSubmit = void 0, this.listeningForm?.removeEventListener("reset", this.nativeReset, !0), this.resetScope = {}, this.listeningForm = void 0, this.nativeOwner.stop(), g(this, "form-rule-change", this.ruleChange), g(this, "input", this.nativeInput), this.removeEventListener("focusout", this.nativeInvalid), this.removeEventListener("change", this.nativeValidityChanged), this.validationRoot?.removeEventListener("invalid", this.nativeInvalid, !0), this.validationRoot?.removeEventListener(d.nativeValidity, this.nativeValidityChanged, !0), this.validationRoot = void 0, super.disconnectedCallback();
|
|
72
332
|
}
|
|
73
333
|
render_v2() {
|
|
74
334
|
return {
|
|
75
|
-
|
|
335
|
+
styleSheets: [r],
|
|
76
336
|
template: this.render()
|
|
77
337
|
};
|
|
78
338
|
}
|
|
79
339
|
render() {
|
|
80
|
-
let e =
|
|
340
|
+
let e = h([
|
|
81
341
|
"l-form",
|
|
82
342
|
this._state.inline ? "l-form-inline" : void 0,
|
|
83
343
|
`l-form--${this._state.labelPosition}`
|
|
84
344
|
]);
|
|
85
|
-
return this._state.labelWidth && this.style.setProperty("--l-form-label-width", this._state.labelWidth), `<
|
|
345
|
+
return this._state.labelWidth && this.style.setProperty("--l-form-label-width", this._state.labelWidth), `<div class="${e}"><slot></slot></div>`;
|
|
86
346
|
}
|
|
87
347
|
ruleChange = (e) => {
|
|
88
|
-
e.
|
|
348
|
+
let t = e.composedPath()[0];
|
|
349
|
+
t instanceof o && t.closest("l-form") === this && (e.stopPropagation(), this.replaceItemRules(t, e.detail ?? void 0));
|
|
89
350
|
};
|
|
351
|
+
replaceItemRules(e, t) {
|
|
352
|
+
let n = t ? C(new v([t]), t.key) : [], r = this.validator, i = this.itemRules.get(e), a = i?.validator === r ? i : void 0, o = /* @__PURE__ */ new Set();
|
|
353
|
+
a && o.add(a.key), t && o.add(t.key);
|
|
354
|
+
let s = [];
|
|
355
|
+
for (let e of o) {
|
|
356
|
+
let i = C(r, e), o = a?.key === e ? a.rules : [], c = t?.key === e ? n : [], l = i.findIndex((e) => o.includes(e));
|
|
357
|
+
if (l === -1 && c.length === 0) continue;
|
|
358
|
+
let u = i.filter((e) => !o.includes(e));
|
|
359
|
+
u.splice(l === -1 ? u.length : l, 0, ...c), this.replaceRules(e, u), s.push(e);
|
|
360
|
+
}
|
|
361
|
+
this.itemRules.delete(e), t && n.length && this.itemRules.set(e, {
|
|
362
|
+
validator: r,
|
|
363
|
+
key: t.key,
|
|
364
|
+
rules: n
|
|
365
|
+
}), this.revalidateChangedRules(s);
|
|
366
|
+
}
|
|
367
|
+
replaceRules(e, t) {
|
|
368
|
+
this.validator instanceof O ? this.validator.replaceRules(e, t) : t.length ? this.validator.rules[e] = t : this.validator.removeSchema(e);
|
|
369
|
+
}
|
|
370
|
+
revalidateChangedRules(e) {
|
|
371
|
+
if (!this.isConnected) return;
|
|
372
|
+
let t = [...new Set(e)].filter((e) => this.businessErrors.has(e) || this.displayedBusinessErrors.has(e));
|
|
373
|
+
t.length && this.applyFieldErrors(this.validateKeys(t, this.validationData(t)), t);
|
|
374
|
+
}
|
|
90
375
|
addSchemas(e) {
|
|
91
|
-
this.validator.addSchemas(e);
|
|
376
|
+
this.validator.addSchemas(e), this.revalidateChangedRules(e.map(({ key: e }) => e));
|
|
92
377
|
}
|
|
93
378
|
setSchemas(e) {
|
|
94
|
-
this.validator.
|
|
379
|
+
let t = Object.keys(this.validator.rules);
|
|
380
|
+
this.validator.setSchemas(e), this.revalidateChangedRules([...t, ...e.map(({ key: e }) => e)]);
|
|
95
381
|
}
|
|
96
382
|
setSchema(e) {
|
|
97
|
-
this.validator.setSchema(e);
|
|
383
|
+
this.validator.setSchema(e), this.revalidateChangedRules([e.key]);
|
|
98
384
|
}
|
|
99
385
|
addSchema(e) {
|
|
100
|
-
this.validator.addSchema(e);
|
|
101
|
-
}
|
|
102
|
-
_provide(e) {
|
|
103
|
-
let { context: t, callback: n } = e.detail;
|
|
104
|
-
t === "form-context-request" && n(this.context, this.errors, this.resetCtx);
|
|
386
|
+
this.validator.addSchema(e), this.revalidateChangedRules([e.key]);
|
|
105
387
|
}
|
|
106
|
-
_formAction = (e) => {
|
|
107
|
-
e.detail === "submit" ? this.submit() : this.reset();
|
|
108
|
-
};
|
|
109
|
-
_valueChange = (e) => {
|
|
110
|
-
let { name: t, value: n, valid: r } = e.detail;
|
|
111
|
-
if (!t) return;
|
|
112
|
-
this._data ??= {};
|
|
113
|
-
let i = Object.hasOwn(this._data, t);
|
|
114
|
-
if (this._data[t] = n, !this._state.novalidate && i && r) try {
|
|
115
|
-
let e = this.errors();
|
|
116
|
-
e[t] = void 0, this.setValidateErrors({ ...e });
|
|
117
|
-
} catch (e) {
|
|
118
|
-
this.setValidateErrors({
|
|
119
|
-
...this.errors(),
|
|
120
|
-
...e.detail
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
388
|
setValidateErrors(e, t = !0) {
|
|
125
389
|
this._state.emitError ? this.emit("validate-error", { detail: {
|
|
126
390
|
errors: e,
|
|
127
391
|
all: t
|
|
128
|
-
} }) : this.
|
|
392
|
+
} }) : this.setErrors(e);
|
|
129
393
|
}
|
|
130
|
-
|
|
131
|
-
let t =
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
394
|
+
relatedRuleNames(e) {
|
|
395
|
+
let t = this.validator;
|
|
396
|
+
return t instanceof O ? t.getInputValidationFields(e) : Object.entries(t.rules).flatMap(([t, n]) => t === e || n.some((t) => t.sameKey === e) ? [t] : []);
|
|
397
|
+
}
|
|
398
|
+
invalidateBusinessRules(e) {
|
|
399
|
+
e && this.businessErrors.size !== 0 && this.updateBusinessErrors({}, /* @__PURE__ */ new Set([e, ...this.relatedRuleNames(e)]));
|
|
400
|
+
}
|
|
401
|
+
validateInput(e) {
|
|
402
|
+
let t = e.name;
|
|
403
|
+
if (this._state.novalidate || !t) return;
|
|
404
|
+
let n = this.relatedRuleNames(t);
|
|
405
|
+
if (n.length === 0) return;
|
|
406
|
+
let r = this.nativeForm;
|
|
407
|
+
if (!r || e.form !== r || !this.isDataField(e)) return;
|
|
408
|
+
let i = this.validationData(n, r, t);
|
|
409
|
+
Object.hasOwn(i, t) && this.applyFieldErrors(this.validateKeys(n, i), n);
|
|
410
|
+
}
|
|
411
|
+
validateKeys(e, t) {
|
|
412
|
+
let n = this.validator, r = this.nativeForm, i = r && D(r);
|
|
413
|
+
return Object.fromEntries(e.map((e) => {
|
|
414
|
+
try {
|
|
415
|
+
if (n instanceof O && !Object.hasOwn(n.rules, e)) return [e, void 0];
|
|
416
|
+
let r = C(n, e), o = i && r.some(T) ? this.findDataField(i, e) : void 0, s = o instanceof a && !o.isDisabled() ? o.requiredSelection : void 0;
|
|
417
|
+
return E(n, e, t, r, s), [e, void 0];
|
|
418
|
+
} catch (t) {
|
|
419
|
+
return [e, t?.detail?.[e] ?? (t instanceof Error && t.message ? t.message : "校验失败")];
|
|
150
420
|
}
|
|
151
|
-
|
|
421
|
+
}));
|
|
422
|
+
}
|
|
423
|
+
applyFieldErrors(e, t, n = this._state.emitError) {
|
|
424
|
+
if (this.updateBusinessErrors(e, t), n) {
|
|
425
|
+
let n = Object.fromEntries(t.map((t) => (this.pendingNativeReports.delete(t), [t, e[t] ?? this.nativeMessageForName(t)])));
|
|
426
|
+
this.setValidateErrors(n, t);
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
let r = /* @__PURE__ */ new Set();
|
|
430
|
+
for (let n of t) {
|
|
431
|
+
let t = e[n];
|
|
432
|
+
(this.errorMessages[n] || void 0) !== (t || void 0) && r.add(n), t === void 0 ? (delete this.errorMessages[n], this.displayRevisions.delete(n), this.displayedBusinessErrors.delete(n)) : (this.errorMessages[n] = t, this.displayRevisions.set(n, ++this.errorRevision), this.displayedBusinessErrors.add(n));
|
|
433
|
+
}
|
|
434
|
+
for (let e of t) r.has(e) ? this.notifyErrorChange(e) : this.locallyClearedFields.size && this.notifyErrorChange(e, !0);
|
|
435
|
+
}
|
|
436
|
+
updateBusinessErrors(e, t) {
|
|
437
|
+
for (let n of t) {
|
|
438
|
+
let t = e[n];
|
|
439
|
+
if (t) this.businessErrors.set(n, {
|
|
440
|
+
message: t,
|
|
441
|
+
revision: ++this.errorRevision
|
|
442
|
+
});
|
|
443
|
+
else if (!this.businessErrors.delete(n)) continue;
|
|
444
|
+
for (let { target: e } of this.fieldContext.getFieldsByName(n)) e instanceof a && this.applyFieldValidity(e, n);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
applyFieldValidity(e, t) {
|
|
448
|
+
e.applyBusinessValidity(t && e.form === this.nativeOwner.form && this.isDataField(e) ? this.businessErrors.get(t)?.message : void 0);
|
|
449
|
+
}
|
|
450
|
+
isDataField(e) {
|
|
451
|
+
return !e || !this.nativeOwner.ownsForm && e.closest("l-form") !== this ? !1 : e instanceof a ? !e.grouped : e instanceof HTMLInputElement ? e.type === "radio" ? e.checked : ![
|
|
452
|
+
"button",
|
|
453
|
+
"submit",
|
|
454
|
+
"reset",
|
|
455
|
+
"image"
|
|
456
|
+
].includes(e.type) : e instanceof HTMLSelectElement || e instanceof HTMLTextAreaElement;
|
|
457
|
+
}
|
|
458
|
+
findDataField(e, t) {
|
|
459
|
+
let n = e.namedItem(t);
|
|
460
|
+
if (n instanceof Element) return this.isDataField(n) && n.name === t ? n : void 0;
|
|
461
|
+
if (n) for (let e = n.length - 1; e >= 0; e--) {
|
|
462
|
+
let r = n.item(e);
|
|
463
|
+
if (this.isDataField(r) && r.name === t) return r;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
validationData(e, t = this.nativeForm, n) {
|
|
467
|
+
if (!t) return {};
|
|
468
|
+
let r = D(t), i = this.validator;
|
|
469
|
+
if (!(i instanceof O)) return this.collectData(r);
|
|
470
|
+
let a = new Set(e);
|
|
471
|
+
n && a.add(n);
|
|
472
|
+
for (let t of e) for (let { sameKey: e } of C(i, t)) e !== void 0 && a.add(e);
|
|
473
|
+
let o = [];
|
|
474
|
+
for (let e of a) {
|
|
475
|
+
let t = this.findDataField(r, e);
|
|
476
|
+
t && o.push([e, S(t)]);
|
|
152
477
|
}
|
|
478
|
+
return Object.fromEntries(o);
|
|
479
|
+
}
|
|
480
|
+
async validateField(e) {
|
|
481
|
+
let t = [...new Set(Array.isArray(e) ? e : [e])];
|
|
482
|
+
if (t.length === 0) return;
|
|
483
|
+
let n = this.validateKeys(t, this.validationData(t));
|
|
484
|
+
if (this.applyFieldErrors(n, t, !1), Object.values(n).some(Boolean)) {
|
|
485
|
+
let e = /* @__PURE__ */ Error("validate field error");
|
|
486
|
+
throw e.detail = n, e;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
get validationErrors() {
|
|
490
|
+
return this._state.emitError ? { ...this.errorMessages } : this.withNativeFeedback(this.errorMessages);
|
|
491
|
+
}
|
|
492
|
+
withNativeFeedback(e) {
|
|
493
|
+
let t = Object.assign(Object.create(null), e);
|
|
494
|
+
for (let [e, n] of this.nativeFeedback) {
|
|
495
|
+
let { name: r } = n;
|
|
496
|
+
if (!r || t[r]) continue;
|
|
497
|
+
let i = this.activeNativeMessage(e, n);
|
|
498
|
+
i && (t[r] = i);
|
|
499
|
+
}
|
|
500
|
+
return { ...t };
|
|
153
501
|
}
|
|
154
502
|
clearValidate() {
|
|
155
|
-
this.
|
|
503
|
+
this.clearPresentation();
|
|
156
504
|
}
|
|
157
505
|
reset() {
|
|
158
|
-
this.
|
|
159
|
-
|
|
160
|
-
|
|
506
|
+
this.listenNativeForm(), this.listeningForm && HTMLFormElement.prototype.reset.call(this.listeningForm);
|
|
507
|
+
}
|
|
508
|
+
clearPresentation(e = Infinity) {
|
|
509
|
+
let t = /* @__PURE__ */ new Set();
|
|
510
|
+
for (let [n, r] of this.displayRevisions) r > e || (this.errorMessages[n] && t.add(n), delete this.errorMessages[n], this.displayRevisions.delete(n), this.displayedBusinessErrors.delete(n));
|
|
511
|
+
let n = /* @__PURE__ */ new Set();
|
|
512
|
+
for (let [t, r] of this.nativeFeedback) r.revision > e || (this.nativeFeedback.delete(t), r.name && this.pendingNativeReports.delete(r.name), r.message && (n.add(t), r.item && n.add(r.item)));
|
|
513
|
+
for (let e of this.fieldContext.getFields()) {
|
|
514
|
+
let r = this.fieldName(e);
|
|
515
|
+
(n.has(e.target) || r && t.has(r)) && this.notifyFieldError(e, r);
|
|
516
|
+
}
|
|
161
517
|
}
|
|
162
518
|
submit() {
|
|
163
519
|
this._state.novalidate ? this.emit("submit", { detail: this.getData() }) : this.validate().then((e) => {
|
|
164
|
-
e.result ? this.emit("submit", { detail: this.getData() }) : this._state.emitError ? this.
|
|
165
|
-
errors: e.errors,
|
|
166
|
-
all: !0
|
|
167
|
-
} }) : this.errors(e.errors);
|
|
520
|
+
e.result ? (this.clearValidate(), this.emit("submit", { detail: this.getData() })) : this._state.emitError ? this.setValidateErrors(this.withNativeFeedback(e.errors)) : this.replaceDisplayedErrors(e.errors, !0);
|
|
168
521
|
});
|
|
169
522
|
}
|
|
170
523
|
validate() {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
result: !1,
|
|
179
|
-
errors: e.detail
|
|
180
|
-
});
|
|
181
|
-
}
|
|
524
|
+
let e = Object.keys(this.validator.rules), t = this.validateKeys(e, this.getData());
|
|
525
|
+
this.updateBusinessErrors(t, /* @__PURE__ */ new Set([...this.businessErrors.keys(), ...e]));
|
|
526
|
+
let n = Object.fromEntries(Object.entries(t).filter(([, e]) => !!e));
|
|
527
|
+
return Promise.resolve({
|
|
528
|
+
result: Object.keys(n).length === 0,
|
|
529
|
+
errors: n
|
|
530
|
+
});
|
|
182
531
|
}
|
|
183
532
|
getData() {
|
|
184
|
-
|
|
533
|
+
let e = this.nativeForm;
|
|
534
|
+
return e ? this.collectData(D(e)) : {};
|
|
535
|
+
}
|
|
536
|
+
collectData(e) {
|
|
537
|
+
let t = [];
|
|
538
|
+
for (let n of Array.from(e)) this.isDataField(n) && n.name && t.push([n.name, S(n)]);
|
|
539
|
+
return Object.fromEntries(t);
|
|
540
|
+
}
|
|
541
|
+
fieldName(e) {
|
|
542
|
+
return e.target instanceof a ? e.target.name : e.getSnapshot().name;
|
|
543
|
+
}
|
|
544
|
+
initializeFieldValidity(e, t = this.fieldName(e)) {
|
|
545
|
+
if (e.target instanceof a) {
|
|
546
|
+
if (!e.target.rendered) return;
|
|
547
|
+
this.applyFieldValidity(e.target, t);
|
|
548
|
+
}
|
|
549
|
+
this.notifyFieldError(e, t);
|
|
550
|
+
}
|
|
551
|
+
visibleError(e, t) {
|
|
552
|
+
if (t && this.errorMessages[t]) return this.errorMessages[t];
|
|
553
|
+
if (!this._state.emitError) {
|
|
554
|
+
if (e instanceof a) {
|
|
555
|
+
let t = this.nativeFeedback.get(e);
|
|
556
|
+
if (t) return this.activeNativeMessage(e, t);
|
|
557
|
+
}
|
|
558
|
+
if (e instanceof o) for (let [t, n] of this.nativeFeedback) {
|
|
559
|
+
if (n.item !== e) continue;
|
|
560
|
+
let r = this.activeNativeMessage(t, n);
|
|
561
|
+
if (r) return r;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
notifyFieldError(e, t = this.fieldName(e)) {
|
|
566
|
+
if (e.target instanceof a && !e.target.rendered) return;
|
|
567
|
+
this.locallyClearedFields.delete(e);
|
|
568
|
+
let n = this.visibleError(e.target, t);
|
|
569
|
+
this.fieldContext.notifyValidity(e, {
|
|
570
|
+
valid: !n,
|
|
571
|
+
message: n
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
notifyErrorChange(e, t = !1) {
|
|
575
|
+
for (let n of this.fieldContext.getFieldsByName(e)) (!t || this.locallyClearedFields.has(n)) && this.fieldName(n) === e && this.notifyFieldError(n, e);
|
|
185
576
|
}
|
|
186
577
|
setErrors(e) {
|
|
187
|
-
this.
|
|
578
|
+
this.replaceDisplayedErrors(e);
|
|
579
|
+
}
|
|
580
|
+
replaceDisplayedErrors(e, t = !1) {
|
|
581
|
+
let n = this.errorMessages, r = Object.assign(Object.create(null), e);
|
|
582
|
+
this.displayRevisions.clear();
|
|
583
|
+
for (let e of Object.keys(r)) this.displayRevisions.set(e, ++this.errorRevision);
|
|
584
|
+
if (this.displayedBusinessErrors.clear(), t) for (let e of Object.keys(r)) this.displayedBusinessErrors.add(e);
|
|
585
|
+
this.errorMessages = r;
|
|
586
|
+
for (let e of /* @__PURE__ */ new Set([...Object.keys(n), ...Object.keys(r)])) (n[e] || void 0) !== (r[e] || void 0) && this.notifyErrorChange(e);
|
|
587
|
+
let i = [...this.locallyClearedFields];
|
|
588
|
+
for (let e of i) this.locallyClearedFields.has(e) && this.notifyFieldError(e);
|
|
188
589
|
}
|
|
189
590
|
};
|
|
190
|
-
|
|
191
|
-
export { d as default };
|
|
591
|
+
export { k as default };
|