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

Commit e7c303f

Browse files
authored
Hooks mounted as Inputs (#102)
* Changed: hooks are defined as a @inputs + tests for CE #83 * Reverted change in style.css #83 * Removed: cached context in settings resolver. #83 * Changes after CR + bumped version of Handsontable #83
1 parent 1b69a54 commit e7c303f

19 files changed

Lines changed: 10822 additions & 8099 deletions

lib/ce/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.0.0-beta4",
44
"keywords": [],
55
"peerDependencies": {
6-
"handsontable": "0.35.1",
6+
"handsontable": "^4.0.0",
77
"zone.js": "^0.8.19"
88
},
99
"ngPackage": {

lib/ce/src/hot-column.component.ts

Lines changed: 3 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
OnInit,
44
OnChanges,
55
OnDestroy,
6-
SimpleChanges,
76
Input,
87
} from '@angular/core';
98

@@ -20,119 +19,52 @@ export class HotColumnComponent implements OnInit, OnChanges, OnDestroy {
2019

2120
@Input() allowEmpty: boolean;
2221
@Input() allowHtml: boolean;
23-
@Input() allowInsertColumn: boolean;
24-
@Input() allowInsertRow: boolean;
2522
@Input() allowInvalid: boolean;
26-
@Input() allowRemoveColumn: boolean;
27-
@Input() allowRemoveRow: boolean;
28-
@Input() autoColumnSize: boolean | object;
29-
@Input() autoComplete: any[];
30-
@Input() autoRowSize: boolean | object;
31-
@Input() autoWrapCol: boolean;
32-
@Input() autoWrapRow: boolean;
33-
@Input() cell: any[];
34-
@Input() cells: (row: number, column: number, prop: object) => object;
3523
@Input() checkedTemplate: boolean | string;
3624
@Input() className: string | string[];
37-
@Input() colHeaders: boolean | string[] | ((column: number) => string);
38-
@Input() columnHeaderHeight: number | number[];
39-
@Input() columns: object[] | ((column: number) => object);
4025
@Input() columnSorting: boolean | object;
4126
@Input() colWidths: number | number[] | string | ((column: number) => number);
4227
@Input() commentedCellClassName: string;
43-
@Input() comments: boolean | object[];
44-
@Input() contextMenu: boolean | object | object[];
4528
@Input() copyable: boolean;
46-
@Input() copyPaste: boolean;
4729
@Input() correctFormat: boolean;
48-
@Input() currentColClassName: string;
49-
@Input() currentHeaderClassName: string;
50-
@Input() currentRowClassName: string;
51-
@Input() customBorders: boolean | object[];
52-
@Input() data: any[];
53-
@Input() dataSchema: object;
30+
@Input() data: string | (() => void);
5431
@Input() dateFormat: string;
55-
@Input() debug: boolean;
5632
@Input() defaultDate: string;
57-
@Input() disableVisualSelection: boolean | string | string[];
58-
@Input() dragToScroll: boolean;
5933
@Input() editor: boolean | string | (() => void);
60-
@Input() enterBeginsEditing: boolean;
61-
@Input() enterMoves: object | (() => void);
62-
@Input() fillHandle: boolean | string | object;
63-
@Input() filter: boolean;
6434
@Input() filteringCaseSensitive: boolean;
65-
@Input() fixedColumnsLeft: number;
66-
@Input() fixedRowsTop: number;
67-
@Input() fragmentSelection: boolean | string;
68-
@Input() height: number | (() => number);
6935
@Input() invalidCellClassName: string;
7036
@Input() label: object;
71-
@Input() language: string;
72-
@Input() manualColumnFreeze: boolean;
73-
@Input() manualColumnMove: boolean | number[];
74-
@Input() manualColumnResize: boolean | number[];
75-
@Input() manualRowMove: boolean | number[];
76-
@Input() manualRowResize: boolean | number[];
77-
@Input() maxCols: number;
78-
@Input() maxRows: number;
79-
@Input() mergeCells: boolean | object[];
80-
@Input() minCols: number;
81-
@Input() minRows: number;
82-
@Input() minSpareCols: number;
83-
@Input() minSpareRows: number;
84-
@Input() multiSelect: boolean;
8537
@Input() noWordWrapClassName: string;
8638
@Input() numericFormat: any;
87-
@Input() observeChanges: boolean;
88-
@Input() observeDOMVisibility: boolean;
89-
@Input() outsideClickDeselects: boolean | ((event: Event) => boolean);
90-
@Input() persistentState: boolean;
9139
@Input() placeholder: any;
9240
@Input() placeholderCellClassName: string;
93-
@Input() preventOverflow: boolean | string;
9441
@Input() readOnly: boolean;
9542
@Input() readOnlyCellClassName: string;
96-
@Input() renderAllRows: boolean;
9743
@Input() renderer: string | (() => void);
98-
@Input() rowHeaders: boolean | string[] | (() => string);
99-
@Input() rowHeaderWidth: number | number[];
100-
@Input() rowHeights: number | number[] | string | ((row: number) => number);
101-
@Input() search: boolean;
10244
@Input() selectOptions: string[] | number[];
10345
@Input() skipColumnOnPaste: boolean;
10446
@Input() sortByRelevance: boolean;
10547
@Input() sortFunction: (sortOrder: boolean) => void;
10648
@Input() sortIndicator: boolean;
10749
@Input() source: any[] | (() => void);
108-
@Input() startCols: number;
109-
@Input() startRows: number;
110-
@Input() stretchH: string;
11150
@Input() strict: boolean;
112-
@Input() tableClassName: string | string[];
113-
@Input() tabMoves: object;
11451
@Input() title: string;
11552
@Input() trimDropdown: boolean;
116-
@Input() trimWhitespace: boolean;
11753
@Input() type: string;
11854
@Input() uncheckedTemplate: boolean | string;
119-
@Input() undo: boolean;
12055
@Input() validator: string | RegExp | (() => void);
121-
@Input() viewportColumnRenderingOffset: number | string;
122-
@Input() viewportRowRenderingOffset: number | string;
12356
@Input() visibleRows: number;
12457
@Input() width: number| (() => number);
12558
@Input() wordWrap: boolean;
12659

127-
constructor(private parentComponent: HotTableComponent) {
128-
}
60+
constructor(private parentComponent: HotTableComponent) {}
12961

13062
ngOnInit() {
13163
this.firstRun = false;
13264
this.parentComponent.addColumn(this);
13365
}
13466

135-
ngOnChanges(changes: SimpleChanges) {
67+
ngOnChanges() {
13668
if (this.firstRun) {
13769
return;
13870
}

lib/ce/src/hot-settings-resolver.service.ts

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Injectable, SimpleChanges } from '@angular/core';
22

3-
const AVAILABLE_OPTIONS: string[] = ['allowEmpty', 'allowHtml', 'allowInsertColumn', 'allowInsertRow',
3+
const AVAILABLE_OPTIONS: string[] = ['activeHeaderClassName', 'allowEmpty', 'allowHtml', 'allowInsertColumn', 'allowInsertRow',
44
'allowInvalid', 'allowRemoveColumn', 'allowRemoveRow', 'autoColumnSize', 'autoComplete', 'autoRowSize',
55
'autoWrapCol', 'autoWrapRow', 'cell', 'cells', 'checkedTemplate', 'className', 'colHeaders', 'columnHeaderHeight',
66
'columns', 'columnSorting', 'colWidths', 'commentedCellClassName', 'comments', 'contextMenu', 'copyable',
@@ -38,7 +38,7 @@ const AVAILABLE_HOOKS: string[] = ['afterBeginEditing', 'afterCellMetaReset', 'a
3838
'beforeInitWalkontable', 'beforeKeyDown', 'beforeLanguageChange', 'beforeOnCellMouseDown', 'beforeOnCellMouseOut',
3939
'beforeOnCellMouseOver', 'beforePaste', 'beforeRedo', 'beforeRemoveCellMeta', 'beforeRemoveCol',
4040
'beforeRemoveRow', 'beforeRender', 'beforeRenderer', 'beforeRowMove', 'beforeRowResize', 'beforeSetRangeEnd',
41-
'beforeSetRangeEnd', 'beforeStretchingColumnWidth', 'beforeTouchScroll', 'beforeUndo', 'beforeValidate',
41+
'beforeSetRangeStart', 'beforeStretchingColumnWidth', 'beforeTouchScroll', 'beforeUndo', 'beforeValidate',
4242
'beforeValueRender', 'construct', 'init', 'manualRowHeights', 'modifyAutofillRange', 'modifyCol',
4343
'modifyColHeader', 'modifyColumnHeaderHeight', 'modifyColWidth', 'modifyCopyableRange', 'modifyData',
4444
'modifyRow', 'modifyRowData', 'modifyRowHeader', 'modifyRowHeaderWidth', 'modifyRowHeight', 'modifyTransformEnd',
@@ -47,44 +47,34 @@ const AVAILABLE_HOOKS: string[] = ['afterBeginEditing', 'afterCellMetaReset', 'a
4747

4848
@Injectable()
4949
export class HotSettingsResolver {
50-
private hooks = AVAILABLE_HOOKS;
51-
private options = AVAILABLE_OPTIONS;
5250

5351
mergeSettings(component): object {
5452
const mergedSettings: object = {};
53+
const options = AVAILABLE_HOOKS.concat(AVAILABLE_OPTIONS);
5554

56-
if (component['settings'] !== void 0) {
57-
Object.keys(component['settings']).forEach((key) => {
58-
if (this.hooks.indexOf(key) > -1) {
59-
mergedSettings[key] = (p1, p2, p3, p4, p5, p6) => {
60-
return component._ngZone.run(() => {
61-
return component['settings'][key].call(component.hotInstance, p1, p2, p3, p4, p5, p6);
62-
})
63-
};
55+
options.forEach((key) => {
56+
let option;
6457

65-
} else {
66-
mergedSettings[key] = component['settings'][key];
67-
}
68-
});
69-
}
70-
71-
this.options.forEach((key) => {
72-
const option = component[key];
58+
if (typeof component['settings'] === 'object') {
59+
option = component['settings'][key];
60+
}
7361

74-
if (option !== void 0) {
75-
mergedSettings[key] = option;
62+
if (component[key] !== void 0) {
63+
option = component[key];
7664
}
77-
});
7865

79-
this.hooks.forEach((key) => {
80-
const hook = component[key];
66+
if (option === void 0) {
67+
return;
8168

82-
if (hook && hook.observers.length > 0) {
83-
mergedSettings[key] = (p1, p2, p3, p4, p5, p6) => {
84-
component._ngZone.run(() => {
85-
component[key].emit({ hotInstance: component.hotInstance, params: [p1, p2, p3, p4, p5, p6] });
69+
} else if (typeof option === 'function' && AVAILABLE_HOOKS.indexOf(key) > -1) {
70+
mergedSettings[key] = function(...args) {
71+
return component._ngZone.run(() => {
72+
return option(this, ...args);
8673
});
8774
};
75+
76+
} else {
77+
mergedSettings[key] = option;
8878
}
8979
});
9080

0 commit comments

Comments
 (0)