@caribeng/ui 22.2.0 → 22.5.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.
- package/README.md +311 -231
- package/fesm2022/caribeng-ui-accordion.mjs +2 -2
- package/fesm2022/caribeng-ui-account-picker.mjs +533 -0
- package/fesm2022/caribeng-ui-aging.mjs +488 -0
- package/fesm2022/{caribeng-ui-caribe-alert.mjs → caribeng-ui-alert.mjs} +45 -45
- package/fesm2022/caribeng-ui-amount.mjs +249 -0
- package/fesm2022/caribeng-ui-anchor.mjs +2 -2
- package/fesm2022/{caribeng-ui-caribe-animation-lottie.mjs → caribeng-ui-animation-lottie.mjs} +41 -41
- package/fesm2022/caribeng-ui-audit-log.mjs +323 -0
- package/fesm2022/caribeng-ui-avatar.mjs +4 -4
- package/fesm2022/caribeng-ui-badge.mjs +8 -2
- package/fesm2022/caribeng-ui-breadcrumb.mjs +26 -9
- package/fesm2022/{caribeng-ui-caribe-button-group.mjs → caribeng-ui-button-group.mjs} +15 -15
- package/fesm2022/caribeng-ui-button.mjs +2 -2
- package/fesm2022/{caribeng-ui-caribe-card-content.mjs → caribeng-ui-card-content.mjs} +39 -39
- package/fesm2022/{caribeng-ui-caribe-card-move.mjs → caribeng-ui-card-move.mjs} +65 -65
- package/fesm2022/{caribeng-ui-caribe-card-primary.mjs → caribeng-ui-card-primary.mjs} +31 -31
- package/fesm2022/{caribeng-ui-caribe-card-select.mjs → caribeng-ui-card-select.mjs} +67 -67
- package/fesm2022/caribeng-ui-carousel.mjs +2 -2
- package/fesm2022/caribeng-ui-cascadeselect.mjs +45 -9
- package/fesm2022/caribeng-ui-chart.mjs +8 -5
- package/fesm2022/caribeng-ui-chat.mjs +1303 -0
- package/fesm2022/{caribeng-ui-caribe-coachmark.mjs → caribeng-ui-coachmark.mjs} +85 -85
- package/fesm2022/caribeng-ui-code-block.mjs +332 -0
- package/fesm2022/caribeng-ui-colorpicker.mjs +99 -5
- package/fesm2022/caribeng-ui-command-palette.mjs +476 -0
- package/fesm2022/caribeng-ui-comments.mjs +864 -0
- package/fesm2022/caribeng-ui-confirmdialog.mjs +78 -13
- package/fesm2022/caribeng-ui-confirmpopup.mjs +91 -16
- package/fesm2022/caribeng-ui-contextmenu.mjs +8 -4
- package/fesm2022/caribeng-ui-copy-button.mjs +230 -0
- package/fesm2022/caribeng-ui-datagrid.mjs +1635 -0
- package/fesm2022/caribeng-ui-dataview.mjs +6 -3
- package/fesm2022/caribeng-ui-datepicker.mjs +2 -2
- package/fesm2022/caribeng-ui-dock.mjs +52 -12
- package/fesm2022/caribeng-ui-document.mjs +495 -0
- package/fesm2022/{caribeng-ui-caribe-dots-indicator.mjs → caribeng-ui-dots-indicator.mjs} +41 -41
- package/fesm2022/caribeng-ui-drawer.mjs +9 -4
- package/fesm2022/caribeng-ui-dynamic-form.mjs +1581 -0
- package/fesm2022/caribeng-ui-editor.mjs +2324 -1311
- package/fesm2022/{caribeng-ui-caribe-expansion-panel.mjs → caribeng-ui-expansion-panel.mjs} +39 -39
- package/fesm2022/{caribeng-ui-caribe-fab-menu.mjs → caribeng-ui-fab-menu.mjs} +75 -75
- package/fesm2022/caribeng-ui-fieldset.mjs +2 -2
- package/fesm2022/caribeng-ui-file-card.mjs +134 -17
- package/fesm2022/{caribeng-ui-caribe-file-download.mjs → caribeng-ui-file-download.mjs} +63 -63
- package/fesm2022/caribeng-ui-financial-report.mjs +380 -0
- package/fesm2022/{caribeng-ui-caribe-float-menu.mjs → caribeng-ui-float-menu.mjs} +31 -31
- package/fesm2022/caribeng-ui-floatlabel.mjs +2 -2
- package/fesm2022/caribeng-ui-flow.mjs +1508 -0
- package/fesm2022/caribeng-ui-folder-card.mjs +122 -12
- package/fesm2022/{caribeng-ui-caribe-footer.mjs → caribeng-ui-footer.mjs} +19 -19
- package/fesm2022/caribeng-ui-gantt.mjs +1094 -0
- package/fesm2022/{caribeng-ui-caribe-header.mjs → caribeng-ui-header.mjs} +49 -49
- package/fesm2022/{caribeng-ui-caribe-icon-button.mjs → caribeng-ui-icon-button.mjs} +23 -23
- package/fesm2022/caribeng-ui-image-cropper.mjs +671 -0
- package/fesm2022/caribeng-ui-import-wizard.mjs +746 -0
- package/fesm2022/caribeng-ui-infinite-scroll.mjs +226 -0
- package/fesm2022/caribeng-ui-inlinemessage.mjs +2 -2
- package/fesm2022/caribeng-ui-input-number.mjs +22 -6
- package/fesm2022/{caribeng-ui-caribe-input-search.mjs → caribeng-ui-input-search.mjs} +65 -65
- package/fesm2022/{caribeng-ui-caribe-input-token.mjs → caribeng-ui-input-token.mjs} +59 -59
- package/fesm2022/caribeng-ui-inputmask.mjs +8 -2
- package/fesm2022/caribeng-ui-inputotp.mjs +2 -2
- package/fesm2022/caribeng-ui-journal-entry.mjs +340 -0
- package/fesm2022/caribeng-ui-kanban.mjs +4612 -0
- package/fesm2022/caribeng-ui-kbd.mjs +122 -0
- package/fesm2022/caribeng-ui-kpi.mjs +189 -0
- package/fesm2022/{caribeng-ui-caribe-link.mjs → caribeng-ui-link.mjs} +37 -37
- package/fesm2022/caribeng-ui-masonry.mjs +93 -0
- package/fesm2022/caribeng-ui-media-player.mjs +821 -0
- package/fesm2022/caribeng-ui-megamenu.mjs +13 -9
- package/fesm2022/caribeng-ui-mentions.mjs +495 -0
- package/fesm2022/caribeng-ui-menu.mjs +8 -4
- package/fesm2022/caribeng-ui-menubar.mjs +9 -5
- package/fesm2022/caribeng-ui-message.mjs +6 -3
- package/fesm2022/caribeng-ui-notification-center.mjs +636 -0
- package/fesm2022/{caribeng-ui-caribe-off-canvas.mjs → caribeng-ui-off-canvas.mjs} +55 -55
- package/fesm2022/{caribeng-ui-caribe-onboarding.mjs → caribeng-ui-onboarding.mjs} +105 -105
- package/fesm2022/caribeng-ui-orderlist.mjs +2 -2
- package/fesm2022/caribeng-ui-organizationchart.mjs +6 -10
- package/fesm2022/caribeng-ui-panel.mjs +6 -6
- package/fesm2022/caribeng-ui-panelmenu.mjs +9 -6
- package/fesm2022/caribeng-ui-pdfviewer.mjs +1755 -25
- package/fesm2022/caribeng-ui-period-picker.mjs +637 -0
- package/fesm2022/caribeng-ui-phone-input.mjs +688 -0
- package/fesm2022/caribeng-ui-picklist.mjs +2 -2
- package/fesm2022/caribeng-ui-pivot.mjs +419 -0
- package/fesm2022/caribeng-ui-pricing.mjs +263 -69
- package/fesm2022/caribeng-ui-qrcode.mjs +564 -0
- package/fesm2022/caribeng-ui-rating.mjs +14 -17
- package/fesm2022/caribeng-ui-reconciliation.mjs +386 -0
- package/fesm2022/caribeng-ui-ripple.mjs +2 -0
- package/fesm2022/caribeng-ui-scheduler.mjs +1027 -0
- package/fesm2022/caribeng-ui-scrolltop.mjs +3 -1
- package/fesm2022/caribeng-ui-select.mjs +2 -2
- package/fesm2022/{caribeng-ui-caribe-shortcut.mjs → caribeng-ui-shortcut.mjs} +29 -29
- package/fesm2022/caribeng-ui-sidebar.mjs +573 -0
- package/fesm2022/caribeng-ui-signature-pad.mjs +654 -0
- package/fesm2022/{caribeng-ui-caribe-status.mjs → caribeng-ui-status.mjs} +11 -11
- package/fesm2022/{caribeng-ui-caribe-step-indicator.mjs → caribeng-ui-step-indicator.mjs} +53 -53
- package/fesm2022/caribeng-ui-stepper.mjs +12 -5
- package/fesm2022/caribeng-ui-steps.mjs +2 -2
- package/fesm2022/caribeng-ui-table.mjs +333 -19
- package/fesm2022/caribeng-ui-tabmenu.mjs +10 -6
- package/fesm2022/caribeng-ui-tabs.mjs +2 -2
- package/fesm2022/{caribeng-ui-caribe-tag-button.mjs → caribeng-ui-tag-button.mjs} +25 -25
- package/fesm2022/caribeng-ui-tag.mjs +2 -2
- package/fesm2022/caribeng-ui-tieredmenu.mjs +111 -21
- package/fesm2022/{caribeng-ui-caribe-tracker.mjs → caribeng-ui-tracker.mjs} +29 -29
- package/fesm2022/{caribeng-ui-caribe-transaction-status.mjs → caribeng-ui-transaction-status.mjs} +11 -11
- package/fesm2022/caribeng-ui-treeselect.mjs +44 -9
- package/fesm2022/caribeng-ui-treetable.mjs +236 -17
- package/fesm2022/{caribeng-ui-caribe-voucher.mjs → caribeng-ui-voucher.mjs} +45 -45
- package/fesm2022/caribeng-ui-xlsx.mjs +486 -0
- package/fesm2022/caribeng-ui.mjs +1568 -1
- package/package.json +258 -178
- package/schematics/collection.json +5 -0
- package/schematics/migrate-from-primeng/core-icons.json +1 -0
- package/schematics/migrate-from-primeng/icons.js +269 -0
- package/schematics/migrate-from-primeng/index.js +290 -0
- package/schematics/migrate-from-primeng/mappings/button.js +93 -0
- package/schematics/migrate-from-primeng/mappings/card.js +33 -0
- package/schematics/migrate-from-primeng/mappings/checkbox.js +44 -0
- package/schematics/migrate-from-primeng/mappings/confirm.js +221 -0
- package/schematics/migrate-from-primeng/mappings/datepicker.js +121 -0
- package/schematics/migrate-from-primeng/mappings/dialog.js +84 -0
- package/schematics/migrate-from-primeng/mappings/index.js +88 -0
- package/schematics/migrate-from-primeng/mappings/inputnumber.js +62 -0
- package/schematics/migrate-from-primeng/mappings/inputtext.js +60 -0
- package/schematics/migrate-from-primeng/mappings/menu.js +468 -0
- package/schematics/migrate-from-primeng/mappings/multiselect.js +49 -0
- package/schematics/migrate-from-primeng/mappings/radiobutton.js +22 -0
- package/schematics/migrate-from-primeng/mappings/rules.js +206 -0
- package/schematics/migrate-from-primeng/mappings/select.js +97 -0
- package/schematics/migrate-from-primeng/mappings/service-calls.js +100 -0
- package/schematics/migrate-from-primeng/mappings/table.js +613 -0
- package/schematics/migrate-from-primeng/mappings/tabs.js +225 -0
- package/schematics/migrate-from-primeng/mappings/tag.js +29 -0
- package/schematics/migrate-from-primeng/mappings/textarea.js +44 -0
- package/schematics/migrate-from-primeng/mappings/toast.js +173 -0
- package/schematics/migrate-from-primeng/mappings/toggleswitch.js +37 -0
- package/schematics/migrate-from-primeng/mappings/tooltip.js +44 -0
- package/schematics/migrate-from-primeng/mappings/types.js +10 -0
- package/schematics/migrate-from-primeng/report.js +79 -0
- package/schematics/migrate-from-primeng/schema.js +2 -0
- package/schematics/migrate-from-primeng/schema.json +34 -0
- package/schematics/migrate-from-primeng/template.js +387 -0
- package/schematics/migrate-from-primeng/todo.js +5 -0
- package/schematics/migrate-from-primeng/typescript.js +442 -0
- package/schematics/migrate-from-primeng/workspace.js +117 -0
- package/schematics/ng-add/index.js +16 -1
- package/types/caribeng-ui-account-picker.d.ts +142 -0
- package/types/caribeng-ui-aging.d.ts +123 -0
- package/types/{caribeng-ui-caribe-alert.d.ts → caribeng-ui-alert.d.ts} +2 -2
- package/types/caribeng-ui-amount.d.ts +82 -0
- package/types/{caribeng-ui-caribe-animation-lottie.d.ts → caribeng-ui-animation-lottie.d.ts} +2 -2
- package/types/caribeng-ui-audit-log.d.ts +86 -0
- package/types/caribeng-ui-badge.d.ts +3 -1
- package/types/caribeng-ui-breadcrumb.d.ts +9 -1
- package/types/{caribeng-ui-caribe-button-group.d.ts → caribeng-ui-button-group.d.ts} +2 -2
- package/types/{caribeng-ui-caribe-card-content.d.ts → caribeng-ui-card-content.d.ts} +2 -2
- package/types/{caribeng-ui-caribe-card-move.d.ts → caribeng-ui-card-move.d.ts} +1 -1
- package/types/{caribeng-ui-caribe-card-primary.d.ts → caribeng-ui-card-primary.d.ts} +2 -2
- package/types/{caribeng-ui-caribe-card-select.d.ts → caribeng-ui-card-select.d.ts} +2 -2
- package/types/caribeng-ui-cascadeselect.d.ts +6 -0
- package/types/caribeng-ui-chart.d.ts +3 -1
- package/types/caribeng-ui-chat.d.ts +299 -0
- package/types/{caribeng-ui-caribe-coachmark.d.ts → caribeng-ui-coachmark.d.ts} +2 -2
- package/types/caribeng-ui-code-block.d.ts +65 -0
- package/types/caribeng-ui-colorpicker.d.ts +5 -1
- package/types/caribeng-ui-command-palette.d.ts +133 -0
- package/types/caribeng-ui-comments.d.ts +214 -0
- package/types/caribeng-ui-confirmdialog.d.ts +34 -2
- package/types/caribeng-ui-confirmpopup.d.ts +39 -2
- package/types/caribeng-ui-contextmenu.d.ts +7 -0
- package/types/caribeng-ui-copy-button.d.ts +90 -0
- package/types/caribeng-ui-datagrid.d.ts +269 -0
- package/types/caribeng-ui-dataview.d.ts +2 -0
- package/types/caribeng-ui-dock.d.ts +13 -1
- package/types/caribeng-ui-document.d.ts +138 -0
- package/types/{caribeng-ui-caribe-dots-indicator.d.ts → caribeng-ui-dots-indicator.d.ts} +2 -2
- package/types/caribeng-ui-drawer.d.ts +3 -1
- package/types/caribeng-ui-dynamic-form.d.ts +409 -0
- package/types/caribeng-ui-editor.d.ts +110 -12
- package/types/{caribeng-ui-caribe-expansion-panel.d.ts → caribeng-ui-expansion-panel.d.ts} +1 -1
- package/types/{caribeng-ui-caribe-fab-menu.d.ts → caribeng-ui-fab-menu.d.ts} +2 -2
- package/types/caribeng-ui-file-card.d.ts +27 -2
- package/types/{caribeng-ui-caribe-file-download.d.ts → caribeng-ui-file-download.d.ts} +1 -1
- package/types/caribeng-ui-financial-report.d.ts +102 -0
- package/types/{caribeng-ui-caribe-float-menu.d.ts → caribeng-ui-float-menu.d.ts} +2 -2
- package/types/caribeng-ui-flow.d.ts +228 -0
- package/types/caribeng-ui-folder-card.d.ts +27 -5
- package/types/{caribeng-ui-caribe-footer.d.ts → caribeng-ui-footer.d.ts} +2 -2
- package/types/caribeng-ui-gantt.d.ts +244 -0
- package/types/{caribeng-ui-caribe-header.d.ts → caribeng-ui-header.d.ts} +2 -2
- package/types/{caribeng-ui-caribe-icon-button.d.ts → caribeng-ui-icon-button.d.ts} +2 -2
- package/types/{caribeng-ui-caribe-illustration.d.ts → caribeng-ui-illustration.d.ts} +1 -1
- package/types/caribeng-ui-image-cropper.d.ts +169 -0
- package/types/caribeng-ui-import-wizard.d.ts +149 -0
- package/types/caribeng-ui-infinite-scroll.d.ts +75 -0
- package/types/caribeng-ui-input-number.d.ts +1 -1
- package/types/{caribeng-ui-caribe-input-search.d.ts → caribeng-ui-input-search.d.ts} +2 -2
- package/types/{caribeng-ui-caribe-input-token.d.ts → caribeng-ui-input-token.d.ts} +2 -2
- package/types/caribeng-ui-inputmask.d.ts +3 -1
- package/types/caribeng-ui-journal-entry.d.ts +110 -0
- package/types/caribeng-ui-kanban.d.ts +783 -0
- package/types/caribeng-ui-kbd.d.ts +36 -0
- package/types/caribeng-ui-kpi.d.ts +64 -0
- package/types/{caribeng-ui-caribe-link.d.ts → caribeng-ui-link.d.ts} +2 -2
- package/types/{caribeng-ui-caribe-logo.d.ts → caribeng-ui-logo.d.ts} +1 -1
- package/types/caribeng-ui-masonry.d.ts +32 -0
- package/types/caribeng-ui-media-player.d.ts +140 -0
- package/types/caribeng-ui-megamenu.d.ts +11 -0
- package/types/caribeng-ui-mentions.d.ts +127 -0
- package/types/caribeng-ui-menu.d.ts +7 -0
- package/types/caribeng-ui-menubar.d.ts +7 -0
- package/types/caribeng-ui-message.d.ts +2 -0
- package/types/caribeng-ui-notification-center.d.ts +153 -0
- package/types/{caribeng-ui-caribe-off-canvas.d.ts → caribeng-ui-off-canvas.d.ts} +2 -2
- package/types/{caribeng-ui-caribe-onboarding.d.ts → caribeng-ui-onboarding.d.ts} +2 -2
- package/types/caribeng-ui-panelmenu.d.ts +7 -0
- package/types/caribeng-ui-pdfviewer.d.ts +245 -5
- package/types/caribeng-ui-period-picker.d.ts +148 -0
- package/types/caribeng-ui-phone-input.d.ts +168 -0
- package/types/caribeng-ui-pivot.d.ts +116 -0
- package/types/caribeng-ui-pricing.d.ts +41 -4
- package/types/caribeng-ui-qrcode.d.ts +88 -0
- package/types/caribeng-ui-reconciliation.d.ts +109 -0
- package/types/caribeng-ui-scheduler.d.ts +188 -0
- package/types/{caribeng-ui-caribe-shortcut.d.ts → caribeng-ui-shortcut.d.ts} +2 -2
- package/types/caribeng-ui-sidebar.d.ts +167 -0
- package/types/caribeng-ui-signature-pad.d.ts +151 -0
- package/types/{caribeng-ui-caribe-status.d.ts → caribeng-ui-status.d.ts} +2 -2
- package/types/{caribeng-ui-caribe-step-indicator.d.ts → caribeng-ui-step-indicator.d.ts} +2 -2
- package/types/caribeng-ui-stepper.d.ts +2 -0
- package/types/caribeng-ui-table.d.ts +67 -3
- package/types/caribeng-ui-tabmenu.d.ts +7 -0
- package/types/{caribeng-ui-caribe-tag-button.d.ts → caribeng-ui-tag-button.d.ts} +2 -2
- package/types/caribeng-ui-tieredmenu.d.ts +17 -1
- package/types/{caribeng-ui-caribe-tracker.d.ts → caribeng-ui-tracker.d.ts} +2 -2
- package/types/{caribeng-ui-caribe-transaction-status.d.ts → caribeng-ui-transaction-status.d.ts} +2 -2
- package/types/caribeng-ui-treeselect.d.ts +6 -0
- package/types/caribeng-ui-treetable.d.ts +67 -2
- package/types/{caribeng-ui-caribe-voucher.d.ts → caribeng-ui-voucher.d.ts} +2 -2
- package/types/caribeng-ui-xlsx.d.ts +79 -0
- package/types/caribeng-ui.d.ts +985 -2
- package/fesm2022/caribeng-ui-caribe-calendar.mjs +0 -92
- package/fesm2022/caribeng-ui-caribe-circle-loading.mjs +0 -130
- package/fesm2022/caribeng-ui-caribe-data-table.mjs +0 -94
- package/fesm2022/caribeng-ui-caribe-file-select.mjs +0 -88
- package/fesm2022/caribeng-ui-caribe-inline-alert.mjs +0 -100
- package/fesm2022/caribeng-ui-caribe-input-date.mjs +0 -138
- package/fesm2022/caribeng-ui-caribe-input-select.mjs +0 -154
- package/fesm2022/caribeng-ui-caribe-loader.mjs +0 -48
- package/fesm2022/caribeng-ui-caribe-modal.mjs +0 -119
- package/fesm2022/caribeng-ui-caribe-pictogram.mjs +0 -52
- package/fesm2022/caribeng-ui-caribe-pop-over.mjs +0 -104
- package/fesm2022/caribeng-ui-caribe-preloader.mjs +0 -57
- package/fesm2022/caribeng-ui-caribe-progress-bar.mjs +0 -84
- package/fesm2022/caribeng-ui-caribe-stroke.mjs +0 -69
- package/fesm2022/caribeng-ui-caribe-switch.mjs +0 -182
- package/styles/caribeng.css +0 -380
- package/styles/scss/_mixins.scss +0 -46
- package/styles/scss/_overlay.scss +0 -15
- package/styles/scss/_tokens.scss +0 -267
- package/styles/scss/_utilities.scss +0 -73
- package/styles/scss/_variables.scss +0 -33
- package/styles/scss/index.scss +0 -16
- package/types/caribeng-ui-caribe-calendar.d.ts +0 -27
- package/types/caribeng-ui-caribe-circle-loading.d.ts +0 -28
- package/types/caribeng-ui-caribe-data-table.d.ts +0 -26
- package/types/caribeng-ui-caribe-file-select.d.ts +0 -31
- package/types/caribeng-ui-caribe-inline-alert.d.ts +0 -28
- package/types/caribeng-ui-caribe-input-date.d.ts +0 -40
- package/types/caribeng-ui-caribe-input-select.d.ts +0 -47
- package/types/caribeng-ui-caribe-loader.d.ts +0 -22
- package/types/caribeng-ui-caribe-modal.d.ts +0 -21
- package/types/caribeng-ui-caribe-pictogram.d.ts +0 -15
- package/types/caribeng-ui-caribe-pop-over.d.ts +0 -17
- package/types/caribeng-ui-caribe-preloader.d.ts +0 -24
- package/types/caribeng-ui-caribe-progress-bar.d.ts +0 -28
- package/types/caribeng-ui-caribe-stroke.d.ts +0 -17
- package/types/caribeng-ui-caribe-switch.d.ts +0 -55
- /package/fesm2022/{caribeng-ui-caribe-illustration.mjs → caribeng-ui-illustration.mjs} +0 -0
- /package/fesm2022/{caribeng-ui-caribe-logo.mjs → caribeng-ui-logo.mjs} +0 -0
|
@@ -0,0 +1,1581 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { input, inject, TemplateRef, Directive, Injector, ElementRef, contentChildren, model, booleanAttribute, output, computed, signal, effect, untracked, DestroyRef, afterNextRender, ViewEncapsulation, ChangeDetectionStrategy, Component } from '@angular/core';
|
|
3
|
+
import { NgTemplateOutlet } from '@angular/common';
|
|
4
|
+
import * as i1 from '@angular/forms';
|
|
5
|
+
import { Validators, FormGroup, FormArray, FormControl, ReactiveFormsModule } from '@angular/forms';
|
|
6
|
+
import { injectCbTranslation, cbFormat } from '@caribeng/ui';
|
|
7
|
+
import { CbButton } from '@caribeng/ui/button';
|
|
8
|
+
import { CbCheckbox } from '@caribeng/ui/checkbox';
|
|
9
|
+
import { CbChips } from '@caribeng/ui/chips';
|
|
10
|
+
import { CbColorPicker } from '@caribeng/ui/colorpicker';
|
|
11
|
+
import { CbDatepicker } from '@caribeng/ui/datepicker';
|
|
12
|
+
import { CbIcon } from '@caribeng/ui/icon';
|
|
13
|
+
import { CbInput } from '@caribeng/ui/input';
|
|
14
|
+
import { CbInputMask } from '@caribeng/ui/inputmask';
|
|
15
|
+
import { CbInputNumber } from '@caribeng/ui/input-number';
|
|
16
|
+
import { CbMultiSelect } from '@caribeng/ui/multiselect';
|
|
17
|
+
import { CbPassword } from '@caribeng/ui/password';
|
|
18
|
+
import { CbRadio, CbRadioGroup } from '@caribeng/ui/radio';
|
|
19
|
+
import { CbRating } from '@caribeng/ui/rating';
|
|
20
|
+
import { CbSelect } from '@caribeng/ui/select';
|
|
21
|
+
import { CbSelectButton } from '@caribeng/ui/selectbutton';
|
|
22
|
+
import { CbSlider } from '@caribeng/ui/slider';
|
|
23
|
+
import { CbTextarea } from '@caribeng/ui/textarea';
|
|
24
|
+
import { CbToggle } from '@caribeng/ui/toggle';
|
|
25
|
+
|
|
26
|
+
/** Tipos que son solo diseño (no tienen valor). */
|
|
27
|
+
const LAYOUT_TYPES = new Set(['heading', 'paragraph', 'divider']);
|
|
28
|
+
function isLayout(field) {
|
|
29
|
+
return LAYOUT_TYPES.has(field.type ?? '');
|
|
30
|
+
}
|
|
31
|
+
/** Pasos del esquema (sin `steps`, un único paso con todo). */
|
|
32
|
+
function stepsOf(schema) {
|
|
33
|
+
if (schema.steps?.length)
|
|
34
|
+
return schema.steps;
|
|
35
|
+
return [{ title: '', fields: schema.fields, sections: schema.sections }];
|
|
36
|
+
}
|
|
37
|
+
/** Secciones de un paso (los campos sueltos forman una sección sin título), con los campos en su orden. */
|
|
38
|
+
function sectionsOf(step) {
|
|
39
|
+
const out = [];
|
|
40
|
+
if (step.fields?.length)
|
|
41
|
+
out.push({ fields: step.fields });
|
|
42
|
+
return [...out, ...(step.sections ?? [])].map((s) => ({ ...s, fields: ordered(s.fields) }));
|
|
43
|
+
}
|
|
44
|
+
/** Campos ordenados por `order` (los que no lo tienen, en su posición). */
|
|
45
|
+
function ordered(fields) {
|
|
46
|
+
return fields
|
|
47
|
+
.map((f, i) => ({ f, i }))
|
|
48
|
+
.sort((a, b) => (a.f.order ?? a.i) - (b.f.order ?? b.i) || a.i - b.i)
|
|
49
|
+
.map((x) => x.f);
|
|
50
|
+
}
|
|
51
|
+
/** Todos los campos de valor del primer nivel del esquema (en todos los pasos). */
|
|
52
|
+
function fieldsOf(schema) {
|
|
53
|
+
return stepsOf(schema)
|
|
54
|
+
.flatMap((s) => sectionsOf(s))
|
|
55
|
+
.flatMap((s) => s.fields)
|
|
56
|
+
.filter((f) => !isLayout(f) && !!f.key);
|
|
57
|
+
}
|
|
58
|
+
/** Valor responsive resuelto en los cuatro tamaños (cada uno hereda el anterior). */
|
|
59
|
+
function responsive(value, fallback) {
|
|
60
|
+
if (value === undefined || value === null)
|
|
61
|
+
return { base: fallback, sm: fallback, md: fallback, lg: fallback };
|
|
62
|
+
if (typeof value !== 'object')
|
|
63
|
+
return { base: value, sm: value, md: value, lg: value };
|
|
64
|
+
const v = value;
|
|
65
|
+
const base = v.base ?? fallback;
|
|
66
|
+
const sm = v.sm ?? base;
|
|
67
|
+
const md = v.md ?? sm;
|
|
68
|
+
const lg = v.lg ?? md;
|
|
69
|
+
return { base, sm, md, lg };
|
|
70
|
+
}
|
|
71
|
+
function isFilled(value) {
|
|
72
|
+
if (value === null || value === undefined || value === '' || value === false)
|
|
73
|
+
return false;
|
|
74
|
+
if (Array.isArray(value))
|
|
75
|
+
return value.length > 0;
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
function sameValue(a, b) {
|
|
79
|
+
if (a instanceof Date && b instanceof Date)
|
|
80
|
+
return a.getTime() === b.getTime();
|
|
81
|
+
return a === b;
|
|
82
|
+
}
|
|
83
|
+
/** Evalúa una condición contra el valor actual del formulario. */
|
|
84
|
+
function matches(condition, value) {
|
|
85
|
+
if (!condition)
|
|
86
|
+
return true;
|
|
87
|
+
if (typeof condition === 'function')
|
|
88
|
+
return condition(value);
|
|
89
|
+
const rules = Array.isArray(condition) ? condition : [condition];
|
|
90
|
+
return rules.every((rule) => {
|
|
91
|
+
const v = value[rule.field];
|
|
92
|
+
if ('equals' in rule && !(Array.isArray(v) ? v.includes(rule.equals) : sameValue(v, rule.equals)))
|
|
93
|
+
return false;
|
|
94
|
+
if ('notEquals' in rule && sameValue(v, rule.notEquals))
|
|
95
|
+
return false;
|
|
96
|
+
if (rule.in && !rule.in.some((x) => sameValue(x, v)))
|
|
97
|
+
return false;
|
|
98
|
+
if (rule.filled !== undefined && isFilled(v) !== rule.filled)
|
|
99
|
+
return false;
|
|
100
|
+
return true;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/** Valor inicial de un campo, convertido al tipo de su control. */
|
|
104
|
+
function initialValue(field) {
|
|
105
|
+
const v = field.default;
|
|
106
|
+
switch (field.type ?? 'text') {
|
|
107
|
+
case 'checkbox':
|
|
108
|
+
case 'toggle':
|
|
109
|
+
return !!v;
|
|
110
|
+
case 'multiselect':
|
|
111
|
+
case 'chips':
|
|
112
|
+
return Array.isArray(v) ? [...v] : [];
|
|
113
|
+
case 'number':
|
|
114
|
+
case 'slider':
|
|
115
|
+
case 'rating':
|
|
116
|
+
return typeof v === 'number' ? v : field.type === 'number' ? null : (field.min ?? 0);
|
|
117
|
+
case 'date': {
|
|
118
|
+
if (v instanceof Date)
|
|
119
|
+
return v;
|
|
120
|
+
const m = typeof v === 'string' ? /^(\d{4})-(\d{2})-(\d{2})/.exec(v) : null;
|
|
121
|
+
return m ? new Date(+m[1], +m[2] - 1, +m[3]) : null;
|
|
122
|
+
}
|
|
123
|
+
case 'select':
|
|
124
|
+
case 'radio':
|
|
125
|
+
case 'buttons':
|
|
126
|
+
return v ?? null;
|
|
127
|
+
case 'color':
|
|
128
|
+
return typeof v === 'string' ? v : '#2563eb';
|
|
129
|
+
default:
|
|
130
|
+
return typeof v === 'string' ? v : v == null ? '' : v;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/** Obligatorio que entiende casillas (`true`) y listas (al menos un elemento). */
|
|
134
|
+
const requiredValidator = (c) => (isFilled(c.value) ? null : { required: true });
|
|
135
|
+
/** Validadores de un campo según su esquema (`required` aparte, porque puede ser condicional). */
|
|
136
|
+
function validatorsOf(field, required) {
|
|
137
|
+
const v = [];
|
|
138
|
+
if (required)
|
|
139
|
+
v.push(requiredValidator);
|
|
140
|
+
const type = field.type ?? 'text';
|
|
141
|
+
if (field.min !== undefined && (type === 'number' || type === 'slider'))
|
|
142
|
+
v.push(Validators.min(field.min));
|
|
143
|
+
if (field.max !== undefined && (type === 'number' || type === 'slider'))
|
|
144
|
+
v.push(Validators.max(field.max));
|
|
145
|
+
if (field.minLength !== undefined)
|
|
146
|
+
v.push(Validators.minLength(field.minLength));
|
|
147
|
+
if (field.maxLength !== undefined)
|
|
148
|
+
v.push(Validators.maxLength(field.maxLength));
|
|
149
|
+
if (type === 'email')
|
|
150
|
+
v.push(Validators.email);
|
|
151
|
+
if (type === 'url')
|
|
152
|
+
v.push(Validators.pattern(/^https?:\/\/\S+\.\S+$/));
|
|
153
|
+
if (field.pattern)
|
|
154
|
+
v.push(Validators.pattern(field.pattern));
|
|
155
|
+
if (field.validators)
|
|
156
|
+
v.push(...field.validators);
|
|
157
|
+
return v;
|
|
158
|
+
}
|
|
159
|
+
/** Comparable de una regla (fecha → tiempo, texto numérico → número). */
|
|
160
|
+
function comparable(v) {
|
|
161
|
+
if (v === null || v === undefined || v === '')
|
|
162
|
+
return null;
|
|
163
|
+
if (v instanceof Date)
|
|
164
|
+
return v.getTime();
|
|
165
|
+
if (typeof v === 'number')
|
|
166
|
+
return v;
|
|
167
|
+
const n = Number(v);
|
|
168
|
+
return Number.isFinite(n) && String(v).trim() !== '' ? n : String(v);
|
|
169
|
+
}
|
|
170
|
+
/** Error de la primera regla entre campos que no se cumple (o `null`). */
|
|
171
|
+
function checkRules(rules, value, scope) {
|
|
172
|
+
if (!rules?.length || !isFilled(value))
|
|
173
|
+
return null;
|
|
174
|
+
const a = comparable(value);
|
|
175
|
+
for (const r of rules) {
|
|
176
|
+
const other = (k) => (k ? comparable(scope[k]) : null);
|
|
177
|
+
if (r.equalsField && !sameValue(value, scope[r.equalsField]) && a !== other(r.equalsField))
|
|
178
|
+
return r;
|
|
179
|
+
if (r.notEqualsField && (sameValue(value, scope[r.notEqualsField]) || a === other(r.notEqualsField)))
|
|
180
|
+
return r;
|
|
181
|
+
const cmp = (k, ok) => {
|
|
182
|
+
const b = other(k);
|
|
183
|
+
return k && a !== null && b !== null && !ok(a, b);
|
|
184
|
+
};
|
|
185
|
+
if (cmp(r.gteField, (x, y) => x >= y))
|
|
186
|
+
return r;
|
|
187
|
+
if (cmp(r.lteField, (x, y) => x <= y))
|
|
188
|
+
return r;
|
|
189
|
+
if (cmp(r.gtField, (x, y) => x > y))
|
|
190
|
+
return r;
|
|
191
|
+
if (cmp(r.ltField, (x, y) => x < y))
|
|
192
|
+
return r;
|
|
193
|
+
}
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
/** Mensaje del primer error de un control (`tr` traduce los textos del esquema). */
|
|
197
|
+
function errorMessage(field, errors, texts, tr = (t) => (typeof t === 'string' ? t : '')) {
|
|
198
|
+
if (!errors)
|
|
199
|
+
return null;
|
|
200
|
+
const key = Object.keys(errors)[0];
|
|
201
|
+
const custom = field.messages?.[key];
|
|
202
|
+
if (custom)
|
|
203
|
+
return tr(custom);
|
|
204
|
+
const e = errors[key];
|
|
205
|
+
switch (key) {
|
|
206
|
+
case 'required':
|
|
207
|
+
return texts.required;
|
|
208
|
+
case 'min':
|
|
209
|
+
return texts.min.replace('{0}', String(e.min));
|
|
210
|
+
case 'max':
|
|
211
|
+
return texts.max.replace('{0}', String(e.max));
|
|
212
|
+
case 'minlength':
|
|
213
|
+
return field.messages?.['minLength'] ? tr(field.messages['minLength']) : texts.minLength.replace('{0}', String(e.requiredLength));
|
|
214
|
+
case 'maxlength':
|
|
215
|
+
return field.messages?.['maxLength'] ? tr(field.messages['maxLength']) : texts.maxLength.replace('{0}', String(e.requiredLength));
|
|
216
|
+
case 'email':
|
|
217
|
+
return texts.email;
|
|
218
|
+
case 'pattern':
|
|
219
|
+
return texts.pattern;
|
|
220
|
+
case 'rule':
|
|
221
|
+
return typeof e === 'string' ? e : texts.invalid;
|
|
222
|
+
default:
|
|
223
|
+
return typeof e === 'string' ? e : texts.invalid;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function tokenize(src) {
|
|
227
|
+
const out = [];
|
|
228
|
+
let i = 0;
|
|
229
|
+
while (i < src.length) {
|
|
230
|
+
const ch = src[i];
|
|
231
|
+
if (/\s/.test(ch)) {
|
|
232
|
+
i++;
|
|
233
|
+
}
|
|
234
|
+
else if (/[0-9.]/.test(ch)) {
|
|
235
|
+
let j = i;
|
|
236
|
+
while (j < src.length && /[0-9.]/.test(src[j]))
|
|
237
|
+
j++;
|
|
238
|
+
out.push({ t: 'num', v: Number(src.slice(i, j)) });
|
|
239
|
+
i = j;
|
|
240
|
+
}
|
|
241
|
+
else if (/[A-Za-z_]/.test(ch)) {
|
|
242
|
+
let j = i;
|
|
243
|
+
while (j < src.length && /[A-Za-z0-9_.]/.test(src[j]))
|
|
244
|
+
j++;
|
|
245
|
+
out.push({ t: 'id', v: src.slice(i, j) });
|
|
246
|
+
i = j;
|
|
247
|
+
}
|
|
248
|
+
else if ('+-*/(),'.includes(ch)) {
|
|
249
|
+
out.push({ t: 'op', v: ch });
|
|
250
|
+
i++;
|
|
251
|
+
}
|
|
252
|
+
else
|
|
253
|
+
throw new Error(`Carácter no válido en la fórmula: ${ch}`);
|
|
254
|
+
}
|
|
255
|
+
return out;
|
|
256
|
+
}
|
|
257
|
+
function num(v) {
|
|
258
|
+
if (typeof v === 'number')
|
|
259
|
+
return Number.isFinite(v) ? v : 0;
|
|
260
|
+
if (v instanceof Date)
|
|
261
|
+
return v.getTime();
|
|
262
|
+
const n = Number(v);
|
|
263
|
+
return Number.isFinite(n) ? n : 0;
|
|
264
|
+
}
|
|
265
|
+
/** Valor de un identificador (`precio`, `lineas.subtotal` → lista). */
|
|
266
|
+
function lookup(name, scope) {
|
|
267
|
+
const [head, ...rest] = name.split('.');
|
|
268
|
+
let v = scope[head];
|
|
269
|
+
for (const part of rest) {
|
|
270
|
+
v = Array.isArray(v) ? v.map((x) => x?.[part]) : v?.[part];
|
|
271
|
+
}
|
|
272
|
+
return v;
|
|
273
|
+
}
|
|
274
|
+
const FUNCS = {
|
|
275
|
+
round: ([x, d]) => {
|
|
276
|
+
const f = 10 ** num(d ?? 0);
|
|
277
|
+
return Math.round(num(x) * f) / f;
|
|
278
|
+
},
|
|
279
|
+
floor: ([x]) => Math.floor(num(x)),
|
|
280
|
+
ceil: ([x]) => Math.ceil(num(x)),
|
|
281
|
+
abs: ([x]) => Math.abs(num(x)),
|
|
282
|
+
min: (args) => Math.min(...args.flatMap((a) => (Array.isArray(a) ? a.map(num) : [num(a)]))),
|
|
283
|
+
max: (args) => Math.max(...args.flatMap((a) => (Array.isArray(a) ? a.map(num) : [num(a)]))),
|
|
284
|
+
sum: (args) => args.flatMap((a) => (Array.isArray(a) ? a.map(num) : [num(a)])).reduce((s, x) => s + x, 0),
|
|
285
|
+
count: (args) => args.flatMap((a) => (Array.isArray(a) ? a : [a])).filter(isFilled).length,
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* Evalúa una fórmula aritmética de forma segura (sin `eval`): números, campos,
|
|
289
|
+
* `+ - * /`, paréntesis y las funciones `round`, `floor`, `ceil`, `abs`, `min`,
|
|
290
|
+
* `max`, `sum` y `count` (estas tres aceptan listas: `sum(lineas.subtotal)`).
|
|
291
|
+
*/
|
|
292
|
+
function evaluateFormula(formula, scope) {
|
|
293
|
+
const tokens = tokenize(formula);
|
|
294
|
+
let pos = 0;
|
|
295
|
+
const peek = () => tokens[pos];
|
|
296
|
+
const take = (v) => {
|
|
297
|
+
const tk = tokens[pos++];
|
|
298
|
+
if (!tk || (v !== undefined && (tk.t !== 'op' || tk.v !== v)))
|
|
299
|
+
throw new Error(`Fórmula no válida: ${formula}`);
|
|
300
|
+
return tk;
|
|
301
|
+
};
|
|
302
|
+
const expr = () => {
|
|
303
|
+
let left = term();
|
|
304
|
+
while (peek()?.t === 'op' && (peek().v === '+' || peek().v === '-')) {
|
|
305
|
+
const op = take().v;
|
|
306
|
+
const right = term();
|
|
307
|
+
left = op === '+' ? num(left) + num(right) : num(left) - num(right);
|
|
308
|
+
}
|
|
309
|
+
return left;
|
|
310
|
+
};
|
|
311
|
+
const term = () => {
|
|
312
|
+
let left = factor();
|
|
313
|
+
while (peek()?.t === 'op' && (peek().v === '*' || peek().v === '/')) {
|
|
314
|
+
const op = take().v;
|
|
315
|
+
const right = factor();
|
|
316
|
+
left = op === '*' ? num(left) * num(right) : num(right) === 0 ? 0 : num(left) / num(right);
|
|
317
|
+
}
|
|
318
|
+
return left;
|
|
319
|
+
};
|
|
320
|
+
const factor = () => {
|
|
321
|
+
const tk = take();
|
|
322
|
+
if (tk.t === 'num')
|
|
323
|
+
return tk.v;
|
|
324
|
+
if (tk.t === 'op' && tk.v === '-')
|
|
325
|
+
return -num(factor());
|
|
326
|
+
if (tk.t === 'op' && tk.v === '(') {
|
|
327
|
+
const v = expr();
|
|
328
|
+
take(')');
|
|
329
|
+
return v;
|
|
330
|
+
}
|
|
331
|
+
if (tk.t === 'id') {
|
|
332
|
+
if (peek()?.t === 'op' && peek().v === '(') {
|
|
333
|
+
const fn = FUNCS[tk.v.toLowerCase()];
|
|
334
|
+
if (!fn)
|
|
335
|
+
throw new Error(`Función desconocida: ${tk.v}`);
|
|
336
|
+
take('(');
|
|
337
|
+
const args = [];
|
|
338
|
+
if (!(peek()?.t === 'op' && peek().v === ')')) {
|
|
339
|
+
args.push(expr());
|
|
340
|
+
while (peek()?.t === 'op' && peek().v === ',') {
|
|
341
|
+
take(',');
|
|
342
|
+
args.push(expr());
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
take(')');
|
|
346
|
+
return fn(args);
|
|
347
|
+
}
|
|
348
|
+
return lookup(tk.v, scope);
|
|
349
|
+
}
|
|
350
|
+
throw new Error(`Fórmula no válida: ${formula}`);
|
|
351
|
+
};
|
|
352
|
+
const result = expr();
|
|
353
|
+
if (pos < tokens.length)
|
|
354
|
+
throw new Error(`Fórmula no válida: ${formula}`);
|
|
355
|
+
return Math.round(num(result) * 1e8) / 1e8;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** Plantilla de un tipo de campo propio: el campo con `type: 'nombre'` la usa. */
|
|
359
|
+
class CbFormFieldTemplate {
|
|
360
|
+
constructor() {
|
|
361
|
+
this.name = input.required({ ...(ngDevMode ? { debugName: "name" } : /* istanbul ignore next */ {}), alias: 'cbFormField' });
|
|
362
|
+
this.template = inject(TemplateRef);
|
|
363
|
+
}
|
|
364
|
+
static ngTemplateContextGuard(_dir, ctx) {
|
|
365
|
+
return true;
|
|
366
|
+
}
|
|
367
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: CbFormFieldTemplate, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
368
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.0.5", type: CbFormFieldTemplate, isStandalone: true, selector: "ng-template[cbFormField]", inputs: { name: { classPropertyName: "name", publicName: "cbFormField", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0 }); }
|
|
369
|
+
}
|
|
370
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: CbFormFieldTemplate, decorators: [{
|
|
371
|
+
type: Directive,
|
|
372
|
+
args: [{ selector: 'ng-template[cbFormField]' }]
|
|
373
|
+
}], propDecorators: { name: [{ type: i0.Input, args: [{ isSignal: true, alias: "cbFormField", required: true }] }] } });
|
|
374
|
+
/** Tipos cuyo control pinta su propia ayuda y error (y los asocia al campo). */
|
|
375
|
+
const OWN_MESSAGES = new Set(['text', 'email', 'tel', 'url', 'number', 'textarea', 'date']);
|
|
376
|
+
/** Tipos que llevan la etiqueta dentro del control (a la derecha de la casilla). */
|
|
377
|
+
const INLINE_LABEL = new Set(['checkbox', 'toggle']);
|
|
378
|
+
/** Tipos con un elemento nativo enlazable con `<label for>`. */
|
|
379
|
+
const LABELABLE = new Set(['text', 'email', 'tel', 'url', 'password', 'number', 'textarea', 'date', 'mask']);
|
|
380
|
+
/** Tipos que admiten etiqueta flotante (dentro de la caja del control). */
|
|
381
|
+
const FLOATABLE = new Set(['text', 'email', 'tel', 'url', 'password', 'number', 'textarea', 'date', 'mask', 'select', 'multiselect']);
|
|
382
|
+
const BUILT_IN = new Set(['text', 'email', 'password', 'tel', 'url', 'number', 'textarea', 'select', 'multiselect', 'radio', 'checkbox', 'toggle', 'date', 'slider', 'rating', 'chips', 'color', 'buttons', 'mask', 'group', 'heading', 'paragraph', 'divider']);
|
|
383
|
+
let nextUid = 0;
|
|
384
|
+
/**
|
|
385
|
+
* Formulario dinámico de CaribeNG: arma el formulario a partir de un esquema JSON.
|
|
386
|
+
*
|
|
387
|
+
* - Campos con tipo (texto, correo, número, lista, opciones, casilla, fecha, máscara…),
|
|
388
|
+
* validación (`required`, `min`, `max`, `minLength`, `maxLength`, `pattern`, reglas
|
|
389
|
+
* entre campos) y mensajes propios, traducibles (`{ es, en }`).
|
|
390
|
+
* - Etiquetas encima, a la izquierda, a la derecha, flotantes u ocultas, por
|
|
391
|
+
* formulario, sección o campo; columnas por tamaño de pantalla, orden, filas,
|
|
392
|
+
* títulos, textos y separadores.
|
|
393
|
+
* - Campos condicionales, opciones que dependen de otro campo o se cargan de una
|
|
394
|
+
* API, campos calculados con fórmulas, grupos repetibles y formulario por pasos.
|
|
395
|
+
* - Tipos propios con plantillas (`<ng-template cbFormField="firma">`).
|
|
396
|
+
*
|
|
397
|
+
* @example
|
|
398
|
+
* ```html
|
|
399
|
+
* <cb-dynamic-form [schema]="esquema" [(value)]="datos" (formSubmit)="guardar($event)" />
|
|
400
|
+
* ```
|
|
401
|
+
*/
|
|
402
|
+
class CbDynamicForm {
|
|
403
|
+
constructor() {
|
|
404
|
+
/** Textos de interfaz en el idioma activo (`provideCaribeNG({ locale })`). */
|
|
405
|
+
this.t = injectCbTranslation();
|
|
406
|
+
this.fmt = cbFormat;
|
|
407
|
+
this.ordered = ordered;
|
|
408
|
+
this.injector = inject(Injector);
|
|
409
|
+
this.host = inject(ElementRef);
|
|
410
|
+
this.uid = `cb-df-${++nextUid}`;
|
|
411
|
+
this.templates = contentChildren(CbFormFieldTemplate, /* @ts-ignore */
|
|
412
|
+
...(ngDevMode ? [{ debugName: "templates" }] : /* istanbul ignore next */ []));
|
|
413
|
+
/** Esquema del formulario (campos, secciones o pasos, columnas, etiquetas…). */
|
|
414
|
+
this.schema = input.required(/* @ts-ignore */
|
|
415
|
+
...(ngDevMode ? [{ debugName: "schema" }] : /* istanbul ignore next */ []));
|
|
416
|
+
/** Valor del formulario (bidireccional; los campos ocultos no se incluyen). */
|
|
417
|
+
this.value = model({}, /* @ts-ignore */
|
|
418
|
+
...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
|
|
419
|
+
/** Disposición (atajo de `labelPosition`); si no, la del esquema. */
|
|
420
|
+
this.layout = input(undefined, /* @ts-ignore */
|
|
421
|
+
...(ngDevMode ? [{ debugName: "layout" }] : /* istanbul ignore next */ []));
|
|
422
|
+
/** Posición de las etiquetas; si no, la del esquema (encima por defecto). */
|
|
423
|
+
this.labelPosition = input(undefined, /* @ts-ignore */
|
|
424
|
+
...(ngDevMode ? [{ debugName: "labelPosition" }] : /* istanbul ignore next */ []));
|
|
425
|
+
/** Columnas; si no, las del esquema (1 por defecto). */
|
|
426
|
+
this.columns = input(undefined, /* @ts-ignore */
|
|
427
|
+
...(ngDevMode ? [{ debugName: "columns" }] : /* istanbul ignore next */ []));
|
|
428
|
+
/** Ancho de la etiqueta a un lado; si no, el del esquema (`10rem`). */
|
|
429
|
+
this.labelWidth = input(undefined, /* @ts-ignore */
|
|
430
|
+
...(ngDevMode ? [{ debugName: "labelWidth" }] : /* istanbul ignore next */ []));
|
|
431
|
+
/** Tamaño de los controles; si no, el del esquema (`md`). */
|
|
432
|
+
this.size = input(undefined, /* @ts-ignore */
|
|
433
|
+
...(ngDevMode ? [{ debugName: "size" }] : /* istanbul ignore next */ []));
|
|
434
|
+
/** Cargadores de opciones por nombre (`optionsLoader` en el esquema). */
|
|
435
|
+
this.loaders = input({}, /* @ts-ignore */
|
|
436
|
+
...(ngDevMode ? [{ debugName: "loaders" }] : /* istanbul ignore next */ []));
|
|
437
|
+
/** Traduce los textos del esquema que son claves (`'clientes.nombre'` → `'Nombre'`). */
|
|
438
|
+
this.translate = input(null, /* @ts-ignore */
|
|
439
|
+
...(ngDevMode ? [{ debugName: "translate" }] : /* istanbul ignore next */ []));
|
|
440
|
+
/** Botones de enviar (y restablecer, si el esquema tiene `resetLabel`). */
|
|
441
|
+
this.actions = input(true, { ...(ngDevMode ? { debugName: "actions" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
442
|
+
/** Deshabilita todo el formulario. */
|
|
443
|
+
this.disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
444
|
+
/** Muestra el botón de enviar cargando (mientras se guarda). */
|
|
445
|
+
this.loading = input(false, { ...(ngDevMode ? { debugName: "loading" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
446
|
+
this.ariaLabel = input(undefined, /* @ts-ignore */
|
|
447
|
+
...(ngDevMode ? [{ debugName: "ariaLabel" }] : /* istanbul ignore next */ []));
|
|
448
|
+
/** Se envió el formulario y es válido: el valor (sin los campos ocultos). */
|
|
449
|
+
this.formSubmit = output();
|
|
450
|
+
/** Se envió (o se intentó pasar de paso) con errores: cuáles (`key` y mensaje). */
|
|
451
|
+
this.formInvalid = output();
|
|
452
|
+
this.formReset = output();
|
|
453
|
+
/** Cambio de paso (índice desde 0). */
|
|
454
|
+
this.stepChange = output();
|
|
455
|
+
this.steps = computed(() => stepsOf(this.schema()), /* @ts-ignore */
|
|
456
|
+
...(ngDevMode ? [{ debugName: "steps" }] : /* istanbul ignore next */ []));
|
|
457
|
+
this.step = signal(0, /* @ts-ignore */
|
|
458
|
+
...(ngDevMode ? [{ debugName: "step" }] : /* istanbul ignore next */ []));
|
|
459
|
+
this.sections = computed(() => sectionsOf(this.steps()[Math.min(this.step(), this.steps().length - 1)]), /* @ts-ignore */
|
|
460
|
+
...(ngDevMode ? [{ debugName: "sections" }] : /* istanbul ignore next */ []));
|
|
461
|
+
this.fields = computed(() => fieldsOf(this.schema()), /* @ts-ignore */
|
|
462
|
+
...(ngDevMode ? [{ debugName: "fields" }] : /* istanbul ignore next */ []));
|
|
463
|
+
this.basePosition = computed(() => {
|
|
464
|
+
const layout = this.layout() ?? this.schema().layout;
|
|
465
|
+
return this.labelPosition() ?? this.schema().labelPosition ?? (layout === 'horizontal' ? 'left' : 'top');
|
|
466
|
+
}, /* @ts-ignore */
|
|
467
|
+
...(ngDevMode ? [{ debugName: "basePosition" }] : /* istanbul ignore next */ []));
|
|
468
|
+
this.labelWidthValue = computed(() => this.labelWidth() ?? this.schema().labelWidth ?? '10rem', /* @ts-ignore */
|
|
469
|
+
...(ngDevMode ? [{ debugName: "labelWidthValue" }] : /* istanbul ignore next */ []));
|
|
470
|
+
this.actionsLabelPosition = computed(() => (this.basePosition() === 'left' ? 'left' : 'top'), /* @ts-ignore */
|
|
471
|
+
...(ngDevMode ? [{ debugName: "actionsLabelPosition" }] : /* istanbul ignore next */ []));
|
|
472
|
+
this.sizeValue = computed(() => this.size() ?? this.schema().size ?? 'md', /* @ts-ignore */
|
|
473
|
+
...(ngDevMode ? [{ debugName: "sizeValue" }] : /* istanbul ignore next */ []));
|
|
474
|
+
this.baseCols = computed(() => this.columns() ?? this.schema().columns ?? 1, /* @ts-ignore */
|
|
475
|
+
...(ngDevMode ? [{ debugName: "baseCols" }] : /* istanbul ignore next */ []));
|
|
476
|
+
/** El `FormGroup` que se arma con el esquema. */
|
|
477
|
+
this.form = signal(new FormGroup({}), /* @ts-ignore */
|
|
478
|
+
...(ngDevMode ? [{ debugName: "form" }] : /* istanbul ignore next */ []));
|
|
479
|
+
/** Se incrementa con cada evento del formulario para recalcular estado y errores. */
|
|
480
|
+
this.tick = signal(0, /* @ts-ignore */
|
|
481
|
+
...(ngDevMode ? [{ debugName: "tick" }] : /* istanbul ignore next */ []));
|
|
482
|
+
/** Paso cuyos errores se muestran (tras intentar avanzar o enviar). */
|
|
483
|
+
this.attempted = signal(-1, /* @ts-ignore */
|
|
484
|
+
...(ngDevMode ? [{ debugName: "attempted" }] : /* istanbul ignore next */ []));
|
|
485
|
+
this.hidden = signal(new Set(), /* @ts-ignore */
|
|
486
|
+
...(ngDevMode ? [{ debugName: "hidden" }] : /* istanbul ignore next */ []));
|
|
487
|
+
this.required = signal(new Set(), /* @ts-ignore */
|
|
488
|
+
...(ngDevMode ? [{ debugName: "required" }] : /* istanbul ignore next */ []));
|
|
489
|
+
this.options = signal(new Map(), /* @ts-ignore */
|
|
490
|
+
...(ngDevMode ? [{ debugName: "options" }] : /* istanbul ignore next */ []));
|
|
491
|
+
this.depsKeys = new Map();
|
|
492
|
+
this.announcement = signal('', /* @ts-ignore */
|
|
493
|
+
...(ngDevMode ? [{ debugName: "announcement" }] : /* istanbul ignore next */ []));
|
|
494
|
+
this.lastEmitted = null;
|
|
495
|
+
this.subscription = null;
|
|
496
|
+
this.syncing = false;
|
|
497
|
+
this.texts = computed(() => {
|
|
498
|
+
const t = this.t();
|
|
499
|
+
return {
|
|
500
|
+
required: t.dynamicFormRequired,
|
|
501
|
+
min: t.dynamicFormMin,
|
|
502
|
+
max: t.dynamicFormMax,
|
|
503
|
+
minLength: t.dynamicFormMinLength,
|
|
504
|
+
maxLength: t.dynamicFormMaxLength,
|
|
505
|
+
email: t.dynamicFormEmail,
|
|
506
|
+
pattern: t.dynamicFormPattern,
|
|
507
|
+
invalid: t.dynamicFormInvalid,
|
|
508
|
+
};
|
|
509
|
+
}, /* @ts-ignore */
|
|
510
|
+
...(ngDevMode ? [{ debugName: "texts" }] : /* istanbul ignore next */ []));
|
|
511
|
+
/** Errores que se listan arriba tras un envío o un intento de avanzar fallido. */
|
|
512
|
+
this.summary = computed(() => {
|
|
513
|
+
this.tick();
|
|
514
|
+
if (this.attempted() !== this.step())
|
|
515
|
+
return [];
|
|
516
|
+
const out = [];
|
|
517
|
+
const walk = (fields, group, path) => {
|
|
518
|
+
for (const f of fields) {
|
|
519
|
+
if (isLayout(f) || !f.key)
|
|
520
|
+
continue;
|
|
521
|
+
const ctrl = group.controls[f.key];
|
|
522
|
+
if (!ctrl || ctrl.disabled)
|
|
523
|
+
continue;
|
|
524
|
+
if (f.type === 'group') {
|
|
525
|
+
if (f.repeatable)
|
|
526
|
+
ctrl.controls.forEach((g, i) => walk(ordered(f.fields ?? []), g, [...path, f.key, i]));
|
|
527
|
+
else
|
|
528
|
+
walk(ordered(f.fields ?? []), ctrl, [...path, f.key]);
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
if (ctrl.valid)
|
|
532
|
+
continue;
|
|
533
|
+
const label = path.length ? `${this.tr(f.label) || f.key} (${this.pathLabel(path)})` : this.tr(f.label) || f.key;
|
|
534
|
+
out.push({ id: this.idOf(path, f.key), label, message: errorMessage(f, ctrl.errors, this.texts(), (x) => this.tr(x)) ?? '' });
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
for (const s of this.sections())
|
|
538
|
+
walk(s.fields, this.form(), []);
|
|
539
|
+
return out;
|
|
540
|
+
}, /* @ts-ignore */
|
|
541
|
+
...(ngDevMode ? [{ debugName: "summary" }] : /* istanbul ignore next */ []));
|
|
542
|
+
// Cada esquema nuevo arma un FormGroup nuevo.
|
|
543
|
+
effect(() => {
|
|
544
|
+
const fields = this.fields();
|
|
545
|
+
untracked(() => {
|
|
546
|
+
this.step.set(0);
|
|
547
|
+
this.build(fields, this.value());
|
|
548
|
+
});
|
|
549
|
+
});
|
|
550
|
+
// Un valor que llega de fuera vuelve a armar el formulario con él.
|
|
551
|
+
effect(() => {
|
|
552
|
+
const value = this.value();
|
|
553
|
+
untracked(() => {
|
|
554
|
+
if (value === this.lastEmitted)
|
|
555
|
+
return;
|
|
556
|
+
this.build(this.fields(), value);
|
|
557
|
+
});
|
|
558
|
+
});
|
|
559
|
+
effect(() => {
|
|
560
|
+
this.disabled();
|
|
561
|
+
untracked(() => {
|
|
562
|
+
this.sync();
|
|
563
|
+
this.tick.update((n) => n + 1);
|
|
564
|
+
});
|
|
565
|
+
});
|
|
566
|
+
inject(DestroyRef).onDestroy(() => this.subscription?.unsubscribe());
|
|
567
|
+
}
|
|
568
|
+
// --- API pública -------------------------------------------------------------------------
|
|
569
|
+
/** Valida y, si todo está bien, emite `formSubmit`; si no, muestra el resumen de errores. */
|
|
570
|
+
submit() {
|
|
571
|
+
if (this.step() < this.steps().length - 1) {
|
|
572
|
+
this.next();
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
if (!this.validateStep(this.step()))
|
|
576
|
+
return;
|
|
577
|
+
// En un formulario por pasos se revisa también el resto (por si algo cambió).
|
|
578
|
+
for (let i = 0; i < this.steps().length; i++) {
|
|
579
|
+
if (!this.validateStep(i, false)) {
|
|
580
|
+
this.goTo(i);
|
|
581
|
+
this.validateStep(i);
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
this.formSubmit.emit(this.currentValue());
|
|
586
|
+
}
|
|
587
|
+
/** Pasa al paso siguiente si los campos del actual son válidos. */
|
|
588
|
+
next() {
|
|
589
|
+
if (!this.validateStep(this.step()))
|
|
590
|
+
return;
|
|
591
|
+
this.goTo(this.step() + 1);
|
|
592
|
+
}
|
|
593
|
+
/** Vuelve al paso anterior (sin validar). */
|
|
594
|
+
back() {
|
|
595
|
+
this.goTo(this.step() - 1);
|
|
596
|
+
}
|
|
597
|
+
/** Vuelve a los valores iniciales del esquema. */
|
|
598
|
+
reset() {
|
|
599
|
+
this.attempted.set(-1);
|
|
600
|
+
this.step.set(0);
|
|
601
|
+
this.build(this.fields(), {});
|
|
602
|
+
this.formReset.emit();
|
|
603
|
+
}
|
|
604
|
+
/** Lleva el foco al control de un campo (por su `key` de primer nivel). */
|
|
605
|
+
focusField(key) {
|
|
606
|
+
this.focusById(this.idOf([], key));
|
|
607
|
+
}
|
|
608
|
+
// --- Plantilla ---------------------------------------------------------------------------
|
|
609
|
+
onSubmit(event) {
|
|
610
|
+
event.preventDefault();
|
|
611
|
+
this.submit();
|
|
612
|
+
}
|
|
613
|
+
/** Texto del esquema resuelto: por idioma (`{ es, en }`) y con `translate`. */
|
|
614
|
+
tr(text) {
|
|
615
|
+
if (text === undefined || text === null)
|
|
616
|
+
return '';
|
|
617
|
+
if (typeof text === 'string')
|
|
618
|
+
return this.translate()?.(text) ?? text;
|
|
619
|
+
const locale = this.t().intlLocale;
|
|
620
|
+
return text[locale] ?? text[locale.split('-')[0]] ?? Object.values(text)[0] ?? '';
|
|
621
|
+
}
|
|
622
|
+
rootCtx(section) {
|
|
623
|
+
const schema = this.schema();
|
|
624
|
+
return {
|
|
625
|
+
group: this.form(),
|
|
626
|
+
path: [],
|
|
627
|
+
opts: {
|
|
628
|
+
labelPosition: section.labelPosition ?? this.basePosition(),
|
|
629
|
+
labelAlign: section.labelAlign ?? schema.labelAlign ?? 'start',
|
|
630
|
+
labelWidth: section.labelWidth ?? this.labelWidthValue(),
|
|
631
|
+
},
|
|
632
|
+
cols: this.colsOf(section.columns ?? this.baseCols()),
|
|
633
|
+
size: section.size ?? this.sizeValue(),
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
childCtx(parent, f, group, index) {
|
|
637
|
+
return {
|
|
638
|
+
group,
|
|
639
|
+
path: index === null ? [...parent.path, f.key] : [...parent.path, f.key, index],
|
|
640
|
+
opts: {
|
|
641
|
+
labelPosition: f.labelPosition ?? parent.opts.labelPosition,
|
|
642
|
+
labelAlign: f.labelAlign ?? parent.opts.labelAlign,
|
|
643
|
+
labelWidth: f.labelWidth ?? parent.opts.labelWidth,
|
|
644
|
+
},
|
|
645
|
+
cols: this.colsOf(f.columns ?? 1),
|
|
646
|
+
size: f.size ?? parent.size,
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
/** Columnas por tamaño: un número fijo `n` es 1 en móvil y `n` desde 40rem. */
|
|
650
|
+
colsOf(value) {
|
|
651
|
+
if (typeof value === 'number')
|
|
652
|
+
return { base: 1, sm: 1, md: Math.max(1, value), lg: Math.max(1, value) };
|
|
653
|
+
return responsive(value, 1);
|
|
654
|
+
}
|
|
655
|
+
gridVars(cols) {
|
|
656
|
+
return `--df-cols-base:${cols.base};--df-cols-sm:${cols.sm};--df-cols-md:${cols.md};--df-cols-lg:${cols.lg}`;
|
|
657
|
+
}
|
|
658
|
+
/** Columnas que ocupa un elemento en cada tamaño (`full` o `span n`), y si empieza fila. */
|
|
659
|
+
cellVars(f, cols, wideByDefault) {
|
|
660
|
+
const span = responsive(f.colSpan, wideByDefault ? 'full' : 1);
|
|
661
|
+
const one = (bp) => {
|
|
662
|
+
const s = span[bp];
|
|
663
|
+
const n = s === 'full' ? cols[bp] : Math.min(Math.max(1, s), cols[bp]);
|
|
664
|
+
if (s === 'full' || n >= cols[bp])
|
|
665
|
+
return '1 / -1';
|
|
666
|
+
return f.newRow ? `1 / span ${n}` : `span ${n}`;
|
|
667
|
+
};
|
|
668
|
+
return `--df-col-base:${one('base')};--df-col-sm:${one('sm')};--df-col-md:${one('md')};--df-col-lg:${one('lg')}`;
|
|
669
|
+
}
|
|
670
|
+
kindOf(f) {
|
|
671
|
+
const type = f.type ?? 'text';
|
|
672
|
+
if (type === 'heading' || type === 'paragraph' || type === 'divider')
|
|
673
|
+
return type;
|
|
674
|
+
if (type === 'group')
|
|
675
|
+
return f.repeatable ? 'list' : 'group';
|
|
676
|
+
return 'field';
|
|
677
|
+
}
|
|
678
|
+
controlKind(f) {
|
|
679
|
+
const type = f.type ?? 'text';
|
|
680
|
+
if (BUILT_IN.has(type))
|
|
681
|
+
return type === 'email' || type === 'tel' || type === 'url' ? 'text' : type;
|
|
682
|
+
return this.customTemplate(f) ? 'custom' : 'text';
|
|
683
|
+
}
|
|
684
|
+
customTemplate(f) {
|
|
685
|
+
return this.templates().find((t) => t.name() === f.type)?.template ?? null;
|
|
686
|
+
}
|
|
687
|
+
labelPos(f, ctx) {
|
|
688
|
+
const pos = f.labelPosition ?? ctx.opts.labelPosition;
|
|
689
|
+
if (pos === 'floating' && !FLOATABLE.has(f.type ?? 'text'))
|
|
690
|
+
return 'top';
|
|
691
|
+
return pos;
|
|
692
|
+
}
|
|
693
|
+
placeholderOf(f, pos) {
|
|
694
|
+
// Con etiqueta flotante, la etiqueta hace de placeholder.
|
|
695
|
+
return pos === 'floating' ? '' : this.tr(f.placeholder);
|
|
696
|
+
}
|
|
697
|
+
sizeOf(f, ctx) {
|
|
698
|
+
return f.size ?? ctx.size;
|
|
699
|
+
}
|
|
700
|
+
isReadonly(f) {
|
|
701
|
+
return !!f.readonly || !!f.formula || !!f.compute;
|
|
702
|
+
}
|
|
703
|
+
filled(ctrl) {
|
|
704
|
+
this.tick();
|
|
705
|
+
return isFilled(ctrl.value);
|
|
706
|
+
}
|
|
707
|
+
pathKey(path, key) {
|
|
708
|
+
return [...path, key ?? ''].join('.');
|
|
709
|
+
}
|
|
710
|
+
idOf(path, key) {
|
|
711
|
+
return `${this.uid}-${[...path, key ?? ''].join('-')}`;
|
|
712
|
+
}
|
|
713
|
+
pathLabel(path) {
|
|
714
|
+
const parts = [];
|
|
715
|
+
let fields = this.fields();
|
|
716
|
+
for (let i = 0; i < path.length; i++) {
|
|
717
|
+
const f = fields.find((x) => x.key === path[i]);
|
|
718
|
+
if (!f)
|
|
719
|
+
break;
|
|
720
|
+
if (f.repeatable && typeof path[i + 1] === 'number') {
|
|
721
|
+
parts.push(this.itemLabel(f, path[i + 1]));
|
|
722
|
+
i++;
|
|
723
|
+
}
|
|
724
|
+
else
|
|
725
|
+
parts.push(this.tr(f.label) || f.key);
|
|
726
|
+
fields = f.fields ?? [];
|
|
727
|
+
}
|
|
728
|
+
return parts.join(' › ');
|
|
729
|
+
}
|
|
730
|
+
isInline(f) {
|
|
731
|
+
return INLINE_LABEL.has(f.type ?? 'text');
|
|
732
|
+
}
|
|
733
|
+
isLabelable(f) {
|
|
734
|
+
return LABELABLE.has(f.type ?? 'text') || (!BUILT_IN.has(f.type ?? 'text') && !!this.customTemplate(f));
|
|
735
|
+
}
|
|
736
|
+
ownsMessages(f) {
|
|
737
|
+
return OWN_MESSAGES.has(f.type ?? 'text');
|
|
738
|
+
}
|
|
739
|
+
inputType(f) {
|
|
740
|
+
const type = f.type ?? 'text';
|
|
741
|
+
return type === 'email' || type === 'tel' || type === 'url' ? type : 'text';
|
|
742
|
+
}
|
|
743
|
+
controlOf(group, f) {
|
|
744
|
+
return group.controls[f.key];
|
|
745
|
+
}
|
|
746
|
+
subGroup(group, f) {
|
|
747
|
+
return group.controls[f.key];
|
|
748
|
+
}
|
|
749
|
+
listItems(group, f) {
|
|
750
|
+
this.tick();
|
|
751
|
+
return group.controls[f.key].controls;
|
|
752
|
+
}
|
|
753
|
+
itemLabel(f, i) {
|
|
754
|
+
const template = this.tr(f.itemLabel) || cbFormat(this.t().dynamicFormItem, '{n}');
|
|
755
|
+
return template.replace('{n}', String(i + 1));
|
|
756
|
+
}
|
|
757
|
+
isDisabledForm() {
|
|
758
|
+
return this.disabled();
|
|
759
|
+
}
|
|
760
|
+
isVisible(f, path, index) {
|
|
761
|
+
return !this.hidden().has(this.pathKey(path, f.key ?? `#${index}`));
|
|
762
|
+
}
|
|
763
|
+
sectionVisible(section) {
|
|
764
|
+
this.tick();
|
|
765
|
+
return matches(section.visibleWhen, this.rawValue());
|
|
766
|
+
}
|
|
767
|
+
isRequired(path, key) {
|
|
768
|
+
return this.required().has(this.pathKey(path, key));
|
|
769
|
+
}
|
|
770
|
+
optionsOf(path, f) {
|
|
771
|
+
const list = f.optionsFrom || f.optionsLoader ? (this.options().get(this.pathKey(path, f.key)) ?? []) : (f.options ?? []);
|
|
772
|
+
return list.map((o) => ({ label: this.tr(o.label), value: o.value, disabled: o.disabled }));
|
|
773
|
+
}
|
|
774
|
+
/** Mensaje de error de un campo, si ya se tocó, se cambió o se intentó enviar. */
|
|
775
|
+
errorOf(path, f, ctrl) {
|
|
776
|
+
this.tick();
|
|
777
|
+
if (!ctrl || ctrl.disabled || ctrl.valid)
|
|
778
|
+
return null;
|
|
779
|
+
if (!ctrl.touched && !ctrl.dirty && this.attempted() !== this.step())
|
|
780
|
+
return null;
|
|
781
|
+
return errorMessage(f, ctrl.errors, this.texts(), (x) => this.tr(x));
|
|
782
|
+
}
|
|
783
|
+
addItem(group, f) {
|
|
784
|
+
const arr = group.controls[f.key];
|
|
785
|
+
if (f.maxItems !== undefined && arr.length >= f.maxItems)
|
|
786
|
+
return;
|
|
787
|
+
arr.push(this.buildGroup(ordered(f.fields ?? []), {}));
|
|
788
|
+
this.say(cbFormat(this.t().dynamicFormAdded, this.itemLabel(f, arr.length - 1)));
|
|
789
|
+
afterNextRender(() => {
|
|
790
|
+
const items = this.host.nativeElement.querySelectorAll(`[data-key="${CSS.escape(f.key)}"] .cb-df__item`);
|
|
791
|
+
items[items.length - 1]?.querySelector('input, textarea, [role="combobox"], button:not(.cb-button)')?.focus();
|
|
792
|
+
}, { injector: this.injector });
|
|
793
|
+
}
|
|
794
|
+
removeItem(group, f, i) {
|
|
795
|
+
const arr = group.controls[f.key];
|
|
796
|
+
if (arr.length <= (f.minItems ?? 0))
|
|
797
|
+
return;
|
|
798
|
+
const label = this.itemLabel(f, i);
|
|
799
|
+
arr.removeAt(i);
|
|
800
|
+
this.say(cbFormat(this.t().dynamicFormRemoved, label));
|
|
801
|
+
}
|
|
802
|
+
focusById(id) {
|
|
803
|
+
const el = this.host.nativeElement.ownerDocument.getElementById(id);
|
|
804
|
+
const box = el?.closest('[data-key]') ?? el;
|
|
805
|
+
const target = el?.matches('input, textarea, select, button, [tabindex]') ? el : box?.querySelector('input:not([type="hidden"]):not([disabled]), textarea, select, button:not([disabled]), [tabindex="0"], [role="combobox"]');
|
|
806
|
+
target?.focus();
|
|
807
|
+
}
|
|
808
|
+
// --- Internos ----------------------------------------------------------------------------
|
|
809
|
+
goTo(i) {
|
|
810
|
+
const next = Math.max(0, Math.min(this.steps().length - 1, i));
|
|
811
|
+
if (next === this.step())
|
|
812
|
+
return;
|
|
813
|
+
this.step.set(next);
|
|
814
|
+
this.stepChange.emit(next);
|
|
815
|
+
afterNextRender(() => this.host.nativeElement.querySelector('.cb-df__step-heading')?.focus(), { injector: this.injector });
|
|
816
|
+
}
|
|
817
|
+
/** Marca los campos de un paso y dice si son válidos (con `show`, muestra el resumen). */
|
|
818
|
+
validateStep(i, show = true) {
|
|
819
|
+
const step = this.steps()[i];
|
|
820
|
+
const fields = sectionsOf(step).flatMap((s) => s.fields).filter((f) => !isLayout(f) && f.key);
|
|
821
|
+
let valid = true;
|
|
822
|
+
for (const f of fields) {
|
|
823
|
+
const ctrl = this.form().controls[f.key];
|
|
824
|
+
if (!ctrl || ctrl.disabled)
|
|
825
|
+
continue;
|
|
826
|
+
if (show)
|
|
827
|
+
ctrl.markAllAsTouched();
|
|
828
|
+
if (ctrl.invalid)
|
|
829
|
+
valid = false;
|
|
830
|
+
}
|
|
831
|
+
if (show) {
|
|
832
|
+
this.attempted.set(valid ? -1 : i);
|
|
833
|
+
this.tick.update((n) => n + 1);
|
|
834
|
+
if (!valid) {
|
|
835
|
+
this.formInvalid.emit(this.summary().map((s) => ({ key: s.id.replace(`${this.uid}-`, ''), message: s.message })));
|
|
836
|
+
afterNextRender(() => this.host.nativeElement.querySelector('.cb-df__summary')?.focus(), { injector: this.injector });
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
return valid;
|
|
840
|
+
}
|
|
841
|
+
build(fields, value) {
|
|
842
|
+
this.subscription?.unsubscribe();
|
|
843
|
+
this.depsKeys.clear();
|
|
844
|
+
const form = this.buildGroup(fields, value);
|
|
845
|
+
this.form.set(form);
|
|
846
|
+
this.attempted.set(-1);
|
|
847
|
+
this.sync();
|
|
848
|
+
this.subscription = form.events.subscribe(() => this.tick.update((n) => n + 1));
|
|
849
|
+
this.subscription.add(form.valueChanges.subscribe(() => {
|
|
850
|
+
if (this.syncing)
|
|
851
|
+
return;
|
|
852
|
+
this.sync();
|
|
853
|
+
this.emitValue();
|
|
854
|
+
}));
|
|
855
|
+
this.emitValue();
|
|
856
|
+
}
|
|
857
|
+
buildGroup(fields, value) {
|
|
858
|
+
const controls = {};
|
|
859
|
+
const v = value ?? {};
|
|
860
|
+
for (const f of fields) {
|
|
861
|
+
if (isLayout(f) || !f.key)
|
|
862
|
+
continue;
|
|
863
|
+
const has = f.key in v;
|
|
864
|
+
if (f.type === 'group') {
|
|
865
|
+
const inner = ordered(f.fields ?? []);
|
|
866
|
+
if (f.repeatable) {
|
|
867
|
+
const items = (has ? v[f.key] : f.default);
|
|
868
|
+
const list = Array.isArray(items) ? items : [];
|
|
869
|
+
while (list.length < (f.minItems ?? 0))
|
|
870
|
+
list.push({});
|
|
871
|
+
controls[f.key] = new FormArray(list.map((item) => this.buildGroup(inner, item)));
|
|
872
|
+
}
|
|
873
|
+
else
|
|
874
|
+
controls[f.key] = this.buildGroup(inner, (has ? v[f.key] : f.default));
|
|
875
|
+
continue;
|
|
876
|
+
}
|
|
877
|
+
controls[f.key] = new FormControl(initialValue(has ? { ...f, default: v[f.key] } : f));
|
|
878
|
+
}
|
|
879
|
+
return new FormGroup(controls);
|
|
880
|
+
}
|
|
881
|
+
/** Aplica condiciones, cálculos, opciones y validaciones en todo el árbol. */
|
|
882
|
+
sync() {
|
|
883
|
+
if (this.syncing)
|
|
884
|
+
return;
|
|
885
|
+
this.syncing = true;
|
|
886
|
+
try {
|
|
887
|
+
const hidden = new Set();
|
|
888
|
+
const required = new Set();
|
|
889
|
+
// Varias pasadas: un total de una lista depende de los cálculos de cada elemento.
|
|
890
|
+
for (let pass = 0; pass < 3; pass++) {
|
|
891
|
+
hidden.clear();
|
|
892
|
+
required.clear();
|
|
893
|
+
const root = this.rawValue();
|
|
894
|
+
for (const step of this.steps()) {
|
|
895
|
+
for (const section of sectionsOf(step)) {
|
|
896
|
+
const shown = matches(section.visibleWhen, root);
|
|
897
|
+
this.walk(section.fields, this.form(), [], root, shown, hidden, required);
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
this.form().updateValueAndValidity({ emitEvent: false });
|
|
902
|
+
this.hidden.set(hidden);
|
|
903
|
+
this.required.set(required);
|
|
904
|
+
}
|
|
905
|
+
finally {
|
|
906
|
+
this.syncing = false;
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
walk(fields, group, path, scope, shown, hidden, required) {
|
|
910
|
+
const disabledAll = this.disabled();
|
|
911
|
+
fields.forEach((f, index) => {
|
|
912
|
+
const key = this.pathKey(path, f.key ?? `#${index}`);
|
|
913
|
+
const visible = shown && matches(f.visibleWhen, scope);
|
|
914
|
+
if (!visible)
|
|
915
|
+
hidden.add(key);
|
|
916
|
+
if (isLayout(f) || !f.key)
|
|
917
|
+
return;
|
|
918
|
+
const ctrl = group.controls[f.key];
|
|
919
|
+
if (!ctrl)
|
|
920
|
+
return;
|
|
921
|
+
if (f.type === 'group') {
|
|
922
|
+
const inner = ordered(f.fields ?? []);
|
|
923
|
+
if (f.repeatable) {
|
|
924
|
+
ctrl.controls.forEach((g, i) => this.walk(inner, g, [...path, f.key, i], { ...scope, ...g.getRawValue() }, visible, hidden, required));
|
|
925
|
+
}
|
|
926
|
+
else
|
|
927
|
+
this.walk(inner, ctrl, [...path, f.key], { ...scope, ...ctrl.getRawValue() }, visible, hidden, required);
|
|
928
|
+
this.setEnabled(ctrl, !(disabledAll || !visible || !!f.disabled));
|
|
929
|
+
return;
|
|
930
|
+
}
|
|
931
|
+
// Campo calculado.
|
|
932
|
+
if (f.formula || f.compute) {
|
|
933
|
+
let result = null;
|
|
934
|
+
try {
|
|
935
|
+
result = f.compute ? f.compute(scope) : evaluateFormula(f.formula, scope);
|
|
936
|
+
}
|
|
937
|
+
catch {
|
|
938
|
+
result = null;
|
|
939
|
+
}
|
|
940
|
+
if (result !== ctrl.value)
|
|
941
|
+
ctrl.setValue(result, { emitEvent: false });
|
|
942
|
+
// Los campos siguientes ya ven el resultado (neto → IVA → total en la misma pasada).
|
|
943
|
+
scope[f.key] = result;
|
|
944
|
+
}
|
|
945
|
+
// Opciones dependientes.
|
|
946
|
+
if (f.optionsFrom || f.optionsLoader)
|
|
947
|
+
this.syncOptions(f, key, ctrl, scope);
|
|
948
|
+
const isRequired = !!f.required || (!!f.requiredWhen && matches(f.requiredWhen, scope));
|
|
949
|
+
if (isRequired)
|
|
950
|
+
required.add(key);
|
|
951
|
+
const validators = validatorsOf(f, isRequired);
|
|
952
|
+
if (f.rules?.length) {
|
|
953
|
+
const snapshot = scope;
|
|
954
|
+
validators.push((c) => {
|
|
955
|
+
const rule = checkRules(f.rules, c.value, snapshot);
|
|
956
|
+
return rule ? { rule: this.tr(rule.message) || this.texts().invalid } : null;
|
|
957
|
+
});
|
|
958
|
+
}
|
|
959
|
+
ctrl.setValidators(validators);
|
|
960
|
+
// Los de solo lectura que no son de texto se deshabilitan (siguen en el valor).
|
|
961
|
+
const readonlyOff = !!f.readonly && !['text', 'email', 'tel', 'url', 'textarea', 'number'].includes(f.type ?? 'text');
|
|
962
|
+
const off = disabledAll || !visible || !!f.disabled || readonlyOff || (!!f.disabledWhen && matches(f.disabledWhen, scope));
|
|
963
|
+
this.setEnabled(ctrl, !off);
|
|
964
|
+
ctrl.updateValueAndValidity({ emitEvent: false });
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
setEnabled(ctrl, enabled) {
|
|
968
|
+
if (enabled && ctrl.disabled)
|
|
969
|
+
ctrl.enable({ emitEvent: false });
|
|
970
|
+
else if (!enabled && ctrl.enabled)
|
|
971
|
+
ctrl.disable({ emitEvent: false });
|
|
972
|
+
}
|
|
973
|
+
/** Opciones de `optionsFrom` / `optionsLoader`: se recalculan al cambiar las dependencias. */
|
|
974
|
+
syncOptions(f, key, ctrl, scope) {
|
|
975
|
+
const deps = f.optionsFrom ? [f.optionsFrom.field] : (f.dependsOn ?? []);
|
|
976
|
+
const depsKey = JSON.stringify(deps.map((d) => scope[d] ?? null));
|
|
977
|
+
const before = this.depsKeys.get(key);
|
|
978
|
+
if (before === depsKey)
|
|
979
|
+
return;
|
|
980
|
+
this.depsKeys.set(key, depsKey);
|
|
981
|
+
const changed = before !== undefined;
|
|
982
|
+
const apply = (list, emit) => {
|
|
983
|
+
this.options.update((m) => new Map(m).set(key, list));
|
|
984
|
+
// Si el valor ya no está entre las opciones nuevas, se limpia.
|
|
985
|
+
if (changed && isFilled(ctrl.value)) {
|
|
986
|
+
const values = new Set(list.map((o) => o.value));
|
|
987
|
+
const current = ctrl.value;
|
|
988
|
+
const keep = Array.isArray(current) ? current.filter((v) => values.has(v)) : values.has(current) ? current : null;
|
|
989
|
+
if (JSON.stringify(keep) !== JSON.stringify(current))
|
|
990
|
+
ctrl.setValue(Array.isArray(current) ? keep : keep, { emitEvent: emit });
|
|
991
|
+
}
|
|
992
|
+
};
|
|
993
|
+
if (f.optionsFrom) {
|
|
994
|
+
apply(f.optionsFrom.map[String(scope[f.optionsFrom.field] ?? '')] ?? [], false);
|
|
995
|
+
return;
|
|
996
|
+
}
|
|
997
|
+
const loader = this.loaders()[f.optionsLoader];
|
|
998
|
+
if (!loader)
|
|
999
|
+
return;
|
|
1000
|
+
Promise.resolve(loader({ value: scope, field: f })).then((list) => {
|
|
1001
|
+
if (this.depsKeys.get(key) === depsKey)
|
|
1002
|
+
apply(list ?? [], true);
|
|
1003
|
+
});
|
|
1004
|
+
}
|
|
1005
|
+
rawValue() {
|
|
1006
|
+
return this.form().getRawValue();
|
|
1007
|
+
}
|
|
1008
|
+
/** Valor sin los campos ocultos (en todos los niveles). */
|
|
1009
|
+
currentValue() {
|
|
1010
|
+
const hidden = this.hidden();
|
|
1011
|
+
const strip = (fields, value, path) => {
|
|
1012
|
+
const out = {};
|
|
1013
|
+
for (const f of fields) {
|
|
1014
|
+
if (isLayout(f) || !f.key || hidden.has(this.pathKey(path, f.key)))
|
|
1015
|
+
continue;
|
|
1016
|
+
const v = value?.[f.key];
|
|
1017
|
+
if (f.type === 'group') {
|
|
1018
|
+
const inner = ordered(f.fields ?? []);
|
|
1019
|
+
out[f.key] = f.repeatable
|
|
1020
|
+
? (v ?? []).map((item, i) => strip(inner, item, [...path, f.key, i]))
|
|
1021
|
+
: strip(inner, v ?? {}, [...path, f.key]);
|
|
1022
|
+
}
|
|
1023
|
+
else
|
|
1024
|
+
out[f.key] = v;
|
|
1025
|
+
}
|
|
1026
|
+
return out;
|
|
1027
|
+
};
|
|
1028
|
+
return strip(this.fields(), this.rawValue(), []);
|
|
1029
|
+
}
|
|
1030
|
+
emitValue() {
|
|
1031
|
+
const value = this.currentValue();
|
|
1032
|
+
this.lastEmitted = value;
|
|
1033
|
+
this.value.set(value);
|
|
1034
|
+
}
|
|
1035
|
+
say(message) {
|
|
1036
|
+
this.announcement.set('');
|
|
1037
|
+
queueMicrotask(() => this.announcement.set(message));
|
|
1038
|
+
}
|
|
1039
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: CbDynamicForm, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
1040
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.5", type: CbDynamicForm, isStandalone: true, selector: "cb-dynamic-form", inputs: { schema: { classPropertyName: "schema", publicName: "schema", isSignal: true, isRequired: true, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null }, layout: { classPropertyName: "layout", publicName: "layout", isSignal: true, isRequired: false, transformFunction: null }, labelPosition: { classPropertyName: "labelPosition", publicName: "labelPosition", isSignal: true, isRequired: false, transformFunction: null }, columns: { classPropertyName: "columns", publicName: "columns", isSignal: true, isRequired: false, transformFunction: null }, labelWidth: { classPropertyName: "labelWidth", publicName: "labelWidth", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, loaders: { classPropertyName: "loaders", publicName: "loaders", isSignal: true, isRequired: false, transformFunction: null }, translate: { classPropertyName: "translate", publicName: "translate", isSignal: true, isRequired: false, transformFunction: null }, actions: { classPropertyName: "actions", publicName: "actions", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, loading: { classPropertyName: "loading", publicName: "loading", isSignal: true, isRequired: false, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "ariaLabel", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { value: "valueChange", formSubmit: "formSubmit", formInvalid: "formInvalid", formReset: "formReset", stepChange: "stepChange" }, host: { classAttribute: "cb-dynamic-form" }, queries: [{ propertyName: "templates", predicate: CbFormFieldTemplate, isSignal: true }], ngImport: i0, template: `
|
|
1041
|
+
<form class="cb-df__form" [formGroup]="form()" [attr.aria-label]="ariaLabel() || null" novalidate (submit)="onSubmit($event)" (reset)="$event.preventDefault(); reset()">
|
|
1042
|
+
@if (steps().length > 1) {
|
|
1043
|
+
<ol class="cb-df__steps">
|
|
1044
|
+
@for (s of steps(); track $index; let i = $index) {
|
|
1045
|
+
<li class="cb-df__step" [class.cb-is-done]="i < step()" [attr.aria-current]="i === step() ? 'step' : null">
|
|
1046
|
+
<span class="cb-df__step-num" aria-hidden="true">
|
|
1047
|
+
@if (i < step()) {
|
|
1048
|
+
<cb-icon name="check" [size]="13" />
|
|
1049
|
+
} @else {
|
|
1050
|
+
{{ i + 1 }}
|
|
1051
|
+
}
|
|
1052
|
+
</span>
|
|
1053
|
+
<span class="cb-df__step-title">{{ tr(s.title) }}</span>
|
|
1054
|
+
</li>
|
|
1055
|
+
}
|
|
1056
|
+
</ol>
|
|
1057
|
+
<h3 class="cb-df__step-heading" [id]="uid + '-step'" tabindex="-1">
|
|
1058
|
+
<span class="cb-df__sr">{{ fmt(t().dynamicFormStep, step() + 1, steps().length) }}</span>
|
|
1059
|
+
{{ tr(steps()[step()].title) }}
|
|
1060
|
+
</h3>
|
|
1061
|
+
@if (steps()[step()].description) {
|
|
1062
|
+
<p class="cb-df__section-desc">{{ tr(steps()[step()].description) }}</p>
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
@if (summary().length) {
|
|
1067
|
+
<div class="cb-df__summary" role="alert" tabindex="-1" [id]="uid + '-summary'">
|
|
1068
|
+
<p class="cb-df__summary-title">
|
|
1069
|
+
<cb-icon name="circle-alert" [size]="18" aria-hidden="true" />
|
|
1070
|
+
{{ summary().length === 1 ? t().dynamicFormSummaryOne : fmt(t().dynamicFormSummary, summary().length) }}
|
|
1071
|
+
</p>
|
|
1072
|
+
<ul class="cb-df__summary-list">
|
|
1073
|
+
@for (item of summary(); track item.id) {
|
|
1074
|
+
<li>
|
|
1075
|
+
<a [href]="'#' + item.id" (click)="$event.preventDefault(); focusById(item.id)">{{ item.label }}: {{ item.message }}</a>
|
|
1076
|
+
</li>
|
|
1077
|
+
}
|
|
1078
|
+
</ul>
|
|
1079
|
+
</div>
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
@for (section of sections(); track $index) {
|
|
1083
|
+
@if (sectionVisible(section)) {
|
|
1084
|
+
<fieldset class="cb-df__section" [class.cb-df__section--titled]="!!section.title">
|
|
1085
|
+
@if (section.title) {
|
|
1086
|
+
<legend class="cb-df__legend">{{ tr(section.title) }}</legend>
|
|
1087
|
+
}
|
|
1088
|
+
@if (section.description) {
|
|
1089
|
+
<p class="cb-df__section-desc">{{ tr(section.description) }}</p>
|
|
1090
|
+
}
|
|
1091
|
+
<ng-container *ngTemplateOutlet="gridTpl; context: { $implicit: section.fields, ctx: rootCtx(section) }" />
|
|
1092
|
+
</fieldset>
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
@if (actions()) {
|
|
1097
|
+
<div class="cb-df__actions" [class]="'cb-df__actions--' + actionsLabelPosition()" [style.--cb-df-label-width]="labelWidthValue()">
|
|
1098
|
+
<span class="cb-df__label cb-df__label--empty" aria-hidden="true"></span>
|
|
1099
|
+
<div class="cb-df__buttons">
|
|
1100
|
+
@if (step() > 0) {
|
|
1101
|
+
<cb-button variant="outlined" severity="secondary" [disabled]="disabled()" (click)="back()">{{ tr(schema().backLabel) || t().dynamicFormBack }}</cb-button>
|
|
1102
|
+
}
|
|
1103
|
+
@if (step() < steps().length - 1) {
|
|
1104
|
+
<cb-button [disabled]="disabled()" (click)="next()">{{ tr(schema().nextLabel) || t().dynamicFormNext }}</cb-button>
|
|
1105
|
+
} @else {
|
|
1106
|
+
<cb-button type="submit" [loading]="loading()" [disabled]="disabled()">{{ tr(schema().submitLabel) || t().dynamicFormSubmit }}</cb-button>
|
|
1107
|
+
}
|
|
1108
|
+
@if (schema().resetLabel) {
|
|
1109
|
+
<cb-button type="reset" variant="text" severity="secondary" [disabled]="disabled()">{{ tr(schema().resetLabel) }}</cb-button>
|
|
1110
|
+
}
|
|
1111
|
+
</div>
|
|
1112
|
+
</div>
|
|
1113
|
+
}
|
|
1114
|
+
<span class="cb-df__sr" role="status">{{ announcement() }}</span>
|
|
1115
|
+
</form>
|
|
1116
|
+
|
|
1117
|
+
<!-- Rejilla de campos (recursiva para grupos y listas). -->
|
|
1118
|
+
<ng-template #gridTpl let-fields let-ctx="ctx">
|
|
1119
|
+
<div class="cb-df__grid" [style]="gridVars(ctx.cols)">
|
|
1120
|
+
@for (f of fields; track $index) {
|
|
1121
|
+
@if (isVisible(f, ctx.path, $index)) {
|
|
1122
|
+
@switch (kindOf(f)) {
|
|
1123
|
+
@case ('heading') {
|
|
1124
|
+
<h4 class="cb-df__heading cb-df__cell" [style]="cellVars(f, ctx.cols, true)">{{ tr(f.content ?? f.label) }}</h4>
|
|
1125
|
+
}
|
|
1126
|
+
@case ('paragraph') {
|
|
1127
|
+
<p class="cb-df__paragraph cb-df__cell" [style]="cellVars(f, ctx.cols, true)">{{ tr(f.content ?? f.label) }}</p>
|
|
1128
|
+
}
|
|
1129
|
+
@case ('divider') {
|
|
1130
|
+
<hr class="cb-df__divider cb-df__cell" [style]="cellVars(f, ctx.cols, true)" />
|
|
1131
|
+
}
|
|
1132
|
+
@case ('list') {
|
|
1133
|
+
<fieldset class="cb-df__group cb-df__cell" [style]="cellVars(f, ctx.cols, true)" [attr.data-key]="pathKey(ctx.path, f.key)">
|
|
1134
|
+
<legend class="cb-df__group-title">{{ tr(f.label) }}</legend>
|
|
1135
|
+
@if (f.hint) {
|
|
1136
|
+
<p class="cb-df__message">{{ tr(f.hint) }}</p>
|
|
1137
|
+
}
|
|
1138
|
+
@for (item of listItems(ctx.group, f); track item; let i = $index) {
|
|
1139
|
+
<div class="cb-df__item" role="group" [attr.aria-label]="itemLabel(f, i)">
|
|
1140
|
+
<div class="cb-df__item-head">
|
|
1141
|
+
<span class="cb-df__item-title">{{ itemLabel(f, i) }}</span>
|
|
1142
|
+
@if (!isDisabledForm()) {
|
|
1143
|
+
<cb-button size="sm" variant="text" severity="secondary" [disabled]="listItems(ctx.group, f).length <= (f.minItems ?? 0)" [ariaLabel]="fmt(t().dynamicFormRemove, itemLabel(f, i))" (click)="removeItem(ctx.group, f, i)">
|
|
1144
|
+
<cb-icon name="x" [size]="15" aria-hidden="true" />
|
|
1145
|
+
{{ t().remove }}
|
|
1146
|
+
</cb-button>
|
|
1147
|
+
}
|
|
1148
|
+
</div>
|
|
1149
|
+
<ng-container *ngTemplateOutlet="gridTpl; context: { $implicit: ordered(f.fields ?? []), ctx: childCtx(ctx, f, item, i) }" />
|
|
1150
|
+
</div>
|
|
1151
|
+
}
|
|
1152
|
+
@if (!isDisabledForm() && (f.maxItems === undefined || listItems(ctx.group, f).length < f.maxItems)) {
|
|
1153
|
+
<div>
|
|
1154
|
+
<cb-button size="sm" variant="outlined" (click)="addItem(ctx.group, f)">
|
|
1155
|
+
<cb-icon name="plus" [size]="15" aria-hidden="true" />
|
|
1156
|
+
{{ tr(f.addLabel) || fmt(t().dynamicFormAdd, tr(f.label)) }}
|
|
1157
|
+
</cb-button>
|
|
1158
|
+
</div>
|
|
1159
|
+
}
|
|
1160
|
+
</fieldset>
|
|
1161
|
+
}
|
|
1162
|
+
@case ('group') {
|
|
1163
|
+
<fieldset class="cb-df__group cb-df__group--plain cb-df__cell" [style]="cellVars(f, ctx.cols, true)" [attr.data-key]="pathKey(ctx.path, f.key)">
|
|
1164
|
+
@if (f.label) {
|
|
1165
|
+
<legend class="cb-df__group-title">{{ tr(f.label) }}</legend>
|
|
1166
|
+
}
|
|
1167
|
+
<ng-container *ngTemplateOutlet="gridTpl; context: { $implicit: ordered(f.fields ?? []), ctx: childCtx(ctx, f, subGroup(ctx.group, f), null) }" />
|
|
1168
|
+
</fieldset>
|
|
1169
|
+
}
|
|
1170
|
+
@default {
|
|
1171
|
+
<ng-container *ngTemplateOutlet="fieldTpl; context: { $implicit: f, ctx: ctx }" />
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
</div>
|
|
1177
|
+
</ng-template>
|
|
1178
|
+
|
|
1179
|
+
<!-- Un campo con su etiqueta, control, ayuda y error. -->
|
|
1180
|
+
<ng-template #fieldTpl let-f let-ctx="ctx">
|
|
1181
|
+
@let id = idOf(ctx.path, f.key);
|
|
1182
|
+
@let ctrl = controlOf(ctx.group, f);
|
|
1183
|
+
@let pos = labelPos(f, ctx);
|
|
1184
|
+
@let err = errorOf(ctx.path, f, ctrl);
|
|
1185
|
+
<div
|
|
1186
|
+
class="cb-df__field cb-df__cell"
|
|
1187
|
+
[class]="'cb-df__field--' + pos"
|
|
1188
|
+
[class.cb-df__field--inline]="isInline(f)"
|
|
1189
|
+
[class.cb-df__field--end]="(f.labelAlign ?? ctx.opts.labelAlign) === 'end'"
|
|
1190
|
+
[class.cb-df__field--filled]="pos === 'floating' && filled(ctrl)"
|
|
1191
|
+
[style]="cellVars(f, ctx.cols, false) + ';--cb-df-label-width:' + (f.labelWidth ?? ctx.opts.labelWidth)"
|
|
1192
|
+
[attr.data-key]="pathKey(ctx.path, f.key)"
|
|
1193
|
+
>
|
|
1194
|
+
@if (isInline(f)) {
|
|
1195
|
+
<span class="cb-df__label cb-df__label--empty" aria-hidden="true"></span>
|
|
1196
|
+
} @else if (isLabelable(f)) {
|
|
1197
|
+
<label class="cb-df__label" [class.cb-df__sr]="pos === 'hidden'" [attr.for]="id" [id]="id + '-label'">
|
|
1198
|
+
{{ tr(f.label) }}
|
|
1199
|
+
@if (isRequired(ctx.path, f.key)) {
|
|
1200
|
+
<span class="cb-df__req" aria-hidden="true">*</span>
|
|
1201
|
+
}
|
|
1202
|
+
</label>
|
|
1203
|
+
} @else {
|
|
1204
|
+
<span class="cb-df__label" [class.cb-df__sr]="pos === 'hidden'" [id]="id + '-label'">
|
|
1205
|
+
{{ tr(f.label) }}
|
|
1206
|
+
@if (isRequired(ctx.path, f.key)) {
|
|
1207
|
+
<span class="cb-df__req" aria-hidden="true">*</span>
|
|
1208
|
+
}
|
|
1209
|
+
</span>
|
|
1210
|
+
}
|
|
1211
|
+
<div class="cb-df__control">
|
|
1212
|
+
<div class="cb-df__addons" [class.cb-df__addons--on]="!!(f.prefix || f.suffix || f.icon)">
|
|
1213
|
+
@if (f.icon) {
|
|
1214
|
+
<span class="cb-df__addon cb-df__addon--icon" aria-hidden="true"><cb-icon [name]="f.icon" [size]="16" /></span>
|
|
1215
|
+
}
|
|
1216
|
+
@if (f.prefix) {
|
|
1217
|
+
<span class="cb-df__addon" aria-hidden="true">{{ tr(f.prefix) }}</span>
|
|
1218
|
+
}
|
|
1219
|
+
<div class="cb-df__input">
|
|
1220
|
+
@switch (controlKind(f)) {
|
|
1221
|
+
@case ('textarea') {
|
|
1222
|
+
<cb-textarea [formControl]="ctrl" [inputId]="id" [size]="sizeOf(f, ctx)" [placeholder]="placeholderOf(f, pos)" [rows]="f.rows ?? 3" [maxlength]="f.maxLength ?? null" [readonly]="isReadonly(f)" [hint]="tr(f.hint)" [error]="err ?? ''" />
|
|
1223
|
+
}
|
|
1224
|
+
@case ('number') {
|
|
1225
|
+
<cb-input-number [formControl]="ctrl" [inputId]="id" [size]="sizeOf(f, ctx)" [placeholder]="placeholderOf(f, pos)" [min]="f.min ?? null" [max]="f.max ?? null" [step]="f.step ?? 1" [readonly]="isReadonly(f)" [hint]="tr(f.hint)" [error]="err ?? ''" />
|
|
1226
|
+
}
|
|
1227
|
+
@case ('date') {
|
|
1228
|
+
<cb-datepicker [formControl]="ctrl" [inputId]="id" [size]="sizeOf(f, ctx)" [placeholder]="placeholderOf(f, pos)" [hint]="tr(f.hint)" [error]="err ?? ''" />
|
|
1229
|
+
}
|
|
1230
|
+
@case ('password') {
|
|
1231
|
+
<cb-password [formControl]="ctrl" [inputId]="id" [size]="sizeOf(f, ctx)" [placeholder]="placeholderOf(f, pos)" [feedback]="false" />
|
|
1232
|
+
}
|
|
1233
|
+
@case ('mask') {
|
|
1234
|
+
<cb-input-mask [formControl]="ctrl" [inputId]="id" [mask]="f.mask ?? '999-999'" [placeholder]="placeholderOf(f, pos)" [ariaLabel]="tr(f.label)" />
|
|
1235
|
+
}
|
|
1236
|
+
@case ('select') {
|
|
1237
|
+
<cb-select [formControl]="ctrl" [inputId]="id" [size]="sizeOf(f, ctx)" [ariaLabelledBy]="id + '-label'" [options]="optionsOf(ctx.path, f)" optionValue="value" [placeholder]="pos === 'floating' ? ' ' : tr(f.placeholder) || t().select" />
|
|
1238
|
+
}
|
|
1239
|
+
@case ('multiselect') {
|
|
1240
|
+
<cb-multiselect [formControl]="ctrl" [inputId]="id" [size]="sizeOf(f, ctx)" [ariaLabelledBy]="id + '-label'" [options]="optionsOf(ctx.path, f)" optionValue="value" [placeholder]="pos === 'floating' ? ' ' : tr(f.placeholder) || t().select" />
|
|
1241
|
+
}
|
|
1242
|
+
@case ('radio') {
|
|
1243
|
+
<cb-radio-group [formControl]="ctrl" [ariaLabel]="tr(f.label) || f.key" [orientation]="f.orientation ?? 'vertical'">
|
|
1244
|
+
@for (o of optionsOf(ctx.path, f); track $index) {
|
|
1245
|
+
<cb-radio [value]="o.value" [label]="o.label" [disabled]="!!o.disabled" />
|
|
1246
|
+
}
|
|
1247
|
+
</cb-radio-group>
|
|
1248
|
+
}
|
|
1249
|
+
@case ('buttons') {
|
|
1250
|
+
<cb-selectbutton [formControl]="ctrl" [inputId]="id" [size]="sizeOf(f, ctx)" [ariaLabel]="tr(f.label) || f.key" [options]="optionsOf(ctx.path, f)" optionValue="value" />
|
|
1251
|
+
}
|
|
1252
|
+
@case ('checkbox') {
|
|
1253
|
+
<cb-checkbox [formControl]="ctrl" [inputId]="id" [label]="tr(f.label)" />
|
|
1254
|
+
}
|
|
1255
|
+
@case ('toggle') {
|
|
1256
|
+
<cb-toggle [formControl]="ctrl" [inputId]="id" [label]="tr(f.label)" />
|
|
1257
|
+
}
|
|
1258
|
+
@case ('slider') {
|
|
1259
|
+
<cb-slider [formControl]="ctrl" [inputId]="id" [ariaLabel]="tr(f.label) || f.key" [min]="f.min ?? 0" [max]="f.max ?? 100" [step]="f.step ?? 1" />
|
|
1260
|
+
}
|
|
1261
|
+
@case ('rating') {
|
|
1262
|
+
<cb-rating [formControl]="ctrl" [inputId]="id" [ariaLabel]="tr(f.label) || f.key" />
|
|
1263
|
+
}
|
|
1264
|
+
@case ('chips') {
|
|
1265
|
+
<cb-chips [formControl]="ctrl" [inputId]="id" [ariaLabel]="tr(f.label) || f.key" [placeholder]="placeholderOf(f, pos)" />
|
|
1266
|
+
}
|
|
1267
|
+
@case ('color') {
|
|
1268
|
+
<cb-colorpicker [formControl]="ctrl" [inputId]="id" [ariaLabel]="tr(f.label) || f.key" />
|
|
1269
|
+
}
|
|
1270
|
+
@case ('custom') {
|
|
1271
|
+
<ng-container *ngTemplateOutlet="customTemplate(f)!; context: { $implicit: ctrl, field: f, id: id, labelId: id + '-label', error: err, invalid: !!err }" />
|
|
1272
|
+
}
|
|
1273
|
+
@default {
|
|
1274
|
+
<cb-input [formControl]="ctrl" [inputId]="id" [size]="sizeOf(f, ctx)" [type]="inputType(f)" [placeholder]="placeholderOf(f, pos)" [readonly]="isReadonly(f)" [hint]="tr(f.hint)" [error]="err ?? ''" />
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
</div>
|
|
1278
|
+
@if (f.suffix) {
|
|
1279
|
+
<span class="cb-df__addon" aria-hidden="true">{{ tr(f.suffix) }}</span>
|
|
1280
|
+
}
|
|
1281
|
+
</div>
|
|
1282
|
+
@if (!ownsMessages(f)) {
|
|
1283
|
+
@if (err) {
|
|
1284
|
+
<p class="cb-df__message cb-df__message--error" role="alert" [id]="id + '-error'">{{ err }}</p>
|
|
1285
|
+
} @else if (f.hint) {
|
|
1286
|
+
<p class="cb-df__message" [id]="id + '-hint'">{{ tr(f.hint) }}</p>
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
</div>
|
|
1290
|
+
</div>
|
|
1291
|
+
</ng-template>
|
|
1292
|
+
`, isInline: true, styles: [":host{--cb-df-gap-x: var(--cb-space-5, 1.25rem);--cb-df-gap-y: var(--cb-space-4, 1rem);display:block;width:100%;min-width:0;container-type:inline-size;color:var(--cb-color-text);font-family:var(--cb-font-sans)}.cb-df__form{display:grid;gap:var(--cb-space-6, 1.5rem)}.cb-df__steps{display:flex;flex-wrap:wrap;gap:.5rem 1.5rem;margin:0;padding:0;list-style:none}.cb-df__step{display:inline-flex;align-items:center;gap:.5rem;color:var(--cb-color-text-muted);font-size:var(--cb-text-sm, .875rem)}.cb-df__step-num{display:inline-flex;align-items:center;justify-content:center;width:1.6rem;height:1.6rem;border:1.5px solid var(--cb-color-border-strong);border-radius:999px;font-size:var(--cb-text-xs, .75rem);font-weight:var(--cb-font-weight-semibold, 600)}.cb-df__step[aria-current=step]{color:var(--cb-color-text);font-weight:var(--cb-font-weight-semibold, 600)}.cb-df__step[aria-current=step] .cb-df__step-num{border-color:var(--cb-color-primary-text, var(--cb-color-primary-700));background:var(--cb-color-primary-text, var(--cb-color-primary-700));color:var(--cb-color-bg)}.cb-df__step.cb-is-done .cb-df__step-num{border-color:var(--cb-color-success-text, #166534);color:var(--cb-color-success-text, #166534)}.cb-df__step-heading{margin:0;font-size:var(--cb-text-base, 1rem);font-weight:var(--cb-font-weight-semibold, 600);outline:none}.cb-df__summary{padding:.85rem 1rem;border:1px solid color-mix(in srgb,var(--cb-color-danger-500, #ef4444) 45%,transparent);border-left-width:4px;border-radius:var(--cb-radius-md);background:color-mix(in srgb,var(--cb-color-danger-500, #ef4444) 7%,var(--cb-color-bg));outline:none}.cb-df__summary:focus-visible{outline:2px solid var(--cb-color-focus-ring);outline-offset:2px}.cb-df__summary-title{display:flex;align-items:center;gap:.5rem;margin:0 0 .4rem;color:var(--cb-color-danger-text, #dc2626);font-weight:var(--cb-font-weight-semibold, 600)}.cb-df__summary-list{display:grid;gap:.2rem;margin:0;padding-left:1.75rem;font-size:var(--cb-text-sm, .875rem)}.cb-df__summary-list a{color:var(--cb-color-danger-text, #dc2626);text-decoration:underline;text-underline-offset:2px}.cb-df__section{min-width:0;margin:0;padding:0;border:0}.cb-df__legend{margin-bottom:.25rem;padding:0;font-size:var(--cb-text-base, 1rem);font-weight:var(--cb-font-weight-semibold, 600)}.cb-df__section-desc{margin:0 0 .75rem;color:var(--cb-color-text-muted);font-size:var(--cb-text-sm, .875rem)}.cb-df__section--titled>.cb-df__grid{margin-top:.75rem}.cb-df__grid{display:grid;grid-template-columns:repeat(var(--df-cols-base, 1),minmax(0,1fr));gap:var(--cb-df-gap-y) var(--cb-df-gap-x);align-items:start;min-width:0}.cb-df__cell{grid-column:var(--df-col-base, auto)}@container (min-width: 30rem){.cb-df__grid{grid-template-columns:repeat(var(--df-cols-sm, 1),minmax(0,1fr))}.cb-df__cell{grid-column:var(--df-col-sm, auto)}}@container (min-width: 40rem){.cb-df__grid{grid-template-columns:repeat(var(--df-cols-md, 1),minmax(0,1fr))}.cb-df__cell{grid-column:var(--df-col-md, auto)}}@container (min-width: 60rem){.cb-df__grid{grid-template-columns:repeat(var(--df-cols-lg, 1),minmax(0,1fr))}.cb-df__cell{grid-column:var(--df-col-lg, auto)}}.cb-df__heading{margin:.5rem 0 0;font-size:var(--cb-text-base, 1rem);font-weight:var(--cb-font-weight-semibold, 600)}.cb-df__paragraph{margin:0;color:var(--cb-color-text-muted);font-size:var(--cb-text-sm, .875rem)}.cb-df__divider{width:100%;margin:.25rem 0;border:0;border-top:1px solid var(--cb-color-border)}.cb-df__group{display:grid;gap:.75rem;min-width:0;margin:0;padding:.85rem 1rem 1rem;border:1px solid var(--cb-color-border);border-radius:var(--cb-radius-md)}.cb-df__group--plain{padding:0;border:0}.cb-df__group-title{padding:0 .25rem;font-size:var(--cb-text-sm, .875rem);font-weight:var(--cb-font-weight-semibold, 600)}.cb-df__group--plain>.cb-df__group-title{padding:0;margin-bottom:.5rem}.cb-df__item{display:grid;gap:.6rem;padding:.75rem;border-radius:var(--cb-radius-md);background:var(--cb-color-surface-subtle)}.cb-df__item-head{display:flex;align-items:center;justify-content:space-between;gap:.5rem}.cb-df__item-title{color:var(--cb-color-text-muted);font-size:var(--cb-text-xs, .75rem);font-weight:var(--cb-font-weight-semibold, 600);text-transform:uppercase;letter-spacing:.04em}.cb-df__field{--cb-df-label-width: 10rem;display:grid;gap:.375rem;min-width:0}.cb-df__label{color:var(--cb-color-text);font-size:var(--cb-text-sm, .875rem);font-weight:var(--cb-font-weight-medium, 500)}.cb-df__label--empty{display:none}.cb-df__req{margin-left:.15rem;color:var(--cb-color-danger-text, #b91c1c)}.cb-df__control{display:grid;gap:.375rem;min-width:0}.cb-df__message{margin:0;color:var(--cb-color-text-muted);font-size:var(--cb-text-xs, .75rem)}.cb-df__message--error{color:var(--cb-color-danger-text, #dc2626)}.cb-df__field--top.cb-df__field--inline{align-self:end;align-content:center;min-height:2.5rem}.cb-df__field--left,.cb-df__actions--left{grid-template-columns:var(--cb-df-label-width) minmax(0,1fr);column-gap:var(--cb-space-4, 1rem)}.cb-df__field--right{grid-template-columns:minmax(0,1fr) var(--cb-df-label-width);column-gap:var(--cb-space-4, 1rem)}.cb-df__field--right>.cb-df__label{order:2}.cb-df__field--left>.cb-df__label,.cb-df__field--right>.cb-df__label{padding-top:.6rem;line-height:1.3}.cb-df__field--end>.cb-df__label{text-align:end}.cb-df__field--left>.cb-df__label--empty,.cb-df__field--right>.cb-df__label--empty,.cb-df__actions--left>.cb-df__label--empty{display:block}.cb-df__field--left.cb-df__field--inline .cb-df__control,.cb-df__field--right.cb-df__field--inline .cb-df__control{padding-top:.5rem}.cb-df__field--floating{position:relative}.cb-df__field--floating>.cb-df__label{position:absolute;top:.65rem;left:.75rem;z-index:1;max-width:calc(100% - 3rem);overflow:hidden;padding:0 .25rem;color:var(--cb-color-text-muted);font-weight:400;text-overflow:ellipsis;white-space:nowrap;pointer-events:none;transform-origin:left top;transition:transform var(--cb-duration-fast, .12s) var(--cb-ease, ease),color var(--cb-duration-fast, .12s) var(--cb-ease, ease)}.cb-df__field--floating:focus-within>.cb-df__label,.cb-df__field--floating.cb-df__field--filled>.cb-df__label{background:var(--cb-color-bg);color:var(--cb-color-text);transform:translateY(-1.15rem) scale(.82)}.cb-df__field--floating:focus-within>.cb-df__label{color:var(--cb-color-primary-text, var(--cb-color-primary-700))}.cb-df__sr{position:absolute!important;width:1px;height:1px;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap}.cb-df__addons{display:block;min-width:0}.cb-df__addons--on{display:flex;align-items:stretch}.cb-df__input{flex:1;min-width:0}.cb-df__addon{display:inline-flex;flex:none;align-items:center;height:2.5rem;padding:0 .75rem;border:var(--cb-border-width, 1px) solid var(--cb-color-border-strong);background:var(--cb-color-surface-subtle);color:var(--cb-color-text-muted);font-size:var(--cb-text-sm, .875rem);white-space:nowrap}.cb-df__addon:first-child{margin-right:-1px;border-radius:var(--cb-radius-md) 0 0 var(--cb-radius-md)}.cb-df__addon:last-child{margin-left:-1px;border-radius:0 var(--cb-radius-md) var(--cb-radius-md) 0}.cb-df__addon+.cb-df__addon{border-left:0}.cb-df__actions{--cb-df-label-width: 10rem;display:grid}.cb-df__buttons{display:flex;flex-wrap:wrap;gap:.5rem}@container (max-width: 30rem){.cb-df__field--left,.cb-df__field--right,.cb-df__actions--left{grid-template-columns:minmax(0,1fr)}.cb-df__field--left>.cb-df__label,.cb-df__field--right>.cb-df__label{order:0;padding-top:0;text-align:start}.cb-df__field--left>.cb-df__label--empty,.cb-df__field--right>.cb-df__label--empty,.cb-df__actions--left>.cb-df__label--empty{display:none}.cb-df__field--left.cb-df__field--inline .cb-df__control,.cb-df__field--right.cb-df__field--inline .cb-df__control{padding-top:0}}\n"], dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],[formArray],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i1.MaxLengthValidator, selector: "[maxlength][formControlName],[maxlength][formControl],[maxlength][ngModel]", inputs: ["maxlength"] }, { kind: "directive", type: i1.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "directive", type: i1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "component", type: CbButton, selector: "cb-button", inputs: ["severity", "variant", "size", "disabled", "loading", "fullWidth", "type", "ariaLabel", "ariaHaspopup", "ariaExpanded", "ariaControls"] }, { kind: "component", type: CbCheckbox, selector: "cb-checkbox", inputs: ["label", "ariaLabel", "size", "value", "indeterminate", "invalid", "required", "requiredIndicator", "disabled", "inputId"], outputs: ["changed"] }, { kind: "component", type: CbChips, selector: "cb-chips", inputs: ["value", "placeholder", "size", "invalid", "readonly", "disabled", "max", "allowDuplicate", "ariaLabel", "inputId"], outputs: ["valueChange", "added", "removed"] }, { kind: "component", type: CbColorPicker, selector: "cb-colorpicker", inputs: ["value", "size", "showValue", "presets", "invalid", "disabled", "ariaLabel", "inputId"], outputs: ["valueChange"] }, { kind: "component", type: CbDatepicker, selector: "cb-datepicker", inputs: ["value", "range", "label", "hint", "error", "placeholder", "size", "invalid", "required", "requiredIndicator", "disabled", "inputId", "locale", "firstDayOfWeek", "minDate", "maxDate", "selectionMode", "view", "numberOfMonths", "showTime", "hourFormat", "stepMinute", "dateFormat", "editable", "presets"], outputs: ["valueChange", "rangeChange"] }, { kind: "component", type: CbIcon, selector: "cb-icon", inputs: ["name", "size", "spin", "ariaLabel"] }, { kind: "component", type: CbInput, selector: "cb-input", inputs: ["value", "label", "hint", "error", "invalid", "type", "placeholder", "size", "readonly", "required", "requiredIndicator", "inputmode", "disabled", "inputId"], outputs: ["valueChange"] }, { kind: "component", type: CbInputMask, selector: "cb-input-mask", inputs: ["mask", "unmask", "placeholder", "disabled", "invalid", "ariaLabel", "inputId", "value"], outputs: ["valueChange"] }, { kind: "component", type: CbInputNumber, selector: "cb-input-number", inputs: ["value", "label", "hint", "error", "placeholder", "size", "invalid", "required", "requiredIndicator", "readonly", "disabled", "inputId", "min", "max", "step", "showButtons", "mode", "currency", "locale", "useGrouping", "minFractionDigits", "maxFractionDigits", "prefix", "suffix"], outputs: ["valueChange"] }, { kind: "component", type: CbMultiSelect, selector: "cb-multiselect", inputs: ["options", "optionLabel", "optionValue", "optionDisabled", "group", "optionGroupLabel", "optionGroupChildren", "placeholder", "size", "filter", "filterPlaceholder", "emptyMessage", "showToggleAll", "maxSelectedLabels", "scrollHeight", "virtualScroll", "virtualScrollItemSize", "invalid", "disabled", "inputId", "ariaLabel", "ariaLabelledBy", "value"], outputs: ["valueChange"] }, { kind: "component", type: CbPassword, selector: "cb-password", inputs: ["placeholder", "disabled", "invalid", "toggleMask", "feedback", "size", "inputId", "autocomplete", "value"], outputs: ["valueChange"] }, { kind: "component", type: CbRadio, selector: "cb-radio", inputs: ["value", "label", "ariaLabel", "disabled", "inputId"] }, { kind: "component", type: CbRadioGroup, selector: "cb-radio-group", inputs: ["ariaLabel", "name", "size", "orientation", "disabled", "invalid"], outputs: ["changed"] }, { kind: "component", type: CbRating, selector: "cb-rating", inputs: ["value", "stars", "size", "readonly", "disabled", "invalid", "ariaLabel", "inputId"], outputs: ["valueChange", "changed"] }, { kind: "component", type: CbSelect, selector: "cb-select", inputs: ["options", "optionLabel", "optionValue", "optionDisabled", "group", "optionGroupLabel", "optionGroupChildren", "placeholder", "size", "filter", "filterPlaceholder", "emptyMessage", "showClear", "scrollHeight", "virtualScroll", "virtualScrollItemSize", "invalid", "disabled", "inputId", "ariaLabel", "ariaLabelledBy", "value"], outputs: ["valueChange"] }, { kind: "component", type: CbSelectButton, selector: "cb-selectbutton", inputs: ["options", "optionLabel", "optionValue", "optionDisabled", "multiple", "size", "disabled", "invalid", "ariaLabel", "inputId", "value"], outputs: ["valueChange", "changed"] }, { kind: "component", type: CbSlider, selector: "cb-slider", inputs: ["value", "rangeValue", "min", "max", "step", "size", "range", "showValue", "valueFormat", "locale", "disabled", "invalid", "ariaLabel", "inputId"], outputs: ["valueChange", "rangeValueChange", "changed", "rangeChanged"] }, { kind: "component", type: CbTextarea, selector: "cb-textarea", inputs: ["value", "label", "hint", "error", "invalid", "placeholder", "size", "rows", "autoResize", "maxlength", "readonly", "required", "requiredIndicator", "disabled", "inputId"], outputs: ["valueChange"] }, { kind: "component", type: CbToggle, selector: "cb-toggle", inputs: ["label", "ariaLabel", "size", "disabled", "invalid", "requiredIndicator", "inputId"], outputs: ["changed"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
|
|
1293
|
+
}
|
|
1294
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: CbDynamicForm, decorators: [{
|
|
1295
|
+
type: Component,
|
|
1296
|
+
args: [{ selector: 'cb-dynamic-form', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.Emulated, imports: [
|
|
1297
|
+
NgTemplateOutlet,
|
|
1298
|
+
ReactiveFormsModule,
|
|
1299
|
+
CbButton,
|
|
1300
|
+
CbCheckbox,
|
|
1301
|
+
CbChips,
|
|
1302
|
+
CbColorPicker,
|
|
1303
|
+
CbDatepicker,
|
|
1304
|
+
CbIcon,
|
|
1305
|
+
CbInput,
|
|
1306
|
+
CbInputMask,
|
|
1307
|
+
CbInputNumber,
|
|
1308
|
+
CbMultiSelect,
|
|
1309
|
+
CbPassword,
|
|
1310
|
+
CbRadio,
|
|
1311
|
+
CbRadioGroup,
|
|
1312
|
+
CbRating,
|
|
1313
|
+
CbSelect,
|
|
1314
|
+
CbSelectButton,
|
|
1315
|
+
CbSlider,
|
|
1316
|
+
CbTextarea,
|
|
1317
|
+
CbToggle,
|
|
1318
|
+
], host: { class: 'cb-dynamic-form' }, template: `
|
|
1319
|
+
<form class="cb-df__form" [formGroup]="form()" [attr.aria-label]="ariaLabel() || null" novalidate (submit)="onSubmit($event)" (reset)="$event.preventDefault(); reset()">
|
|
1320
|
+
@if (steps().length > 1) {
|
|
1321
|
+
<ol class="cb-df__steps">
|
|
1322
|
+
@for (s of steps(); track $index; let i = $index) {
|
|
1323
|
+
<li class="cb-df__step" [class.cb-is-done]="i < step()" [attr.aria-current]="i === step() ? 'step' : null">
|
|
1324
|
+
<span class="cb-df__step-num" aria-hidden="true">
|
|
1325
|
+
@if (i < step()) {
|
|
1326
|
+
<cb-icon name="check" [size]="13" />
|
|
1327
|
+
} @else {
|
|
1328
|
+
{{ i + 1 }}
|
|
1329
|
+
}
|
|
1330
|
+
</span>
|
|
1331
|
+
<span class="cb-df__step-title">{{ tr(s.title) }}</span>
|
|
1332
|
+
</li>
|
|
1333
|
+
}
|
|
1334
|
+
</ol>
|
|
1335
|
+
<h3 class="cb-df__step-heading" [id]="uid + '-step'" tabindex="-1">
|
|
1336
|
+
<span class="cb-df__sr">{{ fmt(t().dynamicFormStep, step() + 1, steps().length) }}</span>
|
|
1337
|
+
{{ tr(steps()[step()].title) }}
|
|
1338
|
+
</h3>
|
|
1339
|
+
@if (steps()[step()].description) {
|
|
1340
|
+
<p class="cb-df__section-desc">{{ tr(steps()[step()].description) }}</p>
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
@if (summary().length) {
|
|
1345
|
+
<div class="cb-df__summary" role="alert" tabindex="-1" [id]="uid + '-summary'">
|
|
1346
|
+
<p class="cb-df__summary-title">
|
|
1347
|
+
<cb-icon name="circle-alert" [size]="18" aria-hidden="true" />
|
|
1348
|
+
{{ summary().length === 1 ? t().dynamicFormSummaryOne : fmt(t().dynamicFormSummary, summary().length) }}
|
|
1349
|
+
</p>
|
|
1350
|
+
<ul class="cb-df__summary-list">
|
|
1351
|
+
@for (item of summary(); track item.id) {
|
|
1352
|
+
<li>
|
|
1353
|
+
<a [href]="'#' + item.id" (click)="$event.preventDefault(); focusById(item.id)">{{ item.label }}: {{ item.message }}</a>
|
|
1354
|
+
</li>
|
|
1355
|
+
}
|
|
1356
|
+
</ul>
|
|
1357
|
+
</div>
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
@for (section of sections(); track $index) {
|
|
1361
|
+
@if (sectionVisible(section)) {
|
|
1362
|
+
<fieldset class="cb-df__section" [class.cb-df__section--titled]="!!section.title">
|
|
1363
|
+
@if (section.title) {
|
|
1364
|
+
<legend class="cb-df__legend">{{ tr(section.title) }}</legend>
|
|
1365
|
+
}
|
|
1366
|
+
@if (section.description) {
|
|
1367
|
+
<p class="cb-df__section-desc">{{ tr(section.description) }}</p>
|
|
1368
|
+
}
|
|
1369
|
+
<ng-container *ngTemplateOutlet="gridTpl; context: { $implicit: section.fields, ctx: rootCtx(section) }" />
|
|
1370
|
+
</fieldset>
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
@if (actions()) {
|
|
1375
|
+
<div class="cb-df__actions" [class]="'cb-df__actions--' + actionsLabelPosition()" [style.--cb-df-label-width]="labelWidthValue()">
|
|
1376
|
+
<span class="cb-df__label cb-df__label--empty" aria-hidden="true"></span>
|
|
1377
|
+
<div class="cb-df__buttons">
|
|
1378
|
+
@if (step() > 0) {
|
|
1379
|
+
<cb-button variant="outlined" severity="secondary" [disabled]="disabled()" (click)="back()">{{ tr(schema().backLabel) || t().dynamicFormBack }}</cb-button>
|
|
1380
|
+
}
|
|
1381
|
+
@if (step() < steps().length - 1) {
|
|
1382
|
+
<cb-button [disabled]="disabled()" (click)="next()">{{ tr(schema().nextLabel) || t().dynamicFormNext }}</cb-button>
|
|
1383
|
+
} @else {
|
|
1384
|
+
<cb-button type="submit" [loading]="loading()" [disabled]="disabled()">{{ tr(schema().submitLabel) || t().dynamicFormSubmit }}</cb-button>
|
|
1385
|
+
}
|
|
1386
|
+
@if (schema().resetLabel) {
|
|
1387
|
+
<cb-button type="reset" variant="text" severity="secondary" [disabled]="disabled()">{{ tr(schema().resetLabel) }}</cb-button>
|
|
1388
|
+
}
|
|
1389
|
+
</div>
|
|
1390
|
+
</div>
|
|
1391
|
+
}
|
|
1392
|
+
<span class="cb-df__sr" role="status">{{ announcement() }}</span>
|
|
1393
|
+
</form>
|
|
1394
|
+
|
|
1395
|
+
<!-- Rejilla de campos (recursiva para grupos y listas). -->
|
|
1396
|
+
<ng-template #gridTpl let-fields let-ctx="ctx">
|
|
1397
|
+
<div class="cb-df__grid" [style]="gridVars(ctx.cols)">
|
|
1398
|
+
@for (f of fields; track $index) {
|
|
1399
|
+
@if (isVisible(f, ctx.path, $index)) {
|
|
1400
|
+
@switch (kindOf(f)) {
|
|
1401
|
+
@case ('heading') {
|
|
1402
|
+
<h4 class="cb-df__heading cb-df__cell" [style]="cellVars(f, ctx.cols, true)">{{ tr(f.content ?? f.label) }}</h4>
|
|
1403
|
+
}
|
|
1404
|
+
@case ('paragraph') {
|
|
1405
|
+
<p class="cb-df__paragraph cb-df__cell" [style]="cellVars(f, ctx.cols, true)">{{ tr(f.content ?? f.label) }}</p>
|
|
1406
|
+
}
|
|
1407
|
+
@case ('divider') {
|
|
1408
|
+
<hr class="cb-df__divider cb-df__cell" [style]="cellVars(f, ctx.cols, true)" />
|
|
1409
|
+
}
|
|
1410
|
+
@case ('list') {
|
|
1411
|
+
<fieldset class="cb-df__group cb-df__cell" [style]="cellVars(f, ctx.cols, true)" [attr.data-key]="pathKey(ctx.path, f.key)">
|
|
1412
|
+
<legend class="cb-df__group-title">{{ tr(f.label) }}</legend>
|
|
1413
|
+
@if (f.hint) {
|
|
1414
|
+
<p class="cb-df__message">{{ tr(f.hint) }}</p>
|
|
1415
|
+
}
|
|
1416
|
+
@for (item of listItems(ctx.group, f); track item; let i = $index) {
|
|
1417
|
+
<div class="cb-df__item" role="group" [attr.aria-label]="itemLabel(f, i)">
|
|
1418
|
+
<div class="cb-df__item-head">
|
|
1419
|
+
<span class="cb-df__item-title">{{ itemLabel(f, i) }}</span>
|
|
1420
|
+
@if (!isDisabledForm()) {
|
|
1421
|
+
<cb-button size="sm" variant="text" severity="secondary" [disabled]="listItems(ctx.group, f).length <= (f.minItems ?? 0)" [ariaLabel]="fmt(t().dynamicFormRemove, itemLabel(f, i))" (click)="removeItem(ctx.group, f, i)">
|
|
1422
|
+
<cb-icon name="x" [size]="15" aria-hidden="true" />
|
|
1423
|
+
{{ t().remove }}
|
|
1424
|
+
</cb-button>
|
|
1425
|
+
}
|
|
1426
|
+
</div>
|
|
1427
|
+
<ng-container *ngTemplateOutlet="gridTpl; context: { $implicit: ordered(f.fields ?? []), ctx: childCtx(ctx, f, item, i) }" />
|
|
1428
|
+
</div>
|
|
1429
|
+
}
|
|
1430
|
+
@if (!isDisabledForm() && (f.maxItems === undefined || listItems(ctx.group, f).length < f.maxItems)) {
|
|
1431
|
+
<div>
|
|
1432
|
+
<cb-button size="sm" variant="outlined" (click)="addItem(ctx.group, f)">
|
|
1433
|
+
<cb-icon name="plus" [size]="15" aria-hidden="true" />
|
|
1434
|
+
{{ tr(f.addLabel) || fmt(t().dynamicFormAdd, tr(f.label)) }}
|
|
1435
|
+
</cb-button>
|
|
1436
|
+
</div>
|
|
1437
|
+
}
|
|
1438
|
+
</fieldset>
|
|
1439
|
+
}
|
|
1440
|
+
@case ('group') {
|
|
1441
|
+
<fieldset class="cb-df__group cb-df__group--plain cb-df__cell" [style]="cellVars(f, ctx.cols, true)" [attr.data-key]="pathKey(ctx.path, f.key)">
|
|
1442
|
+
@if (f.label) {
|
|
1443
|
+
<legend class="cb-df__group-title">{{ tr(f.label) }}</legend>
|
|
1444
|
+
}
|
|
1445
|
+
<ng-container *ngTemplateOutlet="gridTpl; context: { $implicit: ordered(f.fields ?? []), ctx: childCtx(ctx, f, subGroup(ctx.group, f), null) }" />
|
|
1446
|
+
</fieldset>
|
|
1447
|
+
}
|
|
1448
|
+
@default {
|
|
1449
|
+
<ng-container *ngTemplateOutlet="fieldTpl; context: { $implicit: f, ctx: ctx }" />
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
</div>
|
|
1455
|
+
</ng-template>
|
|
1456
|
+
|
|
1457
|
+
<!-- Un campo con su etiqueta, control, ayuda y error. -->
|
|
1458
|
+
<ng-template #fieldTpl let-f let-ctx="ctx">
|
|
1459
|
+
@let id = idOf(ctx.path, f.key);
|
|
1460
|
+
@let ctrl = controlOf(ctx.group, f);
|
|
1461
|
+
@let pos = labelPos(f, ctx);
|
|
1462
|
+
@let err = errorOf(ctx.path, f, ctrl);
|
|
1463
|
+
<div
|
|
1464
|
+
class="cb-df__field cb-df__cell"
|
|
1465
|
+
[class]="'cb-df__field--' + pos"
|
|
1466
|
+
[class.cb-df__field--inline]="isInline(f)"
|
|
1467
|
+
[class.cb-df__field--end]="(f.labelAlign ?? ctx.opts.labelAlign) === 'end'"
|
|
1468
|
+
[class.cb-df__field--filled]="pos === 'floating' && filled(ctrl)"
|
|
1469
|
+
[style]="cellVars(f, ctx.cols, false) + ';--cb-df-label-width:' + (f.labelWidth ?? ctx.opts.labelWidth)"
|
|
1470
|
+
[attr.data-key]="pathKey(ctx.path, f.key)"
|
|
1471
|
+
>
|
|
1472
|
+
@if (isInline(f)) {
|
|
1473
|
+
<span class="cb-df__label cb-df__label--empty" aria-hidden="true"></span>
|
|
1474
|
+
} @else if (isLabelable(f)) {
|
|
1475
|
+
<label class="cb-df__label" [class.cb-df__sr]="pos === 'hidden'" [attr.for]="id" [id]="id + '-label'">
|
|
1476
|
+
{{ tr(f.label) }}
|
|
1477
|
+
@if (isRequired(ctx.path, f.key)) {
|
|
1478
|
+
<span class="cb-df__req" aria-hidden="true">*</span>
|
|
1479
|
+
}
|
|
1480
|
+
</label>
|
|
1481
|
+
} @else {
|
|
1482
|
+
<span class="cb-df__label" [class.cb-df__sr]="pos === 'hidden'" [id]="id + '-label'">
|
|
1483
|
+
{{ tr(f.label) }}
|
|
1484
|
+
@if (isRequired(ctx.path, f.key)) {
|
|
1485
|
+
<span class="cb-df__req" aria-hidden="true">*</span>
|
|
1486
|
+
}
|
|
1487
|
+
</span>
|
|
1488
|
+
}
|
|
1489
|
+
<div class="cb-df__control">
|
|
1490
|
+
<div class="cb-df__addons" [class.cb-df__addons--on]="!!(f.prefix || f.suffix || f.icon)">
|
|
1491
|
+
@if (f.icon) {
|
|
1492
|
+
<span class="cb-df__addon cb-df__addon--icon" aria-hidden="true"><cb-icon [name]="f.icon" [size]="16" /></span>
|
|
1493
|
+
}
|
|
1494
|
+
@if (f.prefix) {
|
|
1495
|
+
<span class="cb-df__addon" aria-hidden="true">{{ tr(f.prefix) }}</span>
|
|
1496
|
+
}
|
|
1497
|
+
<div class="cb-df__input">
|
|
1498
|
+
@switch (controlKind(f)) {
|
|
1499
|
+
@case ('textarea') {
|
|
1500
|
+
<cb-textarea [formControl]="ctrl" [inputId]="id" [size]="sizeOf(f, ctx)" [placeholder]="placeholderOf(f, pos)" [rows]="f.rows ?? 3" [maxlength]="f.maxLength ?? null" [readonly]="isReadonly(f)" [hint]="tr(f.hint)" [error]="err ?? ''" />
|
|
1501
|
+
}
|
|
1502
|
+
@case ('number') {
|
|
1503
|
+
<cb-input-number [formControl]="ctrl" [inputId]="id" [size]="sizeOf(f, ctx)" [placeholder]="placeholderOf(f, pos)" [min]="f.min ?? null" [max]="f.max ?? null" [step]="f.step ?? 1" [readonly]="isReadonly(f)" [hint]="tr(f.hint)" [error]="err ?? ''" />
|
|
1504
|
+
}
|
|
1505
|
+
@case ('date') {
|
|
1506
|
+
<cb-datepicker [formControl]="ctrl" [inputId]="id" [size]="sizeOf(f, ctx)" [placeholder]="placeholderOf(f, pos)" [hint]="tr(f.hint)" [error]="err ?? ''" />
|
|
1507
|
+
}
|
|
1508
|
+
@case ('password') {
|
|
1509
|
+
<cb-password [formControl]="ctrl" [inputId]="id" [size]="sizeOf(f, ctx)" [placeholder]="placeholderOf(f, pos)" [feedback]="false" />
|
|
1510
|
+
}
|
|
1511
|
+
@case ('mask') {
|
|
1512
|
+
<cb-input-mask [formControl]="ctrl" [inputId]="id" [mask]="f.mask ?? '999-999'" [placeholder]="placeholderOf(f, pos)" [ariaLabel]="tr(f.label)" />
|
|
1513
|
+
}
|
|
1514
|
+
@case ('select') {
|
|
1515
|
+
<cb-select [formControl]="ctrl" [inputId]="id" [size]="sizeOf(f, ctx)" [ariaLabelledBy]="id + '-label'" [options]="optionsOf(ctx.path, f)" optionValue="value" [placeholder]="pos === 'floating' ? ' ' : tr(f.placeholder) || t().select" />
|
|
1516
|
+
}
|
|
1517
|
+
@case ('multiselect') {
|
|
1518
|
+
<cb-multiselect [formControl]="ctrl" [inputId]="id" [size]="sizeOf(f, ctx)" [ariaLabelledBy]="id + '-label'" [options]="optionsOf(ctx.path, f)" optionValue="value" [placeholder]="pos === 'floating' ? ' ' : tr(f.placeholder) || t().select" />
|
|
1519
|
+
}
|
|
1520
|
+
@case ('radio') {
|
|
1521
|
+
<cb-radio-group [formControl]="ctrl" [ariaLabel]="tr(f.label) || f.key" [orientation]="f.orientation ?? 'vertical'">
|
|
1522
|
+
@for (o of optionsOf(ctx.path, f); track $index) {
|
|
1523
|
+
<cb-radio [value]="o.value" [label]="o.label" [disabled]="!!o.disabled" />
|
|
1524
|
+
}
|
|
1525
|
+
</cb-radio-group>
|
|
1526
|
+
}
|
|
1527
|
+
@case ('buttons') {
|
|
1528
|
+
<cb-selectbutton [formControl]="ctrl" [inputId]="id" [size]="sizeOf(f, ctx)" [ariaLabel]="tr(f.label) || f.key" [options]="optionsOf(ctx.path, f)" optionValue="value" />
|
|
1529
|
+
}
|
|
1530
|
+
@case ('checkbox') {
|
|
1531
|
+
<cb-checkbox [formControl]="ctrl" [inputId]="id" [label]="tr(f.label)" />
|
|
1532
|
+
}
|
|
1533
|
+
@case ('toggle') {
|
|
1534
|
+
<cb-toggle [formControl]="ctrl" [inputId]="id" [label]="tr(f.label)" />
|
|
1535
|
+
}
|
|
1536
|
+
@case ('slider') {
|
|
1537
|
+
<cb-slider [formControl]="ctrl" [inputId]="id" [ariaLabel]="tr(f.label) || f.key" [min]="f.min ?? 0" [max]="f.max ?? 100" [step]="f.step ?? 1" />
|
|
1538
|
+
}
|
|
1539
|
+
@case ('rating') {
|
|
1540
|
+
<cb-rating [formControl]="ctrl" [inputId]="id" [ariaLabel]="tr(f.label) || f.key" />
|
|
1541
|
+
}
|
|
1542
|
+
@case ('chips') {
|
|
1543
|
+
<cb-chips [formControl]="ctrl" [inputId]="id" [ariaLabel]="tr(f.label) || f.key" [placeholder]="placeholderOf(f, pos)" />
|
|
1544
|
+
}
|
|
1545
|
+
@case ('color') {
|
|
1546
|
+
<cb-colorpicker [formControl]="ctrl" [inputId]="id" [ariaLabel]="tr(f.label) || f.key" />
|
|
1547
|
+
}
|
|
1548
|
+
@case ('custom') {
|
|
1549
|
+
<ng-container *ngTemplateOutlet="customTemplate(f)!; context: { $implicit: ctrl, field: f, id: id, labelId: id + '-label', error: err, invalid: !!err }" />
|
|
1550
|
+
}
|
|
1551
|
+
@default {
|
|
1552
|
+
<cb-input [formControl]="ctrl" [inputId]="id" [size]="sizeOf(f, ctx)" [type]="inputType(f)" [placeholder]="placeholderOf(f, pos)" [readonly]="isReadonly(f)" [hint]="tr(f.hint)" [error]="err ?? ''" />
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
</div>
|
|
1556
|
+
@if (f.suffix) {
|
|
1557
|
+
<span class="cb-df__addon" aria-hidden="true">{{ tr(f.suffix) }}</span>
|
|
1558
|
+
}
|
|
1559
|
+
</div>
|
|
1560
|
+
@if (!ownsMessages(f)) {
|
|
1561
|
+
@if (err) {
|
|
1562
|
+
<p class="cb-df__message cb-df__message--error" role="alert" [id]="id + '-error'">{{ err }}</p>
|
|
1563
|
+
} @else if (f.hint) {
|
|
1564
|
+
<p class="cb-df__message" [id]="id + '-hint'">{{ tr(f.hint) }}</p>
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
</div>
|
|
1568
|
+
</div>
|
|
1569
|
+
</ng-template>
|
|
1570
|
+
`, styles: [":host{--cb-df-gap-x: var(--cb-space-5, 1.25rem);--cb-df-gap-y: var(--cb-space-4, 1rem);display:block;width:100%;min-width:0;container-type:inline-size;color:var(--cb-color-text);font-family:var(--cb-font-sans)}.cb-df__form{display:grid;gap:var(--cb-space-6, 1.5rem)}.cb-df__steps{display:flex;flex-wrap:wrap;gap:.5rem 1.5rem;margin:0;padding:0;list-style:none}.cb-df__step{display:inline-flex;align-items:center;gap:.5rem;color:var(--cb-color-text-muted);font-size:var(--cb-text-sm, .875rem)}.cb-df__step-num{display:inline-flex;align-items:center;justify-content:center;width:1.6rem;height:1.6rem;border:1.5px solid var(--cb-color-border-strong);border-radius:999px;font-size:var(--cb-text-xs, .75rem);font-weight:var(--cb-font-weight-semibold, 600)}.cb-df__step[aria-current=step]{color:var(--cb-color-text);font-weight:var(--cb-font-weight-semibold, 600)}.cb-df__step[aria-current=step] .cb-df__step-num{border-color:var(--cb-color-primary-text, var(--cb-color-primary-700));background:var(--cb-color-primary-text, var(--cb-color-primary-700));color:var(--cb-color-bg)}.cb-df__step.cb-is-done .cb-df__step-num{border-color:var(--cb-color-success-text, #166534);color:var(--cb-color-success-text, #166534)}.cb-df__step-heading{margin:0;font-size:var(--cb-text-base, 1rem);font-weight:var(--cb-font-weight-semibold, 600);outline:none}.cb-df__summary{padding:.85rem 1rem;border:1px solid color-mix(in srgb,var(--cb-color-danger-500, #ef4444) 45%,transparent);border-left-width:4px;border-radius:var(--cb-radius-md);background:color-mix(in srgb,var(--cb-color-danger-500, #ef4444) 7%,var(--cb-color-bg));outline:none}.cb-df__summary:focus-visible{outline:2px solid var(--cb-color-focus-ring);outline-offset:2px}.cb-df__summary-title{display:flex;align-items:center;gap:.5rem;margin:0 0 .4rem;color:var(--cb-color-danger-text, #dc2626);font-weight:var(--cb-font-weight-semibold, 600)}.cb-df__summary-list{display:grid;gap:.2rem;margin:0;padding-left:1.75rem;font-size:var(--cb-text-sm, .875rem)}.cb-df__summary-list a{color:var(--cb-color-danger-text, #dc2626);text-decoration:underline;text-underline-offset:2px}.cb-df__section{min-width:0;margin:0;padding:0;border:0}.cb-df__legend{margin-bottom:.25rem;padding:0;font-size:var(--cb-text-base, 1rem);font-weight:var(--cb-font-weight-semibold, 600)}.cb-df__section-desc{margin:0 0 .75rem;color:var(--cb-color-text-muted);font-size:var(--cb-text-sm, .875rem)}.cb-df__section--titled>.cb-df__grid{margin-top:.75rem}.cb-df__grid{display:grid;grid-template-columns:repeat(var(--df-cols-base, 1),minmax(0,1fr));gap:var(--cb-df-gap-y) var(--cb-df-gap-x);align-items:start;min-width:0}.cb-df__cell{grid-column:var(--df-col-base, auto)}@container (min-width: 30rem){.cb-df__grid{grid-template-columns:repeat(var(--df-cols-sm, 1),minmax(0,1fr))}.cb-df__cell{grid-column:var(--df-col-sm, auto)}}@container (min-width: 40rem){.cb-df__grid{grid-template-columns:repeat(var(--df-cols-md, 1),minmax(0,1fr))}.cb-df__cell{grid-column:var(--df-col-md, auto)}}@container (min-width: 60rem){.cb-df__grid{grid-template-columns:repeat(var(--df-cols-lg, 1),minmax(0,1fr))}.cb-df__cell{grid-column:var(--df-col-lg, auto)}}.cb-df__heading{margin:.5rem 0 0;font-size:var(--cb-text-base, 1rem);font-weight:var(--cb-font-weight-semibold, 600)}.cb-df__paragraph{margin:0;color:var(--cb-color-text-muted);font-size:var(--cb-text-sm, .875rem)}.cb-df__divider{width:100%;margin:.25rem 0;border:0;border-top:1px solid var(--cb-color-border)}.cb-df__group{display:grid;gap:.75rem;min-width:0;margin:0;padding:.85rem 1rem 1rem;border:1px solid var(--cb-color-border);border-radius:var(--cb-radius-md)}.cb-df__group--plain{padding:0;border:0}.cb-df__group-title{padding:0 .25rem;font-size:var(--cb-text-sm, .875rem);font-weight:var(--cb-font-weight-semibold, 600)}.cb-df__group--plain>.cb-df__group-title{padding:0;margin-bottom:.5rem}.cb-df__item{display:grid;gap:.6rem;padding:.75rem;border-radius:var(--cb-radius-md);background:var(--cb-color-surface-subtle)}.cb-df__item-head{display:flex;align-items:center;justify-content:space-between;gap:.5rem}.cb-df__item-title{color:var(--cb-color-text-muted);font-size:var(--cb-text-xs, .75rem);font-weight:var(--cb-font-weight-semibold, 600);text-transform:uppercase;letter-spacing:.04em}.cb-df__field{--cb-df-label-width: 10rem;display:grid;gap:.375rem;min-width:0}.cb-df__label{color:var(--cb-color-text);font-size:var(--cb-text-sm, .875rem);font-weight:var(--cb-font-weight-medium, 500)}.cb-df__label--empty{display:none}.cb-df__req{margin-left:.15rem;color:var(--cb-color-danger-text, #b91c1c)}.cb-df__control{display:grid;gap:.375rem;min-width:0}.cb-df__message{margin:0;color:var(--cb-color-text-muted);font-size:var(--cb-text-xs, .75rem)}.cb-df__message--error{color:var(--cb-color-danger-text, #dc2626)}.cb-df__field--top.cb-df__field--inline{align-self:end;align-content:center;min-height:2.5rem}.cb-df__field--left,.cb-df__actions--left{grid-template-columns:var(--cb-df-label-width) minmax(0,1fr);column-gap:var(--cb-space-4, 1rem)}.cb-df__field--right{grid-template-columns:minmax(0,1fr) var(--cb-df-label-width);column-gap:var(--cb-space-4, 1rem)}.cb-df__field--right>.cb-df__label{order:2}.cb-df__field--left>.cb-df__label,.cb-df__field--right>.cb-df__label{padding-top:.6rem;line-height:1.3}.cb-df__field--end>.cb-df__label{text-align:end}.cb-df__field--left>.cb-df__label--empty,.cb-df__field--right>.cb-df__label--empty,.cb-df__actions--left>.cb-df__label--empty{display:block}.cb-df__field--left.cb-df__field--inline .cb-df__control,.cb-df__field--right.cb-df__field--inline .cb-df__control{padding-top:.5rem}.cb-df__field--floating{position:relative}.cb-df__field--floating>.cb-df__label{position:absolute;top:.65rem;left:.75rem;z-index:1;max-width:calc(100% - 3rem);overflow:hidden;padding:0 .25rem;color:var(--cb-color-text-muted);font-weight:400;text-overflow:ellipsis;white-space:nowrap;pointer-events:none;transform-origin:left top;transition:transform var(--cb-duration-fast, .12s) var(--cb-ease, ease),color var(--cb-duration-fast, .12s) var(--cb-ease, ease)}.cb-df__field--floating:focus-within>.cb-df__label,.cb-df__field--floating.cb-df__field--filled>.cb-df__label{background:var(--cb-color-bg);color:var(--cb-color-text);transform:translateY(-1.15rem) scale(.82)}.cb-df__field--floating:focus-within>.cb-df__label{color:var(--cb-color-primary-text, var(--cb-color-primary-700))}.cb-df__sr{position:absolute!important;width:1px;height:1px;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap}.cb-df__addons{display:block;min-width:0}.cb-df__addons--on{display:flex;align-items:stretch}.cb-df__input{flex:1;min-width:0}.cb-df__addon{display:inline-flex;flex:none;align-items:center;height:2.5rem;padding:0 .75rem;border:var(--cb-border-width, 1px) solid var(--cb-color-border-strong);background:var(--cb-color-surface-subtle);color:var(--cb-color-text-muted);font-size:var(--cb-text-sm, .875rem);white-space:nowrap}.cb-df__addon:first-child{margin-right:-1px;border-radius:var(--cb-radius-md) 0 0 var(--cb-radius-md)}.cb-df__addon:last-child{margin-left:-1px;border-radius:0 var(--cb-radius-md) var(--cb-radius-md) 0}.cb-df__addon+.cb-df__addon{border-left:0}.cb-df__actions{--cb-df-label-width: 10rem;display:grid}.cb-df__buttons{display:flex;flex-wrap:wrap;gap:.5rem}@container (max-width: 30rem){.cb-df__field--left,.cb-df__field--right,.cb-df__actions--left{grid-template-columns:minmax(0,1fr)}.cb-df__field--left>.cb-df__label,.cb-df__field--right>.cb-df__label{order:0;padding-top:0;text-align:start}.cb-df__field--left>.cb-df__label--empty,.cb-df__field--right>.cb-df__label--empty,.cb-df__actions--left>.cb-df__label--empty{display:none}.cb-df__field--left.cb-df__field--inline .cb-df__control,.cb-df__field--right.cb-df__field--inline .cb-df__control{padding-top:0}}\n"] }]
|
|
1571
|
+
}], ctorParameters: () => [], propDecorators: { templates: [{ type: i0.ContentChildren, args: [i0.forwardRef(() => CbFormFieldTemplate), { isSignal: true }] }], schema: [{ type: i0.Input, args: [{ isSignal: true, alias: "schema", required: true }] }], value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }, { type: i0.Output, args: ["valueChange"] }], layout: [{ type: i0.Input, args: [{ isSignal: true, alias: "layout", required: false }] }], labelPosition: [{ type: i0.Input, args: [{ isSignal: true, alias: "labelPosition", required: false }] }], columns: [{ type: i0.Input, args: [{ isSignal: true, alias: "columns", required: false }] }], labelWidth: [{ type: i0.Input, args: [{ isSignal: true, alias: "labelWidth", required: false }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], loaders: [{ type: i0.Input, args: [{ isSignal: true, alias: "loaders", required: false }] }], translate: [{ type: i0.Input, args: [{ isSignal: true, alias: "translate", required: false }] }], actions: [{ type: i0.Input, args: [{ isSignal: true, alias: "actions", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], loading: [{ type: i0.Input, args: [{ isSignal: true, alias: "loading", required: false }] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaLabel", required: false }] }], formSubmit: [{ type: i0.Output, args: ["formSubmit"] }], formInvalid: [{ type: i0.Output, args: ["formInvalid"] }], formReset: [{ type: i0.Output, args: ["formReset"] }], stepChange: [{ type: i0.Output, args: ["stepChange"] }] } });
|
|
1572
|
+
|
|
1573
|
+
/*
|
|
1574
|
+
* Public API Surface de @caribeng/ui/dynamic-form
|
|
1575
|
+
*/
|
|
1576
|
+
|
|
1577
|
+
/**
|
|
1578
|
+
* Generated bundle index. Do not edit.
|
|
1579
|
+
*/
|
|
1580
|
+
|
|
1581
|
+
export { CbDynamicForm, CbFormFieldTemplate, evaluateFormula };
|