@cloudfrogger/goodui 0.0.60 → 0.0.63
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 +10 -0
- package/ai/README.md +47 -0
- package/ai/case-studies/index.md +10 -0
- package/ai/case-studies/vpshoster.md +18 -0
- package/ai/case-studies/webmailer.md +21 -0
- package/ai/catalog/README.md +7 -0
- package/ai/catalog/component.schema.json +289 -0
- package/ai/catalog/components/div-goodDetailRow.json +33 -0
- package/ai/catalog/components/form-goodForm.json +84 -0
- package/ai/catalog/components/good-action-bar.json +83 -0
- package/ai/catalog/components/good-action-group.json +143 -0
- package/ai/catalog/components/good-action-menu.json +121 -0
- package/ai/catalog/components/good-alert.json +184 -0
- package/ai/catalog/components/good-app-layout.json +247 -0
- package/ai/catalog/components/good-assistant-body.json +43 -0
- package/ai/catalog/components/good-assistant-footer.json +43 -0
- package/ai/catalog/components/good-assistant-header.json +43 -0
- package/ai/catalog/components/good-assistant-main.json +61 -0
- package/ai/catalog/components/good-assistant-mobile.json +43 -0
- package/ai/catalog/components/good-assistant-panel.json +131 -0
- package/ai/catalog/components/good-avatar-menu-item.json +82 -0
- package/ai/catalog/components/good-avatar-menu.json +83 -0
- package/ai/catalog/components/good-badge.json +180 -0
- package/ai/catalog/components/good-bar-chart.json +118 -0
- package/ai/catalog/components/good-brand-icon.json +71 -0
- package/ai/catalog/components/good-breadcrumbs.json +102 -0
- package/ai/catalog/components/good-button.json +192 -0
- package/ai/catalog/components/good-calendar.json +430 -0
- package/ai/catalog/components/good-card-footer.json +63 -0
- package/ai/catalog/components/good-card-header.json +100 -0
- package/ai/catalog/components/good-card.json +57 -0
- package/ai/catalog/components/good-chart-axis.json +168 -0
- package/ai/catalog/components/good-chart-bar.json +89 -0
- package/ai/catalog/components/good-chart-histogram.json +78 -0
- package/ai/catalog/components/good-chart-line.json +89 -0
- package/ai/catalog/components/good-chart-scatter.json +87 -0
- package/ai/catalog/components/good-checkbox.json +171 -0
- package/ai/catalog/components/good-citation.json +62 -0
- package/ai/catalog/components/good-code-block.json +116 -0
- package/ai/catalog/components/good-color-controls.json +58 -0
- package/ai/catalog/components/good-color-picker.json +141 -0
- package/ai/catalog/components/good-column.json +53 -0
- package/ai/catalog/components/good-columns.json +77 -0
- package/ai/catalog/components/good-date-input.json +386 -0
- package/ai/catalog/components/good-detail-list.json +43 -0
- package/ai/catalog/components/good-dropdown.json +259 -0
- package/ai/catalog/components/good-error-page.json +133 -0
- package/ai/catalog/components/good-error-text.json +43 -0
- package/ai/catalog/components/good-expandable.json +159 -0
- package/ai/catalog/components/good-eyebrow.json +61 -0
- package/ai/catalog/components/good-field-label.json +62 -0
- package/ai/catalog/components/good-form-field.json +67 -0
- package/ai/catalog/components/good-form-row.json +70 -0
- package/ai/catalog/components/good-group.json +150 -0
- package/ai/catalog/components/good-heading-group.json +45 -0
- package/ai/catalog/components/good-heading.json +69 -0
- package/ai/catalog/components/good-hint.json +43 -0
- package/ai/catalog/components/good-histogram.json +103 -0
- package/ai/catalog/components/good-icon.json +97 -0
- package/ai/catalog/components/good-image-input.json +190 -0
- package/ai/catalog/components/good-image-preview.json +97 -0
- package/ai/catalog/components/good-inline-image.json +131 -0
- package/ai/catalog/components/good-input-phone.json +226 -0
- package/ai/catalog/components/good-input.json +350 -0
- package/ai/catalog/components/good-line-chart.json +94 -0
- package/ai/catalog/components/good-link.json +147 -0
- package/ai/catalog/components/good-listbox.json +248 -0
- package/ai/catalog/components/good-main-menu.json +140 -0
- package/ai/catalog/components/good-main-view.json +179 -0
- package/ai/catalog/components/good-map-color-scale.json +163 -0
- package/ai/catalog/components/good-map-overlay.json +136 -0
- package/ai/catalog/components/good-modal-footer.json +63 -0
- package/ai/catalog/components/good-modal-header.json +73 -0
- package/ai/catalog/components/good-modal.json +131 -0
- package/ai/catalog/components/good-month-calendar.json +170 -0
- package/ai/catalog/components/good-notification-host.json +46 -0
- package/ai/catalog/components/good-notifications.json +72 -0
- package/ai/catalog/components/good-number-input.json +180 -0
- package/ai/catalog/components/good-paragraph.json +47 -0
- package/ai/catalog/components/good-pdf-preview.json +153 -0
- package/ai/catalog/components/good-pin-input.json +211 -0
- package/ai/catalog/components/good-progress.json +158 -0
- package/ai/catalog/components/good-prose.json +43 -0
- package/ai/catalog/components/good-radio-group.json +181 -0
- package/ai/catalog/components/good-range-slider.json +285 -0
- package/ai/catalog/components/good-rating.json +160 -0
- package/ai/catalog/components/good-resizable-pane.json +61 -0
- package/ai/catalog/components/good-resizable.json +185 -0
- package/ai/catalog/components/good-rich-text-editor.json +164 -0
- package/ai/catalog/components/good-scatter-chart.json +94 -0
- package/ai/catalog/components/good-search.json +60 -0
- package/ai/catalog/components/good-section.json +43 -0
- package/ai/catalog/components/good-select-country.json +205 -0
- package/ai/catalog/components/good-select-font.json +111 -0
- package/ai/catalog/components/good-select.json +217 -0
- package/ai/catalog/components/good-separator.json +59 -0
- package/ai/catalog/components/good-settings.json +60 -0
- package/ai/catalog/components/good-sidebar-container.json +112 -0
- package/ai/catalog/components/good-sidebar-item.json +210 -0
- package/ai/catalog/components/good-sidebar-menu-container.json +80 -0
- package/ai/catalog/components/good-sidebar-submenu-group.json +98 -0
- package/ai/catalog/components/good-sidebar-submenu-item.json +113 -0
- package/ai/catalog/components/good-signature-pad.json +115 -0
- package/ai/catalog/components/good-sparkline.json +188 -0
- package/ai/catalog/components/good-status-icon.json +425 -0
- package/ai/catalog/components/good-subheading.json +67 -0
- package/ai/catalog/components/good-subnav.json +132 -0
- package/ai/catalog/components/good-summary.json +43 -0
- package/ai/catalog/components/good-switch.json +167 -0
- package/ai/catalog/components/good-tab.json +129 -0
- package/ai/catalog/components/good-table.json +294 -0
- package/ai/catalog/components/good-tabs.json +90 -0
- package/ai/catalog/components/good-textarea.json +194 -0
- package/ai/catalog/components/good-theme-toggle.json +57 -0
- package/ai/catalog/components/good-timeline-section.json +105 -0
- package/ai/catalog/components/good-timeline-step.json +248 -0
- package/ai/catalog/components/good-timeline.json +302 -0
- package/ai/catalog/components/good-topbar-dropdown-item.json +115 -0
- package/ai/catalog/components/good-topbar-dropdown-menu.json +85 -0
- package/ai/catalog/components/good-topbar-menu-container.json +96 -0
- package/ai/catalog/components/good-topbar-menu-item.json +99 -0
- package/ai/catalog/components/good-topbar-submenu.json +77 -0
- package/ai/catalog/components/good-topbar.json +259 -0
- package/ai/catalog/components/good-world-map.json +145 -0
- package/ai/catalog/components/goodCardActions.json +33 -0
- package/ai/catalog/components/goodDropdownFooter.json +33 -0
- package/ai/catalog/components/goodDropdownHeader.json +33 -0
- package/ai/catalog/components/goodExpandableHeader.json +33 -0
- package/ai/catalog/components/ng-template-goodListboxItem.json +33 -0
- package/ai/catalog/components/ng-template-goodTableCell.json +43 -0
- package/ai/catalog/index.json +1484 -0
- package/ai/catalog/index.schema.json +13 -0
- package/ai/examples/angular.json +26 -0
- package/ai/examples/edit-form.html +13 -0
- package/ai/examples/edit-form.ts +18 -0
- package/ai/examples/index.html +1 -0
- package/ai/examples/login.html +11 -0
- package/ai/examples/login.ts +14 -0
- package/ai/examples/main.ts +25 -0
- package/ai/examples/settings.html +10 -0
- package/ai/examples/settings.ts +13 -0
- package/ai/examples/table-view.html +3 -0
- package/ai/examples/table-view.ts +21 -0
- package/ai/examples/tsconfig.json +27 -0
- package/ai/guides/common-mistakes.md +9 -0
- package/ai/guides/component-discovery.md +19 -0
- package/ai/guides/design-tokens.md +10 -0
- package/ai/guides/layout.md +19 -0
- package/ai/guides/page-patterns.md +39 -0
- package/ai/install.mjs +25 -0
- package/ai/manifest.json +6 -0
- package/ai/skill/goodui/SKILL.md +27 -0
- package/angular/projects/goodui/package.json +28 -0
- package/angular/projects/goodui/src/action-bar.css +20 -0
- package/angular/projects/goodui/src/assistant-panel.css +38 -0
- package/angular/projects/goodui/src/calendar.css +161 -0
- package/angular/projects/goodui/src/chart.css +35 -0
- package/angular/projects/goodui/src/color-picker.css +40 -0
- package/angular/projects/goodui/src/error-page.css +24 -0
- package/angular/projects/goodui/src/lib/action-bar.ts +161 -0
- package/angular/projects/goodui/src/lib/action-group.ts +31 -0
- package/angular/projects/goodui/src/lib/action-menu.ts +81 -0
- package/angular/projects/goodui/src/lib/actions.ts +320 -0
- package/angular/projects/goodui/src/lib/alert.ts +60 -0
- package/angular/projects/goodui/src/lib/app-layout.ts +84 -0
- package/angular/projects/goodui/src/lib/assistant-panel.ts +133 -0
- package/angular/projects/goodui/src/lib/badge.ts +47 -0
- package/angular/projects/goodui/src/lib/bar-chart.html +80 -0
- package/angular/projects/goodui/src/lib/bar-chart.ts +233 -0
- package/angular/projects/goodui/src/lib/breadcrumbs.ts +81 -0
- package/angular/projects/goodui/src/lib/button.ts +38 -0
- package/angular/projects/goodui/src/lib/calendar-layout.ts +68 -0
- package/angular/projects/goodui/src/lib/calendar-service.ts +144 -0
- package/angular/projects/goodui/src/lib/calendar-working-hours.ts +65 -0
- package/angular/projects/goodui/src/lib/calendar.html +200 -0
- package/angular/projects/goodui/src/lib/calendar.ts +471 -0
- package/angular/projects/goodui/src/lib/card.ts +64 -0
- package/angular/projects/goodui/src/lib/chart-colors.ts +22 -0
- package/angular/projects/goodui/src/lib/chart-data.ts +269 -0
- package/angular/projects/goodui/src/lib/checkbox.ts +87 -0
- package/angular/projects/goodui/src/lib/code-block.ts +147 -0
- package/angular/projects/goodui/src/lib/color-controls.ts +107 -0
- package/angular/projects/goodui/src/lib/color-picker.ts +142 -0
- package/angular/projects/goodui/src/lib/color-utils.ts +69 -0
- package/angular/projects/goodui/src/lib/country-data.ts +16 -0
- package/angular/projects/goodui/src/lib/date-input.ts +542 -0
- package/angular/projects/goodui/src/lib/dropdown.ts +309 -0
- package/angular/projects/goodui/src/lib/error-page.ts +46 -0
- package/angular/projects/goodui/src/lib/expandable.ts +64 -0
- package/angular/projects/goodui/src/lib/form.ts +12 -0
- package/angular/projects/goodui/src/lib/goodui-config.ts +16 -0
- package/angular/projects/goodui/src/lib/group.ts +45 -0
- package/angular/projects/goodui/src/lib/histogram.html +52 -0
- package/angular/projects/goodui/src/lib/histogram.ts +146 -0
- package/angular/projects/goodui/src/lib/icon.ts +44 -0
- package/angular/projects/goodui/src/lib/image-input.ts +154 -0
- package/angular/projects/goodui/src/lib/image-preview.ts +26 -0
- package/angular/projects/goodui/src/lib/input-phone.ts +305 -0
- package/angular/projects/goodui/src/lib/input.ts +143 -0
- package/angular/projects/goodui/src/lib/line-chart.html +53 -0
- package/angular/projects/goodui/src/lib/line-chart.ts +193 -0
- package/angular/projects/goodui/src/lib/link.ts +46 -0
- package/angular/projects/goodui/src/lib/listbox.ts +254 -0
- package/angular/projects/goodui/src/lib/main-view.ts +39 -0
- package/angular/projects/goodui/src/lib/marker-colors.ts +7 -0
- package/angular/projects/goodui/src/lib/modal.ts +199 -0
- package/angular/projects/goodui/src/lib/models.ts +115 -0
- package/angular/projects/goodui/src/lib/month-calendar.ts +289 -0
- package/angular/projects/goodui/src/lib/notification-center.ts +170 -0
- package/angular/projects/goodui/src/lib/notification-host.ts +86 -0
- package/angular/projects/goodui/src/lib/number-input.ts +180 -0
- package/angular/projects/goodui/src/lib/pdf-preview.ts +242 -0
- package/angular/projects/goodui/src/lib/pdf-worker.generated.ts +2 -0
- package/angular/projects/goodui/src/lib/pin-input.ts +193 -0
- package/angular/projects/goodui/src/lib/progress.ts +93 -0
- package/angular/projects/goodui/src/lib/provide-goodui.ts +15 -0
- package/angular/projects/goodui/src/lib/radio-group.ts +94 -0
- package/angular/projects/goodui/src/lib/range-slider.ts +313 -0
- package/angular/projects/goodui/src/lib/rating.ts +90 -0
- package/angular/projects/goodui/src/lib/required-control.ts +4 -0
- package/angular/projects/goodui/src/lib/resizable.ts +168 -0
- package/angular/projects/goodui/src/lib/rich-text-command.ts +111 -0
- package/angular/projects/goodui/src/lib/rich-text-editor.html +193 -0
- package/angular/projects/goodui/src/lib/rich-text-editor.ts +864 -0
- package/angular/projects/goodui/src/lib/rich-text-sanitize.ts +99 -0
- package/angular/projects/goodui/src/lib/scatter-chart.html +48 -0
- package/angular/projects/goodui/src/lib/scatter-chart.ts +150 -0
- package/angular/projects/goodui/src/lib/select-country.ts +104 -0
- package/angular/projects/goodui/src/lib/select-font.ts +189 -0
- package/angular/projects/goodui/src/lib/select.ts +336 -0
- package/angular/projects/goodui/src/lib/sidebar.ts +232 -0
- package/angular/projects/goodui/src/lib/signature-pad.ts +238 -0
- package/angular/projects/goodui/src/lib/sparkline.html +15 -0
- package/angular/projects/goodui/src/lib/sparkline.ts +106 -0
- package/angular/projects/goodui/src/lib/status-icon.ts +79 -0
- package/angular/projects/goodui/src/lib/subnav.ts +156 -0
- package/angular/projects/goodui/src/lib/switch.ts +54 -0
- package/angular/projects/goodui/src/lib/table.ts +538 -0
- package/angular/projects/goodui/src/lib/tabs.ts +251 -0
- package/angular/projects/goodui/src/lib/textarea.ts +83 -0
- package/angular/projects/goodui/src/lib/theme.ts +49 -0
- package/angular/projects/goodui/src/lib/timeline.ts +252 -0
- package/angular/projects/goodui/src/lib/topbar.ts +403 -0
- package/angular/projects/goodui/src/lib/typography.ts +250 -0
- package/angular/projects/goodui/src/lib/world-map-data.ts +3 -0
- package/angular/projects/goodui/src/lib/world-map.html +73 -0
- package/angular/projects/goodui/src/lib/world-map.ts +391 -0
- package/angular/projects/goodui/src/month-calendar.css +47 -0
- package/angular/projects/goodui/src/pdf-preview.css +25 -0
- package/angular/projects/goodui/src/progress.css +38 -0
- package/angular/projects/goodui/src/public-api.ts +74 -0
- package/angular/projects/goodui/src/range-slider.css +54 -0
- package/angular/projects/goodui/src/resizable.css +32 -0
- package/angular/projects/goodui/src/rich-text-editor.css +33 -0
- package/angular/projects/goodui/src/select-font.css +16 -0
- package/angular/projects/goodui/src/signature-pad.css +14 -0
- package/angular/projects/goodui/src/styles.css +1105 -0
- package/angular/projects/goodui/src/timeline.css +138 -0
- package/angular/projects/goodui/src/tokens.generated.css +754 -0
- package/design/component-map.json +2233 -0
- package/design-tokens/penpot.tokens.json +3339 -0
- package/design.md +452 -0
- package/fesm2022/cloudfrogger-goodui.mjs +32 -18
- package/fesm2022/cloudfrogger-goodui.mjs.map +1 -1
- package/guides/README.md +17 -0
- package/guides/components/action-bar.md +43 -0
- package/guides/components/action-group.md +43 -0
- package/guides/components/action-menu.md +22 -0
- package/guides/components/alert.md +28 -0
- package/guides/components/assistant-panel.md +50 -0
- package/guides/components/avatar-menu.md +34 -0
- package/guides/components/badge.md +39 -0
- package/guides/components/bar-chart.md +40 -0
- package/guides/components/breadcrumbs.md +37 -0
- package/guides/components/button.md +40 -0
- package/guides/components/calendar.md +166 -0
- package/guides/components/card.md +62 -0
- package/guides/components/chart-axis.md +5 -0
- package/guides/components/chart-bar.md +5 -0
- package/guides/components/chart-data.md +58 -0
- package/guides/components/chart-histogram.md +16 -0
- package/guides/components/chart-line.md +5 -0
- package/guides/components/chart-scatter.md +14 -0
- package/guides/components/checkbox.md +36 -0
- package/guides/components/code-block.md +35 -0
- package/guides/components/color-controls.md +22 -0
- package/guides/components/column.md +5 -0
- package/guides/components/columns.md +13 -0
- package/guides/components/date-input.md +62 -0
- package/guides/components/detail-list.md +25 -0
- package/guides/components/dropdown.md +48 -0
- package/guides/components/error-page.md +31 -0
- package/guides/components/expandable.md +36 -0
- package/guides/components/form.md +49 -0
- package/guides/components/group.md +41 -0
- package/guides/components/histogram.md +45 -0
- package/guides/components/icon.md +13 -0
- package/guides/components/image-input.md +34 -0
- package/guides/components/input-phone.md +45 -0
- package/guides/components/input.md +59 -0
- package/guides/components/line-chart.md +37 -0
- package/guides/components/link.md +31 -0
- package/guides/components/listbox.md +109 -0
- package/guides/components/main-menu.md +23 -0
- package/guides/components/main-view.md +21 -0
- package/guides/components/modal.md +58 -0
- package/guides/components/month-calendar.md +88 -0
- package/guides/components/notifications.md +76 -0
- package/guides/components/number-input.md +21 -0
- package/guides/components/pdf-preview.md +38 -0
- package/guides/components/pin-input.md +37 -0
- package/guides/components/progress.md +41 -0
- package/guides/components/radio-group.md +41 -0
- package/guides/components/range-slider.md +42 -0
- package/guides/components/rating.md +39 -0
- package/guides/components/resizable-pane.md +3 -0
- package/guides/components/resizable.md +75 -0
- package/guides/components/rich-text-editor.md +113 -0
- package/guides/components/scatter-chart.md +43 -0
- package/guides/components/search.md +51 -0
- package/guides/components/select-font.md +16 -0
- package/guides/components/select.md +65 -0
- package/guides/components/settings.md +11 -0
- package/guides/components/sidebar.md +47 -0
- package/guides/components/signature-pad.md +45 -0
- package/guides/components/sparkline.md +31 -0
- package/guides/components/status-icon.md +32 -0
- package/guides/components/submenus.md +30 -0
- package/guides/components/subnav.md +54 -0
- package/guides/components/switch.md +48 -0
- package/guides/components/table.md +256 -0
- package/guides/components/tabs.md +46 -0
- package/guides/components/textarea.md +44 -0
- package/guides/components/theme-toggle.md +33 -0
- package/guides/components/timeline-section.md +7 -0
- package/guides/components/timeline-step.md +12 -0
- package/guides/components/timeline.md +179 -0
- package/guides/components/topbar.md +89 -0
- package/guides/components/typography.md +155 -0
- package/guides/components/world-map.md +72 -0
- package/guides/contributing/design-to-code.md +265 -0
- package/guides/deployment/drone.md +77 -0
- package/guides/examples/user-registration.md +11 -0
- package/guides/foundations/naming.md +7 -0
- package/guides/foundations/tokens.md +203 -0
- package/guides/intro.md +80 -0
- package/guides/layout/app-layout.md +81 -0
- package/guides/layout/layout-rules.md +16 -0
- package/homepage/src/app/examples/calendar-workspace/calendar-workspace-page.html +22 -0
- package/homepage/src/app/examples/calendar-workspace/calendar-workspace-page.ts +111 -0
- package/homepage/src/app/examples/calendar-workspace/source-code.generated.ts +3 -0
- package/homepage/src/app/examples/case-studies/cloudhoster/billing-page.html +166 -0
- package/homepage/src/app/examples/case-studies/cloudhoster/billing-page.ts +134 -0
- package/homepage/src/app/examples/case-studies/cloudhoster/cloudhoster-store.ts +92 -0
- package/homepage/src/app/examples/case-studies/cloudhoster/create-database-page.html +93 -0
- package/homepage/src/app/examples/case-studies/cloudhoster/create-database-page.ts +115 -0
- package/homepage/src/app/examples/case-studies/cloudhoster/database-detail-page.html +202 -0
- package/homepage/src/app/examples/case-studies/cloudhoster/database-detail-page.ts +143 -0
- package/homepage/src/app/examples/case-studies/cloudhoster/databases-page.html +70 -0
- package/homepage/src/app/examples/case-studies/cloudhoster/databases-page.ts +44 -0
- package/homepage/src/app/examples/case-studies/cloudhoster/home-page.html +70 -0
- package/homepage/src/app/examples/case-studies/cloudhoster/home-page.ts +32 -0
- package/homepage/src/app/examples/case-studies/cloudhoster/source-code.generated.ts +12 -0
- package/homepage/src/app/examples/case-studies/vpshoster/create-server-page.html +208 -0
- package/homepage/src/app/examples/case-studies/vpshoster/create-server-page.ts +214 -0
- package/homepage/src/app/examples/case-studies/vpshoster/overview-page.html +35 -0
- package/homepage/src/app/examples/case-studies/vpshoster/overview-page.ts +17 -0
- package/homepage/src/app/examples/case-studies/vpshoster/servers-page.html +111 -0
- package/homepage/src/app/examples/case-studies/vpshoster/servers-page.ts +206 -0
- package/homepage/src/app/examples/case-studies/vpshoster/source-code.generated.ts +6 -0
- package/homepage/src/app/examples/case-studies/vpshoster/vps-store.ts +92 -0
- package/homepage/src/app/examples/case-studies/webmailer/webmailer-page.html +35 -0
- package/homepage/src/app/examples/case-studies/webmailer/webmailer-page.ts +17 -0
- package/homepage/src/app/examples/error-pages/error-pages-example-page.html +27 -0
- package/homepage/src/app/examples/error-pages/error-pages-example-page.ts +34 -0
- package/homepage/src/app/examples/error-pages/not-found-page.html +8 -0
- package/homepage/src/app/examples/error-pages/not-found-page.ts +19 -0
- package/homepage/src/app/examples/error-pages/server-error-page.html +8 -0
- package/homepage/src/app/examples/error-pages/server-error-page.ts +20 -0
- package/homepage/src/app/examples/error-pages/source-code.generated.ts +7 -0
- package/homepage/src/app/examples/mail-compose/mail-compose-page.html +25 -0
- package/homepage/src/app/examples/mail-compose/mail-compose-page.ts +28 -0
- package/homepage/src/app/examples/mail-workspace/mail-workspace-page.html +59 -0
- package/homepage/src/app/examples/mail-workspace/mail-workspace-page.ts +128 -0
- package/homepage/src/app/examples/mail-workspace/source-code.generated.ts +3 -0
- package/homepage/src/app/examples/notifications/notifications-page.html +51 -0
- package/homepage/src/app/examples/notifications/notifications-page.ts +133 -0
- package/homepage/src/app/examples/notifications/source-code.generated.ts +3 -0
- package/homepage/src/app/examples/pdf-reader/pdf-reader-page.html +27 -0
- package/homepage/src/app/examples/pdf-reader/pdf-reader-page.ts +39 -0
- package/homepage/src/app/examples/pdf-reader/source-code.generated.ts +3 -0
- package/homepage/src/app/examples/user-registration/source-code.generated.ts +5 -0
- package/homepage/src/app/examples/user-registration/user-registration-example-page.html +11 -0
- package/homepage/src/app/examples/user-registration/user-registration-example-page.ts +21 -0
- package/homepage/src/app/examples/user-registration/user-registration-form.html +116 -0
- package/homepage/src/app/examples/user-registration/user-registration-form.ts +93 -0
- package/homepage/src/app/examples/user-registration/user-registration-page.html +11 -0
- package/homepage/src/app/examples/user-registration/user-registration-page.ts +23 -0
- package/package.json +2 -2
- package/types/cloudfrogger-goodui.d.ts +2 -2
|
@@ -0,0 +1,864 @@
|
|
|
1
|
+
import { DOCUMENT } from '@angular/common';
|
|
2
|
+
import { ChangeDetectionStrategy, Component, ElementRef, HostListener, computed, effect, forwardRef, inject, input, model, output, signal, viewChild } from '@angular/core';
|
|
3
|
+
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
|
|
4
|
+
import {
|
|
5
|
+
LucideBold, LucideItalic, LucideUnderline, LucideUndo2, LucideRedo2, LucideLink, LucideImage,
|
|
6
|
+
LucideTable, LucideEllipsis, LucideRemoveFormatting, LucidePanelRight, LucideList, LucideListOrdered,
|
|
7
|
+
LucideTextAlignStart, LucideTextAlignCenter, LucideTextAlignEnd, LucideTextAlignJustify,
|
|
8
|
+
LucideDynamicIcon, LucideTableProperties, LucideListChecks, LucideHeading1, LucideRows3, LucideColumns3,
|
|
9
|
+
LucideArrowUpToLine, LucideArrowDownToLine, LucideArrowLeftToLine, LucideArrowRightToLine,
|
|
10
|
+
LucideTrash2, LucideGripVertical, LucideGripHorizontal,
|
|
11
|
+
} from '@lucide/angular';
|
|
12
|
+
import { GoodButtonComponent } from './button';
|
|
13
|
+
import { GoodColorPickerComponent } from './color-picker';
|
|
14
|
+
import { GoodDropdownComponent, type GoodDropdownItem } from './dropdown';
|
|
15
|
+
import { GoodInputComponent } from './input';
|
|
16
|
+
import { GoodModalComponent, GoodModalFooterComponent, GoodModalHeaderComponent } from './modal';
|
|
17
|
+
import { GoodNumberInputComponent } from './number-input';
|
|
18
|
+
import { GoodSelectFontComponent, goodFontFamilyCss } from './select-font';
|
|
19
|
+
import { GoodRichTextHistory, GoodRichTextMutationCommand, GoodRichTextSnapshotCommand,
|
|
20
|
+
captureRichTextSelection, restoreRichTextSelection, type GoodRichTextCommandContext,
|
|
21
|
+
type GoodRichTextSnapshot } from './rich-text-command';
|
|
22
|
+
import { safeRichTextUrl, sanitizeRichText } from './rich-text-sanitize';
|
|
23
|
+
|
|
24
|
+
export type GoodRichTextAlignment = 'left' | 'center' | 'right' | 'justify';
|
|
25
|
+
/** Omit `features` for every tool; pass an array to allow only its entries. */
|
|
26
|
+
export type GoodRichTextFeature =
|
|
27
|
+
| 'undo' | 'redo'
|
|
28
|
+
| 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6'
|
|
29
|
+
| 'bold' | 'italic' | 'underline' | 'strikethrough' | 'superscript' | 'subscript' | 'code'
|
|
30
|
+
| 'paragraph' | 'blockquote' | 'div' | 'pre'
|
|
31
|
+
| 'alignment' | 'smallcaps' | 'subtitle' | 'highlight'
|
|
32
|
+
| 'fontfamily' | 'fontsize' | 'textcolor' | 'background'
|
|
33
|
+
| 'link' | 'image' | 'bullets' | 'numbering' | 'table' | 'clearformatting';
|
|
34
|
+
|
|
35
|
+
const formatFeatures: Readonly<Record<string, GoodRichTextFeature>> = {
|
|
36
|
+
'inline-bold': 'bold', 'inline-italic': 'italic', 'inline-underline': 'underline',
|
|
37
|
+
'inline-strike': 'strikethrough', 'inline-super': 'superscript', 'inline-sub': 'subscript',
|
|
38
|
+
'inline-code': 'code', 'block-p': 'paragraph', 'block-quote': 'blockquote',
|
|
39
|
+
'block-div': 'div', 'block-pre': 'pre', 'align-left': 'alignment',
|
|
40
|
+
'align-center': 'alignment', 'align-right': 'alignment', 'align-justify': 'alignment',
|
|
41
|
+
'style-small-caps': 'smallcaps', 'style-subtitle': 'subtitle', 'style-highlight': 'highlight',
|
|
42
|
+
};
|
|
43
|
+
export type GoodRichTextTableAction = 'properties' | 'delete-table' | 'row-before' | 'row-after' | 'delete-row' |
|
|
44
|
+
'column-before' | 'column-after' | 'delete-column' | 'header-cell' | 'body-cell';
|
|
45
|
+
|
|
46
|
+
let nextRichTextTableMenuId = 0;
|
|
47
|
+
type TableResizeAxis = 'column' | 'row';
|
|
48
|
+
interface TableCellBox { left: number; top: number; width: number; height: number; }
|
|
49
|
+
interface TableResizeState {
|
|
50
|
+
axis: TableResizeAxis;
|
|
51
|
+
pointerId: number;
|
|
52
|
+
table: HTMLTableElement;
|
|
53
|
+
row: HTMLTableRowElement;
|
|
54
|
+
columnIndex: number;
|
|
55
|
+
columnWidths: number[];
|
|
56
|
+
start: number;
|
|
57
|
+
size: number;
|
|
58
|
+
before: GoodRichTextSnapshot;
|
|
59
|
+
changed: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@Component({
|
|
63
|
+
selector: 'good-rich-text-editor', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush,
|
|
64
|
+
imports: [GoodButtonComponent, GoodColorPickerComponent, GoodDropdownComponent, GoodInputComponent, GoodSelectFontComponent, LucideDynamicIcon,
|
|
65
|
+
GoodModalComponent, GoodModalHeaderComponent, GoodModalFooterComponent, GoodNumberInputComponent],
|
|
66
|
+
host: { class: 'good-rich-text-editor', '[attr.data-disabled]': 'isDisabled()', '[attr.data-fill-height]': 'fillHeight()' },
|
|
67
|
+
providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => GoodRichTextEditorComponent), multi: true }],
|
|
68
|
+
templateUrl: './rich-text-editor.html',
|
|
69
|
+
})
|
|
70
|
+
export class GoodRichTextEditorComponent implements ControlValueAccessor, GoodRichTextCommandContext {
|
|
71
|
+
private readonly document = inject(DOCUMENT);
|
|
72
|
+
private readonly editor = viewChild<ElementRef<HTMLElement>>('editor');
|
|
73
|
+
private readonly tableActionButton = viewChild('tableActionTrigger', { read: ElementRef<HTMLElement> });
|
|
74
|
+
private readonly history = new GoodRichTextHistory();
|
|
75
|
+
private savedRange: Range | null = null;
|
|
76
|
+
private pendingInput: GoodRichTextSnapshot | null = null;
|
|
77
|
+
private lastPublished = '';
|
|
78
|
+
private applying = false;
|
|
79
|
+
private activeCell: HTMLTableCellElement | null = null;
|
|
80
|
+
private activeTable: HTMLTableElement | null = null;
|
|
81
|
+
private selectedCells = new Set<HTMLTableCellElement>();
|
|
82
|
+
private selectionAnchor: HTMLTableCellElement | null = null;
|
|
83
|
+
private tableResize: TableResizeState | null = null;
|
|
84
|
+
private onChange: (value: string) => void = () => {};
|
|
85
|
+
private onTouched: () => void = () => {};
|
|
86
|
+
private readonly formDisabled = signal(false);
|
|
87
|
+
|
|
88
|
+
readonly label = input('Rich text editor');
|
|
89
|
+
readonly tableMenuId = `good-rich-editor-table-menu-${++nextRichTextTableMenuId}`;
|
|
90
|
+
readonly value = model('<p><br></p>');
|
|
91
|
+
readonly disabled = input(false);
|
|
92
|
+
readonly readonly = input(false);
|
|
93
|
+
readonly minHeight = input(320);
|
|
94
|
+
readonly fillHeight = input(false);
|
|
95
|
+
readonly features = input<readonly GoodRichTextFeature[] | null>(null);
|
|
96
|
+
readonly showAssistant = input(false);
|
|
97
|
+
readonly assistantOpen = model(false);
|
|
98
|
+
readonly assistantTitle = input('Assistant');
|
|
99
|
+
readonly commandExecuted = output<string>();
|
|
100
|
+
readonly isDisabled = computed(() => this.disabled() || this.formDisabled());
|
|
101
|
+
hasFeature(feature: GoodRichTextFeature): boolean {
|
|
102
|
+
const features = this.features();
|
|
103
|
+
return features === null || features.includes(feature);
|
|
104
|
+
}
|
|
105
|
+
readonly hasToolbar = computed(() => this.features() === null || this.features()!.length > 0 || this.showAssistant());
|
|
106
|
+
readonly canUndo = signal(false);
|
|
107
|
+
readonly canRedo = signal(false);
|
|
108
|
+
readonly fontSize = signal(14);
|
|
109
|
+
readonly fontFamily = signal('sans-serif');
|
|
110
|
+
readonly textColor = signal('#09090B');
|
|
111
|
+
readonly backgroundColor = signal('#FFFF00');
|
|
112
|
+
readonly linkOpen = signal(false);
|
|
113
|
+
readonly linkUrl = signal('');
|
|
114
|
+
readonly linkText = signal('');
|
|
115
|
+
readonly linkTarget = signal<'current' | 'new'>('current');
|
|
116
|
+
readonly linkError = signal('');
|
|
117
|
+
readonly imageOpen = signal(false);
|
|
118
|
+
readonly imageFile = signal<File | null>(null);
|
|
119
|
+
readonly imageAlt = signal('');
|
|
120
|
+
readonly imageError = signal('');
|
|
121
|
+
readonly tableGridOpen = signal(false);
|
|
122
|
+
readonly tableGridPosition = signal({ left: 0, top: 0 });
|
|
123
|
+
readonly gridRows = signal(1);
|
|
124
|
+
readonly gridColumns = signal(1);
|
|
125
|
+
readonly tableMenuOpen = signal(false);
|
|
126
|
+
readonly tableMenuPosition = signal({ left: 0, top: 0 });
|
|
127
|
+
readonly tableActionVisible = signal(false);
|
|
128
|
+
readonly tableActionPosition = signal({ left: 0, top: 0 });
|
|
129
|
+
readonly tableGripPosition = signal({ columnLeft: 0, columnTop: 0, rowLeft: 0, rowTop: 0 });
|
|
130
|
+
readonly columnGripVisible = signal(false);
|
|
131
|
+
readonly rowGripVisible = signal(false);
|
|
132
|
+
readonly selectedCellBoxes = signal<readonly TableCellBox[]>([]);
|
|
133
|
+
readonly selectedCellCount = signal(0);
|
|
134
|
+
readonly selectingCells = signal(false);
|
|
135
|
+
readonly tablePropertiesOpen = signal(false);
|
|
136
|
+
readonly tableWidth = signal(100);
|
|
137
|
+
readonly tablePadding = signal(8);
|
|
138
|
+
readonly tableCaption = signal('');
|
|
139
|
+
readonly tableRows = Array.from({ length: 8 }, (_, index) => index + 1);
|
|
140
|
+
readonly tableColumns = Array.from({ length: 10 }, (_, index) => index + 1);
|
|
141
|
+
|
|
142
|
+
readonly undoIcon = LucideUndo2;
|
|
143
|
+
readonly redoIcon = LucideRedo2;
|
|
144
|
+
readonly boldIcon = LucideBold;
|
|
145
|
+
readonly italicIcon = LucideItalic;
|
|
146
|
+
readonly underlineIcon = LucideUnderline;
|
|
147
|
+
readonly linkIcon = LucideLink;
|
|
148
|
+
readonly imageIcon = LucideImage;
|
|
149
|
+
readonly tableIcon = LucideTable;
|
|
150
|
+
readonly tableActionIcon = LucideEllipsis;
|
|
151
|
+
readonly tablePropertiesIcon = LucideTableProperties;
|
|
152
|
+
readonly selectCellsIcon = LucideListChecks;
|
|
153
|
+
readonly headerCellIcon = LucideHeading1;
|
|
154
|
+
readonly bodyCellIcon = LucideTable;
|
|
155
|
+
readonly rowBeforeIcon = LucideArrowUpToLine;
|
|
156
|
+
readonly rowAfterIcon = LucideArrowDownToLine;
|
|
157
|
+
readonly columnBeforeIcon = LucideArrowLeftToLine;
|
|
158
|
+
readonly columnAfterIcon = LucideArrowRightToLine;
|
|
159
|
+
readonly rowIcon = LucideRows3;
|
|
160
|
+
readonly columnIcon = LucideColumns3;
|
|
161
|
+
readonly deleteIcon = LucideTrash2;
|
|
162
|
+
readonly columnGripIcon = LucideGripVertical;
|
|
163
|
+
readonly rowGripIcon = LucideGripHorizontal;
|
|
164
|
+
readonly clearIcon = LucideRemoveFormatting;
|
|
165
|
+
readonly assistantIcon = LucidePanelRight;
|
|
166
|
+
readonly listIcon = LucideList;
|
|
167
|
+
readonly orderedListIcon = LucideListOrdered;
|
|
168
|
+
readonly alignIcon = LucideTextAlignStart;
|
|
169
|
+
|
|
170
|
+
private readonly allFormatItems: readonly GoodDropdownItem[] = [
|
|
171
|
+
{ id: 'headings', label: 'Headings', children: Array.from({ length: 6 }, (_, index) => ({
|
|
172
|
+
id: `heading-${index + 1}`, label: `Heading ${index + 1}`, action: () => this.block(`h${index + 1}`),
|
|
173
|
+
})) },
|
|
174
|
+
{ id: 'inline', label: 'Inline', children: [
|
|
175
|
+
{ id: 'inline-bold', label: 'Bold', action: () => this.native('bold', 'Bold') },
|
|
176
|
+
{ id: 'inline-italic', label: 'Italic', action: () => this.native('italic', 'Italic') },
|
|
177
|
+
{ id: 'inline-underline', label: 'Underline', action: () => this.native('underline', 'Underline') },
|
|
178
|
+
{ id: 'inline-strike', label: 'Strikethrough', action: () => this.native('strikeThrough', 'Strikethrough') },
|
|
179
|
+
{ id: 'inline-super', label: 'Superscript', action: () => this.native('superscript', 'Superscript') },
|
|
180
|
+
{ id: 'inline-sub', label: 'Subscript', action: () => this.native('subscript', 'Subscript') },
|
|
181
|
+
{ id: 'inline-code', label: 'Code', action: () => this.wrapInline('code', 'Code') },
|
|
182
|
+
] },
|
|
183
|
+
{ id: 'blocks', label: 'Blocks', children: [
|
|
184
|
+
{ id: 'block-p', label: 'Paragraph', action: () => this.block('p') },
|
|
185
|
+
{ id: 'block-quote', label: 'Blockquote', action: () => this.block('blockquote') },
|
|
186
|
+
{ id: 'block-div', label: 'Div', action: () => this.block('div') },
|
|
187
|
+
{ id: 'block-pre', label: 'Preformatted', action: () => this.block('pre') },
|
|
188
|
+
] },
|
|
189
|
+
{ id: 'align', label: 'Align', children: [
|
|
190
|
+
{ id: 'align-left', label: 'Left', action: () => this.align('left') },
|
|
191
|
+
{ id: 'align-center', label: 'Center', action: () => this.align('center') },
|
|
192
|
+
{ id: 'align-right', label: 'Right', action: () => this.align('right') },
|
|
193
|
+
{ id: 'align-justify', label: 'Justify', action: () => this.align('justify') },
|
|
194
|
+
] },
|
|
195
|
+
{ id: 'styles', label: 'Styles', children: [
|
|
196
|
+
{ id: 'style-small-caps', label: 'Small caps', action: () => this.wrapInline('span', 'Small caps', { fontVariant: 'small-caps' }) },
|
|
197
|
+
{ id: 'style-subtitle', label: 'Subtitle', action: () => this.wrapInline('small', 'Subtitle') },
|
|
198
|
+
{ id: 'style-highlight', label: 'Highlight', action: () => this.wrapInline('span', 'Highlight', { backgroundColor: '#FFFF00' }) },
|
|
199
|
+
] },
|
|
200
|
+
];
|
|
201
|
+
readonly formatItems = computed<readonly GoodDropdownItem[]>(() => this.allFormatItems.map(group => ({
|
|
202
|
+
...group,
|
|
203
|
+
children: group.children?.filter(item => this.hasFeature(item.id.startsWith('heading-')
|
|
204
|
+
? `heading${item.id.slice(8)}` as GoodRichTextFeature : formatFeatures[item.id])),
|
|
205
|
+
})).filter(group => group.children?.length));
|
|
206
|
+
readonly alignmentItems: readonly GoodDropdownItem[] = [
|
|
207
|
+
{ id: 'left', label: 'Left', icon: LucideTextAlignStart, action: () => this.align('left') },
|
|
208
|
+
{ id: 'center', label: 'Center', icon: LucideTextAlignCenter, action: () => this.align('center') },
|
|
209
|
+
{ id: 'right', label: 'Right', icon: LucideTextAlignEnd, action: () => this.align('right') },
|
|
210
|
+
{ id: 'justify', label: 'Justify', icon: LucideTextAlignJustify, action: () => this.align('justify') },
|
|
211
|
+
];
|
|
212
|
+
readonly unorderedItems: readonly GoodDropdownItem[] = [
|
|
213
|
+
{ id: 'disc', label: 'Disc', action: () => this.list('ul', 'disc') },
|
|
214
|
+
{ id: 'circle', label: 'Circle', action: () => this.list('ul', 'circle') },
|
|
215
|
+
{ id: 'square', label: 'Block', action: () => this.list('ul', 'square') },
|
|
216
|
+
];
|
|
217
|
+
readonly orderedItems: readonly GoodDropdownItem[] = [
|
|
218
|
+
{ id: 'decimal', label: '1, 2, 3', action: () => this.list('ol', 'decimal') },
|
|
219
|
+
{ id: 'lower-alpha', label: 'a, b, c', action: () => this.list('ol', 'lower-alpha') },
|
|
220
|
+
{ id: 'lower-greek', label: 'α, β, γ', action: () => this.list('ol', 'lower-greek') },
|
|
221
|
+
{ id: 'lower-roman', label: 'i, ii, iii', action: () => this.list('ol', 'lower-roman') },
|
|
222
|
+
{ id: 'upper-alpha', label: 'A, B, C', action: () => this.list('ol', 'upper-alpha') },
|
|
223
|
+
{ id: 'upper-roman', label: 'I, II, III', action: () => this.list('ol', 'upper-roman') },
|
|
224
|
+
];
|
|
225
|
+
|
|
226
|
+
constructor() {
|
|
227
|
+
effect(() => {
|
|
228
|
+
if (this.hasFeature('table')) return;
|
|
229
|
+
this.tableGridOpen.set(false);
|
|
230
|
+
this.tableMenuOpen.set(false);
|
|
231
|
+
this.tablePropertiesOpen.set(false);
|
|
232
|
+
this.tableActionVisible.set(false);
|
|
233
|
+
this.columnGripVisible.set(false);
|
|
234
|
+
this.rowGripVisible.set(false);
|
|
235
|
+
this.clearCellSelection();
|
|
236
|
+
});
|
|
237
|
+
effect(() => {
|
|
238
|
+
if (!this.hasFeature('link')) this.linkOpen.set(false);
|
|
239
|
+
if (!this.hasFeature('image')) this.imageOpen.set(false);
|
|
240
|
+
});
|
|
241
|
+
effect(() => {
|
|
242
|
+
const root = this.editor()?.nativeElement;
|
|
243
|
+
const html = sanitizeRichText(this.document, this.value());
|
|
244
|
+
if (!root || html === this.lastPublished) return;
|
|
245
|
+
root.innerHTML = html || '<p><br></p>';
|
|
246
|
+
this.lastPublished = root.innerHTML;
|
|
247
|
+
if (this.value() !== this.lastPublished) this.value.set(this.lastPublished);
|
|
248
|
+
this.savedRange = null;
|
|
249
|
+
this.activeCell = null;
|
|
250
|
+
this.activeTable = null;
|
|
251
|
+
this.clearCellSelection();
|
|
252
|
+
this.tableActionVisible.set(false);
|
|
253
|
+
this.tableMenuOpen.set(false);
|
|
254
|
+
this.history.reset();
|
|
255
|
+
this.updateHistoryState();
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
capture(): GoodRichTextSnapshot {
|
|
260
|
+
const root = this.editor()?.nativeElement;
|
|
261
|
+
return { html: root?.innerHTML ?? '', selection: root ? captureRichTextSelection(root) : null };
|
|
262
|
+
}
|
|
263
|
+
restore(snapshot: GoodRichTextSnapshot): void {
|
|
264
|
+
const root = this.editor()?.nativeElement;
|
|
265
|
+
if (!root) return;
|
|
266
|
+
root.innerHTML = snapshot.html;
|
|
267
|
+
this.clearCellSelection();
|
|
268
|
+
root.focus();
|
|
269
|
+
restoreRichTextSelection(root, snapshot.selection);
|
|
270
|
+
this.saveSelection();
|
|
271
|
+
this.lastPublished = root.innerHTML;
|
|
272
|
+
this.value.set(this.lastPublished);
|
|
273
|
+
this.onChange(this.lastPublished);
|
|
274
|
+
}
|
|
275
|
+
private normalizeDom(): void {
|
|
276
|
+
const root = this.editor()?.nativeElement;
|
|
277
|
+
if (!root) return;
|
|
278
|
+
const html = sanitizeRichText(this.document, root.innerHTML);
|
|
279
|
+
if (html !== root.innerHTML) {
|
|
280
|
+
const selection = captureRichTextSelection(root);
|
|
281
|
+
root.innerHTML = html;
|
|
282
|
+
restoreRichTextSelection(root, selection);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
private publish(): void {
|
|
286
|
+
const root = this.editor()?.nativeElement;
|
|
287
|
+
if (!root) return;
|
|
288
|
+
this.normalizeDom();
|
|
289
|
+
this.lastPublished = root.innerHTML;
|
|
290
|
+
this.value.set(this.lastPublished);
|
|
291
|
+
this.onChange(this.lastPublished);
|
|
292
|
+
this.saveSelection();
|
|
293
|
+
}
|
|
294
|
+
private updateHistoryState(): void { this.canUndo.set(this.history.canUndo); this.canRedo.set(this.history.canRedo); }
|
|
295
|
+
private run(name: string, mutate: () => void): void {
|
|
296
|
+
if (this.isDisabled() || this.readonly()) return;
|
|
297
|
+
this.restoreSavedSelection();
|
|
298
|
+
this.applying = true;
|
|
299
|
+
const changed = this.history.run(new GoodRichTextMutationCommand(name, () => { mutate(); this.normalizeDom(); }), this);
|
|
300
|
+
this.applying = false;
|
|
301
|
+
if (changed) { this.publish(); this.commandExecuted.emit(name); }
|
|
302
|
+
this.updateHistoryState();
|
|
303
|
+
}
|
|
304
|
+
undo(): void { if (!this.hasFeature('undo') || this.isDisabled() || this.readonly()) return; const command = this.history.undo(this); if (command) this.commandExecuted.emit(`undo:${command.name}`); this.updateHistoryState(); }
|
|
305
|
+
redo(): void { if (!this.hasFeature('redo') || this.isDisabled() || this.readonly()) return; const command = this.history.redo(this); if (command) this.commandExecuted.emit(`redo:${command.name}`); this.updateHistoryState(); }
|
|
306
|
+
private exec(command: string, value?: string): void { this.document.execCommand(command, false, value); }
|
|
307
|
+
native(command: string, name = command): void {
|
|
308
|
+
const feature = ({ strikeThrough: 'strikethrough' } as Record<string, GoodRichTextFeature>)[command] ?? command as GoodRichTextFeature;
|
|
309
|
+
if (!this.hasFeature(feature)) return;
|
|
310
|
+
this.run(name, () => this.exec(command));
|
|
311
|
+
}
|
|
312
|
+
block(tag: string): void {
|
|
313
|
+
const feature = tag.startsWith('h') && /^h[1-6]$/.test(tag) ? `heading${tag[1]}` : ({ p: 'paragraph', blockquote: 'blockquote', div: 'div', pre: 'pre' } as Record<string, string>)[tag];
|
|
314
|
+
if (!feature || !this.hasFeature(feature as GoodRichTextFeature)) return;
|
|
315
|
+
this.run(`block:${tag}`, () => this.exec('formatBlock', tag));
|
|
316
|
+
}
|
|
317
|
+
align(alignment: GoodRichTextAlignment): void {
|
|
318
|
+
if (!this.hasFeature('alignment')) return;
|
|
319
|
+
this.run(`align:${alignment}`, () => {
|
|
320
|
+
const root = this.editor()?.nativeElement;
|
|
321
|
+
const selection = this.document.getSelection();
|
|
322
|
+
if (!root || !selection?.rangeCount) return;
|
|
323
|
+
const range = selection.getRangeAt(0);
|
|
324
|
+
if (!root.contains(range.commonAncestorContainer)) return;
|
|
325
|
+
const candidates = [...root.querySelectorAll<HTMLElement>('p, div, h1, h2, h3, h4, h5, h6, blockquote, pre, li, th, td, caption')];
|
|
326
|
+
const blocks = candidates.filter(block => range.intersectsNode(block));
|
|
327
|
+
if (!blocks.length && candidates.length) blocks.push(candidates[candidates.length - 1]);
|
|
328
|
+
for (const block of blocks) block.style.textAlign = alignment;
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
list(kind: 'ol' | 'ul', style: string): void {
|
|
332
|
+
if (!this.hasFeature(kind === 'ul' ? 'bullets' : 'numbering')) return;
|
|
333
|
+
this.run(`list:${style}`, () => {
|
|
334
|
+
const existing = this.closestSelection(kind) as HTMLOListElement | HTMLUListElement | null;
|
|
335
|
+
if (!existing) this.exec(kind === 'ol' ? 'insertOrderedList' : 'insertUnorderedList');
|
|
336
|
+
const list = (this.closestSelection(kind) ?? this.editor()?.nativeElement.querySelector(`${kind}:last-of-type`)) as HTMLElement | null;
|
|
337
|
+
if (list) list.style.listStyleType = style;
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
clearFormatting(): void {
|
|
341
|
+
if (!this.hasFeature('clearformatting')) return;
|
|
342
|
+
this.run('clear-formatting', () => { this.exec('removeFormat'); this.exec('formatBlock', 'p'); });
|
|
343
|
+
}
|
|
344
|
+
fontSizeChanged(size: number): void {
|
|
345
|
+
if (!this.hasFeature('fontsize')) return;
|
|
346
|
+
this.fontSize.set(size);
|
|
347
|
+
this.wrapInline('span', `font-size:${size}`, { fontSize: `${size}px` });
|
|
348
|
+
}
|
|
349
|
+
fontFamilyChanged(family: string): void {
|
|
350
|
+
if (!this.hasFeature('fontfamily')) return;
|
|
351
|
+
const css = goodFontFamilyCss(family);
|
|
352
|
+
if (!css) return;
|
|
353
|
+
this.fontFamily.set(family);
|
|
354
|
+
this.wrapInline('span', `font-family:${family}`, { fontFamily: css });
|
|
355
|
+
}
|
|
356
|
+
applyColor(kind: 'text' | 'background', color: string): void {
|
|
357
|
+
if (!this.hasFeature(kind === 'text' ? 'textcolor' : 'background')) return;
|
|
358
|
+
this.run(`${kind}-color:${color}`, () => {
|
|
359
|
+
this.exec('styleWithCSS', 'true');
|
|
360
|
+
this.exec(kind === 'text' ? 'foreColor' : 'hiliteColor', color);
|
|
361
|
+
this.exec('styleWithCSS', 'false');
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
wrapInline(tag: 'code' | 'span' | 'small', name: string, style?: Partial<CSSStyleDeclaration>): void {
|
|
365
|
+
const feature = ({ Code: 'code', 'Small caps': 'smallcaps', Subtitle: 'subtitle', Highlight: 'highlight' } as Record<string, GoodRichTextFeature>)[name];
|
|
366
|
+
if (feature && !this.hasFeature(feature)) return;
|
|
367
|
+
this.run(name, () => {
|
|
368
|
+
const selection = this.document.getSelection();
|
|
369
|
+
if (!selection?.rangeCount) return;
|
|
370
|
+
const range = selection.getRangeAt(0);
|
|
371
|
+
if (!this.editor()?.nativeElement.contains(range.commonAncestorContainer)) return;
|
|
372
|
+
const collapsed = range.collapsed;
|
|
373
|
+
const wrapper = this.document.createElement(tag);
|
|
374
|
+
if (style) Object.assign(wrapper.style, style);
|
|
375
|
+
const content = range.extractContents();
|
|
376
|
+
if (content.hasChildNodes()) wrapper.appendChild(content);
|
|
377
|
+
else wrapper.appendChild(this.document.createTextNode('\u200B'));
|
|
378
|
+
range.insertNode(wrapper);
|
|
379
|
+
range.selectNodeContents(wrapper);
|
|
380
|
+
if (collapsed) range.collapse(false);
|
|
381
|
+
selection.removeAllRanges(); selection.addRange(range);
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
onBeforeInput(event: InputEvent): void {
|
|
386
|
+
if (event.inputType === 'historyUndo' || event.inputType === 'historyRedo') {
|
|
387
|
+
event.preventDefault(); event.inputType === 'historyUndo' ? this.undo() : this.redo(); return;
|
|
388
|
+
}
|
|
389
|
+
const nativeFeature = ({ formatBold: 'bold', formatItalic: 'italic', formatUnderline: 'underline',
|
|
390
|
+
formatStrikeThrough: 'strikethrough', insertOrderedList: 'numbering', insertUnorderedList: 'bullets' } as Record<string, GoodRichTextFeature>)[event.inputType];
|
|
391
|
+
if (nativeFeature && !this.hasFeature(nativeFeature)) { event.preventDefault(); return; }
|
|
392
|
+
if (!this.applying) this.pendingInput = this.capture();
|
|
393
|
+
}
|
|
394
|
+
onInput(): void {
|
|
395
|
+
if (this.applying) return;
|
|
396
|
+
this.normalizeDom();
|
|
397
|
+
const before = this.pendingInput;
|
|
398
|
+
this.pendingInput = null;
|
|
399
|
+
if (before) this.history.record(new GoodRichTextSnapshotCommand('typing', before, this.capture()));
|
|
400
|
+
this.publish();
|
|
401
|
+
this.updateHistoryState();
|
|
402
|
+
}
|
|
403
|
+
onPaste(event: ClipboardEvent): void {
|
|
404
|
+
event.preventDefault();
|
|
405
|
+
const html = event.clipboardData?.getData('text/html');
|
|
406
|
+
const plain = event.clipboardData?.getData('text/plain') ?? '';
|
|
407
|
+
const safe = html ? sanitizeRichText(this.document, html) : this.escape(plain).replace(/\n/g, '<br>');
|
|
408
|
+
this.run('paste', () => this.exec('insertHTML', safe));
|
|
409
|
+
}
|
|
410
|
+
onDrop(event: DragEvent): void { event.preventDefault(); }
|
|
411
|
+
onKeydown(event: KeyboardEvent): void {
|
|
412
|
+
if ((event.ctrlKey || event.metaKey) && !event.altKey) {
|
|
413
|
+
const shortcut = ({ b: 'bold', i: 'italic', u: 'underline' } as Record<string, GoodRichTextFeature>)[event.key.toLowerCase()];
|
|
414
|
+
if (shortcut && !this.hasFeature(shortcut)) { event.preventDefault(); return; }
|
|
415
|
+
if (event.key.toLowerCase() === 'z') { event.preventDefault(); event.shiftKey ? this.redo() : this.undo(); }
|
|
416
|
+
else if (event.key.toLowerCase() === 'y') { event.preventDefault(); this.redo(); }
|
|
417
|
+
}
|
|
418
|
+
if (event.key === 'Escape') { this.tableGridOpen.set(false); this.tableMenuOpen.set(false); }
|
|
419
|
+
}
|
|
420
|
+
@HostListener('document:selectionchange') saveSelection(): void {
|
|
421
|
+
const root = this.editor()?.nativeElement, selection = this.document.getSelection();
|
|
422
|
+
if (!root || !selection?.rangeCount || !selection.anchorNode || !root.contains(selection.anchorNode)) return;
|
|
423
|
+
this.savedRange = selection.getRangeAt(0).cloneRange();
|
|
424
|
+
const node = selection.anchorNode.nodeType === Node.ELEMENT_NODE ? selection.anchorNode as Element : selection.anchorNode.parentElement;
|
|
425
|
+
this.activeCell = node?.closest('td, th') as HTMLTableCellElement | null;
|
|
426
|
+
this.activeTable = node?.closest('table') as HTMLTableElement | null;
|
|
427
|
+
this.updateTableActionPosition();
|
|
428
|
+
}
|
|
429
|
+
private restoreSavedSelection(): void {
|
|
430
|
+
const root = this.editor()?.nativeElement;
|
|
431
|
+
if (!root) return;
|
|
432
|
+
const selection = this.document.getSelection();
|
|
433
|
+
if (!selection) return;
|
|
434
|
+
const wasInside = !!selection.rangeCount && !!selection.anchorNode && root.contains(selection.anchorNode);
|
|
435
|
+
const savedRange = this.savedRange;
|
|
436
|
+
root.focus();
|
|
437
|
+
if (savedRange?.startContainer.isConnected && root.contains(savedRange.startContainer)) {
|
|
438
|
+
selection.removeAllRanges(); selection.addRange(savedRange);
|
|
439
|
+
} else if (!wasInside) {
|
|
440
|
+
const range = this.document.createRange(); range.selectNodeContents(root); range.collapse(false);
|
|
441
|
+
selection.removeAllRanges(); selection.addRange(range);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
private closestSelection(selector: string): Element | null {
|
|
445
|
+
const node = this.document.getSelection()?.anchorNode;
|
|
446
|
+
return (node?.nodeType === Node.ELEMENT_NODE ? node as Element : node?.parentElement)?.closest(selector) ?? null;
|
|
447
|
+
}
|
|
448
|
+
private escape(value: string): string { const node = this.document.createElement('span'); node.textContent = value; return node.innerHTML; }
|
|
449
|
+
private insertHtml(html: string): void {
|
|
450
|
+
const root = this.editor()?.nativeElement;
|
|
451
|
+
if (!root) return;
|
|
452
|
+
const range = this.savedRange?.startContainer.isConnected && root.contains(this.savedRange.startContainer)
|
|
453
|
+
? this.savedRange.cloneRange() : this.document.createRange();
|
|
454
|
+
if (!this.savedRange?.startContainer.isConnected || !root.contains(range.startContainer)) {
|
|
455
|
+
range.selectNodeContents(root); range.collapse(false);
|
|
456
|
+
}
|
|
457
|
+
const template = this.document.createElement('template');
|
|
458
|
+
template.innerHTML = sanitizeRichText(this.document, html);
|
|
459
|
+
const fragment = template.content;
|
|
460
|
+
const last = fragment.lastChild;
|
|
461
|
+
range.deleteContents(); range.insertNode(fragment);
|
|
462
|
+
if (last) { range.setStartAfter(last); range.collapse(true); }
|
|
463
|
+
this.savedRange = range.cloneRange();
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
openLink(): void {
|
|
467
|
+
if (!this.hasFeature('link')) return;
|
|
468
|
+
this.saveSelection();
|
|
469
|
+
const selection = this.document.getSelection();
|
|
470
|
+
this.linkText.set(selection?.toString() || '');
|
|
471
|
+
this.linkUrl.set(''); this.linkTarget.set('current'); this.linkError.set(''); this.linkOpen.set(true);
|
|
472
|
+
}
|
|
473
|
+
saveLink(): void {
|
|
474
|
+
if (!this.hasFeature('link')) return;
|
|
475
|
+
const url = safeRichTextUrl(this.linkUrl());
|
|
476
|
+
if (!url) { this.linkError.set('Enter a valid web address, email link, or in-app path.'); return; }
|
|
477
|
+
const text = this.linkText().trim() || url;
|
|
478
|
+
const link = this.document.createElement('a');
|
|
479
|
+
link.href = url; link.textContent = text;
|
|
480
|
+
if (this.linkTarget() === 'new') { link.target = '_blank'; link.rel = 'noopener noreferrer'; }
|
|
481
|
+
this.linkOpen.set(false);
|
|
482
|
+
this.run('insert-link', () => this.insertHtml(link.outerHTML));
|
|
483
|
+
}
|
|
484
|
+
openImage(): void { if (!this.hasFeature('image')) return; this.saveSelection(); this.imageFile.set(null); this.imageAlt.set(''); this.imageError.set(''); this.imageOpen.set(true); }
|
|
485
|
+
chooseImage(files: FileList | null): void {
|
|
486
|
+
const file = files?.item(0) ?? null;
|
|
487
|
+
if (file && (!/^image\/(png|jpeg|gif|webp)$/.test(file.type) || file.size > 5 * 1024 * 1024)) {
|
|
488
|
+
this.imageFile.set(null); this.imageError.set('Choose a PNG, JPEG, GIF, or WebP image up to 5 MB.'); return;
|
|
489
|
+
}
|
|
490
|
+
this.imageError.set(''); this.imageFile.set(file);
|
|
491
|
+
}
|
|
492
|
+
insertImage(): void {
|
|
493
|
+
if (!this.hasFeature('image')) return;
|
|
494
|
+
const file = this.imageFile();
|
|
495
|
+
if (!file) { this.imageError.set('Choose an image first.'); return; }
|
|
496
|
+
const reader = new FileReader();
|
|
497
|
+
reader.onload = () => {
|
|
498
|
+
if (!this.hasFeature('image')) return;
|
|
499
|
+
const source = String(reader.result ?? '');
|
|
500
|
+
if (!safeRichTextUrl(source, true)) { this.imageError.set('The image could not be read.'); return; }
|
|
501
|
+
const image = this.document.createElement('img');
|
|
502
|
+
image.src = source; image.alt = this.imageAlt().trim();
|
|
503
|
+
this.imageOpen.set(false);
|
|
504
|
+
this.run('insert-image', () => this.insertHtml(`${image.outerHTML}<p><br></p>`));
|
|
505
|
+
};
|
|
506
|
+
reader.onerror = () => this.imageError.set('The image could not be read.');
|
|
507
|
+
reader.readAsDataURL(file);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
toggleTableGrid(event: MouseEvent): void {
|
|
511
|
+
if (!this.hasFeature('table')) return;
|
|
512
|
+
const rect = (event.currentTarget as HTMLElement).getBoundingClientRect();
|
|
513
|
+
const width = 233, height = 245;
|
|
514
|
+
this.tableGridPosition.set({
|
|
515
|
+
left: Math.max(8, Math.min(rect.left, window.innerWidth - width - 8)),
|
|
516
|
+
top: rect.bottom + height + 8 < window.innerHeight ? rect.bottom + 4 : Math.max(8, rect.top - height - 4),
|
|
517
|
+
});
|
|
518
|
+
this.tableGridOpen.update(open => !open); this.tableMenuOpen.set(false);
|
|
519
|
+
}
|
|
520
|
+
openTableMenuFromCell(event: MouseEvent): void {
|
|
521
|
+
if (!this.hasFeature('table') || !this.activeTable || this.isDisabled() || this.readonly()) return;
|
|
522
|
+
if (this.tableMenuOpen()) { this.tableMenuOpen.set(false); return; }
|
|
523
|
+
const bounds = (event.currentTarget as HTMLElement).getBoundingClientRect();
|
|
524
|
+
this.tableGridOpen.set(false);
|
|
525
|
+
this.positionTableMenu(bounds.left, bounds.bottom + 4, bounds.top);
|
|
526
|
+
this.tableMenuOpen.set(true);
|
|
527
|
+
}
|
|
528
|
+
isHeaderCell(): boolean { return this.activeCell?.tagName === 'TH'; }
|
|
529
|
+
hasActiveCell(): boolean { return !!this.activeCell; }
|
|
530
|
+
private clearCellSelection(): void {
|
|
531
|
+
this.selectedCells.clear();
|
|
532
|
+
this.selectionAnchor = null;
|
|
533
|
+
this.selectedCellCount.set(0);
|
|
534
|
+
this.selectedCellBoxes.set([]);
|
|
535
|
+
this.selectingCells.set(false);
|
|
536
|
+
}
|
|
537
|
+
private selectCell(cell: HTMLTableCellElement, event?: MouseEvent, preserve = false): void {
|
|
538
|
+
const table = cell.closest('table');
|
|
539
|
+
if (!table) return;
|
|
540
|
+
if ([...this.selectedCells].some(selected => selected.closest('table') !== table || !selected.isConnected)) this.clearCellSelection();
|
|
541
|
+
if (preserve && this.selectedCells.has(cell)) return;
|
|
542
|
+
if (event?.shiftKey && this.selectionAnchor?.isConnected && this.selectionAnchor.closest('table') === table) {
|
|
543
|
+
const startRow = this.selectionAnchor.parentElement as HTMLTableRowElement;
|
|
544
|
+
const endRow = cell.parentElement as HTMLTableRowElement;
|
|
545
|
+
const firstRow = Math.min(startRow.rowIndex, endRow.rowIndex), lastRow = Math.max(startRow.rowIndex, endRow.rowIndex);
|
|
546
|
+
const firstColumn = Math.min(this.selectionAnchor.cellIndex, cell.cellIndex), lastColumn = Math.max(this.selectionAnchor.cellIndex, cell.cellIndex);
|
|
547
|
+
this.selectedCells.clear();
|
|
548
|
+
for (let row = firstRow; row <= lastRow; row++) {
|
|
549
|
+
for (let column = firstColumn; column <= lastColumn; column++) {
|
|
550
|
+
const current = table.rows[row]?.cells[column];
|
|
551
|
+
if (current) this.selectedCells.add(current);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
} else if (this.selectingCells() || event?.ctrlKey || event?.metaKey) {
|
|
555
|
+
if (this.selectedCells.has(cell) && this.selectedCells.size > 1) this.selectedCells.delete(cell);
|
|
556
|
+
else this.selectedCells.add(cell);
|
|
557
|
+
this.selectionAnchor = cell;
|
|
558
|
+
} else {
|
|
559
|
+
this.selectedCells.clear();
|
|
560
|
+
this.selectedCells.add(cell);
|
|
561
|
+
this.selectionAnchor = cell;
|
|
562
|
+
}
|
|
563
|
+
this.selectedCellCount.set(this.selectedCells.size);
|
|
564
|
+
this.updateSelectedCellBoxes();
|
|
565
|
+
}
|
|
566
|
+
toggleCellSelectionMode(): void {
|
|
567
|
+
if (!this.activeCell) return;
|
|
568
|
+
if (!this.selectedCells.size) this.selectCell(this.activeCell);
|
|
569
|
+
this.selectingCells.update(value => !value);
|
|
570
|
+
this.tableMenuOpen.set(false);
|
|
571
|
+
}
|
|
572
|
+
private updateSelectedCellBoxes(): void {
|
|
573
|
+
const canvas = this.editor()?.nativeElement.parentElement;
|
|
574
|
+
if (!canvas) return;
|
|
575
|
+
const bounds = canvas.getBoundingClientRect();
|
|
576
|
+
this.selectedCellBoxes.set([...this.selectedCells].filter(cell => cell.isConnected).map(cell => {
|
|
577
|
+
const rect = cell.getBoundingClientRect();
|
|
578
|
+
const left = Math.max(rect.left, bounds.left), right = Math.min(rect.right, bounds.right);
|
|
579
|
+
const top = Math.max(rect.top, bounds.top), bottom = Math.min(rect.bottom, bounds.bottom);
|
|
580
|
+
return { left, top, width: right - left, height: bottom - top };
|
|
581
|
+
}).filter(box => box.width > 0 && box.height > 0));
|
|
582
|
+
}
|
|
583
|
+
private canResizeColumns(table: HTMLTableElement): boolean {
|
|
584
|
+
return table.rows.length > 0 && [...table.rows].every(row => row.cells.length === table.rows[0].cells.length)
|
|
585
|
+
&& [...table.querySelectorAll<HTMLTableCellElement>('td,th')].every(cell => cell.colSpan === 1 && cell.rowSpan === 1);
|
|
586
|
+
}
|
|
587
|
+
private positionTableMenu(left: number, below: number, above: number): void {
|
|
588
|
+
const menuWidth = 230, menuHeight = this.activeCell ? this.selectedCellCount() > 1 ? 496 : 452 : 100;
|
|
589
|
+
this.tableMenuPosition.set({
|
|
590
|
+
left: Math.max(8, Math.min(left, window.innerWidth - menuWidth - 8)),
|
|
591
|
+
top: below + menuHeight <= window.innerHeight - 8 ? below : Math.max(8, above - menuHeight - 4),
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
updateTableActionPosition(): void {
|
|
595
|
+
const root = this.editor()?.nativeElement;
|
|
596
|
+
const canvas = root?.parentElement;
|
|
597
|
+
const anchor = this.activeCell?.isConnected ? this.activeCell : this.activeTable?.isConnected ? this.activeTable : null;
|
|
598
|
+
if (!this.hasFeature('table') || !root || !canvas || !anchor || !root.contains(anchor) || this.isDisabled() || this.readonly()) {
|
|
599
|
+
this.tableActionVisible.set(false);
|
|
600
|
+
this.columnGripVisible.set(false); this.rowGripVisible.set(false);
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
const rect = anchor.getBoundingClientRect(), bounds = canvas.getBoundingClientRect();
|
|
604
|
+
const left = Math.max(rect.left, bounds.left, 0), right = Math.min(rect.right, bounds.right, window.innerWidth);
|
|
605
|
+
const top = Math.max(rect.top, bounds.top, 0), bottom = Math.min(rect.bottom, bounds.bottom, window.innerHeight);
|
|
606
|
+
if (right <= left || bottom <= top) {
|
|
607
|
+
this.tableActionVisible.set(false);
|
|
608
|
+
this.columnGripVisible.set(false); this.rowGripVisible.set(false);
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
this.tableActionPosition.set({ left: Math.max(8, Math.min(right - 44, window.innerWidth - 52)), top: Math.max(8, Math.min(top - 44 >= bounds.top ? top - 44 : top, window.innerHeight - 52)) });
|
|
612
|
+
if (this.activeCell?.isConnected) {
|
|
613
|
+
const cell = this.activeCell.getBoundingClientRect();
|
|
614
|
+
this.columnGripVisible.set(!!this.activeTable && this.canResizeColumns(this.activeTable) && cell.right >= bounds.left + 18 && cell.right <= bounds.right + 18);
|
|
615
|
+
this.rowGripVisible.set(cell.bottom >= bounds.top + 18 && cell.bottom <= bounds.bottom + 18);
|
|
616
|
+
this.tableGripPosition.set({
|
|
617
|
+
columnLeft: Math.max(8, Math.min(cell.right - 18, bounds.right - 36, window.innerWidth - 44)),
|
|
618
|
+
columnTop: Math.max(8, Math.min(cell.top + (cell.height - 36) / 2, window.innerHeight - 44)),
|
|
619
|
+
rowLeft: Math.max(8, Math.min(cell.left + (cell.width - 36) / 2, window.innerWidth - 44)),
|
|
620
|
+
rowTop: Math.max(8, Math.min(cell.bottom - 18, bounds.bottom - 36, window.innerHeight - 44)),
|
|
621
|
+
});
|
|
622
|
+
} else { this.columnGripVisible.set(false); this.rowGripVisible.set(false); }
|
|
623
|
+
this.updateSelectedCellBoxes();
|
|
624
|
+
this.tableActionVisible.set(true);
|
|
625
|
+
}
|
|
626
|
+
onEditorScroll(): void { this.tableMenuOpen.set(false); this.updateTableActionPosition(); }
|
|
627
|
+
@HostListener('window:resize') onViewportResize(): void { this.tableMenuOpen.set(false); this.updateTableActionPosition(); }
|
|
628
|
+
@HostListener('window:scroll') onViewportScroll(): void { this.onEditorScroll(); }
|
|
629
|
+
@HostListener('document:keydown.escape') closeTableMenuOnEscape(): void {
|
|
630
|
+
if (!this.tableMenuOpen()) return;
|
|
631
|
+
this.tableMenuOpen.set(false);
|
|
632
|
+
this.tableActionButton()?.nativeElement.querySelector('button')?.focus();
|
|
633
|
+
}
|
|
634
|
+
startTableResize(event: PointerEvent, axis: TableResizeAxis): void {
|
|
635
|
+
if (!this.hasFeature('table')) return;
|
|
636
|
+
const cell = this.activeCell, table = this.activeTable;
|
|
637
|
+
if (!cell || !table || this.isDisabled() || this.readonly() || (event.pointerType === 'mouse' && event.button !== 0)) return;
|
|
638
|
+
if (axis === 'column' && !this.canResizeColumns(table)) return;
|
|
639
|
+
event.preventDefault(); event.stopPropagation();
|
|
640
|
+
(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId);
|
|
641
|
+
const row = cell.parentElement as HTMLTableRowElement;
|
|
642
|
+
this.tableResize = {
|
|
643
|
+
axis, pointerId: event.pointerId, table, row, columnIndex: cell.cellIndex,
|
|
644
|
+
columnWidths: [...table.rows[0].cells].map(item => item.getBoundingClientRect().width),
|
|
645
|
+
start: axis === 'column' ? event.clientX : event.clientY,
|
|
646
|
+
size: axis === 'column' ? cell.getBoundingClientRect().width : row.getBoundingClientRect().height,
|
|
647
|
+
before: this.capture(), changed: false,
|
|
648
|
+
};
|
|
649
|
+
this.tableMenuOpen.set(false);
|
|
650
|
+
}
|
|
651
|
+
moveTableResize(event: PointerEvent): void {
|
|
652
|
+
const resize = this.tableResize;
|
|
653
|
+
if (!resize || resize.pointerId !== event.pointerId) return;
|
|
654
|
+
event.preventDefault();
|
|
655
|
+
const delta = (resize.axis === 'column' ? event.clientX : event.clientY) - resize.start;
|
|
656
|
+
if (Math.abs(delta) < 1) return;
|
|
657
|
+
if (resize.axis === 'column') {
|
|
658
|
+
const otherWidths = resize.columnWidths.reduce((sum, width, index) => sum + (index === resize.columnIndex ? 0 : Math.max(64, Math.round(width))), 0);
|
|
659
|
+
const width = Math.max(64, Math.min(2000, 5000 - otherWidths, Math.round(resize.size + delta)));
|
|
660
|
+
for (const row of [...resize.table.rows]) row.cells[resize.columnIndex].style.width = `${width}px`;
|
|
661
|
+
resize.table.style.width = `${Math.round(otherWidths + width)}px`;
|
|
662
|
+
for (let index = 0; index < resize.columnWidths.length; index++) {
|
|
663
|
+
if (index === resize.columnIndex) continue;
|
|
664
|
+
for (const row of [...resize.table.rows]) row.cells[index].style.width = `${Math.max(64, Math.round(resize.columnWidths[index]))}px`;
|
|
665
|
+
}
|
|
666
|
+
} else resize.row.style.height = `${Math.max(32, Math.min(2000, Math.round(resize.size + delta)))}px`;
|
|
667
|
+
resize.changed = true;
|
|
668
|
+
this.updateTableActionPosition();
|
|
669
|
+
}
|
|
670
|
+
finishTableResize(event: PointerEvent, canceled = false): void {
|
|
671
|
+
const resize = this.tableResize;
|
|
672
|
+
if (!resize || resize.pointerId !== event.pointerId) return;
|
|
673
|
+
this.tableResize = null;
|
|
674
|
+
if (canceled) { this.restore(resize.before); return; }
|
|
675
|
+
if (!resize.changed) return;
|
|
676
|
+
this.normalizeDom();
|
|
677
|
+
const name = resize.axis === 'column' ? 'resize-column' : 'resize-row';
|
|
678
|
+
if (this.history.record(new GoodRichTextSnapshotCommand(name, resize.before, this.capture()))) {
|
|
679
|
+
this.publish(); this.commandExecuted.emit(name);
|
|
680
|
+
}
|
|
681
|
+
this.updateHistoryState();
|
|
682
|
+
}
|
|
683
|
+
onTableResizeKeydown(event: KeyboardEvent, axis: TableResizeAxis): void {
|
|
684
|
+
const direction = axis === 'column' ? event.key === 'ArrowRight' ? 1 : event.key === 'ArrowLeft' ? -1 : 0
|
|
685
|
+
: event.key === 'ArrowDown' ? 1 : event.key === 'ArrowUp' ? -1 : 0;
|
|
686
|
+
if (!direction || !this.activeCell || !this.activeTable) return;
|
|
687
|
+
event.preventDefault();
|
|
688
|
+
const cell = this.activeCell, table = this.activeTable, row = cell.parentElement as HTMLTableRowElement;
|
|
689
|
+
const step = event.shiftKey ? 24 : 8;
|
|
690
|
+
this.run(axis === 'column' ? 'resize-column' : 'resize-row', () => {
|
|
691
|
+
if (axis === 'row') row.style.height = `${Math.max(32, Math.min(2000, Math.round(row.getBoundingClientRect().height + direction * step)))}px`;
|
|
692
|
+
else if (this.canResizeColumns(table)) {
|
|
693
|
+
const widths = [...table.rows[0].cells].map(current => Math.max(64, Math.round(current.getBoundingClientRect().width)));
|
|
694
|
+
const otherWidths = widths.reduce((sum, current, index) => sum + (index === cell.cellIndex ? 0 : current), 0);
|
|
695
|
+
const width = Math.max(64, Math.min(2000, 5000 - otherWidths, Math.round(widths[cell.cellIndex] + direction * step)));
|
|
696
|
+
widths[cell.cellIndex] = width;
|
|
697
|
+
table.style.width = `${Math.round(widths.reduce((sum, current) => sum + current, 0))}px`;
|
|
698
|
+
for (const current of [...table.rows]) for (let index = 0; index < widths.length; index++) current.cells[index].style.width = `${Math.max(64, Math.round(widths[index]))}px`;
|
|
699
|
+
}
|
|
700
|
+
});
|
|
701
|
+
(event.currentTarget as HTMLElement).focus();
|
|
702
|
+
}
|
|
703
|
+
previewTable(rows: number, columns: number): void { this.gridRows.set(rows); this.gridColumns.set(columns); }
|
|
704
|
+
insertTable(rows = this.gridRows(), columns = this.gridColumns()): void {
|
|
705
|
+
if (!this.hasFeature('table')) return;
|
|
706
|
+
const cells = '<td><p><br></p></td>'.repeat(columns);
|
|
707
|
+
const html = `<table><tbody>${`<tr>${cells}</tr>`.repeat(rows)}</tbody></table><p><br></p>`;
|
|
708
|
+
this.tableGridOpen.set(false);
|
|
709
|
+
this.run(`insert-table:${rows}x${columns}`, () => this.insertHtml(html));
|
|
710
|
+
}
|
|
711
|
+
onContextMenu(event: MouseEvent): void {
|
|
712
|
+
if (!this.hasFeature('table') || this.isDisabled() || this.readonly()) return;
|
|
713
|
+
const target = event.target as Element;
|
|
714
|
+
const table = target.closest('table');
|
|
715
|
+
if (!table) return;
|
|
716
|
+
event.preventDefault();
|
|
717
|
+
this.activeTable = table as HTMLTableElement;
|
|
718
|
+
this.activeCell = target.closest('td, th') as HTMLTableCellElement | null;
|
|
719
|
+
if (this.activeCell) this.selectCell(this.activeCell, undefined, true);
|
|
720
|
+
this.updateTableActionPosition();
|
|
721
|
+
this.tableGridOpen.set(false);
|
|
722
|
+
this.positionTableMenu(event.clientX, event.clientY + 4, event.clientY);
|
|
723
|
+
this.tableMenuOpen.set(true);
|
|
724
|
+
}
|
|
725
|
+
onEditorClick(event: MouseEvent): void {
|
|
726
|
+
if (!this.hasFeature('table')) return;
|
|
727
|
+
const target = event.target as Element;
|
|
728
|
+
this.activeCell = target.closest('td, th') as HTMLTableCellElement | null;
|
|
729
|
+
this.activeTable = target.closest('table') as HTMLTableElement | null;
|
|
730
|
+
if (this.activeCell) this.selectCell(this.activeCell, event);
|
|
731
|
+
else this.clearCellSelection();
|
|
732
|
+
this.updateTableActionPosition();
|
|
733
|
+
}
|
|
734
|
+
onEditorPointerDown(event: PointerEvent): void {
|
|
735
|
+
if (!this.hasFeature('table')) return;
|
|
736
|
+
if ((event.shiftKey || event.ctrlKey || event.metaKey || this.selectingCells()) && (event.target as Element).closest('td,th')) {
|
|
737
|
+
event.preventDefault();
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
openTableProperties(): void {
|
|
741
|
+
if (!this.hasFeature('table')) return;
|
|
742
|
+
const table = this.activeTable;
|
|
743
|
+
if (!table) return;
|
|
744
|
+
const width = table.style.width.endsWith('px')
|
|
745
|
+
? Math.round(table.getBoundingClientRect().width / (this.editor()?.nativeElement.clientWidth || table.getBoundingClientRect().width) * 100)
|
|
746
|
+
: parseInt(table.style.width, 10) || 100;
|
|
747
|
+
this.tableWidth.set(Math.max(10, Math.min(100, width)));
|
|
748
|
+
this.tablePadding.set(parseInt(table.querySelector<HTMLElement>('td,th')?.style.padding ?? '8', 10) || 8);
|
|
749
|
+
this.tableCaption.set(table.querySelector('caption')?.textContent ?? '');
|
|
750
|
+
this.tableMenuOpen.set(false); this.tableGridOpen.set(false); this.tablePropertiesOpen.set(true);
|
|
751
|
+
}
|
|
752
|
+
saveTableProperties(): void {
|
|
753
|
+
if (!this.hasFeature('table')) return;
|
|
754
|
+
const table = this.activeTable;
|
|
755
|
+
if (!table) return;
|
|
756
|
+
this.tablePropertiesOpen.set(false);
|
|
757
|
+
this.run('table-properties', () => {
|
|
758
|
+
if (table.style.width.endsWith('px')) for (const cell of table.querySelectorAll<HTMLElement>('td,th')) cell.style.width = '';
|
|
759
|
+
table.style.width = `${Math.max(10, Math.min(100, this.tableWidth()))}%`;
|
|
760
|
+
for (const cell of table.querySelectorAll<HTMLElement>('td,th')) cell.style.padding = `${Math.max(0, Math.min(24, this.tablePadding()))}px`;
|
|
761
|
+
let caption = table.querySelector('caption');
|
|
762
|
+
if (this.tableCaption().trim()) {
|
|
763
|
+
if (!caption) { caption = this.document.createElement('caption'); table.prepend(caption); }
|
|
764
|
+
caption.textContent = this.tableCaption().trim();
|
|
765
|
+
} else caption?.remove();
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
tableAction(action: GoodRichTextTableAction): void {
|
|
769
|
+
if (!this.hasFeature('table')) return;
|
|
770
|
+
if (action === 'properties') { this.openTableProperties(); return; }
|
|
771
|
+
const table = this.activeTable, cell = this.activeCell;
|
|
772
|
+
this.tableMenuOpen.set(false); this.tableGridOpen.set(false);
|
|
773
|
+
if (!table) return;
|
|
774
|
+
this.run(`table:${action}`, () => {
|
|
775
|
+
if (action === 'delete-table') { table.remove(); return; }
|
|
776
|
+
if (!cell) return;
|
|
777
|
+
const row = cell.parentElement as HTMLTableRowElement;
|
|
778
|
+
const index = Array.from(row.cells).indexOf(cell);
|
|
779
|
+
if (action === 'header-cell' || action === 'body-cell') {
|
|
780
|
+
const tag = action === 'header-cell' ? 'th' : 'td';
|
|
781
|
+
const cells = this.selectedCells.size > 1 ? [...this.selectedCells].filter(current => current.isConnected && current.closest('table') === table) : [cell];
|
|
782
|
+
for (const current of cells) this.replaceTableCell(current, tag, table);
|
|
783
|
+
const replacement = table.rows[row.rowIndex]?.cells[index];
|
|
784
|
+
if (!replacement) return;
|
|
785
|
+
this.activeCell = replacement;
|
|
786
|
+
const range = this.document.createRange();
|
|
787
|
+
range.selectNodeContents(replacement); range.collapse(false);
|
|
788
|
+
const selection = this.document.getSelection();
|
|
789
|
+
selection?.removeAllRanges(); selection?.addRange(range);
|
|
790
|
+
} else if (action === 'row-before' || action === 'row-after') {
|
|
791
|
+
const newRow = this.document.createElement('tr');
|
|
792
|
+
for (const existing of [...row.cells]) {
|
|
793
|
+
const next = this.emptyCell(); next.style.width = existing.style.width;
|
|
794
|
+
newRow.appendChild(next);
|
|
795
|
+
}
|
|
796
|
+
row.insertAdjacentElement(action === 'row-before' ? 'beforebegin' : 'afterend', newRow);
|
|
797
|
+
} else if (action === 'delete-row') {
|
|
798
|
+
row.remove(); if (!table.rows.length) table.remove();
|
|
799
|
+
} else if (action === 'column-before' || action === 'column-after') {
|
|
800
|
+
let addedWidth = 0;
|
|
801
|
+
for (const current of Array.from(table.rows)) {
|
|
802
|
+
const reference = current.cells[index] ?? current.cells[current.cells.length - 1];
|
|
803
|
+
const next = this.emptyCell();
|
|
804
|
+
if (reference?.style.width) next.style.width = reference.style.width;
|
|
805
|
+
if (reference) reference.insertAdjacentElement(action === 'column-before' ? 'beforebegin' : 'afterend', next);
|
|
806
|
+
else current.appendChild(next);
|
|
807
|
+
addedWidth ||= reference?.getBoundingClientRect().width ?? 80;
|
|
808
|
+
}
|
|
809
|
+
if (table.style.width.endsWith('px')) table.style.width = `${Math.min(5000, Math.round(parseFloat(table.style.width) + addedWidth))}px`;
|
|
810
|
+
} else if (action === 'delete-column') {
|
|
811
|
+
const removedWidth = table.rows[0]?.cells[index]?.getBoundingClientRect().width ?? 0;
|
|
812
|
+
for (const current of Array.from(table.rows)) current.cells[index]?.remove();
|
|
813
|
+
if (!table.querySelector('td,th')) table.remove();
|
|
814
|
+
else if (table.style.width.endsWith('px')) table.style.width = `${Math.max(64, Math.round(parseFloat(table.style.width) - removedWidth))}px`;
|
|
815
|
+
}
|
|
816
|
+
});
|
|
817
|
+
this.selectingCells.set(false);
|
|
818
|
+
this.selectedCells.clear();
|
|
819
|
+
if (this.activeCell?.isConnected) this.selectedCells.add(this.activeCell);
|
|
820
|
+
this.selectedCellCount.set(this.selectedCells.size);
|
|
821
|
+
this.updateTableActionPosition();
|
|
822
|
+
}
|
|
823
|
+
private replaceTableCell(cell: HTMLTableCellElement, tag: 'th' | 'td', table: HTMLTableElement): void {
|
|
824
|
+
if (cell.tagName.toLowerCase() === tag) return;
|
|
825
|
+
const row = cell.parentElement as HTMLTableRowElement;
|
|
826
|
+
const replacement = this.document.createElement(tag);
|
|
827
|
+
for (const attribute of ['colspan', 'rowspan']) {
|
|
828
|
+
const value = cell.getAttribute(attribute);
|
|
829
|
+
if (value) replacement.setAttribute(attribute, value);
|
|
830
|
+
}
|
|
831
|
+
replacement.style.textAlign = cell.style.textAlign;
|
|
832
|
+
replacement.style.padding = cell.style.padding;
|
|
833
|
+
replacement.style.width = cell.style.width;
|
|
834
|
+
if (tag === 'th') {
|
|
835
|
+
if (row === table.rows[0]) replacement.scope = 'col';
|
|
836
|
+
else if (cell.cellIndex === 0) replacement.scope = 'row';
|
|
837
|
+
}
|
|
838
|
+
while (cell.firstChild) replacement.appendChild(cell.firstChild);
|
|
839
|
+
cell.replaceWith(replacement);
|
|
840
|
+
}
|
|
841
|
+
private emptyCell(): HTMLTableCellElement {
|
|
842
|
+
const cell = this.document.createElement('td');
|
|
843
|
+
cell.innerHTML = '<p><br></p>';
|
|
844
|
+
return cell;
|
|
845
|
+
}
|
|
846
|
+
@HostListener('document:pointerdown', ['$event']) closeFloatingMenus(event: PointerEvent): void {
|
|
847
|
+
const target = event.target as Element;
|
|
848
|
+
if (!target.closest('.good-rich-editor-table-control, .good-rich-editor-table-trigger, .good-rich-editor-table-menu')) {
|
|
849
|
+
this.tableGridOpen.set(false); this.tableMenuOpen.set(false);
|
|
850
|
+
}
|
|
851
|
+
if (!target.closest('good-rich-text-editor')) this.tableActionVisible.set(false);
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
writeValue(value: string | null): void { this.value.set(value ?? '<p><br></p>'); }
|
|
855
|
+
/** Returns the currently rendered text, including browser-rendered line breaks. */
|
|
856
|
+
getPlainText(): string {
|
|
857
|
+
const root = this.editor()?.nativeElement;
|
|
858
|
+
return (root?.innerText ?? root?.textContent ?? '').trim();
|
|
859
|
+
}
|
|
860
|
+
registerOnChange(fn: (value: string) => void): void { this.onChange = fn; }
|
|
861
|
+
registerOnTouched(fn: () => void): void { this.onTouched = fn; }
|
|
862
|
+
setDisabledState(disabled: boolean): void { this.formDisabled.set(disabled); }
|
|
863
|
+
onBlur(): void { this.onTouched(); }
|
|
864
|
+
}
|