@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.
Files changed (207) hide show
  1. package/dist/jsenv_navi.js +13838 -23291
  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 -193
  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,389 +0,0 @@
1
- /**
2
- * Input component for all textual input types.
3
- *
4
- * Supports:
5
- * - text (default)
6
- * - password
7
- * - hidden
8
- * - email
9
- * - url
10
- * - search
11
- * - tel
12
- * - etc.
13
- *
14
- * For non-textual inputs, specialized components will be used:
15
- * - <InputCheckbox /> for type="checkbox"
16
- * - <InputRadio /> for type="radio"
17
- */
18
-
19
- import { forwardRef } from "preact/compat";
20
- import {
21
- useContext,
22
- useImperativeHandle,
23
- useLayoutEffect,
24
- useRef,
25
- } from "preact/hooks";
26
-
27
- import { useActionStatus } from "../../use_action_status.js";
28
- import { forwardActionRequested } from "../../validation/custom_constraint_validation.js";
29
- import { useConstraints } from "../../validation/hooks/use_constraints.js";
30
- import { renderActionableComponent } from "../action_execution/render_actionable_component.jsx";
31
- import { useActionBoundToOneParam } from "../action_execution/use_action.js";
32
- import { useExecuteAction } from "../action_execution/use_execute_action.js";
33
- import { useLayoutStyle } from "../layout/use_layout_style.js";
34
- import { LoadableInlineElement } from "../loader/loader_background.jsx";
35
- import { withPropsClassName } from "../props_composition/with_props_class_name.js";
36
- import { withPropsStyle } from "../props_composition/with_props_style.js";
37
- import { useAutoFocus } from "../use_auto_focus.js";
38
- import { initCustomField } from "./custom_field.js";
39
- import { ReportReadOnlyOnLabelContext } from "./label.jsx";
40
- import { useActionEvents } from "./use_action_events.js";
41
- import {
42
- DisabledContext,
43
- LoadingContext,
44
- LoadingElementContext,
45
- ReadOnlyContext,
46
- UIStateContext,
47
- UIStateControllerContext,
48
- useUIState,
49
- useUIStateController,
50
- } from "./use_ui_state_controller.js";
51
-
52
- import.meta.css = /* css */ `
53
- @layer navi {
54
- .navi_input {
55
- --border-width: 1px;
56
- --outline-width: 1px;
57
- --outer-width: calc(var(--border-width) + var(--outline-width));
58
- --padding-x: 6px;
59
- --padding-y: 1px;
60
-
61
- --outline-color: light-dark(#4476ff, #3b82f6);
62
-
63
- --border-radius: 2px;
64
- --border-color: light-dark(#767676, #8e8e93);
65
- --border-color-hover: color-mix(in srgb, var(--border-color) 70%, black);
66
- --border-color-active: color-mix(in srgb, var(--border-color) 90%, black);
67
- --border-color-readonly: color-mix(
68
- in srgb,
69
- var(--border-color) 45%,
70
- transparent
71
- );
72
- --border-color-disabled: var(--border-color-readonly);
73
-
74
- --background-color: white;
75
- --background-color-hover: color-mix(
76
- in srgb,
77
- var(--background-color) 95%,
78
- black
79
- );
80
- --background-color-readonly: var(--background-color);
81
- --background-color-disabled: color-mix(
82
- in srgb,
83
- var(--background-color) 60%,
84
- transparent
85
- );
86
-
87
- --color: currentColor;
88
- --color-readonly: color-mix(in srgb, currentColor 60%, transparent);
89
- --color-disabled: var(--color-readonly);
90
-
91
- width: 100%;
92
- color: var(--color);
93
-
94
- background-color: var(--background-color);
95
- border-width: var(--outer-width);
96
- border-width: var(--outer-width);
97
- border-style: solid;
98
- border-color: transparent;
99
- border-radius: var(--border-radius);
100
- outline-width: var(--border-width);
101
- outline-style: solid;
102
- outline-color: var(--border-color);
103
- outline-offset: calc(-1 * (var(--border-width)));
104
- }
105
- /* Focus */
106
- .navi_input[data-focus] {
107
- border-color: var(--outline-color);
108
- outline-width: var(--outer-width);
109
- outline-color: var(--outline-color);
110
- outline-offset: calc(-1 * var(--outer-width));
111
- }
112
- /* Readonly */
113
- .navi_input[data-readonly] {
114
- color: var(--color-readonly);
115
- background-color: var(--background-color-readonly);
116
- outline-color: var(--border-color-readonly);
117
- }
118
- .navi_input[data-readonly]::placeholder {
119
- color: var(--color-readonly);
120
- }
121
- /* Disabled */
122
- .navi_input[data-disabled] {
123
- color: var(--color-disabled);
124
- background-color: var(--background-color-disabled);
125
- outline-color: var(--border-color-disabled);
126
- }
127
- /* Callout (info, warning, error) */
128
- .navi_input[data-callout] {
129
- border-color: var(--callout-color);
130
- }
131
- }
132
- `;
133
-
134
- export const InputTextual = forwardRef((props, ref) => {
135
- const uiStateController = useUIStateController(props, "input");
136
- const uiState = useUIState(uiStateController);
137
-
138
- const input = renderActionableComponent(props, ref, {
139
- Basic: InputTextualBasic,
140
- WithAction: InputTextualWithAction,
141
- InsideForm: InputTextualInsideForm,
142
- });
143
- return (
144
- <UIStateControllerContext.Provider value={uiStateController}>
145
- <UIStateContext.Provider value={uiState}>{input}</UIStateContext.Provider>
146
- </UIStateControllerContext.Provider>
147
- );
148
- });
149
-
150
- const InputTextualBasic = forwardRef((props, ref) => {
151
- const contextReadOnly = useContext(ReadOnlyContext);
152
- const contextDisabled = useContext(DisabledContext);
153
- const contextLoading = useContext(LoadingContext);
154
- const contextLoadingElement = useContext(LoadingElementContext);
155
- const reportReadOnlyOnLabel = useContext(ReportReadOnlyOnLabelContext);
156
- const uiStateController = useContext(UIStateControllerContext);
157
- const uiState = useContext(UIStateContext);
158
- const {
159
- type,
160
- onInput,
161
-
162
- readOnly,
163
- disabled,
164
- constraints = [],
165
- loading,
166
-
167
- autoFocus,
168
- autoFocusVisible,
169
- autoSelect,
170
-
171
- // visual
172
- appearance = "navi",
173
- accentColor,
174
- className,
175
- style,
176
-
177
- ...rest
178
- } = props;
179
- const innerRef = useRef();
180
- useImperativeHandle(ref, () => innerRef.current);
181
-
182
- const innerValue =
183
- type === "datetime-local" ? convertToLocalTimezone(uiState) : uiState;
184
- const innerLoading =
185
- loading || (contextLoading && contextLoadingElement === innerRef.current);
186
- const innerReadOnly =
187
- readOnly || contextReadOnly || innerLoading || uiStateController.readOnly;
188
- const innerDisabled = disabled || contextDisabled;
189
- // infom any <label> parent of our readOnly state
190
- reportReadOnlyOnLabel?.(innerReadOnly);
191
- useAutoFocus(innerRef, autoFocus, {
192
- autoFocusVisible,
193
- autoSelect,
194
- });
195
- useConstraints(innerRef, constraints);
196
-
197
- const innerClassName = withPropsClassName(
198
- appearance === "navi" ? "navi_input" : undefined,
199
- className,
200
- );
201
- const { margin, padding, alignment, expansion } = useLayoutStyle(rest);
202
- const innerStyle = withPropsStyle(padding, style);
203
- const inputTextual = (
204
- <input
205
- {...rest}
206
- ref={innerRef}
207
- className={innerClassName}
208
- style={innerStyle}
209
- type={type}
210
- data-value={uiState}
211
- value={innerValue}
212
- readOnly={innerReadOnly}
213
- disabled={innerDisabled}
214
- data-readOnly={innerReadOnly ? "" : undefined}
215
- data-disabled={innerDisabled ? "" : undefined}
216
- onInput={(e) => {
217
- let inputValue;
218
- if (type === "number") {
219
- inputValue = e.target.valueAsNumber;
220
- } else if (type === "datetime-local") {
221
- inputValue = convertToUTCTimezone(e.target.value);
222
- } else {
223
- inputValue = e.target.value;
224
- }
225
- uiStateController.setUIState(inputValue, e);
226
- onInput?.(e);
227
- }}
228
- // eslint-disable-next-line react/no-unknown-property
229
- onresetuistate={(e) => {
230
- uiStateController.resetUIState(e);
231
- }}
232
- // eslint-disable-next-line react/no-unknown-property
233
- onsetuistate={(e) => {
234
- uiStateController.setUIState(e.detail.value, e);
235
- }}
236
- />
237
- );
238
-
239
- useLayoutEffect(() => {
240
- return initCustomField(innerRef.current, innerRef.current);
241
- }, []);
242
-
243
- if (type === "hidden") {
244
- return inputTextual;
245
- }
246
- return (
247
- <LoadableInlineElement
248
- loading={innerLoading}
249
- style={{
250
- ...margin,
251
- ...alignment,
252
- ...expansion,
253
- "--accent-color": accentColor || "light-dark(#355fcc, #4476ff)",
254
- }}
255
- color="var(--accent-color)"
256
- inset={-1}
257
- >
258
- {inputTextual}
259
- </LoadableInlineElement>
260
- );
261
- });
262
-
263
- const InputTextualWithAction = forwardRef((props, ref) => {
264
- const uiState = useContext(UIStateContext);
265
- const {
266
- action,
267
- loading,
268
- onCancel,
269
- onActionPrevented,
270
- onActionStart,
271
- onActionError,
272
- onActionEnd,
273
- cancelOnBlurInvalid,
274
- cancelOnEscape,
275
- actionErrorEffect,
276
- ...rest
277
- } = props;
278
- const innerRef = useRef(null);
279
- useImperativeHandle(ref, () => innerRef.current);
280
- const [boundAction] = useActionBoundToOneParam(action, uiState);
281
- const { loading: actionLoading } = useActionStatus(boundAction);
282
- const executeAction = useExecuteAction(innerRef, {
283
- errorEffect: actionErrorEffect,
284
- });
285
- // here updating the input won't call the associated action
286
- // (user have to blur or press enter for this to happen)
287
- // so we can keep the ui state on cancel/abort/error and let user decide
288
- // to update ui state or retry via blur/enter as is
289
- useActionEvents(innerRef, {
290
- onCancel: (e, reason) => {
291
- if (reason.startsWith("blur_invalid")) {
292
- if (!cancelOnBlurInvalid) {
293
- return;
294
- }
295
- if (
296
- // error prevent cancellation until the user closes it (or something closes it)
297
- e.detail.failedConstraintInfo.level === "error" &&
298
- e.detail.failedConstraintInfo.reportStatus !== "closed"
299
- ) {
300
- return;
301
- }
302
- }
303
- if (reason === "escape_key") {
304
- if (!cancelOnEscape) {
305
- return;
306
- }
307
- }
308
- onCancel?.(e, reason);
309
- },
310
- onRequested: (e) => {
311
- forwardActionRequested(e, boundAction);
312
- },
313
- onPrevented: onActionPrevented,
314
- onAction: executeAction,
315
- onStart: onActionStart,
316
- onError: onActionError,
317
- onEnd: onActionEnd,
318
- });
319
-
320
- return (
321
- <InputTextualBasic
322
- data-action={boundAction.name}
323
- {...rest}
324
- ref={innerRef}
325
- loading={loading || actionLoading}
326
- />
327
- );
328
- });
329
- const InputTextualInsideForm = forwardRef((props, ref) => {
330
- const {
331
- // We destructure formContext to avoid passing it to the underlying input element
332
- // eslint-disable-next-line no-unused-vars
333
- formContext,
334
- ...rest
335
- } = props;
336
-
337
- return <InputTextualBasic {...rest} ref={ref} />;
338
- });
339
-
340
- // As explained in https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input/datetime-local#setting_timezones
341
- // datetime-local does not support timezones
342
- const convertToLocalTimezone = (dateTimeString) => {
343
- const date = new Date(dateTimeString);
344
- // Check if the date is valid
345
- if (isNaN(date.getTime())) {
346
- return dateTimeString;
347
- }
348
-
349
- // Format to YYYY-MM-DDThh:mm:ss
350
- const year = date.getFullYear();
351
- const month = String(date.getMonth() + 1).padStart(2, "0");
352
- const day = String(date.getDate()).padStart(2, "0");
353
- const hours = String(date.getHours()).padStart(2, "0");
354
- const minutes = String(date.getMinutes()).padStart(2, "0");
355
- const seconds = String(date.getSeconds()).padStart(2, "0");
356
-
357
- return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}`;
358
- };
359
- /**
360
- * Converts a datetime string without timezone (local time) to UTC format with 'Z' notation
361
- *
362
- * @param {string} localDateTimeString - Local datetime string without timezone (e.g., "2023-07-15T14:30:00")
363
- * @returns {string} Datetime string in UTC with 'Z' notation (e.g., "2023-07-15T12:30:00Z")
364
- */
365
- const convertToUTCTimezone = (localDateTimeString) => {
366
- if (!localDateTimeString) {
367
- return localDateTimeString;
368
- }
369
-
370
- try {
371
- // Create a Date object using the local time string
372
- // The browser will interpret this as local timezone
373
- const localDate = new Date(localDateTimeString);
374
-
375
- // Check if the date is valid
376
- if (isNaN(localDate.getTime())) {
377
- return localDateTimeString;
378
- }
379
-
380
- // Convert to UTC ISO string
381
- const utcString = localDate.toISOString();
382
-
383
- // Return the UTC string (which includes the 'Z' notation)
384
- return utcString;
385
- } catch (error) {
386
- console.error("Error converting local datetime to UTC:", error);
387
- return localDateTimeString;
388
- }
389
- };
@@ -1,46 +0,0 @@
1
- import { createContext } from "preact";
2
- import { forwardRef } from "preact/compat";
3
- import { useImperativeHandle, useRef, useState } from "preact/hooks";
4
-
5
- import.meta.css = /* css */ `
6
- @layer navi {
7
- label {
8
- cursor: pointer;
9
- }
10
-
11
- label[data-readonly],
12
- label[data-disabled] {
13
- color: rgba(0, 0, 0, 0.5);
14
- cursor: default;
15
- }
16
- }
17
- `;
18
-
19
- export const ReportReadOnlyOnLabelContext = createContext();
20
- export const ReportDisabledOnLabelContext = createContext();
21
-
22
- export const Label = forwardRef((props, ref) => {
23
- const { readOnly, disabled, children, ...rest } = props;
24
- const innerRef = useRef();
25
- useImperativeHandle(ref, () => innerRef.current);
26
-
27
- const [inputReadOnly, setInputReadOnly] = useState(false);
28
- const innerReadOnly = readOnly || inputReadOnly;
29
- const [inputDisabled, setInputDisabled] = useState(false);
30
- const innerDisabled = disabled || inputDisabled;
31
-
32
- return (
33
- <label
34
- ref={innerRef}
35
- data-readonly={innerReadOnly ? "" : undefined}
36
- data-disabled={innerDisabled ? "" : undefined}
37
- {...rest}
38
- >
39
- <ReportReadOnlyOnLabelContext.Provider value={setInputReadOnly}>
40
- <ReportDisabledOnLabelContext.Provider value={setInputDisabled}>
41
- {children}
42
- </ReportDisabledOnLabelContext.Provider>
43
- </ReportReadOnlyOnLabelContext.Provider>
44
- </label>
45
- );
46
- });
@@ -1,183 +0,0 @@
1
- import { forwardRef } from "preact/compat";
2
- import {
3
- useContext,
4
- useImperativeHandle,
5
- useRef,
6
- useState,
7
- } from "preact/hooks";
8
-
9
- import { useActionStatus } from "../../use_action_status.js";
10
- import { requestAction } from "../../validation/custom_constraint_validation.js";
11
- import { renderActionableComponent } from "../action_execution/render_actionable_component.jsx";
12
- import { useActionBoundToOneParam } from "../action_execution/use_action.js";
13
- import { useExecuteAction } from "../action_execution/use_execute_action.js";
14
- import { InputRadio } from "./input_radio.jsx";
15
- import { useActionEvents } from "./use_action_events.js";
16
- import {
17
- DisabledContext,
18
- FieldNameContext,
19
- LoadingContext,
20
- LoadingElementContext,
21
- ParentUIStateControllerContext,
22
- ReadOnlyContext,
23
- RequiredContext,
24
- UIStateContext,
25
- UIStateControllerContext,
26
- useUIGroupStateController,
27
- useUIState,
28
- } from "./use_ui_state_controller.js";
29
-
30
- import.meta.css = /* css */ `
31
- @layer navi {
32
- .navi_radio_list {
33
- display: flex;
34
- flex-direction: column;
35
- }
36
- }
37
- `;
38
-
39
- export const RadioList = forwardRef((props, ref) => {
40
- const uiStateController = useUIGroupStateController(props, "radio_list", {
41
- childComponentType: "radio",
42
- aggregateChildStates: (childUIStateControllers) => {
43
- let activeValue;
44
- for (const childUIStateController of childUIStateControllers) {
45
- if (childUIStateController.uiState) {
46
- activeValue = childUIStateController.uiState;
47
- break;
48
- }
49
- }
50
- return activeValue;
51
- },
52
- });
53
- const uiState = useUIState(uiStateController);
54
- const radioList = renderActionableComponent(props, ref, {
55
- Basic: RadioListBasic,
56
- WithAction: RadioListWithAction,
57
- InsideForm: RadioListInsideForm,
58
- });
59
- return (
60
- <UIStateControllerContext.Provider value={uiStateController}>
61
- <UIStateContext.Provider value={uiState}>
62
- {radioList}
63
- </UIStateContext.Provider>
64
- </UIStateControllerContext.Provider>
65
- );
66
- });
67
- export const Radio = InputRadio;
68
-
69
- const RadioListBasic = forwardRef((props, ref) => {
70
- const contextReadOnly = useContext(ReadOnlyContext);
71
- const contextDisabled = useContext(DisabledContext);
72
- const contextLoading = useContext(LoadingContext);
73
- const uiStateController = useContext(UIStateControllerContext);
74
- const { name, loading, disabled, readOnly, children, required, ...rest } =
75
- props;
76
- const innerRef = useRef();
77
- useImperativeHandle(ref, () => innerRef.current);
78
-
79
- const innerLoading = loading || contextLoading;
80
- const innerReadOnly =
81
- readOnly || contextReadOnly || innerLoading || uiStateController.readOnly;
82
- const innerDisabled = disabled || contextDisabled;
83
-
84
- return (
85
- <div
86
- data-action={rest["data-action"]}
87
- {...rest}
88
- ref={innerRef}
89
- className="navi_radio_list"
90
- data-radio-list
91
- // eslint-disable-next-line react/no-unknown-property
92
- onresetuistate={(e) => {
93
- uiStateController.resetUIState(e);
94
- }}
95
- >
96
- <ParentUIStateControllerContext.Provider value={uiStateController}>
97
- <FieldNameContext.Provider value={name}>
98
- <ReadOnlyContext.Provider value={innerReadOnly}>
99
- <DisabledContext.Provider value={innerDisabled}>
100
- <RequiredContext.Provider value={required}>
101
- <LoadingContext.Provider value={innerLoading}>
102
- {children}
103
- </LoadingContext.Provider>
104
- </RequiredContext.Provider>
105
- </DisabledContext.Provider>
106
- </ReadOnlyContext.Provider>
107
- </FieldNameContext.Provider>
108
- </ParentUIStateControllerContext.Provider>
109
- </div>
110
- );
111
- });
112
- const RadioListWithAction = forwardRef((props, ref) => {
113
- const uiStateController = useContext(UIStateControllerContext);
114
- const uiState = useContext(UIStateContext);
115
- const {
116
- action,
117
-
118
- onCancel,
119
- onActionPrevented,
120
- onActionStart,
121
- onActionAbort,
122
- onActionError,
123
- onActionEnd,
124
- actionErrorEffect,
125
- loading,
126
- children,
127
- ...rest
128
- } = props;
129
- const innerRef = useRef();
130
- useImperativeHandle(ref, () => innerRef.current);
131
- const [boundAction] = useActionBoundToOneParam(action, uiState);
132
- const { loading: actionLoading } = useActionStatus(boundAction);
133
- const executeAction = useExecuteAction(innerRef, {
134
- errorEffect: actionErrorEffect,
135
- });
136
- const [actionRequester, setActionRequester] = useState(null);
137
-
138
- useActionEvents(innerRef, {
139
- onCancel: (e, reason) => {
140
- uiStateController.resetUIState(e);
141
- onCancel?.(e, reason);
142
- },
143
- onPrevented: onActionPrevented,
144
- onAction: (actionEvent) => {
145
- setActionRequester(actionEvent.detail.requester);
146
- executeAction(actionEvent);
147
- },
148
- onStart: onActionStart,
149
- onAbort: (e) => {
150
- uiStateController.resetUIState(e);
151
- onActionAbort?.(e);
152
- },
153
- onError: (e) => {
154
- uiStateController.resetUIState(e);
155
- onActionError?.(e);
156
- },
157
- onEnd: (e) => {
158
- onActionEnd?.(e);
159
- },
160
- });
161
-
162
- return (
163
- <RadioListBasic
164
- data-action={boundAction}
165
- {...rest}
166
- ref={innerRef}
167
- onChange={(e) => {
168
- const radio = e.target;
169
- const radioListContainer = innerRef.current;
170
- requestAction(radioListContainer, boundAction, {
171
- event: e,
172
- requester: radio,
173
- });
174
- }}
175
- loading={loading || actionLoading}
176
- >
177
- <LoadingElementContext.Provider value={actionRequester}>
178
- {children}
179
- </LoadingElementContext.Provider>
180
- </RadioListBasic>
181
- );
182
- });
183
- const RadioListInsideForm = RadioListBasic;