Skip to content

Commit c646025

Browse files
committed
Merge branch 'feature/issue-4254' into develop
2 parents 45d79b9 + 00e541a commit c646025

55 files changed

Lines changed: 1218 additions & 430 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/cellTypes.js

Lines changed: 0 additions & 109 deletions
This file was deleted.

src/cellTypes/autocompleteType.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {getEditor} from './../editors';
2+
import {getRenderer} from './../renderers';
3+
import {getValidator} from './../validators';
4+
5+
const CELL_TYPE = 'autocomplete';
6+
7+
export default {
8+
editor: getEditor(CELL_TYPE),
9+
renderer: getRenderer(CELL_TYPE),
10+
validator: getValidator(CELL_TYPE),
11+
};

src/cellTypes/checkboxType.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {getEditor} from './../editors';
2+
import {getRenderer} from './../renderers';
3+
4+
const CELL_TYPE = 'checkbox';
5+
6+
export default {
7+
editor: getEditor(CELL_TYPE),
8+
renderer: getRenderer(CELL_TYPE),
9+
};

src/cellTypes/dateType.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {getEditor} from './../editors';
2+
import {getRenderer} from './../renderers';
3+
import {getValidator} from './../validators';
4+
5+
const CELL_TYPE = 'date';
6+
7+
export default {
8+
editor: getEditor(CELL_TYPE),
9+
// displays small gray arrow on right side of the cell
10+
renderer: getRenderer('autocomplete'),
11+
validator: getValidator(CELL_TYPE),
12+
};

src/cellTypes/dropdownType.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {getEditor} from './../editors';
2+
import {getRenderer} from './../renderers';
3+
import {getValidator} from './../validators';
4+
5+
const CELL_TYPE = 'dropdown';
6+
7+
export default {
8+
editor: getEditor(CELL_TYPE),
9+
// displays small gray arrow on right side of the cell
10+
renderer: getRenderer('autocomplete'),
11+
validator: getValidator('autocomplete'),
12+
};

src/cellTypes/handsontableType.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {getEditor} from './../editors';
2+
import {getRenderer} from './../renderers';
3+
4+
const CELL_TYPE = 'handsontable';
5+
6+
export default {
7+
editor: getEditor(CELL_TYPE),
8+
// displays small gray arrow on right side of the cell
9+
renderer: getRenderer('autocomplete'),
10+
};

src/cellTypes/index.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import staticRegister from './../utils/staticRegister';
2+
import {hasEditor, registerEditor} from './../editors';
3+
import {hasRenderer, registerRenderer} from './../renderers';
4+
import {hasValidator, registerValidator} from './../validators';
5+
6+
import autocompleteCellType from './autocompleteType';
7+
import checkboxCellType from './checkboxType';
8+
import dateCellType from './dateType';
9+
import dropdownCellType from './dropdownType';
10+
import handsontableCellType from './handsontableType';
11+
import numericCellType from './numericType';
12+
import passwordCellType from './passwordType';
13+
import textCellType from './textType';
14+
import timeCellType from './timeType';
15+
16+
const {
17+
register,
18+
getItem,
19+
hasItem,
20+
getNames,
21+
getValues,
22+
} = staticRegister('cellTypes');
23+
24+
_register('autocomplete', autocompleteCellType);
25+
_register('checkbox', checkboxCellType);
26+
_register('date', dateCellType);
27+
_register('dropdown', dropdownCellType);
28+
_register('handsontable', handsontableCellType);
29+
_register('numeric', numericCellType);
30+
_register('password', passwordCellType);
31+
_register('text', textCellType);
32+
_register('time', timeCellType);
33+
34+
/**
35+
* Retrieve cell type object.
36+
*
37+
* @param {String} name Cell type identification.
38+
* @returns {Object} Returns cell type object.
39+
*/
40+
function _getItem(name) {
41+
if (!hasItem(name)) {
42+
throw Error(`You declared cell type "${name}" as a string that is not mapped to a known object.
43+
Cell type must be an object or a string mapped to an object registered by "Handsontable.cellTypes.registerCellType" method`);
44+
}
45+
46+
return getItem(name);
47+
}
48+
49+
/**
50+
* Register cell type under specified name.
51+
*
52+
* @param {String} name Cell type identification.
53+
* @param {Object} type An object with contains keys (eq: `editor`, `renderer`, `validator`) which describes specified behaviour of the cell.
54+
*/
55+
function _register(name, type) {
56+
const {editor, renderer, validator} = type;
57+
58+
if (editor) {
59+
registerEditor(name, editor);
60+
}
61+
if (renderer) {
62+
registerRenderer(name, renderer);
63+
}
64+
if (validator) {
65+
registerValidator(name, validator);
66+
}
67+
68+
register(name, type);
69+
}
70+
71+
export {
72+
_register as registerCellType,
73+
_getItem as getCellType,
74+
hasItem as hasCellType,
75+
getNames as getRegisteredCellTypeNames,
76+
getValues as getRegisteredCellTypes,
77+
};

src/cellTypes/numericType.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {getEditor} from './../editors';
2+
import {getRenderer} from './../renderers';
3+
import {getValidator} from './../validators';
4+
5+
const CELL_TYPE = 'numeric';
6+
7+
export default {
8+
editor: getEditor(CELL_TYPE),
9+
renderer: getRenderer(CELL_TYPE),
10+
validator: getValidator(CELL_TYPE),
11+
dataType: 'number',
12+
};

src/cellTypes/passwordType.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {getEditor} from './../editors';
2+
import {getRenderer} from './../renderers';
3+
import {getValidator} from './../validators';
4+
5+
const CELL_TYPE = 'password';
6+
7+
export default {
8+
editor: getEditor(CELL_TYPE),
9+
renderer: getRenderer(CELL_TYPE),
10+
copyable: false,
11+
};

src/cellTypes/textType.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {isMobileBrowser} from './../helpers/browser';
2+
import {getEditor} from './../editors';
3+
import {getRenderer} from './../renderers';
4+
5+
const CELL_TYPE = 'text';
6+
7+
export default {
8+
editor: isMobileBrowser() ? getEditor('mobile') : getEditor(CELL_TYPE),
9+
renderer: getRenderer(CELL_TYPE),
10+
};

0 commit comments

Comments
 (0)