@yuneta/gobj-ui 7.23.79 → 7.23.81
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 +37 -0
- package/dist/gobj-ui.cjs.js +393 -12
- package/dist/gobj-ui.es.js +394 -13
- package/package.json +1 -1
- package/src/c_g6_nodes_tree.js +499 -19
- package/src/lib_graph.css +2 -0
package/dist/gobj-ui.es.js
CHANGED
|
@@ -6,7 +6,7 @@ import { createJSONEditor } from "vanilla-jsoneditor";
|
|
|
6
6
|
import { TabulatorFull } from "tabulator-tables";
|
|
7
7
|
import * as maplibregl from "maplibre-gl";
|
|
8
8
|
import uPlot from "uplot";
|
|
9
|
-
import { BaseLayout, BrushSelect, CanvasEvent, Circle, CommonEvent, DragCanvas, EdgeEvent, ExtensionCategory, Graph, HistoryEvent, NodeEvent, Toolbar, ZoomCanvas, register } from "@antv/g6";
|
|
9
|
+
import { BaseLayout, BrushSelect, CanvasEvent, Circle, CommonEvent, DragCanvas, EdgeEvent, ExtensionCategory, Graph, HTML, HistoryEvent, NodeEvent, Toolbar, ZoomCanvas, register } from "@antv/g6";
|
|
10
10
|
//#region \0rolldown/runtime.js
|
|
11
11
|
var __create = Object.create;
|
|
12
12
|
var __defProp = Object.defineProperty;
|
|
@@ -43154,7 +43154,7 @@ var _excluded$5 = ["style"];
|
|
|
43154
43154
|
* HTML container
|
|
43155
43155
|
* @see https://github.com/pmndrs/drei#html
|
|
43156
43156
|
*/
|
|
43157
|
-
var HTML = /*#__PURE__*/ function(_DisplayObject) {
|
|
43157
|
+
var HTML$1 = /*#__PURE__*/ function(_DisplayObject) {
|
|
43158
43158
|
function HTML() {
|
|
43159
43159
|
var _this;
|
|
43160
43160
|
var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, style = _ref.style, rest = _objectWithoutProperties(_ref, _excluded$5);
|
|
@@ -43202,7 +43202,7 @@ var HTML = /*#__PURE__*/ function(_DisplayObject) {
|
|
|
43202
43202
|
}
|
|
43203
43203
|
]);
|
|
43204
43204
|
}(DisplayObject);
|
|
43205
|
-
HTML.PARSED_STYLE_LIST = new Set([].concat(_toConsumableArray(DisplayObject.PARSED_STYLE_LIST), [
|
|
43205
|
+
HTML$1.PARSED_STYLE_LIST = new Set([].concat(_toConsumableArray(DisplayObject.PARSED_STYLE_LIST), [
|
|
43206
43206
|
"x",
|
|
43207
43207
|
"y",
|
|
43208
43208
|
"$el",
|
|
@@ -54653,6 +54653,8 @@ var PRIVATE_DATA$4 = {
|
|
|
54653
54653
|
_edge_icon_el: null,
|
|
54654
54654
|
_edge_delete_el: null,
|
|
54655
54655
|
_edge_popover_el: null,
|
|
54656
|
+
_port_icon_el: null,
|
|
54657
|
+
_port_popover_el: null,
|
|
54656
54658
|
_node_icon_el: null,
|
|
54657
54659
|
_node_delete_el: null,
|
|
54658
54660
|
_node_popover_el: null,
|
|
@@ -54843,6 +54845,7 @@ function register_layouts(gobj) {
|
|
|
54843
54845
|
register(ExtensionCategory.LAYOUT, "treedb-tree", TreedbTreeLayout);
|
|
54844
54846
|
register(ExtensionCategory.LAYOUT, "treedb-radial", TreedbRadialLayout);
|
|
54845
54847
|
register(ExtensionCategory.NODE, "light", LightNode);
|
|
54848
|
+
register(ExtensionCategory.NODE, "treedb-card", TreedbCard);
|
|
54846
54849
|
}
|
|
54847
54850
|
}
|
|
54848
54851
|
/************************************************************
|
|
@@ -54912,6 +54915,7 @@ function configure_events(gobj) {
|
|
|
54912
54915
|
update_edge_icon_position(gobj);
|
|
54913
54916
|
update_node_icon_position(gobj);
|
|
54914
54917
|
update_link_icon_position(gobj);
|
|
54918
|
+
update_port_icon_position(gobj);
|
|
54915
54919
|
});
|
|
54916
54920
|
graph.on(NodeEvent.DRAG_END, (evt) => {
|
|
54917
54921
|
gobj_send_event(gobj, "EV_NODE_DRAG_END", { evt }, gobj);
|
|
@@ -54936,6 +54940,7 @@ function configure_events(gobj) {
|
|
|
54936
54940
|
update_edge_icon_position(gobj);
|
|
54937
54941
|
update_node_icon_position(gobj);
|
|
54938
54942
|
update_link_icon_position(gobj);
|
|
54943
|
+
update_port_icon_position(gobj);
|
|
54939
54944
|
update_zoom_readout(gobj);
|
|
54940
54945
|
let z = priv.last_zoom;
|
|
54941
54946
|
try {
|
|
@@ -55652,12 +55657,22 @@ function card_shape_of(gobj, desc, record, geometry, pills_html) {
|
|
|
55652
55657
|
if (r == null && is_object(default_port_sizes)) r = default_port_sizes[key];
|
|
55653
55658
|
if (r != null) style.ports[i].r = r;
|
|
55654
55659
|
}
|
|
55660
|
+
let port_shapes = geometry.port_shapes;
|
|
55661
|
+
let default_port_shapes = topic_defaults ? topic_defaults.port_shapes : null;
|
|
55662
|
+
let default_shape = topic_defaults ? topic_defaults.port_shape : null;
|
|
55663
|
+
for (let i = 0; i < style.ports.length; i++) {
|
|
55664
|
+
let key = style.ports[i].key;
|
|
55665
|
+
let shape = is_object(port_shapes) ? port_shapes[key] : null;
|
|
55666
|
+
if (!shape && is_object(default_port_shapes)) shape = default_port_shapes[key];
|
|
55667
|
+
if (!shape) shape = default_shape;
|
|
55668
|
+
if (shape && str_in_list(PORT_SHAPES, shape)) style.ports[i].shape = shape;
|
|
55669
|
+
}
|
|
55655
55670
|
} else {
|
|
55656
55671
|
style.port = false;
|
|
55657
55672
|
style.ports = [];
|
|
55658
55673
|
}
|
|
55659
55674
|
return {
|
|
55660
|
-
type: "
|
|
55675
|
+
type: "treedb-card",
|
|
55661
55676
|
style
|
|
55662
55677
|
};
|
|
55663
55678
|
}
|
|
@@ -56052,17 +56067,40 @@ function update_geometry(gobj, node_id) {
|
|
|
56052
56067
|
let topic_props = priv._graph_properties[topic_name];
|
|
56053
56068
|
if (!is_object(topic_props.nodes)) topic_props.nodes = {};
|
|
56054
56069
|
let node_props = topic_props.nodes[record.id] || {};
|
|
56055
|
-
|
|
56070
|
+
let picked = kw_clone_by_keys(gobj, style, [
|
|
56056
56071
|
"x",
|
|
56057
56072
|
"y",
|
|
56058
56073
|
"size",
|
|
56059
56074
|
"portR"
|
|
56060
|
-
])
|
|
56061
|
-
|
|
56062
|
-
|
|
56063
|
-
|
|
56064
|
-
|
|
56065
|
-
|
|
56075
|
+
]);
|
|
56076
|
+
if (node_is_compact(gobj, node_id)) {
|
|
56077
|
+
delete picked.size;
|
|
56078
|
+
delete picked.portR;
|
|
56079
|
+
} else {
|
|
56080
|
+
let desc = nodedata.data.desc;
|
|
56081
|
+
let def_size = card_size_for(desc.node_treedb_type, !!pills_html_of(gobj, nodedata));
|
|
56082
|
+
if (is_array(picked.size) && picked.size[0] === def_size[0] && picked.size[1] === def_size[1]) {
|
|
56083
|
+
delete picked.size;
|
|
56084
|
+
delete node_props.size;
|
|
56085
|
+
}
|
|
56086
|
+
let def_r = desc.node_treedb_type === "child" ? PORT_R_CHILD : PORT_R_ENTITY;
|
|
56087
|
+
if (picked.portR === def_r) {
|
|
56088
|
+
delete picked.portR;
|
|
56089
|
+
delete node_props.portR;
|
|
56090
|
+
}
|
|
56091
|
+
}
|
|
56092
|
+
json_object_update(node_props, picked);
|
|
56093
|
+
if (!node_is_compact(gobj, node_id)) {
|
|
56094
|
+
let ports = (nodedata.style || {}).ports || [];
|
|
56095
|
+
let port_sizes = {};
|
|
56096
|
+
for (let i = 0; i < ports.length; i++) if (ports[i].r != null) port_sizes[ports[i].key] = ports[i].r;
|
|
56097
|
+
if (Object.keys(port_sizes).length > 0) node_props.port_sizes = port_sizes;
|
|
56098
|
+
else delete node_props.port_sizes;
|
|
56099
|
+
let port_shapes = {};
|
|
56100
|
+
for (let i = 0; i < ports.length; i++) if (ports[i].shape && ports[i].shape !== "circle") port_shapes[ports[i].key] = ports[i].shape;
|
|
56101
|
+
if (Object.keys(port_shapes).length > 0) node_props.port_shapes = port_shapes;
|
|
56102
|
+
else delete node_props.port_shapes;
|
|
56103
|
+
}
|
|
56066
56104
|
topic_props.nodes[record.id] = node_props;
|
|
56067
56105
|
nodedata.data.graph_props = node_props;
|
|
56068
56106
|
}
|
|
@@ -56544,11 +56582,74 @@ function graph_resize(gobj, width, height) {
|
|
|
56544
56582
|
update_port_resize_handles_position(gobj);
|
|
56545
56583
|
update_node_icon_position(gobj);
|
|
56546
56584
|
update_link_icon_position(gobj);
|
|
56585
|
+
update_port_icon_position(gobj);
|
|
56547
56586
|
}
|
|
56548
56587
|
function graph_write_behaviors(gobj, behaviors) {
|
|
56549
56588
|
gobj.priv.graph.setOptions({ behaviors });
|
|
56550
56589
|
}
|
|
56551
56590
|
/************************************************************
|
|
56591
|
+
* Custom G6 node: TreedbCard -- G6's html node with ports that
|
|
56592
|
+
* have a SHAPE.
|
|
56593
|
+
*
|
|
56594
|
+
* G6 draws every port as a circle (`drawPortShapes` upserts a
|
|
56595
|
+
* `Circle`, nothing in the port style says otherwise). A port's
|
|
56596
|
+
* `shape` -- `circle`, `square`, `diamond`, `triangle` -- picks
|
|
56597
|
+
* the G shape here, by the names G6 registers itself, and `r`
|
|
56598
|
+
* stays the one size: the half-side of the square, the half-
|
|
56599
|
+
* diagonal of the diamond, the half-height of the triangle. The
|
|
56600
|
+
* hit test, the resize handles and the edge's landing point all
|
|
56601
|
+
* read `r` and none of them care about the outline.
|
|
56602
|
+
************************************************************/
|
|
56603
|
+
var PORT_SHAPES = [
|
|
56604
|
+
"circle",
|
|
56605
|
+
"square",
|
|
56606
|
+
"diamond",
|
|
56607
|
+
"triangle"
|
|
56608
|
+
];
|
|
56609
|
+
var TreedbCard = class extends HTML {
|
|
56610
|
+
drawPortShapes(attributes, container) {
|
|
56611
|
+
const portsStyle = this.getPortsStyle(attributes);
|
|
56612
|
+
Object.keys(portsStyle).forEach((key) => {
|
|
56613
|
+
const style = portsStyle[key];
|
|
56614
|
+
const shapeKey = `port-${key}`;
|
|
56615
|
+
if (style === false) {
|
|
56616
|
+
this.upsert(shapeKey, "circle", false, container);
|
|
56617
|
+
return;
|
|
56618
|
+
}
|
|
56619
|
+
let r = Number(style.r) || 0;
|
|
56620
|
+
switch (style.shape) {
|
|
56621
|
+
case "square":
|
|
56622
|
+
this.upsert(shapeKey, "rect", Object.assign({}, style, {
|
|
56623
|
+
x: -r,
|
|
56624
|
+
y: -r,
|
|
56625
|
+
width: 2 * r,
|
|
56626
|
+
height: 2 * r
|
|
56627
|
+
}), container);
|
|
56628
|
+
break;
|
|
56629
|
+
case "diamond":
|
|
56630
|
+
this.upsert(shapeKey, "polygon", Object.assign({}, style, { points: [
|
|
56631
|
+
[0, -r],
|
|
56632
|
+
[r, 0],
|
|
56633
|
+
[0, r],
|
|
56634
|
+
[-r, 0]
|
|
56635
|
+
] }), container);
|
|
56636
|
+
break;
|
|
56637
|
+
case "triangle":
|
|
56638
|
+
this.upsert(shapeKey, "polygon", Object.assign({}, style, { points: [
|
|
56639
|
+
[0, -r],
|
|
56640
|
+
[r, r],
|
|
56641
|
+
[-r, r]
|
|
56642
|
+
] }), container);
|
|
56643
|
+
break;
|
|
56644
|
+
default: this.upsert(shapeKey, "circle", style, container);
|
|
56645
|
+
}
|
|
56646
|
+
});
|
|
56647
|
+
}
|
|
56648
|
+
};
|
|
56649
|
+
function is_card_type(type) {
|
|
56650
|
+
return type === "treedb-card" || type === "html";
|
|
56651
|
+
}
|
|
56652
|
+
/************************************************************
|
|
56552
56653
|
* Custom G6 node: LightNode (circle with status indicator)
|
|
56553
56654
|
************************************************************/
|
|
56554
56655
|
var LightNode = class extends Circle {
|
|
@@ -57294,7 +57395,7 @@ function start_node_resize(gobj, e, mx, my) {
|
|
|
57294
57395
|
};
|
|
57295
57396
|
if (nodeType === "circle") updateStyle.size = [Math.max(newW, newH)];
|
|
57296
57397
|
else updateStyle.size = [newW, newH];
|
|
57297
|
-
if (nodeType
|
|
57398
|
+
if (is_card_type(nodeType)) {
|
|
57298
57399
|
updateStyle.dx = -newW / 2;
|
|
57299
57400
|
updateStyle.dy = -newH / 2;
|
|
57300
57401
|
}
|
|
@@ -57419,6 +57520,7 @@ function select_port(gobj, node_id, port_key) {
|
|
|
57419
57520
|
priv._selected_port_key = port_key;
|
|
57420
57521
|
show_port_resize_handles(gobj);
|
|
57421
57522
|
show_link_icon_if_fkey(gobj);
|
|
57523
|
+
show_port_icon(gobj);
|
|
57422
57524
|
}
|
|
57423
57525
|
/************************************************************
|
|
57424
57526
|
* Deselect port: clear port state, return to node selection.
|
|
@@ -57427,6 +57529,8 @@ function deselect_port(gobj) {
|
|
|
57427
57529
|
let priv = gobj.priv;
|
|
57428
57530
|
exit_linking_mode(gobj);
|
|
57429
57531
|
hide_link_icon(gobj);
|
|
57532
|
+
hide_port_icon(gobj);
|
|
57533
|
+
hide_port_popover(gobj);
|
|
57430
57534
|
hide_port_resize_handles(gobj);
|
|
57431
57535
|
priv._selected_port_key = null;
|
|
57432
57536
|
}
|
|
@@ -57479,6 +57583,217 @@ function update_link_icon_position(gobj) {
|
|
|
57479
57583
|
}
|
|
57480
57584
|
}
|
|
57481
57585
|
/************************************************************
|
|
57586
|
+
* Port properties icon and popover: the gear beside a selected
|
|
57587
|
+
* port, as the node has its own. The popover has the two things
|
|
57588
|
+
* a port IS on screen -- its shape and its radius -- and the
|
|
57589
|
+
* scope: this port, the same port of every card of the topic
|
|
57590
|
+
* (the hook or fkey column), or every port there is.
|
|
57591
|
+
************************************************************/
|
|
57592
|
+
function port_icon_xy(gobj) {
|
|
57593
|
+
let priv = gobj.priv;
|
|
57594
|
+
let graph = priv.graph;
|
|
57595
|
+
let canvasPos = get_port_canvas_position(gobj, priv._selected_node_id, priv._selected_port_key);
|
|
57596
|
+
if (!canvasPos) return null;
|
|
57597
|
+
let vp = graph.getViewportByCanvas([canvasPos.x, canvasPos.y]);
|
|
57598
|
+
let below = priv._link_icon_el ? floating_icon_step() : 0;
|
|
57599
|
+
return {
|
|
57600
|
+
x: vp[0] + floating_icon_size() / 2 + 4,
|
|
57601
|
+
y: vp[1] + floating_icon_dy() + below
|
|
57602
|
+
};
|
|
57603
|
+
}
|
|
57604
|
+
function show_port_icon(gobj) {
|
|
57605
|
+
hide_port_icon(gobj);
|
|
57606
|
+
let priv = gobj.priv;
|
|
57607
|
+
if (!priv._selected_node_id || !priv._selected_port_key) return;
|
|
57608
|
+
let xy = port_icon_xy(gobj);
|
|
57609
|
+
if (!xy) return;
|
|
57610
|
+
let icon = create_floating_icon("gear", "#1890ff", xy.x, xy.y, t("port properties"), () => toggle_port_popover(gobj));
|
|
57611
|
+
priv.$container.appendChild(icon);
|
|
57612
|
+
priv._port_icon_el = icon;
|
|
57613
|
+
}
|
|
57614
|
+
function hide_port_icon(gobj) {
|
|
57615
|
+
hide_overlay(gobj, "_port_icon_el");
|
|
57616
|
+
}
|
|
57617
|
+
function update_port_icon_position(gobj) {
|
|
57618
|
+
let priv = gobj.priv;
|
|
57619
|
+
if (!priv._port_icon_el || !priv._selected_node_id || !priv._selected_port_key) return;
|
|
57620
|
+
try {
|
|
57621
|
+
let xy = port_icon_xy(gobj);
|
|
57622
|
+
if (!xy) {
|
|
57623
|
+
hide_port_icon(gobj);
|
|
57624
|
+
hide_port_popover(gobj);
|
|
57625
|
+
return;
|
|
57626
|
+
}
|
|
57627
|
+
priv._port_icon_el.style.left = xy.x + "px";
|
|
57628
|
+
priv._port_icon_el.style.top = xy.y + "px";
|
|
57629
|
+
if (priv._port_popover_el) {
|
|
57630
|
+
priv._port_popover_el.style.left = xy.x + floating_popover_dx() + "px";
|
|
57631
|
+
priv._port_popover_el.style.top = xy.y + "px";
|
|
57632
|
+
clamp_popover_position(gobj, priv._port_popover_el);
|
|
57633
|
+
}
|
|
57634
|
+
} catch (e) {
|
|
57635
|
+
hide_port_icon(gobj);
|
|
57636
|
+
hide_port_popover(gobj);
|
|
57637
|
+
}
|
|
57638
|
+
}
|
|
57639
|
+
function toggle_port_popover(gobj) {
|
|
57640
|
+
if (gobj.priv._port_popover_el) hide_port_popover(gobj);
|
|
57641
|
+
else show_port_popover(gobj);
|
|
57642
|
+
}
|
|
57643
|
+
function hide_port_popover(gobj) {
|
|
57644
|
+
hide_overlay(gobj, "_port_popover_el");
|
|
57645
|
+
}
|
|
57646
|
+
function ports_with(ports, port_key, changes) {
|
|
57647
|
+
return (ports || []).map((p) => p.key === port_key ? Object.assign({}, p, changes) : p);
|
|
57648
|
+
}
|
|
57649
|
+
function show_port_popover(gobj) {
|
|
57650
|
+
hide_port_popover(gobj);
|
|
57651
|
+
let priv = gobj.priv;
|
|
57652
|
+
let graph = priv.graph;
|
|
57653
|
+
let node_id = priv._selected_node_id;
|
|
57654
|
+
let port_key = priv._selected_port_key;
|
|
57655
|
+
if (!node_id || !port_key) return;
|
|
57656
|
+
let nodeData = graph.getNodeData(node_id);
|
|
57657
|
+
if (!nodeData || !nodeData.style) return;
|
|
57658
|
+
let port = (nodeData.style.ports || []).find((p) => p.key === port_key);
|
|
57659
|
+
if (!port) return;
|
|
57660
|
+
let orig_shape = port.shape || "circle";
|
|
57661
|
+
let orig_r = get_port_radius(gobj, node_id, port_key);
|
|
57662
|
+
let xy = port_icon_xy(gobj);
|
|
57663
|
+
if (!xy) return;
|
|
57664
|
+
const popover = create_popover_base(xy.x + floating_popover_dx(), xy.y, "g6-port-popover", "#d9d9d9", 180);
|
|
57665
|
+
function preview_port() {
|
|
57666
|
+
let r = parseInt(rInput.value) || orig_r;
|
|
57667
|
+
graph.updateNodeData([{
|
|
57668
|
+
id: node_id,
|
|
57669
|
+
style: { ports: ports_with(nodeData.style.ports, port_key, {
|
|
57670
|
+
shape: shapeSelect.value,
|
|
57671
|
+
r
|
|
57672
|
+
}) }
|
|
57673
|
+
}]);
|
|
57674
|
+
graph.draw().then(() => {
|
|
57675
|
+
update_port_resize_handles_position(gobj);
|
|
57676
|
+
});
|
|
57677
|
+
}
|
|
57678
|
+
create_form_label(popover, "shape");
|
|
57679
|
+
let shapeSelect = create_form_select(popover, PORT_SHAPES.map((shape) => {
|
|
57680
|
+
return {
|
|
57681
|
+
value: shape,
|
|
57682
|
+
label: t(shape)
|
|
57683
|
+
};
|
|
57684
|
+
}));
|
|
57685
|
+
shapeSelect.value = orig_shape;
|
|
57686
|
+
shapeSelect.addEventListener("change", preview_port);
|
|
57687
|
+
create_form_label(popover, "radius");
|
|
57688
|
+
let rInput = create_form_number_input(popover, orig_r, 2, 40, preview_port);
|
|
57689
|
+
create_form_label(popover, "apply to");
|
|
57690
|
+
let scopeSelect = create_form_select(popover, [
|
|
57691
|
+
{
|
|
57692
|
+
value: "this",
|
|
57693
|
+
label: t("this port")
|
|
57694
|
+
},
|
|
57695
|
+
{
|
|
57696
|
+
value: "same_topic",
|
|
57697
|
+
label: t("same port in topic")
|
|
57698
|
+
},
|
|
57699
|
+
{
|
|
57700
|
+
value: "all",
|
|
57701
|
+
label: t("all ports")
|
|
57702
|
+
}
|
|
57703
|
+
]);
|
|
57704
|
+
create_form_button_row(popover, [{
|
|
57705
|
+
text: "cancel",
|
|
57706
|
+
style: BTN_STYLE_CANCEL,
|
|
57707
|
+
onClick: () => {
|
|
57708
|
+
graph.updateNodeData([{
|
|
57709
|
+
id: node_id,
|
|
57710
|
+
style: { ports: ports_with(nodeData.style.ports, port_key, {
|
|
57711
|
+
shape: orig_shape,
|
|
57712
|
+
r: orig_r
|
|
57713
|
+
}) }
|
|
57714
|
+
}]);
|
|
57715
|
+
graph.draw().then(() => {
|
|
57716
|
+
update_port_resize_handles_position(gobj);
|
|
57717
|
+
});
|
|
57718
|
+
hide_port_popover(gobj);
|
|
57719
|
+
}
|
|
57720
|
+
}, {
|
|
57721
|
+
text: "apply",
|
|
57722
|
+
style: "flex:1;padding:6px;background:#1890ff;color:#fff;border:none;border-radius:4px;cursor:pointer;font-size:13px;font-weight:500;",
|
|
57723
|
+
onClick: () => {
|
|
57724
|
+
apply_port_properties(gobj, node_id, port_key, shapeSelect.value, parseInt(rInput.value) || orig_r, scopeSelect.value);
|
|
57725
|
+
}
|
|
57726
|
+
}]);
|
|
57727
|
+
priv.$container.appendChild(popover);
|
|
57728
|
+
priv._port_popover_el = popover;
|
|
57729
|
+
clamp_popover_position(gobj, popover);
|
|
57730
|
+
}
|
|
57731
|
+
/************************************************************
|
|
57732
|
+
* Apply a port's shape and radius to one port, to the same port
|
|
57733
|
+
* of every card of the topic, or to every port -- and remember
|
|
57734
|
+
* the choice as the topic's default, the way `resize all ports`
|
|
57735
|
+
* does, so a card that arrives later is born with it.
|
|
57736
|
+
* scope: 'this', 'same_topic', 'all'
|
|
57737
|
+
************************************************************/
|
|
57738
|
+
function apply_port_properties(gobj, node_id, port_key, shape, r, scope) {
|
|
57739
|
+
let priv = gobj.priv;
|
|
57740
|
+
let graph = priv.graph;
|
|
57741
|
+
let nodeData = graph.getNodeData(node_id);
|
|
57742
|
+
if (!nodeData || !nodeData.data) return;
|
|
57743
|
+
let source_topic = nodeData.data.topic_name;
|
|
57744
|
+
if (scope === "same_topic") {
|
|
57745
|
+
if (!is_object(priv._graph_properties[source_topic])) priv._graph_properties[source_topic] = {};
|
|
57746
|
+
let defaults = priv._graph_properties[source_topic].defaults || {};
|
|
57747
|
+
defaults.port_sizes = Object.assign({}, defaults.port_sizes, { [port_key]: r });
|
|
57748
|
+
defaults.port_shapes = Object.assign({}, defaults.port_shapes, { [port_key]: shape });
|
|
57749
|
+
priv._graph_properties[source_topic].defaults = defaults;
|
|
57750
|
+
} else if (scope === "all") for (const topic_name of Object.keys(priv.descs || {})) {
|
|
57751
|
+
if (!is_object(priv._graph_properties[topic_name])) priv._graph_properties[topic_name] = {};
|
|
57752
|
+
let defaults = priv._graph_properties[topic_name].defaults || {};
|
|
57753
|
+
defaults.portR = r;
|
|
57754
|
+
defaults.port_shape = shape;
|
|
57755
|
+
delete defaults.port_sizes;
|
|
57756
|
+
delete defaults.port_shapes;
|
|
57757
|
+
priv._graph_properties[topic_name].defaults = defaults;
|
|
57758
|
+
}
|
|
57759
|
+
let updates = [];
|
|
57760
|
+
for (let nd of graph.getNodeData() || []) {
|
|
57761
|
+
if (!nd || !nd.data || !nd.data.desc || !nd.style || !is_array(nd.style.ports)) continue;
|
|
57762
|
+
let new_ports;
|
|
57763
|
+
if (scope === "this") {
|
|
57764
|
+
if (nd.id !== node_id) continue;
|
|
57765
|
+
new_ports = ports_with(nd.style.ports, port_key, {
|
|
57766
|
+
shape,
|
|
57767
|
+
r
|
|
57768
|
+
});
|
|
57769
|
+
} else if (scope === "same_topic") {
|
|
57770
|
+
if (nd.data.topic_name !== source_topic) continue;
|
|
57771
|
+
new_ports = ports_with(nd.style.ports, port_key, {
|
|
57772
|
+
shape,
|
|
57773
|
+
r
|
|
57774
|
+
});
|
|
57775
|
+
} else new_ports = nd.style.ports.map((p) => Object.assign({}, p, {
|
|
57776
|
+
shape,
|
|
57777
|
+
r
|
|
57778
|
+
}));
|
|
57779
|
+
let upd = { ports: new_ports };
|
|
57780
|
+
if (scope === "all") upd.portR = r;
|
|
57781
|
+
updates.push({
|
|
57782
|
+
id: nd.id,
|
|
57783
|
+
style: upd
|
|
57784
|
+
});
|
|
57785
|
+
}
|
|
57786
|
+
if (updates.length > 0) {
|
|
57787
|
+
graph.updateNodeData(updates);
|
|
57788
|
+
graph.draw().then(() => {
|
|
57789
|
+
update_port_resize_handles_position(gobj);
|
|
57790
|
+
update_port_icon_position(gobj);
|
|
57791
|
+
mark_graph_dirty(gobj);
|
|
57792
|
+
});
|
|
57793
|
+
}
|
|
57794
|
+
hide_port_popover(gobj);
|
|
57795
|
+
}
|
|
57796
|
+
/************************************************************
|
|
57482
57797
|
* Get a column descriptor by field id from a topic desc.
|
|
57483
57798
|
************************************************************/
|
|
57484
57799
|
function get_col_by_id(desc, col_id) {
|
|
@@ -59141,6 +59456,8 @@ function build_node_context_menu(gobj, node_id) {
|
|
|
59141
59456
|
if (gobj.priv.edit_mode && !node_is_compact(gobj, node_id)) {
|
|
59142
59457
|
items.push(ctx_item("g6-icon-resize", t("resize all"), "resize_all_nodes"));
|
|
59143
59458
|
items.push(ctx_item("g6-icon-resize", t("resize topic nodes"), "resize_topic_nodes"));
|
|
59459
|
+
items.push(ctx_item("g6-icon-undo", t("reset sizes"), "reset_all_sizes"));
|
|
59460
|
+
items.push(ctx_item("g6-icon-undo", t("reset topic sizes"), "reset_topic_sizes"));
|
|
59144
59461
|
}
|
|
59145
59462
|
return items;
|
|
59146
59463
|
}
|
|
@@ -59151,6 +59468,7 @@ function build_port_context_menu(gobj, node_id, port_key) {
|
|
|
59151
59468
|
let items = [];
|
|
59152
59469
|
if (gobj.priv.edit_mode) {
|
|
59153
59470
|
inject_svg_icons();
|
|
59471
|
+
items.push(ctx_item("g6-icon-edit", t("port properties"), "port_properties"));
|
|
59154
59472
|
items.push(ctx_item("g6-icon-resize", t("resize all ports"), "resize_all_ports"));
|
|
59155
59473
|
items.push(ctx_item("g6-icon-resize", t("resize topic ports"), "resize_topic_ports"));
|
|
59156
59474
|
}
|
|
@@ -59177,6 +59495,18 @@ function handle_context_menu_click(gobj, value) {
|
|
|
59177
59495
|
case "resize_topic_nodes":
|
|
59178
59496
|
copy_size_to_nodes(gobj, true);
|
|
59179
59497
|
break;
|
|
59498
|
+
case "reset_all_sizes":
|
|
59499
|
+
reset_sizes(gobj, false);
|
|
59500
|
+
break;
|
|
59501
|
+
case "reset_topic_sizes":
|
|
59502
|
+
reset_sizes(gobj, true);
|
|
59503
|
+
break;
|
|
59504
|
+
case "port_properties":
|
|
59505
|
+
if (priv._context_node_id && priv._context_port_key) {
|
|
59506
|
+
select_port(gobj, priv._context_node_id, priv._context_port_key);
|
|
59507
|
+
show_port_popover(gobj);
|
|
59508
|
+
}
|
|
59509
|
+
break;
|
|
59180
59510
|
case "resize_all_ports":
|
|
59181
59511
|
copy_size_to_ports(gobj, false);
|
|
59182
59512
|
break;
|
|
@@ -59220,7 +59550,7 @@ function copy_size_to_nodes(gobj, same_topic_only) {
|
|
|
59220
59550
|
if (nodes[i].id === node_id) continue;
|
|
59221
59551
|
let updateStyle = { size: [...source_size] };
|
|
59222
59552
|
if (source_portR != null) updateStyle.portR = source_portR;
|
|
59223
|
-
if (nd.type
|
|
59553
|
+
if (is_card_type(nd.type)) {
|
|
59224
59554
|
updateStyle.dx = -source_size[0] / 2;
|
|
59225
59555
|
updateStyle.dy = -(source_size.length > 1 ? source_size[1] : source_size[0]) / 2;
|
|
59226
59556
|
}
|
|
@@ -59238,6 +59568,56 @@ function copy_size_to_nodes(gobj, same_topic_only) {
|
|
|
59238
59568
|
}
|
|
59239
59569
|
}
|
|
59240
59570
|
/************************************************************
|
|
59571
|
+
* Forget every SAVED size: the card sizes, the port radii and the
|
|
59572
|
+
* per-port radii, per node and as topic defaults (`resize all`),
|
|
59573
|
+
* for one topic or for all of them. The cards go back to the
|
|
59574
|
+
* library's defaults on the spot, and Save writes the cleared
|
|
59575
|
+
* entries -- a size nobody chose is not written back (see
|
|
59576
|
+
* update_geometry). Positions and edge styles are not touched:
|
|
59577
|
+
* they are a different choice.
|
|
59578
|
+
************************************************************/
|
|
59579
|
+
function reset_sizes(gobj, same_topic_only) {
|
|
59580
|
+
let priv = gobj.priv;
|
|
59581
|
+
let graph = priv.graph;
|
|
59582
|
+
let topic = "";
|
|
59583
|
+
if (same_topic_only) {
|
|
59584
|
+
let nd = priv._context_node_id ? graph.getNodeData(priv._context_node_id) : null;
|
|
59585
|
+
if (!nd || !nd.data || !nd.data.topic_name) {
|
|
59586
|
+
log_error(`${gobj_short_name(gobj)}: reset topic sizes without a node`);
|
|
59587
|
+
return;
|
|
59588
|
+
}
|
|
59589
|
+
topic = nd.data.topic_name;
|
|
59590
|
+
}
|
|
59591
|
+
const SIZE_KEYS = [
|
|
59592
|
+
"size",
|
|
59593
|
+
"portR",
|
|
59594
|
+
"port_sizes"
|
|
59595
|
+
];
|
|
59596
|
+
let strip = (props) => {
|
|
59597
|
+
if (!is_object(props)) return;
|
|
59598
|
+
for (let k of SIZE_KEYS) delete props[k];
|
|
59599
|
+
};
|
|
59600
|
+
for (const [topic_name, props] of Object.entries(priv._graph_properties || {})) {
|
|
59601
|
+
if (topic && topic_name !== topic) continue;
|
|
59602
|
+
if (is_object(props.nodes)) for (let node_props of Object.values(props.nodes)) strip(node_props);
|
|
59603
|
+
strip(props.defaults);
|
|
59604
|
+
}
|
|
59605
|
+
let ids = [];
|
|
59606
|
+
for (let nd of graph.getNodeData() || []) {
|
|
59607
|
+
if (!nd || !nd.data || !nd.data.desc || is_more_node(nd)) continue;
|
|
59608
|
+
if (topic && nd.data.topic_name !== topic) continue;
|
|
59609
|
+
strip(nd.data.graph_props);
|
|
59610
|
+
if (nd.data.record) strip(nd.data.record._geometry);
|
|
59611
|
+
ids.push(nd.id);
|
|
59612
|
+
}
|
|
59613
|
+
reshape_nodes(gobj, ids);
|
|
59614
|
+
graph.draw().then(() => {
|
|
59615
|
+
update_resize_handles_position(gobj);
|
|
59616
|
+
update_port_resize_handles_position(gobj);
|
|
59617
|
+
mark_graph_dirty(gobj);
|
|
59618
|
+
});
|
|
59619
|
+
}
|
|
59620
|
+
/************************************************************
|
|
59241
59621
|
* Copy the selected port's radius to matching ports.
|
|
59242
59622
|
* If same_topic_only=true, only ports in same-topic nodes.
|
|
59243
59623
|
* If same_topic_only=false, matching ports in all nodes.
|
|
@@ -59770,6 +60150,7 @@ async function reconcile_fold_apply(gobj, opts, visible) {
|
|
|
59770
60150
|
update_edge_icon_position(gobj);
|
|
59771
60151
|
update_node_icon_position(gobj);
|
|
59772
60152
|
update_link_icon_position(gobj);
|
|
60153
|
+
update_port_icon_position(gobj);
|
|
59773
60154
|
return changed;
|
|
59774
60155
|
}
|
|
59775
60156
|
/************************************************************
|