@jsenv/navi 0.10.2 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/dist/jsenv_navi.js +13838 -23291
  2. package/dist/jsenv_navi.js.map +1281 -0
  3. package/package.json +5 -7
  4. package/index.js +0 -122
  5. package/src/action_private_properties.js +0 -11
  6. package/src/action_proxy_test.html +0 -353
  7. package/src/action_run_states.js +0 -5
  8. package/src/actions.js +0 -1401
  9. package/src/browser_integration/browser_integration.js +0 -216
  10. package/src/browser_integration/document_back_and_forward.js +0 -17
  11. package/src/browser_integration/document_loading_signal.js +0 -100
  12. package/src/browser_integration/document_state_signal.js +0 -9
  13. package/src/browser_integration/document_url_signal.js +0 -9
  14. package/src/browser_integration/use_is_visited.js +0 -19
  15. package/src/browser_integration/via_history.js +0 -232
  16. package/src/browser_integration/via_navigation.js +0 -168
  17. package/src/components/action_execution/form_context.js +0 -5
  18. package/src/components/action_execution/render_actionable_component.jsx +0 -29
  19. package/src/components/action_execution/use_action.js +0 -99
  20. package/src/components/action_execution/use_execute_action.js +0 -193
  21. package/src/components/action_execution/use_run_on_mount.js +0 -9
  22. package/src/components/action_renderer.jsx +0 -125
  23. package/src/components/callout/callout.js +0 -990
  24. package/src/components/callout/callout_demo.html +0 -201
  25. package/src/components/callout/test_dynamic_positioning.html +0 -161
  26. package/src/components/callout/test_html_document_iframe.html +0 -182
  27. package/src/components/demos/0_button_demo.html +0 -707
  28. package/src/components/demos/10_column_reordering_debug.html +0 -277
  29. package/src/components/demos/11_table_selection_debug.html +0 -432
  30. package/src/components/demos/1_checkbox_demo.html +0 -754
  31. package/src/components/demos/2_input_textual_demo.html +0 -286
  32. package/src/components/demos/3_radio_demo.html +0 -874
  33. package/src/components/demos/4_select_demo.html +0 -100
  34. package/src/components/demos/5_list_scrollable_demo.html +0 -153
  35. package/src/components/demos/6_tablist_demo.html +0 -77
  36. package/src/components/demos/7_table_selection_demo.html +0 -176
  37. package/src/components/demos/8_table_fixed_headers_demo.html +0 -584
  38. package/src/components/demos/9_table_column_drag_demo.html +0 -325
  39. package/src/components/demos/action/0_button_demo.html +0 -204
  40. package/src/components/demos/action/10_shortcuts_demo.html +0 -189
  41. package/src/components/demos/action/11_nested_shortcuts_demo.xhtml +0 -401
  42. package/src/components/demos/action/1_input_text_demo.html +0 -876
  43. package/src/components/demos/action/2_form_multiple.html +0 -303
  44. package/src/components/demos/action/3_details_demo.html +0 -203
  45. package/src/components/demos/action/4_input_checkbox_demo.html +0 -731
  46. package/src/components/demos/action/5_input_checkbox_state_demo.html +0 -270
  47. package/src/components/demos/action/6_checkbox_list_demo.html +0 -341
  48. package/src/components/demos/action/7_radio_list_demo.html +0 -357
  49. package/src/components/demos/action/8_editable_demo.html +0 -431
  50. package/src/components/demos/action/9_link_demo.html +0 -194
  51. package/src/components/demos/demo.md +0 -0
  52. package/src/components/demos/route/basic/basic.html +0 -14
  53. package/src/components/demos/route/basic/basic_route_demo.jsx +0 -224
  54. package/src/components/demos/route/multi/multi.html +0 -14
  55. package/src/components/demos/route/multi/multi_route_demo.jsx +0 -277
  56. package/src/components/demos/ui_transition/0_action_renderer_ui_transition_demo.html +0 -695
  57. package/src/components/demos/ui_transition/1_nested_ui_transition_demo.html +0 -429
  58. package/src/components/demos/ui_transition/2_height_transition_test.html +0 -295
  59. package/src/components/details/details.jsx +0 -245
  60. package/src/components/details/summary_marker.jsx +0 -141
  61. package/src/components/edition/editable.jsx +0 -186
  62. package/src/components/error_boundary_context.js +0 -9
  63. package/src/components/field/README.md +0 -247
  64. package/src/components/field/button.jsx +0 -429
  65. package/src/components/field/checkbox_list.jsx +0 -185
  66. package/src/components/field/collect_form_element_values.js +0 -82
  67. package/src/components/field/custom_field.js +0 -106
  68. package/src/components/field/form.jsx +0 -209
  69. package/src/components/field/input.jsx +0 -16
  70. package/src/components/field/input_checkbox.jsx +0 -434
  71. package/src/components/field/input_radio.jsx +0 -432
  72. package/src/components/field/input_textual.jsx +0 -389
  73. package/src/components/field/label.jsx +0 -46
  74. package/src/components/field/radio_list.jsx +0 -183
  75. package/src/components/field/select.jsx +0 -256
  76. package/src/components/field/use_action_events.js +0 -132
  77. package/src/components/field/use_form_events.js +0 -59
  78. package/src/components/field/use_ui_state_controller.js +0 -506
  79. package/src/components/item_tracker/README.md +0 -461
  80. package/src/components/item_tracker/use_isolated_item_tracker.jsx +0 -209
  81. package/src/components/item_tracker/use_isolated_item_tracker_demo.html +0 -148
  82. package/src/components/item_tracker/use_isolated_item_tracker_demo.jsx +0 -460
  83. package/src/components/item_tracker/use_item_tracker.jsx +0 -143
  84. package/src/components/item_tracker/use_item_tracker_demo.html +0 -207
  85. package/src/components/item_tracker/use_item_tracker_demo.jsx +0 -216
  86. package/src/components/keyboard_shortcuts/active_keyboard_shortcuts.jsx +0 -87
  87. package/src/components/keyboard_shortcuts/aria_key_shortcuts.js +0 -61
  88. package/src/components/keyboard_shortcuts/keyboard_key_meta.js +0 -17
  89. package/src/components/keyboard_shortcuts/keyboard_shortcuts.js +0 -371
  90. package/src/components/keyboard_shortcuts/os.js +0 -9
  91. package/src/components/layout/demos/demo_flex.html +0 -638
  92. package/src/components/layout/demos/demo_layout_style_buttons.html +0 -351
  93. package/src/components/layout/demos/demo_layout_style_input.html +0 -226
  94. package/src/components/layout/demos/demo_layout_style_text.html +0 -514
  95. package/src/components/layout/flex.jsx +0 -109
  96. package/src/components/layout/layout_context.jsx +0 -3
  97. package/src/components/layout/spacing.jsx +0 -20
  98. package/src/components/layout/use_layout_style.js +0 -249
  99. package/src/components/link/link.jsx +0 -267
  100. package/src/components/link/link_with_icon.jsx +0 -52
  101. package/src/components/loader/loader_background.jsx +0 -372
  102. package/src/components/loader/loading_spinner.jsx +0 -68
  103. package/src/components/loader/network_speed.js +0 -83
  104. package/src/components/loader/rectangle_loading.jsx +0 -244
  105. package/src/components/props_composition/demos/demo_with_props_style.html +0 -81
  106. package/src/components/props_composition/with_props_class_name.js +0 -37
  107. package/src/components/props_composition/with_props_style.js +0 -26
  108. package/src/components/route.jsx +0 -19
  109. package/src/components/selection/selection.jsx +0 -1583
  110. package/src/components/svg/font_sized_svg.jsx +0 -59
  111. package/src/components/svg/icon_and_text.jsx +0 -21
  112. package/src/components/svg/svg_mask_overlay.jsx +0 -105
  113. package/src/components/table/drag/table_drag.jsx +0 -506
  114. package/src/components/table/resize/table_resize.jsx +0 -650
  115. package/src/components/table/resize/table_size.js +0 -43
  116. package/src/components/table/selection/table_selection.js +0 -106
  117. package/src/components/table/selection/table_selection.jsx +0 -203
  118. package/src/components/table/sticky/sticky_group.js +0 -354
  119. package/src/components/table/sticky/table_sticky.js +0 -25
  120. package/src/components/table/sticky/table_sticky.jsx +0 -501
  121. package/src/components/table/table.jsx +0 -721
  122. package/src/components/table/table_css.js +0 -211
  123. package/src/components/table/table_ui.jsx +0 -49
  124. package/src/components/table/use_cells_and_columns.js +0 -90
  125. package/src/components/table/use_object_array_to_cells.js +0 -46
  126. package/src/components/table/z_indexes.js +0 -23
  127. package/src/components/tablist/tablist.jsx +0 -99
  128. package/src/components/text/demos/demo_text_and_icon.html +0 -421
  129. package/src/components/text/overflow.jsx +0 -15
  130. package/src/components/text/text.jsx +0 -83
  131. package/src/components/text/text_and_count.jsx +0 -28
  132. package/src/components/ui_transition.jsx +0 -128
  133. package/src/components/use_auto_focus.js +0 -94
  134. package/src/components/use_batch_during_render.js +0 -33
  135. package/src/components/use_debounce_true.js +0 -31
  136. package/src/components/use_dependencies_diff.js +0 -35
  137. package/src/components/use_focus_group.js +0 -20
  138. package/src/components/use_initial_value.js +0 -78
  139. package/src/components/use_is_visited.js +0 -19
  140. package/src/components/use_ref_array.js +0 -38
  141. package/src/components/use_signal_sync.js +0 -50
  142. package/src/components/use_stable_callback.js +0 -68
  143. package/src/components/use_state_array.js +0 -47
  144. package/src/docs/actions.md +0 -250
  145. package/src/docs/demos/resource/action_status.jsx +0 -42
  146. package/src/docs/demos/resource/demo.md +0 -1
  147. package/src/docs/demos/resource/resource_demo_0.html +0 -84
  148. package/src/docs/demos/resource/resource_demo_10_post_gc.html +0 -364
  149. package/src/docs/demos/resource/resource_demo_11_describe_many.html +0 -362
  150. package/src/docs/demos/resource/resource_demo_2.html +0 -173
  151. package/src/docs/demos/resource/resource_demo_3_filtered_users.html +0 -415
  152. package/src/docs/demos/resource/resource_demo_4_details.html +0 -284
  153. package/src/docs/demos/resource/resource_demo_5_renderer_lazy.html +0 -115
  154. package/src/docs/demos/resource/resource_demo_6_gc.html +0 -217
  155. package/src/docs/demos/resource/resource_demo_7_child_gc.html +0 -240
  156. package/src/docs/demos/resource/resource_demo_8_proxy_gc.html +0 -319
  157. package/src/docs/demos/resource/resource_demo_9_describe_one.html +0 -472
  158. package/src/docs/demos/resource/tata.jsx +0 -3
  159. package/src/docs/demos/resource/toto.jsx +0 -3
  160. package/src/docs/demos/user_nav/user_nav.html +0 -12
  161. package/src/docs/demos/user_nav/user_nav.jsx +0 -330
  162. package/src/docs/resource_dependencies.md +0 -103
  163. package/src/docs/resource_with_params.md +0 -80
  164. package/src/navi_css_vars.js +0 -14
  165. package/src/notes.md +0 -34
  166. package/src/route/route.js +0 -596
  167. package/src/route/route.xtest.html +0 -228
  168. package/src/store/array_signal_store.js +0 -537
  169. package/src/store/local_storage_signal.js +0 -17
  170. package/src/store/resource_graph.js +0 -1304
  171. package/src/store/tests/resource_graph_autoreload_demo.html +0 -12
  172. package/src/store/tests/resource_graph_autoreload_demo.jsx +0 -964
  173. package/src/store/tests/resource_graph_dependencies.test_manual.js +0 -95
  174. package/src/store/value_in_local_storage.js +0 -187
  175. package/src/symbol_object_signal.js +0 -1
  176. package/src/use_action_data.js +0 -10
  177. package/src/use_action_status.js +0 -47
  178. package/src/utils/add_many_event_listeners.js +0 -15
  179. package/src/utils/array_add_remove.js +0 -61
  180. package/src/utils/array_signal.js +0 -15
  181. package/src/utils/compare_two_js_values.js +0 -172
  182. package/src/utils/execute_with_cleanup.js +0 -21
  183. package/src/utils/get_caller_info.js +0 -85
  184. package/src/utils/is_signal.js +0 -20
  185. package/src/utils/js_value_weak_map.js +0 -162
  186. package/src/utils/js_value_weak_map_demo.html +0 -690
  187. package/src/utils/merge_two_js_values.js +0 -53
  188. package/src/utils/stringify_for_display.js +0 -131
  189. package/src/utils/weak_effect.js +0 -48
  190. package/src/validation/constraints/confirm_constraint.js +0 -14
  191. package/src/validation/constraints/create_unique_value_constraint.js +0 -27
  192. package/src/validation/constraints/native_constraints.js +0 -338
  193. package/src/validation/constraints/readonly_constraint.js +0 -41
  194. package/src/validation/constraints/same_as_constraint.js +0 -42
  195. package/src/validation/constraints/single_space_constraint.js +0 -13
  196. package/src/validation/custom_constraint_validation.js +0 -793
  197. package/src/validation/custom_message.js +0 -18
  198. package/src/validation/demos/browser_style.png +0 -0
  199. package/src/validation/demos/demo_same_as_constraint.html +0 -259
  200. package/src/validation/demos/form_validation_demo.html +0 -142
  201. package/src/validation/demos/form_validation_demo_preact.html +0 -87
  202. package/src/validation/demos/form_validation_native_popover_demo.html +0 -168
  203. package/src/validation/demos/form_validation_vs_native_demo.html +0 -172
  204. package/src/validation/hooks/use_constraints.js +0 -23
  205. package/src/validation/hooks/use_custom_validation_ref.js +0 -73
  206. package/src/validation/hooks/use_validation_message.js +0 -19
  207. package/src/validation/input_change_effect.js +0 -106
@@ -1,721 +0,0 @@
1
- /**
2
- * Table Component with Custom Border and Selection System
3
- *
4
- * PROBLEM: We want to draw selected table cells with a clear visual perimeter
5
- *
6
- * ATTEMPTED SOLUTIONS & THEIR ISSUES:
7
- *
8
- * 1. Drawing selection outside the table:
9
- * - z-index issues: Hard to ensure selection appears above all table elements
10
- * - Performance issues: Constant recalculation during resizing, scrolling, etc.
11
- * - Positioning complexity: Managing absolute positioning relative to table cells
12
- *
13
- * 2. Using native CSS table cell borders:
14
- * - Border rendering artifacts: CSS borders are not rendered as straight lines,
15
- * making selection perimeter imperfect (especially with thick borders)
16
- * - Border-collapse compatibility: Native border-collapse causes sticky elements
17
- * to lose borders while scrolling in some browsers
18
- * - Dimension changes: Custom border-collapse (manually disabling adjacent borders)
19
- * changes cell dimensions, making selection outline visible and inconsistent
20
- *
21
- * SOLUTION: Custom border system using box-shadow
22
- *
23
- * KEY PRINCIPLES:
24
- * - Use inset box-shadow to ensure borders appear above table cell backgrounds
25
- * - Use ::before pseudo-elements with position: absolute for flexible positioning
26
- * - Each cell draws its own borders independently (no border-collapse by default)
27
- * - Selection borders override table borders using higher CSS specificity
28
- * - Sticky borders use thicker box-shadows in accent color (yellow)
29
- *
30
- * TECHNICAL IMPLEMENTATION:
31
- * - All borders use inset box-shadow with specific directional mapping:
32
- * * Top: inset 0 1px 0 0
33
- * * Right: inset -1px 0 0 0
34
- * * Bottom: inset 0 -1px 0 0
35
- * * Left: inset 1px 0 0 0
36
- * - Selection borders (blue) override table borders (red) in same pseudo-element
37
- * - Sticky borders replace regular borders with thicker colored variants
38
- * - Border-collapse mode available as optional feature for future use
39
- *
40
- * Note how border disappear for sticky elements when using border-collapse (https://bugzilla.mozilla.org/show_bug.cgi?id=1727594)
41
- *
42
- * Next steps:
43
- *
44
- * - Mettre le sticky again dans les tables cells (mais les suivantes pour avoir l'effet d'ombre)
45
- *
46
- * - Can add a column (+ button at the end of table headers)
47
- * - Can add a row (+ button at the end of the row number column )
48
- * - Delete a row (how?)
49
- * - Delete a column (how?)
50
- * - Update table column info (I guess a down arrow icon which opens a meny when clicked for instance)
51
- */
52
-
53
- import { useActiveElement } from "@jsenv/dom";
54
- import { createContext, toChildArray } from "preact";
55
- import { forwardRef } from "preact/compat";
56
- import { useContext, useId, useImperativeHandle, useRef } from "preact/hooks";
57
-
58
- import { Editable, useEditionController } from "../edition/editable.jsx";
59
- import { createIsolatedItemTracker } from "../item_tracker/use_isolated_item_tracker.jsx";
60
- import { createItemTracker } from "../item_tracker/use_item_tracker.jsx";
61
- import { useKeyboardShortcuts } from "../keyboard_shortcuts/keyboard_shortcuts.js";
62
- import {
63
- createSelectionKeyboardShortcuts,
64
- useSelectableElement,
65
- } from "../selection/selection.jsx";
66
- import { useFocusGroup } from "../use_focus_group.js";
67
- import {
68
- initDragTableColumnViaPointer,
69
- TableColumnDropPreview,
70
- TableDragCloneContainer,
71
- TableDragContext,
72
- useTableDragContextValue,
73
- } from "./drag/table_drag.jsx";
74
- import {
75
- TableCellColumnResizeHandles,
76
- TableCellRowResizeHandles,
77
- TableColumnResizer,
78
- TableRowResizer,
79
- } from "./resize/table_resize.jsx";
80
- import {
81
- TableSizeContext,
82
- useTableSizeContextValue,
83
- } from "./resize/table_size.js";
84
- import {
85
- parseTableSelectionValue,
86
- stringifyTableSelectionValue,
87
- TableSelectionContext,
88
- useTableSelectionContextValue,
89
- } from "./selection/table_selection.js";
90
- import { useTableSelectionController } from "./selection/table_selection.jsx";
91
- import { useStickyGroup } from "./sticky/sticky_group.js";
92
- import {
93
- TableStickyContext,
94
- useTableStickyContextValue,
95
- } from "./sticky/table_sticky.js";
96
- import "./sticky/table_sticky.jsx";
97
- import { TableStickyFrontier } from "./sticky/table_sticky.jsx";
98
- import "./table_css.js";
99
- import { TableUI } from "./table_ui.jsx";
100
-
101
- const [useColumnTrackerProviders, useRegisterColumn, useColumnByIndex] =
102
- createIsolatedItemTracker();
103
- const [useRowTrackerProvider, useRegisterRow, useRowByIndex] =
104
- createItemTracker();
105
-
106
- const ColumnProducerProviderContext = createContext();
107
- const ColumnConsumerProviderContext = createContext();
108
- const ColumnContext = createContext();
109
- const RowContext = createContext();
110
- const ColumnIndexContext = createContext();
111
- const RowIndexContext = createContext();
112
-
113
- const TableSectionContext = createContext();
114
- const useIsInTableHead = () => useContext(TableSectionContext) === "head";
115
-
116
- export const Table = forwardRef((props, ref) => {
117
- const tableDefaultId = `table-${useId()}`;
118
- const {
119
- id = tableDefaultId,
120
- selection = [],
121
- selectionColor,
122
- onSelectionChange,
123
- onColumnSizeChange,
124
- onRowSizeChange,
125
- borderCollapse = true,
126
- stickyLeftFrontierColumnIndex = -1,
127
- onStickyLeftFrontierChange,
128
- stickyTopFrontierRowIndex = -1,
129
- onStickyTopFrontierChange,
130
- onColumnOrderChange,
131
- maxWidth,
132
- maxHeight,
133
- overflow,
134
- children,
135
- } = props;
136
-
137
- const innerRef = useRef();
138
- useImperativeHandle(ref, () => innerRef.current);
139
- const tableContainerRef = useRef();
140
- const tableUIRef = useRef();
141
-
142
- const [ColumnProducerProvider, ColumnConsumerProvider, columns] =
143
- useColumnTrackerProviders();
144
- const RowTrackerProvider = useRowTrackerProvider();
145
- const rows = RowTrackerProvider.items;
146
-
147
- // selection
148
- const selectionController = useTableSelectionController({
149
- tableRef: innerRef,
150
- selection,
151
- onSelectionChange,
152
- selectionColor,
153
- });
154
- const selectionContextValue = useTableSelectionContextValue(
155
- selection,
156
- selectionController,
157
- );
158
-
159
- useFocusGroup(innerRef);
160
-
161
- // sticky
162
- useStickyGroup(tableContainerRef, {
163
- elementSelector: ".navi_table",
164
- elementReceivingCumulativeStickyPositionRef: tableUIRef,
165
- });
166
- const stickyContextValue = useTableStickyContextValue({
167
- stickyLeftFrontierColumnIndex,
168
- stickyTopFrontierRowIndex,
169
- onStickyLeftFrontierChange,
170
- onStickyTopFrontierChange,
171
- });
172
-
173
- // drag columns
174
- const tableRootRef = useRef();
175
- const setColumnOrder = (columnIdsNewOrder) => {
176
- // the code below ensures we re-render the selection when column are re-ordered
177
- // forcing each previously selected <td> to unselect and newly selected <td> to be selected
178
- // (because the corresponding DOM node is now different)
179
- onSelectionChange?.([...selection]);
180
- onColumnOrderChange?.(columnIdsNewOrder);
181
- };
182
- const tableDragCloneContainerRef = useRef();
183
- const tableColumnDropPreviewRef = useRef();
184
- const dragContextValue = useTableDragContextValue({
185
- tableDragCloneContainerRef,
186
- tableColumnDropPreviewRef,
187
- setColumnOrder,
188
- columns,
189
- canChangeColumnOrder: Boolean(onColumnOrderChange),
190
- });
191
-
192
- useKeyboardShortcuts(innerRef, [
193
- ...createSelectionKeyboardShortcuts(selectionController, {
194
- toggleEnabled: true,
195
- enabled: () => dragContextValue.grabTarget === null,
196
- }),
197
- {
198
- key: "enter",
199
- description: "Edit table cell content",
200
- enabled: () => dragContextValue.grabTarget === null,
201
- handler: () => {
202
- // Find the currently focused cell
203
- const activeCell = document.activeElement.closest("td");
204
- if (!activeCell) {
205
- return false;
206
- }
207
- activeCell.dispatchEvent(
208
- new CustomEvent("editrequested", { bubbles: false }),
209
- );
210
- return true;
211
- },
212
- },
213
- {
214
- key: "a-z",
215
- description: "Start editing table cell content",
216
- enabled: () => dragContextValue.grabTarget === null,
217
- handler: (e) => {
218
- const activeCell = document.activeElement.closest("td");
219
- if (!activeCell) {
220
- return false;
221
- }
222
- activeCell.dispatchEvent(
223
- new CustomEvent("editrequested", {
224
- bubbles: false,
225
- detail: { initialValue: e.key },
226
- }),
227
- );
228
- return true;
229
- },
230
- },
231
- ]);
232
-
233
- // resizing
234
- const columnResizerRef = useRef();
235
- const rowResizerRef = useRef();
236
- const tableSizeContextValue = useTableSizeContextValue({
237
- onColumnSizeChange,
238
- onRowSizeChange,
239
- columns,
240
- rows,
241
- columnResizerRef,
242
- rowResizerRef,
243
- });
244
-
245
- return (
246
- <div
247
- ref={tableRootRef}
248
- className="navi_table_root"
249
- style={{
250
- overflow,
251
- "--table-max-width": maxWidth ? `${maxWidth}px` : undefined,
252
- "--table-max-height": maxHeight ? `${maxHeight}px` : undefined,
253
- }}
254
- >
255
- <div ref={tableContainerRef} className="navi_table_container">
256
- <table
257
- ref={innerRef}
258
- id={id}
259
- className="navi_table"
260
- aria-multiselectable="true"
261
- data-multiselection={selection.length > 1 ? "" : undefined}
262
- data-border-collapse={borderCollapse ? "" : undefined}
263
- data-droppable=""
264
- >
265
- <TableSizeContext.Provider value={tableSizeContextValue}>
266
- <TableSelectionContext.Provider value={selectionContextValue}>
267
- <TableDragContext.Provider value={dragContextValue}>
268
- <TableStickyContext.Provider value={stickyContextValue}>
269
- <ColumnProducerProviderContext.Provider
270
- value={ColumnProducerProvider}
271
- >
272
- <ColumnConsumerProviderContext.Provider
273
- value={ColumnConsumerProvider}
274
- >
275
- <RowTrackerProvider>{children}</RowTrackerProvider>
276
- </ColumnConsumerProviderContext.Provider>
277
- </ColumnProducerProviderContext.Provider>
278
- </TableStickyContext.Provider>
279
- </TableDragContext.Provider>
280
- </TableSelectionContext.Provider>
281
- </TableSizeContext.Provider>
282
- </table>
283
- <TableUI ref={tableUIRef} tableRef={innerRef} tableId={id}>
284
- <TableStickyContext.Provider value={stickyContextValue}>
285
- <TableStickyFrontier tableRef={innerRef} />
286
- </TableStickyContext.Provider>
287
- <TableColumnResizer ref={columnResizerRef} />
288
- <TableRowResizer ref={rowResizerRef} />
289
- <TableDragCloneContainer
290
- ref={tableDragCloneContainerRef}
291
- tableId={id}
292
- />
293
- <TableColumnDropPreview ref={tableColumnDropPreviewRef} />
294
- </TableUI>
295
- </div>
296
- </div>
297
- );
298
- });
299
- export const Colgroup = ({ children }) => {
300
- const ColumnProducerProvider = useContext(ColumnProducerProviderContext);
301
- return (
302
- <colgroup className="navi_colgroup">
303
- <ColumnProducerProvider>{children}</ColumnProducerProvider>
304
- </colgroup>
305
- );
306
- };
307
- export const Col = ({ id, width, immovable, backgroundColor }) => {
308
- const columnIndex = useRegisterColumn({
309
- id,
310
- width,
311
- immovable,
312
- backgroundColor,
313
- });
314
- const { stickyLeftFrontierColumnIndex } = useContext(TableStickyContext);
315
- const isStickyLeft = columnIndex <= stickyLeftFrontierColumnIndex;
316
-
317
- return (
318
- <col
319
- className="navi_col"
320
- id={id}
321
- data-sticky-left={isStickyLeft ? "" : undefined}
322
- data-drag-sticky-left-frontier={isStickyLeft ? "" : undefined}
323
- data-drag-obstacle={immovable ? "move-column" : undefined}
324
- style={{
325
- minWidth: width ? `${width}px` : undefined,
326
- maxWidth: width ? `${width}px` : undefined,
327
- }}
328
- />
329
- );
330
- };
331
- export const Thead = ({ children }) => {
332
- return (
333
- <thead>
334
- <TableSectionContext.Provider value="head">
335
- {children}
336
- </TableSectionContext.Provider>
337
- </thead>
338
- );
339
- };
340
- export const Tbody = ({ children }) => {
341
- return (
342
- <tbody>
343
- <TableSectionContext.Provider value="body">
344
- {children}
345
- </TableSectionContext.Provider>
346
- </tbody>
347
- );
348
- };
349
- export const Tr = ({ id, height, children }) => {
350
- if (!id) {
351
- console.warn("<Tr /> must have an id prop to enable selection");
352
- }
353
- id = String(id); // we need strings as this value is going to be used in data attributes
354
- // and when generating cell ids
355
-
356
- const { selectedRowIds } = useContext(TableSelectionContext);
357
- const { stickyTopFrontierRowIndex } = useContext(TableStickyContext);
358
- const rowIndex = useRegisterRow({ id, height });
359
- const row = useRowByIndex(rowIndex);
360
- const ColumnConsumerProvider = useContext(ColumnConsumerProviderContext);
361
-
362
- const isStickyTop = rowIndex <= stickyTopFrontierRowIndex;
363
- const isStickyTopFrontier = rowIndex === stickyTopFrontierRowIndex;
364
- const isRowSelected = selectedRowIds.includes(id);
365
-
366
- children = toChildArray(children);
367
-
368
- /* We use <TableRowCells> to be able to provide <ColumnConsumerProvider />
369
- that is needed by useColumnByIndex */
370
-
371
- return (
372
- <tr
373
- className="navi_tr"
374
- data-row-id={id ? id : undefined}
375
- aria-selected={isRowSelected}
376
- data-sticky-top={isStickyTop ? "" : undefined}
377
- data-drag-sticky-top-frontier={isStickyTopFrontier ? "" : undefined}
378
- style={{
379
- height: height ? `${height}px` : undefined,
380
- maxHeight: height ? `${height}px` : undefined,
381
- }}
382
- >
383
- <ColumnConsumerProvider>
384
- <TableRowCells rowIndex={rowIndex} row={row}>
385
- {children}
386
- </TableRowCells>
387
- </ColumnConsumerProvider>
388
- </tr>
389
- );
390
- };
391
-
392
- const TableRowCells = ({ children, rowIndex, row }) => {
393
- return children.map((child, columnIndex) => {
394
- const column = useColumnByIndex(columnIndex);
395
- const columnId = column.id;
396
-
397
- return (
398
- <RowContext.Provider key={columnId} value={row}>
399
- <RowIndexContext.Provider value={rowIndex}>
400
- <ColumnIndexContext.Provider value={columnIndex}>
401
- <ColumnContext.Provider value={column}>
402
- {child}
403
- </ColumnContext.Provider>
404
- </ColumnIndexContext.Provider>
405
- </RowIndexContext.Provider>
406
- </RowContext.Provider>
407
- );
408
- });
409
- };
410
-
411
- export const TableCell = forwardRef((props, ref) => {
412
- const column = useContext(ColumnContext);
413
- const row = useContext(RowContext);
414
- const columnIndex = useContext(ColumnIndexContext);
415
- const rowIndex = useContext(RowIndexContext);
416
- const {
417
- className = "",
418
- canSelectAll,
419
- canDragColumn,
420
- canResizeWidth,
421
- canResizeHeight,
422
- selectionImpact,
423
- onClick,
424
- action,
425
- name,
426
- valueSignal,
427
- // appeareance
428
- style,
429
- cursor,
430
- bold,
431
- alignX = column.alignX,
432
- alignY = column.alignY,
433
- backgroundColor = column.backgroundColor || row.backgroundColor,
434
- children,
435
- } = props;
436
- const cellRef = useRef();
437
- const isFirstRow = rowIndex === 0;
438
- const isFirstColumn = columnIndex === 0;
439
-
440
- // editing
441
- const editable = Boolean(action);
442
- const { editing, startEditing, stopEditing } = useEditionController();
443
- useImperativeHandle(ref, () => ({
444
- startEditing,
445
- stopEditing,
446
- element: cellRef.current,
447
- }));
448
-
449
- // stickyness
450
- const { stickyLeftFrontierColumnIndex, stickyTopFrontierRowIndex } =
451
- useContext(TableStickyContext);
452
- const stickyLeft = columnIndex <= stickyLeftFrontierColumnIndex;
453
- const stickyTop = rowIndex <= stickyTopFrontierRowIndex;
454
- const isStickyLeftFrontier = columnIndex === stickyLeftFrontierColumnIndex;
455
- const isAfterStickyLeftFrontier =
456
- columnIndex === stickyLeftFrontierColumnIndex + 1;
457
- const isStickyTopFrontier = rowIndex === stickyTopFrontierRowIndex;
458
- const isAfterStickyTopFrontier = rowIndex === stickyTopFrontierRowIndex + 1;
459
-
460
- // selection
461
- const rowId = row.id;
462
- const columnId = column.id;
463
- const selectionValue = stringifyTableSelectionValue("cell", {
464
- rowId,
465
- columnId,
466
- });
467
- const {
468
- selection,
469
- selectionController,
470
- columnIdWithSomeSelectedCellSet,
471
- rowIdWithSomeSelectedCellSet,
472
- } = useContext(TableSelectionContext);
473
- const innerSelectionImpact =
474
- selectionImpact === undefined
475
- ? isFirstRow && isFirstColumn && canSelectAll
476
- ? (allValues) => {
477
- const cells = allValues.filter(
478
- (v) => parseTableSelectionValue(v).type === "cell",
479
- );
480
- return cells;
481
- }
482
- : isFirstRow
483
- ? (allValues) => {
484
- const columnCells = allValues.filter((v) => {
485
- const selectionValueInfo = parseTableSelectionValue(v);
486
- return (
487
- selectionValueInfo.type === "cell" &&
488
- selectionValueInfo.columnId === columnId
489
- );
490
- });
491
- return columnCells;
492
- }
493
- : isFirstColumn
494
- ? (allValues) => {
495
- const rowCells = allValues.filter((v) => {
496
- const selectionValueInfo = parseTableSelectionValue(v);
497
- return (
498
- selectionValueInfo.type === "cell" &&
499
- selectionValueInfo.rowId === rowId
500
- );
501
- });
502
- return rowCells;
503
- }
504
- : undefined
505
- : selectionImpact;
506
-
507
- const { selected } = useSelectableElement(cellRef, {
508
- selection,
509
- selectionController,
510
- selectionImpact: innerSelectionImpact,
511
- // value: selectionId,
512
- });
513
-
514
- // moving column
515
- const {
516
- tableDragCloneContainerRef,
517
- tableColumnDropPreviewRef,
518
- grabTarget,
519
- grabColumn,
520
- releaseColumn,
521
- canChangeColumnOrder,
522
- } = useContext(TableDragContext);
523
- const columnGrabbed = grabTarget === `column:${columnIndex}`;
524
-
525
- // resizing
526
- const innerCanDragColumn =
527
- canDragColumn === undefined
528
- ? rowIndex === 0 && !column.immovable && Boolean(canChangeColumnOrder)
529
- : canDragColumn;
530
- const innerCanResizeWidth =
531
- canResizeWidth === undefined ? rowIndex === 0 : canResizeWidth;
532
- const innerCanResizeHeight =
533
- canResizeHeight === undefined ? columnIndex === 0 : canResizeHeight;
534
-
535
- // display
536
- const isInTableHead = useIsInTableHead();
537
- const innerStyle = {
538
- ...style,
539
- };
540
-
541
- const columnContainsSelectedCell =
542
- columnIdWithSomeSelectedCellSet.has(columnId);
543
- const rowContainsSelectedCell = rowIdWithSomeSelectedCellSet.has(rowId);
544
- const containSelectedCell =
545
- (isFirstRow && columnContainsSelectedCell) ||
546
- (isFirstColumn && rowContainsSelectedCell);
547
-
548
- // appeareance
549
- const innerBackgroundColor =
550
- backgroundColor || containSelectedCell
551
- ? "var(--selection-background-color)"
552
- : isFirstColumn
553
- ? "#F8F8F8"
554
- : isFirstRow
555
- ? "#d3e7ff"
556
- : "white";
557
- if (innerBackgroundColor) {
558
- innerStyle["--background-color"] = innerBackgroundColor;
559
- }
560
- if (cursor) {
561
- innerStyle.cursor = cursor;
562
- }
563
- const columnWidth = column.width;
564
- if (columnWidth !== undefined) {
565
- innerStyle.minWidth = `${columnWidth}px`;
566
- innerStyle.width = `${columnWidth}px`;
567
- innerStyle.maxWidth = `${columnWidth}px`;
568
- }
569
- const rowHeight = row.height;
570
- if (rowHeight !== undefined) {
571
- innerStyle.maxHeight = `${rowHeight}px`;
572
- }
573
- const innerAlignX = alignX || isFirstRow ? "center" : "start";
574
- const innerAlignY = alignY || isFirstColumn ? "center" : "start";
575
- const innerBold = bold || containSelectedCell;
576
- if (innerBold) {
577
- innerStyle.fontWeight = "bold";
578
- }
579
-
580
- const activeElement = useActiveElement();
581
- const TagName = isInTableHead ? "th" : "td";
582
-
583
- return (
584
- <TagName
585
- className={["navi_table_cell", ...className.split(" ")].join(" ")}
586
- ref={cellRef}
587
- style={innerStyle}
588
- data-align-x={innerAlignX}
589
- data-align-y={innerAlignY}
590
- // we use [data-focus] so that the attribute can be copied
591
- // to the dragged cell copies
592
- data-focus={activeElement === cellRef.current ? "" : undefined}
593
- data-first-row={isFirstRow ? "" : undefined}
594
- data-first-column={isFirstColumn ? "" : undefined}
595
- data-sticky-left={stickyLeft ? "" : undefined}
596
- data-sticky-top={stickyTop ? "" : undefined}
597
- data-sticky-left-frontier={
598
- stickyLeft && isStickyLeftFrontier ? "" : undefined
599
- }
600
- data-sticky-top-frontier={
601
- stickyTop && isStickyTopFrontier ? "" : undefined
602
- }
603
- data-after-sticky-left-frontier={
604
- isAfterStickyLeftFrontier ? "" : undefined
605
- }
606
- data-after-sticky-top-frontier={isAfterStickyTopFrontier ? "" : undefined}
607
- tabIndex={-1}
608
- data-height-xxs={
609
- rowHeight !== undefined && rowHeight < 42 ? "" : undefined
610
- }
611
- data-width-xxs={
612
- columnWidth !== undefined && columnWidth < 42 ? "" : undefined
613
- }
614
- data-selection-name={isInTableHead ? "column" : "cell"}
615
- data-selection-keyboard-toggle
616
- aria-selected={selected}
617
- data-value={selectionValue}
618
- data-editing={editing ? "" : undefined}
619
- data-grabbed={columnGrabbed ? "" : undefined}
620
- onClick={onClick}
621
- onPointerDown={(e) => {
622
- if (!innerCanDragColumn) {
623
- return;
624
- }
625
- if (e.button !== 0) {
626
- return;
627
- }
628
- initDragTableColumnViaPointer(e, {
629
- tableDragCloneContainer: tableDragCloneContainerRef.current,
630
- dropPreview: tableColumnDropPreviewRef.current,
631
- onGrab: () => grabColumn(columnIndex),
632
- onDrag: () => {},
633
- onRelease: (_, newColumnIndex) =>
634
- releaseColumn(columnIndex, newColumnIndex),
635
- });
636
- }}
637
- onDoubleClick={(e) => {
638
- if (!editable) {
639
- return;
640
- }
641
- startEditing(e);
642
- }}
643
- oneditrequested={(e) => {
644
- if (!editable) {
645
- return;
646
- }
647
- startEditing(e);
648
- }}
649
- >
650
- {editable ? (
651
- <Editable
652
- editing={editing}
653
- onEditEnd={stopEditing}
654
- value={children}
655
- action={action}
656
- name={name}
657
- valueSignal={valueSignal}
658
- height="100%"
659
- width="100%"
660
- >
661
- {children}
662
- </Editable>
663
- ) : (
664
- children
665
- )}
666
- {innerCanResizeWidth && (
667
- <TableCellColumnResizeHandles
668
- columnIndex={columnIndex}
669
- columnMinWidth={column.minWidth}
670
- columnMaxWidth={column.maxWidth}
671
- />
672
- )}
673
- {innerCanResizeHeight && (
674
- <TableCellRowResizeHandles
675
- rowIndex={rowIndex}
676
- rowMinHeight={row.minHeight}
677
- rowMaxHeight={row.maxHeight}
678
- />
679
- )}
680
- {isInTableHead && (
681
- <span className="navi_table_cell_content_bold_clone" aria-hidden="true">
682
- {children}
683
- </span>
684
- )}
685
- <div
686
- className="navi_table_cell_foreground"
687
- data-visible={columnGrabbed ? "" : undefined}
688
- ></div>
689
- </TagName>
690
- );
691
- });
692
-
693
- export const RowNumberCol = ({
694
- width = 50,
695
- minWidth = 30,
696
- maxWidth = 100,
697
- immovable = true,
698
- ...rest
699
- }) => {
700
- return (
701
- <Col
702
- id="row_number"
703
- width={width}
704
- minWidth={minWidth}
705
- maxWidth={maxWidth}
706
- immovable={immovable}
707
- {...rest}
708
- />
709
- );
710
- };
711
- export const RowNumberTableCell = (props) => {
712
- const columnIndex = useContext(ColumnIndexContext);
713
- const rowIndex = useContext(RowIndexContext);
714
- const isTopLeftCell = columnIndex === 0 && rowIndex === 0;
715
-
716
- return (
717
- <TableCell canSelectAll={isTopLeftCell} alignX="left" {...props}>
718
- {isTopLeftCell ? "" : rowIndex}
719
- </TableCell>
720
- );
721
- };