@dxos/lit-grid 0.8.1-main.ba2dec9 → 0.8.1-staging.31c3ee1

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/src/dx-grid.ts CHANGED
@@ -58,6 +58,7 @@ import {
58
58
  resolveColPlane,
59
59
  resolveFrozenPlane,
60
60
  isSameCell,
61
+ isReadonly,
61
62
  } from './util';
62
63
 
63
64
  @customElement('dx-grid')
@@ -1016,6 +1017,10 @@ export class DxGrid extends LitElement {
1016
1017
  this.updatePosBlock(this.blockOffset(row, 'grid'));
1017
1018
  }
1018
1019
 
1020
+ scrollToEndRow() {
1021
+ this.updatePosBlock(Infinity);
1022
+ }
1023
+
1019
1024
  //
1020
1025
  // Map scroll DOM methods to virtualized value.
1021
1026
  //
@@ -1222,21 +1227,44 @@ export class DxGrid extends LitElement {
1222
1227
  const colPlane = resolveColPlane(plane);
1223
1228
  const rowPlane = resolveRowPlane(plane);
1224
1229
 
1230
+ // Check cell-specific setting first.
1225
1231
  const cellReadonly = this.cell(col, row, plane)?.readonly;
1226
1232
  if (cellReadonly !== undefined) {
1227
- return cellReadonly;
1233
+ return isReadonly(cellReadonly);
1228
1234
  }
1229
1235
 
1230
- return (
1231
- (this.columns?.[colPlane]?.[col]?.readonly ?? this.columnDefault?.[colPlane]?.readonly) ||
1232
- (this.rows?.[rowPlane]?.[row]?.readonly ?? this.rowDefault?.[rowPlane]?.readonly)
1233
- );
1236
+ // Check column/row defaults.
1237
+ const colReadOnly = this.columns?.[colPlane]?.[col]?.readonly ?? this.columnDefault?.[colPlane]?.readonly;
1238
+ const rowReadOnly = this.rows?.[rowPlane]?.[row]?.readonly ?? this.rowDefault?.[rowPlane]?.readonly;
1239
+
1240
+ return isReadonly(colReadOnly) || isReadonly(rowReadOnly);
1241
+ }
1242
+
1243
+ /**
1244
+ * Determines if the cell's text content should be selectable based on its readonly value.
1245
+ * @returns true if the cells text content is selectable, false otherwise.
1246
+ */
1247
+ private cellTextSelectable(col: number, row: number, plane: DxGridPlane): boolean {
1248
+ const colPlane = resolveColPlane(plane);
1249
+ const rowPlane = resolveRowPlane(plane);
1250
+
1251
+ // Check cell-specific setting first.
1252
+ const cellReadonly = this.cell(col, row, plane)?.readonly;
1253
+ if (cellReadonly !== undefined) {
1254
+ return cellReadonly === 'text-select';
1255
+ }
1256
+
1257
+ // Check column/row defaults.
1258
+ const colReadonly = this.columns?.[colPlane]?.[col]?.readonly ?? this.columnDefault?.[colPlane]?.readonly;
1259
+ const rowReadonly = this.rows?.[rowPlane]?.[row]?.readonly ?? this.rowDefault?.[rowPlane]?.readonly;
1260
+ return colReadonly === 'text-select' || rowReadonly === 'text-select';
1234
1261
  }
1235
1262
 
1236
1263
  private renderCell(col: number, row: number, plane: DxGridPlane, selected?: boolean, visCol = col, visRow = row) {
1237
1264
  const cell = this.cell(col, row, plane);
1238
1265
  const active = this.cellActive(col, row, plane);
1239
1266
  const readonly = this.cellReadonly(col, row, plane);
1267
+ const textSelectable = this.cellTextSelectable(col, row, plane);
1240
1268
  const resizeIndex = cell?.resizeHandle ? (cell.resizeHandle === 'col' ? col : row) : undefined;
1241
1269
  const resizePlane = cell?.resizeHandle ? resolveFrozenPlane(cell.resizeHandle, plane) : undefined;
1242
1270
  const accessory = cell?.accessoryHtml ? staticHtml`${unsafeStatic(cell.accessoryHtml)}` : null;
@@ -1248,6 +1276,7 @@ export class DxGrid extends LitElement {
1248
1276
  class=${cell?.className ?? nothing}
1249
1277
  data-refs=${cell?.dataRefs ?? nothing}
1250
1278
  ?data-dx-active=${active}
1279
+ data-text-selectable=${textSelectable ? 'true' : 'false'}
1251
1280
  data-dx-grid-action="cell"
1252
1281
  aria-colindex=${col}
1253
1282
  aria-rowindex=${row}
package/src/types.ts CHANGED
@@ -45,6 +45,8 @@ export type DxGridPointer =
45
45
  | { state: 'maybeSelecting'; pageX: number; pageY: number }
46
46
  | { state: 'selecting' };
47
47
 
48
+ export type DxGridReadonlyValue = boolean | 'no-text-select' | 'text-select';
49
+
48
50
  export type DxAxisResizeProps = Pick<DxAxisResize, 'axis' | 'plane' | 'index' | 'size'>;
49
51
  export type DxAxisResizeInternalProps = DxAxisResizeProps & { delta: number; state: 'dragging' | 'dropped' };
50
52
 
@@ -78,16 +80,16 @@ export type DxGridCellValue = {
78
80
  */
79
81
  resizeHandle?: DxGridAxis;
80
82
  /**
81
- * Whether this cell is read-only.
83
+ * Controls the read-only state of the cell.
82
84
  */
83
- readonly?: boolean;
85
+ readonly?: DxGridReadonlyValue;
84
86
  };
85
87
 
86
88
  export type DxGridAxisMetaProps = {
87
89
  size: number;
88
90
  description?: string;
89
91
  resizeable?: boolean;
90
- readonly?: boolean;
92
+ readonly?: DxGridReadonlyValue;
91
93
  };
92
94
 
93
95
  export type DxGridAxisSizes = DxGridPlaneRecord<DxGridFrozenPlane, Record<string, number>>;
package/src/util.ts CHANGED
@@ -17,6 +17,7 @@ import {
17
17
  type DxGridAxis,
18
18
  type DxGridPlanePosition,
19
19
  separator,
20
+ type DxGridReadonlyValue,
20
21
  } from './types';
21
22
 
22
23
  export const toPlaneCellIndex = (cellCoords: Partial<DxGridPosition> & DxGridPlanePosition): DxGridPlaneCellIndex =>
@@ -204,3 +205,7 @@ export const isSameCell = (a: DxGridPositionNullable, b: DxGridPositionNullable)
204
205
  Number.isFinite(a.row) &&
205
206
  a.col === b.col &&
206
207
  a.row === b.row;
208
+
209
+ export const isReadonly = (cellReadonly?: DxGridReadonlyValue) => {
210
+ return !(cellReadonly === false || cellReadonly === undefined);
211
+ };