From 0c9e9cbdb176720042603aed4ebc9f988ff6852d Mon Sep 17 00:00:00 2001 From: Thomas Burleson Date: Tue, 1 Jan 2019 18:57:32 -0600 Subject: [PATCH] feat(core): add print support with mediaQuery override (#954) When printing developers can now configure how layouts should render. Default print will use the current layout and current elements shown/visible. By specifying 1..n mediaQuery aliases, developers can specify alternate layouts with alternate breakpoints to be used for printing. Elements can also be shown and hidden for printing-only. > This feature supports totally different print outputs without modifying the current browser layout. Implement PrintHook service to intercept print mediaQuery activation events. * add fxShow.print and fxHide.print support to show/hide elements during printing * suspend activation changes in MediaMarshaller while print-mode is active * trigger MediaObserver to notify subscribers with print mqAlias(es) * use PrintHook to intercept activation changes in MediaMarshaller while print-mode is active * trigger MediaObserver to notify subscribers with print mqAlias(es) * add watermark component to Demo app that is shown only during printing Using the new `printWithBreakpoint` allows developers to specify a breakpoint that should be used to render layouts only during printing. With the configuration below, the breakpoint associated with the **`md`** alias will be used. ```ts FlexLayoutModule.withConfig({ useColumnBasisZero: false, printWithBreakpoints: ['md', 'lt-lg', 'lt-xl', 'gt-sm', 'gt-xs'] }) ``` Shown below is the print layout rendered in floating dialog over the normal layout that is currently using 'lg' breakpoints. ![angular-layout-printing](https://user-images.githubusercontent.com/210413/50407211-2e04ca00-0798-11e9-8f35-b4e9e2fca864.jpg) Fixes #603. --- docs/documentation/BreakPoints.md | 4 +- docs/documentation/fxHide-API.md | 2 +- docs/documentation/fxShow-API.md | 2 +- src/apps/demo-app/src/app/app.component.html | 6 +- src/apps/demo-app/src/app/app.module.ts | 19 +- .../docs-responsive.component.ts | 3 +- .../demo-app/src/app/watermark.component.scss | 16 + .../demo-app/src/app/watermark.component.ts | 56 +++ src/apps/demo-app/src/styles.scss | 12 + src/lib/core/add-alias.ts | 2 +- src/lib/core/base/base2.ts | 2 +- .../core/breakpoints/break-point-registry.ts | 4 +- src/lib/core/breakpoints/breakpoint-tools.ts | 7 +- .../data/orientation-break-points.spec.ts | 29 +- .../data/orientation-break-points.ts | 18 +- src/lib/core/match-media/match-media.spec.ts | 5 +- .../match-media/mock/mock-match-media.spec.ts | 2 +- .../core/match-media/mock/mock-match-media.ts | 15 +- .../media-marshaller/media-marshaller.spec.ts | 350 ++++++++++++------ .../core/media-marshaller/media-marshaller.ts | 71 ++-- src/lib/core/media-marshaller/print-hook.ts | 215 +++++++++++ .../media-observer/media-observer.spec.ts | 336 +++++++++++------ src/lib/core/media-observer/media-observer.ts | 34 +- src/lib/core/public-api.ts | 1 + src/lib/core/tokens/library-config.ts | 2 + src/lib/extended/class/class.spec.ts | 1 - src/lib/extended/show-hide/hide.spec.ts | 53 ++- src/lib/extended/show-hide/show-hide.ts | 38 +- src/lib/extended/show-hide/show.spec.ts | 37 +- src/lib/flex/flex/flex.spec.ts | 76 ++-- src/lib/grid/grid-align/grid-align.spec.ts | 8 +- src/lib/module.ts | 6 +- 32 files changed, 1058 insertions(+), 374 deletions(-) create mode 100644 src/apps/demo-app/src/app/watermark.component.scss create mode 100644 src/apps/demo-app/src/app/watermark.component.ts create mode 100644 src/lib/core/media-marshaller/print-hook.ts diff --git a/docs/documentation/BreakPoints.md b/docs/documentation/BreakPoints.md index ed2b3a0ea..9d823431f 100644 --- a/docs/documentation/BreakPoints.md +++ b/docs/documentation/BreakPoints.md @@ -42,7 +42,7 @@ import {BREAKPOINT} from '@angular/flex-layout'; const PRINT_BREAKPOINTS = [{ alias: 'xs.print', suffix: 'XsPrint', - mediaQuery: 'print and (max-width: 297px)', + mediaQuery: 'screen and (max-width: 297px)', overlapping: false }]; @@ -157,4 +157,4 @@ export class CustomShowHideDirective extends ShowHideDirective { this._cacheInput("showXsPrint", negativeOf(val)); } } -``` \ No newline at end of file +``` diff --git a/docs/documentation/fxHide-API.md b/docs/documentation/fxHide-API.md index 15f0a91f2..45ed55cd3 100644 --- a/docs/documentation/fxHide-API.md +++ b/docs/documentation/fxHide-API.md @@ -24,7 +24,7 @@ e.g. ### Using Responsive API -When a mediaQuery range activates, the directive instances will be notified. If the current activate mediaQuery range +When a mediaQuery range activates, the directive instances will be notified. If the current activated mediaQuery range (and its associated alias) are not used, then the static API value is restored as the fallback value. The *fallback* solution uses a **`largest_range-to-smallest_range`** search algorithm. Consider the following: diff --git a/docs/documentation/fxShow-API.md b/docs/documentation/fxShow-API.md index 10c7a3e54..5e9671647 100644 --- a/docs/documentation/fxShow-API.md +++ b/docs/documentation/fxShow-API.md @@ -24,7 +24,7 @@ e.g. ### Using Responsive API -When a mediaQuery range activates, the directive instances will be notified. If the current activate mediaQuery range +When a mediaQuery range activates, the directive instances will be notified. If the current activated mediaQuery range (and its associated alias) are not used, then the static API value is restored as the fallback value. The *fallback* solution uses a **`largest_range-to-smallest_range`** search algorithm. Consider the following: diff --git a/src/apps/demo-app/src/app/app.component.html b/src/apps/demo-app/src/app/app.component.html index da731abbf..693050a1c 100644 --- a/src/apps/demo-app/src/app/app.component.html +++ b/src/apps/demo-app/src/app/app.component.html @@ -13,8 +13,8 @@

Layout Demos: