@yuneta/gobj-ui 7.32.9 → 7.32.11
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/README.md +94 -2
- package/dist/gobj-ui.cjs.js +1057 -360
- package/dist/gobj-ui.es.js +1046 -361
- package/index.js +18 -0
- package/package.json +1 -1
- package/src/c_yui_json.js +157 -2
- package/src/c_yui_node.js +47 -9
- package/src/c_yui_preferences.js +282 -0
- package/src/c_yui_shell.js +57 -1
- package/src/i18n_key_functions.js +6 -0
- package/src/json_level_stepper.wiring.test.js +186 -0
- package/src/preferences.wiring.test.js +159 -0
- package/src/yui_preferences.js +331 -0
package/index.js
CHANGED
|
@@ -63,8 +63,26 @@ export {
|
|
|
63
63
|
yui_shell_register_overlay,
|
|
64
64
|
yui_shell_overlay_dismissed,
|
|
65
65
|
yui_shell_unpark_route,
|
|
66
|
+
yui_shell_nav_mode,
|
|
67
|
+
yui_shell_set_nav_mode,
|
|
66
68
|
} from "./src/c_yui_shell.js";
|
|
67
69
|
export { register_c_yui_nav } from "./src/c_yui_nav.js";
|
|
70
|
+
/*
|
|
71
|
+
* Preferences: the page every app shows at /preferences (theme,
|
|
72
|
+
* language, navigation), whole or in parts.
|
|
73
|
+
*/
|
|
74
|
+
export { register_c_yui_preferences } from "./src/c_yui_preferences.js";
|
|
75
|
+
export {
|
|
76
|
+
YUI_PREFERENCES_I18N_KEYS,
|
|
77
|
+
yui_preferences_setup,
|
|
78
|
+
yui_pref_header,
|
|
79
|
+
yui_pref_box,
|
|
80
|
+
yui_pref_field,
|
|
81
|
+
yui_pref_segment,
|
|
82
|
+
yui_pref_appearance_fields,
|
|
83
|
+
yui_pref_sections,
|
|
84
|
+
yui_pref_apply,
|
|
85
|
+
} from "./src/yui_preferences.js";
|
|
68
86
|
/*
|
|
69
87
|
* Site map: the whole navigation surface (toolbar + account menu +
|
|
70
88
|
* nav + dynamic tabs + view-contributed sub-routes) as a clickable,
|
package/package.json
CHANGED
package/src/c_yui_json.js
CHANGED
|
@@ -355,6 +355,8 @@ function build_ui(gobj)
|
|
|
355
355
|
priv.$search_ctl = $container.querySelector('.JSON_SEARCH_CONTROL');
|
|
356
356
|
priv.$expand_btn = $container.querySelector('.EV_EXPAND_ALL');
|
|
357
357
|
priv.$collapse_btn = $container.querySelector('.EV_COLLAPSE_ALL');
|
|
358
|
+
priv.$collapse_level_btn = $container.querySelector('.EV_COLLAPSE_LEVEL');
|
|
359
|
+
priv.$expand_level_btn = $container.querySelector('.EV_EXPAND_LEVEL');
|
|
358
360
|
priv.$graph = $container.querySelector('.JSON_GRAPH');
|
|
359
361
|
priv.$mode_btns = new Map();
|
|
360
362
|
VIEWS.forEach(function(v) {
|
|
@@ -388,6 +390,8 @@ function destroy_ui(gobj)
|
|
|
388
390
|
priv.$search_ctl = null;
|
|
389
391
|
priv.$expand_btn = null;
|
|
390
392
|
priv.$collapse_btn = null;
|
|
393
|
+
priv.$collapse_level_btn = null;
|
|
394
|
+
priv.$expand_level_btn = null;
|
|
391
395
|
priv.$mode_btns = null;
|
|
392
396
|
}
|
|
393
397
|
|
|
@@ -438,7 +442,13 @@ function make_toolbar(gobj)
|
|
|
438
442
|
* per-row toggles live in the rows. */
|
|
439
443
|
left_items.push(
|
|
440
444
|
icon_button(gobj, "yi-angles-down", "EV_EXPAND_ALL", "expand loaded"),
|
|
441
|
-
icon_button(gobj, "yi-angles-up", "EV_COLLAPSE_ALL", "collapse all")
|
|
445
|
+
icon_button(gobj, "yi-angles-up", "EV_COLLAPSE_ALL", "collapse all"),
|
|
446
|
+
/* The level stepper, beside the pair that does it all at once:
|
|
447
|
+
* `-` folds the deepest level open, `+` opens the next one. The
|
|
448
|
+
* tree boxes of the icon rule (one LEVEL of the whole tree), in
|
|
449
|
+
* the order of the treedb graph's stepper. */
|
|
450
|
+
icon_button(gobj, "yi-square-minus", "EV_COLLAPSE_LEVEL", "collapse one level"),
|
|
451
|
+
icon_button(gobj, "yi-square-plus", "EV_EXPAND_LEVEL", "expand one level")
|
|
442
452
|
);
|
|
443
453
|
|
|
444
454
|
attach_clear($search_control, $search_input);
|
|
@@ -592,7 +602,8 @@ function apply_view_mode(gobj)
|
|
|
592
602
|
* worse than an absent one. A <pre> is searched with the browser's
|
|
593
603
|
* own Ctrl+F, and the graph carries its own controls.
|
|
594
604
|
*/
|
|
595
|
-
[priv.$search_ctl, priv.$expand_btn, priv.$collapse_btn
|
|
605
|
+
[priv.$search_ctl, priv.$expand_btn, priv.$collapse_btn,
|
|
606
|
+
priv.$collapse_level_btn, priv.$expand_level_btn].forEach(function($el) {
|
|
596
607
|
if($el) {
|
|
597
608
|
$el.classList.toggle('is-hidden', mode !== "tree");
|
|
598
609
|
}
|
|
@@ -1095,6 +1106,100 @@ function collect_loaded_paths(value, segments, out)
|
|
|
1095
1106
|
}
|
|
1096
1107
|
}
|
|
1097
1108
|
|
|
1109
|
+
/************************************************************
|
|
1110
|
+
* The entries of a container, as [key, value] pairs: the keys
|
|
1111
|
+
* of an object, the indexes of an array (as strings, the way
|
|
1112
|
+
* a path spells them). None for anything else.
|
|
1113
|
+
************************************************************/
|
|
1114
|
+
function entries_of(value)
|
|
1115
|
+
{
|
|
1116
|
+
let type = json_type(value);
|
|
1117
|
+
if(type === "object") {
|
|
1118
|
+
return Object.entries(value);
|
|
1119
|
+
}
|
|
1120
|
+
if(type === "array") {
|
|
1121
|
+
return value.map((v, i) => [String(i), v]);
|
|
1122
|
+
}
|
|
1123
|
+
return [];
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
/************************************************************
|
|
1127
|
+
* Is it a container the tree can open in place: an object or
|
|
1128
|
+
* an array that is loaded (not a `__collapsed__` sentinel,
|
|
1129
|
+
* which opens through the backend).
|
|
1130
|
+
************************************************************/
|
|
1131
|
+
function is_open_able(value)
|
|
1132
|
+
{
|
|
1133
|
+
if(is_collapsed(value)) {
|
|
1134
|
+
return false;
|
|
1135
|
+
}
|
|
1136
|
+
let type = json_type(value);
|
|
1137
|
+
return type === "object" || type === "array";
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
/************************************************************
|
|
1141
|
+
* The shallowest level that has a loaded container still
|
|
1142
|
+
* closed, -1 when every loaded container is open. A level is
|
|
1143
|
+
* the depth of a row: 0 for an entry of the root.
|
|
1144
|
+
************************************************************/
|
|
1145
|
+
function first_closed_level(priv, value, segments)
|
|
1146
|
+
{
|
|
1147
|
+
let level = -1;
|
|
1148
|
+
for(let [k, v] of entries_of(value)) {
|
|
1149
|
+
if(!is_open_able(v)) {
|
|
1150
|
+
continue;
|
|
1151
|
+
}
|
|
1152
|
+
let child = segments.concat(k);
|
|
1153
|
+
let found = priv.expanded.has(seg_join(child)) ?
|
|
1154
|
+
first_closed_level(priv, v, child) :
|
|
1155
|
+
child.length - 1;
|
|
1156
|
+
if(found >= 0 && (level < 0 || found < level)) {
|
|
1157
|
+
level = found;
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
return level;
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
/************************************************************
|
|
1164
|
+
* The deepest level with a container open in sight (all its
|
|
1165
|
+
* parents open too), -1 when none is. Only what the reader
|
|
1166
|
+
* sees counts: an open container under a closed one is not
|
|
1167
|
+
* on screen, and folding it would change nothing they see.
|
|
1168
|
+
************************************************************/
|
|
1169
|
+
function deepest_open_level(priv, value, segments)
|
|
1170
|
+
{
|
|
1171
|
+
let level = -1;
|
|
1172
|
+
for(let [k, v] of entries_of(value)) {
|
|
1173
|
+
if(!is_open_able(v)) {
|
|
1174
|
+
continue;
|
|
1175
|
+
}
|
|
1176
|
+
let child = segments.concat(k);
|
|
1177
|
+
if(!priv.expanded.has(seg_join(child))) {
|
|
1178
|
+
continue;
|
|
1179
|
+
}
|
|
1180
|
+
level = Math.max(level, child.length - 1, deepest_open_level(priv, v, child));
|
|
1181
|
+
}
|
|
1182
|
+
return level;
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
/************************************************************
|
|
1186
|
+
* Open every loaded container of the levels up to `level`.
|
|
1187
|
+
************************************************************/
|
|
1188
|
+
function open_levels_up_to(priv, value, segments, level)
|
|
1189
|
+
{
|
|
1190
|
+
for(let [k, v] of entries_of(value)) {
|
|
1191
|
+
if(!is_open_able(v)) {
|
|
1192
|
+
continue;
|
|
1193
|
+
}
|
|
1194
|
+
let child = segments.concat(k);
|
|
1195
|
+
if(child.length - 1 > level) {
|
|
1196
|
+
continue;
|
|
1197
|
+
}
|
|
1198
|
+
priv.expanded.add(seg_join(child));
|
|
1199
|
+
open_levels_up_to(priv, v, child, level);
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1098
1203
|
|
|
1099
1204
|
|
|
1100
1205
|
|
|
@@ -1274,6 +1379,52 @@ function ac_collapse_all(gobj, event, kw, src)
|
|
|
1274
1379
|
return 0;
|
|
1275
1380
|
}
|
|
1276
1381
|
|
|
1382
|
+
/************************************************************
|
|
1383
|
+
* EV_EXPAND_LEVEL — open the next level: every loaded
|
|
1384
|
+
* container of the shallowest level that still has one closed.
|
|
1385
|
+
* The levels above it are all open already, so the tree shows
|
|
1386
|
+
* one level more. A `__collapsed__` sentinel is not opened: it
|
|
1387
|
+
* asks the backend, as with "expand loaded".
|
|
1388
|
+
************************************************************/
|
|
1389
|
+
function ac_expand_level(gobj, event, kw, src)
|
|
1390
|
+
{
|
|
1391
|
+
let priv = gobj.priv;
|
|
1392
|
+
if(priv.root === null || priv.root === undefined) {
|
|
1393
|
+
return 0;
|
|
1394
|
+
}
|
|
1395
|
+
let level = first_closed_level(priv, priv.root, []);
|
|
1396
|
+
if(level < 0) {
|
|
1397
|
+
return 0; /* every loaded container is open: nothing to step */
|
|
1398
|
+
}
|
|
1399
|
+
open_levels_up_to(priv, priv.root, [], level);
|
|
1400
|
+
render_view(gobj);
|
|
1401
|
+
return 0;
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
/************************************************************
|
|
1405
|
+
* EV_COLLAPSE_LEVEL — fold the deepest level open in sight:
|
|
1406
|
+
* every container open at that level or under it is closed,
|
|
1407
|
+
* so the tree shows one level less.
|
|
1408
|
+
************************************************************/
|
|
1409
|
+
function ac_collapse_level(gobj, event, kw, src)
|
|
1410
|
+
{
|
|
1411
|
+
let priv = gobj.priv;
|
|
1412
|
+
if(priv.root === null || priv.root === undefined) {
|
|
1413
|
+
return 0;
|
|
1414
|
+
}
|
|
1415
|
+
let level = deepest_open_level(priv, priv.root, []);
|
|
1416
|
+
if(level < 0) {
|
|
1417
|
+
return 0; /* nothing open: nothing to step */
|
|
1418
|
+
}
|
|
1419
|
+
for(let path of Array.from(priv.expanded)) {
|
|
1420
|
+
if(seg_split(path).length - 1 >= level) {
|
|
1421
|
+
priv.expanded.delete(path);
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
render_view(gobj);
|
|
1425
|
+
return 0;
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1277
1428
|
/************************************************************
|
|
1278
1429
|
* EV_COPY_ALL — copy the working document to the clipboard
|
|
1279
1430
|
************************************************************/
|
|
@@ -1468,6 +1619,8 @@ function create_gclass(gclass_name)
|
|
|
1468
1619
|
["EV_SEARCH", ac_search, null],
|
|
1469
1620
|
["EV_EXPAND_ALL", ac_expand_all, null],
|
|
1470
1621
|
["EV_COLLAPSE_ALL", ac_collapse_all, null],
|
|
1622
|
+
["EV_EXPAND_LEVEL", ac_expand_level, null],
|
|
1623
|
+
["EV_COLLAPSE_LEVEL", ac_collapse_level, null],
|
|
1471
1624
|
["EV_COPY_ALL", ac_copy_all, null],
|
|
1472
1625
|
["EV_SET_VIEW_MODE", ac_set_view_mode, null],
|
|
1473
1626
|
["EV_LANGUAGE_CHANGED", ac_language_changed, null],
|
|
@@ -1489,6 +1642,8 @@ function create_gclass(gclass_name)
|
|
|
1489
1642
|
["EV_SEARCH", 0],
|
|
1490
1643
|
["EV_EXPAND_ALL", 0],
|
|
1491
1644
|
["EV_COLLAPSE_ALL", 0],
|
|
1645
|
+
["EV_EXPAND_LEVEL", 0],
|
|
1646
|
+
["EV_COLLAPSE_LEVEL", 0],
|
|
1492
1647
|
["EV_COPY_ALL", 0],
|
|
1493
1648
|
["EV_SET_VIEW_MODE", 0],
|
|
1494
1649
|
["EV_JSON_ITEM_CLICKED", 0],
|
package/src/c_yui_node.js
CHANGED
|
@@ -144,6 +144,7 @@ import {
|
|
|
144
144
|
yui_shell_navigate,
|
|
145
145
|
yui_shell_set_sub_routes,
|
|
146
146
|
yui_shell_translate,
|
|
147
|
+
yui_shell_nav_mode,
|
|
147
148
|
} from "./c_yui_shell.js";
|
|
148
149
|
|
|
149
150
|
import "./c_yui_node.css";
|
|
@@ -180,7 +181,7 @@ SDATA(data_type_t.DTP_JSON, "children", 0, null, "Declared child spec
|
|
|
180
181
|
|
|
181
182
|
SDATA(data_type_t.DTP_STRING, "base_route", 0, "", "ROOT only: the declared route the whole tree hangs from"),
|
|
182
183
|
SDATA(data_type_t.DTP_STRING, "tree_version", 0, "", "ROOT only: version of the tree CONTRACT (its paths are public urls)"),
|
|
183
|
-
SDATA(data_type_t.DTP_STRING, "nav_mode", 0, "
|
|
184
|
+
SDATA(data_type_t.DTP_STRING, "nav_mode", 0, "", "ROOT only: how the way in is shown — stack|back|path. Empty: the reader's choice for the app, the shell's navigation preference (yui_shell_nav_mode), followed when it changes"),
|
|
184
185
|
SDATA(data_type_t.DTP_BOOLEAN, "remember_position", 0, false, "A nav item points at WHERE THE OPERATOR LEFT that child, not at its bare route: the tail last active under each child is remembered and appended. For a tree whose children are workspaces with a position inside them (a treedb and its open topic); off for one whose children are pages, where the item IS the destination"),
|
|
185
186
|
|
|
186
187
|
SDATA(data_type_t.DTP_POINTER, "$container", 0, null, "Root HTMLElement (shell view contract)"),
|
|
@@ -297,6 +298,9 @@ function mt_start(gobj)
|
|
|
297
298
|
return -1;
|
|
298
299
|
}
|
|
299
300
|
gobj_subscribe_event(shell, "EV_ROUTE_CHANGED", {}, gobj);
|
|
301
|
+
/* The reader's navigation preference: followed while the tree has
|
|
302
|
+
* no `nav_mode` of its own (ac_nav_mode_changed). */
|
|
303
|
+
gobj_subscribe_event(shell, "EV_NAV_MODE_CHANGED", {}, gobj);
|
|
300
304
|
publish_sub_routes(gobj);
|
|
301
305
|
}
|
|
302
306
|
|
|
@@ -311,6 +315,7 @@ function mt_stop(gobj)
|
|
|
311
315
|
let shell = yui_shell_of(gobj);
|
|
312
316
|
if(shell) {
|
|
313
317
|
gobj_unsubscribe_event(shell, "EV_ROUTE_CHANGED", {}, gobj);
|
|
318
|
+
gobj_unsubscribe_event(shell, "EV_NAV_MODE_CHANGED", {}, gobj);
|
|
314
319
|
yui_shell_set_sub_routes(shell, gobj_read_attr(gobj, "base_route"), null);
|
|
315
320
|
}
|
|
316
321
|
}
|
|
@@ -420,7 +425,13 @@ function tree_root_of(gobj)
|
|
|
420
425
|
************************************************************/
|
|
421
426
|
function nav_mode_of(gobj)
|
|
422
427
|
{
|
|
423
|
-
let
|
|
428
|
+
let root = tree_root_of(gobj);
|
|
429
|
+
let mode = gobj_read_attr(root, "nav_mode");
|
|
430
|
+
if(!mode) {
|
|
431
|
+
/* No mode of its own: the reader's, for the whole app (7.32.11). */
|
|
432
|
+
let shell = yui_shell_of(root);
|
|
433
|
+
mode = shell ? yui_shell_nav_mode(shell) : "stack";
|
|
434
|
+
}
|
|
424
435
|
|
|
425
436
|
if(!is_nav_mode(mode)) {
|
|
426
437
|
log_error(
|
|
@@ -1624,7 +1635,8 @@ function ac_set_nav_mode(gobj, event, kw, src)
|
|
|
1624
1635
|
let priv = gobj.priv;
|
|
1625
1636
|
let mode = kw.nav_mode || "";
|
|
1626
1637
|
|
|
1627
|
-
|
|
1638
|
+
/* "" is no mode of its own: follow the reader's (yui_shell_nav_mode). */
|
|
1639
|
+
if(mode !== "" && !is_nav_mode(mode)) {
|
|
1628
1640
|
log_error(
|
|
1629
1641
|
`${GCLASS_NAME} '${node_path_str(gobj)}': unknown nav_mode ` +
|
|
1630
1642
|
`'${mode}' — expected one of ${NAV_MODES.join("|")}`
|
|
@@ -1639,17 +1651,38 @@ function ac_set_nav_mode(gobj, event, kw, src)
|
|
|
1639
1651
|
return -1;
|
|
1640
1652
|
}
|
|
1641
1653
|
gobj_write_attr(gobj, "nav_mode", mode);
|
|
1654
|
+
reapply_route(gobj);
|
|
1655
|
+
return 0;
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
/************************************************************
|
|
1659
|
+
* The reader chose another way in for the whole app (the shell's
|
|
1660
|
+
* EV_NAV_MODE_CHANGED, from Preferences). A root with a
|
|
1661
|
+
* `nav_mode` of its own keeps it: the host pinned it.
|
|
1662
|
+
************************************************************/
|
|
1663
|
+
function ac_nav_mode_changed(gobj, event, kw, src)
|
|
1664
|
+
{
|
|
1665
|
+
let priv = gobj.priv;
|
|
1666
|
+
if(!priv.is_root || gobj_read_attr(gobj, "nav_mode")) {
|
|
1667
|
+
return 0;
|
|
1668
|
+
}
|
|
1669
|
+
reapply_route(gobj);
|
|
1670
|
+
return 0;
|
|
1671
|
+
}
|
|
1642
1672
|
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1673
|
+
/************************************************************
|
|
1674
|
+
* Same reason as EV_SET_CHROME_DEPTH: what changes with the
|
|
1675
|
+
* mode is the shape of the ACTIVE PATH, whose strips are
|
|
1676
|
+
* painted by the ancestors, so the tree is asked to re-apply
|
|
1677
|
+
* the current route instead of repainting one node.
|
|
1678
|
+
************************************************************/
|
|
1679
|
+
function reapply_route(gobj)
|
|
1680
|
+
{
|
|
1647
1681
|
let shell = yui_shell_of(gobj);
|
|
1648
1682
|
if(shell) {
|
|
1649
1683
|
yui_shell_navigate(shell, gobj_read_attr(shell, "current_route") ||
|
|
1650
1684
|
route_of(gobj), {replace: true});
|
|
1651
1685
|
}
|
|
1652
|
-
return 0;
|
|
1653
1686
|
}
|
|
1654
1687
|
|
|
1655
1688
|
/************************************************************
|
|
@@ -1746,7 +1779,8 @@ function yui_node_set_nav_mode(node, mode)
|
|
|
1746
1779
|
|
|
1747
1780
|
function yui_node_nav_mode(node)
|
|
1748
1781
|
{
|
|
1749
|
-
|
|
1782
|
+
/* The mode the tree draws in: its own, else the reader's. */
|
|
1783
|
+
return nav_mode_of(node);
|
|
1750
1784
|
}
|
|
1751
1785
|
|
|
1752
1786
|
/************************************************************
|
|
@@ -1838,6 +1872,7 @@ function create_gclass(gclass_name)
|
|
|
1838
1872
|
["EV_SET_PROJECTION", ac_set_projection, null],
|
|
1839
1873
|
["EV_SET_CHROME_DEPTH", ac_set_chrome_depth, null],
|
|
1840
1874
|
["EV_SET_NAV_MODE", ac_set_nav_mode, null],
|
|
1875
|
+
["EV_NAV_MODE_CHANGED", ac_nav_mode_changed, null],
|
|
1841
1876
|
["EV_SET_CONTENT", ac_set_content, null],
|
|
1842
1877
|
["EV_NODE_TREE_CHANGED", ac_tree_changed, null],
|
|
1843
1878
|
["EV_DESTROY_NAVS", ac_destroy_navs, null]
|
|
@@ -1854,6 +1889,7 @@ function create_gclass(gclass_name)
|
|
|
1854
1889
|
["EV_SET_PROJECTION", ac_set_projection, null],
|
|
1855
1890
|
["EV_SET_CHROME_DEPTH", ac_set_chrome_depth, null],
|
|
1856
1891
|
["EV_SET_NAV_MODE", ac_set_nav_mode, null],
|
|
1892
|
+
["EV_NAV_MODE_CHANGED", ac_nav_mode_changed, null],
|
|
1857
1893
|
["EV_SET_CONTENT", ac_set_content, null],
|
|
1858
1894
|
["EV_NODE_TREE_CHANGED", ac_tree_changed, null],
|
|
1859
1895
|
["EV_DESTROY_NAVS", ac_destroy_navs, null]
|
|
@@ -1870,6 +1906,7 @@ function create_gclass(gclass_name)
|
|
|
1870
1906
|
["EV_SET_PROJECTION", ac_set_projection, null],
|
|
1871
1907
|
["EV_SET_CHROME_DEPTH", ac_set_chrome_depth, null],
|
|
1872
1908
|
["EV_SET_NAV_MODE", ac_set_nav_mode, null],
|
|
1909
|
+
["EV_NAV_MODE_CHANGED", ac_nav_mode_changed, null],
|
|
1873
1910
|
["EV_SET_CONTENT", ac_set_content, null],
|
|
1874
1911
|
["EV_NODE_TREE_CHANGED", ac_tree_changed, null],
|
|
1875
1912
|
["EV_DESTROY_NAVS", ac_destroy_navs, null]
|
|
@@ -1891,6 +1928,7 @@ function create_gclass(gclass_name)
|
|
|
1891
1928
|
["EV_SET_PROJECTION", 0],
|
|
1892
1929
|
["EV_SET_CHROME_DEPTH", 0],
|
|
1893
1930
|
["EV_SET_NAV_MODE", 0],
|
|
1931
|
+
["EV_NAV_MODE_CHANGED", 0],
|
|
1894
1932
|
["EV_SET_CONTENT", 0],
|
|
1895
1933
|
["EV_NODE_TREE_CHANGED", 0],
|
|
1896
1934
|
/* internal: posted to itself, the navs a render left */
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* c_yui_preferences.js
|
|
3
|
+
* C_YUI_PREFERENCES GClass.
|
|
4
|
+
*
|
|
5
|
+
* The Preferences page of an app, whole: a view the shell
|
|
6
|
+
* mounts at /preferences (a route target of the app config).
|
|
7
|
+
*
|
|
8
|
+
* "/preferences": {"target": {"gclass": "C_YUI_PREFERENCES"}}
|
|
9
|
+
*
|
|
10
|
+
* It draws the three rows every app shows -- theme, language,
|
|
11
|
+
* navigation (yui_preferences.js) -- and then the boxes the
|
|
12
|
+
* app adds in its yui_preferences_setup(). A press applies at
|
|
13
|
+
* once and is kept in this browser; the page is drawn again
|
|
14
|
+
* to mark the new choice, and when the language changes from
|
|
15
|
+
* elsewhere (the toolbar), because which option is marked is
|
|
16
|
+
* markup.
|
|
17
|
+
*
|
|
18
|
+
* An app whose page has fields with actions of its own keeps
|
|
19
|
+
* its own view and draws the same rows with the parts of
|
|
20
|
+
* yui_preferences.js.
|
|
21
|
+
*
|
|
22
|
+
* Copyright (c) 2026, ArtGins.
|
|
23
|
+
* All Rights Reserved.
|
|
24
|
+
***********************************************************************/
|
|
25
|
+
import {
|
|
26
|
+
SDATA,
|
|
27
|
+
SDATA_END,
|
|
28
|
+
data_type_t,
|
|
29
|
+
gclass_create,
|
|
30
|
+
log_error,
|
|
31
|
+
gobj_parent,
|
|
32
|
+
gobj_read_attr,
|
|
33
|
+
gobj_write_attr,
|
|
34
|
+
gobj_read_pointer_attr,
|
|
35
|
+
gobj_subscribe_event,
|
|
36
|
+
gobj_unsubscribe_event,
|
|
37
|
+
createElement2,
|
|
38
|
+
refresh_language,
|
|
39
|
+
} from "@yuneta/gobj-js";
|
|
40
|
+
|
|
41
|
+
import {t} from "i18next";
|
|
42
|
+
|
|
43
|
+
import {yui_shell_of} from "./c_yui_shell.js";
|
|
44
|
+
import {
|
|
45
|
+
yui_pref_header,
|
|
46
|
+
yui_pref_box,
|
|
47
|
+
yui_pref_appearance_fields,
|
|
48
|
+
yui_pref_sections,
|
|
49
|
+
yui_pref_apply,
|
|
50
|
+
} from "./yui_preferences.js";
|
|
51
|
+
|
|
52
|
+
/***************************************************************
|
|
53
|
+
* Constants
|
|
54
|
+
***************************************************************/
|
|
55
|
+
const GCLASS_NAME = "C_YUI_PREFERENCES";
|
|
56
|
+
|
|
57
|
+
/***************************************************************
|
|
58
|
+
* Data
|
|
59
|
+
***************************************************************/
|
|
60
|
+
const attrs_table = [
|
|
61
|
+
SDATA(data_type_t.DTP_POINTER, "subscriber", 0, null, "Subscriber of output events"),
|
|
62
|
+
SDATA(data_type_t.DTP_POINTER, "$container", 0, null, "Root HTMLElement (shell view contract)"),
|
|
63
|
+
SDATA_END()
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
/*
|
|
67
|
+
* A field named like an attribute is written by the framework on every
|
|
68
|
+
* write of that attribute.
|
|
69
|
+
*/
|
|
70
|
+
let PRIVATE_DATA = {
|
|
71
|
+
shell: null,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
let __gclass__ = null;
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
/******************************
|
|
80
|
+
* Framework Methods
|
|
81
|
+
******************************/
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
/***************************************************************
|
|
87
|
+
* Framework Method: Create
|
|
88
|
+
***************************************************************/
|
|
89
|
+
function mt_create(gobj)
|
|
90
|
+
{
|
|
91
|
+
let $container = createElement2(
|
|
92
|
+
["div", {class: "C_YUI_PREFERENCES PREF_PAGE p-4"}, []]
|
|
93
|
+
);
|
|
94
|
+
gobj_write_attr(gobj, "$container", $container);
|
|
95
|
+
|
|
96
|
+
/*
|
|
97
|
+
* CHILD subscription model
|
|
98
|
+
*/
|
|
99
|
+
let subscriber = gobj_read_pointer_attr(gobj, "subscriber");
|
|
100
|
+
if(!subscriber) {
|
|
101
|
+
subscriber = gobj_parent(gobj);
|
|
102
|
+
}
|
|
103
|
+
gobj_subscribe_event(gobj, null, {}, subscriber);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/***************************************************************
|
|
107
|
+
* Framework Method: Start
|
|
108
|
+
***************************************************************/
|
|
109
|
+
function mt_start(gobj)
|
|
110
|
+
{
|
|
111
|
+
let priv = gobj.priv;
|
|
112
|
+
|
|
113
|
+
/* The language can change from the toolbar while the page is
|
|
114
|
+
* open: which option is marked is markup, drawn again. */
|
|
115
|
+
priv.shell = yui_shell_of(gobj);
|
|
116
|
+
if(priv.shell) {
|
|
117
|
+
gobj_subscribe_event(priv.shell, "EV_LANGUAGE_CHANGED", {}, gobj);
|
|
118
|
+
}
|
|
119
|
+
render(gobj);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/***************************************************************
|
|
123
|
+
* Framework Method: Stop
|
|
124
|
+
***************************************************************/
|
|
125
|
+
function mt_stop(gobj)
|
|
126
|
+
{
|
|
127
|
+
let priv = gobj.priv;
|
|
128
|
+
|
|
129
|
+
if(priv.shell) {
|
|
130
|
+
gobj_unsubscribe_event(priv.shell, "EV_LANGUAGE_CHANGED", {}, gobj);
|
|
131
|
+
priv.shell = null;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/***************************************************************
|
|
136
|
+
* Framework Method: Destroy
|
|
137
|
+
***************************************************************/
|
|
138
|
+
function mt_destroy(gobj)
|
|
139
|
+
{
|
|
140
|
+
let $container = gobj_read_attr(gobj, "$container");
|
|
141
|
+
if($container && $container.parentNode) {
|
|
142
|
+
$container.parentNode.removeChild($container);
|
|
143
|
+
}
|
|
144
|
+
gobj_write_attr(gobj, "$container", null);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
/***************************
|
|
151
|
+
* Local Methods
|
|
152
|
+
***************************/
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
/***************************************************************
|
|
158
|
+
* Draw the page: the header, the box of the three rows, the
|
|
159
|
+
* boxes of the app.
|
|
160
|
+
***************************************************************/
|
|
161
|
+
function render(gobj)
|
|
162
|
+
{
|
|
163
|
+
let $container = gobj_read_attr(gobj, "$container");
|
|
164
|
+
if(!$container) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
$container.replaceChildren();
|
|
168
|
+
$container.appendChild(createElement2(yui_pref_header()));
|
|
169
|
+
$container.appendChild(createElement2(
|
|
170
|
+
yui_pref_box(yui_pref_appearance_fields(gobj), "PREF_APPEARANCE")
|
|
171
|
+
));
|
|
172
|
+
for(let box of yui_pref_sections(gobj)) {
|
|
173
|
+
$container.appendChild((box && box.nodeType) ? box : createElement2(box));
|
|
174
|
+
}
|
|
175
|
+
refresh_language($container, t);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
/***************************
|
|
182
|
+
* Actions
|
|
183
|
+
***************************/
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
/***************************************************************
|
|
189
|
+
* EV_SET_THEME / EV_SET_LANGUAGE / EV_SET_NAV_MODE {value}:
|
|
190
|
+
* a press on one of the three rows.
|
|
191
|
+
***************************************************************/
|
|
192
|
+
function ac_set_preference(gobj, event, kw, src)
|
|
193
|
+
{
|
|
194
|
+
let ret = yui_pref_apply(gobj, event, kw);
|
|
195
|
+
render(gobj);
|
|
196
|
+
return ret;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/***************************************************************
|
|
200
|
+
* The language changed somewhere else (the toolbar).
|
|
201
|
+
***************************************************************/
|
|
202
|
+
function ac_language_changed(gobj, event, kw, src)
|
|
203
|
+
{
|
|
204
|
+
render(gobj);
|
|
205
|
+
return 0;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/***************************************************************
|
|
209
|
+
* FSM
|
|
210
|
+
***************************************************************/
|
|
211
|
+
/*---------------------------------------------*
|
|
212
|
+
* Global methods table
|
|
213
|
+
*---------------------------------------------*/
|
|
214
|
+
const gmt = {
|
|
215
|
+
mt_create: mt_create,
|
|
216
|
+
mt_start: mt_start,
|
|
217
|
+
mt_stop: mt_stop,
|
|
218
|
+
mt_destroy: mt_destroy
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
/***************************************************************
|
|
222
|
+
* Create the GClass
|
|
223
|
+
***************************************************************/
|
|
224
|
+
function create_gclass(gclass_name)
|
|
225
|
+
{
|
|
226
|
+
if(__gclass__) {
|
|
227
|
+
log_error(`GClass ALREADY created: ${gclass_name}`);
|
|
228
|
+
return -1;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/*---------------------------------------------*
|
|
232
|
+
* States
|
|
233
|
+
*---------------------------------------------*/
|
|
234
|
+
const states = [
|
|
235
|
+
["ST_IDLE", [
|
|
236
|
+
["EV_SET_THEME", ac_set_preference, null],
|
|
237
|
+
["EV_SET_LANGUAGE", ac_set_preference, null],
|
|
238
|
+
["EV_SET_NAV_MODE", ac_set_preference, null],
|
|
239
|
+
["EV_LANGUAGE_CHANGED", ac_language_changed, null]
|
|
240
|
+
]]
|
|
241
|
+
];
|
|
242
|
+
|
|
243
|
+
/*---------------------------------------------*
|
|
244
|
+
* Events
|
|
245
|
+
*---------------------------------------------*/
|
|
246
|
+
const event_types = [
|
|
247
|
+
["EV_SET_THEME", 0],
|
|
248
|
+
["EV_SET_LANGUAGE", 0],
|
|
249
|
+
["EV_SET_NAV_MODE", 0],
|
|
250
|
+
["EV_LANGUAGE_CHANGED", 0]
|
|
251
|
+
];
|
|
252
|
+
|
|
253
|
+
__gclass__ = gclass_create(
|
|
254
|
+
gclass_name,
|
|
255
|
+
event_types,
|
|
256
|
+
states,
|
|
257
|
+
gmt,
|
|
258
|
+
0, // lmt,
|
|
259
|
+
attrs_table,
|
|
260
|
+
PRIVATE_DATA,
|
|
261
|
+
0, // authz_table,
|
|
262
|
+
0, // command_table,
|
|
263
|
+
0, // s_user_trace_level
|
|
264
|
+
0 // gclass_flag
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
if(!__gclass__) {
|
|
268
|
+
return -1;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return 0;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/***************************************************************
|
|
275
|
+
* Register GClass
|
|
276
|
+
***************************************************************/
|
|
277
|
+
function register_c_yui_preferences()
|
|
278
|
+
{
|
|
279
|
+
return create_gclass(GCLASS_NAME);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export { register_c_yui_preferences };
|