@dxos/lit-grid 0.6.10-main.3cfcc89 → 0.6.10-main.bbdfaa4
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/lib/browser/index.mjs +134 -303
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/dx-grid.d.ts +10 -42
- package/dist/types/src/dx-grid.d.ts.map +1 -1
- package/dist/types/src/dx-grid.lit-stories.d.ts +4 -6
- package/dist/types/src/dx-grid.lit-stories.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/position.d.ts +18 -0
- package/dist/types/src/position.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/dx-grid.lit-stories.ts +7 -30
- package/src/dx-grid.pcss +10 -50
- package/src/dx-grid.ts +126 -353
- package/src/index.ts +1 -1
- package/src/position.ts +80 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/dx-grid.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { LitElement, html } from 'lit';\nimport { customElement, state, property } from 'lit/decorators.js';\nimport { ref, createRef, type Ref } from 'lit/directives/ref.js';\n\n/**\n * The size in pixels of the gap between cells\n */\nconst gap = 1;\n\n/**\n * This should be about the width of the `1` numeral so resize is triggered as the row header column’s intrinsic size\n * changes when scrolling vertically.\n */\nconst resizeTolerance = 8;\n\n//\n// `overscan` is the number of columns or rows to render outside of the viewport\n//\nconst overscanCol = 1;\nconst overscanRow = 1;\n\n//\n// `size`, when suffixed with ‘row’ or ‘col’, are limits on size applied when resizing\n//\nconst sizeColMin = 32;\nconst sizeColMax = 1024;\nconst sizeRowMin = 16;\nconst sizeRowMax = 1024;\n\n/**\n * Separator for serializing cell position vectors\n */\nconst separator = ',';\n\n//\n// A1 notation is the fallback for numbering columns and rows.\n//\n\nconst colToA1Notation = (col: number): string => {\n return (\n (col >= 26 ? String.fromCharCode('A'.charCodeAt(0) + Math.floor(col / 26) - 1) : '') +\n String.fromCharCode('A'.charCodeAt(0) + (col % 26))\n );\n};\n\nconst rowToA1Notation = (row: number): string => {\n return `${row + 1}`;\n};\n\nexport type CellValue = {\n /**\n * The content value\n */\n value: string;\n /**\n * If this is a merged cell, the bottomright-most of the range in numeric notation, otherwise undefined.\n */\n end?: string;\n /**\n * CSS inline styles to apply to the gridcell element\n */\n style?: string;\n};\n\ntype AxisMeta = {\n size: number;\n description?: string;\n resizeable?: boolean;\n};\n\nexport type DxGridProps = Pick<DxGrid, 'cells' | 'rows' | 'columns' | 'rowDefault' | 'columnDefault'>;\n\nconst localChId = (c0: number) => `ch--${c0}`;\nconst localRhId = (r0: number) => `rh--${r0}`;\n\nconst getPage = (axis: string, event: PointerEvent) => (axis === 'col' ? event.pageX : event.pageY);\n\n@customElement('dx-grid')\nexport class DxGrid extends LitElement {\n @property({ type: Object })\n rowDefault: AxisMeta = { size: 32 };\n\n @property({ type: Object })\n columnDefault: AxisMeta = { size: 180 };\n\n @property({ type: Object })\n rows: Record<string, AxisMeta> = {};\n\n @property({ type: Object })\n columns: Record<string, AxisMeta> = {};\n\n @property({ type: Object })\n cells: Record<string, CellValue> = {};\n\n //\n // `pos`, short for ‘position’, is the position in pixels of the viewport from the origin.\n //\n\n @state()\n posInline = 0;\n\n @state()\n posBlock = 0;\n\n //\n // `size` (when not suffixed with ‘row’ or ‘col’, see above) is the size in pixels of the viewport.\n //\n\n @state()\n sizeInline = 0;\n\n @state()\n sizeBlock = 0;\n\n //\n // `overscan` is the amount in pixels to offset the grid content due to the number of overscanned columns or rows.\n //\n\n @state()\n overscanInline = 0;\n\n @state()\n overscanBlock = 0;\n\n //\n // `bin`, not short for anything, is the range in pixels within which virtualization does not need to reassess.\n //\n\n @state()\n binInlineMin = 0;\n\n @state()\n binInlineMax = this.colSize(0);\n\n @state()\n binBlockMin = 0;\n\n @state()\n binBlockMax = this.rowSize(0);\n\n //\n // `vis`, short for ‘visible’, is the range in numeric index of the columns or rows which should be rendered within\n // the viewport. These start with naïve values that are updated before first contentful render.\n //\n\n @state()\n visColMin = 0;\n\n @state()\n visColMax = 1;\n\n @state()\n visRowMin = 0;\n\n @state()\n visRowMax = 1;\n\n //\n // `template` is the rendered value of `grid-{axis}-template`.\n //\n @state()\n templateColumns = `${this.colSize(0)}px`;\n\n @state()\n templateRows = `${this.rowSize(0)}px`;\n\n //\n // Resize state and handlers\n //\n\n @state()\n colSizes: Record<string, number> = {};\n\n @state()\n rowSizes: Record<string, number> = {};\n\n @state()\n resizing: null | { axis: 'col' | 'row'; page: number; size: number; index: string } = null;\n\n handlePointerDown = (event: PointerEvent) => {\n const actionEl = (event.target as HTMLElement)?.closest('[data-dx-grid-action]');\n const action = actionEl?.getAttribute('data-dx-grid-action');\n if (action) {\n if (action.startsWith('resize')) {\n const [resize, index] = action.split(',');\n const [_, axis] = resize.split('-');\n this.resizing = {\n axis: axis as 'col' | 'row',\n size: axis === 'col' ? this.colSize(index) : this.rowSize(index),\n page: getPage(axis, event),\n index,\n };\n }\n }\n };\n\n handlePointerUp = (_event: PointerEvent) => {\n this.resizing = null;\n };\n\n handlePointerMove = (event: PointerEvent) => {\n if (this.resizing) {\n const delta = getPage(this.resizing.axis, event) - this.resizing.page;\n if (this.resizing.axis === 'col') {\n const nextSize = Math.max(sizeColMin, Math.min(sizeColMax, this.resizing.size + delta));\n this.colSizes = { ...this.colSizes, [this.resizing.index]: nextSize };\n this.updateVisInline();\n } else {\n const nextSize = Math.max(sizeRowMin, Math.min(sizeRowMax, this.resizing.size + delta));\n this.rowSizes = { ...this.rowSizes, [this.resizing.index]: nextSize };\n this.updateVisBlock();\n }\n }\n };\n\n //\n // Accessors\n //\n\n private colSize(c: number | string) {\n return this.colSizes?.[c] ?? this.columnDefault.size;\n }\n\n private rowSize(r: number | string) {\n return this.rowSizes?.[r] ?? this.rowDefault.size;\n }\n\n private getCell(c: number | string, r: number | string) {\n return this.cells[`${c}${separator}${r}`];\n }\n\n //\n // Resize & reposition handlers, observer, ref\n //\n\n @state()\n observer = new ResizeObserver((entries) => {\n const { inlineSize, blockSize } = entries?.[0]?.contentBoxSize?.[0] ?? {\n inlineSize: 0,\n blockSize: 0,\n };\n if (\n Math.abs(inlineSize - this.sizeInline) > resizeTolerance ||\n Math.abs(blockSize - this.sizeBlock) > resizeTolerance\n ) {\n // console.info('[updating bounds]', 'resize', [inlineSize - this.sizeInline, blockSize - this.sizeBlock]);\n this.sizeInline = inlineSize;\n this.sizeBlock = blockSize;\n this.updateVis();\n }\n });\n\n viewportRef: Ref<HTMLDivElement> = createRef();\n\n handleWheel = ({ deltaX, deltaY }: WheelEvent) => {\n this.posInline = Math.max(0, this.posInline + deltaX);\n this.posBlock = Math.max(0, this.posBlock + deltaY);\n if (\n this.posInline >= this.binInlineMin &&\n this.posInline < this.binInlineMax &&\n this.posBlock >= this.binBlockMin &&\n this.posBlock < this.binBlockMax\n ) {\n // do nothing\n } else {\n // console.info(\n // '[updating bounds]',\n // 'wheel',\n // [this.binInlineMin, this.posInline, this.binInlineMax],\n // [this.binBlockMin, this.posBlock, this.binBlockMax],\n // );\n this.updateVis();\n }\n };\n\n private updateVisInline() {\n // todo: avoid starting from zero\n let colIndex = 0;\n let pxInline = this.colSize(colIndex);\n\n while (pxInline < this.posInline) {\n colIndex += 1;\n pxInline += this.colSize(colIndex) + gap;\n }\n\n this.visColMin = colIndex - overscanCol;\n\n this.binInlineMin = pxInline - this.colSize(colIndex) - gap;\n this.binInlineMax = pxInline + gap;\n\n this.overscanInline =\n [...Array(overscanCol)].reduce((acc, _, c0) => {\n acc += this.colSize(this.visColMin + c0);\n return acc;\n }, 0) +\n gap * (overscanCol - 1);\n\n while (pxInline < this.binInlineMax + this.sizeInline) {\n colIndex += 1;\n pxInline += this.colSize(colIndex) + gap;\n }\n\n this.visColMax = colIndex + overscanCol + 1;\n\n this.templateColumns = [...Array(this.visColMax - this.visColMin)]\n .map((_, c0) => `${this.colSize(this.visColMin + c0)}px`)\n .join(' ');\n }\n\n private updateVisBlock() {\n // todo: avoid starting from zero\n let rowIndex = 0;\n let pxBlock = this.rowSize(rowIndex);\n\n while (pxBlock < this.posBlock) {\n rowIndex += 1;\n pxBlock += this.rowSize(rowIndex) + gap;\n }\n\n this.visRowMin = rowIndex - overscanRow;\n\n this.binBlockMin = pxBlock - this.rowSize(rowIndex) - gap;\n this.binBlockMax = pxBlock + gap;\n\n this.overscanBlock =\n [...Array(overscanRow)].reduce((acc, _, r0) => {\n acc += this.rowSize(this.visRowMin + r0);\n return acc;\n }, 0) +\n gap * (overscanRow - 1);\n\n while (pxBlock < this.binBlockMax + this.sizeBlock) {\n rowIndex += 1;\n pxBlock += this.rowSize(rowIndex) + gap;\n }\n\n this.visRowMax = rowIndex + overscanRow + 1;\n\n this.templateRows = [...Array(this.visRowMax - this.visRowMin)]\n .map((_, r0) => `${this.rowSize(this.visRowMin + r0)}px`)\n .join(' ');\n }\n\n private updateVis() {\n this.updateVisInline();\n this.updateVisBlock();\n }\n\n //\n // Render and other lifecycle methods\n //\n\n override render() {\n const visibleCols = this.visColMax - this.visColMin;\n const visibleRows = this.visRowMax - this.visRowMin;\n // TODO NEXT -> ensure offset is using the right components\n const offsetInline = this.binInlineMin - this.posInline - this.overscanInline;\n const offsetBlock = this.binBlockMin - this.posBlock - this.overscanBlock;\n\n return html`<div\n role=\"none\"\n class=\"dx-grid\"\n @pointerdown=${this.handlePointerDown}\n @pointerup=${this.handlePointerUp}\n @pointermove=${this.handlePointerMove}\n >\n <div role=\"none\" class=\"dx-grid__corner\"></div>\n <div role=\"none\" class=\"dx-grid__columnheader\">\n <div\n role=\"none\"\n class=\"dx-grid__columnheader__content\"\n style=\"transform:translate3d(${offsetInline}px,0,0);grid-template-columns:${this.templateColumns};\"\n >\n ${[...Array(visibleCols)].map((_, c0) => {\n const c = this.visColMin + c0;\n return html`<div\n role=\"columnheader\"\n ?inert=${c < 0}\n style=\"inline-size:${this.colSize(c)}px;block-size:${this.rowDefault.size}px;grid-column:${c0 + 1}/${c0 +\n 2};\"\n >\n <span id=${localChId(c0)}>${colToA1Notation(c)}</span>\n ${(this.columns[c]?.resizeable ?? this.columnDefault.resizeable) &&\n html`<button class=\"dx-grid__resize-handle\" data-dx-grid-action=${`resize-col,${c}`}>\n <span class=\"sr-only\">Resize</span>\n </button>`}\n </div>`;\n })}\n </div>\n </div>\n <div role=\"none\" class=\"dx-grid__corner\"></div>\n <div role=\"none\" class=\"dx-grid__rowheader\">\n <div role=\"none\" class=\"dx-grid__rowheader__content\" style=\"transform:translate3d(0,${offsetBlock}px,0);\">\n ${[...Array(visibleRows)].map((_, r0) => {\n const r = this.visRowMin + r0;\n return html`<div\n role=\"rowheader\"\n ?inert=${r < 0}\n style=\"block-size:${this.rowSize(r)}px;grid-row:${r0 + 1}/${r0 + 2}\"\n >\n <span id=${localRhId(r0)}>${rowToA1Notation(r)}</span>\n ${(this.rows[r]?.resizeable ?? this.rowDefault.resizeable) &&\n html`<button class=\"dx-grid__resize-handle\" data-dx-grid-action=${`resize-row,${r}`}>\n <span class=\"sr-only\">Resize</span>\n </button>`}\n </div>`;\n })}\n </div>\n </div>\n <div role=\"none\" class=\"dx-grid__viewport\" @wheel=\"${this.handleWheel}\" ${ref(this.viewportRef)}>\n <div\n role=\"grid\"\n class=\"dx-grid__content\"\n style=\"transform:translate3d(${offsetInline}px,${offsetBlock}px,0);grid-template-columns:${this\n .templateColumns};grid-template-rows:${this.templateRows};\"\n >\n ${[...Array(visibleCols)].map((_, c0) => {\n return [...Array(visibleRows)].map((_, r0) => {\n const c = c0 + this.visColMin;\n const r = r0 + this.visRowMin;\n const cell = this.getCell(c, r);\n return html`<div\n role=\"gridcell\"\n ?inert=${c < 0 || r < 0}\n aria-rowindex=${r}\n aria-colindex=${c}\n data-dx-grid-action=\"cell\"\n style=\"grid-column:${c0 + 1};grid-row:${r0 + 1}\"\n >\n ${cell?.value}\n </div>`;\n });\n })}\n </div>\n </div>\n <div role=\"none\" class=\"dx-grid__scrollbar\" aria-orientation=\"vertical\">\n <div role=\"none\" class=\"dx-grid__scrollbar__thumb\"></div>\n </div>\n <div role=\"none\" class=\"dx-grid__corner\"></div>\n <div role=\"none\" class=\"dx-grid__scrollbar\" aria-orientation=\"horizontal\">\n <div role=\"none\" class=\"dx-grid__scrollbar__thumb\"></div>\n </div>\n <div role=\"none\" class=\"dx-grid__corner\"></div>\n </div>`;\n }\n\n override firstUpdated() {\n this.observer.observe(this.viewportRef.value!);\n this.colSizes = Object.entries(this.columns).reduce((acc: Record<string, number>, [colId, colMeta]) => {\n if (colMeta?.size) {\n acc[colId] = colMeta.size;\n }\n return acc;\n }, {});\n this.rowSizes = Object.entries(this.rows).reduce((acc: Record<string, number>, [rowId, rowMeta]) => {\n if (rowMeta?.size) {\n acc[rowId] = rowMeta.size;\n }\n return acc;\n }, {});\n }\n\n override disconnectedCallback() {\n super.disconnectedCallback();\n // console.log('[disconnected]', this.viewportRef.value);\n // TODO(thure): Will this even work?\n if (this.viewportRef.value) {\n this.observer.unobserve(this.viewportRef.value);\n }\n }\n\n override createRenderRoot() {\n return this;\n }\n}\n"],
|
|
5
|
-
"mappings": ";AAIA,SAASA,YAAYC,
|
|
6
|
-
"names": ["LitElement", "html", "customElement", "state", "property", "ref", "createRef", "
|
|
3
|
+
"sources": ["../../../src/dx-grid.ts", "../../../src/position.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { LitElement, html, type PropertyValues } from 'lit';\nimport { customElement, state, property } from 'lit/decorators.js';\nimport { ref, createRef, type Ref } from 'lit/directives/ref.js';\n\nimport { colToA1Notation, posFromNumericNotation, rowToA1Notation } from './position';\n\nconst colSize = 64;\n\nconst rowSize = 20;\n\nconst gap = 0;\n\nexport type CellValue = {\n /**\n * The position (or topleft-most of the range) in numeric notation\n */\n pos: string;\n /**\n * The content value\n */\n value: string;\n /**\n * If this is a merged cell, the bottomright-most of the range in numeric notation, otherwise undefined.\n */\n end?: string;\n /**\n * CSS inline styles to apply to the gridcell element\n */\n style?: string;\n};\n\n@customElement('dx-grid')\nexport class DxGrid extends LitElement {\n @property({ type: Object })\n values: Record<string, CellValue> = {};\n\n @state()\n posInline = 0;\n\n @state()\n posBlock = 0;\n\n @state()\n sizeInline = 0;\n\n @state()\n sizeBlock = 0;\n\n @state()\n cellByPosition: Record<string, string> = {};\n\n @state()\n observer = new ResizeObserver((entries) => {\n const { inlineSize, blockSize } = entries?.[0]?.contentBoxSize?.[0] ?? {\n inlineSize: 0,\n blockSize: 0,\n };\n this.sizeInline = inlineSize;\n this.sizeBlock = blockSize;\n });\n\n viewportRef: Ref<HTMLDivElement> = createRef();\n\n handleWheel = ({ deltaX, deltaY }: WheelEvent) => {\n this.posInline = Math.max(0, this.posInline + deltaX);\n this.posBlock = Math.max(0, this.posBlock + deltaY);\n };\n\n override willUpdate(changed: PropertyValues<this>) {\n if (changed.has('values')) {\n // console.log('[computing cellByPosition]');\n this.cellByPosition = Object.entries(this.values).reduce((acc: Record<string, string>, [id, { pos, end }]) => {\n const { i: i1, j: j1 } = posFromNumericNotation(pos);\n if (end) {\n const { i: i2, j: j2 } = posFromNumericNotation(end);\n for (let ci = i1; ci <= i2; ci += 1) {\n for (let cj = j1; cj <= j2; cj += 1) {\n acc[`${ci},${cj}`] = id;\n }\n }\n } else {\n acc[`${i1},${j1}`] = id;\n }\n return acc;\n }, {});\n }\n }\n\n private getCell(i: number, j: number) {\n const pos = `${i},${j}`;\n const cellId = this.cellByPosition[pos];\n return cellId ? this.values[cellId] : undefined;\n }\n\n private computeExtrema() {\n const colVisMin = Math.floor(this.posInline / (colSize + gap));\n const colVisMax = Math.ceil((this.sizeInline + this.posInline) / (colSize + gap));\n\n const rowVisMin = Math.floor(this.posBlock / (rowSize + gap));\n const rowVisMax = Math.ceil((this.sizeBlock + this.posBlock) / (rowSize + gap));\n\n const { colExtMin, colExtMax } = [...Array(rowVisMax - rowVisMin)].reduce(\n (acc, _, j) => {\n const colVisMinCell = this.getCell(colVisMin, j + rowVisMin);\n if (colVisMinCell?.end) {\n const { i: iStart } = posFromNumericNotation(colVisMinCell.pos);\n acc.colExtMin = Math.min(acc.colExtMin, iStart);\n }\n const colVisMaxCell = this.getCell(colVisMax, j + rowVisMin);\n if (colVisMaxCell?.end) {\n const { i: iEnd } = posFromNumericNotation(colVisMaxCell.end);\n acc.colExtMax = Math.max(acc.colExtMax, iEnd);\n }\n return acc;\n },\n { colExtMin: colVisMin, colExtMax: colVisMax },\n );\n\n const { rowExtMin, rowExtMax } = [...Array(colVisMax - colVisMin)].reduce(\n (acc, _, i) => {\n const rowVisMinCell = this.getCell(i + colVisMin, rowVisMin);\n if (rowVisMinCell?.end) {\n const { j: jStart } = posFromNumericNotation(rowVisMinCell.pos);\n acc.rowExtMin = Math.min(acc.rowExtMin, jStart);\n }\n const rowVisMaxCell = this.getCell(i + colVisMin, rowVisMax);\n if (rowVisMaxCell?.end) {\n const { j: jEnd } = posFromNumericNotation(rowVisMaxCell.end);\n acc.rowExtMax = Math.max(acc.rowExtMax, jEnd);\n }\n return acc;\n },\n { rowExtMin: rowVisMin, rowExtMax: rowVisMax },\n );\n\n return {\n colVisMin,\n colExtMin,\n colVisMax,\n colExtMax,\n rowVisMin,\n rowExtMin,\n rowVisMax,\n rowExtMax,\n };\n }\n\n override render() {\n const { colVisMin, colVisMax, rowVisMin, rowVisMax } = this.computeExtrema();\n\n const visibleCols = colVisMax - colVisMin;\n const visibleRows = rowVisMax - rowVisMin;\n\n // TODO(thure): now compute the offset based on the extrema.\n const offsetInline = colVisMin * colSize - this.posInline;\n const offsetBlock = rowVisMin * rowSize - this.posBlock;\n\n return html`<div role=\"none\" class=\"dx-grid\">\n <div role=\"none\" class=\"dx-grid__corner\"></div>\n <div role=\"none\" class=\"dx-grid__columnheader\">\n <div\n role=\"none\"\n class=\"dx-grid__columnheader__content\"\n style=\"transform:translate3d(${offsetInline}px,0,0);grid-template-columns:repeat(${visibleCols},${colSize}px);\"\n >\n ${[...Array(visibleCols)].map((_, i) => {\n return html`<div\n role=\"gridcell\"\n style=\"inline-size:${colSize}px;block-size:${rowSize}px;grid-column:${i + 1}/${i + 2};\"\n >\n ${colToA1Notation(colVisMin + i)}\n </div>`;\n })}\n </div>\n </div>\n <div role=\"none\" class=\"dx-grid__corner\"></div>\n <div role=\"none\" class=\"dx-grid__rowheader\">\n <div role=\"none\" class=\"dx-grid__rowheader__content\" style=\"transform:translate3d(0,${offsetBlock}px,0);\">\n ${[...Array(visibleRows)].map((_, j) => {\n return html`<div role=\"gridcell\" style=\"block-size:${rowSize}px;grid-row:${j + 1}/${j + 2}\">\n ${rowToA1Notation(rowVisMin + j)}\n </div>`;\n })}\n </div>\n </div>\n <div role=\"none\" class=\"dx-grid__viewport\" @wheel=\"${this.handleWheel}\" ${ref(this.viewportRef)}>\n <div\n role=\"grid\"\n class=\"dx-grid__content\"\n style=\"transform:translate3d(${offsetInline}px,${offsetBlock}px,0);grid-template-columns:repeat(${visibleCols},${colSize}px);grid-template-rows:repeat(${visibleRows},${rowSize}px);\"\n >\n ${[...Array(visibleCols)].map((_, i) => {\n return [...Array(visibleRows)].map((_, j) => {\n const posAbs = `${i + colVisMin},${j + rowVisMin}`;\n const cellId = this.cellByPosition[posAbs];\n const cell = cellId ? this.values[cellId] : undefined;\n if (cell?.end) {\n // This is a merged cell\n if (posAbs !== cell?.pos) {\n // Don’t render subcells within the merge if not at the start (probably)\n return null;\n } else {\n // Render the full merged cell\n const { i: iEndAbs, j: jEndAbs } = posFromNumericNotation(cell.end);\n return html`<div\n role=\"gridcell\"\n style=\"grid-column:${i + 1} / ${iEndAbs - colVisMin + 2};grid-row:${j + 1} / ${jEndAbs -\n rowVisMin +\n 2}\"\n >\n ${cell?.value}\n </div>`;\n }\n } else {\n return html`<div role=\"gridcell\" style=\"grid-column:${i + 1};grid-row:${j + 1}\">${cell?.value}</div>`;\n }\n });\n })}\n </div>\n </div>\n <div role=\"none\" class=\"dx-grid__scrollbar\" aria-orientation=\"vertical\">\n <div role=\"none\" class=\"dx-grid__scrollbar__thumb\"></div>\n </div>\n <div role=\"none\" class=\"dx-grid__corner\"></div>\n <div role=\"none\" class=\"dx-grid__scrollbar\" aria-orientation=\"horizontal\">\n <div role=\"none\" class=\"dx-grid__scrollbar__thumb\"></div>\n </div>\n <div role=\"none\" class=\"dx-grid__corner\"></div>\n </div>`;\n }\n\n override firstUpdated() {\n this.observer.observe(this.viewportRef.value!);\n }\n\n override disconnectedCallback() {\n super.disconnectedCallback();\n // console.log('[disconnected]', this.viewportRef.value);\n // TODO(thure): Will this even work?\n if (this.viewportRef.value) {\n this.observer.unobserve(this.viewportRef.value);\n }\n }\n\n override createRenderRoot() {\n return this;\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nexport type CellPosition = { i: number; j: number };\n\nexport type CellRange = { from: CellPosition; to?: CellPosition };\n\nexport const posEquals = (a: CellPosition | undefined, b: CellPosition | undefined) => a?.i === b?.i && a?.j === b?.j;\n\nexport const colToA1Notation = (column: number): string => {\n return (\n (column >= 26 ? String.fromCharCode('A'.charCodeAt(0) + Math.floor(column / 26) - 1) : '') +\n String.fromCharCode('A'.charCodeAt(0) + (column % 26))\n );\n};\n\nexport const rowToA1Notation = (row: number): string => {\n return `${row + 1}`;\n};\n\nexport const posToA1Notation = (column: number, row: number): string => {\n const columnA1 = colToA1Notation(column);\n const rowA1 = rowToA1Notation(row);\n return `${columnA1}${rowA1}`;\n};\n\nexport const posFromA1Notation = (notation: string): CellPosition => {\n const match = notation.match(/([A-Z]+)(\\d+)/);\n if (!match) {\n throw Error('[posFromA1Notation] No match.');\n }\n const column = match[1].split('').reduce((acc, c) => acc * 26 + c.charCodeAt(0) - 'A'.charCodeAt(0) + 1, 0) - 1;\n const row = parseInt(match[2], 10) - 1;\n return { i: column, j: row };\n};\n\nexport const posFromNumericNotation = (notation: string): CellPosition => {\n const [iStr, jStr] = notation.split(',');\n if (!iStr || !jStr) {\n throw Error('[posFromNumericNotation] Bad input');\n }\n return { i: parseInt(iStr), j: parseInt(jStr) };\n};\n\nexport const rangeToA1Notation = (range: CellRange) =>\n [range?.from && posToA1Notation(range?.from.i, range?.from.j), range?.to && posToA1Notation(range?.to.i, range.to.j)]\n .filter(Boolean)\n .join(':');\n\nexport const rangeFromA1Notation = (notation: string): CellRange => {\n const [from, to] = notation.split(':').map(posFromA1Notation);\n return { from, to };\n};\n\nexport const inRange = (range: CellRange | undefined, pos: CellPosition): boolean => {\n if (!range) {\n return false;\n }\n\n const { from, to } = range;\n if ((from && posEquals(from, pos)) || (to && posEquals(to, pos))) {\n return true;\n }\n\n if (!from || !to) {\n return false;\n }\n\n const { i, j } = pos;\n\n const { i: c1, j: r1 } = from;\n const { i: c2, j: r2 } = to;\n const cMin = Math.min(c1, c2);\n const cMax = Math.max(c1, c2);\n const rMin = Math.min(r1, r2);\n const rMax = Math.max(r1, r2);\n\n return i >= cMin && i <= cMax && j >= rMin && j <= rMax;\n};\n"],
|
|
5
|
+
"mappings": ";AAIA,SAASA,YAAYC,YAAiC;AACtD,SAASC,eAAeC,OAAOC,gBAAgB;AAC/C,SAASC,KAAKC,iBAA2B;;;ACIlC,IAAMC,kBAAkB,CAACC,WAAAA;AAC9B,UACGA,UAAU,KAAKC,OAAOC,aAAa,IAAIC,WAAW,CAAA,IAAKC,KAAKC,MAAML,SAAS,EAAA,IAAM,CAAA,IAAK,MACvFC,OAAOC,aAAa,IAAIC,WAAW,CAAA,IAAMH,SAAS,EAAA;AAEtD;AAEO,IAAMM,kBAAkB,CAACC,QAAAA;AAC9B,SAAO,GAAGA,MAAM,CAAA;AAClB;AAkBO,IAAMC,yBAAyB,CAACC,aAAAA;AACrC,QAAM,CAACC,MAAMC,IAAAA,IAAQF,SAASG,MAAM,GAAA;AACpC,MAAI,CAACF,QAAQ,CAACC,MAAM;AAClB,UAAME,MAAM,oCAAA;EACd;AACA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AMA,qBAAAA;AAGN,QAAI,KAAKnE,YAAYgE,OAAO;AAC1B,WAAKtE,SAAS0E,UAAU,KAAKpE,YAAYgE,KAAK;IAChD;EACF;EAESK,mBAAmB;AAC1B,WAAO;EACT;AACF;;EAtNGC,SAAS;IAAEC,MAAM7D;EAAO,CAAA;GADdxB,OAAAA,WAAAA,UAAAA,MAAAA;;EAIVsF,MAAAA;GAJUtF,OAAAA,WAAAA,aAAAA,MAAAA;;EAOVsF,MAAAA;GAPUtF,OAAAA,WAAAA,YAAAA,MAAAA;;EAUVsF,MAAAA;GAVUtF,OAAAA,WAAAA,cAAAA,MAAAA;;EAaVsF,MAAAA;GAbUtF,OAAAA,WAAAA,aAAAA,MAAAA;;EAgBVsF,MAAAA;GAhBUtF,OAAAA,WAAAA,kBAAAA,MAAAA;;EAmBVsF,MAAAA;GAnBUtF,OAAAA,WAAAA,YAAAA,MAAAA;AAAAA,SAAAA,aAAAA;EADZuF,cAAc,SAAA;GACFvF,MAAAA;",
|
|
6
|
+
"names": ["LitElement", "html", "customElement", "state", "property", "ref", "createRef", "colToA1Notation", "column", "String", "fromCharCode", "charCodeAt", "Math", "floor", "rowToA1Notation", "row", "posFromNumericNotation", "notation", "iStr", "jStr", "split", "Error", "i", "parseInt", "j", "colSize", "rowSize", "gap", "DxGrid", "LitElement", "values", "posInline", "posBlock", "sizeInline", "sizeBlock", "cellByPosition", "observer", "ResizeObserver", "entries", "inlineSize", "blockSize", "contentBoxSize", "viewportRef", "createRef", "handleWheel", "deltaX", "deltaY", "Math", "max", "willUpdate", "changed", "has", "Object", "reduce", "acc", "id", "pos", "end", "i", "i1", "j", "j1", "posFromNumericNotation", "i2", "j2", "ci", "cj", "getCell", "cellId", "undefined", "computeExtrema", "colVisMin", "floor", "colVisMax", "ceil", "rowVisMin", "rowVisMax", "colExtMin", "colExtMax", "Array", "_", "colVisMinCell", "iStart", "min", "colVisMaxCell", "iEnd", "rowExtMin", "rowExtMax", "rowVisMinCell", "jStart", "rowVisMaxCell", "jEnd", "render", "visibleCols", "visibleRows", "offsetInline", "offsetBlock", "html", "map", "colToA1Notation", "rowToA1Notation", "ref", "posAbs", "cell", "iEndAbs", "jEndAbs", "value", "firstUpdated", "observe", "disconnectedCallback", "unobserve", "createRenderRoot", "property", "type", "state", "customElement"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/ui/lit-grid/src/dx-grid.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/ui/lit-grid/src/position.ts":{"bytes":9203,"imports":[],"format":"esm"},"packages/ui/lit-grid/src/dx-grid.ts":{"bytes":30216,"imports":[{"path":"lit","kind":"import-statement","external":true},{"path":"lit/decorators.js","kind":"import-statement","external":true},{"path":"lit/directives/ref.js","kind":"import-statement","external":true},{"path":"packages/ui/lit-grid/src/position.ts","kind":"import-statement","original":"./position"}],"format":"esm"},"packages/ui/lit-grid/src/index.ts":{"bytes":536,"imports":[{"path":"packages/ui/lit-grid/src/dx-grid.ts","kind":"import-statement","original":"./dx-grid"}],"format":"esm"}},"outputs":{"packages/ui/lit-grid/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":17859},"packages/ui/lit-grid/dist/lib/browser/index.mjs":{"imports":[{"path":"lit","kind":"import-statement","external":true},{"path":"lit/decorators.js","kind":"import-statement","external":true},{"path":"lit/directives/ref.js","kind":"import-statement","external":true}],"exports":["DxGrid"],"entryPoint":"packages/ui/lit-grid/src/index.ts","inputs":{"packages/ui/lit-grid/src/dx-grid.ts":{"bytesInOutput":8155},"packages/ui/lit-grid/src/position.ts":{"bytesInOutput":490},"packages/ui/lit-grid/src/index.ts":{"bytesInOutput":0}},"bytes":8821}}}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { LitElement } from 'lit';
|
|
1
|
+
import { LitElement, type PropertyValues } from 'lit';
|
|
2
2
|
import { type Ref } from 'lit/directives/ref.js';
|
|
3
3
|
export type CellValue = {
|
|
4
|
+
/**
|
|
5
|
+
* The position (or topleft-most of the range) in numeric notation
|
|
6
|
+
*/
|
|
7
|
+
pos: string;
|
|
4
8
|
/**
|
|
5
9
|
* The content value
|
|
6
10
|
*/
|
|
@@ -14,58 +18,22 @@ export type CellValue = {
|
|
|
14
18
|
*/
|
|
15
19
|
style?: string;
|
|
16
20
|
};
|
|
17
|
-
type AxisMeta = {
|
|
18
|
-
size: number;
|
|
19
|
-
description?: string;
|
|
20
|
-
resizeable?: boolean;
|
|
21
|
-
};
|
|
22
|
-
export type DxGridProps = Pick<DxGrid, 'cells' | 'rows' | 'columns' | 'rowDefault' | 'columnDefault'>;
|
|
23
21
|
export declare class DxGrid extends LitElement {
|
|
24
|
-
|
|
25
|
-
columnDefault: AxisMeta;
|
|
26
|
-
rows: Record<string, AxisMeta>;
|
|
27
|
-
columns: Record<string, AxisMeta>;
|
|
28
|
-
cells: Record<string, CellValue>;
|
|
22
|
+
values: Record<string, CellValue>;
|
|
29
23
|
posInline: number;
|
|
30
24
|
posBlock: number;
|
|
31
25
|
sizeInline: number;
|
|
32
26
|
sizeBlock: number;
|
|
33
|
-
|
|
34
|
-
overscanBlock: number;
|
|
35
|
-
binInlineMin: number;
|
|
36
|
-
binInlineMax: number;
|
|
37
|
-
binBlockMin: number;
|
|
38
|
-
binBlockMax: number;
|
|
39
|
-
visColMin: number;
|
|
40
|
-
visColMax: number;
|
|
41
|
-
visRowMin: number;
|
|
42
|
-
visRowMax: number;
|
|
43
|
-
templateColumns: string;
|
|
44
|
-
templateRows: string;
|
|
45
|
-
colSizes: Record<string, number>;
|
|
46
|
-
rowSizes: Record<string, number>;
|
|
47
|
-
resizing: null | {
|
|
48
|
-
axis: 'col' | 'row';
|
|
49
|
-
page: number;
|
|
50
|
-
size: number;
|
|
51
|
-
index: string;
|
|
52
|
-
};
|
|
53
|
-
handlePointerDown: (event: PointerEvent) => void;
|
|
54
|
-
handlePointerUp: (_event: PointerEvent) => void;
|
|
55
|
-
handlePointerMove: (event: PointerEvent) => void;
|
|
56
|
-
private colSize;
|
|
57
|
-
private rowSize;
|
|
58
|
-
private getCell;
|
|
27
|
+
cellByPosition: Record<string, string>;
|
|
59
28
|
observer: ResizeObserver;
|
|
60
29
|
viewportRef: Ref<HTMLDivElement>;
|
|
61
30
|
handleWheel: ({ deltaX, deltaY }: WheelEvent) => void;
|
|
62
|
-
|
|
63
|
-
private
|
|
64
|
-
private
|
|
31
|
+
willUpdate(changed: PropertyValues<this>): void;
|
|
32
|
+
private getCell;
|
|
33
|
+
private computeExtrema;
|
|
65
34
|
render(): import("lit").TemplateResult<1>;
|
|
66
35
|
firstUpdated(): void;
|
|
67
36
|
disconnectedCallback(): void;
|
|
68
37
|
createRenderRoot(): this;
|
|
69
38
|
}
|
|
70
|
-
export {};
|
|
71
39
|
//# sourceMappingURL=dx-grid.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dx-grid.d.ts","sourceRoot":"","sources":["../../../src/dx-grid.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAQ,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"dx-grid.d.ts","sourceRoot":"","sources":["../../../src/dx-grid.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAQ,KAAK,cAAc,EAAE,MAAM,KAAK,CAAC;AAE5D,OAAO,EAAkB,KAAK,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAUjE,MAAM,MAAM,SAAS,GAAG;IACtB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,qBACa,MAAO,SAAQ,UAAU;IAEpC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAM;IAGvC,SAAS,SAAK;IAGd,QAAQ,SAAK;IAGb,UAAU,SAAK;IAGf,SAAS,SAAK;IAGd,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM;IAG5C,QAAQ,iBAOL;IAEH,WAAW,EAAE,GAAG,CAAC,cAAc,CAAC,CAAe;IAE/C,WAAW,uBAAwB,UAAU,UAG3C;IAEO,UAAU,CAAC,OAAO,EAAE,cAAc,CAAC,IAAI,CAAC;IAoBjD,OAAO,CAAC,OAAO;IAMf,OAAO,CAAC,cAAc;IAqDb,MAAM;IAoFN,YAAY;IAIZ,oBAAoB;IASpB,gBAAgB;CAG1B"}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import './dx-grid.ts';
|
|
2
2
|
import './dx-grid.pcss';
|
|
3
|
-
import { type DxGridProps } from './dx-grid';
|
|
4
3
|
declare const _default: {
|
|
5
4
|
title: string;
|
|
6
5
|
};
|
|
7
6
|
export default _default;
|
|
8
7
|
export declare const Basic: {
|
|
9
|
-
(
|
|
8
|
+
({ values }: {
|
|
9
|
+
values: string;
|
|
10
|
+
}): import("lit").TemplateResult<1>;
|
|
10
11
|
args: {
|
|
11
|
-
|
|
12
|
-
columnDefault: string;
|
|
13
|
-
rowDefault: string;
|
|
14
|
-
columns: string;
|
|
12
|
+
values: string;
|
|
15
13
|
};
|
|
16
14
|
};
|
|
17
15
|
//# sourceMappingURL=dx-grid.lit-stories.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dx-grid.lit-stories.d.ts","sourceRoot":"","sources":["../../../src/dx-grid.lit-stories.ts"],"names":[],"mappings":"AAIA,OAAO,cAAc,CAAC;AACtB,OAAO,gBAAgB,CAAC
|
|
1
|
+
{"version":3,"file":"dx-grid.lit-stories.d.ts","sourceRoot":"","sources":["../../../src/dx-grid.lit-stories.ts"],"names":[],"mappings":"AAIA,OAAO,cAAc,CAAC;AACtB,OAAO,gBAAgB,CAAC;;;;AAIxB,wBAEE;AAEF,eAAO,MAAM,KAAK;iBAAgB;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE;;;;CAAiD,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { DxGrid
|
|
1
|
+
export { DxGrid } from './dx-grid';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type CellPosition = {
|
|
2
|
+
i: number;
|
|
3
|
+
j: number;
|
|
4
|
+
};
|
|
5
|
+
export type CellRange = {
|
|
6
|
+
from: CellPosition;
|
|
7
|
+
to?: CellPosition;
|
|
8
|
+
};
|
|
9
|
+
export declare const posEquals: (a: CellPosition | undefined, b: CellPosition | undefined) => boolean;
|
|
10
|
+
export declare const colToA1Notation: (column: number) => string;
|
|
11
|
+
export declare const rowToA1Notation: (row: number) => string;
|
|
12
|
+
export declare const posToA1Notation: (column: number, row: number) => string;
|
|
13
|
+
export declare const posFromA1Notation: (notation: string) => CellPosition;
|
|
14
|
+
export declare const posFromNumericNotation: (notation: string) => CellPosition;
|
|
15
|
+
export declare const rangeToA1Notation: (range: CellRange) => string;
|
|
16
|
+
export declare const rangeFromA1Notation: (notation: string) => CellRange;
|
|
17
|
+
export declare const inRange: (range: CellRange | undefined, pos: CellPosition) => boolean;
|
|
18
|
+
//# sourceMappingURL=position.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"position.d.ts","sourceRoot":"","sources":["../../../src/position.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,YAAY,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpD,MAAM,MAAM,SAAS,GAAG;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,EAAE,CAAC,EAAE,YAAY,CAAA;CAAE,CAAC;AAElE,eAAO,MAAM,SAAS,MAAO,YAAY,GAAG,SAAS,KAAK,YAAY,GAAG,SAAS,YAAmC,CAAC;AAEtH,eAAO,MAAM,eAAe,WAAY,MAAM,KAAG,MAKhD,CAAC;AAEF,eAAO,MAAM,eAAe,QAAS,MAAM,KAAG,MAE7C,CAAC;AAEF,eAAO,MAAM,eAAe,WAAY,MAAM,OAAO,MAAM,KAAG,MAI7D,CAAC;AAEF,eAAO,MAAM,iBAAiB,aAAc,MAAM,KAAG,YAQpD,CAAC;AAEF,eAAO,MAAM,sBAAsB,aAAc,MAAM,KAAG,YAMzD,CAAC;AAEF,eAAO,MAAM,iBAAiB,UAAW,SAAS,WAGpC,CAAC;AAEf,eAAO,MAAM,mBAAmB,aAAc,MAAM,KAAG,SAGtD,CAAC;AAEF,eAAO,MAAM,OAAO,UAAW,SAAS,GAAG,SAAS,OAAO,YAAY,KAAG,OAwBzE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/lit-grid",
|
|
3
|
-
"version": "0.6.10-main.
|
|
3
|
+
"version": "0.6.10-main.bbdfaa4",
|
|
4
4
|
"description": "A grid webcomponent using Lit",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
"author": "DXOS.org",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"
|
|
11
|
+
"import": "./dist/esm/index.js",
|
|
12
|
+
"require": "./dist/cjs/index.cjs",
|
|
12
13
|
"types": "./dist/types/src/index.d.ts"
|
|
13
|
-
}
|
|
14
|
-
"./dx-grid.pcss": "./src/dx-grid.pcss"
|
|
14
|
+
}
|
|
15
15
|
},
|
|
16
16
|
"main": "src/index.ts",
|
|
17
17
|
"files": [
|
|
@@ -5,43 +5,20 @@
|
|
|
5
5
|
import './dx-grid.ts';
|
|
6
6
|
import './dx-grid.pcss';
|
|
7
7
|
|
|
8
|
-
import { html
|
|
9
|
-
|
|
10
|
-
import { type DxGridProps } from './dx-grid';
|
|
8
|
+
import { html } from 'lit';
|
|
11
9
|
|
|
12
10
|
export default {
|
|
13
11
|
title: 'dx-grid',
|
|
14
12
|
};
|
|
15
13
|
|
|
16
|
-
export const Basic = (
|
|
17
|
-
return html`<dx-grid
|
|
18
|
-
cells=${props.cells ?? nothing}
|
|
19
|
-
columnDefault=${props.columnDefault ?? nothing}
|
|
20
|
-
rowDefault=${props.rowDefault ?? nothing}
|
|
21
|
-
columns=${props.columns ?? nothing}
|
|
22
|
-
></dx-grid>`;
|
|
23
|
-
};
|
|
14
|
+
export const Basic = ({ values }: { values: string }) => html`<dx-grid values="${values}"></dx-grid>`;
|
|
24
15
|
|
|
25
16
|
Basic.args = {
|
|
26
|
-
|
|
27
|
-
'
|
|
28
|
-
|
|
17
|
+
values: JSON.stringify({
|
|
18
|
+
':g1': {
|
|
19
|
+
pos: '1,1',
|
|
20
|
+
end: '8,1',
|
|
29
21
|
value: 'Weekly sales report',
|
|
30
22
|
},
|
|
31
|
-
}
|
|
32
|
-
columnDefault: JSON.stringify({
|
|
33
|
-
size: 180,
|
|
34
|
-
resizeable: true,
|
|
35
|
-
} satisfies DxGridProps['columnDefault']),
|
|
36
|
-
rowDefault: JSON.stringify({
|
|
37
|
-
size: 32,
|
|
38
|
-
resizeable: true,
|
|
39
|
-
} satisfies DxGridProps['rowDefault']),
|
|
40
|
-
columns: JSON.stringify({
|
|
41
|
-
0: { size: 200 },
|
|
42
|
-
1: { size: 210 },
|
|
43
|
-
2: { size: 230 },
|
|
44
|
-
3: { size: 250 },
|
|
45
|
-
4: { size: 270 },
|
|
46
|
-
} satisfies DxGridProps['columns']),
|
|
23
|
+
}),
|
|
47
24
|
};
|
package/src/dx-grid.pcss
CHANGED
|
@@ -2,25 +2,12 @@ dx-grid {
|
|
|
2
2
|
display: contents;
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
.sr-only {
|
|
6
|
-
position: absolute;
|
|
7
|
-
width: 1px;
|
|
8
|
-
height: 1px;
|
|
9
|
-
padding: 0;
|
|
10
|
-
margin: -1px;
|
|
11
|
-
overflow: hidden;
|
|
12
|
-
clip: rect(0, 0, 0, 0);
|
|
13
|
-
white-space: nowrap;
|
|
14
|
-
border-width: 0;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
5
|
.dx-grid {
|
|
18
6
|
position: fixed;
|
|
19
7
|
inset: 0;
|
|
20
8
|
display: grid;
|
|
21
9
|
grid-template-columns: min-content 1fr min-content;
|
|
22
10
|
grid-template-rows: min-content 1fr min-content;
|
|
23
|
-
font-variant-numeric: tabular-nums;
|
|
24
11
|
}
|
|
25
12
|
|
|
26
13
|
.dx-grid__scrollbar__thumb {
|
|
@@ -51,51 +38,24 @@ dx-grid {
|
|
|
51
38
|
}
|
|
52
39
|
|
|
53
40
|
.dx-grid__columnheader__content {
|
|
54
|
-
|
|
41
|
+
padding-inline: 1px;
|
|
55
42
|
grid-template-columns: repeat(99, 64px);
|
|
56
43
|
}
|
|
57
44
|
|
|
58
45
|
.dx-grid__rowheader__content {
|
|
59
|
-
|
|
46
|
+
padding-block: 1px;
|
|
60
47
|
grid-template-columns: min-content;
|
|
61
48
|
text-align: end;
|
|
62
49
|
}
|
|
63
50
|
|
|
64
|
-
.dx-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
box-sizing: border-box;
|
|
69
|
-
&[inert] {
|
|
70
|
-
visibility: hidden;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
.dx-grid__columnheader__content,
|
|
76
|
-
.dx-grid__rowheader__content {
|
|
77
|
-
& > [role='columnheader'], &> [role='rowheader'] {
|
|
78
|
-
position: relative;
|
|
79
|
-
& > button.dx-grid__resize-handle {
|
|
80
|
-
position: absolute;
|
|
81
|
-
background: transparent;
|
|
82
|
-
&:hover {
|
|
83
|
-
background: var(--dx-hoverSurface)
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
51
|
+
.dx-grid__content {
|
|
52
|
+
padding: 1px;
|
|
53
|
+
grid-template-columns: repeat(99, 64px);
|
|
54
|
+
grid-template-rows: repeat(99, 20px);
|
|
87
55
|
}
|
|
88
56
|
|
|
89
|
-
.dx-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
cursor: col-resize;
|
|
57
|
+
.dx-grid [role='gridcell'] {
|
|
58
|
+
background: var(--dx-base);
|
|
59
|
+
padding: 1px;
|
|
60
|
+
box-sizing: border-box;
|
|
94
61
|
}
|
|
95
|
-
|
|
96
|
-
.dx-grid__rowheader__content > [role='rowheader'] > button.dx-grid__resize-handle {
|
|
97
|
-
inset-inline: 0;
|
|
98
|
-
inset-block-end: 0;
|
|
99
|
-
block-size: .5rem;
|
|
100
|
-
cursor: row-resize;
|
|
101
|
-
}
|