sheet-happens 0.0.51 → 0.0.52

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.
@@ -1,3 +1,3 @@
1
- import { RowOrColumnPropertyFunction, RowOrColumnPropertyStyledFunction, CellPropertyFunction, CellPropertyStyledFunction, CellContentType, Style } from './types';
2
- export declare const useAutoSizeColumn: (rows: number[], displayData: CellPropertyStyledFunction<CellContentType>, cellStyle: CellPropertyFunction<Style>, columnHeaders: RowOrColumnPropertyStyledFunction<CellContentType>, columnHeaderStyle: RowOrColumnPropertyFunction<Style>, canvasWidth: number) => (x: number) => number;
3
- export declare const useAutoSizeRow: (columns: number[], displayData: CellPropertyStyledFunction<CellContentType>, cellStyle: CellPropertyFunction<Style>, columnHeaders: RowOrColumnPropertyStyledFunction<CellContentType>, columnHeaderStyle: RowOrColumnPropertyFunction<Style>, cellWidth: RowOrColumnPropertyFunction<number>, canvasHeight: number) => (y: number) => number;
1
+ import { RowOrColumnPropertyFunction, RowOrColumnPropertyStyledFunction, CellLayout, CellPropertyFunction, CellPropertyStyledFunction, CellContentType, Style } from './types';
2
+ export declare const useAutoSizeColumn: (rows: number[], displayData: CellPropertyStyledFunction<CellContentType>, cellLayout: CellLayout, cellStyle: CellPropertyFunction<Style>, columnHeaders: RowOrColumnPropertyStyledFunction<CellContentType>, columnHeaderStyle: RowOrColumnPropertyFunction<Style>, canvasWidth: number, frozenColumns: number) => (x: number) => number;
3
+ export declare const useAutoSizeRow: (columns: number[], displayData: CellPropertyStyledFunction<CellContentType>, cellLayout: CellLayout, cellStyle: CellPropertyFunction<Style>, columnHeaders: RowOrColumnPropertyStyledFunction<CellContentType>, columnHeaderStyle: RowOrColumnPropertyFunction<Style>, cellWidth: RowOrColumnPropertyFunction<number>, canvasHeight: number, frozenRows: number) => (y: number) => number;
package/dist/index.js CHANGED
@@ -993,8 +993,8 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
993
993
  _normalizeSelection2$2 = _normalizeSelection2[1],
994
994
  maxX = _normalizeSelection2$2[0],
995
995
  maxY = _normalizeSelection2$2[1];
996
- var cellX = pixelToColumn(x, 0.5);
997
- var cellY = pixelToRow(y, 0.5);
996
+ var cellX = Math.max(0, pixelToColumn(x, 0.5));
997
+ var cellY = Math.max(0, pixelToRow(y, 0.5));
998
998
  if (columnDrag) {
999
999
  var indices = columnDrag.indices;
1000
1000
  var insideSelection = cellX >= minX && cellX <= maxX + 1;
@@ -2018,12 +2018,13 @@ var wrapText = function wrapText(context, text, style, itemAlign, xCoord, yCoord
2018
2018
  newline(n);
2019
2019
  };
2020
2020
 
2021
- var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth) {
2021
+ var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth, frozenColumns) {
2022
2022
  var context = React.useMemo(function () {
2023
2023
  return document.createElement('canvas').getContext('2d');
2024
2024
  }, []);
2025
2025
  var getAutoSizeWidth = React.useCallback(function (x) {
2026
2026
  if (!context) return 0;
2027
+ var viewWidth = canvasWidth - cellLayout.columnToAbsolute(x < frozenColumns ? 0 : frozenColumns);
2027
2028
  var getWidth = function getWidth(cellContent, style) {
2028
2029
  context.font = style.fontWeight + ' ' + style.fontSize + 'px ' + style.fontFamily;
2029
2030
  var inlineMargin = style.marginLeft + style.marginRight;
@@ -2067,22 +2068,23 @@ var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle,
2067
2068
  maxWidth = Math.max(maxWidth, getWidth(cellContent, style));
2068
2069
  }
2069
2070
  }
2070
- return Math.ceil(Math.min(canvasWidth, maxWidth));
2071
- }, [context, displayData, cellStyle, columnHeaders, columnHeaderStyle]);
2071
+ return Math.ceil(Math.min(viewWidth, maxWidth));
2072
+ }, [context, rows, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth, frozenColumns]);
2072
2073
  return getAutoSizeWidth;
2073
2074
  };
2074
- var useAutoSizeRow = function useAutoSizeRow(columns, displayData, cellStyle, columnHeaders, columnHeaderStyle, cellWidth, canvasHeight) {
2075
+ var useAutoSizeRow = function useAutoSizeRow(columns, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, cellWidth, canvasHeight, frozenRows) {
2075
2076
  var context = React.useMemo(function () {
2076
2077
  return document.createElement('canvas').getContext('2d');
2077
2078
  }, []);
2078
2079
  var getAutoSizeHeight = React.useCallback(function (y) {
2079
2080
  if (!context) return 0;
2081
+ var viewHeight = canvasHeight - cellLayout.rowToAbsolute(y < frozenRows ? 0 : frozenRows);
2080
2082
  var measureTextHeight = function measureTextHeight(text, style, columnWidth) {
2081
2083
  var maxY = 0;
2082
2084
  var measureY = function measureY(_t, _x, y) {
2083
2085
  maxY = y + style.lineHeight;
2084
2086
  };
2085
- wrapText(context, text, style, undefined, 0, 0, columnWidth, canvasHeight, measureY);
2087
+ wrapText(context, text, style, undefined, 0, 0, columnWidth, viewHeight, measureY);
2086
2088
  return maxY;
2087
2089
  };
2088
2090
  var getHeight = function getHeight(cellContent, style, columnWidth) {
@@ -2093,13 +2095,19 @@ var useAutoSizeRow = function useAutoSizeRow(columns, displayData, cellStyle, co
2093
2095
  return height + verticalMargin;
2094
2096
  } else if (typeof cellContent === 'object') {
2095
2097
  var _maxHeight = 0;
2096
- for (var _iterator3 = _createForOfIteratorHelperLoose(cellContent.items), _step3; !(_step3 = _iterator3()).done;) {
2097
- var item = _step3.value;
2098
- if (item.absolute) continue;
2098
+ var flexLayout = resolveCellFlexLayout(context, cellContent, 0, 0, columnWidth, 0);
2099
+ for (var _iterator3 = _createForOfIteratorHelperLoose(flexLayout), _step3; !(_step3 = _iterator3()).done;) {
2100
+ var _step3$value = _step3.value,
2101
+ box = _step3$value.box,
2102
+ item = _step3$value.item;
2099
2103
  if (item.height != null) {
2100
2104
  _maxHeight = Math.max(_maxHeight, item.height);
2101
2105
  } else if (item.display === 'inline' && item.text != null) {
2102
- var _height = measureTextHeight(item.text.toString(), style, columnWidth);
2106
+ var _box$ = box[0],
2107
+ left = _box$[0],
2108
+ _box$2 = box[1],
2109
+ right = _box$2[0];
2110
+ var _height = measureTextHeight(item.text.toString(), style, right - left);
2103
2111
  _maxHeight = Math.max(_maxHeight, _height);
2104
2112
  }
2105
2113
  }
@@ -2118,8 +2126,8 @@ var useAutoSizeRow = function useAutoSizeRow(columns, displayData, cellStyle, co
2118
2126
  maxHeight = Math.max(maxHeight, getHeight(cellContent, style, columnWidth));
2119
2127
  }
2120
2128
  }
2121
- return Math.ceil(Math.min(canvasHeight, maxHeight));
2122
- }, [context, displayData, cellStyle, cellWidth]);
2129
+ return Math.ceil(Math.min(viewHeight, maxHeight));
2130
+ }, [context, columns, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, cellWidth, canvasHeight, frozenRows]);
2123
2131
  return getAutoSizeHeight;
2124
2132
  };
2125
2133
 
@@ -3156,9 +3164,11 @@ var renderCell = function renderCell(context, imageRenderer, cellContent, style,
3156
3164
  var renderedFlex = resolveCellFlexLayout(context, cellContent, innerX, innerY, innerWidth, innerHeight);
3157
3165
  var renderedAbsolute = resolveCellAbsoluteLayout(cellContent, innerX, innerY, innerWidth, innerHeight);
3158
3166
  var rendered = [].concat(renderedFlex, renderedAbsolute);
3159
- clipToBox(context, innerX, innerY, innerWidth, innerHeight, function () {
3167
+ clipToBox(context, xCoord, yCoord, cellWidth, cellHeight, function () {
3160
3168
  var _loop = function _loop() {
3161
- var render = _step12.value;
3169
+ var _step12$value = _step12.value,
3170
+ i = _step12$value[0],
3171
+ render = _step12$value[1];
3162
3172
  var box = render.box,
3163
3173
  item = render.item;
3164
3174
  var _box$ = box[0],
@@ -3174,7 +3184,10 @@ var renderCell = function renderCell(context, imageRenderer, cellContent, style,
3174
3184
  context.strokeStyle = '#ff00ff';
3175
3185
  context.strokeRect(left + 0.5, top + 0.5, width - 0.5, height - 0.5);
3176
3186
  }
3177
- clipToBox(context, left, top, width, height, function () {
3187
+ var clipLeft = i > 0 ? left : xCoord;
3188
+ var clipRight = i < rendered.length ? right : yCoord + cellWidth;
3189
+ var clipWidth = clipRight - clipLeft;
3190
+ clipToBox(context, clipLeft, yCoord, clipWidth, cellHeight, function () {
3178
3191
  if (item.display === 'inline') {
3179
3192
  var text = item.text;
3180
3193
  if (text != null) {
@@ -3186,7 +3199,7 @@ var renderCell = function renderCell(context, imageRenderer, cellContent, style,
3186
3199
  }
3187
3200
  });
3188
3201
  };
3189
- for (var _iterator12 = _createForOfIteratorHelperLoose(rendered), _step12; !(_step12 = _iterator12()).done;) {
3202
+ for (var _iterator12 = _createForOfIteratorHelperLoose(rendered.entries()), _step12; !(_step12 = _iterator12()).done;) {
3190
3203
  _loop();
3191
3204
  }
3192
3205
  });
@@ -3621,8 +3634,8 @@ var Sheet = React.forwardRef(function (props, ref) {
3621
3634
  clipboardApi = _useClipboardAPI.clipboardApi,
3622
3635
  onClipboardCopy = _useClipboardAPI.onClipboardCopy;
3623
3636
  var onScroll = useScroll(dataOffset, maxScroll, cellLayout, setDataOffset, setMaxScroll);
3624
- var getAutoSizeWidth = useAutoSizeColumn(visibleCells.rows, displayData, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth);
3625
- var getAutoSizeHeight = useAutoSizeRow(visibleCells.columns, displayData, cellStyle, columnHeaders, columnHeaderStyle, cellWidth, canvasHeight);
3637
+ var getAutoSizeWidth = useAutoSizeColumn(visibleCells.rows, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth, freezeColumns);
3638
+ var getAutoSizeHeight = useAutoSizeRow(visibleCells.columns, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, cellWidth, canvasHeight, freezeRows);
3626
3639
  var _useMouse = useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, getAutoSizeWidth, getAutoSizeHeight, startEditingCell, commitEditingCell, setKnobArea, setDragIndices, setDragOffset, setDropTarget, changeSelection, setFocused, props.cacheLayout ? columnLayout.clearAfter : undefined, props.cacheLayout ? rowLayout.clearAfter : undefined, props.onChange, props.onColumnOrderChange, props.onRowOrderChange, props.onCellWidthChange, props.onCellHeightChange, props.onRightClick, props.dontCommitEditOnSelectionChange, props.dontChangeSelectionOnOrderChange),
3627
3640
  mouseHandlers = _useMouse.mouseHandlers,
3628
3641
  knobPosition = _useMouse.knobPosition;
@@ -3657,6 +3670,9 @@ var Sheet = React.forwardRef(function (props, ref) {
3657
3670
  var editTextAlign = 'right';
3658
3671
  var editTextLineHeight = '';
3659
3672
  var editTextMargin = '';
3673
+ var editTextFontSize = DEFAULT_CELL_STYLE.fontSize;
3674
+ var editTextFontFamily = DEFAULT_CELL_STYLE.fontFamily;
3675
+ var editTextFontWeight = DEFAULT_CELL_STYLE.fontWeight;
3660
3676
  if (editMode) {
3661
3677
  var style = _extends({}, DEFAULT_CELL_STYLE, cellStyle.apply(void 0, editCell));
3662
3678
  editTextPosition = cellToPixel(editCell);
@@ -3665,6 +3681,9 @@ var Sheet = React.forwardRef(function (props, ref) {
3665
3681
  editTextHeight = cellHeight(editCellY) - 3;
3666
3682
  editTextAlign = style.textAlign;
3667
3683
  editTextLineHeight = style.lineHeight + "px";
3684
+ editTextFontSize = style.fontSize;
3685
+ editTextFontFamily = style.fontFamily;
3686
+ editTextFontWeight = style.fontWeight;
3668
3687
  var yNudge = getDpiNudge();
3669
3688
  editTextMargin = style.marginTop - 1 + yNudge + "px " + (style.marginRight - 2) + "px " + (style.marginBottom - 2) + "px " + (style.marginLeft - 1) + "px";
3670
3689
  var editKey = editKeys.apply(void 0, editCell);
@@ -3692,8 +3711,9 @@ var Sheet = React.forwardRef(function (props, ref) {
3692
3711
  textAlign: editTextAlign,
3693
3712
  lineHeight: editTextLineHeight,
3694
3713
  color: 'black',
3695
- fontSize: DEFAULT_CELL_STYLE.fontSize,
3696
- fontFamily: 'sans-serif',
3714
+ fontSize: editTextFontSize,
3715
+ fontFamily: editTextFontFamily,
3716
+ fontWeight: editTextFontWeight,
3697
3717
  resize: 'none'
3698
3718
  }
3699
3719
  };