@omegagrid/grid 0.11.3 → 0.11.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ui/grid.d.ts +2 -0
- package/dist/ui/grid.d.ts.map +1 -1
- package/dist/ui/grid.events.d.ts +8 -0
- package/dist/ui/grid.events.d.ts.map +1 -1
- package/dist/ui/grid.events.js +38 -10
- package/dist/ui/grid.events.js.map +1 -1
- package/dist/ui/grid.js +5 -0
- package/dist/ui/grid.js.map +1 -1
- package/dist/ui/grid.menu.d.ts.map +1 -1
- package/dist/ui/grid.menu.js +7 -2
- package/dist/ui/grid.menu.js.map +1 -1
- package/dist/ui/grid.rendering.d.ts +39 -0
- package/dist/ui/grid.rendering.d.ts.map +1 -1
- package/dist/ui/grid.rendering.js +117 -24
- package/dist/ui/grid.rendering.js.map +1 -1
- package/dist/ui/index.d.ts +1 -0
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +1 -0
- package/dist/ui/index.js.map +1 -1
- package/dist/ui/table.d.ts +6 -0
- package/dist/ui/table.d.ts.map +1 -1
- package/dist/ui/table.js +8 -2
- package/dist/ui/table.js.map +1 -1
- package/dist/ui/table.styles.d.ts +4 -0
- package/dist/ui/table.styles.d.ts.map +1 -1
- package/dist/ui/table.styles.js +6 -2
- package/dist/ui/table.styles.js.map +1 -1
- package/dist/ui/userColumnWidths.d.ts +21 -0
- package/dist/ui/userColumnWidths.d.ts.map +1 -0
- package/dist/ui/userColumnWidths.js +35 -0
- package/dist/ui/userColumnWidths.js.map +1 -0
- package/package.json +7 -7
package/dist/ui/grid.menu.js
CHANGED
|
@@ -51,13 +51,18 @@ export class GridMenus {
|
|
|
51
51
|
};
|
|
52
52
|
this._onOutlineLevelChange = (e, element) => {
|
|
53
53
|
const level = e.target.value;
|
|
54
|
+
// the table theme items match the level - re-apply them onto the changed elements
|
|
54
55
|
if (element instanceof RowModel) {
|
|
55
|
-
this.model.getRowIterator(this.grid.selection.range)
|
|
56
|
+
const rows = [...this.model.getRowIterator(this.grid.selection.range)];
|
|
57
|
+
rows.forEach(row => row.level = level);
|
|
56
58
|
this.model.rebuildRowTree();
|
|
59
|
+
this.model.applyThemeToRows(rows);
|
|
57
60
|
}
|
|
58
61
|
else {
|
|
59
|
-
this.model.getColumnIterator(this.grid.selection.range)
|
|
62
|
+
const columns = [...this.model.getColumnIterator(this.grid.selection.range)];
|
|
63
|
+
columns.forEach(col => col.level = level);
|
|
60
64
|
this.model.rebuildColumnTree();
|
|
65
|
+
this.model.applyThemeToColumns(columns);
|
|
61
66
|
}
|
|
62
67
|
this.grid.rendering.render(true);
|
|
63
68
|
};
|
package/dist/ui/grid.menu.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grid.menu.js","sourceRoot":"","sources":["../../src/ui/grid.menu.ts"],"names":[],"mappings":"AACA,OAAO,EAA0B,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAExE,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAE3B,MAAM,OAAO,aAAc,SAAQ,SAAS;IAI3C,YAAY,IAAY,EAAE,IAA6B;QACtD,KAAK,CAAC,QAAQ,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;IAC7B,CAAC;CAED;AAED,MAAM,OAAO,SAAS;IAErB,IAAI,KAAK,KAAK,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAA,CAAC,CAAC;IACtC,IAAI,SAAS,KAAK,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,CAAA,CAAC,CAAC;IAC9C,IAAI,QAAQ,KAAK,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAA,CAAC,CAAC;IAC5C,IAAI,MAAM,KAAK,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAA,CAAC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,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;aACtE,CAAC;QACH,CAAC;QAED,IAAI,CAAC,gBAAgB,GAAG,KAAK,CAAC;QAC9B,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACzB,CAAC;CAED","sourcesContent":["import { ListSelectEvent, MenuItem, NumericInput } from \"@omegagrid/core\";\nimport { CellModel, ColumnModel, RowModel } from \"@omegagrid/grid-core\";\nimport { Grid } from \"./grid\";\nimport { msg } from \"@omegagrid/localize\";\nimport { GridEvent } from \"./grid.events\";\nimport { html } from \"lit\";\n\nexport class GridMenuEvent extends GridEvent {\n\n\treadonly item: MenuItem;\n\n\tconstructor(type: string, args?: Partial<GridMenuEvent>) {\n\t\tsuper(`menu.${type}`, args);\n\t}\n\n}\n\nexport class GridMenus {\n\n\tget model() { return this.grid.model }\n\tget selection() { return this.grid.selection }\n\tget selector() { return this.grid.selector }\n\tget events() { return this.grid.events }\n\tget table() { return this.grid.table }\n\tget contextMenu() { return this.grid.contextMenu }\n\n\tprivate currentMenuItems: MenuItem[];\n\tprivate currentColumn: ColumnModel;\n\tprivate currentRow: RowModel;\n\tprivate currentCell: CellModel;\n\n\tconstructor(readonly grid: Grid) { }\n\n\t_onContextMenuClick = (e: ListSelectEvent) => {\n\t\tconst grid = this.grid;\n\t\tswitch (this.currentMenuItems[e.index].key) {\n\t\t\tcase 'insertColumn':\n\t\t\t\tgrid.editing.insertColumns({index: this.currentColumn.index, count: 1});\n\t\t\t\tbreak;\n\t\t\tcase 'insertColumnAfter':\n\t\t\t\tgrid.editing.insertColumns({index: this.currentColumn.index, count: 1, after: true});\n\t\t\t\tbreak;\n\t\t\tcase 'deleteColumn':\n\t\t\t\tgrid.editing.deleteColumns({index: this.currentColumn.index, count: 1});\n\t\t\t\tbreak;\n\t\t\tcase 'insertRow':\n\t\t\t\tgrid.editing.insertRows({index: this.currentRow.index, count: 1});\n\t\t\t\tbreak;\n\t\t\tcase 'insertRowAfter':\n\t\t\t\tgrid.editing.insertRows({index: this.currentRow.index, count: 1, after: true});\n\t\t\t\tbreak;\n\t\t\tcase 'deleteRow':\n\t\t\t\tgrid.editing.deleteRows({index: this.currentRow.index, count: 1});\n\t\t\t\tbreak;\n\t\t\tcase 'comment':\n\t\t\t\tthis.grid.editing.openComments(this.currentCell);\n\t\t\t\tbreak;\n\t\t}\n\n\t\tthis.grid.dispatchEvent(new GridMenuEvent('click', {\n\t\t\tgrid: this.grid,\n\t\t\tcell: this.currentCell,\n\t\t\trow: this.currentRow,\n\t\t\tcolumn: this.currentColumn,\n\t\t\titem: this.currentMenuItems[e.index]\n\t\t}));\n\t}\n\n\tinit() {\n\t\tthis.contextMenu.addEventListener('select', this._onContextMenuClick);\n\t}\n\n\t_onOutlineLevelChange = (e: Event, element: RowModel|ColumnModel) => {\n\t\tconst level = (e.target as NumericInput).value;\n\n\t\tif (element instanceof RowModel) {\n\t\t\tthis.model.getRowIterator(this.grid.selection.range).forEach(row => row.level = level);\n\t\t\tthis.model.rebuildRowTree();\n\t\t} else {\n\t\t\tthis.model.getColumnIterator(this.grid.selection.range).forEach(col => col.level = level);\n\t\t\tthis.model.rebuildColumnTree();\n\t\t}\n\t\t\n\t\tthis.grid.rendering.render(true);\n\t}\n\n\trenderOutlineMenuItem = (element: RowModel|ColumnModel) => {\n\t\treturn html`\n\t\t\t<div\n\t\t\t\tstyle=\"display: flex; flex-direction: row; align-items: center;\"\n\t\t\t\t@mousedown=\"${(e: Event) => e.stopPropagation()}\"\n\t\t\t\t@mouseup=\"${(e: Event) => e.stopPropagation()}\">\n\t\t\t\t<og-numericinput buttons\n\t\t\t\t\tmin=\"0\"\n\t\t\t\t\tmax=\"9\"\n\t\t\t\t\tvalue=\"${element.level}\"\n\t\t\t\t\tstyle=\"margin-right: 2px; text-align: center\"\n\t\t\t\t\t@change=\"${(e: Event) => this._onOutlineLevelChange(e, element)}\">\n\t\t\t\t</og-numericinput>\n\t\t\t</div>\n\t\t`;\n\t}\n\n\topenMenu(position: {x: number, y: number}) {\n\t\tif (this.currentMenuItems.length > 0) {\n\t\t\tthis.contextMenu.items = this.currentMenuItems;\n\t\t\tthis.contextMenu.openAt(position.x, position.y);\n\t\t}\n\t}\n\n\topenColumnMenu(column: ColumnModel, position: {x: number, y: number}) {\n\t\tconst opts = this.grid.options;\n\t\tconst customMenu = opts.menus?.column;\n\t\tlet items: MenuItem[] = [];\n\n\t\tthis.currentColumn = column;\n\n\t\tif (!customMenu?.replace) {\n\t\t\tif (opts.editable && opts.editing.colInsertion) {\n\t\t\t\titems.push({key: 'insertColumn', value: 'Insert column', icon: 'plus'});\n\t\t\t\titems.push({key: 'insertColumnAfter', value: 'Insert column (after)', icon: 'plus'});\n\t\t\t}\n\t\t\t\n\t\t\tif (opts.editable && opts.editing.colDeletion) {\n\t\t\t\titems.push({key: 'deleteColumn', value: 'Delete column', icon: 'minus'});\n\t\t\t}\n\n\t\t\tif (opts.editable && opts.editing.colOutline) {\n\t\t\t\titems.push({key: 'colLevel', icon: 'list-tree', renderer: () => this.renderOutlineMenuItem(column)});\n\t\t\t}\n\t\t}\n\n\t\tif (customMenu) {\n\t\t\tif (items.length > 0) items[items.length - 1].divider = true;\n\t\t\titems = [\n\t\t\t\t...items,\n\t\t\t\t...customMenu.items.filter(item => !item.hidden || !item.hidden(column))\n\t\t\t];\n\t\t}\n\n\t\tthis.currentMenuItems = items;\n\t\tthis.openMenu(position);\n\t}\n\n\topenRowMenu(row: RowModel, position: {x: number, y: number}) {\n\t\tconst opts = this.grid.options;\n\t\tconst customMenu = opts.menus?.row;\n\t\tlet items: MenuItem[] = [];\n\n\t\tthis.currentRow = row;\n\t\t\n\t\tif (!customMenu?.replace) {\n\t\t\tif (opts.editable && opts.editing.rowInsertion) {\n\t\t\t\titems.push({key: 'insertRow', value: 'Insert row', icon: 'plus'});\n\t\t\t\titems.push({key: 'insertRowAfter', value: 'Insert row (after)', icon: 'plus'});\n\t\t\t}\n\t\t\t\n\t\t\tif (opts.editable && opts.editing.rowDeletion) {\n\t\t\t\titems.push({key: 'deleteRow', value: 'Delete row', icon: 'minus'});\n\t\t\t}\n\n\t\t\tif (opts.editable && opts.editing.rowOutline) {\n\t\t\t\titems.push({key: 'rowLevel', icon: 'list-tree', renderer: () => this.renderOutlineMenuItem(row)});\n\t\t\t}\n\t\t}\n\n\t\tif (customMenu) {\n\t\t\tif (items.length > 0) items[items.length - 1].divider = true;\n\t\t\titems = [\n\t\t\t\t...items,\n\t\t\t\t...customMenu.items.filter(item => !item.hidden || !item.hidden(row))\n\t\t\t];\n\t\t}\n\n\t\tthis.currentMenuItems = items;\n\t\tthis.openMenu(position);\n\t}\n\n\topenCellMenu(cell: CellModel, position: {x: number, y: number}) {\n\t\tconst opts = this.grid.options;\n\t\tconst customMenu = opts.menus?.cell;\n\t\tlet items: MenuItem[] = [];\n\n\t\tthis.currentCell = cell;\n\n\t\tif (!customMenu?.replace) {\n\t\t\tif (cell.commentable) {\n\t\t\t\titems.push({key: 'comment', value: msg('Comment'), icon: 'comment'});\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (customMenu) {\n\t\t\tif (items.length > 0) items[items.length - 1].divider = true;\n\t\t\titems = [\n\t\t\t\t...items,\n\t\t\t\t...customMenu.items.filter(item => !item.hidden || !item.hidden(cell))\n\t\t\t];\n\t\t}\n\n\t\tthis.currentMenuItems = items;\n\t\tthis.openMenu(position);\n\t}\n\n}"]}
|
|
1
|
+
{"version":3,"file":"grid.menu.js","sourceRoot":"","sources":["../../src/ui/grid.menu.ts"],"names":[],"mappings":"AACA,OAAO,EAA0B,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAExE,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAE3B,MAAM,OAAO,aAAc,SAAQ,SAAS;IAI3C,YAAY,IAAY,EAAE,IAA6B;QACtD,KAAK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AAE,IAAI,CAAC;QACpC,IAAI,KAAK,GAAe,EAAE,CAAC;QAE3B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QAExB,IAAI,CAAC,UAAU,EAAE,OAAO,EAAE,CAAC;YAC1B,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;gBACtB,KAAK,CAAC,IAAI,CAAC,EAAC,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,SAAS,EAAC,CAAC,CAAC;YACtE,CAAC;QACF,CAAC;QAED,IAAI,UAAU,EAAE,CAAC;YAChB,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;gBAAE,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,OAAO,GAAG,IAAI,CAAC;YAC7D,KAAK,GAAG;gBACP,GAAG,KAAK;gBACR,GAAG,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;aACtE,CAAC;QACH,CAAC;QAED,IAAI,CAAC,gBAAgB,GAAG,KAAK,CAAC;QAC9B,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACzB,CAAC;CAED","sourcesContent":["import { ListSelectEvent, MenuItem, NumericInput } from \"@omegagrid/core\";\nimport { CellModel, ColumnModel, RowModel } from \"@omegagrid/grid-core\";\nimport { Grid } from \"./grid\";\nimport { msg } from \"@omegagrid/localize\";\nimport { GridEvent } from \"./grid.events\";\nimport { html } from \"lit\";\n\nexport class GridMenuEvent extends GridEvent {\n\n\treadonly item: MenuItem;\n\n\tconstructor(type: string, args?: Partial<GridMenuEvent>) {\n\t\tsuper(`menu.${type}`, args);\n\t}\n\n}\n\nexport class GridMenus {\n\n\tget model() { return this.grid.model }\n\tget selection() { return this.grid.selection }\n\tget selector() { return this.grid.selector }\n\tget events() { return this.grid.events }\n\tget table() { return this.grid.table }\n\tget contextMenu() { return this.grid.contextMenu }\n\n\tprivate currentMenuItems: MenuItem[];\n\tprivate currentColumn: ColumnModel;\n\tprivate currentRow: RowModel;\n\tprivate currentCell: CellModel;\n\n\tconstructor(readonly grid: Grid) { }\n\n\t_onContextMenuClick = (e: ListSelectEvent) => {\n\t\tconst grid = this.grid;\n\t\tswitch (this.currentMenuItems[e.index].key) {\n\t\t\tcase 'insertColumn':\n\t\t\t\tgrid.editing.insertColumns({index: this.currentColumn.index, count: 1});\n\t\t\t\tbreak;\n\t\t\tcase 'insertColumnAfter':\n\t\t\t\tgrid.editing.insertColumns({index: this.currentColumn.index, count: 1, after: true});\n\t\t\t\tbreak;\n\t\t\tcase 'deleteColumn':\n\t\t\t\tgrid.editing.deleteColumns({index: this.currentColumn.index, count: 1});\n\t\t\t\tbreak;\n\t\t\tcase 'insertRow':\n\t\t\t\tgrid.editing.insertRows({index: this.currentRow.index, count: 1});\n\t\t\t\tbreak;\n\t\t\tcase 'insertRowAfter':\n\t\t\t\tgrid.editing.insertRows({index: this.currentRow.index, count: 1, after: true});\n\t\t\t\tbreak;\n\t\t\tcase 'deleteRow':\n\t\t\t\tgrid.editing.deleteRows({index: this.currentRow.index, count: 1});\n\t\t\t\tbreak;\n\t\t\tcase 'comment':\n\t\t\t\tthis.grid.editing.openComments(this.currentCell);\n\t\t\t\tbreak;\n\t\t}\n\n\t\tthis.grid.dispatchEvent(new GridMenuEvent('click', {\n\t\t\tgrid: this.grid,\n\t\t\tcell: this.currentCell,\n\t\t\trow: this.currentRow,\n\t\t\tcolumn: this.currentColumn,\n\t\t\titem: this.currentMenuItems[e.index]\n\t\t}));\n\t}\n\n\tinit() {\n\t\tthis.contextMenu.addEventListener('select', this._onContextMenuClick);\n\t}\n\n\t_onOutlineLevelChange = (e: Event, element: RowModel|ColumnModel) => {\n\t\tconst level = (e.target as NumericInput).value;\n\n\t\t// the table theme items match the level - re-apply them onto the changed elements\n\t\tif (element instanceof RowModel) {\n\t\t\tconst rows = [...this.model.getRowIterator(this.grid.selection.range)];\n\t\t\trows.forEach(row => row.level = level);\n\t\t\tthis.model.rebuildRowTree();\n\t\t\tthis.model.applyThemeToRows(rows);\n\t\t} else {\n\t\t\tconst columns = [...this.model.getColumnIterator(this.grid.selection.range)];\n\t\t\tcolumns.forEach(col => col.level = level);\n\t\t\tthis.model.rebuildColumnTree();\n\t\t\tthis.model.applyThemeToColumns(columns);\n\t\t}\n\t\t\n\t\tthis.grid.rendering.render(true);\n\t}\n\n\trenderOutlineMenuItem = (element: RowModel|ColumnModel) => {\n\t\treturn html`\n\t\t\t<div\n\t\t\t\tstyle=\"display: flex; flex-direction: row; align-items: center;\"\n\t\t\t\t@mousedown=\"${(e: Event) => e.stopPropagation()}\"\n\t\t\t\t@mouseup=\"${(e: Event) => e.stopPropagation()}\">\n\t\t\t\t<og-numericinput buttons\n\t\t\t\t\tmin=\"0\"\n\t\t\t\t\tmax=\"9\"\n\t\t\t\t\tvalue=\"${element.level}\"\n\t\t\t\t\tstyle=\"margin-right: 2px; text-align: center\"\n\t\t\t\t\t@change=\"${(e: Event) => this._onOutlineLevelChange(e, element)}\">\n\t\t\t\t</og-numericinput>\n\t\t\t</div>\n\t\t`;\n\t}\n\n\topenMenu(position: {x: number, y: number}) {\n\t\tif (this.currentMenuItems.length > 0) {\n\t\t\tthis.contextMenu.items = this.currentMenuItems;\n\t\t\tthis.contextMenu.openAt(position.x, position.y);\n\t\t}\n\t}\n\n\topenColumnMenu(column: ColumnModel, position: {x: number, y: number}) {\n\t\tconst opts = this.grid.options;\n\t\tconst customMenu = opts.menus?.column;\n\t\tlet items: MenuItem[] = [];\n\n\t\tthis.currentColumn = column;\n\n\t\tif (!customMenu?.replace) {\n\t\t\tif (opts.editable && opts.editing.colInsertion) {\n\t\t\t\titems.push({key: 'insertColumn', value: 'Insert column', icon: 'plus'});\n\t\t\t\titems.push({key: 'insertColumnAfter', value: 'Insert column (after)', icon: 'plus'});\n\t\t\t}\n\t\t\t\n\t\t\tif (opts.editable && opts.editing.colDeletion) {\n\t\t\t\titems.push({key: 'deleteColumn', value: 'Delete column', icon: 'minus'});\n\t\t\t}\n\n\t\t\tif (opts.editable && opts.editing.colOutline) {\n\t\t\t\titems.push({key: 'colLevel', icon: 'list-tree', renderer: () => this.renderOutlineMenuItem(column)});\n\t\t\t}\n\t\t}\n\n\t\tif (customMenu) {\n\t\t\tif (items.length > 0) items[items.length - 1].divider = true;\n\t\t\titems = [\n\t\t\t\t...items,\n\t\t\t\t...customMenu.items.filter(item => !item.hidden || !item.hidden(column))\n\t\t\t];\n\t\t}\n\n\t\tthis.currentMenuItems = items;\n\t\tthis.openMenu(position);\n\t}\n\n\topenRowMenu(row: RowModel, position: {x: number, y: number}) {\n\t\tconst opts = this.grid.options;\n\t\tconst customMenu = opts.menus?.row;\n\t\tlet items: MenuItem[] = [];\n\n\t\tthis.currentRow = row;\n\t\t\n\t\tif (!customMenu?.replace) {\n\t\t\tif (opts.editable && opts.editing.rowInsertion) {\n\t\t\t\titems.push({key: 'insertRow', value: 'Insert row', icon: 'plus'});\n\t\t\t\titems.push({key: 'insertRowAfter', value: 'Insert row (after)', icon: 'plus'});\n\t\t\t}\n\t\t\t\n\t\t\tif (opts.editable && opts.editing.rowDeletion) {\n\t\t\t\titems.push({key: 'deleteRow', value: 'Delete row', icon: 'minus'});\n\t\t\t}\n\n\t\t\tif (opts.editable && opts.editing.rowOutline) {\n\t\t\t\titems.push({key: 'rowLevel', icon: 'list-tree', renderer: () => this.renderOutlineMenuItem(row)});\n\t\t\t}\n\t\t}\n\n\t\tif (customMenu) {\n\t\t\tif (items.length > 0) items[items.length - 1].divider = true;\n\t\t\titems = [\n\t\t\t\t...items,\n\t\t\t\t...customMenu.items.filter(item => !item.hidden || !item.hidden(row))\n\t\t\t];\n\t\t}\n\n\t\tthis.currentMenuItems = items;\n\t\tthis.openMenu(position);\n\t}\n\n\topenCellMenu(cell: CellModel, position: {x: number, y: number}) {\n\t\tconst opts = this.grid.options;\n\t\tconst customMenu = opts.menus?.cell;\n\t\tlet items: MenuItem[] = [];\n\n\t\tthis.currentCell = cell;\n\n\t\tif (!customMenu?.replace) {\n\t\t\tif (cell.commentable) {\n\t\t\t\titems.push({key: 'comment', value: msg('Comment'), icon: 'comment'});\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (customMenu) {\n\t\t\tif (items.length > 0) items[items.length - 1].divider = true;\n\t\t\titems = [\n\t\t\t\t...items,\n\t\t\t\t...customMenu.items.filter(item => !item.hidden || !item.hidden(cell))\n\t\t\t];\n\t\t}\n\n\t\tthis.currentMenuItems = items;\n\t\tthis.openMenu(position);\n\t}\n\n}"]}
|
|
@@ -8,6 +8,23 @@ export type RefreshOptions = {
|
|
|
8
8
|
horizontal?: boolean;
|
|
9
9
|
rerenderTable?: boolean;
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* The width the table gives a cell for its content when its row is autofitted: the column width, for a merged
|
|
13
|
+
* cell the width of the shown columns it spans. Null for a cell that must not size the row: one in a column
|
|
14
|
+
* that is not shown (hidden or in a collapsed group), one covered by a merge, or a merge that spans other rows as well.
|
|
15
|
+
* @param visibleColumns the columns the table shows (`model.visibleColumns`)
|
|
16
|
+
*/
|
|
17
|
+
export declare function autofitCellWidth(cell: CellModel, visibleColumns: ReadonlySet<ColumnModel>): number | null;
|
|
18
|
+
/**
|
|
19
|
+
* The columns (or rows) a double click on the divider of `node` autofits. Like in Excel: all the selected ones
|
|
20
|
+
* when the selection covers whole columns (rows) and `node` is among them, otherwise `node` alone.
|
|
21
|
+
* @param visibleNodes the columns (rows) the table shows (`model.visibleColumns` / `model.visibleRows`)
|
|
22
|
+
* @param whole whether the selection covers whole columns (rows)
|
|
23
|
+
* @param from the selected index span, in either order (a selection dragged backwards is not normalized)
|
|
24
|
+
*/
|
|
25
|
+
export declare function autofitTargets<T extends {
|
|
26
|
+
index: number;
|
|
27
|
+
}>(node: T, visibleNodes: readonly T[], whole: boolean, from: number, to: number): T[];
|
|
11
28
|
export declare class GridRendering {
|
|
12
29
|
readonly grid: Grid;
|
|
13
30
|
requireVerticalUpdate: boolean;
|
|
@@ -99,10 +116,32 @@ export declare class GridRendering {
|
|
|
99
116
|
height: number;
|
|
100
117
|
};
|
|
101
118
|
private autofitDiv;
|
|
119
|
+
/**
|
|
120
|
+
* The detached div the autofit renders cells into, reset and given the chrome of a body cell
|
|
121
|
+
* (`td>div` in table.styles, font size and line height of the table style) so that it measures
|
|
122
|
+
* what the table shows. The renderers leave inline styles and classes behind, hence the reset per cell.
|
|
123
|
+
* @param width the width the table gives the cell, `'auto'` to measure the content width
|
|
124
|
+
*/
|
|
125
|
+
private prepareAutofitDiv;
|
|
126
|
+
private renderToAutofitDiv;
|
|
127
|
+
/** Width of the content rendered into the autofit div: the client width less the padding, so the border rendering (1.5px snaps to device pixels) does not get in. */
|
|
128
|
+
private autofitContentWidth;
|
|
129
|
+
/** Drops the last measured cell from the autofit div: its elements (buttons, expanders) would keep the cell and its model alive. */
|
|
130
|
+
private releaseAutofitDiv;
|
|
102
131
|
autofitColumn(c: number | ColumnModel, visibleValuesOnly?: boolean, rerender?: boolean): void;
|
|
103
132
|
autofitColumns(visibleValuesOnly?: boolean): void;
|
|
104
133
|
autofitRow(r: number | RowModel, visibleValuesOnly?: boolean, rerender?: boolean): void;
|
|
105
134
|
autofitRows(visibleValuesOnly?: boolean): void;
|
|
135
|
+
/**
|
|
136
|
+
* Autofits `column` or, when the selection covers whole columns including it, all the selected columns (see autofitTargets).
|
|
137
|
+
* @returns the autofitted columns
|
|
138
|
+
*/
|
|
139
|
+
autofitColumnWithSelection(column: ColumnModel): ColumnModel[];
|
|
140
|
+
/**
|
|
141
|
+
* Autofits `row` or, when the selection covers whole rows including it, all the selected rows (see autofitTargets).
|
|
142
|
+
* @returns the autofitted rows
|
|
143
|
+
*/
|
|
144
|
+
autofitRowWithSelection(row: RowModel): RowModel[];
|
|
106
145
|
scrollTo(r: number | RangeAddress, c?: number): void;
|
|
107
146
|
}
|
|
108
147
|
//# sourceMappingURL=grid.rendering.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grid.rendering.d.ts","sourceRoot":"","sources":["../../src/ui/grid.rendering.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA+B,MAAM,iBAAiB,CAAC;AAEzE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAA8B,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC7H,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAY,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"grid.rendering.d.ts","sourceRoot":"","sources":["../../src/ui/grid.rendering.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA+B,MAAM,iBAAiB,CAAC;AAEzE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAA8B,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC7H,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAY,MAAM,SAAS,CAAC;AAI9D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGhD,MAAM,MAAM,cAAc,GAAG;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,aAAa,CAAC,EAAE,OAAO,CAAA;CACvB,CAAC;AAKF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,cAAc,EAAE,WAAW,CAAC,WAAW,CAAC,GAAG,MAAM,GAAC,IAAI,CAavG;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS;IAAC,KAAK,EAAE,MAAM,CAAA;CAA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AoI;IACpI,OAAO,CAAC,iBAAiB;IAIzB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAC,WAAW,EAAE,iBAAiB,UAAQ,EAAE,QAAQ,UAAO;IAyB/E,cAAc,CAAC,iBAAiB,UAAQ;IAKxC,UAAU,CAAC,CAAC,EAAE,MAAM,GAAC,QAAQ,EAAE,iBAAiB,UAAQ,EAAE,QAAQ,UAAO;IAiBzE,WAAW,CAAC,iBAAiB,UAAQ;IAKrC;;;OAGG;IACH,0BAA0B,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,EAAE;IAQ9D;;;OAGG;IACH,uBAAuB,CAAC,GAAG,EAAE,QAAQ,GAAG,QAAQ,EAAE;IAQlD,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAC,YAAY,EAAE,CAAC,SAAI;CAatC"}
|
|
@@ -4,7 +4,48 @@ import { CellRange, gridConstants as constants } from "@omegagrid/grid-core";
|
|
|
4
4
|
import { Table } from "./table";
|
|
5
5
|
import { GridEvent } from "./grid.events";
|
|
6
6
|
import { getCellRenderer } from "../renderers";
|
|
7
|
+
import { CELL_BORDER_WIDTH, CELL_PADDING } from "./table.styles";
|
|
7
8
|
import { createThemeVariablesCss } from "@omegagrid/core";
|
|
9
|
+
/** Room the column autofit leaves around the content, the cell chrome included. */
|
|
10
|
+
const AUTOFIT_COLUMN_SPACE = 22;
|
|
11
|
+
/**
|
|
12
|
+
* The width the table gives a cell for its content when its row is autofitted: the column width, for a merged
|
|
13
|
+
* cell the width of the shown columns it spans. Null for a cell that must not size the row: one in a column
|
|
14
|
+
* that is not shown (hidden or in a collapsed group), one covered by a merge, or a merge that spans other rows as well.
|
|
15
|
+
* @param visibleColumns the columns the table shows (`model.visibleColumns`)
|
|
16
|
+
*/
|
|
17
|
+
export function autofitCellWidth(cell, visibleColumns) {
|
|
18
|
+
if (!visibleColumns.has(cell.column))
|
|
19
|
+
return null;
|
|
20
|
+
const merges = cell.model.merges;
|
|
21
|
+
if (merges.hiddenCells.has(cell.address))
|
|
22
|
+
return null;
|
|
23
|
+
const merge = merges.mergedCells.get(cell.address);
|
|
24
|
+
if (!merge)
|
|
25
|
+
return cell.column.width;
|
|
26
|
+
if (merge.rs > 1)
|
|
27
|
+
return null;
|
|
28
|
+
let width = 0;
|
|
29
|
+
for (let c = merge.c; c < merge.c + merge.cs; c++) {
|
|
30
|
+
const column = cell.model.columns[c];
|
|
31
|
+
if (column && visibleColumns.has(column))
|
|
32
|
+
width += column.width;
|
|
33
|
+
}
|
|
34
|
+
return width;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The columns (or rows) a double click on the divider of `node` autofits. Like in Excel: all the selected ones
|
|
38
|
+
* when the selection covers whole columns (rows) and `node` is among them, otherwise `node` alone.
|
|
39
|
+
* @param visibleNodes the columns (rows) the table shows (`model.visibleColumns` / `model.visibleRows`)
|
|
40
|
+
* @param whole whether the selection covers whole columns (rows)
|
|
41
|
+
* @param from the selected index span, in either order (a selection dragged backwards is not normalized)
|
|
42
|
+
*/
|
|
43
|
+
export function autofitTargets(node, visibleNodes, whole, from, to) {
|
|
44
|
+
const [first, last] = [Math.min(from, to), Math.max(from, to)];
|
|
45
|
+
if (!whole || node.index < first || node.index > last)
|
|
46
|
+
return [node];
|
|
47
|
+
return visibleNodes.filter(n => n.index >= first && n.index <= last);
|
|
48
|
+
}
|
|
8
49
|
export class GridRendering {
|
|
9
50
|
get vScrolling() { return this._vScrolling; }
|
|
10
51
|
get hScrolling() { return this._hScrolling; }
|
|
@@ -532,20 +573,51 @@ export class GridRendering {
|
|
|
532
573
|
height: this.table.thead.offsetHeight + this.model.visibleRows.reduce((acc, row) => acc + row.height, 0)
|
|
533
574
|
};
|
|
534
575
|
}
|
|
576
|
+
/**
|
|
577
|
+
* The detached div the autofit renders cells into, reset and given the chrome of a body cell
|
|
578
|
+
* (`td>div` in table.styles, font size and line height of the table style) so that it measures
|
|
579
|
+
* what the table shows. The renderers leave inline styles and classes behind, hence the reset per cell.
|
|
580
|
+
* @param width the width the table gives the cell, `'auto'` to measure the content width
|
|
581
|
+
*/
|
|
582
|
+
prepareAutofitDiv(width) {
|
|
583
|
+
const div = this.autofitDiv ?? (this.autofitDiv = dom.createElement('div'));
|
|
584
|
+
dom.empty(div);
|
|
585
|
+
div.className = '';
|
|
586
|
+
div.removeAttribute('style');
|
|
587
|
+
dom.setPosition(div, { l: -10000, t: -10000 });
|
|
588
|
+
div.style.visibility = 'hidden';
|
|
589
|
+
div.style.boxSizing = 'border-box';
|
|
590
|
+
div.style.border = `${CELL_BORDER_WIDTH}px solid transparent`;
|
|
591
|
+
div.style.padding = `0 ${CELL_PADDING}px`;
|
|
592
|
+
div.style.fontSize = dom.numToPixels(this.table.cellFontSize);
|
|
593
|
+
div.style.lineHeight = dom.numToPixels(this.table.rowLineHeight);
|
|
594
|
+
div.style.whiteSpace = 'nowrap';
|
|
595
|
+
div.style.width = width === 'auto' ? 'auto' : dom.numToPixels(width);
|
|
596
|
+
if (!div.isConnected)
|
|
597
|
+
this.grid.shadowRoot.appendChild(div);
|
|
598
|
+
return div;
|
|
599
|
+
}
|
|
600
|
+
renderToAutofitDiv(cell, width) {
|
|
601
|
+
const div = this.prepareAutofitDiv(width);
|
|
602
|
+
return getCellRenderer(cell).call(this.table, div, cell) || div;
|
|
603
|
+
}
|
|
604
|
+
/** Width of the content rendered into the autofit div: the client width less the padding, so the border rendering (1.5px snaps to device pixels) does not get in. */
|
|
605
|
+
autofitContentWidth(div) {
|
|
606
|
+
return div.clientWidth - 2 * CELL_PADDING;
|
|
607
|
+
}
|
|
608
|
+
/** Drops the last measured cell from the autofit div: its elements (buttons, expanders) would keep the cell and its model alive. */
|
|
609
|
+
releaseAutofitDiv() {
|
|
610
|
+
if (this.autofitDiv)
|
|
611
|
+
dom.empty(this.autofitDiv);
|
|
612
|
+
}
|
|
535
613
|
autofitColumn(c, visibleValuesOnly = false, rerender = true) {
|
|
536
614
|
const column = typeof c === 'number' ? this.model.columns[c] : c;
|
|
537
|
-
const div = this.autofitDiv ?? (this.autofitDiv = dom.createElement('div'));
|
|
538
|
-
div.style.position = 'absolute';
|
|
539
|
-
div.style.zIndex = '100000';
|
|
540
|
-
dom.setPosition(div, { l: -1000, t: -1000 });
|
|
541
|
-
this.grid.shadowRoot.appendChild(div);
|
|
542
615
|
let maxWidth = 0;
|
|
543
616
|
for (const cell of this.model.getRangeIterator(CellRange.fromA1(column.address), !!visibleValuesOnly)) {
|
|
544
|
-
|
|
545
|
-
cellDiv.style.width = 'auto';
|
|
546
|
-
maxWidth = Math.max(maxWidth, cellDiv.offsetWidth);
|
|
617
|
+
maxWidth = Math.max(maxWidth, this.autofitContentWidth(this.renderToAutofitDiv(cell, 'auto')));
|
|
547
618
|
}
|
|
548
619
|
if (column.header) {
|
|
620
|
+
const div = this.prepareAutofitDiv('auto');
|
|
549
621
|
for (const h of column.header) {
|
|
550
622
|
if (!h)
|
|
551
623
|
continue;
|
|
@@ -553,11 +625,11 @@ export class GridRendering {
|
|
|
553
625
|
div.innerHTML = h.label ?? '';
|
|
554
626
|
else
|
|
555
627
|
div.innerText = h.label ?? '';
|
|
556
|
-
maxWidth = Math.max(maxWidth, div
|
|
628
|
+
maxWidth = Math.max(maxWidth, this.autofitContentWidth(div));
|
|
557
629
|
}
|
|
558
|
-
div.innerHTML = '';
|
|
559
630
|
}
|
|
560
|
-
|
|
631
|
+
this.releaseAutofitDiv();
|
|
632
|
+
column.width = maxWidth + AUTOFIT_COLUMN_SPACE;
|
|
561
633
|
// limit max column width to 90% of the table body
|
|
562
634
|
maxWidth = (this.grid.offsetWidth - (this.table?.totalHeaderWidth ?? 0)) * 0.9;
|
|
563
635
|
if (maxWidth > 0 && column.width > maxWidth)
|
|
@@ -571,20 +643,19 @@ export class GridRendering {
|
|
|
571
643
|
}
|
|
572
644
|
autofitRow(r, visibleValuesOnly = false, rerender = true) {
|
|
573
645
|
const row = typeof r === 'number' ? this.model.rows[r] : r;
|
|
574
|
-
const
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
// div.style.backgroundColor = 'red';
|
|
578
|
-
// dom.setPosition(div, {l: 100, t: 100});
|
|
579
|
-
dom.setPosition(div, { l: -1000, t: -1000 });
|
|
580
|
-
this.grid.shadowRoot.appendChild(div);
|
|
581
|
-
let maxHeight = 0;
|
|
646
|
+
const table = this.table;
|
|
647
|
+
const visibleColumns = new Set(this.model.visibleColumns);
|
|
648
|
+
let maxHeight = table.rowLineHeight; // an empty row keeps one line
|
|
582
649
|
for (const cell of this.model.getRangeIterator(CellRange.fromA1(row.address), !!visibleValuesOnly)) {
|
|
583
|
-
const
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
650
|
+
const width = autofitCellWidth(cell, visibleColumns);
|
|
651
|
+
if (width == null)
|
|
652
|
+
continue;
|
|
653
|
+
// the cell wraps within the width the table gives it; clientHeight is the content without the border
|
|
654
|
+
maxHeight = Math.max(maxHeight, this.renderToAutofitDiv(cell, width).clientHeight);
|
|
655
|
+
}
|
|
656
|
+
this.releaseAutofitDiv();
|
|
657
|
+
// the default row is one line plus a pixel - keep the same around the measured lines
|
|
658
|
+
row.height = maxHeight + table.defaultRowHeight - table.rowLineHeight;
|
|
588
659
|
if (rerender)
|
|
589
660
|
this.table.renderCells({ vertical: true });
|
|
590
661
|
}
|
|
@@ -592,6 +663,28 @@ export class GridRendering {
|
|
|
592
663
|
this.model.rows.forEach(row => this.autofitRow(row, visibleValuesOnly, false));
|
|
593
664
|
this.table.renderCells({ vertical: true });
|
|
594
665
|
}
|
|
666
|
+
/**
|
|
667
|
+
* Autofits `column` or, when the selection covers whole columns including it, all the selected columns (see autofitTargets).
|
|
668
|
+
* @returns the autofitted columns
|
|
669
|
+
*/
|
|
670
|
+
autofitColumnWithSelection(column) {
|
|
671
|
+
const range = this.grid.selection.range;
|
|
672
|
+
const columns = autofitTargets(column, this.model.visibleColumns, range.isColumn, range.c1, range.c2);
|
|
673
|
+
columns.forEach(col => this.autofitColumn(col, false, false));
|
|
674
|
+
this.table.renderCells({ horizontal: true });
|
|
675
|
+
return columns;
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Autofits `row` or, when the selection covers whole rows including it, all the selected rows (see autofitTargets).
|
|
679
|
+
* @returns the autofitted rows
|
|
680
|
+
*/
|
|
681
|
+
autofitRowWithSelection(row) {
|
|
682
|
+
const range = this.grid.selection.range;
|
|
683
|
+
const rows = autofitTargets(row, this.model.visibleRows, range.isRow, range.r1, range.r2);
|
|
684
|
+
rows.forEach(r => this.autofitRow(r, false, false));
|
|
685
|
+
this.table.renderCells({ vertical: true });
|
|
686
|
+
return rows;
|
|
687
|
+
}
|
|
595
688
|
scrollTo(r, c = 0) {
|
|
596
689
|
let range;
|
|
597
690
|
if (utils.isString(r))
|