43ab179470958de7c9a2c926527d576e4cdcf49ba428606df204229fcdc11c1ce8ca328b11497b5f22c7c370d1ddc11dfda3b52e984018eead78430c4fb345 2.2 KB

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