@teipublisher/pb-components 1.42.1 → 1.42.3
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/CHANGELOG.md +14 -0
- package/dist/demo/pb-print-preview.html +2 -2
- package/dist/pb-components-bundle.js +77 -57
- package/dist/pb-elements.json +29 -0
- package/lib/paged.polyfill.js +33040 -0
- package/package.json +1 -1
- package/pb-elements.json +29 -0
- package/src/pb-components.js +1 -0
- package/src/pb-print-preview.js +82 -50
- package/dist/pb-print-preview.js +0 -6
package/package.json
CHANGED
package/pb-elements.json
CHANGED
|
@@ -8393,6 +8393,7 @@
|
|
|
8393
8393
|
{
|
|
8394
8394
|
"name": "pb-print-preview",
|
|
8395
8395
|
"path": "./src/pb-print-preview.js",
|
|
8396
|
+
"description": "Generates a HTML print preview of a document using the [pagedjs](https://pagedjs.org/) polyfill\nto support CSS Paged Media.",
|
|
8396
8397
|
"attributes": [
|
|
8397
8398
|
{
|
|
8398
8399
|
"name": "src",
|
|
@@ -8401,8 +8402,21 @@
|
|
|
8401
8402
|
},
|
|
8402
8403
|
{
|
|
8403
8404
|
"name": "styles",
|
|
8405
|
+
"description": "Additional CSS stylesheets to be loaded. Relative URLs will be resolved\nrelative to the API endpoint.",
|
|
8404
8406
|
"type": "string"
|
|
8405
8407
|
},
|
|
8408
|
+
{
|
|
8409
|
+
"name": "url",
|
|
8410
|
+
"description": "The generated API URL from which the HTML content will be loaded.\nReadonly.",
|
|
8411
|
+
"type": "string",
|
|
8412
|
+
"default": "\"about:blank\""
|
|
8413
|
+
},
|
|
8414
|
+
{
|
|
8415
|
+
"name": "raw",
|
|
8416
|
+
"description": "Set to disable the pagejs polyfill, i.e. show the HTML as delivered from the server.",
|
|
8417
|
+
"type": "boolean",
|
|
8418
|
+
"default": "false"
|
|
8419
|
+
},
|
|
8406
8420
|
{
|
|
8407
8421
|
"name": "subscribe",
|
|
8408
8422
|
"description": "The name of the channel to subscribe to. Only events on a channel corresponding\nto this property are listened to.",
|
|
@@ -8445,8 +8459,23 @@
|
|
|
8445
8459
|
{
|
|
8446
8460
|
"name": "styles",
|
|
8447
8461
|
"attribute": "styles",
|
|
8462
|
+
"description": "Additional CSS stylesheets to be loaded. Relative URLs will be resolved\nrelative to the API endpoint.",
|
|
8448
8463
|
"type": "string"
|
|
8449
8464
|
},
|
|
8465
|
+
{
|
|
8466
|
+
"name": "url",
|
|
8467
|
+
"attribute": "url",
|
|
8468
|
+
"description": "The generated API URL from which the HTML content will be loaded.\nReadonly.",
|
|
8469
|
+
"type": "string",
|
|
8470
|
+
"default": "\"about:blank\""
|
|
8471
|
+
},
|
|
8472
|
+
{
|
|
8473
|
+
"name": "raw",
|
|
8474
|
+
"attribute": "raw",
|
|
8475
|
+
"description": "Set to disable the pagejs polyfill, i.e. show the HTML as delivered from the server.",
|
|
8476
|
+
"type": "boolean",
|
|
8477
|
+
"default": "false"
|
|
8478
|
+
},
|
|
8450
8479
|
{
|
|
8451
8480
|
"name": "subscribe",
|
|
8452
8481
|
"attribute": "subscribe",
|
package/src/pb-components.js
CHANGED
package/src/pb-print-preview.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { LitElement, html } from 'lit-element';
|
|
2
|
-
import { Previewer } from "pagedjs/dist/paged.esm";
|
|
1
|
+
import { LitElement, html, css } from 'lit-element';
|
|
3
2
|
import { pbMixin } from './pb-mixin.js';
|
|
4
3
|
import { resolveURL } from './utils.js';
|
|
5
4
|
|
|
6
5
|
/**
|
|
6
|
+
* Generates a HTML print preview of a document using the [pagedjs](https://pagedjs.org/) polyfill
|
|
7
|
+
* to support CSS Paged Media.
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
-
* @customElement pb-print-preview
|
|
10
|
-
* @polymer
|
|
11
9
|
* @demo demo/pb-print-preview.html
|
|
12
10
|
* @appliesMixin pbMixin
|
|
13
11
|
*/
|
|
@@ -21,91 +19,125 @@ export class PbPrintPreview extends pbMixin(LitElement) {
|
|
|
21
19
|
src: {
|
|
22
20
|
type: String
|
|
23
21
|
},
|
|
22
|
+
/**
|
|
23
|
+
* Additional CSS stylesheets to be loaded. Relative URLs will be resolved
|
|
24
|
+
* relative to the API endpoint.
|
|
25
|
+
*/
|
|
24
26
|
styles: {
|
|
25
27
|
type: String
|
|
26
28
|
},
|
|
29
|
+
/**
|
|
30
|
+
* The generated API URL from which the HTML content will be loaded.
|
|
31
|
+
* Readonly.
|
|
32
|
+
*/
|
|
33
|
+
url: {
|
|
34
|
+
type: String,
|
|
35
|
+
reflect: true,
|
|
36
|
+
readOnly: true
|
|
37
|
+
},
|
|
38
|
+
/**
|
|
39
|
+
* Set to disable the pagejs polyfill, i.e. show the HTML as delivered from the server.
|
|
40
|
+
*/
|
|
41
|
+
raw: {
|
|
42
|
+
type: Boolean
|
|
43
|
+
},
|
|
27
44
|
...super.properties
|
|
28
45
|
};
|
|
29
46
|
}
|
|
30
47
|
|
|
31
48
|
constructor() {
|
|
32
49
|
super();
|
|
33
|
-
}
|
|
34
50
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (!document.head.querySelector('#pb-print-preview-interface')) {
|
|
39
|
-
const style = document.createElement('link');
|
|
40
|
-
style.id = 'pb-print-preview-interface';
|
|
41
|
-
style.rel = 'Stylesheet';
|
|
42
|
-
style.type = 'text/css';
|
|
43
|
-
style.href = resolveURL('../css/pagedjs/interface.css');
|
|
44
|
-
document.head.appendChild(style);
|
|
45
|
-
}
|
|
51
|
+
this.url = 'about:blank';
|
|
52
|
+
this.raw = false;
|
|
46
53
|
}
|
|
47
54
|
|
|
48
55
|
firstUpdated() {
|
|
49
56
|
super.firstUpdated();
|
|
50
57
|
|
|
51
|
-
this.
|
|
58
|
+
this._iframe = this.shadowRoot.querySelector('iframe');
|
|
59
|
+
this._iframe.addEventListener('load', () => {
|
|
60
|
+
if (this._iframe.src === 'about:blank') {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
this._iframe.className = '';
|
|
64
|
+
this.emitTo('pb-end-update');
|
|
65
|
+
});
|
|
52
66
|
|
|
53
67
|
PbPrintPreview.waitOnce('pb-page-ready', () => {
|
|
54
68
|
this.refresh();
|
|
55
69
|
});
|
|
56
70
|
}
|
|
57
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Open the browser's print dialog.
|
|
74
|
+
*/
|
|
75
|
+
print() {
|
|
76
|
+
this._iframe.contentWindow.print();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Refresh the displayed content.
|
|
81
|
+
*/
|
|
58
82
|
refresh() {
|
|
59
83
|
this.emitTo('pb-start-update');
|
|
84
|
+
this._iframe.className = 'hidden';
|
|
85
|
+
this._iframe.src = 'about:blank';
|
|
60
86
|
|
|
61
87
|
const doc = this.getDocument();
|
|
62
88
|
const params = new URLSearchParams();
|
|
63
|
-
params.set('wc', false);
|
|
89
|
+
params.set('wc', 'false');
|
|
64
90
|
if (doc.odd) {
|
|
65
91
|
params.set('odd', `${doc.odd}.odd`);
|
|
66
92
|
}
|
|
67
|
-
params.set('base', `${this.getEndpoint()}/${doc.getCollection()}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
.then((response) => response.text())
|
|
76
|
-
.then((data) => {
|
|
77
|
-
const previewer = new Previewer();
|
|
78
|
-
// previewer.registerHandlers(previewHandler(this._container));
|
|
79
|
-
previewer.preview(data, this._getCustomStyles(), this._container);
|
|
80
|
-
this.emitTo('pb-end-update');
|
|
81
|
-
});
|
|
93
|
+
params.set('base', `${this.getEndpoint()}/${doc.getCollection()}/`);
|
|
94
|
+
if (!this.raw) {
|
|
95
|
+
params.set('script', resolveURL('../lib/paged.polyfill.js'));
|
|
96
|
+
}
|
|
97
|
+
this._getCustomStyles().forEach((href) => params.append('style', href));
|
|
98
|
+
this.url = `${this.getEndpoint()}/api/document/${encodeURIComponent(doc.path)}/print?${params.toString()}`;
|
|
99
|
+
|
|
100
|
+
this._iframe.src = this.url;
|
|
82
101
|
}
|
|
83
102
|
|
|
84
103
|
render() {
|
|
85
104
|
return html`
|
|
86
|
-
<
|
|
105
|
+
<iframe title="Preview" src="about:blank"></iframe>
|
|
87
106
|
`;
|
|
88
107
|
}
|
|
89
108
|
|
|
90
|
-
createRenderRoot() {
|
|
91
|
-
return this;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
109
|
_getCustomStyles() {
|
|
95
110
|
let customStyles = [];
|
|
96
|
-
if (this.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
if (doc.odd) {
|
|
104
|
-
customStyles.push(`${this.getEndpoint()}/transform/${doc.odd}.css`);
|
|
105
|
-
}
|
|
106
|
-
return customStyles;
|
|
111
|
+
if (this.styles) {
|
|
112
|
+
customStyles = this.styles.split(/\s*,\s*/);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (!this.raw) {
|
|
116
|
+
customStyles.push(resolveURL('../css/pagedjs/interface.css'));
|
|
107
117
|
}
|
|
108
118
|
return customStyles;
|
|
109
119
|
}
|
|
120
|
+
|
|
121
|
+
static get styles() {
|
|
122
|
+
return css`
|
|
123
|
+
:host {
|
|
124
|
+
display: block;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
iframe {
|
|
128
|
+
border: 0;
|
|
129
|
+
width: 100%;
|
|
130
|
+
height: 100%;
|
|
131
|
+
opacity: 1;
|
|
132
|
+
transition: opacity 0.5s ease-out 0.5s;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.hidden {
|
|
136
|
+
opacity: 0;
|
|
137
|
+
transition: opacity 0.5s ease-out;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
`;
|
|
141
|
+
}
|
|
110
142
|
}
|
|
111
143
|
customElements.define('pb-print-preview', PbPrintPreview);
|