@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.mjs CHANGED
@@ -3839,11 +3839,13 @@ function Spreadsheet({
3839
3839
  column: col
3840
3840
  }));
3841
3841
  }
3842
- const items = [];
3842
+ const leftPinnedItems = [];
3843
+ const middleItems = [];
3844
+ const rightPinnedItems = [];
3843
3845
  for (const group of columnGroups) {
3844
3846
  const isCollapsed = collapsedGroups.has(group.id);
3845
3847
  if (isCollapsed) {
3846
- items.push({
3848
+ middleItems.push({
3847
3849
  type: "collapsed-placeholder",
3848
3850
  groupId: group.id,
3849
3851
  headerColor: group.headerColor
@@ -3855,7 +3857,14 @@ function Spreadsheet({
3855
3857
  return true;
3856
3858
  });
3857
3859
  for (const col of groupVisibleCols) {
3858
- items.push({ type: "column", column: col });
3860
+ const pinSide = pinnedColumns.get(col.id);
3861
+ if (pinSide === "left") {
3862
+ leftPinnedItems.push({ type: "column", column: col });
3863
+ } else if (pinSide === "right") {
3864
+ rightPinnedItems.push({ type: "column", column: col });
3865
+ } else {
3866
+ middleItems.push({ type: "column", column: col });
3867
+ }
3859
3868
  }
3860
3869
  }
3861
3870
  const allGroupedIds = new Set(
@@ -3863,11 +3872,78 @@ function Spreadsheet({
3863
3872
  );
3864
3873
  for (const col of visibleColumns) {
3865
3874
  if (!allGroupedIds.has(col.id)) {
3866
- items.push({ type: "column", column: col });
3875
+ const pinSide = pinnedColumns.get(col.id);
3876
+ if (pinSide === "left") {
3877
+ leftPinnedItems.push({ type: "column", column: col });
3878
+ } else if (pinSide === "right") {
3879
+ rightPinnedItems.push({ type: "column", column: col });
3880
+ } else {
3881
+ middleItems.push({ type: "column", column: col });
3882
+ }
3867
3883
  }
3868
3884
  }
3869
- return items;
3885
+ const pinnedLeftOrder = Array.from(pinnedColumns.entries()).filter(([id, side]) => side === "left" && id !== ROW_INDEX_COLUMN_ID).map(([id]) => id);
3886
+ const pinnedRightOrder = Array.from(pinnedColumns.entries()).filter(([, side]) => side === "right").map(([id]) => id);
3887
+ leftPinnedItems.sort(
3888
+ (a, b) => pinnedLeftOrder.indexOf(a.column.id) - pinnedLeftOrder.indexOf(b.column.id)
3889
+ );
3890
+ rightPinnedItems.sort(
3891
+ (a, b) => pinnedRightOrder.indexOf(a.column.id) - pinnedRightOrder.indexOf(b.column.id)
3892
+ );
3893
+ return [...leftPinnedItems, ...middleItems, ...rightPinnedItems];
3870
3894
  }, [columnGroups, collapsedGroups, columns, pinnedColumns, visibleColumns]);
3895
+ const groupHeaderItems = useMemo5(() => {
3896
+ if (!columnGroups || columnGroups.length === 0) return null;
3897
+ const leftPinned = [];
3898
+ const groups = [];
3899
+ const rightPinned = [];
3900
+ for (const group of columnGroups) {
3901
+ const isCollapsed = collapsedGroups.has(group.id);
3902
+ const groupColumns = (columns || []).filter((c) => group.columns.includes(c.id));
3903
+ const visibleGroupColumns = isCollapsed ? groupColumns.filter((c) => pinnedColumns.has(c.id)) : groupColumns;
3904
+ let movedLeftCount = 0;
3905
+ let movedRightCount = 0;
3906
+ for (const col of visibleGroupColumns) {
3907
+ const pinSide = pinnedColumns.get(col.id);
3908
+ if (pinSide === "left") {
3909
+ movedLeftCount++;
3910
+ leftPinned.push({
3911
+ type: "pinned-column",
3912
+ columnId: col.id,
3913
+ headerColor: group.headerColor,
3914
+ pinSide: "left"
3915
+ });
3916
+ } else if (pinSide === "right") {
3917
+ movedRightCount++;
3918
+ rightPinned.push({
3919
+ type: "pinned-column",
3920
+ columnId: col.id,
3921
+ headerColor: group.headerColor,
3922
+ pinSide: "right"
3923
+ });
3924
+ }
3925
+ }
3926
+ const remainingCols = visibleGroupColumns.length - movedLeftCount - movedRightCount;
3927
+ const colSpan = remainingCols + (isCollapsed ? 1 : 0);
3928
+ if (colSpan > 0) {
3929
+ groups.push({
3930
+ type: "group",
3931
+ group,
3932
+ colSpan,
3933
+ isCollapsed
3934
+ });
3935
+ }
3936
+ }
3937
+ const pinnedLeftOrder = Array.from(pinnedColumns.entries()).filter(([id, side]) => side === "left" && id !== ROW_INDEX_COLUMN_ID).map(([id]) => id);
3938
+ const pinnedRightOrder = Array.from(pinnedColumns.entries()).filter(([, side]) => side === "right").map(([id]) => id);
3939
+ leftPinned.sort(
3940
+ (a, b) => pinnedLeftOrder.indexOf(a.columnId) - pinnedLeftOrder.indexOf(b.columnId)
3941
+ );
3942
+ rightPinned.sort(
3943
+ (a, b) => pinnedRightOrder.indexOf(a.columnId) - pinnedRightOrder.indexOf(b.columnId)
3944
+ );
3945
+ return [...leftPinned, ...groups, ...rightPinned];
3946
+ }, [columnGroups, collapsedGroups, columns, pinnedColumns]);
3871
3947
  return /* @__PURE__ */ jsxs12("div", { className: cn("flex flex-col h-full bg-white", className), children: [
3872
3948
  showToolbar && /* @__PURE__ */ jsx12(
3873
3949
  SpreadsheetToolbar,
@@ -3907,7 +3983,7 @@ function Spreadsheet({
3907
3983
  },
3908
3984
  children: /* @__PURE__ */ jsxs12("table", { className: "w-full border-separate border-spacing-0 text-xs select-none", children: [
3909
3985
  /* @__PURE__ */ jsxs12("thead", { children: [
3910
- columnGroups && /* @__PURE__ */ jsxs12("tr", { children: [
3986
+ columnGroups && groupHeaderItems && /* @__PURE__ */ jsxs12("tr", { children: [
3911
3987
  /* @__PURE__ */ jsx12(
3912
3988
  RowIndexColumnHeader,
3913
3989
  {
@@ -3920,16 +3996,31 @@ function Spreadsheet({
3920
3996
  compactMode: effectiveCompactMode
3921
3997
  }
3922
3998
  ),
3923
- columnGroups.map((group) => {
3924
- const groupColumns = (columns || []).filter(
3925
- (c) => group.columns.includes(c.id)
3926
- );
3927
- const isCollapsed = collapsedGroups.has(group.id);
3928
- const visibleGroupColumns = isCollapsed ? groupColumns.filter((c) => pinnedColumns.has(c.id)) : groupColumns;
3929
- const colSpan = Math.max(
3930
- 1,
3931
- visibleGroupColumns.length + (isCollapsed ? 1 : 0)
3932
- );
3999
+ groupHeaderItems.map((item) => {
4000
+ if (item.type === "pinned-column") {
4001
+ const col = columns.find(
4002
+ (c) => c.id === item.columnId
4003
+ );
4004
+ const isPinnedLeft = item.pinSide === "left";
4005
+ return /* @__PURE__ */ jsx12(
4006
+ "th",
4007
+ {
4008
+ className: cn(
4009
+ "border border-gray-200 px-2 py-1.5 text-center font-bold text-gray-700",
4010
+ "z-30"
4011
+ ),
4012
+ style: {
4013
+ backgroundColor: item.headerColor || "rgb(243 244 246)",
4014
+ position: "sticky",
4015
+ left: isPinnedLeft ? `${getColumnLeftOffset(item.columnId)}px` : void 0,
4016
+ right: !isPinnedLeft ? `${getColumnRightOffset(item.columnId)}px` : void 0,
4017
+ minWidth: col?.minWidth || col?.width
4018
+ }
4019
+ },
4020
+ `pinned-group-${item.columnId}`
4021
+ );
4022
+ }
4023
+ const { group, colSpan, isCollapsed } = item;
3933
4024
  return /* @__PURE__ */ jsx12(
3934
4025
  "th",
3935
4026
  {