@jsenv/navi 0.0.1 → 0.1.1

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 (139) hide show
  1. package/dist/jsenv_navi.js +22959 -0
  2. package/index.js +66 -16
  3. package/package.json +23 -11
  4. package/src/actions.js +50 -26
  5. package/src/browser_integration/browser_integration.js +31 -6
  6. package/src/browser_integration/via_history.js +42 -9
  7. package/src/components/action_execution/render_actionable_component.jsx +6 -4
  8. package/src/components/action_execution/use_action.js +51 -282
  9. package/src/components/action_execution/use_execute_action.js +106 -92
  10. package/src/components/action_execution/use_run_on_mount.js +9 -0
  11. package/src/components/action_renderer.jsx +21 -32
  12. package/src/components/demos/0_button_demo.html +574 -103
  13. package/src/components/demos/10_column_reordering_debug.html +277 -0
  14. package/src/components/demos/11_table_selection_debug.html +432 -0
  15. package/src/components/demos/1_checkbox_demo.html +579 -202
  16. package/src/components/demos/2_input_textual_demo.html +81 -138
  17. package/src/components/demos/3_radio_demo.html +0 -2
  18. package/src/components/demos/4_select_demo.html +19 -23
  19. package/src/components/demos/6_tablist_demo.html +77 -0
  20. package/src/components/demos/7_table_selection_demo.html +176 -0
  21. package/src/components/demos/8_table_fixed_headers_demo.html +584 -0
  22. package/src/components/demos/9_table_column_drag_demo.html +325 -0
  23. package/src/components/demos/action/0_button_demo.html +2 -4
  24. package/src/components/demos/action/1_input_text_demo.html +643 -222
  25. package/src/components/demos/action/3_details_demo.html +146 -115
  26. package/src/components/demos/action/4_input_checkbox_demo.html +442 -322
  27. package/src/components/demos/action/5_input_checkbox_state_demo.html +270 -0
  28. package/src/components/demos/action/6_checkbox_list_demo.html +304 -72
  29. package/src/components/demos/action/7_radio_list_demo.html +310 -170
  30. package/src/components/demos/action/{8_editable_text_demo.html → 8_editable_demo.html} +65 -76
  31. package/src/components/demos/action/9_link_demo.html +84 -62
  32. package/src/components/demos/ui_transition/0_action_renderer_ui_transition_demo.html +695 -0
  33. package/src/components/demos/ui_transition/1_nested_ui_transition_demo.html +429 -0
  34. package/src/components/demos/ui_transition/2_height_transition_test.html +295 -0
  35. package/src/components/details/details.jsx +62 -64
  36. package/src/components/edition/editable.jsx +186 -0
  37. package/src/components/field/README.md +247 -0
  38. package/src/components/{input → field}/button.jsx +151 -130
  39. package/src/components/field/checkbox_list.jsx +184 -0
  40. package/src/components/{collect_form_element_values.js → field/collect_form_element_values.js} +7 -4
  41. package/src/components/{input → field}/field_css.js +4 -1
  42. package/src/components/field/form.jsx +211 -0
  43. package/src/components/{input → field}/input.jsx +1 -0
  44. package/src/components/{input → field}/input_checkbox.jsx +132 -155
  45. package/src/components/{input → field}/input_radio.jsx +135 -46
  46. package/src/components/field/input_textual.jsx +418 -0
  47. package/src/components/field/label.jsx +32 -0
  48. package/src/components/field/radio_list.jsx +182 -0
  49. package/src/components/{input → field}/select.jsx +17 -32
  50. package/src/components/field/use_action_events.js +132 -0
  51. package/src/components/field/use_form_events.js +55 -0
  52. package/src/components/field/use_ui_state_controller.js +506 -0
  53. package/src/components/item_tracker/README.md +461 -0
  54. package/src/components/item_tracker/use_isolated_item_tracker.jsx +209 -0
  55. package/src/components/item_tracker/use_isolated_item_tracker_demo.html +148 -0
  56. package/src/components/item_tracker/use_isolated_item_tracker_demo.jsx +460 -0
  57. package/src/components/item_tracker/use_item_tracker.jsx +143 -0
  58. package/src/components/item_tracker/use_item_tracker_demo.html +207 -0
  59. package/src/components/item_tracker/use_item_tracker_demo.jsx +216 -0
  60. package/src/components/keyboard_shortcuts/active_keyboard_shortcuts.jsx +87 -0
  61. package/src/components/keyboard_shortcuts/aria_key_shortcuts.js +61 -0
  62. package/src/components/keyboard_shortcuts/keyboard_key_meta.js +17 -0
  63. package/src/components/keyboard_shortcuts/keyboard_shortcuts.js +371 -0
  64. package/src/components/link/link.jsx +65 -102
  65. package/src/components/link/link_with_icon.jsx +52 -0
  66. package/src/components/loader/loader_background.jsx +85 -64
  67. package/src/components/loader/rectangle_loading.jsx +38 -19
  68. package/src/components/route.jsx +8 -4
  69. package/src/components/selection/selection.jsx +1583 -0
  70. package/src/components/svg/font_sized_svg.jsx +45 -0
  71. package/src/components/svg/icon_and_text.jsx +21 -0
  72. package/src/components/svg/svg_mask_overlay.jsx +105 -0
  73. package/src/components/table/drag/table_drag.jsx +506 -0
  74. package/src/components/table/resize/table_resize.jsx +650 -0
  75. package/src/components/table/resize/table_size.js +43 -0
  76. package/src/components/table/selection/table_selection.js +106 -0
  77. package/src/components/table/selection/table_selection.jsx +203 -0
  78. package/src/components/table/sticky/sticky_group.js +354 -0
  79. package/src/components/table/sticky/table_sticky.js +25 -0
  80. package/src/components/table/sticky/table_sticky.jsx +501 -0
  81. package/src/components/table/table.jsx +721 -0
  82. package/src/components/table/table_css.js +211 -0
  83. package/src/components/table/table_ui.jsx +49 -0
  84. package/src/components/table/use_cells_and_columns.js +90 -0
  85. package/src/components/table/use_object_array_to_cells.js +46 -0
  86. package/src/components/table/z_indexes.js +23 -0
  87. package/src/components/tablist/tablist.jsx +99 -0
  88. package/src/components/text/overflow.jsx +15 -0
  89. package/src/components/text/text_and_count.jsx +28 -0
  90. package/src/components/ui_transition.jsx +128 -0
  91. package/src/components/use_auto_focus.js +58 -7
  92. package/src/components/use_batch_during_render.js +33 -0
  93. package/src/components/use_debounce_true.js +7 -7
  94. package/src/components/use_dependencies_diff.js +35 -0
  95. package/src/components/use_focus_group.js +4 -3
  96. package/src/components/use_initial_value.js +8 -34
  97. package/src/components/use_signal_sync.js +1 -1
  98. package/src/components/use_stable_callback.js +68 -0
  99. package/src/components/use_state_array.js +16 -9
  100. package/src/docs/actions.md +22 -0
  101. package/src/notes.md +33 -12
  102. package/src/route/route.js +97 -47
  103. package/src/store/resource_graph.js +2 -1
  104. package/src/store/tests/{resource_graph_dependencies.test.js → resource_graph_dependencies.test_manual.js} +13 -13
  105. package/src/utils/is_signal.js +20 -0
  106. package/src/utils/stringify_for_display.js +4 -23
  107. package/src/validation/constraints/confirm_constraint.js +14 -0
  108. package/src/validation/constraints/create_unique_value_constraint.js +27 -0
  109. package/src/validation/constraints/native_constraints.js +313 -0
  110. package/src/validation/constraints/readonly_constraint.js +36 -0
  111. package/src/validation/constraints/single_space_constraint.js +13 -0
  112. package/src/validation/custom_constraint_validation.js +599 -0
  113. package/src/validation/custom_message.js +18 -0
  114. package/src/validation/demos/browser_style.png +0 -0
  115. package/src/validation/demos/form_validation_demo.html +142 -0
  116. package/src/validation/demos/form_validation_demo_preact.html +87 -0
  117. package/src/validation/demos/form_validation_native_popover_demo.html +168 -0
  118. package/src/validation/demos/form_validation_vs_native_demo.html +172 -0
  119. package/src/validation/demos/validation_message_demo.html +203 -0
  120. package/src/validation/hooks/use_constraints.js +23 -0
  121. package/src/validation/hooks/use_custom_validation_ref.js +73 -0
  122. package/src/validation/hooks/use_validation_message.js +19 -0
  123. package/src/validation/validation_message.js +741 -0
  124. package/src/components/editable_text/editable_text.jsx +0 -96
  125. package/src/components/form.jsx +0 -144
  126. package/src/components/input/checkbox_list.jsx +0 -294
  127. package/src/components/input/field.jsx +0 -61
  128. package/src/components/input/input_textual.jsx +0 -338
  129. package/src/components/input/radio_list.jsx +0 -283
  130. package/src/components/input/use_form_event.js +0 -20
  131. package/src/components/input/use_on_change.js +0 -12
  132. package/src/components/selection/selection.js +0 -5
  133. package/src/components/selection/selection_context.jsx +0 -262
  134. package/src/components/shortcut/shortcut_context.jsx +0 -390
  135. package/src/components/use_action_events.js +0 -37
  136. package/src/utils/iterable_weak_set.js +0 -62
  137. /package/src/components/demos/action/{11_nested_shortcuts_demo.html → 11_nested_shortcuts_demo.xhtml} +0 -0
  138. /package/src/components/{shortcut → keyboard_shortcuts}/os.js +0 -0
  139. /package/src/route/{route.test.html → route.xtest.html} +0 -0
@@ -0,0 +1,211 @@
1
+ import { Z_INDEX_EDITING } from "./z_indexes.js";
2
+
3
+ /*
4
+ * Box-shadow border mapping template:
5
+ *
6
+ * box-shadow:
7
+ * inset 0 1px 0 0 color, // Top border
8
+ * inset 1px 0 0 0 color, // Left border
9
+ * inset -1px 0 0 0 color, // Right border
10
+ * inset 0 -1px 0 0 color; // Bottom border
11
+ */
12
+
13
+ import.meta.css = /* css */ `
14
+ .navi_table_root {
15
+ position: relative;
16
+ max-width: var(--table-max-width, none);
17
+ max-height: var(--table-max-height, none);
18
+ }
19
+
20
+ .navi_table_container {
21
+ --border-color: #e1e1e1;
22
+ --focus-border-color: #0078d4;
23
+ position: relative;
24
+ }
25
+
26
+ .navi_table {
27
+ border-radius: 2px;
28
+ border-spacing: 0; /* Required for manual border collapse */
29
+ }
30
+ .navi_table_cell {
31
+ white-space: nowrap;
32
+ overflow: hidden;
33
+ text-overflow: ellipsis;
34
+ background-color: var(--background-color, transparent);
35
+ }
36
+
37
+ .navi_table_cell[data-align-x="start"] {
38
+ text-align: left;
39
+ }
40
+ .navi_table_cell[data-align-x="center"] {
41
+ text-align: center;
42
+ }
43
+ .navi_table_cell[data-align-y="end"] {
44
+ text-align: right;
45
+ }
46
+ .navi_table_cell[data-align-x="start"] {
47
+ vertical-align: top;
48
+ }
49
+ .navi_table_cell[data-align-y="center"] {
50
+ vertical-align: middle;
51
+ }
52
+ .navi_table_cell[data-align-y="end"] {
53
+ vertical-align: bottom;
54
+ }
55
+
56
+ /* Table borders using ::before pseudo-elements */
57
+ /* Default: each cell draws all its own borders (no border-collapse) */
58
+ .navi_table_cell {
59
+ border: none; /* Remove default borders - we'll use pseudo-elements */
60
+ /* Required for pseudo-element positioning */
61
+ position: relative;
62
+ }
63
+
64
+ .navi_table_cell::before {
65
+ content: "";
66
+ position: absolute;
67
+ inset: 0;
68
+ pointer-events: none;
69
+ box-shadow:
70
+ inset 0 1px 0 0 var(--border-color),
71
+ inset 1px 0 0 0 var(--border-color),
72
+ inset -1px 0 0 0 var(--border-color),
73
+ inset 0 -1px 0 0 var(--border-color);
74
+ }
75
+ .navi_table_cell::after {
76
+ content: "";
77
+ position: absolute;
78
+ /* Default: include bottom and right borders (owned by this cell) */
79
+ inset: 0;
80
+ pointer-events: none;
81
+ }
82
+
83
+ /* padding */
84
+ .navi_table_cell {
85
+ padding-left: 12px;
86
+ padding-right: 12px;
87
+ padding-top: 8px;
88
+ padding-bottom: 8px;
89
+ }
90
+ .navi_table_cell[data-width-xxs] {
91
+ padding-left: 0;
92
+ padding-right: 0;
93
+ }
94
+ .navi_table_cell[data-height-xxs] {
95
+ padding-top: 0;
96
+ padding-bottom: 0;
97
+ }
98
+ .navi_table_cell[data-editing] input {
99
+ padding: 0;
100
+ padding-left: 12px;
101
+ }
102
+ .navi_table [data-sticky-left-frontier] {
103
+ /* padding-left: 12px; */
104
+ /* 12 px + 5px of the sticky frontier */
105
+ /* padding-right: 17px; */
106
+ }
107
+
108
+ .navi_table_cell {
109
+ user-select: none;
110
+ }
111
+
112
+ /* Number column specific styling */
113
+ .navi_row_number_cell {
114
+ text-align: center;
115
+ background: #fafafa;
116
+ font-weight: 500;
117
+ color: #666;
118
+ user-select: none;
119
+ }
120
+
121
+ .navi_table_cell_content_bold_clone {
122
+ font-weight: bold; /* force bold to compute max width */
123
+ visibility: hidden; /* not visible */
124
+ display: block; /* in-flow so it contributes to width */
125
+ height: 0; /* zero height so it doesn't change layout height */
126
+ overflow: hidden; /* avoid any accidental height */
127
+ pointer-events: none; /* inert */
128
+ }
129
+
130
+ /* Border-collapse mode: each cell only owns specific borders to avoid doubling */
131
+
132
+ /* Base rule: all cells get right and bottom borders */
133
+ .navi_table[data-border-collapse] .navi_table_cell::before {
134
+ box-shadow:
135
+ inset -1px 0 0 0 var(--border-color),
136
+ inset 0 -1px 0 0 var(--border-color);
137
+ }
138
+
139
+ /* Header cells (all th) get top border in addition to right and bottom */
140
+ .navi_table[data-border-collapse] .navi_table_cell[data-first-row]::before {
141
+ box-shadow:
142
+ inset 0 1px 0 0 var(--border-color),
143
+ inset -1px 0 0 0 var(--border-color),
144
+ inset 0 -1px 0 0 var(--border-color);
145
+ }
146
+
147
+ /* First column cells get left border in addition to right and bottom */
148
+ .navi_table[data-border-collapse]
149
+ .navi_table_cell[data-first-column]::before {
150
+ box-shadow:
151
+ inset 1px 0 0 0 var(--border-color),
152
+ inset -1px 0 0 0 var(--border-color),
153
+ inset 0 -1px 0 0 var(--border-color);
154
+ }
155
+
156
+ /* Header first column gets all four borders */
157
+ .navi_table[data-border-collapse]
158
+ .navi_table_cell[data-first-row][data-first-column]::before {
159
+ box-shadow:
160
+ inset 0 1px 0 0 var(--border-color),
161
+ inset 1px 0 0 0 var(--border-color),
162
+ inset -1px 0 0 0 var(--border-color),
163
+ inset 0 -1px 0 0 var(--border-color);
164
+ }
165
+
166
+ /* Focus styles */
167
+ .navi_table_cell[data-focus] {
168
+ outline: none; /* Remove default outline */
169
+ }
170
+
171
+ .navi_table_cell[data-focus]::after {
172
+ box-shadow:
173
+ inset 0 2px 0 0 var(--focus-border-color),
174
+ inset -2px 0 0 0 var(--focus-border-color),
175
+ inset 0 -2px 0 0 var(--focus-border-color),
176
+ inset 2px 0 0 0 var(--focus-border-color) !important;
177
+ }
178
+
179
+ .navi_table {
180
+ font-size: 16px;
181
+ font-family: Arial;
182
+
183
+ --editing-border-color: #a8c7fa;
184
+ }
185
+
186
+ .navi_table_cell[data-editing] .navi_table_cell_content {
187
+ outline: 2px solid #a8c7fa;
188
+ outline-offset: 0px;
189
+ }
190
+
191
+ .navi_table_cell[data-editing] input {
192
+ width: 100%;
193
+ height: 100%;
194
+ display: inline-flex;
195
+ flex-grow: 1;
196
+ border-radius: 0; /* match table cell border-radius */
197
+ border: none;
198
+ font-size: 16px;
199
+ }
200
+
201
+ .navi_table_cell[data-editing]
202
+ input[type="number"]::-webkit-inner-spin-button {
203
+ width: 14px;
204
+ height: 30px;
205
+ }
206
+
207
+ .navi_table_cell[data-editing] {
208
+ outline: 2px solid var(--editing-border-color);
209
+ z-index: ${Z_INDEX_EDITING};
210
+ }
211
+ `;
@@ -0,0 +1,49 @@
1
+ import { visibleRectEffect } from "@jsenv/dom";
2
+ import { createPortal, forwardRef } from "preact/compat";
3
+ import { useLayoutEffect } from "preact/hooks";
4
+
5
+ import { Z_INDEX_TABLE_UI } from "./z_indexes.js";
6
+
7
+ import.meta.css = /* css */ `
8
+ .navi_table_ui {
9
+ position: fixed;
10
+ z-index: ${Z_INDEX_TABLE_UI};
11
+ overflow: hidden; /* Ensure UI elements cannot impact scrollbars of the document */
12
+ inset: 0;
13
+ pointer-events: none; /* UI elements must use pointer-events: auto if they need to be interactive */
14
+ /* background: rgba(0, 255, 0, 0.2); */
15
+ }
16
+ `;
17
+
18
+ export const TableUI = forwardRef((props, ref) => {
19
+ const { tableRef, tableId, children } = props;
20
+
21
+ // ui positioning
22
+ useLayoutEffect(() => {
23
+ const ui = ref.current;
24
+ const table = tableRef.current;
25
+ if (!ui || !table) {
26
+ return null;
27
+ }
28
+
29
+ // TODO: external code should be able to call tableVisibleRectEffect.check();
30
+ // (for the drag operation when we scroll)
31
+ // -> actually not that important because browser will dispatch "scroll" events
32
+ // cause by programmatic scrolls before re-painting
33
+ // -> no intermediate state visible to the user where overlay is not in sync
34
+ const tableVisibleRectEffect = visibleRectEffect(table, (visibleRect) => {
35
+ ui.style.setProperty("--table-visual-left", `${visibleRect.left}px`);
36
+ ui.style.setProperty("--table-visual-width", `${visibleRect.width}px`);
37
+ ui.style.setProperty("--table-visual-top", `${visibleRect.top}px`);
38
+ ui.style.setProperty("--table-visual-height", `${visibleRect.height}px`);
39
+ });
40
+ return tableVisibleRectEffect.disconnect;
41
+ });
42
+
43
+ return createPortal(
44
+ <div ref={ref} className="navi_table_ui" data-overlay-for={tableId}>
45
+ {children}
46
+ </div>,
47
+ document.body,
48
+ );
49
+ });
@@ -0,0 +1,90 @@
1
+ import { useMemo, useState } from "preact/hooks";
2
+
3
+ export const useCellsAndColumns = (cells, columns) => {
4
+ const [columnIds, idToColumnMap] = useMemo(() => {
5
+ const columnIds = [];
6
+ const idToColumnMap = new Map();
7
+ for (const column of columns) {
8
+ const columnId = column.id;
9
+ columnIds.push(columnId);
10
+ idToColumnMap.set(columnId, column);
11
+ }
12
+ return [columnIds, idToColumnMap];
13
+ }, [columns]);
14
+ const [orderedAllColumnIds, setOrderedAllColumnIds] = useState(columnIds);
15
+ const orderedColumnIds = [];
16
+ for (const columnId of orderedAllColumnIds) {
17
+ if (!columnIds.includes(columnId)) {
18
+ // generated column (like the row column)
19
+ continue;
20
+ }
21
+ orderedColumnIds.push(columnId);
22
+ }
23
+ const orderedColumns = [];
24
+ for (const columnId of orderedColumnIds) {
25
+ const column = idToColumnMap.get(columnId);
26
+ orderedColumns.push(column);
27
+ }
28
+
29
+ // Base cell values in original column order (2D array: rows x columns)
30
+ const [baseCells, setBaseCells] = useState(cells);
31
+
32
+ // Memoized index mapping for performance - maps display index to original index
33
+ const columnOrderedIndexMap = useMemo(() => {
34
+ const indexMap = new Map();
35
+ for (let columnIndex = 0; columnIndex < columnIds.length; columnIndex++) {
36
+ const columnIdAtThisIndex = orderedColumnIds[columnIndex];
37
+ const originalIndex = columnIds.indexOf(columnIdAtThisIndex);
38
+ indexMap.set(columnIndex, originalIndex);
39
+ }
40
+ return indexMap;
41
+ }, [columnIds, orderedColumnIds]);
42
+
43
+ // Derived state: reorder cell values according to column display order
44
+ const orderedCells = useMemo(() => {
45
+ const reorderedCells = [];
46
+ for (let y = 0; y < baseCells.length; y++) {
47
+ const originalRow = baseCells[y];
48
+ const reorderedRow = [];
49
+ for (let x = 0; x < orderedColumnIds.length; x++) {
50
+ const columnOrderedIndex = columnOrderedIndexMap.get(x);
51
+ const cellValue = originalRow[columnOrderedIndex];
52
+ reorderedRow.push(cellValue);
53
+ }
54
+ reorderedCells.push(reorderedRow);
55
+ }
56
+ return reorderedCells;
57
+ }, [baseCells, columnOrderedIndexMap, orderedColumnIds.length]);
58
+
59
+ const setCellValue = ({ columnIndex, rowIndex }, value) => {
60
+ const originalColumnIndex = columnOrderedIndexMap.get(columnIndex);
61
+ if (originalColumnIndex === undefined) {
62
+ console.warn(`Invalid column index: ${columnIndex}`);
63
+ return;
64
+ }
65
+ setBaseCells((previousCells) => {
66
+ const newCells = [];
67
+ for (let y = 0; y < previousCells.length; y++) {
68
+ const currentRow = previousCells[y];
69
+ if (y !== rowIndex) {
70
+ newCells.push(currentRow);
71
+ continue;
72
+ }
73
+ const newRow = [];
74
+ for (let x = 0; x < currentRow.length; x++) {
75
+ const cellValue = x === originalColumnIndex ? value : currentRow[x];
76
+ newRow.push(cellValue);
77
+ }
78
+ newCells.push(newRow);
79
+ }
80
+ return newCells;
81
+ });
82
+ };
83
+
84
+ return {
85
+ cells: orderedCells,
86
+ setCellValue,
87
+ columns: orderedColumns,
88
+ setColumnOrder: setOrderedAllColumnIds,
89
+ };
90
+ };
@@ -0,0 +1,46 @@
1
+ import { useMemo } from "preact/hooks";
2
+
3
+ /**
4
+ * Custom hook for converting an array of objects into a 2D array of cell values.
5
+ *
6
+ * This hook is essential for table components that receive data as objects but need
7
+ * to work with a 2D array structure for rendering and manipulation:
8
+ *
9
+ * 1. **Object to Array Conversion**: Extracts values from object properties based
10
+ * on column definitions, creating a consistent 2D array structure.
11
+ *
12
+ * 2. **Column Mapping**: Uses column names/keys to determine which object property
13
+ * corresponds to each column position.
14
+ *
15
+ * 3. **Missing Data Handling**: Provides fallback values when object properties
16
+ * don't exist for specific columns.
17
+ *
18
+ * 4. **Performance**: Memoized to avoid unnecessary recalculations when data
19
+ * or column definitions haven't changed.
20
+ *
21
+ * Common use case: Converting API response data (array of objects) into table-ready
22
+ * format for rendering with existing cell management hooks.
23
+ */
24
+
25
+ /**
26
+ * Convert an array of objects into a 2D array of cell values
27
+ * @param {Array<Object>} data - Array of objects to convert
28
+ * @param {Array<Object>} columns - Column definitions
29
+ * @param {string} columns[].key - Property key to extract from each object
30
+ * @param {*} [columns[].defaultValue] - Default value when property is missing (optional)
31
+ * @returns {Array<Array>} 2D array of cell values
32
+ */
33
+ export const useObjectArrayToCells = (data, columns) => {
34
+ // Convert object array to 2D cell values array
35
+ const cellValues = useMemo(() => {
36
+ return data.map((rowObject) =>
37
+ columns.map((column) => {
38
+ const value = rowObject[column.key];
39
+ // Return the value if it exists, otherwise use default or empty string
40
+ return value !== undefined ? value : (column.defaultValue ?? "");
41
+ }),
42
+ );
43
+ }, [data, columns]);
44
+
45
+ return cellValues;
46
+ };
@@ -0,0 +1,23 @@
1
+ export const Z_INDEX_EDITING = 1; /* To go above neighbours, but should not be too big to stay under the sticky cells */
2
+
3
+ /* needed because cell uses position:relative, sticky must win even if before in DOM order */
4
+ export const Z_INDEX_STICKY_COLUMN = Z_INDEX_EDITING + 1;
5
+ export const Z_INDEX_STICKY_ROW = Z_INDEX_STICKY_COLUMN + 1;
6
+ export const Z_INDEX_STICKY_CORNER = Z_INDEX_STICKY_ROW + 1;
7
+
8
+ export const Z_INDEX_STICKY_FRONTIER_BACKDROP = Z_INDEX_STICKY_CORNER + 1;
9
+ export const Z_INDEX_STICKY_FRONTIER_PREVIEW =
10
+ Z_INDEX_STICKY_FRONTIER_BACKDROP + 1;
11
+ export const Z_INDEX_STICKY_FRONTIER_GHOST =
12
+ Z_INDEX_STICKY_FRONTIER_PREVIEW + 1;
13
+
14
+ export const Z_INDEX_TABLE_UI_CONTAINER = Z_INDEX_STICKY_CORNER + 1;
15
+ export const Z_INDEX_DRAGGING_CLONE = Z_INDEX_STICKY_CORNER + 1; // above sticky cells
16
+ export const Z_INDEX_RESIZER_BACKDROP = Z_INDEX_STICKY_CORNER + 1; // above sticky cells
17
+
18
+ export const Z_INDEX_CELL_FOREGROUND = 1;
19
+ export const Z_INDEX_STICKY_FRONTIER_HANDLE = 2; // above the cell placeholder to keep the sticky frontier visible
20
+ export const Z_INDEX_RESIZER_HANDLE = Z_INDEX_STICKY_FRONTIER_HANDLE + 1;
21
+ export const Z_INDEX_DROP_PREVIEW = Z_INDEX_STICKY_CORNER + 1;
22
+
23
+ export const Z_INDEX_TABLE_UI = Z_INDEX_STICKY_CORNER + 1;
@@ -0,0 +1,99 @@
1
+ import.meta.css = /* css */ `
2
+ .navi_tablist {
3
+ display: flex;
4
+ overflow-x: auto;
5
+ overflow-y: hidden;
6
+ justify-content: space-between;
7
+ }
8
+
9
+ .navi_tablist > ul {
10
+ align-items: center;
11
+ display: flex;
12
+ gap: 0.5rem;
13
+ list-style: none;
14
+ margin: 0;
15
+ padding: 0;
16
+ }
17
+
18
+ .navi_tablist > ul > li {
19
+ display: inline-flex;
20
+ position: relative;
21
+ }
22
+
23
+ .navi_tab {
24
+ white-space: nowrap;
25
+ display: flex;
26
+ flex-direction: column;
27
+ }
28
+
29
+ .navi_tab_content {
30
+ transition: background 0.12s ease-out;
31
+ border-radius: 6px;
32
+ text-decoration: none;
33
+ line-height: 30px;
34
+ display: flex;
35
+ padding: 0 0.5rem;
36
+ }
37
+
38
+ .navi_tab:hover .navi_tab_content {
39
+ background: #dae0e7;
40
+ color: #010409;
41
+ }
42
+
43
+ .navi_tab .active_marker {
44
+ display: flex;
45
+ background: transparent;
46
+ border-radius: 0.1px;
47
+ width: 100%;
48
+ z-index: 1;
49
+ height: 2px;
50
+ margin-top: 5px;
51
+ }
52
+
53
+ /* Hidden bold clone to reserve space for bold width without affecting height */
54
+ .navi_tab_content_bold_clone {
55
+ font-weight: 600; /* force bold to compute max width */
56
+ visibility: hidden; /* not visible */
57
+ display: block; /* in-flow so it contributes to width */
58
+ height: 0; /* zero height so it doesn't change layout height */
59
+ overflow: hidden; /* avoid any accidental height */
60
+ pointer-events: none; /* inert */
61
+ }
62
+
63
+ .navi_tab[aria-selected="true"] .active_marker {
64
+ background: rgb(205, 52, 37);
65
+ }
66
+
67
+ .navi_tab[aria-selected="true"] .navi_tab_content {
68
+ font-weight: 600;
69
+ }
70
+ `;
71
+
72
+ export const TabList = ({ children, ...props }) => {
73
+ return (
74
+ <nav className="navi_tablist" role="tablist" {...props}>
75
+ <ul>
76
+ {children.map((child) => {
77
+ return <li key={child.props.key}>{child}</li>;
78
+ })}
79
+ </ul>
80
+ </nav>
81
+ );
82
+ };
83
+
84
+ export const Tab = ({ children, selected, ...props }) => {
85
+ return (
86
+ <div
87
+ className="navi_tab"
88
+ role="tab"
89
+ aria-selected={selected ? "true" : "false"}
90
+ {...props}
91
+ >
92
+ <div className="navi_tab_content">{children}</div>
93
+ <div className="navi_tab_content_bold_clone" aria-hidden="true">
94
+ {children}
95
+ </div>
96
+ <span className="active_marker"></span>
97
+ </div>
98
+ );
99
+ };
@@ -0,0 +1,15 @@
1
+ export const Overflow = ({ className, children, afterContent }) => {
2
+ return (
3
+ <div
4
+ className={className}
5
+ style="display: flex; flex-wrap: wrap; overflow: hidden; width: 100%; box-sizing: border-box; white-space: nowrap; text-overflow: ellipsis;"
6
+ >
7
+ <div style="display: flex; flex-grow: 1; width: 0; gap: 0.3em">
8
+ <div style="overflow: hidden; max-width: 100%; text-overflow: ellipsis;">
9
+ {children}
10
+ </div>
11
+ {afterContent}
12
+ </div>
13
+ </div>
14
+ );
15
+ };
@@ -0,0 +1,28 @@
1
+ import { Overflow } from "./overflow.jsx";
2
+
3
+ import.meta.css = /* css */ `
4
+ .text_and_count {
5
+ display: flex;
6
+ align-items: center;
7
+ gap: 3px;
8
+ flex: 1;
9
+ white-space: nowrap;
10
+ }
11
+
12
+ .count {
13
+ position: relative;
14
+ top: -1px;
15
+ color: rgba(28, 43, 52, 0.4);
16
+ }
17
+ `;
18
+
19
+ export const TextAndCount = ({ text, count }) => {
20
+ return (
21
+ <Overflow
22
+ className="text_and_count"
23
+ afterContent={count > 0 && <span className="count">({count})</span>}
24
+ >
25
+ <span className="label">{text}</span>
26
+ </Overflow>
27
+ );
28
+ };
@@ -0,0 +1,128 @@
1
+ /**
2
+ * UITransition
3
+ *
4
+ * A Preact component that enables smooth animated transitions between its children when the content changes.
5
+ * It observes content keys and phases to create different types of transitions.
6
+ *
7
+ * Features:
8
+ * - Content transitions: Between different content keys (e.g., user profiles, search results)
9
+ * - Phase transitions: Between loading/content/error states for the same content key
10
+ * - Automatic size animation to accommodate content changes
11
+ * - Configurable transition types: "slide-left", "cross-fade"
12
+ * - Independent duration control for content and phase transitions
13
+ *
14
+ * Usage:
15
+ * - Wrap dynamic content in <UITransition> to animate between states
16
+ * - Set a unique `data-content-key` on your rendered content to identify each content variant
17
+ * - Use `data-content-phase` to mark loading/error states for phase transitions
18
+ * - Configure transition types and durations for both content and phase changes
19
+ *
20
+ * Example:
21
+ *
22
+ * <UITransition
23
+ * transitionType="slide-left"
24
+ * transitionDuration={400}
25
+ * phaseTransitionType="cross-fade"
26
+ * phaseTransitionDuration={300}
27
+ * >
28
+ * {isLoading
29
+ * ? <Spinner data-content-key={userId} data-content-phase />
30
+ * : <UserProfile user={user} data-content-key={userId} />}
31
+ * </UITransition>
32
+ *
33
+ * When `data-content-key` changes, UITransition animates content transitions.
34
+ * When `data-content-phase` changes for the same key, it animates phase transitions.
35
+ */
36
+
37
+ import { initUITransition } from "@jsenv/dom";
38
+ import { createContext } from "preact";
39
+ import { useContext, useLayoutEffect, useRef, useState } from "preact/hooks";
40
+
41
+ const ContentKeyContext = createContext();
42
+
43
+ export const UITransition = ({
44
+ children,
45
+ contentKey,
46
+ sizeTransition,
47
+ sizeTransitionDuration,
48
+ transitionType,
49
+ transitionDuration,
50
+ phaseTransitionType,
51
+ phaseTransitionDuration,
52
+ debugTransition,
53
+ ...props
54
+ }) => {
55
+ const [contentKeyFromContext, setContentKeyFromContext] = useState();
56
+ const effectiveContentKey = contentKey || contentKeyFromContext;
57
+
58
+ const ref = useRef();
59
+ useLayoutEffect(() => {
60
+ const uiTransition = initUITransition(ref.current);
61
+ return () => {
62
+ uiTransition.cleanup();
63
+ };
64
+ }, []);
65
+
66
+ return (
67
+ <ContentKeyContext.Provider value={setContentKeyFromContext}>
68
+ <div
69
+ ref={ref}
70
+ {...props}
71
+ className="ui_transition_container"
72
+ data-size-transition={sizeTransition ? "" : undefined}
73
+ data-size-transition-duration={
74
+ sizeTransitionDuration ? sizeTransitionDuration : undefined
75
+ }
76
+ data-content-transition={transitionType ? transitionType : undefined}
77
+ data-content-transition-duration={
78
+ transitionDuration ? transitionDuration : undefined
79
+ }
80
+ data-phase-transition={
81
+ phaseTransitionType ? phaseTransitionType : undefined
82
+ }
83
+ data-phase-transition-duration={
84
+ phaseTransitionDuration ? phaseTransitionDuration : undefined
85
+ }
86
+ data-debug-transition={debugTransition ? "" : undefined}
87
+ >
88
+ <div className="ui_transition_outer_wrapper">
89
+ <div className="ui_transition_measure_wrapper">
90
+ <div
91
+ className="ui_transition_slot"
92
+ data-content-key={
93
+ effectiveContentKey ? effectiveContentKey : undefined
94
+ }
95
+ >
96
+ {children}
97
+ </div>
98
+ <div className="ui_transition_phase_overlay"></div>
99
+ </div>
100
+ </div>
101
+ <div className="ui_transition_content_overlay"></div>
102
+ </div>
103
+ </ContentKeyContext.Provider>
104
+ );
105
+ };
106
+
107
+ export const useContentKey = (key, enabled) => {
108
+ const setKey = useContext(ContentKeyContext);
109
+ if (setKey && enabled) {
110
+ setKey(key);
111
+ }
112
+ useLayoutEffect(() => {
113
+ if (!setKey || !enabled) {
114
+ return null;
115
+ }
116
+ return () => {
117
+ setKey((v) => {
118
+ if (v !== key) {
119
+ // the current key is different from the one we set
120
+ // it means another component set it in the meantime
121
+ // we should not clear it
122
+ return v;
123
+ }
124
+ return undefined;
125
+ });
126
+ };
127
+ }, [enabled]);
128
+ };