@jsenv/navi 0.10.2 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/jsenv_navi.js +13838 -23291
- 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 -193
- 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,106 +0,0 @@
|
|
|
1
|
-
import { createPubSub } from "@jsenv/dom";
|
|
2
|
-
|
|
3
|
-
export const initCustomField = (customField, field) => {
|
|
4
|
-
const [teardown, addTeardown] = createPubSub();
|
|
5
|
-
|
|
6
|
-
const addEventListener = (element, eventType, listener) => {
|
|
7
|
-
element.addEventListener(eventType, listener);
|
|
8
|
-
return addTeardown(() => {
|
|
9
|
-
element.removeEventListener(eventType, listener);
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
const updateBooleanAttribute = (attributeName, isPresent) => {
|
|
13
|
-
if (isPresent) {
|
|
14
|
-
customField.setAttribute(attributeName, "");
|
|
15
|
-
} else {
|
|
16
|
-
customField.removeAttribute(attributeName);
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
const checkPseudoClasses = () => {
|
|
20
|
-
const hover = field.matches(":hover");
|
|
21
|
-
const active = field.matches(":active");
|
|
22
|
-
const checked = field.matches(":checked");
|
|
23
|
-
const focus = field.matches(":focus");
|
|
24
|
-
const focusVisible = field.matches(":focus-visible");
|
|
25
|
-
const valid = field.matches(":valid");
|
|
26
|
-
const invalid = field.matches(":invalid");
|
|
27
|
-
updateBooleanAttribute(`data-hover`, hover);
|
|
28
|
-
updateBooleanAttribute(`data-active`, active);
|
|
29
|
-
updateBooleanAttribute(`data-checked`, checked);
|
|
30
|
-
updateBooleanAttribute(`data-focus`, focus);
|
|
31
|
-
updateBooleanAttribute(`data-focus-visible`, focusVisible);
|
|
32
|
-
updateBooleanAttribute(`data-valid`, valid);
|
|
33
|
-
updateBooleanAttribute(`data-invalid`, invalid);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
// :hover
|
|
37
|
-
addEventListener(field, "mouseenter", checkPseudoClasses);
|
|
38
|
-
addEventListener(field, "mouseleave", checkPseudoClasses);
|
|
39
|
-
// :active
|
|
40
|
-
addEventListener(field, "mousedown", checkPseudoClasses);
|
|
41
|
-
addEventListener(document, "mouseup", checkPseudoClasses);
|
|
42
|
-
// :focus
|
|
43
|
-
addEventListener(field, "focusin", checkPseudoClasses);
|
|
44
|
-
addEventListener(field, "focusout", checkPseudoClasses);
|
|
45
|
-
// :focus-visible
|
|
46
|
-
addEventListener(document, "keydown", checkPseudoClasses);
|
|
47
|
-
addEventListener(document, "keyup", checkPseudoClasses);
|
|
48
|
-
// :checked
|
|
49
|
-
if (field.type === "checkbox") {
|
|
50
|
-
// Listen to user interactions
|
|
51
|
-
addEventListener(field, "input", checkPseudoClasses);
|
|
52
|
-
|
|
53
|
-
// Intercept programmatic changes to .checked property
|
|
54
|
-
const originalDescriptor = Object.getOwnPropertyDescriptor(
|
|
55
|
-
HTMLInputElement.prototype,
|
|
56
|
-
"checked",
|
|
57
|
-
);
|
|
58
|
-
Object.defineProperty(field, "checked", {
|
|
59
|
-
get: originalDescriptor.get,
|
|
60
|
-
set(value) {
|
|
61
|
-
originalDescriptor.set.call(this, value);
|
|
62
|
-
checkPseudoClasses();
|
|
63
|
-
},
|
|
64
|
-
configurable: true,
|
|
65
|
-
});
|
|
66
|
-
addTeardown(() => {
|
|
67
|
-
// Restore original property descriptor
|
|
68
|
-
Object.defineProperty(field, "checked", originalDescriptor);
|
|
69
|
-
});
|
|
70
|
-
} else if (field.type === "radio") {
|
|
71
|
-
// Listen to changes on the radio group
|
|
72
|
-
const radioSet =
|
|
73
|
-
field.closest("[data-radio-list], fieldset, form") || document;
|
|
74
|
-
addEventListener(radioSet, "input", checkPseudoClasses);
|
|
75
|
-
|
|
76
|
-
// Intercept programmatic changes to .checked property
|
|
77
|
-
const originalDescriptor = Object.getOwnPropertyDescriptor(
|
|
78
|
-
HTMLInputElement.prototype,
|
|
79
|
-
"checked",
|
|
80
|
-
);
|
|
81
|
-
Object.defineProperty(field, "checked", {
|
|
82
|
-
get: originalDescriptor.get,
|
|
83
|
-
set(value) {
|
|
84
|
-
originalDescriptor.set.call(this, value);
|
|
85
|
-
checkPseudoClasses();
|
|
86
|
-
},
|
|
87
|
-
configurable: true,
|
|
88
|
-
});
|
|
89
|
-
addTeardown(() => {
|
|
90
|
-
// Restore original property descriptor
|
|
91
|
-
Object.defineProperty(field, "checked", originalDescriptor);
|
|
92
|
-
});
|
|
93
|
-
} else if (field.tagName === "INPUT") {
|
|
94
|
-
addEventListener(field, "input", checkPseudoClasses);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// just in case + catch use forcing them in chrome devtools
|
|
98
|
-
const interval = setInterval(() => {
|
|
99
|
-
checkPseudoClasses();
|
|
100
|
-
}, 150);
|
|
101
|
-
addTeardown(() => {
|
|
102
|
-
clearInterval(interval);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
return teardown;
|
|
106
|
-
};
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Here we want the same behaviour as web standards:
|
|
4
|
-
*
|
|
5
|
-
* 1. When submitting the form URL does not change
|
|
6
|
-
* 2. When form submission id done user is redirected (by default the current one)
|
|
7
|
-
* (we can configure this using target)
|
|
8
|
-
* So for example user might be reidrect to a page with the resource he just created
|
|
9
|
-
* I could create an example where we would put a link on the page to let user see what he created
|
|
10
|
-
* but by default user stays on the form allowing to create multiple resources at once
|
|
11
|
-
* And an other where he is redirected to the resource he created
|
|
12
|
-
* 3. If form submission fails ideally we should display this somewhere on the UI
|
|
13
|
-
* right now it's just logged to the console I need to see how we can achieve this
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { forwardRef } from "preact/compat";
|
|
17
|
-
import { useContext, useImperativeHandle, useMemo, useRef } from "preact/hooks";
|
|
18
|
-
|
|
19
|
-
import { forwardActionRequested } from "../../validation/custom_constraint_validation.js";
|
|
20
|
-
import { useConstraints } from "../../validation/hooks/use_constraints.js";
|
|
21
|
-
import {
|
|
22
|
-
FormActionContext,
|
|
23
|
-
FormContext,
|
|
24
|
-
} from "../action_execution/form_context.js";
|
|
25
|
-
import { renderActionableComponent } from "../action_execution/render_actionable_component.jsx";
|
|
26
|
-
import { useActionBoundToOneParam } from "../action_execution/use_action.js";
|
|
27
|
-
import { useExecuteAction } from "../action_execution/use_execute_action.js";
|
|
28
|
-
import { useLayoutStyle } from "../layout/use_layout_style.js";
|
|
29
|
-
import { withPropsStyle } from "../props_composition/with_props_style.js";
|
|
30
|
-
import { collectFormElementValues } from "./collect_form_element_values.js";
|
|
31
|
-
import {
|
|
32
|
-
useActionEvents,
|
|
33
|
-
useRequestedActionStatus,
|
|
34
|
-
} from "./use_action_events.js";
|
|
35
|
-
import {
|
|
36
|
-
LoadingContext,
|
|
37
|
-
LoadingElementContext,
|
|
38
|
-
ParentUIStateControllerContext,
|
|
39
|
-
ReadOnlyContext,
|
|
40
|
-
UIStateContext,
|
|
41
|
-
UIStateControllerContext,
|
|
42
|
-
useUIGroupStateController,
|
|
43
|
-
useUIState,
|
|
44
|
-
} from "./use_ui_state_controller.js";
|
|
45
|
-
|
|
46
|
-
export const Form = forwardRef((props, ref) => {
|
|
47
|
-
const uiStateController = useUIGroupStateController(props, "form", {
|
|
48
|
-
childComponentType: "*",
|
|
49
|
-
aggregateChildStates: (childUIStateControllers) => {
|
|
50
|
-
const formValues = {};
|
|
51
|
-
for (const childUIStateController of childUIStateControllers) {
|
|
52
|
-
const { name, uiState } = childUIStateController;
|
|
53
|
-
if (!name) {
|
|
54
|
-
console.warn(
|
|
55
|
-
"A form child component is missing a name property, its state won't be included in the form state",
|
|
56
|
-
childUIStateController,
|
|
57
|
-
);
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
formValues[name] = uiState;
|
|
61
|
-
}
|
|
62
|
-
return formValues;
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
const uiState = useUIState(uiStateController);
|
|
66
|
-
|
|
67
|
-
const form = renderActionableComponent(props, ref, {
|
|
68
|
-
Basic: FormBasic,
|
|
69
|
-
WithAction: FormWithAction,
|
|
70
|
-
});
|
|
71
|
-
return (
|
|
72
|
-
<UIStateControllerContext.Provider value={uiStateController}>
|
|
73
|
-
<UIStateContext.Provider value={uiState}>{form}</UIStateContext.Provider>
|
|
74
|
-
</UIStateControllerContext.Provider>
|
|
75
|
-
);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
const FormBasic = forwardRef((props, ref) => {
|
|
79
|
-
const uiStateController = useContext(UIStateControllerContext);
|
|
80
|
-
const { readOnly, loading, style, children, ...rest } = props;
|
|
81
|
-
const innerRef = useRef();
|
|
82
|
-
useImperativeHandle(ref, () => innerRef.current);
|
|
83
|
-
|
|
84
|
-
// instantiation validation to:
|
|
85
|
-
// - receive "requestsubmit" custom event ensure submit is prevented
|
|
86
|
-
// (and also execute action without validation if form.submit() is ever called)
|
|
87
|
-
useConstraints(innerRef, []);
|
|
88
|
-
|
|
89
|
-
const innerReadOnly = readOnly || loading;
|
|
90
|
-
|
|
91
|
-
const formContextValue = useMemo(() => {
|
|
92
|
-
return { loading };
|
|
93
|
-
}, [loading]);
|
|
94
|
-
|
|
95
|
-
const { all } = useLayoutStyle(rest);
|
|
96
|
-
const innerStyle = withPropsStyle(all, style);
|
|
97
|
-
|
|
98
|
-
return (
|
|
99
|
-
<form
|
|
100
|
-
{...rest}
|
|
101
|
-
ref={innerRef}
|
|
102
|
-
style={innerStyle}
|
|
103
|
-
onReset={(e) => {
|
|
104
|
-
// browser would empty all fields to their default values (likely empty/unchecked)
|
|
105
|
-
// we want to reset to the last known external state instead
|
|
106
|
-
e.preventDefault();
|
|
107
|
-
uiStateController.resetUIState(e);
|
|
108
|
-
}}
|
|
109
|
-
>
|
|
110
|
-
<ParentUIStateControllerContext.Provider value={uiStateController}>
|
|
111
|
-
<ReadOnlyContext.Provider value={innerReadOnly}>
|
|
112
|
-
<LoadingContext.Provider value={loading}>
|
|
113
|
-
<FormContext.Provider value={formContextValue}>
|
|
114
|
-
{children}
|
|
115
|
-
</FormContext.Provider>
|
|
116
|
-
</LoadingContext.Provider>
|
|
117
|
-
</ReadOnlyContext.Provider>
|
|
118
|
-
</ParentUIStateControllerContext.Provider>
|
|
119
|
-
</form>
|
|
120
|
-
);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
const FormWithAction = forwardRef((props, ref) => {
|
|
124
|
-
const uiStateController = useContext(UIStateControllerContext);
|
|
125
|
-
const uiState = useContext(UIStateContext);
|
|
126
|
-
const {
|
|
127
|
-
action,
|
|
128
|
-
method,
|
|
129
|
-
actionErrorEffect = "show_validation_message", // "show_validation_message" or "throw"
|
|
130
|
-
errorMapping,
|
|
131
|
-
onActionPrevented,
|
|
132
|
-
onActionStart,
|
|
133
|
-
onActionAbort,
|
|
134
|
-
onActionError,
|
|
135
|
-
onActionEnd,
|
|
136
|
-
loading,
|
|
137
|
-
children,
|
|
138
|
-
...rest
|
|
139
|
-
} = props;
|
|
140
|
-
const innerRef = useRef();
|
|
141
|
-
useImperativeHandle(ref, () => innerRef.current);
|
|
142
|
-
const [actionBoundToUIState] = useActionBoundToOneParam(action, uiState);
|
|
143
|
-
const executeAction = useExecuteAction(innerRef, {
|
|
144
|
-
errorEffect: actionErrorEffect,
|
|
145
|
-
errorMapping,
|
|
146
|
-
});
|
|
147
|
-
const { actionPending, actionRequester: formActionRequester } =
|
|
148
|
-
useRequestedActionStatus(innerRef);
|
|
149
|
-
|
|
150
|
-
useActionEvents(innerRef, {
|
|
151
|
-
onPrevented: onActionPrevented,
|
|
152
|
-
onRequested: (e) => {
|
|
153
|
-
forwardActionRequested(e, actionBoundToUIState);
|
|
154
|
-
},
|
|
155
|
-
onAction: (e) => {
|
|
156
|
-
const form = innerRef.current;
|
|
157
|
-
const formElementValues = collectFormElementValues(form);
|
|
158
|
-
uiStateController.setUIState(formElementValues, e);
|
|
159
|
-
executeAction(e);
|
|
160
|
-
},
|
|
161
|
-
onStart: onActionStart,
|
|
162
|
-
onAbort: (e) => {
|
|
163
|
-
// user might want to re-submit as is
|
|
164
|
-
// or change the ui state before re-submitting
|
|
165
|
-
// we can't decide for him
|
|
166
|
-
onActionAbort?.(e);
|
|
167
|
-
},
|
|
168
|
-
onError: (e) => {
|
|
169
|
-
// user might want to re-submit as is
|
|
170
|
-
// or change the ui state before re-submitting
|
|
171
|
-
// we can't decide for him
|
|
172
|
-
onActionError?.(e);
|
|
173
|
-
},
|
|
174
|
-
onEnd: (e) => {
|
|
175
|
-
// form side effect is a success
|
|
176
|
-
// we can get rid of the nav state
|
|
177
|
-
// that was keeping the ui state in case user navigates away without submission
|
|
178
|
-
uiStateController.actionEnd(e);
|
|
179
|
-
onActionEnd?.(e);
|
|
180
|
-
},
|
|
181
|
-
});
|
|
182
|
-
const innerLoading = loading || actionPending;
|
|
183
|
-
|
|
184
|
-
return (
|
|
185
|
-
<FormBasic
|
|
186
|
-
data-action={actionBoundToUIState.name}
|
|
187
|
-
data-method={action.meta?.httpVerb || method || "GET"}
|
|
188
|
-
{...rest}
|
|
189
|
-
ref={innerRef}
|
|
190
|
-
loading={innerLoading}
|
|
191
|
-
>
|
|
192
|
-
<FormActionContext.Provider value={actionBoundToUIState}>
|
|
193
|
-
<LoadingElementContext.Provider value={formActionRequester}>
|
|
194
|
-
{children}
|
|
195
|
-
</LoadingElementContext.Provider>
|
|
196
|
-
</FormActionContext.Provider>
|
|
197
|
-
</FormBasic>
|
|
198
|
-
);
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
// const dispatchCustomEventOnFormAndFormElements = (type, options) => {
|
|
202
|
-
// const form = innerRef.current;
|
|
203
|
-
// const customEvent = new CustomEvent(type, options);
|
|
204
|
-
// // https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/elements
|
|
205
|
-
// for (const element of form.elements) {
|
|
206
|
-
// element.dispatchEvent(customEvent);
|
|
207
|
-
// }
|
|
208
|
-
// form.dispatchEvent(customEvent);
|
|
209
|
-
// };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { forwardRef } from "preact/compat";
|
|
2
|
-
|
|
3
|
-
import { InputCheckbox } from "./input_checkbox.jsx";
|
|
4
|
-
import { InputRadio } from "./input_radio.jsx";
|
|
5
|
-
import { InputTextual } from "./input_textual.jsx";
|
|
6
|
-
|
|
7
|
-
export const Input = forwardRef((props, ref) => {
|
|
8
|
-
const { type } = props;
|
|
9
|
-
if (type === "radio") {
|
|
10
|
-
return <InputRadio {...props} ref={ref} />;
|
|
11
|
-
}
|
|
12
|
-
if (type === "checkbox") {
|
|
13
|
-
return <InputCheckbox {...props} ref={ref} />;
|
|
14
|
-
}
|
|
15
|
-
return <InputTextual {...props} ref={ref} />;
|
|
16
|
-
});
|