11b21b5db35edfea2554d2071306a34b2063c83004c9c7d95b991cbb6dc7d6d51fe2dfb968086aedb3ff31f061c3392f06205a695f5870d670ab24cc5cc2a5 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import 'babel-polyfill';
  2. import './css/bootstrap.css';
  3. import './css/handsontable.css';
  4. import './css/mobile.handsontable.css';
  5. import {getRegisteredEditorNames, registerEditor, getEditor} from './editors';
  6. import {getRegisteredRendererNames, getRenderer, registerRenderer} from './renderers';
  7. import {getRegisteredValidatorNames, getValidator, registerValidator} from './validators';
  8. import {getRegisteredCellTypeNames, getCellType, registerCellType} from './cellTypes';
  9. import Core from './core';
  10. import jQueryWrapper from './helpers/wrappers/jquery';
  11. import EventManager, {getListenersCounter} from './eventManager';
  12. import Hooks from './pluginHooks';
  13. import GhostTable from './utils/ghostTable';
  14. import * as arrayHelpers from './helpers/array';
  15. import * as browserHelpers from './helpers/browser';
  16. import * as dataHelpers from './helpers/data';
  17. import * as dateHelpers from './helpers/date';
  18. import * as featureHelpers from './helpers/feature';
  19. import * as functionHelpers from './helpers/function';
  20. import * as mixedHelpers from './helpers/mixed';
  21. import * as numberHelpers from './helpers/number';
  22. import * as objectHelpers from './helpers/object';
  23. import * as settingHelpers from './helpers/setting';
  24. import * as stringHelpers from './helpers/string';
  25. import * as unicodeHelpers from './helpers/unicode';
  26. import * as domHelpers from './helpers/dom/element';
  27. import * as domEventHelpers from './helpers/dom/event';
  28. import * as plugins from './plugins/index';
  29. import {registerPlugin} from './plugins';
  30. import DefaultSettings from './defaultSettings';
  31. function Handsontable(rootElement, userSettings) {
  32. const instance = new Core(rootElement, userSettings || {});
  33. instance.init();
  34. return instance;
  35. }
  36. jQueryWrapper(Handsontable);
  37. Handsontable.Core = Core;
  38. Handsontable.DefaultSettings = DefaultSettings;
  39. Handsontable.EventManager = EventManager;
  40. Handsontable._getListenersCounter = getListenersCounter; // For MemoryLeak tests
  41. Handsontable.buildDate = __HOT_BUILD_DATE__;
  42. Handsontable.packageName = __HOT_PACKAGE_NAME__;
  43. Handsontable.version = __HOT_VERSION__;
  44. const baseVersion = __HOT_BASE_VERSION__;
  45. if (baseVersion) {
  46. Handsontable.baseVersion = baseVersion;
  47. }
  48. // Export Hooks singleton
  49. Handsontable.hooks = Hooks.getSingleton();
  50. // TODO: Remove this exports after rewrite tests about this module
  51. Handsontable.__GhostTable = GhostTable;
  52. //
  53. // Export all helpers to the Handsontable object
  54. const HELPERS = [
  55. arrayHelpers,
  56. browserHelpers,
  57. dataHelpers,
  58. dateHelpers,
  59. featureHelpers,
  60. functionHelpers,
  61. mixedHelpers,
  62. numberHelpers,
  63. objectHelpers,
  64. settingHelpers,
  65. stringHelpers,
  66. unicodeHelpers,
  67. ];
  68. const DOM = [
  69. domHelpers,
  70. domEventHelpers,
  71. ];
  72. Handsontable.helper = {};
  73. Handsontable.dom = {};
  74. // Fill general helpers.
  75. arrayHelpers.arrayEach(HELPERS, (helper) => {
  76. arrayHelpers.arrayEach(Object.getOwnPropertyNames(helper), (key) => {
  77. if (key.charAt(0) !== '_') {
  78. Handsontable.helper[key] = helper[key];
  79. }
  80. });
  81. });
  82. // Fill DOM helpers.
  83. arrayHelpers.arrayEach(DOM, (helper) => {
  84. arrayHelpers.arrayEach(Object.getOwnPropertyNames(helper), (key) => {
  85. if (key.charAt(0) !== '_') {
  86. Handsontable.dom[key] = helper[key];
  87. }
  88. });
  89. });
  90. // Export cell types.
  91. Handsontable.cellTypes = {};
  92. arrayHelpers.arrayEach(getRegisteredCellTypeNames(), (cellTypeName) => {
  93. Handsontable.cellTypes[cellTypeName] = getCellType(cellTypeName);
  94. });
  95. Handsontable.cellTypes.registerCellType = registerCellType;
  96. Handsontable.cellTypes.getCellType = getCellType;
  97. // Export all registered editors from the Handsontable.
  98. Handsontable.editors = {};
  99. arrayHelpers.arrayEach(getRegisteredEditorNames(), (editorName) => {
  100. Handsontable.editors[`${stringHelpers.toUpperCaseFirst(editorName)}Editor`] = getEditor(editorName);
  101. });
  102. Handsontable.editors.registerEditor = registerEditor;
  103. Handsontable.editors.getEditor = getEditor;
  104. // Export all registered renderers from the Handsontable.
  105. Handsontable.renderers = {};
  106. arrayHelpers.arrayEach(getRegisteredRendererNames(), (rendererName) => {
  107. const renderer = getRenderer(rendererName);
  108. if (rendererName === 'base') {
  109. Handsontable.renderers.cellDecorator = renderer;
  110. }
  111. Handsontable.renderers[`${stringHelpers.toUpperCaseFirst(rendererName)}Renderer`] = renderer;
  112. });
  113. Handsontable.renderers.registerRenderer = registerRenderer;
  114. Handsontable.renderers.getRenderer = getRenderer;
  115. // Export all registered validators from the Handsontable.
  116. Handsontable.validators = {};
  117. arrayHelpers.arrayEach(getRegisteredValidatorNames(), (validatorName) => {
  118. Handsontable.validators[`${stringHelpers.toUpperCaseFirst(validatorName)}Validator`] = getValidator(validatorName);
  119. });
  120. Handsontable.validators.registerValidator = registerValidator;
  121. Handsontable.validators.getValidator = getValidator;
  122. // Export all registered plugins from the Handsontable.
  123. Handsontable.plugins = {};
  124. arrayHelpers.arrayEach(Object.getOwnPropertyNames(plugins), (pluginName) => {
  125. const plugin = plugins[pluginName];
  126. if (pluginName === 'Base') {
  127. Handsontable.plugins[`${pluginName}Plugin`] = plugin;
  128. } else {
  129. Handsontable.plugins[pluginName] = plugin;
  130. }
  131. });
  132. Handsontable.plugins.registerPlugin = registerPlugin;
  133. // Export Handsontable
  134. module.exports = Handsontable;