canvas-datagrid 0.4.4 → 0.4.5
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 +6 -0
- package/dist/canvas-datagrid.debug.js +465 -84
- 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 +25 -1
- package/lib/defaults.js +4 -0
- package/lib/docs.js +32 -1
- package/lib/draw.js +94 -11
- package/lib/events/index.js +456 -70
- package/lib/intf.js +9 -0
- package/lib/main.js +1 -0
- package/lib/publicMethods.js +8 -8
- package/package.json +2 -2
package/lib/events/index.js
CHANGED
|
@@ -493,6 +493,8 @@ export default function (self) {
|
|
|
493
493
|
y = self.mouse.y,
|
|
494
494
|
cell = self.getCellAt(x, y),
|
|
495
495
|
delta,
|
|
496
|
+
disallowVerticalAutoScroll = false,
|
|
497
|
+
disallowHorizontalAutoScroll = false,
|
|
496
498
|
ev = { NativeEvent: e, cell: cell, x: x, y: y },
|
|
497
499
|
previousCell = self.currentCell;
|
|
498
500
|
clearTimeout(self.scrollTimer);
|
|
@@ -762,10 +764,33 @@ export default function (self) {
|
|
|
762
764
|
}
|
|
763
765
|
}
|
|
764
766
|
}
|
|
767
|
+
} else if (self.movingSelectionHandle) {
|
|
768
|
+
delta = {
|
|
769
|
+
x: Math.abs(self.dragStart.x - x),
|
|
770
|
+
y: Math.abs(self.dragStart.y - y),
|
|
771
|
+
};
|
|
765
772
|
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
773
|
+
// Disallow auto-scroll to the direction that overlay is not
|
|
774
|
+
// moving towards.
|
|
775
|
+
if (self.fillOverlay.direction === 'y') {
|
|
776
|
+
disallowHorizontalAutoScroll = true;
|
|
777
|
+
} else if (self.fillOverlay.direction === 'x') {
|
|
778
|
+
disallowVerticalAutoScroll = true;
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
if (delta) {
|
|
783
|
+
if (
|
|
784
|
+
self.attributes.autoScrollOnMousemove ||
|
|
785
|
+
disallowVerticalAutoScroll ||
|
|
786
|
+
disallowHorizontalAutoScroll
|
|
787
|
+
) {
|
|
788
|
+
var movedVertically =
|
|
789
|
+
!disallowVerticalAutoScroll &&
|
|
790
|
+
delta.y > self.attributes.autoScrollMargin;
|
|
791
|
+
var movedHorizontally =
|
|
792
|
+
!disallowHorizontalAutoScroll &&
|
|
793
|
+
delta.x > self.attributes.autoScrollMargin;
|
|
769
794
|
|
|
770
795
|
if (movedVertically && !movedHorizontally)
|
|
771
796
|
self.autoScrollZone(e, -1, y, ctrl);
|
|
@@ -1445,7 +1470,8 @@ export default function (self) {
|
|
|
1445
1470
|
var ctrl = e.ctrlKey || e.metaKey,
|
|
1446
1471
|
move = /-move/.test(self.dragMode),
|
|
1447
1472
|
freeze = /frozen-row-marker|frozen-column-marker/.test(self.dragMode),
|
|
1448
|
-
resize = /-resize/.test(self.dragMode)
|
|
1473
|
+
resize = /-resize/.test(self.dragMode),
|
|
1474
|
+
selectionHandleMove = /selection-handle-br/.test(self.dragMode);
|
|
1449
1475
|
const onUnhideIndicator = self.hovers && self.hovers.unhideIndicator;
|
|
1450
1476
|
self.dragStart = overridePos || self.getLayerPos(e);
|
|
1451
1477
|
self.scrollStart = {
|
|
@@ -1464,7 +1490,8 @@ export default function (self) {
|
|
|
1464
1490
|
!self.currentCell.isColumnHeader &&
|
|
1465
1491
|
!move &&
|
|
1466
1492
|
!freeze &&
|
|
1467
|
-
!resize
|
|
1493
|
+
!resize &&
|
|
1494
|
+
!selectionHandleMove
|
|
1468
1495
|
) {
|
|
1469
1496
|
if (
|
|
1470
1497
|
!(self.dragMode == 'row-reorder' && self.isMultiRowsSelected) &&
|
|
@@ -1523,6 +1550,23 @@ export default function (self) {
|
|
|
1523
1550
|
}
|
|
1524
1551
|
return;
|
|
1525
1552
|
}
|
|
1553
|
+
if (selectionHandleMove) {
|
|
1554
|
+
self.movingSelectionHandle = true;
|
|
1555
|
+
self.fillOverlay = {
|
|
1556
|
+
handle: {
|
|
1557
|
+
x: self.dragStartObject.x + self.dragStartObject.width / 2,
|
|
1558
|
+
y: self.dragStartObject.y + self.dragStartObject.height / 2,
|
|
1559
|
+
},
|
|
1560
|
+
snapTo: { x: -1, y: -1 },
|
|
1561
|
+
selection: self.getSelectionBounds(),
|
|
1562
|
+
};
|
|
1563
|
+
if (self.dispatchEvent('beginselectionhandlemove', { NativeEvent: e })) {
|
|
1564
|
+
return;
|
|
1565
|
+
}
|
|
1566
|
+
window.addEventListener('mousemove', self.selectionHandleMove, false);
|
|
1567
|
+
window.addEventListener('mouseup', self.stopSelectionHandleMove, false);
|
|
1568
|
+
return self.selectionHandleMove(e);
|
|
1569
|
+
}
|
|
1526
1570
|
if (move) {
|
|
1527
1571
|
self.draggingItem = self.dragItem;
|
|
1528
1572
|
self.movingSelection = self.selections.concat([]);
|
|
@@ -1947,6 +1991,8 @@ export default function (self) {
|
|
|
1947
1991
|
mimeType,
|
|
1948
1992
|
startRowIndex,
|
|
1949
1993
|
startColIndex,
|
|
1994
|
+
minRowsLength = 0,
|
|
1995
|
+
minColumnsLength = 0,
|
|
1950
1996
|
) {
|
|
1951
1997
|
if (mimeType === 'text/html' && !isSupportedHtml(pasteValue)) {
|
|
1952
1998
|
console.warn(
|
|
@@ -1958,66 +2004,49 @@ export default function (self) {
|
|
|
1958
2004
|
|
|
1959
2005
|
return;
|
|
1960
2006
|
}
|
|
1961
|
-
|
|
1962
|
-
|
|
2007
|
+
|
|
2008
|
+
self.selectedRows = [];
|
|
2009
|
+
self.selectedColumns = [];
|
|
2010
|
+
|
|
2011
|
+
const rows = parseData(pasteValue, mimeType);
|
|
2012
|
+
const columnsLength = rows[0].length;
|
|
1963
2013
|
|
|
1964
2014
|
// selected cell. This mimics Excel's paste functionality, and works
|
|
1965
2015
|
// as a poor-man's fill-down.
|
|
1966
|
-
if (
|
|
2016
|
+
if (
|
|
2017
|
+
rows.length === 1 &&
|
|
2018
|
+
columnsLength === 1 &&
|
|
2019
|
+
minRowsLength <= 1 &&
|
|
2020
|
+
minColumnsLength <= 1
|
|
2021
|
+
) {
|
|
1967
2022
|
var cellData = rows[0][0].value.map((item) => item.value).join();
|
|
1968
2023
|
|
|
1969
2024
|
self.forEachSelectedCell(function (data, rowIndex, colName) {
|
|
1970
2025
|
data[rowIndex][colName] = cellData;
|
|
1971
2026
|
});
|
|
1972
2027
|
} else {
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
var existingRowData = self.viewData[realRowIndex];
|
|
1983
|
-
var newRowData = Object.assign({}, existingRowData);
|
|
1984
|
-
|
|
1985
|
-
selections[realRowIndex] = [];
|
|
1986
|
-
self.selectedRows.push(realRowIndex);
|
|
1987
|
-
|
|
1988
|
-
for (var colIndex = 0; colIndex < cells.length; colIndex++) {
|
|
1989
|
-
var column = schema[startColIndex + colIndex];
|
|
1990
|
-
|
|
1991
|
-
if (!column) {
|
|
1992
|
-
console.warn('Paste data exceeded grid bounds. Skipping.');
|
|
1993
|
-
continue;
|
|
1994
|
-
}
|
|
1995
|
-
|
|
1996
|
-
var columnName = column.name;
|
|
1997
|
-
var cellData = cells[colIndex].value
|
|
1998
|
-
.map((item) => item.value)
|
|
1999
|
-
.join('');
|
|
2000
|
-
|
|
2001
|
-
if (cellData === undefined || cellData === null) {
|
|
2002
|
-
newRowData[columnName] = existingRowData[columnName];
|
|
2003
|
-
continue;
|
|
2004
|
-
}
|
|
2005
|
-
|
|
2006
|
-
selections[realRowIndex].push(startColIndex + colIndex);
|
|
2007
|
-
|
|
2008
|
-
newRowData[columnName] = cellData;
|
|
2009
|
-
if (self.selectedColumns.indexOf(startColIndex + colIndex) === -1)
|
|
2010
|
-
self.selectedColumns.push(startColIndex + colIndex);
|
|
2011
|
-
}
|
|
2012
|
-
|
|
2013
|
-
self.originalData[self.boundRowIndexMap.get(realRowIndex)] = newRowData;
|
|
2014
|
-
// Update view date here to avoid a full refresh of `viewData`.
|
|
2015
|
-
// To stay in line with Excel and Google Sheet behaviour,
|
|
2016
|
-
// don't perform a full refresh (and filter/sort results)
|
|
2017
|
-
// as this would make any pasted values disappear and/or suddenly change position.
|
|
2018
|
-
self.viewData[realRowIndex] = newRowData;
|
|
2028
|
+
let direction = null;
|
|
2029
|
+
|
|
2030
|
+
if (minRowsLength > rows.length && minColumnsLength > columnsLength) {
|
|
2031
|
+
direction = 'both';
|
|
2032
|
+
} else if (minRowsLength > rows.length) {
|
|
2033
|
+
direction = 'vertical';
|
|
2034
|
+
} else if (minColumnsLength > columnsLength) {
|
|
2035
|
+
direction = 'horizontal';
|
|
2019
2036
|
}
|
|
2020
|
-
|
|
2037
|
+
|
|
2038
|
+
self.insert({
|
|
2039
|
+
rows: rows,
|
|
2040
|
+
startRowIndex: startRowIndex,
|
|
2041
|
+
startColumnIndex: startColIndex,
|
|
2042
|
+
minRowsLength: minRowsLength,
|
|
2043
|
+
minColumnsLength: minColumnsLength,
|
|
2044
|
+
reverseRows: false,
|
|
2045
|
+
reverseColumns: false,
|
|
2046
|
+
clearSelections: true,
|
|
2047
|
+
alwaysFilling: false,
|
|
2048
|
+
direction: direction,
|
|
2049
|
+
});
|
|
2021
2050
|
}
|
|
2022
2051
|
|
|
2023
2052
|
// selections is a sparse array, so we condense:
|
|
@@ -2042,6 +2071,165 @@ export default function (self) {
|
|
|
2042
2071
|
|
|
2043
2072
|
return rows.length;
|
|
2044
2073
|
};
|
|
2074
|
+
self.insert = function ({
|
|
2075
|
+
rows = [],
|
|
2076
|
+
startRowIndex = 0,
|
|
2077
|
+
startColumnIndex = 0,
|
|
2078
|
+
minRowsLength = 0,
|
|
2079
|
+
minColumnsLength = 0,
|
|
2080
|
+
reverseRows = false,
|
|
2081
|
+
reverseColumns = false,
|
|
2082
|
+
clearSelections = false,
|
|
2083
|
+
alwaysFilling = false,
|
|
2084
|
+
direction = 'both',
|
|
2085
|
+
}) {
|
|
2086
|
+
var schema = self.getSchema();
|
|
2087
|
+
const rowsLength = Math.max(rows.length, minRowsLength);
|
|
2088
|
+
const fillCellCallback = self.fillCellCallback;
|
|
2089
|
+
const selections = clearSelections ? [] : self.selections;
|
|
2090
|
+
const filledCells = [];
|
|
2091
|
+
|
|
2092
|
+
for (
|
|
2093
|
+
let rowPosReal = 0, rowDataPos = 0;
|
|
2094
|
+
rowPosReal < rowsLength;
|
|
2095
|
+
rowPosReal++, rowDataPos++
|
|
2096
|
+
) {
|
|
2097
|
+
if (rowDataPos >= rows.length) {
|
|
2098
|
+
rowDataPos = 0;
|
|
2099
|
+
}
|
|
2100
|
+
|
|
2101
|
+
const fillingRow = rowPosReal >= rows.length;
|
|
2102
|
+
const rowPosition = reverseRows
|
|
2103
|
+
? rowsLength - rowPosReal - 1
|
|
2104
|
+
: rowPosReal;
|
|
2105
|
+
// Rows may have been moved by user, so get the actual row index
|
|
2106
|
+
// (instead of the row index at which the row is rendered):
|
|
2107
|
+
var realRowIndex = self.orders.rows[startRowIndex + rowPosition];
|
|
2108
|
+
var cells = rows[rowDataPos];
|
|
2109
|
+
const cellsLength = Math.max(cells.length, minColumnsLength);
|
|
2110
|
+
|
|
2111
|
+
var existingRowData = self.viewData[realRowIndex];
|
|
2112
|
+
var newRowData = Object.assign({}, existingRowData);
|
|
2113
|
+
const fillArgs = fillCellCallback
|
|
2114
|
+
? {
|
|
2115
|
+
rows: rows,
|
|
2116
|
+
direction: direction,
|
|
2117
|
+
rowData: newRowData,
|
|
2118
|
+
existingRowData: existingRowData,
|
|
2119
|
+
rowIndex: realRowIndex,
|
|
2120
|
+
rowOffset: rowDataPos,
|
|
2121
|
+
cells: cells,
|
|
2122
|
+
reversed: direction === 'horizontal' ? reverseColumns : reverseRows,
|
|
2123
|
+
isFillingRow: fillingRow || alwaysFilling,
|
|
2124
|
+
fillingRowPosition: alwaysFilling
|
|
2125
|
+
? rowPosReal
|
|
2126
|
+
: fillingRow
|
|
2127
|
+
? rowPosReal - rows.length
|
|
2128
|
+
: -1,
|
|
2129
|
+
fillingRowLength: alwaysFilling
|
|
2130
|
+
? rowsLength
|
|
2131
|
+
: fillingRow
|
|
2132
|
+
? rowsLength - rows.length
|
|
2133
|
+
: -1,
|
|
2134
|
+
}
|
|
2135
|
+
: undefined;
|
|
2136
|
+
|
|
2137
|
+
self.selectedRows.push(realRowIndex);
|
|
2138
|
+
|
|
2139
|
+
if (selections[realRowIndex] === undefined) {
|
|
2140
|
+
selections[realRowIndex] = [];
|
|
2141
|
+
}
|
|
2142
|
+
|
|
2143
|
+
for (
|
|
2144
|
+
var colPosReal = 0, cellDataPos = 0;
|
|
2145
|
+
colPosReal < cellsLength;
|
|
2146
|
+
colPosReal++, cellDataPos++
|
|
2147
|
+
) {
|
|
2148
|
+
if (cellDataPos >= cells.length) {
|
|
2149
|
+
cellDataPos = 0;
|
|
2150
|
+
}
|
|
2151
|
+
|
|
2152
|
+
const fillingColumn = colPosReal >= cells.length;
|
|
2153
|
+
const colPosition = reverseColumns
|
|
2154
|
+
? cellsLength - colPosReal - 1
|
|
2155
|
+
: colPosReal;
|
|
2156
|
+
const columnIndex = startColumnIndex + colPosition;
|
|
2157
|
+
var column = schema[columnIndex];
|
|
2158
|
+
|
|
2159
|
+
if (!column) {
|
|
2160
|
+
console.warn('Paste data exceeded grid bounds. Skipping.');
|
|
2161
|
+
continue;
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2164
|
+
var columnName = column.name;
|
|
2165
|
+
var cellData = cells[cellDataPos];
|
|
2166
|
+
if (cellData && cellData.value) {
|
|
2167
|
+
cellData = cellData.value.map((item) => item.value).join('');
|
|
2168
|
+
}
|
|
2169
|
+
|
|
2170
|
+
const existingCellData = existingRowData[columnName];
|
|
2171
|
+
|
|
2172
|
+
if (
|
|
2173
|
+
fillCellCallback &&
|
|
2174
|
+
(fillingColumn || fillingRow || alwaysFilling)
|
|
2175
|
+
) {
|
|
2176
|
+
newRowData[columnName] = fillCellCallback({
|
|
2177
|
+
...fillArgs,
|
|
2178
|
+
column: column,
|
|
2179
|
+
columnIndex: columnIndex,
|
|
2180
|
+
columnOffset: cellDataPos,
|
|
2181
|
+
newCellData: cellData,
|
|
2182
|
+
existingCellData: existingCellData,
|
|
2183
|
+
isFillingColumn: fillingColumn || alwaysFilling,
|
|
2184
|
+
fillingColumnPosition: alwaysFilling
|
|
2185
|
+
? colPosReal
|
|
2186
|
+
: fillingColumn
|
|
2187
|
+
? colPosReal - cells.length
|
|
2188
|
+
: -1,
|
|
2189
|
+
fillingColumnLength: alwaysFilling
|
|
2190
|
+
? cellsLength
|
|
2191
|
+
: fillingColumn
|
|
2192
|
+
? cellsLength - cells.length
|
|
2193
|
+
: -1,
|
|
2194
|
+
});
|
|
2195
|
+
} else {
|
|
2196
|
+
newRowData[columnName] =
|
|
2197
|
+
cellData === undefined || cellData === null
|
|
2198
|
+
? existingCellData
|
|
2199
|
+
: cellData;
|
|
2200
|
+
}
|
|
2201
|
+
|
|
2202
|
+
selections[realRowIndex].push(columnIndex);
|
|
2203
|
+
|
|
2204
|
+
if (alwaysFilling || fillingRow || fillingColumn) {
|
|
2205
|
+
filledCells.push([
|
|
2206
|
+
realRowIndex,
|
|
2207
|
+
columnIndex,
|
|
2208
|
+
self.getBoundRowIndexFromViewRowIndex(realRowIndex),
|
|
2209
|
+
self.getBoundColumnIndexFromViewColumnIndex(columnIndex),
|
|
2210
|
+
]);
|
|
2211
|
+
}
|
|
2212
|
+
|
|
2213
|
+
if (self.selectedColumns.indexOf(columnIndex) === -1)
|
|
2214
|
+
self.selectedColumns.push(columnIndex);
|
|
2215
|
+
}
|
|
2216
|
+
|
|
2217
|
+
self.originalData[self.boundRowIndexMap.get(realRowIndex)] = newRowData;
|
|
2218
|
+
// Update view date here to avoid a full refresh of `viewData`.
|
|
2219
|
+
// To stay in line with Excel and Google Sheet behaviour,
|
|
2220
|
+
// don't perform a full refresh (and filter/sort results)
|
|
2221
|
+
// as this would make any pasted values disappear and/or suddenly change position.
|
|
2222
|
+
self.viewData[realRowIndex] = newRowData;
|
|
2223
|
+
}
|
|
2224
|
+
|
|
2225
|
+
self.selections = selections;
|
|
2226
|
+
|
|
2227
|
+
if (filledCells.length > 0 || alwaysFilling) {
|
|
2228
|
+
self.dispatchEvent('afterfill', {
|
|
2229
|
+
filledCells: filledCells,
|
|
2230
|
+
});
|
|
2231
|
+
}
|
|
2232
|
+
};
|
|
2045
2233
|
self.getNextVisibleColumnIndex = function (visibleColumnIndex) {
|
|
2046
2234
|
var x,
|
|
2047
2235
|
s = self.getVisibleSchema();
|
|
@@ -2062,6 +2250,27 @@ export default function (self) {
|
|
|
2062
2250
|
}
|
|
2063
2251
|
return -1;
|
|
2064
2252
|
};
|
|
2253
|
+
self.getSelectionIndex = function () {
|
|
2254
|
+
for (
|
|
2255
|
+
let rowIndex = 0, len = self.selections.length;
|
|
2256
|
+
rowIndex < len;
|
|
2257
|
+
rowIndex++
|
|
2258
|
+
) {
|
|
2259
|
+
const row = self.selections[rowIndex];
|
|
2260
|
+
if (row) {
|
|
2261
|
+
if (row[0] === undefined) break;
|
|
2262
|
+
|
|
2263
|
+
return {
|
|
2264
|
+
row: rowIndex,
|
|
2265
|
+
column: row[0] < 0 ? row[1] : row[0],
|
|
2266
|
+
rowLength: len - rowIndex,
|
|
2267
|
+
columnLength: row.length - (row[0] < 0 ? 1 : 0),
|
|
2268
|
+
};
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
|
|
2272
|
+
return null;
|
|
2273
|
+
};
|
|
2065
2274
|
self.paste = function (event) {
|
|
2066
2275
|
if (!self.attributes.editable) {
|
|
2067
2276
|
return;
|
|
@@ -2098,28 +2307,24 @@ export default function (self) {
|
|
|
2098
2307
|
return;
|
|
2099
2308
|
}
|
|
2100
2309
|
|
|
2101
|
-
|
|
2310
|
+
const selectionIndex = self.getSelectionIndex();
|
|
2311
|
+
if (!selectionIndex) return;
|
|
2102
2312
|
|
|
2103
|
-
|
|
2104
|
-
for (
|
|
2105
|
-
let rowIndex = 0, len = self.selections.length;
|
|
2106
|
-
rowIndex < len;
|
|
2107
|
-
rowIndex++
|
|
2108
|
-
) {
|
|
2109
|
-
const row = self.selections[rowIndex];
|
|
2110
|
-
if (row) {
|
|
2111
|
-
if (row[0] === undefined) return;
|
|
2112
|
-
startCell = [rowIndex, row[0] < 0 ? row[1] : row[0]];
|
|
2113
|
-
break;
|
|
2114
|
-
}
|
|
2115
|
-
}
|
|
2313
|
+
var itemToPaste = pasteableItems[0];
|
|
2116
2314
|
|
|
2117
2315
|
// itemToPaste is cleared once accessed (getData or getAsString),
|
|
2118
2316
|
// so we need to store the type here, before reading its value:
|
|
2119
2317
|
var pasteType = itemToPaste.type;
|
|
2120
2318
|
|
|
2121
2319
|
itemToPaste.getAsString(function (pasteValue) {
|
|
2122
|
-
self.pasteData(
|
|
2320
|
+
self.pasteData(
|
|
2321
|
+
pasteValue,
|
|
2322
|
+
pasteType,
|
|
2323
|
+
selectionIndex.row,
|
|
2324
|
+
selectionIndex.column,
|
|
2325
|
+
selectionIndex.rowLength,
|
|
2326
|
+
selectionIndex.columnLength,
|
|
2327
|
+
);
|
|
2123
2328
|
|
|
2124
2329
|
self.draw();
|
|
2125
2330
|
});
|
|
@@ -2159,5 +2364,186 @@ export default function (self) {
|
|
|
2159
2364
|
|
|
2160
2365
|
event.preventDefault();
|
|
2161
2366
|
};
|
|
2367
|
+
self.selectionHandleMove = function (e) {
|
|
2368
|
+
if (!self.movingSelectionHandle) {
|
|
2369
|
+
return;
|
|
2370
|
+
}
|
|
2371
|
+
|
|
2372
|
+
const clippingRect = self.getClippingRect(e);
|
|
2373
|
+
const rowIndex = self.currentCell.rowIndex;
|
|
2374
|
+
const columnIndex = self.currentCell.columnIndex;
|
|
2375
|
+
const isInSelectionBounds =
|
|
2376
|
+
rowIndex >= -1 &&
|
|
2377
|
+
columnIndex >= -1 &&
|
|
2378
|
+
self.fillOverlay.selection.left <= columnIndex &&
|
|
2379
|
+
self.fillOverlay.selection.right >= columnIndex &&
|
|
2380
|
+
self.fillOverlay.selection.top <= rowIndex &&
|
|
2381
|
+
self.fillOverlay.selection.bottom >= rowIndex;
|
|
2382
|
+
|
|
2383
|
+
self.fillOverlay.minX = clippingRect.x;
|
|
2384
|
+
self.fillOverlay.minY = clippingRect.y;
|
|
2385
|
+
self.fillOverlay.x = Math.max(clippingRect.x, e.clientX);
|
|
2386
|
+
self.fillOverlay.y = Math.max(clippingRect.y, e.clientY);
|
|
2387
|
+
|
|
2388
|
+
// If we are in the selection bounds, allow user to change directions.
|
|
2389
|
+
if (isInSelectionBounds) {
|
|
2390
|
+
self.fillOverlay.lastInBoundsLocation = {
|
|
2391
|
+
x: e.clientX,
|
|
2392
|
+
y: e.clientY,
|
|
2393
|
+
};
|
|
2394
|
+
} else if (
|
|
2395
|
+
self.fillOverlay.lastInBoundsLocation ||
|
|
2396
|
+
!self.fillOverlay.direction
|
|
2397
|
+
) {
|
|
2398
|
+
const lastInBoundsLocation = self.fillOverlay.lastInBoundsLocation;
|
|
2399
|
+
self.fillOverlay.lastInBoundsLocation = undefined;
|
|
2400
|
+
|
|
2401
|
+
const x = lastInBoundsLocation
|
|
2402
|
+
? lastInBoundsLocation.x
|
|
2403
|
+
: self.fillOverlay.handle.x;
|
|
2404
|
+
const y = lastInBoundsLocation
|
|
2405
|
+
? lastInBoundsLocation.y
|
|
2406
|
+
: self.fillOverlay.handle.y;
|
|
2407
|
+
const dx = Math.abs(e.clientX - x);
|
|
2408
|
+
const dy = Math.abs(e.clientY - y);
|
|
2409
|
+
|
|
2410
|
+
if (dx > 5 || dy > 5) {
|
|
2411
|
+
self.fillOverlay.direction = dx > dy ? 'x' : 'y';
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2415
|
+
if (rowIndex >= 0) {
|
|
2416
|
+
self.fillOverlay.rowIndex = rowIndex;
|
|
2417
|
+
}
|
|
2418
|
+
if (columnIndex >= 0) {
|
|
2419
|
+
self.fillOverlay.columnIndex = columnIndex;
|
|
2420
|
+
if (rowIndex === -1 && self.visibleRows.length) {
|
|
2421
|
+
self.fillOverlay.rowIndex = self.visibleRows[0];
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2424
|
+
|
|
2425
|
+
if (rowIndex >= -1 && columnIndex >= -1) {
|
|
2426
|
+
self.fillOverlay.snap = self.currentCell;
|
|
2427
|
+
} else {
|
|
2428
|
+
self.fillOverlay.snap = undefined;
|
|
2429
|
+
}
|
|
2430
|
+
};
|
|
2431
|
+
self.stopSelectionHandleMove = function (e) {
|
|
2432
|
+
if (!self.fillOverlay.handle) {
|
|
2433
|
+
return false;
|
|
2434
|
+
}
|
|
2435
|
+
|
|
2436
|
+
self.ignoreNextClick = true;
|
|
2437
|
+
|
|
2438
|
+
window.removeEventListener('mousemove', self.selectionHandleMove, false);
|
|
2439
|
+
window.removeEventListener('mouseup', self.stopSelectionHandleMove, false);
|
|
2440
|
+
|
|
2441
|
+
const overlay = self.fillOverlay;
|
|
2442
|
+
const selectionIndex = self.getSelectionIndex();
|
|
2443
|
+
const bounds = overlay.selection;
|
|
2444
|
+
if (!selectionIndex) return;
|
|
2445
|
+
|
|
2446
|
+
self.movingSelectionHandle = undefined;
|
|
2447
|
+
self.fillOverlay = {};
|
|
2448
|
+
|
|
2449
|
+
if (overlay.rowIndex >= 0 && overlay.columnIndex >= 0) {
|
|
2450
|
+
const boundsOld = { ...bounds };
|
|
2451
|
+
const isVertical = overlay.direction === 'y';
|
|
2452
|
+
const isHorizontal = overlay.direction === 'x';
|
|
2453
|
+
|
|
2454
|
+
let startRow,
|
|
2455
|
+
rowLength,
|
|
2456
|
+
startColumn,
|
|
2457
|
+
columnLength,
|
|
2458
|
+
reverseVertically = false,
|
|
2459
|
+
reverseHorizontally = false;
|
|
2460
|
+
|
|
2461
|
+
if (isVertical) {
|
|
2462
|
+
if (overlay.rowIndex < bounds.top) {
|
|
2463
|
+
bounds.top = overlay.rowIndex;
|
|
2464
|
+
reverseVertically = true;
|
|
2465
|
+
} else if (overlay.rowIndex > bounds.bottom) {
|
|
2466
|
+
bounds.bottom = overlay.rowIndex;
|
|
2467
|
+
}
|
|
2468
|
+
|
|
2469
|
+
startRow =
|
|
2470
|
+
bounds.top < boundsOld.top ? bounds.top : boundsOld.bottom + 1;
|
|
2471
|
+
rowLength =
|
|
2472
|
+
bounds.top < boundsOld.top
|
|
2473
|
+
? boundsOld.top - bounds.top
|
|
2474
|
+
: bounds.bottom - boundsOld.bottom;
|
|
2475
|
+
startColumn = selectionIndex.column;
|
|
2476
|
+
columnLength = selectionIndex.columnLength;
|
|
2477
|
+
} else if (isHorizontal) {
|
|
2478
|
+
if (overlay.columnIndex < bounds.left) {
|
|
2479
|
+
bounds.left = overlay.columnIndex;
|
|
2480
|
+
reverseHorizontally = true;
|
|
2481
|
+
} else if (overlay.columnIndex > bounds.right) {
|
|
2482
|
+
bounds.right = overlay.columnIndex;
|
|
2483
|
+
}
|
|
2484
|
+
|
|
2485
|
+
startColumn =
|
|
2486
|
+
bounds.left < boundsOld.left ? bounds.left : boundsOld.right + 1;
|
|
2487
|
+
columnLength =
|
|
2488
|
+
bounds.left < boundsOld.left
|
|
2489
|
+
? boundsOld.left - bounds.left
|
|
2490
|
+
: bounds.right - boundsOld.right;
|
|
2491
|
+
startRow = selectionIndex.row;
|
|
2492
|
+
rowLength = selectionIndex.rowLength;
|
|
2493
|
+
}
|
|
2494
|
+
|
|
2495
|
+
if (
|
|
2496
|
+
bounds.left <= bounds.right &&
|
|
2497
|
+
bounds.top <= bounds.bottom &&
|
|
2498
|
+
(bounds.left < boundsOld.left ||
|
|
2499
|
+
bounds.top < boundsOld.top ||
|
|
2500
|
+
bounds.right > boundsOld.right ||
|
|
2501
|
+
bounds.bottom > boundsOld.bottom)
|
|
2502
|
+
) {
|
|
2503
|
+
const schema = self.getSchema();
|
|
2504
|
+
const rows = [];
|
|
2505
|
+
|
|
2506
|
+
for (
|
|
2507
|
+
let rowIndex = 0;
|
|
2508
|
+
rowIndex < Math.min(rowLength, selectionIndex.rowLength);
|
|
2509
|
+
rowIndex++
|
|
2510
|
+
) {
|
|
2511
|
+
const rowData = self.viewData[selectionIndex.row + rowIndex];
|
|
2512
|
+
|
|
2513
|
+
rows[rowIndex] = [];
|
|
2514
|
+
|
|
2515
|
+
for (
|
|
2516
|
+
let columnIndex = 0;
|
|
2517
|
+
columnIndex < Math.min(columnLength, selectionIndex.columnLength);
|
|
2518
|
+
columnIndex++
|
|
2519
|
+
) {
|
|
2520
|
+
const column = schema[selectionIndex.column + columnIndex];
|
|
2521
|
+
if (!column) continue;
|
|
2522
|
+
|
|
2523
|
+
const cellData = rowData[column.name];
|
|
2524
|
+
|
|
2525
|
+
rows[rowIndex][columnIndex] = cellData;
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
|
|
2529
|
+
self.insert({
|
|
2530
|
+
rows: rows,
|
|
2531
|
+
startRowIndex: startRow,
|
|
2532
|
+
startColumnIndex: startColumn,
|
|
2533
|
+
minRowsLength: rowLength,
|
|
2534
|
+
minColumnsLength: columnLength,
|
|
2535
|
+
reverseRows: reverseVertically,
|
|
2536
|
+
reverseColumns: reverseHorizontally,
|
|
2537
|
+
clearSelections: false,
|
|
2538
|
+
alwaysFilling: true,
|
|
2539
|
+
direction: isHorizontal ? 'horizontal' : 'vertical',
|
|
2540
|
+
});
|
|
2541
|
+
|
|
2542
|
+
self.draw();
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
|
|
2546
|
+
return true;
|
|
2547
|
+
};
|
|
2162
2548
|
return;
|
|
2163
2549
|
}
|
package/lib/intf.js
CHANGED
|
@@ -92,6 +92,7 @@ export default function (self, ctor) {
|
|
|
92
92
|
self.selections = [];
|
|
93
93
|
self.selectedRows = [];
|
|
94
94
|
self.selectedColumns = [];
|
|
95
|
+
self.fillOverlay = {};
|
|
95
96
|
self.filterable = {
|
|
96
97
|
rows: [],
|
|
97
98
|
columns: [],
|
|
@@ -2057,6 +2058,14 @@ export default function (self, ctor) {
|
|
|
2057
2058
|
self.cellGridAttributes = value;
|
|
2058
2059
|
},
|
|
2059
2060
|
});
|
|
2061
|
+
Object.defineProperty(self.intf, 'fillCellCallback', {
|
|
2062
|
+
get: function () {
|
|
2063
|
+
return self.fillCellCallback;
|
|
2064
|
+
},
|
|
2065
|
+
set: function setFillCellCallback(value) {
|
|
2066
|
+
self.fillCellCallback = value;
|
|
2067
|
+
},
|
|
2068
|
+
});
|
|
2060
2069
|
Object.defineProperty(self.intf, 'ctx', {
|
|
2061
2070
|
get: function () {
|
|
2062
2071
|
return self.ctx;
|
package/lib/main.js
CHANGED
package/lib/publicMethods.js
CHANGED
|
@@ -782,8 +782,8 @@ export default function (self) {
|
|
|
782
782
|
* @memberof canvasDatagrid
|
|
783
783
|
* @name hideColumns
|
|
784
784
|
* @method
|
|
785
|
-
* @param {number} beginColumnOrderIndex
|
|
786
|
-
* @param {number} [endColumnOrderIndex]
|
|
785
|
+
* @param {number} beginColumnOrderIndex The begin column order index
|
|
786
|
+
* @param {number} [endColumnOrderIndex] The end column order index
|
|
787
787
|
*/
|
|
788
788
|
self.hideColumns = function (beginColumnOrderIndex, endColumnOrderIndex) {
|
|
789
789
|
const schema = self.getSchema();
|
|
@@ -823,8 +823,8 @@ export default function (self) {
|
|
|
823
823
|
* @memberof canvasDatagrid
|
|
824
824
|
* @name unhideColumns
|
|
825
825
|
* @method
|
|
826
|
-
* @param {number} beginColumnOrderIndex
|
|
827
|
-
* @param {number} [endColumnOrderIndex]
|
|
826
|
+
* @param {number} beginColumnOrderIndex The begin column order index
|
|
827
|
+
* @param {number} [endColumnOrderIndex] The end column order index
|
|
828
828
|
*/
|
|
829
829
|
self.unhideColumns = function (beginColumnOrderIndex, endColumnOrderIndex) {
|
|
830
830
|
const orders = self.orders.columns;
|
|
@@ -849,8 +849,8 @@ export default function (self) {
|
|
|
849
849
|
* @memberof canvasDatagrid
|
|
850
850
|
* @name hideRows
|
|
851
851
|
* @method
|
|
852
|
-
* @param {number} beginRowIndex
|
|
853
|
-
* @param {number} endRowIndex
|
|
852
|
+
* @param {number} beginRowIndex The begin row index
|
|
853
|
+
* @param {number} endRowIndex The end row index
|
|
854
854
|
*/
|
|
855
855
|
self.hideRows = function (beginRowIndex, endRowIndex) {
|
|
856
856
|
if (
|
|
@@ -863,8 +863,8 @@ export default function (self) {
|
|
|
863
863
|
* @memberof canvasDatagrid
|
|
864
864
|
* @name unhideRows
|
|
865
865
|
* @method
|
|
866
|
-
* @param {number} beginRowIndex
|
|
867
|
-
* @param {number} endRowIndex
|
|
866
|
+
* @param {number} beginRowIndex The begin row index
|
|
867
|
+
* @param {number} endRowIndex The end row index
|
|
868
868
|
*/
|
|
869
869
|
self.unhideRows = function (beginRowIndex, endRowIndex) {
|
|
870
870
|
self.hiddenRowRanges = self.hiddenRowRanges.filter(
|