@tap-payments/os-micro-frontend-shared 0.1.440-test.1 → 0.1.440-test.2-test.3

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,33 +1,20 @@
1
- import { useState, useCallback, useRef, useEffect, useMemo } from 'react';
1
+ import { useState, useCallback, useRef, useEffect } from 'react';
2
2
  import { getColumnWidth as getStoredColumnWidth } from '../../../../../../utils/index.js';
3
3
  import { getColumnId, parseColumnWidth, clampWidth, cleanupEventListeners as cleanupEventListenersUtil, createMouseMoveHandler, getColumnWidthFromState, createResizeEndHandler, } from '../utils/resize';
4
4
  export const useColumnResize = ({ columns, onColumnResize, handleColumnClick, windowId, serviceCode, tableContainerRef }) => {
5
- // Stable column key derived from column IDs — used to detect when real columns replace skeleton columns
6
- const columnKey = useMemo(() => columns.map((col) => getColumnId(col)).join(','), [columns]);
7
- // Memoize initial column widths to prevent unnecessary recalculations
8
- const initialColumnWidths = useMemo(() => {
9
- return columns.reduce((acc, col) => {
10
- const columnId = getColumnId(col);
11
- const defaultWidth = parseColumnWidth(col.width);
12
- // Try to get width from localStorage if windowId and serviceCode are provided
13
- let finalWidth = defaultWidth;
14
- if (windowId && serviceCode) {
15
- try {
16
- const storedWidth = getStoredColumnWidth(windowId, serviceCode, columnId, defaultWidth);
17
- finalWidth = storedWidth !== null && storedWidth !== void 0 ? storedWidth : defaultWidth;
18
- }
19
- catch (error) {
20
- console.warn(`Failed to load stored width for column ${columnId}:`, error);
21
- finalWidth = defaultWidth;
22
- }
23
- }
24
- acc[columnId] = clampWidth(finalWidth);
25
- return acc;
26
- }, {});
27
- // eslint-disable-next-line react-hooks/exhaustive-deps
28
- }, [windowId, serviceCode, columnKey]);
5
+ const buildWidths = (cols) => cols.reduce((acc, col) => {
6
+ const columnId = getColumnId(col);
7
+ const defaultWidth = parseColumnWidth(col.width);
8
+ let finalWidth = defaultWidth;
9
+ if (windowId && serviceCode) {
10
+ const storedWidth = getStoredColumnWidth(windowId, serviceCode, columnId, defaultWidth);
11
+ finalWidth = storedWidth !== null && storedWidth !== void 0 ? storedWidth : defaultWidth;
12
+ }
13
+ acc[columnId] = clampWidth(finalWidth);
14
+ return acc;
15
+ }, {});
29
16
  const [{ columnWidths, isResizing, resizingColumn, resizeIndicatorX }, setResizeState] = useState(() => ({
30
- columnWidths: initialColumnWidths,
17
+ columnWidths: buildWidths(columns),
31
18
  isResizing: false,
32
19
  resizingColumn: null,
33
20
  startX: 0,
@@ -35,6 +22,13 @@ export const useColumnResize = ({ columns, onColumnResize, handleColumnClick, wi
35
22
  resizeIndicatorX: 0,
36
23
  }));
37
24
  const [cursorPosition, setCursorPosition] = useState({ x: 0, y: 0 });
25
+ const prevColumnCountRef = useRef(columns.length);
26
+ useEffect(() => {
27
+ if (columns.length === prevColumnCountRef.current)
28
+ return;
29
+ prevColumnCountRef.current = columns.length;
30
+ setResizeState((prev) => (Object.assign(Object.assign({}, prev), { columnWidths: Object.assign(Object.assign({}, buildWidths(columns)), prev.columnWidths) })));
31
+ }, [columns.length]);
38
32
  // Refs for managing resize state and event listeners
39
33
  const isResizingRef = useRef(false);
40
34
  const initialCursorYRef = useRef(0);
@@ -43,21 +37,6 @@ export const useColumnResize = ({ columns, onColumnResize, handleColumnClick, wi
43
37
  const startWidthRef = useRef(0);
44
38
  const mouseMoveRef = useRef();
45
39
  const mouseUpRef = useRef();
46
- useEffect(() => {
47
- setResizeState((prev) => {
48
- const currentKeys = new Set(Object.keys(prev.columnWidths));
49
- const newKeys = new Set(Object.keys(initialColumnWidths));
50
- if (currentKeys.size !== newKeys.size) {
51
- return Object.assign(Object.assign({}, prev), { columnWidths: initialColumnWidths });
52
- }
53
- const hasChanged = Array.from(newKeys).some((key) => !currentKeys.has(key) || prev.columnWidths[key] !== initialColumnWidths[key]);
54
- if (!hasChanged) {
55
- return prev;
56
- }
57
- return Object.assign(Object.assign({}, prev), { columnWidths: initialColumnWidths });
58
- });
59
- // eslint-disable-next-line react-hooks/exhaustive-deps
60
- }, [initialColumnWidths]);
61
40
  const getColumnWidth = useCallback((columnId) => {
62
41
  return getColumnWidthFromState(columnWidths, columnId);
63
42
  }, [columnWidths]);
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@tap-payments/os-micro-frontend-shared",
3
3
  "description": "Shared components and utilities for Tap Payments micro frontends",
4
- "version": "0.1.440-test.1",
5
- "testVersion": 1,
4
+ "version": "0.1.440-test.2-test.3",
5
+ "testVersion": 3,
6
6
  "type": "module",
7
7
  "main": "build/index.js",
8
8
  "module": "build/index.js",