@yuneta/gobj-ui 7.26.5 → 7.26.6
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 +67 -0
- package/dist/gobj-ui.cjs.js +723 -187
- package/dist/gobj-ui.es.js +714 -188
- package/index.js +13 -1
- package/package.json +1 -1
- package/src/c_yui_form.js +147 -8
- package/src/c_yui_shell.js +28 -0
- package/src/c_yui_treedb_topic_with_form.js +78 -2
- package/src/c_yui_treedb_topics.js +77 -7
- package/src/lib_icons.js +395 -0
- package/src/lib_icons.test.js +214 -0
- package/src/yui_icons.css +20 -0
package/index.js
CHANGED
|
@@ -118,7 +118,19 @@ export {
|
|
|
118
118
|
* Libraries and utilities
|
|
119
119
|
*/
|
|
120
120
|
export { addClasses, removeClasses, toggleClasses, removeChildElements, disableElements, enableElements, set_submit_state, set_cancel_state, set_active_state, set_pressed_state, getStrokeColor } from "./src/lib_graph.js";
|
|
121
|
-
export {
|
|
121
|
+
export {
|
|
122
|
+
inject_svg_icons,
|
|
123
|
+
yui_icon_is_defined,
|
|
124
|
+
ICONS_TOPIC,
|
|
125
|
+
USER_ICON_PREFIX,
|
|
126
|
+
yui_user_icon_class,
|
|
127
|
+
yui_svg_sanitize,
|
|
128
|
+
yui_svg_icon_element,
|
|
129
|
+
yui_icons_set_user,
|
|
130
|
+
yui_icons_put_user,
|
|
131
|
+
yui_icons_remove_user,
|
|
132
|
+
yui_icons_list,
|
|
133
|
+
} from "./src/lib_icons.js";
|
|
122
134
|
export { EditControl, MarkerControl } from "./src/lib_maplibre.js";
|
|
123
135
|
export { yui_asset_id, yui_asset_ids, yui_asset_src, yui_asset_element, yui_asset_missing } from "./src/yui_asset.js";
|
|
124
136
|
export {
|
package/package.json
CHANGED
package/src/c_yui_form.js
CHANGED
|
@@ -73,6 +73,11 @@ import {field_is_readonly} from "./form_field_readonly.js";
|
|
|
73
73
|
* dialog rebuilds the form on every open, and re-rendering a form under
|
|
74
74
|
* the user mid-edit would throw away what they typed. */
|
|
75
75
|
import {yui_is_dark} from "./yui_theme.js";
|
|
76
|
+
import {
|
|
77
|
+
yui_icons_list,
|
|
78
|
+
yui_icons_is_svg_field,
|
|
79
|
+
yui_svg_icon_element
|
|
80
|
+
} from "./lib_icons.js";
|
|
76
81
|
/* ORDER MATTERS, and it is this way round: `tabulator.css` is OUR sheet of
|
|
77
82
|
* fixes ON TOP of Tabulator's theme, and at equal specificity the cascade is
|
|
78
83
|
* decided by which one the bundle emits last. Imported before the theme (as
|
|
@@ -579,6 +584,12 @@ function build_html_form(gobj, $form, prefix, template)
|
|
|
579
584
|
{
|
|
580
585
|
Object.entries(template).forEach(([key, value]) => {
|
|
581
586
|
const field_desc = template_get_field_desc(key, value);
|
|
587
|
+
/* The drawing of a user icon (`svg` of __icons__): a text area
|
|
588
|
+
* with the icon it draws below it. */
|
|
589
|
+
if(!prefix && yui_icons_is_svg_field(
|
|
590
|
+
gobj_read_str_attr(gobj, "topic_name"), field_desc.name)) {
|
|
591
|
+
field_desc.type = "svg";
|
|
592
|
+
}
|
|
582
593
|
let html_field_conf = build_form_field_conf(gobj, field_desc);
|
|
583
594
|
|
|
584
595
|
/*
|
|
@@ -740,8 +751,21 @@ function build_form_field_conf(gobj, field_desc)
|
|
|
740
751
|
field_conf.tag = "file";
|
|
741
752
|
break;
|
|
742
753
|
|
|
743
|
-
|
|
754
|
+
/* The NAME of an icon, chosen from the icons there are -- each
|
|
755
|
+
* drawn beside its name -- and not typed from memory. */
|
|
744
756
|
case "icon":
|
|
757
|
+
field_conf.tag = "select2";
|
|
758
|
+
field_conf.options = yui_icons_list().map(icon => icon.name);
|
|
759
|
+
break;
|
|
760
|
+
|
|
761
|
+
case "svg":
|
|
762
|
+
field_conf.tag = "textarea";
|
|
763
|
+
field_conf.extras.rows = 6;
|
|
764
|
+
field_conf.extras.spellcheck = "false";
|
|
765
|
+
field_conf.extras.class = "textarea is-family-monospace";
|
|
766
|
+
break;
|
|
767
|
+
|
|
768
|
+
case "image":
|
|
745
769
|
case "string":
|
|
746
770
|
field_conf.tag = 'input';
|
|
747
771
|
field_conf.inputType = 'text';
|
|
@@ -1308,6 +1332,9 @@ function create_form_field(
|
|
|
1308
1332
|
let extend = ['textarea', attrs];
|
|
1309
1333
|
$extend = createElement2(extend);
|
|
1310
1334
|
$control.appendChild($extend);
|
|
1335
|
+
if(field_desc.type === "svg") {
|
|
1336
|
+
attach_svg_preview(gobj, $control, $extend);
|
|
1337
|
+
}
|
|
1311
1338
|
break;
|
|
1312
1339
|
}
|
|
1313
1340
|
|
|
@@ -1362,14 +1389,17 @@ function create_form_field(
|
|
|
1362
1389
|
));
|
|
1363
1390
|
opts = [];
|
|
1364
1391
|
}
|
|
1392
|
+
/* An icon name is not text to translate: it is a class. */
|
|
1393
|
+
let is_icon = (field_desc.type === "icon");
|
|
1365
1394
|
let extend = ["select",
|
|
1366
1395
|
{
|
|
1367
1396
|
name: name,
|
|
1368
1397
|
class: '',
|
|
1369
1398
|
multiple: true,
|
|
1370
1399
|
},
|
|
1371
|
-
opts.map(option =>
|
|
1372
|
-
['option', {value:option
|
|
1400
|
+
opts.map(option => is_icon
|
|
1401
|
+
? ['option', {value:option}, option]
|
|
1402
|
+
: ['option', {value:option, i18n:option}, option]
|
|
1373
1403
|
)
|
|
1374
1404
|
];
|
|
1375
1405
|
$extend = createElement2(extend);
|
|
@@ -1377,9 +1407,11 @@ function create_form_field(
|
|
|
1377
1407
|
$extend.tom_select = new TomSelect($extend, {
|
|
1378
1408
|
allowEmptyOption: true,
|
|
1379
1409
|
placeholder: placeholder,
|
|
1380
|
-
/* single-valued fkey (real_type string): one selection only
|
|
1381
|
-
|
|
1382
|
-
|
|
1410
|
+
/* single-valued fkey (real_type string): one selection only.
|
|
1411
|
+
* An icon column holds one name. */
|
|
1412
|
+
maxItems: (is_icon || (field_desc.type === "fkey" &&
|
|
1413
|
+
field_desc.real_type === "string"))? 1 : null,
|
|
1414
|
+
render: is_icon? icon_select_render() : undefined,
|
|
1383
1415
|
plugins: {
|
|
1384
1416
|
'clear_button': {
|
|
1385
1417
|
/* i18n keys are lower-case by convention (the apps'
|
|
@@ -1598,6 +1630,92 @@ function attach_color_value($control, $input)
|
|
|
1598
1630
|
$control.appendChild($value);
|
|
1599
1631
|
}
|
|
1600
1632
|
|
|
1633
|
+
/******************************************************************
|
|
1634
|
+
* How the icon picker draws a name: the icon, then the name.
|
|
1635
|
+
* The names come from yui_icons_list() -- class names, already
|
|
1636
|
+
* [a-z0-9-] -- and are escaped anyway, because they are written
|
|
1637
|
+
* as markup.
|
|
1638
|
+
******************************************************************/
|
|
1639
|
+
function icon_select_render()
|
|
1640
|
+
{
|
|
1641
|
+
function draw(data, escape) {
|
|
1642
|
+
let name = escape(data.value);
|
|
1643
|
+
return `<div class="ICON_SELECT_ITEM"><span class="icon"><i class="${name}" aria-hidden="true"></i></span><span>${escape(data.text)}</span></div>`;
|
|
1644
|
+
}
|
|
1645
|
+
return {
|
|
1646
|
+
option: draw,
|
|
1647
|
+
item: draw
|
|
1648
|
+
};
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
/******************************************************************
|
|
1652
|
+
* Why a drawing cannot be an icon, in the reader's language.
|
|
1653
|
+
* The causes are the fixed set yui_svg_sanitize() answers, each
|
|
1654
|
+
* written here as a literal t() so validate-locales sees it.
|
|
1655
|
+
******************************************************************/
|
|
1656
|
+
function svg_error_text(error)
|
|
1657
|
+
{
|
|
1658
|
+
switch(error) {
|
|
1659
|
+
case "empty svg":
|
|
1660
|
+
return t("empty svg");
|
|
1661
|
+
case "svg too big":
|
|
1662
|
+
return t("svg too big");
|
|
1663
|
+
case "not an svg document":
|
|
1664
|
+
return t("not an svg document");
|
|
1665
|
+
case "svg without size":
|
|
1666
|
+
return t("svg without size");
|
|
1667
|
+
case "svg without shapes":
|
|
1668
|
+
return t("svg without shapes");
|
|
1669
|
+
default:
|
|
1670
|
+
log_error(`svg_error_text(): unknown cause '${error}'`);
|
|
1671
|
+
return error;
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
/******************************************************************
|
|
1676
|
+
* The icon a drawing (`svg` of __icons__) makes, below its text
|
|
1677
|
+
* area, redrawn as it is typed: what is saved is what the app
|
|
1678
|
+
* will show. A drawing that cannot be drawn says why, and what
|
|
1679
|
+
* the sanitizer left out is named.
|
|
1680
|
+
******************************************************************/
|
|
1681
|
+
function attach_svg_preview(gobj, $control, $textarea)
|
|
1682
|
+
{
|
|
1683
|
+
let $preview = createElement2(
|
|
1684
|
+
['div', {class: 'SVG_PREVIEW is-flex is-align-items-center mt-2'}, [
|
|
1685
|
+
['span', {class: 'SVG_PREVIEW_ICON icon is-large is-size-3'}],
|
|
1686
|
+
['span', {class: 'SVG_PREVIEW_NOTE is-size-7 yui-text-quiet ml-2'}]
|
|
1687
|
+
]]
|
|
1688
|
+
);
|
|
1689
|
+
$control.appendChild($preview);
|
|
1690
|
+
let $icon = $preview.querySelector('.SVG_PREVIEW_ICON');
|
|
1691
|
+
let $note = $preview.querySelector('.SVG_PREVIEW_NOTE');
|
|
1692
|
+
|
|
1693
|
+
function redraw() {
|
|
1694
|
+
$icon.replaceChildren();
|
|
1695
|
+
$note.textContent = "";
|
|
1696
|
+
if(!$textarea.value || !$textarea.value.trim()) {
|
|
1697
|
+
return;
|
|
1698
|
+
}
|
|
1699
|
+
let preview = yui_svg_icon_element($textarea.value);
|
|
1700
|
+
if(preview.error) {
|
|
1701
|
+
$note.textContent = svg_error_text(preview.error);
|
|
1702
|
+
return;
|
|
1703
|
+
}
|
|
1704
|
+
$icon.appendChild(preview.element);
|
|
1705
|
+
if(preview.dropped && preview.dropped.length > 0) {
|
|
1706
|
+
/* What the sanitizer left out is named as the svg names it
|
|
1707
|
+
* (`script`, `@onclick`): it is the reader's own markup. */
|
|
1708
|
+
$note.textContent = `${t("left out")}: ${preview.dropped.join(" ")}`;
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
|
|
1712
|
+
$textarea.yui_svg_preview = redraw;
|
|
1713
|
+
$textarea.addEventListener('input', function() {
|
|
1714
|
+
redraw();
|
|
1715
|
+
gobj_send_event(gobj, "EV_RECORD_CHANGED", {}, gobj);
|
|
1716
|
+
});
|
|
1717
|
+
}
|
|
1718
|
+
|
|
1601
1719
|
/******************************************************************
|
|
1602
1720
|
* `readonly` is an attribute of a TEXT control and of nothing else.
|
|
1603
1721
|
*
|
|
@@ -2455,6 +2573,9 @@ function clear_data(gobj, $form)
|
|
|
2455
2573
|
$input.tom_select.clear();
|
|
2456
2574
|
} else {
|
|
2457
2575
|
$input.value = null;
|
|
2576
|
+
if($input.yui_svg_preview) {
|
|
2577
|
+
$input.yui_svg_preview();
|
|
2578
|
+
}
|
|
2458
2579
|
}
|
|
2459
2580
|
}
|
|
2460
2581
|
});
|
|
@@ -2611,12 +2732,23 @@ function set_form_values(gobj, template, $form, record)
|
|
|
2611
2732
|
break;
|
|
2612
2733
|
case "textarea":
|
|
2613
2734
|
$input.value = value;
|
|
2735
|
+
if($input.yui_svg_preview) {
|
|
2736
|
+
$input.yui_svg_preview();
|
|
2737
|
+
}
|
|
2614
2738
|
break;
|
|
2615
2739
|
case "select":
|
|
2616
2740
|
$input.value = value;
|
|
2617
2741
|
break;
|
|
2618
2742
|
case "select2":
|
|
2619
2743
|
$input.tom_select.clear();
|
|
2744
|
+
/* A name the list does not carry (an icon deleted, or
|
|
2745
|
+
* not loaded yet) is kept, not dropped: dropping it would
|
|
2746
|
+
* write "" on the next save of an unrelated field. */
|
|
2747
|
+
if(field_desc && field_desc.type === "icon" &&
|
|
2748
|
+
is_string(value) && value &&
|
|
2749
|
+
!$input.tom_select.options[value]) {
|
|
2750
|
+
$input.tom_select.addOption({value: value, text: value});
|
|
2751
|
+
}
|
|
2620
2752
|
$input.tom_select.setValue(value);
|
|
2621
2753
|
break;
|
|
2622
2754
|
case "checkbox":
|
|
@@ -2797,6 +2929,7 @@ function treedb_value_2_form_value(gobj, field_desc, value)
|
|
|
2797
2929
|
case "color":
|
|
2798
2930
|
case "image":
|
|
2799
2931
|
case "icon":
|
|
2932
|
+
case "svg":
|
|
2800
2933
|
case "tel":
|
|
2801
2934
|
case "template":
|
|
2802
2935
|
case "table":
|
|
@@ -2938,11 +3071,17 @@ function form_value_2_treedb_value(gobj, field_desc, value)
|
|
|
2938
3071
|
break;
|
|
2939
3072
|
}
|
|
2940
3073
|
break;
|
|
3074
|
+
case "icon":
|
|
3075
|
+
/* The picker is a tom-select of one item, which answers a list */
|
|
3076
|
+
if(Array.isArray(value)) {
|
|
3077
|
+
value = value.length > 0? value[0] : "";
|
|
3078
|
+
}
|
|
3079
|
+
break;
|
|
2941
3080
|
case "date":
|
|
2942
3081
|
case "color":
|
|
2943
3082
|
case "image":
|
|
2944
|
-
case "icon":
|
|
2945
3083
|
case "tel":
|
|
3084
|
+
case "svg":
|
|
2946
3085
|
break;
|
|
2947
3086
|
case "template":
|
|
2948
3087
|
if(is_string(value)) {
|
|
@@ -3504,4 +3643,4 @@ function register_c_yui_form()
|
|
|
3504
3643
|
return create_gclass(GCLASS_NAME);
|
|
3505
3644
|
}
|
|
3506
3645
|
|
|
3507
|
-
export { register_c_yui_form };
|
|
3646
|
+
export { register_c_yui_form, svg_error_text };
|
package/src/c_yui_shell.js
CHANGED
|
@@ -3119,6 +3119,15 @@ function create_gclass(gclass_name)
|
|
|
3119
3119
|
|event_flag_t.EVF_PUBLIC_EVENT
|
|
3120
3120
|
|event_flag_t.EVF_NO_WARN_SUBS],
|
|
3121
3121
|
|
|
3122
|
+
/* The user icons changed (a view loaded `__icons__`, or a node of
|
|
3123
|
+
* it was written, and called yui_shell_icons_changed). A class name
|
|
3124
|
+
* picks its icon up by itself once the rule exists, but a view that
|
|
3125
|
+
* DECIDED, at render time, whether a name is an icon at all -- the
|
|
3126
|
+
* icon cell of a table -- has to decide again. */
|
|
3127
|
+
["EV_ICONS_CHANGED", event_flag_t.EVF_OUTPUT_EVENT
|
|
3128
|
+
|event_flag_t.EVF_PUBLIC_EVENT
|
|
3129
|
+
|event_flag_t.EVF_NO_WARN_SUBS],
|
|
3130
|
+
|
|
3122
3131
|
/* The app's backend connection went up or down
|
|
3123
3132
|
* (yui_shell_set_connection_state), {connected}. Delivered only
|
|
3124
3133
|
* to the subscribers that declare it: see
|
|
@@ -3643,6 +3652,24 @@ function yui_shell_language_changed(shell_gobj)
|
|
|
3643
3652
|
gobj_publish_event(shell_gobj, "EV_LANGUAGE_CHANGED", {});
|
|
3644
3653
|
}
|
|
3645
3654
|
|
|
3655
|
+
/************************************************************
|
|
3656
|
+
* The user icons changed (lib_icons.js: yui_icons_set_user,
|
|
3657
|
+
* yui_icons_put_user, yui_icons_remove_user): PUBLISH it, so
|
|
3658
|
+
* the views that decided at render time whether a name is an
|
|
3659
|
+
* icon draw it again.
|
|
3660
|
+
*
|
|
3661
|
+
* The registry is a module and knows no shell; the view that
|
|
3662
|
+
* fed it calls this.
|
|
3663
|
+
************************************************************/
|
|
3664
|
+
function yui_shell_icons_changed(shell_gobj)
|
|
3665
|
+
{
|
|
3666
|
+
if(!shell_gobj || !is_gobj(shell_gobj)) {
|
|
3667
|
+
log_error("yui_shell_icons_changed(): no shell");
|
|
3668
|
+
return;
|
|
3669
|
+
}
|
|
3670
|
+
gobj_publish_event(shell_gobj, "EV_ICONS_CHANGED", {});
|
|
3671
|
+
}
|
|
3672
|
+
|
|
3646
3673
|
/************************************************************
|
|
3647
3674
|
* Set the backend-connection state painted by every
|
|
3648
3675
|
* type:"connection" toolbar item. Host/event-driven: the
|
|
@@ -3798,6 +3825,7 @@ export {
|
|
|
3798
3825
|
yui_shell_set_translator,
|
|
3799
3826
|
yui_shell_translate,
|
|
3800
3827
|
yui_shell_language_changed,
|
|
3828
|
+
yui_shell_icons_changed,
|
|
3801
3829
|
yui_shell_set_connection_state,
|
|
3802
3830
|
yui_shell_set_toolbar_item_icon,
|
|
3803
3831
|
yui_shell_set_toolbar_item_badge,
|
|
@@ -72,7 +72,7 @@ import {
|
|
|
72
72
|
yui_shell_of,
|
|
73
73
|
} from "./c_yui_shell.js";
|
|
74
74
|
|
|
75
|
-
import {register_c_yui_form} from "./c_yui_form.js";
|
|
75
|
+
import {register_c_yui_form, svg_error_text} from "./c_yui_form.js";
|
|
76
76
|
import {register_c_yui_json} from "./c_yui_json.js";
|
|
77
77
|
import {attach_clear} from "./yui_inputs.js";
|
|
78
78
|
|
|
@@ -91,7 +91,11 @@ import {
|
|
|
91
91
|
} from "./yui_table_select.js";
|
|
92
92
|
|
|
93
93
|
import {yui_table_filter_clear} from "./yui_table_filter_clear.js";
|
|
94
|
-
import {
|
|
94
|
+
import {
|
|
95
|
+
yui_icon_is_defined,
|
|
96
|
+
yui_icons_is_svg_field,
|
|
97
|
+
yui_svg_icon_element
|
|
98
|
+
} from "./lib_icons.js";
|
|
95
99
|
import {row_matches} from "./yui_row_search.js";
|
|
96
100
|
|
|
97
101
|
import {t} from "i18next";
|
|
@@ -467,6 +471,9 @@ function mt_start(gobj)
|
|
|
467
471
|
let shell = yui_shell_of(gobj);
|
|
468
472
|
if(shell) {
|
|
469
473
|
gobj_subscribe_event(shell, "EV_LANGUAGE_CHANGED", {}, gobj);
|
|
474
|
+
/* An `icon` cell decides when it is drawn whether its name is an
|
|
475
|
+
* icon (icon_formatter), and a user icon can arrive after that. */
|
|
476
|
+
gobj_subscribe_event(shell, "EV_ICONS_CHANGED", {}, gobj);
|
|
470
477
|
}
|
|
471
478
|
create_tabulator(gobj);
|
|
472
479
|
}
|
|
@@ -479,6 +486,7 @@ function mt_stop(gobj)
|
|
|
479
486
|
let shell = yui_shell_of(gobj);
|
|
480
487
|
if(shell) {
|
|
481
488
|
gobj_unsubscribe_event(shell, "EV_LANGUAGE_CHANGED", {}, gobj);
|
|
489
|
+
gobj_unsubscribe_event(shell, "EV_ICONS_CHANGED", {}, gobj);
|
|
482
490
|
}
|
|
483
491
|
close_form_dialog(gobj);
|
|
484
492
|
close_schema_dialog(gobj);
|
|
@@ -1377,7 +1385,18 @@ function create_tabulator(gobj)
|
|
|
1377
1385
|
if(field_desc.is_hidden) {
|
|
1378
1386
|
continue;
|
|
1379
1387
|
}
|
|
1388
|
+
/* The drawing of a user icon: the cell shows the icon, not its
|
|
1389
|
+
* source, and it is edited in the form (a text area with a
|
|
1390
|
+
* preview) -- never typed into a cell, nor filtered. */
|
|
1391
|
+
if(yui_icons_is_svg_field(gobj_read_str_attr(gobj, "topic_name"), col.id)) {
|
|
1392
|
+
field_desc.type = "svg";
|
|
1393
|
+
}
|
|
1380
1394
|
switch(field_desc.type) {
|
|
1395
|
+
case "svg":
|
|
1396
|
+
hozAlign = "center";
|
|
1397
|
+
vertAlign = "middle";
|
|
1398
|
+
colFormatter = svg_cell_formatter;
|
|
1399
|
+
break;
|
|
1381
1400
|
case "hook":
|
|
1382
1401
|
hozAlign = "center";
|
|
1383
1402
|
cellClick = function(e, cell) {
|
|
@@ -2067,6 +2086,31 @@ function icon_formatter(cell)
|
|
|
2067
2086
|
]);
|
|
2068
2087
|
}
|
|
2069
2088
|
|
|
2089
|
+
/************************************************************
|
|
2090
|
+
* Cell of the drawing of a user icon (`svg` of __icons__): the
|
|
2091
|
+
* icon itself, as the app will draw it. A drawing that cannot
|
|
2092
|
+
* be drawn says why, in plain grey -- the same honest half as
|
|
2093
|
+
* an unknown icon name in icon_formatter.
|
|
2094
|
+
************************************************************/
|
|
2095
|
+
function svg_cell_formatter(cell)
|
|
2096
|
+
{
|
|
2097
|
+
let svg = cell.getValue();
|
|
2098
|
+
if(!is_string(svg) || empty_string(svg)) {
|
|
2099
|
+
return "";
|
|
2100
|
+
}
|
|
2101
|
+
let preview = yui_svg_icon_element(svg);
|
|
2102
|
+
if(preview.error) {
|
|
2103
|
+
let text = svg_error_text(preview.error);
|
|
2104
|
+
return createElement2([
|
|
2105
|
+
"span",
|
|
2106
|
+
{class: "ICON_CELL_UNKNOWN is-size-7 yui-text-quiet", title: text},
|
|
2107
|
+
text
|
|
2108
|
+
]);
|
|
2109
|
+
}
|
|
2110
|
+
preview.element.classList.add("ICON_CELL");
|
|
2111
|
+
return preview.element;
|
|
2112
|
+
}
|
|
2113
|
+
|
|
2070
2114
|
/************************************************************
|
|
2071
2115
|
* Cell of a col holding a JSON document (dict/list/blob/
|
|
2072
2116
|
* template/coordinates/…): a one-line truncated preview,
|
|
@@ -3753,6 +3797,36 @@ function ac_language_changed(gobj, event, kw, src)
|
|
|
3753
3797
|
return 0;
|
|
3754
3798
|
}
|
|
3755
3799
|
|
|
3800
|
+
/************************************************************
|
|
3801
|
+
* The user icons changed (published by the shell): the cells
|
|
3802
|
+
* of an `icon` column decided when they were drawn whether
|
|
3803
|
+
* their name was an icon, so they are drawn again.
|
|
3804
|
+
************************************************************/
|
|
3805
|
+
function ac_icons_changed(gobj, event, kw, src)
|
|
3806
|
+
{
|
|
3807
|
+
let tabulator = gobj_read_attr(gobj, "tabulator");
|
|
3808
|
+
if(!tabulator) {
|
|
3809
|
+
return 0;
|
|
3810
|
+
}
|
|
3811
|
+
let desc = gobj_read_attr(gobj, "desc");
|
|
3812
|
+
let cols = (desc && Array.isArray(desc.cols))? desc.cols : [];
|
|
3813
|
+
let icon_cols = cols.filter(col =>
|
|
3814
|
+
col && col.id && treedb_get_field_desc(col).type === "icon"
|
|
3815
|
+
);
|
|
3816
|
+
if(icon_cols.length === 0) {
|
|
3817
|
+
return 0;
|
|
3818
|
+
}
|
|
3819
|
+
try {
|
|
3820
|
+
for(const row of tabulator.getRows()) {
|
|
3821
|
+
row.reformat();
|
|
3822
|
+
}
|
|
3823
|
+
} catch(e) {
|
|
3824
|
+
log_error(`${gobj_short_name(gobj)}: cannot redraw the icon cells: ${e}`);
|
|
3825
|
+
return -1;
|
|
3826
|
+
}
|
|
3827
|
+
return 0;
|
|
3828
|
+
}
|
|
3829
|
+
|
|
3756
3830
|
function ac_load_nodes(gobj, event, kw, src)
|
|
3757
3831
|
{
|
|
3758
3832
|
let data = kw;
|
|
@@ -5333,6 +5407,7 @@ function create_gclass(gclass_name)
|
|
|
5333
5407
|
const states = [
|
|
5334
5408
|
["ST_IDLE", [
|
|
5335
5409
|
["EV_LANGUAGE_CHANGED", ac_language_changed, null],
|
|
5410
|
+
["EV_ICONS_CHANGED", ac_icons_changed, null],
|
|
5336
5411
|
["EV_LOAD_NODES", ac_load_nodes, null],
|
|
5337
5412
|
["EV_LOAD_NODE_CREATED", ac_load_node_created, null],
|
|
5338
5413
|
["EV_LOAD_NODE_UPDATED", ac_load_node_updated, null],
|
|
@@ -5390,6 +5465,7 @@ function create_gclass(gclass_name)
|
|
|
5390
5465
|
*---------------------------------------------*/
|
|
5391
5466
|
const event_types = [
|
|
5392
5467
|
["EV_LANGUAGE_CHANGED", 0],
|
|
5468
|
+
["EV_ICONS_CHANGED", 0],
|
|
5393
5469
|
["EV_LOAD_NODES", 0],
|
|
5394
5470
|
["EV_LOAD_NODE_CREATED", 0],
|
|
5395
5471
|
["EV_LOAD_NODE_UPDATED", 0],
|
|
@@ -66,12 +66,19 @@ import {
|
|
|
66
66
|
import {yui_shell_show_error, yui_shell_show_modal, yui_shell_popup_layer} from "./shell_modals.js";
|
|
67
67
|
import {
|
|
68
68
|
yui_shell_of,
|
|
69
|
+
yui_shell_icons_changed,
|
|
69
70
|
yui_shell_set_sub_routes,
|
|
70
71
|
yui_shell_navigate,
|
|
71
72
|
yui_shell_last_route_under,
|
|
72
73
|
yui_shell_previous_route,
|
|
73
74
|
} from "./c_yui_shell.js";
|
|
74
75
|
import {nodes_answer} from "./nodes_answer.js";
|
|
76
|
+
import {
|
|
77
|
+
ICONS_TOPIC,
|
|
78
|
+
yui_icons_set_user,
|
|
79
|
+
yui_icons_put_user,
|
|
80
|
+
yui_icons_remove_user
|
|
81
|
+
} from "./lib_icons.js";
|
|
75
82
|
import {yui_toolbar_icon} from "./yui_toolbar.js";
|
|
76
83
|
import {
|
|
77
84
|
desc_pkey2s, desc_tkey, col_key_roles, system_flag_names
|
|
@@ -1255,6 +1262,56 @@ function request_treedb_descs(gobj)
|
|
|
1255
1262
|
}
|
|
1256
1263
|
}
|
|
1257
1264
|
|
|
1265
|
+
/************************************************************
|
|
1266
|
+
* A user view shows the topics of the user and, of the system
|
|
1267
|
+
* topics, only __icons__: its nodes are what the user ADDS to
|
|
1268
|
+
* the app (the icons a column `icon` can name), so editing them
|
|
1269
|
+
* is the user's business. The other `__` topics are the
|
|
1270
|
+
* treedb's own bookkeeping.
|
|
1271
|
+
************************************************************/
|
|
1272
|
+
function topic_is_shown(topic_name)
|
|
1273
|
+
{
|
|
1274
|
+
return topic_name.substring(0, 2) !== "__" || topic_name === ICONS_TOPIC;
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
/************************************************************
|
|
1278
|
+
* The nodes of __icons__ are the user icons of the app: each
|
|
1279
|
+
* load and each write of them goes to the icon registry
|
|
1280
|
+
* (lib_icons.js), and the shell tells the views that decided
|
|
1281
|
+
* at render time whether a name was an icon.
|
|
1282
|
+
*
|
|
1283
|
+
* how: "load" (nodes = the whole topic), "put" (one node
|
|
1284
|
+
* created or updated) or "remove" (one node deleted).
|
|
1285
|
+
************************************************************/
|
|
1286
|
+
function feed_user_icons(gobj, how, nodes)
|
|
1287
|
+
{
|
|
1288
|
+
switch(how) {
|
|
1289
|
+
case "load":
|
|
1290
|
+
yui_icons_set_user(nodes);
|
|
1291
|
+
break;
|
|
1292
|
+
case "put":
|
|
1293
|
+
for(const node of nodes) {
|
|
1294
|
+
yui_icons_put_user(node);
|
|
1295
|
+
}
|
|
1296
|
+
break;
|
|
1297
|
+
case "remove":
|
|
1298
|
+
for(const node of nodes) {
|
|
1299
|
+
if(node && typeof node.id === "string") {
|
|
1300
|
+
yui_icons_remove_user(node.id);
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
break;
|
|
1304
|
+
default:
|
|
1305
|
+
log_error(`${gobj_short_name(gobj)}: feed_user_icons(): unknown '${how}'`);
|
|
1306
|
+
return;
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
let shell = yui_shell_of(gobj);
|
|
1310
|
+
if(shell) {
|
|
1311
|
+
yui_shell_icons_changed(shell);
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1258
1315
|
/************************************************************
|
|
1259
1316
|
* Response of remote command
|
|
1260
1317
|
************************************************************/
|
|
@@ -1271,11 +1328,8 @@ function process_treedb_descs(gobj)
|
|
|
1271
1328
|
let treedb_name = gobj_read_str_attr(gobj, "treedb_name");
|
|
1272
1329
|
let readonly = gobj_read_bool_attr(gobj, "readonly");
|
|
1273
1330
|
for(const [key, desc] of Object.entries(descs)) {
|
|
1274
|
-
if(system) {
|
|
1275
|
-
|
|
1276
|
-
if(key.substring(0, 2) === "__") {
|
|
1277
|
-
continue;
|
|
1278
|
-
}
|
|
1331
|
+
if(!system && !topic_is_shown(key)) {
|
|
1332
|
+
continue;
|
|
1279
1333
|
}
|
|
1280
1334
|
|
|
1281
1335
|
let kw_topic_form = {
|
|
@@ -1292,7 +1346,11 @@ function process_treedb_descs(gobj)
|
|
|
1292
1346
|
treedb_name: treedb_name,
|
|
1293
1347
|
topic_name: key,
|
|
1294
1348
|
desc: desc,
|
|
1295
|
-
|
|
1349
|
+
/* __icons__ is read WHOLE, never by pages: its nodes are the
|
|
1350
|
+
* user icons of the app (feed_user_icons), and a page of them
|
|
1351
|
+
* would leave the rest of the icons undrawn. */
|
|
1352
|
+
with_remote_paging: key !== ICONS_TOPIC &&
|
|
1353
|
+
gobj_read_bool_attr(gobj, "with_remote_paging"),
|
|
1296
1354
|
page_size: gobj_read_integer_attr(gobj, "page_size"),
|
|
1297
1355
|
with_selection_bar: gobj_read_bool_attr(gobj, "with_selection_bar"),
|
|
1298
1356
|
/* This host answers every write of the form (see
|
|
@@ -1402,7 +1460,7 @@ function register_sub_routes(gobj)
|
|
|
1402
1460
|
}
|
|
1403
1461
|
if(is_object(descs)) {
|
|
1404
1462
|
for(let topic of Object.keys(descs)) {
|
|
1405
|
-
if(!system && topic
|
|
1463
|
+
if(!system && !topic_is_shown(topic)) {
|
|
1406
1464
|
continue;
|
|
1407
1465
|
}
|
|
1408
1466
|
nodes.push({
|
|
@@ -2503,6 +2561,9 @@ function ac_mt_command_answer(gobj, event, kw, src)
|
|
|
2503
2561
|
);
|
|
2504
2562
|
} else {
|
|
2505
2563
|
forget_topic_rereads(gobj, topic_name);
|
|
2564
|
+
if(topic_name === ICONS_TOPIC) {
|
|
2565
|
+
feed_user_icons(gobj, "load", answer.rows);
|
|
2566
|
+
}
|
|
2506
2567
|
gobj_send_event(
|
|
2507
2568
|
gobj_topic_form,
|
|
2508
2569
|
"EV_LOAD_NODES",
|
|
@@ -2914,6 +2975,9 @@ function ac_treedb_node_created(gobj, event, kw, src)
|
|
|
2914
2975
|
let node = kw_get_dict_value(gobj, kw, "node", null, 0);
|
|
2915
2976
|
|
|
2916
2977
|
if(treedb_name === gobj_read_str_attr(gobj, "treedb_name")) {
|
|
2978
|
+
if(topic_name === ICONS_TOPIC) {
|
|
2979
|
+
feed_user_icons(gobj, "put", [node]);
|
|
2980
|
+
}
|
|
2917
2981
|
let gobj_formtable = get_gobj_formtable(gobj, topic_name);
|
|
2918
2982
|
gobj_send_event(
|
|
2919
2983
|
gobj_formtable,
|
|
@@ -2936,6 +3000,9 @@ function ac_treedb_node_updated(gobj, event, kw, src)
|
|
|
2936
3000
|
let node = kw_get_dict_value(gobj, kw, "node", null, 0);
|
|
2937
3001
|
|
|
2938
3002
|
if(treedb_name === gobj_read_str_attr(gobj, "treedb_name")) {
|
|
3003
|
+
if(topic_name === ICONS_TOPIC) {
|
|
3004
|
+
feed_user_icons(gobj, "put", [node]);
|
|
3005
|
+
}
|
|
2939
3006
|
let gobj_formtable = get_gobj_formtable(gobj, topic_name);
|
|
2940
3007
|
gobj_send_event(
|
|
2941
3008
|
gobj_formtable,
|
|
@@ -2988,6 +3055,9 @@ function ac_treedb_node_deleted(gobj, event, kw, src)
|
|
|
2988
3055
|
let node = kw_get_dict_value(gobj, kw, "node", null, 0);
|
|
2989
3056
|
|
|
2990
3057
|
if(treedb_name === gobj_read_str_attr(gobj, "treedb_name")) {
|
|
3058
|
+
if(topic_name === ICONS_TOPIC) {
|
|
3059
|
+
feed_user_icons(gobj, "remove", [node]);
|
|
3060
|
+
}
|
|
2991
3061
|
let gobj_formtable = get_gobj_formtable(gobj, topic_name);
|
|
2992
3062
|
gobj_send_event(
|
|
2993
3063
|
gobj_formtable,
|