Skip to content
This repository was archived by the owner on Mar 14, 2022. It is now read-only.

Commit 3331959

Browse files
committed
Merge branch 'release/3.1.1'
2 parents 78848f8 + f396eff commit 3331959

17 files changed

+725
-411
lines changed

package-lock.json

+356-373
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@handsontable/react",
3-
"version": "3.1.0",
3+
"version": "3.1.1",
44
"description": "Best Data Grid for React with Spreadsheet Look and Feel.",
55
"author": "Handsoncode <[email protected]> (https://handsoncode.net)",
66
"homepage": "https://handsontable.com",

src/helpers.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import ReactDOM from 'react-dom';
33

44
let bulkComponentContainer = null;
55

6+
/**
7+
* Warning message for the `autoRowSize`/`autoColumnSize` compatibility check.
8+
*/
9+
export const AUTOSIZE_WARNING = 'Your `HotTable` configuration includes `autoRowSize`/`autoColumnSize` options, which are not compatible with ' +
10+
' the component-based renderers`. Disable `autoRowSize` and `autoColumnSize` to prevent row and column misalignment.';
11+
612
/**
713
* Filter out and return elements of the provided `type` from the `HotColumn` component's children.
814
*

src/hotColumn.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class HotColumn extends React.Component<HotColumnProps, {}> {
4040
* @returns {Object}
4141
*/
4242
getSettingsProps(): HotTableProps {
43-
this.internalProps = ['_emitColumnSettings', '_columnIndex', '_getChildElementByType', '_getRendererWrapper',
43+
this.internalProps = ['__componentRendererColumns', '_emitColumnSettings', '_columnIndex', '_getChildElementByType', '_getRendererWrapper',
4444
'_getEditorClass', '_getEditorCache', 'hot-renderer', 'hot-editor', 'children'];
4545

4646
return Object.keys(this.props)
@@ -84,6 +84,7 @@ class HotColumn extends React.Component<HotColumnProps, {}> {
8484

8585
if (rendererElement !== null) {
8686
this.columnSettings.renderer = this.props._getRendererWrapper(rendererElement);
87+
this.props._componentRendererColumns.set(this.props._columnIndex, true);
8788

8889
} else if (this.hasProp('renderer')) {
8990
this.columnSettings.renderer = this.props.renderer;

src/hotTable.tsx

+19-28
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { HotColumn } from './hotColumn';
66
import * as packageJson from '../package.json';
77
import { HotTableProps } from './types';
88
import {
9+
AUTOSIZE_WARNING,
910
createEditorPortal,
1011
createPortal,
1112
getChildElementByType,
@@ -14,6 +15,7 @@ import {
1415
addUnsafePrefixes,
1516
removeEditorContainers
1617
} from './helpers';
18+
import { warn } from 'handsontable/commonjs/helpers/console';
1719

1820
/**
1921
* A Handsontable-ReactJS wrapper.
@@ -113,6 +115,15 @@ class HotTable extends React.Component<HotTableProps, {}> {
113115
*/
114116
private editorCache: Map<string, React.Component> = new Map();
115117

118+
/**
119+
* Map with column indexes (or a string = 'global') as keys, and booleans as values. Each key represents a component-based editor
120+
* declared for the used column index, or a global one, if the key is the `global` string.
121+
*
122+
* @private
123+
* @type {Map}
124+
*/
125+
private componentRendererColumns: Map<number | string, boolean> = new Map();
126+
116127
/**
117128
* Package version getter.
118129
*
@@ -169,6 +180,8 @@ class HotTable extends React.Component<HotTableProps, {}> {
169180
removeEditorContainers(this.hotElementRef ? this.hotElementRef.ownerDocument : document);
170181

171182
renderedCellCache.clear();
183+
184+
this.componentRendererColumns.clear();
172185
}
173186

174187
/**
@@ -336,14 +349,15 @@ class HotTable extends React.Component<HotTableProps, {}> {
336349
newSettings.editor = this.getEditorClass(globalEditorNode);
337350

338351
} else {
339-
newSettings.editor = this.props.editor || this.props.settings ? this.props.settings.editor : void 0;
352+
newSettings.editor = this.props.editor || (this.props.settings ? this.props.settings.editor : void 0);
340353
}
341354

342355
if (globalRendererNode) {
343356
newSettings.renderer = this.getRendererWrapper(globalRendererNode);
357+
this.componentRendererColumns.set('global', true);
344358

345359
} else {
346-
newSettings.renderer = this.props.renderer || this.props.settings ? this.props.settings.renderer : void 0;
360+
newSettings.renderer = this.props.renderer || (this.props.settings ? this.props.settings.renderer : void 0);
347361
}
348362

349363
return newSettings;
@@ -356,32 +370,8 @@ class HotTable extends React.Component<HotTableProps, {}> {
356370
*/
357371
displayAutoSizeWarning(newGlobalSettings: Handsontable.GridSettings): void {
358372
if (this.hotInstance.getPlugin('autoRowSize').enabled || this.hotInstance.getPlugin('autoColumnSize').enabled) {
359-
const isNativeRenderer = (renderer, column?) => {
360-
const standaloneColumnRenderer = this.props.columns && this.props.columns[column] ? this.props.columns[column].renderer : null;
361-
const settingsObjectColumnRenderer = this.props.settings && this.props.settings.columns && this.props.settings.columns[column] ? this.props.settings.columns[column].renderer : null;
362-
363-
return column ?
364-
standaloneColumnRenderer === renderer || settingsObjectColumnRenderer === renderer :
365-
this.props.renderer === renderer || this.props.settings.renderer === renderer;
366-
};
367-
let rendererDefined = false;
368-
369-
if (newGlobalSettings.renderer && !isNativeRenderer(newGlobalSettings.renderer)) {
370-
rendererDefined = true;
371-
}
372-
373-
if (!rendererDefined && newGlobalSettings.columns) {
374-
for (let i = 0; i < newGlobalSettings.columns.length; i++) {
375-
if (newGlobalSettings.columns[i].renderer && !isNativeRenderer(newGlobalSettings.columns[i].renderer, i)) {
376-
rendererDefined = true;
377-
break;
378-
}
379-
}
380-
}
381-
382-
if (rendererDefined) {
383-
console.warn('Your `HotTable` configuration includes `autoRowSize`/`autoColumnSize` options, which are not compatible with ' +
384-
' the component-based renderers`. Disable `autoRowSize` and `autoColumnSize` to prevent row and column misalignment.');
373+
if (this.componentRendererColumns.size > 0) {
374+
warn(AUTOSIZE_WARNING);
385375
}
386376
}
387377
}
@@ -513,6 +503,7 @@ class HotTable extends React.Component<HotTableProps, {}> {
513503
// clone the HotColumn nodes and extend them with the callbacks
514504
let childClones = children.map((childNode: React.ReactElement, columnIndex: number) => {
515505
return React.cloneElement(childNode, {
506+
_componentRendererColumns: this.componentRendererColumns,
516507
_emitColumnSettings: this.setHotColumnSettings.bind(this),
517508
_columnIndex: columnIndex,
518509
_getChildElementByType: getChildElementByType.bind(this),

src/types.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface HotTableProps extends Handsontable.GridSettings {
1818
* Properties related to the HotColumn architecture.
1919
*/
2020
export interface HotColumnProps extends Handsontable.GridSettings {
21+
_componentRendererColumns?: Map<number | string, boolean>;
2122
_emitColumnSettings?: (columnSettings: Handsontable.GridSettings, columnIndex: number) => void;
2223
_columnIndex?: number,
2324
_getChildElementByType?: (children: React.ReactNode, type: string) => React.ReactElement;

test/_helpers.tsx

+15-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ class IndividualPropsWrapper extends React.Component<{ref?: string, id?: string}
6565
render(): React.ReactElement {
6666
return (
6767
<div>
68-
<HotTable licenseKey="non-commercial-and-evaluation" ref={this.setHotElementRef.bind(this)} id="hot" {...this.state.hotSettings} />
68+
<HotTable
69+
licenseKey="non-commercial-and-evaluation"
70+
ref={this.setHotElementRef.bind(this)}
71+
id="hot" {...this.state.hotSettings}
72+
autoRowSize={false}
73+
autoColumnSize={false}
74+
/>
6975
</div>
7076
);
7177
}
@@ -91,7 +97,14 @@ class SingleObjectWrapper extends React.Component<{ref?: string, id?: string}, {
9197
render(): React.ReactElement {
9298
return (
9399
<div>
94-
<HotTable licenseKey="non-commercial-and-evaluation" ref={this.setHotElementRef.bind(this)} id="hot" settings={this.state.hotSettings}/>
100+
<HotTable
101+
licenseKey="non-commercial-and-evaluation"
102+
ref={this.setHotElementRef.bind(this)}
103+
id="hot"
104+
settings={this.state.hotSettings}
105+
autoRowSize={false}
106+
autoColumnSize={false}
107+
/>
95108
</div>
96109
);
97110
}

0 commit comments

Comments
 (0)