index.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import '@babel/polyfill/lib/noConflict';
  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. import { rootInstanceSymbol } from './utils/rootInstance';
  32. import { getTranslatedPhrase } from './i18n';
  33. import * as constants from './i18n/constants';
  34. import { registerLanguageDictionary, getLanguagesDictionaries, getLanguageDictionary } from './i18n/dictionariesManager';
  35. function Handsontable(rootElement, userSettings) {
  36. const instance = new Core(rootElement, userSettings || {}, rootInstanceSymbol);
  37. instance.init();
  38. return instance;
  39. }
  40. jQueryWrapper(Handsontable);
  41. Handsontable.Core = Core;
  42. Handsontable.DefaultSettings = DefaultSettings;
  43. Handsontable.EventManager = EventManager;
  44. Handsontable._getListenersCounter = getListenersCounter; // For MemoryLeak tests
  45. Handsontable.buildDate = process.env.HOT_BUILD_DATE;
  46. Handsontable.packageName = process.env.HOT_PACKAGE_NAME;
  47. Handsontable.version = process.env.HOT_VERSION;
  48. const baseVersion = process.env.HOT_BASE_VERSION;
  49. if (baseVersion) {
  50. Handsontable.baseVersion = baseVersion;
  51. }
  52. // Export Hooks singleton
  53. Handsontable.hooks = Hooks.getSingleton();
  54. // TODO: Remove this exports after rewrite tests about this module
  55. Handsontable.__GhostTable = GhostTable;
  56. //
  57. // Export all helpers to the Handsontable object
  58. const HELPERS = [
  59. arrayHelpers,
  60. browserHelpers,
  61. dataHelpers,
  62. dateHelpers,
  63. featureHelpers,
  64. functionHelpers,
  65. mixedHelpers,
  66. numberHelpers,
  67. objectHelpers,
  68. settingHelpers,
  69. stringHelpers,
  70. unicodeHelpers,
  71. ];
  72. const DOM = [
  73. domHelpers,
  74. domEventHelpers,
  75. ];
  76. Handsontable.helper = {};
  77. Handsontable.dom = {};
  78. // Fill general helpers.
  79. arrayHelpers.arrayEach(HELPERS, (helper) => {
  80. arrayHelpers.arrayEach(Object.getOwnPropertyNames(helper), (key) => {
  81. if (key.charAt(0) !== '_') {
  82. Handsontable.helper[key] = helper[key];
  83. }
  84. });
  85. });
  86. // Fill DOM helpers.
  87. arrayHelpers.arrayEach(DOM, (helper) => {
  88. arrayHelpers.arrayEach(Object.getOwnPropertyNames(helper), (key) => {
  89. if (key.charAt(0) !== '_') {
  90. Handsontable.dom[key] = helper[key];
  91. }
  92. });
  93. });
  94. // Export cell types.
  95. Handsontable.cellTypes = {};
  96. arrayHelpers.arrayEach(getRegisteredCellTypeNames(), (cellTypeName) => {
  97. Handsontable.cellTypes[cellTypeName] = getCellType(cellTypeName);
  98. });
  99. Handsontable.cellTypes.registerCellType = registerCellType;
  100. Handsontable.cellTypes.getCellType = getCellType;
  101. // Export all registered editors from the Handsontable.
  102. Handsontable.editors = {};
  103. arrayHelpers.arrayEach(getRegisteredEditorNames(), (editorName) => {
  104. Handsontable.editors[`${stringHelpers.toUpperCaseFirst(editorName)}Editor`] = getEditor(editorName);
  105. });
  106. Handsontable.editors.registerEditor = registerEditor;
  107. Handsontable.editors.getEditor = getEditor;
  108. // Export all registered renderers from the Handsontable.
  109. Handsontable.renderers = {};
  110. arrayHelpers.arrayEach(getRegisteredRendererNames(), (rendererName) => {
  111. const renderer = getRenderer(rendererName);
  112. if (rendererName === 'base') {
  113. Handsontable.renderers.cellDecorator = renderer;
  114. }
  115. Handsontable.renderers[`${stringHelpers.toUpperCaseFirst(rendererName)}Renderer`] = renderer;
  116. });
  117. Handsontable.renderers.registerRenderer = registerRenderer;
  118. Handsontable.renderers.getRenderer = getRenderer;
  119. // Export all registered validators from the Handsontable.
  120. Handsontable.validators = {};
  121. arrayHelpers.arrayEach(getRegisteredValidatorNames(), (validatorName) => {
  122. Handsontable.validators[`${stringHelpers.toUpperCaseFirst(validatorName)}Validator`] = getValidator(validatorName);
  123. });
  124. Handsontable.validators.registerValidator = registerValidator;
  125. Handsontable.validators.getValidator = getValidator;
  126. // Export all registered plugins from the Handsontable.
  127. Handsontable.plugins = {};
  128. arrayHelpers.arrayEach(Object.getOwnPropertyNames(plugins), (pluginName) => {
  129. const plugin = plugins[pluginName];
  130. if (pluginName === 'Base') {
  131. Handsontable.plugins[`${pluginName}Plugin`] = plugin;
  132. } else {
  133. Handsontable.plugins[pluginName] = plugin;
  134. }
  135. });
  136. Handsontable.plugins.registerPlugin = registerPlugin;
  137. Handsontable.languages = {};
  138. Handsontable.languages.dictionaryKeys = constants;
  139. Handsontable.languages.getLanguageDictionary = getLanguageDictionary;
  140. Handsontable.languages.getLanguagesDictionaries = getLanguagesDictionaries;
  141. Handsontable.languages.registerLanguageDictionary = registerLanguageDictionary;
  142. // Alias to `getTranslatedPhrase` function, for more information check it API.
  143. Handsontable.languages.getTranslatedPhrase = (...args) => getTranslatedPhrase(...args);
  144. export default Handsontable;