@yuneta/gobj-ui 7.23.132 → 7.23.134
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/gobj-ui.cjs.js +313 -89
- package/dist/gobj-ui.es.js +313 -89
- package/package.json +1 -1
- package/src/c_g6_nodes_tree.js +428 -112
package/dist/gobj-ui.es.js
CHANGED
|
@@ -55075,7 +55075,7 @@ var NODE_SHAPES = [
|
|
|
55075
55075
|
"hexagon",
|
|
55076
55076
|
"star"
|
|
55077
55077
|
];
|
|
55078
|
-
var DEFAULT_NODE_SHAPE = "
|
|
55078
|
+
var DEFAULT_NODE_SHAPE = "circle";
|
|
55079
55079
|
/***************************************************************
|
|
55080
55080
|
* Internal layout and operation mode definitions
|
|
55081
55081
|
***************************************************************/
|
|
@@ -55228,6 +55228,7 @@ var PRIVATE_DATA$4 = {
|
|
|
55228
55228
|
_focus_topic: null,
|
|
55229
55229
|
_focus_ids: [],
|
|
55230
55230
|
_on_pointerdown_focus: null,
|
|
55231
|
+
_on_native_contextmenu: null,
|
|
55231
55232
|
_uninstall_long_press: null,
|
|
55232
55233
|
toolbar_collapsed: true,
|
|
55233
55234
|
_toolbars_could_collapse: null,
|
|
@@ -55325,6 +55326,10 @@ function mt_destroy$4(gobj) {
|
|
|
55325
55326
|
priv.$container.removeEventListener("focusout", priv._on_focusout_restore);
|
|
55326
55327
|
priv._on_focusout_restore = null;
|
|
55327
55328
|
}
|
|
55329
|
+
if (priv._on_native_contextmenu) {
|
|
55330
|
+
priv.$container.removeEventListener("contextmenu", priv._on_native_contextmenu, true);
|
|
55331
|
+
priv._on_native_contextmenu = null;
|
|
55332
|
+
}
|
|
55328
55333
|
if (priv.theme_observer) {
|
|
55329
55334
|
priv.theme_observer.disconnect();
|
|
55330
55335
|
priv.theme_observer = null;
|
|
@@ -55528,6 +55533,13 @@ function configure_events(gobj) {
|
|
|
55528
55533
|
if ($canvas && $canvas.isConnected && document.activeElement !== $canvas) $canvas.focus({ preventScroll: true });
|
|
55529
55534
|
};
|
|
55530
55535
|
priv.$container.addEventListener("focusout", priv._on_focusout_restore);
|
|
55536
|
+
if (priv._on_native_contextmenu) priv.$container.removeEventListener("contextmenu", priv._on_native_contextmenu, true);
|
|
55537
|
+
priv._on_native_contextmenu = (ev) => {
|
|
55538
|
+
let target = ev.target;
|
|
55539
|
+
if (target && typeof target.closest === "function" && target.closest("input, textarea, select, [contenteditable]")) return;
|
|
55540
|
+
ev.preventDefault();
|
|
55541
|
+
};
|
|
55542
|
+
priv.$container.addEventListener("contextmenu", priv._on_native_contextmenu, true);
|
|
55531
55543
|
graph.on("keydown", (evt) => {
|
|
55532
55544
|
let ctrl = !!(evt.ctrlKey || evt.metaKey);
|
|
55533
55545
|
if (ctrl && (evt.key === "a" || evt.key === "A")) {
|
|
@@ -55561,7 +55573,8 @@ function configure_plugins(gobj) {
|
|
|
55561
55573
|
}
|
|
55562
55574
|
});
|
|
55563
55575
|
let menu_enable = (e) => {
|
|
55564
|
-
|
|
55576
|
+
if (e.targetType === "node") return true;
|
|
55577
|
+
return e.targetType === "edge" && !!priv.edit_mode;
|
|
55565
55578
|
};
|
|
55566
55579
|
graph_add_plugin(gobj, "contextmenu", {
|
|
55567
55580
|
trigger: "contextmenu",
|
|
@@ -56397,11 +56410,8 @@ function figure_shape_of(gobj, desc, record, geometry, flags) {
|
|
|
56397
56410
|
let paint = node_paint_of(gobj, desc, geometry);
|
|
56398
56411
|
let fill = dark ? mix_colors(paint.fill, .25, "#2c3542") : mix_colors(paint.fill, .1, "#ffffff");
|
|
56399
56412
|
let stroke = dark ? mix_colors(paint.fill, .85, "#ffffff") : paint.fill;
|
|
56400
|
-
let line_width =
|
|
56401
|
-
if (paint.stroke !== getStrokeColor(paint.fill))
|
|
56402
|
-
stroke = paint.stroke;
|
|
56403
|
-
line_width = Math.max(paint.lineWidth, 2);
|
|
56404
|
-
}
|
|
56413
|
+
let line_width = paint.lineWidth;
|
|
56414
|
+
if (paint.stroke !== getStrokeColor(paint.fill)) stroke = paint.stroke;
|
|
56405
56415
|
if (f.selected) {
|
|
56406
56416
|
stroke = SELECT_RING;
|
|
56407
56417
|
line_width = 3;
|
|
@@ -56630,42 +56640,17 @@ function draw_link(gobj, child_topic, child_id, source_col, fkey, verbose) {
|
|
|
56630
56640
|
return;
|
|
56631
56641
|
}
|
|
56632
56642
|
if (get_edge_by_link(gobj, parent_topic, parent_id, hook_name, child_topic, child_id, fkey_name)) return;
|
|
56633
|
-
let dark = priv.theme === "dark";
|
|
56634
56643
|
let is_tree = parent_topic === child_topic;
|
|
56635
|
-
let
|
|
56636
|
-
|
|
56637
|
-
|
|
56638
|
-
|
|
56639
|
-
|
|
56640
|
-
|
|
56641
|
-
|
|
56642
|
-
|
|
56643
|
-
|
|
56644
|
-
|
|
56645
|
-
if (edge_props.stroke) {
|
|
56646
|
-
saved_stroke = edge_props.stroke;
|
|
56647
|
-
themed_default = false;
|
|
56648
|
-
}
|
|
56649
|
-
}
|
|
56650
|
-
}
|
|
56651
|
-
if (themed_default && is_object(topic_props.defaults)) {
|
|
56652
|
-
let defs = topic_props.defaults;
|
|
56653
|
-
if (defs.edge_styles && defs.edge_styles[hook_name]) {
|
|
56654
|
-
let hook_style = defs.edge_styles[hook_name];
|
|
56655
|
-
if (hook_style.lineWidth != null) saved_lineWidth = hook_style.lineWidth;
|
|
56656
|
-
if (hook_style.stroke) {
|
|
56657
|
-
saved_stroke = hook_style.stroke;
|
|
56658
|
-
themed_default = false;
|
|
56659
|
-
}
|
|
56660
|
-
} else if (defs.edge_style) {
|
|
56661
|
-
if (defs.edge_style.lineWidth != null) saved_lineWidth = defs.edge_style.lineWidth;
|
|
56662
|
-
if (defs.edge_style.stroke) {
|
|
56663
|
-
saved_stroke = defs.edge_style.stroke;
|
|
56664
|
-
themed_default = false;
|
|
56665
|
-
}
|
|
56666
|
-
}
|
|
56667
|
-
}
|
|
56668
|
-
}
|
|
56644
|
+
let edge_style = edge_style_of(gobj, {
|
|
56645
|
+
parent_topic,
|
|
56646
|
+
parent_id,
|
|
56647
|
+
hook_name,
|
|
56648
|
+
child_id,
|
|
56649
|
+
is_tree
|
|
56650
|
+
});
|
|
56651
|
+
let saved_lineWidth = edge_style.lineWidth;
|
|
56652
|
+
let saved_stroke = edge_style.stroke;
|
|
56653
|
+
let themed_default = edge_style.themed_default;
|
|
56669
56654
|
let edge = {
|
|
56670
56655
|
id: build_edge_id(gobj),
|
|
56671
56656
|
type: edge_type_for(gobj),
|
|
@@ -59353,6 +59338,7 @@ function show_node_popover(gobj) {
|
|
|
59353
59338
|
};
|
|
59354
59339
|
}));
|
|
59355
59340
|
shapeSelect.value = nodeData.data && nodeData.data.desc ? node_figure_of(gobj, nodeData.data.desc, nodeData.data.graph_props || {}) : DEFAULT_NODE_SHAPE;
|
|
59341
|
+
let orig_figure = shapeSelect.value;
|
|
59356
59342
|
create_form_label(popover, "apply to");
|
|
59357
59343
|
let scopeSelect = create_form_select(popover, [
|
|
59358
59344
|
{
|
|
@@ -59379,7 +59365,7 @@ function show_node_popover(gobj) {
|
|
|
59379
59365
|
style: "flex:1;padding:6px;background:#1890ff;color:#fff;border:none;border-radius:4px;cursor:pointer;font-size:13px;font-weight:500;",
|
|
59380
59366
|
onClick: () => {
|
|
59381
59367
|
drop_preview_undo(gobj, "_node_preview_undo");
|
|
59382
|
-
apply_node_properties(gobj, node_id, fillInput.value, strokeInput.value, parseInt(lwInput.value) || 1, scopeSelect.value, shapeSelect.value);
|
|
59368
|
+
apply_node_properties(gobj, node_id, fillInput.value, strokeInput.value, parseInt(lwInput.value) || 1, scopeSelect.value, shapeSelect.value !== orig_figure ? shapeSelect.value : "");
|
|
59383
59369
|
}
|
|
59384
59370
|
}]);
|
|
59385
59371
|
priv.$container.appendChild(popover);
|
|
@@ -60264,19 +60250,81 @@ function apply_edge_properties(gobj, edge_id, lineWidth, stroke, scope) {
|
|
|
60264
60250
|
deselect_edge(gobj);
|
|
60265
60251
|
}
|
|
60266
60252
|
/************************************************************
|
|
60253
|
+
* The style an edge INHERITS, before anything saved for the
|
|
60254
|
+
* edge itself: its hook's default in the parent topic, else the
|
|
60255
|
+
* parent topic's default for every edge, else the library's.
|
|
60256
|
+
*
|
|
60257
|
+
* The library's: neutral grey, teal for the containment/tree
|
|
60258
|
+
* relation (parent and child of the same topic, a
|
|
60259
|
+
* self-hierarchy). `themed_default` says the colour is still the
|
|
60260
|
+
* library's, so a theme toggle re-themes it and leaves a chosen
|
|
60261
|
+
* one alone.
|
|
60262
|
+
************************************************************/
|
|
60263
|
+
function edge_inherited_style_of(gobj, d) {
|
|
60264
|
+
let dark = gobj.priv.theme === "dark";
|
|
60265
|
+
let style = {
|
|
60266
|
+
lineWidth: d.is_tree ? 2 : 1.6,
|
|
60267
|
+
stroke: d.is_tree ? dark ? "#22a7c2" : "#0e7490" : dark ? "#8b94a3" : "#6b7280",
|
|
60268
|
+
themed_default: true
|
|
60269
|
+
};
|
|
60270
|
+
let defs = topic_defaults_of(gobj, d.parent_topic);
|
|
60271
|
+
if (!defs) return style;
|
|
60272
|
+
let chosen = null;
|
|
60273
|
+
if (is_object(defs.edge_styles) && is_object(defs.edge_styles[d.hook_name])) chosen = defs.edge_styles[d.hook_name];
|
|
60274
|
+
else if (is_object(defs.edge_style)) chosen = defs.edge_style;
|
|
60275
|
+
if (chosen) {
|
|
60276
|
+
if (chosen.lineWidth != null) style.lineWidth = chosen.lineWidth;
|
|
60277
|
+
if (chosen.stroke) {
|
|
60278
|
+
style.stroke = chosen.stroke;
|
|
60279
|
+
style.themed_default = false;
|
|
60280
|
+
}
|
|
60281
|
+
}
|
|
60282
|
+
return style;
|
|
60283
|
+
}
|
|
60284
|
+
function edge_key_of(d) {
|
|
60285
|
+
return d.hook_name + ":" + d.parent_id + ":" + d.child_id;
|
|
60286
|
+
}
|
|
60287
|
+
/************************************************************
|
|
60288
|
+
* The style an edge WEARS: what it inherits, with what was saved
|
|
60289
|
+
* for the edge itself on top.
|
|
60290
|
+
************************************************************/
|
|
60291
|
+
function edge_style_of(gobj, d) {
|
|
60292
|
+
let style = edge_inherited_style_of(gobj, d);
|
|
60293
|
+
let topic_props = gobj.priv._graph_properties[d.parent_topic];
|
|
60294
|
+
let own = is_object(topic_props) && is_object(topic_props.edges) ? topic_props.edges[edge_key_of(d)] : null;
|
|
60295
|
+
if (is_object(own)) {
|
|
60296
|
+
if (own.lineWidth != null) style.lineWidth = own.lineWidth;
|
|
60297
|
+
if (own.stroke) {
|
|
60298
|
+
style.stroke = own.stroke;
|
|
60299
|
+
style.themed_default = false;
|
|
60300
|
+
}
|
|
60301
|
+
}
|
|
60302
|
+
return style;
|
|
60303
|
+
}
|
|
60304
|
+
/************************************************************
|
|
60267
60305
|
* Save edge styles into _graph_properties (called from
|
|
60268
60306
|
* save_geometry).
|
|
60307
|
+
*
|
|
60308
|
+
* Only what differs from what the edge INHERITS is written. It
|
|
60309
|
+
* used to be "any line width but 2", and the library's own width
|
|
60310
|
+
* for an edge between two topics is 1.6: every Save wrote every
|
|
60311
|
+
* such edge down with its width and its theme's colour, so the
|
|
60312
|
+
* default was frozen on it -- a theme toggle no longer re-themed
|
|
60313
|
+
* it after a reload, and a topic default never reached it.
|
|
60269
60314
|
************************************************************/
|
|
60270
60315
|
function update_edge_geometry(gobj, edge_id) {
|
|
60271
60316
|
let priv = gobj.priv;
|
|
60272
60317
|
let edgeData = priv.graph.getEdgeData(edge_id);
|
|
60273
60318
|
if (!edgeData || !edgeData.data || !edgeData.data.parent_topic) return;
|
|
60274
60319
|
let style = edgeData.style || {};
|
|
60275
|
-
let
|
|
60276
|
-
let
|
|
60277
|
-
let parent_topic =
|
|
60278
|
-
let edge_key =
|
|
60279
|
-
|
|
60320
|
+
let d = edgeData.data;
|
|
60321
|
+
let inherited = edge_inherited_style_of(gobj, d);
|
|
60322
|
+
let parent_topic = d.parent_topic;
|
|
60323
|
+
let edge_key = edge_key_of(d);
|
|
60324
|
+
let edge_props = {};
|
|
60325
|
+
if (style.lineWidth != null && style.lineWidth !== inherited.lineWidth) edge_props.lineWidth = style.lineWidth;
|
|
60326
|
+
if (style.stroke && style.stroke !== inherited.stroke) edge_props.stroke = style.stroke;
|
|
60327
|
+
if (Object.keys(edge_props).length === 0) {
|
|
60280
60328
|
let topic_props = priv._graph_properties[parent_topic];
|
|
60281
60329
|
if (topic_props && is_object(topic_props.edges)) {
|
|
60282
60330
|
delete topic_props.edges[edge_key];
|
|
@@ -60287,8 +60335,6 @@ function update_edge_geometry(gobj, edge_id) {
|
|
|
60287
60335
|
if (!is_object(priv._graph_properties[parent_topic])) priv._graph_properties[parent_topic] = {};
|
|
60288
60336
|
let topic_props = priv._graph_properties[parent_topic];
|
|
60289
60337
|
if (!is_object(topic_props.edges)) topic_props.edges = {};
|
|
60290
|
-
let edge_props = { lineWidth };
|
|
60291
|
-
if (stroke) edge_props.stroke = stroke;
|
|
60292
60338
|
topic_props.edges[edge_key] = edge_props;
|
|
60293
60339
|
}
|
|
60294
60340
|
/************************************************************
|
|
@@ -60312,7 +60358,7 @@ function build_context_menu_items(gobj, e) {
|
|
|
60312
60358
|
let containerRect = priv.$container.getBoundingClientRect();
|
|
60313
60359
|
let canvasPoint = graph.getCanvasByViewport([e.client.x - containerRect.left, e.client.y - containerRect.top]);
|
|
60314
60360
|
let port_key = detect_port_click(gobj, node_id, canvasPoint[0], canvasPoint[1]);
|
|
60315
|
-
if (port_key) {
|
|
60361
|
+
if (port_key && priv.edit_mode) {
|
|
60316
60362
|
priv._context_port_key = port_key;
|
|
60317
60363
|
return build_port_context_menu(gobj, node_id, port_key);
|
|
60318
60364
|
} else return build_node_context_menu(gobj, node_id);
|
|
@@ -60342,8 +60388,11 @@ function build_node_context_menu(gobj, node_id) {
|
|
|
60342
60388
|
if (gobj.priv.edit_mode && !node_is_compact(gobj, node_id)) {
|
|
60343
60389
|
items.push(ctx_item("g6-icon-resize", t("resize all"), "resize_all_nodes"));
|
|
60344
60390
|
items.push(ctx_item("g6-icon-resize", t("resize topic nodes"), "resize_topic_nodes"));
|
|
60345
|
-
|
|
60346
|
-
|
|
60391
|
+
}
|
|
60392
|
+
if (gobj.priv.edit_mode) {
|
|
60393
|
+
items.push(ctx_item("g6-icon-undo", t("reset node"), "reset_node"));
|
|
60394
|
+
items.push(ctx_item("g6-icon-undo", t("reset topic nodes"), "reset_topic_nodes"));
|
|
60395
|
+
items.push(ctx_item("g6-icon-undo", t("reset all nodes"), "reset_all_nodes"));
|
|
60347
60396
|
}
|
|
60348
60397
|
return items;
|
|
60349
60398
|
}
|
|
@@ -60357,14 +60406,27 @@ function build_port_context_menu(gobj, node_id, port_key) {
|
|
|
60357
60406
|
items.push(ctx_item("g6-icon-edit", t("port properties"), "port_properties"));
|
|
60358
60407
|
items.push(ctx_item("g6-icon-resize", t("resize all ports"), "resize_all_ports"));
|
|
60359
60408
|
items.push(ctx_item("g6-icon-resize", t("resize topic ports"), "resize_topic_ports"));
|
|
60409
|
+
items.push(ctx_item("g6-icon-undo", t("reset port"), "reset_port"));
|
|
60410
|
+
items.push(ctx_item("g6-icon-undo", t("reset topic ports"), "reset_topic_ports"));
|
|
60411
|
+
items.push(ctx_item("g6-icon-undo", t("reset all ports"), "reset_all_ports"));
|
|
60360
60412
|
}
|
|
60361
60413
|
return items;
|
|
60362
60414
|
}
|
|
60363
60415
|
/************************************************************
|
|
60364
|
-
* Build edge context menu items
|
|
60416
|
+
* Build edge context menu items: the two floating icons of a
|
|
60417
|
+
* selected edge, for a right click and for a finger.
|
|
60365
60418
|
************************************************************/
|
|
60366
60419
|
function build_edge_context_menu(gobj) {
|
|
60367
|
-
|
|
60420
|
+
let items = [];
|
|
60421
|
+
if (gobj.priv.edit_mode) {
|
|
60422
|
+
inject_svg_icons();
|
|
60423
|
+
items.push(ctx_item("g6-icon-edit", t("edge properties"), "edge_properties"));
|
|
60424
|
+
items.push(ctx_item("g6-icon-delete", t("unlink"), "unlink_edge"));
|
|
60425
|
+
items.push(ctx_item("g6-icon-undo", t("reset edge"), "reset_edge"));
|
|
60426
|
+
items.push(ctx_item("g6-icon-undo", t("reset same type edges"), "reset_same_type_edges"));
|
|
60427
|
+
items.push(ctx_item("g6-icon-undo", t("reset all edges"), "reset_all_edges"));
|
|
60428
|
+
}
|
|
60429
|
+
return items;
|
|
60368
60430
|
}
|
|
60369
60431
|
/************************************************************
|
|
60370
60432
|
* Handle context menu click: dispatch by value.
|
|
@@ -60381,11 +60443,23 @@ function handle_context_menu_click(gobj, value) {
|
|
|
60381
60443
|
case "resize_topic_nodes":
|
|
60382
60444
|
copy_size_to_nodes(gobj, true);
|
|
60383
60445
|
break;
|
|
60384
|
-
case "
|
|
60385
|
-
|
|
60446
|
+
case "reset_node":
|
|
60447
|
+
reset_nodes(gobj, "this");
|
|
60448
|
+
break;
|
|
60449
|
+
case "reset_topic_nodes":
|
|
60450
|
+
reset_nodes(gobj, "same_topic");
|
|
60451
|
+
break;
|
|
60452
|
+
case "reset_all_nodes":
|
|
60453
|
+
reset_nodes(gobj, "all");
|
|
60454
|
+
break;
|
|
60455
|
+
case "reset_edge":
|
|
60456
|
+
reset_edges(gobj, "this");
|
|
60386
60457
|
break;
|
|
60387
|
-
case "
|
|
60388
|
-
|
|
60458
|
+
case "reset_same_type_edges":
|
|
60459
|
+
reset_edges(gobj, "same_type");
|
|
60460
|
+
break;
|
|
60461
|
+
case "reset_all_edges":
|
|
60462
|
+
reset_edges(gobj, "all");
|
|
60389
60463
|
break;
|
|
60390
60464
|
case "port_properties":
|
|
60391
60465
|
if (priv._context_node_id && priv._context_port_key) {
|
|
@@ -60396,7 +60470,33 @@ function handle_context_menu_click(gobj, value) {
|
|
|
60396
60470
|
case "resize_all_ports":
|
|
60397
60471
|
copy_size_to_ports(gobj, false);
|
|
60398
60472
|
break;
|
|
60399
|
-
case "resize_topic_ports":
|
|
60473
|
+
case "resize_topic_ports":
|
|
60474
|
+
copy_size_to_ports(gobj, true);
|
|
60475
|
+
break;
|
|
60476
|
+
case "reset_port":
|
|
60477
|
+
reset_ports(gobj, "this");
|
|
60478
|
+
break;
|
|
60479
|
+
case "reset_topic_ports":
|
|
60480
|
+
reset_ports(gobj, "same_topic");
|
|
60481
|
+
break;
|
|
60482
|
+
case "reset_all_ports":
|
|
60483
|
+
reset_ports(gobj, "all");
|
|
60484
|
+
break;
|
|
60485
|
+
case "edge_properties":
|
|
60486
|
+
if (priv._context_edge_id) {
|
|
60487
|
+
deselect_node(gobj);
|
|
60488
|
+
select_edge(gobj, priv._context_edge_id);
|
|
60489
|
+
show_edge_popover(gobj);
|
|
60490
|
+
}
|
|
60491
|
+
break;
|
|
60492
|
+
case "unlink_edge":
|
|
60493
|
+
if (priv._context_edge_id) {
|
|
60494
|
+
deselect_node(gobj);
|
|
60495
|
+
select_edge(gobj, priv._context_edge_id);
|
|
60496
|
+
request_unlink_edge(gobj);
|
|
60497
|
+
}
|
|
60498
|
+
break;
|
|
60499
|
+
default: log_error(`${gobj_short_name(gobj)}: unknown context menu item: ${value}`);
|
|
60400
60500
|
}
|
|
60401
60501
|
}
|
|
60402
60502
|
/************************************************************
|
|
@@ -60453,53 +60553,177 @@ function copy_size_to_nodes(gobj, same_topic_only) {
|
|
|
60453
60553
|
});
|
|
60454
60554
|
}
|
|
60455
60555
|
}
|
|
60556
|
+
var NODE_STYLE_KEYS = [
|
|
60557
|
+
"size",
|
|
60558
|
+
"fill",
|
|
60559
|
+
"stroke",
|
|
60560
|
+
"lineWidth",
|
|
60561
|
+
"node_shape"
|
|
60562
|
+
];
|
|
60563
|
+
var PORT_STYLE_KEYS = [
|
|
60564
|
+
"portR",
|
|
60565
|
+
"port_sizes",
|
|
60566
|
+
"port_shapes",
|
|
60567
|
+
"port_shape"
|
|
60568
|
+
];
|
|
60456
60569
|
/************************************************************
|
|
60457
|
-
* Forget
|
|
60458
|
-
*
|
|
60459
|
-
*
|
|
60460
|
-
*
|
|
60461
|
-
*
|
|
60462
|
-
*
|
|
60463
|
-
* they are a different choice.
|
|
60570
|
+
* Forget these saved keys -- on the node of the menu alone
|
|
60571
|
+
* ('this'), or on every node of its topic and in the topic's
|
|
60572
|
+
* defaults ('same_topic'), or everywhere ('all'). Both copies of
|
|
60573
|
+
* an entry are stripped: the one in `_graph_properties` (which
|
|
60574
|
+
* Save writes, folded nodes included) and the one the node
|
|
60575
|
+
* carries. Returns the ids of the nodes on screen to reshape.
|
|
60464
60576
|
************************************************************/
|
|
60465
|
-
function
|
|
60577
|
+
function forget_saved_node_keys(gobj, nd, scope, keys) {
|
|
60466
60578
|
let priv = gobj.priv;
|
|
60467
60579
|
let graph = priv.graph;
|
|
60468
|
-
let topic = "";
|
|
60469
|
-
if (same_topic_only) {
|
|
60470
|
-
let nd = priv._context_node_id ? graph.getNodeData(priv._context_node_id) : null;
|
|
60471
|
-
if (!nd || !nd.data || !nd.data.topic_name) {
|
|
60472
|
-
log_error(`${gobj_short_name(gobj)}: reset topic sizes without a node`);
|
|
60473
|
-
return;
|
|
60474
|
-
}
|
|
60475
|
-
topic = nd.data.topic_name;
|
|
60476
|
-
}
|
|
60477
|
-
const SIZE_KEYS = [
|
|
60478
|
-
"size",
|
|
60479
|
-
"portR",
|
|
60480
|
-
"port_sizes"
|
|
60481
|
-
];
|
|
60482
60580
|
let strip = (props) => {
|
|
60483
60581
|
if (!is_object(props)) return;
|
|
60484
|
-
for (let k of
|
|
60582
|
+
for (let k of keys) delete props[k];
|
|
60485
60583
|
};
|
|
60584
|
+
if (scope === "this") {
|
|
60585
|
+
strip(node_props_entry(gobj, nd));
|
|
60586
|
+
strip(nd.data.graph_props);
|
|
60587
|
+
if (nd.data.record) strip(nd.data.record._geometry);
|
|
60588
|
+
return [nd.id];
|
|
60589
|
+
}
|
|
60590
|
+
let topic = scope === "same_topic" ? nd.data.topic_name : "";
|
|
60486
60591
|
for (const [topic_name, props] of Object.entries(priv._graph_properties || {})) {
|
|
60487
60592
|
if (topic && topic_name !== topic) continue;
|
|
60488
60593
|
if (is_object(props.nodes)) for (let node_props of Object.values(props.nodes)) strip(node_props);
|
|
60489
60594
|
strip(props.defaults);
|
|
60490
60595
|
}
|
|
60491
60596
|
let ids = [];
|
|
60492
|
-
for (let
|
|
60493
|
-
if (!
|
|
60494
|
-
if (topic &&
|
|
60495
|
-
strip(
|
|
60496
|
-
if (
|
|
60497
|
-
ids.push(
|
|
60597
|
+
for (let n of graph.getNodeData() || []) {
|
|
60598
|
+
if (!n || !n.data || !n.data.desc || is_more_node(n)) continue;
|
|
60599
|
+
if (topic && n.data.topic_name !== topic) continue;
|
|
60600
|
+
strip(n.data.graph_props);
|
|
60601
|
+
if (n.data.record) strip(n.data.record._geometry);
|
|
60602
|
+
ids.push(n.id);
|
|
60498
60603
|
}
|
|
60604
|
+
return ids;
|
|
60605
|
+
}
|
|
60606
|
+
function reshape_after_reset(gobj, ids) {
|
|
60607
|
+
let graph = gobj.priv.graph;
|
|
60499
60608
|
reshape_nodes(gobj, ids);
|
|
60500
60609
|
graph.draw().then(() => {
|
|
60501
60610
|
update_resize_handles_position(gobj);
|
|
60502
60611
|
update_port_resize_handles_position(gobj);
|
|
60612
|
+
update_port_icon_position(gobj);
|
|
60613
|
+
mark_graph_dirty(gobj);
|
|
60614
|
+
});
|
|
60615
|
+
}
|
|
60616
|
+
/************************************************************
|
|
60617
|
+
* Forget the saved look of nodes (NODE_STYLE_KEYS), back to the
|
|
60618
|
+
* library's: this node, its topic's, or all of them. A figure
|
|
60619
|
+
* saved as a square before the circle became the default goes
|
|
60620
|
+
* back to the default this way.
|
|
60621
|
+
************************************************************/
|
|
60622
|
+
function reset_nodes(gobj, scope) {
|
|
60623
|
+
let priv = gobj.priv;
|
|
60624
|
+
let nd = priv._context_node_id ? priv.graph.getNodeData(priv._context_node_id) : null;
|
|
60625
|
+
if (!nd || !nd.data || !nd.data.topic_name) {
|
|
60626
|
+
log_error(`${gobj_short_name(gobj)}: reset nodes without a node`);
|
|
60627
|
+
return;
|
|
60628
|
+
}
|
|
60629
|
+
reshape_after_reset(gobj, forget_saved_node_keys(gobj, nd, scope, NODE_STYLE_KEYS));
|
|
60630
|
+
}
|
|
60631
|
+
/************************************************************
|
|
60632
|
+
* Forget the saved SHAPE and RADIUS of ports, back to the
|
|
60633
|
+
* library's own:
|
|
60634
|
+
* 'this' the port of the menu, on its node only
|
|
60635
|
+
* 'same_topic' every port of the node's topic, with the
|
|
60636
|
+
* topic's port defaults
|
|
60637
|
+
* 'all' every port of every topic, likewise
|
|
60638
|
+
* The node's own look is not touched: that is `reset node`.
|
|
60639
|
+
************************************************************/
|
|
60640
|
+
function reset_ports(gobj, scope) {
|
|
60641
|
+
let priv = gobj.priv;
|
|
60642
|
+
let graph = priv.graph;
|
|
60643
|
+
let node_id = priv._context_node_id;
|
|
60644
|
+
let port_key = priv._context_port_key;
|
|
60645
|
+
let nd = node_id ? graph.getNodeData(node_id) : null;
|
|
60646
|
+
if (!nd || !nd.data || !nd.data.topic_name || !port_key) {
|
|
60647
|
+
log_error(`${gobj_short_name(gobj)}: reset ports without a port`);
|
|
60648
|
+
return;
|
|
60649
|
+
}
|
|
60650
|
+
if (scope !== "this") {
|
|
60651
|
+
reshape_after_reset(gobj, forget_saved_node_keys(gobj, nd, scope, PORT_STYLE_KEYS));
|
|
60652
|
+
return;
|
|
60653
|
+
}
|
|
60654
|
+
let strip_port = (props) => {
|
|
60655
|
+
if (!is_object(props)) return;
|
|
60656
|
+
for (let k of ["port_sizes", "port_shapes"]) if (is_object(props[k])) {
|
|
60657
|
+
delete props[k][port_key];
|
|
60658
|
+
if (Object.keys(props[k]).length === 0) delete props[k];
|
|
60659
|
+
}
|
|
60660
|
+
};
|
|
60661
|
+
strip_port(node_props_entry(gobj, nd));
|
|
60662
|
+
strip_port(nd.data.graph_props);
|
|
60663
|
+
if (nd.data.record) strip_port(nd.data.record._geometry);
|
|
60664
|
+
reshape_after_reset(gobj, [node_id]);
|
|
60665
|
+
}
|
|
60666
|
+
/************************************************************
|
|
60667
|
+
* Forget the saved style of edges, back to what they inherit:
|
|
60668
|
+
* 'this' the edge of the menu, its own entry
|
|
60669
|
+
* 'same_type' every edge of its hook in its parent topic,
|
|
60670
|
+
* with that hook's default
|
|
60671
|
+
* 'all' every edge, with every edge default
|
|
60672
|
+
* The same three scopes as the edge properties popover.
|
|
60673
|
+
************************************************************/
|
|
60674
|
+
function reset_edges(gobj, scope) {
|
|
60675
|
+
let priv = gobj.priv;
|
|
60676
|
+
let graph = priv.graph;
|
|
60677
|
+
let ed = priv._context_edge_id ? graph.getEdgeData(priv._context_edge_id) : null;
|
|
60678
|
+
if (!ed || !ed.data || !ed.data.parent_topic) {
|
|
60679
|
+
log_error(`${gobj_short_name(gobj)}: reset edges without an edge`);
|
|
60680
|
+
return;
|
|
60681
|
+
}
|
|
60682
|
+
let src = ed.data;
|
|
60683
|
+
let hits = (d) => {
|
|
60684
|
+
if (!d || !d.parent_topic) return false;
|
|
60685
|
+
if (scope === "this") return edge_key_of(d) === edge_key_of(src) && d.parent_topic === src.parent_topic;
|
|
60686
|
+
if (scope === "same_type") return d.parent_topic === src.parent_topic && d.hook_name === src.hook_name;
|
|
60687
|
+
return true;
|
|
60688
|
+
};
|
|
60689
|
+
for (const [topic_name, props] of Object.entries(priv._graph_properties || {})) {
|
|
60690
|
+
if (!is_object(props)) continue;
|
|
60691
|
+
if (scope !== "all" && topic_name !== src.parent_topic) continue;
|
|
60692
|
+
if (is_object(props.edges)) {
|
|
60693
|
+
for (let key of Object.keys(props.edges)) {
|
|
60694
|
+
let hook_name = key.split(":")[0];
|
|
60695
|
+
if (scope === "this" && key !== edge_key_of(src)) continue;
|
|
60696
|
+
if (scope === "same_type" && hook_name !== src.hook_name) continue;
|
|
60697
|
+
delete props.edges[key];
|
|
60698
|
+
}
|
|
60699
|
+
if (Object.keys(props.edges).length === 0) delete props.edges;
|
|
60700
|
+
}
|
|
60701
|
+
if (is_object(props.defaults)) {
|
|
60702
|
+
if (scope === "same_type" && is_object(props.defaults.edge_styles)) {
|
|
60703
|
+
delete props.defaults.edge_styles[src.hook_name];
|
|
60704
|
+
if (Object.keys(props.defaults.edge_styles).length === 0) delete props.defaults.edge_styles;
|
|
60705
|
+
} else if (scope === "all") {
|
|
60706
|
+
delete props.defaults.edge_styles;
|
|
60707
|
+
delete props.defaults.edge_style;
|
|
60708
|
+
}
|
|
60709
|
+
}
|
|
60710
|
+
}
|
|
60711
|
+
let updates = [];
|
|
60712
|
+
for (let e of graph.getEdgeData() || []) {
|
|
60713
|
+
if (!e || !hits(e.data)) continue;
|
|
60714
|
+
let style = edge_style_of(gobj, e.data);
|
|
60715
|
+
updates.push({
|
|
60716
|
+
id: e.id,
|
|
60717
|
+
style: {
|
|
60718
|
+
lineWidth: style.lineWidth,
|
|
60719
|
+
stroke: style.stroke
|
|
60720
|
+
},
|
|
60721
|
+
data: Object.assign({}, e.data, { themed_default: style.themed_default })
|
|
60722
|
+
});
|
|
60723
|
+
}
|
|
60724
|
+
deselect_edge(gobj);
|
|
60725
|
+
if (updates.length > 0) graph.updateEdgeData(updates);
|
|
60726
|
+
graph.draw().then(() => {
|
|
60503
60727
|
mark_graph_dirty(gobj);
|
|
60504
60728
|
});
|
|
60505
60729
|
}
|