aloha-vue 2.59.0 → 2.60.1

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.
@@ -1,606 +1,614 @@
1
- import {
2
- computed,
3
- h,
4
- onBeforeUnmount,
5
- onMounted,
6
- toRef,
7
- } from "vue";
8
-
9
- import AButton from "../AButton/AButton";
10
- import ARequired from "../ui/ARequired/ARequired";
11
- import ATableFormRow from "./ATableFormRow/ATableFormRow";
12
- import ATranslation from "../ATranslation/ATranslation";
13
-
14
- import ClassesAPI from "./compositionAPI/ClassesAPI";
15
- import ColumnsAPI from "./compositionAPI/ColumnsAPI";
16
- import ColumnsGrowAPI from "./compositionAPI/ColumnsGrowAPI";
17
- import DeleteAPI from "./compositionAPI/DeleteAPI";
18
- import DragAndDropAPI from "./compositionAPI/DragAndDropAPI";
19
- import EditAPI from "./compositionAPI/EditAPI";
20
- import IconsAPI from "./compositionAPI/IconsAPI";
21
- import RowsAPI from "./compositionAPI/RowsAPI";
22
- import TextsAPI from "./compositionAPI/TextsAPI";
23
- import WidthsAPI from "./compositionAPI/WidthsAPI";
24
-
25
- import ExclamationCircleFill from "aloha-svg/dist/js/bootstrap/ExclamationCircleFill";
26
- import {
27
- get,
28
- isFunction,
29
- uniqueId,
30
- } from "lodash-es";
31
-
32
- export default {
33
- name: "ATableForm",
34
- props: {
35
- actionsClasses: {
36
- type: Object,
37
- required: false,
38
- default: () => ({}),
39
- },
40
- actionsDisabledCallback: {
41
- type: Object,
42
- required: false,
43
- default: () => ({}),
44
- },
45
- actionsHideCallback: {
46
- type: Object,
47
- required: false,
48
- default: () => ({}),
49
- },
50
- actionsTitleCallback: {
51
- type: Object,
52
- required: false,
53
- default: () => ({}),
54
- },
55
- addRow: {
56
- type: Function,
57
- required: false,
58
- default: undefined,
59
- },
60
- columns: {
61
- type: Array,
62
- required: true,
63
- },
64
- columnsDefaultValue: {
65
- type: [String, Number],
66
- required: false,
67
- default: "",
68
- },
69
- changeModel: {
70
- type: Function,
71
- required: false,
72
- default: undefined,
73
- },
74
- errorIcon: {
75
- type: String,
76
- required: false,
77
- default: ExclamationCircleFill,
78
- },
79
- extra: {
80
- type: Object,
81
- required: false,
82
- default: undefined,
83
- },
84
- focusAfterMove: {
85
- type: Boolean,
86
- required: false,
87
- default: true,
88
- },
89
- icons: {
90
- type: Object,
91
- required: false,
92
- default: () => ({}),
93
- },
94
- id: {
95
- type: String,
96
- required: false,
97
- default: () => uniqueId("a_table_form_"),
98
- },
99
- isActionsSticky: {
100
- type: Boolean,
101
- required: false,
102
- default: false,
103
- },
104
- isAddable: {
105
- type: Boolean,
106
- required: false,
107
- default: false,
108
- },
109
- isColumnsGrow: {
110
- type: Boolean,
111
- required: false,
112
- default: false,
113
- },
114
- isDeletable: {
115
- type: Boolean,
116
- required: false,
117
- default: false,
118
- },
119
- isDeletableConfirm: {
120
- type: Boolean,
121
- required: false,
122
- default: false,
123
- },
124
- isDragAndDrop: {
125
- type: Boolean,
126
- required: false,
127
- default: false,
128
- },
129
- isEditable: {
130
- type: Boolean,
131
- required: false,
132
- default: false,
133
- },
134
- keyId: {
135
- type: String,
136
- required: false,
137
- default: undefined,
138
- },
139
- label: {
140
- type: [String, Number],
141
- required: false,
142
- default: "",
143
- },
144
- labelClass: {
145
- type: [String, Object, Array],
146
- required: false,
147
- default: undefined,
148
- },
149
- labelTag: {
150
- type: String,
151
- required: false,
152
- default: "h2",
153
- },
154
- prepareEditModel: {
155
- type: Function,
156
- required: false,
157
- default: undefined,
158
- },
159
- rowClass: {
160
- type: [String, Object, Array, Function],
161
- required: false,
162
- default: undefined,
163
- },
164
- rows: {
165
- type: Array,
166
- required: false,
167
- default: () => [],
168
- },
169
- rowsFooter: {
170
- type: Array,
171
- required: false,
172
- default: () => [],
173
- },
174
- saveRow: {
175
- type: Function,
176
- required: false,
177
- default: () => undefined,
178
- },
179
- texts: {
180
- type: Object,
181
- required: false,
182
- default: () => ({}),
183
- },
184
- widths: {
185
- type: Object,
186
- required: false,
187
- default: () => ({}),
188
- },
189
- },
190
- emits: [
191
- "deleteRow",
192
- "moveRow",
193
- "updateRows",
194
- ],
195
- setup(props, context) {
196
- const actionsDisabledCallback = toRef(props, "actionsDisabledCallback");
197
- const actionsTitleCallback = toRef(props, "actionsTitleCallback");
198
-
199
- const {
200
- allColumnsLength,
201
- columnsVisible,
202
- hasActionsColumn,
203
- } = ColumnsAPI(props);
204
-
205
- const {
206
- getRowKey,
207
- hasRows,
208
- hasRowsFooter,
209
- } = RowsAPI(props);
210
-
211
- const {
212
- textsLocal,
213
- } = TextsAPI(props);
214
-
215
- const {
216
- widthsLocal,
217
- } = WidthsAPI(props);
218
-
219
- const {
220
- iconsLocal,
221
- } = IconsAPI(props);
222
-
223
- const {
224
- actionsClassesLocal,
225
- } = ClassesAPI(props);
226
-
227
- const {
228
- columnsStylesGrow,
229
- destroyColumnsGrowObserver,
230
- initColumnsGrowObserver,
231
- } = ColumnsGrowAPI(props, {
232
- columnsVisible,
233
- hasActionsColumn,
234
- widthsLocal,
235
- });
236
-
237
- onMounted(() => {
238
- initColumnsGrowObserver();
239
- });
240
-
241
- onBeforeUnmount(() => {
242
- destroyColumnsGrowObserver();
243
- });
244
-
245
- const {
246
- activeEditRowKey,
247
- activeEditModel,
248
- canAddRow,
249
- hasActiveEditRow,
250
- hasRequiredEditableColumns,
251
- isAddRowActive,
252
- onAddRow,
253
- onCancelEditRow,
254
- onEditRow,
255
- } = EditAPI(props, {
256
- columnsVisible,
257
- getRowKey,
258
- });
259
-
260
- const {
261
- canMoveRowDown,
262
- canMoveRowUp,
263
- dragOverPosition,
264
- dragOverRowIndex,
265
- draggedRowIndex,
266
- moveRowDown,
267
- moveRowUp,
268
- onDragend,
269
- onDragleave,
270
- onDragover,
271
- onDragstart,
272
- onDrop,
273
- } = DragAndDropAPI(props, context, {
274
- isDndDisabled: hasActiveEditRow,
275
- });
276
-
277
- const {
278
- onDeleteRow,
279
- } = DeleteAPI(props, context);
280
-
281
- const isAddDisabled = computed(() => {
282
- if (hasActiveEditRow.value) {
283
- return true;
284
- }
285
-
286
- const addDisabledCallback = get(actionsDisabledCallback.value, "add");
287
-
288
- if (isFunction(addDisabledCallback)) {
289
- return addDisabledCallback();
290
- }
291
-
292
- return false;
293
- });
294
-
295
- const addTitle = computed(() => {
296
- const addTitleCallback = get(actionsTitleCallback.value, "add");
297
-
298
- if (isFunction(addTitleCallback)) {
299
- return addTitleCallback();
300
- }
301
-
302
- return textsLocal.value.actionAddRow;
303
- });
304
-
305
- return {
306
- activeEditRowKey,
307
- activeEditModel,
308
- allColumnsLength,
309
- addTitle,
310
- canAddRow,
311
- canMoveRowDown,
312
- canMoveRowUp,
313
- actionsClassesLocal,
314
- columnsStylesGrow,
315
- columnsVisible,
316
- draggedRowIndex,
317
- dragOverPosition,
318
- dragOverRowIndex,
319
- getRowKey,
320
- hasActionsColumn,
321
- hasActiveEditRow,
322
- hasRequiredEditableColumns,
323
- hasRows,
324
- hasRowsFooter,
325
- iconsLocal,
326
- isAddDisabled,
327
- isAddRowActive,
328
- moveRowDown,
329
- moveRowUp,
330
- onAddRow,
331
- onCancelEditRow,
332
- onDeleteRow,
333
- onDragend,
334
- onDragleave,
335
- onDragover,
336
- onDragstart,
337
- onDrop,
338
- onEditRow,
339
- textsLocal,
340
- widthsLocal,
341
- };
342
- },
343
- render() {
344
- return h("div", {
345
- class: "a_table_form",
346
- }, [
347
- this.label && h(ATranslation, {
348
- class: [
349
- "a_table_form__label",
350
- this.labelClass,
351
- ],
352
- html: this.label,
353
- tag: this.labelTag,
354
- }),
355
- this.hasRequiredEditableColumns && h(ARequired),
356
- h("div", {
357
- class: "a_table_form__wrapper",
358
- }, [
359
- h("table", {
360
- id: this.id,
361
- class: [
362
- "a_table_form__table",
363
- {
364
- a_table_form_drag_active: this.draggedRowIndex !== undefined,
365
- },
366
- ],
367
- }, [
368
- h("thead", {
369
- class: "a_table_form__head",
370
- }, [
371
- h(ATableFormRow, {
372
- id: this.id,
373
- actionsClasses: this.actionsClasses,
374
- actionsDisabledCallback: this.actionsDisabledCallback,
375
- actionsHideCallback: this.actionsHideCallback,
376
- actionsTitleCallback: this.actionsTitleCallback,
377
- allColumnsLength: this.allColumnsLength,
378
- canMoveRowDown: this.canMoveRowDown,
379
- canMoveRowUp: this.canMoveRowUp,
380
- cellTag: "th",
381
- changeModel: this.changeModel,
382
- columns: this.columnsVisible,
383
- columnsStylesGrow: this.columnsStylesGrow,
384
- draggedRowIndex: this.draggedRowIndex,
385
- extra: this.extra,
386
- hasActionsColumn: this.hasActionsColumn,
387
- hasActiveEditRow: false,
388
- isActionsSticky: this.isActionsSticky,
389
- isActiveEditMode: false,
390
- isDeletable: this.isDeletable,
391
- isDeletableConfirm: this.isDeletableConfirm,
392
- isDndDisabled: this.hasActiveEditRow,
393
- isDragAndDrop: this.isDragAndDrop,
394
- isEditable: this.isEditable,
395
- isHeader: true,
396
- moveRowDown: this.moveRowDown,
397
- moveRowUp: this.moveRowUp,
398
- onCancelEditRow: this.onCancelEditRow,
399
- onDeleteRow: this.onDeleteRow,
400
- onDragend: this.onDragend,
401
- onDragstart: this.onDragstart,
402
- onEditRow: this.onEditRow,
403
- row: {},
404
- rowIndex: 0,
405
- rows: this.rows,
406
- saveRow: this.saveRow,
407
- texts: this.textsLocal,
408
- trClass: "a_table_form__row a_table_form__row_head",
409
- widths: this.widthsLocal,
410
- }, this.$slots),
411
- ]),
412
- h("tbody", {
413
- class: "a_table_form__body",
414
- }, this.hasRows || this.isAddRowActive ?
415
- [
416
- ...this.rows.map((row, rowIndex) => {
417
- const rowKey = this.getRowKey({
418
- row,
419
- rowIndex,
420
- });
421
-
422
- return h(ATableFormRow, {
423
- key: rowKey,
424
- id: this.id,
425
- actionsClasses: this.actionsClassesLocal,
426
- actionsDisabledCallback: this.actionsDisabledCallback,
427
- actionsHideCallback: this.actionsHideCallback,
428
- actionsTitleCallback: this.actionsTitleCallback,
429
- allColumnsLength: this.allColumnsLength,
430
- canMoveRowDown: this.canMoveRowDown,
431
- canMoveRowUp: this.canMoveRowUp,
432
- changeModel: this.changeModel,
433
- columns: this.columnsVisible,
434
- columnsStylesGrow: this.columnsStylesGrow,
435
- draggedRowIndex: this.draggedRowIndex,
436
- editModel: this.activeEditRowKey === rowKey ? this.activeEditModel : undefined,
437
- errorIcon: this.errorIcon,
438
- extra: this.extra,
439
- hasActionsColumn: this.hasActionsColumn,
440
- hasActiveEditRow: this.hasActiveEditRow,
441
- isActionsSticky: this.isActionsSticky,
442
- isActiveEditMode: this.activeEditRowKey === rowKey,
443
- isCreateMode: false,
444
- isDeletable: this.isDeletable,
445
- isDeletableConfirm: this.isDeletableConfirm,
446
- isDndDisabled: this.hasActiveEditRow,
447
- isDragAndDrop: this.isDragAndDrop,
448
- isEditable: this.isEditable,
449
- moveRowDown: this.moveRowDown,
450
- moveRowUp: this.moveRowUp,
451
- onCancelEditRow: this.onCancelEditRow,
452
- onDeleteRow: this.onDeleteRow,
453
- onDragend: this.onDragend,
454
- onDragleave: this.onDragleave,
455
- onDragover: this.onDragover,
456
- onDragstart: this.onDragstart,
457
- onDrop: this.onDrop,
458
- onEditRow: this.onEditRow,
459
- row,
460
- rowClass: this.rowClass,
461
- rowIndex,
462
- rows: this.rows,
463
- saveRow: this.saveRow,
464
- texts: this.textsLocal,
465
- widths: this.widthsLocal,
466
- trClass: [
467
- "a_table_form__row",
468
- {
469
- a_table_form__row_drag_after: this.dragOverRowIndex === rowIndex &&
470
- this.dragOverPosition === "after",
471
- a_table_form__row_drag_before: this.dragOverRowIndex === rowIndex &&
472
- this.dragOverPosition === "before",
473
- a_table_form__row_drag_over: this.dragOverRowIndex === rowIndex,
474
- a_table_form__row_dragging: this.draggedRowIndex === rowIndex,
475
- },
476
- ],
477
- }, this.$slots);
478
- }),
479
- this.isAddRowActive && h(ATableFormRow, {
480
- id: this.id,
481
- actionsClasses: this.actionsClassesLocal,
482
- actionsDisabledCallback: this.actionsDisabledCallback,
483
- actionsHideCallback: this.actionsHideCallback,
484
- actionsTitleCallback: this.actionsTitleCallback,
485
- allColumnsLength: this.allColumnsLength,
486
- canMoveRowDown: this.canMoveRowDown,
487
- canMoveRowUp: this.canMoveRowUp,
488
- changeModel: this.changeModel,
489
- columns: this.columnsVisible,
490
- columnsStylesGrow: this.columnsStylesGrow,
491
- draggedRowIndex: this.draggedRowIndex,
492
- editModel: this.activeEditModel,
493
- errorIcon: this.errorIcon,
494
- extra: this.extra,
495
- hasActionsColumn: this.hasActionsColumn,
496
- hasActiveEditRow: this.hasActiveEditRow,
497
- isActionsSticky: this.isActionsSticky,
498
- isActiveEditMode: true,
499
- isCreateMode: true,
500
- isDeletable: false,
501
- isDeletableConfirm: false,
502
- isDndDisabled: true,
503
- isDragAndDrop: this.isDragAndDrop,
504
- isEditable: this.isEditable,
505
- key: "body_create",
506
- moveRowDown: this.moveRowDown,
507
- moveRowUp: this.moveRowUp,
508
- onCancelEditRow: this.onCancelEditRow,
509
- onDeleteRow: this.onDeleteRow,
510
- onDragend: this.onDragend,
511
- onDragleave: this.onDragleave,
512
- onDragover: this.onDragover,
513
- onDragstart: this.onDragstart,
514
- onDrop: this.onDrop,
515
- onEditRow: this.onEditRow,
516
- row: {},
517
- rowClass: this.rowClass,
518
- rowIndex: this.rows.length,
519
- rows: this.rows,
520
- saveRow: this.addRow,
521
- texts: this.textsLocal,
522
- trClass: "a_table_form__row a_table_form__row_create",
523
- widths: this.widthsLocal,
524
- }, this.$slots),
525
- ] :
526
- [h("tr", {
527
- class: "a_table_form__row a_table_form__row_empty",
528
- }, [
529
- h("td", {
530
- class: "a_table_form__cell a_table_form__empty",
531
- colspan: this.allColumnsLength,
532
- }, [
533
- h(ATranslation, {
534
- tag: "span",
535
- text: this.textsLocal.emptyText,
536
- }),
537
- ]),
538
- ])]),
539
- this.hasRowsFooter && h("tfoot", {
540
- class: "a_table_form__foot",
541
- }, this.rowsFooter.map((row, rowIndex) => {
542
- return h(ATableFormRow, {
543
- id: this.id,
544
- actionsClasses: this.actionsClassesLocal,
545
- actionsDisabledCallback: this.actionsDisabledCallback,
546
- actionsHideCallback: this.actionsHideCallback,
547
- actionsTitleCallback: this.actionsTitleCallback,
548
- allColumnsLength: this.allColumnsLength,
549
- canMoveRowDown: this.canMoveRowDown,
550
- canMoveRowUp: this.canMoveRowUp,
551
- changeModel: this.changeModel,
552
- columns: this.columnsVisible,
553
- columnsStylesGrow: this.columnsStylesGrow,
554
- draggedRowIndex: this.draggedRowIndex,
555
- extra: this.extra,
556
- hasActionsColumn: this.hasActionsColumn,
557
- hasActiveEditRow: this.hasActiveEditRow,
558
- isActionsSticky: this.isActionsSticky,
559
- isActiveEditMode: false,
560
- isDeletable: this.isDeletable,
561
- isDeletableConfirm: this.isDeletableConfirm,
562
- isDndDisabled: this.hasActiveEditRow,
563
- isDragAndDrop: this.isDragAndDrop,
564
- isEditable: this.isEditable,
565
- isFooter: true,
566
- key: this.getRowKey({
567
- isFooter: true,
568
- row,
569
- rowIndex,
570
- }),
571
- moveRowDown: this.moveRowDown,
572
- moveRowUp: this.moveRowUp,
573
- onCancelEditRow: this.onCancelEditRow,
574
- onDeleteRow: this.onDeleteRow,
575
- onDragend: this.onDragend,
576
- onDragstart: this.onDragstart,
577
- onEditRow: this.onEditRow,
578
- row,
579
- rowClass: this.rowClass,
580
- rowIndex,
581
- rows: this.rowsFooter,
582
- saveRow: this.saveRow,
583
- texts: this.textsLocal,
584
- widths: this.widthsLocal,
585
- trClass: "a_table_form__row a_table_form__row_footer",
586
- }, this.$slots);
587
- })),
588
- ]),
589
- ]),
590
- this.canAddRow && h("div", {
591
- class: "a_mt_3 a_text_right",
592
- }, [
593
- h(AButton, {
594
- class: this.actionsClassesLocal.addRow,
595
- disabled: this.isAddDisabled,
596
- extra: this.extra,
597
- iconLeft: this.iconsLocal.actionAddRow,
598
- text: this.textsLocal.actionAddRow,
599
- textScreenReader: this.addTitle,
600
- title: this.addTitle,
601
- onClick: this.onAddRow,
602
- }),
603
- ]),
604
- ]);
605
- },
606
- };
1
+ import {
2
+ computed,
3
+ h,
4
+ onBeforeUnmount,
5
+ onMounted,
6
+ toRef,
7
+ } from "vue";
8
+
9
+ import AButton from "../AButton/AButton";
10
+ import ARequired from "../ui/ARequired/ARequired";
11
+ import ATableFormRow from "./ATableFormRow/ATableFormRow";
12
+ import ATranslation from "../ATranslation/ATranslation";
13
+
14
+ import ClassesAPI from "./compositionAPI/ClassesAPI";
15
+ import ColumnsAPI from "./compositionAPI/ColumnsAPI";
16
+ import ColumnsGrowAPI from "./compositionAPI/ColumnsGrowAPI";
17
+ import DeleteAPI from "./compositionAPI/DeleteAPI";
18
+ import DragAndDropAPI from "./compositionAPI/DragAndDropAPI";
19
+ import EditAPI from "./compositionAPI/EditAPI";
20
+ import IconsAPI from "./compositionAPI/IconsAPI";
21
+ import RowsAPI from "./compositionAPI/RowsAPI";
22
+ import TextsAPI from "./compositionAPI/TextsAPI";
23
+ import WidthsAPI from "./compositionAPI/WidthsAPI";
24
+
25
+ import ExclamationCircleFill from "aloha-svg/dist/js/bootstrap/ExclamationCircleFill";
26
+ import {
27
+ get,
28
+ isFunction,
29
+ uniqueId,
30
+ } from "lodash-es";
31
+
32
+ export default {
33
+ name: "ATableForm",
34
+ props: {
35
+ actionsClasses: {
36
+ type: Object,
37
+ required: false,
38
+ default: () => ({}),
39
+ },
40
+
41
+ /*
42
+ * Supported callbacks:
43
+ * add: () => boolean
44
+ * delete, dnd, edit: ({ row, rowIndex }) => boolean
45
+ */
46
+ actionsDisabledCallback: {
47
+ type: Object,
48
+ required: false,
49
+ default: () => ({}),
50
+ },
51
+ actionsHideCallback: {
52
+ type: Object,
53
+ required: false,
54
+ default: () => ({}),
55
+ },
56
+ actionsTitleCallback: {
57
+ type: Object,
58
+ required: false,
59
+ default: () => ({}),
60
+ },
61
+ addRow: {
62
+ type: Function,
63
+ required: false,
64
+ default: undefined,
65
+ },
66
+ columns: {
67
+ type: Array,
68
+ required: true,
69
+ },
70
+ columnsDefaultValue: {
71
+ type: [String, Number],
72
+ required: false,
73
+ default: "",
74
+ },
75
+ changeModel: {
76
+ type: Function,
77
+ required: false,
78
+ default: undefined,
79
+ },
80
+ errorIcon: {
81
+ type: String,
82
+ required: false,
83
+ default: ExclamationCircleFill,
84
+ },
85
+ extra: {
86
+ type: Object,
87
+ required: false,
88
+ default: undefined,
89
+ },
90
+ focusAfterMove: {
91
+ type: Boolean,
92
+ required: false,
93
+ default: true,
94
+ },
95
+ icons: {
96
+ type: Object,
97
+ required: false,
98
+ default: () => ({}),
99
+ },
100
+ id: {
101
+ type: String,
102
+ required: false,
103
+ default: () => uniqueId("a_table_form_"),
104
+ },
105
+ isActionsSticky: {
106
+ type: Boolean,
107
+ required: false,
108
+ default: false,
109
+ },
110
+ isAddable: {
111
+ type: Boolean,
112
+ required: false,
113
+ default: false,
114
+ },
115
+ isColumnsGrow: {
116
+ type: Boolean,
117
+ required: false,
118
+ default: false,
119
+ },
120
+ isDeletable: {
121
+ type: Boolean,
122
+ required: false,
123
+ default: false,
124
+ },
125
+ isDeletableConfirm: {
126
+ type: Boolean,
127
+ required: false,
128
+ default: false,
129
+ },
130
+ isDragAndDrop: {
131
+ type: Boolean,
132
+ required: false,
133
+ default: false,
134
+ },
135
+ isEditable: {
136
+ type: Boolean,
137
+ required: false,
138
+ default: false,
139
+ },
140
+ keyId: {
141
+ type: String,
142
+ required: false,
143
+ default: undefined,
144
+ },
145
+ label: {
146
+ type: [String, Number],
147
+ required: false,
148
+ default: "",
149
+ },
150
+ labelClass: {
151
+ type: [String, Object, Array],
152
+ required: false,
153
+ default: undefined,
154
+ },
155
+ labelTag: {
156
+ type: String,
157
+ required: false,
158
+ default: "h2",
159
+ },
160
+ prepareEditModel: {
161
+ type: Function,
162
+ required: false,
163
+ default: undefined,
164
+ },
165
+ rowClass: {
166
+ type: [String, Object, Array, Function],
167
+ required: false,
168
+ default: undefined,
169
+ },
170
+ rows: {
171
+ type: Array,
172
+ required: false,
173
+ default: () => [],
174
+ },
175
+ rowsFooter: {
176
+ type: Array,
177
+ required: false,
178
+ default: () => [],
179
+ },
180
+ saveRow: {
181
+ type: Function,
182
+ required: false,
183
+ default: () => undefined,
184
+ },
185
+ texts: {
186
+ type: Object,
187
+ required: false,
188
+ default: () => ({}),
189
+ },
190
+ widths: {
191
+ type: Object,
192
+ required: false,
193
+ default: () => ({}),
194
+ },
195
+ },
196
+ emits: [
197
+ "deleteRow",
198
+ "moveRow",
199
+ "updateRows",
200
+ ],
201
+ setup(props, context) {
202
+ const actionsDisabledCallback = toRef(props, "actionsDisabledCallback");
203
+ const actionsTitleCallback = toRef(props, "actionsTitleCallback");
204
+
205
+ const {
206
+ allColumnsLength,
207
+ columnsVisible,
208
+ hasActionsColumn,
209
+ } = ColumnsAPI(props);
210
+
211
+ const {
212
+ getRowKey,
213
+ hasRows,
214
+ hasRowsFooter,
215
+ } = RowsAPI(props);
216
+
217
+ const {
218
+ textsLocal,
219
+ } = TextsAPI(props);
220
+
221
+ const {
222
+ widthsLocal,
223
+ } = WidthsAPI(props);
224
+
225
+ const {
226
+ iconsLocal,
227
+ } = IconsAPI(props);
228
+
229
+ const {
230
+ actionsClassesLocal,
231
+ } = ClassesAPI(props);
232
+
233
+ const {
234
+ columnsStylesGrow,
235
+ destroyColumnsGrowObserver,
236
+ initColumnsGrowObserver,
237
+ } = ColumnsGrowAPI(props, {
238
+ columnsVisible,
239
+ hasActionsColumn,
240
+ widthsLocal,
241
+ });
242
+
243
+ onMounted(() => {
244
+ initColumnsGrowObserver();
245
+ });
246
+
247
+ onBeforeUnmount(() => {
248
+ destroyColumnsGrowObserver();
249
+ });
250
+
251
+ const {
252
+ activeEditRowKey,
253
+ activeEditModel,
254
+ canAddRow,
255
+ hasActiveEditRow,
256
+ hasRequiredEditableColumns,
257
+ isAddRowActive,
258
+ onAddRow,
259
+ onCancelEditRow,
260
+ onEditRow,
261
+ } = EditAPI(props, {
262
+ columnsVisible,
263
+ getRowKey,
264
+ });
265
+
266
+ const {
267
+ canMoveRowDown,
268
+ canMoveRowUp,
269
+ dragOverPosition,
270
+ dragOverRowIndex,
271
+ draggedRowIndex,
272
+ isDndDisabledForRow,
273
+ moveRowDown,
274
+ moveRowUp,
275
+ onDragend,
276
+ onDragleave,
277
+ onDragover,
278
+ onDragstart,
279
+ onDrop,
280
+ } = DragAndDropAPI(props, context, {
281
+ isDndDisabled: hasActiveEditRow,
282
+ });
283
+
284
+ const {
285
+ onDeleteRow,
286
+ } = DeleteAPI(props, context);
287
+
288
+ const isAddDisabled = computed(() => {
289
+ if (hasActiveEditRow.value) {
290
+ return true;
291
+ }
292
+
293
+ const addDisabledCallback = get(actionsDisabledCallback.value, "add");
294
+
295
+ if (isFunction(addDisabledCallback)) {
296
+ return addDisabledCallback();
297
+ }
298
+
299
+ return false;
300
+ });
301
+
302
+ const addTitle = computed(() => {
303
+ const addTitleCallback = get(actionsTitleCallback.value, "add");
304
+
305
+ if (isFunction(addTitleCallback)) {
306
+ return addTitleCallback();
307
+ }
308
+
309
+ return textsLocal.value.actionAddRow;
310
+ });
311
+
312
+ return {
313
+ activeEditRowKey,
314
+ activeEditModel,
315
+ allColumnsLength,
316
+ addTitle,
317
+ canAddRow,
318
+ canMoveRowDown,
319
+ canMoveRowUp,
320
+ actionsClassesLocal,
321
+ columnsStylesGrow,
322
+ columnsVisible,
323
+ draggedRowIndex,
324
+ dragOverPosition,
325
+ dragOverRowIndex,
326
+ isDndDisabledForRow,
327
+ getRowKey,
328
+ hasActionsColumn,
329
+ hasActiveEditRow,
330
+ hasRequiredEditableColumns,
331
+ hasRows,
332
+ hasRowsFooter,
333
+ iconsLocal,
334
+ isAddDisabled,
335
+ isAddRowActive,
336
+ moveRowDown,
337
+ moveRowUp,
338
+ onAddRow,
339
+ onCancelEditRow,
340
+ onDeleteRow,
341
+ onDragend,
342
+ onDragleave,
343
+ onDragover,
344
+ onDragstart,
345
+ onDrop,
346
+ onEditRow,
347
+ textsLocal,
348
+ widthsLocal,
349
+ };
350
+ },
351
+ render() {
352
+ return h("div", {
353
+ class: "a_table_form",
354
+ }, [
355
+ this.label && h(ATranslation, {
356
+ class: [
357
+ "a_table_form__label",
358
+ this.labelClass,
359
+ ],
360
+ html: this.label,
361
+ tag: this.labelTag,
362
+ }),
363
+ this.hasRequiredEditableColumns && h(ARequired),
364
+ h("div", {
365
+ class: "a_table_form__wrapper",
366
+ }, [
367
+ h("table", {
368
+ id: this.id,
369
+ class: [
370
+ "a_table_form__table",
371
+ {
372
+ a_table_form_drag_active: this.draggedRowIndex !== undefined,
373
+ },
374
+ ],
375
+ }, [
376
+ h("thead", {
377
+ class: "a_table_form__head",
378
+ }, [
379
+ h(ATableFormRow, {
380
+ id: this.id,
381
+ actionsClasses: this.actionsClasses,
382
+ actionsDisabledCallback: this.actionsDisabledCallback,
383
+ actionsHideCallback: this.actionsHideCallback,
384
+ actionsTitleCallback: this.actionsTitleCallback,
385
+ allColumnsLength: this.allColumnsLength,
386
+ canMoveRowDown: this.canMoveRowDown,
387
+ canMoveRowUp: this.canMoveRowUp,
388
+ cellTag: "th",
389
+ changeModel: this.changeModel,
390
+ columns: this.columnsVisible,
391
+ columnsStylesGrow: this.columnsStylesGrow,
392
+ draggedRowIndex: this.draggedRowIndex,
393
+ extra: this.extra,
394
+ hasActionsColumn: this.hasActionsColumn,
395
+ hasActiveEditRow: false,
396
+ isActionsSticky: this.isActionsSticky,
397
+ isActiveEditMode: false,
398
+ isDeletable: this.isDeletable,
399
+ isDeletableConfirm: this.isDeletableConfirm,
400
+ isDndDisabled: this.hasActiveEditRow,
401
+ isDragAndDrop: this.isDragAndDrop,
402
+ isEditable: this.isEditable,
403
+ isHeader: true,
404
+ moveRowDown: this.moveRowDown,
405
+ moveRowUp: this.moveRowUp,
406
+ onCancelEditRow: this.onCancelEditRow,
407
+ onDeleteRow: this.onDeleteRow,
408
+ onDragend: this.onDragend,
409
+ onDragstart: this.onDragstart,
410
+ onEditRow: this.onEditRow,
411
+ row: {},
412
+ rowIndex: 0,
413
+ rows: this.rows,
414
+ saveRow: this.saveRow,
415
+ texts: this.textsLocal,
416
+ trClass: "a_table_form__row a_table_form__row_head",
417
+ widths: this.widthsLocal,
418
+ }, this.$slots),
419
+ ]),
420
+ h("tbody", {
421
+ class: "a_table_form__body",
422
+ }, this.hasRows || this.isAddRowActive ?
423
+ [
424
+ ...this.rows.map((row, rowIndex) => {
425
+ const rowKey = this.getRowKey({
426
+ row,
427
+ rowIndex,
428
+ });
429
+
430
+ return h(ATableFormRow, {
431
+ key: rowKey,
432
+ id: this.id,
433
+ actionsClasses: this.actionsClassesLocal,
434
+ actionsDisabledCallback: this.actionsDisabledCallback,
435
+ actionsHideCallback: this.actionsHideCallback,
436
+ actionsTitleCallback: this.actionsTitleCallback,
437
+ allColumnsLength: this.allColumnsLength,
438
+ canMoveRowDown: this.canMoveRowDown,
439
+ canMoveRowUp: this.canMoveRowUp,
440
+ changeModel: this.changeModel,
441
+ columns: this.columnsVisible,
442
+ columnsStylesGrow: this.columnsStylesGrow,
443
+ draggedRowIndex: this.draggedRowIndex,
444
+ editModel: this.activeEditRowKey === rowKey ? this.activeEditModel : undefined,
445
+ errorIcon: this.errorIcon,
446
+ extra: this.extra,
447
+ hasActionsColumn: this.hasActionsColumn,
448
+ hasActiveEditRow: this.hasActiveEditRow,
449
+ isActionsSticky: this.isActionsSticky,
450
+ isActiveEditMode: this.activeEditRowKey === rowKey,
451
+ isCreateMode: false,
452
+ isDeletable: this.isDeletable,
453
+ isDeletableConfirm: this.isDeletableConfirm,
454
+ isDndDisabled: this.isDndDisabledForRow(rowIndex),
455
+ isDragAndDrop: this.isDragAndDrop,
456
+ isEditable: this.isEditable,
457
+ moveRowDown: this.moveRowDown,
458
+ moveRowUp: this.moveRowUp,
459
+ onCancelEditRow: this.onCancelEditRow,
460
+ onDeleteRow: this.onDeleteRow,
461
+ onDragend: this.onDragend,
462
+ onDragleave: this.onDragleave,
463
+ onDragover: this.onDragover,
464
+ onDragstart: this.onDragstart,
465
+ onDrop: this.onDrop,
466
+ onEditRow: this.onEditRow,
467
+ row,
468
+ rowClass: this.rowClass,
469
+ rowIndex,
470
+ rows: this.rows,
471
+ saveRow: this.saveRow,
472
+ texts: this.textsLocal,
473
+ widths: this.widthsLocal,
474
+ trClass: [
475
+ "a_table_form__row",
476
+ {
477
+ a_table_form__row_drag_after: this.dragOverRowIndex === rowIndex &&
478
+ this.dragOverPosition === "after",
479
+ a_table_form__row_drag_before: this.dragOverRowIndex === rowIndex &&
480
+ this.dragOverPosition === "before",
481
+ a_table_form__row_drag_over: this.dragOverRowIndex === rowIndex,
482
+ a_table_form__row_dragging: this.draggedRowIndex === rowIndex,
483
+ },
484
+ ],
485
+ }, this.$slots);
486
+ }),
487
+ this.isAddRowActive && h(ATableFormRow, {
488
+ id: this.id,
489
+ actionsClasses: this.actionsClassesLocal,
490
+ actionsDisabledCallback: this.actionsDisabledCallback,
491
+ actionsHideCallback: this.actionsHideCallback,
492
+ actionsTitleCallback: this.actionsTitleCallback,
493
+ allColumnsLength: this.allColumnsLength,
494
+ canMoveRowDown: this.canMoveRowDown,
495
+ canMoveRowUp: this.canMoveRowUp,
496
+ changeModel: this.changeModel,
497
+ columns: this.columnsVisible,
498
+ columnsStylesGrow: this.columnsStylesGrow,
499
+ draggedRowIndex: this.draggedRowIndex,
500
+ editModel: this.activeEditModel,
501
+ errorIcon: this.errorIcon,
502
+ extra: this.extra,
503
+ hasActionsColumn: this.hasActionsColumn,
504
+ hasActiveEditRow: this.hasActiveEditRow,
505
+ isActionsSticky: this.isActionsSticky,
506
+ isActiveEditMode: true,
507
+ isCreateMode: true,
508
+ isDeletable: false,
509
+ isDeletableConfirm: false,
510
+ isDndDisabled: true,
511
+ isDragAndDrop: this.isDragAndDrop,
512
+ isEditable: this.isEditable,
513
+ key: "body_create",
514
+ moveRowDown: this.moveRowDown,
515
+ moveRowUp: this.moveRowUp,
516
+ onCancelEditRow: this.onCancelEditRow,
517
+ onDeleteRow: this.onDeleteRow,
518
+ onDragend: this.onDragend,
519
+ onDragleave: this.onDragleave,
520
+ onDragover: this.onDragover,
521
+ onDragstart: this.onDragstart,
522
+ onDrop: this.onDrop,
523
+ onEditRow: this.onEditRow,
524
+ row: {},
525
+ rowClass: this.rowClass,
526
+ rowIndex: this.rows.length,
527
+ rows: this.rows,
528
+ saveRow: this.addRow,
529
+ texts: this.textsLocal,
530
+ trClass: "a_table_form__row a_table_form__row_create",
531
+ widths: this.widthsLocal,
532
+ }, this.$slots),
533
+ ] :
534
+ [h("tr", {
535
+ class: "a_table_form__row a_table_form__row_empty",
536
+ }, [
537
+ h("td", {
538
+ class: "a_table_form__cell a_table_form__empty",
539
+ colspan: this.allColumnsLength,
540
+ }, [
541
+ h(ATranslation, {
542
+ tag: "span",
543
+ text: this.textsLocal.emptyText,
544
+ }),
545
+ ]),
546
+ ])]),
547
+ this.hasRowsFooter && h("tfoot", {
548
+ class: "a_table_form__foot",
549
+ }, this.rowsFooter.map((row, rowIndex) => {
550
+ return h(ATableFormRow, {
551
+ id: this.id,
552
+ actionsClasses: this.actionsClassesLocal,
553
+ actionsDisabledCallback: this.actionsDisabledCallback,
554
+ actionsHideCallback: this.actionsHideCallback,
555
+ actionsTitleCallback: this.actionsTitleCallback,
556
+ allColumnsLength: this.allColumnsLength,
557
+ canMoveRowDown: this.canMoveRowDown,
558
+ canMoveRowUp: this.canMoveRowUp,
559
+ changeModel: this.changeModel,
560
+ columns: this.columnsVisible,
561
+ columnsStylesGrow: this.columnsStylesGrow,
562
+ draggedRowIndex: this.draggedRowIndex,
563
+ extra: this.extra,
564
+ hasActionsColumn: this.hasActionsColumn,
565
+ hasActiveEditRow: this.hasActiveEditRow,
566
+ isActionsSticky: this.isActionsSticky,
567
+ isActiveEditMode: false,
568
+ isDeletable: this.isDeletable,
569
+ isDeletableConfirm: this.isDeletableConfirm,
570
+ isDndDisabled: this.hasActiveEditRow,
571
+ isDragAndDrop: this.isDragAndDrop,
572
+ isEditable: this.isEditable,
573
+ isFooter: true,
574
+ key: this.getRowKey({
575
+ isFooter: true,
576
+ row,
577
+ rowIndex,
578
+ }),
579
+ moveRowDown: this.moveRowDown,
580
+ moveRowUp: this.moveRowUp,
581
+ onCancelEditRow: this.onCancelEditRow,
582
+ onDeleteRow: this.onDeleteRow,
583
+ onDragend: this.onDragend,
584
+ onDragstart: this.onDragstart,
585
+ onEditRow: this.onEditRow,
586
+ row,
587
+ rowClass: this.rowClass,
588
+ rowIndex,
589
+ rows: this.rowsFooter,
590
+ saveRow: this.saveRow,
591
+ texts: this.textsLocal,
592
+ widths: this.widthsLocal,
593
+ trClass: "a_table_form__row a_table_form__row_footer",
594
+ }, this.$slots);
595
+ })),
596
+ ]),
597
+ ]),
598
+ this.canAddRow && h("div", {
599
+ class: "a_mt_3 a_text_right",
600
+ }, [
601
+ h(AButton, {
602
+ class: this.actionsClassesLocal.addRow,
603
+ disabled: this.isAddDisabled,
604
+ extra: this.extra,
605
+ iconLeft: this.iconsLocal.actionAddRow,
606
+ text: this.textsLocal.actionAddRow,
607
+ textScreenReader: this.addTitle,
608
+ title: this.addTitle,
609
+ onClick: this.onAddRow,
610
+ }),
611
+ ]),
612
+ ]);
613
+ },
614
+ };