| @@ -1,14 +1,17 @@ | ||
| 1 | 1 | /** |
| 2 | - * Jspreadsheet v4.13.3 | |
| 2 | + * Jspreadsheet v4.15.0 | |
| 3 | 3 | * |
| 4 | 4 | * Website: https://bossanova.uk/jspreadsheet/ |
| 5 | 5 | * Description: Create amazing web based spreadsheets. |
| 6 | 6 | * |
| 7 | - * This software is distribute under MIT License | |
| 7 | + * This software is distributed under MIT License | |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -// TablePress: var formula = ... removed. | |
| 10 | +/* TablePress: | |
| 11 | + * - var formula = ... removed. | |
| 12 | + * - obj.updateTablePressToolbarUndoRedoState(); added | |
| 13 | + */ | |
| 11 | 14 | |
| 12 | 15 | ;(function (global, factory) { |
| 13 | 16 | // TablePress: Comment out next to lines to force creation of a global jspreadsheet object. |
| 14 | 17 | // typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
| @@ -22,9 +25,9 @@ | ||
| 22 | 25 | var Version = function() { |
| 23 | 26 | // Information |
| 24 | 27 | var info = { |
| 25 | 28 | title: 'Jspreadsheet', |
| 26 | - version: '4.13.3', | |
| 29 | + version: '4.15.0', | |
| 27 | 30 | type: 'CE', |
| 28 | 31 | host: 'https://bossanova.uk/jspreadsheet', |
| 29 | 32 | license: 'MIT', |
| 30 | 33 | print: function() { |
| @@ -689,19 +692,9 @@ | ||
| 689 | 692 | var ads = document.createElement('a'); |
| 690 | 693 | ads.setAttribute('href', 'https://bossanova.uk/jspreadsheet/'); |
| 691 | 694 | obj.ads = document.createElement('div'); |
| 692 | 695 | obj.ads.className = 'jexcel_about'; |
| 693 | - /* // TablePress: Remove this as it loads a file from the Jspreadsheet server. | |
| 694 | - try { | |
| 695 | - if (typeof(sessionStorage) !== "undefined" && ! sessionStorage.getItem('jexcel')) { | |
| 696 | - sessionStorage.setItem('jexcel', true); | |
| 697 | - var img = document.createElement('img'); | |
| 698 | - img.src = '//bossanova.uk/jspreadsheet/logo.png'; | |
| 699 | - ads.appendChild(img); | |
| 700 | - } | |
| 701 | - } catch (exception) { | |
| 702 | - } | |
| 703 | - */ | |
| 696 | + | |
| 704 | 697 | var span = document.createElement('span'); |
| 705 | 698 | span.innerHTML = 'Jspreadsheet CE'; |
| 706 | 699 | ads.appendChild(span); |
| 707 | 700 | obj.ads.appendChild(ads); |
| @@ -3100,9 +3093,9 @@ | ||
| 3100 | 3093 | if (! borderRight) { |
| 3101 | 3094 | borderRight = 0; |
| 3102 | 3095 | } |
| 3103 | 3096 | for (var i = borderLeft; i <= borderRight; i++) { |
| 3104 | - if (obj.options.columns[i].type != 'hidden') { | |
| 3097 | + if (obj.options.columns[i].type != 'hidden' && obj.colgroup[i].style && obj.colgroup[i].style.display != 'none') { | |
| 3105 | 3098 | // Top border |
| 3106 | 3099 | if (obj.records[borderTop] && obj.records[borderTop][i]) { |
| 3107 | 3100 | obj.records[borderTop][i].classList.add('highlight-top'); |
| 3108 | 3101 | } |
| @@ -3954,17 +3947,20 @@ | ||
| 3954 | 3947 | newValue[j] = temp[j][0]; |
| 3955 | 3948 | } |
| 3956 | 3949 | |
| 3957 | 3950 | // TablePress: Keep Table Head and Table Foot row at the top/bottom, if used. |
| 3958 | - if ( window?.tp?.table?.options?.table_head ) { | |
| 3959 | - const first_row_idx = 0; | |
| 3960 | - newValue = newValue.filter( ( row_idx ) => ( row_idx > first_row_idx ) ); | |
| 3961 | - newValue.unshift( first_row_idx ); | |
| 3951 | + if ( window?.tp?.table?.options?.table_head > 0 ) { | |
| 3952 | + const last_head_row_idx = window?.tp?.table?.options?.table_head - 1; | |
| 3953 | + newValue = newValue.filter( ( row_idx ) => ( row_idx > last_head_row_idx ) ); | |
| 3954 | + newValue.unshift( ...Array( window?.tp?.table?.options?.table_head ).keys() ); | |
| 3962 | 3955 | } |
| 3963 | - if ( window?.tp?.table?.options?.table_foot ) { | |
| 3956 | + if ( window?.tp?.table?.options?.table_foot > 0) { | |
| 3964 | 3957 | const last_row_idx = newValue.length - 1; |
| 3965 | - newValue = newValue.filter( ( row_idx ) => ( row_idx < last_row_idx ) ); | |
| 3966 | - newValue.push( last_row_idx ); | |
| 3958 | + const first_foot_row_idx = newValue.length - window?.tp?.table?.options?.table_foot; | |
| 3959 | + newValue = newValue.filter( ( row_idx ) => ( row_idx < first_foot_row_idx ) ); | |
| 3960 | + for ( let idx = first_foot_row_idx; idx <= last_row_idx; idx++ ) { | |
| 3961 | + newValue.push( idx ); | |
| 3962 | + } | |
| 3967 | 3963 | } |
| 3968 | 3964 | |
| 3969 | 3965 | // Save history |
| 3970 | 3966 | obj.setHistory({ |
| @@ -5354,9 +5350,9 @@ | ||
| 5354 | 5350 | obj.formula[tokens[i]].push(parentId); |
| 5355 | 5351 | } |
| 5356 | 5352 | |
| 5357 | 5353 | // Do not calculate again |
| 5358 | - if (eval('typeof(' + tokens[i] + ') == "undefined"')) { | |
| 5354 | + if (typeof globalThis[tokens[i]] === 'undefined') { | |
| 5359 | 5355 | // Coords |
| 5360 | 5356 | var position = jexcel.getIdFromColumnName(tokens[i], 1); |
| 5361 | 5357 | // Get value |
| 5362 | 5358 | if (typeof(obj.options.data[position[1]]) != 'undefined' && typeof(obj.options.data[position[1]][position[0]]) != 'undefined') { |
| @@ -6271,8 +6267,36 @@ | ||
| 6271 | 6267 | } |
| 6272 | 6268 | } |
| 6273 | 6269 | |
| 6274 | 6270 | /** |
| 6271 | + * TablePress: Initialize the toolbar state for undo/redo buttons. | |
| 6272 | + */ | |
| 6273 | + obj.tablePressToolbarUndoRedoState = { | |
| 6274 | + undoDisabled: true, | |
| 6275 | + redoDisabled: true, | |
| 6276 | + }; | |
| 6277 | + | |
| 6278 | + /** | |
| 6279 | + * TablePress: Updates the toolbar state for undo/redo buttons, if the state has changed. | |
| 6280 | + * | |
| 6281 | + * @return null | |
| 6282 | + */ | |
| 6283 | + obj.updateTablePressToolbarUndoRedoState = function() { | |
| 6284 | + const newToolbarUndoRedoState = { | |
| 6285 | + undoDisabled: ( -1 === obj.historyIndex ), | |
| 6286 | + redoDisabled: ( obj.historyIndex === obj.history.length - 1 ), | |
| 6287 | + }; | |
| 6288 | + | |
| 6289 | + if ( | |
| 6290 | + newToolbarUndoRedoState.undoDisabled !== obj.tablePressToolbarUndoRedoState.undoDisabled | |
| 6291 | + || newToolbarUndoRedoState.redoDisabled !== obj.tablePressToolbarUndoRedoState.redoDisabled | |
| 6292 | + ) { | |
| 6293 | + obj.tablePressToolbarUndoRedoState = newToolbarUndoRedoState; | |
| 6294 | + wp?.hooks?.doAction?.( 'tablepress.toolbarUndoRedoStateUpdate', newToolbarUndoRedoState ); | |
| 6295 | + } | |
| 6296 | + }; | |
| 6297 | + | |
| 6298 | + /** | |
| 6275 | 6299 | * Initializes a new history record for undo/redo |
| 6276 | 6300 | * |
| 6277 | 6301 | * @return null |
| 6278 | 6302 | */ |
| @@ -6285,8 +6309,11 @@ | ||
| 6285 | 6309 | obj.history = (obj.history = obj.history.slice(0, index + 1)); |
| 6286 | 6310 | |
| 6287 | 6311 | // Keep history |
| 6288 | 6312 | obj.history[index] = changes; |
| 6313 | + | |
| 6314 | + // TablePress: Update the toolbar state for undo/redo buttons. | |
| 6315 | + obj.updateTablePressToolbarUndoRedoState(); | |
| 6289 | 6316 | } |
| 6290 | 6317 | } |
| 6291 | 6318 | |
| 6292 | 6319 | /** |
| @@ -6503,8 +6530,25 @@ | ||
| 6503 | 6530 | * @param integer row number |
| 6504 | 6531 | * @return string value |
| 6505 | 6532 | */ |
| 6506 | 6533 | obj.paste = function(x, y, data) { |
| 6534 | + var x_1 = parseInt(x), | |
| 6535 | + y_1 = parseInt(y), | |
| 6536 | + x_2 = parseInt(obj.selectedCell[2]), | |
| 6537 | + y_2 = parseInt(obj.selectedCell[3]), | |
| 6538 | + w = x_2 - x_1 + 1, | |
| 6539 | + h = y_2 - y_1 + 1; | |
| 6540 | + | |
| 6541 | + // change paste range if select is from right to left | |
| 6542 | + if (x_2 < x_1){ | |
| 6543 | + x = x_2.toString(); | |
| 6544 | + w = x_1 - x_2 + 1; | |
| 6545 | + } | |
| 6546 | + // change paste range if select is from down to up | |
| 6547 | + if (y_2 < y_1){ | |
| 6548 | + y = y_2.toString(); | |
| 6549 | + h = y_1 - y_2 + 1; | |
| 6550 | + } | |
| 6507 | 6551 | // Paste filter |
| 6508 | 6552 | var ret = obj.dispatch('onbeforepaste', el, data, x, y); |
| 6509 | 6553 | |
| 6510 | 6554 | if (ret === false) { |
| @@ -6523,9 +6567,30 @@ | ||
| 6523 | 6567 | } |
| 6524 | 6568 | |
| 6525 | 6569 | // Split new line |
| 6526 | 6570 | var data = obj.parseCSV(data, "\t"); |
| 6571 | + // Modify data to allow wor extending paste range in multiples of input range | |
| 6572 | + if ((w > 1) & Number.isInteger(w / data[0].length)) { | |
| 6573 | + style = null; | |
| 6574 | + repeats = w / data[0].length; | |
| 6527 | 6575 | |
| 6576 | + var arrayB = data.map(function (row, i) { | |
| 6577 | + var arrayC = Array.apply(null, { length: repeats * row.length }).map( | |
| 6578 | + function (e, i) { return row[i % row.length]; } | |
| 6579 | + ); | |
| 6580 | + return arrayC; | |
| 6581 | + }); | |
| 6582 | + data = arrayB; | |
| 6583 | + } | |
| 6584 | + if ((h > 1) & Number.isInteger(h / data.length)) { | |
| 6585 | + style = null; | |
| 6586 | + var repeats = h / data.length; | |
| 6587 | + var arrayB = Array.apply(null, { length: repeats * data.length }).map( | |
| 6588 | + function (e, i) { return data[i % data.length]; } | |
| 6589 | + ); | |
| 6590 | + data = arrayB; | |
| 6591 | + } | |
| 6592 | + | |
| 6528 | 6593 | if (x != null && y != null && data) { |
| 6529 | 6594 | // Records |
| 6530 | 6595 | var i = 0; |
| 6531 | 6596 | var j = 0; |
| @@ -6837,8 +6902,11 @@ | ||
| 6837 | 6902 | obj.ignoreHistory = ignoreHistory; |
| 6838 | 6903 | |
| 6839 | 6904 | // Events |
| 6840 | 6905 | obj.dispatch('onundo', el, historyRecord); |
| 6906 | + | |
| 6907 | + // TablePress: Update the toolbar state for undo/redo buttons. | |
| 6908 | + obj.updateTablePressToolbarUndoRedoState(); | |
| 6841 | 6909 | } |
| 6842 | 6910 | |
| 6843 | 6911 | /** |
| 6844 | 6912 | * Redo previously undone action |
| @@ -6904,8 +6972,11 @@ | ||
| 6904 | 6972 | obj.ignoreHistory = ignoreHistory; |
| 6905 | 6973 | |
| 6906 | 6974 | // Events |
| 6907 | 6975 | obj.dispatch('onredo', el, historyRecord); |
| 6976 | + | |
| 6977 | + // TablePress: Update the toolbar state for undo/redo buttons. | |
| 6978 | + obj.updateTablePressToolbarUndoRedoState(); | |
| 6908 | 6979 | } |
| 6909 | 6980 | |
| 6910 | 6981 | /** |
| 6911 | 6982 | * Get dropdown value from key |
| @@ -7615,9 +7686,9 @@ | ||
| 7615 | 7686 | e.preventDefault(); |
| 7616 | 7687 | } else if (e.which == 35) { |
| 7617 | 7688 | jexcel.current.last(e.shiftKey, e.ctrlKey); |
| 7618 | 7689 | e.preventDefault(); |
| 7619 | - } else if (e.which == 46) { | |
| 7690 | + } else if (e.which == 46 || e.which == 8) { | |
| 7620 | 7691 | // Delete |
| 7621 | 7692 | if (jexcel.current.options.editable == true) { |
| 7622 | 7693 | if (jexcel.current.selectedRow) { |
| 7623 | 7694 | if (jexcel.current.options.allowDeleteRow == true) { |
| @@ -8717,22 +8788,13 @@ | ||
| 8717 | 8788 | |
| 8718 | 8789 | /** |
| 8719 | 8790 | * Get letter based on a number |
| 8720 | 8791 | * |
| 8721 | - * @param integer i | |
| 8792 | + * @param {number} columnNumber | |
| 8722 | 8793 | * @return string letter |
| 8723 | 8794 | */ |
| 8724 | - jexcel.getColumnName = function(i) { | |
| 8725 | - var letter = ''; | |
| 8726 | - if (i > 701) { | |
| 8727 | - letter += String.fromCharCode(64 + parseInt(i / 676)); | |
| 8728 | - letter += String.fromCharCode(64 + parseInt((i % 676) / 26)); | |
| 8729 | - } else if (i > 25) { | |
| 8730 | - letter += String.fromCharCode(64 + parseInt(i / 26)); | |
| 8731 | - } | |
| 8732 | - letter += String.fromCharCode(65 + (i % 26)); | |
| 8733 | - | |
| 8734 | - return letter; | |
| 8795 | + jexcel.getColumnName = function(columnNumber) { | |
| 8796 | + return jexcel.helpers.getColumnName(columnNumber); | |
| 8735 | 8797 | } |
| 8736 | 8798 | |
| 8737 | 8799 | /** |
| 8738 | 8800 | * Convert excel like column to jexcel id |
| @@ -9101,22 +9163,21 @@ | ||
| 9101 | 9163 | |
| 9102 | 9164 | /** |
| 9103 | 9165 | * Get letter based on a number |
| 9104 | 9166 | * |
| 9105 | - * @param integer i | |
| 9167 | + * @param {number} columnNumber | |
| 9106 | 9168 | * @return string letter |
| 9107 | 9169 | */ |
| 9108 | - component.getColumnName = function(i) { | |
| 9109 | - var letter = ''; | |
| 9110 | - if (i > 701) { | |
| 9111 | - letter += String.fromCharCode(64 + parseInt(i / 676)); | |
| 9112 | - letter += String.fromCharCode(64 + parseInt((i % 676) / 26)); | |
| 9113 | - } else if (i > 25) { | |
| 9114 | - letter += String.fromCharCode(64 + parseInt(i / 26)); | |
| 9170 | + component.getColumnName = function(columnNumber) { | |
| 9171 | + let dividend = columnNumber+1; | |
| 9172 | + let columnName = ""; | |
| 9173 | + let modulo; | |
| 9174 | + while (dividend > 0) { | |
| 9175 | + modulo = (dividend - 1) % 26; | |
| 9176 | + columnName = String.fromCharCode(65 + modulo).toString() + columnName; | |
| 9177 | + dividend = parseInt((dividend - modulo) / 26); | |
| 9115 | 9178 | } |
| 9116 | - letter += String.fromCharCode(65 + (i % 26)); | |
| 9117 | - | |
| 9118 | - return letter; | |
| 9179 | + return columnName; | |
| 9119 | 9180 | } |
| 9120 | 9181 | |
| 9121 | 9182 | /** |
| 9122 | 9183 | * Get column name from coords |