@opentui/core 0.1.82 → 0.1.83

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/index.js CHANGED
@@ -153,7 +153,7 @@ import {
153
153
  white,
154
154
  wrapWithDelegates,
155
155
  yellow
156
- } from "./index-fv58mb45.js";
156
+ } from "./index-a215gqtt.js";
157
157
  // src/text-buffer-view.ts
158
158
  class TextBufferView {
159
159
  lib;
@@ -7186,6 +7186,7 @@ class TextTableRenderable extends Renderable {
7186
7186
  _selectionBg;
7187
7187
  _selectionFg;
7188
7188
  _lastLocalSelection = null;
7189
+ _lastSelectionMode = null;
7189
7190
  _cells = [];
7190
7191
  _prevCellContent = [];
7191
7192
  _rowCount = 0;
@@ -7344,6 +7345,7 @@ class TextTableRenderable extends Renderable {
7344
7345
  const dirtyRows = this.getDirtySelectionRowRange(previousLocalSelection, localSelection);
7345
7346
  if (!localSelection?.isActive) {
7346
7347
  this.resetCellSelections();
7348
+ this._lastSelectionMode = null;
7347
7349
  } else {
7348
7350
  this.applySelectionToCells(localSelection, selection?.isStart ?? false);
7349
7351
  }
@@ -7876,6 +7878,10 @@ class TextTableRenderable extends Renderable {
7876
7878
  const maxSelY = Math.max(localSelection.anchorY, localSelection.focusY);
7877
7879
  const firstRow = this.findRowForLocalY(minSelY);
7878
7880
  const lastRow = this.findRowForLocalY(maxSelY);
7881
+ const selection = this.resolveSelectionResolution(localSelection);
7882
+ const modeChanged = this._lastSelectionMode !== selection.mode;
7883
+ this._lastSelectionMode = selection.mode;
7884
+ const lockToAnchorColumn = selection.mode === "column-locked" && selection.anchorColumn !== null;
7879
7885
  for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
7880
7886
  if (rowIdx < firstRow || rowIdx > lastRow) {
7881
7887
  this.resetRowSelection(rowIdx);
@@ -7886,19 +7892,82 @@ class TextTableRenderable extends Renderable {
7886
7892
  const cell = this._cells[rowIdx]?.[colIdx];
7887
7893
  if (!cell)
7888
7894
  continue;
7895
+ if (lockToAnchorColumn && colIdx !== selection.anchorColumn) {
7896
+ cell.textBufferView.resetLocalSelection();
7897
+ continue;
7898
+ }
7889
7899
  const cellLeft = (this._layout.columnOffsets[colIdx] ?? 0) + 1 + this._cellPadding;
7890
- const anchorX = localSelection.anchorX - cellLeft;
7891
- const anchorY = localSelection.anchorY - cellTop;
7892
- const focusX = localSelection.focusX - cellLeft;
7893
- const focusY = localSelection.focusY - cellTop;
7894
- if (isStart) {
7895
- cell.textBufferView.setLocalSelection(anchorX, anchorY, focusX, focusY, this._selectionBg, this._selectionFg);
7900
+ let coords = {
7901
+ anchorX: localSelection.anchorX - cellLeft,
7902
+ anchorY: localSelection.anchorY - cellTop,
7903
+ focusX: localSelection.focusX - cellLeft,
7904
+ focusY: localSelection.focusY - cellTop
7905
+ };
7906
+ const isAnchorCell = selection.anchorCell !== null && selection.anchorCell.rowIdx === rowIdx && selection.anchorCell.colIdx === colIdx;
7907
+ const forceSet = isAnchorCell && selection.mode !== "single-cell";
7908
+ if (forceSet) {
7909
+ coords = this.getFullCellSelectionCoords(rowIdx, colIdx);
7910
+ }
7911
+ const shouldUseSet = isStart || modeChanged || forceSet;
7912
+ if (shouldUseSet) {
7913
+ cell.textBufferView.setLocalSelection(coords.anchorX, coords.anchorY, coords.focusX, coords.focusY, this._selectionBg, this._selectionFg);
7896
7914
  } else {
7897
- cell.textBufferView.updateLocalSelection(anchorX, anchorY, focusX, focusY, this._selectionBg, this._selectionFg);
7915
+ cell.textBufferView.updateLocalSelection(coords.anchorX, coords.anchorY, coords.focusX, coords.focusY, this._selectionBg, this._selectionFg);
7898
7916
  }
7899
7917
  }
7900
7918
  }
7901
7919
  }
7920
+ resolveSelectionResolution(localSelection) {
7921
+ const anchorCell = this.getCellAtLocalPosition(localSelection.anchorX, localSelection.anchorY);
7922
+ const focusCell = this.getCellAtLocalPosition(localSelection.focusX, localSelection.focusY);
7923
+ const anchorColumn = anchorCell?.colIdx ?? this.getColumnAtLocalX(localSelection.anchorX);
7924
+ if (anchorCell !== null && focusCell !== null && anchorCell.rowIdx === focusCell.rowIdx && anchorCell.colIdx === focusCell.colIdx) {
7925
+ return {
7926
+ mode: "single-cell",
7927
+ anchorCell,
7928
+ anchorColumn
7929
+ };
7930
+ }
7931
+ const focusColumn = this.getColumnAtLocalX(localSelection.focusX);
7932
+ if (anchorColumn !== null && focusColumn === anchorColumn) {
7933
+ return {
7934
+ mode: "column-locked",
7935
+ anchorCell,
7936
+ anchorColumn
7937
+ };
7938
+ }
7939
+ return {
7940
+ mode: "grid",
7941
+ anchorCell,
7942
+ anchorColumn
7943
+ };
7944
+ }
7945
+ getColumnAtLocalX(localX) {
7946
+ if (this._columnCount === 0)
7947
+ return null;
7948
+ if (localX < 0 || localX >= this._layout.tableWidth)
7949
+ return null;
7950
+ for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
7951
+ const colStart = (this._layout.columnOffsets[colIdx] ?? 0) + 1;
7952
+ const colEnd = colStart + (this._layout.columnWidths[colIdx] ?? 1) - 1;
7953
+ if (localX >= colStart && localX <= colEnd) {
7954
+ return colIdx;
7955
+ }
7956
+ }
7957
+ return null;
7958
+ }
7959
+ getFullCellSelectionCoords(rowIdx, colIdx) {
7960
+ const colWidth = this._layout.columnWidths[colIdx] ?? 1;
7961
+ const rowHeight = this._layout.rowHeights[rowIdx] ?? 1;
7962
+ const contentWidth = Math.max(1, colWidth - this.getHorizontalCellPadding());
7963
+ const contentHeight = Math.max(1, rowHeight - this.getVerticalCellPadding());
7964
+ return {
7965
+ anchorX: -1,
7966
+ anchorY: 0,
7967
+ focusX: contentWidth,
7968
+ focusY: contentHeight
7969
+ };
7970
+ }
7902
7971
  findRowForLocalY(localY) {
7903
7972
  if (this._rowCount === 0)
7904
7973
  return 0;
@@ -7939,8 +8008,6 @@ class TextTableRenderable extends Renderable {
7939
8008
  if (!row)
7940
8009
  return;
7941
8010
  for (const cell of row) {
7942
- if (!cell.textBufferView.hasSelection())
7943
- continue;
7944
8011
  cell.textBufferView.resetLocalSelection();
7945
8012
  }
7946
8013
  }
@@ -9308,6 +9375,7 @@ class MarkdownRenderable extends Renderable {
9308
9375
  _syntaxStyle;
9309
9376
  _conceal;
9310
9377
  _treeSitterClient;
9378
+ _tableOptions;
9311
9379
  _renderNode;
9312
9380
  _parseState = null;
9313
9381
  _streaming = false;
@@ -9328,6 +9396,7 @@ class MarkdownRenderable extends Renderable {
9328
9396
  this._conceal = options.conceal ?? this._contentDefaultOptions.conceal;
9329
9397
  this._content = options.content ?? this._contentDefaultOptions.content;
9330
9398
  this._treeSitterClient = options.treeSitterClient;
9399
+ this._tableOptions = options.tableOptions;
9331
9400
  this._renderNode = options.renderNode;
9332
9401
  this._streaming = options.streaming ?? this._contentDefaultOptions.streaming;
9333
9402
  this.updateBlocks();
@@ -9369,6 +9438,13 @@ class MarkdownRenderable extends Renderable {
9369
9438
  this.clearCache();
9370
9439
  }
9371
9440
  }
9441
+ get tableOptions() {
9442
+ return this._tableOptions;
9443
+ }
9444
+ set tableOptions(value) {
9445
+ this._tableOptions = value;
9446
+ this.applyTableOptionsToBlocks();
9447
+ }
9372
9448
  getStyle(group) {
9373
9449
  if (!this._syntaxStyle)
9374
9450
  return;
@@ -9744,18 +9820,60 @@ class MarkdownRenderable extends Renderable {
9744
9820
  changed
9745
9821
  };
9746
9822
  }
9823
+ resolveTableRenderableOptions() {
9824
+ const borders = this._tableOptions?.borders ?? true;
9825
+ return {
9826
+ columnWidthMode: this._tableOptions?.widthMode ?? "content",
9827
+ wrapMode: this._tableOptions?.wrapMode ?? "none",
9828
+ cellPadding: this._tableOptions?.cellPadding ?? 0,
9829
+ border: borders,
9830
+ outerBorder: this._tableOptions?.outerBorder ?? borders,
9831
+ showBorders: borders,
9832
+ borderStyle: this._tableOptions?.borderStyle ?? "single",
9833
+ borderColor: this._tableOptions?.borderColor ?? this.getStyle("conceal")?.fg ?? "#888888",
9834
+ selectable: this._tableOptions?.selectable ?? true
9835
+ };
9836
+ }
9837
+ applyTableRenderableOptions(tableRenderable, options) {
9838
+ tableRenderable.columnWidthMode = options.columnWidthMode;
9839
+ tableRenderable.wrapMode = options.wrapMode;
9840
+ tableRenderable.cellPadding = options.cellPadding;
9841
+ tableRenderable.border = options.border;
9842
+ tableRenderable.outerBorder = options.outerBorder;
9843
+ tableRenderable.showBorders = options.showBorders;
9844
+ tableRenderable.borderStyle = options.borderStyle;
9845
+ tableRenderable.borderColor = options.borderColor;
9846
+ tableRenderable.selectable = options.selectable;
9847
+ }
9848
+ applyTableOptionsToBlocks() {
9849
+ const options = this.resolveTableRenderableOptions();
9850
+ let updated = false;
9851
+ for (const state of this._blockStates) {
9852
+ if (state.renderable instanceof TextTableRenderable) {
9853
+ this.applyTableRenderableOptions(state.renderable, options);
9854
+ updated = true;
9855
+ }
9856
+ }
9857
+ if (updated) {
9858
+ this.requestRender();
9859
+ }
9860
+ }
9747
9861
  createTextTableRenderable(content, id, marginBottom = 0) {
9862
+ const options = this.resolveTableRenderableOptions();
9748
9863
  return new TextTableRenderable(this.ctx, {
9749
9864
  id,
9750
9865
  content,
9751
9866
  width: "100%",
9752
9867
  marginBottom,
9753
- border: true,
9754
- outerBorder: true,
9755
- showBorders: true,
9756
- borderStyle: "single",
9757
- borderColor: this.getStyle("conceal")?.fg ?? "#888888",
9758
- selectable: false
9868
+ columnWidthMode: options.columnWidthMode,
9869
+ wrapMode: options.wrapMode,
9870
+ cellPadding: options.cellPadding,
9871
+ border: options.border,
9872
+ outerBorder: options.outerBorder,
9873
+ showBorders: options.showBorders,
9874
+ borderStyle: options.borderStyle,
9875
+ borderColor: options.borderColor,
9876
+ selectable: options.selectable
9759
9877
  });
9760
9878
  }
9761
9879
  createTableBlock(table, id, marginBottom = 0, previousCache, forceRegenerate = false) {
@@ -9824,7 +9942,7 @@ class MarkdownRenderable extends Renderable {
9824
9942
  if (changed) {
9825
9943
  state.renderable.content = cache.content;
9826
9944
  }
9827
- state.renderable.borderColor = this.getStyle("conceal")?.fg ?? "#888888";
9945
+ this.applyTableRenderableOptions(state.renderable, this.resolveTableRenderableOptions());
9828
9946
  state.renderable.marginBottom = marginBottom;
9829
9947
  state.tableContentCache = cache;
9830
9948
  return;
@@ -9968,7 +10086,7 @@ class MarkdownRenderable extends Renderable {
9968
10086
  state.tableContentCache = undefined;
9969
10087
  } else if (state.renderable instanceof TextTableRenderable) {
9970
10088
  state.renderable.content = cache.content;
9971
- state.renderable.borderColor = this.getStyle("conceal")?.fg ?? "#888888";
10089
+ this.applyTableRenderableOptions(state.renderable, this.resolveTableRenderableOptions());
9972
10090
  state.renderable.marginBottom = marginBottom;
9973
10091
  state.tableContentCache = cache;
9974
10092
  } else {
@@ -12088,5 +12206,5 @@ export {
12088
12206
  ASCIIFont
12089
12207
  };
12090
12208
 
12091
- //# debugId=115C19DFB6D5E10364756E2164756E21
12209
+ //# debugId=0C8001DA726AC37664756E2164756E21
12092
12210
  //# sourceMappingURL=index.js.map