@jsenv/navi 0.10.1 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/jsenv_navi.js +13858 -23295
- package/dist/jsenv_navi.js.map +1281 -0
- package/package.json +5 -7
- package/index.js +0 -122
- package/src/action_private_properties.js +0 -11
- package/src/action_proxy_test.html +0 -353
- package/src/action_run_states.js +0 -5
- package/src/actions.js +0 -1401
- package/src/browser_integration/browser_integration.js +0 -216
- package/src/browser_integration/document_back_and_forward.js +0 -17
- package/src/browser_integration/document_loading_signal.js +0 -100
- package/src/browser_integration/document_state_signal.js +0 -9
- package/src/browser_integration/document_url_signal.js +0 -9
- package/src/browser_integration/use_is_visited.js +0 -19
- package/src/browser_integration/via_history.js +0 -232
- package/src/browser_integration/via_navigation.js +0 -168
- package/src/components/action_execution/form_context.js +0 -5
- package/src/components/action_execution/render_actionable_component.jsx +0 -29
- package/src/components/action_execution/use_action.js +0 -99
- package/src/components/action_execution/use_execute_action.js +0 -177
- package/src/components/action_execution/use_run_on_mount.js +0 -9
- package/src/components/action_renderer.jsx +0 -125
- package/src/components/callout/callout.js +0 -990
- package/src/components/callout/callout_demo.html +0 -201
- package/src/components/callout/test_dynamic_positioning.html +0 -161
- package/src/components/callout/test_html_document_iframe.html +0 -182
- package/src/components/demos/0_button_demo.html +0 -707
- package/src/components/demos/10_column_reordering_debug.html +0 -277
- package/src/components/demos/11_table_selection_debug.html +0 -432
- package/src/components/demos/1_checkbox_demo.html +0 -754
- package/src/components/demos/2_input_textual_demo.html +0 -286
- package/src/components/demos/3_radio_demo.html +0 -874
- package/src/components/demos/4_select_demo.html +0 -100
- package/src/components/demos/5_list_scrollable_demo.html +0 -153
- package/src/components/demos/6_tablist_demo.html +0 -77
- package/src/components/demos/7_table_selection_demo.html +0 -176
- package/src/components/demos/8_table_fixed_headers_demo.html +0 -584
- package/src/components/demos/9_table_column_drag_demo.html +0 -325
- package/src/components/demos/action/0_button_demo.html +0 -204
- package/src/components/demos/action/10_shortcuts_demo.html +0 -189
- package/src/components/demos/action/11_nested_shortcuts_demo.xhtml +0 -401
- package/src/components/demos/action/1_input_text_demo.html +0 -876
- package/src/components/demos/action/2_form_multiple.html +0 -303
- package/src/components/demos/action/3_details_demo.html +0 -203
- package/src/components/demos/action/4_input_checkbox_demo.html +0 -731
- package/src/components/demos/action/5_input_checkbox_state_demo.html +0 -270
- package/src/components/demos/action/6_checkbox_list_demo.html +0 -341
- package/src/components/demos/action/7_radio_list_demo.html +0 -357
- package/src/components/demos/action/8_editable_demo.html +0 -431
- package/src/components/demos/action/9_link_demo.html +0 -194
- package/src/components/demos/demo.md +0 -0
- package/src/components/demos/route/basic/basic.html +0 -14
- package/src/components/demos/route/basic/basic_route_demo.jsx +0 -224
- package/src/components/demos/route/multi/multi.html +0 -14
- package/src/components/demos/route/multi/multi_route_demo.jsx +0 -277
- package/src/components/demos/ui_transition/0_action_renderer_ui_transition_demo.html +0 -695
- package/src/components/demos/ui_transition/1_nested_ui_transition_demo.html +0 -429
- package/src/components/demos/ui_transition/2_height_transition_test.html +0 -295
- package/src/components/details/details.jsx +0 -245
- package/src/components/details/summary_marker.jsx +0 -141
- package/src/components/edition/editable.jsx +0 -186
- package/src/components/error_boundary_context.js +0 -9
- package/src/components/field/README.md +0 -247
- package/src/components/field/button.jsx +0 -429
- package/src/components/field/checkbox_list.jsx +0 -185
- package/src/components/field/collect_form_element_values.js +0 -82
- package/src/components/field/custom_field.js +0 -106
- package/src/components/field/form.jsx +0 -209
- package/src/components/field/input.jsx +0 -16
- package/src/components/field/input_checkbox.jsx +0 -434
- package/src/components/field/input_radio.jsx +0 -432
- package/src/components/field/input_textual.jsx +0 -389
- package/src/components/field/label.jsx +0 -46
- package/src/components/field/radio_list.jsx +0 -183
- package/src/components/field/select.jsx +0 -256
- package/src/components/field/use_action_events.js +0 -132
- package/src/components/field/use_form_events.js +0 -59
- package/src/components/field/use_ui_state_controller.js +0 -506
- package/src/components/item_tracker/README.md +0 -461
- package/src/components/item_tracker/use_isolated_item_tracker.jsx +0 -209
- package/src/components/item_tracker/use_isolated_item_tracker_demo.html +0 -148
- package/src/components/item_tracker/use_isolated_item_tracker_demo.jsx +0 -460
- package/src/components/item_tracker/use_item_tracker.jsx +0 -143
- package/src/components/item_tracker/use_item_tracker_demo.html +0 -207
- package/src/components/item_tracker/use_item_tracker_demo.jsx +0 -216
- package/src/components/keyboard_shortcuts/active_keyboard_shortcuts.jsx +0 -87
- package/src/components/keyboard_shortcuts/aria_key_shortcuts.js +0 -61
- package/src/components/keyboard_shortcuts/keyboard_key_meta.js +0 -17
- package/src/components/keyboard_shortcuts/keyboard_shortcuts.js +0 -371
- package/src/components/keyboard_shortcuts/os.js +0 -9
- package/src/components/layout/demos/demo_flex.html +0 -638
- package/src/components/layout/demos/demo_layout_style_buttons.html +0 -351
- package/src/components/layout/demos/demo_layout_style_input.html +0 -226
- package/src/components/layout/demos/demo_layout_style_text.html +0 -514
- package/src/components/layout/flex.jsx +0 -109
- package/src/components/layout/layout_context.jsx +0 -3
- package/src/components/layout/spacing.jsx +0 -20
- package/src/components/layout/use_layout_style.js +0 -249
- package/src/components/link/link.jsx +0 -267
- package/src/components/link/link_with_icon.jsx +0 -52
- package/src/components/loader/loader_background.jsx +0 -372
- package/src/components/loader/loading_spinner.jsx +0 -68
- package/src/components/loader/network_speed.js +0 -83
- package/src/components/loader/rectangle_loading.jsx +0 -244
- package/src/components/props_composition/demos/demo_with_props_style.html +0 -81
- package/src/components/props_composition/with_props_class_name.js +0 -37
- package/src/components/props_composition/with_props_style.js +0 -26
- package/src/components/route.jsx +0 -19
- package/src/components/selection/selection.jsx +0 -1583
- package/src/components/svg/font_sized_svg.jsx +0 -59
- package/src/components/svg/icon_and_text.jsx +0 -21
- package/src/components/svg/svg_mask_overlay.jsx +0 -105
- package/src/components/table/drag/table_drag.jsx +0 -506
- package/src/components/table/resize/table_resize.jsx +0 -650
- package/src/components/table/resize/table_size.js +0 -43
- package/src/components/table/selection/table_selection.js +0 -106
- package/src/components/table/selection/table_selection.jsx +0 -203
- package/src/components/table/sticky/sticky_group.js +0 -354
- package/src/components/table/sticky/table_sticky.js +0 -25
- package/src/components/table/sticky/table_sticky.jsx +0 -501
- package/src/components/table/table.jsx +0 -721
- package/src/components/table/table_css.js +0 -211
- package/src/components/table/table_ui.jsx +0 -49
- package/src/components/table/use_cells_and_columns.js +0 -90
- package/src/components/table/use_object_array_to_cells.js +0 -46
- package/src/components/table/z_indexes.js +0 -23
- package/src/components/tablist/tablist.jsx +0 -99
- package/src/components/text/demos/demo_text_and_icon.html +0 -421
- package/src/components/text/overflow.jsx +0 -15
- package/src/components/text/text.jsx +0 -83
- package/src/components/text/text_and_count.jsx +0 -28
- package/src/components/ui_transition.jsx +0 -128
- package/src/components/use_auto_focus.js +0 -94
- package/src/components/use_batch_during_render.js +0 -33
- package/src/components/use_debounce_true.js +0 -31
- package/src/components/use_dependencies_diff.js +0 -35
- package/src/components/use_focus_group.js +0 -20
- package/src/components/use_initial_value.js +0 -78
- package/src/components/use_is_visited.js +0 -19
- package/src/components/use_ref_array.js +0 -38
- package/src/components/use_signal_sync.js +0 -50
- package/src/components/use_stable_callback.js +0 -68
- package/src/components/use_state_array.js +0 -47
- package/src/docs/actions.md +0 -250
- package/src/docs/demos/resource/action_status.jsx +0 -42
- package/src/docs/demos/resource/demo.md +0 -1
- package/src/docs/demos/resource/resource_demo_0.html +0 -84
- package/src/docs/demos/resource/resource_demo_10_post_gc.html +0 -364
- package/src/docs/demos/resource/resource_demo_11_describe_many.html +0 -362
- package/src/docs/demos/resource/resource_demo_2.html +0 -173
- package/src/docs/demos/resource/resource_demo_3_filtered_users.html +0 -415
- package/src/docs/demos/resource/resource_demo_4_details.html +0 -284
- package/src/docs/demos/resource/resource_demo_5_renderer_lazy.html +0 -115
- package/src/docs/demos/resource/resource_demo_6_gc.html +0 -217
- package/src/docs/demos/resource/resource_demo_7_child_gc.html +0 -240
- package/src/docs/demos/resource/resource_demo_8_proxy_gc.html +0 -319
- package/src/docs/demos/resource/resource_demo_9_describe_one.html +0 -472
- package/src/docs/demos/resource/tata.jsx +0 -3
- package/src/docs/demos/resource/toto.jsx +0 -3
- package/src/docs/demos/user_nav/user_nav.html +0 -12
- package/src/docs/demos/user_nav/user_nav.jsx +0 -330
- package/src/docs/resource_dependencies.md +0 -103
- package/src/docs/resource_with_params.md +0 -80
- package/src/navi_css_vars.js +0 -14
- package/src/notes.md +0 -34
- package/src/route/route.js +0 -596
- package/src/route/route.xtest.html +0 -228
- package/src/store/array_signal_store.js +0 -537
- package/src/store/local_storage_signal.js +0 -17
- package/src/store/resource_graph.js +0 -1304
- package/src/store/tests/resource_graph_autoreload_demo.html +0 -12
- package/src/store/tests/resource_graph_autoreload_demo.jsx +0 -964
- package/src/store/tests/resource_graph_dependencies.test_manual.js +0 -95
- package/src/store/value_in_local_storage.js +0 -187
- package/src/symbol_object_signal.js +0 -1
- package/src/use_action_data.js +0 -10
- package/src/use_action_status.js +0 -47
- package/src/utils/add_many_event_listeners.js +0 -15
- package/src/utils/array_add_remove.js +0 -61
- package/src/utils/array_signal.js +0 -15
- package/src/utils/compare_two_js_values.js +0 -172
- package/src/utils/execute_with_cleanup.js +0 -21
- package/src/utils/get_caller_info.js +0 -85
- package/src/utils/is_signal.js +0 -20
- package/src/utils/js_value_weak_map.js +0 -162
- package/src/utils/js_value_weak_map_demo.html +0 -690
- package/src/utils/merge_two_js_values.js +0 -53
- package/src/utils/stringify_for_display.js +0 -131
- package/src/utils/weak_effect.js +0 -48
- package/src/validation/constraints/confirm_constraint.js +0 -14
- package/src/validation/constraints/create_unique_value_constraint.js +0 -27
- package/src/validation/constraints/native_constraints.js +0 -338
- package/src/validation/constraints/readonly_constraint.js +0 -41
- package/src/validation/constraints/same_as_constraint.js +0 -42
- package/src/validation/constraints/single_space_constraint.js +0 -13
- package/src/validation/custom_constraint_validation.js +0 -793
- package/src/validation/custom_message.js +0 -18
- package/src/validation/demos/browser_style.png +0 -0
- package/src/validation/demos/demo_same_as_constraint.html +0 -259
- package/src/validation/demos/form_validation_demo.html +0 -142
- package/src/validation/demos/form_validation_demo_preact.html +0 -87
- package/src/validation/demos/form_validation_native_popover_demo.html +0 -168
- package/src/validation/demos/form_validation_vs_native_demo.html +0 -172
- package/src/validation/hooks/use_constraints.js +0 -23
- package/src/validation/hooks/use_custom_validation_ref.js +0 -73
- package/src/validation/hooks/use_validation_message.js +0 -19
- package/src/validation/input_change_effect.js +0 -106
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<link rel="icon" href="data:," />
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
-
<title>Resource demo describe many</title>
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
<div id="root" style="position: relative; width: 600px"></div>
|
|
11
|
-
|
|
12
|
-
<script type="module" jsenv-type="module/jsx">
|
|
13
|
-
import { render } from "preact";
|
|
14
|
-
import { useState, useEffect, useRef } from "preact/hooks";
|
|
15
|
-
import {
|
|
16
|
-
resource,
|
|
17
|
-
// eslint-disable-next-line no-unused-vars
|
|
18
|
-
ActionRenderer,
|
|
19
|
-
} from "@jsenv/navi";
|
|
20
|
-
import {
|
|
21
|
-
// eslint-disable-next-line no-unused-vars
|
|
22
|
-
ActionStatus,
|
|
23
|
-
} from "./action_status.jsx";
|
|
24
|
-
import { localStorageSignal } from "../../../store/local_storage_signal.js";
|
|
25
|
-
|
|
26
|
-
// Mock data
|
|
27
|
-
const users = [
|
|
28
|
-
{ id: "user_1", name: "Alice" },
|
|
29
|
-
{ id: "user_2", name: "Bob" },
|
|
30
|
-
{ id: "user_3", name: "Charlie" },
|
|
31
|
-
{ id: "user_4", name: "Diana" },
|
|
32
|
-
];
|
|
33
|
-
|
|
34
|
-
// Mock friendships data (userId -> array of friend userIds)
|
|
35
|
-
const friendships = {
|
|
36
|
-
user_1: ["user_2", "user_3"],
|
|
37
|
-
user_2: ["user_1"],
|
|
38
|
-
user_3: ["user_1", "user_4"],
|
|
39
|
-
user_4: ["user_3"],
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const getUser = ({ userId }) => {
|
|
43
|
-
const user = users.find((user) => user.id === userId);
|
|
44
|
-
if (!user) {
|
|
45
|
-
throw new Error(`User with id "${userId}" not found`);
|
|
46
|
-
}
|
|
47
|
-
return user;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const USER = resource("user", {
|
|
51
|
-
idKey: "id",
|
|
52
|
-
mutableIdKey: "name",
|
|
53
|
-
GET: getUser,
|
|
54
|
-
GET_MANY: () => users,
|
|
55
|
-
PUT: ({ userId, field, value }) => {
|
|
56
|
-
let userToUpdate = users.find((u) => u.id === userId);
|
|
57
|
-
userToUpdate[field] = value;
|
|
58
|
-
return { id: userId, [field]: value };
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
// ✅ One-to-many relationship: User can have many friends
|
|
63
|
-
const USER_FRIENDS = USER.many("friends", USER, {
|
|
64
|
-
// GET - Retrieve all friends of a user
|
|
65
|
-
GET_MANY: ({ userId }) => {
|
|
66
|
-
const friendIds = friendships[userId] || [];
|
|
67
|
-
return {
|
|
68
|
-
id: userId,
|
|
69
|
-
friends: friendIds.map((friendId) =>
|
|
70
|
-
users.find((u) => u.id === friendId),
|
|
71
|
-
),
|
|
72
|
-
};
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
// POST - Add a friend relationship
|
|
76
|
-
POST: ({ userId, friendId }) => {
|
|
77
|
-
if (!friendships[userId]) {
|
|
78
|
-
friendships[userId] = [];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Add friend if not already added
|
|
82
|
-
if (!friendships[userId].includes(friendId)) {
|
|
83
|
-
friendships[userId].push(friendId);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Return the added friend
|
|
87
|
-
return users.find((u) => u.id === friendId);
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
// DELETE - Remove a friend relationship
|
|
91
|
-
DELETE: ({ userId, friendId }) => {
|
|
92
|
-
if (friendships[userId]) {
|
|
93
|
-
friendships[userId] = friendships[userId].filter(
|
|
94
|
-
(id) => id !== friendId,
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
return [userId, friendId];
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
USER.RENAME = USER.PUT.bindParams({ field: "name" });
|
|
102
|
-
|
|
103
|
-
// Signal for current user
|
|
104
|
-
const currentUserIdSignal = localStorageSignal("current_user_id");
|
|
105
|
-
const currentUserAction = USER.GET.bindParams({
|
|
106
|
-
userId: currentUserIdSignal,
|
|
107
|
-
});
|
|
108
|
-
if (currentUserIdSignal.value) {
|
|
109
|
-
currentUserAction.load();
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Load initial data
|
|
113
|
-
USER.GET_MANY.load();
|
|
114
|
-
|
|
115
|
-
// eslint-disable-next-line no-unused-vars
|
|
116
|
-
const App = () => {
|
|
117
|
-
return (
|
|
118
|
-
<div style={{ display: "flex", gap: "20px" }}>
|
|
119
|
-
<div style={{ flex: 1 }}>
|
|
120
|
-
<h2>Users</h2>
|
|
121
|
-
<UsersList />
|
|
122
|
-
</div>
|
|
123
|
-
|
|
124
|
-
<div style={{ flex: 1 }}>
|
|
125
|
-
<h2>Current User Friends</h2>
|
|
126
|
-
<CurrentUserFriends />
|
|
127
|
-
</div>
|
|
128
|
-
</div>
|
|
129
|
-
);
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
// eslint-disable-next-line no-unused-vars
|
|
133
|
-
const UsersList = () => {
|
|
134
|
-
return (
|
|
135
|
-
<ActionRenderer action={USER.GET_MANY}>
|
|
136
|
-
{(users) => (
|
|
137
|
-
<div>
|
|
138
|
-
{users.map((user) => (
|
|
139
|
-
<UserItem key={user.id} user={user} />
|
|
140
|
-
))}
|
|
141
|
-
</div>
|
|
142
|
-
)}
|
|
143
|
-
</ActionRenderer>
|
|
144
|
-
);
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
// eslint-disable-next-line no-unused-vars
|
|
148
|
-
const UserItem = ({ user }) => {
|
|
149
|
-
const [isEditing, setIsEditing] = useState(false);
|
|
150
|
-
const [editName, setEditName] = useState(user.name);
|
|
151
|
-
|
|
152
|
-
const handleSave = async () => {
|
|
153
|
-
await USER.RENAME.bindParams({
|
|
154
|
-
userId: user.id,
|
|
155
|
-
value: editName,
|
|
156
|
-
}).reload();
|
|
157
|
-
setIsEditing(false);
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
const handleCancel = () => {
|
|
161
|
-
setEditName(user.name);
|
|
162
|
-
setIsEditing(false);
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
const inputRef = useRef();
|
|
166
|
-
useEffect(() => {
|
|
167
|
-
if (isEditing) {
|
|
168
|
-
inputRef.current.focus();
|
|
169
|
-
inputRef.current.select();
|
|
170
|
-
}
|
|
171
|
-
}, [isEditing]);
|
|
172
|
-
|
|
173
|
-
// Count friends
|
|
174
|
-
const friendCount = friendships[user.id]?.length || 0;
|
|
175
|
-
|
|
176
|
-
return (
|
|
177
|
-
<div
|
|
178
|
-
style={{
|
|
179
|
-
border: "1px solid #ccc",
|
|
180
|
-
padding: "10px",
|
|
181
|
-
margin: "5px 0",
|
|
182
|
-
backgroundColor:
|
|
183
|
-
currentUserIdSignal.value === user.id ? "#e6f3ff" : "white",
|
|
184
|
-
}}
|
|
185
|
-
>
|
|
186
|
-
<div style={{ display: "flex", alignItems: "center", gap: "10px" }}>
|
|
187
|
-
{isEditing ? (
|
|
188
|
-
<>
|
|
189
|
-
<input
|
|
190
|
-
ref={inputRef}
|
|
191
|
-
value={editName}
|
|
192
|
-
onChange={(e) => setEditName(e.target.value)}
|
|
193
|
-
style={{ flex: 1 }}
|
|
194
|
-
/>
|
|
195
|
-
<button onClick={handleSave}>Save</button>
|
|
196
|
-
<button onClick={handleCancel}>Cancel</button>
|
|
197
|
-
</>
|
|
198
|
-
) : (
|
|
199
|
-
<>
|
|
200
|
-
<strong style={{ flex: 1 }}>{user.name}</strong>
|
|
201
|
-
<button onClick={() => setIsEditing(true)}>Rename</button>
|
|
202
|
-
<button
|
|
203
|
-
onClick={() => {
|
|
204
|
-
currentUserIdSignal.value = user.id;
|
|
205
|
-
currentUserAction.reload();
|
|
206
|
-
}}
|
|
207
|
-
disabled={currentUserIdSignal.value === user.id}
|
|
208
|
-
>
|
|
209
|
-
Select
|
|
210
|
-
</button>
|
|
211
|
-
</>
|
|
212
|
-
)}
|
|
213
|
-
</div>
|
|
214
|
-
|
|
215
|
-
<div style={{ marginTop: "10px", fontSize: "12px", color: "#666" }}>
|
|
216
|
-
ID: {user.id} | Friends: {friendCount}
|
|
217
|
-
</div>
|
|
218
|
-
</div>
|
|
219
|
-
);
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
// eslint-disable-next-line no-unused-vars
|
|
223
|
-
const CurrentUserFriends = () => {
|
|
224
|
-
if (!currentUserIdSignal.value) {
|
|
225
|
-
return <p>No user selected</p>;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
return (
|
|
229
|
-
<div>
|
|
230
|
-
<ActionStatus action={currentUserAction} />
|
|
231
|
-
<ActionRenderer action={currentUserAction}>
|
|
232
|
-
{(user) => <UserFriends user={user} />}
|
|
233
|
-
</ActionRenderer>
|
|
234
|
-
</div>
|
|
235
|
-
);
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
// eslint-disable-next-line no-unused-vars
|
|
239
|
-
const UserFriends = ({ user }) => {
|
|
240
|
-
const [isAddingFriend, setIsAddingFriend] = useState(false);
|
|
241
|
-
const [selectedFriendId, setSelectedFriendId] = useState("");
|
|
242
|
-
|
|
243
|
-
const userFriendsAction = USER_FRIENDS.GET_MANY.bindParams({
|
|
244
|
-
userId: user.id,
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
useEffect(() => {
|
|
248
|
-
userFriendsAction.load();
|
|
249
|
-
}, [user.id]);
|
|
250
|
-
|
|
251
|
-
const handleAddFriend = async () => {
|
|
252
|
-
if (!selectedFriendId) return;
|
|
253
|
-
|
|
254
|
-
await USER_FRIENDS.POST.bindParams({
|
|
255
|
-
userId: user.id,
|
|
256
|
-
friendId: selectedFriendId,
|
|
257
|
-
}).reload();
|
|
258
|
-
|
|
259
|
-
setSelectedFriendId("");
|
|
260
|
-
setIsAddingFriend(false);
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
const handleRemoveFriend = async (friendId) => {
|
|
264
|
-
await USER_FRIENDS.DELETE.bindParams({
|
|
265
|
-
userId: user.id,
|
|
266
|
-
friendId,
|
|
267
|
-
}).reload();
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
// Get available users to add as friends (excluding self and existing friends)
|
|
271
|
-
const currentFriendIds = friendships[user.id] || [];
|
|
272
|
-
const availableUsers = users.filter(
|
|
273
|
-
(u) => u.id !== user.id && !currentFriendIds.includes(u.id),
|
|
274
|
-
);
|
|
275
|
-
|
|
276
|
-
return (
|
|
277
|
-
<div style={{ border: "2px solid #007acc", padding: "15px" }}>
|
|
278
|
-
<h3>{user.name}'s Friends</h3>
|
|
279
|
-
|
|
280
|
-
<div style={{ marginBottom: "15px" }}>
|
|
281
|
-
{isAddingFriend ? (
|
|
282
|
-
<div
|
|
283
|
-
style={{ display: "flex", gap: "10px", alignItems: "center" }}
|
|
284
|
-
>
|
|
285
|
-
<select
|
|
286
|
-
value={selectedFriendId}
|
|
287
|
-
onChange={(e) => setSelectedFriendId(e.target.value)}
|
|
288
|
-
>
|
|
289
|
-
<option value="">Select a friend to add...</option>
|
|
290
|
-
{availableUsers.map((u) => (
|
|
291
|
-
<option key={u.id} value={u.id}>
|
|
292
|
-
{u.name}
|
|
293
|
-
</option>
|
|
294
|
-
))}
|
|
295
|
-
</select>
|
|
296
|
-
<button
|
|
297
|
-
onClick={handleAddFriend}
|
|
298
|
-
disabled={!selectedFriendId}
|
|
299
|
-
>
|
|
300
|
-
Add
|
|
301
|
-
</button>
|
|
302
|
-
<button onClick={() => setIsAddingFriend(false)}>
|
|
303
|
-
Cancel
|
|
304
|
-
</button>
|
|
305
|
-
</div>
|
|
306
|
-
) : (
|
|
307
|
-
<button
|
|
308
|
-
onClick={() => setIsAddingFriend(true)}
|
|
309
|
-
disabled={availableUsers.length === 0}
|
|
310
|
-
>
|
|
311
|
-
Add Friend
|
|
312
|
-
</button>
|
|
313
|
-
)}
|
|
314
|
-
</div>
|
|
315
|
-
|
|
316
|
-
<ActionRenderer action={userFriendsAction}>
|
|
317
|
-
{(friends) => (
|
|
318
|
-
<div>
|
|
319
|
-
{friends.length === 0 ? (
|
|
320
|
-
<p style={{ color: "#666" }}>No friends yet</p>
|
|
321
|
-
) : (
|
|
322
|
-
friends.map((friend) => (
|
|
323
|
-
<div
|
|
324
|
-
key={friend.id}
|
|
325
|
-
style={{
|
|
326
|
-
display: "flex",
|
|
327
|
-
alignItems: "center",
|
|
328
|
-
justifyContent: "space-between",
|
|
329
|
-
padding: "8px",
|
|
330
|
-
margin: "5px 0",
|
|
331
|
-
backgroundColor: "#f0f0f0",
|
|
332
|
-
borderRadius: "4px",
|
|
333
|
-
}}
|
|
334
|
-
>
|
|
335
|
-
<span>{friend.name}</span>
|
|
336
|
-
<button
|
|
337
|
-
onClick={() => handleRemoveFriend(friend.id)}
|
|
338
|
-
style={{
|
|
339
|
-
background: "#ff4444",
|
|
340
|
-
color: "white",
|
|
341
|
-
border: "none",
|
|
342
|
-
padding: "4px 8px",
|
|
343
|
-
borderRadius: "4px",
|
|
344
|
-
cursor: "pointer",
|
|
345
|
-
}}
|
|
346
|
-
>
|
|
347
|
-
Remove
|
|
348
|
-
</button>
|
|
349
|
-
</div>
|
|
350
|
-
))
|
|
351
|
-
)}
|
|
352
|
-
</div>
|
|
353
|
-
)}
|
|
354
|
-
</ActionRenderer>
|
|
355
|
-
</div>
|
|
356
|
-
);
|
|
357
|
-
};
|
|
358
|
-
|
|
359
|
-
render(<App />, document.querySelector("#root"));
|
|
360
|
-
</script>
|
|
361
|
-
</body>
|
|
362
|
-
</html>
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<link rel="icon" href="data:," />
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
-
<title>Action demo 2</title>
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
<div id="root" style="position: relative; width: 400px"></div>
|
|
11
|
-
|
|
12
|
-
<script type="module" jsenv-type="module/jsx">
|
|
13
|
-
/**
|
|
14
|
-
* Ici on test une action ayant un param qui est lu dans le local storage
|
|
15
|
-
* On peut utiliser deux actions dérivées pour charger deux users différents
|
|
16
|
-
* on peut aussi savoir qui est l'utilisateur courant
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import { render } from "preact";
|
|
20
|
-
import { effect, signal } from "@preact/signals";
|
|
21
|
-
import {
|
|
22
|
-
useActionStatus,
|
|
23
|
-
resource,
|
|
24
|
-
// eslint-disable-next-line no-unused-vars
|
|
25
|
-
ActionRenderer,
|
|
26
|
-
} from "@jsenv/navi";
|
|
27
|
-
import {
|
|
28
|
-
// eslint-disable-next-line no-unused-vars
|
|
29
|
-
ActionStatus,
|
|
30
|
-
} from "./action_status.jsx";
|
|
31
|
-
|
|
32
|
-
const USER = resource("user", {
|
|
33
|
-
idKey: "name",
|
|
34
|
-
GET_MANY: () => {
|
|
35
|
-
return [{ name: "dam" }, { name: "seb" }, { name: "john" }];
|
|
36
|
-
},
|
|
37
|
-
GET: ({ name }) => {
|
|
38
|
-
return { name, greeting: `Hello ${name}` };
|
|
39
|
-
},
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
const activeUsernameSignal = signal(
|
|
43
|
-
localStorage.getItem("active_user_name"),
|
|
44
|
-
);
|
|
45
|
-
effect(() => {
|
|
46
|
-
const activeUsername = activeUsernameSignal.value;
|
|
47
|
-
if (activeUsername) {
|
|
48
|
-
localStorage.setItem("active_user_name", activeUsername);
|
|
49
|
-
} else {
|
|
50
|
-
localStorage.removeItem("active_user_name");
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
USER.ACTIVE = {
|
|
55
|
-
GET: USER.GET.bindParams({
|
|
56
|
-
name: activeUsernameSignal,
|
|
57
|
-
}),
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
if (activeUsernameSignal.peek()) {
|
|
61
|
-
USER.ACTIVE.GET.load();
|
|
62
|
-
}
|
|
63
|
-
USER.GET_MANY.load();
|
|
64
|
-
|
|
65
|
-
// eslint-disable-next-line no-unused-vars
|
|
66
|
-
const App = () => {
|
|
67
|
-
const { data: users } = useActionStatus(USER.GET_MANY);
|
|
68
|
-
|
|
69
|
-
const [dam, seb, john] = users;
|
|
70
|
-
const getDamAction = USER.GET.bindParams({
|
|
71
|
-
name: dam.name,
|
|
72
|
-
});
|
|
73
|
-
const getSebAction = USER.GET.bindParams({
|
|
74
|
-
name: seb.name,
|
|
75
|
-
});
|
|
76
|
-
const getJohnAction = USER.GET.bindParams({
|
|
77
|
-
name: john.name,
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
return (
|
|
81
|
-
<div>
|
|
82
|
-
<button
|
|
83
|
-
onClick={() => {
|
|
84
|
-
getDamAction.load();
|
|
85
|
-
activeUsernameSignal.value = dam.name;
|
|
86
|
-
}}
|
|
87
|
-
>
|
|
88
|
-
Load dam
|
|
89
|
-
</button>
|
|
90
|
-
<button
|
|
91
|
-
onClick={() => {
|
|
92
|
-
getDamAction.unload();
|
|
93
|
-
}}
|
|
94
|
-
>
|
|
95
|
-
Unload dam
|
|
96
|
-
</button>
|
|
97
|
-
<button
|
|
98
|
-
onClick={() => {
|
|
99
|
-
getDamAction.preload();
|
|
100
|
-
}}
|
|
101
|
-
>
|
|
102
|
-
Preload dam
|
|
103
|
-
</button>
|
|
104
|
-
<br />
|
|
105
|
-
<button
|
|
106
|
-
onClick={() => {
|
|
107
|
-
getSebAction.load();
|
|
108
|
-
activeUsernameSignal.value = seb.name;
|
|
109
|
-
}}
|
|
110
|
-
>
|
|
111
|
-
Load seb
|
|
112
|
-
</button>
|
|
113
|
-
<button
|
|
114
|
-
onClick={() => {
|
|
115
|
-
getSebAction.unload();
|
|
116
|
-
}}
|
|
117
|
-
>
|
|
118
|
-
Unload seb
|
|
119
|
-
</button>
|
|
120
|
-
<button
|
|
121
|
-
onClick={() => {
|
|
122
|
-
getSebAction.preload();
|
|
123
|
-
}}
|
|
124
|
-
>
|
|
125
|
-
Preload seb
|
|
126
|
-
</button>
|
|
127
|
-
<br />
|
|
128
|
-
<button
|
|
129
|
-
onClick={() => {
|
|
130
|
-
getJohnAction.load();
|
|
131
|
-
activeUsernameSignal.value = john.name;
|
|
132
|
-
}}
|
|
133
|
-
>
|
|
134
|
-
Load john
|
|
135
|
-
</button>
|
|
136
|
-
<button
|
|
137
|
-
onClick={() => {
|
|
138
|
-
getJohnAction.unload();
|
|
139
|
-
}}
|
|
140
|
-
>
|
|
141
|
-
Unload john
|
|
142
|
-
</button>
|
|
143
|
-
<button
|
|
144
|
-
onClick={() => {
|
|
145
|
-
getJohnAction.preload();
|
|
146
|
-
}}
|
|
147
|
-
>
|
|
148
|
-
Preload john
|
|
149
|
-
</button>
|
|
150
|
-
|
|
151
|
-
<ActionStatus action={getDamAction} />
|
|
152
|
-
<ActionStatus action={getSebAction} />
|
|
153
|
-
<ActionStatus action={getJohnAction} />
|
|
154
|
-
<ActionStatus action={USER.ACTIVE.GET} />
|
|
155
|
-
|
|
156
|
-
<ActionRenderer action={USER.ACTIVE.GET}>
|
|
157
|
-
{{
|
|
158
|
-
loading: () => <div>Loading user...</div>,
|
|
159
|
-
error: (error) => <div>Error: {error.message}</div>,
|
|
160
|
-
unloaded: () => <div>User not loaded</div>,
|
|
161
|
-
loaded: (user) => {
|
|
162
|
-
return <div>{user.greeting}</div>;
|
|
163
|
-
},
|
|
164
|
-
}}
|
|
165
|
-
</ActionRenderer>
|
|
166
|
-
</div>
|
|
167
|
-
);
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
render(<App />, document.querySelector("#root"));
|
|
171
|
-
</script>
|
|
172
|
-
</body>
|
|
173
|
-
</html>
|