@ricsam/react-spreadsheets 0.0.13 → 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.13",
3
+ "version": "0.0.14",
4
4
  "type": "commonjs"
5
5
  }
package/dist/mjs/lib.mjs CHANGED
@@ -3944,6 +3944,186 @@ function FormulaSheet({
3944
3944
  viewId,
3945
3945
  workbookName
3946
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
+ ]);
3947
4127
  if (!sheet) {
3948
4128
  return /* @__PURE__ */ jsxs3("div", {
3949
4129
  className: "rsp-root rsp-workbook",
@@ -3985,183 +4165,7 @@ function FormulaSheet({
3985
4165
  containerProps: isSelected && selectedArea ? {
3986
4166
  "data-grid-no-interaction": "true"
3987
4167
  } : {},
3988
- customCellStyle: (cell) => {
3989
- const conditionalStyle = engine.getCellStyle({
3990
- sheetName,
3991
- colIndex: cell.colIndex,
3992
- rowIndex: cell.rowIndex,
3993
- workbookName
3994
- });
3995
- const tableInfo = engine.isCellInTable({
3996
- sheetName,
3997
- colIndex: cell.colIndex,
3998
- rowIndex: cell.rowIndex,
3999
- workbookName
4000
- });
4001
- if (!tableInfo) {
4002
- const style = conditionalStyle ? {
4003
- ...conditionalStyle.backgroundColor && {
4004
- backgroundColor: conditionalStyle.backgroundColor
4005
- },
4006
- ...conditionalStyle.color && {
4007
- color: conditionalStyle.color
4008
- },
4009
- ...conditionalStyle.fontSize && {
4010
- fontSize: conditionalStyle.fontSize
4011
- },
4012
- ...conditionalStyle.bold && {
4013
- fontWeight: "bold"
4014
- },
4015
- ...conditionalStyle.italic && {
4016
- fontStyle: "italic"
4017
- },
4018
- ...conditionalStyle.underline && {
4019
- textDecoration: "underline"
4020
- },
4021
- ...getBorderCellStyle(conditionalStyle),
4022
- ...getWrapCellStyle(conditionalStyle)
4023
- } : {};
4024
- return customCellStyle ? customCellStyle(cell, style) : style;
4025
- }
4026
- const isHeaderRow = cell.rowIndex === tableInfo.start.rowIndex;
4027
- const isFirstColumn = cell.colIndex === tableInfo.start.colIndex;
4028
- const isLastColumn = cell.colIndex === tableInfo.start.colIndex + tableInfo.headers.size - 1;
4029
- const isLastRow = tableInfo.endRow.type === "number" ? cell.rowIndex === tableInfo.endRow.value : false;
4030
- const style = {
4031
- border: "1px solid var(--_rsp-table-border-light)"
4032
- };
4033
- if (isHeaderRow) {
4034
- style.backgroundColor = "var(--_rsp-table-header-bg)";
4035
- style.color = "var(--_rsp-table-header-color)";
4036
- style.fontWeight = "bold";
4037
- style.borderBottom = "2px solid var(--_rsp-table-header-border)";
4038
- } else {
4039
- const dataRowIndex = cell.rowIndex - tableInfo.start.rowIndex - 1;
4040
- if (dataRowIndex % 2 === 0) {
4041
- style.backgroundColor = "var(--_rsp-table-even-row-bg)";
4042
- } else {
4043
- style.backgroundColor = "var(--_rsp-table-odd-row-bg)";
4044
- }
4045
- }
4046
- if (isFirstColumn) {
4047
- style.borderLeft = "2px solid var(--_rsp-table-border-color)";
4048
- }
4049
- if (isLastColumn) {
4050
- style.borderRight = "2px solid var(--_rsp-table-border-color)";
4051
- }
4052
- if (isHeaderRow) {
4053
- style.borderTop = "2px solid var(--_rsp-table-border-color)";
4054
- }
4055
- if (isLastRow) {
4056
- style.borderBottom = "2px solid var(--_rsp-table-border-color)";
4057
- }
4058
- if (conditionalStyle?.backgroundColor) {
4059
- style.backgroundColor = conditionalStyle.backgroundColor;
4060
- }
4061
- if (conditionalStyle?.color) {
4062
- style.color = conditionalStyle.color;
4063
- }
4064
- if (conditionalStyle?.fontSize) {
4065
- style.fontSize = conditionalStyle.fontSize;
4066
- }
4067
- if (conditionalStyle?.bold) {
4068
- style.fontWeight = "bold";
4069
- }
4070
- if (conditionalStyle?.italic) {
4071
- style.fontStyle = "italic";
4072
- }
4073
- if (conditionalStyle?.underline) {
4074
- style.textDecoration = "underline";
4075
- }
4076
- Object.assign(style, getBorderCellStyle(conditionalStyle));
4077
- Object.assign(style, getWrapCellStyle(conditionalStyle));
4078
- if (customCellStyle) {
4079
- return customCellStyle(cell, style);
4080
- }
4081
- return style;
4082
- },
4083
- customCellRenderer: (cell) => {
4084
- const cellRef = getCellReference2({
4085
- colIndex: cell.colIndex,
4086
- rowIndex: cell.rowIndex
4087
- });
4088
- const value = showFormulas ? sheet?.content.get(cellRef) : engine.getCellValue({
4089
- sheetName,
4090
- workbookName,
4091
- colIndex: cell.colIndex,
4092
- rowIndex: cell.rowIndex
4093
- }, verboseErrors);
4094
- const conditionalStyle = engine.getCellStyle({
4095
- sheetName,
4096
- colIndex: cell.colIndex,
4097
- rowIndex: cell.rowIndex,
4098
- workbookName
4099
- });
4100
- const conditionalStyleProps = {};
4101
- if (conditionalStyle?.backgroundColor) {
4102
- conditionalStyleProps.backgroundColor = conditionalStyle.backgroundColor;
4103
- }
4104
- if (conditionalStyle?.color) {
4105
- conditionalStyleProps.color = conditionalStyle.color;
4106
- }
4107
- if (conditionalStyle?.fontSize) {
4108
- conditionalStyleProps.fontSize = conditionalStyle.fontSize;
4109
- }
4110
- if (conditionalStyle?.bold) {
4111
- conditionalStyleProps.fontWeight = "bold";
4112
- }
4113
- if (conditionalStyle?.italic) {
4114
- conditionalStyleProps.fontStyle = "italic";
4115
- }
4116
- if (conditionalStyle?.underline) {
4117
- conditionalStyleProps.textDecoration = "underline";
4118
- }
4119
- Object.assign(conditionalStyleProps, getWrapContentStyle(conditionalStyle));
4120
- let defaultElement;
4121
- if (showFormulas) {
4122
- defaultElement = /* @__PURE__ */ jsx4("div", {
4123
- "data-conditional-background": conditionalStyle?.backgroundColor,
4124
- "data-conditional-text-color": conditionalStyle?.color,
4125
- style: conditionalStyleProps,
4126
- children: getCellDisplayText(value)
4127
- });
4128
- } else if (typeof value === "boolean") {
4129
- defaultElement = /* @__PURE__ */ jsx4("div", {
4130
- "data-conditional-background": conditionalStyle?.backgroundColor,
4131
- "data-conditional-text-color": conditionalStyle?.color,
4132
- "data-type": "boolean",
4133
- style: {
4134
- ...conditionalStyleProps,
4135
- width: "100%",
4136
- textAlign: "center",
4137
- fontFamily: "'Courier New', monospace"
4138
- },
4139
- children: value ? "TRUE" : "FALSE"
4140
- });
4141
- } else if (typeof value === "number") {
4142
- defaultElement = /* @__PURE__ */ jsx4("div", {
4143
- "data-conditional-background": conditionalStyle?.backgroundColor,
4144
- "data-conditional-text-color": conditionalStyle?.color,
4145
- "data-type": "number",
4146
- style: { ...conditionalStyleProps, width: "100%", textAlign: "right" },
4147
- children: value.toLocaleString("en-US", {
4148
- minimumFractionDigits: 0,
4149
- maximumFractionDigits: 10
4150
- })
4151
- });
4152
- } else {
4153
- defaultElement = /* @__PURE__ */ jsx4("div", {
4154
- "data-conditional-background": conditionalStyle?.backgroundColor,
4155
- "data-conditional-text-color": conditionalStyle?.color,
4156
- style: { ...conditionalStyleProps, width: "100%", textAlign: "left" },
4157
- children: getCellDisplayText(value)
4158
- });
4159
- }
4160
- if (customCellRenderer) {
4161
- return customCellRenderer(cell, defaultElement);
4162
- }
4163
- return defaultElement;
4164
- }
4168
+ ...renderCallbacks
4165
4169
  })
4166
4170
  })
4167
4171
  ]
@@ -4571,4 +4575,4 @@ export {
4571
4575
  useResizeObserver
4572
4576
  };
4573
4577
 
4574
- //# debugId=A4984B6C177B85D364756E2164756E21
4578
+ //# debugId=05DAA767DBF706AE64756E2164756E21