464ec34e6720bd6402689b8c2db22927a6b9295f535656f311304bc4d9ac0e74eb6567aa79bc79413c3e8254acbae27e31dbc39e46b070bff29685298a6c8b 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. var _staticRegister = staticRegister('cellTypes'),
  15. register = _staticRegister.register,
  16. getItem = _staticRegister.getItem,
  17. hasItem = _staticRegister.hasItem,
  18. getNames = _staticRegister.getNames,
  19. getValues = _staticRegister.getValues;
  20. _register('autocomplete', autocompleteCellType);
  21. _register('checkbox', checkboxCellType);
  22. _register('date', dateCellType);
  23. _register('dropdown', dropdownCellType);
  24. _register('handsontable', handsontableCellType);
  25. _register('numeric', numericCellType);
  26. _register('password', passwordCellType);
  27. _register('text', textCellType);
  28. _register('time', timeCellType);
  29. /**
  30. * Retrieve cell type object.
  31. *
  32. * @param {String} name Cell type identification.
  33. * @returns {Object} Returns cell type object.
  34. */
  35. function _getItem(name) {
  36. if (!hasItem(name)) {
  37. throw Error('You declared cell type "' + name + '" as a string that is not mapped to a known object.\n Cell type must be an object or a string mapped to an object registered by "Handsontable.cellTypes.registerCellType" method');
  38. }
  39. return getItem(name);
  40. }
  41. /**
  42. * Register cell type under specified name.
  43. *
  44. * @param {String} name Cell type identification.
  45. * @param {Object} type An object with contains keys (eq: `editor`, `renderer`, `validator`) which describes specified behaviour of the cell.
  46. */
  47. function _register(name, type) {
  48. var editor = type.editor,
  49. renderer = type.renderer,
  50. validator = type.validator;
  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 { _register as registerCellType, _getItem as getCellType, hasItem as hasCellType, getNames as getRegisteredCellTypeNames, getValues as getRegisteredCellTypes };