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/form_item.js
CHANGED
|
@@ -1,24 +1,48 @@
|
|
|
1
|
-
import { kebabToCamel as e,
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { kebabToCamel as e, unitNumberStr as t } from "../utils/index.js";
|
|
2
|
+
import n from "./form_item_style.js";
|
|
3
|
+
import r from "../base.js";
|
|
4
|
+
import i from "./form_inner.js";
|
|
5
|
+
import { FieldAccessibility as a, referenceElements as o } from "./accessibility.js";
|
|
6
|
+
import { FORM_CONTEXT_EVENTS as s, createFormContextProvider as c, provideFormContext as l, readFormBooleanAttribute as u, requestFormContext as d } from "./context.js";
|
|
7
|
+
import { $$ as f, $one as p, addClass as m, removeClass as h } from "utilane/browser";
|
|
8
|
+
// src/components/form/form_item.ts
|
|
9
|
+
var g = /* @__PURE__ */ new WeakMap(), _ = class _ extends r {
|
|
8
10
|
static baseName = "form-item";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
itemContext = c();
|
|
12
|
+
disposeContext;
|
|
13
|
+
formContext;
|
|
14
|
+
unregisterForm;
|
|
15
|
+
programRules;
|
|
16
|
+
validationError;
|
|
17
|
+
accessibilityObserver;
|
|
18
|
+
accessibilityScheduled = !1;
|
|
19
|
+
connectedFields = /* @__PURE__ */ new Set();
|
|
20
|
+
nativePresentation = /* @__PURE__ */ new Map();
|
|
21
|
+
itemProvider = {
|
|
22
|
+
getSnapshot: () => this.itemContext.getSnapshot(),
|
|
23
|
+
registerField: (e) => {
|
|
24
|
+
let t = this.itemContext.registerField(e);
|
|
25
|
+
return this.scheduleAccessibility(), () => {
|
|
26
|
+
t() && this.scheduleAccessibility();
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
formField = {
|
|
31
|
+
target: this,
|
|
32
|
+
getSnapshot: () => ({
|
|
33
|
+
name: this._state.prop,
|
|
34
|
+
value: void 0
|
|
35
|
+
})
|
|
36
|
+
};
|
|
11
37
|
constructor() {
|
|
12
|
-
super(), this.version = 2, this.
|
|
13
|
-
labelPosition: "right",
|
|
14
|
-
required: !1
|
|
15
|
-
}, this.context = d({ innerBlock: !1 });
|
|
38
|
+
super(), this.version = 2, this._state = { labelPosition: "right" };
|
|
16
39
|
}
|
|
17
40
|
static get observedAttributes() {
|
|
18
41
|
return [
|
|
19
42
|
"error",
|
|
20
43
|
"label",
|
|
21
44
|
"required",
|
|
45
|
+
"disabled",
|
|
22
46
|
"inner-block",
|
|
23
47
|
"prop",
|
|
24
48
|
"label-position",
|
|
@@ -29,113 +53,222 @@ var f = class extends a {
|
|
|
29
53
|
"label-height"
|
|
30
54
|
];
|
|
31
55
|
}
|
|
32
|
-
attributeChanged(n,
|
|
56
|
+
attributeChanged(n, r, i) {
|
|
33
57
|
switch (n) {
|
|
34
58
|
case "error":
|
|
35
59
|
case "label":
|
|
36
60
|
case "verify":
|
|
37
61
|
case "pattern":
|
|
38
62
|
case "validity":
|
|
39
|
-
this._state[n] =
|
|
63
|
+
this._state[n] = i ?? void 0;
|
|
40
64
|
break;
|
|
41
65
|
case "label-position":
|
|
42
|
-
this._state.labelPosition =
|
|
66
|
+
this._state.labelPosition = i === "left" || i === "top" ? i : "right";
|
|
43
67
|
break;
|
|
44
68
|
case "inner-block":
|
|
45
|
-
|
|
46
|
-
this.context({ innerBlock: i });
|
|
69
|
+
this._state.innerBlock = u(i);
|
|
47
70
|
break;
|
|
48
71
|
case "required":
|
|
49
|
-
|
|
50
|
-
this._state
|
|
72
|
+
case "disabled":
|
|
73
|
+
this._state[n] = u(i);
|
|
51
74
|
break;
|
|
52
75
|
case "prop":
|
|
53
|
-
this._state.prop =
|
|
54
|
-
...this.context(),
|
|
55
|
-
prop: a
|
|
56
|
-
});
|
|
76
|
+
this._state.prop = i ?? void 0, this.validationError = void 0, this.rendered && (this.formContext?.fieldNameChanged?.(this.formField, this._state.prop), this._updateError());
|
|
57
77
|
break;
|
|
58
78
|
case "label-width":
|
|
59
|
-
case "label-height": this._state[e(n)] =
|
|
79
|
+
case "label-height": this._state[e(n)] = i ? t(i) : void 0;
|
|
60
80
|
}
|
|
81
|
+
[
|
|
82
|
+
"prop",
|
|
83
|
+
"inner-block",
|
|
84
|
+
"required",
|
|
85
|
+
"disabled"
|
|
86
|
+
].includes(n) && this.updateContext();
|
|
87
|
+
let a = [
|
|
88
|
+
"required",
|
|
89
|
+
"verify",
|
|
90
|
+
"pattern",
|
|
91
|
+
"validity"
|
|
92
|
+
].includes(n);
|
|
93
|
+
a && (this.programRules = void 0), this.rendered && (n === "prop" || a) && this._parseSchema();
|
|
61
94
|
}
|
|
95
|
+
updateContext() {
|
|
96
|
+
let { prop: e, innerBlock: t, required: n, disabled: r } = this._state;
|
|
97
|
+
this.itemContext.updateConfiguration({
|
|
98
|
+
prop: e,
|
|
99
|
+
innerBlock: t,
|
|
100
|
+
required: n,
|
|
101
|
+
disabled: r
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
refreshFormContext = () => {
|
|
105
|
+
if (!this.rendered) return;
|
|
106
|
+
let e = d(this, "form");
|
|
107
|
+
this.formContext !== e && (this.unregisterForm?.(), this.formContext = e, this.unregisterForm = e?.registerField(this.formField), e && this._parseSchema());
|
|
108
|
+
};
|
|
109
|
+
receiveValidity = (e) => {
|
|
110
|
+
if (e.target !== this) return;
|
|
111
|
+
let { valid: t, message: n } = e.detail;
|
|
112
|
+
this.validationError = t ? void 0 : n, this._updateError();
|
|
113
|
+
};
|
|
62
114
|
updateDOM(e) {
|
|
63
|
-
e.has("required") && this._updateRequired(), e.has("label") && this._updateLabel(), e.has("error") && this._updateError(), e.has("label-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
this.
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
115
|
+
e.has("required") && this._updateRequired(), e.has("label") && this._updateLabel(), e.has("error") && this._updateError(), e.has("label-position") && this.updateLabelPosition();
|
|
116
|
+
for (let t of ["label-width", "label-height"]) {
|
|
117
|
+
if (!e.has(t)) continue;
|
|
118
|
+
let n = this._state[t === "label-width" ? "labelWidth" : "labelHeight"];
|
|
119
|
+
n ? this.style.setProperty(`--l-form-${t}`, n) : this.style.removeProperty(`--l-form-${t}`);
|
|
120
|
+
}
|
|
121
|
+
(e.has("label") || e.has("required")) && this.updateAccessibility();
|
|
122
|
+
}
|
|
123
|
+
afterInit() {
|
|
124
|
+
this.updateContext(), this.disposeContext = l(this, "item", this.itemProvider);
|
|
125
|
+
for (let e of this.querySelectorAll("*")) e.refreshFormContext?.();
|
|
126
|
+
this.addEventListener(s.validity, this.receiveValidity), this.addEventListener(s.configuration, this.refreshFormContext), this.refreshFormContext(), this._updateRequired(), this._updateError(), this.root.addEventListener("click", this.focusFieldFromLabel), this.root.querySelector("slot")?.addEventListener("slotchange", this.updateAccessibility), this.addEventListener("focusin", this.updateAccessibility), this.accessibilityObserver = new MutationObserver(this.updateAccessibility), this.accessibilityObserver.observe(this, {
|
|
127
|
+
childList: !0,
|
|
128
|
+
subtree: !0,
|
|
129
|
+
attributes: !0,
|
|
130
|
+
attributeFilter: [
|
|
131
|
+
"type",
|
|
132
|
+
"name",
|
|
133
|
+
"slot",
|
|
134
|
+
"for",
|
|
135
|
+
"id",
|
|
136
|
+
"hidden",
|
|
137
|
+
"required",
|
|
138
|
+
"aria-label",
|
|
139
|
+
"aria-labelledby",
|
|
140
|
+
"aria-describedby",
|
|
141
|
+
"aria-invalid",
|
|
142
|
+
"aria-required"
|
|
143
|
+
]
|
|
71
144
|
});
|
|
72
145
|
}
|
|
73
146
|
beforeDestroy() {
|
|
74
|
-
this.
|
|
147
|
+
this.root.removeEventListener("click", this.focusFieldFromLabel), this.root.querySelector("slot")?.removeEventListener("slotchange", this.updateAccessibility), this.removeEventListener("focusin", this.updateAccessibility), this.accessibilityObserver?.disconnect();
|
|
148
|
+
for (let e of this.connectedFields) this.clearFieldPresentation(e);
|
|
149
|
+
this.connectedFields.clear(), this.removeEventListener(s.validity, this.receiveValidity), this.removeEventListener(s.configuration, this.refreshFormContext), this.unregisterForm?.(), this.unregisterForm = void 0, this.formContext = void 0, this.disposeContext?.(), this.disposeContext = void 0, this.itemContext.dispose(), this.validationError = void 0;
|
|
75
150
|
}
|
|
76
151
|
setRules(e) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
key: t
|
|
82
|
-
};
|
|
83
|
-
this._updateRules(n);
|
|
84
|
-
}
|
|
152
|
+
this.programRules = {
|
|
153
|
+
...e,
|
|
154
|
+
rules: Array.isArray(e.rules) ? [...e.rules] : e.rules
|
|
155
|
+
}, this.rendered && this._parseSchema();
|
|
85
156
|
}
|
|
86
157
|
render_v2() {
|
|
87
158
|
return {
|
|
88
159
|
template: this.render(),
|
|
89
|
-
|
|
160
|
+
styleSheets: [n]
|
|
90
161
|
};
|
|
91
162
|
}
|
|
163
|
+
get errorMessage() {
|
|
164
|
+
return this._state.error ?? this.validationError;
|
|
165
|
+
}
|
|
166
|
+
updateLabelPosition() {
|
|
167
|
+
for (let e of [
|
|
168
|
+
"left",
|
|
169
|
+
"right",
|
|
170
|
+
"top"
|
|
171
|
+
]) this.classList.toggle(`l-form-item--${e}`, e === this._state.labelPosition);
|
|
172
|
+
}
|
|
92
173
|
render() {
|
|
93
|
-
this.
|
|
174
|
+
this.updateLabelPosition();
|
|
94
175
|
let e = document.createDocumentFragment();
|
|
95
|
-
this._state.label != null && e.appendChild(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
let t = o("div", { class: "l-form-item__content" }), n = o("slot");
|
|
100
|
-
return t.appendChild(n), this._state.error && t.appendChild(o("div", {
|
|
176
|
+
this._state.label != null && e.appendChild(this.createLabel(this._state.label));
|
|
177
|
+
let t = f("div", { class: "l-form-item__content" });
|
|
178
|
+
return t.appendChild(f("slot")), this.errorMessage && t.appendChild(f("div", {
|
|
179
|
+
id: "l-form-item-error",
|
|
101
180
|
class: "l-form-item__error",
|
|
102
|
-
textContent: this.
|
|
181
|
+
textContent: this.errorMessage
|
|
103
182
|
})), e.appendChild(t), e;
|
|
104
183
|
}
|
|
105
184
|
_updateRequired() {
|
|
106
|
-
this._state.required ?
|
|
185
|
+
this._state.required ? m(this, "is-required") : h(this, "is-required");
|
|
107
186
|
}
|
|
108
187
|
_parseSchema() {
|
|
109
|
-
let e = this.
|
|
110
|
-
if (e)
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
188
|
+
let e = this._state.prop;
|
|
189
|
+
if (!e) return this._updateRules();
|
|
190
|
+
if (this.programRules) return this._updateRules({
|
|
191
|
+
...this.programRules,
|
|
192
|
+
key: e
|
|
193
|
+
});
|
|
194
|
+
let t = this._state.verify ? this._state.verify.split("|") : [];
|
|
195
|
+
this._state.pattern && t.push(new RegExp(this._state.pattern)), this._updateRules({
|
|
196
|
+
key: e,
|
|
197
|
+
required: this._state.required,
|
|
198
|
+
message: this._state.validity,
|
|
199
|
+
rules: t
|
|
200
|
+
});
|
|
123
201
|
}
|
|
124
202
|
_updateError() {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
e = document.createElement("div"), e.className = "l-form-item__error", e.textContent = this._state.error;
|
|
130
|
-
let t = s(".l-form-item__content", this.root);
|
|
131
|
-
t && t.appendChild(e);
|
|
132
|
-
}
|
|
203
|
+
let e = this.errorMessage;
|
|
204
|
+
if (e ? m(this, "is-error") : h(this, "is-error"), !this.rendered) return;
|
|
205
|
+
let t = p(".l-form-item__error", this.root);
|
|
206
|
+
t ? e ? t.textContent = e : t.remove() : e && (t = document.createElement("div"), t.id = "l-form-item-error", t.className = "l-form-item__error", t.textContent = e, p(".l-form-item__content", this.root)?.appendChild(t)), this.updateAccessibility();
|
|
133
207
|
}
|
|
134
208
|
_updateLabel() {
|
|
135
209
|
if (!this.rendered) return;
|
|
136
|
-
let e =
|
|
137
|
-
|
|
210
|
+
let e = this.root.querySelector(".l-form-item__label"), t = this._state.label;
|
|
211
|
+
t === void 0 ? e?.remove() : e ? this.setLabelText(e, t) : this.root.prepend(this.createLabel(t));
|
|
212
|
+
}
|
|
213
|
+
createLabel(e) {
|
|
214
|
+
let t = this.ownerDocument.createElement("label");
|
|
215
|
+
return t.className = "l-form-item__label", t.id = "l-form-item-label", this.setLabelText(t, e), t;
|
|
138
216
|
}
|
|
217
|
+
setLabelText(e, t) {
|
|
218
|
+
e.replaceChildren(), t ? (e.removeAttribute("aria-hidden"), e.append(f("span", {
|
|
219
|
+
class: "l-form-item__required",
|
|
220
|
+
"aria-hidden": "true"
|
|
221
|
+
}), t)) : e.setAttribute("aria-hidden", "true");
|
|
222
|
+
}
|
|
223
|
+
itemFields() {
|
|
224
|
+
let e = [], t = (n) => {
|
|
225
|
+
if (!(n instanceof _ || n.hasAttribute("hidden"))) {
|
|
226
|
+
if (n instanceof i || n.matches("input:not([type=\"hidden\"],[type=\"button\"],[type=\"submit\"],[type=\"reset\"],[type=\"image\"]),textarea,select")) e.push(n);
|
|
227
|
+
else for (let e of n.children) t(e);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
for (let e of this.root.querySelector("slot")?.assignedElements() ?? []) t(e);
|
|
231
|
+
return e;
|
|
232
|
+
}
|
|
233
|
+
focusFieldFromLabel = (e) => {
|
|
234
|
+
if (e.defaultPrevented || !this._state.label?.trim() || !(e.target instanceof Element) || !e.target.closest(".l-form-item__label")) return;
|
|
235
|
+
let t = this.itemFields();
|
|
236
|
+
if (t.length !== 1 || this._state.disabled) return;
|
|
237
|
+
let n = t[0];
|
|
238
|
+
if (n instanceof i && n.isDisabled()) return;
|
|
239
|
+
let r = n instanceof i ? n.formItemControl : n;
|
|
240
|
+
r && !r.matches(":disabled") && r.focus();
|
|
241
|
+
};
|
|
242
|
+
scheduleAccessibility() {
|
|
243
|
+
this.accessibilityScheduled || (this.accessibilityScheduled = !0, queueMicrotask(() => {
|
|
244
|
+
this.accessibilityScheduled = !1, this.updateAccessibility();
|
|
245
|
+
}));
|
|
246
|
+
}
|
|
247
|
+
clearFieldPresentation(e) {
|
|
248
|
+
e instanceof i ? e.setFormItemPresentation(this) : (this.nativePresentation.get(e)?.clear(this), this.nativePresentation.delete(e), g.get(e) === this && g.delete(e));
|
|
249
|
+
}
|
|
250
|
+
updateAccessibility = () => {
|
|
251
|
+
if (!this.isConnected || !this.rendered) return;
|
|
252
|
+
let e = this.itemFields();
|
|
253
|
+
for (let t of this.connectedFields) e.includes(t) || this.clearFieldPresentation(t);
|
|
254
|
+
this.connectedFields.clear();
|
|
255
|
+
let t = this._state.label?.trim() || void 0, n = this.errorMessage, r = e.length === 1 ? e[0] : void 0, s = this._state.prop ? e.filter((e) => e.name === this._state.prop) : [], c = r ?? (s.length === 1 ? s[0] : void 0), l = c instanceof i && !c.formItemControl ? void 0 : c, u = r && (!(r instanceof i) || !!r.formItemControl), d = e.length > 0 && !l && n || void 0;
|
|
256
|
+
for (let r of e) {
|
|
257
|
+
this.connectedFields.add(r);
|
|
258
|
+
let e = u ? t : void 0, s = r === l ? n : void 0;
|
|
259
|
+
if (r instanceof i) r.setFormItemPresentation(this, e, s, d);
|
|
260
|
+
else {
|
|
261
|
+
let t = this.nativePresentation.get(r);
|
|
262
|
+
t || (g.get(r)?.clearFieldPresentation(r), t = new a(r), this.nativePresentation.set(r, t), g.set(r, this));
|
|
263
|
+
let n = t.authoredValue("aria-label") !== null || o(r, "aria-labelledby").length > 0 || !!r.labels?.length;
|
|
264
|
+
t.attribute("aria-label", n ? void 0 : e), t.attribute("aria-invalid", s ? "true" : void 0), t.attribute("aria-required", this._state.required && !r.required && t.authoredValue("aria-required") === null ? "true" : void 0), t.describe(this, s ?? "");
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
let f = this.root.querySelector(".l-form-item__content");
|
|
268
|
+
if (!f) return;
|
|
269
|
+
let p = !!t && e.length > 0 && !u;
|
|
270
|
+
p || d ? f.setAttribute("role", "group") : f.removeAttribute("role"), p ? f.setAttribute("aria-labelledby", "l-form-item-label") : f.removeAttribute("aria-labelledby"), d ? f.setAttribute("aria-describedby", "l-form-item-error") : f.removeAttribute("aria-describedby");
|
|
271
|
+
};
|
|
139
272
|
_updateRules(e) {
|
|
140
273
|
this.emit("form-rule-change", {
|
|
141
274
|
bubbles: !0,
|
|
@@ -144,5 +277,4 @@ var f = class extends a {
|
|
|
144
277
|
});
|
|
145
278
|
}
|
|
146
279
|
};
|
|
147
|
-
|
|
148
|
-
export { f as default };
|
|
280
|
+
export { _ as default };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
var e = ":host{display:var(--l-form-item-display,flex);font-size:14px}.l-form-item__label{text-align:var(--l-form-label-align,right);width:var(--l-form-label-width,auto);height:var(--l-form-label-height,var(--l-form-control-height,32px));line-height:var(--l-form-label-height,var(--l-form-control-height,32px));color:#606266;box-sizing:border-box;padding:0 10px 0 0;display:inline-block}.l-form-item__label:empty{display:var(--l-form-label-empty-display,inline-block)}:host(.is-required) .l-form-item__label:before{content:\"*\";color:var(--l-warning-color,#f56c6c);vertical-align:middle;margin-right:4px}.l-form-item__content{flex:1;align-items:center;display:flex;position:relative}.l-form-item__error{color:var(--nt-error-color,#ed3f13);padding-top:3px;font-size:12px;line-height:1;position:absolute;top:100%;left:0}:host(.l-form-item--left){--l-form-label-align:left}:host(.l-form-item--top){--l-form-item-display:grid;--l-form-label-align:left;--l-form-label-empty-display:none;grid-template-columns:1fr}";
|
|
3
|
-
//#endregion
|
|
1
|
+
// src/components/form/form_item.less?inline
|
|
2
|
+
var e = ":host{display:var(--l-form-item-display,flex);font-size:14px}.l-form-item__label{text-align:var(--l-form-label-align,right);width:var(--l-form-label-width,auto);height:var(--l-form-label-height,var(--l-form-control-height,32px));line-height:var(--l-form-label-height,var(--l-form-control-height,32px));color:#606266;box-sizing:border-box;padding:0 10px 0 0;display:inline-block}.l-form-item__label:empty{display:var(--l-form-label-empty-display,inline-block)}:host(.is-required) .l-form-item__label:empty:before,:host(.is-required) .l-form-item__required:before{content:\"*\";color:var(--l-warning-color,#f56c6c);vertical-align:middle;margin-right:4px}.l-form-item__content{flex:1;align-items:center;display:flex;position:relative}.l-form-item__error{color:var(--nt-error-color,#ed3f13);padding-top:3px;font-size:12px;line-height:1;position:absolute;top:100%;left:0}:host(.l-form-item--left),:host(.l-form-item--right[label-position=right]){--l-form-item-display:flex;--l-form-label-empty-display:inline-block}:host(.l-form-item--left){--l-form-label-align:left}:host(.l-form-item--right[label-position=right]){--l-form-label-align:right}:host(.l-form-item--top){--l-form-item-display:grid;--l-form-label-align:left;--l-form-label-empty-display:none;grid-template-columns:1fr}";
|
|
4
3
|
export { e as default };
|
package/lib/form/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { Signal } from "../utils/signal_types";
|
|
2
1
|
import { Validator } from "utilane";
|
|
3
2
|
import type { SchemaType } from "utilane";
|
|
4
|
-
import type { FormSignal } from "./types";
|
|
5
3
|
import BaseComponent from "../base";
|
|
6
4
|
interface FormState {
|
|
7
5
|
inline: boolean;
|
|
6
|
+
innerBlock: boolean;
|
|
7
|
+
disabled: boolean;
|
|
8
8
|
labelPosition: "left" | "right" | "top";
|
|
9
9
|
labelWidth: string;
|
|
10
10
|
labelHeight?: string;
|
|
@@ -15,45 +15,99 @@ interface FormState {
|
|
|
15
15
|
export default class Form extends BaseComponent<FormState> {
|
|
16
16
|
static baseName: string;
|
|
17
17
|
validator: Validator;
|
|
18
|
-
private
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
private errorMessages;
|
|
19
|
+
private errorRevision;
|
|
20
|
+
private readonly displayRevisions;
|
|
21
|
+
private readonly businessErrors;
|
|
22
|
+
private readonly displayedBusinessErrors;
|
|
23
|
+
private readonly nativeFeedback;
|
|
24
|
+
private readonly pendingNativeReports;
|
|
25
|
+
private readonly itemRules;
|
|
26
|
+
private readonly nativeOwner;
|
|
27
|
+
private readonly fieldContext;
|
|
28
|
+
private readonly autocompleteConfiguration;
|
|
29
|
+
private readonly locallyClearedFields;
|
|
30
|
+
private disposeContext?;
|
|
31
|
+
private readonly provider;
|
|
32
|
+
private listeningForm?;
|
|
33
|
+
private stopNativeSubmit?;
|
|
34
|
+
private resetScope;
|
|
35
|
+
private validationRoot?;
|
|
36
|
+
/** 当前原生表单;独立 l-form 使用辅助 form,已有原生祖先时复用。 */
|
|
37
|
+
get nativeForm(): HTMLFormElement | undefined;
|
|
38
|
+
get disabled(): boolean;
|
|
39
|
+
get autocomplete(): "on" | "off" | "";
|
|
40
|
+
set autocomplete(value: "on" | "off" | "" | null | undefined);
|
|
41
|
+
set disabled(value: boolean);
|
|
42
|
+
private fields;
|
|
43
|
+
private nativeReset;
|
|
44
|
+
private validationField;
|
|
45
|
+
private nativeInvalid;
|
|
46
|
+
private nativeValidityChanged;
|
|
47
|
+
private nativeInput;
|
|
48
|
+
private updateNativeFeedback;
|
|
49
|
+
private notifyNativeFeedback;
|
|
50
|
+
private nativeMessageForName;
|
|
51
|
+
private activeNativeMessage;
|
|
52
|
+
private setEmitError;
|
|
53
|
+
private reconcileNativeFeedback;
|
|
54
|
+
private listenNativeForm;
|
|
22
55
|
constructor();
|
|
23
56
|
static get observedAttributes(): string[];
|
|
24
|
-
protected attributeChanged(name: string, oldValue: string, newValue: string): void;
|
|
57
|
+
protected attributeChanged(name: string, oldValue: string, newValue: string | null): void;
|
|
25
58
|
protected updateDOM(changedProps: Set<string>): void;
|
|
26
59
|
connectedCallback(): void;
|
|
27
60
|
afterInit(): void;
|
|
28
61
|
disconnectedCallback(): void;
|
|
29
62
|
render_v2(): {
|
|
30
|
-
|
|
63
|
+
styleSheets: CSSStyleSheet[];
|
|
31
64
|
template: string;
|
|
32
65
|
};
|
|
33
66
|
render(): string;
|
|
34
67
|
ruleChange: (e: CustomEvent) => void;
|
|
68
|
+
private replaceItemRules;
|
|
69
|
+
private replaceRules;
|
|
70
|
+
private revalidateChangedRules;
|
|
35
71
|
addSchemas(schemas: SchemaType[]): void;
|
|
36
72
|
setSchemas(schemas: SchemaType[]): void;
|
|
37
73
|
setSchema(schema: SchemaType): void;
|
|
38
74
|
addSchema(schema: SchemaType): void;
|
|
39
|
-
private _provide;
|
|
40
|
-
_formAction: (e: CustomEvent) => void;
|
|
41
|
-
_valueChange: (e: CustomEvent) => void;
|
|
42
75
|
setValidateErrors(errs: Record<string, string | undefined>, all?: string | string[] | boolean): void;
|
|
76
|
+
private relatedRuleNames;
|
|
77
|
+
private invalidateBusinessRules;
|
|
78
|
+
private validateInput;
|
|
79
|
+
private validateKeys;
|
|
80
|
+
private applyFieldErrors;
|
|
81
|
+
private updateBusinessErrors;
|
|
82
|
+
private applyFieldValidity;
|
|
83
|
+
private isDataField;
|
|
84
|
+
private findDataField;
|
|
85
|
+
private validationData;
|
|
43
86
|
validateField(field: string | string[]): Promise<void>;
|
|
87
|
+
/** 当前错误快照;普通数据,不再暴露 signal 调用接口。 */
|
|
88
|
+
get validationErrors(): Readonly<Record<string, string | undefined>>;
|
|
89
|
+
private withNativeFeedback;
|
|
44
90
|
clearValidate(): void;
|
|
45
91
|
reset(): void;
|
|
92
|
+
private clearPresentation;
|
|
46
93
|
submit(): void;
|
|
47
94
|
/**
|
|
48
95
|
* 校验全部表单数据
|
|
49
96
|
*/
|
|
50
97
|
validate(): Promise<{
|
|
51
98
|
result: boolean;
|
|
52
|
-
errors:
|
|
99
|
+
errors: {
|
|
100
|
+
[k: string]: string | undefined;
|
|
101
|
+
};
|
|
53
102
|
}>;
|
|
54
|
-
getData():
|
|
55
|
-
|
|
56
|
-
|
|
103
|
+
getData(): Record<string, any>;
|
|
104
|
+
private collectData;
|
|
105
|
+
private fieldName;
|
|
106
|
+
private initializeFieldValidity;
|
|
107
|
+
private visibleError;
|
|
108
|
+
private notifyFieldError;
|
|
109
|
+
private notifyErrorChange;
|
|
57
110
|
setErrors(errorObj: Record<string, any>): void;
|
|
111
|
+
private replaceDisplayedErrors;
|
|
58
112
|
}
|
|
59
113
|
export {};
|