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

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,71 +1,71 @@
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 { 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({
5
5
  name: "Refresh",
6
6
  __name: "refresh",
7
7
  setup(e) {
8
- return (o, n) => (u(), M("svg", {
8
+ return (n, t) => (p(), N("svg", {
9
9
  xmlns: "http://www.w3.org/2000/svg",
10
10
  viewBox: "0 0 1024 1024"
11
11
  }, [
12
- x("path", {
12
+ J("path", {
13
13
  fill: "currentColor",
14
14
  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
15
  })
16
16
  ]));
17
17
  }
18
- }), we = Se, ke = /* @__PURE__ */ k({
18
+ }), je = $e, Le = /* @__PURE__ */ P({
19
19
  name: "Search",
20
20
  __name: "search",
21
21
  setup(e) {
22
- return (o, n) => (u(), M("svg", {
22
+ return (n, t) => (p(), N("svg", {
23
23
  xmlns: "http://www.w3.org/2000/svg",
24
24
  viewBox: "0 0 1024 1024"
25
25
  }, [
26
- x("path", {
26
+ J("path", {
27
27
  fill: "currentColor",
28
28
  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
29
  })
30
30
  ]));
31
31
  }
32
- }), Fe = ke;
33
- const Pe = ["comp", "compAttrs", "vIf", "vShow"], Me = {
32
+ }), ze = Le;
33
+ const We = ["comp", "compAttrs", "vIf", "vShow"], Ge = {
34
34
  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 = {
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 = {
61
61
  /**
62
62
  * 获取组件默认属性
63
63
  */
64
64
  getDefaults(e) {
65
- const { comp: o, compAttrs: n = {} } = e, s = this.getComponentType(o);
65
+ const { comp: n, compAttrs: t = {} } = e, s = this.getComponentType(n);
66
66
  return {
67
67
  ...this.buildComponentAttrs(e, s),
68
- ...n
68
+ ...t
69
69
  // 用户配置最后合并,优先级最高
70
70
  };
71
71
  },
@@ -73,24 +73,24 @@ const Pe = ["comp", "compAttrs", "vIf", "vShow"], Me = {
73
73
  * 判断组件类型
74
74
  */
75
75
  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";
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";
78
78
  },
79
79
  /**
80
80
  * 动态生成 placeholder
81
81
  */
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}` : "";
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}` : "";
85
85
  },
86
86
  /**
87
87
  * 构建组件属性
88
88
  */
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;
89
+ buildComponentAttrs(e, n) {
90
+ 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;
92
92
  }
93
- }, Ve = {
93
+ }, Xe = {
94
94
  showMessage: !0,
95
95
  scrollToError: !0,
96
96
  scrollIntoViewOptions: {
@@ -101,16 +101,16 @@ const Pe = ["comp", "compAttrs", "vIf", "vShow"], Me = {
101
101
  inline: "nearest"
102
102
  // 水平方向保持最近位置
103
103
  }
104
- }, Be = {
105
- search: { label: "搜索", icon: Fe, type: "primary" },
106
- reset: { label: "重置", icon: we },
104
+ }, Ye = {
105
+ search: { label: "搜索", icon: ze, type: "primary" },
106
+ reset: { label: "重置", icon: je },
107
107
  submit: { label: "确认", type: "primary" },
108
108
  cancel: { label: "取消" }
109
- }, Ne = {
110
- getDefaults(e, o) {
109
+ }, Je = {
110
+ getDefaults(e, n) {
111
111
  return {
112
112
  ...this.buildActionAttrs(e),
113
- ...o
113
+ ...n
114
114
  };
115
115
  },
116
116
  generateActionButtons(e) {
@@ -123,7 +123,7 @@ const Pe = ["comp", "compAttrs", "vIf", "vShow"], Me = {
123
123
  vShow: !0
124
124
  };
125
125
  }
126
- }, xe = /* @__PURE__ */ k({
126
+ }, Qe = /* @__PURE__ */ P({
127
127
  name: "ElementPlusKitFormItemAction",
128
128
  __name: "FormAction",
129
129
  props: {
@@ -133,47 +133,118 @@ const Pe = ["comp", "compAttrs", "vIf", "vShow"], Me = {
133
133
  },
134
134
  emits: ["action"],
135
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;
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) => {
142
+ if (typeof m != "string")
143
+ return m;
144
+ const v = Ye[m];
145
+ return v ? { ...v, eventName: m } : { label: m.toUpperCase(), eventName: m };
144
146
  });
145
- }), p = i(() => (v) => {
146
- const { label: d, eventName: c, ...g } = v;
147
- return { ...g };
148
- });
149
- return (v, d) => n.value.config.vIf ? _((u(), h(w(L), {
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), {
150
152
  key: 0,
151
153
  prop: "action"
152
154
  }, {
153
- default: C(() => [
154
- e.actionSlot ? (u(), h(b(e.actionSlot), {
155
+ default: b(() => [
156
+ e.actionSlot ? (p(), I(F(e.actionSlot), {
155
157
  key: 1,
156
158
  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 })
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 })
161
163
  }), {
162
- default: C(() => [
163
- G(H(c.label ?? ""), 1)
164
+ default: b(() => [
165
+ se(ie(v.label ?? ""), 1)
164
166
  ]),
165
167
  _: 2
166
168
  }, 1040, ["onClick"]))), 128))
167
169
  ]),
168
170
  _: 1
169
171
  }, 512)), [
170
- [R, n.value.config.vShow]
171
- ]) : W("", !0);
172
+ [ee, t.value.config.vShow]
173
+ ]) : ae("", !0);
172
174
  }
173
- }), _e = /* @__PURE__ */ k({
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
+ }
221
+ };
222
+ }
223
+ function re(e, n) {
224
+ if (!e || e.length === 0)
225
+ return [];
226
+ const t = Array.from(new Set(e));
227
+ return n ? t.filter((s) => s !== n) : t;
228
+ }
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;
234
+ }
235
+ function $(e) {
236
+ return e && typeof e == "object" && typeof e.loader == "function";
237
+ }
238
+ function z(e) {
239
+ return e == null || e === "";
240
+ }
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);
243
+ }
244
+ const et = /* @__PURE__ */ P({
174
245
  name: "ElementPlusKitFormItem",
175
246
  __name: "FormItem",
176
- props: /* @__PURE__ */ O({
247
+ props: /* @__PURE__ */ W({
177
248
  formItem: {},
178
249
  index: {},
179
250
  formData: { default: () => ({}) },
@@ -183,65 +254,168 @@ const Pe = ["comp", "compAttrs", "vIf", "vShow"], Me = {
183
254
  modelValue: {},
184
255
  modelModifiers: {}
185
256
  }),
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);
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);
191
261
  return Object.fromEntries(
192
- Object.entries(o.formItem).filter(([f]) => !m.has(f))
262
+ Object.entries(t.formItem).filter(([i]) => !o.has(i))
193
263
  );
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)
268
+ ])
269
+ )), S = L([]), w = L(!1), E = Ze();
270
+ function O() {
271
+ if (!z(l.value)) {
272
+ if (E.isClearing)
273
+ return;
274
+ E.startClearing(l.value), l.value = void 0, s("change", g.value, void 0), H(() => {
275
+ E.endClearing();
276
+ });
277
+ }
194
278
  }
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 };
198
- });
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;
279
+ function x(o) {
280
+ E.isClearing || (E.startUserInteraction(), s("change", g.value, o), H(() => {
281
+ E.endUserInteraction();
282
+ }));
283
+ }
284
+ const h = f(() => {
285
+ const o = qe.getDefaults(t.formItem), i = t.formItem.compAttrs ?? {}, c = "options" in i;
286
+ return {
287
+ ...o,
288
+ ...i,
289
+ ...T.value,
290
+ ...c && {
291
+ options: S.value,
292
+ loading: w.value
293
+ }
294
+ };
295
+ }), U = (o) => t.formSlots.dynamicComponentSlots.get(o);
296
+ async function r(o, i) {
297
+ try {
298
+ const c = await o(i);
299
+ return Array.isArray(c) ? c : [];
300
+ } catch (c) {
301
+ return console.error(`[FormItem] 加载字段 "${t.formItem.prop}" 的选项失败:`, c), [];
302
+ }
303
+ }
304
+ function a() {
305
+ const o = t.formItem.compAttrs?.options;
306
+ return $(o) ? o : null;
307
+ }
308
+ async function u() {
309
+ const o = t.formItem.compAttrs?.options;
310
+ if (o && !Array.isArray(o)) {
311
+ w.value = !0;
312
+ 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();
319
+ }
320
+ } finally {
321
+ w.value = !1;
322
+ }
323
+ }
324
+ }
325
+ function C(o) {
326
+ S.value = o, j(l.value, o) || O();
327
+ }
328
+ function y() {
329
+ u();
204
330
  }
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,
331
+ function M(o) {
332
+ const { immediate: i = !1, deps: c = [], loader: k } = o;
333
+ if (c.length > 0) {
334
+ const A = t.formData ?? {}, _ = Y(c, A, t.formItem.prop);
335
+ try {
336
+ k({ ...A, ..._ });
337
+ } catch {
338
+ }
339
+ i && u();
340
+ return;
341
+ }
342
+ i && u();
343
+ }
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;
350
+ });
351
+ return G(
352
+ () => {
353
+ const o = R.value, i = {};
354
+ for (const c of o)
355
+ i[c] = t.formData?.[c];
356
+ return i;
357
+ },
358
+ () => {
359
+ a() && u();
360
+ },
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);
367
+ return;
368
+ }
369
+ if (typeof o == "function") {
370
+ y();
371
+ return;
372
+ }
373
+ $(o) && M(o);
374
+ }
375
+ }), G(
376
+ () => l.value,
377
+ (o, i) => {
378
+ E.isClearingOperation(i, o, z) || E.isUserInteraction || o !== i && s("change", g.value, o);
379
+ }
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) => ({
388
+ name: c.slotName,
389
+ fn: b((A) => [
390
+ (p(), I(F(c.slotFn), D({
391
+ value: l.value,
218
392
  form: e.formData,
219
393
  "form-item": e.formItem
220
- }, t), null, 16, ["value", "form", "form-item"]))
394
+ }, A), null, 16, ["value", "form", "form-item"]))
221
395
  ])
222
396
  }))
223
- ]), 1040, ["modelValue"])) : X(m.$slots, e.formItem.prop, {
397
+ ]), 1040, ["modelValue"])) : me(o.$slots, e.formItem.prop, {
224
398
  key: 1,
225
- value: n.value,
399
+ value: l.value,
226
400
  form: e.formData,
227
401
  formItem: e.formItem
228
402
  })
229
403
  ]),
230
404
  _: 2
231
405
  }, [
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,
406
+ B(m.value, (c, k) => ({
407
+ name: c.slotName,
408
+ fn: b((A) => [
409
+ (p(), I(F(c.slotFn), D({
410
+ value: l.value,
237
411
  form: e.formData,
238
412
  "form-item": e.formItem
239
- }, t), null, 16, ["value", "form", "form-item"]))
413
+ }, A), null, 16, ["value", "form", "form-item"]))
240
414
  ])
241
415
  }))
242
416
  ]), 1040));
243
417
  }
244
- }), je = /* @__PURE__ */ k({
418
+ }), rt = /* @__PURE__ */ P({
245
419
  name: "WForm",
246
420
  __name: "Form",
247
421
  props: {
@@ -265,97 +439,96 @@ const Pe = ["comp", "compAttrs", "vIf", "vShow"], Me = {
265
439
  scrollIntoViewOptions: {}
266
440
  },
267
441
  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
- )
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";
446
+ }
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))
278
452
  );
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 } };
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 } };
285
459
  });
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;
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]
466
+ }));
296
467
  }
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);
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);
302
473
  }
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);
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);
311
484
  }
312
- return o({
485
+ return n({
313
486
  // element-plus form exposes
314
487
  get fields() {
315
- return a.value?.fields;
488
+ return h.value?.fields;
316
489
  },
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({
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({
324
497
  ref_key: "formRef",
325
- ref: a
326
- }, c.value, {
498
+ ref: h
499
+ }, g.value, {
327
500
  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(() => {
501
+ onValidate: a[1] || (a[1] = (u, C, y) => l("validate", u, C, y)),
502
+ onSubmit: a[2] || (a[2] = pe(() => {
330
503
  }, ["prevent"]))
331
504
  }), {
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,
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,
343
516
  "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))
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))
348
521
  }, null, 8, ["modelValue", "onUpdate:modelValue", "form-item", "form-data", "dynamic-comp-events", "form-slots", "index"])
349
522
  ]),
350
523
  _: 2
351
524
  }, 1040)), [
352
- [R, w(N)({ condition: r.vShow, data: s.model, defaultValue: !0 })]
525
+ [ee, V(X)({ condition: u.vShow, data: s.model, defaultValue: !0 })]
353
526
  ])), 128)),
354
- B(xe, {
355
- inline: c.value.inline,
356
- "action-slot": t.$slots.action,
527
+ q(Qe, {
528
+ inline: g.value.inline,
529
+ "action-slot": r.$slots.action,
357
530
  config: e.actionConfig,
358
- onAction: S
531
+ onAction: U
359
532
  }, null, 8, ["inline", "action-slot", "config"])
360
533
  ]),
361
534
  _: 1
@@ -366,6 +539,6 @@ const Pe = ["comp", "compAttrs", "vIf", "vShow"], Me = {
366
539
  }
367
540
  });
368
541
  export {
369
- je as WForm,
370
- je as default
542
+ rt as WForm,
543
+ rt as default
371
544
  };