@iswangh/element-plus-kit-form 0.1.3 → 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.
package/dist/index.js CHANGED
@@ -1,70 +1,188 @@
1
- import { defineComponent as P, createElementBlock as N, openBlock as p, createElementVNode as J, computed as f, withDirectives as Q, createCommentVNode as ae, createBlock as I, unref as V, withCtx as b, Fragment as Z, renderList as B, mergeProps as D, createTextVNode as se, toDisplayString as ie, resolveDynamicComponent as F, vShow as ee, mergeModels as W, useModel as ce, ref as L, watch as G, watchEffect as ue, normalizeProps as te, guardReactiveProps as oe, createSlots as K, renderSlot as me, nextTick as H, useAttrs as fe, useSlots as de, withModifiers as pe, createVNode as q } from "vue";
2
- import { checkCondition as X } from "@iswangh/element-plus-kit-core";
3
- import { ElTreeSelect as ve, ElTransfer as ge, ElTimeSelect as he, ElTimePicker as Ce, ElSwitch as Ee, ElSlider as Ie, ElSelectV2 as ye, ElSelect as Ae, ElRate as be, ElRadioGroup as Se, ElMention as we, ElInputTag as Oe, ElInputNumber as ke, ElInput as De, ElDatePicker as Fe, ElDatePickerPanel as Te, ElColorPicker as Me, ElColorPickerPanel as Ve, ElCheckboxGroup as Pe, ElCascader as xe, ElAutocomplete as _e, ElFormItem as ne, ElButton as Be, ElCol as Ne, ElRow as Ue, ElForm as Re } from "element-plus";
4
- var $e = /* @__PURE__ */ P({
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 (n, t) => (p(), N("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
- J("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
- }), je = $e, Le = /* @__PURE__ */ P({
105
+ }), ct = ut, ft = /* @__PURE__ */ L({
19
106
  name: "Search",
20
107
  __name: "search",
21
108
  setup(e) {
22
- return (n, t) => (p(), N("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
- J("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
- }), ze = Le;
33
- const We = ["comp", "compAttrs", "vIf", "vShow"], Ge = {
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
- }, Ke = {
36
- autocomplete: _e,
37
- cascader: xe,
38
- checkbox: Pe,
39
- "color-picker-panel": Ve,
40
- "color-picker": Me,
41
- "date-picker-panel": Te,
42
- "date-picker": Fe,
43
- input: De,
44
- "input-number": ke,
45
- "input-tag": Oe,
46
- mention: we,
47
- radio: Se,
48
- rate: be,
49
- select: Ae,
50
- "select-v2": ye,
51
- slider: Ie,
52
- switch: Ee,
53
- "time-picker": Ce,
54
- "time-select": he,
55
- transfer: ge,
56
- "tree-select": ve
57
- }, He = {
58
- ...Ke,
59
- ...Ge
60
- }, qe = {
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: n, compAttrs: t = {} } = e, s = this.getComponentType(n);
183
+ const { comp: s, compAttrs: t = {} } = e, i = this.getComponentType(s);
66
184
  return {
67
- ...this.buildComponentAttrs(e, s),
185
+ ...this.buildComponentAttrs(e, i),
68
186
  ...t
69
187
  // 用户配置最后合并,优先级最高
70
188
  };
@@ -73,178 +191,163 @@ const We = ["comp", "compAttrs", "vIf", "vShow"], Ge = {
73
191
  * 判断组件类型
74
192
  */
75
193
  getComponentType(e) {
76
- const n = ["autocomplete", "input", "input-number", "input-tag", "mention"], t = ["cascader", "select", "select-v2", "tree-select"], s = ["date-picker", "time-select", "time-picker"];
77
- return n.includes(e) ? "input" : t.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, n) {
83
- const { label: t, comp: s } = e, l = t ? `${t}` : "";
84
- return n === "input" ? s === "input-number" ? "请输入" : `请输入${l}` : ["select", "picker"].includes(n) ? `请选择${l}` : "";
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, n) {
207
+ buildComponentAttrs(e, s) {
90
208
  const t = {};
91
- return ["input", "select", "picker"].includes(n) && (t.placeholder = this.generatePlaceholder(e, n), t.clearable = !0), ["select"].includes(n) && (t.filterable = !0), 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
- }, Xe = {
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
- }, Ye = {
105
- search: { label: "搜索", icon: ze, type: "primary" },
106
- reset: { label: "重置", icon: je },
107
- submit: { label: "确认", type: "primary" },
108
- cancel: { label: "取消" }
109
- }, Je = {
110
- getDefaults(e, n) {
111
- return {
112
- ...this.buildActionAttrs(e),
113
- ...n
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
- }, Qe = /* @__PURE__ */ P({
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 n = e, t = f(() => ({
137
- ...n,
138
- config: { ...Je.getDefaults(n.inline, n.config) }
139
- })), s = f(() => {
140
- const { buttons: d } = t.value.config;
141
- return d.map((m) => {
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) => {
142
235
  if (typeof m != "string")
143
236
  return m;
144
- const v = Ye[m];
145
- return v ? { ...v, eventName: m } : { label: m.toUpperCase(), eventName: m };
237
+ const h = dt[m];
238
+ return h ? { ...h, eventName: m } : { label: m.toUpperCase(), eventName: m };
146
239
  });
147
- }), l = (d) => {
148
- const { label: m, eventName: v, ...g } = d;
149
- return g;
150
- };
151
- return (d, m) => t.value.config.vIf ? Q((p(), I(V(ne), {
240
+ });
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), {
152
268
  key: 0,
153
269
  prop: "action"
154
270
  }, {
155
- default: b(() => [
156
- e.actionSlot ? (p(), I(F(e.actionSlot), {
271
+ default: w(() => [
272
+ e.actionSlot ? (v(), y(D(e.actionSlot), {
157
273
  key: 1,
158
274
  prop: "action"
159
- })) : (p(!0), N(Z, { key: 0 }, B(s.value, (v, g) => (p(), I(V(Be), D({
160
- key: `${v.label}-${g}`
161
- }, { ref_for: !0 }, l(v), {
162
- onClick: (T) => d.$emit("action", { eventName: v.eventName })
163
- }), {
164
- default: b(() => [
165
- se(ie(v.label ?? ""), 1)
166
- ]),
167
- _: 2
168
- }, 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))
169
300
  ]),
170
- _: 1
301
+ _: 3
171
302
  }, 512)), [
172
- [ee, t.value.config.vShow]
173
- ]) : ae("", !0);
303
+ [oe, r.value.config.vShow]
304
+ ]) : Ae("", !0);
174
305
  }
175
- });
176
- function Ze() {
177
- let e = !1, n = !1, t = null, s = !1;
178
- return {
179
- /** 是否正在清理 */
180
- get isClearing() {
181
- return e;
182
- },
183
- /** 是否用户交互 */
184
- get isUserInteraction() {
185
- return n;
186
- },
187
- /**
188
- * 开始清理操作
189
- * @param value - 清理前的值
190
- */
191
- startClearing(l) {
192
- e = !0, t = l, s = !0;
193
- },
194
- /**
195
- * 结束清理操作(在 nextTick 中调用)
196
- */
197
- endClearing() {
198
- e = !1, t = null, s = !1;
199
- },
200
- /**
201
- * 开始用户交互
202
- */
203
- startUserInteraction() {
204
- n = !0;
205
- },
206
- /**
207
- * 结束用户交互(在 nextTick 中调用)
208
- */
209
- endUserInteraction() {
210
- n = !1;
211
- },
212
- /**
213
- * 判断是否是清理操作
214
- * @param oldValue - 旧值
215
- * @param newValue - 新值
216
- * @param isEmpty - 检查值是否为空的函数
217
- */
218
- isClearingOperation(l, d, m) {
219
- return !!(e || s || !m(l) && m(d) && l === t);
220
- }
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);
221
321
  };
222
322
  }
223
- function re(e, n) {
323
+ function he(e, s) {
224
324
  if (!e || e.length === 0)
225
325
  return [];
226
326
  const t = Array.from(new Set(e));
227
- return n ? t.filter((s) => s !== n) : t;
327
+ return s ? t.filter((i) => i !== s) : t;
228
328
  }
229
- function Y(e, n, t) {
230
- const s = re(e, t), l = {};
231
- for (const d of s)
232
- l[d] = n[d];
233
- return l;
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;
234
334
  }
235
- function $(e) {
335
+ function ee(e) {
236
336
  return e && typeof e == "object" && typeof e.loader == "function";
237
337
  }
238
- function z(e) {
338
+ function re(e) {
239
339
  return e == null || e === "";
240
340
  }
241
- function j(e, n) {
242
- return n.length === 0 ? !1 : z(e) ? !0 : n.some((t) => (typeof t == "object" && t !== null ? t.value : t) === e);
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;
243
346
  }
244
- const et = /* @__PURE__ */ P({
347
+ const ue = /* @__PURE__ */ L({
245
348
  name: "ElementPlusKitFormItem",
246
349
  __name: "FormItem",
247
- props: /* @__PURE__ */ W({
350
+ props: /* @__PURE__ */ J({
248
351
  formItem: {},
249
352
  index: {},
250
353
  formData: { default: () => ({}) },
@@ -254,171 +357,174 @@ const et = /* @__PURE__ */ P({
254
357
  modelValue: {},
255
358
  modelModifiers: {}
256
359
  }),
257
- emits: /* @__PURE__ */ W(["change"], ["update:modelValue"]),
258
- setup(e, { emit: n }) {
259
- const t = e, s = n, l = ce(e, "modelValue"), d = f(() => {
260
- const o = new Set(We);
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);
261
364
  return Object.fromEntries(
262
- Object.entries(t.formItem).filter(([i]) => !o.has(i))
365
+ Object.entries(t.formItem).filter(([u]) => !a.has(u))
263
366
  );
264
- }), m = f(() => t.formSlots.formItemSlots), v = f(() => He[t.formItem.comp] || "div"), g = f(() => ({ prop: t.formItem.prop, formItem: t.formItem, index: t.index })), T = f(() => Object.fromEntries(
265
- Object.entries(t.dynamicCompEvents).map(([o, i]) => [
266
- o,
267
- (...c) => i(g.value, ...c)
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)
268
371
  ])
269
- )), S = L([]), w = L(!1), E = Ze();
270
- function O() {
271
- if (!z(l.value)) {
272
- if (E.isClearing)
372
+ )), A = Y([]), f = Y(!1), m = lt();
373
+ function h() {
374
+ if (!re(r.value)) {
375
+ if (m.isClearing)
273
376
  return;
274
- E.startClearing(l.value), l.value = void 0, s("change", g.value, void 0), H(() => {
275
- E.endClearing();
377
+ m.startClearing(r.value), r.value = void 0, i("change", E.value, void 0), q(() => {
378
+ m.endClearing();
276
379
  });
277
380
  }
278
381
  }
279
- function x(o) {
280
- E.isClearing || (E.startUserInteraction(), s("change", g.value, o), H(() => {
281
- E.endUserInteraction();
382
+ function F(a) {
383
+ m.isClearing || (m.startUserInteraction(), i("change", E.value, a), q(() => {
384
+ m.endUserInteraction();
282
385
  }));
283
386
  }
284
- const h = f(() => {
285
- const o = qe.getDefaults(t.formItem), i = t.formItem.compAttrs ?? {}, c = "options" in i;
387
+ const d = p(() => {
388
+ const a = Et.getDefaults(t.formItem), u = t.formItem.compAttrs ?? {}, c = "options" in u;
286
389
  return {
287
- ...o,
288
- ...i,
289
- ...T.value,
390
+ ...a,
391
+ ...u,
392
+ ...I.value,
290
393
  ...c && {
291
- options: S.value,
292
- loading: w.value
394
+ options: A.value,
395
+ loading: f.value
293
396
  }
294
397
  };
295
- }), U = (o) => t.formSlots.dynamicComponentSlots.get(o);
296
- async function r(o, i) {
398
+ });
399
+ function z(a) {
400
+ return t.formSlots.dynamicComponentSlots.get(a);
401
+ }
402
+ async function V(a, u) {
297
403
  try {
298
- const c = await o(i);
404
+ const c = await a(u);
299
405
  return Array.isArray(c) ? c : [];
300
406
  } catch (c) {
301
407
  return console.error(`[FormItem] 加载字段 "${t.formItem.prop}" 的选项失败:`, c), [];
302
408
  }
303
409
  }
304
- function a() {
305
- const o = t.formItem.compAttrs?.options;
306
- return $(o) ? o : null;
410
+ function B() {
411
+ const a = t.formItem.compAttrs?.options;
412
+ return ee(a) ? a : null;
307
413
  }
308
- async function u() {
309
- const o = t.formItem.compAttrs?.options;
310
- if (o && !Array.isArray(o)) {
311
- w.value = !0;
414
+ async function P() {
415
+ const a = t.formItem.compAttrs?.options;
416
+ if (a && !Array.isArray(a)) {
417
+ f.value = !0;
312
418
  try {
313
- if (typeof o == "function") {
314
- const i = await r(o, t.formData ?? {});
315
- S.value = i, j(l.value, i) || O();
316
- } else if ($(o)) {
317
- const { loader: i, deps: c = [] } = o, k = t.formData ?? {}, A = Y(c, k, t.formItem.prop), _ = await r(i, { ...k, ...A });
318
- S.value = _, j(l.value, _) || O();
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();
319
425
  }
320
426
  } finally {
321
- w.value = !1;
427
+ f.value = !1;
322
428
  }
323
429
  }
324
430
  }
325
- function C(o) {
326
- S.value = o, j(l.value, o) || O();
431
+ function H(a) {
432
+ A.value = a, te(r.value, a) || h();
327
433
  }
328
- function y() {
329
- u();
434
+ function G() {
435
+ P();
330
436
  }
331
- function M(o) {
332
- const { immediate: i = !1, deps: c = [], loader: k } = o;
437
+ function W(a) {
438
+ const { immediate: u = !1, deps: c = [], loader: b } = a;
333
439
  if (c.length > 0) {
334
- const A = t.formData ?? {}, _ = Y(c, A, t.formItem.prop);
440
+ const O = t.formData ?? {}, R = ie(c, O, t.formItem.prop);
335
441
  try {
336
- k({ ...A, ..._ });
442
+ b({ ...O, ...R });
337
443
  } catch {
338
444
  }
339
- i && u();
445
+ u && P();
340
446
  return;
341
447
  }
342
- i && u();
448
+ u && P();
343
449
  }
344
- const R = f(() => {
345
- const o = a();
346
- return o ? re(o.deps ?? [], t.formItem.prop) : [];
347
- }), le = f(() => {
348
- const o = a();
349
- return o ? o.immediate ?? !1 : !1;
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;
350
456
  });
351
- return G(
457
+ return Q(
352
458
  () => {
353
- const o = R.value, i = {};
354
- for (const c of o)
355
- i[c] = t.formData?.[c];
356
- return i;
459
+ const a = K.value, u = {};
460
+ for (const c of a)
461
+ u[c] = t.formData?.[c];
462
+ return u;
357
463
  },
358
464
  () => {
359
- a() && u();
465
+ B() && P();
360
466
  },
361
- { deep: !0, immediate: le.value }
362
- ), ue(() => {
363
- const o = t.formItem.compAttrs?.options;
364
- if (o) {
365
- if (Array.isArray(o)) {
366
- C(o);
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);
367
473
  return;
368
474
  }
369
- if (typeof o == "function") {
370
- y();
475
+ if (typeof a == "function") {
476
+ G();
371
477
  return;
372
478
  }
373
- $(o) && M(o);
479
+ ee(a) && W(a);
374
480
  }
375
- }), G(
376
- () => l.value,
377
- (o, i) => {
378
- E.isClearingOperation(i, o, z) || E.isUserInteraction || o !== i && s("change", g.value, o);
481
+ }), Q(
482
+ () => r.value,
483
+ (a, u) => {
484
+ m.isClearingOperation(u, a, re) || m.isUserInteraction || a !== u && i("change", E.value, a);
379
485
  }
380
- ), (o, i) => (p(), I(V(ne), te(oe(d.value)), K({
381
- default: b(() => [
382
- e.formItem.comp !== "custom" ? (p(), I(F(v.value), D({ key: 0 }, h.value, {
383
- modelValue: l.value,
384
- "onUpdate:modelValue": i[0] || (i[0] = (c) => l.value = c),
385
- onChange: x
386
- }), K({ _: 2 }, [
387
- B(U(e.formItem.prop) ?? [], (c, k) => ({
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) => ({
388
494
  name: c.slotName,
389
- fn: b((A) => [
390
- (p(), I(F(c.slotFn), D({
391
- value: l.value,
495
+ fn: w((O) => [
496
+ (v(), y(D(c.slotFn), _({
497
+ value: r.value,
392
498
  form: e.formData,
393
499
  "form-item": e.formItem
394
- }, A), null, 16, ["value", "form", "form-item"]))
500
+ }, O), null, 16, ["value", "form", "form-item"]))
395
501
  ])
396
502
  }))
397
- ]), 1040, ["modelValue"])) : me(o.$slots, e.formItem.prop, {
503
+ ]), 1040, ["modelValue"])) : ce(a.$slots, e.formItem.prop, {
398
504
  key: 1,
399
- value: l.value,
505
+ value: r.value,
400
506
  form: e.formData,
401
507
  formItem: e.formItem
402
508
  })
403
509
  ]),
404
510
  _: 2
405
511
  }, [
406
- B(m.value, (c, k) => ({
512
+ j(x.value, (c, b) => ({
407
513
  name: c.slotName,
408
- fn: b((A) => [
409
- (p(), I(F(c.slotFn), D({
410
- value: l.value,
514
+ fn: w((O) => [
515
+ (v(), y(D(c.slotFn), _({
516
+ value: r.value,
411
517
  form: e.formData,
412
518
  "form-item": e.formItem
413
- }, A), null, 16, ["value", "form", "form-item"]))
519
+ }, O), null, 16, ["value", "form", "form-item"]))
414
520
  ])
415
521
  }))
416
522
  ]), 1040));
417
523
  }
418
- }), rt = /* @__PURE__ */ P({
524
+ }), St = /* @__PURE__ */ L({
419
525
  name: "WForm",
420
526
  __name: "Form",
421
- props: {
527
+ props: /* @__PURE__ */ J({
422
528
  formItems: {},
423
529
  rowAttrs: { default: () => ({}) },
424
530
  actionConfig: { default: () => ({}) },
@@ -437,99 +543,223 @@ const et = /* @__PURE__ */ P({
437
543
  validateOnRuleChange: { type: Boolean },
438
544
  scrollToError: { type: Boolean },
439
545
  scrollIntoViewOptions: {}
440
- },
441
- emits: ["validate", "change", "action", "search", "reset", "submit", "cancel"],
442
- setup(e, { expose: n, emit: t }) {
443
- const s = e, l = t, d = fe();
444
- function m(r, a) {
445
- return r.startsWith("on") && typeof a == "function";
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";
446
555
  }
447
- const v = f(() => Object.fromEntries(
448
- Object.entries(d).filter(([r, a]) => m(r, a))
449
- )), g = f(() => {
450
- const { formItems: r, actionConfig: a, rowAttrs: u, ...C } = s, y = Object.fromEntries(
451
- Object.entries(d).filter(([M, R]) => !m(M, R))
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))
452
561
  );
453
- return { ...C, ...Xe, ...y };
454
- }), T = f(() => {
455
- const { span: r } = s?.rowAttrs ?? {};
456
- return s.formItems.filter((a) => X({ condition: a.vIf, data: s.model, defaultValue: !0 })).map((a) => {
457
- const { colAttrs: u = {} } = a ?? {};
458
- return { ...a, colAttrs: { ...u, span: u.span ?? r } };
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);
459
588
  });
460
- }), S = de();
461
- function w(r) {
462
- return Object.keys(S).filter((a) => a.startsWith(r)).map((a) => ({
463
- rawSlotName: a,
464
- slotName: a.replace(r, ""),
465
- slotFn: S[a]
589
+ }
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]
466
612
  }));
467
613
  }
468
- const E = f(() => {
469
- const r = w("form-item-"), a = /* @__PURE__ */ new Map();
470
- for (const u of T.value) {
471
- const C = w(`${u.prop}-`);
472
- C.length > 0 && a.set(u.prop, C);
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);
619
+ }
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;
473
643
  }
474
- return { formItemSlots: r, dynamicComponentSlots: a };
475
- }), O = f(() => Object.keys(s.rowAttrs ?? {}).length > 0), x = f(() => ({
476
- row: g.value.inline || O.value ? Ue : "div",
477
- col: O.value ? Ne : "div"
478
- })), h = L();
479
- async function U({ eventName: r }) {
480
- const a = ["submit", "search"], u = ["cancel", "reset"];
481
- if (![...a, ...u].includes(r))
482
- return l("action", r);
483
- a.includes(r) && await h.value?.validate?.(), u.includes(r) && h.value?.resetFields?.(), l(r), l("action", r);
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);
484
650
  }
485
- return n({
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);
669
+ }
670
+ return s({
486
671
  // element-plus form exposes
487
672
  get fields() {
488
- return h.value?.fields;
673
+ return d.value?.fields;
489
674
  },
490
- getField: (r) => h.value?.getField?.(r),
491
- validate: () => h.value?.validate?.(),
492
- validateField: (r) => h.value?.validateField?.(r),
493
- resetFields: (r) => h.value?.resetFields?.(r),
494
- clearValidate: (r) => h.value?.clearValidate?.(r),
495
- scrollToField: (r) => h.value?.scrollToField?.(r)
496
- }), (r, a) => (p(), I(V(Re), D({
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), _({
497
695
  ref_key: "formRef",
498
- ref: h
499
- }, g.value, {
696
+ ref: d
697
+ }, E.value, {
500
698
  model: e.model,
501
- onValidate: a[1] || (a[1] = (u, C, y) => l("validate", u, C, y)),
502
- onSubmit: a[2] || (a[2] = pe(() => {
699
+ onValidate: Ee,
700
+ onSubmit: o[2] || (o[2] = Me(() => {
503
701
  }, ["prevent"]))
504
702
  }), {
505
- default: b(() => [
506
- (p(), I(F(x.value.row), te(oe(e.rowAttrs)), {
507
- default: b(() => [
508
- (p(!0), N(Z, null, B(T.value, (u, C) => Q((p(), I(F(x.value.col), D({
509
- key: `${u.prop}-${C}`
510
- }, { ref_for: !0 }, u.colAttrs), {
511
- default: b(() => [
512
- q(et, {
513
- modelValue: e.model[u.prop],
514
- "onUpdate:modelValue": (y) => e.model[u.prop] = y,
515
- "form-item": u,
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,
516
742
  "form-data": e.model,
517
- "dynamic-comp-events": v.value,
518
- "form-slots": E.value,
519
- index: C,
520
- onChange: a[0] || (a[0] = (y, M) => l("change", y, M))
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))
521
747
  }, null, 8, ["modelValue", "onUpdate:modelValue", "form-item", "form-data", "dynamic-comp-events", "form-slots", "index"])
522
748
  ]),
523
749
  _: 2
524
750
  }, 1040)), [
525
- [ee, V(X)({ condition: u.vShow, data: s.model, defaultValue: !0 })]
751
+ [oe, S(Z)({ condition: l.vShow, data: i.model, defaultValue: !0 })]
526
752
  ])), 128)),
527
- q(Qe, {
528
- inline: g.value.inline,
529
- "action-slot": r.$slots.action,
753
+ X(At, {
754
+ inline: E.value.inline,
755
+ "action-slot": n.$slots.action,
530
756
  config: e.actionConfig,
531
- onAction: U
532
- }, 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"])
533
763
  ]),
534
764
  _: 1
535
765
  }, 16))
@@ -537,8 +767,8 @@ const et = /* @__PURE__ */ P({
537
767
  _: 1
538
768
  }, 16, ["model"]));
539
769
  }
540
- });
770
+ }), Ft = /* @__PURE__ */ ge(St, [["__scopeId", "data-v-b241f6ca"]]);
541
771
  export {
542
- rt as WForm,
543
- rt as default
772
+ Ft as WForm,
773
+ Ft as default
544
774
  };