@jsenv/navi 0.10.1 → 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.
- package/dist/jsenv_navi.js +13858 -23295
- package/dist/jsenv_navi.js.map +1281 -0
- package/package.json +5 -7
- package/index.js +0 -122
- package/src/action_private_properties.js +0 -11
- package/src/action_proxy_test.html +0 -353
- package/src/action_run_states.js +0 -5
- package/src/actions.js +0 -1401
- package/src/browser_integration/browser_integration.js +0 -216
- package/src/browser_integration/document_back_and_forward.js +0 -17
- package/src/browser_integration/document_loading_signal.js +0 -100
- package/src/browser_integration/document_state_signal.js +0 -9
- package/src/browser_integration/document_url_signal.js +0 -9
- package/src/browser_integration/use_is_visited.js +0 -19
- package/src/browser_integration/via_history.js +0 -232
- package/src/browser_integration/via_navigation.js +0 -168
- package/src/components/action_execution/form_context.js +0 -5
- package/src/components/action_execution/render_actionable_component.jsx +0 -29
- package/src/components/action_execution/use_action.js +0 -99
- package/src/components/action_execution/use_execute_action.js +0 -177
- package/src/components/action_execution/use_run_on_mount.js +0 -9
- package/src/components/action_renderer.jsx +0 -125
- package/src/components/callout/callout.js +0 -990
- package/src/components/callout/callout_demo.html +0 -201
- package/src/components/callout/test_dynamic_positioning.html +0 -161
- package/src/components/callout/test_html_document_iframe.html +0 -182
- package/src/components/demos/0_button_demo.html +0 -707
- package/src/components/demos/10_column_reordering_debug.html +0 -277
- package/src/components/demos/11_table_selection_debug.html +0 -432
- package/src/components/demos/1_checkbox_demo.html +0 -754
- package/src/components/demos/2_input_textual_demo.html +0 -286
- package/src/components/demos/3_radio_demo.html +0 -874
- package/src/components/demos/4_select_demo.html +0 -100
- package/src/components/demos/5_list_scrollable_demo.html +0 -153
- package/src/components/demos/6_tablist_demo.html +0 -77
- package/src/components/demos/7_table_selection_demo.html +0 -176
- package/src/components/demos/8_table_fixed_headers_demo.html +0 -584
- package/src/components/demos/9_table_column_drag_demo.html +0 -325
- package/src/components/demos/action/0_button_demo.html +0 -204
- package/src/components/demos/action/10_shortcuts_demo.html +0 -189
- package/src/components/demos/action/11_nested_shortcuts_demo.xhtml +0 -401
- package/src/components/demos/action/1_input_text_demo.html +0 -876
- package/src/components/demos/action/2_form_multiple.html +0 -303
- package/src/components/demos/action/3_details_demo.html +0 -203
- package/src/components/demos/action/4_input_checkbox_demo.html +0 -731
- package/src/components/demos/action/5_input_checkbox_state_demo.html +0 -270
- package/src/components/demos/action/6_checkbox_list_demo.html +0 -341
- package/src/components/demos/action/7_radio_list_demo.html +0 -357
- package/src/components/demos/action/8_editable_demo.html +0 -431
- package/src/components/demos/action/9_link_demo.html +0 -194
- package/src/components/demos/demo.md +0 -0
- package/src/components/demos/route/basic/basic.html +0 -14
- package/src/components/demos/route/basic/basic_route_demo.jsx +0 -224
- package/src/components/demos/route/multi/multi.html +0 -14
- package/src/components/demos/route/multi/multi_route_demo.jsx +0 -277
- package/src/components/demos/ui_transition/0_action_renderer_ui_transition_demo.html +0 -695
- package/src/components/demos/ui_transition/1_nested_ui_transition_demo.html +0 -429
- package/src/components/demos/ui_transition/2_height_transition_test.html +0 -295
- package/src/components/details/details.jsx +0 -245
- package/src/components/details/summary_marker.jsx +0 -141
- package/src/components/edition/editable.jsx +0 -186
- package/src/components/error_boundary_context.js +0 -9
- package/src/components/field/README.md +0 -247
- package/src/components/field/button.jsx +0 -429
- package/src/components/field/checkbox_list.jsx +0 -185
- package/src/components/field/collect_form_element_values.js +0 -82
- package/src/components/field/custom_field.js +0 -106
- package/src/components/field/form.jsx +0 -209
- package/src/components/field/input.jsx +0 -16
- package/src/components/field/input_checkbox.jsx +0 -434
- package/src/components/field/input_radio.jsx +0 -432
- package/src/components/field/input_textual.jsx +0 -389
- package/src/components/field/label.jsx +0 -46
- package/src/components/field/radio_list.jsx +0 -183
- package/src/components/field/select.jsx +0 -256
- package/src/components/field/use_action_events.js +0 -132
- package/src/components/field/use_form_events.js +0 -59
- package/src/components/field/use_ui_state_controller.js +0 -506
- package/src/components/item_tracker/README.md +0 -461
- package/src/components/item_tracker/use_isolated_item_tracker.jsx +0 -209
- package/src/components/item_tracker/use_isolated_item_tracker_demo.html +0 -148
- package/src/components/item_tracker/use_isolated_item_tracker_demo.jsx +0 -460
- package/src/components/item_tracker/use_item_tracker.jsx +0 -143
- package/src/components/item_tracker/use_item_tracker_demo.html +0 -207
- package/src/components/item_tracker/use_item_tracker_demo.jsx +0 -216
- package/src/components/keyboard_shortcuts/active_keyboard_shortcuts.jsx +0 -87
- package/src/components/keyboard_shortcuts/aria_key_shortcuts.js +0 -61
- package/src/components/keyboard_shortcuts/keyboard_key_meta.js +0 -17
- package/src/components/keyboard_shortcuts/keyboard_shortcuts.js +0 -371
- package/src/components/keyboard_shortcuts/os.js +0 -9
- package/src/components/layout/demos/demo_flex.html +0 -638
- package/src/components/layout/demos/demo_layout_style_buttons.html +0 -351
- package/src/components/layout/demos/demo_layout_style_input.html +0 -226
- package/src/components/layout/demos/demo_layout_style_text.html +0 -514
- package/src/components/layout/flex.jsx +0 -109
- package/src/components/layout/layout_context.jsx +0 -3
- package/src/components/layout/spacing.jsx +0 -20
- package/src/components/layout/use_layout_style.js +0 -249
- package/src/components/link/link.jsx +0 -267
- package/src/components/link/link_with_icon.jsx +0 -52
- package/src/components/loader/loader_background.jsx +0 -372
- package/src/components/loader/loading_spinner.jsx +0 -68
- package/src/components/loader/network_speed.js +0 -83
- package/src/components/loader/rectangle_loading.jsx +0 -244
- package/src/components/props_composition/demos/demo_with_props_style.html +0 -81
- package/src/components/props_composition/with_props_class_name.js +0 -37
- package/src/components/props_composition/with_props_style.js +0 -26
- package/src/components/route.jsx +0 -19
- package/src/components/selection/selection.jsx +0 -1583
- package/src/components/svg/font_sized_svg.jsx +0 -59
- package/src/components/svg/icon_and_text.jsx +0 -21
- package/src/components/svg/svg_mask_overlay.jsx +0 -105
- package/src/components/table/drag/table_drag.jsx +0 -506
- package/src/components/table/resize/table_resize.jsx +0 -650
- package/src/components/table/resize/table_size.js +0 -43
- package/src/components/table/selection/table_selection.js +0 -106
- package/src/components/table/selection/table_selection.jsx +0 -203
- package/src/components/table/sticky/sticky_group.js +0 -354
- package/src/components/table/sticky/table_sticky.js +0 -25
- package/src/components/table/sticky/table_sticky.jsx +0 -501
- package/src/components/table/table.jsx +0 -721
- package/src/components/table/table_css.js +0 -211
- package/src/components/table/table_ui.jsx +0 -49
- package/src/components/table/use_cells_and_columns.js +0 -90
- package/src/components/table/use_object_array_to_cells.js +0 -46
- package/src/components/table/z_indexes.js +0 -23
- package/src/components/tablist/tablist.jsx +0 -99
- package/src/components/text/demos/demo_text_and_icon.html +0 -421
- package/src/components/text/overflow.jsx +0 -15
- package/src/components/text/text.jsx +0 -83
- package/src/components/text/text_and_count.jsx +0 -28
- package/src/components/ui_transition.jsx +0 -128
- package/src/components/use_auto_focus.js +0 -94
- package/src/components/use_batch_during_render.js +0 -33
- package/src/components/use_debounce_true.js +0 -31
- package/src/components/use_dependencies_diff.js +0 -35
- package/src/components/use_focus_group.js +0 -20
- package/src/components/use_initial_value.js +0 -78
- package/src/components/use_is_visited.js +0 -19
- package/src/components/use_ref_array.js +0 -38
- package/src/components/use_signal_sync.js +0 -50
- package/src/components/use_stable_callback.js +0 -68
- package/src/components/use_state_array.js +0 -47
- package/src/docs/actions.md +0 -250
- package/src/docs/demos/resource/action_status.jsx +0 -42
- package/src/docs/demos/resource/demo.md +0 -1
- package/src/docs/demos/resource/resource_demo_0.html +0 -84
- package/src/docs/demos/resource/resource_demo_10_post_gc.html +0 -364
- package/src/docs/demos/resource/resource_demo_11_describe_many.html +0 -362
- package/src/docs/demos/resource/resource_demo_2.html +0 -173
- package/src/docs/demos/resource/resource_demo_3_filtered_users.html +0 -415
- package/src/docs/demos/resource/resource_demo_4_details.html +0 -284
- package/src/docs/demos/resource/resource_demo_5_renderer_lazy.html +0 -115
- package/src/docs/demos/resource/resource_demo_6_gc.html +0 -217
- package/src/docs/demos/resource/resource_demo_7_child_gc.html +0 -240
- package/src/docs/demos/resource/resource_demo_8_proxy_gc.html +0 -319
- package/src/docs/demos/resource/resource_demo_9_describe_one.html +0 -472
- package/src/docs/demos/resource/tata.jsx +0 -3
- package/src/docs/demos/resource/toto.jsx +0 -3
- package/src/docs/demos/user_nav/user_nav.html +0 -12
- package/src/docs/demos/user_nav/user_nav.jsx +0 -330
- package/src/docs/resource_dependencies.md +0 -103
- package/src/docs/resource_with_params.md +0 -80
- package/src/navi_css_vars.js +0 -14
- package/src/notes.md +0 -34
- package/src/route/route.js +0 -596
- package/src/route/route.xtest.html +0 -228
- package/src/store/array_signal_store.js +0 -537
- package/src/store/local_storage_signal.js +0 -17
- package/src/store/resource_graph.js +0 -1304
- package/src/store/tests/resource_graph_autoreload_demo.html +0 -12
- package/src/store/tests/resource_graph_autoreload_demo.jsx +0 -964
- package/src/store/tests/resource_graph_dependencies.test_manual.js +0 -95
- package/src/store/value_in_local_storage.js +0 -187
- package/src/symbol_object_signal.js +0 -1
- package/src/use_action_data.js +0 -10
- package/src/use_action_status.js +0 -47
- package/src/utils/add_many_event_listeners.js +0 -15
- package/src/utils/array_add_remove.js +0 -61
- package/src/utils/array_signal.js +0 -15
- package/src/utils/compare_two_js_values.js +0 -172
- package/src/utils/execute_with_cleanup.js +0 -21
- package/src/utils/get_caller_info.js +0 -85
- package/src/utils/is_signal.js +0 -20
- package/src/utils/js_value_weak_map.js +0 -162
- package/src/utils/js_value_weak_map_demo.html +0 -690
- package/src/utils/merge_two_js_values.js +0 -53
- package/src/utils/stringify_for_display.js +0 -131
- package/src/utils/weak_effect.js +0 -48
- package/src/validation/constraints/confirm_constraint.js +0 -14
- package/src/validation/constraints/create_unique_value_constraint.js +0 -27
- package/src/validation/constraints/native_constraints.js +0 -338
- package/src/validation/constraints/readonly_constraint.js +0 -41
- package/src/validation/constraints/same_as_constraint.js +0 -42
- package/src/validation/constraints/single_space_constraint.js +0 -13
- package/src/validation/custom_constraint_validation.js +0 -793
- package/src/validation/custom_message.js +0 -18
- package/src/validation/demos/browser_style.png +0 -0
- package/src/validation/demos/demo_same_as_constraint.html +0 -259
- package/src/validation/demos/form_validation_demo.html +0 -142
- package/src/validation/demos/form_validation_demo_preact.html +0 -87
- package/src/validation/demos/form_validation_native_popover_demo.html +0 -168
- package/src/validation/demos/form_validation_vs_native_demo.html +0 -172
- package/src/validation/hooks/use_constraints.js +0 -23
- package/src/validation/hooks/use_custom_validation_ref.js +0 -73
- package/src/validation/hooks/use_validation_message.js +0 -19
- package/src/validation/input_change_effect.js +0 -106
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef } from "preact/hooks";
|
|
2
|
-
import { updateActions } from "../actions.js";
|
|
3
|
-
import {
|
|
4
|
-
setBrowserIntegration,
|
|
5
|
-
setOnRouteDefined,
|
|
6
|
-
updateRoutes,
|
|
7
|
-
} from "../route/route.js";
|
|
8
|
-
import {
|
|
9
|
-
documentIsBusySignal,
|
|
10
|
-
routingWhile,
|
|
11
|
-
windowIsLoadingSignal,
|
|
12
|
-
workingWhile,
|
|
13
|
-
} from "./document_loading_signal.js";
|
|
14
|
-
import { setupBrowserIntegrationViaHistory } from "./via_history.js";
|
|
15
|
-
|
|
16
|
-
const applyActions = (params) => {
|
|
17
|
-
const updateActionsResult = updateActions(params);
|
|
18
|
-
const { allResult, runningActionSet } = updateActionsResult;
|
|
19
|
-
const pendingTaskNameArray = [];
|
|
20
|
-
for (const runningAction of runningActionSet) {
|
|
21
|
-
pendingTaskNameArray.push(runningAction.name);
|
|
22
|
-
}
|
|
23
|
-
workingWhile(() => allResult, pendingTaskNameArray);
|
|
24
|
-
return updateActionsResult;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const applyRouting = (
|
|
28
|
-
url,
|
|
29
|
-
{
|
|
30
|
-
globalAbortSignal,
|
|
31
|
-
abortSignal,
|
|
32
|
-
// state
|
|
33
|
-
replace,
|
|
34
|
-
isVisited,
|
|
35
|
-
reason,
|
|
36
|
-
},
|
|
37
|
-
) => {
|
|
38
|
-
const {
|
|
39
|
-
loadSet,
|
|
40
|
-
reloadSet,
|
|
41
|
-
abortSignalMap,
|
|
42
|
-
routeLoadRequestedMap,
|
|
43
|
-
activeRouteSet,
|
|
44
|
-
} = updateRoutes(url, {
|
|
45
|
-
replace,
|
|
46
|
-
// state,
|
|
47
|
-
isVisited,
|
|
48
|
-
});
|
|
49
|
-
if (loadSet.size === 0 && reloadSet.size === 0) {
|
|
50
|
-
return {
|
|
51
|
-
allResult: undefined,
|
|
52
|
-
requestedResult: undefined,
|
|
53
|
-
activeRouteSet: new Set(),
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
const updateActionsResult = updateActions({
|
|
57
|
-
globalAbortSignal,
|
|
58
|
-
abortSignal,
|
|
59
|
-
runSet: loadSet,
|
|
60
|
-
rerunSet: reloadSet,
|
|
61
|
-
abortSignalMap,
|
|
62
|
-
reason,
|
|
63
|
-
});
|
|
64
|
-
const { allResult, runningActionSet } = updateActionsResult;
|
|
65
|
-
const pendingTaskNameArray = [];
|
|
66
|
-
for (const [route, routeAction] of routeLoadRequestedMap) {
|
|
67
|
-
if (runningActionSet.has(routeAction)) {
|
|
68
|
-
pendingTaskNameArray.push(`${route.relativeUrl} -> ${routeAction.name}`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
routingWhile(() => allResult, pendingTaskNameArray);
|
|
72
|
-
return { ...updateActionsResult, activeRouteSet };
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const browserIntegration = setupBrowserIntegrationViaHistory({
|
|
76
|
-
applyActions,
|
|
77
|
-
applyRouting,
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
setOnRouteDefined(() => {
|
|
81
|
-
browserIntegration.init();
|
|
82
|
-
});
|
|
83
|
-
setBrowserIntegration(browserIntegration);
|
|
84
|
-
|
|
85
|
-
export const actionIntegratedVia = browserIntegration.integration;
|
|
86
|
-
export const goTo = browserIntegration.goTo;
|
|
87
|
-
export const stopLoad = (reason = "stopLoad() called") => {
|
|
88
|
-
const windowIsLoading = windowIsLoadingSignal.value;
|
|
89
|
-
if (windowIsLoading) {
|
|
90
|
-
window.stop();
|
|
91
|
-
}
|
|
92
|
-
const documentIsBusy = documentIsBusySignal.value;
|
|
93
|
-
if (documentIsBusy) {
|
|
94
|
-
browserIntegration.stop(reason);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
export const reload = browserIntegration.reload;
|
|
98
|
-
export const goBack = browserIntegration.goBack;
|
|
99
|
-
export const goForward = browserIntegration.goForward;
|
|
100
|
-
export const isVisited = browserIntegration.isVisited;
|
|
101
|
-
export const visitedUrlsSignal = browserIntegration.visitedUrlsSignal;
|
|
102
|
-
export const handleActionTask = browserIntegration.handleActionTask;
|
|
103
|
-
|
|
104
|
-
const idUsageMap = new Map();
|
|
105
|
-
const useNavStateWithWarnings = (id, initialValue, options) => {
|
|
106
|
-
const idRef = useRef(undefined);
|
|
107
|
-
if (idRef.current !== id) {
|
|
108
|
-
const oldId = idRef.current;
|
|
109
|
-
idUsageMap.delete(oldId);
|
|
110
|
-
idRef.current = id;
|
|
111
|
-
|
|
112
|
-
const usage = idUsageMap.get(id);
|
|
113
|
-
if (!usage) {
|
|
114
|
-
idUsageMap.set(id, {
|
|
115
|
-
stackTrace: new Error().stack,
|
|
116
|
-
});
|
|
117
|
-
} else {
|
|
118
|
-
console.warn(
|
|
119
|
-
`useNavState ID conflict detected!
|
|
120
|
-
ID "${id}" is already in use by another component.
|
|
121
|
-
This can cause UI state conflicts and unexpected behavior.
|
|
122
|
-
Consider using unique IDs for each component instance.`,
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
useEffect(() => {
|
|
128
|
-
return () => {
|
|
129
|
-
idUsageMap.delete(id);
|
|
130
|
-
};
|
|
131
|
-
}, [id]);
|
|
132
|
-
|
|
133
|
-
return useNavStateBasic(id, initialValue, options);
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
const NOT_SET = {};
|
|
137
|
-
const NO_OP = () => {};
|
|
138
|
-
const NO_ID_GIVEN = [undefined, NO_OP, NO_OP];
|
|
139
|
-
const useNavStateBasic = (id, initialValue, { debug } = {}) => {
|
|
140
|
-
const navStateRef = useRef(NOT_SET);
|
|
141
|
-
if (!id) {
|
|
142
|
-
return NO_ID_GIVEN;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (navStateRef.current === NOT_SET) {
|
|
146
|
-
const documentState = browserIntegration.getDocumentState();
|
|
147
|
-
const valueInDocumentState = documentState ? documentState[id] : undefined;
|
|
148
|
-
if (valueInDocumentState === undefined) {
|
|
149
|
-
navStateRef.current = initialValue;
|
|
150
|
-
if (initialValue !== undefined) {
|
|
151
|
-
console.debug(
|
|
152
|
-
`useNavState(${id}) initial value is ${initialValue} (from initialValue passed in as argument)`,
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
} else {
|
|
156
|
-
navStateRef.current = valueInDocumentState;
|
|
157
|
-
if (debug) {
|
|
158
|
-
console.debug(
|
|
159
|
-
`useNavState(${id}) initial value is ${initialValue} (from nav state)`,
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const set = (value) => {
|
|
166
|
-
const currentValue = navStateRef.current;
|
|
167
|
-
if (typeof value === "function") {
|
|
168
|
-
value = value(currentValue);
|
|
169
|
-
}
|
|
170
|
-
if (debug) {
|
|
171
|
-
console.debug(
|
|
172
|
-
`useNavState(${id}) set ${value} (previous was ${currentValue})`,
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const currentState = browserIntegration.getDocumentState() || {};
|
|
177
|
-
|
|
178
|
-
if (value === undefined) {
|
|
179
|
-
if (!Object.hasOwn(currentState, id)) {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
delete currentState[id];
|
|
183
|
-
browserIntegration.replaceDocumentState(currentState, {
|
|
184
|
-
reason: `delete "${id}" from browser state`,
|
|
185
|
-
});
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const valueInBrowserState = currentState[id];
|
|
190
|
-
if (valueInBrowserState === value) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
currentState[id] = value;
|
|
194
|
-
browserIntegration.replaceDocumentState(currentState, {
|
|
195
|
-
reason: `set { ${id}: ${value} } in browser state`,
|
|
196
|
-
});
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
return [
|
|
200
|
-
navStateRef.current,
|
|
201
|
-
set,
|
|
202
|
-
() => {
|
|
203
|
-
set(undefined);
|
|
204
|
-
},
|
|
205
|
-
];
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
export const useNavState = import.meta.dev
|
|
209
|
-
? useNavStateWithWarnings
|
|
210
|
-
: useNavStateBasic;
|
|
211
|
-
|
|
212
|
-
if (import.meta.hot) {
|
|
213
|
-
import.meta.hot.dispose(() => {
|
|
214
|
-
idUsageMap.clear();
|
|
215
|
-
});
|
|
216
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { signal } from "@preact/signals";
|
|
2
|
-
|
|
3
|
-
export const canGoBackSignal = signal(false);
|
|
4
|
-
export const updateCanGoBack = (can) => {
|
|
5
|
-
canGoBackSignal.value = can;
|
|
6
|
-
};
|
|
7
|
-
export const useCanGoBack = () => {
|
|
8
|
-
return canGoBackSignal.value;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const canGoForwardSignal = signal(false);
|
|
12
|
-
export const updateCanGoForward = (can) => {
|
|
13
|
-
canGoBackSignal.value = can;
|
|
14
|
-
};
|
|
15
|
-
export const useCanGoForward = () => {
|
|
16
|
-
return canGoForwardSignal.value;
|
|
17
|
-
};
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { computed, signal } from "@preact/signals";
|
|
2
|
-
import { arraySignal } from "../utils/array_signal.js";
|
|
3
|
-
import { executeWithCleanup } from "../utils/execute_with_cleanup.js";
|
|
4
|
-
|
|
5
|
-
let DEBUG = false;
|
|
6
|
-
export const enableDebugOnDocumentLoading = () => {
|
|
7
|
-
DEBUG = true;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const windowIsLoadingSignal = signal(true);
|
|
11
|
-
if (document.readyState === "complete") {
|
|
12
|
-
windowIsLoadingSignal.value = false;
|
|
13
|
-
} else {
|
|
14
|
-
document.addEventListener("readystatechange", () => {
|
|
15
|
-
if (document.readyState === "complete") {
|
|
16
|
-
windowIsLoadingSignal.value = false;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const [
|
|
22
|
-
documentLoadingRouteArraySignal,
|
|
23
|
-
addToDocumentLoadingRouteArraySignal,
|
|
24
|
-
removeFromDocumentLoadingRouteArraySignal,
|
|
25
|
-
] = arraySignal([]);
|
|
26
|
-
export { documentLoadingRouteArraySignal };
|
|
27
|
-
export const routingWhile = (fn, routeNames = []) => {
|
|
28
|
-
if (DEBUG && routeNames.length > 0) {
|
|
29
|
-
console.debug(`routingWhile: Adding routes to loading state:`, routeNames);
|
|
30
|
-
}
|
|
31
|
-
addToDocumentLoadingRouteArraySignal(...routeNames);
|
|
32
|
-
return executeWithCleanup(fn, () => {
|
|
33
|
-
removeFromDocumentLoadingRouteArraySignal(...routeNames);
|
|
34
|
-
if (DEBUG && routeNames.length > 0) {
|
|
35
|
-
console.debug(
|
|
36
|
-
`routingWhile: Removed routes from loading state:`,
|
|
37
|
-
routeNames,
|
|
38
|
-
"state after removing:",
|
|
39
|
-
documentLoadingRouteArraySignal.peek(),
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const [
|
|
46
|
-
documentLoadingActionArraySignal,
|
|
47
|
-
addToDocumentLoadingActionArraySignal,
|
|
48
|
-
removeFromDocumentLoadingActionArraySignal,
|
|
49
|
-
] = arraySignal([]);
|
|
50
|
-
export { documentLoadingActionArraySignal };
|
|
51
|
-
export const workingWhile = (fn, actionNames = []) => {
|
|
52
|
-
if (DEBUG && actionNames.length > 0) {
|
|
53
|
-
console.debug(
|
|
54
|
-
`workingWhile: Adding actions to loading state:`,
|
|
55
|
-
actionNames,
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
addToDocumentLoadingActionArraySignal(...actionNames);
|
|
59
|
-
return executeWithCleanup(fn, () => {
|
|
60
|
-
removeFromDocumentLoadingActionArraySignal(...actionNames);
|
|
61
|
-
if (DEBUG && actionNames.length > 0) {
|
|
62
|
-
console.debug(
|
|
63
|
-
`routingWhile: Removed action from loading state:`,
|
|
64
|
-
actionNames,
|
|
65
|
-
"start after removing:",
|
|
66
|
-
documentLoadingActionArraySignal.peek(),
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export const documentIsBusySignal = computed(() => {
|
|
73
|
-
return (
|
|
74
|
-
documentLoadingRouteArraySignal.value.length > 0 ||
|
|
75
|
-
documentLoadingActionArraySignal.value.length > 0
|
|
76
|
-
);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const documentLoadingReasonArraySignal = computed(() => {
|
|
80
|
-
const windowIsLoading = windowIsLoadingSignal.value;
|
|
81
|
-
const routesLoading = documentLoadingRouteArraySignal.value;
|
|
82
|
-
const actionsLoading = documentLoadingActionArraySignal.value;
|
|
83
|
-
const reasonArray = [];
|
|
84
|
-
if (windowIsLoading) {
|
|
85
|
-
reasonArray.push("window_loading");
|
|
86
|
-
}
|
|
87
|
-
if (routesLoading.length > 0) {
|
|
88
|
-
reasonArray.push("document_routing");
|
|
89
|
-
}
|
|
90
|
-
if (actionsLoading.length > 0) {
|
|
91
|
-
reasonArray.push("document_working");
|
|
92
|
-
}
|
|
93
|
-
return reasonArray;
|
|
94
|
-
});
|
|
95
|
-
export const useDocumentLoadingReasonArray = () => {
|
|
96
|
-
return documentLoadingReasonArraySignal.value;
|
|
97
|
-
};
|
|
98
|
-
export const useDocumentIsLoading = () => {
|
|
99
|
-
return documentLoadingReasonArraySignal.value.length > 0;
|
|
100
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { signal } from "@preact/signals";
|
|
2
|
-
|
|
3
|
-
export const documentStateSignal = signal(null);
|
|
4
|
-
export const useDocumentState = () => {
|
|
5
|
-
return documentStateSignal.value;
|
|
6
|
-
};
|
|
7
|
-
export const updateDocumentState = (value) => {
|
|
8
|
-
documentStateSignal.value = value;
|
|
9
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { signal } from "@preact/signals";
|
|
2
|
-
|
|
3
|
-
export const documentUrlSignal = signal(window.location.href);
|
|
4
|
-
export const useDocumentUrl = () => {
|
|
5
|
-
return documentUrlSignal.value;
|
|
6
|
-
};
|
|
7
|
-
export const updateDocumentUrl = (value) => {
|
|
8
|
-
documentUrlSignal.value = value;
|
|
9
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { useMemo } from "preact/hooks";
|
|
2
|
-
import { isVisited, visitedUrlsSignal } from "./browser_integration.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Hook that reactively checks if a URL is visited.
|
|
6
|
-
* Re-renders when the visited URL set changes.
|
|
7
|
-
*
|
|
8
|
-
* @param {string} url - The URL to check
|
|
9
|
-
* @returns {boolean} Whether the URL has been visited
|
|
10
|
-
*/
|
|
11
|
-
export const useIsVisited = (url) => {
|
|
12
|
-
return useMemo(() => {
|
|
13
|
-
// Access the signal to create reactive dependency
|
|
14
|
-
// eslint-disable-next-line no-unused-expressions
|
|
15
|
-
visitedUrlsSignal.value;
|
|
16
|
-
|
|
17
|
-
return isVisited(url);
|
|
18
|
-
}, [url, visitedUrlsSignal.value]);
|
|
19
|
-
};
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import { signal } from "@preact/signals";
|
|
2
|
-
import { setActionDispatcher } from "../actions.js";
|
|
3
|
-
import { executeWithCleanup } from "../utils/execute_with_cleanup.js";
|
|
4
|
-
import { updateDocumentState } from "./document_state_signal.js";
|
|
5
|
-
import { documentUrlSignal, updateDocumentUrl } from "./document_url_signal.js";
|
|
6
|
-
|
|
7
|
-
export const setupBrowserIntegrationViaHistory = ({
|
|
8
|
-
applyActions,
|
|
9
|
-
applyRouting,
|
|
10
|
-
}) => {
|
|
11
|
-
const { history } = window;
|
|
12
|
-
|
|
13
|
-
let globalAbortController = new AbortController();
|
|
14
|
-
const triggerGlobalAbort = (reason) => {
|
|
15
|
-
globalAbortController.abort(reason);
|
|
16
|
-
globalAbortController = new AbortController();
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const dispatchActions = (params) => {
|
|
20
|
-
const { requestedResult } = applyActions({
|
|
21
|
-
globalAbortSignal: globalAbortController.signal,
|
|
22
|
-
abortSignal: new AbortController().signal,
|
|
23
|
-
...params,
|
|
24
|
-
});
|
|
25
|
-
return requestedResult;
|
|
26
|
-
};
|
|
27
|
-
setActionDispatcher(dispatchActions);
|
|
28
|
-
|
|
29
|
-
const getDocumentState = () => {
|
|
30
|
-
return window.history.state ? { ...window.history.state } : null;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const replaceDocumentState = (
|
|
34
|
-
newState,
|
|
35
|
-
{ reason = "replaceDocumentState called" } = {},
|
|
36
|
-
) => {
|
|
37
|
-
const url = window.location.href;
|
|
38
|
-
window.history.replaceState(newState, null, url);
|
|
39
|
-
handleRoutingTask(url, {
|
|
40
|
-
replace: true,
|
|
41
|
-
state: newState,
|
|
42
|
-
reason,
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const historyStartAtStart = getDocumentState();
|
|
47
|
-
const visitedUrlSet = historyStartAtStart
|
|
48
|
-
? new Set(historyStartAtStart.jsenv_visited_urls || [])
|
|
49
|
-
: new Set();
|
|
50
|
-
|
|
51
|
-
// Create a signal that tracks visited URLs for reactive updates
|
|
52
|
-
// Using a counter instead of the Set directly for better performance
|
|
53
|
-
// Links will check isVisited() when this signal changes
|
|
54
|
-
const visitedUrlsSignal = signal(0);
|
|
55
|
-
|
|
56
|
-
const isVisited = (url) => {
|
|
57
|
-
url = new URL(url, window.location.href).href;
|
|
58
|
-
return visitedUrlSet.has(url);
|
|
59
|
-
};
|
|
60
|
-
const markUrlAsVisited = (url) => {
|
|
61
|
-
if (visitedUrlSet.has(url)) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
visitedUrlSet.add(url);
|
|
65
|
-
|
|
66
|
-
// Increment signal to notify subscribers that visited URLs changed
|
|
67
|
-
visitedUrlsSignal.value++;
|
|
68
|
-
|
|
69
|
-
const historyState = getDocumentState() || {};
|
|
70
|
-
const hsitoryStateWithVisitedUrls = {
|
|
71
|
-
...historyState,
|
|
72
|
-
jsenv_visited_urls: Array.from(visitedUrlSet),
|
|
73
|
-
};
|
|
74
|
-
window.history.replaceState(
|
|
75
|
-
hsitoryStateWithVisitedUrls,
|
|
76
|
-
null,
|
|
77
|
-
window.location.href,
|
|
78
|
-
);
|
|
79
|
-
updateDocumentState(hsitoryStateWithVisitedUrls);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
let abortController = null;
|
|
83
|
-
const handleRoutingTask = (url, { state, replace, reason }) => {
|
|
84
|
-
markUrlAsVisited(url);
|
|
85
|
-
updateDocumentUrl(url);
|
|
86
|
-
updateDocumentState(state);
|
|
87
|
-
if (abortController) {
|
|
88
|
-
abortController.abort(`navigating to ${url}`);
|
|
89
|
-
}
|
|
90
|
-
abortController = new AbortController();
|
|
91
|
-
|
|
92
|
-
const { allResult, requestedResult } = applyRouting(url, {
|
|
93
|
-
globalAbortSignal: globalAbortController.signal,
|
|
94
|
-
abortSignal: abortController.signal,
|
|
95
|
-
state,
|
|
96
|
-
replace,
|
|
97
|
-
isVisited,
|
|
98
|
-
reason,
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
executeWithCleanup(
|
|
102
|
-
() => allResult,
|
|
103
|
-
() => {
|
|
104
|
-
abortController = undefined;
|
|
105
|
-
},
|
|
106
|
-
);
|
|
107
|
-
return requestedResult;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
// Browser event handlers
|
|
111
|
-
window.addEventListener(
|
|
112
|
-
"click",
|
|
113
|
-
(e) => {
|
|
114
|
-
if (e.button !== 0) {
|
|
115
|
-
// Ignore non-left clicks
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
if (e.metaKey) {
|
|
119
|
-
// Ignore clicks with meta key (e.g. open in new tab)
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
const linkElement = e.target.closest("a");
|
|
123
|
-
if (!linkElement) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
const href = linkElement.href;
|
|
127
|
-
if (!href || !href.startsWith(window.location.origin)) {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
if (linkElement.hasAttribute("data-readonly")) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
// Ignore anchor navigation (same page, different hash)
|
|
134
|
-
const currentUrl = new URL(window.location.href);
|
|
135
|
-
const targetUrl = new URL(href);
|
|
136
|
-
if (
|
|
137
|
-
currentUrl.pathname === targetUrl.pathname &&
|
|
138
|
-
currentUrl.search === targetUrl.search &&
|
|
139
|
-
targetUrl.hash !== ""
|
|
140
|
-
) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
e.preventDefault();
|
|
144
|
-
const state = null;
|
|
145
|
-
history.pushState(state, null, href);
|
|
146
|
-
handleRoutingTask(href, {
|
|
147
|
-
state,
|
|
148
|
-
reason: `"click" on a[href="${href}"]`,
|
|
149
|
-
});
|
|
150
|
-
},
|
|
151
|
-
{ capture: true },
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
window.addEventListener(
|
|
155
|
-
"submit",
|
|
156
|
-
() => {
|
|
157
|
-
// TODO: Handle form submissions
|
|
158
|
-
},
|
|
159
|
-
{ capture: true },
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
window.addEventListener("popstate", (popstateEvent) => {
|
|
163
|
-
const url = window.location.href;
|
|
164
|
-
const state = popstateEvent.state;
|
|
165
|
-
handleRoutingTask(url, {
|
|
166
|
-
state,
|
|
167
|
-
reason: `"popstate" event for ${url}`,
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
const goTo = async (url, { state = null, replace } = {}) => {
|
|
172
|
-
const currentUrl = documentUrlSignal.peek();
|
|
173
|
-
if (url === currentUrl) {
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
if (replace) {
|
|
177
|
-
window.history.replaceState(state, null, url);
|
|
178
|
-
} else {
|
|
179
|
-
window.history.pushState(state, null, url);
|
|
180
|
-
}
|
|
181
|
-
handleRoutingTask(url, {
|
|
182
|
-
state,
|
|
183
|
-
replace,
|
|
184
|
-
reason: `goTo called with "${url}"`,
|
|
185
|
-
});
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
const stop = (reason = "stop called") => {
|
|
189
|
-
triggerGlobalAbort(reason);
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
const reload = () => {
|
|
193
|
-
const url = window.location.href;
|
|
194
|
-
const state = history.state;
|
|
195
|
-
handleRoutingTask(url, {
|
|
196
|
-
state,
|
|
197
|
-
});
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
const goBack = () => {
|
|
201
|
-
window.history.back();
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
const goForward = () => {
|
|
205
|
-
window.history.forward();
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
const init = () => {
|
|
209
|
-
const url = window.location.href;
|
|
210
|
-
const state = history.state;
|
|
211
|
-
history.replaceState(state, null, url);
|
|
212
|
-
handleRoutingTask(url, {
|
|
213
|
-
state,
|
|
214
|
-
replace: true,
|
|
215
|
-
reason: "routing initialization",
|
|
216
|
-
});
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
return {
|
|
220
|
-
integration: "browser_history_api",
|
|
221
|
-
init,
|
|
222
|
-
goTo,
|
|
223
|
-
stop,
|
|
224
|
-
reload,
|
|
225
|
-
goBack,
|
|
226
|
-
goForward,
|
|
227
|
-
getDocumentState,
|
|
228
|
-
replaceDocumentState,
|
|
229
|
-
isVisited,
|
|
230
|
-
visitedUrlsSignal,
|
|
231
|
-
};
|
|
232
|
-
};
|