jsl-ui 9.14.6 → 9.15.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.
@@ -34,6 +34,9 @@ var MoveableContainer = /** @class */ (function () {
34
34
  var target = evt.target;
35
35
  var directChild = target;
36
36
  while (directChild.parentElement != null && directChild.parentElement !== _this.container) {
37
+ if (_this.options.selector != null && directChild.matches(_this.options.selector)) {
38
+ break;
39
+ }
37
40
  directChild = directChild.parentElement;
38
41
  }
39
42
  if (directChild.parentElement == null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsl-ui",
3
- "version": "9.14.6",
3
+ "version": "9.15.0",
4
4
  "description": "javascript UI library",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -1 +0,0 @@
1
- export declare function CellExternalCopyManager(options: any): void;
@@ -1,411 +0,0 @@
1
- import { jQueryReplacement } from "../../core/jq";
2
- import { Slick } from "../slick.core";
3
- var $ = jQueryReplacement;
4
- // register namespace
5
- $.deepExtend(Slick, {
6
- "CellExternalCopyManager": CellExternalCopyManager
7
- });
8
- export function CellExternalCopyManager(options) {
9
- /*
10
- This manager enables users to copy/paste data from/to an external Spreadsheet application
11
- such as MS-Excel® or OpenOffice-Spreadsheet.
12
-
13
- Since it is not possible to access directly the clipboard in javascript, the plugin uses
14
- a trick to do it's job. After detecting the keystroke, we dynamically create a textarea
15
- where the browser copies/pastes the serialized data.
16
-
17
- options:
18
- copiedCellStyle : sets the css className used for copied cells. default : "copied"
19
- copiedCellStyleLayerKey : sets the layer key for setting css values of copied cells. default : "copy-manager"
20
- dataItemColumnValueExtractor : option to specify a custom column value extractor function
21
- dataItemColumnValueSetter : option to specify a custom column value setter function
22
- clipboardCommandHandler : option to specify a custom handler for paste actions
23
- includeHeaderWhenCopying : set to true and the plugin will take the name property from each column (which is usually what appears in your header) and put that as the first row of the text that's copied to the clipboard
24
- bodyElement: option to specify a custom DOM element which to will be added the hidden textbox. It's useful if the grid is inside a modal dialog.
25
- onCopyInit: optional handler to run when copy action initializes
26
- onCopySuccess: optional handler to run when copy action is complete
27
- newRowCreator: function to add rows to table if paste overflows bottom of table, if this function is not provided new rows will be ignored.
28
- readOnlyMode: suppresses paste
29
- headerColumnValueExtractor : option to specify a custom column header value extractor function
30
- */
31
- var _grid;
32
- var _self = this;
33
- var _copiedRanges;
34
- var _options = options || {};
35
- var _copiedCellStyleLayerKey = _options.copiedCellStyleLayerKey || "copy-manager";
36
- var _copiedCellStyle = _options.copiedCellStyle || "copied";
37
- var _clearCopyTI = 0;
38
- var _bodyElement = _options.bodyElement || document.body;
39
- var _onCopyInit = _options.onCopyInit || null;
40
- var _onCopySuccess = _options.onCopySuccess || null;
41
- var keyCodes = {
42
- 'C': 67,
43
- 'V': 86,
44
- 'ESC': 27,
45
- 'INSERT': 45
46
- };
47
- function init(grid) {
48
- _grid = grid;
49
- _grid.onKeyDown.subscribe(handleKeyDown);
50
- // we need a cell selection model
51
- var cellSelectionModel = grid.getSelectionModel();
52
- if (!cellSelectionModel) {
53
- throw new Error("Selection model is mandatory for this plugin. Please set a selection model on the grid before adding this plugin: grid.setSelectionModel(new Slick.CellSelectionModel())");
54
- }
55
- // we give focus on the grid when a selection is done on it.
56
- // without this, if the user selects a range of cell without giving focus on a particular cell, the grid doesn't get the focus and key stroke handles (ctrl+c) don't work
57
- cellSelectionModel.onSelectedRangesChanged.subscribe(function (e, args) {
58
- _grid.focus();
59
- });
60
- }
61
- function destroy() {
62
- _grid.onKeyDown.unsubscribe(handleKeyDown);
63
- }
64
- function getHeaderValueForColumn(columnDef) {
65
- if (_options.headerColumnValueExtractor) {
66
- var val = _options.headerColumnValueExtractor(columnDef);
67
- if (val) {
68
- return val;
69
- }
70
- }
71
- return columnDef.name;
72
- }
73
- function getDataItemValueForColumn(item, columnDef, e) {
74
- if (_options.dataItemColumnValueExtractor) {
75
- var val = _options.dataItemColumnValueExtractor(item, columnDef);
76
- if (val) {
77
- return val;
78
- }
79
- }
80
- var retVal = '';
81
- // if a custom getter is not defined, we call serializeValue of the editor to serialize
82
- if (columnDef.editor) {
83
- var editorArgs = {
84
- 'container': document.createElement('div'),
85
- 'column': columnDef,
86
- 'position': { 'top': 0, 'left': 0 },
87
- 'grid': _grid,
88
- 'event': e
89
- };
90
- var editor = new columnDef.editor(editorArgs);
91
- editor.loadValue(item);
92
- retVal = editor.serializeValue();
93
- editor.destroy();
94
- }
95
- else {
96
- retVal = item[columnDef.field];
97
- }
98
- return retVal;
99
- }
100
- function setDataItemValueForColumn(item, columnDef, value) {
101
- if (columnDef.denyPaste) {
102
- return null;
103
- }
104
- if (_options.dataItemColumnValueSetter) {
105
- return _options.dataItemColumnValueSetter(item, columnDef, value);
106
- }
107
- // if a custom setter is not defined, we call applyValue of the editor to unserialize
108
- if (columnDef.editor) {
109
- var editorArgs = {
110
- 'container': document.createElement('div'),
111
- 'column': columnDef,
112
- 'position': { 'top': 0, 'left': 0 },
113
- 'grid': _grid
114
- };
115
- var editor = new columnDef.editor(editorArgs);
116
- editor.loadValue(item);
117
- editor.applyValue(item, value);
118
- editor.destroy();
119
- }
120
- else {
121
- item[columnDef.field] = value;
122
- }
123
- }
124
- function _createTextBox(innerText) {
125
- var ta = document.createElement('textarea');
126
- ta.style.position = 'absolute';
127
- ta.style.left = '-1000px';
128
- ta.style.top = document.body.scrollTop + 'px';
129
- ta.value = innerText;
130
- _bodyElement.appendChild(ta);
131
- ta.select();
132
- return ta;
133
- }
134
- function _decodeTabularData(_grid, ta) {
135
- var columns = _grid.getColumns();
136
- var clipText = ta.value;
137
- var clipRows = clipText.split(/[\n\f\r]/);
138
- // trim trailing CR if present
139
- if (clipRows[clipRows.length - 1] == "") {
140
- clipRows.pop();
141
- }
142
- var clippedRange = [];
143
- var j = 0;
144
- _bodyElement.removeChild(ta);
145
- for (var i = 0; i < clipRows.length; i++) {
146
- if (clipRows[i] != "")
147
- clippedRange[j++] = clipRows[i].split("\t");
148
- else
149
- clippedRange[i] = [""];
150
- }
151
- var selectedCell = _grid.getActiveCell();
152
- var ranges = _grid.getSelectionModel().getSelectedRanges();
153
- var selectedRange = ranges && ranges.length ? ranges[0] : null; // pick only one selection
154
- var activeRow = null;
155
- var activeCell = null;
156
- if (selectedRange) {
157
- activeRow = selectedRange.fromRow;
158
- activeCell = selectedRange.fromCell;
159
- }
160
- else if (selectedCell) {
161
- activeRow = selectedCell.row;
162
- activeCell = selectedCell.cell;
163
- }
164
- else {
165
- // we don't know where to paste
166
- return;
167
- }
168
- var oneCellToMultiple = false;
169
- var destH = clippedRange.length;
170
- var destW = clippedRange.length ? clippedRange[0].length : 0;
171
- if (clippedRange.length == 1 && clippedRange[0].length == 1 && selectedRange) {
172
- oneCellToMultiple = true;
173
- destH = selectedRange.toRow - selectedRange.fromRow + 1;
174
- destW = selectedRange.toCell - selectedRange.fromCell + 1;
175
- }
176
- var availableRows = _grid.getData().length - activeRow;
177
- var addRows = 0;
178
- // ignore new rows if we don't have a "newRowCreator"
179
- if (availableRows < destH && _options.newRowCreator) {
180
- var d = _grid.getData();
181
- for (addRows = 1; addRows <= destH - availableRows; addRows++)
182
- d.push({});
183
- _grid.setData(d);
184
- _grid.render();
185
- }
186
- var overflowsBottomOfGrid = activeRow + destH > _grid.getDataLength();
187
- if (_options.newRowCreator && overflowsBottomOfGrid) {
188
- var newRowsNeeded = activeRow + destH - _grid.getDataLength();
189
- _options.newRowCreator(newRowsNeeded);
190
- }
191
- var clipCommand = {
192
- isClipboardCommand: true,
193
- clippedRange: clippedRange,
194
- oldValues: [],
195
- cellExternalCopyManager: _self,
196
- _options: _options,
197
- setDataItemValueForColumn: setDataItemValueForColumn,
198
- markCopySelection: markCopySelection,
199
- oneCellToMultiple: oneCellToMultiple,
200
- activeRow: activeRow,
201
- activeCell: activeCell,
202
- destH: destH,
203
- destW: destW,
204
- maxDestY: _grid.getDataLength(),
205
- maxDestX: _grid.getColumns().length,
206
- h: 0,
207
- w: 0,
208
- execute: function () {
209
- this.h = 0;
210
- for (var y = 0; y < this.destH; y++) {
211
- this.oldValues[y] = [];
212
- this.w = 0;
213
- this.h++;
214
- for (var x = 0; x < this.destW; x++) {
215
- this.w++;
216
- var desty = activeRow + y;
217
- var destx = activeCell + x;
218
- if (desty < this.maxDestY && destx < this.maxDestX) {
219
- var nd = _grid.getCellNode(desty, destx);
220
- var dt = _grid.getDataItem(desty);
221
- this.oldValues[y][x] = dt[columns[destx]['field']];
222
- if (oneCellToMultiple)
223
- this.setDataItemValueForColumn(dt, columns[destx], clippedRange[0][0]);
224
- else
225
- this.setDataItemValueForColumn(dt, columns[destx], clippedRange[y] ? clippedRange[y][x] : '');
226
- _grid.updateCell(desty, destx);
227
- _grid.onCellChange.notify({
228
- row: desty,
229
- cell: destx,
230
- item: dt,
231
- grid: _grid
232
- });
233
- }
234
- }
235
- }
236
- var bRange = {
237
- 'fromCell': activeCell,
238
- 'fromRow': activeRow,
239
- 'toCell': activeCell + this.w - 1,
240
- 'toRow': activeRow + this.h - 1
241
- };
242
- this.markCopySelection([bRange]);
243
- _grid.getSelectionModel().setSelectedRanges([bRange]);
244
- this.cellExternalCopyManager.onPasteCells.notify({ ranges: [bRange] });
245
- },
246
- undo: function () {
247
- for (var y = 0; y < this.destH; y++) {
248
- for (var x = 0; x < this.destW; x++) {
249
- var desty = activeRow + y;
250
- var destx = activeCell + x;
251
- if (desty < this.maxDestY && destx < this.maxDestX) {
252
- var nd = _grid.getCellNode(desty, destx);
253
- var dt = _grid.getDataItem(desty);
254
- if (oneCellToMultiple)
255
- this.setDataItemValueForColumn(dt, columns[destx], this.oldValues[0][0]);
256
- else
257
- this.setDataItemValueForColumn(dt, columns[destx], this.oldValues[y][x]);
258
- _grid.updateCell(desty, destx);
259
- _grid.onCellChange.notify({
260
- row: desty,
261
- cell: destx,
262
- item: dt,
263
- grid: _grid
264
- });
265
- }
266
- }
267
- }
268
- var bRange = {
269
- 'fromCell': activeCell,
270
- 'fromRow': activeRow,
271
- 'toCell': activeCell + this.w - 1,
272
- 'toRow': activeRow + this.h - 1
273
- };
274
- this.markCopySelection([bRange]);
275
- _grid.getSelectionModel().setSelectedRanges([bRange]);
276
- this.cellExternalCopyManager.onPasteCells.notify({ ranges: [bRange] });
277
- if (addRows > 1) {
278
- var d = _grid.getData();
279
- for (; addRows > 1; addRows--)
280
- d.splice(d.length - 1, 1);
281
- _grid.setData(d);
282
- _grid.render();
283
- }
284
- }
285
- };
286
- if (_options.clipboardCommandHandler) {
287
- _options.clipboardCommandHandler(clipCommand);
288
- }
289
- else {
290
- clipCommand.execute();
291
- }
292
- }
293
- function handleKeyDown(e, args) {
294
- var ranges;
295
- if (!_grid.getEditorLock().isActive() || _grid.getOptions().autoEdit) {
296
- if (e.which == keyCodes.ESC) {
297
- if (_copiedRanges) {
298
- e.preventDefault();
299
- clearCopySelection();
300
- _self.onCopyCancelled.notify({ ranges: _copiedRanges });
301
- _copiedRanges = null;
302
- }
303
- }
304
- if ((e.which === keyCodes.C || e.which === keyCodes.INSERT) && (e.ctrlKey || e.metaKey) && !e.shiftKey) { // CTRL+C or CTRL+INS
305
- if (_onCopyInit) {
306
- _onCopyInit.call();
307
- }
308
- ranges = _grid.getSelectionModel().getSelectedRanges();
309
- if (ranges.length != 0) {
310
- _copiedRanges = ranges;
311
- markCopySelection(ranges);
312
- _self.onCopyCells.notify({ ranges: ranges });
313
- var columns = _grid.getColumns();
314
- var clipText = "";
315
- for (var rg = 0; rg < ranges.length; rg++) {
316
- var range = ranges[rg];
317
- var clipTextRows = [];
318
- for (var i = range.fromRow; i < range.toRow + 1; i++) {
319
- var clipTextCells = [];
320
- var dt = _grid.getDataItem(i);
321
- if (clipTextRows.length === 0 && _options.includeHeaderWhenCopying) {
322
- var clipTextHeaders = [];
323
- for (var j = range.fromCell; j < range.toCell + 1; j++) {
324
- if (columns[j].name.length > 0)
325
- clipTextHeaders.push(getHeaderValueForColumn(columns[j]));
326
- }
327
- clipTextRows.push(clipTextHeaders.join("\t"));
328
- }
329
- for (var j = range.fromCell; j < range.toCell + 1; j++) {
330
- clipTextCells.push(getDataItemValueForColumn(dt, columns[j], e));
331
- }
332
- clipTextRows.push(clipTextCells.join("\t"));
333
- }
334
- clipText += clipTextRows.join("\r\n") + "\r\n";
335
- }
336
- // if (true) {
337
- navigator.clipboard.writeText(clipText);
338
- // }
339
- // else {
340
- // var focusEl = document.activeElement;
341
- // var ta = _createTextBox(clipText);
342
- // ta.focus();
343
- // setTimeout(function () {
344
- // _bodyElement.removeChild(ta);
345
- // // restore focus
346
- // if (focusEl)
347
- // (focusEl.focus();
348
- // else
349
- // console.log("Not element to restore focus to after copy?");
350
- // }, 100);
351
- // if (_onCopySuccess) {
352
- // var rowCount = 0;
353
- // // If it's cell selection, use the toRow/fromRow fields
354
- // if (ranges.length === 1) {
355
- // rowCount = (ranges[0].toRow + 1) - ranges[0].fromRow;
356
- // }
357
- // else {
358
- // rowCount = ranges.length;
359
- // }
360
- // _onCopySuccess.call(this, rowCount);
361
- // }
362
- // return false;
363
- // }
364
- }
365
- }
366
- if (!_options.readOnlyMode && ((e.which === keyCodes.V && (e.ctrlKey || e.metaKey) && !e.shiftKey)
367
- || (e.which === keyCodes.INSERT && e.shiftKey && !e.ctrlKey))) { // CTRL+V or Shift+INS
368
- var ta = _createTextBox('');
369
- setTimeout(function () {
370
- _decodeTabularData(_grid, ta);
371
- }, 100);
372
- return false;
373
- }
374
- }
375
- }
376
- function markCopySelection(ranges) {
377
- clearCopySelection();
378
- var columns = _grid.getColumns();
379
- var hash = {};
380
- for (var i = 0; i < ranges.length; i++) {
381
- for (var j = ranges[i].fromRow; j <= ranges[i].toRow; j++) {
382
- hash[j] = {};
383
- for (var k = ranges[i].fromCell; k <= ranges[i].toCell && k < columns.length; k++) {
384
- hash[j][columns[k].id] = _copiedCellStyle;
385
- }
386
- }
387
- }
388
- _grid.setCellCssStyles(_copiedCellStyleLayerKey, hash);
389
- clearTimeout(_clearCopyTI);
390
- _clearCopyTI = window.setTimeout(function () {
391
- _self.clearCopySelection();
392
- }, 2000);
393
- }
394
- function clearCopySelection() {
395
- _grid.removeCellCssStyles(_copiedCellStyleLayerKey);
396
- }
397
- function setIncludeHeaderWhenCopying(includeHeaderWhenCopying) {
398
- _options.includeHeaderWhenCopying = includeHeaderWhenCopying;
399
- }
400
- $.shallowExtend(this, {
401
- "init": init,
402
- "destroy": destroy,
403
- "pluginName": "CellExternalCopyManager",
404
- "clearCopySelection": clearCopySelection,
405
- "handleKeyDown": handleKeyDown,
406
- "onCopyCells": new Slick.Event(),
407
- "onCopyCancelled": new Slick.Event(),
408
- "onPasteCells": new Slick.Event(),
409
- "setIncludeHeaderWhenCopying": setIncludeHeaderWhenCopying
410
- });
411
- }