@ricsam/react-spreadsheets 0.0.12 → 0.0.14

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,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/react-spreadsheets",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "type": "commonjs"
5
5
  }
package/dist/mjs/lib.mjs CHANGED
@@ -3370,13 +3370,21 @@ class WorkbookSelectionManager {
3370
3370
  if (cachedSelections && manager.getState().selections.length === 0) {
3371
3371
  manager.replaceSelections(cachedSelections);
3372
3372
  }
3373
+ let previousFocus = manager.getState().hasFocus;
3374
+ let previousSelections = JSON.stringify(manager.getState().selections);
3373
3375
  const focusCleanup = manager.observeStateChange((state) => state.hasFocus, (hasFocus) => {
3376
+ if (hasFocus === previousFocus)
3377
+ return;
3378
+ previousFocus = hasFocus;
3374
3379
  if (hasFocus && !this.applyingRangeFocus.has(manager)) {
3375
3380
  this.rememberSelections(manager, registeredContext);
3376
3381
  this.emitChange();
3377
3382
  }
3378
3383
  });
3379
3384
  const selectionCleanup = manager.observeStateChange((state) => JSON.stringify(state.selections), (selectionsJson) => {
3385
+ if (selectionsJson === previousSelections)
3386
+ return;
3387
+ previousSelections = selectionsJson;
3380
3388
  if (this.applyingRangeFocus.has(manager))
3381
3389
  return;
3382
3390
  const selections = JSON.parse(selectionsJson);
@@ -3936,6 +3944,186 @@ function FormulaSheet({
3936
3944
  viewId,
3937
3945
  workbookName
3938
3946
  ]);
3947
+ const renderCallbacks = useMemo2(() => {
3948
+ const metadata = engine.getWorkbookMetadata(workbookName);
3949
+ const defaults = metadata?.defaultCellStyle;
3950
+ const fontStyle = (style) => ({
3951
+ ...style?.fontFamily && { fontFamily: style.fontFamily },
3952
+ ...style?.bold !== undefined && { fontWeight: style.bold ? "bold" : "normal" },
3953
+ ...style?.italic !== undefined && { fontStyle: style.italic ? "italic" : "normal" },
3954
+ ...style?.underline !== undefined && { textDecoration: style.underline ? "underline" : "none" }
3955
+ });
3956
+ const styles = new Map;
3957
+ const getStyle = (cell) => {
3958
+ if (styles.has(cell.id))
3959
+ return styles.get(cell.id);
3960
+ const explicit = engine.getCellStyle({
3961
+ sheetName,
3962
+ workbookName,
3963
+ colIndex: cell.colIndex,
3964
+ rowIndex: cell.rowIndex
3965
+ });
3966
+ const style = defaults ? { ...defaults, ...explicit } : explicit;
3967
+ if (styles.size >= 4096)
3968
+ styles.clear();
3969
+ styles.set(cell.id, style);
3970
+ return style;
3971
+ };
3972
+ return {
3973
+ customCellStyle: (cell) => {
3974
+ const conditionalStyle = getStyle(cell);
3975
+ const tableInfo = engine.isCellInTable({
3976
+ sheetName,
3977
+ colIndex: cell.colIndex,
3978
+ rowIndex: cell.rowIndex,
3979
+ workbookName
3980
+ });
3981
+ if (!tableInfo) {
3982
+ const style = conditionalStyle ? {
3983
+ ...conditionalStyle.backgroundColor && {
3984
+ backgroundColor: conditionalStyle.backgroundColor
3985
+ },
3986
+ ...conditionalStyle.color && {
3987
+ color: conditionalStyle.color
3988
+ },
3989
+ ...conditionalStyle.fontSize && {
3990
+ fontSize: conditionalStyle.fontSize
3991
+ },
3992
+ ...fontStyle(conditionalStyle),
3993
+ ...getBorderCellStyle(conditionalStyle),
3994
+ ...getWrapCellStyle(conditionalStyle)
3995
+ } : {};
3996
+ return customCellStyle ? customCellStyle(cell, style) : style;
3997
+ }
3998
+ const isHeaderRow = cell.rowIndex === tableInfo.start.rowIndex;
3999
+ const isFirstColumn = cell.colIndex === tableInfo.start.colIndex;
4000
+ const isLastColumn = cell.colIndex === tableInfo.start.colIndex + tableInfo.headers.size - 1;
4001
+ const isLastRow = tableInfo.endRow.type === "number" ? cell.rowIndex === tableInfo.endRow.value : false;
4002
+ const style = {
4003
+ border: "1px solid var(--_rsp-table-border-light)"
4004
+ };
4005
+ if (isHeaderRow) {
4006
+ style.backgroundColor = "var(--_rsp-table-header-bg)";
4007
+ style.color = "var(--_rsp-table-header-color)";
4008
+ style.fontWeight = "bold";
4009
+ style.borderBottom = "2px solid var(--_rsp-table-header-border)";
4010
+ } else {
4011
+ const dataRowIndex = cell.rowIndex - tableInfo.start.rowIndex - 1;
4012
+ if (dataRowIndex % 2 === 0) {
4013
+ style.backgroundColor = "var(--_rsp-table-even-row-bg)";
4014
+ } else {
4015
+ style.backgroundColor = "var(--_rsp-table-odd-row-bg)";
4016
+ }
4017
+ }
4018
+ if (isFirstColumn) {
4019
+ style.borderLeft = "2px solid var(--_rsp-table-border-color)";
4020
+ }
4021
+ if (isLastColumn) {
4022
+ style.borderRight = "2px solid var(--_rsp-table-border-color)";
4023
+ }
4024
+ if (isHeaderRow) {
4025
+ style.borderTop = "2px solid var(--_rsp-table-border-color)";
4026
+ }
4027
+ if (isLastRow) {
4028
+ style.borderBottom = "2px solid var(--_rsp-table-border-color)";
4029
+ }
4030
+ if (conditionalStyle?.backgroundColor) {
4031
+ style.backgroundColor = conditionalStyle.backgroundColor;
4032
+ }
4033
+ if (conditionalStyle?.color) {
4034
+ style.color = conditionalStyle.color;
4035
+ }
4036
+ if (conditionalStyle?.fontSize) {
4037
+ style.fontSize = conditionalStyle.fontSize;
4038
+ }
4039
+ Object.assign(style, fontStyle(conditionalStyle));
4040
+ Object.assign(style, getBorderCellStyle(conditionalStyle));
4041
+ Object.assign(style, getWrapCellStyle(conditionalStyle));
4042
+ if (customCellStyle) {
4043
+ return customCellStyle(cell, style);
4044
+ }
4045
+ return style;
4046
+ },
4047
+ customCellRenderer: (cell) => {
4048
+ const cellRef = getCellReference2({
4049
+ colIndex: cell.colIndex,
4050
+ rowIndex: cell.rowIndex
4051
+ });
4052
+ const value = showFormulas ? sheet?.content.get(cellRef) : engine.getCellValue({
4053
+ sheetName,
4054
+ workbookName,
4055
+ colIndex: cell.colIndex,
4056
+ rowIndex: cell.rowIndex
4057
+ }, verboseErrors);
4058
+ const conditionalStyle = getStyle(cell);
4059
+ const conditionalStyleProps = {};
4060
+ if (conditionalStyle?.backgroundColor) {
4061
+ conditionalStyleProps.backgroundColor = conditionalStyle.backgroundColor;
4062
+ }
4063
+ if (conditionalStyle?.color) {
4064
+ conditionalStyleProps.color = conditionalStyle.color;
4065
+ }
4066
+ if (conditionalStyle?.fontSize) {
4067
+ conditionalStyleProps.fontSize = conditionalStyle.fontSize;
4068
+ }
4069
+ Object.assign(conditionalStyleProps, fontStyle(conditionalStyle), getWrapContentStyle(conditionalStyle));
4070
+ let defaultElement;
4071
+ if (showFormulas) {
4072
+ defaultElement = /* @__PURE__ */ jsx4("div", {
4073
+ "data-conditional-background": conditionalStyle?.backgroundColor,
4074
+ "data-conditional-text-color": conditionalStyle?.color,
4075
+ style: conditionalStyleProps,
4076
+ children: getCellDisplayText(value)
4077
+ });
4078
+ } else if (typeof value === "boolean") {
4079
+ defaultElement = /* @__PURE__ */ jsx4("div", {
4080
+ "data-conditional-background": conditionalStyle?.backgroundColor,
4081
+ "data-conditional-text-color": conditionalStyle?.color,
4082
+ "data-type": "boolean",
4083
+ style: {
4084
+ ...conditionalStyleProps,
4085
+ width: "100%",
4086
+ textAlign: "center",
4087
+ fontFamily: conditionalStyle?.fontFamily ?? "'Courier New', monospace"
4088
+ },
4089
+ children: value ? "TRUE" : "FALSE"
4090
+ });
4091
+ } else if (typeof value === "number") {
4092
+ defaultElement = /* @__PURE__ */ jsx4("div", {
4093
+ "data-conditional-background": conditionalStyle?.backgroundColor,
4094
+ "data-conditional-text-color": conditionalStyle?.color,
4095
+ "data-type": "number",
4096
+ style: { ...conditionalStyleProps, width: "100%", textAlign: "right" },
4097
+ children: value.toLocaleString("en-US", {
4098
+ minimumFractionDigits: 0,
4099
+ maximumFractionDigits: 10
4100
+ })
4101
+ });
4102
+ } else {
4103
+ defaultElement = /* @__PURE__ */ jsx4("div", {
4104
+ "data-conditional-background": conditionalStyle?.backgroundColor,
4105
+ "data-conditional-text-color": conditionalStyle?.color,
4106
+ style: { ...conditionalStyleProps, width: "100%", textAlign: "left" },
4107
+ children: getCellDisplayText(value)
4108
+ });
4109
+ }
4110
+ if (customCellRenderer) {
4111
+ return customCellRenderer(cell, defaultElement);
4112
+ }
4113
+ return defaultElement;
4114
+ }
4115
+ };
4116
+ }, [
4117
+ engine,
4118
+ state,
4119
+ workbookName,
4120
+ sheetName,
4121
+ sheet,
4122
+ showFormulas,
4123
+ verboseErrors,
4124
+ customCellStyle,
4125
+ customCellRenderer
4126
+ ]);
3939
4127
  if (!sheet) {
3940
4128
  return /* @__PURE__ */ jsxs3("div", {
3941
4129
  className: "rsp-root rsp-workbook",
@@ -3977,183 +4165,7 @@ function FormulaSheet({
3977
4165
  containerProps: isSelected && selectedArea ? {
3978
4166
  "data-grid-no-interaction": "true"
3979
4167
  } : {},
3980
- customCellStyle: (cell) => {
3981
- const conditionalStyle = engine.getCellStyle({
3982
- sheetName,
3983
- colIndex: cell.colIndex,
3984
- rowIndex: cell.rowIndex,
3985
- workbookName
3986
- });
3987
- const tableInfo = engine.isCellInTable({
3988
- sheetName,
3989
- colIndex: cell.colIndex,
3990
- rowIndex: cell.rowIndex,
3991
- workbookName
3992
- });
3993
- if (!tableInfo) {
3994
- const style = conditionalStyle ? {
3995
- ...conditionalStyle.backgroundColor && {
3996
- backgroundColor: conditionalStyle.backgroundColor
3997
- },
3998
- ...conditionalStyle.color && {
3999
- color: conditionalStyle.color
4000
- },
4001
- ...conditionalStyle.fontSize && {
4002
- fontSize: conditionalStyle.fontSize
4003
- },
4004
- ...conditionalStyle.bold && {
4005
- fontWeight: "bold"
4006
- },
4007
- ...conditionalStyle.italic && {
4008
- fontStyle: "italic"
4009
- },
4010
- ...conditionalStyle.underline && {
4011
- textDecoration: "underline"
4012
- },
4013
- ...getBorderCellStyle(conditionalStyle),
4014
- ...getWrapCellStyle(conditionalStyle)
4015
- } : {};
4016
- return customCellStyle ? customCellStyle(cell, style) : style;
4017
- }
4018
- const isHeaderRow = cell.rowIndex === tableInfo.start.rowIndex;
4019
- const isFirstColumn = cell.colIndex === tableInfo.start.colIndex;
4020
- const isLastColumn = cell.colIndex === tableInfo.start.colIndex + tableInfo.headers.size - 1;
4021
- const isLastRow = tableInfo.endRow.type === "number" ? cell.rowIndex === tableInfo.endRow.value : false;
4022
- const style = {
4023
- border: "1px solid var(--_rsp-table-border-light)"
4024
- };
4025
- if (isHeaderRow) {
4026
- style.backgroundColor = "var(--_rsp-table-header-bg)";
4027
- style.color = "var(--_rsp-table-header-color)";
4028
- style.fontWeight = "bold";
4029
- style.borderBottom = "2px solid var(--_rsp-table-header-border)";
4030
- } else {
4031
- const dataRowIndex = cell.rowIndex - tableInfo.start.rowIndex - 1;
4032
- if (dataRowIndex % 2 === 0) {
4033
- style.backgroundColor = "var(--_rsp-table-even-row-bg)";
4034
- } else {
4035
- style.backgroundColor = "var(--_rsp-table-odd-row-bg)";
4036
- }
4037
- }
4038
- if (isFirstColumn) {
4039
- style.borderLeft = "2px solid var(--_rsp-table-border-color)";
4040
- }
4041
- if (isLastColumn) {
4042
- style.borderRight = "2px solid var(--_rsp-table-border-color)";
4043
- }
4044
- if (isHeaderRow) {
4045
- style.borderTop = "2px solid var(--_rsp-table-border-color)";
4046
- }
4047
- if (isLastRow) {
4048
- style.borderBottom = "2px solid var(--_rsp-table-border-color)";
4049
- }
4050
- if (conditionalStyle?.backgroundColor) {
4051
- style.backgroundColor = conditionalStyle.backgroundColor;
4052
- }
4053
- if (conditionalStyle?.color) {
4054
- style.color = conditionalStyle.color;
4055
- }
4056
- if (conditionalStyle?.fontSize) {
4057
- style.fontSize = conditionalStyle.fontSize;
4058
- }
4059
- if (conditionalStyle?.bold) {
4060
- style.fontWeight = "bold";
4061
- }
4062
- if (conditionalStyle?.italic) {
4063
- style.fontStyle = "italic";
4064
- }
4065
- if (conditionalStyle?.underline) {
4066
- style.textDecoration = "underline";
4067
- }
4068
- Object.assign(style, getBorderCellStyle(conditionalStyle));
4069
- Object.assign(style, getWrapCellStyle(conditionalStyle));
4070
- if (customCellStyle) {
4071
- return customCellStyle(cell, style);
4072
- }
4073
- return style;
4074
- },
4075
- customCellRenderer: (cell) => {
4076
- const cellRef = getCellReference2({
4077
- colIndex: cell.colIndex,
4078
- rowIndex: cell.rowIndex
4079
- });
4080
- const value = showFormulas ? sheet?.content.get(cellRef) : engine.getCellValue({
4081
- sheetName,
4082
- workbookName,
4083
- colIndex: cell.colIndex,
4084
- rowIndex: cell.rowIndex
4085
- }, verboseErrors);
4086
- const conditionalStyle = engine.getCellStyle({
4087
- sheetName,
4088
- colIndex: cell.colIndex,
4089
- rowIndex: cell.rowIndex,
4090
- workbookName
4091
- });
4092
- const conditionalStyleProps = {};
4093
- if (conditionalStyle?.backgroundColor) {
4094
- conditionalStyleProps.backgroundColor = conditionalStyle.backgroundColor;
4095
- }
4096
- if (conditionalStyle?.color) {
4097
- conditionalStyleProps.color = conditionalStyle.color;
4098
- }
4099
- if (conditionalStyle?.fontSize) {
4100
- conditionalStyleProps.fontSize = conditionalStyle.fontSize;
4101
- }
4102
- if (conditionalStyle?.bold) {
4103
- conditionalStyleProps.fontWeight = "bold";
4104
- }
4105
- if (conditionalStyle?.italic) {
4106
- conditionalStyleProps.fontStyle = "italic";
4107
- }
4108
- if (conditionalStyle?.underline) {
4109
- conditionalStyleProps.textDecoration = "underline";
4110
- }
4111
- Object.assign(conditionalStyleProps, getWrapContentStyle(conditionalStyle));
4112
- let defaultElement;
4113
- if (showFormulas) {
4114
- defaultElement = /* @__PURE__ */ jsx4("div", {
4115
- "data-conditional-background": conditionalStyle?.backgroundColor,
4116
- "data-conditional-text-color": conditionalStyle?.color,
4117
- style: conditionalStyleProps,
4118
- children: getCellDisplayText(value)
4119
- });
4120
- } else if (typeof value === "boolean") {
4121
- defaultElement = /* @__PURE__ */ jsx4("div", {
4122
- "data-conditional-background": conditionalStyle?.backgroundColor,
4123
- "data-conditional-text-color": conditionalStyle?.color,
4124
- "data-type": "boolean",
4125
- style: {
4126
- ...conditionalStyleProps,
4127
- width: "100%",
4128
- textAlign: "center",
4129
- fontFamily: "'Courier New', monospace"
4130
- },
4131
- children: value ? "TRUE" : "FALSE"
4132
- });
4133
- } else if (typeof value === "number") {
4134
- defaultElement = /* @__PURE__ */ jsx4("div", {
4135
- "data-conditional-background": conditionalStyle?.backgroundColor,
4136
- "data-conditional-text-color": conditionalStyle?.color,
4137
- "data-type": "number",
4138
- style: { ...conditionalStyleProps, width: "100%", textAlign: "right" },
4139
- children: value.toLocaleString("en-US", {
4140
- minimumFractionDigits: 0,
4141
- maximumFractionDigits: 10
4142
- })
4143
- });
4144
- } else {
4145
- defaultElement = /* @__PURE__ */ jsx4("div", {
4146
- "data-conditional-background": conditionalStyle?.backgroundColor,
4147
- "data-conditional-text-color": conditionalStyle?.color,
4148
- style: { ...conditionalStyleProps, width: "100%", textAlign: "left" },
4149
- children: getCellDisplayText(value)
4150
- });
4151
- }
4152
- if (customCellRenderer) {
4153
- return customCellRenderer(cell, defaultElement);
4154
- }
4155
- return defaultElement;
4156
- }
4168
+ ...renderCallbacks
4157
4169
  })
4158
4170
  })
4159
4171
  ]
@@ -4563,4 +4575,4 @@ export {
4563
4575
  useResizeObserver
4564
4576
  };
4565
4577
 
4566
- //# debugId=FA27216279C90A7964756E2164756E21
4578
+ //# debugId=05DAA767DBF706AE64756E2164756E21