litos-ui 0.23.0 → 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 (312) hide show
  1. package/README.md +2 -2
  2. package/README.zh-CN.md +2 -2
  3. package/lib/base.d.ts +3 -2
  4. package/lib/base.js +11 -8
  5. package/lib/button/index.d.ts +21 -5
  6. package/lib/button/index.js +115 -62
  7. package/lib/button/index.less_inline.js +2 -3
  8. package/lib/button/style.js +1 -2
  9. package/lib/calendar/index.d.ts +1 -0
  10. package/lib/calendar/index.js +19 -17
  11. package/lib/calendar/index.less_inline.js +1 -2
  12. package/lib/calendar/langs.js +21 -11
  13. package/lib/card/index.js +8 -9
  14. package/lib/card/index.less_inline.js +1 -2
  15. package/lib/carousel/index.js +10 -11
  16. package/lib/carousel/index.less_inline.js +1 -2
  17. package/lib/carousel/item.js +1 -2
  18. package/lib/carousel/item.less_inline.js +1 -2
  19. package/lib/carousel/timer.js +1 -2
  20. package/lib/check/check.d.ts +40 -8
  21. package/lib/check/check.js +200 -65
  22. package/lib/check/check.less_inline.js +2 -3
  23. package/lib/check/checkbox.js +2 -3
  24. package/lib/check/checkbox.less_inline.js +2 -3
  25. package/lib/check/checkbox_group.js +1 -2
  26. package/lib/check/index.d.ts +28 -8
  27. package/lib/check/index.js +151 -46
  28. package/lib/check/index.less_inline.js +1 -2
  29. package/lib/check/radio.js +2 -3
  30. package/lib/check/radio.less_inline.js +1 -2
  31. package/lib/check/radio_group.js +2 -3
  32. package/lib/collapse/index.d.ts +12 -4
  33. package/lib/collapse/index.js +80 -46
  34. package/lib/collapse/index.less_inline.js +2 -3
  35. package/lib/collapse/item.d.ts +35 -9
  36. package/lib/collapse/item.js +219 -57
  37. package/lib/collapse/item.less_inline.js +2 -3
  38. package/lib/collapse/types.d.ts +17 -3
  39. package/lib/color_picker/index.d.ts +4 -2
  40. package/lib/color_picker/index.js +26 -17
  41. package/lib/color_picker/index.less_inline.js +1 -2
  42. package/lib/date_picker/index.d.ts +5 -1
  43. package/lib/date_picker/index.js +39 -23
  44. package/lib/date_picker/index.less_inline.js +1 -2
  45. package/lib/date_picker_ori/index.d.ts +7 -2
  46. package/lib/date_picker_ori/index.js +123 -47
  47. package/lib/date_picker_ori/index.less_inline.js +1 -2
  48. package/lib/description_panel/index.js +2 -10
  49. package/lib/description_panel/index.less_inline.js +1 -2
  50. package/lib/dialog/dialog_box.js +28 -29
  51. package/lib/dialog/dialog_container.css_inline.js +1 -2
  52. package/lib/dialog/dialog_container.js +13 -14
  53. package/lib/dialog/dialog_container_style.js +1 -2
  54. package/lib/dialog/index.d.ts +2 -0
  55. package/lib/dialog/index.js +11 -9
  56. package/lib/dropdown/index.d.ts +39 -0
  57. package/lib/dropdown/index.js +98 -0
  58. package/lib/entries/base.js +1 -2
  59. package/lib/entries/button.js +5 -6
  60. package/lib/entries/calendar.js +5 -6
  61. package/lib/entries/card.js +5 -6
  62. package/lib/entries/carousel-item.js +5 -6
  63. package/lib/entries/carousel.js +5 -6
  64. package/lib/entries/checkbox-group.js +5 -6
  65. package/lib/entries/checkbox.js +5 -6
  66. package/lib/entries/collapse-item.d.ts +0 -1
  67. package/lib/entries/collapse-item.js +6 -6
  68. package/lib/entries/collapse.d.ts +0 -1
  69. package/lib/entries/collapse.js +11 -6
  70. package/lib/entries/color-picker.js +5 -6
  71. package/lib/entries/date-picker-ori.js +5 -6
  72. package/lib/entries/date-picker.js +5 -6
  73. package/lib/entries/description-panel.js +5 -6
  74. package/lib/entries/dialog-box.js +1 -2
  75. package/lib/entries/dialog-container.js +5 -6
  76. package/lib/entries/dialog.js +1 -2
  77. package/lib/entries/dropdown.d.ts +2 -0
  78. package/lib/entries/dropdown.js +1 -0
  79. package/lib/entries/form-item.js +5 -6
  80. package/lib/entries/form.js +5 -6
  81. package/lib/entries/icon-arrow-down.js +5 -6
  82. package/lib/entries/icon-arrow-left.js +5 -6
  83. package/lib/entries/icon-arrow-right.js +5 -6
  84. package/lib/entries/icon-arrow-up.js +5 -6
  85. package/lib/entries/icon-base.js +5 -6
  86. package/lib/entries/icon-calendar.js +5 -6
  87. package/lib/entries/icon-caret-bottom.js +5 -6
  88. package/lib/entries/icon-caret-top.js +5 -6
  89. package/lib/entries/icon-close-filled.js +5 -6
  90. package/lib/entries/icon-close.js +5 -6
  91. package/lib/entries/icon-copy.js +5 -6
  92. package/lib/entries/icon-d-arrow-left.js +5 -6
  93. package/lib/entries/icon-d-arrow-right.js +5 -6
  94. package/lib/entries/icon-delete.js +5 -6
  95. package/lib/entries/icon-eye-outline.js +5 -6
  96. package/lib/entries/icon-font-icon.js +5 -6
  97. package/lib/entries/icon-info.js +5 -6
  98. package/lib/entries/icon-loading.js +5 -6
  99. package/lib/entries/icon-minus.js +5 -6
  100. package/lib/entries/icon-moon.js +5 -6
  101. package/lib/entries/icon-more.js +5 -6
  102. package/lib/entries/icon-picture.js +5 -6
  103. package/lib/entries/icon-plus.js +5 -6
  104. package/lib/entries/icon-reduction.js +5 -6
  105. package/lib/entries/icon-refresh-left.js +5 -6
  106. package/lib/entries/icon-refresh-right.js +5 -6
  107. package/lib/entries/icon-refresh.js +5 -6
  108. package/lib/entries/icon-search.js +5 -6
  109. package/lib/entries/icon-select.js +5 -6
  110. package/lib/entries/icon-sort.js +5 -6
  111. package/lib/entries/icon-success.js +5 -6
  112. package/lib/entries/icon-sun.js +5 -6
  113. package/lib/entries/icon-theme-default.js +5 -6
  114. package/lib/entries/icon-warn.js +5 -6
  115. package/lib/entries/icon-zoom-in.js +5 -6
  116. package/lib/entries/icon-zoom-out.js +5 -6
  117. package/lib/entries/image-preview.js +5 -6
  118. package/lib/entries/image.js +5 -6
  119. package/lib/entries/input-number.js +5 -6
  120. package/lib/entries/input.js +5 -6
  121. package/lib/entries/list.js +5 -6
  122. package/lib/entries/loading.js +1 -2
  123. package/lib/entries/mask.js +5 -6
  124. package/lib/entries/md-input.js +5 -6
  125. package/lib/entries/menu.js +5 -6
  126. package/lib/entries/message.js +1 -2
  127. package/lib/entries/modal-box.js +1 -2
  128. package/lib/entries/modal.js +5 -6
  129. package/lib/entries/notification-box.js +1 -2
  130. package/lib/entries/notification.js +1 -2
  131. package/lib/entries/page-header.js +5 -6
  132. package/lib/entries/pagination.js +5 -6
  133. package/lib/entries/polygon.js +5 -6
  134. package/lib/entries/popconfirm.js +1 -2
  135. package/lib/entries/popover.js +1 -2
  136. package/lib/entries/qrcode.js +5 -6
  137. package/lib/entries/radio-group.js +5 -6
  138. package/lib/entries/radio.js +5 -6
  139. package/lib/entries/select-ori.js +5 -6
  140. package/lib/entries/select.js +5 -6
  141. package/lib/entries/space.js +5 -6
  142. package/lib/entries/switch.js +5 -6
  143. package/lib/entries/tabbar-item.js +5 -6
  144. package/lib/entries/tabbar.js +5 -6
  145. package/lib/entries/table.js +5 -6
  146. package/lib/entries/tabs.js +1 -2
  147. package/lib/entries/tag.js +5 -6
  148. package/lib/entries/theme-color.js +5 -6
  149. package/lib/entries/theme.js +5 -6
  150. package/lib/entries/transition.js +1 -2
  151. package/lib/entries/upload.js +5 -6
  152. package/lib/entries/utils.js +1 -2
  153. package/lib/form/accessibility.d.ts +15 -0
  154. package/lib/form/accessibility.js +56 -0
  155. package/lib/form/autocomplete.d.ts +21 -0
  156. package/lib/form/autocomplete.js +59 -0
  157. package/lib/form/context.d.ts +157 -0
  158. package/lib/form/context.js +88 -0
  159. package/lib/form/form_inner.d.ts +99 -24
  160. package/lib/form/form_inner.js +424 -72
  161. package/lib/form/form_item.d.ts +35 -11
  162. package/lib/form/form_item.js +210 -78
  163. package/lib/form/form_item.less_inline.js +2 -3
  164. package/lib/form/form_item_style.d.ts +3 -0
  165. package/lib/form/form_item_style.js +7 -0
  166. package/lib/form/index.d.ts +69 -15
  167. package/lib/form/index.js +501 -101
  168. package/lib/form/index.less_inline.js +1 -2
  169. package/lib/form/owner.d.ts +78 -0
  170. package/lib/form/owner.js +138 -0
  171. package/lib/form/style.d.ts +3 -0
  172. package/lib/form/style.js +7 -0
  173. package/lib/icon/arrow_down.js +1 -2
  174. package/lib/icon/arrow_left.js +1 -2
  175. package/lib/icon/arrow_right.js +1 -2
  176. package/lib/icon/arrow_up.js +1 -2
  177. package/lib/icon/base.js +1 -2
  178. package/lib/icon/calendar.js +1 -2
  179. package/lib/icon/caret_bottom.js +1 -2
  180. package/lib/icon/caret_top.js +1 -2
  181. package/lib/icon/close.js +1 -2
  182. package/lib/icon/close_filled.js +1 -2
  183. package/lib/icon/copy.js +1 -2
  184. package/lib/icon/d_arrow_left.js +1 -2
  185. package/lib/icon/d_arrow_right.js +1 -2
  186. package/lib/icon/delete.js +1 -2
  187. package/lib/icon/eye_outline.js +1 -2
  188. package/lib/icon/font_icon.js +1 -2
  189. package/lib/icon/icon_style.js +1 -2
  190. package/lib/icon/index.less_inline.js +1 -2
  191. package/lib/icon/info.js +1 -2
  192. package/lib/icon/loading.js +1 -2
  193. package/lib/icon/minus.js +1 -2
  194. package/lib/icon/moon.js +1 -2
  195. package/lib/icon/more.js +1 -2
  196. package/lib/icon/picture.js +1 -2
  197. package/lib/icon/plus.js +1 -2
  198. package/lib/icon/reduction.js +1 -2
  199. package/lib/icon/refresh.js +1 -2
  200. package/lib/icon/refresh_left.js +1 -2
  201. package/lib/icon/refresh_right.js +1 -2
  202. package/lib/icon/search.js +1 -2
  203. package/lib/icon/select.js +1 -2
  204. package/lib/icon/sort.js +1 -2
  205. package/lib/icon/success.js +1 -2
  206. package/lib/icon/sun.js +1 -2
  207. package/lib/icon/theme_default.js +1 -2
  208. package/lib/icon/warn.js +1 -2
  209. package/lib/icon/zoom_in.js +1 -2
  210. package/lib/icon/zoom_out.js +1 -2
  211. package/lib/image/image_preview.js +1 -2
  212. package/lib/image/image_preview.less_inline.js +1 -2
  213. package/lib/image/index.js +1 -2
  214. package/lib/image/index.less_inline.js +1 -2
  215. package/lib/index.d.ts +2 -1
  216. package/lib/index.js +88 -87
  217. package/lib/input/index.d.ts +18 -1
  218. package/lib/input/index.js +151 -48
  219. package/lib/input/index.less_inline.js +2 -3
  220. package/lib/input/input_inner.less_inline.js +1 -2
  221. package/lib/input/style.d.ts +3 -0
  222. package/lib/input/style.js +7 -0
  223. package/lib/input_number/index.d.ts +7 -0
  224. package/lib/input_number/index.js +70 -48
  225. package/lib/input_number/index.less_inline.js +1 -2
  226. package/lib/input_number/style.js +1 -2
  227. package/lib/list/index.js +4 -5
  228. package/lib/list/index.less_inline.js +1 -2
  229. package/lib/loading/index.js +1 -2
  230. package/lib/mask/index.js +2 -7
  231. package/lib/mask/index.less_inline.js +1 -2
  232. package/lib/md_input/index.d.ts +11 -2
  233. package/lib/md_input/index.js +63 -27
  234. package/lib/md_input/index.less_inline.js +2 -3
  235. package/lib/menu/index.js +2 -7
  236. package/lib/menu/index.less_inline.js +1 -2
  237. package/lib/message/index.js +1 -2
  238. package/lib/modal/index.js +15 -16
  239. package/lib/modal/index.less_inline.js +1 -2
  240. package/lib/modal/modal_box.js +24 -25
  241. package/lib/notification/index.js +15 -29
  242. package/lib/notification/index.less_inline.js +1 -2
  243. package/lib/notification/notification_box.js +2 -3
  244. package/lib/notification/placement.js +1 -2
  245. package/lib/notification/style.js +1 -2
  246. package/lib/page_header/index.js +1 -2
  247. package/lib/page_header/index.less_inline.js +1 -2
  248. package/lib/pagination/index.js +26 -25
  249. package/lib/pagination/index.less_inline.js +2 -3
  250. package/lib/polygon/index.js +1 -2
  251. package/lib/polygon/index.less_inline.js +1 -2
  252. package/lib/qrcode/index.js +1 -2
  253. package/lib/qrcode/index.less_inline.js +1 -2
  254. package/lib/select/index.d.ts +21 -2
  255. package/lib/select/index.js +138 -77
  256. package/lib/select/index.less_inline.js +1 -2
  257. package/lib/select_ori/index.d.ts +9 -1
  258. package/lib/select_ori/index.js +36 -24
  259. package/lib/select_ori/index.less_inline.js +1 -2
  260. package/lib/space/index.js +1 -2
  261. package/lib/space/index.less_inline.js +1 -2
  262. package/lib/styles/animation/index.css_inline.js +1 -2
  263. package/lib/styles/animation/index.js +1 -2
  264. package/lib/styles/mask/index.css_inline.js +1 -2
  265. package/lib/styles/mask/index.js +1 -2
  266. package/lib/switch/index.d.ts +6 -0
  267. package/lib/switch/index.js +31 -16
  268. package/lib/switch/index.less_inline.js +1 -2
  269. package/lib/tabbar/index.js +1 -2
  270. package/lib/tabbar/index.less_inline.js +1 -2
  271. package/lib/tabbar/item.js +1 -2
  272. package/lib/tabbar/item.less_inline.js +1 -2
  273. package/lib/table/index.d.ts +2 -0
  274. package/lib/table/index.js +12 -4
  275. package/lib/table/index.less_inline.js +1 -2
  276. package/lib/tabs/index.js +1 -2
  277. package/lib/tag/index.d.ts +11 -3
  278. package/lib/tag/index.js +25 -24
  279. package/lib/tag/index.less_inline.js +2 -3
  280. package/lib/theme/appearance.d.ts +5 -0
  281. package/lib/theme/appearance.js +34 -0
  282. package/lib/theme/index.js +83 -39
  283. package/lib/theme/index.less_inline.js +1 -2
  284. package/lib/theme/theme_color.js +1 -2
  285. package/lib/upload/index.js +28 -41
  286. package/lib/upload/index.less_inline.js +2 -3
  287. package/lib/upload/style.js +1 -2
  288. package/lib/utils/clickoutside.js +1 -2
  289. package/lib/utils/event.js +1 -2
  290. package/lib/utils/index.d.ts +27 -5
  291. package/lib/utils/index.js +43 -22
  292. package/lib/utils/popover.js +7 -16
  293. package/lib/utils/transition.js +1 -2
  294. package/package.json +16 -13
  295. package/styles/dark.css +10 -2
  296. package/styles/dropdown.css +46 -0
  297. package/styles/reset.css +0 -1
  298. package/styles/select.css +5 -0
  299. package/styles/themes/apple.css +47 -0
  300. package/styles/{theme-coral.css → themes/coral.css} +5 -3
  301. package/styles/themes/deep-sea-blue.css +12 -0
  302. package/styles/themes/gamboge.css +15 -0
  303. package/styles/{theme-jade.css → themes/jade.css} +5 -3
  304. package/styles/themes/lotus-seed.css +12 -0
  305. package/styles/{theme-tangerine.css → themes/tangerine.css} +5 -3
  306. package/styles/themes.css +8 -0
  307. package/styles/vars.css +8 -2
  308. package/types/preact.d.ts +43 -0
  309. package/lib/form/types.d.ts +0 -7
  310. package/lib/utils/context_provide.d.ts +0 -10
  311. package/lib/utils/context_provide.js +0 -22
  312. package/lib/utils/signal_types.d.ts +0 -5
package/lib/form/index.js CHANGED
@@ -1,25 +1,267 @@
1
- import e from "../base.js";
2
- import { kebabToCamel as t, parseAttrValue as n, unitNumberStr as r } from "../utils/index.js";
3
- import i from "./index.less_inline.js";
4
- import { $one as a, formatClass as o, off as s, on as c } from "utilane/browser";
5
- import { Validator as l } from "utilane";
6
- import { signal as u } from "alien-signals";
7
- //#region src/components/form/index.ts
8
- var d = class extends e {
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
- _data;
12
- context;
13
- errors;
14
- resetCtx;
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
- }, this.validator = new l([]), this.context = u({ innerBlock: !1 }), this.errors = u({}), this.resetCtx = u(0);
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(e, i, a) {
36
- switch (e) {
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
- let i = n(a, !1, e);
42
- this.context({ innerBlock: i });
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[t(e)] = r(a);
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 o = n(a, !1, e);
50
- this._state[t(e)] = o;
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 = a("form", this.root);
56
- e && (e.className = o([
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
- c(this, "form-context-request", this._provide), super.connectedCallback();
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
- c(this, "form-rule-change", this.ruleChange), c(this, "form-value-change", this._valueChange), c(this, "form-action", this._formAction);
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.validator = void 0, s(this, "form-rule-change", this.ruleChange), s(this, "form-value-change", this._valueChange), s(this, "form-context-request", this._provide), s(this, "form-action", this._formAction), super.disconnectedCallback();
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
- style: [i],
335
+ styleSheets: [r],
76
336
  template: this.render()
77
337
  };
78
338
  }
79
339
  render() {
80
- let e = o([
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), `<form class="${e}"><slot></slot></form>`;
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.stopPropagation(), this.validator.addSchema(e.detail);
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.setSchemas(e);
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.errors(e);
392
+ } }) : this.setErrors(e);
129
393
  }
130
- async validateField(e) {
131
- let t = !1, n = {};
132
- if (this._data != null) {
133
- if (Array.isArray(e)) for (let r = 0, i = e.length; r < i; r++) {
134
- let i = e[r];
135
- try {
136
- n[i] = void 0;
137
- } catch (e) {
138
- n[i] = e.detail, t = !0;
139
- break;
140
- }
141
- }
142
- else try {
143
- n[e] = void 0;
144
- } catch (r) {
145
- n[e] = r.detail, t = !0;
146
- }
147
- if (t) {
148
- let e = /* @__PURE__ */ Error("validate field error");
149
- return e.detail = n, Promise.reject(e);
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
- return Promise.resolve();
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.errors({});
503
+ this.clearPresentation();
156
504
  }
157
505
  reset() {
158
- this.clearValidate();
159
- let e = this.resetCtx();
160
- this.resetCtx(e >= 100 ? 1 : e + 1);
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.emit("validate-error", { detail: {
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
- try {
172
- return this.validator.validate(this._data || {}), Promise.resolve({
173
- result: !0,
174
- errors: {}
175
- });
176
- } catch (e) {
177
- return Promise.resolve({
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
- return { ...this._data };
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.errors(e);
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
- //#endregion
191
- export { d as default };
591
+ export { k as default };