@mediafly/js-ui 51.5.1-1 → 51.5.2
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/.node-version +1 -1
- package/.release-it.json +13 -13
- package/.semaphore/promotion-deploy-docs.yml +35 -35
- package/.semaphore/scripts/notify_jira.sh +115 -115
- package/.semaphore/semaphore.yml +91 -91
- package/.stylelintignore +5 -5
- package/CHANGELOG.md +514 -510
- package/README.md +61 -61
- package/archive/old-changelog.md +1645 -1645
- package/browserslist.config.js +27 -27
- package/cypress.config.ts +26 -26
- package/lib/actionable-empty-state/actionable-empty-state.d.ts +10 -10
- package/lib/actionable-empty-state/actionable-empty-state.html +15 -15
- package/lib/actionable-empty-state/actionable-empty-state.js +53 -53
- package/lib/actionable-empty-state/index.d.ts +1 -1
- package/lib/actionable-empty-state/index.js +3 -3
- package/lib/auto-complete/auto-complete-match-renderer.component.d.ts +62 -62
- package/lib/auto-complete/auto-complete-match-renderer.component.html +20 -20
- package/lib/auto-complete/auto-complete-match-renderer.component.js +244 -244
- package/lib/auto-complete/auto-complete.component.d.ts +29 -29
- package/lib/auto-complete/auto-complete.component.html +43 -43
- package/lib/auto-complete/auto-complete.component.js +102 -102
- package/lib/auto-complete/index.d.ts +2 -2
- package/lib/auto-complete/index.js +4 -4
- package/lib/auto-focus/auto-focus.d.ts +1 -1
- package/lib/auto-focus/auto-focus.js +16 -16
- package/lib/auto-focus/auto-focus.service.d.ts +7 -7
- package/lib/auto-focus/auto-focus.service.js +40 -40
- package/lib/auto-focus/index.d.ts +2 -2
- package/lib/auto-focus/index.js +4 -4
- package/lib/badge/badge.d.ts +1 -1
- package/lib/badge/badge.html +3 -3
- package/lib/badge/badge.js +17 -17
- package/lib/badge/index.d.ts +1 -1
- package/lib/badge/index.js +3 -3
- package/lib/checkbox/checkbox.d.ts +1 -1
- package/lib/checkbox/checkbox.html +23 -23
- package/lib/checkbox/checkbox.js +30 -30
- package/lib/checkbox/index.d.ts +1 -1
- package/lib/checkbox/index.js +3 -3
- package/lib/collapse/collapse.d.ts +1 -1
- package/lib/collapse/collapse.js +73 -73
- package/lib/collapse/index.d.ts +1 -1
- package/lib/collapse/index.js +3 -3
- package/lib/color-input/color-input.d.ts +1 -1
- package/lib/color-input/color-input.html +32 -32
- package/lib/color-input/color-input.js +83 -83
- package/lib/color-input/index.d.ts +2 -2
- package/lib/color-input/index.js +4 -4
- package/lib/color-input/spectrum-color-picker.d.ts +1 -1
- package/lib/color-input/spectrum-color-picker.js +60 -60
- package/lib/color-utils/color-utils.service.d.ts +9 -9
- package/lib/color-utils/color-utils.service.js +46 -46
- package/lib/color-utils/index.d.ts +1 -1
- package/lib/color-utils/index.js +3 -3
- package/lib/constants/constants.d.ts +1 -1
- package/lib/constants/constants.js +12 -12
- package/lib/constants/index.d.ts +1 -1
- package/lib/constants/index.js +3 -3
- package/lib/date-input/date-input.d.ts +1 -1
- package/lib/date-input/date-input.html +31 -31
- package/lib/date-input/date-input.js +124 -124
- package/lib/date-input/index.d.ts +2 -2
- package/lib/date-input/index.js +4 -4
- package/lib/date-input/validate-date.d.ts +1 -1
- package/lib/date-input/validate-date.js +34 -34
- package/lib/date-time-zone-picker/date-time-zone-factory.d.ts +1 -1
- package/lib/date-time-zone-picker/date-time-zone-factory.js +123 -123
- package/lib/date-time-zone-picker/date-time-zone-picker.d.ts +1 -1
- package/lib/date-time-zone-picker/date-time-zone-picker.html +36 -36
- package/lib/date-time-zone-picker/date-time-zone-picker.js +188 -188
- package/lib/date-time-zone-picker/datepicker.d.ts +1 -1
- package/lib/date-time-zone-picker/datepicker.html +30 -30
- package/lib/date-time-zone-picker/datepicker.js +204 -204
- package/lib/date-time-zone-picker/index.d.ts +6 -6
- package/lib/date-time-zone-picker/index.js +8 -8
- package/lib/date-time-zone-picker/time-format-filter.d.ts +1 -1
- package/lib/date-time-zone-picker/time-format-filter.js +46 -46
- package/lib/date-time-zone-picker/time-zone-picker.d.ts +1 -1
- package/lib/date-time-zone-picker/time-zone-picker.html +21 -21
- package/lib/date-time-zone-picker/time-zone-picker.js +44 -44
- package/lib/date-time-zone-picker/timepicker.d.ts +1 -1
- package/lib/date-time-zone-picker/timepicker.html +31 -31
- package/lib/date-time-zone-picker/timepicker.js +99 -99
- package/lib/decorators/index.d.ts +9 -9
- package/lib/decorators/index.js +63 -63
- package/lib/dropdown/dropdown.d.ts +39 -39
- package/lib/dropdown/dropdown.html +21 -21
- package/lib/dropdown/dropdown.js +120 -120
- package/lib/dropdown/index.d.ts +1 -1
- package/lib/dropdown/index.js +3 -3
- package/lib/dropdown-menu/dropdown-menu-action.component.d.ts +22 -22
- package/lib/dropdown-menu/dropdown-menu-action.component.html +27 -27
- package/lib/dropdown-menu/dropdown-menu-action.component.js +89 -89
- package/lib/dropdown-menu/dropdown-menu-contents.d.ts +16 -16
- package/lib/dropdown-menu/dropdown-menu-contents.html +3 -3
- package/lib/dropdown-menu/dropdown-menu-contents.js +115 -115
- package/lib/dropdown-menu/dropdown-menu-header.d.ts +1 -1
- package/lib/dropdown-menu/dropdown-menu-header.html +1 -1
- package/lib/dropdown-menu/dropdown-menu-header.js +15 -15
- package/lib/dropdown-menu/dropdown-menu-item.d.ts +1 -1
- package/lib/dropdown-menu/dropdown-menu-item.html +1 -1
- package/lib/dropdown-menu/dropdown-menu-item.js +15 -15
- package/lib/dropdown-menu/dropdown-menu-note.d.ts +1 -1
- package/lib/dropdown-menu/dropdown-menu-note.html +1 -1
- package/lib/dropdown-menu/dropdown-menu-note.js +15 -15
- package/lib/dropdown-menu/dropdown-menu-separator.d.ts +1 -1
- package/lib/dropdown-menu/dropdown-menu-separator.html +1 -1
- package/lib/dropdown-menu/dropdown-menu-separator.js +14 -14
- package/lib/dropdown-menu/dropdown-menu-toggle.d.ts +1 -1
- package/lib/dropdown-menu/dropdown-menu-toggle.js +67 -67
- package/lib/dropdown-menu/dropdown-menu.d.ts +22 -22
- package/lib/dropdown-menu/dropdown-menu.html +1 -1
- package/lib/dropdown-menu/dropdown-menu.js +108 -108
- package/lib/dropdown-menu/index.d.ts +8 -8
- package/lib/dropdown-menu/index.js +10 -10
- package/lib/feedback/clipboard.service.d.ts +12 -12
- package/lib/feedback/clipboard.service.js +51 -51
- package/lib/feedback/feedback.component.d.ts +31 -31
- package/lib/feedback/feedback.component.html +32 -32
- package/lib/feedback/feedback.component.js +102 -102
- package/lib/feedback/feedback.service.d.ts +35 -35
- package/lib/feedback/feedback.service.js +67 -67
- package/lib/feedback/index.d.ts +3 -3
- package/lib/feedback/index.js +5 -5
- package/lib/first-time-motivator/first-time-motivator-transclude.html +1 -1
- package/lib/first-time-motivator/first-time-motivator.d.ts +1 -1
- package/lib/first-time-motivator/first-time-motivator.html +29 -29
- package/lib/first-time-motivator/first-time-motivator.js +282 -282
- package/lib/first-time-motivator/ftm-target-element.d.ts +1 -1
- package/lib/first-time-motivator/ftm-target-element.js +70 -70
- package/lib/first-time-motivator/index.d.ts +2 -2
- package/lib/first-time-motivator/index.js +4 -4
- package/lib/font-selector/font-selector.d.ts +62 -62
- package/lib/font-selector/font-selector.html +67 -67
- package/lib/font-selector/font-selector.js +261 -261
- package/lib/font-selector/google-webfonts-api.service.d.ts +12 -12
- package/lib/font-selector/google-webfonts-api.service.js +64 -64
- package/lib/font-selector/index.d.ts +3 -3
- package/lib/font-selector/index.js +5 -5
- package/lib/font-selector/webfont-loader.service.d.ts +4 -4
- package/lib/font-selector/webfont-loader.service.js +59 -59
- package/lib/font-weight-selector/font-weight-selector.d.ts +32 -32
- package/lib/font-weight-selector/font-weight-selector.html +29 -29
- package/lib/font-weight-selector/font-weight-selector.js +164 -164
- package/lib/font-weight-selector/index.d.ts +1 -1
- package/lib/font-weight-selector/index.js +3 -3
- package/lib/footer/footer.d.ts +1 -1
- package/lib/footer/footer.html +6 -6
- package/lib/footer/footer.js +24 -24
- package/lib/footer/index.d.ts +1 -1
- package/lib/footer/index.js +3 -3
- package/lib/form-validation-utils/form-validation-utils.d.ts +5 -5
- package/lib/form-validation-utils/form-validation-utils.js +13 -13
- package/lib/form-validation-utils/index.d.ts +1 -1
- package/lib/form-validation-utils/index.js +3 -3
- package/lib/full-screen/full-screen.service.d.ts +13 -13
- package/lib/full-screen/full-screen.service.js +68 -68
- package/lib/full-screen/index.d.ts +1 -1
- package/lib/full-screen/index.js +3 -3
- package/lib/gesture-handler/gesture-handler.d.ts +1 -1
- package/lib/gesture-handler/gesture-handler.js +97 -97
- package/lib/gesture-handler/index.d.ts +1 -1
- package/lib/gesture-handler/index.js +3 -3
- package/lib/hierarchy/hierarchy.d.ts +1 -1
- package/lib/hierarchy/hierarchy.html +38 -38
- package/lib/hierarchy/hierarchy.js +27 -27
- package/lib/hierarchy/index.d.ts +1 -1
- package/lib/hierarchy/index.js +3 -3
- package/lib/hover-tooltip/hover-tooltip.d.ts +1 -1
- package/lib/hover-tooltip/hover-tooltip.js +116 -116
- package/lib/hover-tooltip/index.d.ts +1 -1
- package/lib/hover-tooltip/index.js +3 -3
- package/lib/icon/icon.d.ts +1 -1
- package/lib/icon/icon.html +1 -1
- package/lib/icon/icon.js +30 -30
- package/lib/icon/icon.service.d.ts +4 -4
- package/lib/icon/icon.service.js +77 -77
- package/lib/icon/index.d.ts +2 -2
- package/lib/icon/index.js +4 -4
- package/lib/index.d.ts +48 -48
- package/lib/index.js +50 -50
- package/lib/inline-text-input/index.d.ts +1 -1
- package/lib/inline-text-input/index.js +3 -3
- package/lib/inline-text-input/inline-text-input.component.d.ts +3 -3
- package/lib/inline-text-input/inline-text-input.component.html +13 -13
- package/lib/inline-text-input/inline-text-input.component.js +25 -25
- package/lib/jsui.module.css +494 -494
- package/lib/loading-indicator/index.d.ts +1 -1
- package/lib/loading-indicator/index.js +3 -3
- package/lib/loading-indicator/loading-indicator.component.d.ts +3 -3
- package/lib/loading-indicator/loading-indicator.component.html +12 -12
- package/lib/loading-indicator/loading-indicator.component.js +25 -25
- package/lib/localization/index.strings.json +59 -59
- package/lib/login-textinput/index.d.ts +1 -1
- package/lib/login-textinput/index.js +3 -3
- package/lib/login-textinput/login-textinput.d.ts +1 -1
- package/lib/login-textinput/login-textinput.html +14 -14
- package/lib/login-textinput/login-textinput.js +28 -28
- package/lib/metadata-form/index.d.ts +10 -10
- package/lib/metadata-form/index.js +13 -13
- package/lib/metadata-form/metadata-form.component.d.ts +97 -97
- package/lib/metadata-form/metadata-form.component.js +289 -289
- package/lib/metadata-form/metadata-form.html +551 -551
- package/lib/metadata-form/template-cache.run.d.ts +1 -1
- package/lib/metadata-form/template-cache.run.js +10 -10
- package/lib/metadata-form/typeahead-match.template.html +3 -3
- package/lib/modal/index.d.ts +2 -2
- package/lib/modal/index.js +4 -4
- package/lib/modal/modal.component.d.ts +41 -43
- package/lib/modal/modal.component.html +39 -41
- package/lib/modal/modal.component.js +168 -187
- package/lib/modal/modal.component.js.map +1 -1
- package/lib/modal/modal.service.d.ts +55 -55
- package/lib/modal/modal.service.js +157 -157
- package/lib/on-media-error/index.d.ts +1 -1
- package/lib/on-media-error/index.js +3 -3
- package/lib/on-media-error/on-media-error.d.ts +1 -1
- package/lib/on-media-error/on-media-error.js +21 -21
- package/lib/page-thumbnail/index.d.ts +1 -1
- package/lib/page-thumbnail/index.js +3 -3
- package/lib/page-thumbnail/page-thumbnail.d.ts +44 -44
- package/lib/page-thumbnail/page-thumbnail.js +107 -107
- package/lib/paging/index.d.ts +4 -4
- package/lib/paging/index.js +6 -6
- package/lib/paging/pager.d.ts +1 -1
- package/lib/paging/pager.html +24 -20
- package/lib/paging/pager.js +52 -52
- package/lib/paging/paging-factory.d.ts +1 -1
- package/lib/paging/paging-factory.js +29 -29
- package/lib/paging/paging-range-bottom.d.ts +1 -1
- package/lib/paging/paging-range-bottom.html +8 -8
- package/lib/paging/paging-range-bottom.js +41 -41
- package/lib/paging/paging-range-top.d.ts +1 -1
- package/lib/paging/paging-range-top.html +34 -34
- package/lib/paging/paging-range-top.js +32 -32
- package/lib/progress-bar/index.d.ts +1 -1
- package/lib/progress-bar/index.js +3 -3
- package/lib/progress-bar/progress-bar.component.d.ts +9 -9
- package/lib/progress-bar/progress-bar.component.js +40 -40
- package/lib/progress-bar/progress-bar.html +6 -6
- package/lib/progress-circle/index.d.ts +1 -1
- package/lib/progress-circle/index.js +3 -3
- package/lib/progress-circle/progress-circle.d.ts +10 -10
- package/lib/progress-circle/progress-circle.html +15 -15
- package/lib/progress-circle/progress-circle.js +45 -45
- package/lib/response-handlers/api-success-handlers.d.ts +4 -4
- package/lib/response-handlers/api-success-handlers.js +21 -21
- package/lib/response-handlers/error-response.service.d.ts +13 -13
- package/lib/response-handlers/error-response.service.js +50 -50
- package/lib/response-handlers/feedback-error-handler.d.ts +12 -12
- package/lib/response-handlers/feedback-error-handler.js +43 -43
- package/lib/response-handlers/index.d.ts +4 -4
- package/lib/response-handlers/index.js +6 -6
- package/lib/response-handlers/log-error-handler.d.ts +9 -9
- package/lib/response-handlers/log-error-handler.js +29 -29
- package/lib/rich-text/index.d.ts +2 -2
- package/lib/rich-text/index.js +4 -4
- package/lib/rich-text/rich-text.component.d.ts +120 -120
- package/lib/rich-text/rich-text.component.html +80 -80
- package/lib/rich-text/rich-text.component.js +632 -632
- package/lib/rich-text/rich-text.service.d.ts +40 -40
- package/lib/rich-text/rich-text.service.js +294 -294
- package/lib/site-header/default-background-img.b64.d.ts +2 -2
- package/lib/site-header/default-background-img.b64.js +1 -1
- package/lib/site-header/index.d.ts +2 -2
- package/lib/site-header/index.js +4 -4
- package/lib/site-header/site-header-navbar-item.component.d.ts +10 -10
- package/lib/site-header/site-header-navbar-item.component.html +12 -12
- package/lib/site-header/site-header-navbar-item.component.js +54 -54
- package/lib/site-header/site-header.component.d.ts +12 -12
- package/lib/site-header/site-header.component.html +28 -28
- package/lib/site-header/site-header.component.js +64 -64
- package/lib/style-typings/styles.d.ts +30 -30
- package/lib/style-typings/styles.js +2 -2
- package/lib/table-blank-slate/index.d.ts +1 -1
- package/lib/table-blank-slate/index.js +3 -3
- package/lib/table-blank-slate/table-blank-slate.d.ts +1 -1
- package/lib/table-blank-slate/table-blank-slate.html +16 -16
- package/lib/table-blank-slate/table-blank-slate.js +20 -20
- package/lib/tabs/index.d.ts +4 -4
- package/lib/tabs/index.js +6 -6
- package/lib/tabs/tab-group.d.ts +21 -21
- package/lib/tabs/tab-group.html +21 -21
- package/lib/tabs/tab-group.js +151 -151
- package/lib/tabs/tab-html-title-append.d.ts +1 -1
- package/lib/tabs/tab-html-title-append.js +17 -17
- package/lib/tabs/tab-html-title.d.ts +10 -10
- package/lib/tabs/tab-html-title.js +45 -45
- package/lib/tabs/tab.d.ts +18 -18
- package/lib/tabs/tab.html +2 -2
- package/lib/tabs/tab.js +70 -70
- package/lib/tag-input/index.d.ts +1 -1
- package/lib/tag-input/index.js +3 -3
- package/lib/tag-input/tag-input.component.d.ts +37 -37
- package/lib/tag-input/tag-input.component.js +143 -143
- package/lib/tag-input/tag-input.html +66 -66
- package/lib/textarea/index.d.ts +1 -1
- package/lib/textarea/index.js +3 -3
- package/lib/textarea/textarea.d.ts +1 -1
- package/lib/textarea/textarea.html +16 -16
- package/lib/textarea/textarea.js +30 -30
- package/lib/textinput/index.d.ts +1 -1
- package/lib/textinput/index.js +3 -3
- package/lib/textinput/textinput.d.ts +1 -1
- package/lib/textinput/textinput.html +33 -33
- package/lib/textinput/textinput.js +51 -51
- package/lib/theme/index.d.ts +1 -1
- package/lib/theme/index.js +3 -3
- package/lib/theme/theme.service.d.ts +11 -11
- package/lib/theme/theme.service.js +69 -69
- package/lib/theme/theme.typings.d.ts +1 -1
- package/lib/theme/theme.typings.js +2 -2
- package/lib/time-input/index.d.ts +2 -2
- package/lib/time-input/index.js +4 -4
- package/lib/time-input/time-input.d.ts +1 -1
- package/lib/time-input/time-input.html +47 -47
- package/lib/time-input/time-input.js +136 -136
- package/lib/time-input/validate-time.d.ts +1 -1
- package/lib/time-input/validate-time.js +31 -31
- package/lib/translate/index.d.ts +1 -1
- package/lib/translate/index.js +3 -3
- package/lib/translate/translate-factory.d.ts +3 -3
- package/lib/translate/translate-factory.js +37 -37
- package/lib/tree/index.d.ts +3 -3
- package/lib/tree/index.js +5 -5
- package/lib/tree/recursion-factory.d.ts +1 -1
- package/lib/tree/recursion-factory.js +45 -45
- package/lib/tree/tree-node.d.ts +1 -1
- package/lib/tree/tree-node.html +56 -56
- package/lib/tree/tree-node.js +29 -29
- package/lib/tree/tree.d.ts +1 -1
- package/lib/tree/tree.html +27 -27
- package/lib/tree/tree.js +89 -89
- package/lib/tsconfig.deploy.tsbuildinfo +282 -282
- package/lib/type-string/index.d.ts +1 -1
- package/lib/type-string/index.js +3 -3
- package/lib/type-string/type-string.component.d.ts +11 -11
- package/lib/type-string/type-string.component.html +1 -1
- package/lib/type-string/type-string.component.js +76 -76
- package/lib/url-modification/index.d.ts +1 -1
- package/lib/url-modification/index.js +3 -3
- package/lib/url-modification/url-modification.service.d.ts +3 -3
- package/lib/url-modification/url-modification.service.js +38 -38
- package/package.json +116 -116
- package/src/components/actionable-empty-state/actionable-empty-state.html +15 -15
- package/src/components/actionable-empty-state/actionable-empty-state.less +19 -19
- package/src/components/actionable-empty-state/actionable-empty-state.ts +36 -36
- package/src/components/actionable-empty-state/index.ts +1 -1
- package/src/components/auto-complete/auto-complete-match-renderer.component.html +20 -20
- package/src/components/auto-complete/auto-complete-match-renderer.component.ts +241 -241
- package/src/components/auto-complete/auto-complete.component.html +43 -43
- package/src/components/auto-complete/auto-complete.component.less +66 -66
- package/src/components/auto-complete/auto-complete.component.ts +70 -70
- package/src/components/auto-complete/index.ts +2 -2
- package/src/components/auto-focus/auto-focus.service.ts +24 -24
- package/src/components/auto-focus/auto-focus.ts +13 -13
- package/src/components/auto-focus/index.ts +2 -2
- package/src/components/badge/badge.html +3 -3
- package/src/components/badge/badge.less +47 -47
- package/src/components/badge/badge.ts +14 -14
- package/src/components/badge/index.ts +1 -1
- package/src/components/checkbox/checkbox.html +23 -23
- package/src/components/checkbox/checkbox.js +29 -29
- package/src/components/checkbox/index.ts +1 -1
- package/src/components/collapse/collapse.js +86 -86
- package/src/components/collapse/collapse.less +17 -17
- package/src/components/collapse/index.ts +1 -1
- package/src/components/color-input/color-input.html +32 -32
- package/src/components/color-input/color-input.less +623 -623
- package/src/components/color-input/color-input.ts +95 -95
- package/src/components/color-input/index.ts +2 -2
- package/src/components/color-input/spectrum-color-picker.js +59 -59
- package/src/components/color-utils/color-utils.service.ts +34 -34
- package/src/components/color-utils/index.ts +1 -1
- package/src/components/constants/constants.js +8 -8
- package/src/components/constants/index.ts +1 -1
- package/src/components/date-input/date-input.html +31 -31
- package/src/components/date-input/date-input.js +134 -134
- package/src/components/date-input/date-input.less +20 -20
- package/src/components/date-input/index.ts +2 -2
- package/src/components/date-input/validate-date.js +36 -36
- package/src/components/date-time-zone-picker/date-time-zone-factory.ts +135 -135
- package/src/components/date-time-zone-picker/date-time-zone-picker.html +36 -36
- package/src/components/date-time-zone-picker/date-time-zone-picker.less +55 -55
- package/src/components/date-time-zone-picker/date-time-zone-picker.ts +220 -220
- package/src/components/date-time-zone-picker/datepicker.html +30 -30
- package/src/components/date-time-zone-picker/datepicker.ts +230 -230
- package/src/components/date-time-zone-picker/index.ts +6 -6
- package/src/components/date-time-zone-picker/time-format-filter.ts +60 -60
- package/src/components/date-time-zone-picker/time-zone-picker.html +21 -21
- package/src/components/date-time-zone-picker/time-zone-picker.js +45 -45
- package/src/components/date-time-zone-picker/timepicker.html +31 -31
- package/src/components/date-time-zone-picker/timepicker.js +114 -114
- package/src/components/decorators/index.ts +82 -82
- package/src/components/dropdown/dropdown.html +21 -21
- package/src/components/dropdown/dropdown.less +67 -67
- package/src/components/dropdown/dropdown.ts +97 -97
- package/src/components/dropdown/index.ts +1 -1
- package/src/components/dropdown-menu/dropdown-menu-action.component.html +27 -27
- package/src/components/dropdown-menu/dropdown-menu-action.component.ts +71 -71
- package/src/components/dropdown-menu/dropdown-menu-contents.html +3 -3
- package/src/components/dropdown-menu/dropdown-menu-contents.ts +120 -120
- package/src/components/dropdown-menu/dropdown-menu-header.html +1 -1
- package/src/components/dropdown-menu/dropdown-menu-header.js +12 -12
- package/src/components/dropdown-menu/dropdown-menu-item.html +1 -1
- package/src/components/dropdown-menu/dropdown-menu-item.js +12 -12
- package/src/components/dropdown-menu/dropdown-menu-note.html +1 -1
- package/src/components/dropdown-menu/dropdown-menu-note.js +12 -12
- package/src/components/dropdown-menu/dropdown-menu-separator.html +1 -1
- package/src/components/dropdown-menu/dropdown-menu-separator.js +11 -11
- package/src/components/dropdown-menu/dropdown-menu-toggle.js +82 -82
- package/src/components/dropdown-menu/dropdown-menu.html +1 -1
- package/src/components/dropdown-menu/dropdown-menu.less +141 -141
- package/src/components/dropdown-menu/dropdown-menu.ts +85 -85
- package/src/components/dropdown-menu/index.ts +8 -8
- package/src/components/feedback/clipboard.service.ts +29 -29
- package/src/components/feedback/feedback.component.html +32 -32
- package/src/components/feedback/feedback.component.ts +110 -110
- package/src/components/feedback/feedback.less +137 -137
- package/src/components/feedback/feedback.service.ts +51 -51
- package/src/components/feedback/index.ts +3 -3
- package/src/components/first-time-motivator/first-time-motivator-transclude.html +1 -1
- package/src/components/first-time-motivator/first-time-motivator.html +29 -29
- package/src/components/first-time-motivator/first-time-motivator.less +151 -151
- package/src/components/first-time-motivator/first-time-motivator.ts +337 -337
- package/src/components/first-time-motivator/ftm-target-element.ts +98 -98
- package/src/components/first-time-motivator/index.ts +2 -2
- package/src/components/font-selector/font-selector.html +67 -67
- package/src/components/font-selector/font-selector.less +122 -122
- package/src/components/font-selector/font-selector.ts +274 -274
- package/src/components/font-selector/google-webfonts-api.backend.ts +5 -5
- package/src/components/font-selector/google-webfonts-api.service.ts +46 -46
- package/src/components/font-selector/index.ts +3 -3
- package/src/components/font-selector/webfont-loader.service.ts +54 -54
- package/src/components/font-weight-selector/font-weight-selector.html +29 -29
- package/src/components/font-weight-selector/font-weight-selector.less +52 -52
- package/src/components/font-weight-selector/font-weight-selector.ts +151 -151
- package/src/components/font-weight-selector/index.ts +1 -1
- package/src/components/footer/footer.html +6 -6
- package/src/components/footer/footer.js +21 -21
- package/src/components/footer/footer.less +9 -9
- package/src/components/footer/index.ts +1 -1
- package/src/components/form-validation-utils/form-validation-utils.ts +11 -11
- package/src/components/form-validation-utils/index.ts +1 -1
- package/src/components/full-screen/full-screen.service.ts +62 -62
- package/src/components/full-screen/index.ts +1 -1
- package/src/components/gesture-handler/gesture-handler.ts +116 -116
- package/src/components/gesture-handler/index.ts +1 -1
- package/src/components/gesture-handler/test/gesture-handler.spec.js +26 -26
- package/src/components/hierarchy/hierarchy.html +38 -38
- package/src/components/hierarchy/hierarchy.js +24 -24
- package/src/components/hierarchy/hierarchy.less +42 -42
- package/src/components/hierarchy/index.ts +1 -1
- package/src/components/hover-tooltip/hover-tooltip.less +85 -85
- package/src/components/hover-tooltip/hover-tooltip.ts +145 -145
- package/src/components/hover-tooltip/index.ts +1 -1
- package/src/components/icon/icon.html +1 -1
- package/src/components/icon/icon.service.ts +70 -70
- package/src/components/icon/icon.ts +34 -34
- package/src/components/icon/index.ts +2 -2
- package/src/components/index.less +35 -35
- package/src/components/index.ts +48 -48
- package/src/components/inline-text-input/index.ts +1 -1
- package/src/components/inline-text-input/inline-text-input.component.html +13 -13
- package/src/components/inline-text-input/inline-text-input.component.ts +10 -10
- package/src/components/inline-text-input/inline-text-input.less +17 -17
- package/src/components/legacy/mediafly-bootstrap.css +2890 -2890
- package/src/components/legacy/mediafly-utils.js +15 -15
- package/src/components/legacy/mediafly.css +2323 -2323
- package/src/components/legacy/oocss.css +77 -77
- package/src/components/less/fonts/font-awesome.less +7146 -7146
- package/src/components/less/fonts/index.less +4 -4
- package/src/components/less/fonts/mfly-webfont.less +93 -93
- package/src/components/less/fonts/poppins.less +26 -26
- package/src/components/less/fonts/roboto.less +38 -38
- package/src/components/less/mixins/vendor-prefixes.less +287 -287
- package/src/components/less/objects/buttons.less +277 -277
- package/src/components/less/objects/buttons.module.css +198 -198
- package/src/components/less/objects/containers.less +244 -244
- package/src/components/less/objects/containers.module.css +18 -18
- package/src/components/less/objects/forms.less +203 -203
- package/src/components/less/objects/grid.less +985 -985
- package/src/components/less/objects/headers.less +81 -81
- package/src/components/less/objects/headers.module.css +85 -85
- package/src/components/less/objects/index.less +11 -11
- package/src/components/less/objects/labels.less +26 -26
- package/src/components/less/objects/links.less +58 -58
- package/src/components/less/objects/links.module.css +57 -57
- package/src/components/less/objects/modals.less +40 -40
- package/src/components/less/objects/radios-checkboxes.less +234 -234
- package/src/components/less/objects/tables.less +237 -237
- package/src/components/less/objects/tabs.less +28 -28
- package/src/components/less/standalone.less +8 -8
- package/src/components/less/utilities/accessibility.less +39 -39
- package/src/components/less/utilities/animations.less +41 -41
- package/src/components/less/utilities/grid-utilities.less +115 -115
- package/src/components/less/utilities/index.less +6 -6
- package/src/components/less/utilities/normalize.less +344 -344
- package/src/components/less/utilities/reset.less +52 -52
- package/src/components/less/utilities/utilities.less +173 -173
- package/src/components/less/variables/colors.less +70 -70
- package/src/components/less/variables/effects.less +17 -17
- package/src/components/less/variables/forms.less +16 -16
- package/src/components/less/variables/index.less +6 -6
- package/src/components/less/variables/pages.less +25 -25
- package/src/components/less/variables/typography.less +19 -19
- package/src/components/less/variables/z-index.less +24 -24
- package/src/components/less/variables.module.css +132 -132
- package/src/components/less/vendor/index.less +2 -2
- package/src/components/less/vendor/pikaday.css +225 -225
- package/src/components/less/vendor/quill.snow.css +10 -10
- package/src/components/loading-indicator/index.ts +1 -1
- package/src/components/loading-indicator/loading-indicator.component.html +12 -12
- package/src/components/loading-indicator/loading-indicator.component.ts +10 -10
- package/src/components/loading-indicator/loading-indicator.less +62 -62
- package/src/components/localization/index.strings.json +59 -59
- package/src/components/login-textinput/index.ts +1 -1
- package/src/components/login-textinput/login-textinput.html +14 -14
- package/src/components/login-textinput/login-textinput.js +26 -26
- package/src/components/metadata-form/index.ts +12 -12
- package/src/components/metadata-form/metadata-form.component.ts +354 -354
- package/src/components/metadata-form/metadata-form.html +551 -551
- package/src/components/metadata-form/metadata-form.less +153 -153
- package/src/components/metadata-form/template-cache.run.ts +8 -8
- package/src/components/metadata-form/typeahead-match.template.html +3 -3
- package/src/components/modal/index.ts +2 -2
- package/src/components/modal/modal.component.html +39 -41
- package/src/components/modal/modal.component.less +136 -136
- package/src/components/modal/modal.component.module.css +126 -126
- package/src/components/modal/modal.component.ts +171 -190
- package/src/components/modal/modal.service.ts +169 -169
- package/src/components/on-media-error/index.ts +1 -1
- package/src/components/on-media-error/on-media-error.js +23 -23
- package/src/components/page-thumbnail/index.ts +1 -1
- package/src/components/page-thumbnail/page-thumbnail.ts +159 -159
- package/src/components/paging/index.ts +4 -4
- package/src/components/paging/pager.html +24 -20
- package/src/components/paging/pager.js +63 -63
- package/src/components/paging/paging-factory.js +36 -36
- package/src/components/paging/paging-range-bottom.html +8 -8
- package/src/components/paging/paging-range-bottom.js +50 -50
- package/src/components/paging/paging-range-top.html +34 -34
- package/src/components/paging/paging-range-top.js +36 -36
- package/src/components/paging/paging.less +36 -36
- package/src/components/progress-bar/index.ts +1 -1
- package/src/components/progress-bar/progress-bar.component.ts +28 -28
- package/src/components/progress-bar/progress-bar.html +6 -6
- package/src/components/progress-bar/progress-bar.less +24 -24
- package/src/components/progress-circle/index.ts +1 -1
- package/src/components/progress-circle/progress-circle.html +15 -15
- package/src/components/progress-circle/progress-circle.less +146 -146
- package/src/components/progress-circle/progress-circle.ts +30 -30
- package/src/components/response-handlers/api-success-handlers.ts +14 -14
- package/src/components/response-handlers/error-response.service.ts +40 -40
- package/src/components/response-handlers/feedback-error-handler.ts +25 -25
- package/src/components/response-handlers/index.ts +4 -4
- package/src/components/response-handlers/log-error-handler.ts +15 -15
- package/src/components/rich-text/index.ts +2 -2
- package/src/components/rich-text/rich-text.component.html +80 -80
- package/src/components/rich-text/rich-text.component.less +165 -165
- package/src/components/rich-text/rich-text.component.ts +710 -710
- package/src/components/rich-text/rich-text.service.ts +333 -333
- package/src/components/site-header/default-background-img.b64.js +1 -1
- package/src/components/site-header/index.ts +2 -2
- package/src/components/site-header/site-header-navbar-item.component.html +12 -12
- package/src/components/site-header/site-header-navbar-item.component.ts +24 -24
- package/src/components/site-header/site-header.component.html +28 -28
- package/src/components/site-header/site-header.component.ts +30 -30
- package/src/components/site-header/site-header.less +196 -196
- package/src/components/style-typings/styles.ts +37 -37
- package/src/components/table-blank-slate/index.ts +1 -1
- package/src/components/table-blank-slate/table-blank-slate.html +16 -16
- package/src/components/table-blank-slate/table-blank-slate.js +17 -17
- package/src/components/table-blank-slate/table-blank-slate.less +22 -22
- package/src/components/tabs/index.ts +4 -4
- package/src/components/tabs/tab-group.html +21 -21
- package/src/components/tabs/tab-group.ts +160 -160
- package/src/components/tabs/tab-html-title-append.ts +17 -17
- package/src/components/tabs/tab-html-title.ts +33 -33
- package/src/components/tabs/tab.html +2 -2
- package/src/components/tabs/tab.ts +56 -56
- package/src/components/tabs/tabs.less +44 -44
- package/src/components/tag-input/index.ts +1 -1
- package/src/components/tag-input/tag-input.component.ts +136 -136
- package/src/components/tag-input/tag-input.html +66 -66
- package/src/components/tag-input/tag-input.less +107 -107
- package/src/components/textarea/index.ts +1 -1
- package/src/components/textarea/textarea.html +16 -16
- package/src/components/textarea/textarea.js +30 -30
- package/src/components/textinput/index.ts +1 -1
- package/src/components/textinput/textinput.html +33 -33
- package/src/components/textinput/textinput.ts +54 -54
- package/src/components/theme/index.ts +1 -1
- package/src/components/theme/theme.service.ts +71 -71
- package/src/components/theme/theme.typings.ts +3 -3
- package/src/components/time-input/index.ts +2 -2
- package/src/components/time-input/time-input.html +47 -47
- package/src/components/time-input/time-input.js +163 -163
- package/src/components/time-input/time-input.less +25 -25
- package/src/components/time-input/validate-time.js +33 -33
- package/src/components/translate/index.ts +1 -1
- package/src/components/translate/translate-factory.ts +49 -49
- package/src/components/tree/index.ts +3 -3
- package/src/components/tree/recursion-factory.js +43 -43
- package/src/components/tree/tree-node.html +56 -56
- package/src/components/tree/tree-node.js +30 -30
- package/src/components/tree/tree.html +27 -27
- package/src/components/tree/tree.less +117 -117
- package/src/components/tree/tree.ts +108 -108
- package/src/components/type-string/index.ts +1 -1
- package/src/components/type-string/type-string.component.html +1 -1
- package/src/components/type-string/type-string.component.ts +63 -63
- package/src/components/url-modification/index.ts +1 -1
- package/src/components/url-modification/url-modification.service.ts +33 -33
- package/src/index.html +90 -90
- package/src/index.js +23 -23
- package/src/index.less +16 -16
- package/src/index.spec.js +39 -39
- package/stylelint.config.js +8 -8
- package/tsconfig.deploy.json +29 -29
- package/tsconfig.json +34 -34
- package/tslint.json +4 -4
- package/typings/index.d.ts +46 -46
- package/webpack.config.js +234 -234
- package/.certs/ca.crt +0 -33
- package/.certs/localhost.crt +0 -34
- package/.certs/localhost.key +0 -27
- package/.certs/localhost.pfx +0 -0
|
@@ -1,710 +1,710 @@
|
|
|
1
|
-
// tslint:disable: max-file-line-count
|
|
2
|
-
import _ from 'lodash'
|
|
3
|
-
import Quill, { Parchment, Range } from 'quill'
|
|
4
|
-
import { Delta, EmitterSource } from 'quill/core'
|
|
5
|
-
import { Component, Inject, Input } from '../decorators'
|
|
6
|
-
import type { TranslateFactory } from '../translate/translate-factory'
|
|
7
|
-
import { v4 as uuidv4 } from 'uuid'
|
|
8
|
-
import RichTextService from './rich-text.service'
|
|
9
|
-
import { IComponentController } from 'angular'
|
|
10
|
-
import { StyleAttributor, Scope } from 'parchment'
|
|
11
|
-
import GoogleWebfontsApiService from '../font-selector/google-webfonts-api.service'
|
|
12
|
-
|
|
13
|
-
@Component({
|
|
14
|
-
selector: 'richText',
|
|
15
|
-
require: {
|
|
16
|
-
ngModelCtrl: 'ngModel',
|
|
17
|
-
},
|
|
18
|
-
template: require('./rich-text.component.html'),
|
|
19
|
-
})
|
|
20
|
-
export default class RichTextComponentController implements IComponentController {
|
|
21
|
-
|
|
22
|
-
@Input() allowColorSelection?: boolean
|
|
23
|
-
@Input() allowFontSelection?: boolean
|
|
24
|
-
@Input() allowImages?: boolean
|
|
25
|
-
@Input() isRequired!: boolean
|
|
26
|
-
|
|
27
|
-
protected cachedSelection?: Range | null
|
|
28
|
-
protected colorInputId: string
|
|
29
|
-
protected editorSizeId: string
|
|
30
|
-
protected fontSelectorId: string
|
|
31
|
-
protected requiredText: string
|
|
32
|
-
protected selectedColor: string
|
|
33
|
-
protected selectedFont: string
|
|
34
|
-
protected fontWeightOptions: string[] = []
|
|
35
|
-
protected fontWeightOptionsCache: Map<string, string[]> = new Map()
|
|
36
|
-
protected selectedFontWeight: string
|
|
37
|
-
protected toolbarId: string
|
|
38
|
-
protected validationForm: ng.IFormController
|
|
39
|
-
|
|
40
|
-
private colorPicker: HTMLElement | null
|
|
41
|
-
private editor: Quill
|
|
42
|
-
private ngModelCtrl: ng.INgModelController
|
|
43
|
-
|
|
44
|
-
private debouncedSanitizeAndValidate = _.debounce(() => this.sanitizeAndValidate(), 250)
|
|
45
|
-
|
|
46
|
-
private DEFAULT_COLOR = '#535353'
|
|
47
|
-
private DEFAULT_FONT = 'Roboto'
|
|
48
|
-
private DEFAULT_SIZE = '14px'
|
|
49
|
-
private DEFAULT_WEIGHT = '400'
|
|
50
|
-
|
|
51
|
-
private HEADING_1_COLOR = '#535353'
|
|
52
|
-
private HEADING_1_FONT = 'Poppins'
|
|
53
|
-
private HEADING_1_SIZE = '24px'
|
|
54
|
-
|
|
55
|
-
private HEADING_2_COLOR = '#535353'
|
|
56
|
-
private HEADING_2_FONT = 'Poppins'
|
|
57
|
-
private HEADING_2_SIZE = '20px'
|
|
58
|
-
|
|
59
|
-
private UNIVERSAL_FONT_WEIGHTS = ['400', '700']
|
|
60
|
-
|
|
61
|
-
constructor(
|
|
62
|
-
@Inject('$element') private $element: ng.IAugmentedJQuery,
|
|
63
|
-
@Inject('$rootScope') private $rootScope: JSUIRootScope,
|
|
64
|
-
@Inject('$timeout') private $timeout: ng.ITimeoutService,
|
|
65
|
-
@Inject('$q') private $q: ng.IQService,
|
|
66
|
-
@Inject('googleWebfontsApiService') private googleWebfontsApiService: GoogleWebfontsApiService,
|
|
67
|
-
@Inject('richTextService') private richTextService: RichTextService,
|
|
68
|
-
@Inject('translateFactory') private translateFactory: TranslateFactory,
|
|
69
|
-
) { }
|
|
70
|
-
|
|
71
|
-
$onChanges(changes: { isRequired?: ng.IChangesObject<boolean> }) {
|
|
72
|
-
|
|
73
|
-
if (!changes.isRequired) { return }
|
|
74
|
-
if (changes.isRequired.currentValue === changes.isRequired.previousValue) { return }
|
|
75
|
-
|
|
76
|
-
this.checkValidity()
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
$onDestroy() {
|
|
80
|
-
|
|
81
|
-
this.editor.off('text-change', (delta: Delta, oldContents, source) => { this.onTextChange(delta, oldContents, source) })
|
|
82
|
-
this.colorPicker?.removeEventListener('change', this.colorChanged.bind(this))
|
|
83
|
-
this.colorPicker?.removeEventListener('click', this.colorInputOpened.bind(this))
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
$onInit() {
|
|
87
|
-
|
|
88
|
-
this.requiredText = this.translateFactory.instant('JSUI.REQUIRED')
|
|
89
|
-
|
|
90
|
-
this.colorInputId = 'rteColorInput-' + uuidv4()
|
|
91
|
-
this.editorSizeId = 'rteEditorSize-' + uuidv4()
|
|
92
|
-
this.fontSelectorId = 'rteFontSelector-' + uuidv4()
|
|
93
|
-
this.toolbarId = 'rteToolbar-' + uuidv4()
|
|
94
|
-
|
|
95
|
-
// Populate the available font weights for the default font
|
|
96
|
-
if (this.allowFontSelection) {
|
|
97
|
-
this.updateAvailableFontWeights([this.DEFAULT_FONT])
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
this.$timeout(() => {
|
|
101
|
-
this.colorPicker = document.getElementById(this.colorInputId)
|
|
102
|
-
this.colorPicker?.addEventListener('change', this.colorChanged.bind(this))
|
|
103
|
-
this.colorPicker?.addEventListener('click', this.colorInputOpened.bind(this))
|
|
104
|
-
|
|
105
|
-
this.updateFontPicker(this.DEFAULT_FONT)
|
|
106
|
-
this.updateFontWeightPicker(this.DEFAULT_WEIGHT)
|
|
107
|
-
this.updateSizePicker(this.DEFAULT_SIZE)
|
|
108
|
-
this.updateColorPicker(this.DEFAULT_COLOR)
|
|
109
|
-
})
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
$postLink() {
|
|
113
|
-
|
|
114
|
-
Quill.register(Quill.import('attributors/class/background') as Parchment.Attributor, true)
|
|
115
|
-
Quill.register(Quill.import('attributors/style/color') as Parchment.Attributor, true)
|
|
116
|
-
Quill.register(new StyleAttributor('font-weight', 'font-weight', { scope: Scope.INLINE }), true)
|
|
117
|
-
|
|
118
|
-
const fontStyle = Quill.import('attributors/style/font') as Parchment.Attributor
|
|
119
|
-
// Setting the whitelist to undefined allows all fonts. (We don't know what fonts Google Fonts will give us.)
|
|
120
|
-
fontStyle.whitelist = undefined
|
|
121
|
-
Quill.register(fontStyle, true)
|
|
122
|
-
|
|
123
|
-
const fontSizeArr = ['6px', '7px', '8px', '9px', '10px', '11px', '12px', '14px', '16px', '18px', '20px', '21px', '24px', '28px', '32px', '36px', '48px', '60px']
|
|
124
|
-
const size = Quill.import('attributors/style/size') as Parchment.Attributor
|
|
125
|
-
size.whitelist = fontSizeArr
|
|
126
|
-
Quill.register(size, true)
|
|
127
|
-
|
|
128
|
-
const options = {
|
|
129
|
-
modules: {
|
|
130
|
-
toolbar: `#${this.toolbarId}`,
|
|
131
|
-
},
|
|
132
|
-
theme: 'snow',
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
this.$timeout(() => {
|
|
136
|
-
this.editor = new Quill(this.$element.find('.js-rich-text-target')[0], options)
|
|
137
|
-
|
|
138
|
-
// Disable spellcheck because of a bad bug that deletes text (CE-4692).
|
|
139
|
-
this.editor.root.setAttribute('spellcheck', 'false')
|
|
140
|
-
|
|
141
|
-
this.editor.on('text-change', (delta: Delta, oldContents, source) => { this.onTextChange(delta, oldContents, source) })
|
|
142
|
-
this.editor.on('selection-change', this.selectionChange.bind(this))
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
this.ngModelCtrl.$render = () => {
|
|
146
|
-
this.$timeout(() => {
|
|
147
|
-
if (!this.ngModelCtrl.$viewValue) {
|
|
148
|
-
this.editor.setText('\n')
|
|
149
|
-
return
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
this.editor.root.innerHTML = this.richTextService.backwardsCompatibleHtml(this.ngModelCtrl.$viewValue)
|
|
153
|
-
})
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
protected colorChanged() {
|
|
158
|
-
|
|
159
|
-
// Re-apply the text selection that was made before selecting a color,
|
|
160
|
-
// as the act of hiding some browsers' color inputs can change the selected text
|
|
161
|
-
if (this.cachedSelection) {
|
|
162
|
-
this.editor.setSelection(this.cachedSelection.index, this.cachedSelection.length)
|
|
163
|
-
}
|
|
164
|
-
this.editor.format('color', this.selectedColor)
|
|
165
|
-
this.debouncedSanitizeAndValidate()
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
protected colorInputOpened() {
|
|
169
|
-
|
|
170
|
-
this.cachedSelection = this.editor.getSelection()
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
protected fontSelected(fontFamily: string, fontWeightOptions?: string[]): void {
|
|
174
|
-
|
|
175
|
-
if (!fontFamily) { return }
|
|
176
|
-
|
|
177
|
-
this.$rootScope.$broadcast('richTextToolbarContainer:closeContainer')
|
|
178
|
-
this.editor.format('font', `"${fontFamily}"`)
|
|
179
|
-
|
|
180
|
-
this.fontWeightOptionsCache.set(fontFamily, fontWeightOptions || [])
|
|
181
|
-
this.updateAvailableFontWeights([fontFamily])
|
|
182
|
-
|
|
183
|
-
if (![...(fontWeightOptions || []), ...this.UNIVERSAL_FONT_WEIGHTS].includes(this.selectedFontWeight)) {
|
|
184
|
-
this.selectedFontWeight = this.DEFAULT_WEIGHT
|
|
185
|
-
this.editor.format('font-weight', this.DEFAULT_WEIGHT)
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
this.debouncedSanitizeAndValidate()
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
protected fontWeightSelected(fontWeight: string): void {
|
|
192
|
-
this.selectedFontWeight = fontWeight
|
|
193
|
-
this.editor.format('font-weight', fontWeight)
|
|
194
|
-
|
|
195
|
-
this.debouncedSanitizeAndValidate()
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/** The user entered/deleted/modified some text. Handle any formatting issues, then store the model. */
|
|
199
|
-
protected onTextChange(delta: Delta, oldContents: Delta, source: EmitterSource): void {
|
|
200
|
-
|
|
201
|
-
if (source !== 'user') { return }
|
|
202
|
-
|
|
203
|
-
if (!this.allowImages && delta.ops.some(op => op.insert && typeof op.insert === 'object' && 'image' in op.insert)) {
|
|
204
|
-
// Don't allow images to be added in any way: pasted, drag-dropped, etc.
|
|
205
|
-
this.editor.history.undo()
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
this.$timeout(() => {
|
|
209
|
-
// In some cases, toggling Bold/Italic/Underline clears the font.
|
|
210
|
-
this.fixClearedFonts(oldContents, delta)
|
|
211
|
-
|
|
212
|
-
// When we choose "Heading 1" or "Heading 2", we also need to set the font, size, and color.
|
|
213
|
-
this.fixHeadingFormat(delta)
|
|
214
|
-
|
|
215
|
-
// Quill's "Clear formatting" button leaves us inheriting styles from the CSS. We want to keep things explicit.
|
|
216
|
-
this.fixClearFormatting(delta)
|
|
217
|
-
|
|
218
|
-
// Also, things like adding a line break can leave us with no style.
|
|
219
|
-
this.fixMissingFormats(delta)
|
|
220
|
-
})
|
|
221
|
-
|
|
222
|
-
this.debouncedSanitizeAndValidate()
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/** The user moved the cursor. Fix missing formats and update the toolbar to reflect the current selection. */
|
|
226
|
-
protected selectionChange(range: Range, _oldRange: Range, source: EmitterSource): void {
|
|
227
|
-
|
|
228
|
-
if (source !== 'user') { return }
|
|
229
|
-
if (!range) { return }
|
|
230
|
-
|
|
231
|
-
this.fixMissingFormats()
|
|
232
|
-
|
|
233
|
-
this.$timeout(() => {
|
|
234
|
-
// Quill updates the toolbar to reflect most formatting (bold, italics, bullet points, etc.), but
|
|
235
|
-
// fonts, text size, and color are handled by plugins so we need to update those ourselves.
|
|
236
|
-
const format = this.editor.getFormat(range)
|
|
237
|
-
this.updateFontPicker(this.getFontFromFormat(format))
|
|
238
|
-
this.updateFontWeightPicker(this.getFontWeightFromFormat(format))
|
|
239
|
-
this.updateColorPicker(this.getColorFromFormat(format))
|
|
240
|
-
this.updateSizePicker(this.getSizeFromFormat(format))
|
|
241
|
-
|
|
242
|
-
this.updateAvailableFontWeights(Array.isArray(format.font) ? format.font : [format.font])
|
|
243
|
-
})
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
private checkValidity(): void {
|
|
247
|
-
|
|
248
|
-
const isValid = !this.isRequired || !!this.ngModelCtrl.$viewValue
|
|
249
|
-
|
|
250
|
-
this.$timeout(() => {
|
|
251
|
-
this.ngModelCtrl.$setValidity('required', isValid)
|
|
252
|
-
})
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Quill's "Clear formatting" button leaves us with no font, size, or color, so the style is inherited from the CSS.
|
|
257
|
-
* We don't want that: we want everything to be fully defined, so that the user-entered text can be faithfully
|
|
258
|
-
* reproduced elsewhere.
|
|
259
|
-
*/
|
|
260
|
-
private fixClearFormatting(delta: Delta): void {
|
|
261
|
-
|
|
262
|
-
// Using the "Clear formatting" button creates a delta that sets font, size, and color to `null`. Detect any of those.
|
|
263
|
-
// (Usually you'd get all three together, but some might be missing from the delta if they were already clear,
|
|
264
|
-
// for example if we were editing an old Workspace Text Section that was created using an older version of this component.)
|
|
265
|
-
if (delta.ops.some((op) => op.retain && (
|
|
266
|
-
op.attributes?.font === null || op.attributes?.size === null || op.attributes?.color === null
|
|
267
|
-
))) {
|
|
268
|
-
this.editor.format('font', `"${this.DEFAULT_FONT}"`)
|
|
269
|
-
this.updateFontPicker(this.DEFAULT_FONT)
|
|
270
|
-
this.editor.format('size', this.DEFAULT_SIZE)
|
|
271
|
-
this.updateSizePicker(this.DEFAULT_SIZE)
|
|
272
|
-
this.editor.format('color', this.DEFAULT_COLOR)
|
|
273
|
-
this.updateColorPicker(this.DEFAULT_COLOR)
|
|
274
|
-
this.editor.format('font-weight', this.DEFAULT_WEIGHT)
|
|
275
|
-
this.updateFontWeightPicker(this.DEFAULT_WEIGHT)
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* Quill's "Heading 1" and "Heading 2" just change the <p> to <h1> or <h2>. The inner <span> will still have a `style` on it,
|
|
281
|
-
* setting the font, size, and color. Quill prefers no `style` tags, so it expects the CSS to cover that. We use `style` for
|
|
282
|
-
* all our formatting, so we also need to define appropriate values for the Headings.
|
|
283
|
-
*/
|
|
284
|
-
private fixHeadingFormat(delta: Delta): void {
|
|
285
|
-
|
|
286
|
-
// Look for an operation that sets a heading style (header = 1 or 2), or clears it (header = null)
|
|
287
|
-
const headingOp = delta.ops.find((op) => op.attributes?.header !== undefined)
|
|
288
|
-
if (!headingOp) { return }
|
|
289
|
-
|
|
290
|
-
const selection = this.editor.getSelection()
|
|
291
|
-
if (!selection) { return }
|
|
292
|
-
|
|
293
|
-
// The selection might cover multiple paragraphs, so get them all
|
|
294
|
-
let lines = this.editor.getLines(selection)
|
|
295
|
-
if (lines.length === 0) {
|
|
296
|
-
// The selection has zero length, so get the current paragraph
|
|
297
|
-
const line = this.editor.getLine(selection.index)
|
|
298
|
-
// (Perversely, `line` is an array, containing the actual line followed by a number :shrug:)
|
|
299
|
-
if (!line || !line[0]) { return }
|
|
300
|
-
lines = [line[0]]
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
let font = this.DEFAULT_FONT
|
|
304
|
-
let size = this.DEFAULT_SIZE
|
|
305
|
-
let color = this.DEFAULT_COLOR
|
|
306
|
-
|
|
307
|
-
switch (headingOp.attributes?.header) {
|
|
308
|
-
case 1:
|
|
309
|
-
font = this.HEADING_1_FONT
|
|
310
|
-
size = this.HEADING_1_SIZE
|
|
311
|
-
color = this.HEADING_1_COLOR
|
|
312
|
-
break
|
|
313
|
-
|
|
314
|
-
case 2:
|
|
315
|
-
font = this.HEADING_2_FONT
|
|
316
|
-
size = this.HEADING_2_SIZE
|
|
317
|
-
color = this.HEADING_2_COLOR
|
|
318
|
-
break
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
for (const line of lines) {
|
|
322
|
-
const range = new Range(line.offset(), line.length())
|
|
323
|
-
this.editor.formatText(range, 'font', `"${font}"`)
|
|
324
|
-
this.editor.formatText(range, 'size', size)
|
|
325
|
-
this.editor.formatText(range, 'color', color)
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
this.updateFontPicker(font)
|
|
329
|
-
this.updateSizePicker(size)
|
|
330
|
-
this.updateColorPicker(color)
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* Toggling bold/italic/underline clears the font, if the font name contains spaces and ends with digits: https://github.com/slab/quill/issues/4370.
|
|
335
|
-
* Spot when that happens and restore the old font(s).
|
|
336
|
-
*/
|
|
337
|
-
private fixClearedFonts(oldContents: Delta, delta: Delta): void {
|
|
338
|
-
|
|
339
|
-
let currentPos: number = 0
|
|
340
|
-
let haveFirstFont: boolean = false
|
|
341
|
-
let allIsFont: string | undefined
|
|
342
|
-
let fontRanges: FontRange[] | undefined
|
|
343
|
-
|
|
344
|
-
// The changes come as an array of ops. Most will be just { retain: ... } where nothing has changed,
|
|
345
|
-
// but some will have attributes indicating what has changed.
|
|
346
|
-
// If the change crosses a line break, there will be multiple ops with attributes. Loop through them all.
|
|
347
|
-
for (const op of delta.ops) {
|
|
348
|
-
|
|
349
|
-
if (typeof op.retain !== 'number') {
|
|
350
|
-
// I've only ever seen this be a number, but the interface says it can be something more complex.
|
|
351
|
-
// We can't handle that, so get out.
|
|
352
|
-
return
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
if (op.retain && op.attributes && !op.attributes.font
|
|
356
|
-
&& ('bold' in op.attributes || 'italic' in op.attributes || 'underline' in op.attributes)) {
|
|
357
|
-
|
|
358
|
-
// The bad thing has happened, so get a list of how the fonts used to be (if we don't have it already).
|
|
359
|
-
if (!fontRanges) {
|
|
360
|
-
fontRanges = this.getFontRanges(oldContents)
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
const affectedRange: Range = {
|
|
364
|
-
index: currentPos,
|
|
365
|
-
length: op.retain,
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
const fontOfRange = this.reinstateMissingFonts(affectedRange, fontRanges)
|
|
369
|
-
if (!haveFirstFont) {
|
|
370
|
-
allIsFont = fontOfRange
|
|
371
|
-
haveFirstFont = true
|
|
372
|
-
} else if (fontOfRange !== allIsFont) {
|
|
373
|
-
allIsFont = undefined
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
currentPos += op.retain
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
if (allIsFont) {
|
|
381
|
-
// The whole selection was the same font, so show that in the font picker.
|
|
382
|
-
this.updateFontPicker(allIsFont)
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* Quill likes to default to no formatting: an empty paragraph has no font, size, or color, so the style is inherited
|
|
388
|
-
* from the CSS.
|
|
389
|
-
* We don't want that: we want everything to be fully defined, so that the user-entered text can be faithfully
|
|
390
|
-
* reproduced elsewhere.
|
|
391
|
-
* We try to get the format from the previous line, or fall back to the default.
|
|
392
|
-
*/
|
|
393
|
-
private fixMissingFormats(delta?: Delta): void {
|
|
394
|
-
|
|
395
|
-
// When debugging this, it can be useful to add this to your CSS to highlight problems:
|
|
396
|
-
// .ql-editor { color: #f0f; font-family: 'Wingdings', sans-serif; font-size: 9px; }
|
|
397
|
-
|
|
398
|
-
const selection = this.editor.getSelection()
|
|
399
|
-
if (!selection) { return }
|
|
400
|
-
|
|
401
|
-
if (selection.length) {
|
|
402
|
-
// Some text is selected; we don't want to change this
|
|
403
|
-
return
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
const format = this.editor.getFormat()
|
|
407
|
-
if (format.font && format.size && format.color && format['font-weight']) {
|
|
408
|
-
// We are fully formatted; nothing more to do
|
|
409
|
-
return
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
const addedFontlessTextRange = this.getRangeOfAddedFontlessText(delta)
|
|
413
|
-
|
|
414
|
-
// Copy missing format from the previous character (or the next, if we're at the start of the document)
|
|
415
|
-
const nearbyCharIndex = selection.index === 0 ? 1 : selection.index - 1
|
|
416
|
-
const nearbyRange: Range = {
|
|
417
|
-
index: nearbyCharIndex,
|
|
418
|
-
length: 0,
|
|
419
|
-
}
|
|
420
|
-
const nearbyFormat = this.editor.getFormat(nearbyRange)
|
|
421
|
-
|
|
422
|
-
this.editor.format('bold', nearbyFormat.bold)
|
|
423
|
-
this.editor.format('italic', nearbyFormat.italic)
|
|
424
|
-
this.editor.format('underline', nearbyFormat.underline)
|
|
425
|
-
|
|
426
|
-
if (!format.font) {
|
|
427
|
-
const font = this.getFontFromFormat(nearbyFormat)
|
|
428
|
-
this.editor.format('font', `"${font}"`)
|
|
429
|
-
if (addedFontlessTextRange) {
|
|
430
|
-
this.editor.formatText(addedFontlessTextRange, 'font', `"${font}"`)
|
|
431
|
-
}
|
|
432
|
-
this.updateFontPicker(font)
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
if (!format.size) {
|
|
436
|
-
const size = this.getSizeFromFormat(nearbyFormat)
|
|
437
|
-
this.editor.format('size', size)
|
|
438
|
-
this.updateSizePicker(size)
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
if (!format.color) {
|
|
442
|
-
const color = this.getColorFromFormat(nearbyFormat)
|
|
443
|
-
this.editor.format('color', color)
|
|
444
|
-
this.updateColorPicker(color)
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
if (!format['font-weight']) {
|
|
448
|
-
const fontWeight = this.getFontWeightFromFormat(nearbyFormat)
|
|
449
|
-
this.editor.format('font-weight', fontWeight)
|
|
450
|
-
this.updateFontWeightPicker(fontWeight)
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
private getColorFromFormat(format: QuillFormat): string {
|
|
455
|
-
|
|
456
|
-
if (!format.color) {
|
|
457
|
-
// We get no color if the default color is selected; or if the selection contains multiple colors, one of which is the default.
|
|
458
|
-
return this.DEFAULT_COLOR
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
if (typeof format.color === 'string') {
|
|
462
|
-
// The selected range is all the same color, which is not the default.
|
|
463
|
-
return format.color
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
if (Array.isArray(format.color)) {
|
|
467
|
-
// The selected range contains multiple colors, none of which are the default. Return the default, to be consistent with other multi-color selections.
|
|
468
|
-
return this.DEFAULT_COLOR
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
// Fall back to the default (should never get here)
|
|
472
|
-
return this.DEFAULT_COLOR
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
private getFontFromFormat(format: QuillFormat): string {
|
|
476
|
-
|
|
477
|
-
if (!format.font) {
|
|
478
|
-
// No font is defined for the selection, so show the default. This can happen if you're on a new empty line.
|
|
479
|
-
return this.DEFAULT_FONT
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
if (typeof format.font === 'string') {
|
|
483
|
-
// The range uses a single font.
|
|
484
|
-
return format.font
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
if (Array.isArray(format.font)) {
|
|
488
|
-
// The selected range contains multiple fonts, so show blank.
|
|
489
|
-
return ''
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
// Fall back to the default (should never get here)
|
|
493
|
-
return this.DEFAULT_FONT
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
private getFontWeightFromFormat(format: QuillFormat): string {
|
|
497
|
-
|
|
498
|
-
if (typeof format['font-weight'] === 'string') {
|
|
499
|
-
return format['font-weight']
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
return this.DEFAULT_WEIGHT
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
/**
|
|
506
|
-
* Scans the entire text and returns an array of objects denoting which font is used for each range.
|
|
507
|
-
*/
|
|
508
|
-
private getFontRanges(contents: Delta): FontRange[] {
|
|
509
|
-
|
|
510
|
-
let currentPos = 0
|
|
511
|
-
const fontRanges: FontRange[] = []
|
|
512
|
-
for (const op of contents.ops) {
|
|
513
|
-
if (typeof op.insert === 'string') {
|
|
514
|
-
const font = op.attributes ? this.getFontFromFormat(op.attributes) : this.DEFAULT_FONT
|
|
515
|
-
fontRanges.push({
|
|
516
|
-
end: currentPos + op.insert.length - 1,
|
|
517
|
-
font,
|
|
518
|
-
length: op.insert.length,
|
|
519
|
-
start: currentPos,
|
|
520
|
-
})
|
|
521
|
-
currentPos += op.insert.length
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
return fontRanges
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
/**
|
|
529
|
-
* If you recently toggled bold/italic/underline with no text selected whilst in a block of text whose font name
|
|
530
|
-
* contains spaces and ends in a number, it will have forgotten the font.
|
|
531
|
-
* There's no event for the bold/italic/underline toggle, so we detect this when the user types the first letter.
|
|
532
|
-
*/
|
|
533
|
-
private getRangeOfAddedFontlessText(delta?: Delta): Range | undefined {
|
|
534
|
-
|
|
535
|
-
if (!delta) {
|
|
536
|
-
return undefined
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
let currentPos = 0
|
|
540
|
-
for (const op of delta.ops) {
|
|
541
|
-
if (!('retain' in op)
|
|
542
|
-
&& 'insert' in op && typeof op.insert === 'string'
|
|
543
|
-
&& op.attributes && !op.attributes.font) {
|
|
544
|
-
// Disclaimer: if you are typing in a block of text whose font name contains spaces and ends in a
|
|
545
|
-
// number, and has bold/italic/underline applied, but you have just turned bold/italic/underline off with
|
|
546
|
-
// no text selected, AND IF the letter you then type matches the prior letter in the existing text,
|
|
547
|
-
// AND that prior letter is the first letter of a word, then the `font` attribute will already be set
|
|
548
|
-
// correctly here, but the font will not be applied to the text you typed. I cannot see a good way to
|
|
549
|
-
// detect this, and quite frankly Quill can go do one at this point.
|
|
550
|
-
// TODO: CE-10797: Yeah right.
|
|
551
|
-
return {
|
|
552
|
-
index: currentPos,
|
|
553
|
-
length: op.insert.length,
|
|
554
|
-
}
|
|
555
|
-
} else if ('retain' in op) {
|
|
556
|
-
if (typeof op.retain !== 'number') {
|
|
557
|
-
// I've only ever seen this be a number, but the interface says it can be something more complex.
|
|
558
|
-
// We can't handle that, so get out.
|
|
559
|
-
return undefined
|
|
560
|
-
}
|
|
561
|
-
currentPos += op.retain
|
|
562
|
-
} else {
|
|
563
|
-
// Neither a 'retain' nor a buggy 'insert', so the type of edit is not one we're interested in here
|
|
564
|
-
return undefined
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
return undefined
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
private getSizeFromFormat(format: QuillFormat): string {
|
|
572
|
-
|
|
573
|
-
if (!format.size) {
|
|
574
|
-
// We get no size if the default size is selected; or if the selection contains multiple sizes, one of which is the default.
|
|
575
|
-
return this.DEFAULT_SIZE
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
if (typeof format.size === 'string') {
|
|
579
|
-
// The selected range is all the same size, which is not the default.
|
|
580
|
-
return format.size
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
if (Array.isArray(format.size)) {
|
|
584
|
-
// The selected range contains multiple sizes, none of which are the default. Return the first size in the array.
|
|
585
|
-
return format.size[0]
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
// Fall back to the default (should never get here)
|
|
589
|
-
return this.DEFAULT_SIZE
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
/**
|
|
593
|
-
* Reapply the old fonts to a given range.
|
|
594
|
-
* @returns If the whole range is of the same font, returns that font. Otherwise undefined.
|
|
595
|
-
*/
|
|
596
|
-
private reinstateMissingFonts(affectedRange: Range, fontRanges: FontRange[]): string | undefined {
|
|
597
|
-
|
|
598
|
-
let haveFirstFont: boolean = false
|
|
599
|
-
let allIsFont: string | undefined
|
|
600
|
-
|
|
601
|
-
// The affected range might contain multiple fonts. Loop through each font section that overlaps our range.
|
|
602
|
-
let currentStart = affectedRange.index
|
|
603
|
-
let fontRange = fontRanges.find((fr) => fr.start <= currentStart && fr.end >= currentStart)
|
|
604
|
-
|
|
605
|
-
while (fontRange && currentStart < affectedRange.index + affectedRange.length) {
|
|
606
|
-
|
|
607
|
-
if (!haveFirstFont) {
|
|
608
|
-
allIsFont = fontRange?.font
|
|
609
|
-
haveFirstFont = true
|
|
610
|
-
} else if (fontRange.font !== allIsFont) {
|
|
611
|
-
allIsFont = undefined
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
const overlappingRange: Range = {
|
|
615
|
-
index: Math.max(fontRange.start, currentStart),
|
|
616
|
-
length: Math.min(fontRange.end, affectedRange.index + affectedRange.length - 1) - currentStart + 1,
|
|
617
|
-
}
|
|
618
|
-
this.editor.formatText(overlappingRange, 'font', `"${fontRange.font}"`)
|
|
619
|
-
|
|
620
|
-
currentStart = overlappingRange.index + overlappingRange.length
|
|
621
|
-
fontRange = fontRanges.find((fr) => fr.start <= currentStart && fr.end >= currentStart)
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
return allIsFont
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
private sanitizeAndValidate(): void {
|
|
628
|
-
|
|
629
|
-
let html: string | undefined
|
|
630
|
-
|
|
631
|
-
// An empty Quill editor's html might be like:
|
|
632
|
-
// <p><span style="font-family: Roboto; font-size: 14px; color: rgb(83, 83, 83);"><span class="ql-cursor"></span></span></p>
|
|
633
|
-
// Detect emptiness and return `undefined` instead, for easier "Required" validation.
|
|
634
|
-
if (!this.editor.getText().trim()) {
|
|
635
|
-
html = undefined
|
|
636
|
-
} else {
|
|
637
|
-
html = this.richTextService.sanitizeHtml(this.editor.root.innerHTML)
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
this.ngModelCtrl.$setViewValue(html)
|
|
641
|
-
this.checkValidity()
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
/** Updates the color shown in the toolbar. Does not change the color being used in the text. */
|
|
645
|
-
private updateColorPicker(color: string): void {
|
|
646
|
-
|
|
647
|
-
this.selectedColor = color
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
/** Updates the font shown in the toolbar. Does not change the font being used in the text. */
|
|
651
|
-
private updateFontPicker(font: string): void {
|
|
652
|
-
|
|
653
|
-
this.selectedFont = font
|
|
654
|
-
|
|
655
|
-
if (font) {
|
|
656
|
-
this.updateAvailableFontWeights([font])
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
private updateFontWeightPicker(fontWeight: string): void {
|
|
661
|
-
this.selectedFontWeight = fontWeight
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
/** Updates the size shown in the toolbar. Does not change the size being used in the text. */
|
|
665
|
-
private updateSizePicker(size: string): void {
|
|
666
|
-
|
|
667
|
-
this.$element.find('.ql-size').val(size)
|
|
668
|
-
this.$element.find(`#${this.editorSizeId} .ql-picker-label`).attr('data-value', size)
|
|
669
|
-
this.$element.find(`#${this.editorSizeId} .ql-picker-label`).attr('data-label', size)
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
/**
|
|
673
|
-
* Caches all available font weights for all provided fonts.
|
|
674
|
-
* Sets fontWeightOptions to the weights common to all fonts (Always include normal and bold).
|
|
675
|
-
*/
|
|
676
|
-
private updateAvailableFontWeights(fonts: string[]): void {
|
|
677
|
-
|
|
678
|
-
// Cache all weights for all requested fonts
|
|
679
|
-
const fontPromises = fonts.map(font => {
|
|
680
|
-
const cachedWeights = this.fontWeightOptionsCache.get(font)
|
|
681
|
-
if (cachedWeights) { return this.$q.resolve(cachedWeights) }
|
|
682
|
-
|
|
683
|
-
return this.googleWebfontsApiService.getFontVariants(font)
|
|
684
|
-
.then(variants => this.googleWebfontsApiService.sortFontWeightVariants(variants))
|
|
685
|
-
.then(weights => {
|
|
686
|
-
this.fontWeightOptionsCache.set(font, weights)
|
|
687
|
-
return weights
|
|
688
|
-
})
|
|
689
|
-
|
|
690
|
-
})
|
|
691
|
-
|
|
692
|
-
// Set fontWeightOptions to the weights common to all requested fonts (plus normal and bold)
|
|
693
|
-
this.$q.all(fontPromises).then(results => {
|
|
694
|
-
const commonWeights = results.reduce((outputWeights: string[], newWeights: string[]) => outputWeights.filter(weight => newWeights.includes(weight), []))
|
|
695
|
-
// Normal and bold should always be available and can be handled by the browser even if there are no weights provided
|
|
696
|
-
this.fontWeightOptions = [...new Set([...commonWeights, ...this.UNIVERSAL_FONT_WEIGHTS].sort())]
|
|
697
|
-
})
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
interface FontRange {
|
|
702
|
-
end: number
|
|
703
|
-
font: string
|
|
704
|
-
length: number
|
|
705
|
-
start: number
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
interface QuillFormat {
|
|
709
|
-
[format: string]: unknown
|
|
710
|
-
}
|
|
1
|
+
// tslint:disable: max-file-line-count
|
|
2
|
+
import _ from 'lodash'
|
|
3
|
+
import Quill, { Parchment, Range } from 'quill'
|
|
4
|
+
import { Delta, EmitterSource } from 'quill/core'
|
|
5
|
+
import { Component, Inject, Input } from '../decorators'
|
|
6
|
+
import type { TranslateFactory } from '../translate/translate-factory'
|
|
7
|
+
import { v4 as uuidv4 } from 'uuid'
|
|
8
|
+
import RichTextService from './rich-text.service'
|
|
9
|
+
import { IComponentController } from 'angular'
|
|
10
|
+
import { StyleAttributor, Scope } from 'parchment'
|
|
11
|
+
import GoogleWebfontsApiService from '../font-selector/google-webfonts-api.service'
|
|
12
|
+
|
|
13
|
+
@Component({
|
|
14
|
+
selector: 'richText',
|
|
15
|
+
require: {
|
|
16
|
+
ngModelCtrl: 'ngModel',
|
|
17
|
+
},
|
|
18
|
+
template: require('./rich-text.component.html'),
|
|
19
|
+
})
|
|
20
|
+
export default class RichTextComponentController implements IComponentController {
|
|
21
|
+
|
|
22
|
+
@Input() allowColorSelection?: boolean
|
|
23
|
+
@Input() allowFontSelection?: boolean
|
|
24
|
+
@Input() allowImages?: boolean
|
|
25
|
+
@Input() isRequired!: boolean
|
|
26
|
+
|
|
27
|
+
protected cachedSelection?: Range | null
|
|
28
|
+
protected colorInputId: string
|
|
29
|
+
protected editorSizeId: string
|
|
30
|
+
protected fontSelectorId: string
|
|
31
|
+
protected requiredText: string
|
|
32
|
+
protected selectedColor: string
|
|
33
|
+
protected selectedFont: string
|
|
34
|
+
protected fontWeightOptions: string[] = []
|
|
35
|
+
protected fontWeightOptionsCache: Map<string, string[]> = new Map()
|
|
36
|
+
protected selectedFontWeight: string
|
|
37
|
+
protected toolbarId: string
|
|
38
|
+
protected validationForm: ng.IFormController
|
|
39
|
+
|
|
40
|
+
private colorPicker: HTMLElement | null
|
|
41
|
+
private editor: Quill
|
|
42
|
+
private ngModelCtrl: ng.INgModelController
|
|
43
|
+
|
|
44
|
+
private debouncedSanitizeAndValidate = _.debounce(() => this.sanitizeAndValidate(), 250)
|
|
45
|
+
|
|
46
|
+
private DEFAULT_COLOR = '#535353'
|
|
47
|
+
private DEFAULT_FONT = 'Roboto'
|
|
48
|
+
private DEFAULT_SIZE = '14px'
|
|
49
|
+
private DEFAULT_WEIGHT = '400'
|
|
50
|
+
|
|
51
|
+
private HEADING_1_COLOR = '#535353'
|
|
52
|
+
private HEADING_1_FONT = 'Poppins'
|
|
53
|
+
private HEADING_1_SIZE = '24px'
|
|
54
|
+
|
|
55
|
+
private HEADING_2_COLOR = '#535353'
|
|
56
|
+
private HEADING_2_FONT = 'Poppins'
|
|
57
|
+
private HEADING_2_SIZE = '20px'
|
|
58
|
+
|
|
59
|
+
private UNIVERSAL_FONT_WEIGHTS = ['400', '700']
|
|
60
|
+
|
|
61
|
+
constructor(
|
|
62
|
+
@Inject('$element') private $element: ng.IAugmentedJQuery,
|
|
63
|
+
@Inject('$rootScope') private $rootScope: JSUIRootScope,
|
|
64
|
+
@Inject('$timeout') private $timeout: ng.ITimeoutService,
|
|
65
|
+
@Inject('$q') private $q: ng.IQService,
|
|
66
|
+
@Inject('googleWebfontsApiService') private googleWebfontsApiService: GoogleWebfontsApiService,
|
|
67
|
+
@Inject('richTextService') private richTextService: RichTextService,
|
|
68
|
+
@Inject('translateFactory') private translateFactory: TranslateFactory,
|
|
69
|
+
) { }
|
|
70
|
+
|
|
71
|
+
$onChanges(changes: { isRequired?: ng.IChangesObject<boolean> }) {
|
|
72
|
+
|
|
73
|
+
if (!changes.isRequired) { return }
|
|
74
|
+
if (changes.isRequired.currentValue === changes.isRequired.previousValue) { return }
|
|
75
|
+
|
|
76
|
+
this.checkValidity()
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
$onDestroy() {
|
|
80
|
+
|
|
81
|
+
this.editor.off('text-change', (delta: Delta, oldContents, source) => { this.onTextChange(delta, oldContents, source) })
|
|
82
|
+
this.colorPicker?.removeEventListener('change', this.colorChanged.bind(this))
|
|
83
|
+
this.colorPicker?.removeEventListener('click', this.colorInputOpened.bind(this))
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
$onInit() {
|
|
87
|
+
|
|
88
|
+
this.requiredText = this.translateFactory.instant('JSUI.REQUIRED')
|
|
89
|
+
|
|
90
|
+
this.colorInputId = 'rteColorInput-' + uuidv4()
|
|
91
|
+
this.editorSizeId = 'rteEditorSize-' + uuidv4()
|
|
92
|
+
this.fontSelectorId = 'rteFontSelector-' + uuidv4()
|
|
93
|
+
this.toolbarId = 'rteToolbar-' + uuidv4()
|
|
94
|
+
|
|
95
|
+
// Populate the available font weights for the default font
|
|
96
|
+
if (this.allowFontSelection) {
|
|
97
|
+
this.updateAvailableFontWeights([this.DEFAULT_FONT])
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
this.$timeout(() => {
|
|
101
|
+
this.colorPicker = document.getElementById(this.colorInputId)
|
|
102
|
+
this.colorPicker?.addEventListener('change', this.colorChanged.bind(this))
|
|
103
|
+
this.colorPicker?.addEventListener('click', this.colorInputOpened.bind(this))
|
|
104
|
+
|
|
105
|
+
this.updateFontPicker(this.DEFAULT_FONT)
|
|
106
|
+
this.updateFontWeightPicker(this.DEFAULT_WEIGHT)
|
|
107
|
+
this.updateSizePicker(this.DEFAULT_SIZE)
|
|
108
|
+
this.updateColorPicker(this.DEFAULT_COLOR)
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
$postLink() {
|
|
113
|
+
|
|
114
|
+
Quill.register(Quill.import('attributors/class/background') as Parchment.Attributor, true)
|
|
115
|
+
Quill.register(Quill.import('attributors/style/color') as Parchment.Attributor, true)
|
|
116
|
+
Quill.register(new StyleAttributor('font-weight', 'font-weight', { scope: Scope.INLINE }), true)
|
|
117
|
+
|
|
118
|
+
const fontStyle = Quill.import('attributors/style/font') as Parchment.Attributor
|
|
119
|
+
// Setting the whitelist to undefined allows all fonts. (We don't know what fonts Google Fonts will give us.)
|
|
120
|
+
fontStyle.whitelist = undefined
|
|
121
|
+
Quill.register(fontStyle, true)
|
|
122
|
+
|
|
123
|
+
const fontSizeArr = ['6px', '7px', '8px', '9px', '10px', '11px', '12px', '14px', '16px', '18px', '20px', '21px', '24px', '28px', '32px', '36px', '48px', '60px']
|
|
124
|
+
const size = Quill.import('attributors/style/size') as Parchment.Attributor
|
|
125
|
+
size.whitelist = fontSizeArr
|
|
126
|
+
Quill.register(size, true)
|
|
127
|
+
|
|
128
|
+
const options = {
|
|
129
|
+
modules: {
|
|
130
|
+
toolbar: `#${this.toolbarId}`,
|
|
131
|
+
},
|
|
132
|
+
theme: 'snow',
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
this.$timeout(() => {
|
|
136
|
+
this.editor = new Quill(this.$element.find('.js-rich-text-target')[0], options)
|
|
137
|
+
|
|
138
|
+
// Disable spellcheck because of a bad bug that deletes text (CE-4692).
|
|
139
|
+
this.editor.root.setAttribute('spellcheck', 'false')
|
|
140
|
+
|
|
141
|
+
this.editor.on('text-change', (delta: Delta, oldContents, source) => { this.onTextChange(delta, oldContents, source) })
|
|
142
|
+
this.editor.on('selection-change', this.selectionChange.bind(this))
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
this.ngModelCtrl.$render = () => {
|
|
146
|
+
this.$timeout(() => {
|
|
147
|
+
if (!this.ngModelCtrl.$viewValue) {
|
|
148
|
+
this.editor.setText('\n')
|
|
149
|
+
return
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
this.editor.root.innerHTML = this.richTextService.backwardsCompatibleHtml(this.ngModelCtrl.$viewValue)
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
protected colorChanged() {
|
|
158
|
+
|
|
159
|
+
// Re-apply the text selection that was made before selecting a color,
|
|
160
|
+
// as the act of hiding some browsers' color inputs can change the selected text
|
|
161
|
+
if (this.cachedSelection) {
|
|
162
|
+
this.editor.setSelection(this.cachedSelection.index, this.cachedSelection.length)
|
|
163
|
+
}
|
|
164
|
+
this.editor.format('color', this.selectedColor)
|
|
165
|
+
this.debouncedSanitizeAndValidate()
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
protected colorInputOpened() {
|
|
169
|
+
|
|
170
|
+
this.cachedSelection = this.editor.getSelection()
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
protected fontSelected(fontFamily: string, fontWeightOptions?: string[]): void {
|
|
174
|
+
|
|
175
|
+
if (!fontFamily) { return }
|
|
176
|
+
|
|
177
|
+
this.$rootScope.$broadcast('richTextToolbarContainer:closeContainer')
|
|
178
|
+
this.editor.format('font', `"${fontFamily}"`)
|
|
179
|
+
|
|
180
|
+
this.fontWeightOptionsCache.set(fontFamily, fontWeightOptions || [])
|
|
181
|
+
this.updateAvailableFontWeights([fontFamily])
|
|
182
|
+
|
|
183
|
+
if (![...(fontWeightOptions || []), ...this.UNIVERSAL_FONT_WEIGHTS].includes(this.selectedFontWeight)) {
|
|
184
|
+
this.selectedFontWeight = this.DEFAULT_WEIGHT
|
|
185
|
+
this.editor.format('font-weight', this.DEFAULT_WEIGHT)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
this.debouncedSanitizeAndValidate()
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
protected fontWeightSelected(fontWeight: string): void {
|
|
192
|
+
this.selectedFontWeight = fontWeight
|
|
193
|
+
this.editor.format('font-weight', fontWeight)
|
|
194
|
+
|
|
195
|
+
this.debouncedSanitizeAndValidate()
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** The user entered/deleted/modified some text. Handle any formatting issues, then store the model. */
|
|
199
|
+
protected onTextChange(delta: Delta, oldContents: Delta, source: EmitterSource): void {
|
|
200
|
+
|
|
201
|
+
if (source !== 'user') { return }
|
|
202
|
+
|
|
203
|
+
if (!this.allowImages && delta.ops.some(op => op.insert && typeof op.insert === 'object' && 'image' in op.insert)) {
|
|
204
|
+
// Don't allow images to be added in any way: pasted, drag-dropped, etc.
|
|
205
|
+
this.editor.history.undo()
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
this.$timeout(() => {
|
|
209
|
+
// In some cases, toggling Bold/Italic/Underline clears the font.
|
|
210
|
+
this.fixClearedFonts(oldContents, delta)
|
|
211
|
+
|
|
212
|
+
// When we choose "Heading 1" or "Heading 2", we also need to set the font, size, and color.
|
|
213
|
+
this.fixHeadingFormat(delta)
|
|
214
|
+
|
|
215
|
+
// Quill's "Clear formatting" button leaves us inheriting styles from the CSS. We want to keep things explicit.
|
|
216
|
+
this.fixClearFormatting(delta)
|
|
217
|
+
|
|
218
|
+
// Also, things like adding a line break can leave us with no style.
|
|
219
|
+
this.fixMissingFormats(delta)
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
this.debouncedSanitizeAndValidate()
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** The user moved the cursor. Fix missing formats and update the toolbar to reflect the current selection. */
|
|
226
|
+
protected selectionChange(range: Range, _oldRange: Range, source: EmitterSource): void {
|
|
227
|
+
|
|
228
|
+
if (source !== 'user') { return }
|
|
229
|
+
if (!range) { return }
|
|
230
|
+
|
|
231
|
+
this.fixMissingFormats()
|
|
232
|
+
|
|
233
|
+
this.$timeout(() => {
|
|
234
|
+
// Quill updates the toolbar to reflect most formatting (bold, italics, bullet points, etc.), but
|
|
235
|
+
// fonts, text size, and color are handled by plugins so we need to update those ourselves.
|
|
236
|
+
const format = this.editor.getFormat(range)
|
|
237
|
+
this.updateFontPicker(this.getFontFromFormat(format))
|
|
238
|
+
this.updateFontWeightPicker(this.getFontWeightFromFormat(format))
|
|
239
|
+
this.updateColorPicker(this.getColorFromFormat(format))
|
|
240
|
+
this.updateSizePicker(this.getSizeFromFormat(format))
|
|
241
|
+
|
|
242
|
+
this.updateAvailableFontWeights(Array.isArray(format.font) ? format.font : [format.font])
|
|
243
|
+
})
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
private checkValidity(): void {
|
|
247
|
+
|
|
248
|
+
const isValid = !this.isRequired || !!this.ngModelCtrl.$viewValue
|
|
249
|
+
|
|
250
|
+
this.$timeout(() => {
|
|
251
|
+
this.ngModelCtrl.$setValidity('required', isValid)
|
|
252
|
+
})
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Quill's "Clear formatting" button leaves us with no font, size, or color, so the style is inherited from the CSS.
|
|
257
|
+
* We don't want that: we want everything to be fully defined, so that the user-entered text can be faithfully
|
|
258
|
+
* reproduced elsewhere.
|
|
259
|
+
*/
|
|
260
|
+
private fixClearFormatting(delta: Delta): void {
|
|
261
|
+
|
|
262
|
+
// Using the "Clear formatting" button creates a delta that sets font, size, and color to `null`. Detect any of those.
|
|
263
|
+
// (Usually you'd get all three together, but some might be missing from the delta if they were already clear,
|
|
264
|
+
// for example if we were editing an old Workspace Text Section that was created using an older version of this component.)
|
|
265
|
+
if (delta.ops.some((op) => op.retain && (
|
|
266
|
+
op.attributes?.font === null || op.attributes?.size === null || op.attributes?.color === null
|
|
267
|
+
))) {
|
|
268
|
+
this.editor.format('font', `"${this.DEFAULT_FONT}"`)
|
|
269
|
+
this.updateFontPicker(this.DEFAULT_FONT)
|
|
270
|
+
this.editor.format('size', this.DEFAULT_SIZE)
|
|
271
|
+
this.updateSizePicker(this.DEFAULT_SIZE)
|
|
272
|
+
this.editor.format('color', this.DEFAULT_COLOR)
|
|
273
|
+
this.updateColorPicker(this.DEFAULT_COLOR)
|
|
274
|
+
this.editor.format('font-weight', this.DEFAULT_WEIGHT)
|
|
275
|
+
this.updateFontWeightPicker(this.DEFAULT_WEIGHT)
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Quill's "Heading 1" and "Heading 2" just change the <p> to <h1> or <h2>. The inner <span> will still have a `style` on it,
|
|
281
|
+
* setting the font, size, and color. Quill prefers no `style` tags, so it expects the CSS to cover that. We use `style` for
|
|
282
|
+
* all our formatting, so we also need to define appropriate values for the Headings.
|
|
283
|
+
*/
|
|
284
|
+
private fixHeadingFormat(delta: Delta): void {
|
|
285
|
+
|
|
286
|
+
// Look for an operation that sets a heading style (header = 1 or 2), or clears it (header = null)
|
|
287
|
+
const headingOp = delta.ops.find((op) => op.attributes?.header !== undefined)
|
|
288
|
+
if (!headingOp) { return }
|
|
289
|
+
|
|
290
|
+
const selection = this.editor.getSelection()
|
|
291
|
+
if (!selection) { return }
|
|
292
|
+
|
|
293
|
+
// The selection might cover multiple paragraphs, so get them all
|
|
294
|
+
let lines = this.editor.getLines(selection)
|
|
295
|
+
if (lines.length === 0) {
|
|
296
|
+
// The selection has zero length, so get the current paragraph
|
|
297
|
+
const line = this.editor.getLine(selection.index)
|
|
298
|
+
// (Perversely, `line` is an array, containing the actual line followed by a number :shrug:)
|
|
299
|
+
if (!line || !line[0]) { return }
|
|
300
|
+
lines = [line[0]]
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
let font = this.DEFAULT_FONT
|
|
304
|
+
let size = this.DEFAULT_SIZE
|
|
305
|
+
let color = this.DEFAULT_COLOR
|
|
306
|
+
|
|
307
|
+
switch (headingOp.attributes?.header) {
|
|
308
|
+
case 1:
|
|
309
|
+
font = this.HEADING_1_FONT
|
|
310
|
+
size = this.HEADING_1_SIZE
|
|
311
|
+
color = this.HEADING_1_COLOR
|
|
312
|
+
break
|
|
313
|
+
|
|
314
|
+
case 2:
|
|
315
|
+
font = this.HEADING_2_FONT
|
|
316
|
+
size = this.HEADING_2_SIZE
|
|
317
|
+
color = this.HEADING_2_COLOR
|
|
318
|
+
break
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
for (const line of lines) {
|
|
322
|
+
const range = new Range(line.offset(), line.length())
|
|
323
|
+
this.editor.formatText(range, 'font', `"${font}"`)
|
|
324
|
+
this.editor.formatText(range, 'size', size)
|
|
325
|
+
this.editor.formatText(range, 'color', color)
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
this.updateFontPicker(font)
|
|
329
|
+
this.updateSizePicker(size)
|
|
330
|
+
this.updateColorPicker(color)
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Toggling bold/italic/underline clears the font, if the font name contains spaces and ends with digits: https://github.com/slab/quill/issues/4370.
|
|
335
|
+
* Spot when that happens and restore the old font(s).
|
|
336
|
+
*/
|
|
337
|
+
private fixClearedFonts(oldContents: Delta, delta: Delta): void {
|
|
338
|
+
|
|
339
|
+
let currentPos: number = 0
|
|
340
|
+
let haveFirstFont: boolean = false
|
|
341
|
+
let allIsFont: string | undefined
|
|
342
|
+
let fontRanges: FontRange[] | undefined
|
|
343
|
+
|
|
344
|
+
// The changes come as an array of ops. Most will be just { retain: ... } where nothing has changed,
|
|
345
|
+
// but some will have attributes indicating what has changed.
|
|
346
|
+
// If the change crosses a line break, there will be multiple ops with attributes. Loop through them all.
|
|
347
|
+
for (const op of delta.ops) {
|
|
348
|
+
|
|
349
|
+
if (typeof op.retain !== 'number') {
|
|
350
|
+
// I've only ever seen this be a number, but the interface says it can be something more complex.
|
|
351
|
+
// We can't handle that, so get out.
|
|
352
|
+
return
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (op.retain && op.attributes && !op.attributes.font
|
|
356
|
+
&& ('bold' in op.attributes || 'italic' in op.attributes || 'underline' in op.attributes)) {
|
|
357
|
+
|
|
358
|
+
// The bad thing has happened, so get a list of how the fonts used to be (if we don't have it already).
|
|
359
|
+
if (!fontRanges) {
|
|
360
|
+
fontRanges = this.getFontRanges(oldContents)
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
const affectedRange: Range = {
|
|
364
|
+
index: currentPos,
|
|
365
|
+
length: op.retain,
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
const fontOfRange = this.reinstateMissingFonts(affectedRange, fontRanges)
|
|
369
|
+
if (!haveFirstFont) {
|
|
370
|
+
allIsFont = fontOfRange
|
|
371
|
+
haveFirstFont = true
|
|
372
|
+
} else if (fontOfRange !== allIsFont) {
|
|
373
|
+
allIsFont = undefined
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
currentPos += op.retain
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (allIsFont) {
|
|
381
|
+
// The whole selection was the same font, so show that in the font picker.
|
|
382
|
+
this.updateFontPicker(allIsFont)
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Quill likes to default to no formatting: an empty paragraph has no font, size, or color, so the style is inherited
|
|
388
|
+
* from the CSS.
|
|
389
|
+
* We don't want that: we want everything to be fully defined, so that the user-entered text can be faithfully
|
|
390
|
+
* reproduced elsewhere.
|
|
391
|
+
* We try to get the format from the previous line, or fall back to the default.
|
|
392
|
+
*/
|
|
393
|
+
private fixMissingFormats(delta?: Delta): void {
|
|
394
|
+
|
|
395
|
+
// When debugging this, it can be useful to add this to your CSS to highlight problems:
|
|
396
|
+
// .ql-editor { color: #f0f; font-family: 'Wingdings', sans-serif; font-size: 9px; }
|
|
397
|
+
|
|
398
|
+
const selection = this.editor.getSelection()
|
|
399
|
+
if (!selection) { return }
|
|
400
|
+
|
|
401
|
+
if (selection.length) {
|
|
402
|
+
// Some text is selected; we don't want to change this
|
|
403
|
+
return
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const format = this.editor.getFormat()
|
|
407
|
+
if (format.font && format.size && format.color && format['font-weight']) {
|
|
408
|
+
// We are fully formatted; nothing more to do
|
|
409
|
+
return
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const addedFontlessTextRange = this.getRangeOfAddedFontlessText(delta)
|
|
413
|
+
|
|
414
|
+
// Copy missing format from the previous character (or the next, if we're at the start of the document)
|
|
415
|
+
const nearbyCharIndex = selection.index === 0 ? 1 : selection.index - 1
|
|
416
|
+
const nearbyRange: Range = {
|
|
417
|
+
index: nearbyCharIndex,
|
|
418
|
+
length: 0,
|
|
419
|
+
}
|
|
420
|
+
const nearbyFormat = this.editor.getFormat(nearbyRange)
|
|
421
|
+
|
|
422
|
+
this.editor.format('bold', nearbyFormat.bold)
|
|
423
|
+
this.editor.format('italic', nearbyFormat.italic)
|
|
424
|
+
this.editor.format('underline', nearbyFormat.underline)
|
|
425
|
+
|
|
426
|
+
if (!format.font) {
|
|
427
|
+
const font = this.getFontFromFormat(nearbyFormat)
|
|
428
|
+
this.editor.format('font', `"${font}"`)
|
|
429
|
+
if (addedFontlessTextRange) {
|
|
430
|
+
this.editor.formatText(addedFontlessTextRange, 'font', `"${font}"`)
|
|
431
|
+
}
|
|
432
|
+
this.updateFontPicker(font)
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (!format.size) {
|
|
436
|
+
const size = this.getSizeFromFormat(nearbyFormat)
|
|
437
|
+
this.editor.format('size', size)
|
|
438
|
+
this.updateSizePicker(size)
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
if (!format.color) {
|
|
442
|
+
const color = this.getColorFromFormat(nearbyFormat)
|
|
443
|
+
this.editor.format('color', color)
|
|
444
|
+
this.updateColorPicker(color)
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
if (!format['font-weight']) {
|
|
448
|
+
const fontWeight = this.getFontWeightFromFormat(nearbyFormat)
|
|
449
|
+
this.editor.format('font-weight', fontWeight)
|
|
450
|
+
this.updateFontWeightPicker(fontWeight)
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
private getColorFromFormat(format: QuillFormat): string {
|
|
455
|
+
|
|
456
|
+
if (!format.color) {
|
|
457
|
+
// We get no color if the default color is selected; or if the selection contains multiple colors, one of which is the default.
|
|
458
|
+
return this.DEFAULT_COLOR
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
if (typeof format.color === 'string') {
|
|
462
|
+
// The selected range is all the same color, which is not the default.
|
|
463
|
+
return format.color
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
if (Array.isArray(format.color)) {
|
|
467
|
+
// The selected range contains multiple colors, none of which are the default. Return the default, to be consistent with other multi-color selections.
|
|
468
|
+
return this.DEFAULT_COLOR
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// Fall back to the default (should never get here)
|
|
472
|
+
return this.DEFAULT_COLOR
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
private getFontFromFormat(format: QuillFormat): string {
|
|
476
|
+
|
|
477
|
+
if (!format.font) {
|
|
478
|
+
// No font is defined for the selection, so show the default. This can happen if you're on a new empty line.
|
|
479
|
+
return this.DEFAULT_FONT
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
if (typeof format.font === 'string') {
|
|
483
|
+
// The range uses a single font.
|
|
484
|
+
return format.font
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
if (Array.isArray(format.font)) {
|
|
488
|
+
// The selected range contains multiple fonts, so show blank.
|
|
489
|
+
return ''
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// Fall back to the default (should never get here)
|
|
493
|
+
return this.DEFAULT_FONT
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
private getFontWeightFromFormat(format: QuillFormat): string {
|
|
497
|
+
|
|
498
|
+
if (typeof format['font-weight'] === 'string') {
|
|
499
|
+
return format['font-weight']
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
return this.DEFAULT_WEIGHT
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Scans the entire text and returns an array of objects denoting which font is used for each range.
|
|
507
|
+
*/
|
|
508
|
+
private getFontRanges(contents: Delta): FontRange[] {
|
|
509
|
+
|
|
510
|
+
let currentPos = 0
|
|
511
|
+
const fontRanges: FontRange[] = []
|
|
512
|
+
for (const op of contents.ops) {
|
|
513
|
+
if (typeof op.insert === 'string') {
|
|
514
|
+
const font = op.attributes ? this.getFontFromFormat(op.attributes) : this.DEFAULT_FONT
|
|
515
|
+
fontRanges.push({
|
|
516
|
+
end: currentPos + op.insert.length - 1,
|
|
517
|
+
font,
|
|
518
|
+
length: op.insert.length,
|
|
519
|
+
start: currentPos,
|
|
520
|
+
})
|
|
521
|
+
currentPos += op.insert.length
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
return fontRanges
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* If you recently toggled bold/italic/underline with no text selected whilst in a block of text whose font name
|
|
530
|
+
* contains spaces and ends in a number, it will have forgotten the font.
|
|
531
|
+
* There's no event for the bold/italic/underline toggle, so we detect this when the user types the first letter.
|
|
532
|
+
*/
|
|
533
|
+
private getRangeOfAddedFontlessText(delta?: Delta): Range | undefined {
|
|
534
|
+
|
|
535
|
+
if (!delta) {
|
|
536
|
+
return undefined
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
let currentPos = 0
|
|
540
|
+
for (const op of delta.ops) {
|
|
541
|
+
if (!('retain' in op)
|
|
542
|
+
&& 'insert' in op && typeof op.insert === 'string'
|
|
543
|
+
&& op.attributes && !op.attributes.font) {
|
|
544
|
+
// Disclaimer: if you are typing in a block of text whose font name contains spaces and ends in a
|
|
545
|
+
// number, and has bold/italic/underline applied, but you have just turned bold/italic/underline off with
|
|
546
|
+
// no text selected, AND IF the letter you then type matches the prior letter in the existing text,
|
|
547
|
+
// AND that prior letter is the first letter of a word, then the `font` attribute will already be set
|
|
548
|
+
// correctly here, but the font will not be applied to the text you typed. I cannot see a good way to
|
|
549
|
+
// detect this, and quite frankly Quill can go do one at this point.
|
|
550
|
+
// TODO: CE-10797: Yeah right.
|
|
551
|
+
return {
|
|
552
|
+
index: currentPos,
|
|
553
|
+
length: op.insert.length,
|
|
554
|
+
}
|
|
555
|
+
} else if ('retain' in op) {
|
|
556
|
+
if (typeof op.retain !== 'number') {
|
|
557
|
+
// I've only ever seen this be a number, but the interface says it can be something more complex.
|
|
558
|
+
// We can't handle that, so get out.
|
|
559
|
+
return undefined
|
|
560
|
+
}
|
|
561
|
+
currentPos += op.retain
|
|
562
|
+
} else {
|
|
563
|
+
// Neither a 'retain' nor a buggy 'insert', so the type of edit is not one we're interested in here
|
|
564
|
+
return undefined
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
return undefined
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
private getSizeFromFormat(format: QuillFormat): string {
|
|
572
|
+
|
|
573
|
+
if (!format.size) {
|
|
574
|
+
// We get no size if the default size is selected; or if the selection contains multiple sizes, one of which is the default.
|
|
575
|
+
return this.DEFAULT_SIZE
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
if (typeof format.size === 'string') {
|
|
579
|
+
// The selected range is all the same size, which is not the default.
|
|
580
|
+
return format.size
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
if (Array.isArray(format.size)) {
|
|
584
|
+
// The selected range contains multiple sizes, none of which are the default. Return the first size in the array.
|
|
585
|
+
return format.size[0]
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// Fall back to the default (should never get here)
|
|
589
|
+
return this.DEFAULT_SIZE
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* Reapply the old fonts to a given range.
|
|
594
|
+
* @returns If the whole range is of the same font, returns that font. Otherwise undefined.
|
|
595
|
+
*/
|
|
596
|
+
private reinstateMissingFonts(affectedRange: Range, fontRanges: FontRange[]): string | undefined {
|
|
597
|
+
|
|
598
|
+
let haveFirstFont: boolean = false
|
|
599
|
+
let allIsFont: string | undefined
|
|
600
|
+
|
|
601
|
+
// The affected range might contain multiple fonts. Loop through each font section that overlaps our range.
|
|
602
|
+
let currentStart = affectedRange.index
|
|
603
|
+
let fontRange = fontRanges.find((fr) => fr.start <= currentStart && fr.end >= currentStart)
|
|
604
|
+
|
|
605
|
+
while (fontRange && currentStart < affectedRange.index + affectedRange.length) {
|
|
606
|
+
|
|
607
|
+
if (!haveFirstFont) {
|
|
608
|
+
allIsFont = fontRange?.font
|
|
609
|
+
haveFirstFont = true
|
|
610
|
+
} else if (fontRange.font !== allIsFont) {
|
|
611
|
+
allIsFont = undefined
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
const overlappingRange: Range = {
|
|
615
|
+
index: Math.max(fontRange.start, currentStart),
|
|
616
|
+
length: Math.min(fontRange.end, affectedRange.index + affectedRange.length - 1) - currentStart + 1,
|
|
617
|
+
}
|
|
618
|
+
this.editor.formatText(overlappingRange, 'font', `"${fontRange.font}"`)
|
|
619
|
+
|
|
620
|
+
currentStart = overlappingRange.index + overlappingRange.length
|
|
621
|
+
fontRange = fontRanges.find((fr) => fr.start <= currentStart && fr.end >= currentStart)
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
return allIsFont
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
private sanitizeAndValidate(): void {
|
|
628
|
+
|
|
629
|
+
let html: string | undefined
|
|
630
|
+
|
|
631
|
+
// An empty Quill editor's html might be like:
|
|
632
|
+
// <p><span style="font-family: Roboto; font-size: 14px; color: rgb(83, 83, 83);"><span class="ql-cursor"></span></span></p>
|
|
633
|
+
// Detect emptiness and return `undefined` instead, for easier "Required" validation.
|
|
634
|
+
if (!this.editor.getText().trim()) {
|
|
635
|
+
html = undefined
|
|
636
|
+
} else {
|
|
637
|
+
html = this.richTextService.sanitizeHtml(this.editor.root.innerHTML)
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
this.ngModelCtrl.$setViewValue(html)
|
|
641
|
+
this.checkValidity()
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/** Updates the color shown in the toolbar. Does not change the color being used in the text. */
|
|
645
|
+
private updateColorPicker(color: string): void {
|
|
646
|
+
|
|
647
|
+
this.selectedColor = color
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
/** Updates the font shown in the toolbar. Does not change the font being used in the text. */
|
|
651
|
+
private updateFontPicker(font: string): void {
|
|
652
|
+
|
|
653
|
+
this.selectedFont = font
|
|
654
|
+
|
|
655
|
+
if (font) {
|
|
656
|
+
this.updateAvailableFontWeights([font])
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
private updateFontWeightPicker(fontWeight: string): void {
|
|
661
|
+
this.selectedFontWeight = fontWeight
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
/** Updates the size shown in the toolbar. Does not change the size being used in the text. */
|
|
665
|
+
private updateSizePicker(size: string): void {
|
|
666
|
+
|
|
667
|
+
this.$element.find('.ql-size').val(size)
|
|
668
|
+
this.$element.find(`#${this.editorSizeId} .ql-picker-label`).attr('data-value', size)
|
|
669
|
+
this.$element.find(`#${this.editorSizeId} .ql-picker-label`).attr('data-label', size)
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* Caches all available font weights for all provided fonts.
|
|
674
|
+
* Sets fontWeightOptions to the weights common to all fonts (Always include normal and bold).
|
|
675
|
+
*/
|
|
676
|
+
private updateAvailableFontWeights(fonts: string[]): void {
|
|
677
|
+
|
|
678
|
+
// Cache all weights for all requested fonts
|
|
679
|
+
const fontPromises = fonts.map(font => {
|
|
680
|
+
const cachedWeights = this.fontWeightOptionsCache.get(font)
|
|
681
|
+
if (cachedWeights) { return this.$q.resolve(cachedWeights) }
|
|
682
|
+
|
|
683
|
+
return this.googleWebfontsApiService.getFontVariants(font)
|
|
684
|
+
.then(variants => this.googleWebfontsApiService.sortFontWeightVariants(variants))
|
|
685
|
+
.then(weights => {
|
|
686
|
+
this.fontWeightOptionsCache.set(font, weights)
|
|
687
|
+
return weights
|
|
688
|
+
})
|
|
689
|
+
|
|
690
|
+
})
|
|
691
|
+
|
|
692
|
+
// Set fontWeightOptions to the weights common to all requested fonts (plus normal and bold)
|
|
693
|
+
this.$q.all(fontPromises).then(results => {
|
|
694
|
+
const commonWeights = results.reduce((outputWeights: string[], newWeights: string[]) => outputWeights.filter(weight => newWeights.includes(weight), []))
|
|
695
|
+
// Normal and bold should always be available and can be handled by the browser even if there are no weights provided
|
|
696
|
+
this.fontWeightOptions = [...new Set([...commonWeights, ...this.UNIVERSAL_FONT_WEIGHTS].sort())]
|
|
697
|
+
})
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
interface FontRange {
|
|
702
|
+
end: number
|
|
703
|
+
font: string
|
|
704
|
+
length: number
|
|
705
|
+
start: number
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
interface QuillFormat {
|
|
709
|
+
[format: string]: unknown
|
|
710
|
+
}
|