Skip to content

Commit

Permalink
Merge branch 'develop' into feature/issue-5684
Browse files Browse the repository at this point in the history
  • Loading branch information
mrpiotr-dev committed May 9, 2019
2 parents 7e75f22 + 13c0b84 commit b216f27
Show file tree
Hide file tree
Showing 28 changed files with 1,104 additions and 918 deletions.
3 changes: 2 additions & 1 deletion handsontable.d.ts
Expand Up @@ -183,6 +183,7 @@ declare namespace Handsontable {
from: CellCoords;
to: CellCoords;
}
type OverlayType = 'top' | 'bottom' | 'left' | 'top_left_corner' | 'bottom_left_corner' | 'debug';
}

namespace cellTypes {
Expand Down Expand Up @@ -2262,7 +2263,7 @@ declare namespace Handsontable {
offset: (elem: HTMLElement) => object;
outerHeight: (elem: HTMLElement) => number;
outerWidth: (element: HTMLElement) => number;
overlayContainsElement: (overlayType: string, element: HTMLElement) => boolean;
overlayContainsElement: (overlayType: wot.OverlayType, element: HTMLElement, root: HTMLElement) => boolean;
pageX: (event: Event) => number;
pageY: (event: Event) => number;
polymerUnwrap: (element: HTMLElement) => any | void;
Expand Down
1,430 changes: 705 additions & 725 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -63,7 +63,7 @@
"dependencies": {
"@types/pikaday": "1.6.0",
"core-js": "^3.0.0",
"hot-formula-parser": "^3.0.0",
"hot-formula-parser": "^3.0.1",
"moment": "2.20.1",
"numbro": "2.1.1",
"pikaday": "1.5.1"
Expand All @@ -90,7 +90,7 @@
"cpy-cli": "^2.0.0",
"cross-env": "^5.0.1",
"css-loader": "^2.1.1",
"ecstatic": "^3.2.0",
"ecstatic": "^4.1.2",
"env-cmd": "^8.0.2",
"eslint": "^4.3.0",
"eslint-config-airbnb-base": "^11.3.1",
Expand All @@ -101,14 +101,14 @@
"jasmine-co": "^1.2.2",
"jasmine-core": "2.5.2",
"jasmine-terminal-reporter": "^1.0.3",
"jest": "^24.1.0",
"jest-cli": "^24.1.0",
"jest": "^24.7.1",
"jest-cli": "^24.7.1",
"loader-utils": "^1.1.0",
"mini-css-extract-plugin": "^0.5.0",
"on-build-webpack": "^0.1.0",
"optimize-css-assets-webpack-plugin": "^5.0.1",
"progress-bar-webpack-plugin": "^1.10.0",
"puppeteer": "1.12.2",
"puppeteer": "^1.15.0",
"rimraf": "^2.5.4",
"spawn-command": "0.0.2",
"string-replace-webpack-plugin": "^0.1.3",
Expand Down
12 changes: 8 additions & 4 deletions src/3rdparty/walkontable/src/table.js
Expand Up @@ -478,12 +478,14 @@ class Table {
let row = index(TR);
let col = cellElement.cellIndex;

if (overlayContainsElement(Overlay.CLONE_TOP_LEFT_CORNER, cellElement) || overlayContainsElement(Overlay.CLONE_TOP, cellElement)) {
if (overlayContainsElement(Overlay.CLONE_TOP_LEFT_CORNER, cellElement, this.wtRootElement)
|| overlayContainsElement(Overlay.CLONE_TOP, cellElement, this.wtRootElement)) {
if (CONTAINER.nodeName === 'THEAD') {
row -= CONTAINER.childNodes.length;
}

} else if (overlayContainsElement(Overlay.CLONE_BOTTOM_LEFT_CORNER, cellElement) || overlayContainsElement(Overlay.CLONE_BOTTOM, cellElement)) {
} else if (overlayContainsElement(Overlay.CLONE_BOTTOM_LEFT_CORNER, cellElement, this.wtRootElement)
|| overlayContainsElement(Overlay.CLONE_BOTTOM, cellElement, this.wtRootElement)) {
const totalRows = this.wot.getSetting('totalRows');

row = totalRows - CONTAINER.childNodes.length + row;
Expand All @@ -495,8 +497,10 @@ class Table {
row = this.rowFilter.renderedToSource(row);
}

if (overlayContainsElement(Overlay.CLONE_TOP_LEFT_CORNER, cellElement) || overlayContainsElement(Overlay.CLONE_LEFT, cellElement)
|| overlayContainsElement(Overlay.CLONE_BOTTOM_LEFT_CORNER, cellElement) || overlayContainsElement(Overlay.CLONE_BOTTOM, cellElement)) {
if (overlayContainsElement(Overlay.CLONE_TOP_LEFT_CORNER, cellElement, this.wtRootElement)
|| overlayContainsElement(Overlay.CLONE_LEFT, cellElement, this.wtRootElement)
|| overlayContainsElement(Overlay.CLONE_BOTTOM_LEFT_CORNER, cellElement, this.wtRootElement)
|| overlayContainsElement(Overlay.CLONE_BOTTOM, cellElement, this.wtRootElement)) {
col = this.columnFilter.offsettedTH(col);

} else {
Expand Down
37 changes: 37 additions & 0 deletions src/3rdparty/walkontable/test/spec/table.spec.js
Expand Up @@ -145,6 +145,43 @@ describe('WalkontableTable', () => {
expect(wt.wtTable.getCoords($td2[0])).toEqual(new Walkontable.CellCoords(1, 1));
});

it('getCoords should return coords of TH', () => {

$wrapper.width(300);

const wt = new Walkontable.Core({
table: $table[0],
data: getData,
totalRows: getTotalRows,
totalColumns: getTotalColumns,
columnHeaders: [function(col, TH) {
TH.innerHTML = col + 1;
}]
});
wt.draw();

const $th2 = $table.find('thead tr:first th:eq(1)');
expect(wt.wtTable.getCoords($th2[0])).toEqual(new Walkontable.CellCoords(-1, 1));
});

it('getCoords should return coords of TD (with fixedColumnsLeft)', () => {
const wt = new Walkontable.Core({
table: $table[0],
data: getData,
totalRows: getTotalRows,
totalColumns: getTotalColumns,
fixedColumnsLeft: 2,
columnHeaders: [function(col, TH) {
TH.innerHTML = col + 1;
}]
});
wt.draw();

const $cloneLeft = $('.ht_clone_left');
const $td2 = $cloneLeft.find('tbody tr:eq(1) td:eq(1)');
expect(wt.wtTable.getCoords($td2[0])).toEqual(new Walkontable.CellCoords(1, 1));
});

it('getStretchedColumnWidth should return valid column width when stretchH is set as \'all\'', () => {
const wt = new Walkontable.Core({
table: $table[0],
Expand Down
2 changes: 1 addition & 1 deletion src/core.js
Expand Up @@ -746,7 +746,7 @@ export default function Core(rootElement, userSettings, rootInstanceSymbol = fal
current.col = start.col;
cellMeta = instance.getCellMeta(current.row, current.col);

if ((source === 'CopyPaste.paste' || source === 'Autofill.autofill') && cellMeta.skipRowOnPaste) {
if ((source === 'CopyPaste.paste' || source === 'Autofill.fill') && cellMeta.skipRowOnPaste) {
skippedRow += 1;
current.row += 1;
rlen += 1;
Expand Down
3 changes: 2 additions & 1 deletion src/css/handsontable.css
Expand Up @@ -511,12 +511,13 @@ CheckboxRenderer
*/
.handsontable .htCheckboxRendererInput {
display: inline-block;
vertical-align: middle;
}
.handsontable .htCheckboxRendererInput.noValue {
opacity: 0.5;
}
.handsontable .htCheckboxRendererLabel {
font-size: inherit;
vertical-align: middle;
cursor: pointer;
display: inline-block;
width: 100%;
Expand Down
23 changes: 23 additions & 0 deletions src/defaultSettings.js
Expand Up @@ -1324,6 +1324,29 @@ DefaultSettings.prototype = {
*/
skipColumnOnPaste: false,

/**
* @description
* When added to a cell property, it skips the row on paste and pastes the data on the following row.
*
* @type {Boolean}
* @default false
*
* @example
* ```js
* cells: function(row, column) {
* const cellProperties = {};
*
* // don't paste data to the second row
* if (row === 1) {
* cellProperties.skipRowOnPaste = true;
* }
*
* return cellProperties;
* }
* ```
*/
skipRowOnPaste: false,

/**
* @description
* Setting to `true` enables the {@link Search} plugin (see [demo](https://docs.handsontable.com/demo-search-for-values.html)).
Expand Down
2 changes: 1 addition & 1 deletion src/editors/textEditor.js
Expand Up @@ -315,7 +315,7 @@ class TextEditor extends BaseEditor {
this.textareaParentStyle.opacity = '1';

this.textareaStyle.textIndent = '';
this.textareaStyle.overflowY = 'auto';
this.textareaStyle.overflowY = 'hidden';
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/helpers/dom/element.js
Expand Up @@ -206,10 +206,11 @@ export function index(element) {
*
* @param {String} overlay
* @param {HTMLElement} element
* @param {HTMLElement} root
* @returns {boolean}
*/
export function overlayContainsElement(overlayType, element) {
const overlayElement = element.ownerDocument.querySelector(`.ht_clone_${overlayType}`);
export function overlayContainsElement(overlayType, element, root) {
const overlayElement = root.parentElement.querySelector(`.ht_clone_${overlayType}`);
return overlayElement ? overlayElement.contains(element) : null;
}

Expand Down
63 changes: 58 additions & 5 deletions src/plugins/autofill/autofill.js
@@ -1,6 +1,8 @@
import BasePlugin from './../_base';
import Hooks from './../../pluginHooks';
import { offset, outerHeight, outerWidth } from './../../helpers/dom/element';
import { arrayEach } from './../../helpers/array';
import { rangeEach } from './../../helpers/number';
import EventManager from './../../eventManager';
import { registerPlugin } from './../../plugins';
import { CellCoords } from './../../3rdparty/walkontable/src';
Expand Down Expand Up @@ -121,19 +123,70 @@ class Autofill extends BasePlugin {
super.disablePlugin();
}

/**
* Prepares copyable ranges from the cells selection.
*
* @private
* @returns {Object[]} ranges Array of objects with properties `startRow`, `startCol`, `endRow` and `endCol`.
*/
getCopyableRanges() {
const selRange = this.hot.getSelectedRangeLast();
const topLeft = selRange.getTopLeftCorner();
const bottomRight = selRange.getBottomRightCorner();
const startRow = topLeft.row;
const startCol = topLeft.col;
const endRow = bottomRight.row;
const endCol = bottomRight.col;
let copyableRanges = [];

copyableRanges.push({
startRow,
startCol,
endRow,
endCol
});

copyableRanges = this.hot.runHooks('modifyCopyableRange', copyableRanges);

return copyableRanges;
}

/**
* Gets selection data
*
* @private
* @returns {Array} Array with the data.
*/
getSelectionData() {
const selRange = {
from: this.hot.getSelectedRangeLast().from,
to: this.hot.getSelectedRangeLast().to,
};
const copyableRanges = this.getCopyableRanges();
const copyableRows = [];
const copyableColumns = [];
const data = [];

arrayEach(copyableRanges, (range) => {
rangeEach(range.startRow, range.endRow, (row) => {
if (copyableRows.indexOf(row) === -1) {
copyableRows.push(row);
}
});
rangeEach(range.startCol, range.endCol, (column) => {
if (copyableColumns.indexOf(column) === -1) {
copyableColumns.push(column);
}
});
});

arrayEach(copyableRows, (row) => {
const rowSet = [];

arrayEach(copyableColumns, (column) => {
rowSet.push(this.hot.getCopyableData(row, column));
});

data.push(rowSet);
});

return this.hot.getData(selRange.from.row, selRange.from.col, selRange.to.row, selRange.to.col);
return data;
}

/**
Expand Down
31 changes: 31 additions & 0 deletions src/plugins/autofill/test/autofill.e2e.js
Expand Up @@ -823,6 +823,37 @@ describe('AutoFill', () => {
expect(JSON.stringify(getData(1, 1, 2, 4))).toEqual(JSON.stringify([[2, 0, 1, 2], [5, 3, 4, 5]]));
});

it('should omitting data from hidden cells', () => {
handsontable({
data: [
[1, 2, 3, 4, 5, 6],
[1, 2, 3, 4, 5, 6],
[1, 2, null, null, null, null],
[1, 2, null, null, null, null]
],
hiddenColumns: {
copyPasteEnabled: false,
indicators: true,
columns: [1]
},
hiddenRows: {
copyPasteEnabled: false,
rows: [1],
indicators: true
},
});

selectCell(0, 0, 0, 2);

spec().$container.find('.wtBorder.area.corner').simulate('mousedown');
$(getCell(2, 2, true)).simulate('mouseover').simulate('mouseup');

expect(getDataAtCell(0, 0)).toEqual(1);
expect(getDataAtCell(0, 2)).toEqual(3);
expect(getDataAtCell(2, 0)).toEqual(1);
expect(getDataAtCell(2, 2)).toEqual(3);
});

describe('should works properly when two or more instances of Handsontable was initialized with other settings (#3257)', () => {
let getData;
let $container1;
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/autofill/utils.js
Expand Up @@ -26,7 +26,7 @@ export function getDeltas(start, end, data, direction) {
if (['down', 'up'].indexOf(direction) !== -1) {
const arr = [];

for (let col = 0; col <= diffCol; col++) {
for (let col = 0; col < diffCol; col++) {
const startValue = parseInt(data[0][col], 10);
const endValue = parseInt(data[rowsLength - 1][col], 10);
const delta = (direction === 'down' ? (endValue - startValue) : (startValue - endValue)) / (rowsLength - 1) || 0;
Expand All @@ -38,7 +38,7 @@ export function getDeltas(start, end, data, direction) {
}

if (['right', 'left'].indexOf(direction) !== -1) {
for (let row = 0; row <= diffRow; row++) {
for (let row = 0; row < diffRow; row++) {
const startValue = parseInt(data[row][0], 10);
const endValue = parseInt(data[row][columnsLength - 1], 10);
const delta = (direction === 'right' ? (endValue - startValue) : (startValue - endValue)) / (columnsLength - 1) || 0;
Expand Down
Expand Up @@ -115,7 +115,7 @@ describe('ContextMenu', () => {

hot.validateCells();

await sleep(100);
await sleep(150);

selectCell(1, 1);
contextMenu();
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/copyPaste/test/copyPaste.e2e.js
Expand Up @@ -66,7 +66,7 @@ describe('CopyPaste', () => {
handsontable();
selectCell(0, 0);

await sleep(10);
await sleep(150);

expect(document.activeElement).toBe(getActiveEditor().TEXTAREA);
expect($('#HandsontableCopyPaste').length).toBe(0);
Expand Down Expand Up @@ -123,7 +123,7 @@ describe('CopyPaste', () => {
hot1.selectCell(0, 0);
hot2.selectCell(1, 1);

await sleep(0);
await sleep(100);

expect($('#HandsontableCopyPaste').length).toBe(0);
expect(document.activeElement).toBe(hot2.getActiveEditor().TEXTAREA);
Expand Down

0 comments on commit b216f27

Please sign in to comment.