@yuneta/gobj-ui 7.23.80 → 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.
@@ -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: "html",
55675
+ type: "treedb-card",
55661
55676
  style
55662
55677
  };
55663
55678
  }
@@ -56081,6 +56096,10 @@ function update_geometry(gobj, node_id) {
56081
56096
  for (let i = 0; i < ports.length; i++) if (ports[i].r != null) port_sizes[ports[i].key] = ports[i].r;
56082
56097
  if (Object.keys(port_sizes).length > 0) node_props.port_sizes = port_sizes;
56083
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;
56084
56103
  }
56085
56104
  topic_props.nodes[record.id] = node_props;
56086
56105
  nodedata.data.graph_props = node_props;
@@ -56563,11 +56582,74 @@ function graph_resize(gobj, width, height) {
56563
56582
  update_port_resize_handles_position(gobj);
56564
56583
  update_node_icon_position(gobj);
56565
56584
  update_link_icon_position(gobj);
56585
+ update_port_icon_position(gobj);
56566
56586
  }
56567
56587
  function graph_write_behaviors(gobj, behaviors) {
56568
56588
  gobj.priv.graph.setOptions({ behaviors });
56569
56589
  }
56570
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
+ /************************************************************
56571
56653
  * Custom G6 node: LightNode (circle with status indicator)
56572
56654
  ************************************************************/
56573
56655
  var LightNode = class extends Circle {
@@ -57313,7 +57395,7 @@ function start_node_resize(gobj, e, mx, my) {
57313
57395
  };
57314
57396
  if (nodeType === "circle") updateStyle.size = [Math.max(newW, newH)];
57315
57397
  else updateStyle.size = [newW, newH];
57316
- if (nodeType === "html") {
57398
+ if (is_card_type(nodeType)) {
57317
57399
  updateStyle.dx = -newW / 2;
57318
57400
  updateStyle.dy = -newH / 2;
57319
57401
  }
@@ -57438,6 +57520,7 @@ function select_port(gobj, node_id, port_key) {
57438
57520
  priv._selected_port_key = port_key;
57439
57521
  show_port_resize_handles(gobj);
57440
57522
  show_link_icon_if_fkey(gobj);
57523
+ show_port_icon(gobj);
57441
57524
  }
57442
57525
  /************************************************************
57443
57526
  * Deselect port: clear port state, return to node selection.
@@ -57446,6 +57529,8 @@ function deselect_port(gobj) {
57446
57529
  let priv = gobj.priv;
57447
57530
  exit_linking_mode(gobj);
57448
57531
  hide_link_icon(gobj);
57532
+ hide_port_icon(gobj);
57533
+ hide_port_popover(gobj);
57449
57534
  hide_port_resize_handles(gobj);
57450
57535
  priv._selected_port_key = null;
57451
57536
  }
@@ -57498,6 +57583,217 @@ function update_link_icon_position(gobj) {
57498
57583
  }
57499
57584
  }
57500
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
+ /************************************************************
57501
57797
  * Get a column descriptor by field id from a topic desc.
57502
57798
  ************************************************************/
57503
57799
  function get_col_by_id(desc, col_id) {
@@ -59172,6 +59468,7 @@ function build_port_context_menu(gobj, node_id, port_key) {
59172
59468
  let items = [];
59173
59469
  if (gobj.priv.edit_mode) {
59174
59470
  inject_svg_icons();
59471
+ items.push(ctx_item("g6-icon-edit", t("port properties"), "port_properties"));
59175
59472
  items.push(ctx_item("g6-icon-resize", t("resize all ports"), "resize_all_ports"));
59176
59473
  items.push(ctx_item("g6-icon-resize", t("resize topic ports"), "resize_topic_ports"));
59177
59474
  }
@@ -59204,6 +59501,12 @@ function handle_context_menu_click(gobj, value) {
59204
59501
  case "reset_topic_sizes":
59205
59502
  reset_sizes(gobj, true);
59206
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;
59207
59510
  case "resize_all_ports":
59208
59511
  copy_size_to_ports(gobj, false);
59209
59512
  break;
@@ -59247,7 +59550,7 @@ function copy_size_to_nodes(gobj, same_topic_only) {
59247
59550
  if (nodes[i].id === node_id) continue;
59248
59551
  let updateStyle = { size: [...source_size] };
59249
59552
  if (source_portR != null) updateStyle.portR = source_portR;
59250
- if (nd.type === "html") {
59553
+ if (is_card_type(nd.type)) {
59251
59554
  updateStyle.dx = -source_size[0] / 2;
59252
59555
  updateStyle.dy = -(source_size.length > 1 ? source_size[1] : source_size[0]) / 2;
59253
59556
  }
@@ -59847,6 +60150,7 @@ async function reconcile_fold_apply(gobj, opts, visible) {
59847
60150
  update_edge_icon_position(gobj);
59848
60151
  update_node_icon_position(gobj);
59849
60152
  update_link_icon_position(gobj);
60153
+ update_port_icon_position(gobj);
59850
60154
  return changed;
59851
60155
  }
59852
60156
  /************************************************************
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.23.80",
3
+ "version": "7.23.81",
4
4
  "type": "module",
5
5
  "main": "dist/gobj-ui.cjs.js",
6
6
  "module": "dist/gobj-ui.es.js",