Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spreadsheet module #4313

Merged
merged 48 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
0fc5f17
initial Spreadsheet module
azmy60 Oct 3, 2023
7b7e993
Avoid clashing SelectRow module, better selection, getSelectedData
azmy60 Oct 4, 2023
f3c4428
allow multiple range selection, handle multi page, select by column
azmy60 Oct 5, 2023
dcaf452
use spreadsheet option to enable it
azmy60 Oct 6, 2023
5294ad2
clipboard module integration
azmy60 Oct 9, 2023
08991b9
allow editing by double clicking
azmy60 Oct 9, 2023
08a2000
allow custom context menu and refactors
azmy60 Oct 9, 2023
db54d9f
use rownum, add range to interaction, themes, refactors
azmy60 Oct 10, 2023
ad44510
optimize range rendering, ignore invisible columns, fix header contex…
azmy60 Oct 11, 2023
abecafe
Respect column editable, row/col range context menu, handle empty table
azmy60 Oct 13, 2023
f5e250c
respect row and column headers interaction, add some helpers
azmy60 Oct 14, 2023
ab2883d
refactors
azmy60 Oct 16, 2023
4c18d5e
expose getActiveRange
azmy60 Oct 16, 2023
8d84b48
refactors, fix virtual dom vertical
azmy60 Oct 16, 2023
6ea2c96
Fix virtual dom horizontal and overlay sizing, optimize row rendering
azmy60 Oct 17, 2023
b4498dc
cleanups
azmy60 Oct 17, 2023
2c3ee04
simplify css classes, fix unfocusable table
azmy60 Oct 18, 2023
da2b5ae
improve range getters
azmy60 Oct 20, 2023
05d406a
fix cell height resize and add rows and columns getters
azmy60 Oct 24, 2023
02edb29
fix destroy table
azmy60 Oct 24, 2023
5447711
make header focusable so we can copy after clicking the headers
azmy60 Oct 27, 2023
c85a8b1
debounce range layout
azmy60 Oct 30, 2023
75fead6
add keybindings
azmy60 Oct 30, 2023
2c519b7
remove render-virtual-dom, naming corrections, inline if, etc
azmy60 Nov 1, 2023
4b6987b
incorrect navigate jump indexing, use scrollend, cleanups
azmy60 Nov 13, 2023
a46eb1f
fix autoscroll issues
azmy60 Nov 14, 2023
a445d29
refactors
azmy60 Nov 14, 2023
30ba414
remove scrollend handler after used
azmy60 Nov 14, 2023
2428229
refactors
azmy60 Nov 15, 2023
d417c18
fix reset selection after changing page
azmy60 Nov 15, 2023
4db39ad
prevent navigation when editing, refocus to table after editing, etc.
azmy60 Nov 16, 2023
f71e71f
trap focus contextmenu, navigate menu with arrow keys and enter
azmy60 Nov 17, 2023
43b2960
fix dangling listener & prevent editing when menu is opened
azmy60 Nov 17, 2023
91f57b4
fix(navigation): cell navigation improvements
azmy60 Dec 4, 2023
8520052
refactor(conditioning): dont use optional chanining
azmy60 Dec 4, 2023
96582a6
fix(autoScroll): fix auto scrolling issue
azmy60 Dec 4, 2023
5ebf390
spreadsheet keybinding does not respect editor
azmy60 Dec 16, 2023
4358dae
undefined self
azmy60 Dec 17, 2023
b1deac5
fix disappearing row headers after setting columns
azmy60 Dec 29, 2023
90df6ce
add left & right getters to range component
azmy60 Dec 29, 2023
e58cd07
cleanups
azmy60 Dec 29, 2023
1b929ab
fix virtual dom error when adding row header
azmy60 Dec 29, 2023
e720110
better redraw
azmy60 Dec 29, 2023
5443320
disable headerSort if spreadsheet is enabled
azmy60 Jan 1, 2024
3e005ed
add options to ResizeColumns and enable multi resize (spreadsheet)
azmy60 Jan 2, 2024
5bf68ae
fix resize guide position and style
azmy60 Jan 2, 2024
94e0b84
fix: bugs when entering editor
azmy60 Jan 4, 2024
52c0bb0
enable sort module
azmy60 Jan 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/js/core/ColumnManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ export default class ColumnManager extends CoreFeature {

return index > -1 ? this.columnsByIndex[index] : false;
}

getVisibleColumnsByIndex() {
return this.columnsByIndex.filter((col) => col.visible);
}

getColumns(){
return this.columns;
Expand Down
2 changes: 1 addition & 1 deletion src/js/core/TabulatorFull.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ class TabulatorFull extends Tabulator {}
//bind modules and static functionality
new ModuleBinder(TabulatorFull, modules);

export default TabulatorFull;
export default TabulatorFull;
4 changes: 4 additions & 0 deletions src/js/core/column/Column.js
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,10 @@ class Column extends CoreFeature{

return this.component;
}

get position() {
return this.table.columnManager.getVisibleColumnsByIndex().indexOf(this) + 1;
}
}

Column.defaultOptionList = defaultOptions;
Expand Down
3 changes: 2 additions & 1 deletion src/js/core/modules/optional.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ export {default as ResizeTableModule} from '../../modules/ResizeTable/ResizeTabl
export {default as ResponsiveLayoutModule} from '../../modules/ResponsiveLayout/ResponsiveLayout.js';
export {default as SelectRowModule} from '../../modules/SelectRow/SelectRow.js';
export {default as SortModule} from '../../modules/Sort/Sort.js';
export {default as SpreadsheetModule} from '../../modules/Spreadsheet/Spreadsheet.js';
export {default as TooltipModule} from '../../modules/Tooltip/Tooltip.js';
export {default as ValidateModule} from '../../modules/Validate/Validate.js';
export {default as ValidateModule} from '../../modules/Validate/Validate.js';
2 changes: 1 addition & 1 deletion src/js/core/rendering/renderers/VirtualDomHorizontal.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,4 @@ export default class VirtualDomHorizontal extends Renderer{
}
}
}
}
}
16 changes: 15 additions & 1 deletion src/js/core/tools/Helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,18 @@ export default class Helpers{

return clone;
}
}

static debounce(func, delay = 0) {
var timeoutId;

return function (...args) {
const context = this;

clearTimeout(timeoutId);

timeoutId = setTimeout(() => {
func.apply(context, args);
}, delay);
};
}
}
6 changes: 3 additions & 3 deletions src/js/core/tools/InteractionMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@ export default class InteractionManager extends CoreFeature {
}
}
}

if(targets.group && targets.group === targets.row){
delete targets.row;
}

return targets;
}

Expand Down Expand Up @@ -319,4 +319,4 @@ export default class InteractionManager extends CoreFeature {
}
}
}
}
}
34 changes: 23 additions & 11 deletions src/js/modules/Edit/Edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Edit extends Module{
this.recursionBlock = false; //prevent focus recursion
this.invalidEdit = false;
this.editedCells = [];
this.elementToFocusOnBlur = false;

this.editors = Edit.editors;

Expand Down Expand Up @@ -55,13 +56,16 @@ class Edit extends Module{
this.subscribe("row-deleting", this.rowDeleteCheck.bind(this));
this.subscribe("row-layout", this.rowEditableCheck.bind(this));
this.subscribe("data-refreshing", this.cancelEdit.bind(this));

this.subscribe("keybinding-nav-prev", this.navigatePrev.bind(this, undefined));
this.subscribe("keybinding-nav-next", this.keybindingNavigateNext.bind(this));
this.subscribe("keybinding-nav-left", this.navigateLeft.bind(this, undefined));
this.subscribe("keybinding-nav-right", this.navigateRight.bind(this, undefined));
this.subscribe("keybinding-nav-up", this.navigateUp.bind(this, undefined));
this.subscribe("keybinding-nav-down", this.navigateDown.bind(this, undefined));

if (!this.table.options.spreadsheet) {
this.subscribe("keybinding-nav-prev", this.navigatePrev.bind(this, undefined));
this.subscribe("keybinding-nav-next", this.keybindingNavigateNext.bind(this));
// FIXME this doesn't respect input navigations when editing
// this.subscribe("keybinding-nav-left", this.navigateLeft.bind(this, undefined));
// this.subscribe("keybinding-nav-right", this.navigateRight.bind(this, undefined));
this.subscribe("keybinding-nav-up", this.navigateUp.bind(this, undefined));
this.subscribe("keybinding-nav-down", this.navigateDown.bind(this, undefined));
}
}


Expand Down Expand Up @@ -677,26 +681,34 @@ class Edit extends Module{
}
}else{
console.warn("Edit Error - Editor should return an instance of Node, the editor returned:", cellEditor);
element.blur();
this.blur(cell);
return false;
}
}else{
element.blur();
this.blur(cell);
return false;
}

return true;
}else{
this.mouseClick = false;
element.blur();
this.blur(cell);
return false;
}
}else{
this.mouseClick = false;
element.blur();
this.blur(cell);
return false;
}
}

blur(cell) {
if (this.elementToFocusOnBlur) {
this.elementToFocusOnBlur.focus();
} else {
cell.getElement().blur();
}
}

getEditedCells(){
var output = [];
Expand Down
48 changes: 32 additions & 16 deletions src/js/modules/Export/Export.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,20 @@ class Export extends Module{
this.cloneTableStyle = style;
this.config = config || {};
this.colVisProp = colVisProp;

var headers = this.config.columnHeaders !== false ? this.headersToExportRows(this.generateColumnGroupHeaders()) : [];
var body = this.bodyToExportRows(this.rowLookup(range));


var headers, body;

if (range === 'spreadsheet') {
var columns = this.table.modules.spreadsheet.selectedColumns;
headers = this.config.columnHeaders !== false
? this.headersToExportRows(this.generateColumnGroupHeaders(columns.map((component) => component._column)))
: [];
body = this.bodyToExportRows(this.rowLookup(range), columns);
} else {
headers = this.config.columnHeaders !== false ? this.headersToExportRows(this.generateColumnGroupHeaders()) : [];
body = this.bodyToExportRows(this.rowLookup(range));
}

return headers.concat(body);
}

Expand Down Expand Up @@ -73,7 +83,11 @@ class Export extends Module{
case "selected":
rows = this.table.modules.selectRow.selectedRows;
break;


case "spreadsheet":
rows = this.table.modules.spreadsheet.selectedRows;
break;

case "active":
default:
if(this.table.options.pagination){
Expand All @@ -87,10 +101,12 @@ class Export extends Module{
return Object.assign([], rows);
}

generateColumnGroupHeaders(){
generateColumnGroupHeaders(columns){
var output = [];

var columns = this.config.columnGroups !== false ? this.table.columnManager.columns : this.table.columnManager.columnsByIndex;
if (!columns) {
columns = this.config.columnGroups !== false ? this.table.columnManager.columns : this.table.columnManager.columnsByIndex;
}

columns.forEach((column) => {
var colData = this.processColumnGroup(column);
Expand All @@ -99,7 +115,7 @@ class Export extends Module{
output.push(colData);
}
});

return output;
}

Expand Down Expand Up @@ -227,16 +243,16 @@ class Export extends Module{
return exportRows;
}

bodyToExportRows(rows){

var columns = [];
bodyToExportRows(rows, columns = []){
var exportRows = [];

this.table.columnManager.columnsByIndex.forEach((column) => {
if (this.columnVisCheck(column)) {
columns.push(column.getComponent());
}
});
if (columns.length === 0) {
this.table.columnManager.columnsByIndex.forEach((column) => {
if (this.columnVisCheck(column)) {
columns.push(column.getComponent());
}
});
}

if(this.config.columnCalcs !== false && this.table.modExists("columnCalcs")){
if(this.table.modules.columnCalcs.topInitialized){
Expand Down
6 changes: 5 additions & 1 deletion src/js/modules/Format/defaults/formatters/rownum.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
export default function(cell, formatterParams, onRendered){
var content = document.createElement("span");
var row = cell.getRow();
var table = cell.getTable();

row.watchPosition((position) => {
if (formatterParams.relativeToPage) {
position += table.modules.page.getPageSize() * (table.modules.page.getPage() - 1);
}
content.innerText = position;
});

return content;
}
}
75 changes: 74 additions & 1 deletion src/js/modules/Keybindings/defaults/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,79 @@ export default {
this.dispatch("keybinding-nav-down", e);
},

spreadsheetJumpLeft: function(e){
if (!this.table.options.spreadsheet) return;
if (this.table.modules.spreadsheet.navigate("jump", "left")) {
e.preventDefault();
}
},
spreadsheetJumpRight: function(e){
if (!this.table.options.spreadsheet) return;
if (this.table.modules.spreadsheet.navigate("jump", "right")) {
e.preventDefault();
}
},
spreadsheetJumpUp: function(e){
if (!this.table.options.spreadsheet) return;
if (this.table.modules.spreadsheet.navigate("jump", "up")) {
e.preventDefault();
}
},
spreadsheetJumpDown: function(e){
if (!this.table.options.spreadsheet) return;
if (this.table.modules.spreadsheet.navigate("jump", "down")) {
e.preventDefault();
}
},
spreadsheetExpandLeft: function(e){
if (!this.table.options.spreadsheet) return;
if (this.table.modules.spreadsheet.navigate("expand", "left")) {
e.preventDefault();
}
},
spreadsheetExpandRight: function(e){
if (!this.table.options.spreadsheet) return;
if (this.table.modules.spreadsheet.navigate("expand", "right")) {
e.preventDefault();
}
},
spreadsheetExpandUp: function(e){
if (!this.table.options.spreadsheet) return;
if (this.table.modules.spreadsheet.navigate("expand", "up")) {
e.preventDefault();
}
},
spreadsheetExpandDown: function(e){
if (!this.table.options.spreadsheet) return;
if (this.table.modules.spreadsheet.navigate("expand", "down")) {
e.preventDefault();
}
},
spreadsheetExpandJumpLeft: function(e){
if (!this.table.options.spreadsheet) return;
if (this.table.modules.spreadsheet.navigate("expand-jump", "left")) {
e.preventDefault();
}
},
spreadsheetExpandJumpRight: function(e){
if (!this.table.options.spreadsheet) return;
if (this.table.modules.spreadsheet.navigate("expand-jump", "right")) {
e.preventDefault();
}
},
spreadsheetExpandJumpUp: function(e){
if (!this.table.options.spreadsheet) return;
if (this.table.modules.spreadsheet.navigate("expand-jump", "up")) {
e.preventDefault();
}
},
spreadsheetExpandJumpDown: function(e){
if (!this.table.options.spreadsheet) return;
if (this.table.modules.spreadsheet.navigate("expand-jump", "down")) {
e.preventDefault();
}
},

undo:function(e){
var cell = false;
if(this.table.options.history && this.table.modExists("history") && this.table.modExists("edit")){
Expand Down Expand Up @@ -116,4 +189,4 @@ export default {
}
}
},
};
};
17 changes: 16 additions & 1 deletion src/js/modules/Keybindings/defaults/bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,26 @@ export default {
navNext:9,
navUp:38,
navDown:40,
navLeft:37,
navRight:39,
scrollPageUp:33,
scrollPageDown:34,
scrollToStart:36,
scrollToEnd:35,
undo:["ctrl + 90", "meta + 90"],
redo:["ctrl + 89", "meta + 89"],
copyToClipboard:["ctrl + 67", "meta + 67"],
};

spreadsheetJumpUp:["ctrl + 38", "meta + 38"],
spreadsheetJumpDown:["ctrl + 40", "meta + 40"],
spreadsheetJumpLeft:["ctrl + 37", "meta + 37"],
spreadsheetJumpRight:["ctrl + 39", "meta + 39"],
spreadsheetExpandUp:"shift + 38",
spreadsheetExpandDown:"shift + 40",
spreadsheetExpandLeft:"shift + 37",
spreadsheetExpandRight:"shift + 39",
spreadsheetExpandJumpUp:["ctrl + shift + 38", "meta + shift + 38"],
spreadsheetExpandJumpDown:["ctrl + shift + 40", "meta + shift + 40"],
spreadsheetExpandJumpLeft:["ctrl + shift + 37", "meta + shift + 37"],
spreadsheetExpandJumpRight:["ctrl + shift + 39", "meta + shift + 39"],
};
Loading
Loading