@form-create/component-elm-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,365 @@
1
+ /*!
2
+ * FormCreate 低代码表单渲染器
3
+ * @form-create/component-elm-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);
203
+ }
204
+ e.forEach((r, l) => {
205
+ this.setValue(s[l], e[l]);
206
+ });
207
+ }
208
+ }
209
+ },
210
+ methods: {
211
+ _value(e) {
212
+ return e && j(e, this.field) ? e[this.field] : e;
213
+ },
214
+ cache(e, t) {
215
+ this.cacheValue[e] = JSON.stringify(t);
216
+ },
217
+ input(e) {
218
+ this.$emit("input", e), this.$emit("change", e);
219
+ },
220
+ formData(e, t) {
221
+ const s = this.cacheRule, i = this.sort;
222
+ if (i.filter((r) => s[r].$f).length !== i.length)
223
+ return;
224
+ const n = i.map((r) => {
225
+ const l = e === r ? t : h({}, this.cacheRule[r].$f.form), u = this.field ? l[this.field] || null : l;
226
+ return this.cache(r, u), u;
227
+ });
228
+ this.input(n);
229
+ },
230
+ setValue(e, t) {
231
+ const s = this.field, i = this.cacheRule[e].$f;
232
+ s && (t = { [s]: this._value(t) }), this.cacheValue[e] !== JSON.stringify(s ? t[s] : t) && (this.cache(e, t), i && i.coverValue(t || {}));
233
+ },
234
+ addRule(e, t) {
235
+ const s = this.formCreateInject.form.copyRules(this.formRule), i = this.options ? h({}, this.options) : {
236
+ submitBtn: !1,
237
+ resetBtn: !1
238
+ };
239
+ if (this.defaultValue) {
240
+ i.formData || (i.formData = {});
241
+ const n = y(this.defaultValue);
242
+ A(i.formData, this.field ? { [this.field]: n } : n);
243
+ }
244
+ 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));
245
+ },
246
+ add$f(e, t, s) {
247
+ this.cacheRule[t].$f = s, this.$nextTick(() => {
248
+ this.$emit("itemMounted", s, Object.keys(this.cacheRule).indexOf(t));
249
+ });
250
+ },
251
+ removeRule(e, t) {
252
+ const s = Object.keys(this.cacheRule).indexOf(e);
253
+ this.$delete(this.cacheRule, e), this.$delete(this.cacheValue, e), t && this.$nextTick(() => this.$emit("remove", s));
254
+ },
255
+ add(e) {
256
+ this.disabled || this.onBeforeAdd(this.value) === !1 || this.addRule(e, !0);
257
+ },
258
+ del(e, t) {
259
+ if (this.disabled || this.onBeforeRemove(this.value, e) === !1)
260
+ return;
261
+ this.removeRule(t, !0);
262
+ const s = [...this.value];
263
+ s.splice(e, 1), this.input(s);
264
+ },
265
+ addIcon(e) {
266
+ return /* @__PURE__ */ React.createElement("div", { class: "_fc-group-btn _fc-group-plus-minus", "on-click": this.add });
267
+ },
268
+ delIcon(e, t) {
269
+ return /* @__PURE__ */ React.createElement(
270
+ "div",
271
+ {
272
+ class: "_fc-group-btn _fc-group-plus-minus _fc-group-minus",
273
+ onClick: () => this.del(e, t)
274
+ }
275
+ );
276
+ },
277
+ sortUpIcon(e) {
278
+ return /* @__PURE__ */ React.createElement(
279
+ "div",
280
+ {
281
+ class: "_fc-group-btn _fc-group-arrow _fc-group-up",
282
+ onClick: () => this.changeSort(e, -1)
283
+ }
284
+ );
285
+ },
286
+ sortDownIcon(e) {
287
+ return /* @__PURE__ */ React.createElement(
288
+ "div",
289
+ {
290
+ class: "_fc-group-btn _fc-group-arrow _fc-group-down",
291
+ onClick: () => this.changeSort(e, 1)
292
+ }
293
+ );
294
+ },
295
+ changeSort(e, t) {
296
+ const s = this.sort[e];
297
+ this.$set(this.sort, e, this.sort[e + t]), this.sort[e + t] = s, this.formData(0);
298
+ },
299
+ makeIcon(e, t, s) {
300
+ if (this.$scopedSlots.button)
301
+ return this.$scopedSlots.button({
302
+ total: e,
303
+ index: t,
304
+ vm: this,
305
+ key: s,
306
+ del: () => this.del(t, s),
307
+ add: this.add
308
+ });
309
+ const i = [];
310
+ 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;
311
+ },
312
+ emitEvent(e, t, s, i) {
313
+ this.$emit(e, ...t, this.cacheRule[i].$f, s);
314
+ },
315
+ expandRule(e) {
316
+ for (let t = 0; t < e; t++)
317
+ this.value.push(this.field ? null : {});
318
+ }
319
+ },
320
+ created() {
321
+ this.type = this.formCreateInject.form.$form();
322
+ const e = (this.expand || 0) - this.value.length;
323
+ e > 0 && this.expandRule(e);
324
+ for (let t = 0; t < this.value.length; t++)
325
+ this.addRule(t);
326
+ },
327
+ render() {
328
+ const e = this.sort, t = this.button, s = this.type, i = this.disabled, n = e.length === 0 ? this.$scopedSlots.default ? this.$scopedSlots.default({
329
+ vm: this,
330
+ add: this.add
331
+ }) : /* @__PURE__ */ React.createElement(
332
+ "div",
333
+ {
334
+ key: "a_def",
335
+ class: "_fc-group-plus-minus _fc-group-add",
336
+ "on-click": this.add
337
+ }
338
+ ) : e.map((r, l) => {
339
+ const { rule: u, options: b } = this.cacheRule[r], d = t && !i ? this.makeIcon(e.length, l, r) : [];
340
+ return /* @__PURE__ */ React.createElement("div", { class: "_fc-group-container", key: r }, /* @__PURE__ */ React.createElement(
341
+ s,
342
+ {
343
+ key: r,
344
+ on: {
345
+ "update:value": (o) => this.formData(r, o),
346
+ "emit-event": (o, ...R) => this.emitEvent(o, R, l, r),
347
+ input: (o) => this.add$f(l, r, o)
348
+ },
349
+ props: {
350
+ disabled: i,
351
+ inFor: !0,
352
+ value: this.field ? { [this.field]: this._value(this.value[l]) } : this.value[l],
353
+ rule: u,
354
+ option: b,
355
+ extendOption: !0
356
+ }
357
+ }
358
+ ), /* @__PURE__ */ React.createElement("div", { class: "_fc-group-idx" }, l + 1), d.length ? /* @__PURE__ */ React.createElement("div", { class: "_fc-group-handle" }, d) : null);
359
+ });
360
+ return /* @__PURE__ */ React.createElement("div", { key: "con", class: "_fc-group " + (i ? "_fc-group-disabled" : "") }, n);
361
+ }
362
+ };
363
+ export {
364
+ S as default
365
+ };