abdul-react 0.0.37 → 0.0.38

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/lib/index.cjs CHANGED
@@ -40214,12 +40214,15 @@ function reducer(state, action) {
40214
40214
  updatedData.forEach((rowData, rowIndex) => {
40215
40215
  let maxHeight = 32; // Default row height
40216
40216
  rowData.forEach((cell, _colIndex) => {
40217
- if (cell && cell.value) {
40218
- const fontSize = cell.style?.fontSize ? parseInt(cell.style.fontSize.toString().replace('px', '')) : 11;
40219
- const lineHeight = Math.max(fontSize * 1.2, 18);
40220
- const lines = String(cell.value).split('\n').length;
40221
- const cellHeight = lineHeight * lines + 10;
40222
- maxHeight = Math.max(Number(cell?.style?.height) ?? maxHeight, cellHeight);
40217
+ if (cell) {
40218
+ maxHeight = Math.max(maxHeight, Number(cell.style?.height ?? 32));
40219
+ if (cell.value) {
40220
+ const fontSize = cell.style?.fontSize ? parseInt(cell.style.fontSize.toString().replace('px', '')) : 11;
40221
+ const lineHeight = Math.max(fontSize * 1.2, 18);
40222
+ const lines = String(cell.value).split('\n').length;
40223
+ const cellHeight = lineHeight * lines + 10;
40224
+ maxHeight = Math.max(maxHeight, cellHeight);
40225
+ }
40223
40226
  }
40224
40227
  });
40225
40228
  newRowDimensions[rowIndex] = {
@@ -40236,10 +40239,13 @@ function reducer(state, action) {
40236
40239
  let maxWidth = 100; // Default column width
40237
40240
  updatedData.forEach((rowData, _rowIndex) => {
40238
40241
  const cell = rowData[col];
40239
- if (cell && cell.value && !['file'].includes(cell?.inputType?.type ?? 'text')) {
40240
- const font = getFontString(cell);
40241
- const textWidth = measureText(String(cell.value), font) + 20;
40242
- maxWidth = Math.max(Number(cell?.style?.width) ?? maxWidth, textWidth);
40242
+ if (cell) {
40243
+ maxWidth = Math.max(maxWidth, Number(cell.style?.width ?? 100));
40244
+ if (cell.value && !['file'].includes(cell?.inputType?.type ?? 'text')) {
40245
+ const font = getFontString(cell);
40246
+ const textWidth = measureText(String(cell.value), font) + 20;
40247
+ maxWidth = Math.max(maxWidth, textWidth);
40248
+ }
40243
40249
  }
40244
40250
  });
40245
40251
  newColumnDimensions[col] = {
@@ -40343,7 +40349,9 @@ function reducer(state, action) {
40343
40349
  } = action.payload;
40344
40350
  const nextActive = state.active && has$1(state.active, data) ? state.active : null;
40345
40351
  const nextSelected = state.selected.normalizeTo(data);
40346
- const updatedModel = new Model(state.model.createFormulaParser, data);
40352
+ // Ensure data is a valid array; fallback to empty matrix if invalid
40353
+ const updatedData = Array.isArray(data) && data.every(row => Array.isArray(row)) ? data : [[EmptyCell]];
40354
+ const updatedModel = new Model(state.model.createFormulaParser, updatedData);
40347
40355
  // Auto-resize all rows and columns on initial load
40348
40356
  let newRowDimensions = {
40349
40357
  ...state.rowDimensions
@@ -40352,15 +40360,18 @@ function reducer(state, action) {
40352
40360
  ...state.columnDimensions
40353
40361
  };
40354
40362
  // Auto-resize all rows
40355
- data.forEach((rowData, rowIndex) => {
40363
+ updatedData.forEach((rowData, rowIndex) => {
40356
40364
  let maxHeight = 32; // Default row height
40357
40365
  rowData.forEach((cell, _colIndex) => {
40358
- if (cell && cell.value) {
40359
- const fontSize = cell.style?.fontSize ? parseInt(cell.style.fontSize.toString().replace('px', '')) : 11;
40360
- const lineHeight = Math.max(fontSize * 1.2, 18);
40361
- const lines = String(cell.value).split('\n').length;
40362
- const cellHeight = lineHeight * lines + 10;
40363
- maxHeight = Math.max(Number(cell?.style?.height) ?? maxHeight, cellHeight);
40366
+ if (cell) {
40367
+ maxHeight = Math.max(maxHeight, Number(cell.style?.height ?? 32));
40368
+ if (cell.value) {
40369
+ const fontSize = cell.style?.fontSize ? parseInt(cell.style.fontSize.toString().replace('px', '')) : 11;
40370
+ const lineHeight = Math.max(fontSize * 1.2, 18);
40371
+ const lines = String(cell.value).split('\n').length;
40372
+ const cellHeight = lineHeight * lines + 10;
40373
+ maxHeight = Math.max(maxHeight, cellHeight);
40374
+ }
40364
40375
  }
40365
40376
  });
40366
40377
  newRowDimensions[rowIndex] = {
@@ -40372,15 +40383,18 @@ function reducer(state, action) {
40372
40383
  };
40373
40384
  });
40374
40385
  // Auto-resize all columns
40375
- const columnCount = data[0] ? data[0].length : 0;
40386
+ const columnCount = updatedData[0] ? updatedData[0].length : 0;
40376
40387
  for (let col = 0; col < columnCount; col++) {
40377
40388
  let maxWidth = 100; // Default column width
40378
- data.forEach((rowData, _rowIndex) => {
40389
+ updatedData.forEach((rowData, _rowIndex) => {
40379
40390
  const cell = rowData[col];
40380
- if (cell && cell.value && !['file'].includes(cell?.inputType?.type ?? 'text')) {
40381
- const font = getFontString(cell);
40382
- const textWidth = measureText(String(cell.value), font) + 20;
40383
- maxWidth = Math.max(Number(cell?.style?.width) ?? maxWidth, textWidth);
40391
+ if (cell) {
40392
+ maxWidth = Math.max(maxWidth, Number(cell.style?.width ?? 100));
40393
+ if (cell.value && !['file'].includes(cell?.inputType?.type ?? 'text')) {
40394
+ const font = getFontString(cell);
40395
+ const textWidth = measureText(String(cell.value), font) + 20;
40396
+ maxWidth = Math.max(maxWidth, textWidth);
40397
+ }
40384
40398
  }
40385
40399
  });
40386
40400
  newColumnDimensions[col] = {
@@ -40528,15 +40542,18 @@ function reducer(state, action) {
40528
40542
  debouncedResize(`resize-${active.row}-${active.column}`, () => {
40529
40543
  // Auto-resize row
40530
40544
  const rowData = updatedModel.data[active.row] || [];
40531
- let maxRowHeight = 32; // Default row height
40545
+ let maxHeight = 32; // Default row height
40532
40546
  // Only check this row's cells for height calculation
40533
40547
  rowData.forEach((cell, _colIndex) => {
40534
- if (cell && cell.value) {
40535
- const fontSize = cell.style?.fontSize ? parseInt(cell.style.fontSize.toString().replace('px', '')) : 11;
40536
- const lineHeight = Math.max(fontSize * 1.2, 18);
40537
- const lines = String(cell.value).split('\n').length;
40538
- const cellHeight = lineHeight * lines + 10;
40539
- maxRowHeight = Math.max(Number(cell?.style?.height) ?? maxRowHeight, cellHeight);
40548
+ if (cell) {
40549
+ maxHeight = Math.max(maxHeight, Number(cell.style?.height ?? 32));
40550
+ if (cell.value) {
40551
+ const fontSize = cell.style?.fontSize ? parseInt(cell.style.fontSize.toString().replace('px', '')) : 11;
40552
+ const lineHeight = Math.max(fontSize * 1.2, 18);
40553
+ const lines = String(cell.value).split('\n').length;
40554
+ const cellHeight = lineHeight * lines + 10;
40555
+ maxHeight = Math.max(maxHeight, cellHeight);
40556
+ }
40540
40557
  }
40541
40558
  });
40542
40559
  newRowDimensions[active.row] = {
@@ -40544,17 +40561,20 @@ function reducer(state, action) {
40544
40561
  top: 0,
40545
40562
  height: 32
40546
40563
  }),
40547
- height: maxRowHeight
40564
+ height: maxHeight
40548
40565
  };
40549
40566
  // Auto-resize column
40550
- let maxColWidth = 100; // Default column width
40567
+ let maxWidth = 100; // Default column width
40551
40568
  // Only check this column's cells for width calculation
40552
40569
  updatedModel.data.forEach((rowData, _rowIndex) => {
40553
40570
  const cell = rowData[active.column];
40554
- if (cell && cell.value && !['file'].includes(cell?.inputType?.type ?? 'text')) {
40555
- const font = getFontString(cell);
40556
- const textWidth = measureText(String(cell.value), font) + 20;
40557
- maxColWidth = Math.max(Number(cell?.style?.width) ?? maxColWidth, textWidth);
40571
+ if (cell) {
40572
+ maxWidth = Math.max(maxWidth, Number(cell.style?.width ?? 100));
40573
+ if (cell.value && !['file'].includes(cell?.inputType?.type ?? 'text')) {
40574
+ const font = getFontString(cell);
40575
+ const textWidth = measureText(String(cell.value), font) + 20;
40576
+ maxWidth = Math.max(maxWidth, textWidth);
40577
+ }
40558
40578
  }
40559
40579
  });
40560
40580
  newColumnDimensions[active.column] = {
@@ -40562,7 +40582,7 @@ function reducer(state, action) {
40562
40582
  left: 0,
40563
40583
  width: 100
40564
40584
  }),
40565
- width: maxColWidth
40585
+ width: maxWidth
40566
40586
  };
40567
40587
  }, 300 // 300ms delay
40568
40588
  );
@@ -41091,12 +41111,15 @@ function reducer(state, action) {
41091
41111
  const rowData = model.data[row] || [];
41092
41112
  let maxHeight = 32;
41093
41113
  rowData.forEach((cell, _colIndex) => {
41094
- if (cell && cell.value) {
41095
- const fontSize = cell.style?.fontSize ? parseInt(cell.style.fontSize.toString().replace('px', '')) : 11;
41096
- const lineHeight = Math.max(fontSize * 1.2, 18);
41097
- const lines = String(cell.value).split('\n').length;
41098
- const cellHeight = lineHeight * lines + 10;
41099
- maxHeight = Math.max(Number(cell?.style?.height) ?? maxHeight, cellHeight);
41114
+ if (cell) {
41115
+ maxHeight = Math.max(maxHeight, Number(cell.style?.height ?? 32));
41116
+ if (cell.value) {
41117
+ const fontSize = cell.style?.fontSize ? parseInt(cell.style.fontSize.toString().replace('px', '')) : 11;
41118
+ const lineHeight = Math.max(fontSize * 1.2, 18);
41119
+ const lines = String(cell.value).split('\n').length;
41120
+ const cellHeight = lineHeight * lines + 10;
41121
+ maxHeight = Math.max(maxHeight, cellHeight);
41122
+ }
41100
41123
  }
41101
41124
  });
41102
41125
  newRowDimensions[row] = {
@@ -41112,10 +41135,13 @@ function reducer(state, action) {
41112
41135
  let maxWidth = 100;
41113
41136
  model.data.forEach((rowData, _rowIndex) => {
41114
41137
  const cell = rowData[col];
41115
- if (cell && cell.value && !['file'].includes(cell?.inputType?.type ?? 'text')) {
41116
- const font = getFontString(cell);
41117
- const textWidth = measureText(String(cell.value), font) + 20;
41118
- maxWidth = Math.max(Number(cell?.style?.width) ?? maxWidth, textWidth);
41138
+ if (cell) {
41139
+ maxWidth = Math.max(maxWidth, Number(cell.style?.width ?? 100));
41140
+ if (cell.value && !['file'].includes(cell?.inputType?.type ?? 'text')) {
41141
+ const font = getFontString(cell);
41142
+ const textWidth = measureText(String(cell.value), font) + 20;
41143
+ maxWidth = Math.max(maxWidth, textWidth);
41144
+ }
41119
41145
  }
41120
41146
  });
41121
41147
  newColumnDimensions[col] = {
@@ -41136,15 +41162,7 @@ function reducer(state, action) {
41136
41162
  throw new Error('Unknown action');
41137
41163
  }
41138
41164
  }
41139
- // const reducer = createReducer(INITIAL_STATE, (builder) => {
41140
- // builder.addMatcher(
41141
- // (action) =>
41142
- // action.type === Actions.copy.type || action.type === Actions.cut.type,
41143
- // (state, action) => {
41144
- // }
41145
- // );
41146
- // });
41147
- // // Shared reducers
41165
+ // Shared reducers
41148
41166
 
41149
41167
  var scheduler = {exports: {}};
41150
41168
 
@@ -42484,7 +42502,7 @@ const ColumnIndicator = ({
42484
42502
  const dispatch = useDispatch();
42485
42503
  const excelData = useSelector(state => state.model.data);
42486
42504
  const activeCell = useSelector(state => state.active);
42487
- const minColumnWidth = minimumColumnWidth ?? 100;
42505
+ const columnWidth = useSelector(state => state.columnDimensions[column]?.width ?? 100);
42488
42506
  const matrixData = useSelector(state => state.model.data);
42489
42507
  const {
42490
42508
  columnCount
@@ -42513,7 +42531,6 @@ const ColumnIndicator = ({
42513
42531
  return value;
42514
42532
  });
42515
42533
  };
42516
- const columnWidth = useSelector(state => state.columnDimensions[column]?.width ?? minColumnWidth);
42517
42534
  const options = React.useMemo(() => {
42518
42535
  const checkVisible = cell?.contextDisable?.['Delete Column'] && isCellDataChanged();
42519
42536
  return [{
@@ -42522,7 +42539,7 @@ const ColumnIndicator = ({
42522
42539
  iconName: 'plus_icon',
42523
42540
  action: () => {
42524
42541
  updateVisibleRangeEnd('increment');
42525
- addColumnLeft(minColumnWidth);
42542
+ addColumnLeft(minimumColumnWidth);
42526
42543
  onAddColumn?.(selectedColumn ?? column, true);
42527
42544
  },
42528
42545
  disableTooltip: 'Column limit reached',
@@ -42534,7 +42551,7 @@ const ColumnIndicator = ({
42534
42551
  iconName: 'plus_icon',
42535
42552
  action: () => {
42536
42553
  updateVisibleRangeEnd('increment');
42537
- addColumnRight(minColumnWidth);
42554
+ addColumnRight(minimumColumnWidth);
42538
42555
  onAddColumn?.(selectedColumn ?? column, false);
42539
42556
  },
42540
42557
  disableTooltip: 'Column limit reached',
@@ -42553,8 +42570,7 @@ const ColumnIndicator = ({
42553
42570
  visible: checkVisible ? true : false,
42554
42571
  disable: false
42555
42572
  }] : [])];
42556
- }, [selectedColumn, cell, addColumnLeft, addColumnRight, deleteColumn, minColumnWidth, columnCount, maxColLimit, disableDeleteOption, onAddColumn, onDeleteColumn, column, isCellDataChanged]);
42557
- const MIN_COLUMN_WIDTH = minimumColumnWidth || 100;
42573
+ }, [selectedColumn, cell, addColumnLeft, addColumnRight, deleteColumn, minimumColumnWidth, columnCount, maxColLimit, disableDeleteOption, onAddColumn, onDeleteColumn, column, isCellDataChanged]);
42558
42574
  const onMouseDrag = React__namespace.useCallback((event, isRight) => {
42559
42575
  const getTargetColumn = isRight ? column - 1 : column;
42560
42576
  const targetColumn = Math.max(getTargetColumn, 0);
@@ -42563,7 +42579,7 @@ const ColumnIndicator = ({
42563
42579
  const initialWidth = Number(columnWidth);
42564
42580
  const onMouseMove = moveEvent => {
42565
42581
  const delta = moveEvent.clientX - startX;
42566
- const newWidth = Math.max(MIN_COLUMN_WIDTH, initialWidth + delta);
42582
+ const newWidth = Math.max(minimumColumnWidth, initialWidth + delta);
42567
42583
  dispatch(setColumnWidth(targetColumn, newWidth));
42568
42584
  };
42569
42585
  const onMouseUp = () => {
@@ -42601,6 +42617,10 @@ const ColumnIndicator = ({
42601
42617
  className: classNames('ff-spreadsheet-header', {
42602
42618
  'ff-spreadsheet-header--selected': selected
42603
42619
  }),
42620
+ style: {
42621
+ width: `${columnWidth}px`,
42622
+ minWidth: '100px'
42623
+ },
42604
42624
  onClick: handleClick,
42605
42625
  onContextMenu: contextClick,
42606
42626
  tabIndex: 0,
@@ -42610,7 +42630,7 @@ const ColumnIndicator = ({
42610
42630
  }), jsxRuntime.jsx("div", {
42611
42631
  className: "drag-column-selector drag-column-left",
42612
42632
  onMouseDown: e => onMouseDrag(e, false),
42613
- onDoubleClick: () => dispatch(setColumnPosition(column, minColumnWidth)),
42633
+ onDoubleClick: () => dispatch(setColumnPosition(column, columnWidth)),
42614
42634
  onClick: () => activate$1({
42615
42635
  row: -1,
42616
42636
  column
@@ -42618,7 +42638,7 @@ const ColumnIndicator = ({
42618
42638
  }), jsxRuntime.jsx("div", {
42619
42639
  className: "drag-column-selector drag-column-right",
42620
42640
  onMouseDown: e => onMouseDrag(e, true),
42621
- onDoubleClick: () => dispatch(setColumnPosition(column, minColumnWidth)),
42641
+ onDoubleClick: () => dispatch(setColumnPosition(column, columnWidth)),
42622
42642
  onClick: () => activate$1({
42623
42643
  row: -1,
42624
42644
  column
@@ -42774,7 +42794,7 @@ const RowIndicator = ({
42774
42794
  }),
42775
42795
  style: {
42776
42796
  height: `${rowHeight}px`,
42777
- minWidth: '60px'
42797
+ minHeight: '32px'
42778
42798
  },
42779
42799
  onClick: handleClick,
42780
42800
  onContextMenu: contextClick,
@@ -44236,13 +44256,57 @@ const Spreadsheet = /*#__PURE__*/React__namespace.forwardRef(function Spreadshee
44236
44256
  const initialState = React__namespace.useMemo(() => {
44237
44257
  const createParser = props.createFormulaParser || createFormulaParser;
44238
44258
  const model = new Model(createParser, props.data);
44259
+ let newRowDimensions = {};
44260
+ let newColumnDimensions = {};
44261
+ props.data.forEach((rowData, rowIndex) => {
44262
+ let maxHeight = DEFAULT_ROW_HEIGHT;
44263
+ rowData.forEach(cell => {
44264
+ if (cell) {
44265
+ const cellHeight = parseFloat(String(cell.style?.height).replace('px', '')) || DEFAULT_ROW_HEIGHT;
44266
+ maxHeight = Math.max(maxHeight, cellHeight);
44267
+ if (cell.value) {
44268
+ const fontSize = parseFloat(String(cell.style?.fontSize).replace('px', '')) || 11;
44269
+ const lineHeight = Math.max(fontSize * 1.2, 18);
44270
+ const lines = String(cell.value).split('\n').length;
44271
+ const contentHeight = lineHeight * lines + 10;
44272
+ maxHeight = Math.max(maxHeight, contentHeight);
44273
+ }
44274
+ }
44275
+ });
44276
+ newRowDimensions[rowIndex] = {
44277
+ top: 0,
44278
+ height: maxHeight
44279
+ };
44280
+ });
44281
+ const columnCount = props.data[0] ? props.data[0].length : 0;
44282
+ for (let col = 0; col < columnCount; col++) {
44283
+ let maxWidth = DEFAULT_COLUMN_WIDTH;
44284
+ props.data.forEach(rowData => {
44285
+ const cell = rowData[col];
44286
+ if (cell) {
44287
+ const cellWidth = parseFloat(String(cell.style?.width).replace('px', '')) || DEFAULT_COLUMN_WIDTH;
44288
+ maxWidth = Math.max(maxWidth, cellWidth);
44289
+ if (cell.value && !['file'].includes(cell?.inputType?.type ?? 'text')) {
44290
+ const font = getFontString(cell);
44291
+ const textWidth = measureText(String(cell.value), font) + 20;
44292
+ maxWidth = Math.max(maxWidth, textWidth);
44293
+ }
44294
+ }
44295
+ });
44296
+ newColumnDimensions[col] = {
44297
+ left: 0,
44298
+ width: maxWidth
44299
+ };
44300
+ }
44239
44301
  setSheetChange(prev => !prev);
44240
44302
  return {
44241
44303
  ...INITIAL_STATE,
44242
44304
  model,
44243
- selected: props.selected || INITIAL_STATE.selected
44305
+ selected: props.selected || INITIAL_STATE.selected,
44306
+ rowDimensions: newRowDimensions,
44307
+ columnDimensions: newColumnDimensions
44244
44308
  };
44245
- }, [props.createFormulaParser, props.data, props.selected]);
44309
+ }, [props.createFormulaParser, props.data, props.selected, props.minimumColumnWidth]);
44246
44310
  const reducerElements = React__namespace.useReducer(reducer, initialState);
44247
44311
  const [state, dispatch] = reducerElements;
44248
44312
  const size = React__namespace.useMemo(() => {
@@ -44355,10 +44419,10 @@ const Spreadsheet = /*#__PURE__*/React__namespace.forwardRef(function Spreadshee
44355
44419
  prevSelectedPropRef.current = props.selected;
44356
44420
  }, [props.selected, setSelection$1]);
44357
44421
  // Update data when props.data changes
44358
- let prevDataPropRef = React__namespace.useRef(props.data);
44422
+ let prevDataPropRef = React__namespace.useRef();
44359
44423
  React__namespace.useEffect(() => {
44360
44424
  setEditable(editable$1);
44361
- if (props.data !== prevDataPropRef.current) {
44425
+ if (prevDataPropRef.current !== undefined && props.data !== prevDataPropRef.current) {
44362
44426
  setData$1(props.data);
44363
44427
  }
44364
44428
  prevDataPropRef.current = props.data;
@@ -44523,7 +44587,7 @@ const Spreadsheet = /*#__PURE__*/React__namespace.forwardRef(function Spreadshee
44523
44587
  requestAnimationFrame(() => {
44524
44588
  let scrollTop = 0;
44525
44589
  for (let r = 0; r <= row; r++) {
44526
- scrollTop += state.rowDimensions?.[r]?.height || DEFAULT_ROW_HEIGHT;
44590
+ scrollTop += state.rowDimensions[r]?.height || DEFAULT_ROW_HEIGHT;
44527
44591
  }
44528
44592
  requestAnimationFrame(() => {
44529
44593
  if (!rootRef.current) return;
@@ -44542,7 +44606,7 @@ const Spreadsheet = /*#__PURE__*/React__namespace.forwardRef(function Spreadshee
44542
44606
  requestAnimationFrame(() => {
44543
44607
  let scrollLeft = 0;
44544
44608
  for (let c = 0; c <= column; c++) {
44545
- scrollLeft += state.columnDimensions?.[c]?.width || DEFAULT_COLUMN_WIDTH;
44609
+ scrollLeft += state.columnDimensions[c]?.width || DEFAULT_COLUMN_WIDTH;
44546
44610
  }
44547
44611
  requestAnimationFrame(() => {
44548
44612
  if (!rootRef.current) return;