@gridsheet/react-core 1.4.0-alpha.1 → 1.4.0-alpha.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/README.md +27 -0
- package/dist/_virtual/_commonjsHelpers.js +7 -0
- package/dist/_virtual/_commonjsHelpers.js.map +1 -0
- package/dist/_virtual/dayjs.min.js +8 -0
- package/dist/_virtual/dayjs.min.js.map +1 -0
- package/dist/_virtual/dayjs.min2.js +5 -0
- package/dist/_virtual/dayjs.min2.js.map +1 -0
- package/dist/_virtual/timezone.js +8 -0
- package/dist/_virtual/timezone.js.map +1 -0
- package/dist/_virtual/timezone2.js +5 -0
- package/dist/_virtual/timezone2.js.map +1 -0
- package/dist/_virtual/utc.js +8 -0
- package/dist/_virtual/utc.js.map +1 -0
- package/dist/_virtual/utc2.js +5 -0
- package/dist/_virtual/utc2.js.map +1 -0
- package/dist/components/Cell.js +232 -0
- package/dist/components/Cell.js.map +1 -0
- package/dist/components/ContextMenu.js +297 -0
- package/dist/components/ContextMenu.js.map +1 -0
- package/dist/components/Editor.js +455 -0
- package/dist/components/Editor.js.map +1 -0
- package/dist/components/Emitter.js +26 -0
- package/dist/components/Emitter.js.map +1 -0
- package/dist/components/Fixed.js +17 -0
- package/dist/components/Fixed.js.map +1 -0
- package/dist/components/FormulaBar.js +149 -0
- package/dist/components/FormulaBar.js.map +1 -0
- package/dist/components/GridSheet.js +246 -0
- package/dist/components/GridSheet.js.map +1 -0
- package/dist/components/HeaderCellLeft.js +131 -0
- package/dist/components/HeaderCellLeft.js.map +1 -0
- package/dist/components/HeaderCellTop.js +132 -0
- package/dist/components/HeaderCellTop.js.map +1 -0
- package/dist/components/PluginBase.js +35 -0
- package/dist/components/PluginBase.js.map +1 -0
- package/dist/components/Resizer.js +98 -0
- package/dist/components/Resizer.js.map +1 -0
- package/dist/components/SearchBar.js +108 -0
- package/dist/components/SearchBar.js.map +1 -0
- package/dist/components/SheetProvider.js +56 -0
- package/dist/components/SheetProvider.js.map +1 -0
- package/dist/components/StoreInitializer.js +84 -0
- package/dist/components/StoreInitializer.js.map +1 -0
- package/dist/components/Tabular.js +308 -0
- package/dist/components/Tabular.js.map +1 -0
- package/dist/components/hooks.js +15 -0
- package/dist/components/hooks.js.map +1 -0
- package/dist/components/svg/Base.js +24 -0
- package/dist/components/svg/Base.js.map +1 -0
- package/dist/components/svg/CloseIcon.js +13 -0
- package/dist/components/svg/CloseIcon.js.map +1 -0
- package/dist/components/svg/SearchIcon.js +13 -0
- package/dist/components/svg/SearchIcon.js.map +1 -0
- package/dist/constants.js +43 -0
- package/dist/constants.js.map +1 -0
- package/dist/formula/evaluator.js +674 -0
- package/dist/formula/evaluator.js.map +1 -0
- package/dist/formula/functions/__base.js +19 -0
- package/dist/formula/functions/__base.js.map +1 -0
- package/dist/formula/functions/__utils.js +145 -0
- package/dist/formula/functions/__utils.js.map +1 -0
- package/dist/formula/functions/abs.js +24 -0
- package/dist/formula/functions/abs.js.map +1 -0
- package/dist/formula/functions/acos.js +32 -0
- package/dist/formula/functions/acos.js.map +1 -0
- package/dist/formula/functions/add.js +57 -0
- package/dist/formula/functions/add.js.map +1 -0
- package/dist/formula/functions/and.js +28 -0
- package/dist/formula/functions/and.js.map +1 -0
- package/dist/formula/functions/asin.js +32 -0
- package/dist/formula/functions/asin.js.map +1 -0
- package/dist/formula/functions/atan.js +29 -0
- package/dist/formula/functions/atan.js.map +1 -0
- package/dist/formula/functions/atan2.js +35 -0
- package/dist/formula/functions/atan2.js.map +1 -0
- package/dist/formula/functions/average.js +44 -0
- package/dist/formula/functions/average.js.map +1 -0
- package/dist/formula/functions/col.js +31 -0
- package/dist/formula/functions/col.js.map +1 -0
- package/dist/formula/functions/concat.js +27 -0
- package/dist/formula/functions/concat.js.map +1 -0
- package/dist/formula/functions/concatenate.js +28 -0
- package/dist/formula/functions/concatenate.js.map +1 -0
- package/dist/formula/functions/cos.js +29 -0
- package/dist/formula/functions/cos.js.map +1 -0
- package/dist/formula/functions/count.js +38 -0
- package/dist/formula/functions/count.js.map +1 -0
- package/dist/formula/functions/counta.js +38 -0
- package/dist/formula/functions/counta.js.map +1 -0
- package/dist/formula/functions/countif.js +32 -0
- package/dist/formula/functions/countif.js.map +1 -0
- package/dist/formula/functions/divide.js +33 -0
- package/dist/formula/functions/divide.js.map +1 -0
- package/dist/formula/functions/eq.js +29 -0
- package/dist/formula/functions/eq.js.map +1 -0
- package/dist/formula/functions/exp.js +29 -0
- package/dist/formula/functions/exp.js.map +1 -0
- package/dist/formula/functions/gt.js +29 -0
- package/dist/formula/functions/gt.js.map +1 -0
- package/dist/formula/functions/gte.js +29 -0
- package/dist/formula/functions/gte.js.map +1 -0
- package/dist/formula/functions/hlookup.js +75 -0
- package/dist/formula/functions/hlookup.js.map +1 -0
- package/dist/formula/functions/if.js +39 -0
- package/dist/formula/functions/if.js.map +1 -0
- package/dist/formula/functions/iferror.js +45 -0
- package/dist/formula/functions/iferror.js.map +1 -0
- package/dist/formula/functions/len.js +29 -0
- package/dist/formula/functions/len.js.map +1 -0
- package/dist/formula/functions/lenb.js +29 -0
- package/dist/formula/functions/lenb.js.map +1 -0
- package/dist/formula/functions/ln.js +32 -0
- package/dist/formula/functions/ln.js.map +1 -0
- package/dist/formula/functions/log.js +36 -0
- package/dist/formula/functions/log.js.map +1 -0
- package/dist/formula/functions/log10.js +32 -0
- package/dist/formula/functions/log10.js.map +1 -0
- package/dist/formula/functions/lt.js +29 -0
- package/dist/formula/functions/lt.js.map +1 -0
- package/dist/formula/functions/lte.js +29 -0
- package/dist/formula/functions/lte.js.map +1 -0
- package/dist/formula/functions/max.js +47 -0
- package/dist/formula/functions/max.js.map +1 -0
- package/dist/formula/functions/min.js +47 -0
- package/dist/formula/functions/min.js.map +1 -0
- package/dist/formula/functions/minus.js +57 -0
- package/dist/formula/functions/minus.js.map +1 -0
- package/dist/formula/functions/mod.js +33 -0
- package/dist/formula/functions/mod.js.map +1 -0
- package/dist/formula/functions/multiply.js +27 -0
- package/dist/formula/functions/multiply.js.map +1 -0
- package/dist/formula/functions/ne.js +29 -0
- package/dist/formula/functions/ne.js.map +1 -0
- package/dist/formula/functions/not.js +30 -0
- package/dist/formula/functions/not.js.map +1 -0
- package/dist/formula/functions/now.js +22 -0
- package/dist/formula/functions/now.js.map +1 -0
- package/dist/formula/functions/or.js +28 -0
- package/dist/formula/functions/or.js.map +1 -0
- package/dist/formula/functions/pi.js +22 -0
- package/dist/formula/functions/pi.js.map +1 -0
- package/dist/formula/functions/power.js +27 -0
- package/dist/formula/functions/power.js.map +1 -0
- package/dist/formula/functions/product.js +40 -0
- package/dist/formula/functions/product.js.map +1 -0
- package/dist/formula/functions/radians.js +29 -0
- package/dist/formula/functions/radians.js.map +1 -0
- package/dist/formula/functions/rand.js +22 -0
- package/dist/formula/functions/rand.js.map +1 -0
- package/dist/formula/functions/round.js +35 -0
- package/dist/formula/functions/round.js.map +1 -0
- package/dist/formula/functions/rounddown.js +35 -0
- package/dist/formula/functions/rounddown.js.map +1 -0
- package/dist/formula/functions/roundup.js +35 -0
- package/dist/formula/functions/roundup.js.map +1 -0
- package/dist/formula/functions/row.js +31 -0
- package/dist/formula/functions/row.js.map +1 -0
- package/dist/formula/functions/sin.js +29 -0
- package/dist/formula/functions/sin.js.map +1 -0
- package/dist/formula/functions/sqrt.js +32 -0
- package/dist/formula/functions/sqrt.js.map +1 -0
- package/dist/formula/functions/sum.js +47 -0
- package/dist/formula/functions/sum.js.map +1 -0
- package/dist/formula/functions/sumif.js +65 -0
- package/dist/formula/functions/sumif.js.map +1 -0
- package/dist/formula/functions/tan.js +29 -0
- package/dist/formula/functions/tan.js.map +1 -0
- package/dist/formula/functions/uminus.js +24 -0
- package/dist/formula/functions/uminus.js.map +1 -0
- package/dist/formula/functions/vlookup.js +75 -0
- package/dist/formula/functions/vlookup.js.map +1 -0
- package/dist/formula/mapping.js +118 -0
- package/dist/formula/mapping.js.map +1 -0
- package/dist/formula/solver.js +70 -0
- package/dist/formula/solver.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +45 -6822
- package/dist/index.js.map +1 -0
- package/dist/lib/autofill.js +391 -0
- package/dist/lib/autofill.js.map +1 -0
- package/dist/lib/clipboard.js +46 -0
- package/dist/lib/clipboard.js.map +1 -0
- package/dist/lib/converters.js +141 -0
- package/dist/lib/converters.js.map +1 -0
- package/dist/lib/input.js +52 -0
- package/dist/lib/input.js.map +1 -0
- package/dist/lib/palette.js +24 -0
- package/dist/lib/palette.js.map +1 -0
- package/dist/lib/prevention.js +82 -0
- package/dist/lib/prevention.js.map +1 -0
- package/dist/lib/structs.js +276 -0
- package/dist/lib/structs.js.map +1 -0
- package/dist/lib/table.js +1248 -0
- package/dist/lib/table.js.map +1 -0
- package/dist/lib/time.js +79 -0
- package/dist/lib/time.js.map +1 -0
- package/dist/lib/virtualization.js +129 -0
- package/dist/lib/virtualization.js.map +1 -0
- package/dist/node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/dayjs.min.js +287 -0
- package/dist/node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/dayjs.min.js.map +1 -0
- package/dist/node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/plugin/timezone.js +72 -0
- package/dist/node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/plugin/timezone.js.map +1 -0
- package/dist/node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/plugin/utc.js +85 -0
- package/dist/node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/plugin/utc.js.map +1 -0
- package/dist/parsers/core.js +139 -0
- package/dist/parsers/core.js.map +1 -0
- package/dist/renderers/checkbox.js +20 -0
- package/dist/renderers/checkbox.js.map +1 -0
- package/dist/renderers/core.d.ts +21 -21
- package/dist/renderers/core.d.ts.map +1 -1
- package/dist/renderers/core.js +147 -0
- package/dist/renderers/core.js.map +1 -0
- package/dist/renderers/thousand_separator.js +17 -0
- package/dist/renderers/thousand_separator.js.map +1 -0
- package/dist/store/actions.js +762 -0
- package/dist/store/actions.js.map +1 -0
- package/dist/store/helpers.js +88 -0
- package/dist/store/helpers.js.map +1 -0
- package/dist/store/index.js +8 -0
- package/dist/store/index.js.map +1 -0
- package/dist/styles/embedder.js +19 -0
- package/dist/styles/embedder.js.map +1 -0
- package/dist/styles/minified.js +7 -0
- package/dist/styles/minified.js.map +1 -0
- package/package.json +3 -8
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[](https://www.npmjs.com/package/@gridsheet/react-core)
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+
|
|
6
|
+
## Introduction
|
|
7
|
+
|
|
8
|
+
@gridsheet/react-core is a simple yet highly functional spreadsheet component for ReactJS.
|
|
9
|
+
|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
$ npm install @gridsheet/react-core --save
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Docs
|
|
20
|
+
|
|
21
|
+
- [ReactGridsheet document](https://docs.walkframe.com/gridsheet/react)
|
|
22
|
+
- [Examples](https://docs.walkframe.com/gridsheet/Examples/react-case1)
|
|
23
|
+
- [Histories](https://docs.walkframe.com/gridsheet/history)
|
|
24
|
+
|
|
25
|
+
## License
|
|
26
|
+
[](https://app.fossa.com/projects/git%2Bgithub.com%2Fwalkframe%2Freact-gridsheet?ref=badge_large)
|
|
27
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_commonjsHelpers.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { getDefaultExportFromCjs } from "./_commonjsHelpers.js";
|
|
2
|
+
import { __require as requireDayjs_min } from "../node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/dayjs.min.js";
|
|
3
|
+
var dayjs_minExports = requireDayjs_min();
|
|
4
|
+
const dayjs = /* @__PURE__ */ getDefaultExportFromCjs(dayjs_minExports);
|
|
5
|
+
export {
|
|
6
|
+
dayjs as default
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=dayjs.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dayjs.min.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dayjs.min2.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { getDefaultExportFromCjs } from "./_commonjsHelpers.js";
|
|
2
|
+
import { __require as requireTimezone } from "../node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/plugin/timezone.js";
|
|
3
|
+
var timezoneExports = requireTimezone();
|
|
4
|
+
const timezone = /* @__PURE__ */ getDefaultExportFromCjs(timezoneExports);
|
|
5
|
+
export {
|
|
6
|
+
timezone as default
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=timezone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timezone.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timezone2.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { getDefaultExportFromCjs } from "./_commonjsHelpers.js";
|
|
2
|
+
import { __require as requireUtc } from "../node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/plugin/utc.js";
|
|
3
|
+
var utcExports = requireUtc();
|
|
4
|
+
const utc = /* @__PURE__ */ getDefaultExportFromCjs(utcExports);
|
|
5
|
+
export {
|
|
6
|
+
utc as default
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=utc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utc.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utc2.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React__default from "react";
|
|
3
|
+
import { x2c, y2r } from "../lib/converters.js";
|
|
4
|
+
import { zoneToArea, among, areaToRange, areaToZone, zoneShape } from "../lib/structs.js";
|
|
5
|
+
import { setEditorRect, setInputting, setAutofillDraggingTo, drag, updateTable, select, choose, setEditingCell, setContextMenuPosition, write } from "../store/actions.js";
|
|
6
|
+
import { DUMMY_IMG } from "../constants.js";
|
|
7
|
+
import { Context } from "../store/index.js";
|
|
8
|
+
import { FormulaError } from "../formula/evaluator.js";
|
|
9
|
+
import { Autofill } from "../lib/autofill.js";
|
|
10
|
+
import { insertRef, isRefInsertable } from "../lib/input.js";
|
|
11
|
+
import { useSheetContext } from "./SheetProvider.js";
|
|
12
|
+
const Cell = React__default.memo(({ y, x, operationStyle }) => {
|
|
13
|
+
const rowId = y2r(y);
|
|
14
|
+
const colId = x2c(x);
|
|
15
|
+
const address = `${colId}${rowId}`;
|
|
16
|
+
const { store, dispatch } = React__default.useContext(Context);
|
|
17
|
+
const isFirstPointed = React__default.useRef(true);
|
|
18
|
+
const [sheetProvided, sheetContext] = useSheetContext();
|
|
19
|
+
const cellRef = React__default.useRef(null);
|
|
20
|
+
const {
|
|
21
|
+
table,
|
|
22
|
+
editingCell,
|
|
23
|
+
choosing,
|
|
24
|
+
selectingZone,
|
|
25
|
+
leftHeaderSelecting,
|
|
26
|
+
topHeaderSelecting,
|
|
27
|
+
editorRef,
|
|
28
|
+
showAddress,
|
|
29
|
+
autofillDraggingTo,
|
|
30
|
+
lastEdited
|
|
31
|
+
} = store;
|
|
32
|
+
const differentSheetFocused = sheetProvided && (sheetContext == null ? void 0 : sheetContext.lastFocusedRef) !== store.lastFocusedRef;
|
|
33
|
+
const lastFocusedRef = (sheetContext == null ? void 0 : sheetContext.lastFocusedRef) || store.lastFocusedRef;
|
|
34
|
+
const selectingArea = zoneToArea(selectingZone);
|
|
35
|
+
const editing = editingCell === address;
|
|
36
|
+
const pointed = choosing.y === y && choosing.x === x;
|
|
37
|
+
const _setEditorRect = React__default.useCallback(() => {
|
|
38
|
+
const rect = cellRef.current.getBoundingClientRect();
|
|
39
|
+
dispatch(
|
|
40
|
+
setEditorRect({
|
|
41
|
+
y: rect.y,
|
|
42
|
+
x: rect.x,
|
|
43
|
+
height: rect.height,
|
|
44
|
+
width: rect.width
|
|
45
|
+
})
|
|
46
|
+
);
|
|
47
|
+
}, []);
|
|
48
|
+
React__default.useEffect(() => {
|
|
49
|
+
if (pointed && !isFirstPointed.current) {
|
|
50
|
+
_setEditorRect();
|
|
51
|
+
if (!editing) {
|
|
52
|
+
dispatch(setInputting(table.stringify({ y, x })));
|
|
53
|
+
}
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
isFirstPointed.current = false;
|
|
57
|
+
}, [pointed, editing]);
|
|
58
|
+
const cell = table.getByPoint({ y, x });
|
|
59
|
+
const writeCell = (value) => {
|
|
60
|
+
if (lastEdited !== value) {
|
|
61
|
+
dispatch(write(value));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
let errorMessage = "";
|
|
66
|
+
let rendered;
|
|
67
|
+
try {
|
|
68
|
+
rendered = table.render({ y, x }, writeCell);
|
|
69
|
+
} catch (e) {
|
|
70
|
+
if (e instanceof FormulaError) {
|
|
71
|
+
errorMessage = e.message;
|
|
72
|
+
rendered = e.code;
|
|
73
|
+
} else {
|
|
74
|
+
errorMessage = e.message;
|
|
75
|
+
rendered = "#UNKNOWN";
|
|
76
|
+
console.error(e);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const lastInput = lastFocusedRef.current;
|
|
80
|
+
const input = editorRef.current;
|
|
81
|
+
if (!input) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
return /* @__PURE__ */ jsx(
|
|
85
|
+
"td",
|
|
86
|
+
{
|
|
87
|
+
ref: cellRef,
|
|
88
|
+
"data-x": x,
|
|
89
|
+
"data-y": y,
|
|
90
|
+
"data-address": address,
|
|
91
|
+
className: `gs-cell ${among(selectingArea, { y, x }) ? "gs-selecting" : ""} ${pointed ? "gs-choosing" : ""} ${editing ? "gs-editing" : ""}`,
|
|
92
|
+
style: {
|
|
93
|
+
...cell == null ? void 0 : cell.style,
|
|
94
|
+
...operationStyle
|
|
95
|
+
},
|
|
96
|
+
onContextMenu: (e) => {
|
|
97
|
+
e.preventDefault();
|
|
98
|
+
dispatch(setContextMenuPosition({ y: e.clientY, x: e.clientX }));
|
|
99
|
+
return false;
|
|
100
|
+
},
|
|
101
|
+
onClick: (e) => {
|
|
102
|
+
if (autofillDraggingTo) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
const fullAddress = `${table.sheetPrefix(!differentSheetFocused)}${address}`;
|
|
106
|
+
const editing2 = !!((sheetContext == null ? void 0 : sheetContext.editingCell) || editingCell);
|
|
107
|
+
if (editing2) {
|
|
108
|
+
const inserted = insertRef(lastInput, fullAddress);
|
|
109
|
+
if (inserted) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
dispatch(setEditingCell(""));
|
|
114
|
+
dispatch(setContextMenuPosition({ y: -1, x: -1 }));
|
|
115
|
+
input.focus();
|
|
116
|
+
if (e.shiftKey) {
|
|
117
|
+
dispatch(drag({ y, x }));
|
|
118
|
+
return;
|
|
119
|
+
} else {
|
|
120
|
+
dispatch(choose({ y, x }));
|
|
121
|
+
dispatch(select({ startY: y, startX: x, endY: -1, endX: -1 }));
|
|
122
|
+
_setEditorRect();
|
|
123
|
+
}
|
|
124
|
+
const valueString = table.stringify({ y, x });
|
|
125
|
+
dispatch(setInputting(valueString));
|
|
126
|
+
},
|
|
127
|
+
onDoubleClick: (e) => {
|
|
128
|
+
e.preventDefault();
|
|
129
|
+
const dblclick = document.createEvent("MouseEvents");
|
|
130
|
+
dblclick.initEvent("dblclick", true, true);
|
|
131
|
+
input.dispatchEvent(dblclick);
|
|
132
|
+
return false;
|
|
133
|
+
},
|
|
134
|
+
draggable: true,
|
|
135
|
+
onDragStart: (e) => {
|
|
136
|
+
if (autofillDraggingTo) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
e.dataTransfer.setDragImage(DUMMY_IMG, 0, 0);
|
|
140
|
+
dispatch(select({ startY: y, startX: x, endY: y, endX: x }));
|
|
141
|
+
const insertable = isRefInsertable(lastInput);
|
|
142
|
+
if (insertable) {
|
|
143
|
+
return true;
|
|
144
|
+
} else if (insertable != null) {
|
|
145
|
+
writeCell(input.value);
|
|
146
|
+
}
|
|
147
|
+
dispatch(choose({ y, x }));
|
|
148
|
+
input.focus();
|
|
149
|
+
dispatch(setInputting(""));
|
|
150
|
+
},
|
|
151
|
+
onDragEnd: () => {
|
|
152
|
+
var _a;
|
|
153
|
+
if (autofillDraggingTo) {
|
|
154
|
+
if (autofillDraggingTo.x !== x || autofillDraggingTo.y !== y) {
|
|
155
|
+
const autofill = new Autofill(store, autofillDraggingTo);
|
|
156
|
+
dispatch(updateTable(autofill.applied));
|
|
157
|
+
dispatch(select(areaToZone(autofill.wholeArea)));
|
|
158
|
+
input.focus();
|
|
159
|
+
}
|
|
160
|
+
dispatch(setAutofillDraggingTo(null));
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
const { height: h, width: w } = zoneShape(selectingZone);
|
|
164
|
+
if (h + w === 0) {
|
|
165
|
+
dispatch(select({ startY: -1, startX: -1, endY: -1, endX: -1 }));
|
|
166
|
+
}
|
|
167
|
+
if (isRefInsertable(lastInput)) {
|
|
168
|
+
dispatch(select({ startY: -1, startX: -1, endY: -1, endX: -1 }));
|
|
169
|
+
}
|
|
170
|
+
(_a = lastFocusedRef.current) == null ? void 0 : _a.focus();
|
|
171
|
+
},
|
|
172
|
+
onDragEnter: () => {
|
|
173
|
+
var _a;
|
|
174
|
+
if (autofillDraggingTo) {
|
|
175
|
+
if (!among(selectingArea, { x, y })) {
|
|
176
|
+
dispatch(setAutofillDraggingTo({ x, y }));
|
|
177
|
+
}
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
if (leftHeaderSelecting) {
|
|
181
|
+
dispatch(drag({ y: table.getNumRows(), x }));
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
if (topHeaderSelecting) {
|
|
185
|
+
dispatch(drag({ y, x: table.getNumCols() }));
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
dispatch(drag({ y, x }));
|
|
189
|
+
const newArea = zoneToArea({ ...selectingZone, endY: y, endX: x });
|
|
190
|
+
const fullRange = `${table.sheetPrefix(!differentSheetFocused)}${areaToRange(newArea)}`;
|
|
191
|
+
insertRef(lastInput, fullRange);
|
|
192
|
+
(_a = sheetContext == null ? void 0 : sheetContext.forceRender) == null ? void 0 : _a.call(sheetContext);
|
|
193
|
+
return true;
|
|
194
|
+
},
|
|
195
|
+
children: /* @__PURE__ */ jsxs("div", { className: `gs-cell-inner-wrap`, children: [
|
|
196
|
+
/* @__PURE__ */ jsxs(
|
|
197
|
+
"div",
|
|
198
|
+
{
|
|
199
|
+
className: "gs-cell-inner",
|
|
200
|
+
style: {
|
|
201
|
+
...cell == null ? void 0 : cell.style,
|
|
202
|
+
justifyContent: (cell == null ? void 0 : cell.justifyContent) || "left",
|
|
203
|
+
alignItems: (cell == null ? void 0 : cell.alignItems) || "start"
|
|
204
|
+
},
|
|
205
|
+
children: [
|
|
206
|
+
errorMessage && /* @__PURE__ */ jsx("div", { className: "gs-formula-error-triangle", title: errorMessage }),
|
|
207
|
+
showAddress && /* @__PURE__ */ jsx("div", { className: "gs-cell-label", children: address }),
|
|
208
|
+
/* @__PURE__ */ jsx("div", { className: "gs-cell-rendered", children: rendered })
|
|
209
|
+
]
|
|
210
|
+
}
|
|
211
|
+
),
|
|
212
|
+
(!editing && pointed && selectingArea.bottom === -1 || selectingArea.bottom === y && selectingArea.right === x) && /* @__PURE__ */ jsx(
|
|
213
|
+
"div",
|
|
214
|
+
{
|
|
215
|
+
className: "gs-autofill-drag",
|
|
216
|
+
draggable: true,
|
|
217
|
+
onDragStart: (e) => {
|
|
218
|
+
e.dataTransfer.setDragImage(DUMMY_IMG, 0, 0);
|
|
219
|
+
dispatch(setAutofillDraggingTo({ x, y }));
|
|
220
|
+
e.stopPropagation();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
)
|
|
224
|
+
] })
|
|
225
|
+
},
|
|
226
|
+
x
|
|
227
|
+
);
|
|
228
|
+
});
|
|
229
|
+
export {
|
|
230
|
+
Cell
|
|
231
|
+
};
|
|
232
|
+
//# sourceMappingURL=Cell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Cell.js","sources":["../../components/Cell.tsx"],"sourcesContent":["import React from 'react';\nimport { x2c, y2r } from '../lib/converters';\nimport { zoneToArea, among, zoneShape, areaToZone, areaToRange } from '../lib/structs';\nimport {\n choose,\n select,\n drag,\n write,\n setEditorRect,\n setContextMenuPosition,\n setAutofillDraggingTo,\n updateTable,\n setEditingCell,\n setInputting,\n} from '../store/actions';\n\nimport { DUMMY_IMG } from '../constants';\n\nimport { Context } from '../store';\nimport { FormulaError } from '../formula/evaluator';\nimport { Autofill } from '../lib/autofill';\nimport { insertRef, isRefInsertable } from '../lib/input';\nimport { useSheetContext } from './SheetProvider';\n\ntype Props = {\n y: number;\n x: number;\n operationStyle?: React.CSSProperties;\n};\n\nexport const Cell: React.FC<Props> = React.memo(({ y, x, operationStyle }) => {\n const rowId = y2r(y);\n const colId = x2c(x);\n const address = `${colId}${rowId}`;\n const { store, dispatch } = React.useContext(Context);\n const isFirstPointed = React.useRef(true);\n\n const [sheetProvided, sheetContext] = useSheetContext();\n\n const cellRef = React.useRef<HTMLTableCellElement | null>(null);\n const {\n table,\n editingCell,\n choosing,\n selectingZone,\n leftHeaderSelecting,\n topHeaderSelecting,\n editorRef,\n showAddress,\n autofillDraggingTo,\n lastEdited,\n } = store;\n\n // Whether the focus is on another sheet\n const differentSheetFocused = sheetProvided && sheetContext?.lastFocusedRef !== store.lastFocusedRef;\n\n const lastFocusedRef = sheetContext?.lastFocusedRef || store.lastFocusedRef;\n\n const selectingArea = zoneToArea(selectingZone); // (top, left) -> (bottom, right)\n\n const editing = editingCell === address;\n const pointed = choosing.y === y && choosing.x === x;\n const _setEditorRect = React.useCallback(() => {\n const rect = cellRef.current!.getBoundingClientRect();\n dispatch(\n setEditorRect({\n y: rect.y,\n x: rect.x,\n height: rect.height,\n width: rect.width,\n }),\n );\n }, []);\n\n React.useEffect(() => {\n // Avoid setting coordinates on the initial render to account for shifts caused by redrawing due to virtualization.\n if (pointed && !isFirstPointed.current) {\n _setEditorRect();\n if (!editing) {\n dispatch(setInputting(table.stringify({ y, x })));\n }\n return;\n }\n isFirstPointed.current = false;\n }, [pointed, editing]);\n const cell = table.getByPoint({ y, x });\n const writeCell = (value: string) => {\n if (lastEdited !== value) {\n dispatch(write(value));\n return;\n }\n };\n\n let errorMessage = '';\n let rendered;\n try {\n rendered = table.render({ y, x }, writeCell);\n } catch (e: any) {\n if (e instanceof FormulaError) {\n errorMessage = e.message;\n rendered = e.code;\n } else {\n errorMessage = e.message;\n rendered = '#UNKNOWN';\n console.error(e);\n }\n // TODO: debug flag\n }\n const lastInput = lastFocusedRef.current;\n const input = editorRef.current;\n if (!input) {\n return null;\n }\n\n return (\n <td\n key={x}\n ref={cellRef}\n data-x={x}\n data-y={y}\n data-address={address}\n className={`gs-cell ${among(selectingArea, { y, x }) ? 'gs-selecting' : ''} ${pointed ? 'gs-choosing' : ''} ${\n editing ? 'gs-editing' : ''\n }`}\n style={{\n ...cell?.style,\n ...operationStyle,\n }}\n onContextMenu={(e) => {\n e.preventDefault();\n dispatch(setContextMenuPosition({ y: e.clientY, x: e.clientX }));\n return false;\n }}\n onClick={(e) => {\n if (autofillDraggingTo) {\n return false;\n }\n\n const fullAddress = `${table.sheetPrefix(!differentSheetFocused)}${address}`;\n const editing = !!(sheetContext?.editingCell || editingCell);\n if (editing) {\n const inserted = insertRef(lastInput, fullAddress);\n if (inserted) {\n return false;\n }\n }\n dispatch(setEditingCell(''));\n dispatch(setContextMenuPosition({ y: -1, x: -1 }));\n input.focus();\n if (e.shiftKey) {\n dispatch(drag({ y, x }));\n return;\n } else {\n dispatch(choose({ y, x }));\n dispatch(select({ startY: y, startX: x, endY: -1, endX: -1 }));\n _setEditorRect();\n }\n const valueString = table.stringify({ y, x });\n dispatch(setInputting(valueString));\n }}\n onDoubleClick={(e) => {\n e.preventDefault();\n const dblclick = document.createEvent('MouseEvents');\n dblclick.initEvent('dblclick', true, true);\n input.dispatchEvent(dblclick);\n return false;\n }}\n draggable\n onDragStart={(e) => {\n if (autofillDraggingTo) {\n return false;\n }\n e.dataTransfer.setDragImage(DUMMY_IMG, 0, 0);\n dispatch(select({ startY: y, startX: x, endY: y, endX: x }));\n const insertable = isRefInsertable(lastInput);\n if (insertable) {\n return true;\n } else if (insertable != null) {\n writeCell(input.value);\n }\n dispatch(choose({ y, x }));\n input.focus();\n dispatch(setInputting(''));\n }}\n onDragEnd={() => {\n if (autofillDraggingTo) {\n if (autofillDraggingTo.x !== x || autofillDraggingTo.y !== y) {\n const autofill = new Autofill(store, autofillDraggingTo);\n dispatch(updateTable(autofill.applied));\n dispatch(select(areaToZone(autofill.wholeArea)));\n input.focus();\n }\n dispatch(setAutofillDraggingTo(null));\n return false;\n }\n const { height: h, width: w } = zoneShape(selectingZone);\n if (h + w === 0) {\n dispatch(select({ startY: -1, startX: -1, endY: -1, endX: -1 }));\n }\n if (isRefInsertable(lastInput)) {\n dispatch(select({ startY: -1, startX: -1, endY: -1, endX: -1 }));\n }\n lastFocusedRef.current?.focus();\n }}\n onDragEnter={() => {\n if (autofillDraggingTo) {\n if (!among(selectingArea, { x, y })) {\n dispatch(setAutofillDraggingTo({ x, y }));\n }\n return false;\n }\n if (leftHeaderSelecting) {\n dispatch(drag({ y: table.getNumRows(), x }));\n return false;\n }\n if (topHeaderSelecting) {\n dispatch(drag({ y, x: table.getNumCols() }));\n return false;\n }\n dispatch(drag({ y, x }));\n\n const newArea = zoneToArea({ ...selectingZone, endY: y, endX: x });\n const fullRange = `${table.sheetPrefix(!differentSheetFocused)}${areaToRange(newArea)}`;\n insertRef(lastInput, fullRange);\n sheetContext?.forceRender?.(); // Force drawing because the formula is not reflected in largeInput\n return true;\n }}\n >\n <div className={`gs-cell-inner-wrap`}>\n <div\n className={'gs-cell-inner'}\n style={{\n ...cell?.style,\n justifyContent: cell?.justifyContent || 'left',\n alignItems: cell?.alignItems || 'start',\n }}\n >\n {errorMessage && <div className=\"gs-formula-error-triangle\" title={errorMessage} />}\n {showAddress && <div className=\"gs-cell-label\">{address}</div>}\n <div className=\"gs-cell-rendered\">{rendered}</div>\n </div>\n {((!editing && pointed && selectingArea.bottom === -1) ||\n (selectingArea.bottom === y && selectingArea.right === x)) && (\n <div\n className=\"gs-autofill-drag\"\n draggable\n onDragStart={(e) => {\n e.dataTransfer.setDragImage(DUMMY_IMG, 0, 0);\n dispatch(setAutofillDraggingTo({ x, y }));\n e.stopPropagation();\n }}\n ></div>\n )}\n </div>\n </td>\n );\n});\n"],"names":["React","editing"],"mappings":";;;;;;;;;;;AA8Ba,MAAA,OAAwBA,eAAM,KAAK,CAAC,EAAE,GAAG,GAAG,qBAAqB;AACtE,QAAA,QAAQ,IAAI,CAAC;AACb,QAAA,QAAQ,IAAI,CAAC;AACnB,QAAM,UAAU,GAAG,KAAK,GAAG,KAAK;AAChC,QAAM,EAAE,OAAO,SAAA,IAAaA,eAAM,WAAW,OAAO;AAC9C,QAAA,iBAAiBA,eAAM,OAAO,IAAI;AAExC,QAAM,CAAC,eAAe,YAAY,IAAI,gBAAgB;AAEhD,QAAA,UAAUA,eAAM,OAAoC,IAAI;AACx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A,WAAU,iBAAiB,UAAQ,SAAA;AAAA,cACvD,oBAAA,OAAA,EAAI,WAAU,oBAAoB,UAAS,SAAA,CAAA;AAAA,YAAA;AAAA,UAAA;AAAA,QAC9C;AAAA,SACG,CAAC,WAAW,WAAW,cAAc,WAAW,MAChD,cAAc,WAAW,KAAK,cAAc,UAAU,MACvD;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,WAAU;AAAA,YACV,WAAS;AAAA,YACT,aAAa,CAAC,MAAM;AAClB,gBAAE,aAAa,aAAa,WAAW,GAAG,CAAC;AAC3C,uBAAS,sBAAsB,EAAE,GAAG,EAAG,CAAA,CAAC;AACxC,gBAAE,gBAAgB;AAAA,YAAA;AAAA,UACpB;AAAA,QAAA;AAAA,MACD,EAEL,CAAA;AAAA,IAAA;AAAA,IAzIK;AAAA,EA0IP;AAEJ,CAAC;"}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React__default from "react";
|
|
3
|
+
import { clip } from "../lib/clipboard.js";
|
|
4
|
+
import { cut, copy, paste, updateTable, undo, redo, setContextMenuPosition } from "../store/actions.js";
|
|
5
|
+
import { zoneToArea, zoneShape, areaToZone } from "../lib/structs.js";
|
|
6
|
+
import { Context } from "../store/index.js";
|
|
7
|
+
import { isPrevented, AddRowAbove, AddRowBelow, AddColLeft, AddColRight, DeleteRow, DeleteCol } from "../lib/prevention.js";
|
|
8
|
+
import { Fixed } from "./Fixed.js";
|
|
9
|
+
const ContextMenu = () => {
|
|
10
|
+
const { store, dispatch } = React__default.useContext(Context);
|
|
11
|
+
const { table, choosing, selectingZone, leftHeaderSelecting, topHeaderSelecting, editorRef, contextMenuPosition } = store;
|
|
12
|
+
const { y, x } = choosing;
|
|
13
|
+
let {
|
|
14
|
+
top: selectingTop,
|
|
15
|
+
left: selectingLeft,
|
|
16
|
+
bottom: selectingBottom,
|
|
17
|
+
right: selectingRight
|
|
18
|
+
} = zoneToArea(selectingZone);
|
|
19
|
+
if (selectingTop === -1) {
|
|
20
|
+
[selectingTop, selectingLeft, selectingBottom, selectingRight] = [y, x, y, x];
|
|
21
|
+
}
|
|
22
|
+
const [tableHeight, tableWidth] = [table.getNumRows(), table.getNumCols()];
|
|
23
|
+
const { height, width } = zoneShape({ ...selectingZone, base: 1 });
|
|
24
|
+
const { y: top, x: left } = contextMenuPosition;
|
|
25
|
+
if (top === -1) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const selectingTopCell = table.getByPoint({ y: selectingTop, x: 0 });
|
|
29
|
+
const selectingLeftCell = table.getByPoint({ y: 0, x: selectingLeft });
|
|
30
|
+
const selectingBottomCell = table.getByPoint({ y: selectingBottom, x: 0 });
|
|
31
|
+
const selectingRightCell = table.getByPoint({ y: 0, x: selectingRight });
|
|
32
|
+
const historyIndex = table.getHistoryIndex();
|
|
33
|
+
return /* @__PURE__ */ jsx(
|
|
34
|
+
Fixed,
|
|
35
|
+
{
|
|
36
|
+
className: "gs-contextmenu-modal",
|
|
37
|
+
onClick: (e) => {
|
|
38
|
+
e.preventDefault();
|
|
39
|
+
dispatch(setContextMenuPosition({ y: -1, x: -1 }));
|
|
40
|
+
return false;
|
|
41
|
+
},
|
|
42
|
+
children: /* @__PURE__ */ jsx(
|
|
43
|
+
"div",
|
|
44
|
+
{
|
|
45
|
+
className: "gs-contextmenu",
|
|
46
|
+
style: {
|
|
47
|
+
top,
|
|
48
|
+
left
|
|
49
|
+
},
|
|
50
|
+
children: /* @__PURE__ */ jsxs("ul", { children: [
|
|
51
|
+
/* @__PURE__ */ jsxs(
|
|
52
|
+
"li",
|
|
53
|
+
{
|
|
54
|
+
className: "gs-enabled",
|
|
55
|
+
onClick: () => {
|
|
56
|
+
const area = clip(store);
|
|
57
|
+
dispatch(cut(areaToZone(area)));
|
|
58
|
+
},
|
|
59
|
+
children: [
|
|
60
|
+
/* @__PURE__ */ jsx("div", { className: "gs-menu-name", children: "Cut" }),
|
|
61
|
+
/* @__PURE__ */ jsx("div", { className: "gs-menu-shortcut", children: /* @__PURE__ */ jsx("span", { className: "gs-menu-underline", children: "X" }) })
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
),
|
|
65
|
+
/* @__PURE__ */ jsxs(
|
|
66
|
+
"li",
|
|
67
|
+
{
|
|
68
|
+
className: "gs-enabled",
|
|
69
|
+
onClick: () => {
|
|
70
|
+
const area = clip(store);
|
|
71
|
+
dispatch(copy(areaToZone(area)));
|
|
72
|
+
},
|
|
73
|
+
children: [
|
|
74
|
+
/* @__PURE__ */ jsx("div", { className: "gs-menu-name", children: "Copy" }),
|
|
75
|
+
/* @__PURE__ */ jsx("div", { className: "gs-menu-shortcut", children: /* @__PURE__ */ jsx("span", { className: "gs-menu-underline", children: "C" }) })
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
),
|
|
79
|
+
/* @__PURE__ */ jsxs(
|
|
80
|
+
"li",
|
|
81
|
+
{
|
|
82
|
+
className: "gs-enabled",
|
|
83
|
+
onClick: () => {
|
|
84
|
+
var _a;
|
|
85
|
+
const text = ((_a = editorRef.current) == null ? void 0 : _a.value) || "";
|
|
86
|
+
dispatch(paste({ text }));
|
|
87
|
+
},
|
|
88
|
+
children: [
|
|
89
|
+
/* @__PURE__ */ jsx("div", { className: "gs-menu-name", children: "Paste" }),
|
|
90
|
+
/* @__PURE__ */ jsx("div", { className: "gs-menu-shortcut", children: /* @__PURE__ */ jsx("span", { className: "gs-menu-underline", children: "V" }) })
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
),
|
|
94
|
+
(leftHeaderSelecting || topHeaderSelecting) && /* @__PURE__ */ jsx("li", { className: "gs-menu-divider" }),
|
|
95
|
+
leftHeaderSelecting && /* @__PURE__ */ jsx(
|
|
96
|
+
"li",
|
|
97
|
+
{
|
|
98
|
+
className: table.maxNumRows !== -1 && tableHeight + height > table.maxNumRows || isPrevented(selectingTopCell == null ? void 0 : selectingTopCell.prevention, AddRowAbove) ? "gs-disabled" : "gs-enabled",
|
|
99
|
+
onClick: () => {
|
|
100
|
+
const newTable = table.addRows({
|
|
101
|
+
y: selectingTop,
|
|
102
|
+
numRows: height,
|
|
103
|
+
baseY: selectingTop,
|
|
104
|
+
reflection: {
|
|
105
|
+
selectingZone,
|
|
106
|
+
choosing
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
dispatch(updateTable(newTable));
|
|
110
|
+
},
|
|
111
|
+
children: /* @__PURE__ */ jsxs("div", { className: "gs-menu-name", children: [
|
|
112
|
+
"Insert ",
|
|
113
|
+
height,
|
|
114
|
+
" row",
|
|
115
|
+
height > 1 && "s",
|
|
116
|
+
" above"
|
|
117
|
+
] })
|
|
118
|
+
}
|
|
119
|
+
),
|
|
120
|
+
leftHeaderSelecting && /* @__PURE__ */ jsx(
|
|
121
|
+
"li",
|
|
122
|
+
{
|
|
123
|
+
className: table.maxNumRows !== -1 && tableHeight + height > table.maxNumRows || isPrevented(selectingBottomCell == null ? void 0 : selectingBottomCell.prevention, AddRowBelow) ? "gs-disabled" : "gs-enabled",
|
|
124
|
+
onClick: (e) => {
|
|
125
|
+
if (e.currentTarget.classList.contains("gs-disabled")) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
selectingZone.startY += height;
|
|
129
|
+
selectingZone.endY += height;
|
|
130
|
+
choosing.y += height;
|
|
131
|
+
const newTable = table.addRows({
|
|
132
|
+
y: selectingBottom + 1,
|
|
133
|
+
numRows: height,
|
|
134
|
+
baseY: selectingBottom,
|
|
135
|
+
reflection: {
|
|
136
|
+
selectingZone,
|
|
137
|
+
choosing
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
dispatch(updateTable(newTable));
|
|
141
|
+
},
|
|
142
|
+
children: /* @__PURE__ */ jsxs("div", { className: "gs-menu-name", children: [
|
|
143
|
+
"Insert ",
|
|
144
|
+
height,
|
|
145
|
+
" row",
|
|
146
|
+
height > 1 && "s",
|
|
147
|
+
" below"
|
|
148
|
+
] })
|
|
149
|
+
}
|
|
150
|
+
),
|
|
151
|
+
topHeaderSelecting && /* @__PURE__ */ jsx(
|
|
152
|
+
"li",
|
|
153
|
+
{
|
|
154
|
+
className: table.maxNumCols !== -1 && tableWidth + width > table.maxNumCols || isPrevented(selectingLeftCell == null ? void 0 : selectingLeftCell.prevention, AddColLeft) ? "gs-disabled" : "gs-enabled",
|
|
155
|
+
onClick: (e) => {
|
|
156
|
+
if (e.currentTarget.classList.contains("gs-disabled")) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const newTable = table.addCols({
|
|
160
|
+
x: selectingLeft,
|
|
161
|
+
numCols: width,
|
|
162
|
+
baseX: selectingLeft,
|
|
163
|
+
reflection: {
|
|
164
|
+
selectingZone,
|
|
165
|
+
choosing
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
dispatch(updateTable(newTable));
|
|
169
|
+
},
|
|
170
|
+
children: /* @__PURE__ */ jsxs("div", { className: "gs-menu-name", children: [
|
|
171
|
+
"Insert ",
|
|
172
|
+
width,
|
|
173
|
+
" column",
|
|
174
|
+
width > 1 && "s",
|
|
175
|
+
" left"
|
|
176
|
+
] })
|
|
177
|
+
}
|
|
178
|
+
),
|
|
179
|
+
topHeaderSelecting && /* @__PURE__ */ jsx(
|
|
180
|
+
"li",
|
|
181
|
+
{
|
|
182
|
+
className: table.maxNumCols !== -1 && tableWidth + width > table.maxNumCols || isPrevented(selectingRightCell == null ? void 0 : selectingRightCell.prevention, AddColRight) ? "gs-disabled" : "gs-enabled",
|
|
183
|
+
onClick: (e) => {
|
|
184
|
+
if (e.currentTarget.classList.contains("gs-disabled")) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
selectingZone.startX += width;
|
|
188
|
+
selectingZone.endX += width;
|
|
189
|
+
choosing.x += width;
|
|
190
|
+
const newTable = table.addCols({
|
|
191
|
+
x: selectingRight + 1,
|
|
192
|
+
numCols: width,
|
|
193
|
+
baseX: selectingRight,
|
|
194
|
+
reflection: {
|
|
195
|
+
selectingZone,
|
|
196
|
+
choosing
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
dispatch(updateTable(newTable));
|
|
200
|
+
},
|
|
201
|
+
children: /* @__PURE__ */ jsxs("div", { className: "gs-menu-name", children: [
|
|
202
|
+
"Insert ",
|
|
203
|
+
width,
|
|
204
|
+
" column",
|
|
205
|
+
width > 1 && "s",
|
|
206
|
+
" right"
|
|
207
|
+
] })
|
|
208
|
+
}
|
|
209
|
+
),
|
|
210
|
+
leftHeaderSelecting && /* @__PURE__ */ jsx(
|
|
211
|
+
"li",
|
|
212
|
+
{
|
|
213
|
+
className: table.minNumRows !== -1 && tableHeight - height < table.minNumRows || isPrevented(selectingTopCell == null ? void 0 : selectingTopCell.prevention, DeleteRow) ? "gs-disabled" : "gs-enabled",
|
|
214
|
+
onClick: (e) => {
|
|
215
|
+
if (e.currentTarget.classList.contains("gs-disabled")) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const newTable = table.deleteRows({
|
|
219
|
+
y: selectingTop,
|
|
220
|
+
numRows: height,
|
|
221
|
+
operator: "USER",
|
|
222
|
+
reflection: {
|
|
223
|
+
selectingZone,
|
|
224
|
+
choosing
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
dispatch(updateTable(newTable));
|
|
228
|
+
},
|
|
229
|
+
children: /* @__PURE__ */ jsxs("div", { className: "gs-menu-name", children: [
|
|
230
|
+
"Delete ",
|
|
231
|
+
height,
|
|
232
|
+
" row",
|
|
233
|
+
height > 1 && "s"
|
|
234
|
+
] })
|
|
235
|
+
}
|
|
236
|
+
),
|
|
237
|
+
topHeaderSelecting && /* @__PURE__ */ jsx(
|
|
238
|
+
"li",
|
|
239
|
+
{
|
|
240
|
+
className: table.minNumCols !== -1 && tableWidth - width < table.minNumCols || isPrevented(selectingRightCell == null ? void 0 : selectingRightCell.prevention, DeleteCol) ? "gs-disabled" : "gs-enabled",
|
|
241
|
+
onClick: () => {
|
|
242
|
+
const newTable = table.deleteCols({
|
|
243
|
+
x: selectingLeft,
|
|
244
|
+
numCols: width,
|
|
245
|
+
operator: "USER",
|
|
246
|
+
reflection: {
|
|
247
|
+
selectingZone,
|
|
248
|
+
choosing
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
dispatch(updateTable(newTable));
|
|
252
|
+
},
|
|
253
|
+
children: /* @__PURE__ */ jsxs("div", { className: "gs-menu-name", children: [
|
|
254
|
+
"Delete ",
|
|
255
|
+
width,
|
|
256
|
+
" column",
|
|
257
|
+
width > 0 && "s"
|
|
258
|
+
] })
|
|
259
|
+
}
|
|
260
|
+
),
|
|
261
|
+
(historyIndex > -1 || historyIndex < table.getHistorySize() - 1) && /* @__PURE__ */ jsx("li", { className: "gs-menu-divider" }),
|
|
262
|
+
historyIndex > -1 && /* @__PURE__ */ jsxs(
|
|
263
|
+
"li",
|
|
264
|
+
{
|
|
265
|
+
className: "gs-enabled",
|
|
266
|
+
onClick: () => {
|
|
267
|
+
dispatch(undo(null));
|
|
268
|
+
},
|
|
269
|
+
children: [
|
|
270
|
+
/* @__PURE__ */ jsx("div", { className: "gs-menu-name", children: "Undo" }),
|
|
271
|
+
/* @__PURE__ */ jsx("div", { className: "gs-menu-shortcut", children: /* @__PURE__ */ jsx("span", { className: "gs-menu-underline", children: "Z" }) })
|
|
272
|
+
]
|
|
273
|
+
}
|
|
274
|
+
),
|
|
275
|
+
historyIndex < table.getHistorySize() - 1 && /* @__PURE__ */ jsxs(
|
|
276
|
+
"li",
|
|
277
|
+
{
|
|
278
|
+
className: "gs-enabled",
|
|
279
|
+
onClick: () => {
|
|
280
|
+
dispatch(redo(null));
|
|
281
|
+
},
|
|
282
|
+
children: [
|
|
283
|
+
/* @__PURE__ */ jsx("div", { className: "gs-menu-name", children: "Redo" }),
|
|
284
|
+
/* @__PURE__ */ jsx("div", { className: "gs-menu-shortcut", children: /* @__PURE__ */ jsx("span", { className: "gs-menu-underline", children: "R" }) })
|
|
285
|
+
]
|
|
286
|
+
}
|
|
287
|
+
)
|
|
288
|
+
] })
|
|
289
|
+
}
|
|
290
|
+
)
|
|
291
|
+
}
|
|
292
|
+
);
|
|
293
|
+
};
|
|
294
|
+
export {
|
|
295
|
+
ContextMenu
|
|
296
|
+
};
|
|
297
|
+
//# sourceMappingURL=ContextMenu.js.map
|