@iswangh/element-plus-kit-form 0.1.2 → 0.1.4

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 (42) hide show
  1. package/README.md +137 -4
  2. package/dist/FormAction.vue.d.ts +27 -1
  3. package/dist/FormAction.vue.d.ts.map +1 -1
  4. package/dist/FormItem.vue.d.ts.map +1 -1
  5. package/dist/composables/index.d.ts +3 -0
  6. package/dist/composables/index.d.ts.map +1 -0
  7. package/dist/composables/useAutoExpandOnHover.d.ts +15 -0
  8. package/dist/composables/useAutoExpandOnHover.d.ts.map +1 -0
  9. package/dist/composables/useChangeEventState.d.ts +35 -0
  10. package/dist/composables/useChangeEventState.d.ts.map +1 -0
  11. package/dist/config/action.d.ts +29 -0
  12. package/dist/config/action.d.ts.map +1 -0
  13. package/dist/config/component.d.ts +38 -0
  14. package/dist/config/component.d.ts.map +1 -0
  15. package/dist/config/form.d.ts +6 -0
  16. package/dist/config/form.d.ts.map +1 -0
  17. package/dist/config/index.d.ts +4 -64
  18. package/dist/config/index.d.ts.map +1 -1
  19. package/dist/config/scroll.d.ts +7 -0
  20. package/dist/config/scroll.d.ts.map +1 -0
  21. package/dist/index.d.ts +1 -1
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +630 -227
  24. package/dist/style.css +1 -1
  25. package/dist/types/action.d.ts +74 -0
  26. package/dist/types/common.d.ts +9 -0
  27. package/dist/types/el.d.ts +43 -0
  28. package/dist/types/form-item.d.ts +109 -0
  29. package/dist/types/index.d.ts +5 -125
  30. package/dist/types/index.d.ts.map +1 -1
  31. package/dist/types/options.d.ts +89 -0
  32. package/dist/utils/action.d.ts +10 -0
  33. package/dist/utils/action.d.ts.map +1 -0
  34. package/dist/utils/debounce.d.ts +25 -0
  35. package/dist/utils/debounce.d.ts.map +1 -0
  36. package/dist/utils/index.d.ts +5 -0
  37. package/dist/utils/index.d.ts.map +1 -0
  38. package/dist/utils/options.d.ts +21 -0
  39. package/dist/utils/options.d.ts.map +1 -0
  40. package/dist/utils/value.d.ts +27 -0
  41. package/dist/utils/value.d.ts.map +1 -0
  42. package/package.json +9 -12
package/dist/index.js CHANGED
@@ -1,71 +1,189 @@
1
- import { defineComponent as k, createElementBlock as M, openBlock as u, createElementVNode as x, computed as i, withDirectives as _, createCommentVNode as W, createBlock as h, unref as w, withCtx as C, Fragment as $, renderList as P, mergeProps as I, createTextVNode as G, toDisplayString as H, resolveDynamicComponent as b, vShow as R, mergeModels as O, useModel as K, normalizeProps as U, guardReactiveProps as j, createSlots as V, renderSlot as X, useAttrs as q, useSlots as Y, ref as J, withModifiers as Q, createVNode as B } from "vue";
2
- import { checkCondition as N } from "@iswangh/element-plus-kit-core";
3
- import { ElTreeSelect as Z, ElTransfer as ee, ElTimeSelect as te, ElTimePicker as oe, ElSwitch as ne, ElSlider as le, ElSelectV2 as re, ElSelect as ae, ElRate as se, ElRadioGroup as ie, ElMention as ce, ElInputTag as me, ElInputNumber as ue, ElInput as fe, ElDatePicker as de, ElDatePickerPanel as pe, ElColorPicker as ve, ElColorPickerPanel as he, ElCheckboxGroup as Ee, ElCascader as ge, ElAutocomplete as Ce, ElFormItem as L, ElButton as Ae, ElCol as Ie, ElRow as be, ElForm as ye } from "element-plus";
4
- var Se = /* @__PURE__ */ k({
1
+ import { onBeforeUnmount as ye, nextTick as q, defineComponent as L, createElementBlock as M, openBlock as v, createElementVNode as ae, computed as p, withDirectives as ne, createCommentVNode as Ae, createBlock as y, unref as S, withCtx as w, Fragment as $, renderSlot as ce, renderList as j, mergeProps as _, normalizeClass as we, createVNode as X, createTextVNode as Oe, toDisplayString as Se, resolveDynamicComponent as D, vShow as oe, mergeModels as J, useModel as fe, ref as Y, watch as Q, watchEffect as be, normalizeProps as me, guardReactiveProps as de, createSlots as le, useAttrs as Te, useSlots as ke, onMounted as Fe, withModifiers as Me, TransitionGroup as _e } from "vue";
2
+ import { checkCondition as Z } from "@iswangh/element-plus-kit-core";
3
+ import { ElTreeSelect as De, ElTransfer as Ve, ElTimeSelect as Be, ElTimePicker as Pe, ElSwitch as Re, ElSlider as Le, ElSelectV2 as Ne, ElSelect as Ue, ElRate as $e, ElRadioGroup as je, ElMention as ze, ElInputTag as He, ElInputNumber as Ge, ElInput as We, ElDatePicker as Ke, ElDatePickerPanel as Xe, ElColorPicker as qe, ElColorPickerPanel as Je, ElCheckboxGroup as Ye, ElCascader as Qe, ElAutocomplete as Ze, ElFormItem as pe, ElButton as et, ElIcon as tt, ElCol as nt, ElRow as ot, ElForm as rt } from "element-plus";
4
+ function at(e, s, t) {
5
+ let i = !1, r = null, g = null;
6
+ function x() {
7
+ r && (clearTimeout(r), r = null), g && (clearTimeout(g), g = null);
8
+ }
9
+ function k() {
10
+ !s.value || i || (r && clearTimeout(r), r = setTimeout(() => {
11
+ !e.value && !i && t(!0);
12
+ }, 500));
13
+ }
14
+ function E() {
15
+ r && (clearTimeout(r), r = null), g && clearTimeout(g), q(() => {
16
+ g = setTimeout(() => {
17
+ i = !1, g = null;
18
+ }, 100);
19
+ });
20
+ }
21
+ function I() {
22
+ s.value && (i = !0, x());
23
+ }
24
+ return ye(x), {
25
+ onMouseEnter: k,
26
+ onMouseLeave: E,
27
+ recordManualToggle: I
28
+ };
29
+ }
30
+ function lt() {
31
+ let e = !1, s = !1, t = null, i = !1;
32
+ return {
33
+ /** 是否正在清理 */
34
+ get isClearing() {
35
+ return e;
36
+ },
37
+ /** 是否用户交互 */
38
+ get isUserInteraction() {
39
+ return s;
40
+ },
41
+ /**
42
+ * 开始清理操作
43
+ * @param value - 清理前的值
44
+ */
45
+ startClearing(r) {
46
+ e = !0, t = r, i = !0;
47
+ },
48
+ /**
49
+ * 结束清理操作(在 nextTick 中调用)
50
+ */
51
+ endClearing() {
52
+ e = !1, t = null, i = !1;
53
+ },
54
+ /**
55
+ * 开始用户交互
56
+ */
57
+ startUserInteraction() {
58
+ s = !0;
59
+ },
60
+ /**
61
+ * 结束用户交互(在 nextTick 中调用)
62
+ */
63
+ endUserInteraction() {
64
+ s = !1;
65
+ },
66
+ /**
67
+ * 判断是否是清理操作
68
+ * @param oldValue - 旧值
69
+ * @param newValue - 新值
70
+ * @param isEmpty - 检查值是否为空的函数
71
+ */
72
+ isClearingOperation(r, g, x) {
73
+ return !!(e || i || !x(r) && x(g) && r === t);
74
+ }
75
+ };
76
+ }
77
+ var it = /* @__PURE__ */ L({
78
+ name: "ArrowDown",
79
+ __name: "arrow-down",
80
+ setup(e) {
81
+ return (s, t) => (v(), M("svg", {
82
+ xmlns: "http://www.w3.org/2000/svg",
83
+ viewBox: "0 0 1024 1024"
84
+ }, [
85
+ ae("path", {
86
+ fill: "currentColor",
87
+ d: "M831.872 340.864 512 652.672 192.128 340.864a30.59 30.59 0 0 0-42.752 0 29.12 29.12 0 0 0 0 41.6L489.664 714.24a32 32 0 0 0 44.672 0l340.288-331.712a29.12 29.12 0 0 0 0-41.728 30.59 30.59 0 0 0-42.752 0z"
88
+ })
89
+ ]));
90
+ }
91
+ }), st = it, ut = /* @__PURE__ */ L({
5
92
  name: "Refresh",
6
93
  __name: "refresh",
7
94
  setup(e) {
8
- return (o, n) => (u(), M("svg", {
95
+ return (s, t) => (v(), M("svg", {
9
96
  xmlns: "http://www.w3.org/2000/svg",
10
97
  viewBox: "0 0 1024 1024"
11
98
  }, [
12
- x("path", {
99
+ ae("path", {
13
100
  fill: "currentColor",
14
101
  d: "M771.776 794.88A384 384 0 0 1 128 512h64a320 320 0 0 0 555.712 216.448H654.72a32 32 0 1 1 0-64h149.056a32 32 0 0 1 32 32v148.928a32 32 0 1 1-64 0v-50.56zM276.288 295.616h92.992a32 32 0 0 1 0 64H220.16a32 32 0 0 1-32-32V178.56a32 32 0 0 1 64 0v50.56A384 384 0 0 1 896.128 512h-64a320 320 0 0 0-555.776-216.384z"
15
102
  })
16
103
  ]));
17
104
  }
18
- }), we = Se, ke = /* @__PURE__ */ k({
105
+ }), ct = ut, ft = /* @__PURE__ */ L({
19
106
  name: "Search",
20
107
  __name: "search",
21
108
  setup(e) {
22
- return (o, n) => (u(), M("svg", {
109
+ return (s, t) => (v(), M("svg", {
23
110
  xmlns: "http://www.w3.org/2000/svg",
24
111
  viewBox: "0 0 1024 1024"
25
112
  }, [
26
- x("path", {
113
+ ae("path", {
27
114
  fill: "currentColor",
28
115
  d: "m795.904 750.72 124.992 124.928a32 32 0 0 1-45.248 45.248L750.656 795.904a416 416 0 1 1 45.248-45.248zM480 832a352 352 0 1 0 0-704 352 352 0 0 0 0 704"
29
116
  })
30
117
  ]));
31
118
  }
32
- }), Fe = ke;
33
- const Pe = ["comp", "compAttrs", "vIf", "vShow"], Me = {
119
+ }), mt = ft;
120
+ const ve = {
121
+ behavior: "smooth",
122
+ // 平滑滚动
123
+ block: "center",
124
+ // 垂直居中,让错误项在视窗中间
125
+ inline: "nearest"
126
+ // 水平方向保持最近位置
127
+ }, dt = {
128
+ search: { label: "搜索", icon: mt, type: "primary" },
129
+ reset: { label: "重置", icon: ct },
130
+ submit: { label: "确认", type: "primary" },
131
+ cancel: { label: "取消" },
132
+ expand: { type: "text" }
133
+ }, pt = ve, vt = {
134
+ getDefaults(e, s) {
135
+ return {
136
+ ...this.buildActionAttrs(e),
137
+ ...s
138
+ };
139
+ },
140
+ generateActionButtons(e) {
141
+ return e ? ["search", "reset"] : ["submit", "cancel"];
142
+ },
143
+ buildActionAttrs(e) {
144
+ return {
145
+ buttons: this.generateActionButtons(e),
146
+ vIf: e,
147
+ autoExpandOnError: !0,
148
+ vShow: !0
149
+ };
150
+ }
151
+ }, gt = ["comp", "compAttrs", "vIf", "vShow"], ht = {
34
152
  custom: "div"
35
- }, Te = {
36
- autocomplete: Ce,
37
- cascader: ge,
38
- checkbox: Ee,
39
- "color-picker-panel": he,
40
- "color-picker": ve,
41
- "date-picker-panel": pe,
42
- "date-picker": de,
43
- input: fe,
44
- "input-number": ue,
45
- "input-tag": me,
46
- mention: ce,
47
- radio: ie,
48
- rate: se,
49
- select: ae,
50
- "select-v2": re,
51
- slider: le,
52
- switch: ne,
53
- "time-picker": oe,
54
- "time-select": te,
55
- transfer: ee,
56
- "tree-select": Z
57
- }, De = {
58
- ...Te,
59
- ...Me
60
- }, Oe = {
153
+ }, xt = {
154
+ autocomplete: Ze,
155
+ cascader: Qe,
156
+ checkbox: Ye,
157
+ "color-picker-panel": Je,
158
+ "color-picker": qe,
159
+ "date-picker-panel": Xe,
160
+ "date-picker": Ke,
161
+ input: We,
162
+ "input-number": Ge,
163
+ "input-tag": He,
164
+ mention: ze,
165
+ radio: je,
166
+ rate: $e,
167
+ select: Ue,
168
+ "select-v2": Ne,
169
+ slider: Le,
170
+ switch: Re,
171
+ "time-picker": Pe,
172
+ "time-select": Be,
173
+ transfer: Ve,
174
+ "tree-select": De
175
+ }, It = {
176
+ ...xt,
177
+ ...ht
178
+ }, Et = {
61
179
  /**
62
180
  * 获取组件默认属性
63
181
  */
64
182
  getDefaults(e) {
65
- const { comp: o, compAttrs: n = {} } = e, s = this.getComponentType(o);
183
+ const { comp: s, compAttrs: t = {} } = e, i = this.getComponentType(s);
66
184
  return {
67
- ...this.buildComponentAttrs(e, s),
68
- ...n
185
+ ...this.buildComponentAttrs(e, i),
186
+ ...t
69
187
  // 用户配置最后合并,优先级最高
70
188
  };
71
189
  },
@@ -73,107 +191,163 @@ const Pe = ["comp", "compAttrs", "vIf", "vShow"], Me = {
73
191
  * 判断组件类型
74
192
  */
75
193
  getComponentType(e) {
76
- const o = ["autocomplete", "input", "input-number", "input-tag", "mention"], n = ["cascader", "select", "select-v2", "tree-select"], s = ["date-picker", "time-select", "time-picker"];
77
- return o.includes(e) ? "input" : n.includes(e) ? "select" : s.includes(e) ? "picker" : "other";
194
+ const s = ["autocomplete", "input", "input-number", "input-tag", "mention"], t = ["cascader", "select", "select-v2", "tree-select"], i = ["date-picker", "time-select", "time-picker"];
195
+ return s.includes(e) ? "input" : t.includes(e) ? "select" : i.includes(e) ? "picker" : "other";
78
196
  },
79
197
  /**
80
198
  * 动态生成 placeholder
81
199
  */
82
- generatePlaceholder(e, o) {
83
- const { label: n, comp: s } = e, p = n ? `${n}` : "";
84
- return o === "input" ? s === "input-number" ? "请输入" : `请输入${p}` : ["select", "picker"].includes(o) ? `请选择${p}` : "";
200
+ generatePlaceholder(e, s) {
201
+ const { label: t, comp: i } = e, r = t ? `${t}` : "";
202
+ return s === "input" ? i === "input-number" ? "请输入" : `请输入${r}` : ["select", "picker"].includes(s) ? `请选择${r}` : "";
85
203
  },
86
204
  /**
87
205
  * 构建组件属性
88
206
  */
89
- buildComponentAttrs(e, o) {
90
- const n = {};
91
- return ["input", "select", "picker"].includes(o) && (n.placeholder = this.generatePlaceholder(e, o), n.clearable = !0), ["select"].includes(o) && (n.filterable = !0), n;
207
+ buildComponentAttrs(e, s) {
208
+ const t = {};
209
+ return ["input", "select", "picker"].includes(s) && (t.placeholder = this.generatePlaceholder(e, s), t.clearable = !0), ["select"].includes(s) && (t.filterable = !0), t;
92
210
  }
93
- }, Ve = {
211
+ }, Ct = {
94
212
  showMessage: !0,
95
213
  scrollToError: !0,
96
- scrollIntoViewOptions: {
97
- behavior: "smooth",
98
- // 平滑滚动
99
- block: "center",
100
- // 垂直居中,让错误项在视窗中间
101
- inline: "nearest"
102
- // 水平方向保持最近位置
103
- }
104
- }, Be = {
105
- search: { label: "搜索", icon: Fe, type: "primary" },
106
- reset: { label: "重置", icon: we },
107
- submit: { label: "确认", type: "primary" },
108
- cancel: { label: "取消" }
109
- }, Ne = {
110
- getDefaults(e, o) {
111
- return {
112
- ...this.buildActionAttrs(e),
113
- ...o
114
- };
115
- },
116
- generateActionButtons(e) {
117
- return e ? ["search", "reset"] : ["submit", "cancel"];
118
- },
119
- buildActionAttrs(e) {
120
- return {
121
- buttons: this.generateActionButtons(e),
122
- vIf: e,
123
- vShow: !0
124
- };
125
- }
126
- }, xe = /* @__PURE__ */ k({
214
+ scrollIntoViewOptions: ve
215
+ }, yt = /* @__PURE__ */ L({
127
216
  name: "ElementPlusKitFormItemAction",
128
217
  __name: "FormAction",
129
218
  props: {
130
219
  inline: { type: Boolean, default: !1 },
131
220
  actionSlot: {},
132
- config: { default: () => ({}) }
221
+ config: { default: () => ({}) },
222
+ expanded: { type: Boolean, default: !1 },
223
+ autoExpandOnHover: { type: Boolean },
224
+ onMouseEnter: {},
225
+ onMouseLeave: {}
133
226
  },
134
227
  emits: ["action"],
135
- setup(e) {
136
- const o = e, n = i(() => ({ ...o, config: { ...Ne.getDefaults(o.inline, o.config) } })), s = i(() => {
137
- const { buttons: v } = n.value.config;
138
- return v.map((d) => {
139
- if (typeof d == "string") {
140
- const c = Be[d];
141
- return c ? { ...c, eventName: d } : { label: d.toUpperCase(), eventName: d };
142
- }
143
- return d;
228
+ setup(e, { emit: s }) {
229
+ const t = e, i = s, r = p(() => ({
230
+ ...t,
231
+ config: { ...vt.getDefaults(t.inline, t.config) }
232
+ })), g = p(() => {
233
+ const { buttons: f } = r.value.config;
234
+ return f.map((m) => {
235
+ if (typeof m != "string")
236
+ return m;
237
+ const h = dt[m];
238
+ return h ? { ...h, eventName: m } : { label: m.toUpperCase(), eventName: m };
144
239
  });
145
- }), p = i(() => (v) => {
146
- const { label: d, eventName: c, ...g } = v;
147
- return { ...g };
148
240
  });
149
- return (v, d) => n.value.config.vIf ? _((u(), h(w(L), {
241
+ function x(f) {
242
+ return f.eventName === "expand";
243
+ }
244
+ function k(f) {
245
+ const { label: m, eventName: h, ...F } = f;
246
+ if (x(f)) {
247
+ const d = t.expanded ? "收起" : "展开";
248
+ return {
249
+ ...F,
250
+ title: d,
251
+ "aria-label": d,
252
+ "aria-expanded": t.expanded
253
+ };
254
+ }
255
+ return F;
256
+ }
257
+ function E(f) {
258
+ const m = f.eventName, h = x(f) ? t.expanded : void 0;
259
+ i("action", { eventName: m, data: h });
260
+ }
261
+ function I(f) {
262
+ x(f) && t.autoExpandOnHover && t.onMouseEnter?.();
263
+ }
264
+ function A(f) {
265
+ x(f) && t.autoExpandOnHover && t.onMouseLeave?.();
266
+ }
267
+ return (f, m) => r.value.config.vIf ? ne((v(), y(S(pe), {
150
268
  key: 0,
151
269
  prop: "action"
152
270
  }, {
153
- default: C(() => [
154
- e.actionSlot ? (u(), h(b(e.actionSlot), {
271
+ default: w(() => [
272
+ e.actionSlot ? (v(), y(D(e.actionSlot), {
155
273
  key: 1,
156
274
  prop: "action"
157
- })) : (u(!0), M($, { key: 0 }, P(s.value, (c, g) => (u(), h(w(Ae), I({
158
- key: `${c.label}-${g}`
159
- }, { ref_for: !0 }, p.value(c), {
160
- onClick: (y) => v.$emit("action", { eventName: c.eventName })
161
- }), {
162
- default: C(() => [
163
- G(H(c.label ?? ""), 1)
164
- ]),
165
- _: 2
166
- }, 1040, ["onClick"]))), 128))
275
+ })) : (v(), M($, { key: 0 }, [
276
+ (v(!0), M($, null, j(g.value, (h, F) => (v(), y(S(et), _({
277
+ key: `${h.eventName}-${F}`
278
+ }, { ref_for: !0 }, k(h), {
279
+ onMouseenter: (d) => I(h),
280
+ onMouseleave: (d) => A(h),
281
+ onClick: (d) => E(h)
282
+ }), {
283
+ default: w(() => [
284
+ x(h) && e.inline ? (v(), y(S(tt), {
285
+ key: 0,
286
+ class: we(["expand-toggle-icon", { "is-expanded": e.expanded }])
287
+ }, {
288
+ default: w(() => [
289
+ X(S(st))
290
+ ]),
291
+ _: 1
292
+ }, 8, ["class"])) : (v(), M($, { key: 1 }, [
293
+ Oe(Se(h.label ?? ""), 1)
294
+ ], 64))
295
+ ]),
296
+ _: 2
297
+ }, 1040, ["onMouseenter", "onMouseleave", "onClick"]))), 128)),
298
+ ce(f.$slots, "default", {}, void 0, !0)
299
+ ], 64))
167
300
  ]),
168
- _: 1
301
+ _: 3
169
302
  }, 512)), [
170
- [R, n.value.config.vShow]
171
- ]) : W("", !0);
303
+ [oe, r.value.config.vShow]
304
+ ]) : Ae("", !0);
172
305
  }
173
- }), _e = /* @__PURE__ */ k({
306
+ }), ge = (e, s) => {
307
+ const t = e.__vccOpts || e;
308
+ for (const [i, r] of s)
309
+ t[i] = r;
310
+ return t;
311
+ }, At = /* @__PURE__ */ ge(yt, [["__scopeId", "data-v-dd21a872"]]);
312
+ function wt(e, s) {
313
+ return e ? e.some((t) => typeof t == "string" ? t === s : t.eventName === s) : !1;
314
+ }
315
+ function Ot(e, s = 100) {
316
+ let t = null;
317
+ return function(...i) {
318
+ t && clearTimeout(t), t = setTimeout(() => {
319
+ e.apply(this, i), t = null;
320
+ }, s);
321
+ };
322
+ }
323
+ function he(e, s) {
324
+ if (!e || e.length === 0)
325
+ return [];
326
+ const t = Array.from(new Set(e));
327
+ return s ? t.filter((i) => i !== s) : t;
328
+ }
329
+ function ie(e, s, t) {
330
+ const i = he(e, t), r = {};
331
+ for (const g of i)
332
+ r[g] = s[g];
333
+ return r;
334
+ }
335
+ function ee(e) {
336
+ return e && typeof e == "object" && typeof e.loader == "function";
337
+ }
338
+ function re(e) {
339
+ return e == null || e === "";
340
+ }
341
+ function te(e, s) {
342
+ return s.length === 0 ? !1 : re(e) ? !0 : s.some((t) => (typeof t == "object" && t !== null ? t.value : t) === e);
343
+ }
344
+ function se(e) {
345
+ return e == null ? e : typeof e == "object" ? JSON.parse(JSON.stringify(e)) : e;
346
+ }
347
+ const ue = /* @__PURE__ */ L({
174
348
  name: "ElementPlusKitFormItem",
175
349
  __name: "FormItem",
176
- props: /* @__PURE__ */ O({
350
+ props: /* @__PURE__ */ J({
177
351
  formItem: {},
178
352
  index: {},
179
353
  formData: { default: () => ({}) },
@@ -183,68 +357,174 @@ const Pe = ["comp", "compAttrs", "vIf", "vShow"], Me = {
183
357
  modelValue: {},
184
358
  modelModifiers: {}
185
359
  }),
186
- emits: /* @__PURE__ */ O(["change"], ["update:modelValue"]),
187
- setup(e) {
188
- const o = e, n = K(e, "modelValue");
189
- function s() {
190
- const m = new Set(Pe);
360
+ emits: /* @__PURE__ */ J(["change"], ["update:modelValue"]),
361
+ setup(e, { emit: s }) {
362
+ const t = e, i = s, r = fe(e, "modelValue"), g = p(() => {
363
+ const a = new Set(gt);
191
364
  return Object.fromEntries(
192
- Object.entries(o.formItem).filter(([f]) => !m.has(f))
365
+ Object.entries(t.formItem).filter(([u]) => !a.has(u))
193
366
  );
367
+ }), x = p(() => t.formSlots.formItemSlots), k = p(() => It[t.formItem.comp] || "div"), E = p(() => ({ prop: t.formItem.prop, formItem: t.formItem, index: t.index })), I = p(() => Object.fromEntries(
368
+ Object.entries(t.dynamicCompEvents).map(([a, u]) => [
369
+ a,
370
+ (...c) => u(E.value, ...c)
371
+ ])
372
+ )), A = Y([]), f = Y(!1), m = lt();
373
+ function h() {
374
+ if (!re(r.value)) {
375
+ if (m.isClearing)
376
+ return;
377
+ m.startClearing(r.value), r.value = void 0, i("change", E.value, void 0), q(() => {
378
+ m.endClearing();
379
+ });
380
+ }
194
381
  }
195
- const p = i(() => s()), v = i(() => o.formSlots.formItemSlots), d = i(() => De[o.formItem.comp] || "div"), c = i(() => {
196
- const { formItem: m, index: f } = o;
197
- return { prop: m.prop, formItem: m, index: f };
382
+ function F(a) {
383
+ m.isClearing || (m.startUserInteraction(), i("change", E.value, a), q(() => {
384
+ m.endUserInteraction();
385
+ }));
386
+ }
387
+ const d = p(() => {
388
+ const a = Et.getDefaults(t.formItem), u = t.formItem.compAttrs ?? {}, c = "options" in u;
389
+ return {
390
+ ...a,
391
+ ...u,
392
+ ...I.value,
393
+ ...c && {
394
+ options: A.value,
395
+ loading: f.value
396
+ }
397
+ };
198
398
  });
199
- function g() {
200
- const m = {};
201
- for (const [f, a] of Object.entries(o.dynamicCompEvents))
202
- m[f] = (...S) => a(c.value, ...S);
203
- return m;
399
+ function z(a) {
400
+ return t.formSlots.dynamicComponentSlots.get(a);
401
+ }
402
+ async function V(a, u) {
403
+ try {
404
+ const c = await a(u);
405
+ return Array.isArray(c) ? c : [];
406
+ } catch (c) {
407
+ return console.error(`[FormItem] 加载字段 "${t.formItem.prop}" 的选项失败:`, c), [];
408
+ }
409
+ }
410
+ function B() {
411
+ const a = t.formItem.compAttrs?.options;
412
+ return ee(a) ? a : null;
204
413
  }
205
- const y = i(() => g()), F = i(() => ({ ...Oe.getDefaults(o.formItem), ...y.value })), T = i(() => (m) => o.formSlots.dynamicComponentSlots.get(m));
206
- return (m, f) => (u(), h(w(L), U(j(p.value)), V({
207
- default: C(() => [
208
- e.formItem.comp !== "custom" ? (u(), h(b(d.value), I({ key: 0 }, F.value, {
209
- modelValue: n.value,
210
- "onUpdate:modelValue": f[0] || (f[0] = (a) => n.value = a),
211
- onChange: f[1] || (f[1] = (a) => m.$emit("change", c.value, a))
212
- }), V({ _: 2 }, [
213
- P(T.value(e.formItem.prop), (a, S) => ({
214
- name: a.slotName,
215
- fn: C((t) => [
216
- (u(), h(b(a.slotFn), I({
217
- value: n.value,
414
+ async function P() {
415
+ const a = t.formItem.compAttrs?.options;
416
+ if (a && !Array.isArray(a)) {
417
+ f.value = !0;
418
+ try {
419
+ if (typeof a == "function") {
420
+ const u = await V(a, t.formData ?? {});
421
+ A.value = u, te(r.value, u) || h();
422
+ } else if (ee(a)) {
423
+ const { loader: u, deps: c = [] } = a, b = t.formData ?? {}, O = ie(c, b, t.formItem.prop), R = await V(u, { ...b, ...O });
424
+ A.value = R, te(r.value, R) || h();
425
+ }
426
+ } finally {
427
+ f.value = !1;
428
+ }
429
+ }
430
+ }
431
+ function H(a) {
432
+ A.value = a, te(r.value, a) || h();
433
+ }
434
+ function G() {
435
+ P();
436
+ }
437
+ function W(a) {
438
+ const { immediate: u = !1, deps: c = [], loader: b } = a;
439
+ if (c.length > 0) {
440
+ const O = t.formData ?? {}, R = ie(c, O, t.formItem.prop);
441
+ try {
442
+ b({ ...O, ...R });
443
+ } catch {
444
+ }
445
+ u && P();
446
+ return;
447
+ }
448
+ u && P();
449
+ }
450
+ const K = p(() => {
451
+ const a = B();
452
+ return a ? he(a.deps ?? [], t.formItem.prop) : [];
453
+ }), N = p(() => {
454
+ const a = B();
455
+ return a ? a.immediate ?? !1 : !1;
456
+ });
457
+ return Q(
458
+ () => {
459
+ const a = K.value, u = {};
460
+ for (const c of a)
461
+ u[c] = t.formData?.[c];
462
+ return u;
463
+ },
464
+ () => {
465
+ B() && P();
466
+ },
467
+ { deep: !0, immediate: N.value }
468
+ ), be(() => {
469
+ const a = t.formItem.compAttrs?.options;
470
+ if (a) {
471
+ if (Array.isArray(a)) {
472
+ H(a);
473
+ return;
474
+ }
475
+ if (typeof a == "function") {
476
+ G();
477
+ return;
478
+ }
479
+ ee(a) && W(a);
480
+ }
481
+ }), Q(
482
+ () => r.value,
483
+ (a, u) => {
484
+ m.isClearingOperation(u, a, re) || m.isUserInteraction || a !== u && i("change", E.value, a);
485
+ }
486
+ ), (a, u) => (v(), y(S(pe), me(de(g.value)), le({
487
+ default: w(() => [
488
+ e.formItem.comp !== "custom" ? (v(), y(D(k.value), _({ key: 0 }, d.value, {
489
+ modelValue: r.value,
490
+ "onUpdate:modelValue": u[0] || (u[0] = (c) => r.value = c),
491
+ onChange: F
492
+ }), le({ _: 2 }, [
493
+ j(z(e.formItem.prop) ?? [], (c, b) => ({
494
+ name: c.slotName,
495
+ fn: w((O) => [
496
+ (v(), y(D(c.slotFn), _({
497
+ value: r.value,
218
498
  form: e.formData,
219
499
  "form-item": e.formItem
220
- }, t), null, 16, ["value", "form", "form-item"]))
500
+ }, O), null, 16, ["value", "form", "form-item"]))
221
501
  ])
222
502
  }))
223
- ]), 1040, ["modelValue"])) : X(m.$slots, e.formItem.prop, {
503
+ ]), 1040, ["modelValue"])) : ce(a.$slots, e.formItem.prop, {
224
504
  key: 1,
225
- value: n.value,
505
+ value: r.value,
226
506
  form: e.formData,
227
507
  formItem: e.formItem
228
508
  })
229
509
  ]),
230
510
  _: 2
231
511
  }, [
232
- P(v.value, (a, S) => ({
233
- name: a.slotName,
234
- fn: C((t) => [
235
- (u(), h(b(a.slotFn), I({
236
- value: n.value,
512
+ j(x.value, (c, b) => ({
513
+ name: c.slotName,
514
+ fn: w((O) => [
515
+ (v(), y(D(c.slotFn), _({
516
+ value: r.value,
237
517
  form: e.formData,
238
518
  "form-item": e.formItem
239
- }, t), null, 16, ["value", "form", "form-item"]))
519
+ }, O), null, 16, ["value", "form", "form-item"]))
240
520
  ])
241
521
  }))
242
522
  ]), 1040));
243
523
  }
244
- }), je = /* @__PURE__ */ k({
524
+ }), St = /* @__PURE__ */ L({
245
525
  name: "WForm",
246
526
  __name: "Form",
247
- props: {
527
+ props: /* @__PURE__ */ J({
248
528
  formItems: {},
249
529
  rowAttrs: { default: () => ({}) },
250
530
  actionConfig: { default: () => ({}) },
@@ -263,100 +543,223 @@ const Pe = ["comp", "compAttrs", "vIf", "vShow"], Me = {
263
543
  validateOnRuleChange: { type: Boolean },
264
544
  scrollToError: { type: Boolean },
265
545
  scrollIntoViewOptions: {}
266
- },
267
- emits: ["validate", "change", "action", "search", "reset", "submit", "cancel"],
268
- setup(e, { expose: o, emit: n }) {
269
- const s = e, p = n, v = q(), d = i(() => Object.fromEntries(
270
- Object.entries(v).filter(
271
- ([t, l]) => t.startsWith("on") && typeof l == "function"
272
- )
273
- )), c = i(() => {
274
- const { formItems: t, actionConfig: l, rowAttrs: r, ...E } = s, A = Object.fromEntries(
275
- Object.entries(v).filter(
276
- ([D, z]) => !(D.startsWith("on") && typeof z == "function")
277
- )
546
+ }, {
547
+ expanded: { type: Boolean, default: !1 },
548
+ expandedModifiers: {}
549
+ }),
550
+ emits: /* @__PURE__ */ J(["validate", "change", "action", "search", "reset", "submit", "cancel", "expand"], ["update:expanded"]),
551
+ setup(e, { expose: s, emit: t }) {
552
+ const i = e, r = t, g = Te();
553
+ function x(n, o) {
554
+ return n.startsWith("on") && typeof o == "function";
555
+ }
556
+ const k = p(() => Object.fromEntries(
557
+ Object.entries(g).filter(([n, o]) => x(n, o))
558
+ )), E = p(() => {
559
+ const { formItems: n, actionConfig: o, rowAttrs: l, ...C } = i, T = Object.fromEntries(
560
+ Object.entries(g).filter(([U, Ce]) => !x(U, Ce))
278
561
  );
279
- return { ...E, ...Ve, ...A };
280
- }), g = i(() => {
281
- const { span: t } = s?.rowAttrs ?? {};
282
- return s.formItems.filter((l) => N({ condition: l.vIf, data: s.model, defaultValue: !0 })).map((l) => {
283
- const { colAttrs: r = {} } = l ?? {};
284
- return { ...l, colAttrs: { ...r, span: r.span ?? t } };
562
+ return { ...C, ...Ct, ...T };
563
+ }), I = fe(e, "expanded");
564
+ Q(
565
+ I,
566
+ (n) => {
567
+ r("expand", n);
568
+ }
569
+ );
570
+ const A = p(() => E.value.inline ? wt(i.actionConfig?.buttons, "expand") : !1), f = p(() => {
571
+ if (!A.value)
572
+ return !1;
573
+ const n = i.actionConfig?.expand;
574
+ return n ? n.autoExpandOnHover === !0 : !1;
575
+ }), { onMouseEnter: m, onMouseLeave: h, recordManualToggle: F } = at(
576
+ I,
577
+ f,
578
+ (n) => {
579
+ I.value = n;
580
+ }
581
+ ), d = Y();
582
+ function z(n) {
583
+ const o = n ?? !I.value;
584
+ I.value = o, F();
585
+ const l = i.actionConfig?.expand;
586
+ l?.scrollOnToggle && q(() => {
587
+ setTimeout(() => d.value?.$el?.scrollIntoView?.(l.scrollIntoViewOptions ?? pt), 250);
285
588
  });
286
- }), y = Y();
287
- function F(t) {
288
- const l = [];
289
- for (const r in y)
290
- r.startsWith(t) && l.push({
291
- rawSlotName: r,
292
- slotName: r.replace(t, ""),
293
- slotFn: y[r]
294
- });
295
- return l;
296
589
  }
297
- const T = i(() => {
298
- const t = F("form-item-"), l = /* @__PURE__ */ new Map();
299
- for (const r of g.value) {
300
- const E = F(`${r.prop}-`);
301
- E.length > 0 && l.set(r.prop, E);
590
+ const V = p(() => {
591
+ const { span: n } = i.rowAttrs;
592
+ return i.formItems.filter((o) => Z({ condition: o.vIf, data: i.model, defaultValue: !0 })).map((o) => {
593
+ const { colAttrs: l = {} } = o ?? {};
594
+ return { ...o, colAttrs: { ...l, span: l.span ?? n } };
595
+ });
596
+ }), B = p(() => V.value.map((n, o) => ({ ...n, _originalIndex: o })).filter((n) => {
597
+ const o = n._originalIndex;
598
+ return A.value ? !P(n, o) : !0;
599
+ }));
600
+ function P(n, o) {
601
+ if (!A.value || I.value)
602
+ return !1;
603
+ const l = i.actionConfig?.expand;
604
+ return l ? !!("exclude" in l && l.exclude.length > 0 && l.exclude.includes(n.prop) || "include" in l && l.include.length > 0 && !l.include.includes(n.prop) || "count" in l && o >= l.count) : !1;
605
+ }
606
+ const H = ke();
607
+ function G(n) {
608
+ return Object.keys(H).filter((o) => o.startsWith(n)).map((o) => ({
609
+ rawSlotName: o,
610
+ slotName: o.replace(n, ""),
611
+ slotFn: H[o]
612
+ }));
613
+ }
614
+ const W = p(() => {
615
+ const n = G("form-item-"), o = /* @__PURE__ */ new Map();
616
+ for (const l of V.value) {
617
+ const C = G(`${l.prop}-`);
618
+ C.length > 0 && o.set(l.prop, C);
302
619
  }
303
- return { formItemSlots: t, dynamicComponentSlots: l };
304
- }), m = i(() => s.rowAttrs && Object.keys(s.rowAttrs).length > 0), f = i(() => ({
305
- row: c.value.inline || m.value ? be : "div",
306
- col: m.value ? Ie : "div"
307
- })), a = J();
308
- async function S({ eventName: t }) {
309
- const l = ["submit", "search"], r = ["cancel", "reset"];
310
- [...l, ...r].includes(t) && (l.includes(t) && await a.value?.validate?.(), r.includes(t) && a.value?.resetFields?.(), p(t)), p("action", t);
620
+ return { formItemSlots: n, dynamicComponentSlots: o };
621
+ }), K = p(() => Object.keys(i.rowAttrs ?? {}).length > 0), N = p(() => ({
622
+ row: E.value.inline || K.value ? ot : "div",
623
+ col: K.value ? nt : "div"
624
+ })), a = p(() => i.formItems.map((n) => n.prop)), u = p(() => {
625
+ if (!A.value)
626
+ return [];
627
+ const n = i.actionConfig?.expand;
628
+ return n ? V.value.map((o, l) => ({ field: o, index: l })).filter(({ field: o, index: l }) => !!("exclude" in n && n.exclude.includes(o.prop) || "include" in n && !n.include.includes(o.prop) || "count" in n && l >= n.count)).map(({ field: o }) => o.prop) : [];
629
+ }), c = Y({});
630
+ function b() {
631
+ c.value = {};
632
+ for (const n of u.value) {
633
+ const o = i.model[n];
634
+ c.value[n] = se(o);
635
+ }
636
+ }
637
+ const O = Ot(b, 100);
638
+ function R() {
639
+ const n = {};
640
+ for (const o of u.value) {
641
+ const l = c.value[o];
642
+ n[o] = l != null ? se(l) : void 0;
643
+ }
644
+ return n;
645
+ }
646
+ function xe() {
647
+ d.value?.clearValidate?.(u.value);
648
+ const n = a.value.filter((o) => !u.value.includes(o));
649
+ n.length > 0 && d.value?.resetFields?.(n);
650
+ }
651
+ async function Ie({ eventName: n }) {
652
+ const o = ["submit", "search"], l = ["cancel", "reset"];
653
+ if (n === "expand") {
654
+ z(), r("action", n, I.value);
655
+ return;
656
+ }
657
+ if (o.includes(n) && await d.value?.validate?.(), l.includes(n)) {
658
+ if (n === "reset") {
659
+ const C = R();
660
+ xe(), r("reset", C), r("action", n, C);
661
+ return;
662
+ }
663
+ d.value?.resetFields?.();
664
+ }
665
+ r(n), r("action", n);
666
+ }
667
+ function Ee(n, o, l) {
668
+ r("validate", n, o, l);
311
669
  }
312
- return o({
670
+ return s({
313
671
  // element-plus form exposes
314
672
  get fields() {
315
- return a.value?.fields;
673
+ return d.value?.fields;
316
674
  },
317
- getField: (t) => a.value?.getField?.(t),
318
- validate: () => a.value?.validate?.(),
319
- validateField: (t) => a.value?.validateField?.(t),
320
- resetFields: (t) => a.value?.resetFields?.(t),
321
- clearValidate: (t) => a.value?.clearValidate?.(t),
322
- scrollToField: (t) => a.value?.scrollToField?.(t)
323
- }), (t, l) => (u(), h(w(ye), I({
675
+ getField: (n) => d.value?.getField?.(n),
676
+ validate: () => d.value?.validate?.(),
677
+ validateField: (n) => d.value?.validateField?.(n),
678
+ resetFields: (n) => d.value?.resetFields?.(n),
679
+ clearValidate: (n) => d.value?.clearValidate?.(n),
680
+ scrollToField: (n) => d.value?.scrollToField?.(n),
681
+ // 展开/折叠控制方法
682
+ get expanded() {
683
+ return I.value;
684
+ },
685
+ toggleExpand: z
686
+ }), Fe(() => {
687
+ b();
688
+ }), Q(
689
+ [() => i.formItems, () => i.actionConfig?.expand],
690
+ () => {
691
+ O();
692
+ },
693
+ { deep: !0 }
694
+ ), (n, o) => (v(), y(S(rt), _({
324
695
  ref_key: "formRef",
325
- ref: a
326
- }, c.value, {
696
+ ref: d
697
+ }, E.value, {
327
698
  model: e.model,
328
- onValidate: l[1] || (l[1] = (r, E, A) => t.$emit("validate", r, E, A)),
329
- onSubmit: l[2] || (l[2] = Q(() => {
699
+ onValidate: Ee,
700
+ onSubmit: o[2] || (o[2] = Me(() => {
330
701
  }, ["prevent"]))
331
702
  }), {
332
- default: C(() => [
333
- (u(), h(b(f.value.row), U(j(e.rowAttrs)), {
334
- default: C(() => [
335
- (u(!0), M($, null, P(g.value, (r, E) => _((u(), h(b(f.value.col), I({
336
- key: `${r.prop}-${E}`
337
- }, { ref_for: !0 }, r.colAttrs), {
338
- default: C(() => [
339
- B(_e, {
340
- modelValue: e.model[r.prop],
341
- "onUpdate:modelValue": (A) => e.model[r.prop] = A,
342
- "form-item": r,
703
+ default: w(() => [
704
+ (v(), y(D(N.value.row), me(de(e.rowAttrs)), {
705
+ default: w(() => [
706
+ A.value ? (v(), y(_e, {
707
+ key: 0,
708
+ name: "form-item",
709
+ tag: "div",
710
+ class: "form-items-transition"
711
+ }, {
712
+ default: w(() => [
713
+ (v(!0), M($, null, j(B.value, (l, C) => ne((v(), y(D(N.value.col), _({
714
+ key: `${l.prop}-${l._originalIndex ?? C}`
715
+ }, { ref_for: !0 }, l.colAttrs), {
716
+ default: w(() => [
717
+ X(ue, {
718
+ modelValue: e.model[l.prop],
719
+ "onUpdate:modelValue": (T) => e.model[l.prop] = T,
720
+ "form-item": l,
721
+ "form-data": e.model,
722
+ "dynamic-comp-events": k.value,
723
+ "form-slots": W.value,
724
+ index: l._originalIndex ?? C,
725
+ onChange: o[0] || (o[0] = (T, U) => r("change", T, U))
726
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "form-item", "form-data", "dynamic-comp-events", "form-slots", "index"])
727
+ ]),
728
+ _: 2
729
+ }, 1040)), [
730
+ [oe, S(Z)({ condition: l.vShow, data: i.model, defaultValue: !0 })]
731
+ ])), 128))
732
+ ]),
733
+ _: 1
734
+ })) : (v(!0), M($, { key: 1 }, j(B.value, (l, C) => ne((v(), y(D(N.value.col), _({
735
+ key: `${l.prop}-${l._originalIndex ?? C}`
736
+ }, { ref_for: !0 }, l.colAttrs), {
737
+ default: w(() => [
738
+ X(ue, {
739
+ modelValue: e.model[l.prop],
740
+ "onUpdate:modelValue": (T) => e.model[l.prop] = T,
741
+ "form-item": l,
343
742
  "form-data": e.model,
344
- "dynamic-comp-events": d.value,
345
- "form-slots": T.value,
346
- index: E,
347
- onChange: l[0] || (l[0] = (A, D) => t.$emit("change", A, D))
743
+ "dynamic-comp-events": k.value,
744
+ "form-slots": W.value,
745
+ index: l._originalIndex ?? C,
746
+ onChange: o[1] || (o[1] = (T, U) => r("change", T, U))
348
747
  }, null, 8, ["modelValue", "onUpdate:modelValue", "form-item", "form-data", "dynamic-comp-events", "form-slots", "index"])
349
748
  ]),
350
749
  _: 2
351
750
  }, 1040)), [
352
- [R, w(N)({ condition: r.vShow, data: s.model, defaultValue: !0 })]
751
+ [oe, S(Z)({ condition: l.vShow, data: i.model, defaultValue: !0 })]
353
752
  ])), 128)),
354
- B(xe, {
355
- inline: c.value.inline,
356
- "action-slot": t.$slots.action,
753
+ X(At, {
754
+ inline: E.value.inline,
755
+ "action-slot": n.$slots.action,
357
756
  config: e.actionConfig,
358
- onAction: S
359
- }, null, 8, ["inline", "action-slot", "config"])
757
+ expanded: I.value,
758
+ "auto-expand-on-hover": f.value,
759
+ "on-mouse-enter": S(m),
760
+ "on-mouse-leave": S(h),
761
+ onAction: Ie
762
+ }, null, 8, ["inline", "action-slot", "config", "expanded", "auto-expand-on-hover", "on-mouse-enter", "on-mouse-leave"])
360
763
  ]),
361
764
  _: 1
362
765
  }, 16))
@@ -364,8 +767,8 @@ const Pe = ["comp", "compAttrs", "vIf", "vShow"], Me = {
364
767
  _: 1
365
768
  }, 16, ["model"]));
366
769
  }
367
- });
770
+ }), Ft = /* @__PURE__ */ ge(St, [["__scopeId", "data-v-b241f6ca"]]);
368
771
  export {
369
- je as WForm,
370
- je as default
772
+ Ft as WForm,
773
+ Ft as default
371
774
  };