@macrostrat/data-sheet 3.1.0 → 4.0.0-dev2

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 (184) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/actions/builtin.cjs +56 -0
  3. package/dist/actions/builtin.cjs.map +1 -0
  4. package/dist/actions/builtin.d.ts +15 -0
  5. package/dist/actions/builtin.js +56 -0
  6. package/dist/actions/builtin.js.map +1 -0
  7. package/dist/actions/clipboard.cjs +250 -0
  8. package/dist/actions/clipboard.cjs.map +1 -0
  9. package/dist/actions/clipboard.d.ts +42 -0
  10. package/dist/actions/clipboard.js +250 -0
  11. package/dist/actions/clipboard.js.map +1 -0
  12. package/dist/actions/filters.cjs +123 -0
  13. package/dist/actions/filters.cjs.map +1 -0
  14. package/dist/actions/filters.d.ts +6 -0
  15. package/dist/actions/filters.js +123 -0
  16. package/dist/actions/filters.js.map +1 -0
  17. package/dist/actions/index.d.ts +6 -0
  18. package/dist/actions/selection.cjs +194 -0
  19. package/dist/actions/selection.cjs.map +1 -0
  20. package/dist/actions/selection.d.ts +40 -0
  21. package/dist/actions/selection.js +192 -0
  22. package/dist/actions/selection.js.map +1 -0
  23. package/dist/actions/toolbar.cjs +171 -0
  24. package/dist/actions/toolbar.cjs.map +1 -0
  25. package/dist/actions/toolbar.d.ts +10 -0
  26. package/dist/actions/toolbar.js +171 -0
  27. package/dist/actions/toolbar.js.map +1 -0
  28. package/dist/actions/toolbar.module.sass.cjs +22 -0
  29. package/dist/actions/toolbar.module.sass.cjs.map +1 -0
  30. package/dist/actions/toolbar.module.sass.js +20 -0
  31. package/dist/actions/toolbar.module.sass.js.map +1 -0
  32. package/dist/actions/types.d.ts +143 -0
  33. package/dist/cell-renderer.cjs +44 -41
  34. package/dist/cell-renderer.cjs.map +1 -1
  35. package/dist/cell-renderer.d.ts +1 -6
  36. package/dist/cell-renderer.js +45 -42
  37. package/dist/cell-renderer.js.map +1 -1
  38. package/dist/components/actions.module.sass.cjs +3 -3
  39. package/dist/components/actions.module.sass.js +2 -2
  40. package/dist/components/colors.cjs +20 -16
  41. package/dist/components/colors.cjs.map +1 -1
  42. package/dist/components/colors.d.ts +3 -2
  43. package/dist/components/colors.js +20 -16
  44. package/dist/components/colors.js.map +1 -1
  45. package/dist/components/editor-popup.cjs +4 -3
  46. package/dist/components/editor-popup.cjs.map +1 -1
  47. package/dist/components/editor-popup.js +4 -3
  48. package/dist/components/editor-popup.js.map +1 -1
  49. package/dist/components/index.d.ts +1 -0
  50. package/dist/components/main.module.sass.cjs +12 -12
  51. package/dist/components/main.module.sass.js +11 -11
  52. package/dist/components/text-areas.cjs +23 -18
  53. package/dist/components/text-areas.cjs.map +1 -1
  54. package/dist/components/text-areas.d.ts +8 -4
  55. package/dist/components/text-areas.js +20 -13
  56. package/dist/components/text-areas.js.map +1 -1
  57. package/dist/components/view-info.cjs +18 -0
  58. package/dist/components/view-info.cjs.map +1 -0
  59. package/dist/components/view-info.d.ts +1 -0
  60. package/dist/components/view-info.js +18 -0
  61. package/dist/components/view-info.js.map +1 -0
  62. package/dist/core.cjs +184 -156
  63. package/dist/core.cjs.map +1 -1
  64. package/dist/core.d.ts +14 -1
  65. package/dist/core.js +187 -157
  66. package/dist/core.js.map +1 -1
  67. package/dist/data-sheet.css +181 -43
  68. package/dist/index.cjs +43 -13
  69. package/dist/index.cjs.map +1 -1
  70. package/dist/index.d.ts +1 -0
  71. package/dist/index.js +43 -10
  72. package/dist/index.js.map +1 -1
  73. package/dist/main.module.sass.cjs +15 -14
  74. package/dist/main.module.sass.cjs.map +1 -1
  75. package/dist/main.module.sass.js +14 -13
  76. package/dist/main.module.sass.js.map +1 -1
  77. package/dist/notifications.cjs +19 -0
  78. package/dist/notifications.cjs.map +1 -0
  79. package/dist/notifications.d.ts +9 -0
  80. package/dist/notifications.js +19 -0
  81. package/dist/notifications.js.map +1 -0
  82. package/dist/postgrest-table/data-loaders.cjs +181 -104
  83. package/dist/postgrest-table/data-loaders.cjs.map +1 -1
  84. package/dist/postgrest-table/data-loaders.d.ts +52 -28
  85. package/dist/postgrest-table/data-loaders.js +181 -104
  86. package/dist/postgrest-table/data-loaders.js.map +1 -1
  87. package/dist/postgrest-table/index.cjs +205 -79
  88. package/dist/postgrest-table/index.cjs.map +1 -1
  89. package/dist/postgrest-table/index.d.ts +13 -16
  90. package/dist/postgrest-table/index.js +186 -58
  91. package/dist/postgrest-table/index.js.map +1 -1
  92. package/dist/postgrest-table/lazy-loader-table.cjs +18 -17
  93. package/dist/postgrest-table/lazy-loader-table.cjs.map +1 -1
  94. package/dist/postgrest-table/lazy-loader-table.d.ts +1 -1
  95. package/dist/postgrest-table/lazy-loader-table.js +17 -14
  96. package/dist/postgrest-table/lazy-loader-table.js.map +1 -1
  97. package/dist/postgrest-table/loading-utils.cjs +16 -0
  98. package/dist/postgrest-table/loading-utils.cjs.map +1 -0
  99. package/dist/postgrest-table/loading-utils.d.ts +13 -0
  100. package/dist/postgrest-table/loading-utils.js +16 -0
  101. package/dist/postgrest-table/loading-utils.js.map +1 -0
  102. package/dist/postgrest-table/main.module.sass.cjs +18 -13
  103. package/dist/postgrest-table/main.module.sass.cjs.map +1 -1
  104. package/dist/postgrest-table/main.module.sass.js +18 -13
  105. package/dist/postgrest-table/main.module.sass.js.map +1 -1
  106. package/dist/provider.cjs +58 -26
  107. package/dist/provider.cjs.map +1 -1
  108. package/dist/provider.js +57 -23
  109. package/dist/provider.js.map +1 -1
  110. package/dist/renderers/column-header-cell-postgrest.cjs +216 -0
  111. package/dist/renderers/column-header-cell-postgrest.cjs.map +1 -0
  112. package/dist/renderers/column-header-cell-postgrest.d.ts +13 -0
  113. package/dist/renderers/column-header-cell-postgrest.js +216 -0
  114. package/dist/renderers/column-header-cell-postgrest.js.map +1 -0
  115. package/dist/renderers/column-header-cell-postgrest.module.sass.cjs +23 -0
  116. package/dist/renderers/column-header-cell-postgrest.module.sass.cjs.map +1 -0
  117. package/dist/renderers/column-header-cell-postgrest.module.sass.js +22 -0
  118. package/dist/renderers/column-header-cell-postgrest.module.sass.js.map +1 -0
  119. package/dist/renderers/column-header-cell.cjs +103 -0
  120. package/dist/renderers/column-header-cell.cjs.map +1 -0
  121. package/dist/renderers/column-header-cell.d.ts +30 -0
  122. package/dist/renderers/column-header-cell.js +101 -0
  123. package/dist/renderers/column-header-cell.js.map +1 -0
  124. package/dist/renderers/index.d.ts +2 -0
  125. package/dist/table-updates/data-parameter.d.ts +14 -0
  126. package/dist/table-updates/filter.d.ts +16 -0
  127. package/dist/table-updates/index.d.ts +19 -0
  128. package/dist/types.cjs +9 -0
  129. package/dist/types.cjs.map +1 -0
  130. package/dist/types.d.ts +58 -4
  131. package/dist/types.js +9 -0
  132. package/dist/types.js.map +1 -0
  133. package/dist/utils/column-spec.cjs +9 -1
  134. package/dist/utils/column-spec.cjs.map +1 -1
  135. package/dist/utils/column-spec.d.ts +21 -0
  136. package/dist/utils/column-spec.js +9 -1
  137. package/dist/utils/column-spec.js.map +1 -1
  138. package/dist/utils/key-handling.cjs +141 -52
  139. package/dist/utils/key-handling.cjs.map +1 -1
  140. package/dist/utils/key-handling.d.ts +2 -3
  141. package/dist/utils/key-handling.js +142 -53
  142. package/dist/utils/key-handling.js.map +1 -1
  143. package/dist/zustand-store.cjs +216 -51
  144. package/dist/zustand-store.cjs.map +1 -1
  145. package/dist/zustand-store.js +197 -32
  146. package/dist/zustand-store.js.map +1 -1
  147. package/package.json +5 -5
  148. package/src/actions/builtin.ts +65 -0
  149. package/src/actions/clipboard.ts +350 -0
  150. package/src/actions/filters.ts +150 -0
  151. package/src/actions/index.ts +6 -0
  152. package/src/actions/selection.ts +271 -0
  153. package/src/actions/toolbar.module.sass +30 -0
  154. package/src/actions/toolbar.ts +212 -0
  155. package/src/actions/types.ts +159 -0
  156. package/src/cell-renderer.ts +55 -51
  157. package/src/components/colors.ts +22 -19
  158. package/src/components/editor-popup.ts +3 -2
  159. package/src/components/index.ts +1 -0
  160. package/src/components/main.module.sass +1 -0
  161. package/src/components/text-areas.ts +34 -19
  162. package/src/components/view-info.ts +17 -0
  163. package/src/core.ts +243 -170
  164. package/src/index.ts +1 -0
  165. package/src/main.module.sass +14 -2
  166. package/src/notifications.ts +22 -0
  167. package/src/postgrest-table/data-loaders.ts +300 -201
  168. package/src/postgrest-table/index.ts +258 -84
  169. package/src/postgrest-table/lazy-loader-table.ts +18 -17
  170. package/src/postgrest-table/loading-utils.ts +49 -0
  171. package/src/postgrest-table/main.module.sass +16 -0
  172. package/src/provider.ts +63 -20
  173. package/src/renderers/column-header-cell-postgrest.module.sass +71 -0
  174. package/src/renderers/column-header-cell-postgrest.ts +282 -0
  175. package/src/renderers/column-header-cell.ts +388 -0
  176. package/src/renderers/index.ts +2 -0
  177. package/src/table-updates/data-parameter.ts +44 -0
  178. package/src/table-updates/filter.ts +124 -0
  179. package/src/table-updates/index.ts +239 -0
  180. package/src/types.ts +58 -3
  181. package/src/utils/column-spec.ts +47 -0
  182. package/src/utils/key-handling.ts +181 -72
  183. package/src/zustand-store.ts +241 -36
  184. package/dist/provider.d.ts +0 -15
@@ -1,11 +1,11 @@
1
1
  import { ColumnSpec, editorKeyHandlerAtom } from "./utils";
2
- import { DataSheetStore } from "./types.ts";
2
+ import { DataSheetStore, TableElementStatus } from "./types.ts";
3
3
  import h from "./main.module.sass";
4
- import { ReactNode } from "react";
4
+ import { ReactNode, useEffect, useState } from "react";
5
5
  import { EditorPopup } from "./components";
6
6
  import { singleFocusedCell } from "./zustand-store.ts";
7
7
  import { Cell } from "@blueprintjs/table";
8
- import { useAtomValue, useSelector } from "./provider.ts";
8
+ import { ctx, useSelector } from "./provider.ts";
9
9
 
10
10
  export function basicCellRenderer<T>(
11
11
  rowIndex: number,
@@ -13,58 +13,60 @@ export function basicCellRenderer<T>(
13
13
  columnSpec: ColumnSpec,
14
14
  state: DataSheetStore<T>,
15
15
  autoFocusEditor = true,
16
+ filteredRowIndices?: number[] | null,
16
17
  ): any {
18
+ // When filters are active, `rowIndex` is the visible row position.
19
+ // Map it to the actual data index for data access.
20
+ const dataRowIndex =
21
+ filteredRowIndices != null
22
+ ? (filteredRowIndices[rowIndex] ?? rowIndex)
23
+ : rowIndex;
24
+
17
25
  const data = state.data;
18
26
  const updatedData = state.updatedData;
19
27
 
20
- const isDeleted = state.deletedRows.has(rowIndex);
28
+ const isDeleted = state.rowStatus[dataRowIndex] == TableElementStatus.DELETED;
21
29
 
22
- const row = data[rowIndex] ?? updatedData[rowIndex];
30
+ const row = data[dataRowIndex] ?? updatedData[dataRowIndex];
23
31
  const loading = row == null;
24
32
  const col = columnSpec;
25
33
 
26
34
  const _topLeftCell = state.topLeftCell;
27
35
  const onCellEdited = state.onCellEdited;
28
36
 
29
- const value = updatedData[rowIndex]?.[col.key] ?? data[rowIndex]?.[col.key];
30
- const _renderedValue = col.valueRenderer?.(value) ?? value;
37
+ const value: T | undefined =
38
+ updatedData[dataRowIndex]?.[col.key] ?? data[dataRowIndex]?.[col.key];
39
+ const isEmpty = value == null || value === "";
40
+ const _renderedValue = isEmpty ? null : (col.valueRenderer?.(value) ?? value);
31
41
 
32
42
  let style = col.style ?? {};
43
+
33
44
  if (isDeleted) {
34
- style = {
35
- ...style,
36
- opacity: 0.5,
37
- textDecoration: "line-through",
38
- };
45
+ style.opacity = 0.5;
46
+ style.textDecoration = "line-through";
39
47
  }
40
48
 
41
- //const focused =
42
- // focusedCell?.col === colIndex && focusedCell?.row === rowIndex;
43
-
44
49
  const editable = (col.editable ?? state.editable) && !isDeleted;
45
50
 
46
- // Top left cell of a ranged selection
51
+ // topLeftCell stores visible row indices, so compare with the visible rowIndex
47
52
  const topLeft =
48
53
  _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;
49
54
 
50
- if (!editable && state.editable) {
51
- // If the cell is not editable but the sheet is editable, we want to differentiate
52
- // between editable and non-editable cells.
53
- style.color = "var(--secondary-color)";
54
- }
55
+ const tableIsEditable = state.editable;
55
56
 
56
- const edited = updatedData[rowIndex]?.[col.key] != null;
57
+ const edited =
58
+ updatedData[dataRowIndex]?.[col.key] != null ||
59
+ state.rowStatus[dataRowIndex] === TableElementStatus.ADDED;
57
60
  let intent = edited ? "success" : undefined;
58
61
  if (isDeleted) {
59
62
  intent = "danger";
60
63
  }
61
64
 
62
- const _Cell = col.cellComponent ?? BaseCell;
65
+ const _Cell = col.cellComponent ?? Cell;
63
66
 
64
67
  let inlineEditor = editable ? (col.inlineEditor ?? true) : false;
65
68
 
66
69
  if (!topLeft) {
67
- // This should be the case for every cell except the focused one
68
70
  return h(
69
71
  _Cell,
70
72
  {
@@ -72,7 +74,8 @@ export function basicCellRenderer<T>(
72
74
  loading,
73
75
  value,
74
76
  style,
75
- isDeleted,
77
+ disabled: tableIsEditable && !editable,
78
+ interactive: false,
76
79
  },
77
80
  _renderedValue,
78
81
  );
@@ -80,12 +83,6 @@ export function basicCellRenderer<T>(
80
83
 
81
84
  // The rest is for the top-left cell of a selection or the focused cell
82
85
 
83
- // Hidden input to capture key events
84
- let hiddenInput = h(EditorInput, {
85
- className: "hidden-input",
86
- autoFocus: true,
87
- });
88
-
89
86
  let cellContents: ReactNode = _renderedValue;
90
87
 
91
88
  let _dataEditor = null;
@@ -102,22 +99,24 @@ export function basicCellRenderer<T>(
102
99
  h(col.dataEditor, {
103
100
  value,
104
101
  editable,
102
+ isEdited: edited,
105
103
  onChange(value) {
106
104
  if (!editable) return;
107
105
  state.onSelectionEdited(value);
108
106
  },
107
+ resetValue() {
108
+ state.resetChanges();
109
+ },
109
110
  }),
110
111
  ],
111
112
  );
112
113
  }
113
114
 
114
115
  if (!editable) {
115
- // Most cells are not focused and don't need to be editable.
116
- // This will be the rendering logic for almost all cells
117
-
118
116
  if (_dataEditor != null) {
119
117
  cellContents = _dataEditor;
120
118
  }
119
+ const className = "value-viewer-cell";
121
120
 
122
121
  return h(
123
122
  _Cell,
@@ -125,18 +124,20 @@ export function basicCellRenderer<T>(
125
124
  intent,
126
125
  value,
127
126
  style,
127
+ className,
128
+ interactive: false,
128
129
  },
129
130
  cellContents,
130
131
  );
131
- // Could probably put the hidden input elsewhere,
132
132
  }
133
133
 
134
134
  /* The remaining logic covers cells that are focused and editable */
135
135
 
136
136
  const onChange = (e) => {
137
137
  if (!editable) return;
138
- if (value === e.target.value) return;
139
- onCellEdited(rowIndex, col.key, e.target.value);
138
+ if (_renderedValue === e.target.value) return;
139
+ // Use dataRowIndex for the actual data mutation
140
+ onCellEdited(dataRowIndex, col.key, e.target.value);
140
141
  };
141
142
 
142
143
  const isSingleCellSelection = singleFocusedCell(state.selection) != null;
@@ -162,6 +163,11 @@ export function basicCellRenderer<T>(
162
163
  _inlineEditor = inlineEditor as ReactNode;
163
164
  }
164
165
 
166
+ let hiddenInput: React.ReactNode = h(EditorInput, {
167
+ className: "hidden-input",
168
+ autoFocus: true,
169
+ });
170
+
165
171
  if (_dataEditor != null) {
166
172
  className = "editor-cell";
167
173
  cellContents = _dataEditor;
@@ -180,21 +186,30 @@ export function basicCellRenderer<T>(
180
186
  value,
181
187
  className,
182
188
  style,
189
+ interactive: true,
183
190
  //truncated: false,
184
191
  },
185
192
  [
186
193
  cellContents,
187
194
  h.if(editable && isSingleCellSelection)(DragHandle),
188
- hiddenInput,
195
+ //hiddenInput,
189
196
  ],
190
197
  );
191
198
  }
192
199
 
193
200
  function EditorInput(props) {
194
- const onKeyDown = useAtomValue(editorKeyHandlerAtom);
201
+ const { value, onChange, ...rest } = props;
202
+ const onKeyDown = ctx.useValue(editorKeyHandlerAtom);
203
+ const [_value, setValue] = useState(value);
204
+ useEffect(() => {
205
+ setValue(value);
206
+ }, [value]);
195
207
  return h("input", {
196
208
  onKeyDown,
197
- ...props,
209
+ onBlur: onChange,
210
+ value: _value ?? value,
211
+ onChange: (e) => setValue(e.target.value),
212
+ ...rest,
198
213
  });
199
214
  }
200
215
 
@@ -204,14 +219,3 @@ function DragHandle() {
204
219
  const onMouseDown = useSelector((state) => state.onDragValue);
205
220
  return h("div.corner-drag-handle", { onMouseDown });
206
221
  }
207
-
208
- export function BaseCell({ children, value, ...rest }) {
209
- return h(
210
- Cell,
211
- {
212
- interactive: true,
213
- ...rest,
214
- },
215
- children,
216
- );
217
- }
@@ -5,6 +5,7 @@ import { getLuminanceAdjustedColorScheme } from "@macrostrat/color-utils";
5
5
  import { memoize } from "underscore";
6
6
  import classNames from "classnames";
7
7
  import { ColorPicker2 } from "@macrostrat/ui-components";
8
+ import { useMemo } from "react";
8
9
 
9
10
  export const ColorPicker = ColorPicker2;
10
11
 
@@ -18,25 +19,31 @@ export function ColorCell({
18
19
  ...rest
19
20
  }) {
20
21
  const darkMode = useInDarkMode();
21
-
22
22
  const _className = classNames(className, "color-cell");
23
+ const _style = useMemo(() => {
24
+ let mainColor = "var(--text-color)";
25
+ let backgroundColor = value;
23
26
 
24
- let mainColor = "var(--text-color)";
25
- let backgroundColor = value;
27
+ if (adjustLuminance) {
28
+ // If adjustLuminance is true, get the color scheme based on the value
29
+ let colors = colorCombo(value, darkMode, 0.05);
30
+ if (colors != null) {
31
+ mainColor = colors.mainColor;
32
+ backgroundColor = colors.backgroundColor;
33
+ }
34
+ }
26
35
 
27
- if (adjustLuminance) {
28
- // If adjustLuminance is true, get the color scheme based on the value
29
- let colors = colorCombo(value, darkMode, 0.05);
30
- if (colors != null) {
31
- mainColor = colors.mainColor;
32
- backgroundColor = colors.backgroundColor;
36
+ if (intent != null) {
37
+ // If an intent is specified, override the main color
38
+ mainColor = undefined;
33
39
  }
34
- }
35
40
 
36
- if (intent != null) {
37
- // If an intent is specified, override the main color
38
- mainColor = undefined;
39
- }
41
+ return {
42
+ ...style,
43
+ color: mainColor,
44
+ backgroundColor,
45
+ };
46
+ }, [value, intent, adjustLuminance, darkMode, style]);
40
47
 
41
48
  return h(
42
49
  Cell,
@@ -44,11 +51,7 @@ export function ColorCell({
44
51
  intent,
45
52
  className: _className,
46
53
  ...rest,
47
- style: {
48
- color: mainColor,
49
- backgroundColor,
50
- ...style,
51
- },
54
+ style: _style,
52
55
  },
53
56
  children,
54
57
  );
@@ -53,6 +53,7 @@ export function EditorPopup(props) {
53
53
  enforceFocus: false,
54
54
  autoFocus: false,
55
55
  animation: "minimal",
56
+ //arrow: false,
56
57
  lazy: true,
57
58
  // modifiers: {
58
59
  // offset: { enabled: true, options: { offset: [0, 8] } },
@@ -61,10 +62,10 @@ export function EditorPopup(props) {
61
62
  interactionKind: "hover-target",
62
63
  isOpen,
63
64
  // Portal must be used to avoid issues with the editor being clipped to the bounds of the cell
64
- usePortal: true,
65
+ //usePortal: true,
65
66
  },
66
67
  h(
67
- "span.editor-popup-target.bp6-table-cell",
68
+ "span.editor-popup-target",
68
69
  {
69
70
  className: targetClassName,
70
71
  onClick: () => setIsOpen(!isOpen),
@@ -2,3 +2,4 @@ export * from "./editor-popup";
2
2
  export * from "./colors";
3
3
  export * from "./text-areas";
4
4
  export * from "./actions";
5
+ export { InfoBar } from "./view-info.ts";
@@ -8,6 +8,7 @@
8
8
  left: 0
9
9
  width: 100%
10
10
  height: 100%
11
+ padding: var(--data-sheet-cell-padding)
11
12
 
12
13
  .editable-text-area
13
14
  position: relative
@@ -1,14 +1,30 @@
1
- import hyper from "@macrostrat/hyper";
2
- import styles from "./main.module.sass";
1
+ import h from "./main.module.sass";
3
2
  import { Button } from "@blueprintjs/core";
4
- import { useEffect, useRef } from "react";
3
+ import { useEffect, useRef, useState } from "react";
5
4
  import { multiLineTextKeyHandler } from "../utils";
6
5
 
7
- const h = hyper.styled(styles);
6
+ export type DataEditorProps = {
7
+ value: string;
8
+ editable: boolean;
9
+ onChange: (value: string) => void;
10
+ isEdited?: boolean;
11
+ resetValue?: () => void;
12
+ };
8
13
 
9
- export function EditableTextArea({ value, onChange }) {
14
+ export function EditableTextArea({
15
+ value,
16
+ onChange,
17
+ isEdited,
18
+ resetValue,
19
+ }: DataEditorProps) {
10
20
  const ref = useRef(null);
11
21
 
22
+ // const [_value, setValue] = useState(value);
23
+ //
24
+ // useEffect(() => {
25
+ // setValue(value);
26
+ // }, [value]);
27
+
12
28
  useEffect(() => {
13
29
  if (ref.current == null) return;
14
30
  ref.current.focus();
@@ -21,26 +37,25 @@ export function EditableTextArea({ value, onChange }) {
21
37
  return h("div.editable-text-area", [
22
38
  h("textarea.bp6-input", {
23
39
  ref,
24
- value: value ?? "",
25
- onChange: (evt) => onChange(evt.target.value),
40
+ defaultValue: value ?? "",
41
+ //onChange: (evt) => setValue(evt.target.value),
42
+ onBlur: (evt) => {
43
+ if (evt.target.value !== value) {
44
+ onChange(evt.target.value);
45
+ }
46
+ },
26
47
  onKeyDown: multiLineTextKeyHandler,
27
48
  }),
28
49
  h("div.tools", [
50
+ // Tool to reset the value to the default
29
51
  h(Button, {
30
- icon: "key-enter",
52
+ icon: "undo",
31
53
  minimal: true,
32
54
  small: true,
33
- onClick() {
34
- // Get cursor position
35
- let _value = value ?? "";
36
-
37
- const cursorPos = ref.current.selectionStart ?? _value.length;
38
- // Insert a newline at the cursor position
39
- onChange(_value.slice(0, cursorPos) + "\n" + _value.slice(cursorPos));
40
- // Re-focus the textarea
41
- ref.current.focus();
42
- // Move the cursor to the end of the line
43
- ref.current.setSelectionRange(cursorPos + 1, cursorPos + 1);
55
+ intent: isEdited ? "success" : "none",
56
+ disabled: !isEdited,
57
+ onClick(evt) {
58
+ resetValue?.();
44
59
  },
45
60
  }),
46
61
  ]),
@@ -0,0 +1,17 @@
1
+ import h from "../postgrest-table/main.module.sass";
2
+ import { ViewInfo, viewInfoAtom } from "../postgrest-table";
3
+ import { ctx } from "../provider.ts";
4
+
5
+ function ViewInfoControl() {
6
+ const viewInfo: ViewInfo = ctx.useValue(viewInfoAtom);
7
+
8
+ return h("p", [
9
+ `Rows ${viewInfo.visibleRegion.rowIndexStart}–${viewInfo.visibleRegion.rowIndexEnd}`,
10
+ " of ",
11
+ h("span.total-count", viewInfo.totalCount),
12
+ ]);
13
+ }
14
+
15
+ export function InfoBar() {
16
+ return h("div.info-bar", [h(ViewInfoControl)]);
17
+ }