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.
Files changed (309) hide show
  1. package/lib/base.d.ts +3 -2
  2. package/lib/base.js +11 -8
  3. package/lib/button/index.d.ts +21 -5
  4. package/lib/button/index.js +115 -62
  5. package/lib/button/index.less_inline.js +2 -3
  6. package/lib/button/style.js +1 -2
  7. package/lib/calendar/index.js +22 -24
  8. package/lib/calendar/index.less_inline.js +1 -2
  9. package/lib/calendar/langs.js +1 -2
  10. package/lib/card/index.js +8 -9
  11. package/lib/card/index.less_inline.js +1 -2
  12. package/lib/carousel/index.js +10 -11
  13. package/lib/carousel/index.less_inline.js +1 -2
  14. package/lib/carousel/item.js +1 -2
  15. package/lib/carousel/item.less_inline.js +1 -2
  16. package/lib/carousel/timer.js +1 -2
  17. package/lib/check/check.d.ts +40 -8
  18. package/lib/check/check.js +200 -65
  19. package/lib/check/check.less_inline.js +2 -3
  20. package/lib/check/checkbox.js +2 -3
  21. package/lib/check/checkbox.less_inline.js +2 -3
  22. package/lib/check/checkbox_group.js +1 -2
  23. package/lib/check/index.d.ts +28 -8
  24. package/lib/check/index.js +151 -46
  25. package/lib/check/index.less_inline.js +1 -2
  26. package/lib/check/radio.js +2 -3
  27. package/lib/check/radio.less_inline.js +1 -2
  28. package/lib/check/radio_group.js +2 -3
  29. package/lib/collapse/index.d.ts +12 -4
  30. package/lib/collapse/index.js +80 -46
  31. package/lib/collapse/index.less_inline.js +2 -3
  32. package/lib/collapse/item.d.ts +35 -9
  33. package/lib/collapse/item.js +219 -57
  34. package/lib/collapse/item.less_inline.js +2 -3
  35. package/lib/collapse/types.d.ts +17 -3
  36. package/lib/color_picker/index.d.ts +4 -2
  37. package/lib/color_picker/index.js +26 -17
  38. package/lib/color_picker/index.less_inline.js +1 -2
  39. package/lib/date_picker/index.d.ts +5 -1
  40. package/lib/date_picker/index.js +39 -23
  41. package/lib/date_picker/index.less_inline.js +1 -2
  42. package/lib/date_picker_ori/index.d.ts +7 -2
  43. package/lib/date_picker_ori/index.js +123 -47
  44. package/lib/date_picker_ori/index.less_inline.js +1 -2
  45. package/lib/description_panel/index.js +2 -10
  46. package/lib/description_panel/index.less_inline.js +1 -2
  47. package/lib/dialog/dialog_box.js +28 -29
  48. package/lib/dialog/dialog_container.css_inline.js +1 -2
  49. package/lib/dialog/dialog_container.js +13 -14
  50. package/lib/dialog/dialog_container_style.js +1 -2
  51. package/lib/dialog/index.js +1 -2
  52. package/lib/dropdown/index.d.ts +39 -0
  53. package/lib/dropdown/index.js +98 -0
  54. package/lib/entries/base.js +1 -2
  55. package/lib/entries/button.js +5 -6
  56. package/lib/entries/calendar.js +5 -6
  57. package/lib/entries/card.js +5 -6
  58. package/lib/entries/carousel-item.js +5 -6
  59. package/lib/entries/carousel.js +5 -6
  60. package/lib/entries/checkbox-group.js +5 -6
  61. package/lib/entries/checkbox.js +5 -6
  62. package/lib/entries/collapse-item.d.ts +0 -1
  63. package/lib/entries/collapse-item.js +6 -6
  64. package/lib/entries/collapse.d.ts +0 -1
  65. package/lib/entries/collapse.js +11 -6
  66. package/lib/entries/color-picker.js +5 -6
  67. package/lib/entries/date-picker-ori.js +5 -6
  68. package/lib/entries/date-picker.js +5 -6
  69. package/lib/entries/description-panel.js +5 -6
  70. package/lib/entries/dialog-box.js +1 -2
  71. package/lib/entries/dialog-container.js +5 -6
  72. package/lib/entries/dialog.js +1 -2
  73. package/lib/entries/dropdown.d.ts +2 -0
  74. package/lib/entries/dropdown.js +1 -0
  75. package/lib/entries/form-item.js +5 -6
  76. package/lib/entries/form.js +5 -6
  77. package/lib/entries/icon-arrow-down.js +5 -6
  78. package/lib/entries/icon-arrow-left.js +5 -6
  79. package/lib/entries/icon-arrow-right.js +5 -6
  80. package/lib/entries/icon-arrow-up.js +5 -6
  81. package/lib/entries/icon-base.js +5 -6
  82. package/lib/entries/icon-calendar.js +5 -6
  83. package/lib/entries/icon-caret-bottom.js +5 -6
  84. package/lib/entries/icon-caret-top.js +5 -6
  85. package/lib/entries/icon-close-filled.js +5 -6
  86. package/lib/entries/icon-close.js +5 -6
  87. package/lib/entries/icon-copy.js +5 -6
  88. package/lib/entries/icon-d-arrow-left.js +5 -6
  89. package/lib/entries/icon-d-arrow-right.js +5 -6
  90. package/lib/entries/icon-delete.js +5 -6
  91. package/lib/entries/icon-eye-outline.js +5 -6
  92. package/lib/entries/icon-font-icon.js +5 -6
  93. package/lib/entries/icon-info.js +5 -6
  94. package/lib/entries/icon-loading.js +5 -6
  95. package/lib/entries/icon-minus.js +5 -6
  96. package/lib/entries/icon-moon.js +5 -6
  97. package/lib/entries/icon-more.js +5 -6
  98. package/lib/entries/icon-picture.js +5 -6
  99. package/lib/entries/icon-plus.js +5 -6
  100. package/lib/entries/icon-reduction.js +5 -6
  101. package/lib/entries/icon-refresh-left.js +5 -6
  102. package/lib/entries/icon-refresh-right.js +5 -6
  103. package/lib/entries/icon-refresh.js +5 -6
  104. package/lib/entries/icon-search.js +5 -6
  105. package/lib/entries/icon-select.js +5 -6
  106. package/lib/entries/icon-sort.js +5 -6
  107. package/lib/entries/icon-success.js +5 -6
  108. package/lib/entries/icon-sun.js +5 -6
  109. package/lib/entries/icon-theme-default.js +5 -6
  110. package/lib/entries/icon-warn.js +5 -6
  111. package/lib/entries/icon-zoom-in.js +5 -6
  112. package/lib/entries/icon-zoom-out.js +5 -6
  113. package/lib/entries/image-preview.js +5 -6
  114. package/lib/entries/image.js +5 -6
  115. package/lib/entries/input-number.js +5 -6
  116. package/lib/entries/input.js +5 -6
  117. package/lib/entries/list.js +5 -6
  118. package/lib/entries/loading.js +1 -2
  119. package/lib/entries/mask.js +5 -6
  120. package/lib/entries/md-input.js +5 -6
  121. package/lib/entries/menu.js +5 -6
  122. package/lib/entries/message.js +1 -2
  123. package/lib/entries/modal-box.js +1 -2
  124. package/lib/entries/modal.js +5 -6
  125. package/lib/entries/notification-box.js +1 -2
  126. package/lib/entries/notification.js +1 -2
  127. package/lib/entries/page-header.js +5 -6
  128. package/lib/entries/pagination.js +5 -6
  129. package/lib/entries/polygon.js +5 -6
  130. package/lib/entries/popconfirm.js +1 -2
  131. package/lib/entries/popover.js +1 -2
  132. package/lib/entries/qrcode.js +5 -6
  133. package/lib/entries/radio-group.js +5 -6
  134. package/lib/entries/radio.js +5 -6
  135. package/lib/entries/select-ori.js +5 -6
  136. package/lib/entries/select.js +5 -6
  137. package/lib/entries/space.js +5 -6
  138. package/lib/entries/switch.js +5 -6
  139. package/lib/entries/tabbar-item.js +5 -6
  140. package/lib/entries/tabbar.js +5 -6
  141. package/lib/entries/table.js +5 -6
  142. package/lib/entries/tabs.js +1 -2
  143. package/lib/entries/tag.js +5 -6
  144. package/lib/entries/theme-color.js +5 -6
  145. package/lib/entries/theme.js +5 -6
  146. package/lib/entries/transition.js +1 -2
  147. package/lib/entries/upload.js +5 -6
  148. package/lib/entries/utils.js +1 -3
  149. package/lib/form/accessibility.d.ts +15 -0
  150. package/lib/form/accessibility.js +56 -0
  151. package/lib/form/autocomplete.d.ts +21 -0
  152. package/lib/form/autocomplete.js +59 -0
  153. package/lib/form/context.d.ts +157 -0
  154. package/lib/form/context.js +88 -0
  155. package/lib/form/form_inner.d.ts +99 -24
  156. package/lib/form/form_inner.js +424 -72
  157. package/lib/form/form_item.d.ts +35 -11
  158. package/lib/form/form_item.js +210 -78
  159. package/lib/form/form_item.less_inline.js +2 -3
  160. package/lib/form/form_item_style.d.ts +3 -0
  161. package/lib/form/form_item_style.js +7 -0
  162. package/lib/form/index.d.ts +69 -15
  163. package/lib/form/index.js +501 -101
  164. package/lib/form/index.less_inline.js +1 -2
  165. package/lib/form/owner.d.ts +78 -0
  166. package/lib/form/owner.js +138 -0
  167. package/lib/form/style.d.ts +3 -0
  168. package/lib/form/style.js +7 -0
  169. package/lib/icon/arrow_down.js +1 -2
  170. package/lib/icon/arrow_left.js +1 -2
  171. package/lib/icon/arrow_right.js +1 -2
  172. package/lib/icon/arrow_up.js +1 -2
  173. package/lib/icon/base.js +1 -2
  174. package/lib/icon/calendar.js +1 -2
  175. package/lib/icon/caret_bottom.js +1 -2
  176. package/lib/icon/caret_top.js +1 -2
  177. package/lib/icon/close.js +1 -2
  178. package/lib/icon/close_filled.js +1 -2
  179. package/lib/icon/copy.js +1 -2
  180. package/lib/icon/d_arrow_left.js +1 -2
  181. package/lib/icon/d_arrow_right.js +1 -2
  182. package/lib/icon/delete.js +1 -2
  183. package/lib/icon/eye_outline.js +1 -2
  184. package/lib/icon/font_icon.js +1 -2
  185. package/lib/icon/icon_style.js +1 -2
  186. package/lib/icon/index.less_inline.js +1 -2
  187. package/lib/icon/info.js +1 -2
  188. package/lib/icon/loading.js +1 -2
  189. package/lib/icon/minus.js +1 -2
  190. package/lib/icon/moon.js +1 -2
  191. package/lib/icon/more.js +1 -2
  192. package/lib/icon/picture.js +1 -2
  193. package/lib/icon/plus.js +1 -2
  194. package/lib/icon/reduction.js +1 -2
  195. package/lib/icon/refresh.js +1 -2
  196. package/lib/icon/refresh_left.js +1 -2
  197. package/lib/icon/refresh_right.js +1 -2
  198. package/lib/icon/search.js +1 -2
  199. package/lib/icon/select.js +1 -2
  200. package/lib/icon/sort.js +1 -2
  201. package/lib/icon/success.js +1 -2
  202. package/lib/icon/sun.js +1 -2
  203. package/lib/icon/theme_default.js +1 -2
  204. package/lib/icon/warn.js +1 -2
  205. package/lib/icon/zoom_in.js +1 -2
  206. package/lib/icon/zoom_out.js +1 -2
  207. package/lib/image/image_preview.js +1 -2
  208. package/lib/image/image_preview.less_inline.js +1 -2
  209. package/lib/image/index.js +1 -2
  210. package/lib/image/index.less_inline.js +1 -2
  211. package/lib/index.d.ts +2 -1
  212. package/lib/index.js +91 -91
  213. package/lib/input/index.d.ts +14 -0
  214. package/lib/input/index.js +126 -31
  215. package/lib/input/index.less_inline.js +2 -3
  216. package/lib/input/input_inner.less_inline.js +1 -2
  217. package/lib/input/style.d.ts +1 -0
  218. package/lib/input/style.js +5 -7
  219. package/lib/input_number/index.d.ts +7 -0
  220. package/lib/input_number/index.js +70 -48
  221. package/lib/input_number/index.less_inline.js +1 -2
  222. package/lib/input_number/style.js +1 -2
  223. package/lib/list/index.js +4 -5
  224. package/lib/list/index.less_inline.js +1 -2
  225. package/lib/loading/index.js +1 -2
  226. package/lib/mask/index.js +2 -7
  227. package/lib/mask/index.less_inline.js +1 -2
  228. package/lib/md_input/index.d.ts +11 -2
  229. package/lib/md_input/index.js +63 -27
  230. package/lib/md_input/index.less_inline.js +2 -3
  231. package/lib/menu/index.js +2 -7
  232. package/lib/menu/index.less_inline.js +1 -2
  233. package/lib/message/index.js +1 -2
  234. package/lib/modal/index.js +15 -16
  235. package/lib/modal/index.less_inline.js +1 -2
  236. package/lib/modal/modal_box.js +24 -25
  237. package/lib/notification/index.js +15 -29
  238. package/lib/notification/index.less_inline.js +1 -2
  239. package/lib/notification/notification_box.js +2 -3
  240. package/lib/notification/placement.js +1 -2
  241. package/lib/notification/style.js +1 -2
  242. package/lib/page_header/index.js +1 -2
  243. package/lib/page_header/index.less_inline.js +1 -2
  244. package/lib/pagination/index.js +2 -7
  245. package/lib/pagination/index.less_inline.js +1 -2
  246. package/lib/polygon/index.js +1 -2
  247. package/lib/polygon/index.less_inline.js +1 -2
  248. package/lib/qrcode/index.js +1 -2
  249. package/lib/qrcode/index.less_inline.js +1 -2
  250. package/lib/select/index.d.ts +19 -2
  251. package/lib/select/index.js +128 -74
  252. package/lib/select/index.less_inline.js +1 -2
  253. package/lib/select_ori/index.d.ts +9 -1
  254. package/lib/select_ori/index.js +36 -24
  255. package/lib/select_ori/index.less_inline.js +1 -2
  256. package/lib/space/index.js +1 -2
  257. package/lib/space/index.less_inline.js +1 -2
  258. package/lib/styles/animation/index.css_inline.js +1 -2
  259. package/lib/styles/animation/index.js +1 -2
  260. package/lib/styles/mask/index.css_inline.js +1 -2
  261. package/lib/styles/mask/index.js +1 -2
  262. package/lib/switch/index.d.ts +6 -0
  263. package/lib/switch/index.js +31 -16
  264. package/lib/switch/index.less_inline.js +1 -2
  265. package/lib/tabbar/index.js +1 -2
  266. package/lib/tabbar/index.less_inline.js +1 -2
  267. package/lib/tabbar/item.js +1 -2
  268. package/lib/tabbar/item.less_inline.js +1 -2
  269. package/lib/table/index.js +1 -2
  270. package/lib/table/index.less_inline.js +1 -2
  271. package/lib/tabs/index.js +1 -2
  272. package/lib/tag/index.d.ts +11 -3
  273. package/lib/tag/index.js +25 -24
  274. package/lib/tag/index.less_inline.js +2 -3
  275. package/lib/theme/appearance.d.ts +5 -0
  276. package/lib/theme/appearance.js +34 -0
  277. package/lib/theme/index.js +83 -39
  278. package/lib/theme/index.less_inline.js +1 -2
  279. package/lib/theme/theme_color.js +1 -2
  280. package/lib/upload/index.js +28 -41
  281. package/lib/upload/index.less_inline.js +2 -3
  282. package/lib/upload/style.js +1 -2
  283. package/lib/utils/clickoutside.js +1 -2
  284. package/lib/utils/event.js +1 -2
  285. package/lib/utils/index.d.ts +27 -6
  286. package/lib/utils/index.js +26 -6
  287. package/lib/utils/popover.js +7 -16
  288. package/lib/utils/transition.js +1 -2
  289. package/package.json +16 -13
  290. package/styles/dark.css +10 -2
  291. package/styles/dropdown.css +46 -0
  292. package/styles/reset.css +0 -1
  293. package/styles/select.css +5 -0
  294. package/styles/themes/apple.css +47 -0
  295. package/styles/{theme-coral.css → themes/coral.css} +5 -3
  296. package/styles/themes/deep-sea-blue.css +12 -0
  297. package/styles/themes/gamboge.css +15 -0
  298. package/styles/{theme-jade.css → themes/jade.css} +5 -3
  299. package/styles/themes/lotus-seed.css +12 -0
  300. package/styles/{theme-tangerine.css → themes/tangerine.css} +5 -3
  301. package/styles/themes.css +8 -0
  302. package/styles/vars.css +8 -2
  303. package/types/preact.d.ts +42 -0
  304. package/lib/form/types.d.ts +0 -7
  305. package/lib/utils/context_provide.d.ts +0 -10
  306. package/lib/utils/context_provide.js +0 -22
  307. package/lib/utils/locale.d.ts +0 -6
  308. package/lib/utils/locale.js +0 -34
  309. package/lib/utils/signal_types.d.ts +0 -5
@@ -1,124 +1,476 @@
1
1
  import e from "../base.js";
2
- import { parseAttrValue as t, stopSignal as n } from "../utils/index.js";
3
- import { getAttr as r } from "utilane/browser";
4
- import { effect as i } from "alien-signals";
5
- //#region src/components/form/form_inner.ts
6
- var a = class extends e {
2
+ import { FieldAccessibility as t, fieldControlSelector as n, referenceElements as r, referenceText as i } from "./accessibility.js";
3
+ import { FORM_CONTEXT_EVENTS as a, readFormBooleanAttribute as o, requestFormContext as s, resolveFieldContext as c } from "./context.js";
4
+ // src/components/form/form_inner.ts
5
+ var l = class extends e {
6
+ static formAssociated = !0;
7
+ internals;
7
8
  _disabled = !1;
8
- _value = void 0;
9
- _resetValue;
10
- _firstPushValue = !0;
11
- _isReset = !1;
12
- _name;
9
+ #e = void 0;
10
+ dirtyValue = !1;
11
+ applyingDefault = !1;
12
+ applyingFormReset = !1;
13
+ valueInitialized = !1;
14
+ ownDisabled = !1;
15
+ nativeDisabled = !1;
16
+ contextDisabled = !1;
17
+ contextRequired = !1;
18
+ explicitName;
19
+ effectiveName;
20
+ syncedNameAttribute = null;
21
+ reflectingDisabled = !1;
22
+ connecting = !1;
23
+ unregister = [];
24
+ groupContext;
13
25
  formContext;
14
- formItemContext;
15
- formErrors;
16
- resetCtx;
17
- _signalStop;
18
- _errorSignalStop;
19
- _resetSignalStop;
20
- constructor(e = !0, t = !0) {
21
- super(!0, { delegatesFocus: t }), this._firstPushValue = e;
26
+ itemContext;
27
+ manualValidity = {};
28
+ manualMessage = "";
29
+ businessMessage;
30
+ nativeValidity;
31
+ displayedValidityMessage;
32
+ itemPresentation;
33
+ accessibilityControl;
34
+ fieldAccessibility;
35
+ accessibilityObserver;
36
+ contextField = {
37
+ target: this,
38
+ getSnapshot: () => ({
39
+ name: this.name,
40
+ value: this.getValue(),
41
+ disabled: this.isDisabled()
42
+ })
43
+ };
44
+ constructor(e = !0) {
45
+ if (super(!0, { delegatesFocus: e }), typeof this.attachInternals != "function") throw Error("Litos UI:原生表单需要 iOS/iPadOS 16.4+ 或具备 ElementInternals 的浏览器。");
46
+ this.internals = this.attachInternals();
47
+ }
48
+ get nativeValueEnabled() {
49
+ return !0;
50
+ }
51
+ get grouped() {
52
+ return !1;
53
+ }
54
+ get valueSnapshot() {
55
+ return this.getValue();
56
+ }
57
+ get requiredSelection() {}
58
+ get form() {
59
+ return this.internals.form;
60
+ }
61
+ get labels() {
62
+ return this.internals.labels;
63
+ }
64
+ get validity() {
65
+ return this.syncNativeValidity(), this.internals.validity;
66
+ }
67
+ get validationMessage() {
68
+ return this.syncNativeValidity(), this.internals.validationMessage;
69
+ }
70
+ get constraintValidationMessage() {
71
+ return this.nativeValidity?.constraintMessage;
72
+ }
73
+ get willValidate() {
74
+ return this.internals.willValidate;
75
+ }
76
+ checkValidity() {
77
+ return this.syncNativeValidity(), this.internals.checkValidity();
78
+ }
79
+ reportValidity() {
80
+ return this.syncNativeValidity(), this.internals.reportValidity();
81
+ }
82
+ setValidity(e = {}, t, n) {
83
+ this.internals.setValidity(e, t, n), this.manualValidity = { ...e }, this.manualMessage = t ?? "", this.syncNativeValidity(n);
22
84
  }
23
85
  get name() {
24
- return this._name;
86
+ return this.effectiveName ?? this.explicitName;
25
87
  }
26
88
  set name(e) {
27
- this._name = e;
89
+ this.syncedNameAttribute = this.getAttribute("name"), this.explicitName = e == null ? void 0 : String(e), this.refreshConfiguration();
90
+ }
91
+ get autocomplete() {
92
+ return this.getAttribute("autocomplete") ?? "";
93
+ }
94
+ set autocomplete(e) {
95
+ e == null || e === "" ? this.removeAttribute("autocomplete") : this.setAttribute("autocomplete", e);
28
96
  }
29
97
  get value() {
30
- return this._value;
98
+ return this.#e;
31
99
  }
32
100
  set value(e) {
33
101
  this.setValue(e);
34
102
  }
35
103
  setValue(e) {
36
- this._value = e, this._resetValue ??= e, this.pushValueChange();
104
+ let t = !Object.is(this.#e, e);
105
+ this.#e = e, this.applyingDefault || (this.dirtyValue = !0), t && this.notifyFieldValueChanged(), this.syncNativeValue();
106
+ }
107
+ notifyFieldValueChanged() {
108
+ this.applyingFormReset || this.formContext?.fieldValueChanged?.(this.contextField);
37
109
  }
38
110
  getValue() {
39
- return this._value;
111
+ return this.#e;
112
+ }
113
+ get defaultValue() {
114
+ return this.copyValue(this.parseDefaultValue(this.getAttribute("value")));
115
+ }
116
+ set defaultValue(e) {
117
+ this.setAttribute("value", this.formatDefaultValue(e));
118
+ }
119
+ get intrinsicDefaultValue() {
120
+ return "";
121
+ }
122
+ parseDefaultValue(e) {
123
+ return e === null ? this.intrinsicDefaultValue : e;
124
+ }
125
+ formatDefaultValue(e) {
126
+ return String(e ?? "");
127
+ }
128
+ applyDefaultValue() {
129
+ if (!this.dirtyValue) {
130
+ this.applyingDefault = !0;
131
+ try {
132
+ this.value = this.copyValue(this.defaultValue);
133
+ } finally {
134
+ this.applyingDefault = !1;
135
+ }
136
+ }
137
+ }
138
+ copyValue(e) {
139
+ return Array.isArray(e) ? e.map((e) => this.copyValue(e)) : e && Object.getPrototypeOf(e) === Object.prototype ? Object.fromEntries(Object.entries(e).map(([e, t]) => [e, this.copyValue(t)])) : e;
40
140
  }
41
141
  static get observedAttributes() {
42
142
  return [
43
143
  "disabled",
144
+ "autocomplete",
44
145
  "value",
45
146
  "name",
46
- "inner-block"
147
+ "form",
148
+ "inner-block",
149
+ "required",
150
+ "pattern",
151
+ "minlength",
152
+ "maxlength",
153
+ "min",
154
+ "max",
155
+ "step",
156
+ "readonly",
157
+ "id",
158
+ "aria-label",
159
+ "aria-labelledby",
160
+ "aria-describedby",
161
+ "aria-invalid"
47
162
  ];
48
163
  }
49
- attributeChanged(e, n, r) {
50
- switch (e) {
51
- case "value":
52
- case "name":
53
- this[e] = r;
54
- break;
55
- case "disabled":
56
- this.setDisabled(t(r, !1, e));
57
- break;
58
- case "inner-block":
59
- let i = t(r, !1, e);
60
- this.innerBlockChange(i);
61
- break;
62
- default: this.attributeChange(e, n, r);
63
- }
164
+ attributeChanged(e, t, n) {
165
+ if (e === "value") this.applyDefaultValue();
166
+ else if (e === "name") {
167
+ if (this.getAttribute("name") === this.syncedNameAttribute) return;
168
+ this.refreshConfiguration();
169
+ } else e === "disabled" ? this.reflectingDisabled || this.setDisabled(o(n) ?? !1) : e === "inner-block" || e === "required" ? this.refreshConfiguration() : e === "id" || e.startsWith("aria-") ? this.syncFieldAccessibility() : (this.attributeChange(e, t, n), e === "form" && this.isConnected && this.bindContexts());
170
+ this.syncNativeValue();
64
171
  }
65
172
  attributeChange(e, t, n) {}
66
173
  connectedCallback() {
67
- this.emitInject("form-context-request", this.formInject), this.emitInject("form-item-context-request", this.formItemInject), super.connectedCallback(), this._signalStop = i(() => {
68
- let e = this.formItemContext ? this.formItemContext() : null, t = this.formContext ? this.formContext() : null;
69
- if (!this.name && e && e.prop && this.setAttribute("name", e.prop), !r(this, "inner-block")) {
70
- let n = e?.innerBlock || t?.innerBlock;
71
- n != null && this.innerBlockChange(n);
72
- }
73
- }), this._value ?? (this._resetValue = "", this._firstPushValue && this.pushValueChange()), this._errorSignalStop = i(() => {
74
- if (!this.name) return;
75
- let e = (this.formErrors ? this.formErrors() : {})[this.name];
76
- this.validResult(e);
77
- }), this._resetSignalStop = i(() => {
78
- (this.resetCtx ? this.resetCtx() : 0) > 0 && this.reset();
79
- });
174
+ this.connecting = !0;
175
+ for (let e of [
176
+ "value",
177
+ "name",
178
+ "disabled",
179
+ "defaultValue",
180
+ "autocomplete",
181
+ "htmlType"
182
+ ]) if (Object.prototype.hasOwnProperty.call(this, e)) {
183
+ let t = this[e];
184
+ delete this[e], this[e] = t;
185
+ }
186
+ this.valueInitialized ||= (this.applyDefaultValue(), !0), this.addEventListener(a.configuration, this.configurationChanged), this.addEventListener(a.validity, this.validityChanged), this.bindContexts(), super.connectedCallback(), this.connecting = !1, this.addEventListener("focusin", this.syncFieldAccessibility), this.refreshConfiguration(), this.syncNativeValue();
80
187
  }
81
188
  disconnectedCallback() {
82
- super.disconnectedCallback(), this._signalStop = n(this._signalStop), this._errorSignalStop = n(this._errorSignalStop), this._resetSignalStop = n(this._resetSignalStop);
189
+ this.removeEventListener("focusin", this.syncFieldAccessibility), this.accessibilityObserver?.disconnect(), this.fieldAccessibility?.clear(this.root), this.accessibilityControl = void 0, this.fieldAccessibility = void 0, this.itemPresentation = void 0, this.displayedValidityMessage = void 0, this.nativeValidity = void 0, this.unbindContexts(), this.removeEventListener(a.configuration, this.configurationChanged), this.removeEventListener(a.validity, this.validityChanged), super.disconnectedCallback();
190
+ }
191
+ unbindContexts() {
192
+ this.unregister.forEach((e) => e()), this.unregister = [], this.formContext = void 0, this.itemContext = void 0, this.groupContext = void 0, this.applyBusinessValidity();
193
+ }
194
+ refreshFormContext() {
195
+ this.bindContexts();
196
+ }
197
+ validateInput() {
198
+ this.formContext?.validateInput?.(this.contextField);
199
+ }
200
+ bindContexts() {
201
+ if (this.unbindContexts(), this.isConnected) {
202
+ this.formContext = s(this, "form"), this.itemContext = s(this, "item"), this.groupContext = s(this, "group");
203
+ for (let e of /* @__PURE__ */ new Set([
204
+ this.formContext,
205
+ this.itemContext,
206
+ this.groupContext
207
+ ])) e && this.unregister.push(e.registerField(this.contextField));
208
+ this.refreshConfiguration();
209
+ }
210
+ }
211
+ configurationChanged = () => {
212
+ this.refreshConfiguration();
213
+ };
214
+ validityChanged = (e) => {
215
+ let t = e.detail;
216
+ this.validResult(t.valid ? void 0 : t.message || "校验失败");
217
+ };
218
+ applyBusinessValidity(e) {
219
+ this.businessMessage !== e && (this.businessMessage = e, this.syncNativeValidity());
220
+ }
221
+ refreshConfiguration() {
222
+ let e = this.getAttribute("name");
223
+ e !== this.syncedNameAttribute && (this.explicitName = e ?? void 0);
224
+ let t = c({
225
+ name: this.explicitName,
226
+ disabled: this.ownDisabled,
227
+ innerBlock: o(this.getAttribute("inner-block")),
228
+ required: o(this.getAttribute("required"))
229
+ }, {
230
+ form: this.formContext?.getSnapshot(),
231
+ item: this.itemContext?.getSnapshot(),
232
+ group: this.groupContext?.getSnapshot()
233
+ }), n = this.effectiveName, r = n !== t.name;
234
+ this.effectiveName = t.name, this.syncedNameAttribute = t.name ?? null, e !== this.syncedNameAttribute && (t.name === void 0 ? this.removeAttribute("name") : this.setAttribute("name", t.name)), this.contextDisabled = !!(this.formContext?.getSnapshot().disabled || this.itemContext?.getSnapshot().disabled || this.groupContext?.getSnapshot().disabled), this.contextRequired = t.required, this.configurationApplied(), this.syncFieldAccessibility(), this.innerBlockChange(t.innerBlock), this.applyDisabled(), this.syncNativeValue(), r && this.formContext?.fieldNameChanged?.(this.contextField, t.name, n);
83
235
  }
84
236
  isDisabled() {
85
237
  return this._disabled;
86
238
  }
87
239
  get disabled() {
88
- return this._disabled;
240
+ return this.ownDisabled;
89
241
  }
90
242
  set disabled(e) {
91
- this.setDisabled(e);
243
+ this.setDisabled(!!e);
92
244
  }
93
245
  setDisabled(e) {
94
- this._disabled = e, this.disabledChange();
246
+ this.ownDisabled = !!e, this.reflectingDisabled = !0;
247
+ try {
248
+ this.ownDisabled ? this.getAttribute("disabled") !== "" && this.setAttribute("disabled", "") : this.hasAttribute("disabled") && this.removeAttribute("disabled");
249
+ } finally {
250
+ this.reflectingDisabled = !1;
251
+ }
252
+ this.applyDisabled();
253
+ }
254
+ applyDisabled() {
255
+ this._disabled = this.ownDisabled || this.nativeDisabled || this.contextDisabled, this.rendered && !this.connecting && this.disabledChange(), this.syncNativeValue();
95
256
  }
96
257
  getName() {
97
258
  return this.name;
98
259
  }
260
+ configurationApplied() {}
99
261
  disabledChange() {}
100
262
  innerBlockChange(e) {}
101
- validResult(e) {}
102
- formInject = (e, t, n) => {
103
- this.formContext = e, this.formErrors = t, this.resetCtx = n;
104
- };
105
- formItemInject = (e) => {
106
- this.formItemContext = e;
263
+ validResult(e) {
264
+ this.displayedValidityMessage = e, this.syncFieldAccessibility();
265
+ }
266
+ get formItemControl() {
267
+ let e = this.root?.querySelectorAll(n);
268
+ return e?.length === 1 ? e[0] : void 0;
269
+ }
270
+ setFormItemPresentation(e, t, n, r) {
271
+ if (t === void 0 && n === void 0 && r === void 0) {
272
+ if (this.itemPresentation?.owner !== e) return;
273
+ this.itemPresentation = void 0;
274
+ } else {
275
+ let i = this.itemPresentation;
276
+ if (i?.owner === e && i.label === t && i.error === n && i.groupError === r) return;
277
+ this.itemPresentation = {
278
+ owner: e,
279
+ label: t,
280
+ error: n,
281
+ groupError: r
282
+ };
283
+ }
284
+ this.syncFieldAccessibility();
285
+ }
286
+ get fallbackAccessibleName() {}
287
+ syncFieldAccessibility = () => {
288
+ if (!this.isConnected || !this.rendered) return;
289
+ let e = this.formItemControl;
290
+ e !== this.accessibilityControl && (this.fieldAccessibility?.clear(this.root), this.accessibilityControl = e, this.fieldAccessibility = e && new t(e));
291
+ let n = this.fieldAccessibility;
292
+ if (!e || !n) return;
293
+ let a = r(this, "aria-labelledby"), o = Array.from(this.labels ?? []), s = this.getAttribute("aria-label"), c = (a.length ? i(a) : s) ?? (i(o) || n.authoredValue("aria-label") || i(r(e, "aria-labelledby")) || i(e.labels ?? []) || this.getAttribute("label") || this.fallbackAccessibleName || this.itemPresentation?.label);
294
+ n.attribute("aria-label", c || void 0), n.attribute("aria-required", String(this.contextRequired));
295
+ let l = r(this, "aria-describedby"), u = this.itemPresentation?.error ?? this.displayedValidityMessage, d = !!(u || this.displayedValidityMessage), f = u === this.itemPresentation?.groupError ? void 0 : u, p = Array.from(new Set([i(l), f].filter(Boolean))).join(" ");
296
+ n.attribute("aria-invalid", d ? "true" : this.getAttribute("aria-invalid") ?? "false"), n.describe(this.root, p), this.accessibilityObserver?.disconnect(), this.accessibilityObserver ??= new MutationObserver(this.syncFieldAccessibility), this.accessibilityObserver.observe(this.parentElement ?? this, {
297
+ childList: !0,
298
+ subtree: !0,
299
+ characterData: !0,
300
+ attributes: !0,
301
+ attributeFilter: [
302
+ "for",
303
+ "id",
304
+ "label",
305
+ "slot",
306
+ "aria-hidden",
307
+ "hidden"
308
+ ]
309
+ });
310
+ for (let e of [
311
+ ...a,
312
+ ...o,
313
+ ...l
314
+ ]) this.accessibilityObserver.observe(e, {
315
+ childList: !0,
316
+ subtree: !0,
317
+ characterData: !0,
318
+ attributes: !0,
319
+ attributeFilter: [
320
+ "id",
321
+ "aria-hidden",
322
+ "hidden"
323
+ ]
324
+ });
107
325
  };
108
- pushValueChange() {
109
- this.name && this.emit("form-value-change", {
326
+ formAssociatedCallback(e) {
327
+ this.isConnected && this.bindContexts(), this.syncNativeValue();
328
+ }
329
+ formDisabledCallback(e) {
330
+ this.nativeDisabled = e, this.applyDisabled();
331
+ }
332
+ serializeFormValue() {
333
+ return String(this.getValue() ?? "");
334
+ }
335
+ get formStateRestorationEnabled() {
336
+ return !0;
337
+ }
338
+ get acceptsAutocompleteText() {
339
+ return !1;
340
+ }
341
+ serializeFormState() {
342
+ return this.formStateRestorationEnabled ? JSON.stringify({
343
+ version: 1,
344
+ value: this.getValue() ?? ""
345
+ }) : null;
346
+ }
347
+ syncNativeValue() {
348
+ if (!this.internals || !this.nativeValueEnabled) return;
349
+ this.syncAutocomplete();
350
+ let e = this.isDisabled() ? null : this.serializeFormValue();
351
+ this.internals.setFormValue(e ?? new FormData(), this.serializeFormState());
352
+ let t = this.root?.querySelector("input,textarea,select");
353
+ t && (t.disabled = this.isDisabled(), "readOnly" in t && (t.readOnly = o(this.getAttribute("readonly")) ?? !1)), this.syncNativeValidity();
354
+ }
355
+ syncAutocomplete() {
356
+ let e = this.getAttribute("autocomplete") ?? this.formContext?.getSnapshot().autocomplete;
357
+ for (let t of this.root?.querySelectorAll("input,textarea,select") ?? []) e === void 0 ? t.removeAttribute("autocomplete") : t.getAttribute("autocomplete") !== e && t.setAttribute("autocomplete", e);
358
+ }
359
+ formResetCallback() {
360
+ this.applyingFormReset = !0;
361
+ try {
362
+ this.reset();
363
+ } finally {
364
+ this.applyingFormReset = !1;
365
+ }
366
+ }
367
+ formStateRestoreCallback(e, t) {
368
+ if (typeof e != "string" || t !== "autocomplete" && !this.formStateRestorationEnabled) return;
369
+ let n;
370
+ try {
371
+ let r = JSON.parse(e);
372
+ if (r?.version === 1 && Object.hasOwn(r, "value")) n = r.value;
373
+ else if (t === "autocomplete" && this.acceptsAutocompleteText) n = e;
374
+ else return;
375
+ } catch {
376
+ if (t !== "autocomplete" || !this.acceptsAutocompleteText) return;
377
+ n = e;
378
+ }
379
+ try {
380
+ this.value = n, this.manualValidity = {}, this.manualMessage = "", this.validResult(), this.formContext?.fieldValidityCleared?.(this.contextField), this.syncNativeValue();
381
+ } catch {}
382
+ }
383
+ get nativeBadInput() {
384
+ return !1;
385
+ }
386
+ get nativeValueMissing() {}
387
+ get nativeSubmissionError() {}
388
+ get nativeConstraintValues() {
389
+ return [this.getValue()];
390
+ }
391
+ syncNativeValidity(e) {
392
+ if (!this.internals || !this.ownerDocument) return;
393
+ let t = this.root?.querySelector("input,textarea,select,button,[tabindex]") ?? void 0, n = {}, r = "", i = o(this.getAttribute("readonly")) ?? !1, s = !this.isDisabled() && !i && !this.grouped;
394
+ if (s) {
395
+ let e = this.ownerDocument.createElement("input"), i = this.getAttribute("type") ?? (t instanceof HTMLInputElement ? t.type : "text");
396
+ e.type = this.constructor.baseName === "input-number" ? "number" : [
397
+ "checkbox",
398
+ "radio",
399
+ "file",
400
+ "hidden",
401
+ "submit",
402
+ "button",
403
+ "reset"
404
+ ].includes(i) ? "text" : i;
405
+ for (let t of [
406
+ "pattern",
407
+ "min",
408
+ "max",
409
+ "step",
410
+ "minlength",
411
+ "maxlength"
412
+ ]) {
413
+ let n = this.getAttribute(t);
414
+ n !== null && e.setAttribute(t, n);
415
+ }
416
+ for (let t of this.nativeConstraintValues) {
417
+ e.value = Array.isArray(t) ? t.join(",") : String(t ?? ""), e.required = this.contextRequired;
418
+ for (let t of [
419
+ "valueMissing",
420
+ "typeMismatch",
421
+ "patternMismatch",
422
+ "rangeUnderflow",
423
+ "rangeOverflow",
424
+ "stepMismatch",
425
+ "badInput"
426
+ ]) e.validity[t] && (n[t] = !0);
427
+ this.contextRequired && (t === !1 || Array.isArray(t) && !t.length) && (n.valueMissing = !0), e.required && this.nativeValueMissing !== void 0 && (this.nativeValueMissing ? n.valueMissing = !0 : delete n.valueMissing);
428
+ let i = Number(this.getAttribute("minlength")), a = Number(this.getAttribute("maxlength"));
429
+ [
430
+ "text",
431
+ "search",
432
+ "url",
433
+ "tel",
434
+ "email",
435
+ "password"
436
+ ].includes(e.type) && e.value && this.hasAttribute("minlength") && i >= 0 && e.value.length < i && (n.tooShort = !0), [
437
+ "text",
438
+ "search",
439
+ "url",
440
+ "tel",
441
+ "email",
442
+ "password"
443
+ ].includes(e.type) && this.hasAttribute("maxlength") && a >= 0 && e.value.length > a && (n.tooLong = !0), r = e.validationMessage || (n.tooShort ? "输入长度不足" : n.tooLong ? "输入长度超出限制" : "");
444
+ }
445
+ this.nativeBadInput && (n.badInput = !0, r = "请输入有效值");
446
+ let a = this.nativeSubmissionError;
447
+ a && (n.customError = !0, r = a);
448
+ for (let e of Object.keys(this.manualValidity)) this.manualValidity[e] && (n[e] = !0);
449
+ }
450
+ let c = s && Object.values(this.manualValidity).some(Boolean);
451
+ c && (r = this.manualMessage);
452
+ let l = Object.values(n).some(Boolean) ? r || "请检查字段值" : void 0, u = s ? this.businessMessage : void 0;
453
+ u && (n.customError = !0);
454
+ let d = (c ? l : u) ?? l;
455
+ this.internals.setValidity(n, d ?? "", e ?? t);
456
+ let f = {
457
+ valid: this.internals.validity.valid,
458
+ message: d,
459
+ flags: n,
460
+ constraintMessage: l,
461
+ willValidate: this.internals.willValidate
462
+ }, p = this.nativeValidity;
463
+ this.nativeValidity = f, this.isConnected && this.rendered && (p && p.valid === f.valid && p.message === f.message && p.constraintMessage === f.constraintMessage && p.willValidate === f.willValidate && Object.keys(p.flags).length === Object.keys(n).length && Object.keys(n).every((e) => p.flags[e]) || this.dispatchEvent(new CustomEvent(a.nativeValidity, {
110
464
  bubbles: !0,
111
- composed: !0,
112
465
  detail: {
113
- name: this.name,
114
- value: this._value,
115
- valid: !this._isReset
466
+ ...f,
467
+ flags: { ...n },
468
+ duringReset: this.applyingFormReset
116
469
  }
117
- }), this._isReset = !1;
470
+ })));
118
471
  }
119
472
  reset() {
120
- this._isReset = !0, this.value = this._resetValue || "";
473
+ this.dirtyValue = !1, this.applyDefaultValue(), this.applyBusinessValidity(), this.validResult(), this.formContext?.fieldValidityCleared?.(this.contextField), this.syncNativeValue();
121
474
  }
122
475
  };
123
- //#endregion
124
- export { a as default };
476
+ export { l as default };
@@ -1,13 +1,14 @@
1
- import type { Signal } from "../utils/signal_types";
2
1
  import type { RuleType } from "utilane";
3
- import ContextProvide from "../utils/context_provide";
4
- import type { FormItemSignal } from "./types";
2
+ import BaseComponent from "../base";
5
3
  type FormItemState = {
6
4
  /** 标签文本 */
7
5
  label?: string;
8
- labelPosition?: "left" | "right" | "top";
6
+ labelPosition: "left" | "right" | "top";
7
+ /** 显式错误;undefined 表示使用校验错误,空字符串表示显式隐藏。 */
9
8
  error?: string;
10
- required: boolean;
9
+ innerBlock?: boolean;
10
+ required?: boolean;
11
+ disabled?: boolean;
11
12
  /** 内置验证规则 */
12
13
  verify?: string;
13
14
  /** 正则表达式 */
@@ -18,15 +19,29 @@ type FormItemState = {
18
19
  labelWidth?: string;
19
20
  labelHeight?: string;
20
21
  };
21
- export default class FormItem extends ContextProvide<FormItemSignal, FormItemState> {
22
+ export default class FormItem extends BaseComponent<FormItemState> {
22
23
  static baseName: string;
23
- formErrors?: Signal<Record<string, string>>;
24
- private _errorSignalStop?;
24
+ private readonly itemContext;
25
+ private disposeContext?;
26
+ private formContext?;
27
+ private unregisterForm?;
28
+ private programRules?;
29
+ private validationError?;
30
+ private accessibilityObserver?;
31
+ private accessibilityScheduled;
32
+ private readonly connectedFields;
33
+ private readonly nativePresentation;
34
+ private readonly itemProvider;
35
+ private readonly formField;
25
36
  constructor();
26
37
  static get observedAttributes(): string[];
27
- protected attributeChanged(name: string, oldValue: string, newValue: string): void;
38
+ protected attributeChanged(name: string, _oldValue: string, newValue: string | null): void;
39
+ private updateContext;
40
+ /** @internal 处理先于 Form 升级的表单项。 */
41
+ refreshFormContext: () => void;
42
+ private receiveValidity;
28
43
  protected updateDOM(changedProps: Set<string>): void;
29
- connectedCallback(): void;
44
+ afterInit(): void;
30
45
  beforeDestroy(): void;
31
46
  setRules(rules: {
32
47
  required?: boolean;
@@ -35,13 +50,22 @@ export default class FormItem extends ContextProvide<FormItemSignal, FormItemSta
35
50
  }): void;
36
51
  render_v2(): {
37
52
  template: DocumentFragment;
38
- style: string[];
53
+ styleSheets: CSSStyleSheet[];
39
54
  };
55
+ private get errorMessage();
56
+ private updateLabelPosition;
40
57
  render(): DocumentFragment;
41
58
  private _updateRequired;
42
59
  private _parseSchema;
43
60
  private _updateError;
44
61
  private _updateLabel;
62
+ private createLabel;
63
+ private setLabelText;
64
+ private itemFields;
65
+ private focusFieldFromLabel;
66
+ private scheduleAccessibility;
67
+ private clearFieldPresentation;
68
+ private updateAccessibility;
45
69
  private _updateRules;
46
70
  }
47
71
  export {};