@form-create/component-antdv-group 2.5.37 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,363 @@
1
+ /*!
2
+ * FormCreate 低代码表单渲染器
3
+ * @form-create/component-antdv-group v2.6.0
4
+ * (c) 2018-2024 xaboy
5
+ * Github https://github.com/xaboy/form-create
6
+ * Site https://form-create.com/
7
+ * Released under the MIT License.
8
+ */
9
+ (function(){"use strict";try{if(typeof document!="undefined"){var o=document.createElement("style");o.appendChild(document.createTextNode('._fc-group{display:flex;min-height:42px;justify-content:center;flex-direction:column}._fc-group-disabled ._fc-group-btn,._fc-group-disabled ._fc-group-add{cursor:not-allowed}._fc-group-handle{display:flex;flex-direction:row;position:absolute;bottom:-15px;right:30px;border-radius:15px;border:1px dashed #d9d9d9;padding:3px 8px;background-color:#fff}._fc-group-btn{cursor:pointer}._fc-group-idx{position:absolute;bottom:-15px;left:10px;width:30px;height:30px;display:flex;align-items:center;justify-content:center;background:#eee;border-radius:15px;font-weight:700}._fc-group-handle ._fc-group-btn+._fc-group-btn{margin-left:7px}._fc-group-container{position:relative;display:flex;flex-direction:column;border:1px dashed #d9d9d9;padding:20px 20px 25px;margin:5px 5px 25px;border-radius:5px}._fc-group-arrow{position:relative;width:20px;height:20px}._fc-group-arrow:before{content:"";position:absolute;top:8px;left:5px;width:9px;height:9px;border-left:2px solid #999;border-top:2px solid #999}._fc-group-arrow:before{transform:rotate(45deg)}._fc-group-arrow._fc-group-down{transform:rotate(180deg)}._fc-group-plus-minus{width:20px;height:20px;position:relative;cursor:pointer}._fc-group-plus-minus:before,._fc-group-plus-minus:after{content:"";position:absolute;top:50%;left:50%;width:60%;height:2px;background-color:#409eff;transform:translate(-50%,-50%)}._fc-group-plus-minus:before{transform:translate(-50%,-50%) rotate(90deg)}._fc-group-plus-minus._fc-group-minus:before{display:none}._fc-group-plus-minus._fc-group-minus:after{background-color:#f56c6c}._fc-group-add{cursor:pointer;width:25px;height:25px;border:1px solid rgb(64 158 255 / 50%);border-radius:15px}._fc-group-add._fc-group-plus-minus:before,._fc-group-add._fc-group-plus-minus:after{width:50%}')),document.head.appendChild(o)}}catch(r){console.error("vite-plugin-css-injected-by-js",r)}})();
10
+ var g = Object.defineProperty;
11
+ var p = Object.getOwnPropertySymbols;
12
+ var _ = Object.prototype.hasOwnProperty, $ = Object.prototype.propertyIsEnumerable;
13
+ var m = (e, t, s) => t in e ? g(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s, h = (e, t) => {
14
+ for (var s in t || (t = {}))
15
+ _.call(t, s) && m(e, s, t[s]);
16
+ if (p)
17
+ for (var s of p(t))
18
+ $.call(t, s) && m(e, s, t[s]);
19
+ return e;
20
+ };
21
+ import v from "vue";
22
+ const c = {
23
+ type(e, t) {
24
+ return Object.prototype.toString.call(e) === "[object " + t + "]";
25
+ },
26
+ Undef(e) {
27
+ return e == null;
28
+ },
29
+ Element(e) {
30
+ return typeof e == "object" && e !== null && e.nodeType === 1 && !c.Object(e);
31
+ },
32
+ trueArray(e) {
33
+ return Array.isArray(e) && e.length > 0;
34
+ },
35
+ Function(e) {
36
+ const t = this.getType(e);
37
+ return t === "Function" || t === "AsyncFunction";
38
+ },
39
+ getType(e) {
40
+ const t = Object.prototype.toString.call(e);
41
+ return /^\[object (.*)\]$/.exec(t)[1];
42
+ },
43
+ empty(e) {
44
+ return e == null || Array.isArray(e) && Array.isArray(e) && !e.length ? !0 : typeof e == "string" && !e;
45
+ }
46
+ };
47
+ ["Date", "Object", "String", "Boolean", "Array", "Number"].forEach((e) => {
48
+ c[e] = function(t) {
49
+ return c.type(t, e);
50
+ };
51
+ });
52
+ function j(e, t) {
53
+ return {}.hasOwnProperty.call(e, t);
54
+ }
55
+ function a(e, t, s) {
56
+ v.set(e, t, s);
57
+ }
58
+ function f(e, t = {}, s) {
59
+ let i = !1;
60
+ for (let n in t)
61
+ if (Object.prototype.hasOwnProperty.call(t, n)) {
62
+ let r = t[n];
63
+ if ((i = Array.isArray(r)) || c.Object(r)) {
64
+ let l = e[n] === void 0;
65
+ if (i)
66
+ i = !1, l && a(e, n, []);
67
+ else if (r._clone && s !== void 0) {
68
+ a(e, n, r._clone());
69
+ continue;
70
+ } else
71
+ l && a(e, n, {});
72
+ e[n] = f(e[n], r, s);
73
+ } else
74
+ a(e, n, r), c.Undef(r) || (c.Undef(r.__json) || (e[n].__json = r.__json), c.Undef(r.__origin) || (e[n].__origin = r.__origin));
75
+ }
76
+ return e;
77
+ }
78
+ function y(e) {
79
+ return f({}, { value: e }).value;
80
+ }
81
+ const O = Object.assign || function(e) {
82
+ for (let t, s = 1; s < arguments.length; s++)
83
+ for (let i in t = arguments[s], t)
84
+ Object.prototype.hasOwnProperty.call(t, i) && a(e, i, t[i]);
85
+ return e;
86
+ };
87
+ function A() {
88
+ return O.apply(this, arguments);
89
+ }
90
+ const E = "fcGroup", S = {
91
+ name: E,
92
+ props: {
93
+ field: String,
94
+ rule: [Array, Object],
95
+ rules: Array,
96
+ expand: Number,
97
+ options: Object,
98
+ formCreateInject: {
99
+ type: Object,
100
+ required: !0
101
+ },
102
+ button: {
103
+ type: Boolean,
104
+ default: !0
105
+ },
106
+ max: {
107
+ type: Number,
108
+ default: 0
109
+ },
110
+ min: {
111
+ type: Number,
112
+ default: 0
113
+ },
114
+ value: {
115
+ type: Array,
116
+ default: () => []
117
+ },
118
+ sortBtn: {
119
+ type: Boolean,
120
+ default: !0
121
+ },
122
+ defaultValue: Object,
123
+ disabled: {
124
+ type: Boolean,
125
+ default: !1
126
+ },
127
+ syncDisabled: {
128
+ type: Boolean,
129
+ default: !0
130
+ },
131
+ onBeforeRemove: {
132
+ type: Function,
133
+ default: () => {
134
+ }
135
+ },
136
+ onBeforeAdd: {
137
+ type: Function,
138
+ default: () => {
139
+ }
140
+ },
141
+ parse: Function
142
+ },
143
+ data() {
144
+ return {
145
+ len: 0,
146
+ cacheRule: {},
147
+ cacheValue: {},
148
+ sort: [],
149
+ type: void 0
150
+ };
151
+ },
152
+ computed: {
153
+ formRule() {
154
+ return this.rules ? this.rules : this.rule ? Array.isArray(this.rule) ? this.rule : [this.rule] : [];
155
+ }
156
+ },
157
+ watch: {
158
+ cacheRule: {
159
+ handler(e) {
160
+ this.sort = Object.keys(e);
161
+ },
162
+ immediate: !0
163
+ },
164
+ formRule: {
165
+ handler(e, t) {
166
+ Object.keys(this.cacheRule).forEach((s) => {
167
+ const i = this.cacheRule[s];
168
+ if (i.$f) {
169
+ const n = i.$f.formData();
170
+ if (e === t)
171
+ i.$f.deferSyncValue(() => {
172
+ f(i.rule, e), i.$f.setValue(n);
173
+ }, !0);
174
+ else {
175
+ const r = i.$f.formData();
176
+ i.$f.once("reloading", () => {
177
+ i.$f.setValue(r);
178
+ }), i.rule = y(e);
179
+ }
180
+ }
181
+ });
182
+ },
183
+ deep: !0
184
+ },
185
+ expand(e) {
186
+ let t = e - this.value.length;
187
+ t > 0 && this.expandRule(t);
188
+ },
189
+ value(e, t) {
190
+ e = e || [];
191
+ let s = this.sort, i = s.length, n = i - e.length;
192
+ if (n < 0) {
193
+ for (let r = n; r < 0; r++)
194
+ this.addRule(e.length + r);
195
+ this.sort = Object.keys(this.cacheRule);
196
+ for (let r = 0; r < i; r++)
197
+ this.setValue(s[r], e[r]);
198
+ } else {
199
+ if (n > 0)
200
+ for (let r = 0; r < n; r++)
201
+ this.removeRule(s[i - r - 1]);
202
+ this.sort = Object.keys(this.cacheRule), e.forEach((r, l) => {
203
+ this.setValue(s[l], e[l]);
204
+ });
205
+ }
206
+ }
207
+ },
208
+ methods: {
209
+ _value(e) {
210
+ return e && j(e, this.field) ? e[this.field] : e;
211
+ },
212
+ cache(e, t) {
213
+ this.cacheValue[e] = JSON.stringify(t);
214
+ },
215
+ input(e) {
216
+ this.$emit("input", e), this.$emit("change", e);
217
+ },
218
+ formData(e, t) {
219
+ const s = this.cacheRule, i = this.sort;
220
+ if (i.filter((r) => s[r].$f).length !== i.length)
221
+ return;
222
+ const n = i.map((r) => {
223
+ const l = e === r ? t : h({}, this.cacheRule[r].$f.form), u = this.field ? l[this.field] || null : l;
224
+ return this.cache(r, u), u;
225
+ });
226
+ this.input(n);
227
+ },
228
+ setValue(e, t) {
229
+ const s = this.field, i = this.cacheRule[e].$f;
230
+ s && (t = { [s]: this._value(t) }), this.cacheValue[e] !== JSON.stringify(s ? t[s] : t) && (this.cache(e, t), i && i.coverValue(t || {}));
231
+ },
232
+ addRule(e, t) {
233
+ const s = this.formCreateInject.form.copyRules(this.formRule), i = this.options ? h({}, this.options) : {
234
+ submitBtn: !1,
235
+ resetBtn: !1
236
+ };
237
+ if (this.defaultValue) {
238
+ i.formData || (i.formData = {});
239
+ const n = y(this.defaultValue);
240
+ A(i.formData, this.field ? { [this.field]: n } : n);
241
+ }
242
+ this.parse && this.parse({ rule: s, options: i, index: this.sort.length }), this.$set(this.cacheRule, ++this.len, { rule: s, options: i }), t && this.$nextTick(() => this.$emit("add", s, Object.keys(this.cacheRule).length - 1));
243
+ },
244
+ add$f(e, t, s) {
245
+ this.cacheRule[t].$f = s, this.$nextTick(() => {
246
+ this.$emit("itemMounted", s, Object.keys(this.cacheRule).indexOf(t));
247
+ });
248
+ },
249
+ removeRule(e, t) {
250
+ const s = Object.keys(this.cacheRule).indexOf(e);
251
+ this.$delete(this.cacheRule, e), this.$delete(this.cacheValue, e), t && this.$nextTick(() => this.$emit("remove", s));
252
+ },
253
+ add(e) {
254
+ this.disabled || this.onBeforeAdd(this.value) === !1 || this.addRule(e, !0);
255
+ },
256
+ del(e, t) {
257
+ if (this.disabled || this.onBeforeRemove(this.value, e) === !1)
258
+ return;
259
+ this.removeRule(t, !0);
260
+ const s = [...this.value];
261
+ s.splice(e, 1), this.input(s);
262
+ },
263
+ addIcon(e) {
264
+ return /* @__PURE__ */ React.createElement("div", { class: "_fc-group-btn _fc-group-plus-minus", "on-click": this.add });
265
+ },
266
+ delIcon(e, t) {
267
+ return /* @__PURE__ */ React.createElement(
268
+ "div",
269
+ {
270
+ class: "_fc-group-btn _fc-group-plus-minus _fc-group-minus",
271
+ onClick: () => this.del(e, t)
272
+ }
273
+ );
274
+ },
275
+ sortUpIcon(e) {
276
+ return /* @__PURE__ */ React.createElement(
277
+ "div",
278
+ {
279
+ class: "_fc-group-btn _fc-group-arrow _fc-group-up",
280
+ onClick: () => this.changeSort(e, -1)
281
+ }
282
+ );
283
+ },
284
+ sortDownIcon(e) {
285
+ return /* @__PURE__ */ React.createElement(
286
+ "div",
287
+ {
288
+ class: "_fc-group-btn _fc-group-arrow _fc-group-down",
289
+ onClick: () => this.changeSort(e, 1)
290
+ }
291
+ );
292
+ },
293
+ changeSort(e, t) {
294
+ const s = this.sort[e];
295
+ this.$set(this.sort, e, this.sort[e + t]), this.sort[e + t] = s, this.formData(0);
296
+ },
297
+ makeIcon(e, t, s) {
298
+ if (this.$scopedSlots.button)
299
+ return this.$scopedSlots.button({
300
+ total: e,
301
+ index: t,
302
+ vm: this,
303
+ key: s,
304
+ del: () => this.del(t, s),
305
+ add: this.add
306
+ });
307
+ const i = [];
308
+ return (!this.max || e < this.max) && e === t + 1 && i.push(this.addIcon(s)), e > this.min && i.push(this.delIcon(t, s)), this.sortBtn && t && i.push(this.sortUpIcon(t)), this.sortBtn && t !== e - 1 && i.push(this.sortDownIcon(t)), i;
309
+ },
310
+ emitEvent(e, t, s, i) {
311
+ this.$emit(e, ...t, this.cacheRule[i].$f, s);
312
+ },
313
+ expandRule(e) {
314
+ for (let t = 0; t < e; t++)
315
+ this.value.push(this.field ? null : {});
316
+ }
317
+ },
318
+ created() {
319
+ this.type = this.formCreateInject.form.$form();
320
+ const e = (this.expand || 0) - this.value.length;
321
+ e > 0 && this.expandRule(e);
322
+ for (let t = 0; t < this.value.length; t++)
323
+ this.addRule(t);
324
+ },
325
+ render() {
326
+ const e = this.sort, t = this.button, s = this.type, i = this.disabled, n = e.length === 0 ? this.$scopedSlots.default ? this.$scopedSlots.default({
327
+ vm: this,
328
+ add: this.add
329
+ }) : /* @__PURE__ */ React.createElement(
330
+ "div",
331
+ {
332
+ key: "a_def",
333
+ class: "_fc-group-plus-minus _fc-group-add",
334
+ "on-click": this.add
335
+ }
336
+ ) : e.map((r, l) => {
337
+ const { rule: u, options: b } = this.cacheRule[r], d = t && !i ? this.makeIcon(e.length, l, r) : [];
338
+ return /* @__PURE__ */ React.createElement("div", { class: "_fc-group-container", key: r }, /* @__PURE__ */ React.createElement(
339
+ s,
340
+ {
341
+ key: r,
342
+ on: {
343
+ "update:value": (o) => this.formData(r, o),
344
+ "emit-event": (o, ...R) => this.emitEvent(o, R, l, r),
345
+ input: (o) => this.add$f(l, r, o)
346
+ },
347
+ props: {
348
+ disabled: i,
349
+ inFor: !0,
350
+ value: this.field ? { [this.field]: this._value(this.value[l]) } : this.value[l],
351
+ rule: u,
352
+ option: b,
353
+ extendOption: !0
354
+ }
355
+ }
356
+ ), /* @__PURE__ */ React.createElement("div", { class: "_fc-group-idx" }, l + 1), d.length ? /* @__PURE__ */ React.createElement("div", { class: "_fc-group-handle" }, d) : null);
357
+ });
358
+ return /* @__PURE__ */ React.createElement("div", { key: "con", class: "_fc-group " + (i ? "_fc-group-disabled" : "") }, n);
359
+ }
360
+ };
361
+ export {
362
+ S as default
363
+ };