@gridsheet/react-core 1.4.0-alpha.8 → 1.4.0
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.d.ts.map +1 -1
- package/dist/components/Cell.js +3 -1
- package/dist/components/Cell.js.map +1 -1
- package/dist/components/Editor.d.ts +2 -1
- package/dist/components/Editor.d.ts.map +1 -1
- package/dist/components/Editor.js +13 -4
- package/dist/components/Editor.js.map +1 -1
- package/dist/components/FormulaBar.d.ts.map +1 -1
- package/dist/components/FormulaBar.js +4 -3
- package/dist/components/FormulaBar.js.map +1 -1
- package/dist/components/GridSheet.d.ts.map +1 -1
- package/dist/components/GridSheet.js +3 -2
- package/dist/components/GridSheet.js.map +1 -1
- package/dist/components/SheetProvider.d.ts +2 -0
- package/dist/components/SheetProvider.d.ts.map +1 -1
- package/dist/components/SheetProvider.js +3 -0
- package/dist/components/SheetProvider.js.map +1 -1
- package/dist/components/Tabular.d.ts.map +1 -1
- package/dist/components/Tabular.js +38 -29
- package/dist/components/Tabular.js.map +1 -1
- package/dist/formula/evaluator.d.ts +10 -3
- package/dist/formula/evaluator.d.ts.map +1 -1
- package/dist/formula/evaluator.js +11 -6
- package/dist/formula/evaluator.js.map +1 -1
- package/dist/formula/functions/__base.d.ts +4 -1
- package/dist/formula/functions/__base.d.ts.map +1 -1
- package/dist/formula/functions/__base.js +2 -1
- package/dist/formula/functions/__base.js.map +1 -1
- package/dist/formula/functions/__utils.js +1 -1
- package/dist/formula/functions/add.js +5 -5
- package/dist/formula/functions/add.js.map +1 -1
- package/dist/formula/functions/col.d.ts +1 -2
- package/dist/formula/functions/col.d.ts.map +1 -1
- package/dist/formula/functions/col.js +8 -5
- package/dist/formula/functions/col.js.map +1 -1
- package/dist/formula/functions/col.spec.d.ts +2 -0
- package/dist/formula/functions/col.spec.d.ts.map +1 -0
- package/dist/formula/functions/minus.js +5 -5
- package/dist/formula/functions/minus.js.map +1 -1
- package/dist/formula/functions/row.d.ts +1 -2
- package/dist/formula/functions/row.d.ts.map +1 -1
- package/dist/formula/functions/row.js +8 -5
- package/dist/formula/functions/row.js.map +1 -1
- package/dist/formula/functions/row.spec.d.ts +2 -0
- package/dist/formula/functions/row.spec.d.ts.map +1 -0
- package/dist/formula/mapping.d.ts.map +1 -1
- package/dist/formula/mapping.js +1 -0
- package/dist/formula/mapping.js.map +1 -1
- package/dist/formula/solver.d.ts +3 -2
- package/dist/formula/solver.d.ts.map +1 -1
- package/dist/formula/solver.js +3 -3
- package/dist/formula/solver.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/lib/autofill.js +1 -1
- package/dist/lib/clipboard.d.ts.map +1 -1
- package/dist/lib/clipboard.js +28 -2
- package/dist/lib/clipboard.js.map +1 -1
- package/dist/lib/table.d.ts +2 -1
- package/dist/lib/table.d.ts.map +1 -1
- package/dist/lib/table.js +21 -10
- package/dist/lib/table.js.map +1 -1
- package/dist/lib/time.d.ts +7 -1
- package/dist/lib/time.d.ts.map +1 -1
- package/dist/lib/time.js +95 -4
- package/dist/lib/time.js.map +1 -1
- 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.d.ts.map +1 -1
- package/dist/parsers/core.js +4 -32
- package/dist/parsers/core.js.map +1 -1
- package/dist/renderers/core.d.ts +24 -21
- package/dist/renderers/core.d.ts.map +1 -1
- package/dist/renderers/core.js +35 -47
- package/dist/renderers/core.js.map +1 -1
- package/dist/store/actions.d.ts.map +1 -1
- package/dist/store/actions.js.map +1 -1
- package/dist/types.d.ts +5 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
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":";"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Cell.d.ts","sourceRoot":"","sources":["../../components/Cell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAwB1B,KAAK,KAAK,GAAG;IACX,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,cAAc,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CACtC,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,
|
|
1
|
+
{"version":3,"file":"Cell.d.ts","sourceRoot":"","sources":["../../components/Cell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAwB1B,KAAK,KAAK,GAAG;IACX,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,cAAc,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CACtC,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAoO/B,CAAC"}
|
package/dist/components/Cell.js
CHANGED
|
@@ -33,6 +33,7 @@ const Cell = React__default.memo(({ y, x, operationStyle }) => {
|
|
|
33
33
|
const lastFocusedRef = (sheetContext == null ? void 0 : sheetContext.lastFocusedRef) || store.lastFocusedRef;
|
|
34
34
|
const selectingArea = zoneToArea(selectingZone);
|
|
35
35
|
const editing = editingCell === address;
|
|
36
|
+
const xEditing = !sheetProvided || (sheetContext == null ? void 0 : sheetContext.editingCell) === (sheetContext == null ? void 0 : sheetContext.choosingCell);
|
|
36
37
|
const pointed = choosing.y === y && choosing.x === x;
|
|
37
38
|
const _setEditorRect = React__default.useCallback(() => {
|
|
38
39
|
const rect = cellRef.current.getBoundingClientRect();
|
|
@@ -126,6 +127,7 @@ const Cell = React__default.memo(({ y, x, operationStyle }) => {
|
|
|
126
127
|
},
|
|
127
128
|
onDoubleClick: (e) => {
|
|
128
129
|
e.preventDefault();
|
|
130
|
+
setEditingCell(address);
|
|
129
131
|
const dblclick = document.createEvent("MouseEvents");
|
|
130
132
|
dblclick.initEvent("dblclick", true, true);
|
|
131
133
|
input.dispatchEvent(dblclick);
|
|
@@ -139,7 +141,7 @@ const Cell = React__default.memo(({ y, x, operationStyle }) => {
|
|
|
139
141
|
e.dataTransfer.setDragImage(DUMMY_IMG, 0, 0);
|
|
140
142
|
dispatch(select({ startY: y, startX: x, endY: y, endX: x }));
|
|
141
143
|
const insertable = isRefInsertable(lastInput);
|
|
142
|
-
if (insertable) {
|
|
144
|
+
if (insertable && xEditing) {
|
|
143
145
|
return true;
|
|
144
146
|
} else if (insertable != null) {
|
|
145
147
|
writeCell(input.value);
|
|
@@ -1 +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":";;;;;;;;;;;AA8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ACT;AAAA,MAEA,UAAA,qBAAC,OAAI,EAAA,WAAW,sBACd,UAAA;AAAA,QAAA;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,WAAW;AAAA,YACX,OAAO;AAAA,cACL,GAAG,6BAAM;AAAA,cACT,iBAAgB,6BAAM,mBAAkB;AAAA,cACxC,aAAY,6BAAM,eAAc;AAAA,YAClC;AAAA,YAEC,UAAA;AAAA,cAAA,gBAAiB,oBAAA,OAAA,EAAI,WAAU,6BAA4B,OAAO,cAAc;AAAA,cAChF,eAAe,oBAAC,OAAI,EAAA,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;"}
|
|
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 xEditing = !sheetProvided || sheetContext?.editingCell === sheetContext?.choosingCell;\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 setEditingCell(address);\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 && xEditing) {\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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YAAY,GAAG,MAAM,YAAY,CAAC,qBAAqB,CAAC,GAAG,YAAY,OAAO,CAAC;AACrF,kBAAU,WAAW,SAAS;AAC9B,2DAAc,gBAAd;AACO,eAAA;AAAA,MACT;AAAA,MAEA,UAAA,qBAAC,OAAI,EAAA,WAAW,sBACd,UAAA;AAAA,QAAA;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,WAAW;AAAA,YACX,OAAO;AAAA,cACL,GAAG,6BAAM;AAAA,cACT,iBAAgB,6BAAM,mBAAkB;AAAA,cACxC,aAAY,6BAAM,eAAc;AAAA,YAClC;AAAA,YAEC,UAAA;AAAA,cAAA,gBAAiB,oBAAA,OAAA,EAAI,WAAU,6BAA4B,OAAO,cAAc;AAAA,cAChF,eAAe,oBAAC,OAAI,EAAA,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,IA1IK;AAAA,EA2IP;AAEJ,CAAC;"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
|
-
import { ModeType } from '../types';
|
|
2
|
+
import { CursorStateType, ModeType } from '../types';
|
|
3
3
|
type Props = {
|
|
4
4
|
mode: ModeType;
|
|
5
|
+
handleKeyUp?: (e: React.KeyboardEvent<HTMLTextAreaElement>, points: CursorStateType) => void;
|
|
5
6
|
};
|
|
6
7
|
export declare const Editor: React.FC<Props>;
|
|
7
8
|
export declare const editorStyle: (text: string) => React.JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Editor.d.ts","sourceRoot":"","sources":["../../components/Editor.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AA8B1B,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"Editor.d.ts","sourceRoot":"","sources":["../../components/Editor.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AA8B1B,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGrD,KAAK,KAAK,GAAG;IACX,IAAI,EAAE,QAAQ,CAAC;IACf,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,eAAe,KAAK,IAAI,CAAC;CAC9F,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CA4alC,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,sBAuCvC,CAAC"}
|
|
@@ -4,14 +4,14 @@ import { x2c, y2r } from "../lib/converters.js";
|
|
|
4
4
|
import { clip } from "../lib/clipboard.js";
|
|
5
5
|
import { setEditingCell, setInputting, setLastEdited, setLastFocusedRef, redo, undo, cut, paste, setSearchQuery, setEntering, copy, select, arrow, escape, clear, walk, write } from "../store/actions.js";
|
|
6
6
|
import { Context } from "../store/index.js";
|
|
7
|
-
import { areaToZone } from "../lib/structs.js";
|
|
7
|
+
import { zoneToArea, areaToZone } from "../lib/structs.js";
|
|
8
8
|
import { isPrevented, Write } from "../lib/prevention.js";
|
|
9
9
|
import { expandInput, insertTextAtCursor } from "../lib/input.js";
|
|
10
10
|
import { useSheetContext } from "./SheetProvider.js";
|
|
11
11
|
import { Lexer } from "../formula/evaluator.js";
|
|
12
12
|
import { REF_PALETTE } from "../lib/palette.js";
|
|
13
13
|
import { Fixed } from "./Fixed.js";
|
|
14
|
-
const Editor = ({ mode }) => {
|
|
14
|
+
const Editor = ({ mode, handleKeyUp }) => {
|
|
15
15
|
var _a, _b;
|
|
16
16
|
const { store, dispatch } = React__default.useContext(Context);
|
|
17
17
|
const {
|
|
@@ -359,7 +359,7 @@ const Editor = ({ mode }) => {
|
|
|
359
359
|
height: (_a = editorRef.current) == null ? void 0 : _a.scrollHeight,
|
|
360
360
|
width: (((_b = editorRef.current) == null ? void 0 : _b.scrollWidth) ?? 0) - 4
|
|
361
361
|
},
|
|
362
|
-
children: editorStyle(inputting)
|
|
362
|
+
children: (cell == null ? void 0 : cell.disableFormula) ? inputting : editorStyle(inputting)
|
|
363
363
|
}
|
|
364
364
|
),
|
|
365
365
|
/* @__PURE__ */ jsx(
|
|
@@ -411,7 +411,16 @@ const Editor = ({ mode }) => {
|
|
|
411
411
|
expandInput(input);
|
|
412
412
|
dispatch(setInputting(e.currentTarget.value));
|
|
413
413
|
},
|
|
414
|
-
onKeyDown: handleKeyDown
|
|
414
|
+
onKeyDown: handleKeyDown,
|
|
415
|
+
onKeyUp: (e) => {
|
|
416
|
+
e.currentTarget;
|
|
417
|
+
const selectingArea = zoneToArea(store.selectingZone);
|
|
418
|
+
handleKeyUp == null ? void 0 : handleKeyUp(e, {
|
|
419
|
+
pointing: choosing,
|
|
420
|
+
selectingFrom: { y: selectingArea.top, x: selectingArea.left },
|
|
421
|
+
selectingTo: { y: selectingArea.bottom, x: selectingArea.right }
|
|
422
|
+
});
|
|
423
|
+
}
|
|
415
424
|
}
|
|
416
425
|
)
|
|
417
426
|
] })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Editor.js","sources":["../../components/Editor.tsx"],"sourcesContent":["import React from 'react';\nimport { x2c, y2r } from '../lib/converters';\nimport { clip } from '../lib/clipboard';\nimport {\n clear,\n escape,\n select,\n setEditingCell,\n undo,\n redo,\n arrow,\n walk,\n write,\n copy,\n cut,\n paste,\n setSearchQuery,\n setEntering,\n setLastEdited,\n setLastFocusedRef,\n setInputting,\n} from '../store/actions';\n\nimport { Context } from '../store';\nimport { areaToZone } from '../lib/structs';\nimport * as prevention from '../lib/prevention';\nimport { expandInput, insertTextAtCursor } from '../lib/input';\nimport { useSheetContext } from './SheetProvider';\nimport { Lexer } from '../formula/evaluator';\nimport { REF_PALETTE } from '../lib/palette';\nimport { ModeType } from '../types';\nimport { Fixed } from './Fixed';\n\ntype Props = {\n mode: ModeType;\n};\n\nexport const Editor: React.FC<Props> = ({ mode }: Props) => {\n const { store, dispatch } = React.useContext(Context);\n const {\n showAddress,\n editorRect,\n editingCell,\n choosing,\n inputting,\n selectingZone,\n searchQuery,\n editorRef,\n largeEditorRef,\n searchInputRef,\n editingOnEnter,\n onSave,\n table,\n sheetId,\n } = store;\n\n const [, sheetContext] = useSheetContext();\n React.useEffect(() => {\n editorRef?.current?.focus?.({ preventScroll: true });\n }, [editorRef]);\n\n React.useEffect(() => {\n if (!sheetContext?.lastFocusedRef) {\n return;\n }\n if (sheetContext.lastFocusedRef === editorRef) {\n return;\n }\n if (sheetContext.lastFocusedRef === largeEditorRef) {\n return;\n }\n dispatch(setEditingCell(''));\n }, [sheetContext?.lastFocusedRef]);\n React.useEffect(() => {\n sheetContext?.setEditingCell?.(editingCell);\n }, [editingCell]);\n\n const { y, x } = choosing;\n const rowId = `${y2r(y)}`;\n const colId = x2c(x);\n const address = `${colId}${rowId}`;\n const editing = editingCell === address;\n\n const cell = table.getByPoint({ y, x });\n const value: any = cell?.value;\n const valueString = table.stringify({ y, x }, value);\n const [before, setBefore] = React.useState<string>(valueString);\n React.useEffect(() => {\n setBefore(valueString);\n }, [choosing]);\n\n const { y: top, x: left, height, width } = editorRect;\n\n const writeCell = (value: string) => {\n if (before !== value) {\n dispatch(write(value));\n }\n setBefore(value);\n };\n\n const numLines = valueString.split('\\n').length;\n const [isKeyDown, setIsKeyDown] = React.useState(false);\n const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {\n if (isKeyDown) {\n return;\n }\n // do not debounce it if control key is down.\n if (!(e.key === 'Meta' || e.key === 'Control')) {\n setIsKeyDown(true);\n const timeout = window.setTimeout(() => {\n setIsKeyDown(false);\n window.clearTimeout(timeout);\n }, 10);\n }\n const input = e.currentTarget;\n\n const shiftKey = e.shiftKey;\n switch (e.key) {\n case 'Tab': // TAB\n e.preventDefault();\n if (editing) {\n writeCell(input.value);\n dispatch(setEditingCell(''));\n dispatch(setInputting(''));\n }\n dispatch(\n walk({\n numRows: table.getNumRows(),\n numCols: table.getNumCols(),\n deltaY: 0,\n deltaX: shiftKey ? -1 : 1,\n }),\n );\n dispatch(setEditingCell(''));\n resetSize(e.currentTarget);\n return false;\n\n case 'Enter': // ENTER\n if (editing) {\n if (e.altKey) {\n insertTextAtCursor(input, '\\n');\n dispatch(setInputting(input.value));\n e.preventDefault();\n return false;\n } else {\n if (e.nativeEvent.isComposing) {\n return false;\n }\n writeCell(input.value);\n dispatch(setEditingCell(''));\n }\n resetSize(e.currentTarget);\n } else if (editingOnEnter && selectingZone.endY === -1) {\n const dblclick = document.createEvent('MouseEvents');\n dblclick.initEvent('dblclick', true, true);\n input.dispatchEvent(dblclick);\n e.preventDefault();\n return false;\n }\n dispatch(\n walk({\n numRows: table.getNumRows(),\n numCols: table.getNumCols(),\n deltaY: shiftKey ? -1 : 1,\n deltaX: 0,\n }),\n );\n e.preventDefault();\n return false;\n\n case 'Backspace': // BACKSPACE\n if (!editing) {\n dispatch(clear(null));\n return false;\n }\n break;\n case 'Shift': // SHIFT\n return false;\n\n case 'Control': // CTRL\n return false;\n\n case 'Alt': // OPTION\n return false;\n\n case 'Meta': // COMMAND\n return false;\n\n case 'NumLock': // NUMLOCK\n return false;\n\n case 'Escape': // ESCAPE\n dispatch(escape(null));\n dispatch(setSearchQuery(undefined));\n // input.blur();\n return false;\n\n case 'ArrowLeft': // LEFT\n if (!editing) {\n dispatch(\n arrow({\n shiftKey,\n numRows: table.getNumRows(),\n numCols: table.getNumCols(),\n deltaY: 0,\n deltaX: -1,\n }),\n );\n return false;\n }\n break;\n case 'ArrowUp': // UP\n if (!editing) {\n dispatch(\n arrow({\n shiftKey,\n numRows: table.getNumRows(),\n numCols: table.getNumCols(),\n deltaY: -1,\n deltaX: 0,\n }),\n );\n return false;\n }\n break;\n case 'ArrowRight': // RIGHT\n if (!editing) {\n dispatch(\n arrow({\n shiftKey,\n numRows: table.getNumRows(),\n numCols: table.getNumCols(),\n deltaY: 0,\n deltaX: 1,\n }),\n );\n return false;\n }\n break;\n case 'ArrowDown': // DOWN\n if (!editing) {\n dispatch(\n arrow({\n shiftKey,\n numRows: table.getNumRows(),\n numCols: table.getNumCols(),\n deltaY: 1,\n deltaX: 0,\n }),\n );\n return false;\n }\n break;\n case 'a': // A\n if (e.ctrlKey || e.metaKey) {\n if (!editing) {\n e.preventDefault();\n dispatch(\n select({\n startY: 1,\n startX: 1,\n endY: table.getNumRows(),\n endX: table.getNumCols(),\n }),\n );\n return false;\n }\n }\n break;\n case 'c': // C\n if (e.ctrlKey || e.metaKey) {\n if (!editing) {\n e.preventDefault();\n const area = clip(store);\n dispatch(copy(areaToZone(area)));\n input.focus(); // refocus\n return false;\n }\n }\n break;\n case 'f': // F\n if (e.ctrlKey || e.metaKey) {\n if (!editing) {\n e.preventDefault();\n if (typeof searchQuery === 'undefined') {\n dispatch(setSearchQuery(''));\n }\n dispatch(setEntering(false));\n window.setTimeout(() => searchInputRef.current!.focus(), 100);\n return false;\n }\n }\n break;\n case 'r': // R\n if (e.ctrlKey || e.metaKey) {\n if (!editing) {\n e.preventDefault();\n dispatch(redo(null));\n window.setTimeout(() => dispatch(setInputting('')), 100); // resetting textarea\n return false;\n }\n }\n break;\n case 's': // S\n if (e.ctrlKey || e.metaKey) {\n if (!editing) {\n e.preventDefault();\n onSave &&\n onSave(table, {\n pointing: choosing,\n selectingFrom: {\n y: selectingZone.startY,\n x: selectingZone.startX,\n },\n selectingTo: {\n y: selectingZone.endY,\n x: selectingZone.endX,\n },\n });\n return false;\n }\n }\n break;\n case 'v': // V\n if (e.ctrlKey || e.metaKey) {\n if (!editing) {\n window.setTimeout(() => {\n dispatch(paste({ text: input.value }));\n dispatch(setInputting(''));\n }, 50);\n return false;\n }\n }\n break;\n case 'x': // X\n if (e.ctrlKey || e.metaKey) {\n if (!editing) {\n e.preventDefault();\n const area = clip(store);\n dispatch(cut(areaToZone(area)));\n input.focus(); // refocus\n\n return false;\n }\n }\n break;\n case 'z': // Z\n if (e.ctrlKey || e.metaKey) {\n if (!editing) {\n e.preventDefault();\n if (e.shiftKey) {\n dispatch(redo(null));\n //window.setTimeout(() => dispatch(setInputting('')), 100); // resetting textarea\n } else {\n dispatch(undo(null));\n }\n return false;\n }\n }\n break;\n case ';': // semicolon\n if (e.ctrlKey || e.metaKey) {\n if (!editing) {\n e.preventDefault();\n // MAYBE: need to aware timezone.\n writeCell(new Date().toDateString());\n }\n }\n break;\n }\n if (e.ctrlKey || e.metaKey) {\n return false;\n }\n if (prevention.isPrevented(cell?.prevention, prevention.Write)) {\n console.warn('This cell is protected from writing.');\n return false;\n }\n dispatch(setEditingCell(address));\n if (!editing) {\n dispatch(setInputting(''));\n }\n return false;\n };\n\n return (\n <Fixed\n className={`gs-editor ${editing ? 'gs-editing' : ''}`}\n style={editing ? { top, left, height } : {}}\n {...{\n 'data-mode': mode,\n 'data-sheet-id': sheetId,\n }}\n >\n {showAddress && <div className=\"gs-cell-label\">{address}</div>}\n <div className=\"gs-editor-inner\" style={{ width }}>\n <pre\n className=\"gs-editor-hl\"\n style={{\n //...cell?.style,\n height: editorRef.current?.scrollHeight,\n width: (editorRef.current?.scrollWidth ?? 0) - 4,\n }}\n >\n {editorStyle(inputting)}\n </pre>\n <textarea\n autoFocus={true}\n spellCheck={false}\n draggable={false}\n ref={editorRef}\n rows={numLines}\n onFocus={() => {\n dispatch(setLastFocusedRef(editorRef));\n sheetContext?.setLastFocusedRef?.(editorRef);\n }}\n style={{ minWidth: width, minHeight: height }}\n onDoubleClick={(e) => {\n if (prevention.isPrevented(cell?.prevention, prevention.Write)) {\n console.warn('This cell is protected from writing.');\n return;\n }\n const input = e.currentTarget;\n resetSize(input);\n if (!editing) {\n dispatch(setInputting(valueString));\n dispatch(setEditingCell(address));\n window.setTimeout(() => {\n input.style.width = `${input.scrollWidth}px`;\n input.style.height = `${input.scrollHeight}px`;\n const length = new String(valueString).length;\n input.setSelectionRange(length, length);\n }, 20);\n }\n }}\n onBlur={(e) => {\n dispatch(setLastEdited(before));\n if (e.target.value.startsWith('=')) {\n return true;\n } else {\n if (editing) {\n writeCell(e.target.value);\n }\n }\n resetSize(e.target);\n }}\n value={inputting}\n onChange={(e) => {\n const input = e.currentTarget;\n expandInput(input);\n dispatch(setInputting(e.currentTarget.value));\n }}\n onKeyDown={handleKeyDown}\n />\n </div>\n </Fixed>\n );\n};\n\nexport const editorStyle = (text: string) => {\n if (text[0] !== '=') {\n return <>{text}</>;\n }\n const lexer = new Lexer(text.substring(1));\n lexer.tokenize();\n let palletIndex = 0;\n const exists: { [ref: string]: number } = {};\n return (\n <>\n =\n {lexer.tokens.map((token, i) => {\n if (token.type === 'REF' || token.type === 'RANGE') {\n const normalizedToken = token.stringify();\n const existsIndex = exists[normalizedToken];\n if (existsIndex !== undefined) {\n return (\n <span key={i} style={{ color: REF_PALETTE[existsIndex % REF_PALETTE.length] }}>\n {token.stringify()}\n </span>\n );\n }\n const color = REF_PALETTE[palletIndex % REF_PALETTE.length];\n exists[normalizedToken] = palletIndex++;\n return (\n <span key={i} style={{ color }} className={`gs-token-type-${token.type}`}>\n {normalizedToken}\n </span>\n );\n }\n\n return (\n <span key={i} className={`gs-token-type-${token.type} gs-token-entity-type-${typeof token.entity}`}>\n {token.stringify()}\n </span>\n );\n })}\n </>\n );\n};\n\nconst resetSize = (input: HTMLTextAreaElement) => {\n input.style.width = '0px';\n input.style.height = '0px';\n};\n"],"names":["React","_b","_a","value","prevention.isPrevented","prevention.Write"],"mappings":";;;;;;;;;;;;;AAqCO,MAAM,SAA0B,CAAC,EAAE,WAAkB;;AAC1D,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,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,IACE;AAEJ,QAAM,CAAG,EAAA,YAAY,IAAI,gBAAgB;AACzCA,iBAAM,UAAU,MAAM;;AACpB,KAAAC,OAAAC,MAAA,uCAAW,YAAX,gBAAAA,IAAoB,UAApB,gBAAAD,IAAA,KAAAC,KAA4B,EAAE,eAAe;EAAM,GAClD,CAAC,SAAS,CAAC;AAEdF,iBAAM,UAAU,MAAM;AAChB,QAAA,EAAC,6CAAc,iBAAgB;AACjC;AAAA,IAAA;AAEE,QAAA,aAAa,mBAAmB,WAAW;AAC7C;AAAA,IAAA;AAEE,QAAA,aAAa,mBAAmB,gBAAgB;AAClD;AAAA,IAAA;AAEO,aAAA,eAAe,EAAE,CAAC;AAAA,EAAA,GAC1B,CAAC,6CAAc,cAAc,CAAC;AACjCA,iBAAM,UAAU,MAAM;;AACpB,KAAAE,MAAA,6CAAc,mBAAd,gBAAAA,IAAA,mBAA+B;AAAA,EAAW,GACzC,CAAC,WAAW,CAAC;AAEV,QAAA,EAAE,GAAG,EAAA,IAAM;AACjB,QAAM,QAAQ,GAAG,IAAI,CAAC,CAAC;AACjB,QAAA,QAAQ,IAAI,CAAC;AACnB,QAAM,UAAU,GAAG,KAAK,GAAG,KAAK;AAChC,QAAM,UAAU,gBAAgB;AAEhC,QAAM,OAAO,MAAM,WAAW,EAAE,GAAG,GAAG;AACtC,QAAM,QAAa,6BAAM;AACzB,QAAM,c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AAS;AACvB;"}
|
|
1
|
+
{"version":3,"file":"Editor.js","sources":["../../components/Editor.tsx"],"sourcesContent":["import React from 'react';\nimport { x2c, y2r } from '../lib/converters';\nimport { clip } from '../lib/clipboard';\nimport {\n clear,\n escape,\n select,\n setEditingCell,\n undo,\n redo,\n arrow,\n walk,\n write,\n copy,\n cut,\n paste,\n setSearchQuery,\n setEntering,\n setLastEdited,\n setLastFocusedRef,\n setInputting,\n} from '../store/actions';\n\nimport { Context } from '../store';\nimport { areaToZone, zoneToArea } from '../lib/structs';\nimport * as prevention from '../lib/prevention';\nimport { expandInput, insertTextAtCursor } from '../lib/input';\nimport { useSheetContext } from './SheetProvider';\nimport { Lexer } from '../formula/evaluator';\nimport { REF_PALETTE } from '../lib/palette';\nimport { CursorStateType, ModeType } from '../types';\nimport { Fixed } from './Fixed';\n\ntype Props = {\n mode: ModeType;\n handleKeyUp?: (e: React.KeyboardEvent<HTMLTextAreaElement>, points: CursorStateType) => void;\n};\n\nexport const Editor: React.FC<Props> = ({ mode, handleKeyUp }: Props) => {\n const { store, dispatch } = React.useContext(Context);\n const {\n showAddress,\n editorRect,\n editingCell,\n choosing,\n inputting,\n selectingZone,\n searchQuery,\n editorRef,\n largeEditorRef,\n searchInputRef,\n editingOnEnter,\n onSave,\n table,\n sheetId,\n } = store;\n\n const [, sheetContext] = useSheetContext();\n React.useEffect(() => {\n editorRef?.current?.focus?.({ preventScroll: true });\n }, [editorRef]);\n\n React.useEffect(() => {\n if (!sheetContext?.lastFocusedRef) {\n return;\n }\n if (sheetContext.lastFocusedRef === editorRef) {\n return;\n }\n if (sheetContext.lastFocusedRef === largeEditorRef) {\n return;\n }\n dispatch(setEditingCell(''));\n }, [sheetContext?.lastFocusedRef]);\n React.useEffect(() => {\n sheetContext?.setEditingCell?.(editingCell);\n }, [editingCell]);\n\n const { y, x } = choosing;\n const rowId = `${y2r(y)}`;\n const colId = x2c(x);\n const address = `${colId}${rowId}`;\n const editing = editingCell === address;\n\n const cell = table.getByPoint({ y, x });\n const value: any = cell?.value;\n const valueString = table.stringify({ y, x }, value);\n const [before, setBefore] = React.useState<string>(valueString);\n React.useEffect(() => {\n setBefore(valueString);\n }, [choosing]);\n\n const { y: top, x: left, height, width } = editorRect;\n\n const writeCell = (value: string) => {\n if (before !== value) {\n dispatch(write(value));\n }\n setBefore(value);\n };\n\n const numLines = valueString.split('\\n').length;\n const [isKeyDown, setIsKeyDown] = React.useState(false);\n const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {\n if (isKeyDown) {\n return;\n }\n // do not debounce it if control key is down.\n if (!(e.key === 'Meta' || e.key === 'Control')) {\n setIsKeyDown(true);\n const timeout = window.setTimeout(() => {\n setIsKeyDown(false);\n window.clearTimeout(timeout);\n }, 10);\n }\n const input = e.currentTarget;\n\n const shiftKey = e.shiftKey;\n switch (e.key) {\n case 'Tab': // TAB\n e.preventDefault();\n if (editing) {\n writeCell(input.value);\n dispatch(setEditingCell(''));\n dispatch(setInputting(''));\n }\n dispatch(\n walk({\n numRows: table.getNumRows(),\n numCols: table.getNumCols(),\n deltaY: 0,\n deltaX: shiftKey ? -1 : 1,\n }),\n );\n dispatch(setEditingCell(''));\n resetSize(e.currentTarget);\n return false;\n\n case 'Enter': // ENTER\n if (editing) {\n if (e.altKey) {\n insertTextAtCursor(input, '\\n');\n dispatch(setInputting(input.value));\n e.preventDefault();\n return false;\n } else {\n if (e.nativeEvent.isComposing) {\n return false;\n }\n writeCell(input.value);\n dispatch(setEditingCell(''));\n }\n resetSize(e.currentTarget);\n } else if (editingOnEnter && selectingZone.endY === -1) {\n const dblclick = document.createEvent('MouseEvents');\n dblclick.initEvent('dblclick', true, true);\n input.dispatchEvent(dblclick);\n e.preventDefault();\n return false;\n }\n dispatch(\n walk({\n numRows: table.getNumRows(),\n numCols: table.getNumCols(),\n deltaY: shiftKey ? -1 : 1,\n deltaX: 0,\n }),\n );\n e.preventDefault();\n return false;\n\n case 'Backspace': // BACKSPACE\n if (!editing) {\n dispatch(clear(null));\n return false;\n }\n break;\n case 'Shift': // SHIFT\n return false;\n\n case 'Control': // CTRL\n return false;\n\n case 'Alt': // OPTION\n return false;\n\n case 'Meta': // COMMAND\n return false;\n\n case 'NumLock': // NUMLOCK\n return false;\n\n case 'Escape': // ESCAPE\n dispatch(escape(null));\n dispatch(setSearchQuery(undefined));\n // input.blur();\n return false;\n\n case 'ArrowLeft': // LEFT\n if (!editing) {\n dispatch(\n arrow({\n shiftKey,\n numRows: table.getNumRows(),\n numCols: table.getNumCols(),\n deltaY: 0,\n deltaX: -1,\n }),\n );\n return false;\n }\n break;\n case 'ArrowUp': // UP\n if (!editing) {\n dispatch(\n arrow({\n shiftKey,\n numRows: table.getNumRows(),\n numCols: table.getNumCols(),\n deltaY: -1,\n deltaX: 0,\n }),\n );\n return false;\n }\n break;\n case 'ArrowRight': // RIGHT\n if (!editing) {\n dispatch(\n arrow({\n shiftKey,\n numRows: table.getNumRows(),\n numCols: table.getNumCols(),\n deltaY: 0,\n deltaX: 1,\n }),\n );\n return false;\n }\n break;\n case 'ArrowDown': // DOWN\n if (!editing) {\n dispatch(\n arrow({\n shiftKey,\n numRows: table.getNumRows(),\n numCols: table.getNumCols(),\n deltaY: 1,\n deltaX: 0,\n }),\n );\n return false;\n }\n break;\n case 'a': // A\n if (e.ctrlKey || e.metaKey) {\n if (!editing) {\n e.preventDefault();\n dispatch(\n select({\n startY: 1,\n startX: 1,\n endY: table.getNumRows(),\n endX: table.getNumCols(),\n }),\n );\n return false;\n }\n }\n break;\n case 'c': // C\n if (e.ctrlKey || e.metaKey) {\n if (!editing) {\n e.preventDefault();\n const area = clip(store);\n dispatch(copy(areaToZone(area)));\n input.focus(); // refocus\n return false;\n }\n }\n break;\n case 'f': // F\n if (e.ctrlKey || e.metaKey) {\n if (!editing) {\n e.preventDefault();\n if (typeof searchQuery === 'undefined') {\n dispatch(setSearchQuery(''));\n }\n dispatch(setEntering(false));\n window.setTimeout(() => searchInputRef.current!.focus(), 100);\n return false;\n }\n }\n break;\n case 'r': // R\n if (e.ctrlKey || e.metaKey) {\n if (!editing) {\n e.preventDefault();\n dispatch(redo(null));\n window.setTimeout(() => dispatch(setInputting('')), 100); // resetting textarea\n return false;\n }\n }\n break;\n case 's': // S\n if (e.ctrlKey || e.metaKey) {\n if (!editing) {\n e.preventDefault();\n onSave &&\n onSave(table, {\n pointing: choosing,\n selectingFrom: {\n y: selectingZone.startY,\n x: selectingZone.startX,\n },\n selectingTo: {\n y: selectingZone.endY,\n x: selectingZone.endX,\n },\n });\n return false;\n }\n }\n break;\n case 'v': // V\n if (e.ctrlKey || e.metaKey) {\n if (!editing) {\n window.setTimeout(() => {\n dispatch(paste({ text: input.value }));\n dispatch(setInputting(''));\n }, 50);\n return false;\n }\n }\n break;\n case 'x': // X\n if (e.ctrlKey || e.metaKey) {\n if (!editing) {\n e.preventDefault();\n const area = clip(store);\n dispatch(cut(areaToZone(area)));\n input.focus(); // refocus\n\n return false;\n }\n }\n break;\n case 'z': // Z\n if (e.ctrlKey || e.metaKey) {\n if (!editing) {\n e.preventDefault();\n if (e.shiftKey) {\n dispatch(redo(null));\n //window.setTimeout(() => dispatch(setInputting('')), 100); // resetting textarea\n } else {\n dispatch(undo(null));\n }\n return false;\n }\n }\n break;\n case ';': // semicolon\n if (e.ctrlKey || e.metaKey) {\n if (!editing) {\n e.preventDefault();\n // MAYBE: need to aware timezone.\n writeCell(new Date().toDateString());\n }\n }\n break;\n }\n if (e.ctrlKey || e.metaKey) {\n return false;\n }\n if (prevention.isPrevented(cell?.prevention, prevention.Write)) {\n console.warn('This cell is protected from writing.');\n return false;\n }\n dispatch(setEditingCell(address));\n if (!editing) {\n dispatch(setInputting(''));\n }\n return false;\n };\n\n return (\n <Fixed\n className={`gs-editor ${editing ? 'gs-editing' : ''}`}\n style={editing ? { top, left, height } : {}}\n {...{\n 'data-mode': mode,\n 'data-sheet-id': sheetId,\n }}\n >\n {showAddress && <div className=\"gs-cell-label\">{address}</div>}\n <div className=\"gs-editor-inner\" style={{ width }}>\n <pre\n className=\"gs-editor-hl\"\n style={{\n //...cell?.style,\n height: editorRef.current?.scrollHeight,\n width: (editorRef.current?.scrollWidth ?? 0) - 4,\n }}\n >\n {cell?.disableFormula ? inputting : editorStyle(inputting)}\n </pre>\n <textarea\n autoFocus={true}\n spellCheck={false}\n draggable={false}\n ref={editorRef}\n rows={numLines}\n onFocus={() => {\n dispatch(setLastFocusedRef(editorRef));\n sheetContext?.setLastFocusedRef?.(editorRef);\n }}\n style={{ minWidth: width, minHeight: height }}\n onDoubleClick={(e) => {\n if (prevention.isPrevented(cell?.prevention, prevention.Write)) {\n console.warn('This cell is protected from writing.');\n return;\n }\n const input = e.currentTarget;\n resetSize(input);\n if (!editing) {\n dispatch(setInputting(valueString));\n dispatch(setEditingCell(address));\n window.setTimeout(() => {\n input.style.width = `${input.scrollWidth}px`;\n input.style.height = `${input.scrollHeight}px`;\n const length = new String(valueString).length;\n input.setSelectionRange(length, length);\n }, 20);\n }\n }}\n onBlur={(e) => {\n dispatch(setLastEdited(before));\n if (e.target.value.startsWith('=')) {\n return true;\n } else {\n if (editing) {\n writeCell(e.target.value);\n }\n }\n resetSize(e.target);\n }}\n value={inputting}\n onChange={(e) => {\n const input = e.currentTarget;\n expandInput(input);\n dispatch(setInputting(e.currentTarget.value));\n }}\n onKeyDown={handleKeyDown}\n onKeyUp={(e) => {\n const input = e.currentTarget;\n const selectingArea = zoneToArea(store.selectingZone);\n handleKeyUp?.(e, {\n pointing: choosing,\n selectingFrom: { y: selectingArea.top, x: selectingArea.left },\n selectingTo: { y: selectingArea.bottom, x: selectingArea.right },\n });\n }}\n />\n </div>\n </Fixed>\n );\n};\n\nexport const editorStyle = (text: string) => {\n if (text[0] !== '=') {\n return <>{text}</>;\n }\n const lexer = new Lexer(text.substring(1));\n lexer.tokenize();\n let palletIndex = 0;\n const exists: { [ref: string]: number } = {};\n return (\n <>\n =\n {lexer.tokens.map((token, i) => {\n if (token.type === 'REF' || token.type === 'RANGE') {\n const normalizedToken = token.stringify();\n const existsIndex = exists[normalizedToken];\n if (existsIndex !== undefined) {\n return (\n <span key={i} style={{ color: REF_PALETTE[existsIndex % REF_PALETTE.length] }}>\n {token.stringify()}\n </span>\n );\n }\n const color = REF_PALETTE[palletIndex % REF_PALETTE.length];\n exists[normalizedToken] = palletIndex++;\n return (\n <span key={i} style={{ color }} className={`gs-token-type-${token.type}`}>\n {normalizedToken}\n </span>\n );\n }\n\n return (\n <span key={i} className={`gs-token-type-${token.type} gs-token-entity-type-${typeof token.entity}`}>\n {token.stringify()}\n </span>\n );\n })}\n </>\n );\n};\n\nconst resetSize = (input: HTMLTextAreaElement) => {\n input.style.width = '0px';\n input.style.height = '0px';\n};\n"],"names":["React","_b","_a","value","prevention.isPrevented","prevention.Write"],"mappings":";;;;;;;;;;;;;AAsCO,MAAM,SAA0B,CAAC,EAAE,MAAM,kBAAyB;;AACvE,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,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,IACE;AAEJ,QAAM,CAAG,EAAA,YAAY,IAAI,gBAAgB;AACzCA,iBAAM,UAAU,MAAM;;AACpB,KAAAC,OAAAC,MAAA,uCAAW,YAAX,gBAAAA,IAAoB,UAApB,gBAAAD,IAAA,KAAAC,KAA4B,EAAE,eAAe;EAAM,GAClD,CAAC,SAAS,CAAC;AAEdF,iBAAM,UAAU,MAAM;AAChB,QAAA,EAAC,6CAAc,iBAAgB;AACjC;AAAA,IAAA;AAEE,QAAA,aAAa,mBAAmB,WAAW;AAC7C;AAAA,IAAA;AAEE,QAAA,aAAa,mBAAmB,gBAAgB;AAClD;AAAA,IAAA;AAEO,aAAA,eAAe,EAAE,CAAC;AAAA,EAAA,GAC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,MAAM;AAC9B,UAAI,MAAM,SAAS,SAAS,MAAM,SAAS,SAAS;AAC5C,cAAA,kBAAkB,MAAM,UAAU;AAClC,cAAA,cAAc,OAAO,eAAe;AAC1C,YAAI,gBAAgB,QAAW;AAC7B,iBACG,oBAAA,QAAA,EAAa,OAAO,EAAE,OAAO,YAAY,cAAc,YAAY,MAAM,EAAE,GACzE,UAAM,MAAA,UAAA,KADE,CAEX;AAAA,QAAA;AAGJ,cAAM,QAAQ,YAAY,cAAc,YAAY,MAAM;AAC1D,eAAO,eAAe,IAAI;AAC1B,eACG,oBAAA,QAAA,EAAa,OAAO,EAAE,MAAM,GAAG,WAAW,iBAAiB,MAAM,IAAI,IACnE,UAAA,gBAAA,GADQ,CAEX;AAAA,MAAA;AAIJ,aACG,oBAAA,QAAA,EAAa,WAAW,iBAAiB,MAAM,IAAI,yBAAyB,OAAO,MAAM,MAAM,IAC7F,UAAM,MAAA,UAAA,KADE,CAEX;AAAA,IAEH,CAAA;AAAA,EAAA,GACH;AAEJ;AAEA,MAAM,YAAY,CAAC,UAA+B;AAChD,QAAM,MAAM,QAAQ;AACpB,QAAM,MAAM,SAAS;AACvB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormulaBar.d.ts","sourceRoot":"","sources":["../../components/FormulaBar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAS1B,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"FormulaBar.d.ts","sourceRoot":"","sources":["../../components/FormulaBar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAS1B,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EA0I9B,CAAC"}
|
|
@@ -15,6 +15,7 @@ const FormulaBar = () => {
|
|
|
15
15
|
const [, sheetContext] = useSheetContext();
|
|
16
16
|
const hlRef = React__default.useRef(null);
|
|
17
17
|
const address = choosing.x === -1 ? "" : p2a(choosing);
|
|
18
|
+
const cell = table.getByPoint(choosing);
|
|
18
19
|
React__default.useEffect(() => {
|
|
19
20
|
var _a2;
|
|
20
21
|
let value = ((_a2 = table.getByPoint(choosing)) == null ? void 0 : _a2.value) ?? "";
|
|
@@ -76,7 +77,7 @@ const FormulaBar = () => {
|
|
|
76
77
|
height: (_a = largeEditorRef.current) == null ? void 0 : _a.clientHeight,
|
|
77
78
|
width: (_b = largeEditorRef.current) == null ? void 0 : _b.clientWidth
|
|
78
79
|
},
|
|
79
|
-
children: editorStyle(inputting)
|
|
80
|
+
children: (cell == null ? void 0 : cell.disableFormula) ? inputting : editorStyle(inputting)
|
|
80
81
|
}
|
|
81
82
|
),
|
|
82
83
|
/* @__PURE__ */ jsx(
|
|
@@ -128,8 +129,8 @@ const FormulaBar = () => {
|
|
|
128
129
|
break;
|
|
129
130
|
}
|
|
130
131
|
}
|
|
131
|
-
const
|
|
132
|
-
if (isPrevented(
|
|
132
|
+
const cell2 = table.getByPoint(choosing);
|
|
133
|
+
if (isPrevented(cell2 == null ? void 0 : cell2.prevention, Write)) {
|
|
133
134
|
console.warn("This cell is protected from writing.");
|
|
134
135
|
e.preventDefault();
|
|
135
136
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormulaBar.js","sources":["../../components/FormulaBar.tsx"],"sourcesContent":["import React from 'react';\nimport { Context } from '../store';\nimport { p2a } from '../lib/converters';\nimport { setEditingCell, setInputting, setLastEdited, setLastFocusedRef, walk, write } from '../store/actions';\nimport * as prevention from '../lib/prevention';\nimport { insertTextAtCursor } from '../lib/input';\nimport { useSheetContext } from './SheetProvider';\nimport { editorStyle } from './Editor';\n\nexport const FormulaBar: React.FC = () => {\n const { store, dispatch } = React.useContext(Context);\n const [before, setBefore] = React.useState('');\n const { choosing, editorRef, largeEditorRef, table, inputting, editingCell } = store;\n const [, sheetContext] = useSheetContext();\n const hlRef = React.useRef<HTMLDivElement | null>(null);\n\n const address = choosing.x === -1 ? '' : p2a(choosing);\n React.useEffect(() => {\n let value = table.getByPoint(choosing)?.value ?? '';\n // debug to remove this line\n value = table.stringify(choosing, value);\n largeEditorRef.current!.value = value;\n setBefore(value as string);\n }, [address, table]);\n\n const writeCell = (value: string) => {\n if (before !== value) {\n dispatch(write(value));\n }\n dispatch(setEditingCell(''));\n editorRef.current!.focus();\n };\n React.useEffect(() => {\n const observer = new ResizeObserver((entries) => {\n entries.forEach(updateScroll);\n });\n if (largeEditorRef.current) {\n observer.observe(largeEditorRef.current);\n }\n return () => {\n observer.disconnect();\n };\n }, []);\n\n const largeInput = largeEditorRef.current;\n\n const handleFocus = () => {\n if (!largeInput) {\n return;\n }\n dispatch(setEditingCell(address));\n dispatch(setLastFocusedRef(largeEditorRef));\n sheetContext?.setLastFocusedRef?.(largeEditorRef);\n };\n const handleInput = (e: React.FormEvent<HTMLTextAreaElement>) => {\n dispatch(setInputting(e.currentTarget.value));\n sheetContext?.forceRender?.();\n };\n\n const updateScroll = () => {\n if (!hlRef.current || !largeEditorRef.current) {\n return;\n }\n hlRef.current.style.height = `${largeEditorRef.current.clientHeight}px`;\n hlRef.current.scrollLeft = largeEditorRef.current.scrollLeft;\n hlRef.current.scrollTop = largeEditorRef.current.scrollTop;\n };\n\n return (\n <label className=\"gs-formula-bar\">\n <div className=\"gs-selecting-address\">{address}</div>\n <div className=\"gs-fx\">Fx</div>\n <div className=\"gs-formula-bar-editor-inner\">\n <div\n className=\"gs-editor-hl\"\n ref={hlRef}\n style={{\n height: largeEditorRef.current?.clientHeight,\n width: largeEditorRef.current?.clientWidth,\n }}\n >\n {editorStyle(inputting)}\n </div>\n <textarea\n rows={1}\n spellCheck={false}\n ref={largeEditorRef}\n value={inputting}\n onInput={handleInput}\n onFocus={handleFocus}\n onBlur={(e) => {\n dispatch(setLastEdited(before));\n if (e.target.value.startsWith('=')) {\n return true;\n } else {\n if (editingCell) {\n writeCell(e.target.value);\n }\n }\n }}\n onKeyDown={(e) => {\n const input = e.currentTarget;\n switch (e.key) {\n case 'Enter': {\n if (e.altKey) {\n insertTextAtCursor(input, '\\n');\n } else {\n writeCell(input.value);\n dispatch(setInputting(''));\n dispatch(\n walk({\n numRows: table.getNumRows(),\n numCols: table.getNumCols(),\n deltaY: 1,\n deltaX: 0,\n }),\n );\n e.preventDefault();\n return false;\n }\n break;\n }\n case 'Escape': {\n input.value = before;\n dispatch(setEditingCell(''));\n e.preventDefault();\n editorRef.current!.focus();\n\n break;\n }\n }\n\n const cell = table.getByPoint(choosing);\n if (prevention.isPrevented(cell?.prevention, prevention.Write)) {\n console.warn('This cell is protected from writing.');\n e.preventDefault();\n }\n updateScroll();\n return false;\n }}\n onKeyUp={updateScroll}\n onScroll={updateScroll}\n ></textarea>\n </div>\n </label>\n );\n};\n"],"names":["React","_a","prevention.isPrevented","prevention.Write"],"mappings":";;;;;;;;;AASO,MAAM,aAAuB,MAAM;;AACxC,QAAM,EAAE,OAAO,SAAA,IAAaA,eAAM,WAAW,OAAO;AACpD,QAAM,CAAC,QAAQ,SAAS,IAAIA,eAAM,SAAS,EAAE;AAC7C,QAAM,EAAE,UAAU,WAAW,gBAAgB,OAAO,WAAW,gBAAgB;AAC/E,QAAM,CAAG,EAAA,YAAY,IAAI,gBAAgB;AACnC,QAAA,QAAQA,eAAM,OAA8B,IAAI;AAEtD,QAAM,UAAU,SAAS,MAAM,KAAK,KAAK,IAAI,QAAQ;
|
|
1
|
+
{"version":3,"file":"FormulaBar.js","sources":["../../components/FormulaBar.tsx"],"sourcesContent":["import React from 'react';\nimport { Context } from '../store';\nimport { p2a } from '../lib/converters';\nimport { setEditingCell, setInputting, setLastEdited, setLastFocusedRef, walk, write } from '../store/actions';\nimport * as prevention from '../lib/prevention';\nimport { insertTextAtCursor } from '../lib/input';\nimport { useSheetContext } from './SheetProvider';\nimport { editorStyle } from './Editor';\n\nexport const FormulaBar: React.FC = () => {\n const { store, dispatch } = React.useContext(Context);\n const [before, setBefore] = React.useState('');\n const { choosing, editorRef, largeEditorRef, table, inputting, editingCell } = store;\n const [, sheetContext] = useSheetContext();\n const hlRef = React.useRef<HTMLDivElement | null>(null);\n\n const address = choosing.x === -1 ? '' : p2a(choosing);\n const cell = table.getByPoint(choosing);\n React.useEffect(() => {\n let value = table.getByPoint(choosing)?.value ?? '';\n // debug to remove this line\n value = table.stringify(choosing, value);\n largeEditorRef.current!.value = value;\n setBefore(value as string);\n }, [address, table]);\n\n const writeCell = (value: string) => {\n if (before !== value) {\n dispatch(write(value));\n }\n dispatch(setEditingCell(''));\n editorRef.current!.focus();\n };\n React.useEffect(() => {\n const observer = new ResizeObserver((entries) => {\n entries.forEach(updateScroll);\n });\n if (largeEditorRef.current) {\n observer.observe(largeEditorRef.current);\n }\n return () => {\n observer.disconnect();\n };\n }, []);\n\n const largeInput = largeEditorRef.current;\n\n const handleFocus = () => {\n if (!largeInput) {\n return;\n }\n dispatch(setEditingCell(address));\n dispatch(setLastFocusedRef(largeEditorRef));\n sheetContext?.setLastFocusedRef?.(largeEditorRef);\n };\n const handleInput = (e: React.FormEvent<HTMLTextAreaElement>) => {\n dispatch(setInputting(e.currentTarget.value));\n sheetContext?.forceRender?.();\n };\n\n const updateScroll = () => {\n if (!hlRef.current || !largeEditorRef.current) {\n return;\n }\n hlRef.current.style.height = `${largeEditorRef.current.clientHeight}px`;\n hlRef.current.scrollLeft = largeEditorRef.current.scrollLeft;\n hlRef.current.scrollTop = largeEditorRef.current.scrollTop;\n };\n\n return (\n <label className=\"gs-formula-bar\">\n <div className=\"gs-selecting-address\">{address}</div>\n <div className=\"gs-fx\">Fx</div>\n <div className=\"gs-formula-bar-editor-inner\">\n <div\n className=\"gs-editor-hl\"\n ref={hlRef}\n style={{\n height: largeEditorRef.current?.clientHeight,\n width: largeEditorRef.current?.clientWidth,\n }}\n >\n {cell?.disableFormula ? inputting : editorStyle(inputting)}\n </div>\n <textarea\n rows={1}\n spellCheck={false}\n ref={largeEditorRef}\n value={inputting}\n onInput={handleInput}\n onFocus={handleFocus}\n onBlur={(e) => {\n dispatch(setLastEdited(before));\n if (e.target.value.startsWith('=')) {\n return true;\n } else {\n if (editingCell) {\n writeCell(e.target.value);\n }\n }\n }}\n onKeyDown={(e) => {\n const input = e.currentTarget;\n switch (e.key) {\n case 'Enter': {\n if (e.altKey) {\n insertTextAtCursor(input, '\\n');\n } else {\n writeCell(input.value);\n dispatch(setInputting(''));\n dispatch(\n walk({\n numRows: table.getNumRows(),\n numCols: table.getNumCols(),\n deltaY: 1,\n deltaX: 0,\n }),\n );\n e.preventDefault();\n return false;\n }\n break;\n }\n case 'Escape': {\n input.value = before;\n dispatch(setEditingCell(''));\n e.preventDefault();\n editorRef.current!.focus();\n\n break;\n }\n }\n\n const cell = table.getByPoint(choosing);\n if (prevention.isPrevented(cell?.prevention, prevention.Write)) {\n console.warn('This cell is protected from writing.');\n e.preventDefault();\n }\n updateScroll();\n return false;\n }}\n onKeyUp={updateScroll}\n onScroll={updateScroll}\n ></textarea>\n </div>\n </label>\n );\n};\n"],"names":["React","_a","cell","prevention.isPrevented","prevention.Write"],"mappings":";;;;;;;;;AASO,MAAM,aAAuB,MAAM;;AACxC,QAAM,EAAE,OAAO,SAAA,IAAaA,eAAM,WAAW,OAAO;AACpD,QAAM,CAAC,QAAQ,SAAS,IAAIA,eAAM,SAAS,EAAE;AAC7C,QAAM,EAAE,UAAU,WAAW,gBAAgB,OAAO,WAAW,gBAAgB;AAC/E,QAAM,CAAG,EAAA,YAAY,IAAI,gBAAgB;AACnC,QAAA,QAAQA,eAAM,OAA8B,IAAI;AAEtD,QAAM,UAAU,SAAS,MAAM,KAAK,KAAK,IAAI,QAAQ;AAC/C,QAAA,OAAO,MAAM,WAAW,QAAQ;AACtCA,iBAAM,UAAU,MAAM;;AACpB,QAAI,UAAQC,MAAA,MAAM,WAAW,QAAQ,MAAzB,gBAAAA,IAA4B,UAAS;AAEzC,YAAA,MAAM,UAAU,UAAU,KAAK;AACvC,mBAAe,QAAS,QAAQ;AAChC,cAAU,KAAe;AAAA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AAAA,cAAA;AAAA,YACF;AAGIC,kBAAAA,QAAO,MAAM,WAAW,QAAQ;AACtC,gBAAIC,YAAuBD,+BAAM,YAAYE,KAAgB,GAAG;AAC9D,sBAAQ,KAAK,sCAAsC;AACnD,gBAAE,eAAe;AAAA,YAAA;AAEN,yBAAA;AACN,mBAAA;AAAA,UACT;AAAA,UACA,SAAS;AAAA,UACT,UAAU;AAAA,QAAA;AAAA,MAAA;AAAA,IACX,EACH,CAAA;AAAA,EAAA,GACF;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GridSheet.d.ts","sourceRoot":"","sources":["../../components/GridSheet.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAmC,KAAK,EAAa,MAAM,UAAU,CAAC;AA4B7E,wBAAgB,SAAS,CAAC,EACxB,YAAY,EACZ,SAAc,EACd,QAAQ,EACR,OAAY,EACZ,SAAS,EACT,KAAK,EACL,mBAAwB,GACzB,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"GridSheet.d.ts","sourceRoot":"","sources":["../../components/GridSheet.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAmC,KAAK,EAAa,MAAM,UAAU,CAAC;AA4B7E,wBAAgB,SAAS,CAAC,EACxB,YAAY,EACZ,SAAc,EACd,QAAQ,EACR,OAAY,EACZ,SAAS,EACT,KAAK,EACL,mBAAwB,GACzB,EAAE,KAAK,qBAwLP"}
|
|
@@ -60,6 +60,7 @@ function GridSheet({
|
|
|
60
60
|
maxNumCols,
|
|
61
61
|
headerHeight,
|
|
62
62
|
headerWidth,
|
|
63
|
+
sheetName,
|
|
63
64
|
functions: { ...functions, ...additionalFunctions }
|
|
64
65
|
});
|
|
65
66
|
let sheetId = 0;
|
|
@@ -169,7 +170,7 @@ function GridSheet({
|
|
|
169
170
|
setSheetWidth(options.sheetWidth);
|
|
170
171
|
}
|
|
171
172
|
}, [options.sheetWidth]);
|
|
172
|
-
const { onChange, onSelect } = options;
|
|
173
|
+
const { onChange, onSelect, onKeyUp } = options;
|
|
173
174
|
return /* @__PURE__ */ jsx(Context.Provider, { value: { store, dispatch }, children: /* @__PURE__ */ jsxs(
|
|
174
175
|
"div",
|
|
175
176
|
{
|
|
@@ -192,7 +193,7 @@ function GridSheet({
|
|
|
192
193
|
resize: sheetResize
|
|
193
194
|
},
|
|
194
195
|
children: [
|
|
195
|
-
/* @__PURE__ */ jsx(Editor, { mode }),
|
|
196
|
+
/* @__PURE__ */ jsx(Editor, { mode, handleKeyUp: onKeyUp }),
|
|
196
197
|
/* @__PURE__ */ jsx(Tabular, { tableRef }),
|
|
197
198
|
/* @__PURE__ */ jsx(
|
|
198
199
|
StoreInitializer,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GridSheet.js","sources":["../../components/GridSheet.tsx"],"sourcesContent":["import * as React from 'react';\nimport { ReducerWithoutAction } from 'react';\n\nimport { CellsByAddressType, OptionsType, Props, StoreType } from '../types';\nimport {\n DEFAULT_HEIGHT,\n DEFAULT_WIDTH,\n HEADER_HEIGHT,\n HEADER_WIDTH,\n SHEET_HEIGHT,\n SHEET_WIDTH,\n HISTORY_LIMIT,\n} from '../constants';\nimport { functions } from '../formula/mapping';\nimport { Context } from '../store';\nimport { reducer as defaultReducer } from '../store/actions';\n\nimport { Editor } from './Editor';\nimport { StoreInitializer } from './StoreInitializer';\nimport { Resizer } from './Resizer';\nimport { Emitter } from './Emitter';\nimport { ContextMenu } from './ContextMenu';\nimport { Table } from '../lib/table';\nimport { Tabular } from './Tabular';\nimport { getMaxSizesFromCells } from '../lib/structs';\nimport { x2c, y2r } from '../lib/converters';\nimport { embedStyle } from '../styles/embedder';\nimport { useSheetContext } from './SheetProvider';\nimport { FormulaBar } from './FormulaBar';\nimport { SearchBar } from './SearchBar';\n\nexport function GridSheet({\n initialCells,\n sheetName = '',\n tableRef,\n options = {},\n className,\n style,\n additionalFunctions = {},\n}: Props) {\n const { sheetResize, showFormulaBar = true, onInit, mode = 'light' } = options;\n const [prevSheetName, setPrevSheetName] = React.useState(sheetName);\n const rootRef = React.useRef<HTMLDivElement | null>(null);\n const mainRef = React.useRef<HTMLDivElement | null>(null);\n const searchInputRef = React.useRef<HTMLTextAreaElement | null>(null);\n const editorRef = React.useRef<HTMLTextAreaElement | null>(null);\n const largeEditorRef = React.useRef<HTMLTextAreaElement | null>(null);\n const tabularRef = React.useRef<HTMLDivElement | null>(null);\n const lastFocusedRef = React.useRef<HTMLTextAreaElement | null>(null);\n const [sheetProvided, sheetContext] = useSheetContext();\n\n const [initialState] = React.useState<StoreType>(() => {\n const {\n headerHeight = HEADER_HEIGHT,\n headerWidth = HEADER_WIDTH,\n historyLimit = HISTORY_LIMIT,\n renderers,\n parsers,\n labelers,\n minNumRows,\n maxNumRows,\n minNumCols,\n maxNumCols,\n } = options;\n const table = new Table({\n historyLimit,\n parsers,\n renderers,\n labelers,\n minNumRows,\n maxNumRows,\n minNumCols,\n maxNumCols,\n headerHeight,\n headerWidth,\n functions: { ...functions, ...additionalFunctions },\n });\n let sheetId = 0;\n if (sheetProvided) {\n sheetId = sheetContext.head.current++;\n table.tables = sheetContext.tables.current;\n table.sheets = sheetContext.sheets.current;\n }\n table.tables[sheetId] = table;\n table.sheetId = sheetId;\n table.initialize(initialCells);\n onInit?.(table);\n return {\n sheetId,\n table, // temporary (see StoreInitializer for detail)\n tableInitialized: false,\n rootRef,\n mainRef,\n searchInputRef,\n editorRef,\n largeEditorRef,\n tabularRef,\n lastFocusedRef,\n choosing: { y: 1, x: 1 },\n cutting: false,\n inputting: '',\n selectingZone: { startY: -1, startX: -1, endY: -1, endX: -1 },\n copyingZone: { startY: -1, startX: -1, endY: -1, endX: -1 },\n autofillDraggingTo: null,\n leftHeaderSelecting: false,\n topHeaderSelecting: false,\n editingCell: '',\n editorRect: { y: 0, x: 0, height: 0, width: 0 },\n resizingRect: { y: -1, x: -1, height: -1, width: -1 },\n sheetHeight: 0,\n sheetWidth: 0,\n headerHeight: 0,\n headerWidth: 0,\n entering: false,\n matchingCells: [],\n matchingCellIndex: 0,\n searchCaseSensitive: false,\n editingOnEnter: true,\n showAddress: true,\n contextMenuPosition: { y: -1, x: -1 },\n resizingPositionY: [-1, -1, -1],\n resizingPositionX: [-1, -1, -1],\n minNumRows: 1,\n maxNumRows: -1,\n minNumCols: 1,\n maxNumCols: -1,\n mode: 'light',\n lastEdited: '',\n };\n });\n\n const [store, dispatch] = React.useReducer(\n defaultReducer as unknown as ReducerWithoutAction<StoreType>,\n initialState,\n () => initialState,\n );\n\n React.useEffect(() => {\n embedStyle();\n }, []);\n\n React.useEffect(() => {\n if (!sheetProvided) {\n return;\n }\n sheetContext.tables.current[store.sheetId] = store.table;\n sheetContext?.forceRender?.();\n }, [store.table]);\n\n React.useEffect(() => {\n if (!sheetProvided) {\n return;\n }\n if (prevSheetName !== sheetName) {\n delete sheetContext.sheets.current[prevSheetName];\n setPrevSheetName(sheetName);\n }\n if (sheetName) {\n sheetContext.sheets.current[sheetName] = store.sheetId;\n }\n store.table.sheetName = sheetName;\n }, [sheetName]);\n\n const [sheetHeight, setSheetHeight] = React.useState(\n options?.sheetHeight || estimateSheetHeight({ options, initialData: initialCells }),\n );\n const [sheetWidth, setSheetWidth] = React.useState(\n options?.sheetWidth || estimateSheetWidth({ options, initialData: initialCells }),\n );\n React.useEffect(() => {\n const intervalId = window.setInterval(() => {\n setSheetHeight(mainRef.current?.clientHeight || 0);\n setSheetWidth(mainRef.current?.clientWidth || 0);\n }, 1000);\n return () => window.clearInterval(intervalId);\n }, []);\n React.useEffect(() => {\n if (options.sheetHeight) {\n setSheetHeight(options.sheetHeight);\n }\n }, [options.sheetHeight]);\n React.useEffect(() => {\n if (options.sheetWidth) {\n setSheetWidth(options.sheetWidth);\n }\n }, [options.sheetWidth]);\n\n const { onChange, onSelect } = options;\n return (\n <Context.Provider value={{ store, dispatch }}>\n <div\n className={`gs-root1`}\n ref={rootRef}\n data-sheet-name={sheetName}\n data-mode={mode}\n style={{ maxWidth: `min(100%, ${store.table.totalWidth + 2}px)` }}\n >\n {typeof store.searchQuery === 'undefined' ? showFormulaBar && <FormulaBar /> : <SearchBar />}\n <div\n className={`gs-main ${className || ''}`}\n ref={mainRef}\n style={{\n maxWidth: `min(100%-1px, ${store.table.totalWidth + 2}px)`,\n maxHeight: store.table.totalHeight + 2,\n ...style,\n resize: sheetResize,\n }}\n >\n <Editor mode={mode} />\n <Tabular tableRef={tableRef} />\n <StoreInitializer\n initialCells={initialCells}\n options={{ ...options, sheetHeight, sheetWidth }}\n additionalFunctions={additionalFunctions}\n />\n <ContextMenu />\n <Resizer />\n <Emitter onChange={onChange} onSelect={onSelect} />\n </div>\n </div>\n </Context.Provider>\n );\n}\n\ntype EstimateProps = {\n initialData: CellsByAddressType;\n options: OptionsType;\n};\n\nconst estimateSheetHeight = ({ initialData, options }: EstimateProps) => {\n const auto = getMaxSizesFromCells(initialData);\n let estimatedHeight = options.headerHeight || HEADER_HEIGHT;\n for (let y = 0; y < auto.numRows; y++) {\n const row = y2r(y);\n const height = initialData?.[row]?.height || initialData?.default?.height || DEFAULT_HEIGHT;\n if (estimatedHeight + height > SHEET_HEIGHT) {\n return SHEET_HEIGHT;\n }\n estimatedHeight += height;\n }\n return estimatedHeight + 3;\n};\n\nconst estimateSheetWidth = ({ initialData, options }: EstimateProps) => {\n const auto = getMaxSizesFromCells(initialData);\n let estimatedWidth = options.headerWidth || HEADER_WIDTH;\n for (let x = 0; x < auto.numCols; x++) {\n const col = x2c(x);\n const width = initialData?.[col]?.width || initialData?.default?.width || DEFAULT_WIDTH;\n if (estimatedWidth + width > SHEET_WIDTH) {\n return SHEET_WIDTH;\n }\n estimatedWidth += width;\n }\n return estimatedWidth + 3;\n};\n"],"names":["defaultReducer"],"mappings":";;;;;;;;;;;;;;;;;;;AA+BO,SAAS,UAAU;AAAA,EACxB;AAAA,EACA,YAA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,IAAA;AAEU,uBAAA;AAAA,EAAA;AAErB,SAAO,kBAAkB;AAC3B;AAEA,MAAM,qBAAqB,CAAC,EAAE,aAAa,cAA6B;;AAChE,QAAA,OAAO,qBAAqB,WAAW;AACzC,MAAA,iBAAiB,QAAQ,eAAe;AAC5C,WAAS,IAAI,GAAG,IAAI,KAAK,SAAS,KAAK;AAC/B,UAAA,MAAM,IAAI,CAAC;AACjB,UAAM,UAAQ,gDAAc,SAAd,mBAAoB,YAAS,gDAAa,YAAb,mBAAsB,UAAS;AACtE,QAAA,iBAAiB,QAAQ,aAAa;AACjC,aAAA;AAAA,IAAA;AAES,sBAAA;AAAA,EAAA;AAEpB,SAAO,iBAAiB;AAC1B;"}
|
|
1
|
+
{"version":3,"file":"GridSheet.js","sources":["../../components/GridSheet.tsx"],"sourcesContent":["import * as React from 'react';\nimport { ReducerWithoutAction } from 'react';\n\nimport { CellsByAddressType, OptionsType, Props, StoreType } from '../types';\nimport {\n DEFAULT_HEIGHT,\n DEFAULT_WIDTH,\n HEADER_HEIGHT,\n HEADER_WIDTH,\n SHEET_HEIGHT,\n SHEET_WIDTH,\n HISTORY_LIMIT,\n} from '../constants';\nimport { functions } from '../formula/mapping';\nimport { Context } from '../store';\nimport { reducer as defaultReducer } from '../store/actions';\n\nimport { Editor } from './Editor';\nimport { StoreInitializer } from './StoreInitializer';\nimport { Resizer } from './Resizer';\nimport { Emitter } from './Emitter';\nimport { ContextMenu } from './ContextMenu';\nimport { Table } from '../lib/table';\nimport { Tabular } from './Tabular';\nimport { getMaxSizesFromCells } from '../lib/structs';\nimport { x2c, y2r } from '../lib/converters';\nimport { embedStyle } from '../styles/embedder';\nimport { useSheetContext } from './SheetProvider';\nimport { FormulaBar } from './FormulaBar';\nimport { SearchBar } from './SearchBar';\n\nexport function GridSheet({\n initialCells,\n sheetName = '',\n tableRef,\n options = {},\n className,\n style,\n additionalFunctions = {},\n}: Props) {\n const { sheetResize, showFormulaBar = true, onInit, mode = 'light' } = options;\n const [prevSheetName, setPrevSheetName] = React.useState(sheetName);\n const rootRef = React.useRef<HTMLDivElement | null>(null);\n const mainRef = React.useRef<HTMLDivElement | null>(null);\n const searchInputRef = React.useRef<HTMLTextAreaElement | null>(null);\n const editorRef = React.useRef<HTMLTextAreaElement | null>(null);\n const largeEditorRef = React.useRef<HTMLTextAreaElement | null>(null);\n const tabularRef = React.useRef<HTMLDivElement | null>(null);\n const lastFocusedRef = React.useRef<HTMLTextAreaElement | null>(null);\n const [sheetProvided, sheetContext] = useSheetContext();\n\n const [initialState] = React.useState<StoreType>(() => {\n const {\n headerHeight = HEADER_HEIGHT,\n headerWidth = HEADER_WIDTH,\n historyLimit = HISTORY_LIMIT,\n renderers,\n parsers,\n labelers,\n minNumRows,\n maxNumRows,\n minNumCols,\n maxNumCols,\n } = options;\n const table = new Table({\n historyLimit,\n parsers,\n renderers,\n labelers,\n minNumRows,\n maxNumRows,\n minNumCols,\n maxNumCols,\n headerHeight,\n headerWidth,\n sheetName,\n functions: { ...functions, ...additionalFunctions },\n });\n let sheetId = 0;\n if (sheetProvided) {\n sheetId = sheetContext.head.current++;\n table.tables = sheetContext.tables.current;\n table.sheets = sheetContext.sheets.current;\n }\n table.tables[sheetId] = table;\n table.sheetId = sheetId;\n table.initialize(initialCells);\n onInit?.(table);\n return {\n sheetId,\n table, // temporary (see StoreInitializer for detail)\n tableInitialized: false,\n rootRef,\n mainRef,\n searchInputRef,\n editorRef,\n largeEditorRef,\n tabularRef,\n lastFocusedRef,\n choosing: { y: 1, x: 1 },\n cutting: false,\n inputting: '',\n selectingZone: { startY: -1, startX: -1, endY: -1, endX: -1 },\n copyingZone: { startY: -1, startX: -1, endY: -1, endX: -1 },\n autofillDraggingTo: null,\n leftHeaderSelecting: false,\n topHeaderSelecting: false,\n editingCell: '',\n editorRect: { y: 0, x: 0, height: 0, width: 0 },\n resizingRect: { y: -1, x: -1, height: -1, width: -1 },\n sheetHeight: 0,\n sheetWidth: 0,\n headerHeight: 0,\n headerWidth: 0,\n entering: false,\n matchingCells: [],\n matchingCellIndex: 0,\n searchCaseSensitive: false,\n editingOnEnter: true,\n showAddress: true,\n contextMenuPosition: { y: -1, x: -1 },\n resizingPositionY: [-1, -1, -1],\n resizingPositionX: [-1, -1, -1],\n minNumRows: 1,\n maxNumRows: -1,\n minNumCols: 1,\n maxNumCols: -1,\n mode: 'light',\n lastEdited: '',\n };\n });\n\n const [store, dispatch] = React.useReducer(\n defaultReducer as unknown as ReducerWithoutAction<StoreType>,\n initialState,\n () => initialState,\n );\n\n React.useEffect(() => {\n embedStyle();\n }, []);\n\n React.useEffect(() => {\n if (!sheetProvided) {\n return;\n }\n sheetContext.tables.current[store.sheetId] = store.table;\n sheetContext?.forceRender?.();\n }, [store.table]);\n\n React.useEffect(() => {\n if (!sheetProvided) {\n return;\n }\n if (prevSheetName !== sheetName) {\n delete sheetContext.sheets.current[prevSheetName];\n setPrevSheetName(sheetName);\n }\n if (sheetName) {\n sheetContext.sheets.current[sheetName] = store.sheetId;\n }\n store.table.sheetName = sheetName;\n }, [sheetName]);\n\n const [sheetHeight, setSheetHeight] = React.useState(\n options?.sheetHeight || estimateSheetHeight({ options, initialData: initialCells }),\n );\n const [sheetWidth, setSheetWidth] = React.useState(\n options?.sheetWidth || estimateSheetWidth({ options, initialData: initialCells }),\n );\n React.useEffect(() => {\n const intervalId = window.setInterval(() => {\n setSheetHeight(mainRef.current?.clientHeight || 0);\n setSheetWidth(mainRef.current?.clientWidth || 0);\n }, 1000);\n return () => window.clearInterval(intervalId);\n }, []);\n React.useEffect(() => {\n if (options.sheetHeight) {\n setSheetHeight(options.sheetHeight);\n }\n }, [options.sheetHeight]);\n React.useEffect(() => {\n if (options.sheetWidth) {\n setSheetWidth(options.sheetWidth);\n }\n }, [options.sheetWidth]);\n\n const { onChange, onSelect, onKeyUp } = options;\n return (\n <Context.Provider value={{ store, dispatch }}>\n <div\n className={`gs-root1`}\n ref={rootRef}\n data-sheet-name={sheetName}\n data-mode={mode}\n style={{ maxWidth: `min(100%, ${store.table.totalWidth + 2}px)` }}\n >\n {typeof store.searchQuery === 'undefined' ? showFormulaBar && <FormulaBar /> : <SearchBar />}\n <div\n className={`gs-main ${className || ''}`}\n ref={mainRef}\n style={{\n maxWidth: `min(100%-1px, ${store.table.totalWidth + 2}px)`,\n maxHeight: store.table.totalHeight + 2,\n ...style,\n resize: sheetResize,\n }}\n >\n <Editor mode={mode} handleKeyUp={onKeyUp} />\n <Tabular tableRef={tableRef} />\n <StoreInitializer\n initialCells={initialCells}\n options={{ ...options, sheetHeight, sheetWidth }}\n additionalFunctions={additionalFunctions}\n />\n <ContextMenu />\n <Resizer />\n <Emitter onChange={onChange} onSelect={onSelect} />\n </div>\n </div>\n </Context.Provider>\n );\n}\n\ntype EstimateProps = {\n initialData: CellsByAddressType;\n options: OptionsType;\n};\n\nconst estimateSheetHeight = ({ initialData, options }: EstimateProps) => {\n const auto = getMaxSizesFromCells(initialData);\n let estimatedHeight = options.headerHeight || HEADER_HEIGHT;\n for (let y = 0; y < auto.numRows; y++) {\n const row = y2r(y);\n const height = initialData?.[row]?.height || initialData?.default?.height || DEFAULT_HEIGHT;\n if (estimatedHeight + height > SHEET_HEIGHT) {\n return SHEET_HEIGHT;\n }\n estimatedHeight += height;\n }\n return estimatedHeight + 3;\n};\n\nconst estimateSheetWidth = ({ initialData, options }: EstimateProps) => {\n const auto = getMaxSizesFromCells(initialData);\n let estimatedWidth = options.headerWidth || HEADER_WIDTH;\n for (let x = 0; x < auto.numCols; x++) {\n const col = x2c(x);\n const width = initialData?.[col]?.width || initialData?.default?.width || DEFAULT_WIDTH;\n if (estimatedWidth + width > SHEET_WIDTH) {\n return SHEET_WIDTH;\n }\n estimatedWidth += width;\n }\n return estimatedWidth + 3;\n};\n"],"names":["defaultReducer"],"mappings":";;;;;;;;;;;;;;;;;;;AA+BO,SAAS,UAAU;AAAA,EACxB;AAAA,EACA,YAAY;AAAA,EACZ;AAAA,EACA,UAAU,CAAC;AAAA,EACX;AAAA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U,uBAAA;AAAA,EAAA;AAErB,SAAO,kBAAkB;AAC3B;AAEA,MAAM,qBAAqB,CAAC,EAAE,aAAa,cAA6B;;AAChE,QAAA,OAAO,qBAAqB,WAAW;AACzC,MAAA,iBAAiB,QAAQ,eAAe;AAC5C,WAAS,IAAI,GAAG,IAAI,KAAK,SAAS,KAAK;AAC/B,UAAA,MAAM,IAAI,CAAC;AACjB,UAAM,UAAQ,gDAAc,SAAd,mBAAoB,YAAS,gDAAa,YAAb,mBAAsB,UAAS;AACtE,QAAA,iBAAiB,QAAQ,aAAa;AACjC,aAAA;AAAA,IAAA;AAES,sBAAA;AAAA,EAAA;AAEpB,SAAO,iBAAiB;AAC1B;"}
|
|
@@ -5,6 +5,8 @@ export type SheetContextType = {
|
|
|
5
5
|
sheets: React.MutableRefObject<SheetMapType>;
|
|
6
6
|
tables: React.MutableRefObject<TableMapType>;
|
|
7
7
|
head: React.MutableRefObject<number>;
|
|
8
|
+
choosingCell: string;
|
|
9
|
+
setChoosingCell: (cell: string) => void;
|
|
8
10
|
editingCell: string;
|
|
9
11
|
setEditingCell: (cell: string) => void;
|
|
10
12
|
externalRefs?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SheetProvider.d.ts","sourceRoot":"","sources":["../../components/SheetProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAEtE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,KAAK,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC;IAC7C,MAAM,EAAE,KAAK,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC;IAC7C,IAAI,EAAE,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAA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IACrB,eAAe,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,YAAY,CAAC,EAAE;QAAE,CAAC,SAAS,EAAE,MAAM,GAAG,cAAc,CAAA;KAAE,CAAC;IACvD,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,CAAC,SAAS,EAAE,MAAM,GAAG,cAAc,CAAA;KAAE,KAAK,IAAI,CAAC;IAC1E,cAAc,EAAE,KAAK,CAAC,gBAAgB,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAAC;IACnE,iBAAiB,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,gBAAgB,CAAC,mBAAmB,GAAG,IAAI,CAAC,KAAK,IAAI,CAAC;IACrF,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,YAAY,iCAA8C,CAAC;AAExE,wBAAgB,eAAe,IAAI,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAM7D;AAED,wBAAgB,gBAAgB,iCAM/B;AAED,KAAK,KAAK,GAAG;IACX,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAAC;AAEF,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE,KAAK,qBA2ChD"}
|
|
@@ -15,6 +15,7 @@ function SheetProvider({ children }) {
|
|
|
15
15
|
const head = React__default.useRef(1);
|
|
16
16
|
const sheets = React__default.useRef({});
|
|
17
17
|
const tables = React__default.useRef({});
|
|
18
|
+
const [choosingCell, setChoosingCell] = React__default.useState("");
|
|
18
19
|
const [editingCell, setEditingCell] = React__default.useState("");
|
|
19
20
|
const [externalRefs, setExternalRefs] = React__default.useState({});
|
|
20
21
|
const lastFocusedRefInitial = React__default.useRef(null);
|
|
@@ -30,6 +31,8 @@ function SheetProvider({ children }) {
|
|
|
30
31
|
tables,
|
|
31
32
|
sheets,
|
|
32
33
|
head,
|
|
34
|
+
choosingCell,
|
|
35
|
+
setChoosingCell,
|
|
33
36
|
editingCell,
|
|
34
37
|
setEditingCell,
|
|
35
38
|
externalRefs,
|