@rowsncolumns/grid 9.0.4 → 13.2.33
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/LICENSE.md +100 -0
- package/Readme.md +53 -59
- package/dist/cjs/Cell.d.ts +35 -0
- package/dist/cjs/Cell.d.ts.map +1 -0
- package/dist/cjs/Cell.js +29 -0
- package/dist/{CellOverlay.d.ts → cjs/CellOverlay.d.ts} +5 -5
- package/dist/cjs/CellOverlay.d.ts.map +1 -0
- package/dist/cjs/CellOverlay.js +126 -0
- package/dist/cjs/Context.d.ts +8 -0
- package/dist/cjs/Context.d.ts.map +1 -0
- package/dist/cjs/Context.js +13 -0
- package/dist/{FillHandle.d.ts → cjs/FillHandle.d.ts} +2 -1
- package/dist/cjs/FillHandle.d.ts.map +1 -0
- package/dist/cjs/FillHandle.js +26 -0
- package/dist/cjs/Grid.d.ts +558 -0
- package/dist/cjs/Grid.d.ts.map +1 -0
- package/dist/cjs/Grid.js +2446 -0
- package/dist/{GridLine.d.ts → cjs/GridLine.d.ts} +2 -1
- package/dist/cjs/GridLine.d.ts.map +1 -0
- package/dist/cjs/GridLine.js +10 -0
- package/dist/cjs/Image.d.ts +11 -0
- package/dist/cjs/Image.d.ts.map +1 -0
- package/dist/cjs/Image.js +57 -0
- package/dist/cjs/MemoizedGrid.d.ts +49 -0
- package/dist/cjs/MemoizedGrid.d.ts.map +1 -0
- package/dist/cjs/MemoizedGrid.js +105 -0
- package/dist/cjs/Selection.d.ts +5 -0
- package/dist/cjs/Selection.d.ts.map +1 -0
- package/dist/cjs/Selection.js +10 -0
- package/dist/{helpers.d.ts → cjs/helpers.d.ts} +59 -39
- package/dist/cjs/helpers.d.ts.map +1 -0
- package/dist/cjs/helpers.js +1409 -0
- package/dist/{hooks → cjs/hooks}/useCopyPaste.d.ts +3 -2
- package/dist/cjs/hooks/useCopyPaste.d.ts.map +1 -0
- package/dist/cjs/hooks/useCopyPaste.js +230 -0
- package/dist/{hooks → cjs/hooks}/useEditable.d.ts +21 -8
- package/dist/cjs/hooks/useEditable.d.ts.map +1 -0
- package/dist/cjs/hooks/useEditable.js +491 -0
- package/dist/{hooks → cjs/hooks}/useFilter.d.ts +3 -2
- package/dist/cjs/hooks/useFilter.d.ts.map +1 -0
- package/dist/cjs/hooks/useFilter.js +97 -0
- package/dist/{hooks → cjs/hooks}/useImage.d.ts +1 -0
- package/dist/cjs/hooks/useImage.d.ts.map +1 -0
- package/dist/cjs/hooks/useImage.js +80 -0
- package/dist/{hooks → cjs/hooks}/usePagination.d.ts +3 -2
- package/dist/cjs/hooks/usePagination.d.ts.map +1 -0
- package/dist/cjs/hooks/usePagination.js +53 -0
- package/dist/{hooks → cjs/hooks}/useSizer.d.ts +28 -29
- package/dist/cjs/hooks/useSizer.d.ts.map +1 -0
- package/dist/cjs/hooks/useSizer.js +176 -0
- package/dist/{hooks → cjs/hooks}/useTooltip.d.ts +2 -1
- package/dist/cjs/hooks/useTooltip.d.ts.map +1 -0
- package/dist/cjs/hooks/useTooltip.js +82 -0
- package/dist/{hooks → cjs/hooks}/useUndo.d.ts +2 -1
- package/dist/cjs/hooks/useUndo.d.ts.map +1 -0
- package/dist/cjs/hooks/useUndo.js +87 -0
- package/dist/cjs/index.d.ts +19 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +29 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/{types.d.ts → cjs/types.d.ts} +8 -3
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/{types.js → cjs/types.js} +7 -8
- package/dist/cjs/utils.d.ts +9 -0
- package/dist/cjs/utils.d.ts.map +1 -0
- package/dist/cjs/utils.js +58 -0
- package/dist/cjs/vitest.config.d.ts +3 -0
- package/dist/cjs/vitest.config.d.ts.map +1 -0
- package/dist/cjs/vitest.config.js +24 -0
- package/dist/esm/Cell.d.ts +35 -0
- package/dist/esm/Cell.d.ts.map +1 -0
- package/dist/esm/Cell.js +24 -0
- package/dist/esm/CellOverlay.d.ts +21 -0
- package/dist/esm/CellOverlay.d.ts.map +1 -0
- package/dist/esm/CellOverlay.js +120 -0
- package/dist/esm/Context.d.ts +8 -0
- package/dist/esm/Context.d.ts.map +1 -0
- package/dist/esm/Context.js +9 -0
- package/dist/esm/FillHandle.d.ts +8 -0
- package/dist/esm/FillHandle.d.ts.map +1 -0
- package/dist/{FillHandle.js → esm/FillHandle.js} +5 -11
- package/dist/esm/Grid.d.ts +558 -0
- package/dist/esm/Grid.d.ts.map +1 -0
- package/dist/esm/Grid.js +2451 -0
- package/dist/esm/GridLine.d.ts +5 -0
- package/dist/esm/GridLine.d.ts.map +1 -0
- package/dist/esm/GridLine.js +7 -0
- package/dist/esm/Image.d.ts +11 -0
- package/dist/esm/Image.d.ts.map +1 -0
- package/dist/esm/Image.js +53 -0
- package/dist/esm/MemoizedGrid.d.ts +49 -0
- package/dist/esm/MemoizedGrid.d.ts.map +1 -0
- package/dist/esm/MemoizedGrid.js +98 -0
- package/dist/esm/Selection.d.ts +5 -0
- package/dist/esm/Selection.d.ts.map +1 -0
- package/dist/esm/Selection.js +7 -0
- package/dist/esm/helpers.d.ts +281 -0
- package/dist/esm/helpers.d.ts.map +1 -0
- package/dist/esm/helpers.js +1260 -0
- package/dist/esm/hooks/useCopyPaste.d.ts +53 -0
- package/dist/esm/hooks/useCopyPaste.d.ts.map +1 -0
- package/dist/{hooks → esm/hooks}/useCopyPaste.js +40 -46
- package/dist/esm/hooks/useEditable.d.ts +253 -0
- package/dist/esm/hooks/useEditable.d.ts.map +1 -0
- package/dist/esm/hooks/useEditable.js +482 -0
- package/dist/esm/hooks/useFilter.d.ts +69 -0
- package/dist/esm/hooks/useFilter.d.ts.map +1 -0
- package/dist/{hooks → esm/hooks}/useFilter.js +22 -42
- package/dist/esm/hooks/useImage.d.ts +13 -0
- package/dist/esm/hooks/useImage.d.ts.map +1 -0
- package/dist/esm/hooks/useImage.js +76 -0
- package/dist/esm/hooks/usePagination.d.ts +69 -0
- package/dist/esm/hooks/usePagination.d.ts.map +1 -0
- package/dist/esm/hooks/usePagination.js +47 -0
- package/dist/esm/hooks/useSizer.d.ts +114 -0
- package/dist/esm/hooks/useSizer.d.ts.map +1 -0
- package/dist/esm/hooks/useSizer.js +176 -0
- package/dist/esm/hooks/useTooltip.d.ts +43 -0
- package/dist/esm/hooks/useTooltip.d.ts.map +1 -0
- package/dist/esm/hooks/useTooltip.js +80 -0
- package/dist/esm/hooks/useUndo.d.ts +36 -0
- package/dist/esm/hooks/useUndo.d.ts.map +1 -0
- package/dist/{hooks → esm/hooks}/useUndo.js +16 -25
- package/dist/esm/index.d.ts +19 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +17 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -0
- package/dist/esm/types.d.ts +70 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +68 -0
- package/dist/esm/utils.d.ts +9 -0
- package/dist/esm/utils.d.ts.map +1 -0
- package/dist/esm/utils.js +104 -0
- package/dist/esm/vitest.config.d.ts +3 -0
- package/dist/esm/vitest.config.d.ts.map +1 -0
- package/dist/esm/vitest.config.js +22 -0
- package/package.json +28 -29
- package/dist/Cell.d.ts +0 -23
- package/dist/Cell.js +0 -55
- package/dist/Cell.js.map +0 -1
- package/dist/CellOverlay.js +0 -116
- package/dist/CellOverlay.js.map +0 -1
- package/dist/FillHandle.js.map +0 -1
- package/dist/Grid.d.ts +0 -385
- package/dist/Grid.js +0 -1684
- package/dist/Grid.js.map +0 -1
- package/dist/GridLine.js +0 -13
- package/dist/GridLine.js.map +0 -1
- package/dist/Image.d.ts +0 -8
- package/dist/Image.js +0 -50
- package/dist/Image.js.map +0 -1
- package/dist/Selection.d.ts +0 -4
- package/dist/Selection.js +0 -9
- package/dist/Selection.js.map +0 -1
- package/dist/helpers.js +0 -1033
- package/dist/helpers.js.map +0 -1
- package/dist/hooks/useCopyPaste.js.map +0 -1
- package/dist/hooks/useEditable.js +0 -477
- package/dist/hooks/useEditable.js.map +0 -1
- package/dist/hooks/useFilter.js.map +0 -1
- package/dist/hooks/useImage.js +0 -42
- package/dist/hooks/useImage.js.map +0 -1
- package/dist/hooks/usePagination.js +0 -73
- package/dist/hooks/usePagination.js.map +0 -1
- package/dist/hooks/useSelection.d.ts +0 -175
- package/dist/hooks/useSelection.js +0 -982
- package/dist/hooks/useSelection.js.map +0 -1
- package/dist/hooks/useSizer.js +0 -150
- package/dist/hooks/useSizer.js.map +0 -1
- package/dist/hooks/useTooltip.js +0 -106
- package/dist/hooks/useTooltip.js.map +0 -1
- package/dist/hooks/useTouch.d.ts +0 -21
- package/dist/hooks/useTouch.js +0 -73
- package/dist/hooks/useTouch.js.map +0 -1
- package/dist/hooks/useUndo.js.map +0 -1
- package/dist/index.d.ts +0 -25
- package/dist/index.js +0 -61
- package/dist/index.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils.d.ts +0 -8
- package/dist/utils.js +0 -153
- package/dist/utils.js.map +0 -1
- package/src/Cell.tsx +0 -100
- package/src/CellOverlay.tsx +0 -191
- package/src/FillHandle.tsx +0 -37
- package/src/Grid.tsx +0 -2677
- package/src/GridLine.tsx +0 -23
- package/src/Image.tsx +0 -43
- package/src/Selection.tsx +0 -9
- package/src/helpers.ts +0 -1455
- package/src/hooks/useCopyPaste.ts +0 -265
- package/src/hooks/useEditable.tsx +0 -945
- package/src/hooks/useFilter.tsx +0 -233
- package/src/hooks/useImage.ts +0 -57
- package/src/hooks/usePagination.tsx +0 -153
- package/src/hooks/useSelection.ts +0 -1440
- package/src/hooks/useSizer.ts +0 -312
- package/src/hooks/useTooltip.tsx +0 -172
- package/src/hooks/useTouch.ts +0 -116
- package/src/hooks/useUndo.ts +0 -134
- package/src/index.tsx +0 -46
- package/src/tests/Grid.spec.tsx +0 -47
- package/src/tests/helpers.test.ts +0 -292
- package/src/tests/usePagination.test.ts +0 -28
- package/src/tests/useSelection.test.ts +0 -27
- package/src/tests/useUndo.test.ts +0 -73
- package/src/types.ts +0 -69
- package/src/utils.tsx +0 -287
package/src/hooks/useUndo.ts
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import React, { useReducer, useRef, useCallback, useEffect } from "react";
|
|
2
|
-
import { KeyCodes } from "../types";
|
|
3
|
-
import { focusableNodeNames } from "../helpers";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Spec: https://tools.ietf.org/html/rfc6902
|
|
7
|
-
*
|
|
8
|
-
* add, { "op": "add", "path": ["data", "1,2"], "value": "hello world" }
|
|
9
|
-
* remove { "op": "remove", "path": ["data", "1,2"], "value": "hello world" }
|
|
10
|
-
* replace { "op": "replace", "path": ["data", "1,2"], "value": "hello world" }
|
|
11
|
-
* move { "op": "move", "from": "/a/b/c", "path": "/a/b/d" }
|
|
12
|
-
* copy
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
export interface UndoProps {
|
|
16
|
-
enableGlobalKeyHandlers?: boolean;
|
|
17
|
-
onRedo?: (patches: any) => void;
|
|
18
|
-
onUndo?: (patches: any) => void;
|
|
19
|
-
identifier?: (patch: any) => any;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface UndoManager {
|
|
23
|
-
undo: () => void;
|
|
24
|
-
redo: () => void;
|
|
25
|
-
add: (patches: any) => void;
|
|
26
|
-
replace: (patches: any, inversePatches: any) => void;
|
|
27
|
-
canUndo: boolean;
|
|
28
|
-
canRedo: boolean;
|
|
29
|
-
onKeyDown?: (e: React.KeyboardEvent<HTMLDivElement>) => void;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface PatchInterface<T> {
|
|
33
|
-
patches: T[];
|
|
34
|
-
inversePatches: T[];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Undo/Redo hook
|
|
39
|
-
* @param
|
|
40
|
-
*/
|
|
41
|
-
const useUndo = <T>(props: UndoProps = {}): UndoManager => {
|
|
42
|
-
const { enableGlobalKeyHandlers, onRedo, onUndo, identifier } = props;
|
|
43
|
-
const undoStack = useRef<PatchInterface<T>[]>([]);
|
|
44
|
-
const undoStackPointer = useRef<number>(-1);
|
|
45
|
-
const [_, forceRender] = useReducer((s) => s + 1, 0);
|
|
46
|
-
|
|
47
|
-
useEffect(() => {
|
|
48
|
-
if (enableGlobalKeyHandlers)
|
|
49
|
-
document.addEventListener("keydown", handleKeyDown);
|
|
50
|
-
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
51
|
-
}, [enableGlobalKeyHandlers]);
|
|
52
|
-
|
|
53
|
-
const handleKeyDown = useCallback(
|
|
54
|
-
(e: React.KeyboardEvent<HTMLElement> | globalThis.KeyboardEvent) => {
|
|
55
|
-
/* Is user focused on an input, textarea or select element */
|
|
56
|
-
if (
|
|
57
|
-
document.activeElement &&
|
|
58
|
-
focusableNodeNames.has(document.activeElement?.nodeName)
|
|
59
|
-
) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
const isMeta = e.metaKey || e.ctrlKey;
|
|
63
|
-
const isUndo = isMeta && e.which === KeyCodes.Z;
|
|
64
|
-
const isRedo = (e.shiftKey && isUndo) || e.which === KeyCodes.KEY_Y;
|
|
65
|
-
if (!isRedo && !isUndo) return;
|
|
66
|
-
if (isRedo) {
|
|
67
|
-
handleRedo();
|
|
68
|
-
} else {
|
|
69
|
-
handleUndo();
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
[]
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
const handleUndo = useCallback(() => {
|
|
76
|
-
if (undoStackPointer.current < 0) return;
|
|
77
|
-
const patches = undoStack.current[undoStackPointer.current].inversePatches;
|
|
78
|
-
undoStackPointer.current--;
|
|
79
|
-
onUndo && onUndo(patches);
|
|
80
|
-
forceRender();
|
|
81
|
-
}, []);
|
|
82
|
-
|
|
83
|
-
const handleRedo = useCallback(() => {
|
|
84
|
-
if (undoStackPointer.current === undoStack.current.length - 1) return;
|
|
85
|
-
undoStackPointer.current++;
|
|
86
|
-
const patches = undoStack.current[undoStackPointer.current].patches;
|
|
87
|
-
onRedo && onRedo(patches);
|
|
88
|
-
forceRender();
|
|
89
|
-
}, []);
|
|
90
|
-
|
|
91
|
-
const addUndoable = useCallback((history: PatchInterface<T>) => {
|
|
92
|
-
const { patches, inversePatches } = history;
|
|
93
|
-
const pointer = ++undoStackPointer.current;
|
|
94
|
-
undoStack.current.length = pointer;
|
|
95
|
-
undoStack.current[pointer] = { patches, inversePatches };
|
|
96
|
-
forceRender();
|
|
97
|
-
}, []);
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Use for async update where you want to replace the last patch
|
|
101
|
-
*/
|
|
102
|
-
const replaceLastPatch = useCallback(
|
|
103
|
-
(patches: T[] | undefined, inversePatches: T[] | undefined) => {
|
|
104
|
-
if (patches === void 0) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
const currentStack = undoStack.current;
|
|
108
|
-
const pointer = undoStackPointer.current;
|
|
109
|
-
const curPatches = currentStack[pointer];
|
|
110
|
-
|
|
111
|
-
if (curPatches?.patches === void 0) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
curPatches.patches.push(...patches);
|
|
115
|
-
|
|
116
|
-
if (inversePatches && curPatches?.inversePatches) {
|
|
117
|
-
curPatches.inversePatches.unshift(...inversePatches);
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
[]
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
return {
|
|
124
|
-
undo: handleUndo,
|
|
125
|
-
redo: handleRedo,
|
|
126
|
-
add: addUndoable,
|
|
127
|
-
replace: replaceLastPatch,
|
|
128
|
-
onKeyDown: enableGlobalKeyHandlers ? undefined : handleKeyDown,
|
|
129
|
-
canUndo: !(undoStackPointer.current < 0),
|
|
130
|
-
canRedo: !(undoStackPointer.current === undoStack.current.length - 1),
|
|
131
|
-
};
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
export default useUndo;
|
package/src/index.tsx
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import Grid from "./Grid";
|
|
2
|
-
import { CellRenderer, Cell } from "./Cell";
|
|
3
|
-
import {
|
|
4
|
-
CellOverlay,
|
|
5
|
-
CellRenderer as CellOverlayRenderer
|
|
6
|
-
} from "./CellOverlay";
|
|
7
|
-
import useEditable from "./hooks/useEditable";
|
|
8
|
-
import useSelection from "./hooks/useSelection";
|
|
9
|
-
import useTooltip from "./hooks/useTooltip";
|
|
10
|
-
import useSizer from "./hooks/useSizer";
|
|
11
|
-
import useTouch from "./hooks/useTouch";
|
|
12
|
-
import useCopyPaste from "./hooks/useCopyPaste";
|
|
13
|
-
import useUndo from "./hooks/useUndo";
|
|
14
|
-
import usePagination from "./hooks/usePagination";
|
|
15
|
-
import useFilter from "./hooks/useFilter";
|
|
16
|
-
import Image from "./Image";
|
|
17
|
-
import Selection from "./Selection";
|
|
18
|
-
|
|
19
|
-
export {
|
|
20
|
-
Grid,
|
|
21
|
-
CellRenderer,
|
|
22
|
-
Cell,
|
|
23
|
-
CellOverlay,
|
|
24
|
-
useEditable,
|
|
25
|
-
useSelection,
|
|
26
|
-
useTooltip,
|
|
27
|
-
useSizer,
|
|
28
|
-
useCopyPaste,
|
|
29
|
-
usePagination,
|
|
30
|
-
useUndo,
|
|
31
|
-
useTouch,
|
|
32
|
-
useFilter,
|
|
33
|
-
CellOverlayRenderer,
|
|
34
|
-
Image,
|
|
35
|
-
Selection
|
|
36
|
-
};
|
|
37
|
-
export default Grid;
|
|
38
|
-
export * from "./Grid";
|
|
39
|
-
export * from "./helpers";
|
|
40
|
-
export * from "./hooks/useFilter";
|
|
41
|
-
export * from "./hooks/useUndo";
|
|
42
|
-
export * from "./hooks/useTooltip";
|
|
43
|
-
export * from "./hooks/useEditable";
|
|
44
|
-
export * from "./hooks/useSelection";
|
|
45
|
-
export * from "./types";
|
|
46
|
-
export * from "./Image";
|
package/src/tests/Grid.spec.tsx
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
import React from "react";
|
|
3
|
-
import Grid from "../Grid";
|
|
4
|
-
import "konva/lib/shapes/Rect";
|
|
5
|
-
import { Rect } from "react-konva";
|
|
6
|
-
import { render } from "@testing-library/react";
|
|
7
|
-
|
|
8
|
-
describe("Grid", () => {
|
|
9
|
-
let itemRenderer;
|
|
10
|
-
let rowHeight;
|
|
11
|
-
let columnWidth;
|
|
12
|
-
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
jest.useFakeTimers();
|
|
15
|
-
itemRenderer = jest.fn((props) => <Rect />);
|
|
16
|
-
columnWidth = jest.fn((index) => 50 + index);
|
|
17
|
-
rowHeight = jest.fn((index) => 25 + index);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test("renders the grid", () => {
|
|
21
|
-
const renderGrid = () =>
|
|
22
|
-
render(
|
|
23
|
-
<Grid
|
|
24
|
-
itemRenderer={itemRenderer}
|
|
25
|
-
rowCount={1}
|
|
26
|
-
columnCount={1}
|
|
27
|
-
rowHeight={rowHeight}
|
|
28
|
-
columnWidth={columnWidth}
|
|
29
|
-
/>
|
|
30
|
-
);
|
|
31
|
-
expect(renderGrid).not.toThrow();
|
|
32
|
-
expect(itemRenderer).toHaveBeenCalled();
|
|
33
|
-
expect(rowHeight).toHaveBeenCalled();
|
|
34
|
-
expect(columnWidth).toHaveBeenCalled();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test("renders empty grid", () => {
|
|
38
|
-
const renderGrid = () => render(<Grid itemRenderer={itemRenderer} />);
|
|
39
|
-
expect(renderGrid).not.toThrow();
|
|
40
|
-
expect(itemRenderer).not.toHaveBeenCalled();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
// test("throws error if itemRenderer is not a valid konva element", () => {
|
|
44
|
-
// const renderGrid = () => render(<Grid itemRenderer={() => <div />} />);
|
|
45
|
-
// expect(renderGrid).toThrow();
|
|
46
|
-
// });
|
|
47
|
-
});
|
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
import {
|
|
3
|
-
getEstimatedTotalWidth,
|
|
4
|
-
getEstimatedTotalHeight,
|
|
5
|
-
getBoundedCells,
|
|
6
|
-
cellIdentifier,
|
|
7
|
-
extendAreaToMergedCells,
|
|
8
|
-
areaIntersects,
|
|
9
|
-
findNextContentfulCell,
|
|
10
|
-
findLastContentfulCell,
|
|
11
|
-
} from "../helpers";
|
|
12
|
-
import { Direction } from "../types";
|
|
13
|
-
|
|
14
|
-
describe("getBoundedCells", () => {
|
|
15
|
-
it("returns empty for undefined area", () => {
|
|
16
|
-
const cells = getBoundedCells(undefined);
|
|
17
|
-
expect(cells.size).toBe(0);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("returns accurate top, left, right and bottom indexs", () => {
|
|
21
|
-
const cells = getBoundedCells({
|
|
22
|
-
top: 1,
|
|
23
|
-
right: 5,
|
|
24
|
-
left: 1,
|
|
25
|
-
bottom: 5,
|
|
26
|
-
});
|
|
27
|
-
expect(cells.has(cellIdentifier(1, 1))).toBeTruthy();
|
|
28
|
-
expect(cells.has(cellIdentifier(5, 5))).toBeTruthy();
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
describe("getEstimatedTotalWidth", () => {
|
|
33
|
-
it("returns estimated width during initial load", () => {
|
|
34
|
-
const columnCount = 200;
|
|
35
|
-
const instanceProps = {
|
|
36
|
-
lastMeasuredColumnIndex: -1,
|
|
37
|
-
columnMetadataMap: {},
|
|
38
|
-
estimatedColumnWidth: 30,
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
expect(getEstimatedTotalWidth(columnCount, instanceProps)).toBe(6000);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("returns correct width", () => {
|
|
45
|
-
const columnCount = 200;
|
|
46
|
-
const instanceProps = {
|
|
47
|
-
lastMeasuredColumnIndex: 1,
|
|
48
|
-
columnMetadataMap: {
|
|
49
|
-
0: {
|
|
50
|
-
offset: 0,
|
|
51
|
-
size: 20,
|
|
52
|
-
},
|
|
53
|
-
1: {
|
|
54
|
-
offset: 20,
|
|
55
|
-
size: 70,
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
estimatedColumnWidth: 30,
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
expect(getEstimatedTotalWidth(columnCount, instanceProps)).toBe(6030);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
describe("getEstimatedTotalHeight", () => {
|
|
66
|
-
it("returns estimated height during initial load", () => {
|
|
67
|
-
const rowCount = 200;
|
|
68
|
-
const instanceProps = {
|
|
69
|
-
lastMeasuredRowIndex: -1,
|
|
70
|
-
rowMetadataMap: {},
|
|
71
|
-
estimatedRowHeight: 30,
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
expect(getEstimatedTotalHeight(rowCount, instanceProps)).toBe(6000);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it("returns correct height after load", () => {
|
|
78
|
-
const rowCount = 200;
|
|
79
|
-
const instanceProps = {
|
|
80
|
-
lastMeasuredRowIndex: 0,
|
|
81
|
-
rowMetadataMap: {
|
|
82
|
-
0: {
|
|
83
|
-
offset: 0,
|
|
84
|
-
size: 20,
|
|
85
|
-
},
|
|
86
|
-
1: {
|
|
87
|
-
offset: 20,
|
|
88
|
-
size: 70,
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
estimatedRowHeight: 30,
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
expect(getEstimatedTotalHeight(rowCount, instanceProps)).toBe(5990);
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
describe("extendAreaToMergedCells", () => {
|
|
99
|
-
it("expands to merged cells", () => {
|
|
100
|
-
const mergedCells = [
|
|
101
|
-
{
|
|
102
|
-
top: 2,
|
|
103
|
-
left: 2,
|
|
104
|
-
right: 5,
|
|
105
|
-
bottom: 5,
|
|
106
|
-
},
|
|
107
|
-
];
|
|
108
|
-
const originalArea = {
|
|
109
|
-
top: 2,
|
|
110
|
-
left: 1,
|
|
111
|
-
bottom: 2,
|
|
112
|
-
right: 3,
|
|
113
|
-
};
|
|
114
|
-
const area = extendAreaToMergedCells(originalArea, mergedCells);
|
|
115
|
-
expect(area.bottom).toBe(5);
|
|
116
|
-
expect(area.right).toBe(5);
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
describe("areaIntersects", () => {
|
|
121
|
-
it("checks if two areas intersects", () => {
|
|
122
|
-
const area1 = {
|
|
123
|
-
top: 2,
|
|
124
|
-
left: 1,
|
|
125
|
-
right: 3,
|
|
126
|
-
bottom: 4,
|
|
127
|
-
};
|
|
128
|
-
const area2 = {
|
|
129
|
-
top: 5,
|
|
130
|
-
left: 2,
|
|
131
|
-
bottom: 3,
|
|
132
|
-
right: 2,
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
expect(areaIntersects(area1, area2)).toBeFalsy();
|
|
136
|
-
});
|
|
137
|
-
it("returns true for intersecting area", () => {
|
|
138
|
-
const area1 = {
|
|
139
|
-
top: 2,
|
|
140
|
-
left: 1,
|
|
141
|
-
right: 3,
|
|
142
|
-
bottom: 4,
|
|
143
|
-
};
|
|
144
|
-
const area2 = {
|
|
145
|
-
top: 2,
|
|
146
|
-
left: 2,
|
|
147
|
-
bottom: 3,
|
|
148
|
-
right: 2,
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
expect(areaIntersects(area1, area2)).toBeTruthy();
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
describe("findNextContentfulCell", () => {
|
|
156
|
-
let activeCell, cell;
|
|
157
|
-
it("returns last cell if no contentful cell is found", () => {
|
|
158
|
-
activeCell = { rowIndex: 1, columnIndex: 2 };
|
|
159
|
-
const getValue = () => null;
|
|
160
|
-
cell = findNextContentfulCell(
|
|
161
|
-
activeCell,
|
|
162
|
-
getValue,
|
|
163
|
-
undefined,
|
|
164
|
-
Direction.Down,
|
|
165
|
-
20
|
|
166
|
-
);
|
|
167
|
-
expect(cell.rowIndex).toBe(20);
|
|
168
|
-
|
|
169
|
-
activeCell = { rowIndex: 10, columnIndex: 2 };
|
|
170
|
-
cell = findNextContentfulCell(
|
|
171
|
-
activeCell,
|
|
172
|
-
getValue,
|
|
173
|
-
undefined,
|
|
174
|
-
Direction.Up,
|
|
175
|
-
1
|
|
176
|
-
);
|
|
177
|
-
expect(cell.rowIndex).toBe(1);
|
|
178
|
-
|
|
179
|
-
activeCell = { rowIndex: 10, columnIndex: 5 };
|
|
180
|
-
cell = findNextContentfulCell(
|
|
181
|
-
activeCell,
|
|
182
|
-
getValue,
|
|
183
|
-
undefined,
|
|
184
|
-
Direction.Left,
|
|
185
|
-
1
|
|
186
|
-
);
|
|
187
|
-
expect(cell.columnIndex).toBe(1);
|
|
188
|
-
|
|
189
|
-
activeCell = { rowIndex: 10, columnIndex: 5 };
|
|
190
|
-
cell = findNextContentfulCell(
|
|
191
|
-
activeCell,
|
|
192
|
-
getValue,
|
|
193
|
-
undefined,
|
|
194
|
-
Direction.Right,
|
|
195
|
-
100
|
|
196
|
-
);
|
|
197
|
-
expect(cell.columnIndex).toBe(100);
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it("returns next cell with content", () => {
|
|
201
|
-
activeCell = { rowIndex: 1, columnIndex: 2 };
|
|
202
|
-
const getValue = (cell) => {
|
|
203
|
-
if (cell.rowIndex == 5) return "hello";
|
|
204
|
-
return null;
|
|
205
|
-
};
|
|
206
|
-
cell = findNextContentfulCell(
|
|
207
|
-
activeCell,
|
|
208
|
-
getValue,
|
|
209
|
-
undefined,
|
|
210
|
-
Direction.Down,
|
|
211
|
-
20
|
|
212
|
-
);
|
|
213
|
-
expect(cell.rowIndex).toBe(5);
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
describe("findLastContentfulCell", () => {
|
|
218
|
-
let activeCell, cell;
|
|
219
|
-
it("returns last cell if no contentful cell is found", () => {
|
|
220
|
-
activeCell = { rowIndex: 1, columnIndex: 2 };
|
|
221
|
-
let getValue = (cell) => {
|
|
222
|
-
if (cell.rowIndex === 5) return null;
|
|
223
|
-
return "hello";
|
|
224
|
-
};
|
|
225
|
-
cell = findLastContentfulCell(
|
|
226
|
-
activeCell,
|
|
227
|
-
getValue,
|
|
228
|
-
undefined,
|
|
229
|
-
Direction.Down,
|
|
230
|
-
20
|
|
231
|
-
);
|
|
232
|
-
expect(cell.rowIndex).toBe(4);
|
|
233
|
-
|
|
234
|
-
activeCell = { rowIndex: 20, columnIndex: 2 };
|
|
235
|
-
getValue = (cell) => {
|
|
236
|
-
if (cell.rowIndex === 5) return null;
|
|
237
|
-
return "hello";
|
|
238
|
-
};
|
|
239
|
-
cell = findLastContentfulCell(
|
|
240
|
-
activeCell,
|
|
241
|
-
getValue,
|
|
242
|
-
undefined,
|
|
243
|
-
Direction.Up,
|
|
244
|
-
1
|
|
245
|
-
);
|
|
246
|
-
expect(cell.rowIndex).toBe(6);
|
|
247
|
-
|
|
248
|
-
activeCell = { rowIndex: 1, columnIndex: 2 };
|
|
249
|
-
getValue = (cell) => {
|
|
250
|
-
if (cell.columnIndex === 5) return null;
|
|
251
|
-
return "hello";
|
|
252
|
-
};
|
|
253
|
-
cell = findLastContentfulCell(
|
|
254
|
-
activeCell,
|
|
255
|
-
getValue,
|
|
256
|
-
undefined,
|
|
257
|
-
Direction.Right,
|
|
258
|
-
10
|
|
259
|
-
);
|
|
260
|
-
expect(cell.columnIndex).toBe(4);
|
|
261
|
-
|
|
262
|
-
activeCell = { rowIndex: 1, columnIndex: 20 };
|
|
263
|
-
getValue = (cell) => {
|
|
264
|
-
if (cell.columnIndex === 5) return null;
|
|
265
|
-
return "hello";
|
|
266
|
-
};
|
|
267
|
-
cell = findLastContentfulCell(
|
|
268
|
-
activeCell,
|
|
269
|
-
getValue,
|
|
270
|
-
undefined,
|
|
271
|
-
Direction.Left,
|
|
272
|
-
1
|
|
273
|
-
);
|
|
274
|
-
expect(cell.columnIndex).toBe(6);
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
it("returns same cell if its already in the edge", () => {
|
|
278
|
-
const activeCell = { rowIndex: 1, columnIndex: 2 };
|
|
279
|
-
const getValue = (cell) => {
|
|
280
|
-
if (cell.rowIndex === 5) return "hello";
|
|
281
|
-
return null;
|
|
282
|
-
};
|
|
283
|
-
const cell = findLastContentfulCell(
|
|
284
|
-
activeCell,
|
|
285
|
-
getValue,
|
|
286
|
-
undefined,
|
|
287
|
-
Direction.Down,
|
|
288
|
-
20
|
|
289
|
-
);
|
|
290
|
-
expect(cell.rowIndex).toBe(1);
|
|
291
|
-
});
|
|
292
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
import { renderHook, act } from "@testing-library/react-hooks";
|
|
3
|
-
import usePagination from "../hooks/usePagination";
|
|
4
|
-
|
|
5
|
-
describe("usePagination", () => {
|
|
6
|
-
let options = { pageSize: 10, total: 100 };
|
|
7
|
-
it("is a function", () => {
|
|
8
|
-
expect(typeof usePagination).toBe("function");
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it("sets initialPage to 1", () => {
|
|
12
|
-
const { result } = renderHook(() => usePagination(options));
|
|
13
|
-
expect(result.current.currentPage).toBe(1);
|
|
14
|
-
expect(result.current.totalPages).toBe(10);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("updates currentPage", () => {
|
|
18
|
-
const { result } = renderHook(() => usePagination(options));
|
|
19
|
-
act(() => result.current.nextPage());
|
|
20
|
-
expect(result.current.currentPage).toBe(2);
|
|
21
|
-
act(() => result.current.goToPage(3));
|
|
22
|
-
expect(result.current.currentPage).toBe(3);
|
|
23
|
-
act(() => result.current.goToLast());
|
|
24
|
-
expect(result.current.currentPage).toBe(10);
|
|
25
|
-
act(() => result.current.goToFirst());
|
|
26
|
-
expect(result.current.currentPage).toBe(1);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { renderHook } from "@testing-library/react-hooks";
|
|
2
|
-
import useSelection from "./../hooks/useSelection";
|
|
3
|
-
|
|
4
|
-
describe("useSelection", () => {
|
|
5
|
-
it("is a function", () => {
|
|
6
|
-
expect(typeof useSelection).toBe("function");
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
it("sets initialselection to be empty", () => {
|
|
10
|
-
// @ts-ignore
|
|
11
|
-
const { result } = renderHook(() => useSelection({}));
|
|
12
|
-
expect(result.current.selections).toStrictEqual([]);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it("picks up initialselection", () => {
|
|
16
|
-
const initialSelections = [
|
|
17
|
-
{ bounds: { top: 0, left: 0, right: 0, bottom: 0 } },
|
|
18
|
-
];
|
|
19
|
-
const { result } = renderHook(() =>
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
useSelection({
|
|
22
|
-
initialSelections,
|
|
23
|
-
})
|
|
24
|
-
);
|
|
25
|
-
expect(result.current.selections).toStrictEqual(initialSelections);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { renderHook, act } from "@testing-library/react-hooks";
|
|
2
|
-
import useUndo, { PatchInterface } from "./../hooks/useUndo";
|
|
3
|
-
|
|
4
|
-
type Patch = any;
|
|
5
|
-
|
|
6
|
-
describe("useUndo", () => {
|
|
7
|
-
it("is a function", () => {
|
|
8
|
-
expect(typeof useUndo).toBe("function");
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it("initializes with falsy canUndo and canRedo", () => {
|
|
12
|
-
const { result } = renderHook(() => useUndo());
|
|
13
|
-
expect(result.current.canRedo).toBeFalsy;
|
|
14
|
-
expect(result.current.canUndo).toBeFalsy;
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("can add add to stack", () => {
|
|
18
|
-
const { result } = renderHook(() => useUndo({}));
|
|
19
|
-
const patch: PatchInterface<Patch> = {
|
|
20
|
-
patches: [{ op: "replace", value: "b", path: ["hello"] }],
|
|
21
|
-
inversePatches: [{ op: "replace", value: "a", path: ["hello"] }],
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
act(() => {
|
|
25
|
-
result.current.add(patch);
|
|
26
|
-
});
|
|
27
|
-
expect(result.current.canUndo).toBeTruthy();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("can add undo and redo", () => {
|
|
31
|
-
const { result } = renderHook(() => useUndo({}));
|
|
32
|
-
const patch: PatchInterface<Patch> = {
|
|
33
|
-
patches: [{ op: "replace", value: "b", path: ["hello"] }],
|
|
34
|
-
inversePatches: [{ op: "replace", value: "a", path: ["hello"] }],
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
act(() => {
|
|
38
|
-
result.current.add(patch);
|
|
39
|
-
});
|
|
40
|
-
expect(result.current.canUndo).toBeTruthy();
|
|
41
|
-
act(() => {
|
|
42
|
-
result.current.undo();
|
|
43
|
-
});
|
|
44
|
-
expect(result.current.canUndo).toBeFalsy();
|
|
45
|
-
expect(result.current.canRedo).toBeTruthy();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("calls onundo and onredo", () => {
|
|
49
|
-
const onUndo = jest.fn();
|
|
50
|
-
const onRedo = jest.fn();
|
|
51
|
-
const { result } = renderHook(() => useUndo({ onUndo, onRedo }));
|
|
52
|
-
const patch: PatchInterface<Patch> = {
|
|
53
|
-
patches: [{ op: "replace", value: "b", path: ["hello"] }],
|
|
54
|
-
inversePatches: [{ op: "replace", value: "a", path: ["hello"] }],
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
act(() => {
|
|
58
|
-
result.current.add(patch);
|
|
59
|
-
});
|
|
60
|
-
expect(result.current.canUndo).toBeTruthy();
|
|
61
|
-
act(() => {
|
|
62
|
-
result.current.undo();
|
|
63
|
-
});
|
|
64
|
-
expect(onUndo).toBeCalled();
|
|
65
|
-
expect(onUndo).toBeCalledTimes(1);
|
|
66
|
-
|
|
67
|
-
act(() => {
|
|
68
|
-
result.current.redo();
|
|
69
|
-
});
|
|
70
|
-
expect(onRedo).toBeCalled();
|
|
71
|
-
expect(onRedo).toBeCalledTimes(1);
|
|
72
|
-
});
|
|
73
|
-
});
|