@ricsam/react-spreadsheets 0.0.3 → 0.0.5
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 +11 -3
- package/dist/cjs/lib.cjs +37 -23
- package/dist/cjs/lib.cjs.map +6 -5
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/lib.mjs +22 -8
- package/dist/mjs/lib.mjs.map +6 -5
- package/dist/mjs/package.json +1 -1
- package/dist/styles.css +100 -33
- package/dist/types/utils/use-scheme-root.d.ts +16 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -102,8 +102,7 @@ you can override them from **any** ancestor of the grid:
|
|
|
102
102
|
|
|
103
103
|
### Light and dark
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
`color-scheme`. By default the grid follows the user's OS preference.
|
|
105
|
+
By default the grid follows the user's OS preference.
|
|
107
106
|
|
|
108
107
|
The grid deliberately does **not** declare `color-scheme` on `.rsp-root`, so a
|
|
109
108
|
pin you set on an ancestor is respected. Pin a subtree with plain CSS:
|
|
@@ -119,7 +118,16 @@ or with the bundled helper classes:
|
|
|
119
118
|
<FormulaWorkbook className="rsp-theme-dark" ... />
|
|
120
119
|
```
|
|
121
120
|
|
|
122
|
-
Canvas gridlines and every DOM surface follow the same resolved scheme.
|
|
121
|
+
Canvas gridlines and every DOM surface follow the same resolved scheme. The
|
|
122
|
+
component resolves the inherited `color-scheme` and reflects it on the grid root
|
|
123
|
+
as `data-rsp-scheme`, which drives the `--rsp-light` / `--rsp-dark` token
|
|
124
|
+
switches.
|
|
125
|
+
|
|
126
|
+
> **Note** — the stylesheet intentionally avoids `light-dark()`. Bundlers that
|
|
127
|
+
> target browsers without native support (Vite's Lightning CSS, for example)
|
|
128
|
+
> lower it to switch variables that only exist next to a `color-scheme`
|
|
129
|
+
> declaration, which makes shared-root tokens compute to an invalid value — in
|
|
130
|
+
> production builds only. An equivalent space-toggle is used instead.
|
|
123
131
|
|
|
124
132
|
### Cell fills stay readable
|
|
125
133
|
|
package/dist/cjs/lib.cjs
CHANGED
|
@@ -2722,6 +2722,7 @@ var Spreadsheet = import_react4.forwardRef(({
|
|
|
2722
2722
|
}), [selectionManager]);
|
|
2723
2723
|
return /* @__PURE__ */ jsx_runtime3.jsx("div", {
|
|
2724
2724
|
className: cn("rsp-root", className),
|
|
2725
|
+
"data-rsp-scheme": colorScheme,
|
|
2725
2726
|
style: { position: "relative", ...style },
|
|
2726
2727
|
...containerProps,
|
|
2727
2728
|
children: /* @__PURE__ */ jsx_runtime3.jsx("div", {
|
|
@@ -2925,7 +2926,15 @@ var Spreadsheet = import_react4.forwardRef(({
|
|
|
2925
2926
|
Spreadsheet.displayName = "Spreadsheet";
|
|
2926
2927
|
// src/workbook/workbook.tsx
|
|
2927
2928
|
var import_formula_engine2 = require("@ricsam/formula-engine");
|
|
2928
|
-
var
|
|
2929
|
+
var import_react6 = __toESM(require("react"));
|
|
2930
|
+
|
|
2931
|
+
// src/utils/use-scheme-root.ts
|
|
2932
|
+
var import_react5 = require("react");
|
|
2933
|
+
function useSchemeRoot() {
|
|
2934
|
+
const [element, setElement] = import_react5.useState(null);
|
|
2935
|
+
const scheme = useColorScheme(element);
|
|
2936
|
+
return { ref: setElement, "data-rsp-scheme": scheme };
|
|
2937
|
+
}
|
|
2929
2938
|
|
|
2930
2939
|
// src/workbook/border-sides.ts
|
|
2931
2940
|
function normalizeBorderSides(sides, defaultAllWhenUnset = false) {
|
|
@@ -3331,8 +3340,8 @@ var MinusIcon = ({ className = "", ...props }) => /* @__PURE__ */ jsx_runtime4.j
|
|
|
3331
3340
|
})
|
|
3332
3341
|
});
|
|
3333
3342
|
function useEngine(engine) {
|
|
3334
|
-
const [state, setState] =
|
|
3335
|
-
|
|
3343
|
+
const [state, setState] = import_react6.useState(() => engine.getState());
|
|
3344
|
+
import_react6.default.useEffect(() => {
|
|
3336
3345
|
return engine.onUpdate(() => {
|
|
3337
3346
|
setState(engine.getState());
|
|
3338
3347
|
});
|
|
@@ -3436,11 +3445,12 @@ function FormulaSheet({
|
|
|
3436
3445
|
showFormulas = false,
|
|
3437
3446
|
...rest
|
|
3438
3447
|
}) {
|
|
3439
|
-
const
|
|
3440
|
-
const
|
|
3448
|
+
const schemeRoot = useSchemeRoot();
|
|
3449
|
+
const [selectedArea, setSelectedArea] = import_react6.useState(null);
|
|
3450
|
+
const clipboardManager = import_react6.default.useMemo(() => controlledClipboardManager ?? new WorkbookClipboardManager(engine), [controlledClipboardManager, engine]);
|
|
3441
3451
|
const state = useEngine(engine);
|
|
3442
3452
|
const sheet = state.workbooks.get(workbookName)?.sheets.get(sheetName);
|
|
3443
|
-
const onCellDataChange =
|
|
3453
|
+
const onCellDataChange = import_react6.useCallback((updatedSpreadsheet) => {
|
|
3444
3454
|
const data = new Map(updatedSpreadsheet);
|
|
3445
3455
|
data.forEach((value, key) => {
|
|
3446
3456
|
if (typeof value === "string") {
|
|
@@ -3456,7 +3466,7 @@ function FormulaSheet({
|
|
|
3456
3466
|
engine.setSheetContent({ sheetName, workbookName }, data);
|
|
3457
3467
|
}, [sheetName, engine, workbookName]);
|
|
3458
3468
|
const passedSelectionEffects = selection?.effects;
|
|
3459
|
-
const selectionManagerEffects =
|
|
3469
|
+
const selectionManagerEffects = import_react6.useCallback((spreadsheetSelectionManager) => {
|
|
3460
3470
|
const convertSmAreaToSpreadsheetRange = (area) => {
|
|
3461
3471
|
const rowEnd = area.end.row.type === "infinity" ? {
|
|
3462
3472
|
type: "infinity",
|
|
@@ -3581,6 +3591,7 @@ function FormulaSheet({
|
|
|
3581
3591
|
if (!sheet) {
|
|
3582
3592
|
return /* @__PURE__ */ jsx_runtime4.jsxs("div", {
|
|
3583
3593
|
className: "rsp-root rsp-workbook",
|
|
3594
|
+
...schemeRoot,
|
|
3584
3595
|
children: [
|
|
3585
3596
|
toolbar,
|
|
3586
3597
|
/* @__PURE__ */ jsx_runtime4.jsx("div", {
|
|
@@ -3591,6 +3602,7 @@ function FormulaSheet({
|
|
|
3591
3602
|
}
|
|
3592
3603
|
return /* @__PURE__ */ jsx_runtime4.jsxs("div", {
|
|
3593
3604
|
className: "rsp-root rsp-workbook",
|
|
3605
|
+
...schemeRoot,
|
|
3594
3606
|
children: [
|
|
3595
3607
|
toolbar,
|
|
3596
3608
|
/* @__PURE__ */ jsx_runtime4.jsx("div", {
|
|
@@ -3822,18 +3834,19 @@ function FormulaWorkbook({
|
|
|
3822
3834
|
showFormulas = false,
|
|
3823
3835
|
...rest
|
|
3824
3836
|
}) {
|
|
3837
|
+
const schemeRoot = useSchemeRoot();
|
|
3825
3838
|
const state = useEngine(engine);
|
|
3826
|
-
const [renamingSheet, setRenamingSheet] =
|
|
3827
|
-
const [newSheetName, setNewSheetName] =
|
|
3828
|
-
const [spreadsheetZoom, setSpreadsheetZoom] =
|
|
3829
|
-
const renameCommittedRef =
|
|
3830
|
-
const clipboardManager =
|
|
3839
|
+
const [renamingSheet, setRenamingSheet] = import_react6.useState(null);
|
|
3840
|
+
const [newSheetName, setNewSheetName] = import_react6.useState("");
|
|
3841
|
+
const [spreadsheetZoom, setSpreadsheetZoom] = import_react6.useState(1);
|
|
3842
|
+
const renameCommittedRef = import_react6.useRef(false);
|
|
3843
|
+
const clipboardManager = import_react6.default.useMemo(() => controlledClipboardManager ?? new WorkbookClipboardManager(engine), [controlledClipboardManager, engine]);
|
|
3831
3844
|
const sheetNames = engine.getOrderedSheetNames(workbookName);
|
|
3832
|
-
const [internalActiveSheet, setInternalActiveSheet] =
|
|
3845
|
+
const [internalActiveSheet, setInternalActiveSheet] = import_react6.useState(() => {
|
|
3833
3846
|
return sheetNames[0] || "";
|
|
3834
3847
|
});
|
|
3835
|
-
const isControlledRef =
|
|
3836
|
-
|
|
3848
|
+
const isControlledRef = import_react6.useRef(controlledActiveSheet !== undefined);
|
|
3849
|
+
import_react6.default.useEffect(() => {
|
|
3837
3850
|
const isCurrentlyControlled = controlledActiveSheet !== undefined;
|
|
3838
3851
|
if (isControlledRef.current !== isCurrentlyControlled) {
|
|
3839
3852
|
console.error(`FormulaWorkbook: Component changed from ${isControlledRef.current ? "controlled" : "uncontrolled"} to ${isCurrentlyControlled ? "controlled" : "uncontrolled"} mode. ` + `A component should not switch between controlled and uncontrolled modes. ` + `Decide between using activeSheet and onActiveSheetChange props (controlled) or neither (uncontrolled) for the lifetime of the component.`);
|
|
@@ -3841,7 +3854,7 @@ function FormulaWorkbook({
|
|
|
3841
3854
|
isControlledRef.current = isCurrentlyControlled;
|
|
3842
3855
|
}, [controlledActiveSheet]);
|
|
3843
3856
|
const activeSheet = controlledActiveSheet ?? internalActiveSheet;
|
|
3844
|
-
const handleActiveSheetChange =
|
|
3857
|
+
const handleActiveSheetChange = import_react6.useCallback((sheetName) => {
|
|
3845
3858
|
if (onActiveSheetChange) {
|
|
3846
3859
|
onActiveSheetChange(sheetName);
|
|
3847
3860
|
} else {
|
|
@@ -3852,16 +3865,16 @@ function FormulaWorkbook({
|
|
|
3852
3865
|
const activeSheetSelectedOverlayId = sheetSelectedOverlayIds?.[activeSheet];
|
|
3853
3866
|
const activeSheetColumnWidths = sheetLayouts?.[activeSheet]?.columnWidths;
|
|
3854
3867
|
const activeSheetRowHeights = sheetLayouts?.[activeSheet]?.rowHeights;
|
|
3855
|
-
const handleOverlaySelect =
|
|
3868
|
+
const handleOverlaySelect = import_react6.useCallback((overlayId) => {
|
|
3856
3869
|
onOverlaySelect?.(activeSheet, overlayId);
|
|
3857
3870
|
}, [onOverlaySelect, activeSheet]);
|
|
3858
|
-
const handleOverlayChildrenChange =
|
|
3871
|
+
const handleOverlayChildrenChange = import_react6.useCallback((children) => {
|
|
3859
3872
|
onOverlayChildrenChange?.(activeSheet, children);
|
|
3860
3873
|
}, [onOverlayChildrenChange, activeSheet]);
|
|
3861
|
-
const handleColumnWidthsChange =
|
|
3874
|
+
const handleColumnWidthsChange = import_react6.useCallback((columnWidths) => {
|
|
3862
3875
|
onSheetColumnWidthsChange?.(activeSheet, columnWidths);
|
|
3863
3876
|
}, [activeSheet, onSheetColumnWidthsChange]);
|
|
3864
|
-
const handleRowHeightsChange =
|
|
3877
|
+
const handleRowHeightsChange = import_react6.useCallback((rowHeights) => {
|
|
3865
3878
|
onSheetRowHeightsChange?.(activeSheet, rowHeights);
|
|
3866
3879
|
}, [activeSheet, onSheetRowHeightsChange]);
|
|
3867
3880
|
const addSheet = () => {
|
|
@@ -3928,6 +3941,7 @@ function FormulaWorkbook({
|
|
|
3928
3941
|
};
|
|
3929
3942
|
return /* @__PURE__ */ jsx_runtime4.jsxs("div", {
|
|
3930
3943
|
className: "rsp-root rsp-workbook",
|
|
3944
|
+
...schemeRoot,
|
|
3931
3945
|
children: [
|
|
3932
3946
|
toolbar,
|
|
3933
3947
|
/* @__PURE__ */ jsx_runtime4.jsxs("div", {
|
|
@@ -4133,9 +4147,9 @@ var DEFAULT_ZOOM = 1;
|
|
|
4133
4147
|
var MIN_ZOOM = 0.5;
|
|
4134
4148
|
var MAX_ZOOM = 3;
|
|
4135
4149
|
// src/utils/use-click-away.ts
|
|
4136
|
-
var
|
|
4150
|
+
var import_react7 = require("react");
|
|
4137
4151
|
var useClickAway = (ref, callback) => {
|
|
4138
|
-
|
|
4152
|
+
import_react7.useEffect(() => {
|
|
4139
4153
|
const handleClickAway = (event) => {
|
|
4140
4154
|
if (ref) {
|
|
4141
4155
|
const away = !ref.contains(event.target);
|
|
@@ -4149,4 +4163,4 @@ var useClickAway = (ref, callback) => {
|
|
|
4149
4163
|
}, [ref, callback]);
|
|
4150
4164
|
};
|
|
4151
4165
|
|
|
4152
|
-
//# debugId=
|
|
4166
|
+
//# debugId=A383A8C557A8A55164756E2164756E21
|