@rowsncolumns/grid 9.0.3 → 13.2.32

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.
Files changed (208) hide show
  1. package/LICENSE.md +100 -0
  2. package/Readme.md +53 -59
  3. package/dist/cjs/Cell.d.ts +35 -0
  4. package/dist/cjs/Cell.d.ts.map +1 -0
  5. package/dist/cjs/Cell.js +29 -0
  6. package/dist/{CellOverlay.d.ts → cjs/CellOverlay.d.ts} +5 -5
  7. package/dist/cjs/CellOverlay.d.ts.map +1 -0
  8. package/dist/cjs/CellOverlay.js +126 -0
  9. package/dist/cjs/Context.d.ts +8 -0
  10. package/dist/cjs/Context.d.ts.map +1 -0
  11. package/dist/cjs/Context.js +13 -0
  12. package/dist/{FillHandle.d.ts → cjs/FillHandle.d.ts} +2 -1
  13. package/dist/cjs/FillHandle.d.ts.map +1 -0
  14. package/dist/cjs/FillHandle.js +26 -0
  15. package/dist/cjs/Grid.d.ts +558 -0
  16. package/dist/cjs/Grid.d.ts.map +1 -0
  17. package/dist/cjs/Grid.js +2446 -0
  18. package/dist/{GridLine.d.ts → cjs/GridLine.d.ts} +2 -1
  19. package/dist/cjs/GridLine.d.ts.map +1 -0
  20. package/dist/cjs/GridLine.js +10 -0
  21. package/dist/cjs/Image.d.ts +11 -0
  22. package/dist/cjs/Image.d.ts.map +1 -0
  23. package/dist/cjs/Image.js +57 -0
  24. package/dist/cjs/MemoizedGrid.d.ts +49 -0
  25. package/dist/cjs/MemoizedGrid.d.ts.map +1 -0
  26. package/dist/cjs/MemoizedGrid.js +105 -0
  27. package/dist/cjs/Selection.d.ts +5 -0
  28. package/dist/cjs/Selection.d.ts.map +1 -0
  29. package/dist/cjs/Selection.js +10 -0
  30. package/dist/{helpers.d.ts → cjs/helpers.d.ts} +59 -39
  31. package/dist/cjs/helpers.d.ts.map +1 -0
  32. package/dist/cjs/helpers.js +1409 -0
  33. package/dist/{hooks → cjs/hooks}/useCopyPaste.d.ts +3 -2
  34. package/dist/cjs/hooks/useCopyPaste.d.ts.map +1 -0
  35. package/dist/cjs/hooks/useCopyPaste.js +230 -0
  36. package/dist/{hooks → cjs/hooks}/useEditable.d.ts +21 -8
  37. package/dist/cjs/hooks/useEditable.d.ts.map +1 -0
  38. package/dist/cjs/hooks/useEditable.js +491 -0
  39. package/dist/{hooks → cjs/hooks}/useFilter.d.ts +3 -2
  40. package/dist/cjs/hooks/useFilter.d.ts.map +1 -0
  41. package/dist/cjs/hooks/useFilter.js +97 -0
  42. package/dist/{hooks → cjs/hooks}/useImage.d.ts +1 -0
  43. package/dist/cjs/hooks/useImage.d.ts.map +1 -0
  44. package/dist/cjs/hooks/useImage.js +80 -0
  45. package/dist/{hooks → cjs/hooks}/usePagination.d.ts +3 -2
  46. package/dist/cjs/hooks/usePagination.d.ts.map +1 -0
  47. package/dist/cjs/hooks/usePagination.js +53 -0
  48. package/dist/{hooks → cjs/hooks}/useSizer.d.ts +28 -29
  49. package/dist/cjs/hooks/useSizer.d.ts.map +1 -0
  50. package/dist/cjs/hooks/useSizer.js +176 -0
  51. package/dist/{hooks → cjs/hooks}/useTooltip.d.ts +2 -1
  52. package/dist/cjs/hooks/useTooltip.d.ts.map +1 -0
  53. package/dist/cjs/hooks/useTooltip.js +82 -0
  54. package/dist/{hooks → cjs/hooks}/useUndo.d.ts +2 -1
  55. package/dist/cjs/hooks/useUndo.d.ts.map +1 -0
  56. package/dist/cjs/hooks/useUndo.js +87 -0
  57. package/dist/cjs/index.d.ts +19 -0
  58. package/dist/cjs/index.d.ts.map +1 -0
  59. package/dist/cjs/index.js +29 -0
  60. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -0
  61. package/dist/{types.d.ts → cjs/types.d.ts} +8 -3
  62. package/dist/cjs/types.d.ts.map +1 -0
  63. package/dist/{types.js → cjs/types.js} +7 -8
  64. package/dist/cjs/utils.d.ts +9 -0
  65. package/dist/cjs/utils.d.ts.map +1 -0
  66. package/dist/cjs/utils.js +58 -0
  67. package/dist/cjs/vitest.config.d.ts +3 -0
  68. package/dist/cjs/vitest.config.d.ts.map +1 -0
  69. package/dist/cjs/vitest.config.js +24 -0
  70. package/dist/esm/Cell.d.ts +35 -0
  71. package/dist/esm/Cell.d.ts.map +1 -0
  72. package/dist/esm/Cell.js +24 -0
  73. package/dist/esm/CellOverlay.d.ts +21 -0
  74. package/dist/esm/CellOverlay.d.ts.map +1 -0
  75. package/dist/esm/CellOverlay.js +120 -0
  76. package/dist/esm/Context.d.ts +8 -0
  77. package/dist/esm/Context.d.ts.map +1 -0
  78. package/dist/esm/Context.js +9 -0
  79. package/dist/esm/FillHandle.d.ts +8 -0
  80. package/dist/esm/FillHandle.d.ts.map +1 -0
  81. package/dist/{FillHandle.js → esm/FillHandle.js} +5 -11
  82. package/dist/esm/Grid.d.ts +558 -0
  83. package/dist/esm/Grid.d.ts.map +1 -0
  84. package/dist/esm/Grid.js +2451 -0
  85. package/dist/esm/GridLine.d.ts +5 -0
  86. package/dist/esm/GridLine.d.ts.map +1 -0
  87. package/dist/esm/GridLine.js +7 -0
  88. package/dist/esm/Image.d.ts +11 -0
  89. package/dist/esm/Image.d.ts.map +1 -0
  90. package/dist/esm/Image.js +53 -0
  91. package/dist/esm/MemoizedGrid.d.ts +49 -0
  92. package/dist/esm/MemoizedGrid.d.ts.map +1 -0
  93. package/dist/esm/MemoizedGrid.js +98 -0
  94. package/dist/esm/Selection.d.ts +5 -0
  95. package/dist/esm/Selection.d.ts.map +1 -0
  96. package/dist/esm/Selection.js +7 -0
  97. package/dist/esm/helpers.d.ts +281 -0
  98. package/dist/esm/helpers.d.ts.map +1 -0
  99. package/dist/esm/helpers.js +1260 -0
  100. package/dist/esm/hooks/useCopyPaste.d.ts +53 -0
  101. package/dist/esm/hooks/useCopyPaste.d.ts.map +1 -0
  102. package/dist/{hooks → esm/hooks}/useCopyPaste.js +40 -46
  103. package/dist/esm/hooks/useEditable.d.ts +253 -0
  104. package/dist/esm/hooks/useEditable.d.ts.map +1 -0
  105. package/dist/esm/hooks/useEditable.js +482 -0
  106. package/dist/esm/hooks/useFilter.d.ts +69 -0
  107. package/dist/esm/hooks/useFilter.d.ts.map +1 -0
  108. package/dist/{hooks → esm/hooks}/useFilter.js +22 -42
  109. package/dist/esm/hooks/useImage.d.ts +13 -0
  110. package/dist/esm/hooks/useImage.d.ts.map +1 -0
  111. package/dist/esm/hooks/useImage.js +76 -0
  112. package/dist/esm/hooks/usePagination.d.ts +69 -0
  113. package/dist/esm/hooks/usePagination.d.ts.map +1 -0
  114. package/dist/esm/hooks/usePagination.js +47 -0
  115. package/dist/esm/hooks/useSizer.d.ts +114 -0
  116. package/dist/esm/hooks/useSizer.d.ts.map +1 -0
  117. package/dist/esm/hooks/useSizer.js +176 -0
  118. package/dist/esm/hooks/useTooltip.d.ts +43 -0
  119. package/dist/esm/hooks/useTooltip.d.ts.map +1 -0
  120. package/dist/esm/hooks/useTooltip.js +80 -0
  121. package/dist/esm/hooks/useUndo.d.ts +36 -0
  122. package/dist/esm/hooks/useUndo.d.ts.map +1 -0
  123. package/dist/{hooks → esm/hooks}/useUndo.js +16 -25
  124. package/dist/esm/index.d.ts +19 -0
  125. package/dist/esm/index.d.ts.map +1 -0
  126. package/dist/esm/index.js +17 -0
  127. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -0
  128. package/dist/esm/types.d.ts +70 -0
  129. package/dist/esm/types.d.ts.map +1 -0
  130. package/dist/esm/types.js +68 -0
  131. package/dist/esm/utils.d.ts +9 -0
  132. package/dist/esm/utils.d.ts.map +1 -0
  133. package/dist/esm/utils.js +104 -0
  134. package/dist/esm/vitest.config.d.ts +3 -0
  135. package/dist/esm/vitest.config.d.ts.map +1 -0
  136. package/dist/esm/vitest.config.js +22 -0
  137. package/package.json +28 -29
  138. package/dist/Cell.d.ts +0 -23
  139. package/dist/Cell.js +0 -55
  140. package/dist/Cell.js.map +0 -1
  141. package/dist/CellOverlay.js +0 -116
  142. package/dist/CellOverlay.js.map +0 -1
  143. package/dist/FillHandle.js.map +0 -1
  144. package/dist/Grid.d.ts +0 -385
  145. package/dist/Grid.js +0 -1684
  146. package/dist/Grid.js.map +0 -1
  147. package/dist/GridLine.js +0 -13
  148. package/dist/GridLine.js.map +0 -1
  149. package/dist/Image.d.ts +0 -8
  150. package/dist/Image.js +0 -50
  151. package/dist/Image.js.map +0 -1
  152. package/dist/Selection.d.ts +0 -4
  153. package/dist/Selection.js +0 -9
  154. package/dist/Selection.js.map +0 -1
  155. package/dist/helpers.js +0 -1033
  156. package/dist/helpers.js.map +0 -1
  157. package/dist/hooks/useCopyPaste.js.map +0 -1
  158. package/dist/hooks/useEditable.js +0 -477
  159. package/dist/hooks/useEditable.js.map +0 -1
  160. package/dist/hooks/useFilter.js.map +0 -1
  161. package/dist/hooks/useImage.js +0 -42
  162. package/dist/hooks/useImage.js.map +0 -1
  163. package/dist/hooks/usePagination.js +0 -73
  164. package/dist/hooks/usePagination.js.map +0 -1
  165. package/dist/hooks/useSelection.d.ts +0 -175
  166. package/dist/hooks/useSelection.js +0 -980
  167. package/dist/hooks/useSelection.js.map +0 -1
  168. package/dist/hooks/useSizer.js +0 -150
  169. package/dist/hooks/useSizer.js.map +0 -1
  170. package/dist/hooks/useTooltip.js +0 -106
  171. package/dist/hooks/useTooltip.js.map +0 -1
  172. package/dist/hooks/useTouch.d.ts +0 -21
  173. package/dist/hooks/useTouch.js +0 -73
  174. package/dist/hooks/useTouch.js.map +0 -1
  175. package/dist/hooks/useUndo.js.map +0 -1
  176. package/dist/index.d.ts +0 -25
  177. package/dist/index.js +0 -61
  178. package/dist/index.js.map +0 -1
  179. package/dist/types.js.map +0 -1
  180. package/dist/utils.d.ts +0 -8
  181. package/dist/utils.js +0 -153
  182. package/dist/utils.js.map +0 -1
  183. package/src/Cell.tsx +0 -100
  184. package/src/CellOverlay.tsx +0 -191
  185. package/src/FillHandle.tsx +0 -37
  186. package/src/Grid.tsx +0 -2677
  187. package/src/GridLine.tsx +0 -23
  188. package/src/Image.tsx +0 -43
  189. package/src/Selection.tsx +0 -9
  190. package/src/helpers.ts +0 -1455
  191. package/src/hooks/useCopyPaste.ts +0 -265
  192. package/src/hooks/useEditable.tsx +0 -945
  193. package/src/hooks/useFilter.tsx +0 -233
  194. package/src/hooks/useImage.ts +0 -57
  195. package/src/hooks/usePagination.tsx +0 -153
  196. package/src/hooks/useSelection.ts +0 -1437
  197. package/src/hooks/useSizer.ts +0 -312
  198. package/src/hooks/useTooltip.tsx +0 -172
  199. package/src/hooks/useTouch.ts +0 -116
  200. package/src/hooks/useUndo.ts +0 -134
  201. package/src/index.tsx +0 -46
  202. package/src/tests/Grid.spec.tsx +0 -47
  203. package/src/tests/helpers.test.ts +0 -292
  204. package/src/tests/usePagination.test.ts +0 -28
  205. package/src/tests/useSelection.test.ts +0 -27
  206. package/src/tests/useUndo.test.ts +0 -73
  207. package/src/types.ts +0 -69
  208. package/src/utils.tsx +0 -287
@@ -0,0 +1,491 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDefaultEditor = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var react_1 = tslib_1.__importStar(require("react"));
6
+ var helpers_1 = require("../helpers");
7
+ var types_1 = require("./../types");
8
+ /**
9
+ * Default cell editor
10
+ * @param props
11
+ */
12
+ var DefaultEditor = function (props) {
13
+ var onChange = props.onChange, onSubmit = props.onSubmit, onCancel = props.onCancel, position = props.position, cell = props.cell, getNextFocusableCell = props.getNextFocusableCell, _a = props.value, value = _a === void 0 ? "" : _a, activeCell = props.activeCell, _b = props.autoFocus, autoFocus = _b === void 0 ? true : _b, onKeyDown = props.onKeyDown, selections = props.selections, scrollPosition = props.scrollPosition, maxWidth = props.maxWidth, maxHeight = props.maxHeight, isFrozenRow = props.isFrozenRow, isFrozenColumn = props.isFrozenColumn, frozenRowOffset = props.frozenRowOffset, frozenColumnOffset = props.frozenColumnOffset, isNewValue = props.isNewValue, rest = tslib_1.__rest(props, ["onChange", "onSubmit", "onCancel", "position", "cell", "getNextFocusableCell", "value", "activeCell", "autoFocus", "onKeyDown", "selections", "scrollPosition", "maxWidth", "maxHeight", "isFrozenRow", "isFrozenColumn", "frozenRowOffset", "frozenColumnOffset", "isNewValue"]);
14
+ var borderWidth = 2;
15
+ var padding = 10; /* 2 + 1 + 1 + 2 + 2 */
16
+ var inputRef = (0, react_1.useRef)(null);
17
+ var _c = position.x, x = _c === void 0 ? 0 : _c, _d = position.y, y = _d === void 0 ? 0 : _d, _e = position.width, width = _e === void 0 ? 0 : _e, _f = position.height, height = _f === void 0 ? 0 : _f;
18
+ var getWidth = (0, react_1.useCallback)(function (text) {
19
+ var _a;
20
+ var textWidth = ((_a = helpers_1.autoSizerCanvas.measureText(text)) === null || _a === void 0 ? void 0 : _a.width) || 0;
21
+ return Math.max(textWidth + padding, width + borderWidth / 2);
22
+ }, [width]);
23
+ (0, react_1.useEffect)(function () {
24
+ setInputWidth(getWidth(value));
25
+ }, [value]);
26
+ var _g = tslib_1.__read((0, react_1.useState)(function () { return getWidth(value); }), 2), inputWidth = _g[0], setInputWidth = _g[1];
27
+ (0, react_1.useEffect)(function () {
28
+ var _a, _b;
29
+ if (!inputRef.current)
30
+ return;
31
+ if (autoFocus)
32
+ inputRef.current.focus();
33
+ /* Focus cursor at the end */
34
+ inputRef.current.selectionStart = (_b = (_a = (0, helpers_1.castToString)(value)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
35
+ }, []);
36
+ var inputHeight = height;
37
+ return (react_1.default.createElement("div", { style: {
38
+ top: y - borderWidth / 2,
39
+ left: x,
40
+ position: "absolute",
41
+ width: inputWidth,
42
+ height: inputHeight + borderWidth,
43
+ padding: borderWidth,
44
+ boxShadow: "0 2px 6px 2px rgba(60,64,67,.15)",
45
+ border: "2px #1a73e8 solid",
46
+ background: "white",
47
+ } },
48
+ react_1.default.createElement("textarea", tslib_1.__assign({ rows: 1, cols: 1, ref: inputRef, value: value, style: {
49
+ font: "12px Arial",
50
+ lineHeight: 1.2,
51
+ width: "100%",
52
+ height: "100%",
53
+ padding: "0 1px",
54
+ margin: 0,
55
+ boxSizing: "border-box",
56
+ borderWidth: 0,
57
+ outline: "none",
58
+ resize: "none",
59
+ overflow: "hidden",
60
+ verticalAlign: "top",
61
+ background: "transparent",
62
+ }, onChange: function (e) {
63
+ onChange === null || onChange === void 0 ? void 0 : onChange(e.target.value, cell);
64
+ }, onKeyDown: function (e) {
65
+ if (!inputRef.current)
66
+ return;
67
+ var isShiftKey = e.nativeEvent.shiftKey;
68
+ var isMetaKey = e.nativeEvent.metaKey;
69
+ var value = inputRef.current.value;
70
+ var isCursorAtEnd = value.length === inputRef.current.selectionEnd;
71
+ var isNewCondition = isNewValue && !isShiftKey && !isMetaKey && isCursorAtEnd;
72
+ // Enter key
73
+ if (e.which === types_1.KeyCodes.Enter) {
74
+ onSubmit &&
75
+ onSubmit(value, cell, getNextFocusableCell === null || getNextFocusableCell === void 0 ? void 0 : getNextFocusableCell(cell, isShiftKey ? types_1.Direction.Up : types_1.Direction.Down));
76
+ }
77
+ if (isNewCondition && e.which === types_1.KeyCodes.Right) {
78
+ onSubmit &&
79
+ onSubmit(value, cell, getNextFocusableCell === null || getNextFocusableCell === void 0 ? void 0 : getNextFocusableCell(cell, types_1.Direction.Right));
80
+ }
81
+ if (isNewCondition && e.which === types_1.KeyCodes.Left) {
82
+ onSubmit &&
83
+ onSubmit(value, cell, getNextFocusableCell === null || getNextFocusableCell === void 0 ? void 0 : getNextFocusableCell(cell, types_1.Direction.Left));
84
+ }
85
+ if (isNewCondition && e.which === types_1.KeyCodes.Up) {
86
+ onSubmit &&
87
+ onSubmit(value, cell, getNextFocusableCell === null || getNextFocusableCell === void 0 ? void 0 : getNextFocusableCell(cell, types_1.Direction.Up));
88
+ }
89
+ if (isNewCondition && e.which === types_1.KeyCodes.Down) {
90
+ onSubmit &&
91
+ onSubmit(value, cell, getNextFocusableCell === null || getNextFocusableCell === void 0 ? void 0 : getNextFocusableCell(cell, types_1.Direction.Down));
92
+ }
93
+ if (e.which === types_1.KeyCodes.Escape) {
94
+ onCancel && onCancel(e);
95
+ }
96
+ if (e.which === types_1.KeyCodes.Tab) {
97
+ e.preventDefault();
98
+ onSubmit &&
99
+ onSubmit(value, cell, getNextFocusableCell === null || getNextFocusableCell === void 0 ? void 0 : getNextFocusableCell(cell, isShiftKey ? types_1.Direction.Left : types_1.Direction.Right));
100
+ }
101
+ onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e);
102
+ } }, rest))));
103
+ };
104
+ var getDefaultEditor = function (cell) { return DefaultEditor; };
105
+ exports.getDefaultEditor = getDefaultEditor;
106
+ var defaultCanEdit = function (cell) { return true; };
107
+ var defaultIsHidden = function (i) { return false; };
108
+ /**
109
+ * Hook to make grid editable
110
+ * @param param
111
+ *
112
+ * TODO:
113
+ * 1. Edit a cell
114
+ * 2. Tab to next cell
115
+ * 3. Enter a value
116
+ * 4. Press down key
117
+ *
118
+ * Moves to incorrect cell
119
+ */
120
+ var useEditable = function (_a) {
121
+ var _b, _c, _d, _e;
122
+ var _f = _a.getEditor, getEditor = _f === void 0 ? exports.getDefaultEditor : _f, gridRef = _a.gridRef, getValue = _a.getValue, onChange = _a.onChange, onSubmit = _a.onSubmit, onCancel = _a.onCancel, onDelete = _a.onDelete, _g = _a.selections, selections = _g === void 0 ? [] : _g, activeCell = _a.activeCell, _h = _a.canEdit, canEdit = _h === void 0 ? defaultCanEdit : _h, _j = _a.frozenRows, frozenRows = _j === void 0 ? 0 : _j, _k = _a.frozenColumns, frozenColumns = _k === void 0 ? 0 : _k, _l = _a.hideOnBlur, hideOnBlur = _l === void 0 ? true : _l, _m = _a.isHiddenRow, isHiddenRow = _m === void 0 ? defaultIsHidden : _m, _o = _a.isHiddenColumn, isHiddenColumn = _o === void 0 ? defaultIsHidden : _o, rowCount = _a.rowCount, columnCount = _a.columnCount, _p = _a.selectionTopBound, selectionTopBound = _p === void 0 ? 0 : _p, _q = _a.selectionBottomBound, selectionBottomBound = _q === void 0 ? rowCount - 1 : _q, _r = _a.selectionLeftBound, selectionLeftBound = _r === void 0 ? 0 : _r, _s = _a.selectionRightBound, selectionRightBound = _s === void 0 ? columnCount - 1 : _s, editorProps = _a.editorProps, onBeforeEdit = _a.onBeforeEdit, onKeyDown = _a.onKeyDown, _t = _a.sticky, sticky = _t === void 0 ? false : _t;
123
+ var _u = tslib_1.__read((0, react_1.useState)(false), 2), isEditorShown = _u[0], setShowEditor = _u[1];
124
+ var _v = tslib_1.__read((0, react_1.useState)(""), 2), value = _v[0], setValue = _v[1];
125
+ var _w = tslib_1.__read((0, react_1.useState)({
126
+ x: 0,
127
+ y: 0,
128
+ width: 0,
129
+ height: 0,
130
+ }), 2), position = _w[0], setPosition = _w[1];
131
+ var currentActiveCellRef = (0, react_1.useRef)(null);
132
+ var initialActiveCell = (0, react_1.useRef)(undefined);
133
+ var _x = tslib_1.__read((0, react_1.useState)({
134
+ scrollLeft: 0,
135
+ scrollTop: 0,
136
+ }), 2), scrollPosition = _x[0], setScrollPosition = _x[1];
137
+ var _y = tslib_1.__read((0, react_1.useState)(true), 2), autoFocus = _y[0], setAutoFocus = _y[1];
138
+ var isDirtyRef = (0, react_1.useRef)(false);
139
+ var isEnteringNewValue = (0, react_1.useRef)(false);
140
+ var currentValueRef = (0, react_1.useRef)(value);
141
+ var initialValueRef = (0, react_1.useRef)(undefined);
142
+ var maxEditorDimensionsRef = (0, react_1.useRef)(undefined);
143
+ var showEditor = (0, react_1.useCallback)(function () { return setShowEditor(true); }, []);
144
+ var hideEditor = (0, react_1.useCallback)(function () {
145
+ setShowEditor(false);
146
+ currentActiveCellRef.current = null;
147
+ }, []);
148
+ var focusGrid = (0, react_1.useCallback)(function () {
149
+ requestAnimationFrame(function () { return gridRef.current && gridRef.current.focus(); });
150
+ }, []);
151
+ /* Keep ref in sync */
152
+ (0, react_1.useEffect)(function () {
153
+ currentValueRef.current = value;
154
+ });
155
+ /**
156
+ * Make a cell editable
157
+ * @param coords
158
+ * @param initialValue
159
+ */
160
+ var makeEditable = (0, react_1.useCallback)(function (coords, initialValue, autoFocus) {
161
+ var _a, _b, _c, _d;
162
+ if (autoFocus === void 0) { autoFocus = true; }
163
+ if (!gridRef.current)
164
+ return;
165
+ /* Get actual coords for merged cells */
166
+ coords = gridRef.current.getActualCellCoords(coords);
167
+ /* Check if its the same cell */
168
+ if ((0, helpers_1.isEqualCells)(coords, currentActiveCellRef.current)) {
169
+ return;
170
+ }
171
+ /* Call on before edit */
172
+ if (canEdit(coords)) {
173
+ /* Let user modify coords before edit */
174
+ onBeforeEdit === null || onBeforeEdit === void 0 ? void 0 : onBeforeEdit(coords);
175
+ /* Focus */
176
+ (_a = gridRef.current) === null || _a === void 0 ? void 0 : _a.scrollToCell(coords);
177
+ currentActiveCellRef.current = coords;
178
+ /* Get offsets */
179
+ var pos = gridRef.current.getCellOffsetFromCoords(coords);
180
+ if ((0, helpers_1.isNull)(pos)) {
181
+ return;
182
+ }
183
+ var scrollPosition_1 = gridRef.current.getScrollPosition();
184
+ var cellValue = getValue === null || getValue === void 0 ? void 0 : getValue(coords.rowIndex, coords.columnIndex);
185
+ var value_1 = (_b = initialValue !== null && initialValue !== void 0 ? initialValue : cellValue) !== null && _b !== void 0 ? _b : "";
186
+ var cellPosition = sticky
187
+ ? // Editor is rendered outside the <Grid /> component
188
+ // If the user has scrolled down, and then activate the editor, we will need to adjust the position
189
+ // of the sticky editor accordingly
190
+ // Subsequent scroll events has no effect, cos of sticky option
191
+ getCellPosition(pos, scrollPosition_1)
192
+ : pos;
193
+ /**
194
+ * Set max editor ref based on grid container
195
+ */
196
+ var _e = gridRef.current.getDimensions(), containerWidth = _e.containerWidth, containerHeight = _e.containerHeight;
197
+ maxEditorDimensionsRef.current = {
198
+ height: containerHeight - ((_c = cellPosition.y) !== null && _c !== void 0 ? _c : 0),
199
+ width: containerWidth - ((_d = cellPosition.x) !== null && _d !== void 0 ? _d : 0),
200
+ };
201
+ /**
202
+ * If the user has entered a value in the cell, mark it as dirty
203
+ * So that during mousedown, onSubmit gets called
204
+ */
205
+ isEnteringNewValue.current =
206
+ initialValue !== void 0 || cellValue === void 0;
207
+ isDirtyRef.current = !!initialValue;
208
+ initialValueRef.current = initialValue !== null && initialValue !== void 0 ? initialValue : value_1;
209
+ /* Trigger onChange handlers */
210
+ setValue(value_1);
211
+ onChange === null || onChange === void 0 ? void 0 : onChange(value_1, coords);
212
+ setAutoFocus(autoFocus);
213
+ setScrollPosition(scrollPosition_1);
214
+ setPosition(cellPosition);
215
+ showEditor();
216
+ }
217
+ }, [frozenRows, frozenColumns, onBeforeEdit, canEdit, sticky, getValue]);
218
+ /* Frozen flags */
219
+ var isFrozenRow = currentActiveCellRef.current &&
220
+ ((_b = currentActiveCellRef.current) === null || _b === void 0 ? void 0 : _b.rowIndex) < frozenRows;
221
+ var isFrozenColumn = currentActiveCellRef.current &&
222
+ ((_c = currentActiveCellRef.current) === null || _c === void 0 ? void 0 : _c.columnIndex) < frozenColumns;
223
+ /**
224
+ * Get current cell position based on scroll position
225
+ * @param position
226
+ * @param scrollPosition
227
+ */
228
+ var getCellPosition = function (position, scrollPosition) {
229
+ if (!currentActiveCellRef.current)
230
+ return { x: 0, y: 0, width: 0, height: 0 };
231
+ return tslib_1.__assign(tslib_1.__assign({}, position), { x: position.x -
232
+ (isFrozenColumn ? 0 : scrollPosition.scrollLeft), y: position.y - (isFrozenRow ? 0 : scrollPosition.scrollTop) });
233
+ };
234
+ /* Activate edit mode */
235
+ var handleDoubleClick = (0, react_1.useCallback)(function (e) {
236
+ if (!gridRef.current)
237
+ return;
238
+ var coords = gridRef.current.getCellCoordsFromOffset(e.nativeEvent.clientX, e.nativeEvent.clientY);
239
+ if (!coords)
240
+ return;
241
+ var rowIndex = coords.rowIndex, columnIndex = coords.columnIndex;
242
+ makeEditable({ rowIndex: rowIndex, columnIndex: columnIndex });
243
+ }, [makeEditable, frozenRows, frozenColumns]);
244
+ var isSelectionKey = (0, react_1.useCallback)(function (keyCode) {
245
+ return ([
246
+ types_1.KeyCodes.Right,
247
+ types_1.KeyCodes.Left,
248
+ types_1.KeyCodes.Up,
249
+ types_1.KeyCodes.Down,
250
+ types_1.KeyCodes.Meta,
251
+ types_1.KeyCodes.Escape,
252
+ types_1.KeyCodes.Tab,
253
+ types_1.KeyCodes.Home,
254
+ types_1.KeyCodes.End,
255
+ types_1.KeyCodes.CapsLock,
256
+ types_1.KeyCodes.PageDown,
257
+ types_1.KeyCodes.PageUp,
258
+ types_1.KeyCodes.ScrollLock,
259
+ types_1.KeyCodes.NumLock,
260
+ types_1.KeyCodes.Insert,
261
+ types_1.KeyCodes.Pause,
262
+ ].indexOf(keyCode) !== -1 ||
263
+ // Exclude Function keys
264
+ (keyCode >= types_1.KeyCodes.F1 && keyCode <= types_1.KeyCodes.F12));
265
+ }, []);
266
+ /**
267
+ * Helper function to keep track of
268
+ * the first cell that the user started editing
269
+ * @param cell
270
+ */
271
+ var setInitialActiveCell = function (cell) {
272
+ initialActiveCell.current = cell;
273
+ };
274
+ var handleKeyDown = (0, react_1.useCallback)(function (e) {
275
+ var keyCode = e.nativeEvent.keyCode;
276
+ var isEnter = keyCode === types_1.KeyCodes.Enter;
277
+ if (keyCode === types_1.KeyCodes.Tab && !initialActiveCell.current) {
278
+ setInitialActiveCell(activeCell);
279
+ }
280
+ // if (isArrowKey(keyCode)) {
281
+ // setInitialActiveCell(null);
282
+ // }
283
+ if (isSelectionKey(keyCode) ||
284
+ e.nativeEvent.ctrlKey ||
285
+ (e.nativeEvent.shiftKey &&
286
+ (e.nativeEvent.key === "Shift" ||
287
+ e.nativeEvent.which === types_1.KeyCodes.SPACE)) ||
288
+ e.nativeEvent.metaKey ||
289
+ e.nativeEvent.which === types_1.KeyCodes.ALT)
290
+ return;
291
+ /* If user has not made any selection yet */
292
+ if (!activeCell)
293
+ return;
294
+ var rowIndex = activeCell.rowIndex, columnIndex = activeCell.columnIndex;
295
+ if (keyCode === types_1.KeyCodes.Delete || keyCode === types_1.KeyCodes.BackSpace) {
296
+ // TODO: onbefore delete
297
+ onDelete && onDelete(activeCell, selections);
298
+ e.preventDefault();
299
+ return;
300
+ }
301
+ var initialValue = isEnter // Enter key
302
+ ? undefined
303
+ : e.nativeEvent.key;
304
+ /* Open the editor */
305
+ makeEditable({ rowIndex: rowIndex, columnIndex: columnIndex }, initialValue);
306
+ /* Prevent the first keystroke */
307
+ e.preventDefault();
308
+ }, [getValue, selections, activeCell, onDelete]);
309
+ /**
310
+ * Get next focusable cell
311
+ * Respects selection bounds
312
+ */
313
+ var getNextFocusableCell = (0, react_1.useCallback)(function (currentCell, direction) {
314
+ var _a, _b, _c, _d, _e;
315
+ if (direction === void 0) { direction = types_1.Direction.Right; }
316
+ /* Next immediate cell */
317
+ var range = (_a = gridRef.current) === null || _a === void 0 ? void 0 : _a.getCellBounds(currentCell);
318
+ if (!range)
319
+ return null;
320
+ var nextActiveCell;
321
+ switch (direction) {
322
+ case types_1.Direction.Right: {
323
+ var columnIndex = (0, helpers_1.clampIndex)(Math.min(range.endColumnIndex + 1, selectionRightBound), isHiddenColumn, direction);
324
+ nextActiveCell = {
325
+ rowIndex: range.startRowIndex,
326
+ columnIndex: columnIndex,
327
+ };
328
+ break;
329
+ }
330
+ case types_1.Direction.Up: {
331
+ var rowIndex = (0, helpers_1.clampIndex)(Math.max(range.startRowIndex - 1, selectionTopBound), isHiddenRow, direction);
332
+ nextActiveCell = {
333
+ rowIndex: rowIndex,
334
+ columnIndex: range.startColumnIndex,
335
+ };
336
+ break;
337
+ }
338
+ case types_1.Direction.Left: {
339
+ var columnIndex = (0, helpers_1.clampIndex)(Math.max(range.startColumnIndex - 1, selectionLeftBound), isHiddenColumn, direction);
340
+ nextActiveCell = {
341
+ rowIndex: range.startRowIndex,
342
+ columnIndex: columnIndex,
343
+ };
344
+ break;
345
+ }
346
+ case types_1.Direction.Down: {
347
+ // Down
348
+ var rowIndex = (0, helpers_1.clampIndex)(Math.min(((_c = (_b = initialActiveCell.current) === null || _b === void 0 ? void 0 : _b.rowIndex) !== null && _c !== void 0 ? _c : range.endRowIndex) + 1, selectionBottomBound), isHiddenRow, direction);
349
+ nextActiveCell = {
350
+ rowIndex: rowIndex,
351
+ columnIndex: (_e = (_d = initialActiveCell.current) === null || _d === void 0 ? void 0 : _d.columnIndex) !== null && _e !== void 0 ? _e : range.startColumnIndex,
352
+ };
353
+ break;
354
+ }
355
+ }
356
+ if (direction === types_1.Direction.Right && !initialActiveCell.current) {
357
+ setInitialActiveCell(currentCell);
358
+ }
359
+ if (direction === types_1.Direction.Down) {
360
+ /* Move to the next row + cell */
361
+ setInitialActiveCell(null);
362
+ }
363
+ /* If user has selected some cells and active cell is within this selection */
364
+ if (selections.length && currentCell && gridRef.current) {
365
+ var range_1 = selections[selections.length - 1].range;
366
+ var activeCellBounds = gridRef.current.getCellBounds(currentCell);
367
+ var nextCell = (0, helpers_1.findNextCellWithinBounds)(activeCellBounds, range_1, direction);
368
+ if (nextCell)
369
+ nextActiveCell = nextCell;
370
+ }
371
+ return nextActiveCell;
372
+ }, [
373
+ selections,
374
+ isHiddenRow,
375
+ isHiddenColumn,
376
+ selectionBottomBound,
377
+ selectionTopBound,
378
+ ]);
379
+ /* Save the value */
380
+ var handleSubmit = (0, react_1.useCallback)(function (value, activeCell, nextActiveCell) {
381
+ /**
382
+ * Hide the editor first, so that we can handle onBlur events
383
+ * 1. Editor hides -> Submit
384
+ * 2. If user clicks outside the grid, onBlur is called, if there is a activeCell, we do another submit
385
+ */
386
+ hideEditor();
387
+ /* Save the new value */
388
+ onSubmit && onSubmit(value, activeCell, nextActiveCell);
389
+ /* Keep the focus */
390
+ focusGrid();
391
+ }, [onSubmit]);
392
+ /* When the input is blurred out */
393
+ var handleCancel = (0, react_1.useCallback)(function (e) {
394
+ hideEditor();
395
+ onCancel && onCancel(e);
396
+ /* Keep the focus back in the grid */
397
+ focusGrid();
398
+ }, [onCancel]);
399
+ var handleMouseDown = (0, react_1.useCallback)(function (e) {
400
+ /* Persistent input, hides only during Enter key or during submit or cancel calls */
401
+ if (!hideOnBlur) {
402
+ return;
403
+ }
404
+ if (currentActiveCellRef.current) {
405
+ if (isDirtyRef.current) {
406
+ handleSubmit(currentValueRef.current, currentActiveCellRef.current);
407
+ }
408
+ else {
409
+ handleCancel();
410
+ }
411
+ }
412
+ setInitialActiveCell(null);
413
+ }, [hideOnBlur, handleSubmit, handleCancel]);
414
+ var handleChange = (0, react_1.useCallback)(function (newValue, activeCell) {
415
+ /**
416
+ * Make sure we dont call onChange if initialValue is set
417
+ * This is to accomodate for editor that fire onChange during initialvalue
418
+ * Eg: Slate <Editor value='' onChange />
419
+ */
420
+ if (initialValueRef.current !== void 0 &&
421
+ initialValueRef.current === newValue) {
422
+ initialValueRef.current = void 0;
423
+ return;
424
+ }
425
+ if (!currentActiveCellRef.current)
426
+ return;
427
+ /* Check if the value has changed. Used to conditionally submit if editor is not in focus */
428
+ isDirtyRef.current = newValue !== value;
429
+ setValue(newValue);
430
+ onChange === null || onChange === void 0 ? void 0 : onChange(newValue, activeCell);
431
+ }, [value]);
432
+ var handleScroll = (0, react_1.useCallback)(function (scrollPos) {
433
+ if (!currentActiveCellRef.current)
434
+ return;
435
+ setScrollPosition(scrollPos);
436
+ }, []);
437
+ /* Editor */
438
+ var editingCell = currentActiveCellRef.current;
439
+ var Editor = (0, react_1.useMemo)(function () {
440
+ return editingCell
441
+ ? getEditor(editingCell) || (0, exports.getDefaultEditor)(editingCell)
442
+ : null;
443
+ }, [editingCell]);
444
+ var handleBlur = (0, react_1.useCallback)(function (e) {
445
+ if (currentActiveCellRef.current) {
446
+ /* Keep the focus */
447
+ focusGrid();
448
+ }
449
+ }, []);
450
+ var finalCellPosition = (0, react_1.useMemo)(function () {
451
+ /**
452
+ * Since the editor is sticky,
453
+ * we dont need to adjust the position,
454
+ * as scrollposition wont move the editor
455
+ *
456
+ * When the editor is first active, in makeEditable,
457
+ * we accomodate for the initial scrollPosition
458
+ */
459
+ if (sticky) {
460
+ return position;
461
+ }
462
+ /**
463
+ * If editor is not sticky, keep adjusting
464
+ * its position to accomodate for scroll
465
+ */
466
+ return getCellPosition(position, scrollPosition);
467
+ }, [sticky, position, scrollPosition, frozenColumns, frozenRows]);
468
+ /* Get offset of frozen rows and columns */
469
+ var frozenRowOffset = (0, react_1.useMemo)(function () { var _a; return (_a = gridRef.current) === null || _a === void 0 ? void 0 : _a.getRowOffset(frozenRows); }, [frozenRows]);
470
+ var frozenColumnOffset = (0, react_1.useMemo)(function () { var _a; return (_a = gridRef.current) === null || _a === void 0 ? void 0 : _a.getColumnOffset(frozenColumns); }, [frozenColumns]);
471
+ var editorComponent = isEditorShown && Editor ? (react_1.default.createElement(Editor, tslib_1.__assign({}, editorProps === null || editorProps === void 0 ? void 0 : editorProps(), {
472
+ /* This is the cell that is currently being edited */
473
+ cell: editingCell, activeCell: activeCell, autoFocus: autoFocus, value: value, isNewValue: isEnteringNewValue.current, selections: selections, onChange: handleChange, onSubmit: handleSubmit, onCancel: handleCancel, position: finalCellPosition, scrollPosition: scrollPosition, getNextFocusableCell: getNextFocusableCell, onBlur: handleBlur, onKeyDown: onKeyDown, maxWidth: (_d = maxEditorDimensionsRef.current) === null || _d === void 0 ? void 0 : _d.width, maxHeight: (_e = maxEditorDimensionsRef.current) === null || _e === void 0 ? void 0 : _e.height, isFrozenRow: isFrozenRow, isFrozenColumn: isFrozenColumn, frozenRowOffset: frozenRowOffset, frozenColumnOffset: frozenColumnOffset }))) : null;
474
+ return {
475
+ editorComponent: editorComponent,
476
+ onDoubleClick: handleDoubleClick,
477
+ onKeyDown: handleKeyDown,
478
+ getNextFocusableCell: getNextFocusableCell,
479
+ isEditInProgress: !!editingCell,
480
+ editingCell: editingCell,
481
+ makeEditable: makeEditable,
482
+ setValue: handleChange,
483
+ hideEditor: hideEditor,
484
+ showEditor: showEditor,
485
+ submitEditor: handleSubmit,
486
+ cancelEditor: handleCancel,
487
+ onMouseDown: handleMouseDown,
488
+ onScroll: handleScroll,
489
+ };
490
+ };
491
+ exports.default = useEditable;
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
- import { CellInterface, GridRef, AreaProps, AreaStyle } from "./../Grid";
2
+ import type { AreaStyle, CellInterface, GridRange, GridRef } from "./../Grid";
3
3
  export interface FilterView {
4
- bounds: AreaProps;
4
+ bounds: GridRange;
5
5
  filters?: Filter;
6
6
  style?: AreaStyle;
7
7
  title?: string;
@@ -66,3 +66,4 @@ export interface FilterState {
66
66
  */
67
67
  declare const useFilter: ({ getFilterComponent, gridRef, width, offset, getValue, frozenRows, frozenColumns, }: FilterProps) => FilterResults;
68
68
  export default useFilter;
69
+ //# sourceMappingURL=useFilter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFilter.d.ts","sourceRoot":"","sources":["../../../hooks/useFilter.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyC,MAAM,OAAO,CAAC;AAG9D,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EAEb,SAAS,EACT,OAAO,EACR,MAAM,WAAW,CAAC;AAEnB,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,SAAS,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;AACtD,MAAM,MAAM,gBAAgB,CAAC,CAAC,GAAG,MAAM,GAAG,MAAM,IAAI;IAClD,SAAS,CAAC,EAAE,yBAAyB,CAAC,CAAC,CAAC,CAAC;IACzC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;IACb,IAAI,CAAC,EAAE,aAAa,CAAC;CACtB,CAAC;AACF,MAAM,MAAM,eAAe,GAAG,qBAAqB,GAAG,sBAAsB,CAAC;AAC7E,MAAM,MAAM,yBAAyB,CAAC,CAAC,GAAG,MAAM,GAAG,MAAM,IAAI;IAC3D,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;CACd,CAAC;AACF,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,MAAM,CAAC;AAC3C,MAAM,MAAM,sBAAsB,GAC9B,SAAS,GACT,YAAY,GACZ,SAAS,GACT,YAAY,GACZ,OAAO,GACP,UAAU,GACV,aAAa,GACb,UAAU,GACV,oBAAoB,GACpB,iBAAiB,CAAC;AAEtB,MAAM,MAAM,qBAAqB,GAC7B,cAAc,GACd,iBAAiB,GACjB,gBAAgB,GAChB,mBAAmB,GACnB,gBAAgB,GAChB,mBAAmB,GACnB,gBAAgB,GAChB,cAAc,GACd,WAAW,CAAC;AAEhB,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,kBAAkB,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI,KAAK,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC;IAC9E;;OAEG;IACH,OAAO,EAAE,KAAK,CAAC,gBAAgB,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;IAChD;;OAEG;IACH,QAAQ,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,GAAG,CAAC;IACvC;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,eAAe,EAAE,KAAK,CAAC,SAAS,CAAC;IACjC;;OAEG;IACH,UAAU,EAAE,CACV,IAAI,EAAE,aAAa,EACnB,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,UAAU,EACtB,MAAM,CAAC,EAAE,gBAAgB,KACtB,IAAI,CAAC;IACV;;OAEG;IACH,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB;AAKD,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,QAAA,MAAM,SAAS,GAAI,sFAQhB,WAAW,KAAG,aA0HhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var tslib_1 = require("tslib");
4
+ var react_1 = tslib_1.__importStar(require("react"));
5
+ var helpers_1 = require("../helpers");
6
+ /* Default filter component */
7
+ var getDefaultFilerComponent = function (cell) { return null; };
8
+ /**
9
+ * Use filter hook
10
+ * @param param0
11
+ */
12
+ var useFilter = function (_a) {
13
+ var _b = _a.getFilterComponent, getFilterComponent = _b === void 0 ? getDefaultFilerComponent : _b, gridRef = _a.gridRef, _c = _a.width, width = _c === void 0 ? 220 : _c, _d = _a.offset, offset = _d === void 0 ? 20 : _d, getValue = _a.getValue, _e = _a.frozenRows, frozenRows = _e === void 0 ? 0 : _e, _f = _a.frozenColumns, frozenColumns = _f === void 0 ? 0 : _f;
14
+ var _g = tslib_1.__read((0, react_1.useState)(null), 2), filterCell = _g[0], setFilterCell = _g[1];
15
+ var _h = tslib_1.__read((0, react_1.useState)(false), 2), isFilterVisible = _h[0], setIsFilterVisible = _h[1];
16
+ var _j = tslib_1.__read((0, react_1.useState)(null), 2), currentFilter = _j[0], setCurrentFilter = _j[1];
17
+ var _k = tslib_1.__read((0, react_1.useState)({
18
+ x: 0,
19
+ y: 0,
20
+ width: 0,
21
+ height: 0,
22
+ }), 2), position = _k[0], setPosition = _k[1];
23
+ var FilterComponent = (0, react_1.useMemo)(function () {
24
+ return getFilterComponent(filterCell);
25
+ }, [filterCell]);
26
+ /**
27
+ * Show filter panel
28
+ */
29
+ var handleShowFilter = (0, react_1.useCallback)(function (coords, index, filterView, filter) {
30
+ if (!gridRef.current)
31
+ return;
32
+ /* Get actual coords for merged cells */
33
+ coords = gridRef.current.getActualCellCoords(coords);
34
+ /* Get scroll position */
35
+ var scrollPosition = gridRef.current.getScrollPosition();
36
+ /* Get cell position */
37
+ var pos = gridRef.current.getCellOffsetFromCoords(coords);
38
+ /* Check if its frozen */
39
+ var isFrozenColumn = coords.columnIndex < frozenColumns;
40
+ var isFrozenRow = coords.rowIndex < frozenRows;
41
+ if ((0, helpers_1.isNull)(pos)) {
42
+ return;
43
+ }
44
+ /* Set cell position */
45
+ setPosition(function (prev) {
46
+ var left = pos.x;
47
+ var top = pos.y;
48
+ var cellWidth = pos.width;
49
+ return tslib_1.__assign(tslib_1.__assign({}, prev), { x: left +
50
+ cellWidth -
51
+ (isFrozenColumn ? 0 : scrollPosition.scrollLeft) <
52
+ width
53
+ ? left +
54
+ cellWidth -
55
+ offset -
56
+ (isFrozenColumn ? 0 : scrollPosition.scrollLeft)
57
+ : left +
58
+ cellWidth -
59
+ (isFrozenColumn ? 0 : scrollPosition.scrollLeft) -
60
+ width, y: top - (isFrozenRow ? 0 : scrollPosition.scrollTop) + offset });
61
+ });
62
+ /* Set filter cell */
63
+ setFilterCell(coords);
64
+ /* set current filter */
65
+ setCurrentFilter({ filter: filter, filterView: filterView, index: index });
66
+ /* Show filter */
67
+ showFilter();
68
+ }, [frozenRows, frozenColumns]);
69
+ var hideFilter = (0, react_1.useCallback)(function () {
70
+ setIsFilterVisible(false);
71
+ }, []);
72
+ var showFilter = (0, react_1.useCallback)(function () {
73
+ setIsFilterVisible(true);
74
+ }, []);
75
+ var values = (0, react_1.useMemo)(function () {
76
+ if (!filterCell || !currentFilter)
77
+ return [];
78
+ var filterView = currentFilter.filterView;
79
+ var columnIndex = filterCell.columnIndex;
80
+ var bounds = filterView.bounds;
81
+ var filterValues = new Set();
82
+ for (var i = bounds.startRowIndex + 1; i <= bounds.endRowIndex; i++) {
83
+ var cell = { rowIndex: i, columnIndex: columnIndex };
84
+ var text = getValue(cell);
85
+ var value = (0, helpers_1.isNull)(text) ? "" : text;
86
+ filterValues.add(value);
87
+ }
88
+ return Array.from(filterValues);
89
+ }, [filterCell, currentFilter]);
90
+ var filterComponent = isFilterVisible && FilterComponent ? (react_1.default.createElement(FilterComponent, { position: position, width: width, values: values, index: currentFilter === null || currentFilter === void 0 ? void 0 : currentFilter.index, filterView: currentFilter === null || currentFilter === void 0 ? void 0 : currentFilter.filterView, filter: currentFilter === null || currentFilter === void 0 ? void 0 : currentFilter.filter, columnIndex: filterCell === null || filterCell === void 0 ? void 0 : filterCell.columnIndex, rowIndex: filterCell === null || filterCell === void 0 ? void 0 : filterCell.rowIndex, onRequestClose: hideFilter, onRequestShow: handleShowFilter })) : null;
91
+ return {
92
+ filterComponent: filterComponent,
93
+ showFilter: handleShowFilter,
94
+ hideFilter: hideFilter,
95
+ };
96
+ };
97
+ exports.default = useFilter;
@@ -10,3 +10,4 @@ export interface UseImageResults {
10
10
  }
11
11
  declare const useImage: ({ url, crossOrigin }: UseImageProps) => UseImageResults;
12
12
  export default useImage;
13
+ //# sourceMappingURL=useImage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useImage.d.ts","sourceRoot":"","sources":["../../../hooks/useImage.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,EAAE,gBAAgB,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAmDD,QAAA,MAAM,QAAQ,GAAI,sBAAsB,aAAa,oBAgDpD,CAAC;AAEF,eAAe,QAAQ,CAAC"}