Skip to content

Commit

Permalink
Merge pull request #739 from fin-hypergrid/develop
Browse files Browse the repository at this point in the history
Merge 3.0.1 develop to master
  • Loading branch information
joneit authored Jul 12, 2018
2 parents f39fa11 + 1ed2947 commit 9fcf6a0
Show file tree
Hide file tree
Showing 12 changed files with 145 additions and 87 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ It also highlights a DOM-based custom external editor triggered via hypergrid ev
<img src="images/README/gridshot04.gif">

## Table of Contents
* [Current Release](#current-release-300---7-july-2018)
* [Current Release](#current-release-301---10-july-2018)
* [Distribution](#distribution)
* [Demos](#demos)
* [Features](#features)
Expand All @@ -17,16 +17,16 @@ It also highlights a DOM-based custom external editor triggered via hypergrid ev
* [Roadmap](#roadmap)
* [Contributing](#contributors)

### Current Release (3.0.0 - 7 July 2018)
### Current Release (3.0.1 - 10 July 2018)

**Hypergrid 3.0.0 includes a revised data model with some breaking changes.**
**Hypergrid 3.0 includes a revised data model with some breaking changes.**

_For a complete list of changes, see the [release notes](https://github.com/fin-hypergrid/core/releases)._

### Distribution

#### npm module
Published as a CommonJS module to npmjs.org. Specify SEMVER `"fin-hypergrid": "3.0.0"` (or `"^3.0.0"`) in your package.json file, issue the `npm install` command, and let your bundler (wepback, Browserify) do the rest.
Published as a CommonJS module to npmjs.org. Specify SEMVER `"fin-hypergrid": "3.0.1"` (or `"^3.0.1"`) in your package.json file, issue the `npm install` command, and let your bundler (wepback, Browserify) do the rest.

#### Build file
Published as a pre-bundled build file, which contains a JavaScript [IIFE](https://en.wikipedia.org/wiki/Immediately-invoked_function_expression) that creates (as needed) the global namespace `window.fin` and populates `window.fin.Hypergrid`. See the [CDN index](https://fin-hypergrid.github.io#index) for links.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fin-hypergrid",
"version": "3.0.0",
"version": "3.0.1",
"description": "Canvas-based high-performance grid",
"main": "src/Hypergrid",
"repository": {
Expand Down
16 changes: 5 additions & 11 deletions src/Hypergrid/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
'use strict';

var dispatchGridEvent = require('../lib/dispatchGridEvent');
var Button = require('../cellRenderers/Button');

/**
* @summary Grid event support.
Expand Down Expand Up @@ -181,7 +182,7 @@ exports.mixin = {
},

fireSyntheticRowHeaderClickedEvent: function(event) {
return dispatchEvent.call(this, 'fin-row-header-clicked', true, {}, event);
return dispatchGridEvent.call(this, 'fin-row-header-clicked', true, {}, event);
},

/**
Expand Down Expand Up @@ -248,7 +249,7 @@ exports.mixin = {
* @returns {boolean} Proceed; event was not [canceled](https://developer.mozilla.org/docs/Web/API/EventTarget/dispatchEvent#Return_Value `EventTarget.dispatchEvent`).
*/
fireSyntheticButtonPressedEvent: function(event) {
if (event.properties.renderer === 'button') {
if (event.cellRenderer instanceof Button) { // Button or subclass thereof?
if (event.value && event.value.subrows) {
var y = event.primitiveEvent.detail.mouse.y - event.bounds.y,
subheight = event.bounds.height / event.value.subrows;
Expand Down Expand Up @@ -500,18 +501,15 @@ exports.mixin = {
}
handleMouseEvent(e, function(mouseEvent) {
var isMouseDownCell = this.mouseDownState && this.mouseDownState.gridCell.equals(mouseEvent.gridCell);
if (
isMouseDownCell &&
isMousePointInClickRect(mouseEvent)
) {
if (isMouseDownCell && mouseEvent.mousePointInClickRect) {
mouseEvent.keys = e.detail.keys; // todo: this was in fin-tap but wasn't here
if (this.mouseDownState) {
this.fireSyntheticButtonPressedEvent(this.mouseDownState);
this.mouseDownState = null;
}
this.fireSyntheticClickEvent(mouseEvent);
this.delegateClick(mouseEvent);
}
this.mouseDownState = null;
});
});

Expand Down Expand Up @@ -691,7 +689,3 @@ exports.mixin = {
this.behavior.onKeyUp(this, event);
},
};

function isMousePointInClickRect(e) {
return !e.clickRect || e.clickRect.contains(e.mousePoint);
}
6 changes: 4 additions & 2 deletions src/Hypergrid/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ var Hypergrid = Base.extend('Hypergrid', {
var canvas = this.canvas;
if (canvas) {
if (this.properties.repaintImmediately) {
canvas.paintNow();
this.paintNow();
} else {
canvas.repaint();
}
Expand All @@ -976,7 +976,9 @@ var Hypergrid = Base.extend('Hypergrid', {
* @desc Paint immediately in this microtask.
*/
paintNow: function() {
this.canvas.paintNow();
if (this.behavior.columnsCreated) {
this.canvas.paintNow();
}
},

/**
Expand Down
4 changes: 4 additions & 0 deletions src/behaviors/Behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ var Behavior = Base.extend('Behavior', {
tc = this.treeColumnIndex,
rc = this.rowColumnIndex;

this.columnsCreated = false;

schema[tc] = schema[tc] || {};
schema[tc].index = tc;
if (schema[tc].name === undefined) { schema[tc].name = this.treeColumnNameDefault; }
Expand Down Expand Up @@ -325,6 +327,8 @@ var Behavior = Base.extend('Behavior', {
realImplementation.call(this);
}

this.columnsCreated = true;

this.changed();

dispatchGridEvent.call(this.grid, 'fin-hypergrid-columns-created');
Expand Down
86 changes: 86 additions & 0 deletions src/behaviors/Local/columnEnum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
'use strict';

// `columnEnum` et al, have been deprecated as of 3.0.0 in favor of accessing column schema
// through .schema, .columns, and .allColumns, all of which now sport self-referential dictionaries.
// To finally remove, delete this file and all lines using `_columnEnum`

var ArrayDecorator = require('synonomous');
var transformers = require('synonomous/transformers');

var warned = {};

var columnEnumKey = function() {};

function warnColumnEnumDeprecation(method, msg) {
if (!warned[method]) {
console.warn('.' + method + ' has been deprecated as of v3.0.0. (Will be removed in a future release.) ' + (msg || ''));
warned[method] = true;
}
}

exports.mixin = {
columnEnumSynchronize: function() {
this._columnEnumKey = this._columnEnumKey || 'toAllCaps';

var columnEnum = this._columnEnum || (this._columnEnum = {}),
allColumns = this.allColumns,
arrayDecorator = new ArrayDecorator({ transformations: [this._columnEnumKey] }),
dict = arrayDecorator.decorateArray(allColumns.slice());

dict.length = 0;
Object.keys(dict).reduce(function(columnEnum, key) {
columnEnum[key] = dict[key].index;
return columnEnum;
}, columnEnum);

// clean up
Object.keys(columnEnum).forEach(function(key) {
if (!(key in dict)) {
delete columnEnum[key];
}
});
},

get columnEnum() {
if (!warned.columnEnum) {
console.warn('.columnEnum[propName] has been deprecated as of v3.0.0 in favor of either .getColumns()[propName].index or .schema[propName].index. (Will be removed in a future release.)');
warned.columnEnum = true;
}
return this._columnEnum;
},

get columnEnumKey() {
warnColumnEnumDeprecation('columnEnumKey');
return this._columnEnumKey === 'verbatim' ? 'passThrough' : this._columnEnumKey;
},
set columnEnumKey(transformer) {
warnColumnEnumDeprecation('columnEnumKey');
var type = typeof transformer,
keys = Object.keys(transformers);
switch (type) {
case 'string':
if (transformer === 'passThrough') {
transformer = 'verbatim';
} else if (!(transformer in transformers)) {
throw new this.HypergridError('Expected registered transformer for .columnEnumKey value from: ' + keys)
}
this._columnEnumKey = transformer;
break;
case 'function':
this._columnEnumKey = keys.find(function(key) { return transformer === transformers[key]; });
if (!this._columnEnumKey) {
throw new this.HypergridError('.columnEnumKey has been deprecated as of v3.0.0 and now accepts a function reference (or string key) from require("synonmous/transformers"): ' + keys)
}
break;
default:
throw new this.HypergridError('Expected string or function for .columnEnumKey assignment but received ' + type + '.');
}
}
};

exports.mixInShared = {
get columnEnumDecorators() {
warnColumnEnumDeprecation('columnEnumDecorators');
return transformers;
}
};
3 changes: 2 additions & 1 deletion src/behaviors/Local/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ function createColumns() {
this.columnEnumSynchronize();
}

Local.prototype.mixIn(require('../columnEnum').mixin);
Local.prototype.mixIn(require('./columnEnum').mixin);
Local.prototype.mixIn.call(Local, require('./columnEnum').mixInShared);

module.exports = Local;
62 changes: 0 additions & 62 deletions src/behaviors/columnEnum.js

This file was deleted.

22 changes: 18 additions & 4 deletions src/cellRenderers/SimpleCell.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var CellRenderer = require('./CellRenderer');
var Rectangle = require('rectangular').Rectangle;
var images = require('../../images');

var WHITESPACE = /\s\s+/g;
Expand Down Expand Up @@ -134,24 +135,34 @@ var SimpleCell = CellRenderer.extend('SimpleCell', {
valWidth = config.isHeaderRow && config.headerTextWrapping
? renderMultiLineText(gc, config, val, leftPadding, rightPadding)
: renderSingleLineText(gc, config, val, leftPadding, rightPadding);
} else if (centerIcon) {
}

if (centerIcon) {
// Measure & draw center icon
iyoffset = Math.round((height - centerIcon.height) / 2);
ixoffset = Math.round((width - centerIcon.width) / 2);
gc.drawImage(centerIcon, x + width - ixoffset - centerIcon.width, y + iyoffset);
ixoffset = width - Math.round((width - centerIcon.width) / 2) - centerIcon.width;
gc.drawImage(centerIcon, x + ixoffset, y + iyoffset);
valWidth = iconPadding + centerIcon.width + iconPadding;
if (config.hotIcon === 'center') {
config.clickRect = new Rectangle(ixoffset, iyoffset, centerIcon.width, centerIcon.height);
}
}


if (leftIcon) {
// Draw left icon
iyoffset = Math.round((height - leftIcon.height) / 2);
gc.drawImage(leftIcon, x + iconPadding, y + iyoffset);
if (config.hotIcon === 'left') {
config.clickRect = new Rectangle(iconPadding, iyoffset, leftIcon.width, leftIcon.height);
}
}

if (rightIcon) {
// Repaint background before painting right icon, because text may have flowed under where it will be.
// This is a work-around to clipping which is too expensive to perform here.
var rightX = x + width - (rightIcon.width + iconPadding);
ixoffset = width - (rightIcon.width + iconPadding);
var rightX = x + ixoffset;
if (inheritsBackgroundColor) {
foundationColor = true;
colors.unshift(config.backgroundColor);
Expand All @@ -161,6 +172,9 @@ var SimpleCell = CellRenderer.extend('SimpleCell', {
// Draw right icon
iyoffset = Math.round((height - rightIcon.height) / 2);
gc.drawImage(rightIcon, rightX, y + iyoffset);
if (config.hotIcon === 'right') {
config.clickRect = new Rectangle(ixoffset, iyoffset, rightIcon.width, rightIcon.height);
}
}

if (config.cellBorderThickness) {
Expand Down
6 changes: 4 additions & 2 deletions src/features/RowSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ var RowSelection = Feature.extend('RowSelection', {
*/
handleMouseDown: function(grid, event) {
var leftClick = !event.primitiveEvent.detail.isRightClick,
rowNumberClick = leftClick && grid.properties.showRowNumbers && event.isHandleColumn;
rowNumberClick = leftClick &&
grid.properties.showRowNumbers &&
event.isHandleColumn &&
event.mousePointInClickRect;

if (rowNumberClick && !grid.fireSyntheticRowHeaderClickedEvent(event)) {
return;
Expand Down Expand Up @@ -435,7 +438,6 @@ function moveCellSelection(grid) {
grid.selectionModel.select(x, y, width, height, fireSelectionChangedEvent);
grid.repaint();
}

}

module.exports = RowSelection;
16 changes: 16 additions & 0 deletions src/lib/cellEventFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,22 @@ var cellEventProperties = Object.defineProperties({}, { // all props non-enumera
}
},

mousePointInClickRect: {
get: function() {
var clickRect = 'clickRect' in this ? this.clickRect : this.properties.clickRect;
if (!clickRect) {
return true;
} else if (typeof clickRect.contains === 'function') {
return clickRect.contains(this.mousePoint);
} else {
return (
clickRect.x <= this.mousePoint.x && this.mousePoint.x < clickRect.x + clickRect.width &&
clickRect.y <= this.mousePoint.y && this.mousePoint.y < clickRect.y + clickRect.height
);
}
}
},

/** "Visible" means scrolled into view.
* @type {boolean}
* @memberOf CellEvent#
Expand Down
1 change: 1 addition & 0 deletions src/renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,7 @@ var Renderer = Base.extend('Renderer', {

// Following supports clicking in a renderer-defined Rectangle of a cell (in the cell's local coordinates)
cellEvent.clickRect = config.clickRect;
cellEvent.cellRenderer = cellRenderer; // renderer actually used per getCell; used by fireSyntheticButtonPressedEvent

return config.minWidth;
},
Expand Down

0 comments on commit 9fcf6a0

Please sign in to comment.