@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.
- package/dist/jsenv_navi.js +22959 -0
- package/index.js +66 -16
- package/package.json +23 -11
- package/src/actions.js +50 -26
- package/src/browser_integration/browser_integration.js +31 -6
- package/src/browser_integration/via_history.js +42 -9
- package/src/components/action_execution/render_actionable_component.jsx +6 -4
- package/src/components/action_execution/use_action.js +51 -282
- package/src/components/action_execution/use_execute_action.js +106 -92
- package/src/components/action_execution/use_run_on_mount.js +9 -0
- package/src/components/action_renderer.jsx +21 -32
- package/src/components/demos/0_button_demo.html +574 -103
- package/src/components/demos/10_column_reordering_debug.html +277 -0
- package/src/components/demos/11_table_selection_debug.html +432 -0
- package/src/components/demos/1_checkbox_demo.html +579 -202
- package/src/components/demos/2_input_textual_demo.html +81 -138
- package/src/components/demos/3_radio_demo.html +0 -2
- package/src/components/demos/4_select_demo.html +19 -23
- package/src/components/demos/6_tablist_demo.html +77 -0
- package/src/components/demos/7_table_selection_demo.html +176 -0
- package/src/components/demos/8_table_fixed_headers_demo.html +584 -0
- package/src/components/demos/9_table_column_drag_demo.html +325 -0
- package/src/components/demos/action/0_button_demo.html +2 -4
- package/src/components/demos/action/1_input_text_demo.html +643 -222
- package/src/components/demos/action/3_details_demo.html +146 -115
- package/src/components/demos/action/4_input_checkbox_demo.html +442 -322
- package/src/components/demos/action/5_input_checkbox_state_demo.html +270 -0
- package/src/components/demos/action/6_checkbox_list_demo.html +304 -72
- package/src/components/demos/action/7_radio_list_demo.html +310 -170
- package/src/components/demos/action/{8_editable_text_demo.html → 8_editable_demo.html} +65 -76
- package/src/components/demos/action/9_link_demo.html +84 -62
- package/src/components/demos/ui_transition/0_action_renderer_ui_transition_demo.html +695 -0
- package/src/components/demos/ui_transition/1_nested_ui_transition_demo.html +429 -0
- package/src/components/demos/ui_transition/2_height_transition_test.html +295 -0
- package/src/components/details/details.jsx +62 -64
- package/src/components/edition/editable.jsx +186 -0
- package/src/components/field/README.md +247 -0
- package/src/components/{input → field}/button.jsx +151 -130
- package/src/components/field/checkbox_list.jsx +184 -0
- package/src/components/{collect_form_element_values.js → field/collect_form_element_values.js} +7 -4
- package/src/components/{input → field}/field_css.js +4 -1
- package/src/components/field/form.jsx +211 -0
- package/src/components/{input → field}/input.jsx +1 -0
- package/src/components/{input → field}/input_checkbox.jsx +132 -155
- package/src/components/{input → field}/input_radio.jsx +135 -46
- package/src/components/field/input_textual.jsx +418 -0
- package/src/components/field/label.jsx +32 -0
- package/src/components/field/radio_list.jsx +182 -0
- package/src/components/{input → field}/select.jsx +17 -32
- package/src/components/field/use_action_events.js +132 -0
- package/src/components/field/use_form_events.js +55 -0
- package/src/components/field/use_ui_state_controller.js +506 -0
- package/src/components/item_tracker/README.md +461 -0
- package/src/components/item_tracker/use_isolated_item_tracker.jsx +209 -0
- package/src/components/item_tracker/use_isolated_item_tracker_demo.html +148 -0
- package/src/components/item_tracker/use_isolated_item_tracker_demo.jsx +460 -0
- package/src/components/item_tracker/use_item_tracker.jsx +143 -0
- package/src/components/item_tracker/use_item_tracker_demo.html +207 -0
- package/src/components/item_tracker/use_item_tracker_demo.jsx +216 -0
- package/src/components/keyboard_shortcuts/active_keyboard_shortcuts.jsx +87 -0
- package/src/components/keyboard_shortcuts/aria_key_shortcuts.js +61 -0
- package/src/components/keyboard_shortcuts/keyboard_key_meta.js +17 -0
- package/src/components/keyboard_shortcuts/keyboard_shortcuts.js +371 -0
- package/src/components/link/link.jsx +65 -102
- package/src/components/link/link_with_icon.jsx +52 -0
- package/src/components/loader/loader_background.jsx +85 -64
- package/src/components/loader/rectangle_loading.jsx +38 -19
- package/src/components/route.jsx +8 -4
- package/src/components/selection/selection.jsx +1583 -0
- package/src/components/svg/font_sized_svg.jsx +45 -0
- package/src/components/svg/icon_and_text.jsx +21 -0
- package/src/components/svg/svg_mask_overlay.jsx +105 -0
- package/src/components/table/drag/table_drag.jsx +506 -0
- package/src/components/table/resize/table_resize.jsx +650 -0
- package/src/components/table/resize/table_size.js +43 -0
- package/src/components/table/selection/table_selection.js +106 -0
- package/src/components/table/selection/table_selection.jsx +203 -0
- package/src/components/table/sticky/sticky_group.js +354 -0
- package/src/components/table/sticky/table_sticky.js +25 -0
- package/src/components/table/sticky/table_sticky.jsx +501 -0
- package/src/components/table/table.jsx +721 -0
- package/src/components/table/table_css.js +211 -0
- package/src/components/table/table_ui.jsx +49 -0
- package/src/components/table/use_cells_and_columns.js +90 -0
- package/src/components/table/use_object_array_to_cells.js +46 -0
- package/src/components/table/z_indexes.js +23 -0
- package/src/components/tablist/tablist.jsx +99 -0
- package/src/components/text/overflow.jsx +15 -0
- package/src/components/text/text_and_count.jsx +28 -0
- package/src/components/ui_transition.jsx +128 -0
- package/src/components/use_auto_focus.js +58 -7
- package/src/components/use_batch_during_render.js +33 -0
- package/src/components/use_debounce_true.js +7 -7
- package/src/components/use_dependencies_diff.js +35 -0
- package/src/components/use_focus_group.js +4 -3
- package/src/components/use_initial_value.js +8 -34
- package/src/components/use_signal_sync.js +1 -1
- package/src/components/use_stable_callback.js +68 -0
- package/src/components/use_state_array.js +16 -9
- package/src/docs/actions.md +22 -0
- package/src/notes.md +33 -12
- package/src/route/route.js +97 -47
- package/src/store/resource_graph.js +2 -1
- package/src/store/tests/{resource_graph_dependencies.test.js → resource_graph_dependencies.test_manual.js} +13 -13
- package/src/utils/is_signal.js +20 -0
- package/src/utils/stringify_for_display.js +4 -23
- package/src/validation/constraints/confirm_constraint.js +14 -0
- package/src/validation/constraints/create_unique_value_constraint.js +27 -0
- package/src/validation/constraints/native_constraints.js +313 -0
- package/src/validation/constraints/readonly_constraint.js +36 -0
- package/src/validation/constraints/single_space_constraint.js +13 -0
- package/src/validation/custom_constraint_validation.js +599 -0
- package/src/validation/custom_message.js +18 -0
- package/src/validation/demos/browser_style.png +0 -0
- package/src/validation/demos/form_validation_demo.html +142 -0
- package/src/validation/demos/form_validation_demo_preact.html +87 -0
- package/src/validation/demos/form_validation_native_popover_demo.html +168 -0
- package/src/validation/demos/form_validation_vs_native_demo.html +172 -0
- package/src/validation/demos/validation_message_demo.html +203 -0
- package/src/validation/hooks/use_constraints.js +23 -0
- package/src/validation/hooks/use_custom_validation_ref.js +73 -0
- package/src/validation/hooks/use_validation_message.js +19 -0
- package/src/validation/validation_message.js +741 -0
- package/src/components/editable_text/editable_text.jsx +0 -96
- package/src/components/form.jsx +0 -144
- package/src/components/input/checkbox_list.jsx +0 -294
- package/src/components/input/field.jsx +0 -61
- package/src/components/input/input_textual.jsx +0 -338
- package/src/components/input/radio_list.jsx +0 -283
- package/src/components/input/use_form_event.js +0 -20
- package/src/components/input/use_on_change.js +0 -12
- package/src/components/selection/selection.js +0 -5
- package/src/components/selection/selection_context.jsx +0 -262
- package/src/components/shortcut/shortcut_context.jsx +0 -390
- package/src/components/use_action_events.js +0 -37
- package/src/utils/iterable_weak_set.js +0 -62
- /package/src/components/demos/action/{11_nested_shortcuts_demo.html → 11_nested_shortcuts_demo.xhtml} +0 -0
- /package/src/components/{shortcut → keyboard_shortcuts}/os.js +0 -0
- /package/src/route/{route.test.html → route.xtest.html} +0 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>Column Reordering Debug Demo</title>
|
|
5
|
+
<meta charset="utf-8" />
|
|
6
|
+
<link rel="icon" href="data:," />
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
font-family: Arial, sans-serif;
|
|
10
|
+
margin: 20px;
|
|
11
|
+
background: #f5f5f5;
|
|
12
|
+
}
|
|
13
|
+
.debug-section {
|
|
14
|
+
background: white;
|
|
15
|
+
padding: 15px;
|
|
16
|
+
margin: 10px 0;
|
|
17
|
+
border-radius: 4px;
|
|
18
|
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
|
19
|
+
}
|
|
20
|
+
.controls {
|
|
21
|
+
margin: 10px 0;
|
|
22
|
+
display: flex;
|
|
23
|
+
gap: 10px;
|
|
24
|
+
align-items: center;
|
|
25
|
+
}
|
|
26
|
+
button {
|
|
27
|
+
padding: 8px 16px;
|
|
28
|
+
border: none;
|
|
29
|
+
border-radius: 4px;
|
|
30
|
+
cursor: pointer;
|
|
31
|
+
font-size: 14px;
|
|
32
|
+
}
|
|
33
|
+
.btn-primary {
|
|
34
|
+
background: #007bff;
|
|
35
|
+
color: white;
|
|
36
|
+
}
|
|
37
|
+
.btn-success {
|
|
38
|
+
background: #28a745;
|
|
39
|
+
color: white;
|
|
40
|
+
}
|
|
41
|
+
.btn-warning {
|
|
42
|
+
background: #ffc107;
|
|
43
|
+
color: black;
|
|
44
|
+
}
|
|
45
|
+
.log {
|
|
46
|
+
background: #2d3748;
|
|
47
|
+
color: #68d391;
|
|
48
|
+
padding: 12px;
|
|
49
|
+
border-radius: 4px;
|
|
50
|
+
font-family: "Courier New", monospace;
|
|
51
|
+
font-size: 12px;
|
|
52
|
+
max-height: 300px;
|
|
53
|
+
overflow-y: auto;
|
|
54
|
+
white-space: pre-wrap;
|
|
55
|
+
margin: 10px 0;
|
|
56
|
+
}
|
|
57
|
+
.state-display {
|
|
58
|
+
background: #f7fafc;
|
|
59
|
+
border: 1px solid #e2e8f0;
|
|
60
|
+
border-radius: 4px;
|
|
61
|
+
padding: 12px;
|
|
62
|
+
margin: 10px 0;
|
|
63
|
+
}
|
|
64
|
+
pre {
|
|
65
|
+
margin: 0;
|
|
66
|
+
font-size: 12px;
|
|
67
|
+
}
|
|
68
|
+
</style>
|
|
69
|
+
</head>
|
|
70
|
+
|
|
71
|
+
<body>
|
|
72
|
+
<h1>Column Reordering Debug Demo</h1>
|
|
73
|
+
<p>
|
|
74
|
+
Simple demo with 3 columns and 1 row to debug column reordering issues.
|
|
75
|
+
</p>
|
|
76
|
+
|
|
77
|
+
<div class="debug-section">
|
|
78
|
+
<h2>Debug Log</h2>
|
|
79
|
+
<div id="log" class="log"></div>
|
|
80
|
+
<button onclick="clearLog()" class="btn-warning">Clear Log</button>
|
|
81
|
+
</div>
|
|
82
|
+
|
|
83
|
+
<div class="debug-section">
|
|
84
|
+
<h2>Demo</h2>
|
|
85
|
+
<div id="root"></div>
|
|
86
|
+
</div>
|
|
87
|
+
|
|
88
|
+
<script type="module" jsenv-type="module/jsx">
|
|
89
|
+
import { render } from "preact";
|
|
90
|
+
import { useState } from "preact/hooks";
|
|
91
|
+
/* eslint-disable no-unused-vars */
|
|
92
|
+
import {
|
|
93
|
+
Table,
|
|
94
|
+
Colgroup,
|
|
95
|
+
Col,
|
|
96
|
+
RowNumberCol,
|
|
97
|
+
Thead,
|
|
98
|
+
Tbody,
|
|
99
|
+
Tr,
|
|
100
|
+
TableCell,
|
|
101
|
+
RowNumberTableCell,
|
|
102
|
+
} from "../table/table.jsx";
|
|
103
|
+
/* eslint-enable no-unused-vars */
|
|
104
|
+
import { useCellsAndColumns } from "../table/use_cells_and_columns.js";
|
|
105
|
+
|
|
106
|
+
window.clearLog = () => {
|
|
107
|
+
document.getElementById("log").textContent = "";
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const log = (message) => {
|
|
111
|
+
const timestamp = new Date().toLocaleTimeString();
|
|
112
|
+
const logElement = document.getElementById("log");
|
|
113
|
+
logElement.textContent += `[${timestamp}] ${message}\n`;
|
|
114
|
+
logElement.scrollTop = logElement.scrollHeight;
|
|
115
|
+
console.log(`[DEBUG] ${message}`);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// eslint-disable-next-line no-unused-vars
|
|
119
|
+
const ColumnReorderingDemo = () => {
|
|
120
|
+
// Initial column configuration
|
|
121
|
+
const [columnConfig] = useState([
|
|
122
|
+
{ id: "col1", name: "Column A", backgroundColor: "#ffebee" },
|
|
123
|
+
{ id: "col2", name: "Column B", backgroundColor: "#e8f5e8" },
|
|
124
|
+
{ id: "col3", name: "Column C", backgroundColor: "#e3f2fd" },
|
|
125
|
+
]);
|
|
126
|
+
|
|
127
|
+
// Simple single row of data
|
|
128
|
+
const initialCellData = [["A1", "B1", "C1"]];
|
|
129
|
+
const { cells, setCellValue, columns, setColumnOrder } =
|
|
130
|
+
useCellsAndColumns(initialCellData, columnConfig);
|
|
131
|
+
|
|
132
|
+
// Get current column order for logging and display
|
|
133
|
+
const columnOrderedIds = columns.map((col) => col.id);
|
|
134
|
+
|
|
135
|
+
log(`🎬 Demo render - columnOrder: [${columnOrderedIds.join(", ")}]`);
|
|
136
|
+
|
|
137
|
+
const handleColumnOrderChange = (newColumnOrder) => {
|
|
138
|
+
log(
|
|
139
|
+
`🔄 Column order changing from [${columnOrderedIds.join(", ")}] to [${newColumnOrder.join(", ")}]`,
|
|
140
|
+
);
|
|
141
|
+
setColumnOrder(newColumnOrder);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const handleCellEdit = ({ rowIndex, columnIndex }, value) => {
|
|
145
|
+
log(
|
|
146
|
+
`✏️ Cell edit: row=${rowIndex}, col=${columnIndex}, value="${value}"`,
|
|
147
|
+
);
|
|
148
|
+
setCellValue({ rowIndex, columnIndex }, value);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// Test buttons for manual reordering
|
|
152
|
+
const moveFirstToLast = () => {
|
|
153
|
+
const newOrder = [
|
|
154
|
+
columnOrderedIds[1],
|
|
155
|
+
columnOrderedIds[2],
|
|
156
|
+
columnOrderedIds[0],
|
|
157
|
+
];
|
|
158
|
+
handleColumnOrderChange(newOrder);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const moveLastToFirst = () => {
|
|
162
|
+
const newOrder = [
|
|
163
|
+
columnOrderedIds[2],
|
|
164
|
+
columnOrderedIds[0],
|
|
165
|
+
columnOrderedIds[1],
|
|
166
|
+
];
|
|
167
|
+
handleColumnOrderChange(newOrder);
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const resetOrder = () => {
|
|
171
|
+
handleColumnOrderChange(["col1", "col2", "col3"]);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
return (
|
|
175
|
+
<div>
|
|
176
|
+
<div className="controls">
|
|
177
|
+
<button onClick={moveFirstToLast} className="btn-primary">
|
|
178
|
+
Move First → Last
|
|
179
|
+
</button>
|
|
180
|
+
<button onClick={moveLastToFirst} className="btn-primary">
|
|
181
|
+
Move Last → First
|
|
182
|
+
</button>
|
|
183
|
+
<button onClick={resetOrder} className="btn-success">
|
|
184
|
+
Reset Order
|
|
185
|
+
</button>
|
|
186
|
+
</div>
|
|
187
|
+
|
|
188
|
+
<div className="state-display">
|
|
189
|
+
<h3>Current State</h3>
|
|
190
|
+
<div>
|
|
191
|
+
<strong>Column Order:</strong> [{columnOrderedIds.join(", ")}]
|
|
192
|
+
</div>
|
|
193
|
+
<div>
|
|
194
|
+
<strong>Cell Values:</strong>
|
|
195
|
+
</div>
|
|
196
|
+
<pre>{JSON.stringify(cells, null, 2)}</pre>
|
|
197
|
+
</div>
|
|
198
|
+
|
|
199
|
+
<Table
|
|
200
|
+
onColumnOrderChange={handleColumnOrderChange}
|
|
201
|
+
maxWidth={600}
|
|
202
|
+
maxHeight={400}
|
|
203
|
+
>
|
|
204
|
+
<Colgroup>
|
|
205
|
+
<RowNumberCol width={50} />
|
|
206
|
+
{columns.map((col) => {
|
|
207
|
+
log(`🏗️ Rendering Col: id=${col.id}, width=${col?.width}`);
|
|
208
|
+
return (
|
|
209
|
+
<Col
|
|
210
|
+
key={col.id}
|
|
211
|
+
id={col.id}
|
|
212
|
+
width={col?.width}
|
|
213
|
+
backgroundColor={col.backgroundColor}
|
|
214
|
+
/>
|
|
215
|
+
);
|
|
216
|
+
})}
|
|
217
|
+
</Colgroup>
|
|
218
|
+
|
|
219
|
+
<Thead>
|
|
220
|
+
<Tr>
|
|
221
|
+
<RowNumberTableCell />
|
|
222
|
+
{columns.map((col) => {
|
|
223
|
+
log(`🏗️ Rendering Header: id=${col.id}, name=${col?.name}`);
|
|
224
|
+
const rowId = "header";
|
|
225
|
+
const columnId = col.id;
|
|
226
|
+
const tableCellKey = `${columnId}-${rowId}`;
|
|
227
|
+
return (
|
|
228
|
+
<TableCell key={tableCellKey}>
|
|
229
|
+
{col?.name} (id: {col.id})
|
|
230
|
+
</TableCell>
|
|
231
|
+
);
|
|
232
|
+
})}
|
|
233
|
+
</Tr>
|
|
234
|
+
</Thead>
|
|
235
|
+
|
|
236
|
+
<Tbody>
|
|
237
|
+
{cells.map((rowValues, rowIndex) => (
|
|
238
|
+
<Tr key={rowIndex}>
|
|
239
|
+
<RowNumberTableCell />
|
|
240
|
+
{rowValues.map((cellValue, columnIndex) => {
|
|
241
|
+
log(
|
|
242
|
+
`🏗️ Rendering Cell: rowIndex=${rowIndex}, columnIndex=${columnIndex}, value="${cellValue}"`,
|
|
243
|
+
);
|
|
244
|
+
const rowId = rowIndex;
|
|
245
|
+
const columnId = columns[columnIndex].id;
|
|
246
|
+
// const tableCellKey = columnId;
|
|
247
|
+
const tableCellKey = `${columnId}-${rowId}`;
|
|
248
|
+
return (
|
|
249
|
+
<TableCell
|
|
250
|
+
key={tableCellKey}
|
|
251
|
+
action={(value) =>
|
|
252
|
+
handleCellEdit({ rowIndex, columnIndex }, value)
|
|
253
|
+
}
|
|
254
|
+
>
|
|
255
|
+
{cellValue}
|
|
256
|
+
</TableCell>
|
|
257
|
+
);
|
|
258
|
+
})}
|
|
259
|
+
</Tr>
|
|
260
|
+
))}
|
|
261
|
+
</Tbody>
|
|
262
|
+
</Table>
|
|
263
|
+
|
|
264
|
+
<div className="state-display">
|
|
265
|
+
<h3>Column Configuration</h3>
|
|
266
|
+
<pre>{JSON.stringify(columnConfig, null, 2)}</pre>
|
|
267
|
+
</div>
|
|
268
|
+
</div>
|
|
269
|
+
);
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
// Initial render
|
|
273
|
+
log("🚀 Starting Column Reordering Demo");
|
|
274
|
+
render(<ColumnReorderingDemo />, document.getElementById("root"));
|
|
275
|
+
</script>
|
|
276
|
+
</body>
|
|
277
|
+
</html>
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>Table Selection Debug Demo</title>
|
|
5
|
+
<meta charset="utf-8" />
|
|
6
|
+
<link rel="icon" href="data:," />
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
font-family: Arial, sans-serif;
|
|
10
|
+
margin: 20px;
|
|
11
|
+
background: #f5f5f5;
|
|
12
|
+
}
|
|
13
|
+
.debug-section {
|
|
14
|
+
background: white;
|
|
15
|
+
padding: 15px;
|
|
16
|
+
margin: 10px 0;
|
|
17
|
+
border-radius: 4px;
|
|
18
|
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
|
19
|
+
}
|
|
20
|
+
.controls {
|
|
21
|
+
margin: 10px 0;
|
|
22
|
+
display: flex;
|
|
23
|
+
gap: 10px;
|
|
24
|
+
align-items: center;
|
|
25
|
+
flex-wrap: wrap;
|
|
26
|
+
}
|
|
27
|
+
button {
|
|
28
|
+
padding: 8px 16px;
|
|
29
|
+
border: none;
|
|
30
|
+
border-radius: 4px;
|
|
31
|
+
cursor: pointer;
|
|
32
|
+
font-size: 14px;
|
|
33
|
+
}
|
|
34
|
+
.btn-primary {
|
|
35
|
+
background: #007bff;
|
|
36
|
+
color: white;
|
|
37
|
+
}
|
|
38
|
+
.btn-success {
|
|
39
|
+
background: #28a745;
|
|
40
|
+
color: white;
|
|
41
|
+
}
|
|
42
|
+
.btn-warning {
|
|
43
|
+
background: #ffc107;
|
|
44
|
+
color: black;
|
|
45
|
+
}
|
|
46
|
+
.btn-danger {
|
|
47
|
+
background: #dc3545;
|
|
48
|
+
color: white;
|
|
49
|
+
}
|
|
50
|
+
.log {
|
|
51
|
+
background: #2d3748;
|
|
52
|
+
color: #68d391;
|
|
53
|
+
padding: 12px;
|
|
54
|
+
border-radius: 4px;
|
|
55
|
+
font-family: "Courier New", monospace;
|
|
56
|
+
font-size: 12px;
|
|
57
|
+
max-height: 300px;
|
|
58
|
+
overflow-y: auto;
|
|
59
|
+
white-space: pre-wrap;
|
|
60
|
+
margin: 10px 0;
|
|
61
|
+
}
|
|
62
|
+
.state-display {
|
|
63
|
+
background: #f7fafc;
|
|
64
|
+
border: 1px solid #e2e8f0;
|
|
65
|
+
border-radius: 4px;
|
|
66
|
+
padding: 12px;
|
|
67
|
+
margin: 10px 0;
|
|
68
|
+
}
|
|
69
|
+
pre {
|
|
70
|
+
margin: 0;
|
|
71
|
+
font-size: 12px;
|
|
72
|
+
}
|
|
73
|
+
.selection-info {
|
|
74
|
+
background: #fff3cd;
|
|
75
|
+
border: 1px solid #ffeeba;
|
|
76
|
+
border-radius: 4px;
|
|
77
|
+
padding: 10px;
|
|
78
|
+
margin: 10px 0;
|
|
79
|
+
}
|
|
80
|
+
.coordinate-buttons {
|
|
81
|
+
display: grid;
|
|
82
|
+
grid-template-columns: repeat(3, 1fr);
|
|
83
|
+
gap: 5px;
|
|
84
|
+
max-width: 250px;
|
|
85
|
+
}
|
|
86
|
+
.coord-label {
|
|
87
|
+
font-weight: bold;
|
|
88
|
+
text-align: center;
|
|
89
|
+
background: #e9ecef;
|
|
90
|
+
padding: 5px;
|
|
91
|
+
border-radius: 3px;
|
|
92
|
+
}
|
|
93
|
+
</style>
|
|
94
|
+
</head>
|
|
95
|
+
|
|
96
|
+
<body>
|
|
97
|
+
<h1>Table Selection Debug Demo</h1>
|
|
98
|
+
<p>Simple 2x2 table to debug selection behavior and external control.</p>
|
|
99
|
+
|
|
100
|
+
<div class="debug-section">
|
|
101
|
+
<h2>External Selection Controls</h2>
|
|
102
|
+
<div class="controls">
|
|
103
|
+
<button id="select-none" class="btn-danger">Clear Selection</button>
|
|
104
|
+
<button id="select-all" class="btn-primary">Select All</button>
|
|
105
|
+
<button id="select-row-0" class="btn-primary">Select Row 0</button>
|
|
106
|
+
<button id="select-row-1" class="btn-primary">Select Row 1</button>
|
|
107
|
+
<button id="select-col-0" class="btn-primary">Select Column 0</button>
|
|
108
|
+
<button id="select-col-1" class="btn-primary">Select Column 1</button>
|
|
109
|
+
</div>
|
|
110
|
+
|
|
111
|
+
<h3>Select Individual Cells</h3>
|
|
112
|
+
<div class="coordinate-buttons">
|
|
113
|
+
<button id="select-header-rownumber" class="btn-success">Row#</button>
|
|
114
|
+
<button id="select-header-0" class="btn-success">H(0)</button>
|
|
115
|
+
<button id="select-header-1" class="btn-success">H(1)</button>
|
|
116
|
+
<button id="select-rownumber-0" class="btn-success">R#1</button>
|
|
117
|
+
<button id="select-0-0" class="btn-success">(1,1)</button>
|
|
118
|
+
<button id="select-0-1" class="btn-success">(1,2)</button>
|
|
119
|
+
<button id="select-rownumber-1" class="btn-success">R#2</button>
|
|
120
|
+
<button id="select-1-0" class="btn-success">(2,1)</button>
|
|
121
|
+
<button id="select-1-1" class="btn-success">(2,2)</button>
|
|
122
|
+
</div>
|
|
123
|
+
</div>
|
|
124
|
+
|
|
125
|
+
<div class="debug-section">
|
|
126
|
+
<h2>Demo Table (2x2)</h2>
|
|
127
|
+
<div id="root"></div>
|
|
128
|
+
</div>
|
|
129
|
+
|
|
130
|
+
<div class="debug-section">
|
|
131
|
+
<h2>Selection State</h2>
|
|
132
|
+
<div id="selection-state" class="selection-info">
|
|
133
|
+
No selection data yet...
|
|
134
|
+
</div>
|
|
135
|
+
</div>
|
|
136
|
+
|
|
137
|
+
<div class="debug-section">
|
|
138
|
+
<h2>Debug Log</h2>
|
|
139
|
+
<div id="log" class="log"></div>
|
|
140
|
+
<button onclick="clearLog()" class="btn-warning">Clear Log</button>
|
|
141
|
+
</div>
|
|
142
|
+
|
|
143
|
+
<script type="module" jsenv-type="module/jsx">
|
|
144
|
+
import { render } from "preact";
|
|
145
|
+
import { useState, useEffect } from "preact/hooks";
|
|
146
|
+
/* eslint-disable no-unused-vars */
|
|
147
|
+
import {
|
|
148
|
+
Table,
|
|
149
|
+
Colgroup,
|
|
150
|
+
Col,
|
|
151
|
+
RowNumberCol,
|
|
152
|
+
Thead,
|
|
153
|
+
Tbody,
|
|
154
|
+
Tr,
|
|
155
|
+
TableCell,
|
|
156
|
+
RowNumberTableCell,
|
|
157
|
+
} from "../table/table.jsx";
|
|
158
|
+
/* eslint-enable no-unused-vars */
|
|
159
|
+
import { useCellsAndColumns } from "../table/use_cells_and_columns.js";
|
|
160
|
+
import {
|
|
161
|
+
stringifyTableSelectionValue,
|
|
162
|
+
isCellSelected,
|
|
163
|
+
} from "../table/selection/table_selection.js";
|
|
164
|
+
|
|
165
|
+
window.clearLog = () => {
|
|
166
|
+
document.getElementById("log").textContent = "";
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const log = (message) => {
|
|
170
|
+
const timestamp = new Date().toLocaleTimeString();
|
|
171
|
+
const logElement = document.getElementById("log");
|
|
172
|
+
logElement.textContent += `[${timestamp}] ${message}\n`;
|
|
173
|
+
logElement.scrollTop = logElement.scrollHeight;
|
|
174
|
+
console.log(`[DEBUG] ${message}`);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const updateSelectionDisplay = (selection) => {
|
|
178
|
+
const selectionElement = document.getElementById("selection-state");
|
|
179
|
+
if (!selection || selection.size === 0) {
|
|
180
|
+
selectionElement.innerHTML = "<strong>No selection</strong>";
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const selectionArray = Array.from(selection);
|
|
185
|
+
const cellSelections = [];
|
|
186
|
+
const rowSelections = [];
|
|
187
|
+
const columnSelections = [];
|
|
188
|
+
|
|
189
|
+
selectionArray.forEach((item) => {
|
|
190
|
+
if (item.startsWith("row:")) {
|
|
191
|
+
rowSelections.push(item.slice(4));
|
|
192
|
+
} else if (item.startsWith("column:")) {
|
|
193
|
+
columnSelections.push(item.slice(7));
|
|
194
|
+
} else {
|
|
195
|
+
cellSelections.push(`(${item})`);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
let displayParts = [];
|
|
200
|
+
if (cellSelections.length > 0)
|
|
201
|
+
displayParts.push(`Cells: ${cellSelections.join(", ")}`);
|
|
202
|
+
if (rowSelections.length > 0)
|
|
203
|
+
displayParts.push(`Rows: ${rowSelections.join(", ")}`);
|
|
204
|
+
if (columnSelections.length > 0)
|
|
205
|
+
displayParts.push(`Columns: ${columnSelections.join(", ")}`);
|
|
206
|
+
|
|
207
|
+
selectionElement.innerHTML = `
|
|
208
|
+
<strong>Selection:</strong> ${displayParts.join(" | ")}<br>
|
|
209
|
+
<strong>Total count:</strong> ${selection.size}<br>
|
|
210
|
+
<strong>Raw values:</strong> ${selectionArray.join(", ")}
|
|
211
|
+
`;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// eslint-disable-next-line no-unused-vars
|
|
215
|
+
const TableSelectionDemo = () => {
|
|
216
|
+
// Simple 2x2 table configuration
|
|
217
|
+
const [columnConfig] = useState([
|
|
218
|
+
{ id: "col1", name: "Column A" },
|
|
219
|
+
{ id: "col2", name: "Column B" },
|
|
220
|
+
]);
|
|
221
|
+
|
|
222
|
+
// 2x2 cell data
|
|
223
|
+
const initialCellData = [
|
|
224
|
+
["A1", "B1"],
|
|
225
|
+
["A2", "B2"],
|
|
226
|
+
];
|
|
227
|
+
|
|
228
|
+
const { cells, setCellValue, columns } = useCellsAndColumns(
|
|
229
|
+
initialCellData,
|
|
230
|
+
columnConfig,
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
// Selection state (controlled from outside)
|
|
234
|
+
const [selectedCells, setSelectedCells] = useState([]);
|
|
235
|
+
|
|
236
|
+
// Log selection changes
|
|
237
|
+
useEffect(() => {
|
|
238
|
+
log(
|
|
239
|
+
`🎯 Selection changed: ${Array.from(selectedCells).join(", ") || "none"}`,
|
|
240
|
+
);
|
|
241
|
+
updateSelectionDisplay(selectedCells);
|
|
242
|
+
}, [selectedCells]);
|
|
243
|
+
|
|
244
|
+
const handleCellEdit = ({ rowIndex, columnIndex }, value) => {
|
|
245
|
+
log(
|
|
246
|
+
`✏️ Cell edit: row=${rowIndex}, col=${columnIndex}, value="${value}"`,
|
|
247
|
+
);
|
|
248
|
+
setCellValue({ rowIndex, columnIndex }, value);
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
const handleSelectionChange = (newSelection) => {
|
|
252
|
+
log(`🔄 Selection changing from internal table interaction`);
|
|
253
|
+
setSelectedCells(newSelection);
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
// External control functions
|
|
257
|
+
const selectNone = () => {
|
|
258
|
+
log(`🚫 External: Clear selection`);
|
|
259
|
+
setSelectedCells([]);
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
const selectAll = () => {
|
|
263
|
+
log(`📱 External: Select all cells`);
|
|
264
|
+
const allCells = [
|
|
265
|
+
stringifyTableSelectionValue("cell", {
|
|
266
|
+
rowIndex: 0,
|
|
267
|
+
columnIndex: 0,
|
|
268
|
+
}),
|
|
269
|
+
stringifyTableSelectionValue("cell", {
|
|
270
|
+
rowIndex: 0,
|
|
271
|
+
columnIndex: 1,
|
|
272
|
+
}),
|
|
273
|
+
stringifyTableSelectionValue("cell", {
|
|
274
|
+
rowIndex: 1,
|
|
275
|
+
columnIndex: 0,
|
|
276
|
+
}),
|
|
277
|
+
stringifyTableSelectionValue("cell", {
|
|
278
|
+
rowIndex: 1,
|
|
279
|
+
columnIndex: 1,
|
|
280
|
+
}),
|
|
281
|
+
];
|
|
282
|
+
setSelectedCells(allCells);
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
const selectRow = (rowIndex) => {
|
|
286
|
+
log(`📏 External: Select row ${rowIndex}`);
|
|
287
|
+
const rowValue = stringifyTableSelectionValue("row", rowIndex);
|
|
288
|
+
setSelectedCells([rowValue]);
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
const selectColumn = (columnIndex) => {
|
|
292
|
+
log(`📐 External: Select column ${columnIndex}`);
|
|
293
|
+
const columnValue = stringifyTableSelectionValue(
|
|
294
|
+
"column",
|
|
295
|
+
columnIndex,
|
|
296
|
+
);
|
|
297
|
+
setSelectedCells([columnValue]);
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
const selectCell = (rowIndex, columnIndex) => {
|
|
301
|
+
log(`🎯 External: Select single cell (${rowIndex},${columnIndex})`);
|
|
302
|
+
const cellValue = stringifyTableSelectionValue("cell", {
|
|
303
|
+
rowIndex,
|
|
304
|
+
columnIndex,
|
|
305
|
+
});
|
|
306
|
+
setSelectedCells([cellValue]);
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
const selectHeaderCell = (columnIndex) => {
|
|
310
|
+
log(`📋 External: Select header cell for column ${columnIndex}`);
|
|
311
|
+
// Headers are at row index -1 in the visual table
|
|
312
|
+
const headerValue = stringifyTableSelectionValue("cell", {
|
|
313
|
+
rowIndex: 0,
|
|
314
|
+
columnIndex,
|
|
315
|
+
});
|
|
316
|
+
setSelectedCells([headerValue]);
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
const selectRowNumberCell = (rowIndex) => {
|
|
320
|
+
log(`🔢 External: Select row number cell for row ${rowIndex}`);
|
|
321
|
+
// Row numbers are at column index -1 in the visual table
|
|
322
|
+
const rowNumberValue = stringifyTableSelectionValue("cell", {
|
|
323
|
+
rowIndex,
|
|
324
|
+
columnIndex: 0,
|
|
325
|
+
});
|
|
326
|
+
setSelectedCells([rowNumberValue]);
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
const selectHeaderRowNumberCell = () => {
|
|
330
|
+
log(`🏠 External: Select header row number cell`);
|
|
331
|
+
// Corner cell is at (-1, -1) in the visual table
|
|
332
|
+
const cornerValue = stringifyTableSelectionValue("cell", {
|
|
333
|
+
rowIndex: 0,
|
|
334
|
+
columnIndex: 0,
|
|
335
|
+
});
|
|
336
|
+
setSelectedCells([cornerValue]);
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
// Setup external control button handlers
|
|
340
|
+
useEffect(() => {
|
|
341
|
+
const setupButton = (id, handler) => {
|
|
342
|
+
const button = document.getElementById(id);
|
|
343
|
+
if (button) {
|
|
344
|
+
button.onclick = handler;
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
setupButton("select-none", selectNone);
|
|
349
|
+
setupButton("select-all", selectAll);
|
|
350
|
+
setupButton("select-row-0", () => selectRow(0));
|
|
351
|
+
setupButton("select-row-1", () => selectRow(1));
|
|
352
|
+
setupButton("select-col-0", () => selectColumn(0));
|
|
353
|
+
setupButton("select-col-1", () => selectColumn(1));
|
|
354
|
+
setupButton("select-0-0", () => selectCell(1, 1));
|
|
355
|
+
setupButton("select-0-1", () => selectCell(1, 2));
|
|
356
|
+
setupButton("select-1-0", () => selectCell(2, 1));
|
|
357
|
+
setupButton("select-1-1", () => selectCell(2, 2));
|
|
358
|
+
// Header cells: visual column 0 and 1 at header row -1
|
|
359
|
+
setupButton("select-header-rownumber", selectHeaderRowNumberCell);
|
|
360
|
+
setupButton("select-header-0", () => selectHeaderCell(1));
|
|
361
|
+
setupButton("select-header-1", () => selectHeaderCell(2));
|
|
362
|
+
// Row number cells: visual row 0 and 1 at row number column -1
|
|
363
|
+
setupButton("select-rownumber-0", () => selectRowNumberCell(1));
|
|
364
|
+
setupButton("select-rownumber-1", () => selectRowNumberCell(2));
|
|
365
|
+
}, []);
|
|
366
|
+
|
|
367
|
+
log(`🎬 Demo render - cells: ${cells.length}x${cells[0]?.length}`);
|
|
368
|
+
|
|
369
|
+
return (
|
|
370
|
+
<div>
|
|
371
|
+
<Table
|
|
372
|
+
selection={selectedCells}
|
|
373
|
+
onSelectionChange={handleSelectionChange}
|
|
374
|
+
maxWidth={400}
|
|
375
|
+
maxHeight={300}
|
|
376
|
+
>
|
|
377
|
+
<Colgroup>
|
|
378
|
+
<RowNumberCol width={60} />
|
|
379
|
+
{columns.map((col) => {
|
|
380
|
+
log(`🏗️ Rendering Col: id=${col.id}`);
|
|
381
|
+
return <Col key={col.id} id={col.id} width={120} />;
|
|
382
|
+
})}
|
|
383
|
+
</Colgroup>
|
|
384
|
+
|
|
385
|
+
<Thead>
|
|
386
|
+
<Tr>
|
|
387
|
+
<RowNumberTableCell />
|
|
388
|
+
{columns.map((col) => {
|
|
389
|
+
log(`🏗️ Rendering Header: id=${col.id}, name=${col?.name}`);
|
|
390
|
+
return <TableCell key={col.id}>{col?.name}</TableCell>;
|
|
391
|
+
})}
|
|
392
|
+
</Tr>
|
|
393
|
+
</Thead>
|
|
394
|
+
|
|
395
|
+
<Tbody>
|
|
396
|
+
{cells.map((rowValues, rowIndex) => (
|
|
397
|
+
<Tr key={rowIndex}>
|
|
398
|
+
<RowNumberTableCell />
|
|
399
|
+
{rowValues.map((cellValue, columnIndex) => {
|
|
400
|
+
const isSelected = isCellSelected(selectedCells, {
|
|
401
|
+
rowIndex,
|
|
402
|
+
columnIndex,
|
|
403
|
+
});
|
|
404
|
+
log(
|
|
405
|
+
`🏗️ Rendering Cell: (${rowIndex},${columnIndex}) value="${cellValue}" selected=${isSelected}`,
|
|
406
|
+
);
|
|
407
|
+
return (
|
|
408
|
+
<TableCell
|
|
409
|
+
key={columnIndex}
|
|
410
|
+
action={(value) =>
|
|
411
|
+
handleCellEdit({ rowIndex, columnIndex }, value)
|
|
412
|
+
}
|
|
413
|
+
backgroundColor="yellow"
|
|
414
|
+
>
|
|
415
|
+
{cellValue}
|
|
416
|
+
</TableCell>
|
|
417
|
+
);
|
|
418
|
+
})}
|
|
419
|
+
</Tr>
|
|
420
|
+
))}
|
|
421
|
+
</Tbody>
|
|
422
|
+
</Table>
|
|
423
|
+
</div>
|
|
424
|
+
);
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
// Initial render
|
|
428
|
+
log("🚀 Starting Table Selection Demo");
|
|
429
|
+
render(<TableSelectionDemo />, document.getElementById("root"));
|
|
430
|
+
</script>
|
|
431
|
+
</body>
|
|
432
|
+
</html>
|