@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.
Files changed (207) hide show
  1. package/dist/jsenv_navi.js +13858 -23295
  2. package/dist/jsenv_navi.js.map +1281 -0
  3. package/package.json +5 -7
  4. package/index.js +0 -122
  5. package/src/action_private_properties.js +0 -11
  6. package/src/action_proxy_test.html +0 -353
  7. package/src/action_run_states.js +0 -5
  8. package/src/actions.js +0 -1401
  9. package/src/browser_integration/browser_integration.js +0 -216
  10. package/src/browser_integration/document_back_and_forward.js +0 -17
  11. package/src/browser_integration/document_loading_signal.js +0 -100
  12. package/src/browser_integration/document_state_signal.js +0 -9
  13. package/src/browser_integration/document_url_signal.js +0 -9
  14. package/src/browser_integration/use_is_visited.js +0 -19
  15. package/src/browser_integration/via_history.js +0 -232
  16. package/src/browser_integration/via_navigation.js +0 -168
  17. package/src/components/action_execution/form_context.js +0 -5
  18. package/src/components/action_execution/render_actionable_component.jsx +0 -29
  19. package/src/components/action_execution/use_action.js +0 -99
  20. package/src/components/action_execution/use_execute_action.js +0 -177
  21. package/src/components/action_execution/use_run_on_mount.js +0 -9
  22. package/src/components/action_renderer.jsx +0 -125
  23. package/src/components/callout/callout.js +0 -990
  24. package/src/components/callout/callout_demo.html +0 -201
  25. package/src/components/callout/test_dynamic_positioning.html +0 -161
  26. package/src/components/callout/test_html_document_iframe.html +0 -182
  27. package/src/components/demos/0_button_demo.html +0 -707
  28. package/src/components/demos/10_column_reordering_debug.html +0 -277
  29. package/src/components/demos/11_table_selection_debug.html +0 -432
  30. package/src/components/demos/1_checkbox_demo.html +0 -754
  31. package/src/components/demos/2_input_textual_demo.html +0 -286
  32. package/src/components/demos/3_radio_demo.html +0 -874
  33. package/src/components/demos/4_select_demo.html +0 -100
  34. package/src/components/demos/5_list_scrollable_demo.html +0 -153
  35. package/src/components/demos/6_tablist_demo.html +0 -77
  36. package/src/components/demos/7_table_selection_demo.html +0 -176
  37. package/src/components/demos/8_table_fixed_headers_demo.html +0 -584
  38. package/src/components/demos/9_table_column_drag_demo.html +0 -325
  39. package/src/components/demos/action/0_button_demo.html +0 -204
  40. package/src/components/demos/action/10_shortcuts_demo.html +0 -189
  41. package/src/components/demos/action/11_nested_shortcuts_demo.xhtml +0 -401
  42. package/src/components/demos/action/1_input_text_demo.html +0 -876
  43. package/src/components/demos/action/2_form_multiple.html +0 -303
  44. package/src/components/demos/action/3_details_demo.html +0 -203
  45. package/src/components/demos/action/4_input_checkbox_demo.html +0 -731
  46. package/src/components/demos/action/5_input_checkbox_state_demo.html +0 -270
  47. package/src/components/demos/action/6_checkbox_list_demo.html +0 -341
  48. package/src/components/demos/action/7_radio_list_demo.html +0 -357
  49. package/src/components/demos/action/8_editable_demo.html +0 -431
  50. package/src/components/demos/action/9_link_demo.html +0 -194
  51. package/src/components/demos/demo.md +0 -0
  52. package/src/components/demos/route/basic/basic.html +0 -14
  53. package/src/components/demos/route/basic/basic_route_demo.jsx +0 -224
  54. package/src/components/demos/route/multi/multi.html +0 -14
  55. package/src/components/demos/route/multi/multi_route_demo.jsx +0 -277
  56. package/src/components/demos/ui_transition/0_action_renderer_ui_transition_demo.html +0 -695
  57. package/src/components/demos/ui_transition/1_nested_ui_transition_demo.html +0 -429
  58. package/src/components/demos/ui_transition/2_height_transition_test.html +0 -295
  59. package/src/components/details/details.jsx +0 -245
  60. package/src/components/details/summary_marker.jsx +0 -141
  61. package/src/components/edition/editable.jsx +0 -186
  62. package/src/components/error_boundary_context.js +0 -9
  63. package/src/components/field/README.md +0 -247
  64. package/src/components/field/button.jsx +0 -429
  65. package/src/components/field/checkbox_list.jsx +0 -185
  66. package/src/components/field/collect_form_element_values.js +0 -82
  67. package/src/components/field/custom_field.js +0 -106
  68. package/src/components/field/form.jsx +0 -209
  69. package/src/components/field/input.jsx +0 -16
  70. package/src/components/field/input_checkbox.jsx +0 -434
  71. package/src/components/field/input_radio.jsx +0 -432
  72. package/src/components/field/input_textual.jsx +0 -389
  73. package/src/components/field/label.jsx +0 -46
  74. package/src/components/field/radio_list.jsx +0 -183
  75. package/src/components/field/select.jsx +0 -256
  76. package/src/components/field/use_action_events.js +0 -132
  77. package/src/components/field/use_form_events.js +0 -59
  78. package/src/components/field/use_ui_state_controller.js +0 -506
  79. package/src/components/item_tracker/README.md +0 -461
  80. package/src/components/item_tracker/use_isolated_item_tracker.jsx +0 -209
  81. package/src/components/item_tracker/use_isolated_item_tracker_demo.html +0 -148
  82. package/src/components/item_tracker/use_isolated_item_tracker_demo.jsx +0 -460
  83. package/src/components/item_tracker/use_item_tracker.jsx +0 -143
  84. package/src/components/item_tracker/use_item_tracker_demo.html +0 -207
  85. package/src/components/item_tracker/use_item_tracker_demo.jsx +0 -216
  86. package/src/components/keyboard_shortcuts/active_keyboard_shortcuts.jsx +0 -87
  87. package/src/components/keyboard_shortcuts/aria_key_shortcuts.js +0 -61
  88. package/src/components/keyboard_shortcuts/keyboard_key_meta.js +0 -17
  89. package/src/components/keyboard_shortcuts/keyboard_shortcuts.js +0 -371
  90. package/src/components/keyboard_shortcuts/os.js +0 -9
  91. package/src/components/layout/demos/demo_flex.html +0 -638
  92. package/src/components/layout/demos/demo_layout_style_buttons.html +0 -351
  93. package/src/components/layout/demos/demo_layout_style_input.html +0 -226
  94. package/src/components/layout/demos/demo_layout_style_text.html +0 -514
  95. package/src/components/layout/flex.jsx +0 -109
  96. package/src/components/layout/layout_context.jsx +0 -3
  97. package/src/components/layout/spacing.jsx +0 -20
  98. package/src/components/layout/use_layout_style.js +0 -249
  99. package/src/components/link/link.jsx +0 -267
  100. package/src/components/link/link_with_icon.jsx +0 -52
  101. package/src/components/loader/loader_background.jsx +0 -372
  102. package/src/components/loader/loading_spinner.jsx +0 -68
  103. package/src/components/loader/network_speed.js +0 -83
  104. package/src/components/loader/rectangle_loading.jsx +0 -244
  105. package/src/components/props_composition/demos/demo_with_props_style.html +0 -81
  106. package/src/components/props_composition/with_props_class_name.js +0 -37
  107. package/src/components/props_composition/with_props_style.js +0 -26
  108. package/src/components/route.jsx +0 -19
  109. package/src/components/selection/selection.jsx +0 -1583
  110. package/src/components/svg/font_sized_svg.jsx +0 -59
  111. package/src/components/svg/icon_and_text.jsx +0 -21
  112. package/src/components/svg/svg_mask_overlay.jsx +0 -105
  113. package/src/components/table/drag/table_drag.jsx +0 -506
  114. package/src/components/table/resize/table_resize.jsx +0 -650
  115. package/src/components/table/resize/table_size.js +0 -43
  116. package/src/components/table/selection/table_selection.js +0 -106
  117. package/src/components/table/selection/table_selection.jsx +0 -203
  118. package/src/components/table/sticky/sticky_group.js +0 -354
  119. package/src/components/table/sticky/table_sticky.js +0 -25
  120. package/src/components/table/sticky/table_sticky.jsx +0 -501
  121. package/src/components/table/table.jsx +0 -721
  122. package/src/components/table/table_css.js +0 -211
  123. package/src/components/table/table_ui.jsx +0 -49
  124. package/src/components/table/use_cells_and_columns.js +0 -90
  125. package/src/components/table/use_object_array_to_cells.js +0 -46
  126. package/src/components/table/z_indexes.js +0 -23
  127. package/src/components/tablist/tablist.jsx +0 -99
  128. package/src/components/text/demos/demo_text_and_icon.html +0 -421
  129. package/src/components/text/overflow.jsx +0 -15
  130. package/src/components/text/text.jsx +0 -83
  131. package/src/components/text/text_and_count.jsx +0 -28
  132. package/src/components/ui_transition.jsx +0 -128
  133. package/src/components/use_auto_focus.js +0 -94
  134. package/src/components/use_batch_during_render.js +0 -33
  135. package/src/components/use_debounce_true.js +0 -31
  136. package/src/components/use_dependencies_diff.js +0 -35
  137. package/src/components/use_focus_group.js +0 -20
  138. package/src/components/use_initial_value.js +0 -78
  139. package/src/components/use_is_visited.js +0 -19
  140. package/src/components/use_ref_array.js +0 -38
  141. package/src/components/use_signal_sync.js +0 -50
  142. package/src/components/use_stable_callback.js +0 -68
  143. package/src/components/use_state_array.js +0 -47
  144. package/src/docs/actions.md +0 -250
  145. package/src/docs/demos/resource/action_status.jsx +0 -42
  146. package/src/docs/demos/resource/demo.md +0 -1
  147. package/src/docs/demos/resource/resource_demo_0.html +0 -84
  148. package/src/docs/demos/resource/resource_demo_10_post_gc.html +0 -364
  149. package/src/docs/demos/resource/resource_demo_11_describe_many.html +0 -362
  150. package/src/docs/demos/resource/resource_demo_2.html +0 -173
  151. package/src/docs/demos/resource/resource_demo_3_filtered_users.html +0 -415
  152. package/src/docs/demos/resource/resource_demo_4_details.html +0 -284
  153. package/src/docs/demos/resource/resource_demo_5_renderer_lazy.html +0 -115
  154. package/src/docs/demos/resource/resource_demo_6_gc.html +0 -217
  155. package/src/docs/demos/resource/resource_demo_7_child_gc.html +0 -240
  156. package/src/docs/demos/resource/resource_demo_8_proxy_gc.html +0 -319
  157. package/src/docs/demos/resource/resource_demo_9_describe_one.html +0 -472
  158. package/src/docs/demos/resource/tata.jsx +0 -3
  159. package/src/docs/demos/resource/toto.jsx +0 -3
  160. package/src/docs/demos/user_nav/user_nav.html +0 -12
  161. package/src/docs/demos/user_nav/user_nav.jsx +0 -330
  162. package/src/docs/resource_dependencies.md +0 -103
  163. package/src/docs/resource_with_params.md +0 -80
  164. package/src/navi_css_vars.js +0 -14
  165. package/src/notes.md +0 -34
  166. package/src/route/route.js +0 -596
  167. package/src/route/route.xtest.html +0 -228
  168. package/src/store/array_signal_store.js +0 -537
  169. package/src/store/local_storage_signal.js +0 -17
  170. package/src/store/resource_graph.js +0 -1304
  171. package/src/store/tests/resource_graph_autoreload_demo.html +0 -12
  172. package/src/store/tests/resource_graph_autoreload_demo.jsx +0 -964
  173. package/src/store/tests/resource_graph_dependencies.test_manual.js +0 -95
  174. package/src/store/value_in_local_storage.js +0 -187
  175. package/src/symbol_object_signal.js +0 -1
  176. package/src/use_action_data.js +0 -10
  177. package/src/use_action_status.js +0 -47
  178. package/src/utils/add_many_event_listeners.js +0 -15
  179. package/src/utils/array_add_remove.js +0 -61
  180. package/src/utils/array_signal.js +0 -15
  181. package/src/utils/compare_two_js_values.js +0 -172
  182. package/src/utils/execute_with_cleanup.js +0 -21
  183. package/src/utils/get_caller_info.js +0 -85
  184. package/src/utils/is_signal.js +0 -20
  185. package/src/utils/js_value_weak_map.js +0 -162
  186. package/src/utils/js_value_weak_map_demo.html +0 -690
  187. package/src/utils/merge_two_js_values.js +0 -53
  188. package/src/utils/stringify_for_display.js +0 -131
  189. package/src/utils/weak_effect.js +0 -48
  190. package/src/validation/constraints/confirm_constraint.js +0 -14
  191. package/src/validation/constraints/create_unique_value_constraint.js +0 -27
  192. package/src/validation/constraints/native_constraints.js +0 -338
  193. package/src/validation/constraints/readonly_constraint.js +0 -41
  194. package/src/validation/constraints/same_as_constraint.js +0 -42
  195. package/src/validation/constraints/single_space_constraint.js +0 -13
  196. package/src/validation/custom_constraint_validation.js +0 -793
  197. package/src/validation/custom_message.js +0 -18
  198. package/src/validation/demos/browser_style.png +0 -0
  199. package/src/validation/demos/demo_same_as_constraint.html +0 -259
  200. package/src/validation/demos/form_validation_demo.html +0 -142
  201. package/src/validation/demos/form_validation_demo_preact.html +0 -87
  202. package/src/validation/demos/form_validation_native_popover_demo.html +0 -168
  203. package/src/validation/demos/form_validation_vs_native_demo.html +0 -172
  204. package/src/validation/hooks/use_constraints.js +0 -23
  205. package/src/validation/hooks/use_custom_validation_ref.js +0 -73
  206. package/src/validation/hooks/use_validation_message.js +0 -19
  207. package/src/validation/input_change_effect.js +0 -106
@@ -1,429 +0,0 @@
1
- import { forwardRef } from "preact/compat";
2
- import {
3
- useContext,
4
- useImperativeHandle,
5
- useLayoutEffect,
6
- useRef,
7
- } from "preact/hooks";
8
-
9
- import { getActionPrivateProperties } from "../../action_private_properties.js";
10
- import { useActionStatus } from "../../use_action_status.js";
11
- import { forwardActionRequested } from "../../validation/custom_constraint_validation.js";
12
- import { useConstraints } from "../../validation/hooks/use_constraints.js";
13
- import { FormActionContext } from "../action_execution/form_context.js";
14
- import { renderActionableComponent } from "../action_execution/render_actionable_component.jsx";
15
- import { useAction } from "../action_execution/use_action.js";
16
- import { useExecuteAction } from "../action_execution/use_execute_action.js";
17
- import { useLayoutStyle } from "../layout/use_layout_style.js";
18
- import { LoaderBackground } from "../loader/loader_background.jsx";
19
- import { withPropsClassName } from "../props_composition/with_props_class_name.js";
20
- import { withPropsStyle } from "../props_composition/with_props_style.js";
21
- import { useAutoFocus } from "../use_auto_focus.js";
22
- import { initCustomField } from "./custom_field.js";
23
- import { useActionEvents } from "./use_action_events.js";
24
- import { useFormEvents } from "./use_form_events.js";
25
- import {
26
- DisabledContext,
27
- LoadingContext,
28
- LoadingElementContext,
29
- ReadOnlyContext,
30
- } from "./use_ui_state_controller.js";
31
-
32
- /**
33
- * We need a content the visually shrink (scale down) but the button interactive are must remain intact
34
- * Otherwise a click on the edges of the button cannot not trigger the click event (mouseup occurs outside the button)
35
- **/
36
-
37
- /**
38
- * We have to re-define the CSS of button because getComputedStyle(button).borderColor returns
39
- * rgb(0, 0, 0) while being visually grey in chrome
40
- * So we redefine chrome styles so that loader can keep up with the actual color visible to the user
41
- */
42
- import.meta.css = /* css */ `
43
- @layer navi {
44
- .navi_button {
45
- position: relative;
46
- display: inline-flex;
47
- width: fit-content;
48
- height: fit-content;
49
- padding: 0;
50
- background: none;
51
- border: none;
52
- border-radius: inherit;
53
- outline: none;
54
- cursor: pointer;
55
-
56
- --border-width: 1px;
57
- --outline-width: 1px;
58
- --outer-width: calc(var(--border-width) + var(--outline-width));
59
- --padding-x: 6px;
60
- --padding-y: 1px;
61
-
62
- --outline-color: light-dark(#4476ff, #3b82f6);
63
-
64
- --border-radius: 2px;
65
- --border-color: light-dark(#767676, #8e8e93);
66
- --border-color-hover: color-mix(in srgb, var(--border-color) 70%, black);
67
- --border-color-active: color-mix(in srgb, var(--border-color) 90%, black);
68
- --border-color-readonly: color-mix(
69
- in srgb,
70
- var(--border-color) 30%,
71
- white
72
- );
73
- --border-color-disabled: var(--border-color-readonly);
74
-
75
- --background-color: light-dark(#f3f4f6, #2d3748);
76
- --background-color-hover: color-mix(
77
- in srgb,
78
- var(--background-color) 95%,
79
- black
80
- );
81
- --background-color-readonly: var(--background-color);
82
- --background-color-disabled: var(--background-color);
83
-
84
- --color: currentColor;
85
- --color-readonly: color-mix(in srgb, currentColor 30%, transparent);
86
- --color-disabled: var(--color-readonly);
87
- }
88
- .navi_button_content {
89
- position: relative;
90
- display: inline-flex;
91
- width: 100%;
92
- padding-top: var(--padding-y);
93
- padding-right: var(--padding-x);
94
- padding-bottom: var(--padding-y);
95
- padding-left: var(--padding-x);
96
- color: var(--color);
97
- background-color: var(--background-color);
98
- border-width: var(--outer-width);
99
- border-style: solid;
100
- border-color: transparent;
101
- border-radius: var(--border-radius);
102
- outline-width: var(--border-width);
103
- outline-style: solid;
104
- outline-color: var(--border-color);
105
- outline-offset: calc(-1 * (var(--border-width)));
106
- transition-property: transform;
107
- transition-duration: 0.15s;
108
- transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
109
- }
110
- .navi_button_shadow {
111
- position: absolute;
112
- inset: calc(-1 * var(--outer-width));
113
- border-radius: inherit;
114
- pointer-events: none;
115
- }
116
- /* Focus */
117
- .navi_button[data-focus-visible] .navi_button_content {
118
- --border-color: var(--outline-color);
119
- outline-width: var(--outer-width);
120
- outline-offset: calc(-1 * var(--outer-width));
121
- }
122
- /* Hover */
123
- .navi_button[data-hover] .navi_button_content {
124
- --border-color: var(--border-color-hover);
125
- --background-color: var(--background-color-hover);
126
- }
127
- /* Active */
128
- .navi_button[data-active] .navi_button_content {
129
- --outline-color: var(--border-color-active);
130
- transform: scale(0.9);
131
- }
132
- .navi_button[data-active] .navi_button_shadow {
133
- box-shadow:
134
- inset 0 3px 6px rgba(0, 0, 0, 0.2),
135
- inset 0 1px 2px rgba(0, 0, 0, 0.3),
136
- inset 0 0 0 1px rgba(0, 0, 0, 0.1),
137
- inset 2px 0 4px rgba(0, 0, 0, 0.1),
138
- inset -2px 0 4px rgba(0, 0, 0, 0.1);
139
- }
140
- /* Readonly */
141
- .navi_button[data-readonly] .navi_button_content {
142
- --border-color: var(--border-color-disabled);
143
- --outline-color: var(--border-color-readonly);
144
- --background-color: var(--background-color-readonly);
145
- --color: var(--color-readonly);
146
- }
147
- /* Disabled */
148
- .navi_button[data-disabled] {
149
- cursor: default;
150
- }
151
- .navi_button[data-disabled] .navi_button_content {
152
- --border-color: var(--border-color-disabled);
153
- --background-color: var(--background-color-disabled);
154
- --color: var(--color-disabled);
155
- transform: none; /* no active effect */
156
- }
157
- .navi_button[data-disabled] .navi_button_shadow {
158
- box-shadow: none;
159
- }
160
- /* Callout (info, warning, error) */
161
- .navi_button[data-callout] .navi_button_content {
162
- --border-color: var(--callout-color);
163
- }
164
-
165
- /* Discrete variant */
166
- .navi_button[data-discrete] .navi_button_content {
167
- --background-color: transparent;
168
- --border-color: transparent;
169
- }
170
- .navi_button[data-discrete][data-hover] .navi_button_content {
171
- --border-color: var(--border-color-hover);
172
- }
173
- .navi_button[data-discrete][data-readonly] .navi_button_content {
174
- --border-color: transparent;
175
- }
176
- .navi_button[data-discrete][data-disabled] .navi_button_content {
177
- --border-color: transparent;
178
- }
179
- button[data-discrete] {
180
- background-color: transparent;
181
- border-color: transparent;
182
- }
183
- button[data-discrete]:hover {
184
- border-color: revert;
185
- }
186
- button[data-discrete][data-readonly],
187
- button[data-discrete][data-disabled] {
188
- border-color: transparent;
189
- }
190
- }
191
- `;
192
- export const Button = forwardRef((props, ref) => {
193
- return renderActionableComponent(props, ref, {
194
- Basic: ButtonBasic,
195
- WithAction: ButtonWithAction,
196
- InsideForm: ButtonInsideForm,
197
- WithActionInsideForm: ButtonWithActionInsideForm,
198
- });
199
- });
200
-
201
- const ButtonBasic = forwardRef((props, ref) => {
202
- const contextLoading = useContext(LoadingContext);
203
- const contextLoadingElement = useContext(LoadingElementContext);
204
- const contextReadOnly = useContext(ReadOnlyContext);
205
- const contextDisabled = useContext(DisabledContext);
206
- const {
207
- readOnly,
208
- disabled,
209
- loading,
210
- constraints = [],
211
- autoFocus,
212
-
213
- // visual
214
- appearance = "navi",
215
- discrete,
216
- className,
217
- style,
218
-
219
- children,
220
- ...rest
221
- } = props;
222
- const innerRef = useRef();
223
- useImperativeHandle(ref, () => innerRef.current);
224
-
225
- useAutoFocus(innerRef, autoFocus);
226
- useConstraints(innerRef, constraints);
227
- const innerLoading =
228
- loading || (contextLoading && contextLoadingElement === innerRef.current);
229
- const innerReadOnly = readOnly || contextReadOnly || innerLoading;
230
- const innerDisabled = disabled || contextDisabled;
231
-
232
- let buttonChildren;
233
- if (appearance === "navi") {
234
- buttonChildren = <NaviButton buttonRef={innerRef}>{children}</NaviButton>;
235
- } else {
236
- buttonChildren = children;
237
- }
238
-
239
- const innerClassName = withPropsClassName(
240
- appearance === "navi" ? "navi_button" : undefined,
241
- className,
242
- );
243
- const { all } = useLayoutStyle(rest);
244
- const innerStyle = withPropsStyle(all, style);
245
-
246
- return (
247
- <button
248
- {...rest}
249
- ref={innerRef}
250
- className={innerClassName}
251
- style={innerStyle}
252
- disabled={innerDisabled}
253
- data-discrete={discrete ? "" : undefined}
254
- data-readonly={innerReadOnly ? "" : undefined}
255
- data-readonly-silent={innerLoading ? "" : undefined}
256
- data-disabled={innerDisabled ? "" : undefined}
257
- data-callout-arrow-x="center"
258
- aria-busy={innerLoading}
259
- >
260
- <LoaderBackground
261
- loading={innerLoading}
262
- inset={-1}
263
- color="light-dark(#355fcc, #3b82f6)"
264
- >
265
- {buttonChildren}
266
- </LoaderBackground>
267
- </button>
268
- );
269
- });
270
- const NaviButton = ({ buttonRef, children }) => {
271
- const ref = useRef();
272
- useLayoutEffect(() => {
273
- return initCustomField(buttonRef.current, buttonRef.current);
274
- }, []);
275
-
276
- return (
277
- <span ref={ref} className="navi_button_content">
278
- {children}
279
- <span className="navi_button_shadow"></span>
280
- </span>
281
- );
282
- };
283
-
284
- const ButtonWithAction = forwardRef((props, ref) => {
285
- const {
286
- action,
287
- loading,
288
- actionErrorEffect,
289
- onActionPrevented,
290
- onActionStart,
291
- onActionError,
292
- onActionEnd,
293
- children,
294
- ...rest
295
- } = props;
296
- const innerRef = useRef();
297
- useImperativeHandle(ref, () => innerRef.current);
298
- const boundAction = useAction(action);
299
- const { loading: actionLoading } = useActionStatus(boundAction);
300
- const executeAction = useExecuteAction(innerRef, {
301
- errorEffect: actionErrorEffect,
302
- });
303
-
304
- const innerLoading = loading || actionLoading;
305
-
306
- useActionEvents(innerRef, {
307
- onPrevented: onActionPrevented,
308
- onRequested: (e) => forwardActionRequested(e, boundAction),
309
- onAction: executeAction,
310
- onStart: onActionStart,
311
- onError: onActionError,
312
- onEnd: onActionEnd,
313
- });
314
-
315
- return (
316
- <ButtonBasic
317
- // put data-action first to help find it in devtools
318
- data-action={boundAction.name}
319
- {...rest}
320
- ref={innerRef}
321
- loading={innerLoading}
322
- >
323
- {children}
324
- </ButtonBasic>
325
- );
326
- });
327
-
328
- const ButtonInsideForm = forwardRef((props, ref) => {
329
- const {
330
- // eslint-disable-next-line no-unused-vars
331
- formContext,
332
- type,
333
- children,
334
- loading,
335
- readOnly,
336
- ...rest
337
- } = props;
338
- const innerRef = useRef();
339
- useImperativeHandle(ref, () => innerRef.current);
340
-
341
- const innerLoading = loading;
342
- const innerReadOnly = readOnly;
343
-
344
- return (
345
- <ButtonBasic
346
- {...rest}
347
- ref={innerRef}
348
- type={type}
349
- loading={innerLoading}
350
- readOnly={innerReadOnly}
351
- >
352
- {children}
353
- </ButtonBasic>
354
- );
355
- });
356
-
357
- const ButtonWithActionInsideForm = forwardRef((props, ref) => {
358
- const formAction = useContext(FormActionContext);
359
- const {
360
- // eslint-disable-next-line no-unused-vars
361
- formContext, // to avoid passing it to the button element
362
- type,
363
- action,
364
- loading,
365
- children,
366
- onActionPrevented,
367
- onActionStart,
368
- onActionAbort,
369
- onActionError,
370
- onActionEnd,
371
- ...rest
372
- } = props;
373
- const hasEffectOnForm =
374
- type === "submit" || type === "reset" || type === "image";
375
- if (import.meta.dev && hasEffectOnForm) {
376
- throw new Error(
377
- `<Button type="${type}" /> should not have their own action`,
378
- );
379
- }
380
- const formParamsSignal = getActionPrivateProperties(formAction).paramsSignal;
381
- const innerRef = useRef();
382
- useImperativeHandle(ref, () => innerRef.current);
383
- const actionBoundToFormParams = useAction(action, formParamsSignal);
384
- const { loading: actionLoading } = useActionStatus(actionBoundToFormParams);
385
-
386
- const innerLoading = loading || actionLoading;
387
- useFormEvents(innerRef, {
388
- onFormActionPrevented: (e) => {
389
- if (e.detail.action === actionBoundToFormParams) {
390
- onActionPrevented?.(e);
391
- }
392
- },
393
- onFormActionStart: (e) => {
394
- if (e.detail.action === actionBoundToFormParams) {
395
- onActionStart?.(e);
396
- }
397
- },
398
- onFormActionAbort: (e) => {
399
- if (e.detail.action === actionBoundToFormParams) {
400
- onActionAbort?.(e);
401
- }
402
- },
403
- onFormActionError: (e) => {
404
- if (e.detail.action === actionBoundToFormParams) {
405
- onActionError?.(e.detail.error);
406
- }
407
- },
408
- onFormActionEnd: (e) => {
409
- if (e.detail.action === actionBoundToFormParams) {
410
- onActionEnd?.(e);
411
- }
412
- },
413
- });
414
-
415
- return (
416
- <ButtonBasic
417
- data-action={actionBoundToFormParams.name}
418
- {...rest}
419
- ref={innerRef}
420
- type={type}
421
- loading={innerLoading}
422
- onactionrequested={(e) => {
423
- forwardActionRequested(e, actionBoundToFormParams, e.target.form);
424
- }}
425
- >
426
- {children}
427
- </ButtonBasic>
428
- );
429
- });
@@ -1,185 +0,0 @@
1
- // TOFIX: select in data then reset, it reset to red/blue instead of red/blue/green
2
-
3
- import { forwardRef } from "preact/compat";
4
- import {
5
- useContext,
6
- useImperativeHandle,
7
- useRef,
8
- useState,
9
- } from "preact/hooks";
10
-
11
- import { useActionStatus } from "../../use_action_status.js";
12
- import { requestAction } from "../../validation/custom_constraint_validation.js";
13
- import { renderActionableComponent } from "../action_execution/render_actionable_component.jsx";
14
- import { useActionBoundToOneArrayParam } from "../action_execution/use_action.js";
15
- import { useExecuteAction } from "../action_execution/use_execute_action.js";
16
- import { InputCheckbox } from "./input_checkbox.jsx";
17
- import { useActionEvents } from "./use_action_events.js";
18
- import {
19
- DisabledContext,
20
- FieldNameContext,
21
- LoadingContext,
22
- LoadingElementContext,
23
- ParentUIStateControllerContext,
24
- ReadOnlyContext,
25
- RequiredContext,
26
- UIStateContext,
27
- UIStateControllerContext,
28
- useUIGroupStateController,
29
- useUIState,
30
- } from "./use_ui_state_controller.js";
31
-
32
- import.meta.css = /* css */ `
33
- @layer navi {
34
- .navi_checkbox_list {
35
- display: flex;
36
- flex-direction: column;
37
- }
38
- }
39
- `;
40
-
41
- export const CheckboxList = forwardRef((props, ref) => {
42
- const uiStateController = useUIGroupStateController(props, "checkbox_list", {
43
- childComponentType: "checkbox",
44
- aggregateChildStates: (childUIStateControllers) => {
45
- const values = [];
46
- for (const childUIStateController of childUIStateControllers) {
47
- if (childUIStateController.uiState) {
48
- values.push(childUIStateController.uiState);
49
- }
50
- }
51
- return values.length === 0 ? undefined : values;
52
- },
53
- });
54
- const uiState = useUIState(uiStateController);
55
-
56
- const checkboxList = renderActionableComponent(props, ref, {
57
- Basic: CheckboxListBasic,
58
- WithAction: CheckboxListWithAction,
59
- InsideForm: CheckboxListInsideForm,
60
- });
61
- return (
62
- <UIStateControllerContext.Provider value={uiStateController}>
63
- <UIStateContext.Provider value={uiState}>
64
- {checkboxList}
65
- </UIStateContext.Provider>
66
- </UIStateControllerContext.Provider>
67
- );
68
- });
69
- export const Checkbox = InputCheckbox;
70
-
71
- const CheckboxListBasic = forwardRef((props, ref) => {
72
- const contextReadOnly = useContext(ReadOnlyContext);
73
- const contextDisabled = useContext(DisabledContext);
74
- const contextLoading = useContext(LoadingContext);
75
- const uiStateController = useContext(UIStateControllerContext);
76
- const { name, readOnly, disabled, required, loading, children, ...rest } =
77
- props;
78
- const innerRef = useRef();
79
- useImperativeHandle(ref, () => innerRef.current);
80
-
81
- const innerLoading = loading || contextLoading;
82
- const innerReadOnly =
83
- readOnly || contextReadOnly || innerLoading || uiStateController.readOnly;
84
- const innerDisabled = disabled || contextDisabled;
85
-
86
- return (
87
- <div
88
- {...rest}
89
- ref={innerRef}
90
- name={name}
91
- className="navi_checkbox_list"
92
- data-checkbox-list
93
- // eslint-disable-next-line react/no-unknown-property
94
- onresetuistate={(e) => {
95
- uiStateController.resetUIState(e);
96
- }}
97
- >
98
- <ParentUIStateControllerContext.Provider value={uiStateController}>
99
- <FieldNameContext.Provider value={name}>
100
- <ReadOnlyContext.Provider value={innerReadOnly}>
101
- <DisabledContext.Provider value={innerDisabled}>
102
- <RequiredContext.Provider value={required}>
103
- <LoadingContext.Provider value={innerLoading}>
104
- {children}
105
- </LoadingContext.Provider>
106
- </RequiredContext.Provider>
107
- </DisabledContext.Provider>
108
- </ReadOnlyContext.Provider>
109
- </FieldNameContext.Provider>
110
- </ParentUIStateControllerContext.Provider>
111
- </div>
112
- );
113
- });
114
-
115
- const CheckboxListWithAction = forwardRef((props, ref) => {
116
- const uiStateController = useContext(UIStateControllerContext);
117
- const uiState = useContext(UIStateContext);
118
- const {
119
- action,
120
- actionErrorEffect,
121
- onCancel,
122
- onActionPrevented,
123
- onActionStart,
124
- onActionAbort,
125
- onActionError,
126
- onActionEnd,
127
- loading,
128
- children,
129
- ...rest
130
- } = props;
131
- const innerRef = useRef();
132
- useImperativeHandle(ref, () => innerRef.current);
133
- const [boundAction] = useActionBoundToOneArrayParam(action, uiState);
134
- const { loading: actionLoading } = useActionStatus(boundAction);
135
- const executeAction = useExecuteAction(innerRef, {
136
- errorEffect: actionErrorEffect,
137
- });
138
- const [actionRequester, setActionRequester] = useState(null);
139
-
140
- useActionEvents(innerRef, {
141
- onCancel: (e, reason) => {
142
- uiStateController.resetUIState(e);
143
- onCancel?.(e, reason);
144
- },
145
- onPrevented: onActionPrevented,
146
- onAction: (actionEvent) => {
147
- setActionRequester(actionEvent.detail.requester);
148
- executeAction(actionEvent);
149
- },
150
- onStart: onActionStart,
151
- onAbort: (e) => {
152
- uiStateController.resetUIState(e);
153
- onActionAbort?.(e);
154
- },
155
- onError: (e) => {
156
- uiStateController.resetUIState(e);
157
- onActionError?.(e);
158
- },
159
- onEnd: (e) => {
160
- onActionEnd?.(e);
161
- },
162
- });
163
-
164
- return (
165
- <CheckboxListBasic
166
- data-action={boundAction.name}
167
- {...rest}
168
- ref={innerRef}
169
- onChange={(event) => {
170
- const checkboxList = innerRef.current;
171
- const checkbox = event.target;
172
- requestAction(checkboxList, boundAction, {
173
- event,
174
- requester: checkbox,
175
- });
176
- }}
177
- loading={loading || actionLoading}
178
- >
179
- <LoadingElementContext.Provider value={actionRequester}>
180
- {children}
181
- </LoadingElementContext.Provider>
182
- </CheckboxListBasic>
183
- );
184
- });
185
- const CheckboxListInsideForm = CheckboxListBasic;
@@ -1,82 +0,0 @@
1
- export const collectFormElementValues = (element) => {
2
- let formElements;
3
- if (element.tagName === "FORM") {
4
- formElements = element.elements;
5
- } else {
6
- // fieldset or anything else
7
- formElements = element.querySelectorAll(
8
- "input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button[name]:not([disabled])",
9
- );
10
- }
11
-
12
- const values = {};
13
- const checkboxArrayNameSet = new Set();
14
- for (const formElement of formElements) {
15
- if (formElement.type === "checkbox" && formElement.name) {
16
- const name = formElement.name;
17
- const endsWithBrackets = name.endsWith("[]");
18
- if (endsWithBrackets) {
19
- checkboxArrayNameSet.add(name);
20
- values[name] = [];
21
- continue;
22
- }
23
- const closestDataCheckboxList = formElement.closest(
24
- "[data-checkbox-list]",
25
- );
26
- if (closestDataCheckboxList) {
27
- checkboxArrayNameSet.add(name);
28
- values[name] = [];
29
- }
30
- }
31
- }
32
-
33
- for (const formElement of formElements) {
34
- const name = formElement.name;
35
- if (!name) {
36
- continue;
37
- }
38
- const value = getFormElementValue(formElement);
39
- if (value === undefined) {
40
- continue; // Skip unchecked checkboxes/radios
41
- }
42
- if (formElement.type === "checkbox" && checkboxArrayNameSet.has(name)) {
43
- values[name].push(value);
44
- } else {
45
- values[name] = value;
46
- }
47
- }
48
- return values;
49
- };
50
-
51
- const getFormElementValue = (formElement) => {
52
- const { type, tagName } = formElement;
53
-
54
- if (tagName === "SELECT") {
55
- if (formElement.multiple) {
56
- return Array.from(formElement.selectedOptions, (option) =>
57
- getValue(option),
58
- );
59
- }
60
- return formElement.value;
61
- }
62
-
63
- if (type === "checkbox" || type === "radio") {
64
- return formElement.checked ? getValue(formElement) : undefined;
65
- }
66
-
67
- if (type === "file") {
68
- return formElement.files; // Return FileList for special handling
69
- }
70
-
71
- return getValue(formElement);
72
- };
73
-
74
- const getValue = (formElement) => {
75
- const hasDataValueAttribute = formElement.hasAttribute("data-value");
76
- if (hasDataValueAttribute) {
77
- // happens for "datetime-local" inputs to keep the timezone
78
- // consistent when sending to the server
79
- return formElement.getAttribute("data-value");
80
- }
81
- return formElement.value;
82
- };