@ricsam/react-spreadsheets 0.0.5 → 0.0.7

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/README.md CHANGED
@@ -86,10 +86,63 @@ export function Demo() {
86
86
  `FormulaWorkbook` adds Excel-style sheet tabs, renaming, deletion and zoom on
87
87
  top of `FormulaSheet`.
88
88
 
89
+ ### Formula reference highlights
90
+
91
+ Keep editor-driven reference highlights separate from the user's spreadsheet
92
+ selection. `FormulaSheet` calls `customCellStyle` with both the cell and its
93
+ engine-provided style, so a host can add a transient range fill and perimeter
94
+ without replacing table or conditional formatting:
95
+
96
+ ```tsx
97
+ type Highlight = {
98
+ start: { rowIndex: number; colIndex: number };
99
+ end: { rowIndex: number; colIndex: number };
100
+ };
101
+
102
+ function ReferenceAwareSheet({ highlight }: { highlight?: Highlight }) {
103
+ return (
104
+ <FormulaSheet
105
+ engine={engine}
106
+ workbookName="Workbook1"
107
+ sheetName="Sheet1"
108
+ style={{ height: 480 }}
109
+ customCellStyle={(cell, internalStyle) => {
110
+ if (
111
+ !highlight ||
112
+ cell.rowIndex < highlight.start.rowIndex ||
113
+ cell.rowIndex > highlight.end.rowIndex ||
114
+ cell.colIndex < highlight.start.colIndex ||
115
+ cell.colIndex > highlight.end.colIndex
116
+ ) {
117
+ return internalStyle;
118
+ }
119
+
120
+ const color = "#7c3aed";
121
+ return {
122
+ ...internalStyle,
123
+ backgroundColor: "rgb(124 58 237 / 14%)",
124
+ ...(cell.rowIndex === highlight.start.rowIndex && { borderTopColor: color }),
125
+ ...(cell.rowIndex === highlight.end.rowIndex && { borderBottomColor: color }),
126
+ ...(cell.colIndex === highlight.start.colIndex && { borderLeftColor: color }),
127
+ ...(cell.colIndex === highlight.end.colIndex && { borderRightColor: color }),
128
+ };
129
+ }}
130
+ />
131
+ );
132
+ }
133
+ ```
134
+
135
+ Update `highlight` from the formula editor's caret/reference analysis. Clearing
136
+ it removes the decoration, while the selection manager continues to own mouse,
137
+ keyboard and edit selection state independently. For `FormulaWorkbook`, pass a
138
+ controlled `activeSheet` if the editor should reveal a reference on another
139
+ sheet; the same `customCellStyle` prop is forwarded to its active sheet.
140
+
89
141
  ## Theming
90
142
 
91
- All colors, fonts and sizes are CSS custom properties declared on `:root`, so
92
- you can override them from **any** ancestor of the grid:
143
+ All colors, fonts and sizes are CSS custom properties. The package only ever
144
+ *reads* the public `--rsp-*` names, so an override on **any** ancestor of the
145
+ grid always wins:
93
146
 
94
147
  ```css
95
148
  .my-panel {
@@ -100,6 +153,16 @@ you can override them from **any** ancestor of the grid:
100
153
  }
101
154
  ```
102
155
 
156
+ An override replaces both schemes, so pick a value that works in the mode(s) you
157
+ support, or scope it per scheme:
158
+
159
+ ```css
160
+ .my-panel { --rsp-bg: #ffffff; }
161
+ @media (prefers-color-scheme: dark) {
162
+ .my-panel { --rsp-bg: #10131a; }
163
+ }
164
+ ```
165
+
103
166
  ### Light and dark
104
167
 
105
168
  By default the grid follows the user's OS preference.
@@ -129,6 +192,13 @@ switches.
129
192
  > declaration, which makes shared-root tokens compute to an invalid value — in
130
193
  > production builds only. An equivalent space-toggle is used instead.
131
194
 
195
+ > **Note** — internally each public token is aliased to a private `--_rsp-*`
196
+ > property declared on `.rsp-root`, and the rules consume the private name. A
197
+ > custom property containing `var()` is substituted at the element where it is
198
+ > *declared*, so themed values declared on `:root` would be resolved against the
199
+ > document root and a subtree pin could never change them. Treat `--_rsp-*` as
200
+ > private and always override the public `--rsp-*` name.
201
+
132
202
  ### Cell fills stay readable
133
203
 
134
204
  A `backgroundColor` coming from your document model is usually a single literal
package/dist/cjs/lib.cjs CHANGED
@@ -2747,7 +2747,7 @@ var Spreadsheet = import_react4.forwardRef(({
2747
2747
  height: 0,
2748
2748
  visibility: "hidden",
2749
2749
  pointerEvents: "none",
2750
- color: "var(--rsp-gridline)"
2750
+ color: "var(--_rsp-gridline)"
2751
2751
  }
2752
2752
  }),
2753
2753
  /* @__PURE__ */ jsx_runtime3.jsx("canvas", {
@@ -3642,63 +3642,61 @@ function FormulaSheet({
3642
3642
  workbookName
3643
3643
  });
3644
3644
  if (!tableInfo) {
3645
- if (conditionalStyle) {
3646
- return {
3647
- ...conditionalStyle.backgroundColor && {
3648
- backgroundColor: conditionalStyle.backgroundColor
3649
- },
3650
- ...conditionalStyle.color && {
3651
- color: conditionalStyle.color
3652
- },
3653
- ...conditionalStyle.fontSize && {
3654
- fontSize: conditionalStyle.fontSize
3655
- },
3656
- ...conditionalStyle.bold && {
3657
- fontWeight: "bold"
3658
- },
3659
- ...conditionalStyle.italic && {
3660
- fontStyle: "italic"
3661
- },
3662
- ...conditionalStyle.underline && {
3663
- textDecoration: "underline"
3664
- },
3665
- ...getBorderCellStyle(conditionalStyle),
3666
- ...getWrapCellStyle(conditionalStyle)
3667
- };
3668
- }
3669
- return {};
3645
+ const style2 = conditionalStyle ? {
3646
+ ...conditionalStyle.backgroundColor && {
3647
+ backgroundColor: conditionalStyle.backgroundColor
3648
+ },
3649
+ ...conditionalStyle.color && {
3650
+ color: conditionalStyle.color
3651
+ },
3652
+ ...conditionalStyle.fontSize && {
3653
+ fontSize: conditionalStyle.fontSize
3654
+ },
3655
+ ...conditionalStyle.bold && {
3656
+ fontWeight: "bold"
3657
+ },
3658
+ ...conditionalStyle.italic && {
3659
+ fontStyle: "italic"
3660
+ },
3661
+ ...conditionalStyle.underline && {
3662
+ textDecoration: "underline"
3663
+ },
3664
+ ...getBorderCellStyle(conditionalStyle),
3665
+ ...getWrapCellStyle(conditionalStyle)
3666
+ } : {};
3667
+ return customCellStyle ? customCellStyle(cell, style2) : style2;
3670
3668
  }
3671
3669
  const isHeaderRow = cell.rowIndex === tableInfo.start.rowIndex;
3672
3670
  const isFirstColumn = cell.colIndex === tableInfo.start.colIndex;
3673
3671
  const isLastColumn = cell.colIndex === tableInfo.start.colIndex + tableInfo.headers.size - 1;
3674
3672
  const isLastRow = tableInfo.endRow.type === "number" ? cell.rowIndex === tableInfo.endRow.value : false;
3675
3673
  const style = {
3676
- border: "1px solid var(--rsp-table-border-light)"
3674
+ border: "1px solid var(--_rsp-table-border-light)"
3677
3675
  };
3678
3676
  if (isHeaderRow) {
3679
- style.backgroundColor = "var(--rsp-table-header-bg)";
3680
- style.color = "var(--rsp-table-header-color)";
3677
+ style.backgroundColor = "var(--_rsp-table-header-bg)";
3678
+ style.color = "var(--_rsp-table-header-color)";
3681
3679
  style.fontWeight = "bold";
3682
- style.borderBottom = "2px solid var(--rsp-table-header-border)";
3680
+ style.borderBottom = "2px solid var(--_rsp-table-header-border)";
3683
3681
  } else {
3684
3682
  const dataRowIndex = cell.rowIndex - tableInfo.start.rowIndex - 1;
3685
3683
  if (dataRowIndex % 2 === 0) {
3686
- style.backgroundColor = "var(--rsp-table-even-row-bg)";
3684
+ style.backgroundColor = "var(--_rsp-table-even-row-bg)";
3687
3685
  } else {
3688
- style.backgroundColor = "var(--rsp-table-odd-row-bg)";
3686
+ style.backgroundColor = "var(--_rsp-table-odd-row-bg)";
3689
3687
  }
3690
3688
  }
3691
3689
  if (isFirstColumn) {
3692
- style.borderLeft = "2px solid var(--rsp-table-border-color)";
3690
+ style.borderLeft = "2px solid var(--_rsp-table-border-color)";
3693
3691
  }
3694
3692
  if (isLastColumn) {
3695
- style.borderRight = "2px solid var(--rsp-table-border-color)";
3693
+ style.borderRight = "2px solid var(--_rsp-table-border-color)";
3696
3694
  }
3697
3695
  if (isHeaderRow) {
3698
- style.borderTop = "2px solid var(--rsp-table-border-color)";
3696
+ style.borderTop = "2px solid var(--_rsp-table-border-color)";
3699
3697
  }
3700
3698
  if (isLastRow) {
3701
- style.borderBottom = "2px solid var(--rsp-table-border-color)";
3699
+ style.borderBottom = "2px solid var(--_rsp-table-border-color)";
3702
3700
  }
3703
3701
  if (conditionalStyle?.backgroundColor) {
3704
3702
  style.backgroundColor = conditionalStyle.backgroundColor;
@@ -4163,4 +4161,4 @@ var useClickAway = (ref, callback) => {
4163
4161
  }, [ref, callback]);
4164
4162
  };
4165
4163
 
4166
- //# debugId=A383A8C557A8A55164756E2164756E21
4164
+ //# debugId=4874F9DF8699906864756E2164756E21