Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript .d.ts type definitions improvement #5767

Merged
merged 50 commits into from Feb 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
8660b12
Added type aliases and refined types for Core, cellTypes, and _editors
aaronbeall Jan 16, 2019
1c489fb
Improved GridSettings, added TODOs
aaronbeall Jan 19, 2019
a6ba670
Refined GridSettings into GridSettings -> ColumnSettings -> CellMeta
aaronbeall Jan 23, 2019
a88c3b2
Added validators, missing renderers and editors, and this types
aaronbeall Jan 23, 2019
ef1eb65
Renamed _editors to editors
aaronbeall Jan 23, 2019
fc1de62
Misc refactoring
aaronbeall Jan 24, 2019
451e64d
Removed TODOs
aaronbeall Jan 24, 2019
3844146
Added datePickerConfig: PikadayOptions
aaronbeall Jan 24, 2019
08301bd
Refactored Hooks into Events and Hooks
aaronbeall Jan 24, 2019
0ac72b0
Cleanup and fix comments plugin config
aaronbeall Jan 24, 2019
b21577a
Renamed CellMeta to CellProperties, added licenseKey prop
aaronbeall Jan 24, 2019
b374d84
get and register methods for cell types
aaronbeall Jan 26, 2019
ac94024
get/register methods for validators
aaronbeall Jan 26, 2019
66dd4cc
Fixed Endpoint type
aaronbeall Jan 26, 2019
5c9f9b3
Improved contextMenu types, CellProperties type
aaronbeall Jan 29, 2019
8a33b43
Improved typing of Events
aaronbeall Jan 29, 2019
7037824
abstract BaseEditor and move CommentEditor
aaronbeall Jan 29, 2019
ff6a4c6
Added Omit<> for backwards compatibilty, semi-colon consistency
aaronbeall Jan 29, 2019
7116e66
Merge branch 'develop' into dts-improvements
aaronbeall Jan 30, 2019
8109b52
Refined Element and Event types
aaronbeall Jan 30, 2019
a67df8c
Type arg improvements to meta functions
aaronbeall Jan 30, 2019
8f8f645
Minor fixes
aaronbeall Jan 30, 2019
2c389f8
Improvements to cell meta types
aaronbeall Jan 30, 2019
990eb5d
Fixed event callback return types
aaronbeall Feb 5, 2019
af35705
Reverted back to using _editors to avoid circular name reference
aaronbeall Feb 5, 2019
279e6db
Fixed type tests
aaronbeall Feb 5, 2019
df9e6fa
Removed missing setting
aaronbeall Feb 5, 2019
6cdfc2f
Added missing type tests
aaronbeall Feb 5, 2019
1388bd8
Enabled --strict type checking
aaronbeall Feb 5, 2019
fe44681
Improve types and tests for top-level editors, renderers, and editors
aaronbeall Feb 6, 2019
f00b08d
Merge branch 'develop' into dts-improvements
aaronbeall Feb 6, 2019
9ce1f2f
Added missing settings
aaronbeall Feb 6, 2019
edfd026
Delete generated typers
aaronbeall Feb 6, 2019
7732f79
Doc
aaronbeall Feb 6, 2019
ccb5d5d
Added missing settings to tests
aaronbeall Feb 6, 2019
de634d9
Doc fix
aaronbeall Feb 6, 2019
20cb4fc
BaseEditor type improvement
aaronbeall Feb 6, 2019
81f6ef4
Minor fixes
aaronbeall Feb 7, 2019
fd45347
Added NestedRows.collapsingUI object
aaronbeall Feb 7, 2019
0238e8f
Added issing Handsontable.EventManager
aaronbeall Feb 7, 2019
6a70e87
Improved tests, updated TS to use tuple rest arg in testing
aaronbeall Feb 8, 2019
22238bc
Rename params to be consistent with docs
aaronbeall Feb 8, 2019
0ff3aa8
Overloads for stricter oneOf(), eliminates need for most enums
aaronbeall Feb 8, 2019
a984012
Doc
aaronbeall Feb 8, 2019
fb0a10b
Rename
aaronbeall Feb 8, 2019
707e922
Simpler way to achieve oneOf()
aaronbeall Feb 12, 2019
528e0a9
Remove unused code
aaronbeall Feb 12, 2019
5a02fb7
Core methods test improvement
aaronbeall Feb 12, 2019
6e9ee72
Moved Events into Hooks.Events
aaronbeall Feb 15, 2019
dc5405c
Move Hooks into Hooks.Methods
aaronbeall Feb 15, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1,409 changes: 946 additions & 463 deletions handsontable.d.ts

Large diffs are not rendered by default.

4,808 changes: 2,408 additions & 2,400 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -75,6 +75,7 @@
"data-spreadsheet"
],
"dependencies": {
"@types/pikaday": "1.6.0",
"hot-formula-parser": "^3.0.0",
"moment": "2.20.1",
"numbro": "^2.0.6",
Expand Down Expand Up @@ -130,7 +131,7 @@
"style-loader": "^0.18.2",
"supports-color": "^4.2.1",
"tree-kill": "^1.2.1",
"typescript": "^2.4.2",
"typescript": "^3.3.3",
"uglifyjs-webpack-plugin": "^1.3.0",
"webpack": "^3.5.6"
},
Expand Down
70 changes: 70 additions & 0 deletions test/types/cellTypes.types.ts
@@ -0,0 +1,70 @@
import Handsontable from 'handsontable';

const elem = document.createElement('div');
const hot = new Handsontable(elem, {});

const cellProperties: Handsontable.CellProperties = {
row: 0,
col: 0,
instance: {} as Handsontable,
visualRow: 0,
visualCol: 0,
prop: 'foo'
};

const TD = document.createElement('td');

// Verify the built-in cellTypes exist and have the correct shape
new Handsontable.cellTypes.autocomplete.editor(hot, 0, 0, 'prop', TD, cellProperties);
Handsontable.cellTypes.autocomplete.renderer(hot, TD, 0, 0, 'prop', 'foo', cellProperties);
Handsontable.cellTypes.autocomplete.validator.apply(cellProperties, ['', (valid: boolean) => {}]);

new Handsontable.cellTypes.checkbox.editor(hot, 0, 0, 'prop', TD, cellProperties);
Handsontable.cellTypes.checkbox.renderer(hot, TD, 0, 0, 'prop', 'foo', cellProperties);

new Handsontable.cellTypes.date.editor(hot, 0, 0, 'prop', TD, cellProperties);
Handsontable.cellTypes.date.renderer(hot, TD, 0, 0, 'prop', 'foo', cellProperties);
Handsontable.cellTypes.date.validator.apply(cellProperties, ['', (valid: boolean) => {}]);

new Handsontable.cellTypes.dropdown.editor(hot, 0, 0, 'prop', TD, cellProperties);
Handsontable.cellTypes.dropdown.renderer(hot, TD, 0, 0, 'prop', 'foo', cellProperties);
Handsontable.cellTypes.dropdown.validator.apply(cellProperties, ['', (valid: boolean) => {}]);

new Handsontable.cellTypes.handsontable.editor(hot, 0, 0, 'prop', TD, cellProperties);
Handsontable.cellTypes.handsontable.renderer(hot, TD, 0, 0, 'prop', 'foo', cellProperties);

new Handsontable.cellTypes.numeric.editor(hot, 0, 0, 'prop', TD, cellProperties);
Handsontable.cellTypes.numeric.renderer(hot, TD, 0, 0, 'prop', 'foo', cellProperties);
Handsontable.cellTypes.numeric.validator.apply(cellProperties, ['', (valid: boolean) => {}]);

new Handsontable.cellTypes.password.editor(hot, 0, 0, 'prop', TD, cellProperties);
Handsontable.cellTypes.password.renderer(hot, TD, 0, 0, 'prop', 'foo', cellProperties);

new Handsontable.cellTypes.text.editor(hot, 0, 0, 'prop', TD, cellProperties);
Handsontable.cellTypes.text.renderer(hot, TD, 0, 0, 'prop', 'foo', cellProperties);

new Handsontable.cellTypes.time.editor(hot, 0, 0, 'prop', TD, cellProperties);
Handsontable.cellTypes.time.renderer(hot, TD, 0, 0, 'prop', 'foo', cellProperties);
Handsontable.cellTypes.time.validator.apply(cellProperties, ['', (valid: boolean) => {}]);

// Verify top-level cellTypes API
const autocomplete = Handsontable.cellTypes.getCellType('autocomplete') as Handsontable.cellTypes.Autocomplete;
new autocomplete.editor(hot, 0, 0, 'prop', TD, cellProperties);
autocomplete.renderer(hot, TD, 0, 0, 'prop', 'foo', cellProperties);
autocomplete.validator.apply(cellProperties, ['', (valid: boolean) => {}]);

class CustomEditor extends Handsontable.editors.BaseEditor {
open(){}
close(){}
getValue(){}
setValue(value: any){}
focus(){}
}
Handsontable.cellTypes.registerCellType('custom', {
editor: CustomEditor,
renderer: (hot: Handsontable, TD: HTMLTableCellElement, row: number, col: number, prop: number | string, value: any, cellProperties: Handsontable.CellProperties) => TD,
validator: (value: any, callback: (valid: boolean) => void) => {},
className: 'my-cell',
allowInvalid: true,
myCustomCellState: 'complete',
});
69 changes: 69 additions & 0 deletions test/types/editors.types.ts
@@ -0,0 +1,69 @@
import Handsontable from 'handsontable';

const elem = document.createElement('div');
const hot = new Handsontable(elem, {});

const cellProperties: Handsontable.CellProperties = {
row: 0,
col: 0,
instance: {} as Handsontable,
visualRow: 0,
visualCol: 0,
prop: 'foo'
};

const TD = document.createElement('td');

// Verify the built-in editors exist and have the right class types -- spot check a couple class methods on each
const autocomplete = new Handsontable.editors.AutocompleteEditor(hot, 0, 0, 'prop', TD, cellProperties);
autocomplete.isOpened();
autocomplete.flipDropdown(100);

const checkbox = new Handsontable.editors.CheckboxEditor(hot, 0, 0, 'prop', TD, cellProperties);
checkbox.getValue();
checkbox.setValue('foo');

const date = new Handsontable.editors.DateEditor(hot, 0, 0, 'prop', TD, cellProperties);
date.getDatePickerConfig();
date.showDatepicker();
date.hideDatepicker();

const dropdown = new Handsontable.editors.DropdownEditor(hot, 0, 0, 'prop', TD, cellProperties);
dropdown.flipDropdownIfNeeded();
dropdown.updateChoicesList([]);

const hansontable = new Handsontable.editors.HandsontableEditor(hot, 0, 0, 'prop', TD, cellProperties);
hansontable.beginEditing('');

const mobile = new Handsontable.editors.MobileEditor(hot, 0, 0, 'prop', TD, cellProperties);
mobile.hideCellPointer();
mobile.scrollToView();

const numeric = new Handsontable.editors.NumericEditor(hot, 0, 0, 'prop', TD, cellProperties);
numeric.checkEditorSection();
numeric.close();

const password = new Handsontable.editors.PasswordEditor(hot, 0, 0, 'prop', TD, cellProperties);
password.open();
password.isWaiting();

const select = new Handsontable.editors.SelectEditor(hot, 0, 0, 'prop', TD, cellProperties);
select.prepareOptions([]);

const text = new Handsontable.editors.TextEditor(hot, 0, 0, 'prop', TD, cellProperties);
text.focus();
text.finishEditing();

const time = new Handsontable.editors.TimeEditor(hot, 0, 0, 'prop', TD, cellProperties);
time.discardEditor();


// Verify top-level editors API
class CustomEditor extends Handsontable.editors.getEditor('text') {
open(){}
close(){}
getValue(){}
setValue(value: any){}
focus(){}
}
Handsontable.editors.registerEditor('custom', CustomEditor);
2 changes: 1 addition & 1 deletion test/types/editors/password.types.ts
Expand Up @@ -3,7 +3,7 @@ import Handsontable from 'handsontable';
class PasswordEditor extends Handsontable.editors.TextEditor {
createElements() {
// Call the original createElements method
super.createElements.apply(this, arguments);
super.createElements();

// Create password input and update relevant properties
this.TEXTAREA = document.createElement('input');
Expand Down
2 changes: 1 addition & 1 deletion test/types/editors/text.types.ts
Expand Up @@ -5,7 +5,7 @@ class TextEditor extends Handsontable.editors.TextEditor {
super.init();
}

prepare(row: number, col: number, prop: string | number, td: HTMLElement, originalValue: any, cellProperties: Handsontable.GridSettings) {
prepare(row: number, col: number, prop: string | number, td: HTMLTableCellElement, originalValue: any, cellProperties: Handsontable.CellProperties) {
super.prepare(row, col, prop, td, originalValue, cellProperties);
}

Expand Down
5 changes: 1 addition & 4 deletions test/types/helpers/helpers.types.ts
@@ -1,9 +1,6 @@
import Handsontable from 'handsontable';

const gridSettings: Handsontable.GridSettings = {
valid: true,
className: 'foo'
};
const gridSettings: Handsontable.GridSettings = { };

Handsontable.helper.arrayAvg([1, 3, 4]);
Handsontable.helper.arrayEach([1, 2, 3], (value, index, array) => {});
Expand Down
27 changes: 20 additions & 7 deletions test/types/index.types.ts
@@ -1,8 +1,21 @@
import Handsontable from '../../handsontable';
import Handsontable from 'handsontable';

const baseVersion = Handsontable.baseVersion;
const buildDate = Handsontable.buildDate;
const packageName = Handsontable.packageName;
const version = Handsontable.version;
const Core = Handsontable.Core;
const DefaultSettings = Handsontable.DefaultSettings;
const elem = document.createElement('div');

// Verify the various top-level namespace APIs exist
Handsontable.baseVersion.toUpperCase();
Handsontable.buildDate.toUpperCase();
Handsontable.packageName == 'handsontable';
Handsontable.version.split('');
Handsontable.cellTypes;
Handsontable.languages;
Handsontable.dom;
Handsontable.editors;
Handsontable.helper;
Handsontable.hooks;
Handsontable.plugins;
Handsontable.renderers;
Handsontable.validators;
new Handsontable.Core(elem, {});
const defaultSettings: Handsontable.GridSettings = new Handsontable.DefaultSettings();
new Handsontable.EventManager({});
138 changes: 74 additions & 64 deletions test/types/methods.types.ts
Expand Up @@ -3,78 +3,83 @@ import Handsontable from 'handsontable';
const elem = document.createElement('div');
const hot = new Handsontable(elem, {});

hot.addHook('foo', [() => {}]);
hot.addHook('foo', () => {});
hot.addHookOnce('foo', [() => {}]);
hot.addHookOnce('foo', () => {});
hot.addHook('afterChange', [(changes: any[] | null, source: string) => {}]);
hot.addHook('afterChange', (changes: any[] | null, source: string) => {});
hot.addHookOnce('afterChange', [(changes: Handsontable.CellChange[] | null, source: Handsontable.ChangeSource) => {}]);
hot.addHookOnce('afterChange', (changes: Handsontable.CellChange[] | null, source: Handsontable.ChangeSource) => {});
hot.alter('insert_row', 123, 123, 'foo', true);
hot.alter('insert_row', [[0, 0], [1, 2]], 123, 'foo', true);
hot.alter('insert_row');
hot.clear();
hot.colOffset();
hot.colToProp(123);
hot.countCols();
hot.countEmptyCols(true);
hot.countEmptyRows(true);
hot.countRenderedCols();
hot.countRenderedRows();
hot.countRows();
hot.countSourceRows();
hot.countVisibleCols();
hot.countVisibleRows();
hot.colOffset() === 123;
hot.colToProp(123) === 'foo';
hot.countCols() === 123;
hot.countEmptyCols(true) === 123;
hot.countEmptyRows(true) === 123;
hot.countRenderedCols() === 123;
hot.countRenderedRows() === 123;
hot.countRows() === 123;
hot.countSourceRows() === 123;
hot.countVisibleCols() === 123;
hot.countVisibleRows() === 123;
hot.deselectCell();
hot.destroy();
hot.destroyEditor(true);
hot.destroyEditor(true, true);
hot.emptySelectedCells();
hot.getActiveEditor();
hot.getCell(123, 123, true);
hot.getCell(123, 123, true)!.focus();
hot.getCellEditor(123, 123);
hot.getCellMeta(123, 123);
hot.getCellRenderer(123, 123);
hot.getCellMeta(123, 123).type === "text";
hot.getCellMetaAtRow(123).forEach(meta => meta.type === "text");
hot.getCellRenderer(123, 123)(hot, {} as any as HTMLTableCellElement, 1, 2, 'prop', '', {} as any as Handsontable.CellProperties);
hot.getCellValidator(123, 123);
hot.getColHeader(123);
hot.getColWidth(123);
hot.getCoords(elem.querySelector('td'));
hot.getCopyableData(123, 123);
hot.getCopyableText(123, 123, 123, 123);
hot.getData(123, 123, 123, 123);
hot.getDataAtCell(123, 123);
hot.getDataAtCol(123);
hot.getDataAtProp(123);
hot.getDataAtRow(123);
hot.getDataAtRowProp(123, 'foo');
hot.getDataType(123, 123, 123, 123);
hot.getInstance();
hot.getRowHeader(123);
hot.getRowHeight(123);
hot.getSchema();
hot.getSelected();
hot.getSelectedLast();
hot.getSelectedRange();
hot.getSelectedRangeLast();
hot.getSettings();
hot.getSourceData(123, 123, 123, 123);
hot.getSourceDataAtCell(123, 123);
hot.getSourceDataAtCol(123);
hot.getSourceDataAtRow(123);
hot.getTranslatedPhrase('foo', 123);
hot.getValue();
hot.hasColHeaders();
hot.hasHook('foo');
hot.hasRowHeaders();
hot.isColumnModificationAllowed();
hot.isEmptyCol(123);
hot.isEmptyRow(123);
hot.isListening();
hot.getColHeader().forEach((header: number | string) => {});
hot.getColHeader(123).toString();
hot.getColWidth(123) === 123;
hot.getCoords(elem.querySelector('td')).row === 0;
hot.getCopyableData(123, 123).toUpperCase();
hot.getCopyableText(123, 123, 123, 123).toUpperCase();
hot.getData(123, 123, 123, 123).forEach(v => v === '');
hot.getDataAtCell(123, 123) === '';
hot.getDataAtCol(123).forEach(v => v === '');
hot.getDataAtProp(123).forEach(v => v === '');
hot.getDataAtRow(123).forEach(v => v === '');
hot.getDataAtRowProp(123, 'foo') === '';
hot.getDataType(123, 123, 123, 123) === 'text';
hot.getInstance() === hot;
hot.getRowHeader().forEach(header => header.toString());
hot.getRowHeader(123) === '';
hot.getRowHeight(123) === 123;
hot.getSchema()['foo'];
hot.getSelected()![0][0] === 123;
hot.getSelectedLast()![0] === 123;
hot.getSelectedRange()![0].from.row === 123;
hot.getSelectedRangeLast()!.to.col === 123;
hot.getSettings().type === 'text';
hot.getSourceData(123, 123, 123, 123)[0];
hot.getSourceDataAtCell(123, 123) === '';
hot.getSourceDataAtCol(123)[0] === '';
hot.getSourceDataAtRow(123) as any[];
hot.getTranslatedPhrase('foo', 123)!.toLowerCase();
hot.getValue() === '';
hot.hasColHeaders() === true;
hot.hasHook('afterChange') === true;
hot.hasRowHeaders() === true;
hot.isColumnModificationAllowed() === true;
hot.isEmptyCol(123) === true;
hot.isEmptyRow(123) === true;
hot.isListening() === true;
hot.listen();
hot.loadData([]);
hot.populateFromArray(123, 123, [], 123, 123, 'foo', 'foo', 'foo', []);
hot.propToCol('foo');
hot.propToCol(123);
hot.loadData([[1,2,3], [1,2,3]]);
hot.loadData([{a:'a',b:2,c:''}, {a:'a',b:2,c:''}]);
hot.populateFromArray(123, 123, [], 123, 123, 'foo', 'shift_down', 'left', []);
hot.propToCol('foo') === 123;
hot.propToCol(123) === 123;
hot.removeCellMeta(123, 123, 'foo');
hot.removeHook('foo', function() {});
hot.removeHook('afterChange', function() {});
hot.render();
hot.rowOffset();
hot.runHooks('foo', 123, 'foo', true, {}, [], function() {});
hot.rowOffset() === 123;
hot.runHooks('afterChange', 123, 'foo', true, {}, [], function() {});
hot.selectAll();
hot.selectCell(123, 123, 123, 123, true, true);
hot.selectCellByProp(123, 'foo', 123, 'foo', true);
Expand All @@ -93,11 +98,16 @@ hot.setDataAtRowProp(123, 'foo', 'foo', 'foo');
hot.setDataAtRowProp([[123, 'foo', 'foo'], [123, 'foo', 'foo']], 'foo');
hot.spliceCol(123, 123, 123, 'foo');
hot.spliceRow(123, 123, 123, 'foo');
hot.toPhysicalColumn(123) == 123;
hot.toPhysicalRow(123) === 123;
hot.toVisualColumn(123) === 123;
hot.toVisualRow(123) === 123;
hot.unlisten();
hot.updateSettings({}, true);
hot.validateCells(function() {});
hot.validateColumns([1, 2, 3], function() {});
hot.validateRows([1, 2, 3], function() {});
hot.updateSettings({} as Handsontable.GridSettings, true);
hot.validateCells((valid: boolean) => {});
hot.validateColumns([1, 2, 3], (valid: boolean) => {});
hot.validateRows([1, 2, 3], (valid: boolean) => {});
hot.isDestroyed === false;

const autoColumnSize: Handsontable.plugins.AutoColumnSize = hot.getPlugin('autoColumnSize');
const autoRowSize: Handsontable.plugins.AutoRowSize = hot.getPlugin('autoRowSize');
Expand Down