@slickgrid-universal/custom-tooltip-plugin 2.5.0 → 2.6.0
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/dist/commonjs/index.js +17 -17
- package/dist/commonjs/slickCustomTooltip.js +410 -407
- package/dist/commonjs/slickCustomTooltip.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/slickCustomTooltip.js +406 -403
- package/dist/esm/slickCustomTooltip.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/{commonjs → types}/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -0
- package/dist/{commonjs → types}/slickCustomTooltip.d.ts +113 -109
- package/dist/types/slickCustomTooltip.d.ts.map +1 -0
- package/package.json +7 -7
- package/dist/esm/index.d.ts +0 -1
- package/dist/esm/slickCustomTooltip.d.ts +0 -109
|
@@ -1,408 +1,411 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SlickCustomTooltip = void 0;
|
|
4
|
-
const common_1 = require("@slickgrid-universal/common");
|
|
5
|
-
/**
|
|
6
|
-
* A plugin to add Custom Tooltip when hovering a cell, it subscribes to the cell "onMouseEnter" and "onMouseLeave" events.
|
|
7
|
-
* The "customTooltip" is defined in the Column Definition OR Grid Options (the first found will have priority over the second)
|
|
8
|
-
* To specify a tooltip when hovering a cell, extend the column definition like so:
|
|
9
|
-
*
|
|
10
|
-
* Available plugin options (same options are available in both column definition and/or grid options)
|
|
11
|
-
* Example 1 - via Column Definition
|
|
12
|
-
* this.columnDefinitions = [
|
|
13
|
-
* {
|
|
14
|
-
* id: "action", name: "Action", field: "action", formatter: fakeButtonFormatter,
|
|
15
|
-
* customTooltip: {
|
|
16
|
-
* formatter: tooltipTaskFormatter,
|
|
17
|
-
* usabilityOverride: (args) => !!(args.dataContext.id % 2) // show it only every second row
|
|
18
|
-
* }
|
|
19
|
-
* }
|
|
20
|
-
* ];
|
|
21
|
-
*
|
|
22
|
-
* OR Example 2 - via Grid Options (for all columns), NOTE: the column definition tooltip options will win over the options defined in the grid options
|
|
23
|
-
* this.gridOptions = {
|
|
24
|
-
* enableCellNavigation: true,
|
|
25
|
-
* customTooltip: {
|
|
26
|
-
* },
|
|
27
|
-
* };
|
|
28
|
-
*/
|
|
29
|
-
class SlickCustomTooltip {
|
|
30
|
-
constructor() {
|
|
31
|
-
this.
|
|
32
|
-
this.
|
|
33
|
-
this.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
this.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
this.
|
|
83
|
-
this.
|
|
84
|
-
this.
|
|
85
|
-
this.
|
|
86
|
-
|
|
87
|
-
.subscribe(grid.
|
|
88
|
-
.subscribe(grid.
|
|
89
|
-
.subscribe(grid.
|
|
90
|
-
.subscribe(grid.
|
|
91
|
-
.subscribe(grid.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
this.
|
|
97
|
-
this.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
*
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
//
|
|
118
|
-
//
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
*
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
args
|
|
151
|
-
args.
|
|
152
|
-
args.
|
|
153
|
-
args.
|
|
154
|
-
args.
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
this.
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
if (
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
return (0, common_1.sanitizeTextByAvailableSanitizer)(this.gridOptions,
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
tmpTitleElm =
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
this._tooltipElm.
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
if ((
|
|
318
|
-
this._tooltipElm.style.
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
const
|
|
348
|
-
const
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
//
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
this.
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
this._tooltipElm.classList.
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
this._tooltipElm.classList.add('arrow-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
//
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
}
|
|
407
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SlickCustomTooltip = void 0;
|
|
4
|
+
const common_1 = require("@slickgrid-universal/common");
|
|
5
|
+
/**
|
|
6
|
+
* A plugin to add Custom Tooltip when hovering a cell, it subscribes to the cell "onMouseEnter" and "onMouseLeave" events.
|
|
7
|
+
* The "customTooltip" is defined in the Column Definition OR Grid Options (the first found will have priority over the second)
|
|
8
|
+
* To specify a tooltip when hovering a cell, extend the column definition like so:
|
|
9
|
+
*
|
|
10
|
+
* Available plugin options (same options are available in both column definition and/or grid options)
|
|
11
|
+
* Example 1 - via Column Definition
|
|
12
|
+
* this.columnDefinitions = [
|
|
13
|
+
* {
|
|
14
|
+
* id: "action", name: "Action", field: "action", formatter: fakeButtonFormatter,
|
|
15
|
+
* customTooltip: {
|
|
16
|
+
* formatter: tooltipTaskFormatter,
|
|
17
|
+
* usabilityOverride: (args) => !!(args.dataContext.id % 2) // show it only every second row
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* ];
|
|
21
|
+
*
|
|
22
|
+
* OR Example 2 - via Grid Options (for all columns), NOTE: the column definition tooltip options will win over the options defined in the grid options
|
|
23
|
+
* this.gridOptions = {
|
|
24
|
+
* enableCellNavigation: true,
|
|
25
|
+
* customTooltip: {
|
|
26
|
+
* },
|
|
27
|
+
* };
|
|
28
|
+
*/
|
|
29
|
+
class SlickCustomTooltip {
|
|
30
|
+
constructor() {
|
|
31
|
+
this._cellType = 'slick-cell';
|
|
32
|
+
this._rxjs = null;
|
|
33
|
+
this._sharedService = null;
|
|
34
|
+
this._defaultOptions = {
|
|
35
|
+
className: 'slick-custom-tooltip',
|
|
36
|
+
offsetLeft: 0,
|
|
37
|
+
offsetRight: 0,
|
|
38
|
+
offsetTopBottom: 4,
|
|
39
|
+
hideArrow: false,
|
|
40
|
+
regularTooltipWhiteSpace: 'pre-line',
|
|
41
|
+
whiteSpace: 'normal',
|
|
42
|
+
};
|
|
43
|
+
this.name = 'CustomTooltip';
|
|
44
|
+
this._eventHandler = new Slick.EventHandler();
|
|
45
|
+
}
|
|
46
|
+
get addonOptions() {
|
|
47
|
+
return this._addonOptions;
|
|
48
|
+
}
|
|
49
|
+
get cancellablePromise() {
|
|
50
|
+
return this._cancellablePromise;
|
|
51
|
+
}
|
|
52
|
+
get cellAddonOptions() {
|
|
53
|
+
return this._cellAddonOptions;
|
|
54
|
+
}
|
|
55
|
+
get className() {
|
|
56
|
+
var _a, _b;
|
|
57
|
+
return (_b = (_a = this._cellAddonOptions) === null || _a === void 0 ? void 0 : _a.className) !== null && _b !== void 0 ? _b : 'slick-custom-tooltip';
|
|
58
|
+
}
|
|
59
|
+
get dataView() {
|
|
60
|
+
return this._grid.getData() || {};
|
|
61
|
+
}
|
|
62
|
+
/** Getter for the Grid Options pulled through the Grid Object */
|
|
63
|
+
get gridOptions() {
|
|
64
|
+
return this._grid.getOptions() || {};
|
|
65
|
+
}
|
|
66
|
+
/** Getter for the grid uid */
|
|
67
|
+
get gridUid() {
|
|
68
|
+
var _a;
|
|
69
|
+
return ((_a = this._grid) === null || _a === void 0 ? void 0 : _a.getUID()) || '';
|
|
70
|
+
}
|
|
71
|
+
get gridUidSelector() {
|
|
72
|
+
return this.gridUid ? `.${this.gridUid}` : '';
|
|
73
|
+
}
|
|
74
|
+
get tooltipElm() {
|
|
75
|
+
return this._tooltipElm;
|
|
76
|
+
}
|
|
77
|
+
addRxJsResource(rxjs) {
|
|
78
|
+
this._rxjs = rxjs;
|
|
79
|
+
}
|
|
80
|
+
init(grid, containerService) {
|
|
81
|
+
var _a, _b;
|
|
82
|
+
this._grid = grid;
|
|
83
|
+
this._rxjs = containerService.get('RxJsFacade');
|
|
84
|
+
this._sharedService = containerService.get('SharedService');
|
|
85
|
+
this._addonOptions = { ...this._defaultOptions, ...((_b = (_a = this._sharedService) === null || _a === void 0 ? void 0 : _a.gridOptions) === null || _b === void 0 ? void 0 : _b.customTooltip) };
|
|
86
|
+
this._eventHandler
|
|
87
|
+
.subscribe(grid.onMouseEnter, this.handleOnMouseEnter.bind(this))
|
|
88
|
+
.subscribe(grid.onHeaderMouseEnter, (e, args) => this.handleOnHeaderMouseEnterByType(e, args, 'slick-header-column'))
|
|
89
|
+
.subscribe(grid.onHeaderRowMouseEnter, (e, args) => this.handleOnHeaderMouseEnterByType(e, args, 'slick-headerrow-column'))
|
|
90
|
+
.subscribe(grid.onMouseLeave, this.hideTooltip.bind(this))
|
|
91
|
+
.subscribe(grid.onHeaderMouseLeave, this.hideTooltip.bind(this))
|
|
92
|
+
.subscribe(grid.onHeaderRowMouseLeave, this.hideTooltip.bind(this));
|
|
93
|
+
}
|
|
94
|
+
dispose() {
|
|
95
|
+
// hide (remove) any tooltip and unsubscribe from all events
|
|
96
|
+
this.hideTooltip();
|
|
97
|
+
this._cancellablePromise = undefined;
|
|
98
|
+
this._eventHandler.unsubscribeAll();
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* hide (remove) tooltip from the DOM, it will also remove it from the DOM and also cancel any pending requests (as mentioned below).
|
|
102
|
+
* When using async process, it will also cancel any opened Promise/Observable that might still be pending.
|
|
103
|
+
*/
|
|
104
|
+
hideTooltip() {
|
|
105
|
+
var _a, _b;
|
|
106
|
+
(_a = this._cancellablePromise) === null || _a === void 0 ? void 0 : _a.cancel();
|
|
107
|
+
(_b = this._observable$) === null || _b === void 0 ? void 0 : _b.unsubscribe();
|
|
108
|
+
const prevTooltip = document.body.querySelector(`.${this.className}${this.gridUidSelector}`);
|
|
109
|
+
prevTooltip === null || prevTooltip === void 0 ? void 0 : prevTooltip.remove();
|
|
110
|
+
}
|
|
111
|
+
getOptions() {
|
|
112
|
+
return this._addonOptions;
|
|
113
|
+
}
|
|
114
|
+
setOptions(newOptions) {
|
|
115
|
+
this._addonOptions = { ...this._addonOptions, ...newOptions };
|
|
116
|
+
}
|
|
117
|
+
// --
|
|
118
|
+
// protected functions
|
|
119
|
+
// ---------------------
|
|
120
|
+
/**
|
|
121
|
+
* Async process callback will hide any prior tooltip & then merge the new result with the item `dataContext` under a `__params` property
|
|
122
|
+
* (unless a new prop name is provided) to provice as dataContext object to the asyncPostFormatter.
|
|
123
|
+
*/
|
|
124
|
+
asyncProcessCallback(asyncResult, cell, value, columnDef, dataContext) {
|
|
125
|
+
var _a, _b, _c;
|
|
126
|
+
this.hideTooltip();
|
|
127
|
+
const itemWithAsyncData = { ...dataContext, [(_b = (_a = this.addonOptions) === null || _a === void 0 ? void 0 : _a.asyncParamsPropName) !== null && _b !== void 0 ? _b : '__params']: asyncResult };
|
|
128
|
+
if ((_c = this._cellAddonOptions) === null || _c === void 0 ? void 0 : _c.useRegularTooltip) {
|
|
129
|
+
this.renderRegularTooltip(this._cellAddonOptions.asyncPostFormatter, cell, value, columnDef, itemWithAsyncData);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
this.renderTooltipFormatter(this._cellAddonOptions.asyncPostFormatter, cell, value, columnDef, itemWithAsyncData);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/** depending on the selector type, execute the necessary handler code */
|
|
136
|
+
handleOnHeaderMouseEnterByType(event, args, selector) {
|
|
137
|
+
var _a, _b, _c;
|
|
138
|
+
this._cellType = selector;
|
|
139
|
+
// before doing anything, let's remove any previous tooltip before
|
|
140
|
+
// and cancel any opened Promise/Observable when using async
|
|
141
|
+
this.hideTooltip();
|
|
142
|
+
const cell = {
|
|
143
|
+
row: -1,
|
|
144
|
+
cell: this._grid.getColumns().findIndex((col) => { var _a, _b; return ((_b = (_a = args === null || args === void 0 ? void 0 : args.column) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : '') === col.id; })
|
|
145
|
+
};
|
|
146
|
+
const columnDef = args.column;
|
|
147
|
+
const item = {};
|
|
148
|
+
const isHeaderRowType = selector === 'slick-headerrow-column';
|
|
149
|
+
// run the override function (when defined), if the result is false it won't go further
|
|
150
|
+
args = args || {};
|
|
151
|
+
args.cell = cell.cell;
|
|
152
|
+
args.row = cell.row;
|
|
153
|
+
args.columnDef = columnDef;
|
|
154
|
+
args.dataContext = item;
|
|
155
|
+
args.grid = this._grid;
|
|
156
|
+
args.type = isHeaderRowType ? 'header-row' : 'header';
|
|
157
|
+
this._cellAddonOptions = { ...this._addonOptions, ...(columnDef === null || columnDef === void 0 ? void 0 : columnDef.customTooltip) };
|
|
158
|
+
if ((columnDef === null || columnDef === void 0 ? void 0 : columnDef.disableTooltip) || (typeof ((_a = this._cellAddonOptions) === null || _a === void 0 ? void 0 : _a.usabilityOverride) === 'function' && !this._cellAddonOptions.usabilityOverride(args))) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (columnDef && event.target) {
|
|
162
|
+
this._cellNodeElm = event.target.closest(`.${selector}`);
|
|
163
|
+
const formatter = isHeaderRowType ? this._cellAddonOptions.headerRowFormatter : this._cellAddonOptions.headerFormatter;
|
|
164
|
+
if (((_b = this._cellAddonOptions) === null || _b === void 0 ? void 0 : _b.useRegularTooltip) || !formatter) {
|
|
165
|
+
const formatterOrText = !isHeaderRowType ? columnDef.name : ((_c = this._cellAddonOptions) === null || _c === void 0 ? void 0 : _c.useRegularTooltip) ? null : formatter;
|
|
166
|
+
this.renderRegularTooltip(formatterOrText, cell, null, columnDef, item);
|
|
167
|
+
}
|
|
168
|
+
else if (this._cellNodeElm && typeof formatter === 'function') {
|
|
169
|
+
this.renderTooltipFormatter(formatter, cell, null, columnDef, item);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
async handleOnMouseEnter(event) {
|
|
174
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
175
|
+
this._cellType = 'slick-cell';
|
|
176
|
+
// before doing anything, let's remove any previous tooltip before
|
|
177
|
+
// and cancel any opened Promise/Observable when using async
|
|
178
|
+
this.hideTooltip();
|
|
179
|
+
if (event && this._grid) {
|
|
180
|
+
// get cell only when it's possible (ie, Composite Editor will not be able to get cell and so it will never show any tooltip)
|
|
181
|
+
const targetClassName = (_b = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.closest('.slick-cell')) === null || _b === void 0 ? void 0 : _b.className;
|
|
182
|
+
const cell = (targetClassName && /l\d+/.exec(targetClassName || '')) ? this._grid.getCellFromEvent(event) : null;
|
|
183
|
+
if (cell) {
|
|
184
|
+
const item = this.dataView ? this.dataView.getItem(cell.row) : this._grid.getDataItem(cell.row);
|
|
185
|
+
const columnDef = this._grid.getColumns()[cell.cell];
|
|
186
|
+
this._cellNodeElm = this._grid.getCellNode(cell.row, cell.cell);
|
|
187
|
+
if (item && columnDef) {
|
|
188
|
+
this._cellAddonOptions = { ...this._addonOptions, ...(columnDef === null || columnDef === void 0 ? void 0 : columnDef.customTooltip) };
|
|
189
|
+
if ((columnDef === null || columnDef === void 0 ? void 0 : columnDef.disableTooltip) || (typeof ((_c = this._cellAddonOptions) === null || _c === void 0 ? void 0 : _c.usabilityOverride) === 'function' && !this._cellAddonOptions.usabilityOverride({ cell: cell.cell, row: cell.row, dataContext: item, column: columnDef, grid: this._grid, type: 'cell' }))) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const value = item.hasOwnProperty(columnDef.field) ? item[columnDef.field] : null;
|
|
193
|
+
// when cell is currently lock for editing, we'll force a tooltip title search
|
|
194
|
+
const cellValue = this._grid.getEditorLock().isActive() ? null : value;
|
|
195
|
+
// when there aren't any formatter OR when user specifically want to use a regular tooltip (via "title" attribute)
|
|
196
|
+
if ((this._cellAddonOptions.useRegularTooltip && !((_d = this._cellAddonOptions) === null || _d === void 0 ? void 0 : _d.asyncProcess)) || !((_e = this._cellAddonOptions) === null || _e === void 0 ? void 0 : _e.formatter)) {
|
|
197
|
+
this.renderRegularTooltip(columnDef.formatter, cell, cellValue, columnDef, item);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
// when we aren't using regular tooltip and we do have a tooltip formatter, let's render it
|
|
201
|
+
if (typeof ((_f = this._cellAddonOptions) === null || _f === void 0 ? void 0 : _f.formatter) === 'function') {
|
|
202
|
+
this.renderTooltipFormatter(this._cellAddonOptions.formatter, cell, cellValue, columnDef, item);
|
|
203
|
+
}
|
|
204
|
+
// when tooltip is an Async (delayed, e.g. with a backend API call)
|
|
205
|
+
if (typeof ((_g = this._cellAddonOptions) === null || _g === void 0 ? void 0 : _g.asyncProcess) === 'function') {
|
|
206
|
+
const asyncProcess = this._cellAddonOptions.asyncProcess(cell.row, cell.cell, value, columnDef, item, this._grid);
|
|
207
|
+
if (!this._cellAddonOptions.asyncPostFormatter) {
|
|
208
|
+
console.error(`[Slickgrid-Universal] when using "asyncProcess" with Custom Tooltip, you must also provide an "asyncPostFormatter" formatter.`);
|
|
209
|
+
}
|
|
210
|
+
if (asyncProcess instanceof Promise) {
|
|
211
|
+
// create a new cancellable promise which will resolve, unless it's cancelled, with the udpated `dataContext` object that includes the `__params`
|
|
212
|
+
this._cancellablePromise = (0, common_1.cancellablePromise)(asyncProcess);
|
|
213
|
+
this._cancellablePromise.promise
|
|
214
|
+
.then((asyncResult) => this.asyncProcessCallback(asyncResult, cell, value, columnDef, item))
|
|
215
|
+
.catch((error) => {
|
|
216
|
+
// we will throw back any errors, unless it's a cancelled promise which in that case will be disregarded (thrown by the promise wrapper cancel() call)
|
|
217
|
+
if (!(error instanceof common_1.CancelledException)) {
|
|
218
|
+
console.error(error);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
else if ((_h = this._rxjs) === null || _h === void 0 ? void 0 : _h.isObservable(asyncProcess)) {
|
|
223
|
+
const rxjs = this._rxjs;
|
|
224
|
+
this._observable$ = asyncProcess
|
|
225
|
+
.pipe(
|
|
226
|
+
// use `switchMap` so that it cancels any previous subscription, it must return an observable so we can use `of` for that, and then finally we can subscribe to the new observable
|
|
227
|
+
rxjs.switchMap((asyncResult) => rxjs.of(asyncResult))).subscribe((asyncResult) => this.asyncProcessCallback(asyncResult, cell, value, columnDef, item), (error) => console.error(error));
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Parse the Custom Formatter (when provided) or return directly the text when it is already a string.
|
|
237
|
+
* We will also sanitize the text in both cases before returning it so that it can be used safely.
|
|
238
|
+
*/
|
|
239
|
+
parseFormatterAndSanitize(formatterOrText, cell, value, columnDef, item) {
|
|
240
|
+
if (typeof formatterOrText === 'function') {
|
|
241
|
+
const tooltipText = formatterOrText(cell.row, cell.cell, value, columnDef, item, this._grid);
|
|
242
|
+
const formatterText = (typeof tooltipText === 'object' && (tooltipText === null || tooltipText === void 0 ? void 0 : tooltipText.text)) ? tooltipText.text : (typeof tooltipText === 'string' ? tooltipText : '');
|
|
243
|
+
return (0, common_1.sanitizeTextByAvailableSanitizer)(this.gridOptions, formatterText);
|
|
244
|
+
}
|
|
245
|
+
else if (typeof formatterOrText === 'string') {
|
|
246
|
+
return (0, common_1.sanitizeTextByAvailableSanitizer)(this.gridOptions, formatterOrText);
|
|
247
|
+
}
|
|
248
|
+
return '';
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Parse the cell formatter and assume it might be html
|
|
252
|
+
* then create a temporary html element to easily retrieve the first [title=""] attribute text content
|
|
253
|
+
* also clear the "title" attribute from the grid div text content so that it won't show also as a 2nd browser tooltip
|
|
254
|
+
*/
|
|
255
|
+
renderRegularTooltip(formatterOrText, cell, value, columnDef, item) {
|
|
256
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
257
|
+
const tmpDiv = (0, common_1.createDomElement)('div', { innerHTML: this.parseFormatterAndSanitize(formatterOrText, cell, value, columnDef, item) });
|
|
258
|
+
let tooltipText = (_a = columnDef === null || columnDef === void 0 ? void 0 : columnDef.toolTip) !== null && _a !== void 0 ? _a : '';
|
|
259
|
+
let tmpTitleElm;
|
|
260
|
+
if (!tooltipText) {
|
|
261
|
+
if (this._cellType === 'slick-cell' && this._cellNodeElm && (this._cellNodeElm.clientWidth < this._cellNodeElm.scrollWidth) && !((_b = this._cellAddonOptions) === null || _b === void 0 ? void 0 : _b.useRegularTooltipFromFormatterOnly)) {
|
|
262
|
+
tooltipText = (_d = (_c = this._cellNodeElm.textContent) === null || _c === void 0 ? void 0 : _c.trim()) !== null && _d !== void 0 ? _d : '';
|
|
263
|
+
if (((_e = this._cellAddonOptions) === null || _e === void 0 ? void 0 : _e.tooltipTextMaxLength) && tooltipText.length > ((_f = this._cellAddonOptions) === null || _f === void 0 ? void 0 : _f.tooltipTextMaxLength)) {
|
|
264
|
+
tooltipText = tooltipText.substring(0, this._cellAddonOptions.tooltipTextMaxLength - 3) + '...';
|
|
265
|
+
}
|
|
266
|
+
tmpTitleElm = this._cellNodeElm;
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
if ((_g = this._cellAddonOptions) === null || _g === void 0 ? void 0 : _g.useRegularTooltipFromFormatterOnly) {
|
|
270
|
+
tmpTitleElm = tmpDiv.querySelector('[title], [data-slick-tooltip]');
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
tmpTitleElm = (0, common_1.findFirstElementAttribute)(this._cellNodeElm, ['title', 'data-slick-tooltip']) ? this._cellNodeElm : tmpDiv.querySelector('[title], [data-slick-tooltip]');
|
|
274
|
+
if ((!tmpTitleElm || !(0, common_1.findFirstElementAttribute)(tmpTitleElm, ['title', 'data-slick-tooltip'])) && this._cellNodeElm) {
|
|
275
|
+
tmpTitleElm = this._cellNodeElm.querySelector('[title], [data-slick-tooltip]');
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (!tooltipText || (typeof formatterOrText === 'function' && ((_h = this._cellAddonOptions) === null || _h === void 0 ? void 0 : _h.useRegularTooltipFromFormatterOnly))) {
|
|
279
|
+
tooltipText = (0, common_1.findFirstElementAttribute)(tmpTitleElm, ['title', 'data-slick-tooltip']) || '';
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (tooltipText !== '') {
|
|
284
|
+
this.renderTooltipFormatter(formatterOrText, cell, value, columnDef, item, tooltipText);
|
|
285
|
+
}
|
|
286
|
+
// also clear any "title" attribute to avoid showing a 2nd browser tooltip
|
|
287
|
+
this.swapAndClearTitleAttribute(tmpTitleElm, tooltipText);
|
|
288
|
+
}
|
|
289
|
+
renderTooltipFormatter(formatter, cell, value, columnDef, item, tooltipText, inputTitleElm) {
|
|
290
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
291
|
+
// create the tooltip DOM element with the text returned by the Formatter
|
|
292
|
+
this._tooltipElm = (0, common_1.createDomElement)('div', { className: this.className });
|
|
293
|
+
this._tooltipElm.classList.add(this.gridUid);
|
|
294
|
+
this._tooltipElm.classList.add('l' + cell.cell);
|
|
295
|
+
this._tooltipElm.classList.add('r' + cell.cell);
|
|
296
|
+
// when cell is currently lock for editing, we'll force a tooltip title search
|
|
297
|
+
// that can happen when user has a formatter but is currently editing and in that case we want the new value
|
|
298
|
+
// ie: when user is currently editing and uses the Slider, when dragging its value is changing, so we wish to use the editing value instead of the previous cell value.
|
|
299
|
+
if (value === null || value === undefined) {
|
|
300
|
+
const tmpTitleElm = (_a = this._cellNodeElm) === null || _a === void 0 ? void 0 : _a.querySelector('[title], [data-slick-tooltip]');
|
|
301
|
+
value = (0, common_1.findFirstElementAttribute)(tmpTitleElm, ['title', 'data-slick-tooltip']) || value;
|
|
302
|
+
}
|
|
303
|
+
let outputText = tooltipText || this.parseFormatterAndSanitize(formatter, cell, value, columnDef, item) || '';
|
|
304
|
+
outputText = (((_b = this._cellAddonOptions) === null || _b === void 0 ? void 0 : _b.tooltipTextMaxLength) && outputText.length > this._cellAddonOptions.tooltipTextMaxLength) ? outputText.substring(0, this._cellAddonOptions.tooltipTextMaxLength - 3) + '...' : outputText;
|
|
305
|
+
let finalOutputText = '';
|
|
306
|
+
if (!tooltipText || ((_c = this._cellAddonOptions) === null || _c === void 0 ? void 0 : _c.renderRegularTooltipAsHtml)) {
|
|
307
|
+
finalOutputText = (0, common_1.sanitizeTextByAvailableSanitizer)(this.gridOptions, outputText);
|
|
308
|
+
this._tooltipElm.innerHTML = finalOutputText;
|
|
309
|
+
this._tooltipElm.style.whiteSpace = (_e = (_d = this._cellAddonOptions) === null || _d === void 0 ? void 0 : _d.whiteSpace) !== null && _e !== void 0 ? _e : this._defaultOptions.whiteSpace;
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
finalOutputText = outputText || '';
|
|
313
|
+
this._tooltipElm.textContent = finalOutputText;
|
|
314
|
+
this._tooltipElm.style.whiteSpace = (_g = (_f = this._cellAddonOptions) === null || _f === void 0 ? void 0 : _f.regularTooltipWhiteSpace) !== null && _g !== void 0 ? _g : this._defaultOptions.regularTooltipWhiteSpace; // use `pre` so that sequences of white space are collapsed. Lines are broken at newline characters
|
|
315
|
+
}
|
|
316
|
+
// optional max height/width of the tooltip container
|
|
317
|
+
if ((_h = this._cellAddonOptions) === null || _h === void 0 ? void 0 : _h.maxHeight) {
|
|
318
|
+
this._tooltipElm.style.maxHeight = `${this._cellAddonOptions.maxHeight}px`;
|
|
319
|
+
}
|
|
320
|
+
if ((_j = this._cellAddonOptions) === null || _j === void 0 ? void 0 : _j.maxWidth) {
|
|
321
|
+
this._tooltipElm.style.maxWidth = `${this._cellAddonOptions.maxWidth}px`;
|
|
322
|
+
}
|
|
323
|
+
// when do have text to show, then append the new tooltip to the html body & reposition the tooltip
|
|
324
|
+
if (finalOutputText) {
|
|
325
|
+
document.body.appendChild(this._tooltipElm);
|
|
326
|
+
// reposition the tooltip on top of the cell that triggered the mouse over event
|
|
327
|
+
this.reposition(cell);
|
|
328
|
+
// user could optionally hide the tooltip arrow (we can simply update the CSS variables, that's the only way we have to update CSS pseudo)
|
|
329
|
+
if (!((_k = this._cellAddonOptions) === null || _k === void 0 ? void 0 : _k.hideArrow)) {
|
|
330
|
+
this._tooltipElm.classList.add('tooltip-arrow');
|
|
331
|
+
}
|
|
332
|
+
// also clear any "title" attribute to avoid showing a 2nd browser tooltip
|
|
333
|
+
this.swapAndClearTitleAttribute(inputTitleElm, outputText);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Reposition the Tooltip to be top-left position over the cell.
|
|
338
|
+
* By default we use an "auto" mode which will allow to position the Tooltip to the best logical position in the window, also when we mention position, we are talking about the relative position against the grid cell.
|
|
339
|
+
* We can assume that in 80% of the time the default position is top-right, the default is "auto" but we can also override it and use a specific position.
|
|
340
|
+
* Most of the time positioning of the tooltip will be to the "top-right" of the cell is ok but if our column is completely on the right side then we'll want to change the position to "left" align.
|
|
341
|
+
* Same goes for the top/bottom position, Most of the time positioning the tooltip to the "top" but if we are hovering a cell at the top of the grid and there's no room to display it then we might need to reposition to "bottom" instead.
|
|
342
|
+
*/
|
|
343
|
+
reposition(cell) {
|
|
344
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
345
|
+
if (this._tooltipElm) {
|
|
346
|
+
this._cellNodeElm = this._cellNodeElm || this._grid.getCellNode(cell.row, cell.cell);
|
|
347
|
+
const cellPosition = (0, common_1.getHtmlElementOffset)(this._cellNodeElm) || { top: 0, left: 0 };
|
|
348
|
+
const cellContainerWidth = this._cellNodeElm.offsetWidth;
|
|
349
|
+
const calculatedTooltipHeight = this._tooltipElm.getBoundingClientRect().height;
|
|
350
|
+
const calculatedTooltipWidth = this._tooltipElm.getBoundingClientRect().width;
|
|
351
|
+
const calculatedBodyWidth = document.body.offsetWidth || window.innerWidth;
|
|
352
|
+
// first calculate the default (top/left) position
|
|
353
|
+
let newPositionTop = (cellPosition.top || 0) - this._tooltipElm.offsetHeight - ((_b = (_a = this._cellAddonOptions) === null || _a === void 0 ? void 0 : _a.offsetTopBottom) !== null && _b !== void 0 ? _b : 0);
|
|
354
|
+
let newPositionLeft = (cellPosition.left || 0) - ((_d = (_c = this._cellAddonOptions) === null || _c === void 0 ? void 0 : _c.offsetRight) !== null && _d !== void 0 ? _d : 0);
|
|
355
|
+
// user could explicitely use a "left-align" arrow position, (when user knows his column is completely on the right in the grid)
|
|
356
|
+
// or when using "auto" and we detect not enough available space then we'll position to the "left" of the cell
|
|
357
|
+
// NOTE the class name is for the arrow and is inverse compare to the tooltip itself, so if user ask for "left-align", then the arrow will in fact be "arrow-right-align"
|
|
358
|
+
const position = (_f = (_e = this._cellAddonOptions) === null || _e === void 0 ? void 0 : _e.position) !== null && _f !== void 0 ? _f : 'auto';
|
|
359
|
+
if (position === 'center') {
|
|
360
|
+
newPositionLeft += (cellContainerWidth / 2) - (calculatedTooltipWidth / 2) + ((_h = (_g = this._cellAddonOptions) === null || _g === void 0 ? void 0 : _g.offsetRight) !== null && _h !== void 0 ? _h : 0);
|
|
361
|
+
this._tooltipElm.classList.remove('arrow-left-align');
|
|
362
|
+
this._tooltipElm.classList.remove('arrow-right-align');
|
|
363
|
+
this._tooltipElm.classList.add('arrow-center-align');
|
|
364
|
+
}
|
|
365
|
+
else if (position === 'right-align' || ((position === 'auto' || position !== 'left-align') && (newPositionLeft + calculatedTooltipWidth) > calculatedBodyWidth)) {
|
|
366
|
+
newPositionLeft -= (calculatedTooltipWidth - cellContainerWidth - ((_k = (_j = this._cellAddonOptions) === null || _j === void 0 ? void 0 : _j.offsetLeft) !== null && _k !== void 0 ? _k : 0));
|
|
367
|
+
this._tooltipElm.classList.remove('arrow-center-align');
|
|
368
|
+
this._tooltipElm.classList.remove('arrow-left-align');
|
|
369
|
+
this._tooltipElm.classList.add('arrow-right-align');
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
this._tooltipElm.classList.remove('arrow-center-align');
|
|
373
|
+
this._tooltipElm.classList.remove('arrow-right-align');
|
|
374
|
+
this._tooltipElm.classList.add('arrow-left-align');
|
|
375
|
+
}
|
|
376
|
+
// do the same calculation/reposition with top/bottom (default is top of the cell or in other word starting from the cell going down)
|
|
377
|
+
// NOTE the class name is for the arrow and is inverse compare to the tooltip itself, so if user ask for "bottom", then the arrow will in fact be "arrow-top"
|
|
378
|
+
if (position === 'bottom' || ((position === 'auto' || position !== 'top') && calculatedTooltipHeight > (0, common_1.calculateAvailableSpace)(this._cellNodeElm).top)) {
|
|
379
|
+
newPositionTop = (cellPosition.top || 0) + ((_l = this.gridOptions.rowHeight) !== null && _l !== void 0 ? _l : 0) + ((_o = (_m = this._cellAddonOptions) === null || _m === void 0 ? void 0 : _m.offsetTopBottom) !== null && _o !== void 0 ? _o : 0);
|
|
380
|
+
this._tooltipElm.classList.remove('arrow-down');
|
|
381
|
+
this._tooltipElm.classList.add('arrow-up');
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
this._tooltipElm.classList.add('arrow-down');
|
|
385
|
+
this._tooltipElm.classList.remove('arrow-up');
|
|
386
|
+
}
|
|
387
|
+
// reposition the tooltip over the cell (90% of the time this will end up using a position on the "right" of the cell)
|
|
388
|
+
this._tooltipElm.style.top = `${newPositionTop}px`;
|
|
389
|
+
this._tooltipElm.style.left = `${newPositionLeft}px`;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* swap and copy the "title" attribute into a new custom attribute then clear the "title" attribute
|
|
394
|
+
* from the grid div text content so that it won't show also as a 2nd browser tooltip
|
|
395
|
+
*/
|
|
396
|
+
swapAndClearTitleAttribute(inputTitleElm, tooltipText) {
|
|
397
|
+
var _a;
|
|
398
|
+
// the title attribute might be directly on the slick-cell container element (when formatter returns a result object)
|
|
399
|
+
// OR in a child element (most commonly as a custom formatter)
|
|
400
|
+
const titleElm = inputTitleElm || (this._cellNodeElm && ((this._cellNodeElm.hasAttribute('title') && this._cellNodeElm.getAttribute('title')) ? this._cellNodeElm : (_a = this._cellNodeElm) === null || _a === void 0 ? void 0 : _a.querySelector('[title]')));
|
|
401
|
+
// flip tooltip text from `title` to `data-slick-tooltip`
|
|
402
|
+
if (titleElm) {
|
|
403
|
+
titleElm.setAttribute('data-slick-tooltip', tooltipText || '');
|
|
404
|
+
if (titleElm.hasAttribute('title')) {
|
|
405
|
+
titleElm.setAttribute('title', '');
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
exports.SlickCustomTooltip = SlickCustomTooltip;
|
|
408
411
|
//# sourceMappingURL=slickCustomTooltip.js.map
|