@refinitiv-ui/efx-grid 6.0.45 → 6.0.46

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.
@@ -0,0 +1,38 @@
1
+ import { Ext } from "../../tr-grid-util/es6/Ext.js";
2
+ import { EventDispatcher } from "../../tr-grid-util/es6/EventDispatcher.js";
3
+
4
+ declare class PrintTrait {
5
+
6
+ constructor();
7
+
8
+ public static readonly DEBUG: boolean;
9
+
10
+ public static calculateEnvironment(): any;
11
+
12
+ public observe(iframeElement?: HTMLIFrameElement): void;
13
+
14
+ public unobserve(): void;
15
+
16
+ public isObserving(): boolean;
17
+
18
+ public dispose(): void;
19
+
20
+ public print(): void;
21
+
22
+ public _print(): void;
23
+
24
+ public static createBlankPages(pageCount: number): Element;
25
+
26
+ public createClientBox(pw: number, ph: number): Element;
27
+
28
+ public enablePaperSizeCorrection(enabled: boolean): void;
29
+
30
+ public fixPaperSize(enabled: boolean): void;
31
+
32
+ public getDocumentElement(): Element|null|null;
33
+
34
+ public getBodyElement(): Element|null|null;
35
+
36
+ }
37
+
38
+ export { PrintTrait };
@@ -0,0 +1,481 @@
1
+ import { Ext } from "../../tr-grid-util/es6/Ext.js";
2
+ import { EventDispatcher } from "../../tr-grid-util/es6/EventDispatcher.js";
3
+
4
+ /** @event PrintTrait#beforeprint
5
+ * @description Triggered before the printing and print preview.
6
+ * @property {number} pageWidth Width of the print page
7
+ * @property {number} pageHeight Height of the print page
8
+ */
9
+ /** @event PrintTrait#afterprint
10
+ * @description Triggered after the printing is completed or canceled. This event is fired only once at the end of printing
11
+ * @property {number} pageWidth Width of the current client window (not the print page)
12
+ * @property {number} pageHeight Height of the current client window (not the print page)
13
+ */
14
+ /** @event PrintTrait#pageCounting
15
+ * @description Triggered before actual print command and {@link PrintTrait#beforeprint} event.<br>
16
+ * Used mainly for setting number of rendered pages for the preview dialog<br>
17
+ * Page counting must be done before triggering browser's preview dialog, because we cannot change number of rendered pages, while the dialog is opened.<br>
18
+ * Note that given paper size is NOT from the print device.
19
+ * @property {number} pageWidth=739 Width of portrait "letter" paper type (739px)
20
+ * @property {number} pageHeight=978 Height of portrait "letter" paper type (978px)
21
+ */
22
+
23
+ /** PrintTrait simplify print process to 2 simple events ("beforeprint" and "afterprint").<br>
24
+ * PrintTrait works by intercepting Window's print call and preparing the necessary information.
25
+ * @constructor
26
+ * @extends{EventDispatcher}
27
+ * @suppress {checkTypes}
28
+ */
29
+ var PrintTrait = function() {
30
+ var t = this;
31
+ t._onKeyDown = t._onKeyDown.bind(t);
32
+ t._onMediaQuery = t._onMediaQuery.bind(t);
33
+ t._onBeforePrint = t._onBeforePrint.bind(t);
34
+ t._onAfterPrint = t._onAfterPrint.bind(t);
35
+ t._onPrintEnd = t._onPrintEnd.bind(t);
36
+ t._print = t._print.bind(t);
37
+ t.print = t.print.bind(t);
38
+ t._eventArg = {};
39
+
40
+ PrintTrait.calculateEnvironment();
41
+ };
42
+ Ext.inherits(PrintTrait, EventDispatcher);
43
+
44
+ /** @type {number}
45
+ * @private
46
+ */
47
+ var IDLE = 0;
48
+ /** @type {number}
49
+ * @private
50
+ */
51
+ var COUNTING = 1;
52
+ /** @type {number}
53
+ * @private
54
+ */
55
+ var BEFORE_PRINT = 2;
56
+ /** @type {number}
57
+ * @private
58
+ */
59
+ var AFTER_PRINT = 3;
60
+
61
+ /** @type {number}
62
+ * @private
63
+ */
64
+ PrintTrait.prototype._defaultWidth = 739;
65
+ /** @type {number}
66
+ * @private
67
+ */
68
+ PrintTrait.prototype._defaultHeight = 978;
69
+ /** @type {Window}
70
+ * @private
71
+ */
72
+ PrintTrait.prototype._window = null;
73
+ /** @type {Function}
74
+ * @private
75
+ */
76
+ PrintTrait.prototype._defaultPrint = null;
77
+ /** @type {Object}
78
+ * @private
79
+ */
80
+ PrintTrait.prototype._eventArg = null;
81
+ /** @type {MediaQueryList}
82
+ * @private
83
+ */
84
+ PrintTrait.prototype._printMedia = null;
85
+ /** @type {boolean}
86
+ * @private
87
+ */
88
+ PrintTrait.prototype._correction = false;
89
+ /** @type {boolean}
90
+ * @private
91
+ */
92
+ PrintTrait.prototype._fixedSize = false;
93
+ /** @type {number}
94
+ * @private
95
+ */
96
+ PrintTrait.prototype._state = IDLE;
97
+ /** @type {number}
98
+ * @private
99
+ */
100
+ PrintTrait.prototype._timerId = 0;
101
+ /** @type {boolean}
102
+ * @public
103
+ */
104
+ PrintTrait.DEBUG = false;
105
+ /** @type {Element}
106
+ * @private
107
+ */
108
+ PrintTrait._debugBtn = null;
109
+
110
+
111
+ /** @type {Object}
112
+ * @private
113
+ */
114
+ PrintTrait._env = {};
115
+ /** @public
116
+ * @function
117
+ * @return {Object}
118
+ */
119
+ PrintTrait.calculateEnvironment = function() {
120
+ var env = PrintTrait._env;
121
+ var ua = navigator.userAgent;
122
+ var jet = window["JET"];
123
+ var cd = jet ? jet["ContainerDescription"] : "";
124
+
125
+ env.isMac = /Mac/.test(navigator.platform);
126
+ env.isIE = (ua.indexOf("MSIE ") > 0) || (ua.indexOf("Trident/") > 0) || (ua.indexOf("Edge/") > 0);
127
+ env.isEikonDesktop = cd ? cd["name"] === "Thomson Reuters Eikon" : false;
128
+ return env;
129
+ };
130
+
131
+ /** @public
132
+ * @param {HTMLIFrameElement=} iframeElement If not specified, current window is used instead. Specify null to un-observe existing window object.
133
+ * @suppress {checkTypes}
134
+ */
135
+ PrintTrait.prototype.observe = function(iframeElement) {
136
+ if(this._state > IDLE && this._state < AFTER_PRINT) {
137
+ console.warn("Cannot observe another window object while printing process is running.");
138
+ return;
139
+ }
140
+
141
+ var winObj = null;
142
+
143
+ if(iframeElement) {
144
+ if(iframeElement.contentWindow) {
145
+ winObj = /** @type{Window} */(iframeElement.contentWindow);
146
+ }
147
+ }
148
+ // eslint-disable-next-line
149
+ else if (iframeElement === undefined) {
150
+ winObj = /** @type{Window} */(window);
151
+ }
152
+
153
+ if(this._window === winObj) {
154
+ return;
155
+ }
156
+
157
+ if(this._window) {
158
+ this._window.print = this._defaultPrint; // Restore native print() method
159
+ this._defaultPrint = null;
160
+
161
+ this._window.removeEventListener("keydown", this._onKeyDown, false);
162
+ this._window.removeEventListener("afterprint", this._onAfterPrint, false);
163
+ this._window = null;
164
+
165
+ if(this._printMedia) {
166
+ this._printMedia.removeListener(this._onMediaQuery);
167
+ this._printMedia = null;
168
+ }
169
+ }
170
+
171
+ this._window = winObj;
172
+
173
+ if(winObj) {
174
+ this._defaultPrint = winObj.print;
175
+
176
+ winObj.print = this.print; // WARNING: Override native print() method
177
+ winObj.addEventListener("keydown", this._onKeyDown, false);
178
+ winObj.addEventListener("afterprint", this._onAfterPrint, false);
179
+
180
+ this._printMedia = winObj.matchMedia("print");
181
+ if(this._printMedia) {
182
+ this._printMedia.addListener(this._onMediaQuery);
183
+ }
184
+ }
185
+ };
186
+ /** @public
187
+ */
188
+ PrintTrait.prototype.unobserve = function() {
189
+ this.observe(null);
190
+ };
191
+ /** @public
192
+ * @return {boolean}
193
+ */
194
+ PrintTrait.prototype.isObserving = function() {
195
+ return this._window ? true : false;
196
+ };
197
+
198
+ /** @public
199
+ * @suppress {checkTypes}
200
+ */
201
+ PrintTrait.prototype.dispose = function() {
202
+ this.removeAllEventlisteners();
203
+
204
+ if(this._timerId) {
205
+ clearTimeout(this._timerId);
206
+ }
207
+
208
+ this._onPrintEnd(); // Force ending the process
209
+ this.unobserve();
210
+ this._eventArg = null;
211
+ };
212
+ /** @public
213
+ */
214
+ PrintTrait.prototype.print = function() {
215
+ if(!this._window) {
216
+ console.error("Cannot perform printing. Window object must be specified by using observe() method.");
217
+ return;
218
+ }
219
+ if(this._state !== IDLE) {
220
+ console.warn("Cannot initiate another printing command while another printing process is running.");
221
+ return;
222
+ }
223
+ this._state = COUNTING;
224
+ if(PrintTrait._env.isEikonDesktop) { // DPI is reduced in Eikon Desktop
225
+ this._defaultWidth = 672; // 692 for letter width
226
+ this._defaultHeight = 917;
227
+ } else {
228
+ this._defaultWidth = 717; // A4 safe width
229
+ this._defaultHeight = 978; // letter safe height
230
+ }
231
+ this._eventArg["pageWidth"] = this._defaultWidth;
232
+ this._eventArg["pageHeight"] = this._defaultHeight;
233
+ this._eventArg["documentElement"] = this.getDocumentElement();
234
+ this._eventArg["bodyElement"] = this.getBodyElement();
235
+ this.getDocumentElement().classList.add("tr-printing-mode");
236
+ this._dispatch("pageCounting", this._eventArg);
237
+
238
+ if(PrintTrait.DEBUG) {
239
+ var debugBtn = PrintTrait._debugBtn = document.createElement("button");
240
+ debugBtn.addEventListener("click", this._onBeforePrint);
241
+ debugBtn.textContent = "BeforePrint";
242
+ debugBtn.style.display = "unset";
243
+ debugBtn.style.position = "fixed";
244
+ debugBtn.style.width = "100px";
245
+ debugBtn.style.left = "50%";
246
+ debugBtn.style.transform = "translateX(-50%)";
247
+ debugBtn.style.top = "20px";
248
+ document.body.appendChild(debugBtn);
249
+ } else {
250
+ /**
251
+ * _onBeforePrint() was originally execute by window 'beforeprint' event.
252
+ * Due to Custom Elements can't be create during 'beforeprint', _onBeforePrint() needs to be executed manually.
253
+ * And window.print() need to be executed after some delay to make sure Custom Elements are created and rendered.
254
+ * See here: https://html.spec.whatwg.org/multipage/custom-elements.html#custom-element-reactions
255
+ */
256
+ this._onBeforePrint();
257
+ setTimeout(this._print, 500);
258
+ }
259
+ };
260
+ /** @public
261
+ */
262
+ PrintTrait.prototype._print = function() {
263
+ this._defaultPrint.call(this._window);
264
+ };
265
+ /** @public
266
+ * @param {number} pageCount
267
+ * @return {!Element}
268
+ */
269
+ PrintTrait.createBlankPages = function(pageCount) {
270
+ var rootElem = document.createElement("div");
271
+ for(var i = 0; i < pageCount; ++i) {
272
+ var bp = document.createElement("div");
273
+ if(PrintTrait.DEBUG) {
274
+ bp.textContent = "Page " + (i + 1);
275
+ } else {
276
+ bp.className = "tr-blank-page";
277
+ }
278
+ rootElem.appendChild(bp);
279
+ }
280
+ rootElem.style.display = "block"; // This will beat any CSS selector
281
+ return rootElem;
282
+ };
283
+ /** @public
284
+ * @param {number} pw Page width
285
+ * @param {number} ph Page height
286
+ * @return {!Element}
287
+ */
288
+ PrintTrait.prototype.createClientBox = function(pw, ph) {
289
+ var rootElem = document.createElement("div");
290
+ var styObj = rootElem.style;
291
+ styObj.width = pw + "px";
292
+ styObj.height = ph + "px";
293
+
294
+ styObj.display = "block";
295
+ styObj.border = "2px solid red";
296
+ styObj.boxSizing = "border-box";
297
+
298
+ styObj.fontSize = "3em";
299
+ rootElem.textContent = pw + " x " + ph;
300
+ return rootElem;
301
+ };
302
+ /** @public
303
+ * @param {boolean} enabled
304
+ */
305
+ PrintTrait.prototype.enablePaperSizeCorrection = function(enabled) {
306
+ this._correction = (enabled !== false);
307
+ };
308
+ /** @public
309
+ * @param {boolean} enabled
310
+ */
311
+ PrintTrait.prototype.fixPaperSize = function(enabled) {
312
+ this._fixedSize = (enabled !== false);
313
+ };
314
+ /** @public
315
+ * @return {Element|null} html tag element
316
+ */
317
+ PrintTrait.prototype.getDocumentElement = function() {
318
+ return this._window.document.documentElement || null;
319
+ };
320
+ /** @public
321
+ * @return {Element|null} body tag element
322
+ */
323
+ PrintTrait.prototype.getBodyElement = function() {
324
+ return this._window.document.body || null;
325
+ };
326
+
327
+
328
+ /** @private
329
+ * @param {KeyboardEvent} e
330
+ */
331
+ PrintTrait.prototype._onKeyDown = function(e) {
332
+ var ctrlCmdKey = PrintTrait._env.isMac ? e.metaKey : e.ctrlKey;
333
+
334
+ if(ctrlCmdKey) {
335
+ if(!e.altKey) {
336
+ if(e.keyCode === 80) { // P
337
+ e.preventDefault();
338
+ e.stopPropagation();
339
+ this.print();
340
+ }
341
+ }
342
+ }
343
+ };
344
+ /** @private
345
+ * @param {Object} e
346
+ */
347
+ PrintTrait.prototype._onMediaQuery = function(e) {
348
+ if (e["matches"]) {
349
+ this._onBeforePrint();
350
+ } else {
351
+ this._onAfterPrint();
352
+ }
353
+ };
354
+ /** @private
355
+ * @param {Object=} e
356
+ */
357
+ PrintTrait.prototype._onBeforePrint = function(e) {
358
+ if(this._state < BEFORE_PRINT) {
359
+ this._state = BEFORE_PRINT;
360
+ this._calculatePageSize(this._correction, this._fixedSize);
361
+
362
+
363
+ this._eventArg["documentElement"] = this.getDocumentElement();
364
+ this._eventArg["bodyElement"] = this.getBodyElement();
365
+ this.getDocumentElement().classList.add("tr-printing-mode");
366
+ this._dispatch("beforeprint", this._eventArg);
367
+
368
+ if(PrintTrait.DEBUG) {
369
+ var debugBtn = PrintTrait._debugBtn;
370
+ debugBtn.removeEventListener("click", this._onBeforePrint);
371
+ debugBtn.addEventListener("click", this._onAfterPrint);
372
+ debugBtn.textContent = "AfterPrint";
373
+ }
374
+ }
375
+ };
376
+ /** @private
377
+ * @param {Object=} e
378
+ */
379
+ PrintTrait.prototype._onAfterPrint = function(e) {
380
+ if(this._state < AFTER_PRINT) {
381
+ this._state = AFTER_PRINT;
382
+ this._calculatePageSize();
383
+
384
+ this.getDocumentElement().classList.remove("tr-printing-mode");
385
+ this._dispatch("afterprint", this._eventArg);
386
+ this._timerId = setTimeout(this._onPrintEnd, 0);
387
+
388
+ if (PrintTrait._debugBtn) { // For debugging
389
+ var pn = PrintTrait._debugBtn.parentNode;
390
+ if(pn) {
391
+ pn.removeChild(PrintTrait._debugBtn);
392
+ }
393
+ PrintTrait._debugBtn = null;
394
+ }
395
+ }
396
+ };
397
+ /** @private
398
+ */
399
+ PrintTrait.prototype._onPrintEnd = function() {
400
+ this._timerId = 0;
401
+ this._state = IDLE;
402
+ };
403
+ /** @private
404
+ * @param {boolean=} sizeCorrection
405
+ * @param {boolean=} fixedSize
406
+ * @return {boolean} True if there is any change
407
+ */
408
+ PrintTrait.prototype._calculatePageSize = function(sizeCorrection, fixedSize) {
409
+ if(PrintTrait._env.isIE) {
410
+ return false; // Cannot calculate paper size in IE
411
+ }
412
+ var documentElement = this.getDocumentElement();
413
+ var cw = documentElement.clientWidth;
414
+ var iw = this._window.innerWidth || 0;
415
+ var ch = documentElement.clientHeight;
416
+ var ih = this._window.innerHeight || 0;
417
+ var nw = (cw >= iw) ? cw : iw;
418
+ var nh = (ch >= ih) ? ch : ih;
419
+
420
+ if(fixedSize) {
421
+ if(nw > nh) {
422
+ nw = this._defaultHeight;
423
+ nh = this._defaultWidth;
424
+ } else {
425
+ nw = this._defaultWidth;
426
+ nh = this._defaultHeight;
427
+ }
428
+ } else if(sizeCorrection) {
429
+ var portrait = nh >= nw;
430
+ var ar = this._calculateAspectRatio(nw, nh);
431
+ var paperSize = PrintTrait._paperSizes[ar];
432
+ if(!paperSize) {
433
+ paperSize = PrintTrait._paperSizes[ar - 1] || PrintTrait._paperSizes[ar + 1];
434
+ }
435
+ if(paperSize) {
436
+ if(portrait) {
437
+ nw = paperSize[0];
438
+ nh = paperSize[1];
439
+ } else {
440
+ nh = paperSize[0];
441
+ nw = paperSize[1];
442
+ }
443
+ }
444
+ }
445
+
446
+ if(this._eventArg["pageWidth"] !== nw || this._eventArg["pageHeight"] !== nh) {
447
+ this._eventArg["pageWidth"] = nw;
448
+ this._eventArg["pageHeight"] = nh;
449
+ return true;
450
+ }
451
+ return false;
452
+ };
453
+
454
+ /** @private
455
+ * @param {number} w width
456
+ * @param {number} h height
457
+ * @return {number}
458
+ */
459
+ PrintTrait.prototype._calculateAspectRatio = function(w, h) {
460
+ var portrait = h >= w;
461
+ var ratio = (portrait) ? w / h : h / w;
462
+ return Math.floor(ratio * 1000); // Return 3 digit precision
463
+ };
464
+
465
+ /** @private
466
+ * @type {Object.<number, Array.<number>>}
467
+ */
468
+ PrintTrait._paperSizes = {
469
+ 702: [3101, 4414], // "A0"
470
+ 699: [2168, 3100], // "A1"
471
+ 697: [1511, 2167], // "A2"
472
+ 692: [1046, 1511], // "A3"
473
+ 685: [717, 1046], // "A4"
474
+ 674: [483, 715], // "A5"
475
+ 583: [739, 1266], // "legal"
476
+ 755: [739, 978], // "letter"
477
+ 629: [979, 1554] // "tabloid"
478
+ };
479
+
480
+
481
+ export { PrintTrait };
@@ -0,0 +1,54 @@
1
+ import { Ext } from "../../tr-grid-util/es6/Ext.js";
2
+ import { ElementWrapper } from "../../tr-grid-util/es6/ElementWrapper.js";
3
+ import { Table } from "../../tr-grid-util/es6/Table.js";
4
+ import { CellWriter } from "./CellWriter.js";
5
+
6
+ declare class SectionWriter extends ElementWrapper {
7
+
8
+ constructor();
9
+
10
+ public getFirstIndexInView(): number;
11
+
12
+ public getLastIndexInView(): number;
13
+
14
+ public getColumnCount(): number;
15
+
16
+ public getColumn(colIndex: number): any;
17
+
18
+ public setColumnCount(val: number): void;
19
+
20
+ public getRowCount(): number;
21
+
22
+ public setRowCount(val: number): void;
23
+
24
+ public getCell(colIndex: number, rowIndex: number): CellWriter|null;
25
+
26
+ public getCellContent(colIndex: number, rowIndex: number): Element|Node|NodeList|null;
27
+
28
+ public setCellContent(colIndex: number, rowIndex: number, data: string|Element|any|any): void;
29
+
30
+ public enableRowClass(rowIndex: number, className: string, enabled: boolean): void;
31
+
32
+ public stretchCell(colIndex: number, rowIndex: number, opt_stretching?: boolean, opt_noLeftStretching?: boolean): void;
33
+
34
+ public hasCellSpan(): boolean;
35
+
36
+ public getCellRowSpan(colIndex: number, rowIndex: number): number;
37
+
38
+ public setCellRowSpan(colIndex: number, rowIndex: number, rowSpan: number): void;
39
+
40
+ public getCellColSpan(colIndex: number, rowIndex: number): number;
41
+
42
+ public setCellColSpan(colIndex: number, rowIndex: number, colSpan: number): void;
43
+
44
+ public clearCellSpans(): void;
45
+
46
+ public clearColumnSpans(colIndex: number): void;
47
+
48
+ public isColumnActive(colIndex: number): boolean;
49
+
50
+ public getCellElement(colIndex: number, rowIndex: number): Element|null;
51
+
52
+ }
53
+
54
+ export { SectionWriter };