7297b18df1b2e31a8a9632dc6f292b7eaea3b518d94fc650e8b13e811b2687d8cc216c944c8e3e841c3a678d583743f24c2bf38de461a532127f21863096a0 5.6 KB

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