@yuneta/gobj-ui 5.15.0 → 5.17.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "5.15.0",
3
+ "version": "5.17.0",
4
4
  "type": "module",
5
5
  "main": "dist/gobj-ui.cjs.js",
6
6
  "module": "dist/gobj-ui.es.js",
@@ -78,6 +78,8 @@ import {
78
78
  getStrokeColor,
79
79
  } from "./lib_graph.js";
80
80
 
81
+ import {node_label} from "./treedb_node_label.js";
82
+
81
83
  import {
82
84
  BaseLayout,
83
85
  ExtensionCategory,
@@ -1227,7 +1229,8 @@ function create_topic_node(gobj, desc, record)
1227
1229
  style.dx = -58;
1228
1230
  style.dy = -20;
1229
1231
  style.innerHTML = build_chip_innerHTML(
1230
- desc.color, priv.theme, record.icon, record.id
1232
+ desc.color, priv.theme, record.icon,
1233
+ node_label(desc, record), record.id
1231
1234
  );
1232
1235
 
1233
1236
  } else if(node_treedb_type === 'extended') {
@@ -1239,8 +1242,8 @@ function create_topic_node(gobj, desc, record)
1239
1242
  style.dx = -72;
1240
1243
  style.dy = -33;
1241
1244
  style.innerHTML = build_node_innerHTML(
1242
- desc.color, priv.theme, record.icon, record.id,
1243
- desc.topic_name, true
1245
+ desc.color, priv.theme, record.icon, node_label(desc, record),
1246
+ desc.topic_name, true, record.id
1244
1247
  );
1245
1248
 
1246
1249
  } else {
@@ -1250,7 +1253,8 @@ function create_topic_node(gobj, desc, record)
1250
1253
  style.dx = -86;
1251
1254
  style.dy = -48;
1252
1255
  style.innerHTML = build_node_innerHTML(
1253
- desc.color, priv.theme, record.icon, record.id, desc.topic_name
1256
+ desc.color, priv.theme, record.icon, node_label(desc, record),
1257
+ desc.topic_name, false, record.id
1254
1258
  );
1255
1259
  }
1256
1260
 
@@ -1353,7 +1357,8 @@ function update_topic_node(gobj, desc, node_name, record)
1353
1357
  id: node_name,
1354
1358
  style: {
1355
1359
  innerHTML: build_chip_innerHTML(
1356
- desc.color, priv.theme, record.icon, record.id
1360
+ desc.color, priv.theme, record.icon,
1361
+ node_label(desc, record), record.id
1357
1362
  ),
1358
1363
  }
1359
1364
  }]);
@@ -1362,8 +1367,9 @@ function update_topic_node(gobj, desc, node_name, record)
1362
1367
  id: node_name,
1363
1368
  style: {
1364
1369
  innerHTML: build_node_innerHTML(
1365
- desc.color, priv.theme, record.icon, record.id,
1366
- desc.topic_name, true
1370
+ desc.color, priv.theme, record.icon,
1371
+ node_label(desc, record),
1372
+ desc.topic_name, true, record.id
1367
1373
  ),
1368
1374
  }
1369
1375
  }]);
@@ -1372,8 +1378,9 @@ function update_topic_node(gobj, desc, node_name, record)
1372
1378
  id: node_name,
1373
1379
  style: {
1374
1380
  innerHTML: build_node_innerHTML(
1375
- desc.color, priv.theme, record.icon, record.id,
1376
- desc.topic_name
1381
+ desc.color, priv.theme, record.icon,
1382
+ node_label(desc, record),
1383
+ desc.topic_name, false, record.id
1377
1384
  ),
1378
1385
  }
1379
1386
  }]);
@@ -4184,8 +4191,9 @@ function show_node_popover(gobj)
4184
4191
  if(node_graph_type === 'hierarchical') {
4185
4192
  let record = nodeData.data.record || {};
4186
4193
  updateStyle.innerHTML = build_node_innerHTML(
4187
- fill, priv.theme, record.icon, record.id,
4188
- nodeData.data.desc.topic_name
4194
+ fill, priv.theme, record.icon,
4195
+ node_label(nodeData.data.desc, record),
4196
+ nodeData.data.desc.topic_name, false, record.id
4189
4197
  );
4190
4198
  }
4191
4199
  graph.updateNodeData([{ id: node_id, style: updateStyle }]);
@@ -4221,8 +4229,9 @@ function show_node_popover(gobj)
4221
4229
  if(node_graph_type === 'hierarchical') {
4222
4230
  let record = nodeData.data.record || {};
4223
4231
  restoreStyle.innerHTML = build_node_innerHTML(
4224
- origFill, priv.theme, record.icon, record.id,
4225
- nodeData.data.desc.topic_name
4232
+ origFill, priv.theme, record.icon,
4233
+ node_label(nodeData.data.desc, record),
4234
+ nodeData.data.desc.topic_name, false, record.id
4226
4235
  );
4227
4236
  }
4228
4237
  graph.updateNodeData([{ id: node_id, style: restoreStyle }]);
@@ -4398,7 +4407,8 @@ function refresh_html_nodes_theme(gobj, theme)
4398
4407
  style: {
4399
4408
  innerHTML: build_node_innerHTML(
4400
4409
  nd.data.desc.color, theme, record.icon,
4401
- record.id, nd.data.desc.topic_name
4410
+ node_label(nd.data.desc, record),
4411
+ nd.data.desc.topic_name, false, record.id
4402
4412
  )
4403
4413
  }
4404
4414
  });
@@ -4408,7 +4418,7 @@ function refresh_html_nodes_theme(gobj, theme)
4408
4418
  style: {
4409
4419
  innerHTML: build_chip_innerHTML(
4410
4420
  nd.data.desc.color, theme, record.icon,
4411
- record.id
4421
+ node_label(nd.data.desc, record), record.id
4412
4422
  )
4413
4423
  }
4414
4424
  });
@@ -4418,7 +4428,8 @@ function refresh_html_nodes_theme(gobj, theme)
4418
4428
  style: {
4419
4429
  innerHTML: build_node_innerHTML(
4420
4430
  nd.data.desc.color, theme, record.icon,
4421
- record.id, nd.data.desc.topic_name, true
4431
+ node_label(nd.data.desc, record),
4432
+ nd.data.desc.topic_name, true, record.id
4422
4433
  )
4423
4434
  }
4424
4435
  });
@@ -4464,8 +4475,9 @@ function refresh_default_edges_theme(gobj, theme)
4464
4475
  * but lighter (1px border, no shadow, single line). The name is
4465
4476
  * always legible (ellipsis + native title tooltip on overflow).
4466
4477
  ************************************************************/
4467
- function build_chip_innerHTML(color, theme, icon, id)
4478
+ function build_chip_innerHTML(color, theme, icon, label, key)
4468
4479
  {
4480
+ let title = key || label;
4469
4481
  let dark = (theme === "dark");
4470
4482
  let surface = dark ? "#1b2230" : "#ffffff";
4471
4483
  let bg = dark
@@ -4485,7 +4497,7 @@ function build_chip_innerHTML(color, theme, icon, id)
4485
4497
  }
4486
4498
 
4487
4499
  return `
4488
- <div title="${escapeHtml(id)}" style="
4500
+ <div title="${escapeHtml(title)}" style="
4489
4501
  box-sizing: border-box;
4490
4502
  width: 100%;
4491
4503
  height: 100%;
@@ -4502,7 +4514,7 @@ function build_chip_innerHTML(color, theme, icon, id)
4502
4514
  ">${icon_html}<span style="
4503
4515
  font-size: 12px; font-weight: 600; line-height: 1;
4504
4516
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
4505
- ">${escapeHtml(id)}</span>
4517
+ ">${escapeHtml(label)}</span>
4506
4518
  </div>
4507
4519
  `;
4508
4520
  }
@@ -4517,8 +4529,9 @@ function build_chip_innerHTML(color, theme, icon, id)
4517
4529
  * colour is kept (per-topic differentiation) but softened via
4518
4530
  * color-mix instead of a harsh saturated fill. Theme-aware.
4519
4531
  ************************************************************/
4520
- function build_node_innerHTML(color, theme, icon, id, topic_name, structural)
4532
+ function build_node_innerHTML(color, theme, icon, label, topic_name, structural, key)
4521
4533
  {
4534
+ let title = key || label;
4522
4535
  let dark = (theme === "dark");
4523
4536
  let surface = dark ? "#1b2230" : "#ffffff";
4524
4537
  let bg, border, border_style;
@@ -4568,7 +4581,7 @@ function build_node_innerHTML(color, theme, icon, id, topic_name, structural)
4568
4581
  }
4569
4582
 
4570
4583
  return `
4571
- <div title="${escapeHtml(id)}" style="
4584
+ <div title="${escapeHtml(title)}" style="
4572
4585
  box-sizing: border-box;
4573
4586
  width: 100%;
4574
4587
  height: 100%;
@@ -4591,7 +4604,7 @@ function build_node_innerHTML(color, theme, icon, id, topic_name, structural)
4591
4604
  max-width: 100%; overflow: hidden; text-overflow: ellipsis;
4592
4605
  display: -webkit-box; -webkit-line-clamp: 2;
4593
4606
  -webkit-box-orient: vertical; word-break: break-word;
4594
- ">${escapeHtml(id)}</div>${sub_html}
4607
+ ">${escapeHtml(label)}</div>${sub_html}
4595
4608
  </div>
4596
4609
  `;
4597
4610
  }
@@ -4945,8 +4958,9 @@ function apply_node_properties(gobj, node_id, fill, stroke, lineWidth, scope)
4945
4958
  if(nd.data.desc.node_treedb_type === 'hierarchical') {
4946
4959
  let record = nd.data.record || {};
4947
4960
  updateStyle.innerHTML = build_node_innerHTML(
4948
- fill, priv.theme, record.icon, record.id,
4949
- nd.data.desc.topic_name
4961
+ fill, priv.theme, record.icon,
4962
+ node_label(nd.data.desc, record),
4963
+ nd.data.desc.topic_name, false, record.id
4950
4964
  );
4951
4965
  }
4952
4966
  updates.push({ id: nodes[i].id, style: updateStyle });
@@ -115,6 +115,7 @@ SDATA(data_type_t.DTP_POINTER, "gobj_remote_yuno", 0, null, "Remote Yuno to
115
115
  SDATA(data_type_t.DTP_STRING, "treedb_name", 0, null, "Remote service treedb name"),
116
116
  SDATA(data_type_t.DTP_DICT, "descs", 0, null, "Descriptions of topics obtained"),
117
117
  SDATA(data_type_t.DTP_BOOLEAN, "system", 0, false, "Manage system topics (true) or user topics (false)"),
118
+ SDATA(data_type_t.DTP_BOOLEAN, "readonly", 0, false, "The whole treedb is read-only: the graph drops its `edition` mode (the only one that draws write affordances) and refuses every write event. Set it when this yuno is not the MASTER of the treedb's tranger -- only the master can write, and the yuno answers 'READ-ONLY' to a write since SDK 7.13.0 (ask `treedb-info`)"),
118
119
  SDATA(data_type_t.DTP_STRING, "back_route", 0, "", "Optional hash route for a '← topics' button back to the topics grid (host-supplied; empty = no button)"),
119
120
  SDATA(data_type_t.DTP_STRING, "base_route", 0, "", "This view's base route (host-supplied); used to declare its per-topic focus sub-routes to the site map (ROUTING.md contributor)."),
120
121
  SDATA(data_type_t.DTP_DICT, "records", 0, "{}", "Data of topics"),
@@ -193,6 +194,16 @@ function mt_create(gobj)
193
194
  log_error(`${gobj_name(gobj)} -> treedb_name not configured`);
194
195
  }
195
196
 
197
+ /*
198
+ * `edition` is the ONLY mode that draws write affordances, and the
199
+ * mode is a PERSISTED user preference: a graph that was left in
200
+ * edition on a master would come back in edition on a replica.
201
+ * Fall back to `reading` before the G6 child is born with it.
202
+ */
203
+ if(gobj_read_bool_attr(gobj, "readonly") && priv.operation_mode === "edition") {
204
+ gobj_write_str_attr(gobj, "operation_mode", "reading");
205
+ }
206
+
196
207
  /*
197
208
  * set canvas_id, before build_ui()
198
209
  */
@@ -433,6 +444,11 @@ function make_toolbar(gobj)
433
444
  * Top Header toolbar
434
445
  *---------------------------------------*/
435
446
  let modes = gobj_read_attr(gobj, "operation_modes");
447
+ if(gobj_read_bool_attr(gobj, "readonly")) {
448
+ /* A mode the user cannot have is not offered: `edition` is the
449
+ * one that draws the create / delete / link affordances. */
450
+ modes = modes.filter(mode => mode !== "edition");
451
+ }
436
452
  let mode_options = modes.map(item => ['option', {}, item]);
437
453
 
438
454
  /*
@@ -1342,6 +1358,24 @@ function refresh_data(gobj)
1342
1358
  request_treedb_descs(gobj);
1343
1359
  }
1344
1360
 
1361
+ /********************************************
1362
+ * The last gate before a write leaves for the yuno. The `edition`
1363
+ * mode is gone on a replica, so no button can raise these -- but the
1364
+ * G6 child also publishes them from its undo/redo history and from
1365
+ * saving the node geometry, and a write that got this far would
1366
+ * travel, be refused by the yuno, and come back as a toast with the
1367
+ * graph already redrawn.
1368
+ ********************************************/
1369
+ function refuse_if_readonly(gobj, event)
1370
+ {
1371
+ if(!gobj_read_bool_attr(gobj, "readonly")) {
1372
+ return false;
1373
+ }
1374
+ log_error(`${gobj_short_name(gobj)}: ${event} refused, treedb ` +
1375
+ `'${gobj_read_str_attr(gobj, "treedb_name")}' is READ-ONLY`);
1376
+ return true;
1377
+ }
1378
+
1345
1379
 
1346
1380
 
1347
1381
 
@@ -1468,7 +1502,36 @@ function ac_mt_command_answer(gobj, event, kw, src)
1468
1502
  case "delete-node":
1469
1503
  case "link-nodes":
1470
1504
  case "unlink-nodes":
1471
- // Don't process here, process on subscribed events.
1505
+ /*
1506
+ * The graph redraws itself from the treedb's own EV_TREEDB_NODE_*
1507
+ * events, which arrive for EVERY writer. This says what those
1508
+ * cannot: THIS view has just written, and the yuno took it. A host
1509
+ * whose save is not finished with the record -- a schema editor,
1510
+ * where the yuno still has to be restarted to re-read the schema --
1511
+ * needs exactly that, and cannot use the node events without
1512
+ * answering its own writes in a loop.
1513
+ *
1514
+ * Same event and same kw as C_YUI_TREEDB_TOPICS, plus `command`:
1515
+ * in a graph a LINK is as much a write as a record is, and the
1516
+ * three of them carry different halves of the kw.
1517
+ *
1518
+ * `__graphs__` is EXCLUDED, and that exclusion is the point of
1519
+ * reading this comment: the view writes that topic ITSELF, one
1520
+ * record per topic, every time the layout is saved. It is this
1521
+ * view's bookkeeping, not the operator's data -- reporting it
1522
+ * would tell a schema editor that the schema changed because
1523
+ * somebody dragged a node.
1524
+ */
1525
+ if(result >= 0 &&
1526
+ kw_get_str(gobj, kw_command, "topic_name", "", 0) !== "__graphs__") {
1527
+ gobj_publish_event(gobj, "EV_RECORD_WRITTEN", {
1528
+ treedb_name: kw_get_str(gobj, kw_command, "treedb_name", "", 0),
1529
+ topic_name: kw_get_str(gobj, kw_command, "topic_name", "", 0),
1530
+ record: kw_get_dict(gobj, kw_command, "record", {}, 0),
1531
+ created: (command === "create-node"),
1532
+ command: command
1533
+ });
1534
+ }
1472
1535
  break;
1473
1536
 
1474
1537
  default:
@@ -1787,6 +1850,11 @@ function ac_edge_clicked(gobj, event, kw, src)
1787
1850
  function ac_create_node(gobj, event, kw, src)
1788
1851
  {
1789
1852
  let priv = gobj.priv;
1853
+
1854
+ if(refuse_if_readonly(gobj, event)) {
1855
+ return -1;
1856
+ }
1857
+
1790
1858
  let treedb_name = priv.treedb_name;
1791
1859
  let topic_name = kw.topic_name;
1792
1860
  let record = kw.record;
@@ -1813,6 +1881,11 @@ function ac_create_node(gobj, event, kw, src)
1813
1881
  function ac_update_node(gobj, event, kw, src)
1814
1882
  {
1815
1883
  let priv = gobj.priv;
1884
+
1885
+ if(refuse_if_readonly(gobj, event)) {
1886
+ return -1;
1887
+ }
1888
+
1816
1889
  let treedb_name = priv.treedb_name;
1817
1890
  let topic_name = kw.topic_name;
1818
1891
  let record = kw.record;
@@ -1839,6 +1912,11 @@ function ac_update_node(gobj, event, kw, src)
1839
1912
  function ac_delete_node(gobj, event, kw, src)
1840
1913
  {
1841
1914
  let priv = gobj.priv;
1915
+
1916
+ if(refuse_if_readonly(gobj, event)) {
1917
+ return -1;
1918
+ }
1919
+
1842
1920
  let treedb_name = priv.treedb_name;
1843
1921
  let topic_name = kw.topic_name;
1844
1922
  let record = kw.record;
@@ -1865,6 +1943,11 @@ function ac_delete_node(gobj, event, kw, src)
1865
1943
  function ac_link_nodes(gobj, event, kw, src)
1866
1944
  {
1867
1945
  let priv = gobj.priv;
1946
+
1947
+ if(refuse_if_readonly(gobj, event)) {
1948
+ return -1;
1949
+ }
1950
+
1868
1951
  let treedb_name = priv.treedb_name;
1869
1952
  let parent_ref = kw.parent_ref;
1870
1953
  let child_ref = kw.child_ref;
@@ -1891,6 +1974,11 @@ function ac_link_nodes(gobj, event, kw, src)
1891
1974
  function ac_unlink_nodes(gobj, event, kw, src)
1892
1975
  {
1893
1976
  let priv = gobj.priv;
1977
+
1978
+ if(refuse_if_readonly(gobj, event)) {
1979
+ return -1;
1980
+ }
1981
+
1894
1982
  let treedb_name = priv.treedb_name;
1895
1983
  let parent_ref = kw.parent_ref;
1896
1984
  let child_ref = kw.child_ref;
@@ -2001,6 +2089,14 @@ function ac_set_operation_mode(gobj, event, kw, src)
2001
2089
  let priv = gobj.priv;
2002
2090
 
2003
2091
  let operation_mode = kw.operation_mode;
2092
+ if(operation_mode === "edition" && gobj_read_bool_attr(gobj, "readonly")) {
2093
+ /* The select does not offer it on a replica, so getting here means
2094
+ * the event came from somewhere else -- and it is the mode that
2095
+ * turns on every write affordance. */
2096
+ log_error(`${gobj_short_name(gobj)}: edition mode refused, treedb ` +
2097
+ `'${gobj_read_str_attr(gobj, "treedb_name")}' is READ-ONLY`);
2098
+ return -1;
2099
+ }
2004
2100
  gobj_write_str_attr(gobj, "operation_mode", operation_mode);
2005
2101
  gobj_save_persistent_attrs(gobj, "operation_mode");
2006
2102
 
@@ -2168,6 +2264,8 @@ function create_gclass(gclass_name)
2168
2264
  ["EV_SET_FOCUS_TOPIC", 0],
2169
2265
  ["EV_OPERATION_MODE_CHANGED",
2170
2266
  event_flag_t.EVF_OUTPUT_EVENT | event_flag_t.EVF_NO_WARN_SUBS],
2267
+ ["EV_RECORD_WRITTEN",
2268
+ event_flag_t.EVF_OUTPUT_EVENT | event_flag_t.EVF_NO_WARN_SUBS],
2171
2269
  ["EV_SHOW", 0],
2172
2270
  ["EV_HIDE", 0],
2173
2271
  ["EV_TRANSPORT_STATE", 0],