canvas-datagrid 0.3.17 → 0.3.21
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 +30 -0
- package/dist/canvas-datagrid.debug.js +883 -73
- package/dist/canvas-datagrid.debug.map +1 -1
- package/dist/canvas-datagrid.js +1 -1
- package/dist/canvas-datagrid.module.js +1 -1
- package/dist/canvas-datagrid.module.js.map +1 -1
- package/dist/types.d.ts +19 -0
- package/lib/button.js +326 -0
- package/lib/contextMenu.js +47 -8
- package/lib/defaults.js +27 -0
- package/lib/docs.js +9 -1
- package/lib/dom.js +90 -0
- package/lib/draw.js +98 -6
- package/lib/events/index.js +203 -52
- package/lib/intf.js +51 -0
- package/lib/main.js +2 -0
- package/lib/publicMethods.js +107 -5
- package/package.json +1 -1
package/dist/types.d.ts
CHANGED
|
@@ -392,6 +392,15 @@ declare class canvasDatagrid {
|
|
|
392
392
|
* @param y - The row index of the cell to scroll to.
|
|
393
393
|
*/
|
|
394
394
|
static gotoRow(y: number): void;
|
|
395
|
+
/**
|
|
396
|
+
* Add a button into the cell.
|
|
397
|
+
* @param columnIndex - The column index of the cell to to add a button.
|
|
398
|
+
* @param rowIndex - The row index of the cell to to add a button.
|
|
399
|
+
* @param offset - Offset how far go away from cell.
|
|
400
|
+
* @param items - a list of items to add into button menu.
|
|
401
|
+
* @param imgSrc - icon path to add into button.
|
|
402
|
+
*/
|
|
403
|
+
static addButton(columnIndex: number, rowIndex: number, offset: any, items: any, imgSrc: string): void;
|
|
395
404
|
/**
|
|
396
405
|
* Scrolls the cell at cell x, row y into view if it is not already.
|
|
397
406
|
* @param x - The column index of the cell to scroll into view.
|
|
@@ -416,6 +425,11 @@ declare class canvasDatagrid {
|
|
|
416
425
|
* @param dontDraw - Suppress the draw method after the selection change.
|
|
417
426
|
*/
|
|
418
427
|
static selectAll(dontDraw: boolean): void;
|
|
428
|
+
/**
|
|
429
|
+
* Returns true if indices of columns next to the selected columnIndex is selected on every row.
|
|
430
|
+
* @param columnIndex - The column index to check.
|
|
431
|
+
*/
|
|
432
|
+
static isMultiColumnsSelected(columnIndex: number): void;
|
|
419
433
|
/**
|
|
420
434
|
* Returns true if the selected columnIndex is selected on every row.
|
|
421
435
|
* @param columnIndex - The column index to check.
|
|
@@ -491,6 +505,11 @@ declare class canvasDatagrid {
|
|
|
491
505
|
* @param offsetY - The number of rows to offset the selection.
|
|
492
506
|
*/
|
|
493
507
|
static moveSelection(offsetX: number, offsetY: number): void;
|
|
508
|
+
/**
|
|
509
|
+
* Deletes currently selected data.
|
|
510
|
+
* @param dontDraw - Suppress the draw method after the selection change.
|
|
511
|
+
*/
|
|
512
|
+
static deleteSelectedData(dontDraw: boolean): void;
|
|
494
513
|
/**
|
|
495
514
|
* Moves data in the provided selection to another position in the grid. Moving data off the edge of the schema (columns/x) will truncate data.
|
|
496
515
|
* @param sel - 2D array representing selected rows and columns. `canvasDatagrid.selections` is in this format and can be used here.
|
package/lib/button.js
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
/*jslint browser: true, unparam: true, todo: true*/
|
|
2
|
+
/*globals define: true, MutationObserver: false, requestAnimationFrame: false, performance: false, btoa: false, Event: false*/
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
export default function (self) {
|
|
6
|
+
let zIndexTop;
|
|
7
|
+
|
|
8
|
+
function applyButtonMenuItemStyle(buttonMenuItemContainer) {
|
|
9
|
+
self.createInlineStyle(
|
|
10
|
+
buttonMenuItemContainer,
|
|
11
|
+
'canvas-datagrid-button-menu-item' + (self.mobile ? '-mobile' : ''),
|
|
12
|
+
);
|
|
13
|
+
buttonMenuItemContainer.addEventListener('mouseover', function () {
|
|
14
|
+
self.createInlineStyle(
|
|
15
|
+
buttonMenuItemContainer,
|
|
16
|
+
'canvas-datagrid-button-menu-item:hover',
|
|
17
|
+
);
|
|
18
|
+
});
|
|
19
|
+
buttonMenuItemContainer.addEventListener('mouseout', function () {
|
|
20
|
+
self.createInlineStyle(
|
|
21
|
+
buttonMenuItemContainer,
|
|
22
|
+
'canvas-datagrid-button-menu-item',
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function applyButtonStyle(button) {
|
|
28
|
+
self.createInlineStyle(button, 'canvas-datagrid-button-wrapper');
|
|
29
|
+
button.addEventListener('mouseover', function () {
|
|
30
|
+
if (!self.buttonMenu) {
|
|
31
|
+
self.createInlineStyle(button, 'canvas-datagrid-button-wrapper:hover');
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
button.addEventListener('mouseout', function () {
|
|
35
|
+
if (!self.buttonMenu) {
|
|
36
|
+
self.createInlineStyle(button, 'canvas-datagrid-button-wrapper');
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function createButton(pos, items, imgSrc) {
|
|
42
|
+
var wrapper = document.createElement('div'),
|
|
43
|
+
buttonArrow = document.createElement('div'),
|
|
44
|
+
buttonIcon = document.createElement('div'),
|
|
45
|
+
intf = {};
|
|
46
|
+
|
|
47
|
+
if (!Array.isArray(items)) {
|
|
48
|
+
throw new Error('createButton expects an array.');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function init() {
|
|
52
|
+
var loc = {},
|
|
53
|
+
s = self.scrollOffset(self.canvas);
|
|
54
|
+
|
|
55
|
+
if (zIndexTop === undefined) {
|
|
56
|
+
zIndexTop = self.style.buttonZIndex;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
applyButtonStyle(wrapper);
|
|
60
|
+
self.createInlineStyle(buttonIcon, 'canvas-datagrid-button-icon');
|
|
61
|
+
self.createInlineStyle(buttonArrow, 'canvas-datagrid-button-arrow');
|
|
62
|
+
|
|
63
|
+
loc.x = pos.left - s.left;
|
|
64
|
+
loc.y = pos.top - s.top;
|
|
65
|
+
loc.height = 0;
|
|
66
|
+
zIndexTop += 1;
|
|
67
|
+
wrapper.style.position = 'absolute';
|
|
68
|
+
wrapper.style.zIndex = zIndexTop;
|
|
69
|
+
wrapper.style.left = loc.x + 'px';
|
|
70
|
+
wrapper.style.top = loc.y + 'px';
|
|
71
|
+
wrapper.left = pos.left + self.scrollBox.scrollLeft;
|
|
72
|
+
wrapper.top = pos.top + self.scrollBox.scrollTop;
|
|
73
|
+
buttonArrow.innerHTML = self.style.buttonArrowDownHTML;
|
|
74
|
+
if (imgSrc) {
|
|
75
|
+
let img = document.createElement('img');
|
|
76
|
+
img.setAttribute('src', imgSrc);
|
|
77
|
+
img.style.maxWidth = '100%';
|
|
78
|
+
img.style.height = '100%';
|
|
79
|
+
buttonIcon.appendChild(img);
|
|
80
|
+
}
|
|
81
|
+
wrapper.appendChild(buttonIcon);
|
|
82
|
+
wrapper.appendChild(buttonArrow);
|
|
83
|
+
document.body.appendChild(wrapper);
|
|
84
|
+
wrapper.addEventListener('click', toggleButtonMenu);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
intf.wrapper = wrapper;
|
|
88
|
+
intf.items = items;
|
|
89
|
+
init();
|
|
90
|
+
|
|
91
|
+
intf.dispose = function () {
|
|
92
|
+
if (wrapper.parentNode) {
|
|
93
|
+
wrapper.parentNode.removeChild(wrapper);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
return intf;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function toggleButtonMenu() {
|
|
100
|
+
function createDisposeEvent() {
|
|
101
|
+
requestAnimationFrame(function () {
|
|
102
|
+
document.addEventListener('click', self.disposeButtonMenu);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
if (self.buttonMenu) {
|
|
106
|
+
self.disposeButtonMenu();
|
|
107
|
+
} else {
|
|
108
|
+
let pos = {
|
|
109
|
+
left: self.button.wrapper.left - self.scrollBox.scrollLeft,
|
|
110
|
+
top:
|
|
111
|
+
self.button.wrapper.top +
|
|
112
|
+
self.button.wrapper.offsetHeight -
|
|
113
|
+
self.scrollBox.scrollTop,
|
|
114
|
+
};
|
|
115
|
+
self.buttonMenu = createButtonMenu(pos, self.button.items);
|
|
116
|
+
self.createInlineStyle(
|
|
117
|
+
self.button.wrapper,
|
|
118
|
+
'canvas-datagrid-button-wrapper:active',
|
|
119
|
+
);
|
|
120
|
+
createDisposeEvent();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function createButtonMenu(pos, items) {
|
|
125
|
+
var buttonMenu = document.createElement('div'),
|
|
126
|
+
selectedIndex = -1,
|
|
127
|
+
intf = {},
|
|
128
|
+
rect;
|
|
129
|
+
|
|
130
|
+
function createItems() {
|
|
131
|
+
function addItem(item, menuItemContainer) {
|
|
132
|
+
function addContent(content) {
|
|
133
|
+
if (content === null) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (typeof content === 'object') {
|
|
138
|
+
menuItemContainer.appendChild(content);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
applyButtonMenuItemStyle(menuItemContainer);
|
|
143
|
+
menuItemContainer.innerHTML = content;
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
addContent(item.title);
|
|
148
|
+
item.buttonMenuItemContainer = menuItemContainer;
|
|
149
|
+
|
|
150
|
+
if (item.click) {
|
|
151
|
+
menuItemContainer.addEventListener('click', function (ev) {
|
|
152
|
+
item.click.apply(self, [ev]);
|
|
153
|
+
self.disposeButton();
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
for (let item of items) {
|
|
159
|
+
var buttonMenuItemContainer = document.createElement('div');
|
|
160
|
+
addItem(item, buttonMenuItemContainer);
|
|
161
|
+
buttonMenu.appendChild(buttonMenuItemContainer);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function clickIndex(idx) {
|
|
166
|
+
items[idx].buttonMenuItemContainer.dispatchEvent(new Event('click'));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function init() {
|
|
170
|
+
var loc = {},
|
|
171
|
+
s = self.scrollOffset(self.canvas);
|
|
172
|
+
|
|
173
|
+
if (zIndexTop === undefined) {
|
|
174
|
+
zIndexTop = self.style.buttonZIndex;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
createItems();
|
|
178
|
+
self.createInlineStyle(
|
|
179
|
+
buttonMenu,
|
|
180
|
+
'canvas-datagrid-button-menu' + (self.mobile ? '-mobile' : ''),
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
loc.x = pos.left - s.left;
|
|
184
|
+
loc.y = pos.top - s.top;
|
|
185
|
+
loc.height = 0;
|
|
186
|
+
zIndexTop += 1;
|
|
187
|
+
buttonMenu.style.position = 'absolute';
|
|
188
|
+
buttonMenu.style.zIndex = zIndexTop;
|
|
189
|
+
buttonMenu.style.left = loc.x + 'px';
|
|
190
|
+
buttonMenu.style.top = loc.y + 'px';
|
|
191
|
+
document.body.appendChild(buttonMenu);
|
|
192
|
+
rect = buttonMenu.getBoundingClientRect();
|
|
193
|
+
|
|
194
|
+
if (rect.bottom > window.innerHeight) {
|
|
195
|
+
loc.y =
|
|
196
|
+
self.button.wrapper.top -
|
|
197
|
+
buttonMenu.offsetHeight -
|
|
198
|
+
self.scrollBox.scrollTop;
|
|
199
|
+
if (loc.y < 0) {
|
|
200
|
+
loc.y = self.style.buttonMenuWindowMargin;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (
|
|
204
|
+
buttonMenu.offsetHeight >
|
|
205
|
+
window.innerHeight - self.style.buttonMenuWindowMargin
|
|
206
|
+
) {
|
|
207
|
+
buttonMenu.style.height =
|
|
208
|
+
window.innerHeight - self.style.buttonMenuWindowMargin * 2 + 'px';
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (rect.right > window.innerWidth) {
|
|
213
|
+
loc.x -=
|
|
214
|
+
rect.right - window.innerWidth + self.style.buttonMenuWindowMargin;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (loc.x < 0) {
|
|
218
|
+
loc.x = self.style.buttonMenuWindowMargin;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (loc.y < 0) {
|
|
222
|
+
loc.y = self.style.buttonMenuWindowMargin;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
buttonMenu.style.left = loc.x + 'px';
|
|
226
|
+
buttonMenu.style.top = loc.y + 'px';
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
intf.buttonMenu = buttonMenu;
|
|
230
|
+
init();
|
|
231
|
+
intf.clickIndex = clickIndex;
|
|
232
|
+
intf.rect = rect;
|
|
233
|
+
intf.items = items;
|
|
234
|
+
|
|
235
|
+
intf.dispose = function () {
|
|
236
|
+
if (buttonMenu.parentNode) {
|
|
237
|
+
buttonMenu.parentNode.removeChild(buttonMenu);
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
Object.defineProperty(intf, 'selectedIndex', {
|
|
242
|
+
get: function get() {
|
|
243
|
+
return selectedIndex;
|
|
244
|
+
},
|
|
245
|
+
set: function set(value) {
|
|
246
|
+
if (typeof value !== 'number' || isNaN(value) || !isFinite(value)) {
|
|
247
|
+
throw new Error('Button menu selected index must be a sane number.');
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
selectedIndex = value;
|
|
251
|
+
|
|
252
|
+
if (selectedIndex > items.length - 1) {
|
|
253
|
+
selectedIndex = items.length - 1;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (selectedIndex < 0) {
|
|
257
|
+
selectedIndex = 0;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
items.forEach(function (item, index) {
|
|
261
|
+
if (index === selectedIndex) {
|
|
262
|
+
return self.createInlineStyle(
|
|
263
|
+
item.buttonMenuItemContainer,
|
|
264
|
+
'canvas-datagrid-button-menu-item:hover',
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
self.createInlineStyle(
|
|
269
|
+
item.buttonMenuItemContainer,
|
|
270
|
+
'canvas-datagrid-button-menu-item',
|
|
271
|
+
);
|
|
272
|
+
});
|
|
273
|
+
},
|
|
274
|
+
});
|
|
275
|
+
return intf;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
self.disposeButtonMenu = function () {
|
|
279
|
+
if (self.buttonMenu) {
|
|
280
|
+
document.removeEventListener('click', self.disposeButtonMenu);
|
|
281
|
+
self.buttonMenu.dispose();
|
|
282
|
+
self.buttonMenu = undefined;
|
|
283
|
+
self.createInlineStyle(
|
|
284
|
+
self.button.wrapper,
|
|
285
|
+
'canvas-datagrid-button-wrapper:hover',
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
self.disposeButton = function (e) {
|
|
291
|
+
if (e && e.keyCode !== 27) return;
|
|
292
|
+
document.removeEventListener('keydown', self.disposeButton);
|
|
293
|
+
zIndexTop = self.style.buttonZIndex;
|
|
294
|
+
self.disposeButtonMenu();
|
|
295
|
+
|
|
296
|
+
if (self.button) {
|
|
297
|
+
self.button.dispose();
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
self.button = undefined;
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
self.moveButtonPos = function () {
|
|
304
|
+
self.button.wrapper.style.left =
|
|
305
|
+
self.button.wrapper.left - self.scrollBox.scrollLeft + 'px';
|
|
306
|
+
self.button.wrapper.style.top =
|
|
307
|
+
self.button.wrapper.top - self.scrollBox.scrollTop + 'px';
|
|
308
|
+
self.disposeButtonMenu();
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
self.attachButton = function (pos, items, imgSrc) {
|
|
312
|
+
function createDisposeEvent() {
|
|
313
|
+
requestAnimationFrame(function () {
|
|
314
|
+
document.addEventListener('keydown', self.disposeButton);
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (self.button) {
|
|
319
|
+
self.disposeButton();
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
self.button = createButton(pos, items, imgSrc);
|
|
323
|
+
createDisposeEvent();
|
|
324
|
+
};
|
|
325
|
+
return;
|
|
326
|
+
}
|
package/lib/contextMenu.js
CHANGED
|
@@ -173,6 +173,33 @@ export default function (self) {
|
|
|
173
173
|
self.parentDOMNode.appendChild(downArrow);
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
|
+
function fade(element) {
|
|
177
|
+
var opacity = 1;
|
|
178
|
+
var timer = setInterval(function () {
|
|
179
|
+
if (opacity <= 0.1) {
|
|
180
|
+
clearInterval(timer);
|
|
181
|
+
element.style.display = 'none';
|
|
182
|
+
if (element.parentNode) {
|
|
183
|
+
element.parentNode.removeChild(element);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
element.style.opacity = opacity;
|
|
187
|
+
element.style.filter = 'alpha(opacity=' + opacity * 100 + ')';
|
|
188
|
+
opacity -= opacity * 0.1;
|
|
189
|
+
}, self.attributes.animationDurationHideContextMenu * 0.1);
|
|
190
|
+
}
|
|
191
|
+
function unfade(element) {
|
|
192
|
+
var opacity = 0.1;
|
|
193
|
+
element.style.display = 'block';
|
|
194
|
+
var timer = setInterval(function () {
|
|
195
|
+
if (opacity >= 1) {
|
|
196
|
+
clearInterval(timer);
|
|
197
|
+
}
|
|
198
|
+
element.style.opacity = opacity;
|
|
199
|
+
element.style.filter = 'alpha(opacity=' + opacity * 100 + ')';
|
|
200
|
+
opacity += opacity * 0.1;
|
|
201
|
+
}, self.attributes.animationDurationShowContextMenu * 0.1);
|
|
202
|
+
}
|
|
176
203
|
function startHoverScroll(type) {
|
|
177
204
|
return function t() {
|
|
178
205
|
var a = self.attributes.contextHoverScrollAmount;
|
|
@@ -210,6 +237,7 @@ export default function (self) {
|
|
|
210
237
|
loc.y = pos.top - s.top;
|
|
211
238
|
loc.height = 0;
|
|
212
239
|
zIndexTop += 1;
|
|
240
|
+
container.style.opacity = 0;
|
|
213
241
|
container.style.position = 'absolute';
|
|
214
242
|
upArrow.style.color = self.style.contextMenuArrowColor;
|
|
215
243
|
downArrow.style.color = self.style.contextMenuArrowColor;
|
|
@@ -246,6 +274,7 @@ export default function (self) {
|
|
|
246
274
|
container.appendChild(upArrow);
|
|
247
275
|
document.body.appendChild(downArrow);
|
|
248
276
|
document.body.appendChild(container);
|
|
277
|
+
unfade(container);
|
|
249
278
|
rect = container.getBoundingClientRect();
|
|
250
279
|
// TODO: fix !(parentContextMenu && parentContextMenu.inputDropdown) state (autocomplete)
|
|
251
280
|
if (rect.bottom > window.innerHeight) {
|
|
@@ -307,9 +336,7 @@ export default function (self) {
|
|
|
307
336
|
c.dispose();
|
|
308
337
|
});
|
|
309
338
|
[downArrow, upArrow, container].forEach(function (el) {
|
|
310
|
-
|
|
311
|
-
el.parentNode.removeChild(el);
|
|
312
|
-
}
|
|
339
|
+
fade(el);
|
|
313
340
|
});
|
|
314
341
|
};
|
|
315
342
|
Object.defineProperty(intf, 'selectedIndex', {
|
|
@@ -664,7 +691,7 @@ export default function (self) {
|
|
|
664
691
|
autoCompleteContext = undefined;
|
|
665
692
|
}
|
|
666
693
|
};
|
|
667
|
-
self.disposeContextMenu = function () {
|
|
694
|
+
self.disposeContextMenu = function (event) {
|
|
668
695
|
document.removeEventListener('click', self.disposeContextMenu);
|
|
669
696
|
zIndexTop = self.style.contextMenuZIndex;
|
|
670
697
|
self.disposeAutocomplete();
|
|
@@ -672,15 +699,20 @@ export default function (self) {
|
|
|
672
699
|
self.contextMenu.dispose();
|
|
673
700
|
}
|
|
674
701
|
self.contextMenu = undefined;
|
|
702
|
+
if (event) {
|
|
703
|
+
self.canvas.focus();
|
|
704
|
+
self.mousedown(event);
|
|
705
|
+
self.mouseup(event);
|
|
706
|
+
}
|
|
675
707
|
};
|
|
676
708
|
self.contextmenuEvent = function (e, overridePos) {
|
|
677
709
|
if (!self.hasFocus && e.target !== self.canvas) {
|
|
678
710
|
return;
|
|
679
711
|
}
|
|
680
|
-
function
|
|
712
|
+
function createDisposeEvent() {
|
|
681
713
|
requestAnimationFrame(function () {
|
|
682
714
|
document.addEventListener('click', self.disposeContextMenu);
|
|
683
|
-
document.removeEventListener('mouseup',
|
|
715
|
+
document.removeEventListener('mouseup', createDisposeEvent);
|
|
684
716
|
});
|
|
685
717
|
}
|
|
686
718
|
var contextPosition,
|
|
@@ -694,7 +726,7 @@ export default function (self) {
|
|
|
694
726
|
if (!ev.cell.isGrid) {
|
|
695
727
|
addDefaultContextMenuItem(ev);
|
|
696
728
|
}
|
|
697
|
-
if (self.dispatchEvent('contextmenu', ev)) {
|
|
729
|
+
if (e.type !== 'mousedown' && self.dispatchEvent('contextmenu', ev)) {
|
|
698
730
|
return;
|
|
699
731
|
}
|
|
700
732
|
if (!ev.cell.isGrid) {
|
|
@@ -722,8 +754,15 @@ export default function (self) {
|
|
|
722
754
|
contextPosition.width =
|
|
723
755
|
self.width - self.style.mobileContextMenuMargin * 2 + 'px';
|
|
724
756
|
}
|
|
757
|
+
if (e.type == 'mousedown') {
|
|
758
|
+
contextPosition.top += self.style.filterButtonMenuOffsetTop;
|
|
759
|
+
}
|
|
725
760
|
self.contextMenu = createContextMenu(ev, contextPosition, items);
|
|
726
|
-
|
|
761
|
+
if (e.type == 'mousedown') {
|
|
762
|
+
document.addEventListener('mouseup', createDisposeEvent);
|
|
763
|
+
} else {
|
|
764
|
+
createDisposeEvent();
|
|
765
|
+
}
|
|
727
766
|
e.preventDefault();
|
|
728
767
|
}
|
|
729
768
|
};
|
package/lib/defaults.js
CHANGED
|
@@ -16,6 +16,8 @@ export default function (self) {
|
|
|
16
16
|
['allowRowResize', true],
|
|
17
17
|
['allowRowResizeFromCell', false],
|
|
18
18
|
['allowSorting', true],
|
|
19
|
+
['animationDurationShowContextMenu', 50],
|
|
20
|
+
['animationDurationHideContextMenu', 50],
|
|
19
21
|
['autoGenerateSchema', false],
|
|
20
22
|
['autoResizeColumns', false],
|
|
21
23
|
['autoResizeRows', false],
|
|
@@ -67,6 +69,7 @@ export default function (self) {
|
|
|
67
69
|
['showColumnSelector', true],
|
|
68
70
|
['showCopy', false],
|
|
69
71
|
['showFilter', true],
|
|
72
|
+
['showFilterInCell', false],
|
|
70
73
|
['showNewRow', false],
|
|
71
74
|
['showOrderByOption', true],
|
|
72
75
|
['showOrderByOptionTextAsc', 'Order by %s ascending'],
|
|
@@ -118,6 +121,16 @@ export default function (self) {
|
|
|
118
121
|
['autocompleteBottomMargin', 60],
|
|
119
122
|
['autosizeHeaderCellPadding', 8],
|
|
120
123
|
['autosizePadding', 5],
|
|
124
|
+
['buttonActiveBackgroundColor', 'rgba(255, 255, 255, 1)'],
|
|
125
|
+
['buttonActiveBorderColor', 'rgba(110, 168, 255, 1)'],
|
|
126
|
+
['buttonArrowColor', 'rgba(50, 50, 50, 1)'],
|
|
127
|
+
['buttonArrowDownHTML', '▼'],
|
|
128
|
+
['buttonZIndex', 10000],
|
|
129
|
+
['buttonBackgroundColor', 'rgba(255, 255, 255, 1)'],
|
|
130
|
+
['buttonBorderColor', 'rgba(172, 172, 172, 1)'],
|
|
131
|
+
['buttonHoverBackgroundColor', 'rgba(240, 240, 240, 1)'],
|
|
132
|
+
['buttonMenuWindowMargin', 30],
|
|
133
|
+
['buttonPadding', '3px'],
|
|
121
134
|
['cellAutoResizePadding', 13],
|
|
122
135
|
['cellBackgroundColor', 'rgba(255, 255, 255, 1)'],
|
|
123
136
|
['cellBorderColor', 'rgba(195, 199, 202, 1)'],
|
|
@@ -232,6 +245,20 @@ export default function (self) {
|
|
|
232
245
|
['editCellFontSize', '16px'],
|
|
233
246
|
['editCellPaddingLeft', 4],
|
|
234
247
|
['editCellZIndex', 10000],
|
|
248
|
+
['filterButtonActiveBackgroundColor', 'rgba(225, 225, 225, 1)'],
|
|
249
|
+
['filterButtonArrowBorderColor', 'rgba(195, 199, 202, 1)'],
|
|
250
|
+
['filterButtonArrowBorderWidth', 1],
|
|
251
|
+
['filterButtonArrowClickRadius', 5],
|
|
252
|
+
['filterButtonArrowColor', 'rgba(50, 50, 50, 1)'],
|
|
253
|
+
['filterButtonArrowHeight', 5],
|
|
254
|
+
['filterButtonArrowWidth', 8],
|
|
255
|
+
['filterButtonBackgroundColor', 'rgba(240, 240, 240, 1)'],
|
|
256
|
+
['filterButtonBorderColor', 'rgba(172, 172, 172, 1)'],
|
|
257
|
+
['filterButtonBorderRadius', 3],
|
|
258
|
+
['filterButtonHeight', 20],
|
|
259
|
+
['filterButtonHoverBackgroundColor', 'rgba(235, 235, 235, 1)'],
|
|
260
|
+
['filterButtonMenuOffsetTop', 10],
|
|
261
|
+
['filterButtonWidth', 20],
|
|
235
262
|
['frozenMarkerHoverColor', 'rgba(236, 243, 255, 1)'],
|
|
236
263
|
['frozenMarkerHoverBorderColor', 'rgba(110, 168, 255, 1)'],
|
|
237
264
|
['frozenMarkerActiveColor', 'rgba(236, 243, 255, 1)'],
|
package/lib/docs.js
CHANGED
|
@@ -460,6 +460,14 @@
|
|
|
460
460
|
* @param {object} e.boundRowIndexMap Mapping of view data row to bound data row index.
|
|
461
461
|
* @param {object} e.boundColumnIndexMap Mapping of view column order to bound column order.
|
|
462
462
|
*/
|
|
463
|
+
/**
|
|
464
|
+
* Fires when the selected is deleted by pressing backspace or delete key.
|
|
465
|
+
* @event
|
|
466
|
+
* @name canvasDatagrid#afterdelete
|
|
467
|
+
* @param {object} e Event object.
|
|
468
|
+
* @param {object} e.ctx Canvas context.
|
|
469
|
+
* @param {array} e.cells Cells affected by the delete action. Each item in the array is a tuple of [rowIndex, columnIndex, boundRowIndex, boundColumnIndex].
|
|
470
|
+
*/
|
|
463
471
|
/**
|
|
464
472
|
* Fires when the user clicks on the "drill in" arrow. When the arrow is clicked a new
|
|
465
473
|
* grid is created and nested inside of the row. The grid, the row data and row index are passed
|
|
@@ -552,7 +560,7 @@
|
|
|
552
560
|
* @name canvasDatagrid#afterpaste
|
|
553
561
|
* @param {object} e Event object
|
|
554
562
|
* @param {object} e.ctx Canvas context.
|
|
555
|
-
* @param {array} e.cells Cells affected by the paste action. Each item in the array is a tuple of [rowIndex, columnIndex].
|
|
563
|
+
* @param {array} e.cells Cells affected by the paste action. Each item in the array is a tuple of [rowIndex, columnIndex, boundRowIndex, boundColumnIndex].
|
|
556
564
|
*/
|
|
557
565
|
/**
|
|
558
566
|
* Fired just before a cell is drawn onto the canvas. `e.preventDefault();` prevents the cell from being drawn.
|
package/lib/dom.js
CHANGED
|
@@ -435,6 +435,96 @@ export default function (self) {
|
|
|
435
435
|
};
|
|
436
436
|
self.createInlineStyle = function (el, className) {
|
|
437
437
|
var css = {
|
|
438
|
+
'canvas-datagrid-button-wrapper': {
|
|
439
|
+
display: 'inline-block',
|
|
440
|
+
padding: self.style.buttonPadding,
|
|
441
|
+
borderWidth: '1px',
|
|
442
|
+
borderStyle: 'solid',
|
|
443
|
+
borderColor: self.style.buttonBorderColor,
|
|
444
|
+
cursor: 'pointer',
|
|
445
|
+
background: self.style.buttonBackgroundColor,
|
|
446
|
+
userSelect: 'none',
|
|
447
|
+
},
|
|
448
|
+
'canvas-datagrid-button-wrapper:hover': {
|
|
449
|
+
borderColor: self.style.buttonBorderColor,
|
|
450
|
+
background: self.style.buttonHoverBackgroundColor,
|
|
451
|
+
},
|
|
452
|
+
'canvas-datagrid-button-wrapper:active': {
|
|
453
|
+
borderColor: self.style.buttonActiveBorderColor,
|
|
454
|
+
background: self.style.buttonActiveBackgroundColor,
|
|
455
|
+
},
|
|
456
|
+
'canvas-datagrid-button-icon': {
|
|
457
|
+
width: '18px',
|
|
458
|
+
height: '18px',
|
|
459
|
+
display: 'inline-block',
|
|
460
|
+
verticalAlign: 'middle',
|
|
461
|
+
},
|
|
462
|
+
'canvas-datagrid-button-arrow': {
|
|
463
|
+
display: 'inline-block',
|
|
464
|
+
color: self.style.buttonArrowColor,
|
|
465
|
+
fontSize: '9px',
|
|
466
|
+
},
|
|
467
|
+
'canvas-datagrid-button-menu-item-mobile': {
|
|
468
|
+
lineHeight: 'normal',
|
|
469
|
+
fontWeight: 'normal',
|
|
470
|
+
fontFamily: self.style.contextMenuFontFamily,
|
|
471
|
+
fontSize: self.style.contextMenuFontSize,
|
|
472
|
+
color: 'inherit',
|
|
473
|
+
background: 'inherit',
|
|
474
|
+
margin: self.style.contextMenuItemMargin,
|
|
475
|
+
borderRadius: self.style.contextMenuItemBorderRadius,
|
|
476
|
+
verticalAlign: 'middle',
|
|
477
|
+
},
|
|
478
|
+
'canvas-datagrid-button-menu-item': {
|
|
479
|
+
lineHeight: 'normal',
|
|
480
|
+
fontWeight: 'normal',
|
|
481
|
+
fontFamily: self.style.contextMenuFontFamily,
|
|
482
|
+
fontSize: self.style.contextMenuFontSize,
|
|
483
|
+
color: 'inherit',
|
|
484
|
+
background: 'inherit',
|
|
485
|
+
margin: self.style.contextMenuItemMargin,
|
|
486
|
+
borderRadius: self.style.contextMenuItemBorderRadius,
|
|
487
|
+
verticalAlign: 'middle',
|
|
488
|
+
},
|
|
489
|
+
'canvas-datagrid-button-menu-item:hover': {
|
|
490
|
+
background: self.style.contextMenuHoverBackground,
|
|
491
|
+
color: self.style.contextMenuHoverColor,
|
|
492
|
+
},
|
|
493
|
+
'canvas-datagrid-button-menu-label': {
|
|
494
|
+
margin: self.style.contextMenuLabelMargin,
|
|
495
|
+
display: self.style.contextMenuLabelDisplay,
|
|
496
|
+
minWidth: self.style.contextMenuLabelMinWidth,
|
|
497
|
+
maxWidth: self.style.contextMenuLabelMaxWidth,
|
|
498
|
+
},
|
|
499
|
+
'canvas-datagrid-button-menu-mobile': {
|
|
500
|
+
lineHeight: 'normal',
|
|
501
|
+
fontWeight: 'normal',
|
|
502
|
+
fontFamily: self.style.contextMenuFontFamily,
|
|
503
|
+
fontSize: self.style.contextMenuFontSize,
|
|
504
|
+
background: self.style.contextMenuBackground,
|
|
505
|
+
color: self.style.contextMenuColor,
|
|
506
|
+
border: self.style.contextMenuBorder,
|
|
507
|
+
padding: self.style.contextMenuPadding,
|
|
508
|
+
borderRadius: self.style.contextMenuBorderRadius,
|
|
509
|
+
opacity: self.style.contextMenuOpacity,
|
|
510
|
+
overflow: 'hidden',
|
|
511
|
+
whiteSpace: 'nowrap',
|
|
512
|
+
},
|
|
513
|
+
'canvas-datagrid-button-menu': {
|
|
514
|
+
lineHeight: 'normal',
|
|
515
|
+
fontWeight: 'normal',
|
|
516
|
+
fontFamily: self.style.contextMenuFontFamily,
|
|
517
|
+
fontSize: self.style.contextMenuFontSize,
|
|
518
|
+
background: self.style.contextMenuBackground,
|
|
519
|
+
color: self.style.contextMenuColor,
|
|
520
|
+
border: self.style.contextMenuBorder,
|
|
521
|
+
padding: self.style.contextMenuPadding,
|
|
522
|
+
borderRadius: self.style.contextMenuBorderRadius,
|
|
523
|
+
opacity: self.style.contextMenuOpacity,
|
|
524
|
+
overflow: 'hidden',
|
|
525
|
+
whiteSpace: 'nowrap',
|
|
526
|
+
cursor: self.style.contextMenuCursor,
|
|
527
|
+
},
|
|
438
528
|
'canvas-datagrid-context-menu-filter-input': {
|
|
439
529
|
height: '19px',
|
|
440
530
|
verticalAlign: 'bottom',
|