@bildvitta/quasar-ui-asteroid 3.17.0-beta.21 → 3.17.0-beta.22
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/package.json +1 -1
- package/src/asteroid.js +4 -4
- package/src/components/actions/QasActions.vue +81 -81
- package/src/components/actions/QasActions.yml +34 -34
- package/src/components/actions-menu/QasActionsMenu.vue +251 -251
- package/src/components/actions-menu/QasActionsMenu.yml +89 -89
- package/src/components/actions-menu/composables/use-delete.js +30 -30
- package/src/components/actions-menu/composables/use-double-split-actions.js +42 -42
- package/src/components/actions-menu/composables/use-options-actions.js +27 -27
- package/src/components/actions-menu/composables/use-single-action.js +17 -17
- package/src/components/actions-menu/composables/use-single-split-actions.js +35 -35
- package/src/components/actions-menu/composables/use-tooltips.js +43 -43
- package/src/components/actions-menu/utils/get-label.js +3 -3
- package/src/components/actions-menu/utils/set-click-handler.js +6 -6
- package/src/components/alert/QasAlert.test.js +43 -43
- package/src/components/alert/QasAlert.vue +110 -110
- package/src/components/alert/QasAlert.yml +39 -39
- package/src/components/app-bar/QasAppBar.vue +119 -119
- package/src/components/app-bar/QasAppBar.yml +44 -44
- package/src/components/app-menu/QasAppMenu.vue +392 -392
- package/src/components/app-menu/QasAppMenu.yml +73 -73
- package/src/components/app-menu/composables/use-app-menu-dropdown.js +71 -71
- package/src/components/app-menu/composables/use-app-user.js +49 -49
- package/src/components/app-menu/composables/use-development-badge.js +23 -23
- package/src/components/app-menu/private/PvAppMenuDropdown.vue +71 -71
- package/src/components/app-menu/private/PvAppMenuHelpChat.vue +222 -222
- package/src/components/app-user/QasAppUser.vue +281 -281
- package/src/components/app-user/QasAppUser.yml +56 -56
- package/src/components/avatar/QasAvatar.vue +95 -95
- package/src/components/avatar/QasAvatar.yml +38 -38
- package/src/components/avatar/enums/AvatarColors.js +10 -10
- package/src/components/badge/QasBadge.vue +87 -87
- package/src/components/badge/QasBadge.yml +55 -55
- package/src/components/board-generator/QasBoardGenerator.vue +712 -712
- package/src/components/board-generator/QasBoardGenerator.yml +167 -167
- package/src/components/box/QasBox.vue +51 -51
- package/src/components/box/QasBox.yml +29 -29
- package/src/components/breakline/QasBreakline.vue +38 -38
- package/src/components/breakline/QasBreakline.yml +25 -25
- package/src/components/btn/QasBtn.vue +148 -148
- package/src/components/btn/QasBtn.yml +48 -48
- package/src/components/btn-dropdown/QasBtnDropdown.vue +146 -146
- package/src/components/btn-dropdown/QasBtnDropdown.yml +59 -59
- package/src/components/card/QasCard.vue +132 -132
- package/src/components/card/QasCard.yml +44 -44
- package/src/components/card-image/QasCardImage.vue +95 -95
- package/src/components/card-image/QasCardImage.yml +48 -48
- package/src/components/chart-view/QasChartView.vue +441 -441
- package/src/components/chart-view/QasChartView.yml +109 -109
- package/src/components/chart-view/config/charts/bar.js +45 -45
- package/src/components/chart-view/config/charts/doughnut.js +43 -43
- package/src/components/chart-view/config/charts/index.js +9 -9
- package/src/components/chart-view/config/charts/line.js +57 -57
- package/src/components/chart-view/config/defaults/colors.js +19 -19
- package/src/components/chart-view/config/defaults/font.js +5 -5
- package/src/components/chart-view/config/defaults/index.js +2 -2
- package/src/components/chart-view/config/index.js +3 -3
- package/src/components/chart-view/config/plugins/index.js +3 -3
- package/src/components/chart-view/config/plugins/legend.js +9 -9
- package/src/components/chart-view/config/plugins/tooltip.js +15 -15
- package/src/components/chart-view/config/plugins/zoom.js +31 -31
- package/src/components/checkbox/QasCheckbox.vue +150 -150
- package/src/components/checkbox/QasCheckbox.yml +36 -36
- package/src/components/copy/QasCopy.vue +46 -46
- package/src/components/copy/QasCopy.yml +23 -23
- package/src/components/date/QasDate.vue +600 -600
- package/src/components/date/QasDate.yml +69 -69
- package/src/components/date/enums/DateMaskOptions.js +6 -6
- package/src/components/date-time-input/QasDateTimeInput.vue +269 -269
- package/src/components/date-time-input/QasDateTimeInput.yml +64 -64
- package/src/components/debugger/QasDebugger.vue +31 -31
- package/src/components/debugger/QasDebugger.yml +10 -10
- package/src/components/delete/QasDelete.vue +100 -100
- package/src/components/delete/QasDelete.yml +60 -60
- package/src/components/dialog/QasDialog.vue +217 -217
- package/src/components/dialog/QasDialog.yml +117 -117
- package/src/components/dialog/composables/use-cancel.js +40 -40
- package/src/components/dialog/composables/use-dynamic-components.js +86 -86
- package/src/components/dialog/composables/use-ok.js +45 -45
- package/src/components/dialog-router/QasDialogRouter.vue +86 -86
- package/src/components/dialog-router/QasDialogRouter.yml +23 -23
- package/src/components/drawer/QasDrawer.vue +118 -118
- package/src/components/drawer/QasDrawer.yml +58 -58
- package/src/components/empty-result-text/QasEmptyResultText.vue +18 -18
- package/src/components/empty-result-text/QasEmptyResultText.yml +14 -14
- package/src/components/expansion-item/QasExpansionItem.vue +291 -291
- package/src/components/expansion-item/QasExpansionItem.yml +76 -76
- package/src/components/field/QasField.vue +220 -220
- package/src/components/field/QasField.yml +36 -36
- package/src/components/filters/QasFilters.vue +472 -472
- package/src/components/filters/QasFilters.yml +171 -171
- package/src/components/filters/private/PvFiltersButton.vue +101 -101
- package/src/components/form-generator/QasFormGenerator.vue +274 -274
- package/src/components/form-generator/QasFormGenerator.yml +109 -109
- package/src/components/form-view/QasFormView.vue +484 -484
- package/src/components/form-view/QasFormView.yml +253 -253
- package/src/components/gallery/QasGallery.vue +243 -243
- package/src/components/gallery/QasGallery.yml +188 -188
- package/src/components/gallery/composables/use-delete.js +54 -54
- package/src/components/gallery/private/PvGalleryCarouselDialog.vue +92 -92
- package/src/components/gallery/private/PvGalleryDeleteDialog.vue +54 -54
- package/src/components/gallery-card/QasGalleryCard.vue +153 -153
- package/src/components/gallery-card/QasGalleryCard.yml +61 -61
- package/src/components/grabbable/QasGrabbable.vue +185 -185
- package/src/components/grabbable/QasGrabbable.yml +26 -26
- package/src/components/grid-generator/QasGridGenerator.vue +210 -210
- package/src/components/grid-generator/QasGridGenerator.yml +127 -127
- package/src/components/grid-item/QasGridItem.vue +89 -89
- package/src/components/grid-item/QasGridItem.yml +22 -22
- package/src/components/header/QasHeader.vue +152 -152
- package/src/components/header/QasHeader.yml +50 -50
- package/src/components/infinite-scroll/QasInfiniteScroll.vue +168 -168
- package/src/components/infinite-scroll/QasInfiniteScroll.yml +78 -78
- package/src/components/info/QasInfo.vue +155 -155
- package/src/components/info/QasInfo.yml +34 -34
- package/src/components/input/QasInput.vue +252 -252
- package/src/components/input/QasInput.yml +65 -65
- package/src/components/label/QasLabel.vue +61 -61
- package/src/components/label/QasLabel.yml +44 -44
- package/src/components/layout/QasLayout.vue +101 -101
- package/src/components/layout/QasLayout.yml +46 -46
- package/src/components/layout/private/PvLayoutNotificationCard.vue +86 -86
- package/src/components/layout/private/PvLayoutNotificationsDrawer.vue +140 -140
- package/src/components/list-items/QasListItems.vue +125 -125
- package/src/components/list-items/QasListItems.yml +71 -71
- package/src/components/list-view/QasListView.vue +302 -302
- package/src/components/list-view/QasListView.yml +169 -169
- package/src/components/map/QasMap.vue +75 -75
- package/src/components/map/QasMap.yml +33 -33
- package/src/components/nested-fields/QasNestedFields.vue +584 -584
- package/src/components/nested-fields/QasNestedFields.yml +296 -296
- package/src/components/numeric-input/QasNumericInput.vue +206 -206
- package/src/components/numeric-input/QasNumericInput.yml +85 -85
- package/src/components/option-group/QasOptionGroup.vue +54 -54
- package/src/components/option-group/QasOptionGroup.yml +30 -30
- package/src/components/page-header/QasPageHeader.vue +143 -143
- package/src/components/page-header/QasPageHeader.yml +42 -42
- package/src/components/pagination/QasPagination.vue +71 -71
- package/src/components/pagination/QasPagination.yml +4 -4
- package/src/components/password-input/QasPasswordInput.vue +110 -110
- package/src/components/password-input/QasPasswordInput.yml +111 -111
- package/src/components/password-strength-checker/QasPasswordStrengthChecker.vue +71 -71
- package/src/components/password-strength-checker/QasPasswordStrengthChecker.yml +103 -103
- package/src/components/profile/QasProfile.vue +98 -98
- package/src/components/profile/QasProfile.yml +60 -60
- package/src/components/radio/QasRadio.vue +62 -62
- package/src/components/radio/QasRadio.yml +11 -11
- package/src/components/resizer/QasResizer.vue +90 -90
- package/src/components/resizer/QasResizer.yml +24 -24
- package/src/components/search-box/QasSearchBox.vue +294 -294
- package/src/components/search-box/QasSearchBox.yml +154 -154
- package/src/components/search-input/QasSearchInput.vue +106 -106
- package/src/components/search-input/QasSearchInput.yml +48 -48
- package/src/components/select/QasSelect.vue +514 -514
- package/src/components/select/QasSelect.yml +157 -157
- package/src/components/select-list/QasSelectList.vue +238 -238
- package/src/components/select-list/QasSelectList.yml +108 -108
- package/src/components/select-list/private/PvSelectListCheckbox.vue +31 -31
- package/src/components/select-list-dialog/QasSelectListDialog.vue +395 -395
- package/src/components/select-list-dialog/QasSelectListDialog.yml +108 -108
- package/src/components/signature-pad/QasSignaturePad.vue +122 -122
- package/src/components/signature-pad/QasSignaturePad.yml +53 -53
- package/src/components/signature-uploader/QasSignatureUploader.vue +164 -164
- package/src/components/signature-uploader/QasSignatureUploader.yml +37 -37
- package/src/components/single-view/QasSingleView.vue +175 -175
- package/src/components/single-view/QasSingleView.yml +131 -131
- package/src/components/sortable/QasSortable.vue +151 -151
- package/src/components/sortable/QasSortable.yml +65 -65
- package/src/components/status/QasStatus.test.js +11 -11
- package/src/components/status/QasStatus.vue +29 -29
- package/src/components/status/QasStatus.yml +10 -10
- package/src/components/stepper/QasStepper.vue +199 -152
- package/src/components/stepper/QasStepper.yml +35 -35
- package/src/components/stepper-form-view/QasStepperFormView.vue +86 -84
- package/src/components/stepper-form-view/QasStepperFormView.yml +58 -58
- package/src/components/table-generator/QasTableGenerator.vue +416 -416
- package/src/components/table-generator/QasTableGenerator.yml +94 -94
- package/src/components/tabs-generator/QasTabsGenerator.vue +196 -196
- package/src/components/tabs-generator/QasTabsGenerator.yml +53 -53
- package/src/components/text-truncate/QasTextTruncate.vue +274 -274
- package/src/components/text-truncate/QasTextTruncate.yml +60 -60
- package/src/components/timeline/QasTimeline.vue +140 -140
- package/src/components/timeline/QasTimeline.yml +36 -36
- package/src/components/toggle/QasToggle.vue +14 -14
- package/src/components/toggle/QasToggle.yml +5 -5
- package/src/components/toggle-visibility/QasToggleVisibility.vue +79 -79
- package/src/components/toggle-visibility/QasToggleVisibility.yml +30 -30
- package/src/components/transfer/QasTransfer.vue +239 -239
- package/src/components/transfer/QasTransfer.yml +60 -60
- package/src/components/tree-generator/QasTreeForm.vue +62 -62
- package/src/components/tree-generator/QasTreeGenerator.vue +488 -488
- package/src/components/tree-generator/QasTreeGenerator.yml +81 -81
- package/src/components/uploader/QasUploader.vue +691 -645
- package/src/components/uploader/QasUploader.yml +206 -192
- package/src/components/uploader/private/PvUploaderGalleryCard.vue +357 -357
- package/src/components/welcome/QasWelcome.vue +125 -125
- package/src/components/welcome/QasWelcome.yml +23 -23
- package/src/components/welcome/private/PvWelcomeShortcutCard.vue +58 -58
- package/src/components/whatsapp-link/QasWhatsappLink.vue +34 -34
- package/src/components/whatsapp-link/QasWhatsappLink.yml +18 -18
- package/src/composables/index.js +8 -8
- package/src/composables/private/index.js +3 -3
- package/src/composables/private/use-generator.js +174 -174
- package/src/composables/private/use-toggle-visibility.js +48 -48
- package/src/composables/private/use-view.js +186 -186
- package/src/composables/use-context.js +15 -15
- package/src/composables/use-form.js +32 -32
- package/src/composables/use-history.js +46 -46
- package/src/composables/use-notifications.js +128 -128
- package/src/composables/use-query-cache.js +60 -60
- package/src/composables/use-screen.js +42 -42
- package/src/css/base/font-face.scss +28 -28
- package/src/css/base/index.scss +1 -1
- package/src/css/components/base.scss +12 -12
- package/src/css/components/button.scss +116 -116
- package/src/css/components/checkbox.scss +14 -14
- package/src/css/components/editor.scss +7 -7
- package/src/css/components/field.scss +88 -88
- package/src/css/components/index.scss +10 -10
- package/src/css/components/item.scss +52 -52
- package/src/css/components/radio.scss +18 -18
- package/src/css/components/scrollbar.scss +20 -20
- package/src/css/components/tabs.scss +3 -3
- package/src/css/components/toggle.scss +13 -13
- package/src/css/mixins/index.scss +3 -3
- package/src/css/mixins/set-brand.scss +15 -15
- package/src/css/mixins/set-button.scss +26 -26
- package/src/css/mixins/set-typography.scss +8 -8
- package/src/css/plugins/index.scss +2 -2
- package/src/css/plugins/loading.scss +5 -5
- package/src/css/plugins/notify.scss +100 -100
- package/src/css/utils/background.scss +34 -34
- package/src/css/utils/border-radius.scss +29 -29
- package/src/css/utils/border.scss +42 -42
- package/src/css/utils/container.scss +36 -36
- package/src/css/utils/fonts.scss +5 -5
- package/src/css/utils/index.scss +10 -10
- package/src/css/utils/line-height.scss +19 -19
- package/src/css/utils/opacity.scss +5 -5
- package/src/css/utils/scroll.scss +21 -21
- package/src/css/utils/text.scss +15 -15
- package/src/css/utils/unset.scss +8 -8
- package/src/css/variables/button.scss +4 -4
- package/src/css/variables/index.scss +6 -6
- package/src/css/variables/scrollbar.scss +11 -11
- package/src/css/variables/separator.scss +2 -2
- package/src/css/variables/shadow.scss +3 -3
- package/src/css/variables/spacing.scss +98 -98
- package/src/css/variables/typography.scss +149 -149
- package/src/directives/Test.js +13 -13
- package/src/enums/Align.js +7 -7
- package/src/enums/Spacing.js +98 -98
- package/src/enums/Status.js +33 -33
- package/src/helpers/add-counter-suffix.js +3 -3
- package/src/helpers/base-64-to-blob.js +21 -21
- package/src/helpers/camelize-fields-name.js +15 -15
- package/src/helpers/construct-object.js +29 -29
- package/src/helpers/copy-to-clipboard.js +15 -15
- package/src/helpers/destroy-nested-children-by-key.js +33 -33
- package/src/helpers/download-file.js +21 -21
- package/src/helpers/filter-list-by-handle.js +31 -31
- package/src/helpers/filter-object-to-array.js +29 -29
- package/src/helpers/filter-object.js +34 -34
- package/src/helpers/filters.js +163 -163
- package/src/helpers/find-children-by-key.js +14 -14
- package/src/helpers/get-greatest-common-divisor.js +16 -16
- package/src/helpers/get-normalized-options.js +20 -20
- package/src/helpers/get-placeholder.js +19 -19
- package/src/helpers/get-required-label.js +3 -3
- package/src/helpers/get-slot-children-text.js +15 -15
- package/src/helpers/handle-process.js +13 -13
- package/src/helpers/images.js +28 -28
- package/src/helpers/index.js +25 -25
- package/src/helpers/is-empty.js +3 -3
- package/src/helpers/is-local-development.js +3 -3
- package/src/helpers/private/gutter-validator.js +15 -15
- package/src/helpers/private/has-parent-by-class-name.js +15 -15
- package/src/helpers/promise-handler.js +40 -40
- package/src/helpers/rules.js +7 -7
- package/src/helpers/set-scroll-on-grab.js +128 -128
- package/src/index.cjs.js +1 -1
- package/src/index.esm.js +4 -4
- package/src/index.scss +38 -38
- package/src/index.umd.js +2 -2
- package/src/mixins/context.js +8 -8
- package/src/mixins/delete.js +48 -48
- package/src/mixins/dialog-router.js +17 -17
- package/src/mixins/form.js +11 -11
- package/src/mixins/generator.js +94 -94
- package/src/mixins/index.js +17 -17
- package/src/mixins/password.js +86 -86
- package/src/mixins/search-filter.js +354 -354
- package/src/mixins/view.js +156 -156
- package/src/pages/ErrorComponent.vue +74 -74
- package/src/pages/Forbidden.vue +29 -29
- package/src/pages/NotFound.vue +29 -29
- package/src/pages/ServerError.vue +29 -29
- package/src/pages/Unauthorized.vue +29 -29
- package/src/plugins/delete/Delete.js +107 -107
- package/src/plugins/delete/Delete.yml +75 -75
- package/src/plugins/dialog/Dialog.js +14 -14
- package/src/plugins/dialog/Dialog.yml +10 -10
- package/src/plugins/index.js +13 -13
- package/src/plugins/notify-error/NotifyError.js +13 -13
- package/src/plugins/notify-error/NotifyError.yml +11 -11
- package/src/plugins/notify-success/NotifySuccess.js +13 -13
- package/src/plugins/notify-success/NotifySuccess.yml +11 -11
- package/src/plugins/screen/Screen.js +35 -35
- package/src/plugins/screen/Screen.yml +16 -16
- package/src/shared/date-config.js +26 -26
- package/src/shared/fuse-config.js +4 -4
- package/src/shared/notify-config.js +7 -7
- package/src/vue-plugin/third-party-component-handler.js +29 -29
- package/src/vue-plugin.js +282 -282
|
@@ -1,584 +1,584 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div :id="fieldName" class="qas-nested-fields" :data-cy="`nested-fields-${fieldName}`">
|
|
3
|
-
<component :is="containerComponent">
|
|
4
|
-
<div v-if="useSingleLabel" class="text-left">
|
|
5
|
-
<qas-label :label="fieldLabel" />
|
|
6
|
-
</div>
|
|
7
|
-
|
|
8
|
-
<div ref="inputContent">
|
|
9
|
-
<component :is="componentTag" v-bind="componentProps">
|
|
10
|
-
<template v-for="(row, index) in nested" :key="`row-${index}`">
|
|
11
|
-
<div v-if="!row[destroyKey]" :id="`row-${index}`" class="full-width qas-nested-fields__field-item" data-cy="nested-fields-item">
|
|
12
|
-
<qas-header v-if="hasHeader({ row })" class="flex" v-bind="getHeaderProps({ index, row })" />
|
|
13
|
-
|
|
14
|
-
<slot :errors="transformedErrors" :fields="getFields(index, row)" :index="index" :model="nested[index]" name="before-fields" :update-value="updateValuesFromInput" />
|
|
15
|
-
|
|
16
|
-
<div ref="formGenerator" :class="formGeneratorParentClasses">
|
|
17
|
-
<slot :errors="transformedErrors" :fields="getFields(index, row)" :index="index" name="fields" :update-value="updateValuesFromInput">
|
|
18
|
-
<qas-form-generator v-model="nested[index]" class="col" :columns="formColumns" :common-columns="formCommonColumns" :disable="isDisabledRow(row)" :errors="transformedErrors[index]" :fields="getFields(index, row)" :fields-props="getFieldsProps(index, row)" :gutter="formGutter" @update:model-value="updateValuesFromInput($event, index)">
|
|
19
|
-
<template v-for="(slot, key) in $slots" #[key]="scope">
|
|
20
|
-
<slot v-bind="scope" :disabled="isDisabledRow(row)" :errors="transformedErrors" :index="index" :name="key" />
|
|
21
|
-
</template>
|
|
22
|
-
</qas-form-generator>
|
|
23
|
-
</slot>
|
|
24
|
-
|
|
25
|
-
<div v-if="hasInlineActions(row)" class="flex items-center qas-nested-fields__actions">
|
|
26
|
-
<qas-actions-menu v-bind="getInlineActionsMenuProps(index, row)" :use-label="false" />
|
|
27
|
-
</div>
|
|
28
|
-
</div>
|
|
29
|
-
|
|
30
|
-
<slot :errors="transformedErrors" :fields="getFields(index, row)" :index="index" :model="nested[index]" name="after-fields" :update-value="updateValuesFromInput" />
|
|
31
|
-
</div>
|
|
32
|
-
</template>
|
|
33
|
-
</component>
|
|
34
|
-
|
|
35
|
-
<div v-if="useAdd" :class="addButtonClass">
|
|
36
|
-
<slot :add="add" name="add-input">
|
|
37
|
-
<div v-if="showAddFirstInputButton" class="text-left">
|
|
38
|
-
<qas-btn class="q-px-sm" color="primary" data-cy="nested-fields-add-btn" :label="addFirstInputLabel" variant="tertiary" @click="add()" />
|
|
39
|
-
</div>
|
|
40
|
-
|
|
41
|
-
<div v-else-if="useInlineActions" class="cursor-pointer items-center q-col-gutter-x-md q-mt-md row" data-cy="nested-fields-add-btn" @click="add()">
|
|
42
|
-
<div class="col">
|
|
43
|
-
<qas-input class="disabled no-pointer-events" hide-bottom-space :label="addInputLabel" @focus="add()" />
|
|
44
|
-
</div>
|
|
45
|
-
|
|
46
|
-
<div class="col-auto">
|
|
47
|
-
<qas-btn color="primary" icon="sym_r_add_circle_outline" variant="tertiary" />
|
|
48
|
-
</div>
|
|
49
|
-
</div>
|
|
50
|
-
|
|
51
|
-
<div v-else class="text-left">
|
|
52
|
-
<qas-btn class="q-px-sm" color="primary" data-cy="nested-fields-add-btn" icon="sym_r_add" :label="addInputLabel" variant="tertiary" @click="add()" />
|
|
53
|
-
</div>
|
|
54
|
-
</slot>
|
|
55
|
-
</div>
|
|
56
|
-
</div>
|
|
57
|
-
</component>
|
|
58
|
-
</div>
|
|
59
|
-
</template>
|
|
60
|
-
|
|
61
|
-
<script>
|
|
62
|
-
import QasActionsMenu from '../actions-menu/QasActionsMenu.vue'
|
|
63
|
-
import QasBtn from '../btn/QasBtn.vue'
|
|
64
|
-
import QasFormGenerator from '../form-generator/QasFormGenerator.vue'
|
|
65
|
-
import QasInput from '../input/QasInput.vue'
|
|
66
|
-
import QasLabel from '../label/QasLabel.vue'
|
|
67
|
-
|
|
68
|
-
import { constructObject } from '../../helpers'
|
|
69
|
-
import { Spacing, SpacingWithNumber } from '../../enums/Spacing'
|
|
70
|
-
|
|
71
|
-
import { TransitionGroup } from 'vue'
|
|
72
|
-
import debug from 'debug'
|
|
73
|
-
import { extend } from 'quasar'
|
|
74
|
-
|
|
75
|
-
const log = debug('asteroid-ui:qas-nested-fields')
|
|
76
|
-
|
|
77
|
-
export default {
|
|
78
|
-
name: 'QasNestedFields',
|
|
79
|
-
|
|
80
|
-
components: {
|
|
81
|
-
QasActionsMenu,
|
|
82
|
-
QasBtn,
|
|
83
|
-
QasFormGenerator,
|
|
84
|
-
QasInput,
|
|
85
|
-
QasLabel,
|
|
86
|
-
|
|
87
|
-
// Vue
|
|
88
|
-
TransitionGroup
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
props: {
|
|
92
|
-
actionsMenuProps: {
|
|
93
|
-
type: [Object, Function],
|
|
94
|
-
default: () => ({})
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
addFirstInputLabel: {
|
|
98
|
-
type: String,
|
|
99
|
-
default: 'Clique aqui para adicionar'
|
|
100
|
-
},
|
|
101
|
-
|
|
102
|
-
addInputLabel: {
|
|
103
|
-
type: String,
|
|
104
|
-
default: 'Adicionar'
|
|
105
|
-
},
|
|
106
|
-
|
|
107
|
-
buttonDestroyProps: {
|
|
108
|
-
type: Object,
|
|
109
|
-
default: () => {
|
|
110
|
-
return {
|
|
111
|
-
color: 'grey-10',
|
|
112
|
-
icon: 'sym_r_delete',
|
|
113
|
-
label: 'Excluir',
|
|
114
|
-
variant: 'tertiary'
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
|
|
119
|
-
buttonDuplicateProps: {
|
|
120
|
-
type: Object,
|
|
121
|
-
default: () => {
|
|
122
|
-
return {
|
|
123
|
-
icon: 'sym_r_content_copy',
|
|
124
|
-
label: 'Duplicar',
|
|
125
|
-
useLabelOnSmallScreen: false,
|
|
126
|
-
variant: 'tertiary'
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
|
|
131
|
-
destroyKey: {
|
|
132
|
-
type: String,
|
|
133
|
-
default: 'destroyed'
|
|
134
|
-
},
|
|
135
|
-
|
|
136
|
-
disabledRows: {
|
|
137
|
-
type: [Array, Boolean, Function],
|
|
138
|
-
default: false
|
|
139
|
-
},
|
|
140
|
-
|
|
141
|
-
errors: {
|
|
142
|
-
type: [Array, Object],
|
|
143
|
-
default: () => ({})
|
|
144
|
-
},
|
|
145
|
-
|
|
146
|
-
field: {
|
|
147
|
-
type: Object,
|
|
148
|
-
default: () => ({})
|
|
149
|
-
},
|
|
150
|
-
|
|
151
|
-
fieldsHandlerFn: {
|
|
152
|
-
type: Function,
|
|
153
|
-
default: undefined
|
|
154
|
-
},
|
|
155
|
-
|
|
156
|
-
fieldsProps: {
|
|
157
|
-
type: [Object, Function],
|
|
158
|
-
default: () => ({})
|
|
159
|
-
},
|
|
160
|
-
|
|
161
|
-
formColumns: {
|
|
162
|
-
type: [Array, String, Object],
|
|
163
|
-
default: () => []
|
|
164
|
-
},
|
|
165
|
-
|
|
166
|
-
formCommonColumns: {
|
|
167
|
-
type: [Object, String],
|
|
168
|
-
default: () => ({})
|
|
169
|
-
},
|
|
170
|
-
|
|
171
|
-
formGutter: {
|
|
172
|
-
default: Spacing.Md,
|
|
173
|
-
type: [String, Boolean],
|
|
174
|
-
validator: value => typeof value === 'boolean' || Object.values(Spacing).includes(value)
|
|
175
|
-
},
|
|
176
|
-
|
|
177
|
-
headerProps: {
|
|
178
|
-
type: Function,
|
|
179
|
-
default: () => {}
|
|
180
|
-
},
|
|
181
|
-
|
|
182
|
-
identifierItemKey: {
|
|
183
|
-
type: String,
|
|
184
|
-
default: 'uuid'
|
|
185
|
-
},
|
|
186
|
-
|
|
187
|
-
rowLabel: {
|
|
188
|
-
type: String,
|
|
189
|
-
default: ''
|
|
190
|
-
},
|
|
191
|
-
|
|
192
|
-
rowObject: {
|
|
193
|
-
type: Object,
|
|
194
|
-
default: () => ({})
|
|
195
|
-
},
|
|
196
|
-
|
|
197
|
-
useAdd: {
|
|
198
|
-
type: Boolean,
|
|
199
|
-
default: true
|
|
200
|
-
},
|
|
201
|
-
|
|
202
|
-
useAnimation: {
|
|
203
|
-
type: Boolean,
|
|
204
|
-
default: true
|
|
205
|
-
},
|
|
206
|
-
|
|
207
|
-
useBox: {
|
|
208
|
-
type: Boolean
|
|
209
|
-
},
|
|
210
|
-
|
|
211
|
-
useDestroyAlways: {
|
|
212
|
-
type: Boolean,
|
|
213
|
-
default: undefined
|
|
214
|
-
},
|
|
215
|
-
|
|
216
|
-
useDuplicate: {
|
|
217
|
-
type: Boolean,
|
|
218
|
-
default: true
|
|
219
|
-
},
|
|
220
|
-
|
|
221
|
-
useFirstInputButton: {
|
|
222
|
-
type: Boolean,
|
|
223
|
-
default: true
|
|
224
|
-
},
|
|
225
|
-
|
|
226
|
-
useIndexLabel: {
|
|
227
|
-
type: Boolean
|
|
228
|
-
},
|
|
229
|
-
|
|
230
|
-
useInlineActions: {
|
|
231
|
-
type: Boolean
|
|
232
|
-
},
|
|
233
|
-
|
|
234
|
-
useSingleLabel: {
|
|
235
|
-
type: Boolean
|
|
236
|
-
},
|
|
237
|
-
|
|
238
|
-
useRemoveOnDestroy: {
|
|
239
|
-
type: Boolean,
|
|
240
|
-
default: true
|
|
241
|
-
},
|
|
242
|
-
|
|
243
|
-
useStartsEmpty: {
|
|
244
|
-
default: true,
|
|
245
|
-
type: Boolean
|
|
246
|
-
},
|
|
247
|
-
|
|
248
|
-
modelValue: {
|
|
249
|
-
type: Array,
|
|
250
|
-
default: () => []
|
|
251
|
-
}
|
|
252
|
-
},
|
|
253
|
-
|
|
254
|
-
emits: ['update:modelValue'],
|
|
255
|
-
|
|
256
|
-
data () {
|
|
257
|
-
return {
|
|
258
|
-
nested: [],
|
|
259
|
-
hasDestroyAlways: true
|
|
260
|
-
}
|
|
261
|
-
},
|
|
262
|
-
|
|
263
|
-
computed: {
|
|
264
|
-
children () {
|
|
265
|
-
return this.field?.children
|
|
266
|
-
},
|
|
267
|
-
|
|
268
|
-
containerComponent () {
|
|
269
|
-
return this.useBox ? 'qas-box' : 'div'
|
|
270
|
-
},
|
|
271
|
-
|
|
272
|
-
componentTag () {
|
|
273
|
-
return this.useAnimation ? 'transition-group' : 'div'
|
|
274
|
-
},
|
|
275
|
-
|
|
276
|
-
componentProps () {
|
|
277
|
-
if (!this.useAnimation) return {}
|
|
278
|
-
|
|
279
|
-
return {
|
|
280
|
-
tag: 'div',
|
|
281
|
-
enterActiveClass: 'animated slideInDown'
|
|
282
|
-
}
|
|
283
|
-
},
|
|
284
|
-
|
|
285
|
-
fieldLabel () {
|
|
286
|
-
return this.field?.label
|
|
287
|
-
},
|
|
288
|
-
|
|
289
|
-
fieldName () {
|
|
290
|
-
return this.field?.name
|
|
291
|
-
},
|
|
292
|
-
|
|
293
|
-
showDestroyButton () {
|
|
294
|
-
return this.nested.filter(item => !item[this.destroyKey]).length > 1 || this.hasDestroyAlways
|
|
295
|
-
},
|
|
296
|
-
|
|
297
|
-
transformedErrors () {
|
|
298
|
-
return Array.isArray(this.errors) ? this.errors : constructObject(this.fieldName, this.errors)
|
|
299
|
-
},
|
|
300
|
-
|
|
301
|
-
showAddFirstInputButton () {
|
|
302
|
-
return this.useFirstInputButton && !this.nested.length
|
|
303
|
-
},
|
|
304
|
-
|
|
305
|
-
addButtonClass () {
|
|
306
|
-
return {
|
|
307
|
-
'q-mt-md': !!this.nested.length
|
|
308
|
-
}
|
|
309
|
-
},
|
|
310
|
-
|
|
311
|
-
formGeneratorParentClasses () {
|
|
312
|
-
return this.useInlineActions ? 'col-12 justify-between q-col-gutter-x-md row' : 'full-width'
|
|
313
|
-
}
|
|
314
|
-
},
|
|
315
|
-
|
|
316
|
-
watch: {
|
|
317
|
-
modelValue: {
|
|
318
|
-
handler (value) {
|
|
319
|
-
this.nested = extend(true, [], value)
|
|
320
|
-
},
|
|
321
|
-
deep: true,
|
|
322
|
-
immediate: true
|
|
323
|
-
},
|
|
324
|
-
|
|
325
|
-
rowObject: {
|
|
326
|
-
handler () {
|
|
327
|
-
this.setDefaultNestedValue()
|
|
328
|
-
},
|
|
329
|
-
immediate: true
|
|
330
|
-
},
|
|
331
|
-
|
|
332
|
-
useDestroyAlways: {
|
|
333
|
-
handler (value) {
|
|
334
|
-
this.hasDestroyAlways = value ?? this.useStartsEmpty
|
|
335
|
-
},
|
|
336
|
-
immediate: true
|
|
337
|
-
}
|
|
338
|
-
},
|
|
339
|
-
|
|
340
|
-
methods: {
|
|
341
|
-
getInlineActionsMenuProps (index, row) {
|
|
342
|
-
if (typeof this.actionsMenuProps === 'function' && this.useInlineActions) {
|
|
343
|
-
return this.actionsMenuProps({
|
|
344
|
-
index,
|
|
345
|
-
row,
|
|
346
|
-
list: this.getDefaultActionsMenuList(index, row)
|
|
347
|
-
})
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
return {
|
|
351
|
-
...this.actionsMenuProps,
|
|
352
|
-
list: this.getActionsMenuList(index, row, this.actionsMenuProps?.list)
|
|
353
|
-
}
|
|
354
|
-
},
|
|
355
|
-
|
|
356
|
-
getDefaultActionsMenuList (index, row) {
|
|
357
|
-
const list = {}
|
|
358
|
-
|
|
359
|
-
if (this.useDuplicate) {
|
|
360
|
-
list.duplicate = {
|
|
361
|
-
...this.buttonDuplicateProps,
|
|
362
|
-
handler: () => this.add(row)
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
if (this.showDestroyButton) {
|
|
367
|
-
list.destroy = {
|
|
368
|
-
...this.buttonDestroyProps,
|
|
369
|
-
handler: () => this.destroy(index, row)
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
return list
|
|
374
|
-
},
|
|
375
|
-
|
|
376
|
-
getActionsMenuList (index, row, defaultList = {}) {
|
|
377
|
-
const list = this.getDefaultActionsMenuList(index, row)
|
|
378
|
-
|
|
379
|
-
for (const key in defaultList) {
|
|
380
|
-
const { handler, ...content } = defaultList[key] || {}
|
|
381
|
-
|
|
382
|
-
list[key] = {
|
|
383
|
-
handler: payload => handler?.({ payload, row, index }),
|
|
384
|
-
...content
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
return list
|
|
389
|
-
},
|
|
390
|
-
|
|
391
|
-
getFields (index, row) {
|
|
392
|
-
const fields = this.children
|
|
393
|
-
|
|
394
|
-
if (this.fieldsHandlerFn) {
|
|
395
|
-
return this.fieldsHandlerFn({ fields, index, row })
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
return fields
|
|
399
|
-
},
|
|
400
|
-
|
|
401
|
-
getFieldsProps (index, row) {
|
|
402
|
-
if (typeof this.fieldsProps === 'function') {
|
|
403
|
-
return this.fieldsProps({ index, row })
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
return this.fieldsProps
|
|
407
|
-
},
|
|
408
|
-
|
|
409
|
-
add (row = {}) {
|
|
410
|
-
const payload = { ...this.rowObject, ...row }
|
|
411
|
-
const hasIdentifierKey = payload[this.identifierItemKey]
|
|
412
|
-
|
|
413
|
-
if (hasIdentifierKey) {
|
|
414
|
-
delete payload[this.identifierItemKey]
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
this.nested.push(payload)
|
|
418
|
-
|
|
419
|
-
this.$nextTick(() => {
|
|
420
|
-
this.useAnimation && this.setScroll()
|
|
421
|
-
this.setFocus()
|
|
422
|
-
})
|
|
423
|
-
|
|
424
|
-
log('add', payload)
|
|
425
|
-
|
|
426
|
-
this.updateModelValue()
|
|
427
|
-
},
|
|
428
|
-
|
|
429
|
-
/*
|
|
430
|
-
* Se o item que for removido não tiver o identificador (uuid por ex) e "useRemoveOnDestroy" for "false"
|
|
431
|
-
* ou "useRemoveOnDestroy" for "true" removemos o item do array, senão adicionamos a flag [destroyKey]
|
|
432
|
-
* no item referente do array.
|
|
433
|
-
*
|
|
434
|
-
* Ex: ao adicionar um item e remover sem salvar, mesmo que useRemoveOnDestroy for false ele será removido
|
|
435
|
-
* ao invés de adicionar a flag [destroyKey]
|
|
436
|
-
*/
|
|
437
|
-
destroy (index, row) {
|
|
438
|
-
!row[this.identifierItemKey] || this.useRemoveOnDestroy
|
|
439
|
-
? this.nested.splice(index, 1)
|
|
440
|
-
: this.nested.splice(index, 1, { [this.destroyKey]: true, ...row })
|
|
441
|
-
|
|
442
|
-
log('destroy', { index, row })
|
|
443
|
-
|
|
444
|
-
this.updateModelValue()
|
|
445
|
-
},
|
|
446
|
-
|
|
447
|
-
updateModelValue () {
|
|
448
|
-
this.$emit('update:modelValue', this.nested)
|
|
449
|
-
},
|
|
450
|
-
|
|
451
|
-
updateValuesFromInput (value, index) {
|
|
452
|
-
this.nested.splice(index, 1, value)
|
|
453
|
-
|
|
454
|
-
this.updateModelValue()
|
|
455
|
-
},
|
|
456
|
-
|
|
457
|
-
setDefaultNestedValue () {
|
|
458
|
-
if (this.nested.length || this.useStartsEmpty) return
|
|
459
|
-
this.nested.splice(0, 0, { ...this.rowObject })
|
|
460
|
-
},
|
|
461
|
-
|
|
462
|
-
setScroll () {
|
|
463
|
-
const elements = this.$refs.inputContent.children
|
|
464
|
-
|
|
465
|
-
// elemento de ação, e não das linhas (rows) de inputs
|
|
466
|
-
const element = elements[elements.length - 1]
|
|
467
|
-
|
|
468
|
-
// ultima linha (rows) de inputs
|
|
469
|
-
const rowsElement = elements[0]?.children
|
|
470
|
-
|
|
471
|
-
// pegamos a posição do elemento de ação
|
|
472
|
-
const { top } = element.getBoundingClientRect()
|
|
473
|
-
|
|
474
|
-
// pegamos a altura da ultima linha (rows) de inputs
|
|
475
|
-
const lastRowHeight = rowsElement?.[rowsElement.length - 1]?.clientHeight
|
|
476
|
-
|
|
477
|
-
// pegamos a posição da página
|
|
478
|
-
const pageOffset = window.scrollY
|
|
479
|
-
|
|
480
|
-
// 56 é a altura do header no mobile
|
|
481
|
-
const safeScrollSize = this.$qas.screen.isSmall ? 56 + SpacingWithNumber.Lg : SpacingWithNumber.Lg
|
|
482
|
-
|
|
483
|
-
/**
|
|
484
|
-
* É necessário descontar a altura da última linha (rows) de inputs para que o scroll
|
|
485
|
-
* fique no final da última linha (rows) de inputs.
|
|
486
|
-
*/
|
|
487
|
-
const scrollTop = pageOffset + top - (lastRowHeight + safeScrollSize)
|
|
488
|
-
|
|
489
|
-
window.scrollTo({ behavior: 'smooth', top: scrollTop })
|
|
490
|
-
},
|
|
491
|
-
|
|
492
|
-
async setFocus () {
|
|
493
|
-
await this.$nextTick()
|
|
494
|
-
|
|
495
|
-
const { formGenerator } = this.$refs
|
|
496
|
-
const firstElementToBeFocused = formGenerator.pop().querySelector('input, select, textarea')
|
|
497
|
-
|
|
498
|
-
return firstElementToBeFocused?.focus && firstElementToBeFocused.focus()
|
|
499
|
-
},
|
|
500
|
-
|
|
501
|
-
getRealRowIndex (index) {
|
|
502
|
-
return [...this.nested].splice(0, index).filter(item => !item[this.destroyKey]).length
|
|
503
|
-
},
|
|
504
|
-
|
|
505
|
-
getRowLabel (rowIndex) {
|
|
506
|
-
if (this.rowLabel) {
|
|
507
|
-
if (!this.useIndexLabel) return this.rowLabel
|
|
508
|
-
|
|
509
|
-
const index = this.useRemoveOnDestroy ? rowIndex : this.getRealRowIndex(rowIndex)
|
|
510
|
-
|
|
511
|
-
return `${this.rowLabel} ${index + 1}`
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
return this.fieldLabel
|
|
515
|
-
},
|
|
516
|
-
|
|
517
|
-
isDisabledRow (row) {
|
|
518
|
-
if (!this.disabledRows) return false
|
|
519
|
-
|
|
520
|
-
if (typeof this.disabledRows === 'function') return this.disabledRows(row)
|
|
521
|
-
|
|
522
|
-
if (typeof this.disabledRows === 'boolean') return true
|
|
523
|
-
|
|
524
|
-
return this.disabledRows.includes(row[this.identifierItemKey])
|
|
525
|
-
},
|
|
526
|
-
|
|
527
|
-
hasBlockActions (row) {
|
|
528
|
-
return !this.useInlineActions && !this.isDisabledRow(row)
|
|
529
|
-
},
|
|
530
|
-
|
|
531
|
-
hasInlineActions (row) {
|
|
532
|
-
return this.useInlineActions && !this.isDisabledRow(row)
|
|
533
|
-
},
|
|
534
|
-
|
|
535
|
-
hasHeader ({ row }) {
|
|
536
|
-
return this.hasBlockActions(row) || !this.useSingleLabel
|
|
537
|
-
},
|
|
538
|
-
|
|
539
|
-
getHeaderProps ({ index, row }) {
|
|
540
|
-
const hasLabel = !this.useSingleLabel
|
|
541
|
-
const hasActions = this.hasBlockActions(row)
|
|
542
|
-
|
|
543
|
-
const { labelProps, actionsMenuProps, ...payload } = this.headerProps?.({ index, row }) || {}
|
|
544
|
-
|
|
545
|
-
return {
|
|
546
|
-
...payload,
|
|
547
|
-
|
|
548
|
-
spacing: 'sm',
|
|
549
|
-
|
|
550
|
-
...(hasActions && {
|
|
551
|
-
actionsMenuProps: {
|
|
552
|
-
useLabel: false,
|
|
553
|
-
|
|
554
|
-
...actionsMenuProps,
|
|
555
|
-
|
|
556
|
-
list: this.getActionsMenuList(index, row, actionsMenuProps?.list)
|
|
557
|
-
}
|
|
558
|
-
}),
|
|
559
|
-
|
|
560
|
-
...(hasLabel && {
|
|
561
|
-
labelProps: {
|
|
562
|
-
typography: 'h5',
|
|
563
|
-
label: this.getRowLabel(index),
|
|
564
|
-
...labelProps
|
|
565
|
-
}
|
|
566
|
-
})
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
</script>
|
|
572
|
-
|
|
573
|
-
<style lang="scss">
|
|
574
|
-
.qas-nested-fields {
|
|
575
|
-
// mesmo tamanho do input
|
|
576
|
-
&__actions {
|
|
577
|
-
height: 40px;
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
&__field-item + &__field-item {
|
|
581
|
-
margin-top: var(--qas-spacing-lg);
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<div :id="fieldName" class="qas-nested-fields" :data-cy="`nested-fields-${fieldName}`">
|
|
3
|
+
<component :is="containerComponent">
|
|
4
|
+
<div v-if="useSingleLabel" class="text-left">
|
|
5
|
+
<qas-label :label="fieldLabel" />
|
|
6
|
+
</div>
|
|
7
|
+
|
|
8
|
+
<div ref="inputContent">
|
|
9
|
+
<component :is="componentTag" v-bind="componentProps">
|
|
10
|
+
<template v-for="(row, index) in nested" :key="`row-${index}`">
|
|
11
|
+
<div v-if="!row[destroyKey]" :id="`row-${index}`" class="full-width qas-nested-fields__field-item" data-cy="nested-fields-item">
|
|
12
|
+
<qas-header v-if="hasHeader({ row })" class="flex" v-bind="getHeaderProps({ index, row })" />
|
|
13
|
+
|
|
14
|
+
<slot :errors="transformedErrors" :fields="getFields(index, row)" :index="index" :model="nested[index]" name="before-fields" :update-value="updateValuesFromInput" />
|
|
15
|
+
|
|
16
|
+
<div ref="formGenerator" :class="formGeneratorParentClasses">
|
|
17
|
+
<slot :errors="transformedErrors" :fields="getFields(index, row)" :index="index" name="fields" :update-value="updateValuesFromInput">
|
|
18
|
+
<qas-form-generator v-model="nested[index]" class="col" :columns="formColumns" :common-columns="formCommonColumns" :disable="isDisabledRow(row)" :errors="transformedErrors[index]" :fields="getFields(index, row)" :fields-props="getFieldsProps(index, row)" :gutter="formGutter" @update:model-value="updateValuesFromInput($event, index)">
|
|
19
|
+
<template v-for="(slot, key) in $slots" #[key]="scope">
|
|
20
|
+
<slot v-bind="scope" :disabled="isDisabledRow(row)" :errors="transformedErrors" :index="index" :name="key" />
|
|
21
|
+
</template>
|
|
22
|
+
</qas-form-generator>
|
|
23
|
+
</slot>
|
|
24
|
+
|
|
25
|
+
<div v-if="hasInlineActions(row)" class="flex items-center qas-nested-fields__actions">
|
|
26
|
+
<qas-actions-menu v-bind="getInlineActionsMenuProps(index, row)" :use-label="false" />
|
|
27
|
+
</div>
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
<slot :errors="transformedErrors" :fields="getFields(index, row)" :index="index" :model="nested[index]" name="after-fields" :update-value="updateValuesFromInput" />
|
|
31
|
+
</div>
|
|
32
|
+
</template>
|
|
33
|
+
</component>
|
|
34
|
+
|
|
35
|
+
<div v-if="useAdd" :class="addButtonClass">
|
|
36
|
+
<slot :add="add" name="add-input">
|
|
37
|
+
<div v-if="showAddFirstInputButton" class="text-left">
|
|
38
|
+
<qas-btn class="q-px-sm" color="primary" data-cy="nested-fields-add-btn" :label="addFirstInputLabel" variant="tertiary" @click="add()" />
|
|
39
|
+
</div>
|
|
40
|
+
|
|
41
|
+
<div v-else-if="useInlineActions" class="cursor-pointer items-center q-col-gutter-x-md q-mt-md row" data-cy="nested-fields-add-btn" @click="add()">
|
|
42
|
+
<div class="col">
|
|
43
|
+
<qas-input class="disabled no-pointer-events" hide-bottom-space :label="addInputLabel" @focus="add()" />
|
|
44
|
+
</div>
|
|
45
|
+
|
|
46
|
+
<div class="col-auto">
|
|
47
|
+
<qas-btn color="primary" icon="sym_r_add_circle_outline" variant="tertiary" />
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
50
|
+
|
|
51
|
+
<div v-else class="text-left">
|
|
52
|
+
<qas-btn class="q-px-sm" color="primary" data-cy="nested-fields-add-btn" icon="sym_r_add" :label="addInputLabel" variant="tertiary" @click="add()" />
|
|
53
|
+
</div>
|
|
54
|
+
</slot>
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
</component>
|
|
58
|
+
</div>
|
|
59
|
+
</template>
|
|
60
|
+
|
|
61
|
+
<script>
|
|
62
|
+
import QasActionsMenu from '../actions-menu/QasActionsMenu.vue'
|
|
63
|
+
import QasBtn from '../btn/QasBtn.vue'
|
|
64
|
+
import QasFormGenerator from '../form-generator/QasFormGenerator.vue'
|
|
65
|
+
import QasInput from '../input/QasInput.vue'
|
|
66
|
+
import QasLabel from '../label/QasLabel.vue'
|
|
67
|
+
|
|
68
|
+
import { constructObject } from '../../helpers'
|
|
69
|
+
import { Spacing, SpacingWithNumber } from '../../enums/Spacing'
|
|
70
|
+
|
|
71
|
+
import { TransitionGroup } from 'vue'
|
|
72
|
+
import debug from 'debug'
|
|
73
|
+
import { extend } from 'quasar'
|
|
74
|
+
|
|
75
|
+
const log = debug('asteroid-ui:qas-nested-fields')
|
|
76
|
+
|
|
77
|
+
export default {
|
|
78
|
+
name: 'QasNestedFields',
|
|
79
|
+
|
|
80
|
+
components: {
|
|
81
|
+
QasActionsMenu,
|
|
82
|
+
QasBtn,
|
|
83
|
+
QasFormGenerator,
|
|
84
|
+
QasInput,
|
|
85
|
+
QasLabel,
|
|
86
|
+
|
|
87
|
+
// Vue
|
|
88
|
+
TransitionGroup
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
props: {
|
|
92
|
+
actionsMenuProps: {
|
|
93
|
+
type: [Object, Function],
|
|
94
|
+
default: () => ({})
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
addFirstInputLabel: {
|
|
98
|
+
type: String,
|
|
99
|
+
default: 'Clique aqui para adicionar'
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
addInputLabel: {
|
|
103
|
+
type: String,
|
|
104
|
+
default: 'Adicionar'
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
buttonDestroyProps: {
|
|
108
|
+
type: Object,
|
|
109
|
+
default: () => {
|
|
110
|
+
return {
|
|
111
|
+
color: 'grey-10',
|
|
112
|
+
icon: 'sym_r_delete',
|
|
113
|
+
label: 'Excluir',
|
|
114
|
+
variant: 'tertiary'
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
buttonDuplicateProps: {
|
|
120
|
+
type: Object,
|
|
121
|
+
default: () => {
|
|
122
|
+
return {
|
|
123
|
+
icon: 'sym_r_content_copy',
|
|
124
|
+
label: 'Duplicar',
|
|
125
|
+
useLabelOnSmallScreen: false,
|
|
126
|
+
variant: 'tertiary'
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
destroyKey: {
|
|
132
|
+
type: String,
|
|
133
|
+
default: 'destroyed'
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
disabledRows: {
|
|
137
|
+
type: [Array, Boolean, Function],
|
|
138
|
+
default: false
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
errors: {
|
|
142
|
+
type: [Array, Object],
|
|
143
|
+
default: () => ({})
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
field: {
|
|
147
|
+
type: Object,
|
|
148
|
+
default: () => ({})
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
fieldsHandlerFn: {
|
|
152
|
+
type: Function,
|
|
153
|
+
default: undefined
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
fieldsProps: {
|
|
157
|
+
type: [Object, Function],
|
|
158
|
+
default: () => ({})
|
|
159
|
+
},
|
|
160
|
+
|
|
161
|
+
formColumns: {
|
|
162
|
+
type: [Array, String, Object],
|
|
163
|
+
default: () => []
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
formCommonColumns: {
|
|
167
|
+
type: [Object, String],
|
|
168
|
+
default: () => ({})
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
formGutter: {
|
|
172
|
+
default: Spacing.Md,
|
|
173
|
+
type: [String, Boolean],
|
|
174
|
+
validator: value => typeof value === 'boolean' || Object.values(Spacing).includes(value)
|
|
175
|
+
},
|
|
176
|
+
|
|
177
|
+
headerProps: {
|
|
178
|
+
type: Function,
|
|
179
|
+
default: () => {}
|
|
180
|
+
},
|
|
181
|
+
|
|
182
|
+
identifierItemKey: {
|
|
183
|
+
type: String,
|
|
184
|
+
default: 'uuid'
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
rowLabel: {
|
|
188
|
+
type: String,
|
|
189
|
+
default: ''
|
|
190
|
+
},
|
|
191
|
+
|
|
192
|
+
rowObject: {
|
|
193
|
+
type: Object,
|
|
194
|
+
default: () => ({})
|
|
195
|
+
},
|
|
196
|
+
|
|
197
|
+
useAdd: {
|
|
198
|
+
type: Boolean,
|
|
199
|
+
default: true
|
|
200
|
+
},
|
|
201
|
+
|
|
202
|
+
useAnimation: {
|
|
203
|
+
type: Boolean,
|
|
204
|
+
default: true
|
|
205
|
+
},
|
|
206
|
+
|
|
207
|
+
useBox: {
|
|
208
|
+
type: Boolean
|
|
209
|
+
},
|
|
210
|
+
|
|
211
|
+
useDestroyAlways: {
|
|
212
|
+
type: Boolean,
|
|
213
|
+
default: undefined
|
|
214
|
+
},
|
|
215
|
+
|
|
216
|
+
useDuplicate: {
|
|
217
|
+
type: Boolean,
|
|
218
|
+
default: true
|
|
219
|
+
},
|
|
220
|
+
|
|
221
|
+
useFirstInputButton: {
|
|
222
|
+
type: Boolean,
|
|
223
|
+
default: true
|
|
224
|
+
},
|
|
225
|
+
|
|
226
|
+
useIndexLabel: {
|
|
227
|
+
type: Boolean
|
|
228
|
+
},
|
|
229
|
+
|
|
230
|
+
useInlineActions: {
|
|
231
|
+
type: Boolean
|
|
232
|
+
},
|
|
233
|
+
|
|
234
|
+
useSingleLabel: {
|
|
235
|
+
type: Boolean
|
|
236
|
+
},
|
|
237
|
+
|
|
238
|
+
useRemoveOnDestroy: {
|
|
239
|
+
type: Boolean,
|
|
240
|
+
default: true
|
|
241
|
+
},
|
|
242
|
+
|
|
243
|
+
useStartsEmpty: {
|
|
244
|
+
default: true,
|
|
245
|
+
type: Boolean
|
|
246
|
+
},
|
|
247
|
+
|
|
248
|
+
modelValue: {
|
|
249
|
+
type: Array,
|
|
250
|
+
default: () => []
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
|
|
254
|
+
emits: ['update:modelValue'],
|
|
255
|
+
|
|
256
|
+
data () {
|
|
257
|
+
return {
|
|
258
|
+
nested: [],
|
|
259
|
+
hasDestroyAlways: true
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
|
|
263
|
+
computed: {
|
|
264
|
+
children () {
|
|
265
|
+
return this.field?.children
|
|
266
|
+
},
|
|
267
|
+
|
|
268
|
+
containerComponent () {
|
|
269
|
+
return this.useBox ? 'qas-box' : 'div'
|
|
270
|
+
},
|
|
271
|
+
|
|
272
|
+
componentTag () {
|
|
273
|
+
return this.useAnimation ? 'transition-group' : 'div'
|
|
274
|
+
},
|
|
275
|
+
|
|
276
|
+
componentProps () {
|
|
277
|
+
if (!this.useAnimation) return {}
|
|
278
|
+
|
|
279
|
+
return {
|
|
280
|
+
tag: 'div',
|
|
281
|
+
enterActiveClass: 'animated slideInDown'
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
|
|
285
|
+
fieldLabel () {
|
|
286
|
+
return this.field?.label
|
|
287
|
+
},
|
|
288
|
+
|
|
289
|
+
fieldName () {
|
|
290
|
+
return this.field?.name
|
|
291
|
+
},
|
|
292
|
+
|
|
293
|
+
showDestroyButton () {
|
|
294
|
+
return this.nested.filter(item => !item[this.destroyKey]).length > 1 || this.hasDestroyAlways
|
|
295
|
+
},
|
|
296
|
+
|
|
297
|
+
transformedErrors () {
|
|
298
|
+
return Array.isArray(this.errors) ? this.errors : constructObject(this.fieldName, this.errors)
|
|
299
|
+
},
|
|
300
|
+
|
|
301
|
+
showAddFirstInputButton () {
|
|
302
|
+
return this.useFirstInputButton && !this.nested.length
|
|
303
|
+
},
|
|
304
|
+
|
|
305
|
+
addButtonClass () {
|
|
306
|
+
return {
|
|
307
|
+
'q-mt-md': !!this.nested.length
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
|
|
311
|
+
formGeneratorParentClasses () {
|
|
312
|
+
return this.useInlineActions ? 'col-12 justify-between q-col-gutter-x-md row' : 'full-width'
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
|
|
316
|
+
watch: {
|
|
317
|
+
modelValue: {
|
|
318
|
+
handler (value) {
|
|
319
|
+
this.nested = extend(true, [], value)
|
|
320
|
+
},
|
|
321
|
+
deep: true,
|
|
322
|
+
immediate: true
|
|
323
|
+
},
|
|
324
|
+
|
|
325
|
+
rowObject: {
|
|
326
|
+
handler () {
|
|
327
|
+
this.setDefaultNestedValue()
|
|
328
|
+
},
|
|
329
|
+
immediate: true
|
|
330
|
+
},
|
|
331
|
+
|
|
332
|
+
useDestroyAlways: {
|
|
333
|
+
handler (value) {
|
|
334
|
+
this.hasDestroyAlways = value ?? this.useStartsEmpty
|
|
335
|
+
},
|
|
336
|
+
immediate: true
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
|
|
340
|
+
methods: {
|
|
341
|
+
getInlineActionsMenuProps (index, row) {
|
|
342
|
+
if (typeof this.actionsMenuProps === 'function' && this.useInlineActions) {
|
|
343
|
+
return this.actionsMenuProps({
|
|
344
|
+
index,
|
|
345
|
+
row,
|
|
346
|
+
list: this.getDefaultActionsMenuList(index, row)
|
|
347
|
+
})
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
return {
|
|
351
|
+
...this.actionsMenuProps,
|
|
352
|
+
list: this.getActionsMenuList(index, row, this.actionsMenuProps?.list)
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
|
|
356
|
+
getDefaultActionsMenuList (index, row) {
|
|
357
|
+
const list = {}
|
|
358
|
+
|
|
359
|
+
if (this.useDuplicate) {
|
|
360
|
+
list.duplicate = {
|
|
361
|
+
...this.buttonDuplicateProps,
|
|
362
|
+
handler: () => this.add(row)
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (this.showDestroyButton) {
|
|
367
|
+
list.destroy = {
|
|
368
|
+
...this.buttonDestroyProps,
|
|
369
|
+
handler: () => this.destroy(index, row)
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
return list
|
|
374
|
+
},
|
|
375
|
+
|
|
376
|
+
getActionsMenuList (index, row, defaultList = {}) {
|
|
377
|
+
const list = this.getDefaultActionsMenuList(index, row)
|
|
378
|
+
|
|
379
|
+
for (const key in defaultList) {
|
|
380
|
+
const { handler, ...content } = defaultList[key] || {}
|
|
381
|
+
|
|
382
|
+
list[key] = {
|
|
383
|
+
handler: payload => handler?.({ payload, row, index }),
|
|
384
|
+
...content
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
return list
|
|
389
|
+
},
|
|
390
|
+
|
|
391
|
+
getFields (index, row) {
|
|
392
|
+
const fields = this.children
|
|
393
|
+
|
|
394
|
+
if (this.fieldsHandlerFn) {
|
|
395
|
+
return this.fieldsHandlerFn({ fields, index, row })
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
return fields
|
|
399
|
+
},
|
|
400
|
+
|
|
401
|
+
getFieldsProps (index, row) {
|
|
402
|
+
if (typeof this.fieldsProps === 'function') {
|
|
403
|
+
return this.fieldsProps({ index, row })
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
return this.fieldsProps
|
|
407
|
+
},
|
|
408
|
+
|
|
409
|
+
add (row = {}) {
|
|
410
|
+
const payload = { ...this.rowObject, ...row }
|
|
411
|
+
const hasIdentifierKey = payload[this.identifierItemKey]
|
|
412
|
+
|
|
413
|
+
if (hasIdentifierKey) {
|
|
414
|
+
delete payload[this.identifierItemKey]
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
this.nested.push(payload)
|
|
418
|
+
|
|
419
|
+
this.$nextTick(() => {
|
|
420
|
+
this.useAnimation && this.setScroll()
|
|
421
|
+
this.setFocus()
|
|
422
|
+
})
|
|
423
|
+
|
|
424
|
+
log('add', payload)
|
|
425
|
+
|
|
426
|
+
this.updateModelValue()
|
|
427
|
+
},
|
|
428
|
+
|
|
429
|
+
/*
|
|
430
|
+
* Se o item que for removido não tiver o identificador (uuid por ex) e "useRemoveOnDestroy" for "false"
|
|
431
|
+
* ou "useRemoveOnDestroy" for "true" removemos o item do array, senão adicionamos a flag [destroyKey]
|
|
432
|
+
* no item referente do array.
|
|
433
|
+
*
|
|
434
|
+
* Ex: ao adicionar um item e remover sem salvar, mesmo que useRemoveOnDestroy for false ele será removido
|
|
435
|
+
* ao invés de adicionar a flag [destroyKey]
|
|
436
|
+
*/
|
|
437
|
+
destroy (index, row) {
|
|
438
|
+
!row[this.identifierItemKey] || this.useRemoveOnDestroy
|
|
439
|
+
? this.nested.splice(index, 1)
|
|
440
|
+
: this.nested.splice(index, 1, { [this.destroyKey]: true, ...row })
|
|
441
|
+
|
|
442
|
+
log('destroy', { index, row })
|
|
443
|
+
|
|
444
|
+
this.updateModelValue()
|
|
445
|
+
},
|
|
446
|
+
|
|
447
|
+
updateModelValue () {
|
|
448
|
+
this.$emit('update:modelValue', this.nested)
|
|
449
|
+
},
|
|
450
|
+
|
|
451
|
+
updateValuesFromInput (value, index) {
|
|
452
|
+
this.nested.splice(index, 1, value)
|
|
453
|
+
|
|
454
|
+
this.updateModelValue()
|
|
455
|
+
},
|
|
456
|
+
|
|
457
|
+
setDefaultNestedValue () {
|
|
458
|
+
if (this.nested.length || this.useStartsEmpty) return
|
|
459
|
+
this.nested.splice(0, 0, { ...this.rowObject })
|
|
460
|
+
},
|
|
461
|
+
|
|
462
|
+
setScroll () {
|
|
463
|
+
const elements = this.$refs.inputContent.children
|
|
464
|
+
|
|
465
|
+
// elemento de ação, e não das linhas (rows) de inputs
|
|
466
|
+
const element = elements[elements.length - 1]
|
|
467
|
+
|
|
468
|
+
// ultima linha (rows) de inputs
|
|
469
|
+
const rowsElement = elements[0]?.children
|
|
470
|
+
|
|
471
|
+
// pegamos a posição do elemento de ação
|
|
472
|
+
const { top } = element.getBoundingClientRect()
|
|
473
|
+
|
|
474
|
+
// pegamos a altura da ultima linha (rows) de inputs
|
|
475
|
+
const lastRowHeight = rowsElement?.[rowsElement.length - 1]?.clientHeight
|
|
476
|
+
|
|
477
|
+
// pegamos a posição da página
|
|
478
|
+
const pageOffset = window.scrollY
|
|
479
|
+
|
|
480
|
+
// 56 é a altura do header no mobile
|
|
481
|
+
const safeScrollSize = this.$qas.screen.isSmall ? 56 + SpacingWithNumber.Lg : SpacingWithNumber.Lg
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* É necessário descontar a altura da última linha (rows) de inputs para que o scroll
|
|
485
|
+
* fique no final da última linha (rows) de inputs.
|
|
486
|
+
*/
|
|
487
|
+
const scrollTop = pageOffset + top - (lastRowHeight + safeScrollSize)
|
|
488
|
+
|
|
489
|
+
window.scrollTo({ behavior: 'smooth', top: scrollTop })
|
|
490
|
+
},
|
|
491
|
+
|
|
492
|
+
async setFocus () {
|
|
493
|
+
await this.$nextTick()
|
|
494
|
+
|
|
495
|
+
const { formGenerator } = this.$refs
|
|
496
|
+
const firstElementToBeFocused = formGenerator.pop().querySelector('input, select, textarea')
|
|
497
|
+
|
|
498
|
+
return firstElementToBeFocused?.focus && firstElementToBeFocused.focus()
|
|
499
|
+
},
|
|
500
|
+
|
|
501
|
+
getRealRowIndex (index) {
|
|
502
|
+
return [...this.nested].splice(0, index).filter(item => !item[this.destroyKey]).length
|
|
503
|
+
},
|
|
504
|
+
|
|
505
|
+
getRowLabel (rowIndex) {
|
|
506
|
+
if (this.rowLabel) {
|
|
507
|
+
if (!this.useIndexLabel) return this.rowLabel
|
|
508
|
+
|
|
509
|
+
const index = this.useRemoveOnDestroy ? rowIndex : this.getRealRowIndex(rowIndex)
|
|
510
|
+
|
|
511
|
+
return `${this.rowLabel} ${index + 1}`
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
return this.fieldLabel
|
|
515
|
+
},
|
|
516
|
+
|
|
517
|
+
isDisabledRow (row) {
|
|
518
|
+
if (!this.disabledRows) return false
|
|
519
|
+
|
|
520
|
+
if (typeof this.disabledRows === 'function') return this.disabledRows(row)
|
|
521
|
+
|
|
522
|
+
if (typeof this.disabledRows === 'boolean') return true
|
|
523
|
+
|
|
524
|
+
return this.disabledRows.includes(row[this.identifierItemKey])
|
|
525
|
+
},
|
|
526
|
+
|
|
527
|
+
hasBlockActions (row) {
|
|
528
|
+
return !this.useInlineActions && !this.isDisabledRow(row)
|
|
529
|
+
},
|
|
530
|
+
|
|
531
|
+
hasInlineActions (row) {
|
|
532
|
+
return this.useInlineActions && !this.isDisabledRow(row)
|
|
533
|
+
},
|
|
534
|
+
|
|
535
|
+
hasHeader ({ row }) {
|
|
536
|
+
return this.hasBlockActions(row) || !this.useSingleLabel
|
|
537
|
+
},
|
|
538
|
+
|
|
539
|
+
getHeaderProps ({ index, row }) {
|
|
540
|
+
const hasLabel = !this.useSingleLabel
|
|
541
|
+
const hasActions = this.hasBlockActions(row)
|
|
542
|
+
|
|
543
|
+
const { labelProps, actionsMenuProps, ...payload } = this.headerProps?.({ index, row }) || {}
|
|
544
|
+
|
|
545
|
+
return {
|
|
546
|
+
...payload,
|
|
547
|
+
|
|
548
|
+
spacing: 'sm',
|
|
549
|
+
|
|
550
|
+
...(hasActions && {
|
|
551
|
+
actionsMenuProps: {
|
|
552
|
+
useLabel: false,
|
|
553
|
+
|
|
554
|
+
...actionsMenuProps,
|
|
555
|
+
|
|
556
|
+
list: this.getActionsMenuList(index, row, actionsMenuProps?.list)
|
|
557
|
+
}
|
|
558
|
+
}),
|
|
559
|
+
|
|
560
|
+
...(hasLabel && {
|
|
561
|
+
labelProps: {
|
|
562
|
+
typography: 'h5',
|
|
563
|
+
label: this.getRowLabel(index),
|
|
564
|
+
...labelProps
|
|
565
|
+
}
|
|
566
|
+
})
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
</script>
|
|
572
|
+
|
|
573
|
+
<style lang="scss">
|
|
574
|
+
.qas-nested-fields {
|
|
575
|
+
// mesmo tamanho do input
|
|
576
|
+
&__actions {
|
|
577
|
+
height: 40px;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
&__field-item + &__field-item {
|
|
581
|
+
margin-top: var(--qas-spacing-lg);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
</style>
|