@xcelsior/ui-spreadsheets 1.1.10 → 1.1.11

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/dist/index.js CHANGED
@@ -3881,11 +3881,13 @@ function Spreadsheet({
3881
3881
  column: col
3882
3882
  }));
3883
3883
  }
3884
- const items = [];
3884
+ const leftPinnedItems = [];
3885
+ const middleItems = [];
3886
+ const rightPinnedItems = [];
3885
3887
  for (const group of columnGroups) {
3886
3888
  const isCollapsed = collapsedGroups.has(group.id);
3887
3889
  if (isCollapsed) {
3888
- items.push({
3890
+ middleItems.push({
3889
3891
  type: "collapsed-placeholder",
3890
3892
  groupId: group.id,
3891
3893
  headerColor: group.headerColor
@@ -3897,7 +3899,14 @@ function Spreadsheet({
3897
3899
  return true;
3898
3900
  });
3899
3901
  for (const col of groupVisibleCols) {
3900
- items.push({ type: "column", column: col });
3902
+ const pinSide = pinnedColumns.get(col.id);
3903
+ if (pinSide === "left") {
3904
+ leftPinnedItems.push({ type: "column", column: col });
3905
+ } else if (pinSide === "right") {
3906
+ rightPinnedItems.push({ type: "column", column: col });
3907
+ } else {
3908
+ middleItems.push({ type: "column", column: col });
3909
+ }
3901
3910
  }
3902
3911
  }
3903
3912
  const allGroupedIds = new Set(
@@ -3905,11 +3914,78 @@ function Spreadsheet({
3905
3914
  );
3906
3915
  for (const col of visibleColumns) {
3907
3916
  if (!allGroupedIds.has(col.id)) {
3908
- items.push({ type: "column", column: col });
3917
+ const pinSide = pinnedColumns.get(col.id);
3918
+ if (pinSide === "left") {
3919
+ leftPinnedItems.push({ type: "column", column: col });
3920
+ } else if (pinSide === "right") {
3921
+ rightPinnedItems.push({ type: "column", column: col });
3922
+ } else {
3923
+ middleItems.push({ type: "column", column: col });
3924
+ }
3909
3925
  }
3910
3926
  }
3911
- return items;
3927
+ const pinnedLeftOrder = Array.from(pinnedColumns.entries()).filter(([id, side]) => side === "left" && id !== ROW_INDEX_COLUMN_ID).map(([id]) => id);
3928
+ const pinnedRightOrder = Array.from(pinnedColumns.entries()).filter(([, side]) => side === "right").map(([id]) => id);
3929
+ leftPinnedItems.sort(
3930
+ (a, b) => pinnedLeftOrder.indexOf(a.column.id) - pinnedLeftOrder.indexOf(b.column.id)
3931
+ );
3932
+ rightPinnedItems.sort(
3933
+ (a, b) => pinnedRightOrder.indexOf(a.column.id) - pinnedRightOrder.indexOf(b.column.id)
3934
+ );
3935
+ return [...leftPinnedItems, ...middleItems, ...rightPinnedItems];
3912
3936
  }, [columnGroups, collapsedGroups, columns, pinnedColumns, visibleColumns]);
3937
+ const groupHeaderItems = (0, import_react17.useMemo)(() => {
3938
+ if (!columnGroups || columnGroups.length === 0) return null;
3939
+ const leftPinned = [];
3940
+ const groups = [];
3941
+ const rightPinned = [];
3942
+ for (const group of columnGroups) {
3943
+ const isCollapsed = collapsedGroups.has(group.id);
3944
+ const groupColumns = (columns || []).filter((c) => group.columns.includes(c.id));
3945
+ const visibleGroupColumns = isCollapsed ? groupColumns.filter((c) => pinnedColumns.has(c.id)) : groupColumns;
3946
+ let movedLeftCount = 0;
3947
+ let movedRightCount = 0;
3948
+ for (const col of visibleGroupColumns) {
3949
+ const pinSide = pinnedColumns.get(col.id);
3950
+ if (pinSide === "left") {
3951
+ movedLeftCount++;
3952
+ leftPinned.push({
3953
+ type: "pinned-column",
3954
+ columnId: col.id,
3955
+ headerColor: group.headerColor,
3956
+ pinSide: "left"
3957
+ });
3958
+ } else if (pinSide === "right") {
3959
+ movedRightCount++;
3960
+ rightPinned.push({
3961
+ type: "pinned-column",
3962
+ columnId: col.id,
3963
+ headerColor: group.headerColor,
3964
+ pinSide: "right"
3965
+ });
3966
+ }
3967
+ }
3968
+ const remainingCols = visibleGroupColumns.length - movedLeftCount - movedRightCount;
3969
+ const colSpan = remainingCols + (isCollapsed ? 1 : 0);
3970
+ if (colSpan > 0) {
3971
+ groups.push({
3972
+ type: "group",
3973
+ group,
3974
+ colSpan,
3975
+ isCollapsed
3976
+ });
3977
+ }
3978
+ }
3979
+ const pinnedLeftOrder = Array.from(pinnedColumns.entries()).filter(([id, side]) => side === "left" && id !== ROW_INDEX_COLUMN_ID).map(([id]) => id);
3980
+ const pinnedRightOrder = Array.from(pinnedColumns.entries()).filter(([, side]) => side === "right").map(([id]) => id);
3981
+ leftPinned.sort(
3982
+ (a, b) => pinnedLeftOrder.indexOf(a.columnId) - pinnedLeftOrder.indexOf(b.columnId)
3983
+ );
3984
+ rightPinned.sort(
3985
+ (a, b) => pinnedRightOrder.indexOf(a.columnId) - pinnedRightOrder.indexOf(b.columnId)
3986
+ );
3987
+ return [...leftPinned, ...groups, ...rightPinned];
3988
+ }, [columnGroups, collapsedGroups, columns, pinnedColumns]);
3913
3989
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: cn("flex flex-col h-full bg-white", className), children: [
3914
3990
  showToolbar && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3915
3991
  SpreadsheetToolbar,
@@ -3949,7 +4025,7 @@ function Spreadsheet({
3949
4025
  },
3950
4026
  children: /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("table", { className: "w-full border-separate border-spacing-0 text-xs select-none", children: [
3951
4027
  /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("thead", { children: [
3952
- columnGroups && /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("tr", { children: [
4028
+ columnGroups && groupHeaderItems && /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("tr", { children: [
3953
4029
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3954
4030
  RowIndexColumnHeader,
3955
4031
  {
@@ -3962,16 +4038,31 @@ function Spreadsheet({
3962
4038
  compactMode: effectiveCompactMode
3963
4039
  }
3964
4040
  ),
3965
- columnGroups.map((group) => {
3966
- const groupColumns = (columns || []).filter(
3967
- (c) => group.columns.includes(c.id)
3968
- );
3969
- const isCollapsed = collapsedGroups.has(group.id);
3970
- const visibleGroupColumns = isCollapsed ? groupColumns.filter((c) => pinnedColumns.has(c.id)) : groupColumns;
3971
- const colSpan = Math.max(
3972
- 1,
3973
- visibleGroupColumns.length + (isCollapsed ? 1 : 0)
3974
- );
4041
+ groupHeaderItems.map((item) => {
4042
+ if (item.type === "pinned-column") {
4043
+ const col = columns.find(
4044
+ (c) => c.id === item.columnId
4045
+ );
4046
+ const isPinnedLeft = item.pinSide === "left";
4047
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
4048
+ "th",
4049
+ {
4050
+ className: cn(
4051
+ "border border-gray-200 px-2 py-1.5 text-center font-bold text-gray-700",
4052
+ "z-30"
4053
+ ),
4054
+ style: {
4055
+ backgroundColor: item.headerColor || "rgb(243 244 246)",
4056
+ position: "sticky",
4057
+ left: isPinnedLeft ? `${getColumnLeftOffset(item.columnId)}px` : void 0,
4058
+ right: !isPinnedLeft ? `${getColumnRightOffset(item.columnId)}px` : void 0,
4059
+ minWidth: col?.minWidth || col?.width
4060
+ }
4061
+ },
4062
+ `pinned-group-${item.columnId}`
4063
+ );
4064
+ }
4065
+ const { group, colSpan, isCollapsed } = item;
3975
4066
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3976
4067
  "th",
3977
4068
  {