@gridsheet/react-core 1.4.0-alpha.2 → 1.4.0-alpha.4
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/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.js +16 -9113
- package/dist/index.js.map +1 -1
- 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/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.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 +1 -7
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React__default from "react";
|
|
3
|
+
import { x2c } from "../lib/converters.js";
|
|
4
|
+
import { zoneToArea, between } from "../lib/structs.js";
|
|
5
|
+
import { Context } from "../store/index.js";
|
|
6
|
+
import { setResizingPositionX, drag, select, selectCols, choose, setContextMenuPosition, setEditingCell } from "../store/actions.js";
|
|
7
|
+
import { DEFAULT_WIDTH, DUMMY_IMG } from "../constants.js";
|
|
8
|
+
import { isPrevented, Resize } from "../lib/prevention.js";
|
|
9
|
+
import { useSheetContext } from "./SheetProvider.js";
|
|
10
|
+
import { insertRef, isRefInsertable } from "../lib/input.js";
|
|
11
|
+
const HeaderCellTop = React__default.memo(({ x }) => {
|
|
12
|
+
const { store, dispatch } = React__default.useContext(Context);
|
|
13
|
+
const colId = x2c(x);
|
|
14
|
+
const {
|
|
15
|
+
table,
|
|
16
|
+
choosing,
|
|
17
|
+
selectingZone,
|
|
18
|
+
resizingRect,
|
|
19
|
+
topHeaderSelecting,
|
|
20
|
+
headerHeight,
|
|
21
|
+
editorRef,
|
|
22
|
+
autofillDraggingTo
|
|
23
|
+
} = store;
|
|
24
|
+
const col = table.getByPoint({ y: 0, x });
|
|
25
|
+
const width = (col == null ? void 0 : col.width) || DEFAULT_WIDTH;
|
|
26
|
+
const [sheetProvided, sheetContext] = useSheetContext();
|
|
27
|
+
const differentSheetFocused = sheetProvided && (sheetContext == null ? void 0 : sheetContext.lastFocusedRef) !== store.lastFocusedRef;
|
|
28
|
+
const lastFocusedRef = (sheetContext == null ? void 0 : sheetContext.lastFocusedRef) || store.lastFocusedRef;
|
|
29
|
+
const lastInput = lastFocusedRef.current;
|
|
30
|
+
return /* @__PURE__ */ jsx(
|
|
31
|
+
"th",
|
|
32
|
+
{
|
|
33
|
+
"data-x": x,
|
|
34
|
+
className: `gs-th gs-th-top ${choosing.x === x ? "gs-choosing" : ""} ${between({ start: selectingZone.startX, end: selectingZone.endX }, x) ? topHeaderSelecting ? "gs-th-selecting" : "gs-selecting" : ""}`,
|
|
35
|
+
style: { width, minWidth: width, maxWidth: width },
|
|
36
|
+
onClick: (e) => {
|
|
37
|
+
let startX = e.shiftKey ? selectingZone.startX : x;
|
|
38
|
+
if (startX === -1) {
|
|
39
|
+
startX = choosing.x;
|
|
40
|
+
}
|
|
41
|
+
const fullColId = `${table.sheetPrefix(!differentSheetFocused)}${colId}:${colId}`;
|
|
42
|
+
const inserted = insertRef(lastInput, fullColId);
|
|
43
|
+
if (inserted) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
dispatch(
|
|
47
|
+
selectCols({
|
|
48
|
+
range: { start: startX, end: x },
|
|
49
|
+
numRows: table.getNumRows()
|
|
50
|
+
})
|
|
51
|
+
);
|
|
52
|
+
dispatch(setContextMenuPosition({ y: -1, x: -1 }));
|
|
53
|
+
dispatch(choose({ y: 1, x: startX }));
|
|
54
|
+
dispatch(setEditingCell(""));
|
|
55
|
+
editorRef.current.focus();
|
|
56
|
+
return false;
|
|
57
|
+
},
|
|
58
|
+
onContextMenu: (e) => {
|
|
59
|
+
e.preventDefault();
|
|
60
|
+
dispatch(setContextMenuPosition({ y: e.clientY, x: e.clientX }));
|
|
61
|
+
return false;
|
|
62
|
+
},
|
|
63
|
+
children: /* @__PURE__ */ jsx(
|
|
64
|
+
"div",
|
|
65
|
+
{
|
|
66
|
+
className: "gs-th-inner-wrap",
|
|
67
|
+
draggable: true,
|
|
68
|
+
onDragStart: (e) => {
|
|
69
|
+
e.dataTransfer.setDragImage(DUMMY_IMG, 0, 0);
|
|
70
|
+
const insertable = isRefInsertable(lastInput);
|
|
71
|
+
if (insertable) {
|
|
72
|
+
dispatch(select({ startY: table.getNumRows(), startX: x, endY: 0, endX: x }));
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
dispatch(
|
|
76
|
+
selectCols({
|
|
77
|
+
range: { start: x, end: x },
|
|
78
|
+
numRows: table.getNumRows()
|
|
79
|
+
})
|
|
80
|
+
);
|
|
81
|
+
dispatch(choose({ y: 1, x }));
|
|
82
|
+
return false;
|
|
83
|
+
},
|
|
84
|
+
onDragEnd: () => {
|
|
85
|
+
if (isRefInsertable(lastInput)) {
|
|
86
|
+
dispatch(select({ startY: -1, startX: -1, endY: -1, endX: -1 }));
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
onDragEnter: () => {
|
|
90
|
+
const newArea = zoneToArea({ ...selectingZone, endY: 1, endX: x });
|
|
91
|
+
const [left, right] = [x2c(newArea.left), x2c(newArea.right)];
|
|
92
|
+
const fullRange = `${table.sheetPrefix(!differentSheetFocused)}${left}:${right}`;
|
|
93
|
+
insertRef(lastInput, fullRange);
|
|
94
|
+
if (resizingRect.x === -1 && autofillDraggingTo == null) {
|
|
95
|
+
const { startY } = selectingZone;
|
|
96
|
+
if (startY === 1) {
|
|
97
|
+
dispatch(drag({ y: table.getNumRows(), x }));
|
|
98
|
+
} else {
|
|
99
|
+
dispatch(drag({ y: 1, x }));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
103
|
+
},
|
|
104
|
+
onDragOver: (e) => {
|
|
105
|
+
e.dataTransfer.dropEffect = "move";
|
|
106
|
+
e.preventDefault();
|
|
107
|
+
},
|
|
108
|
+
children: /* @__PURE__ */ jsxs("div", { className: "gs-th-inner", style: { height: headerHeight, position: "relative" }, children: [
|
|
109
|
+
(col == null ? void 0 : col.labeler) ? table.getLabel(col.labeler, x) : colId,
|
|
110
|
+
/* @__PURE__ */ jsx(
|
|
111
|
+
"div",
|
|
112
|
+
{
|
|
113
|
+
className: `gs-resizer ${isPrevented(col == null ? void 0 : col.prevention, Resize) ? "gs-protected" : ""}`,
|
|
114
|
+
style: { height: headerHeight },
|
|
115
|
+
onMouseDown: (e) => {
|
|
116
|
+
dispatch(setResizingPositionX([x, e.clientX, e.clientX]));
|
|
117
|
+
e.preventDefault();
|
|
118
|
+
e.stopPropagation();
|
|
119
|
+
},
|
|
120
|
+
children: /* @__PURE__ */ jsx("i", {})
|
|
121
|
+
}
|
|
122
|
+
)
|
|
123
|
+
] })
|
|
124
|
+
}
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
});
|
|
129
|
+
export {
|
|
130
|
+
HeaderCellTop
|
|
131
|
+
};
|
|
132
|
+
//# sourceMappingURL=HeaderCellTop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HeaderCellTop.js","sources":["../../components/HeaderCellTop.tsx"],"sourcesContent":["import React from 'react';\nimport { x2c } from '../lib/converters';\nimport { between, zoneToArea } from '../lib/structs';\nimport { Context } from '../store';\nimport {\n choose,\n drag,\n select,\n selectCols,\n setContextMenuPosition,\n setEditingCell,\n setResizingPositionX,\n} from '../store/actions';\nimport { DUMMY_IMG, DEFAULT_WIDTH } from '../constants';\nimport * as prevention from '../lib/prevention';\nimport { useSheetContext } from './SheetProvider';\nimport { insertRef, isRefInsertable } from '../lib/input';\n\ntype Props = {\n x: number;\n};\n\nexport const HeaderCellTop: React.FC<Props> = React.memo(({ x }) => {\n const { store, dispatch } = React.useContext(Context);\n const colId = x2c(x);\n\n const {\n table,\n choosing,\n selectingZone,\n resizingRect,\n topHeaderSelecting,\n headerHeight,\n editorRef,\n autofillDraggingTo,\n } = store;\n\n const col = table.getByPoint({ y: 0, x });\n const width = col?.width || DEFAULT_WIDTH;\n\n const [sheetProvided, sheetContext] = useSheetContext();\n const differentSheetFocused = sheetProvided && sheetContext?.lastFocusedRef !== store.lastFocusedRef;\n\n const lastFocusedRef = sheetContext?.lastFocusedRef || store.lastFocusedRef;\n const lastInput = lastFocusedRef.current;\n\n return (\n <th\n data-x={x}\n className={`gs-th gs-th-top ${choosing.x === x ? 'gs-choosing' : ''} ${\n between({ start: selectingZone.startX, end: selectingZone.endX }, x)\n ? topHeaderSelecting\n ? 'gs-th-selecting'\n : 'gs-selecting'\n : ''\n }`}\n style={{ width, minWidth: width, maxWidth: width }}\n onClick={(e) => {\n let startX = e.shiftKey ? selectingZone.startX : x;\n if (startX === -1) {\n startX = choosing.x;\n }\n const fullColId = `${table.sheetPrefix(!differentSheetFocused)}${colId}:${colId}`;\n const inserted = insertRef(lastInput, fullColId);\n if (inserted) {\n return false;\n }\n\n dispatch(\n selectCols({\n range: { start: startX, end: x },\n numRows: table.getNumRows(),\n }),\n );\n dispatch(setContextMenuPosition({ y: -1, x: -1 }));\n dispatch(choose({ y: 1, x: startX }));\n dispatch(setEditingCell(''));\n editorRef.current!.focus();\n return false;\n }}\n onContextMenu={(e) => {\n e.preventDefault();\n dispatch(setContextMenuPosition({ y: e.clientY, x: e.clientX }));\n return false;\n }}\n >\n <div\n className=\"gs-th-inner-wrap\"\n draggable\n onDragStart={(e) => {\n e.dataTransfer.setDragImage(DUMMY_IMG, 0, 0);\n const insertable = isRefInsertable(lastInput);\n if (insertable) {\n dispatch(select({ startY: table.getNumRows(), startX: x, endY: 0, endX: x }));\n return false;\n }\n dispatch(\n selectCols({\n range: { start: x, end: x },\n numRows: table.getNumRows(),\n }),\n );\n dispatch(choose({ y: 1, x }));\n return false;\n }}\n onDragEnd={() => {\n if (isRefInsertable(lastInput)) {\n dispatch(select({ startY: -1, startX: -1, endY: -1, endX: -1 }));\n }\n }}\n onDragEnter={() => {\n const newArea = zoneToArea({ ...selectingZone, endY: 1, endX: x });\n const [left, right] = [x2c(newArea.left), x2c(newArea.right)];\n const fullRange = `${table.sheetPrefix(!differentSheetFocused)}${left}:${right}`;\n insertRef(lastInput, fullRange);\n\n if (resizingRect.x === -1 && autofillDraggingTo == null) {\n const { startY } = selectingZone;\n if (startY === 1) {\n dispatch(drag({ y: table.getNumRows(), x }));\n } else {\n dispatch(drag({ y: 1, x }));\n }\n }\n return false;\n }}\n onDragOver={(e) => {\n e.dataTransfer.dropEffect = 'move';\n e.preventDefault();\n }}\n >\n <div className=\"gs-th-inner\" style={{ height: headerHeight, position: 'relative' }}>\n {col?.labeler ? table.getLabel(col.labeler, x) : colId}\n <div\n className={`gs-resizer ${prevention.isPrevented(col?.prevention, prevention.Resize) ? 'gs-protected' : ''}`}\n style={{ height: headerHeight }}\n onMouseDown={(e) => {\n dispatch(setResizingPositionX([x, e.clientX, e.clientX]));\n e.preventDefault();\n e.stopPropagation();\n }}\n >\n <i />\n </div>\n </div>\n </div>\n </th>\n );\n});\n"],"names":["React","prevention.isPrevented","prevention.Resize"],"mappings":";;;;;;;;;;AAsBO,MAAM,gBAAiCA,eAAM,KAAK,CAAC,EAAE,QAAQ;AAClE,QAAM,EAAE,OAAO,SAAA,IAAaA,eAAM,WAAW,OAAO;AAC9C,QAAA,QAAQ,IAAI,CAAC;AAEb,QAAA;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,IACE;AAEJ,QAAM,MAAM,MAAM,WAAW,EAAE,GAAG,GAAG,GAAG;AAClC,QAAA,SAAQ,2BAAK,UAAS;AAE5B,QAAM,CAAC,eAA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YAAY,CAAC,MAAM;AACjB,cAAE,aAAa,aAAa;AAC5B,cAAE,eAAe;AAAA,UACnB;AAAA,UAEA,UAAA,qBAAC,OAAI,EAAA,WAAU,eAAc,OAAO,EAAE,QAAQ,cAAc,UAAU,WAAA,GACnE,UAAA;AAAA,aAAA,2BAAK,WAAU,MAAM,SAAS,IAAI,SAAS,CAAC,IAAI;AAAA,YACjD;AAAA,cAAC;AAAA,cAAA;AAAA,gBACC,WAAW,cAAcC,YAAuB,2BAAK,YAAYC,MAAiB,IAAI,iBAAiB,EAAE;AAAA,gBACzG,OAAO,EAAE,QAAQ,aAAa;AAAA,gBAC9B,aAAa,CAAC,MAAM;AACT,2BAAA,qBAAqB,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AACxD,oBAAE,eAAe;AACjB,oBAAE,gBAAgB;AAAA,gBACpB;AAAA,gBAEA,8BAAC,KAAE,CAAA,CAAA;AAAA,cAAA;AAAA,YAAA;AAAA,UACL,EACF,CAAA;AAAA,QAAA;AAAA,MAAA;AAAA,IACF;AAAA,EACF;AAEJ,CAAC;"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import React__default from "react";
|
|
3
|
+
const PluginContext = React__default.createContext({});
|
|
4
|
+
function useInitialPluginContext() {
|
|
5
|
+
const [store, setStore] = React__default.useState(void 0);
|
|
6
|
+
const [dispatch, setDispatch] = React__default.useState();
|
|
7
|
+
return {
|
|
8
|
+
provided: true,
|
|
9
|
+
store,
|
|
10
|
+
dispatch,
|
|
11
|
+
setStore,
|
|
12
|
+
setDispatch
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function usePluginContext() {
|
|
16
|
+
const ctx = React__default.useContext(PluginContext);
|
|
17
|
+
if ((ctx == null ? void 0 : ctx.provided) == null) {
|
|
18
|
+
return [false, ctx];
|
|
19
|
+
}
|
|
20
|
+
return [true, ctx];
|
|
21
|
+
}
|
|
22
|
+
function PluginBase({ children, context }) {
|
|
23
|
+
const [provided] = usePluginContext();
|
|
24
|
+
if (provided) {
|
|
25
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
26
|
+
}
|
|
27
|
+
return /* @__PURE__ */ jsx(PluginContext.Provider, { value: context, children });
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
PluginBase,
|
|
31
|
+
PluginContext,
|
|
32
|
+
useInitialPluginContext,
|
|
33
|
+
usePluginContext
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=PluginBase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PluginBase.js","sources":["../../components/PluginBase.tsx"],"sourcesContent":["import React from 'react';\n\nimport { StoreType } from '../types';\nimport { Dispatcher } from '../store';\n\nexport type PluginContextType = {\n provided: boolean;\n store?: StoreType;\n dispatch?: Dispatcher;\n setStore: (store: StoreType) => void;\n setDispatch: (dispatch: Dispatcher) => void;\n};\n\nexport const PluginContext = React.createContext({} as PluginContextType);\n\nexport function useInitialPluginContext(): PluginContextType {\n const [store, setStore] = React.useState<StoreType | undefined>(undefined);\n const [dispatch, setDispatch] = React.useState<Dispatcher>();\n return {\n provided: true,\n store,\n dispatch,\n setStore,\n setDispatch,\n };\n}\n\nexport function usePluginContext(): [boolean, PluginContextType] {\n const ctx = React.useContext(PluginContext);\n if (ctx?.provided == null) {\n return [false, ctx];\n }\n return [true, ctx];\n}\n\nexport function usePluginDispatch() {\n const dispatch = React.useContext(PluginContext);\n if (!dispatch) {\n return undefined;\n }\n return dispatch;\n}\n\ntype Props = {\n children: React.ReactNode;\n context: PluginContextType;\n};\n\nexport function PluginBase({ children, context }: Props) {\n const [provided] = usePluginContext();\n if (provided) {\n return <>{children}</>;\n }\n return <PluginContext.Provider value={context}>{children}</PluginContext.Provider>;\n}\n"],"names":["React"],"mappings":";;AAaO,MAAM,gBAAgBA,eAAM,cAAc,CAAuB,CAAA;AAEjE,SAAS,0BAA6C;AAC3D,QAAM,CAAC,OAAO,QAAQ,IAAIA,eAAM,SAAgC,MAAS;AACzE,QAAM,CAAC,UAAU,WAAW,IAAIA,eAAM,SAAqB;AACpD,SAAA;AAAA,IACL,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,mBAAiD;AACzD,QAAA,MAAMA,eAAM,WAAW,aAAa;AACtC,OAAA,2BAAK,aAAY,MAAM;AAClB,WAAA,CAAC,OAAO,GAAG;AAAA,EAAA;AAEb,SAAA,CAAC,MAAM,GAAG;AACnB;AAeO,SAAS,WAAW,EAAE,UAAU,WAAkB;AACjD,QAAA,CAAC,QAAQ,IAAI,iBAAiB;AACpC,MAAI,UAAU;AACZ,2CAAU,UAAS;AAAA,EAAA;AAErB,6BAAQ,cAAc,UAAd,EAAuB,OAAO,SAAU,UAAS;AAC3D;"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import React__default from "react";
|
|
3
|
+
import { Context } from "../store/index.js";
|
|
4
|
+
import { setResizingPositionY, setResizingPositionX, updateTable } from "../store/actions.js";
|
|
5
|
+
import { DEFAULT_WIDTH, DEFAULT_HEIGHT, MIN_HEIGHT, MIN_WIDTH } from "../constants.js";
|
|
6
|
+
import { zoneToArea, between, makeSequence } from "../lib/structs.js";
|
|
7
|
+
import { p2a } from "../lib/converters.js";
|
|
8
|
+
const Resizer = React__default.memo(() => {
|
|
9
|
+
const { store, dispatch } = React__default.useContext(Context);
|
|
10
|
+
const {
|
|
11
|
+
resizingPositionY: posY,
|
|
12
|
+
resizingPositionX: posX,
|
|
13
|
+
table,
|
|
14
|
+
leftHeaderSelecting,
|
|
15
|
+
topHeaderSelecting,
|
|
16
|
+
selectingZone,
|
|
17
|
+
editorRef,
|
|
18
|
+
mainRef
|
|
19
|
+
} = store;
|
|
20
|
+
const [y, startY, endY] = posY;
|
|
21
|
+
const [x, startX, endX] = posX;
|
|
22
|
+
if (y === -1 && x === -1) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
if (mainRef.current == null || editorRef.current == null) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const cell = table.getByPoint({ y: y === -1 ? 0 : y, x: x === -1 ? 0 : x });
|
|
29
|
+
const { y: offsetY, x: offsetX } = mainRef.current.getBoundingClientRect();
|
|
30
|
+
const baseWidth = (cell == null ? void 0 : cell.width) || DEFAULT_WIDTH;
|
|
31
|
+
const baseHeight = (cell == null ? void 0 : cell.height) || DEFAULT_HEIGHT;
|
|
32
|
+
const width = baseWidth + (endX - startX);
|
|
33
|
+
const height = baseHeight + (endY - startY);
|
|
34
|
+
const handleResizeEnd = () => {
|
|
35
|
+
const selectingArea = zoneToArea(selectingZone);
|
|
36
|
+
const { top, left, bottom, right } = selectingArea;
|
|
37
|
+
const diff = {};
|
|
38
|
+
if (x !== -1) {
|
|
39
|
+
let xs = [x];
|
|
40
|
+
if (topHeaderSelecting && between({ start: left, end: right }, x)) {
|
|
41
|
+
xs = makeSequence(left, right + 1);
|
|
42
|
+
}
|
|
43
|
+
xs.forEach((x2) => {
|
|
44
|
+
diff[p2a({ y: 0, x: x2 })] = { width };
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
if (y !== -1) {
|
|
48
|
+
let ys = [y];
|
|
49
|
+
if (leftHeaderSelecting && between({ start: top, end: bottom }, y)) {
|
|
50
|
+
ys = makeSequence(top, bottom + 1);
|
|
51
|
+
}
|
|
52
|
+
ys.forEach((y2) => {
|
|
53
|
+
diff[p2a({ y: y2, x: 0 })] = { height };
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const newTable = table.update({
|
|
57
|
+
diff,
|
|
58
|
+
partial: true,
|
|
59
|
+
operator: "USER",
|
|
60
|
+
reflection: { selectingZone }
|
|
61
|
+
});
|
|
62
|
+
dispatch(updateTable(newTable));
|
|
63
|
+
dispatch(setResizingPositionY([-1, -1, -1]));
|
|
64
|
+
dispatch(setResizingPositionX([-1, -1, -1]));
|
|
65
|
+
editorRef.current.focus();
|
|
66
|
+
};
|
|
67
|
+
const handleResizeMove = (e) => {
|
|
68
|
+
if (y !== -1) {
|
|
69
|
+
let endY2 = e.clientY;
|
|
70
|
+
const height2 = baseHeight + (endY2 - startY);
|
|
71
|
+
if (height2 < MIN_HEIGHT) {
|
|
72
|
+
endY2 += MIN_HEIGHT - height2;
|
|
73
|
+
}
|
|
74
|
+
dispatch(setResizingPositionY([y, startY, endY2]));
|
|
75
|
+
} else if (x !== -1) {
|
|
76
|
+
let endX2 = e.clientX;
|
|
77
|
+
const width2 = baseWidth + (endX2 - startX);
|
|
78
|
+
if (width2 < MIN_WIDTH) {
|
|
79
|
+
endX2 += MIN_WIDTH - width2;
|
|
80
|
+
}
|
|
81
|
+
dispatch(setResizingPositionX([x, startX, endX2]));
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
return /* @__PURE__ */ jsxs("div", { className: "gs-resizing", onMouseUp: handleResizeEnd, onMouseMove: handleResizeMove, children: [
|
|
85
|
+
x !== -1 && /* @__PURE__ */ jsx("div", { className: "gs-line", style: { width: 1, height: "100%", left: endX - offsetX }, children: /* @__PURE__ */ jsxs("span", { style: { left: "-50%" }, children: [
|
|
86
|
+
width,
|
|
87
|
+
"px"
|
|
88
|
+
] }) }),
|
|
89
|
+
y !== -1 && /* @__PURE__ */ jsx("div", { className: "gs-line", style: { width: "100%", height: 1, top: endY - offsetY }, children: /* @__PURE__ */ jsxs("span", { style: { top: "-50%" }, children: [
|
|
90
|
+
height,
|
|
91
|
+
"px"
|
|
92
|
+
] }) })
|
|
93
|
+
] });
|
|
94
|
+
});
|
|
95
|
+
export {
|
|
96
|
+
Resizer
|
|
97
|
+
};
|
|
98
|
+
//# sourceMappingURL=Resizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Resizer.js","sources":["../../components/Resizer.tsx"],"sourcesContent":["import React from 'react';\n\nimport { Context } from '../store';\nimport { setResizingPositionY, setResizingPositionX, updateTable } from '../store/actions';\n\nimport { DEFAULT_HEIGHT, DEFAULT_WIDTH, MIN_WIDTH, MIN_HEIGHT } from '../constants';\nimport { zoneToArea, makeSequence, between } from '../lib/structs';\nimport { CellsByAddressType } from '../types';\nimport { p2a } from '../lib/converters';\n\nexport const Resizer: React.FC = React.memo(() => {\n const { store, dispatch } = React.useContext(Context);\n const {\n resizingPositionY: posY,\n resizingPositionX: posX,\n table,\n leftHeaderSelecting,\n topHeaderSelecting,\n selectingZone,\n editorRef,\n mainRef,\n } = store;\n\n const [y, startY, endY] = posY;\n const [x, startX, endX] = posX;\n if (y === -1 && x === -1) {\n return null;\n }\n if (mainRef.current == null || editorRef.current == null) {\n return null;\n }\n const cell = table.getByPoint({ y: y === -1 ? 0 : y, x: x === -1 ? 0 : x });\n const { y: offsetY, x: offsetX } = mainRef.current.getBoundingClientRect();\n\n const baseWidth = cell?.width || DEFAULT_WIDTH;\n const baseHeight = cell?.height || DEFAULT_HEIGHT;\n\n const width = baseWidth + (endX - startX);\n const height = baseHeight + (endY - startY);\n\n const handleResizeEnd = () => {\n const selectingArea = zoneToArea(selectingZone);\n const { top, left, bottom, right } = selectingArea;\n const diff: CellsByAddressType = {};\n if (x !== -1) {\n let xs = [x];\n if (topHeaderSelecting && between({ start: left, end: right }, x)) {\n xs = makeSequence(left, right + 1);\n }\n xs.forEach((x) => {\n diff[p2a({ y: 0, x })] = { width };\n });\n }\n if (y !== -1) {\n let ys = [y];\n if (leftHeaderSelecting && between({ start: top, end: bottom }, y)) {\n ys = makeSequence(top, bottom + 1);\n }\n ys.forEach((y) => {\n diff[p2a({ y, x: 0 })] = { height };\n });\n }\n const newTable = table.update({\n diff,\n partial: true,\n operator: 'USER',\n reflection: { selectingZone },\n });\n dispatch(updateTable(newTable));\n dispatch(setResizingPositionY([-1, -1, -1]));\n dispatch(setResizingPositionX([-1, -1, -1]));\n editorRef.current!.focus();\n };\n const handleResizeMove = (e: React.MouseEvent) => {\n if (y !== -1) {\n let endY = e.clientY;\n const height = baseHeight + (endY - startY);\n if (height < MIN_HEIGHT) {\n endY += MIN_HEIGHT - height;\n }\n dispatch(setResizingPositionY([y, startY, endY]));\n } else if (x !== -1) {\n let endX = e.clientX;\n const width = baseWidth + (endX - startX);\n if (width < MIN_WIDTH) {\n endX += MIN_WIDTH - width;\n }\n dispatch(setResizingPositionX([x, startX, endX]));\n }\n };\n\n return (\n <div className=\"gs-resizing\" onMouseUp={handleResizeEnd} onMouseMove={handleResizeMove}>\n {x !== -1 && (\n <div className={'gs-line'} style={{ width: 1, height: '100%', left: endX - offsetX }}>\n <span style={{ left: '-50%' }}>{width}px</span>\n </div>\n )}\n {y !== -1 && (\n <div className={'gs-line'} style={{ width: '100%', height: 1, top: endY - offsetY }}>\n <span style={{ top: '-50%' }}>{height}px</span>\n </div>\n )}\n </div>\n );\n});\n"],"names":["React","x","y","endY","height","endX","width"],"mappings":";;;;;;;AAUa,MAAA,UAAoBA,eAAM,KAAK,MAAM;AAChD,QAAM,EAAE,OAAO,SAAA,IAAaA,eAAM,WAAW,OAAO;AAC9C,QAAA;AAAA,IACJ,mBAAmB;AAAA,IACnB,mBAAmB;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,IACE;AAEJ,QAAM,CAAC,GAAG,QAAQ,IAAI,IAAI;AAC1B,QAAM,CAAC,GAAG,QAAQ,IAAI,IAAI;AACtB,MAAA,MAAM,MAAM,MAAM,IAAI;AACjB,WAAA;AAAA,EAAA;AAET,MAAI,QAAQ,WAAW,QAAQ,UAAU,WAAW,MAAM;AACjD,WAAA;AAAA,EAAA;AAET,QAAM,OAAO,MAAM,WAAW,EAAE,GAAG,MAAM,KAAK,IAAI,GAAG,GAAG,MAAM,KAAK,IAAI,GAAG;AACpE,QAAA,EAAE,GAAG,SAAS,GAAG,YAAY,QAAQ,QAAQ,sBAAsB;AAEnE,Q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AI,MAAM,IAAI;AACZ,UAAIC,QAAO,EAAE;AACPC,YAAAA,UAAS,cAAcD,QAAO;AACpC,UAAIC,UAAS,YAAY;AACvBD,iBAAQ,aAAaC;AAAAA,MAAA;AAEvB,eAAS,qBAAqB,CAAC,GAAG,QAAQD,KAAI,CAAC,CAAC;AAAA,IAAA,WACvC,MAAM,IAAI;AACnB,UAAIE,QAAO,EAAE;AACPC,YAAAA,SAAQ,aAAaD,QAAO;AAClC,UAAIC,SAAQ,WAAW;AACrBD,iBAAQ,YAAYC;AAAAA,MAAA;AAEtB,eAAS,qBAAqB,CAAC,GAAG,QAAQD,KAAI,CAAC,CAAC;AAAA,IAAA;AAAA,EAEpD;AAEA,8BACG,OAAI,EAAA,WAAU,eAAc,WAAW,iBAAiB,aAAa,kBACnE,UAAA;AAAA,IAAM,MAAA,0BACJ,OAAI,EAAA,WAAW,WAAW,OAAO,EAAE,OAAO,GAAG,QAAQ,QAAQ,MAAM,OAAO,WACzE,UAAA,qBAAC,UAAK,OAAO,EAAE,MAAM,OAAA,GAAW,UAAA;AAAA,MAAA;AAAA,MAAM;AAAA,IAAA,EAAA,CAAE,EAC1C,CAAA;AAAA,IAED,MAAM,MACJ,oBAAA,OAAA,EAAI,WAAW,WAAW,OAAO,EAAE,OAAO,QAAQ,QAAQ,GAAG,KAAK,OAAO,WACxE,UAAA,qBAAC,UAAK,OAAO,EAAE,KAAK,OAAA,GAAW,UAAA;AAAA,MAAA;AAAA,MAAO;AAAA,IAAA,EAAA,CAAE,EAC1C,CAAA;AAAA,EAAA,GAEJ;AAEJ,CAAC;"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { a2p } from "../lib/converters.js";
|
|
3
|
+
import React__default from "react";
|
|
4
|
+
import { Context } from "../store/index.js";
|
|
5
|
+
import { search, setSearchQuery, setSearchCaseSensitive } from "../store/actions.js";
|
|
6
|
+
import { smartScroll } from "../lib/virtualization.js";
|
|
7
|
+
import { SearchIcon } from "./svg/SearchIcon.js";
|
|
8
|
+
import { CloseIcon } from "./svg/CloseIcon.js";
|
|
9
|
+
const SearchBar = () => {
|
|
10
|
+
const { store, dispatch } = React__default.useContext(Context);
|
|
11
|
+
const {
|
|
12
|
+
rootRef,
|
|
13
|
+
editorRef,
|
|
14
|
+
searchInputRef,
|
|
15
|
+
tabularRef,
|
|
16
|
+
searchQuery,
|
|
17
|
+
searchCaseSensitive,
|
|
18
|
+
matchingCellIndex,
|
|
19
|
+
matchingCells,
|
|
20
|
+
table
|
|
21
|
+
} = store;
|
|
22
|
+
const matchingCell = matchingCells[matchingCellIndex];
|
|
23
|
+
React__default.useEffect(() => {
|
|
24
|
+
if (!matchingCell) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const point = a2p(matchingCell);
|
|
28
|
+
if (typeof point === "undefined") {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
smartScroll(table, tabularRef.current, point);
|
|
32
|
+
}, [searchQuery, matchingCellIndex, searchCaseSensitive]);
|
|
33
|
+
if (typeof searchQuery === "undefined") {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
if (rootRef.current === null) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return /* @__PURE__ */ jsxs("label", { className: `gs-search-bar ${matchingCells.length > 0 ? "gs-search-found" : ""}`, children: [
|
|
40
|
+
/* @__PURE__ */ jsxs(
|
|
41
|
+
"div",
|
|
42
|
+
{
|
|
43
|
+
className: "gs-search-progress",
|
|
44
|
+
onClick: (e) => {
|
|
45
|
+
const input = e.currentTarget.previousSibling;
|
|
46
|
+
(input == null ? void 0 : input.nodeName) === "INPUT" && input.focus();
|
|
47
|
+
},
|
|
48
|
+
children: [
|
|
49
|
+
matchingCells.length === 0 ? 0 : matchingCellIndex + 1,
|
|
50
|
+
" / ",
|
|
51
|
+
matchingCells.length
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
),
|
|
55
|
+
/* @__PURE__ */ jsx("div", { className: "gs-search-bar-icon", onClick: () => dispatch(search(1)), children: /* @__PURE__ */ jsx(SearchIcon, { style: { verticalAlign: "middle", marginLeft: "5px" } }) }),
|
|
56
|
+
/* @__PURE__ */ jsx(
|
|
57
|
+
"textarea",
|
|
58
|
+
{
|
|
59
|
+
ref: searchInputRef,
|
|
60
|
+
value: searchQuery,
|
|
61
|
+
onChange: (e) => dispatch(setSearchQuery(e.target.value)),
|
|
62
|
+
onKeyDown: (e) => {
|
|
63
|
+
if (e.key === "Escape") {
|
|
64
|
+
const el = editorRef == null ? void 0 : editorRef.current;
|
|
65
|
+
if (el) {
|
|
66
|
+
el.focus();
|
|
67
|
+
}
|
|
68
|
+
dispatch(setSearchQuery(void 0));
|
|
69
|
+
}
|
|
70
|
+
if (e.key === "f" && (e.ctrlKey || e.metaKey)) {
|
|
71
|
+
e.preventDefault();
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
if (e.key === "Enter") {
|
|
75
|
+
dispatch(search(e.shiftKey ? -1 : 1));
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
),
|
|
83
|
+
/* @__PURE__ */ jsx("div", { className: `gs-search-casesensitive`, children: /* @__PURE__ */ jsx(
|
|
84
|
+
"span",
|
|
85
|
+
{
|
|
86
|
+
className: `${searchCaseSensitive ? "gs-search-casesensitive-on" : ""}`,
|
|
87
|
+
onClick: () => dispatch(setSearchCaseSensitive(!searchCaseSensitive)),
|
|
88
|
+
children: "Aa"
|
|
89
|
+
}
|
|
90
|
+
) }),
|
|
91
|
+
/* @__PURE__ */ jsx(
|
|
92
|
+
"a",
|
|
93
|
+
{
|
|
94
|
+
className: "gs-search-close",
|
|
95
|
+
onClick: () => {
|
|
96
|
+
var _a;
|
|
97
|
+
dispatch(setSearchQuery(void 0));
|
|
98
|
+
(_a = editorRef.current) == null ? void 0 : _a.focus();
|
|
99
|
+
},
|
|
100
|
+
children: /* @__PURE__ */ jsx(CloseIcon, { style: { verticalAlign: "middle" } })
|
|
101
|
+
}
|
|
102
|
+
)
|
|
103
|
+
] });
|
|
104
|
+
};
|
|
105
|
+
export {
|
|
106
|
+
SearchBar
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=SearchBar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchBar.js","sources":["../../components/SearchBar.tsx"],"sourcesContent":["import { a2p } from '../lib/converters';\nimport React from 'react';\n\nimport { Context } from '../store';\nimport { setSearchQuery, search, setSearchCaseSensitive } from '../store/actions';\nimport { smartScroll } from '../lib/virtualization';\nimport { SearchIcon } from './svg/SearchIcon';\nimport { CloseIcon } from './svg/CloseIcon';\n\nexport const SearchBar: React.FC = () => {\n const { store, dispatch } = React.useContext(Context);\n const {\n rootRef,\n editorRef,\n searchInputRef,\n tabularRef,\n searchQuery,\n searchCaseSensitive,\n matchingCellIndex,\n matchingCells,\n table,\n } = store;\n\n const matchingCell = matchingCells[matchingCellIndex];\n React.useEffect(() => {\n if (!matchingCell) {\n return;\n }\n const point = a2p(matchingCell);\n if (typeof point === 'undefined') {\n return;\n }\n smartScroll(table, tabularRef.current, point);\n }, [searchQuery, matchingCellIndex, searchCaseSensitive]);\n\n if (typeof searchQuery === 'undefined') {\n return null;\n }\n if (rootRef.current === null) {\n return null;\n }\n return (\n <label className={`gs-search-bar ${matchingCells.length > 0 ? 'gs-search-found' : ''}`}>\n <div\n className=\"gs-search-progress\"\n onClick={(e) => {\n const input = e.currentTarget.previousSibling as HTMLInputElement;\n input?.nodeName === 'INPUT' && input.focus();\n }}\n >\n {matchingCells.length === 0 ? 0 : matchingCellIndex + 1} / {matchingCells.length}\n </div>\n <div className=\"gs-search-bar-icon\" onClick={() => dispatch(search(1))}>\n <SearchIcon style={{ verticalAlign: 'middle', marginLeft: '5px' }} />\n </div>\n <textarea\n ref={searchInputRef}\n value={searchQuery}\n onChange={(e) => dispatch(setSearchQuery(e.target.value))}\n onKeyDown={(e) => {\n if (e.key === 'Escape') {\n const el = editorRef?.current;\n if (el) {\n el.focus();\n }\n dispatch(setSearchQuery(undefined));\n }\n if (e.key === 'f' && (e.ctrlKey || e.metaKey)) {\n e.preventDefault();\n return false;\n }\n if (e.key === 'Enter') {\n dispatch(search(e.shiftKey ? -1 : 1));\n e.preventDefault();\n return false;\n }\n return true;\n }}\n ></textarea>\n <div className={`gs-search-casesensitive`}>\n <span\n className={`${searchCaseSensitive ? 'gs-search-casesensitive-on' : ''}`}\n onClick={() => dispatch(setSearchCaseSensitive(!searchCaseSensitive))}\n >\n Aa\n </span>\n </div>\n <a\n className=\"gs-search-close\"\n onClick={() => {\n dispatch(setSearchQuery(undefined));\n editorRef.current?.focus();\n }}\n >\n <CloseIcon style={{ verticalAlign: 'middle' }} />\n </a>\n </label>\n );\n};\n"],"names":["React"],"mappings":";;;;;;;;AASO,MAAM,YAAsB,MAAM;AACvC,QAAM,EAAE,OAAO,SAAA,IAAaA,eAAM,WAAW,OAAO;AAC9C,QAAA;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,IACE;AAEE,QAAA,eAAe,cAAc,iBAAiB;AACpDA,iBAAM,UAAU,MAAM;AACpB,QAAI,CAAC,cAAc;AACjB;AAAA,IAAA;AAEI,UAAA,QAAQ,IAAI,YAAY;AAC1B,QAAA,OAAO,UAAU,aAAa;AAChC;AAAA,IAAA;AAEU,gBAAA,OAAO,WAAW,SAAS,KAAK;AAAA,EAC3C,GAAA,CAAC,aAAa,mBAAmB,mBAAmB,CAAC;AAEpD,MAAA,OAAO,gBAAgB,aAAa;AAC/B,WAAA;AAAA,EAAA;AAEL,MAAA,QAAQ,YAAY,MAAM;AACrB,WAAA;AAAA,EAAA;AAGP,SAAA,qBAAC,WAAM,WAAW,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,uBAAuB,CAAC,mBAAmB,CAAC;AAAA,QACrE,UAAA;AAAA,MAAA;AAAA,IAAA,GAGH;AAAA,IACA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,WAAU;AAAA,QACV,SAAS,MAAM;;AACJ,mBAAA,eAAe,MAAS,CAAC;AAClC,0BAAU,YAAV,mBAAmB;AAAA,QACrB;AAAA,QAEA,8BAAC,WAAU,EAAA,OAAO,EAAE,eAAe,WAAY,CAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EACjD,GACF;AAEJ;"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import React__default from "react";
|
|
3
|
+
const SheetContext = React__default.createContext({});
|
|
4
|
+
function useSheetContext() {
|
|
5
|
+
var _a;
|
|
6
|
+
const ctx = React__default.useContext(SheetContext);
|
|
7
|
+
if (((_a = ctx.tables) == null ? void 0 : _a.current) == null) {
|
|
8
|
+
return [false, ctx];
|
|
9
|
+
}
|
|
10
|
+
return [true, ctx];
|
|
11
|
+
}
|
|
12
|
+
function SheetProvider({ children }) {
|
|
13
|
+
const [mounted, setMounted] = React__default.useState(false);
|
|
14
|
+
const [version, setVersion] = React__default.useState(0);
|
|
15
|
+
const head = React__default.useRef(1);
|
|
16
|
+
const sheets = React__default.useRef({});
|
|
17
|
+
const tables = React__default.useRef({});
|
|
18
|
+
const [editingCell, setEditingCell] = React__default.useState("");
|
|
19
|
+
const [externalRefs, setExternalRefs] = React__default.useState({});
|
|
20
|
+
const lastFocusedRefInitial = React__default.useRef(null);
|
|
21
|
+
const [lastFocusedRef, setLastFocusedRef] = React__default.useState(lastFocusedRefInitial);
|
|
22
|
+
React__default.useEffect(() => {
|
|
23
|
+
setMounted(true);
|
|
24
|
+
}, []);
|
|
25
|
+
return /* @__PURE__ */ jsx(
|
|
26
|
+
SheetContext.Provider,
|
|
27
|
+
{
|
|
28
|
+
value: {
|
|
29
|
+
mounted,
|
|
30
|
+
tables,
|
|
31
|
+
sheets,
|
|
32
|
+
head,
|
|
33
|
+
editingCell,
|
|
34
|
+
setEditingCell,
|
|
35
|
+
externalRefs,
|
|
36
|
+
setExternalRefs,
|
|
37
|
+
lastFocusedRef,
|
|
38
|
+
setLastFocusedRef,
|
|
39
|
+
forceRender: () => {
|
|
40
|
+
if (version >= Number.MAX_SAFE_INTEGER) {
|
|
41
|
+
setVersion(0);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
setVersion(version + 1);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
children
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
SheetContext,
|
|
53
|
+
SheetProvider,
|
|
54
|
+
useSheetContext
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=SheetProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SheetProvider.js","sources":["../../components/SheetProvider.tsx"],"sourcesContent":["import React from 'react';\n\nimport { RefPaletteType, SheetMapType, TableMapType } from '../types';\n\nexport type SheetContextType = {\n mounted: boolean;\n sheets: React.MutableRefObject<SheetMapType>;\n tables: React.MutableRefObject<TableMapType>;\n head: React.MutableRefObject<number>;\n editingCell: string;\n setEditingCell: (cell: string) => void;\n externalRefs?: { [sheetName: string]: RefPaletteType };\n setExternalRefs?: (refs: { [sheetName: string]: RefPaletteType }) => void;\n lastFocusedRef: React.MutableRefObject<HTMLTextAreaElement | null>;\n setLastFocusedRef: (ref: React.MutableRefObject<HTMLTextAreaElement | null>) => void;\n forceRender: () => void;\n};\n\nexport const SheetContext = React.createContext({} as SheetContextType);\n\nexport function useSheetContext(): [boolean, SheetContextType] {\n const ctx = React.useContext(SheetContext);\n if (ctx.tables?.current == null) {\n return [false, ctx];\n }\n return [true, ctx];\n}\n\nexport function useSheetDispatch() {\n const dispatch = React.useContext(SheetContext);\n if (!dispatch) {\n return undefined;\n }\n return dispatch;\n}\n\ntype Props = {\n children: React.ReactNode;\n};\n\nexport function SheetProvider({ children }: Props) {\n const [mounted, setMounted] = React.useState(false);\n const [version, setVersion] = React.useState(0);\n const head = React.useRef(1);\n const sheets = React.useRef<SheetMapType>({});\n const tables = React.useRef<TableMapType>({});\n const [editingCell, setEditingCell] = React.useState('');\n const [externalRefs, setExternalRefs] = React.useState<{ [sheetName: string]: RefPaletteType }>({});\n const lastFocusedRefInitial = React.useRef<HTMLTextAreaElement | null>(null);\n const [lastFocusedRef, setLastFocusedRef] = React.useState(lastFocusedRefInitial);\n\n React.useEffect(() => {\n setMounted(true);\n }, []);\n\n return (\n <SheetContext.Provider\n value={{\n mounted,\n tables,\n sheets,\n head,\n editingCell,\n setEditingCell,\n externalRefs,\n setExternalRefs,\n lastFocusedRef,\n setLastFocusedRef,\n forceRender: () => {\n if (version >= Number.MAX_SAFE_INTEGER) {\n setVersion(0);\n return;\n }\n setVersion(version + 1);\n },\n }}\n >\n {children}\n </SheetContext.Provider>\n );\n}\n"],"names":["React"],"mappings":";;AAkBO,MAAM,eAAeA,eAAM,cAAc,CAAsB,CAAA;AAE/D,SAAS,kBAA+C;;AACvD,QAAA,MAAMA,eAAM,WAAW,YAAY;AACrC,QAAA,SAAI,WAAJ,mBAAY,YAAW,MAAM;AACxB,WAAA,CAAC,OAAO,GAAG;AAAA,EAAA;AAEb,SAAA,CAAC,MAAM,GAAG;AACnB;AAcgB,SAAA,cAAc,EAAE,YAAmB;AACjD,QAAM,CAAC,SAAS,UAAU,IAAIA,eAAM,SAAS,KAAK;AAClD,QAAM,CAAC,SAAS,UAAU,IAAIA,eAAM,SAAS,CAAC;AACxC,QAAA,OAAOA,eAAM,OAAO,CAAC;AAC3B,QAAM,SAASA,eAAM,OAAqB,EAAE;AAC5C,QAAM,SAASA,eAAM,OAAqB,EAAE;AAC5C,QAAM,CAAC,aAAa,cAAc,IAAIA,eAAM,SAAS,EAAE;AACvD,QAAM,CAAC,cAAc,eAAe,IAAIA,eAAM,SAAkD,CAAA,CAAE;AAC5F,QAAA,wBAAwBA,eAAM,OAAmC,IAAI;AAC3E,QAAM,CAAC,gBAAgB,iBAAiB,IAAIA,eAAM,SAAS,qBAAqB;AAEhFA,iBAAM,UAAU,MAAM;AACpB,eAAW,IAAI;AAAA,EACjB,GAAG,EAAE;AAGH,SAAA;AAAA,IAAC,aAAa;AAAA,IAAb;AAAA,MACC,OAAO;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,aAAa,MAAM;AACb,cAAA,WAAW,OAAO,kBAAkB;AACtC,uBAAW,CAAC;AACZ;AAAA,UAAA;AAEF,qBAAW,UAAU,CAAC;AAAA,QAAA;AAAA,MAE1B;AAAA,MAEC;AAAA,IAAA;AAAA,EACH;AAEJ;"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import React__default from "react";
|
|
3
|
+
import { Context } from "../store/index.js";
|
|
4
|
+
import { initializeTable, setSheetHeight, setSheetWidth, setHeaderHeight, setHeaderWidth, setEditingOnEnter, setShowAddress, setMode, setOnSave } from "../store/actions.js";
|
|
5
|
+
import { HEADER_HEIGHT, HEADER_WIDTH } from "../constants.js";
|
|
6
|
+
import { useSheetContext } from "./SheetProvider.js";
|
|
7
|
+
import { usePluginContext } from "./PluginBase.js";
|
|
8
|
+
const StoreInitializer = ({ options = {} }) => {
|
|
9
|
+
const {
|
|
10
|
+
headerHeight = HEADER_HEIGHT,
|
|
11
|
+
headerWidth = HEADER_WIDTH,
|
|
12
|
+
sheetHeight,
|
|
13
|
+
sheetWidth,
|
|
14
|
+
editingOnEnter,
|
|
15
|
+
showAddress,
|
|
16
|
+
mode,
|
|
17
|
+
onSave
|
|
18
|
+
} = options;
|
|
19
|
+
const [sheetProvided, sheetContext] = useSheetContext();
|
|
20
|
+
const { store, dispatch } = React__default.useContext(Context);
|
|
21
|
+
React__default.useEffect(() => {
|
|
22
|
+
const { table, tableInitialized } = store;
|
|
23
|
+
if (table == null || tableInitialized) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (!sheetProvided || sheetContext.mounted) {
|
|
27
|
+
table.absolutizeFormula();
|
|
28
|
+
dispatch(initializeTable(table.shallowCopy()));
|
|
29
|
+
}
|
|
30
|
+
}, [sheetContext.mounted]);
|
|
31
|
+
React__default.useEffect(() => {
|
|
32
|
+
if (sheetHeight) {
|
|
33
|
+
dispatch(setSheetHeight(sheetHeight));
|
|
34
|
+
}
|
|
35
|
+
}, [sheetHeight]);
|
|
36
|
+
React__default.useEffect(() => {
|
|
37
|
+
if (sheetWidth) {
|
|
38
|
+
dispatch(setSheetWidth(sheetWidth));
|
|
39
|
+
}
|
|
40
|
+
}, [sheetWidth]);
|
|
41
|
+
React__default.useEffect(() => {
|
|
42
|
+
if (headerHeight) {
|
|
43
|
+
dispatch(setHeaderHeight(headerHeight));
|
|
44
|
+
}
|
|
45
|
+
}, [headerHeight]);
|
|
46
|
+
React__default.useEffect(() => {
|
|
47
|
+
if (headerWidth) {
|
|
48
|
+
dispatch(setHeaderWidth(headerWidth));
|
|
49
|
+
}
|
|
50
|
+
}, [headerWidth]);
|
|
51
|
+
React__default.useEffect(() => {
|
|
52
|
+
if (typeof editingOnEnter !== "undefined") {
|
|
53
|
+
dispatch(setEditingOnEnter(editingOnEnter));
|
|
54
|
+
}
|
|
55
|
+
}, [editingOnEnter]);
|
|
56
|
+
React__default.useEffect(() => {
|
|
57
|
+
if (typeof showAddress !== "undefined") {
|
|
58
|
+
dispatch(setShowAddress(showAddress));
|
|
59
|
+
}
|
|
60
|
+
}, [showAddress]);
|
|
61
|
+
React__default.useEffect(() => {
|
|
62
|
+
if (mode) {
|
|
63
|
+
dispatch(setMode(mode));
|
|
64
|
+
}
|
|
65
|
+
}, [mode]);
|
|
66
|
+
React__default.useEffect(() => {
|
|
67
|
+
if (typeof onSave !== "undefined") {
|
|
68
|
+
dispatch(setOnSave(onSave));
|
|
69
|
+
}
|
|
70
|
+
}, [onSave]);
|
|
71
|
+
const [pluginProvided, pluginContext] = usePluginContext();
|
|
72
|
+
React__default.useEffect(() => {
|
|
73
|
+
if (!pluginProvided) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
pluginContext.setStore(store);
|
|
77
|
+
pluginContext.setDispatch(() => dispatch);
|
|
78
|
+
}, [store, dispatch]);
|
|
79
|
+
return /* @__PURE__ */ jsx(Fragment, {});
|
|
80
|
+
};
|
|
81
|
+
export {
|
|
82
|
+
StoreInitializer
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=StoreInitializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StoreInitializer.js","sources":["../../components/StoreInitializer.tsx"],"sourcesContent":["import React from 'react';\n\nimport { Props } from '../types';\n\nimport { Context } from '../store';\nimport {\n setSheetHeight,\n setSheetWidth,\n setHeaderHeight,\n setHeaderWidth,\n setEditingOnEnter,\n setShowAddress,\n setOnSave,\n initializeTable,\n setMode,\n} from '../store/actions';\n\nimport { HEADER_HEIGHT, HEADER_WIDTH } from '../constants';\nimport { useSheetContext } from './SheetProvider';\nimport { usePluginContext } from './PluginBase';\n\nexport const StoreInitializer: React.FC<Props> = ({ options = {} }) => {\n const {\n headerHeight = HEADER_HEIGHT,\n headerWidth = HEADER_WIDTH,\n sheetHeight,\n sheetWidth,\n editingOnEnter,\n showAddress,\n mode,\n onSave,\n } = options;\n\n const [sheetProvided, sheetContext] = useSheetContext();\n const { store, dispatch } = React.useContext(Context);\n\n React.useEffect(() => {\n const { table, tableInitialized } = store;\n if (table == null || tableInitialized) {\n return;\n }\n\n if (!sheetProvided || sheetContext.mounted) {\n table.absolutizeFormula();\n dispatch(initializeTable(table.shallowCopy()));\n }\n }, [sheetContext.mounted]);\n\n React.useEffect(() => {\n if (sheetHeight) {\n dispatch(setSheetHeight(sheetHeight));\n }\n }, [sheetHeight]);\n React.useEffect(() => {\n if (sheetWidth) {\n dispatch(setSheetWidth(sheetWidth));\n }\n }, [sheetWidth]);\n React.useEffect(() => {\n if (headerHeight) {\n dispatch(setHeaderHeight(headerHeight));\n }\n }, [headerHeight]);\n React.useEffect(() => {\n if (headerWidth) {\n dispatch(setHeaderWidth(headerWidth));\n }\n }, [headerWidth]);\n React.useEffect(() => {\n if (typeof editingOnEnter !== 'undefined') {\n dispatch(setEditingOnEnter(editingOnEnter));\n }\n }, [editingOnEnter]);\n React.useEffect(() => {\n if (typeof showAddress !== 'undefined') {\n dispatch(setShowAddress(showAddress));\n }\n }, [showAddress]);\n\n React.useEffect(() => {\n if (mode) {\n dispatch(setMode(mode));\n }\n }, [mode]);\n\n React.useEffect(() => {\n if (typeof onSave !== 'undefined') {\n dispatch(setOnSave(onSave));\n }\n }, [onSave]);\n\n const [pluginProvided, pluginContext] = usePluginContext();\n React.useEffect(() => {\n if (!pluginProvided) {\n return;\n }\n pluginContext.setStore(store);\n pluginContext.setDispatch(() => dispatch);\n }, [store, dispatch]);\n\n return <></>;\n};\n"],"names":["React"],"mappings":";;;;;;;AAqBO,MAAM,mBAAoC,CAAC,EAAE,UAAU,CAAA,QAAS;AAC/D,QAAA;AAAA,IACJ,eAAe;AAAA,IACf,cAAc;AAAA,IACd;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,IACE;AAEJ,QAAM,CAAC,eAAe,YAAY,IAAI,gBAAgB;AACtD,QAAM,EAAE,OAAO,SAAA,IAAaA,eAAM,WAAW,OAAO;AAEpDA,iBAAM,UAAU,MAAM;AACd,UAAA,EAAE,OAAO,iBAAA,IAAqB;AAChC,QAAA,SAAS,QAAQ,kBAAkB;AACrC;AAAA,IAAA;AAGE,QAAA,CAAC,iBAAiB,aAAa,SAAS;AAC1C,YAAM,kBAAkB;AACxB,eAAS,gBAAgB,MAAM,YAAa,CAAA,CAAC;AAAA,IAAA;AAAA,EAC/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