index.js 6.0 KB

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