c1e9655fbd8c772d4629648f60863006fa5a41bd7f01ca2578957ad83b858542a35673d686da9c75e446970ea3d21d3f0214088fb21e0c0de3bc113735e477 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  4. var _element = require('./../../../helpers/dom/element');
  5. var _object = require('./../../../helpers/object');
  6. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7. /**
  8. * @class Settings
  9. */
  10. var Settings = function () {
  11. /**
  12. * @param {Walkontable} wotInstance
  13. * @param {Object} settings
  14. */
  15. function Settings(wotInstance, settings) {
  16. var _this = this;
  17. _classCallCheck(this, Settings);
  18. this.wot = wotInstance;
  19. // legacy support
  20. this.instance = wotInstance;
  21. // default settings. void 0 means it is required, null means it can be empty
  22. this.defaults = {
  23. table: void 0,
  24. debug: false, // shows WalkontableDebugOverlay
  25. // presentation mode
  26. externalRowCalculator: false,
  27. stretchH: 'none', // values: all, last, none
  28. currentRowClassName: null,
  29. currentColumnClassName: null,
  30. preventOverflow: function preventOverflow() {
  31. return false;
  32. },
  33. // data source
  34. data: void 0,
  35. freezeOverlays: false,
  36. fixedColumnsLeft: 0,
  37. fixedRowsTop: 0,
  38. fixedRowsBottom: 0,
  39. minSpareRows: 0,
  40. // this must be array of functions: [function (row, TH) {}]
  41. rowHeaders: function rowHeaders() {
  42. return [];
  43. },
  44. // this must be array of functions: [function (column, TH) {}]
  45. columnHeaders: function columnHeaders() {
  46. return [];
  47. },
  48. totalRows: void 0,
  49. totalColumns: void 0,
  50. cellRenderer: function cellRenderer(row, column, TD) {
  51. var cellData = _this.getSetting('data', row, column);
  52. (0, _element.fastInnerText)(TD, cellData === void 0 || cellData === null ? '' : cellData);
  53. },
  54. // columnWidth: 50,
  55. columnWidth: function columnWidth(col) {
  56. // return undefined means use default size for the rendered cell content
  57. },
  58. rowHeight: function rowHeight(row) {
  59. // return undefined means use default size for the rendered cell content
  60. },
  61. defaultRowHeight: 23,
  62. defaultColumnWidth: 50,
  63. selections: null,
  64. hideBorderOnMouseDownOver: false,
  65. viewportRowCalculatorOverride: null,
  66. viewportColumnCalculatorOverride: null,
  67. // callbacks
  68. onCellMouseDown: null,
  69. onCellMouseOver: null,
  70. onCellMouseOut: null,
  71. onCellMouseUp: null,
  72. // onCellMouseOut: null,
  73. onCellDblClick: null,
  74. onCellCornerMouseDown: null,
  75. onCellCornerDblClick: null,
  76. beforeDraw: null,
  77. onDraw: null,
  78. onBeforeDrawBorders: null,
  79. onScrollVertically: null,
  80. onScrollHorizontally: null,
  81. onBeforeTouchScroll: null,
  82. onAfterMomentumScroll: null,
  83. onBeforeStretchingColumnWidth: function onBeforeStretchingColumnWidth(width) {
  84. return width;
  85. },
  86. onModifyRowHeaderWidth: null,
  87. // constants
  88. scrollbarWidth: 10,
  89. scrollbarHeight: 10,
  90. renderAllRows: false,
  91. groups: false,
  92. rowHeaderWidth: null,
  93. columnHeaderHeight: null,
  94. headerClassName: null
  95. };
  96. // reference to settings
  97. this.settings = {};
  98. for (var i in this.defaults) {
  99. if ((0, _object.hasOwnProperty)(this.defaults, i)) {
  100. if (settings[i] !== void 0) {
  101. this.settings[i] = settings[i];
  102. } else if (this.defaults[i] === void 0) {
  103. throw new Error('A required setting "' + i + '" was not provided');
  104. } else {
  105. this.settings[i] = this.defaults[i];
  106. }
  107. }
  108. }
  109. }
  110. /**
  111. * Update settings
  112. *
  113. * @param {Object} settings
  114. * @param {*} value
  115. * @returns {Walkontable}
  116. */
  117. _createClass(Settings, [{
  118. key: 'update',
  119. value: function update(settings, value) {
  120. if (value === void 0) {
  121. // settings is object
  122. for (var i in settings) {
  123. if ((0, _object.hasOwnProperty)(settings, i)) {
  124. this.settings[i] = settings[i];
  125. }
  126. }
  127. } else {
  128. // if value is defined then settings is the key
  129. this.settings[settings] = value;
  130. }
  131. return this.wot;
  132. }
  133. /**
  134. * Get setting by name
  135. *
  136. * @param {String} key
  137. * @param {*} param1
  138. * @param {*} param2
  139. * @param {*} param3
  140. * @param {*} param4
  141. * @returns {*}
  142. */
  143. }, {
  144. key: 'getSetting',
  145. value: function getSetting(key, param1, param2, param3, param4) {
  146. if (typeof this.settings[key] === 'function') {
  147. // this is faster than .apply - https://github.com/handsontable/handsontable/wiki/JavaScript-&-DOM-performance-tips
  148. return this.settings[key](param1, param2, param3, param4);
  149. } else if (param1 !== void 0 && Array.isArray(this.settings[key])) {
  150. // perhaps this can be removed, it is only used in tests
  151. return this.settings[key][param1];
  152. }
  153. return this.settings[key];
  154. }
  155. /**
  156. * Checks if setting exists
  157. *
  158. * @param {Boolean} key
  159. * @returns {Boolean}
  160. */
  161. }, {
  162. key: 'has',
  163. value: function has(key) {
  164. return !!this.settings[key];
  165. }
  166. }]);
  167. return Settings;
  168. }();
  169. exports.default = Settings;