@pi-outpost/embed 0.51.0 → 0.52.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.
@@ -21614,6 +21614,7 @@ var zT = {
21614
21614
  UNDO: "pi-outpost:drawio-undo",
21615
21615
  REDO: "pi-outpost:drawio-redo",
21616
21616
  EXPORT_SVG: "pi-outpost:drawio-export-svg",
21617
+ WIRE_STYLE: "pi-outpost:drawio-wire-style",
21617
21618
  CHANGED: "pi-outpost:drawio-changed",
21618
21619
  SAVED: "pi-outpost:drawio-saved",
21619
21620
  SVG: "pi-outpost:drawio-svg",
@@ -21766,7 +21767,79 @@ div.mxRubberband { position: absolute; overflow: hidden; border: 1px solid #29b6
21766
21767
  var undo = touch.undo;
21767
21768
  // A label being typed is an edit too: leaving now would drop it
21768
21769
  var typing = viewer !== null && viewer.graph.isEditing();
21769
- tell({ type: M.CHANGED, dirty: typing || undo.indexOfNextAdd !== touch.clean, canUndo: undo.canUndo(), canRedo: undo.canRedo() });
21770
+ tell({ type: M.CHANGED, dirty: typing || undo.indexOfNextAdd !== touch.clean, canUndo: undo.canUndo(), canRedo: undo.canRedo(), wireStyle: viewer === null ? null : targetWireStyle(viewer.graph) });
21771
+ }
21772
+
21773
+ // Wire styles as draw.io's Waypoints menu sets them (Menus.js, edgeStyleChange): the keys
21774
+ // each one writes, null removing a key
21775
+ var WIRE_STYLES = {
21776
+ straight: { edgeStyle: null, curved: null, noEdgeStyle: null, elbow: null },
21777
+ orthogonal: { edgeStyle: "orthogonalEdgeStyle", curved: null, noEdgeStyle: null, elbow: null },
21778
+ curved: { edgeStyle: "orthogonalEdgeStyle", curved: "1", noEdgeStyle: null, elbow: null }
21779
+ };
21780
+
21781
+ function wireStyleOf(graph, cell) {
21782
+ var style = graph.getCurrentCellStyle(cell);
21783
+ if (style.noEdgeStyle == 1 || style.edgeStyle == null || style.edgeStyle === "none") return "straight";
21784
+ return style.curved == 1 ? "curved" : "orthogonal";
21785
+ }
21786
+
21787
+ function pageWires(graph) {
21788
+ var model = graph.getModel();
21789
+ return Object.keys(model.cells).map(function (id) { return model.cells[id]; }).filter(function (cell) { return model.isEdge(cell); });
21790
+ }
21791
+
21792
+ // The wires a choice changes: the selected ones, else all of the page's
21793
+ function targetWires(graph) {
21794
+ var selected = graph.getSelectionCells().filter(function (cell) { return graph.getModel().isEdge(cell); });
21795
+ return selected.length > 0 ? selected : pageWires(graph);
21796
+ }
21797
+
21798
+ function targetWireStyle(graph) {
21799
+ var wires = targetWires(graph);
21800
+ if (wires.length === 0) return newWireStyle(graph);
21801
+ var first = wireStyleOf(graph, wires[0]);
21802
+ for (var i = 1; i < wires.length; i++) if (wireStyleOf(graph, wires[i]) !== first) return "mixed";
21803
+ return first;
21804
+ }
21805
+
21806
+ function newWireStyle(graph) {
21807
+ var current = graph.currentEdgeStyle || {};
21808
+ if (current.edgeStyle == null || current.edgeStyle === "none") return "straight";
21809
+ return current.curved == "1" ? "curved" : "orthogonal";
21810
+ }
21811
+
21812
+ // New wires take this style (Graph.createCurrentEdgeStyle reads currentEdgeStyle)
21813
+ function setNewWireStyle(graph, name) {
21814
+ var current = mxUtils.clone(graph.currentEdgeStyle || {});
21815
+ var keys = WIRE_STYLES[name];
21816
+ for (var key in keys) {
21817
+ if (keys[key] === null) delete current[key];
21818
+ else current[key] = keys[key];
21819
+ }
21820
+ graph.currentEdgeStyle = current;
21821
+ }
21822
+
21823
+ // One model update: one undo takes it back. Waypoints go, as draw.io resets them: laid out
21824
+ // for one style, they make no sense in another
21825
+ function applyWireStyle(name) {
21826
+ if (touch === null || viewer === null || !WIRE_STYLES[name]) return;
21827
+ var graph = viewer.graph;
21828
+ if (graph.isEditing()) graph.stopEditing(false);
21829
+ var wires = targetWires(graph);
21830
+ var model = graph.getModel();
21831
+ model.beginUpdate();
21832
+ try {
21833
+ for (var i = 0; i < wires.length; i++) {
21834
+ graph.resetEdge(wires[i]);
21835
+ var keys = WIRE_STYLES[name];
21836
+ for (var key in keys) graph.setCellStyles(key, keys[key], [wires[i]]);
21837
+ }
21838
+ } finally {
21839
+ model.endUpdate();
21840
+ }
21841
+ setNewWireStyle(graph, name);
21842
+ changed();
21770
21843
  }
21771
21844
 
21772
21845
  // The viewer holds back the editing core it bundles; this lets it go, for the page shown
@@ -21805,6 +21878,13 @@ div.mxRubberband { position: absolute; overflow: hidden; border: 1px solid #29b6
21805
21878
  if (height > container.offsetHeight) shown.updateContainerHeight(container, height);
21806
21879
  };
21807
21880
  graph.getModel().addListener(mxEvent.CHANGE, grow);
21881
+ // New wires start in the style most of the page's wires have: an agent's diagonal wires
21882
+ // get diagonal neighbours, not draw.io's orthogonal default
21883
+ var counts = { straight: 0, orthogonal: 0, curved: 0 };
21884
+ pageWires(graph).forEach(function (cell) { counts[wireStyleOf(graph, cell)] += 1; });
21885
+ var most = counts.orthogonal >= counts.straight && counts.orthogonal >= counts.curved ? "orthogonal" : counts.straight >= counts.curved ? "straight" : "curved";
21886
+ setNewWireStyle(graph, most);
21887
+ graph.getSelectionModel().addListener(mxEvent.CHANGE, changed);
21808
21888
  graph.addListener(mxEvent.EDITING_STARTED, changed);
21809
21889
  graph.addListener(mxEvent.EDITING_STOPPED, changed);
21810
21890
  // The keys are the graph's own, not the document's: mxKeyHandler only takes an event
@@ -21869,6 +21949,7 @@ div.mxRubberband { position: absolute; overflow: hidden; border: 1px solid #29b6
21869
21949
  viewer.graph.getModel().removeListener(current.record);
21870
21950
  viewer.graph.getModel().removeListener(current.grow);
21871
21951
  viewer.graph.removeListener(changed);
21952
+ viewer.graph.getSelectionModel().removeListener(changed);
21872
21953
  viewer.graph.getView().removeListener(current.record);
21873
21954
  }
21874
21955
  }
@@ -21947,6 +22028,7 @@ div.mxRubberband { position: absolute; overflow: hidden; border: 1px solid #29b6
21947
22028
  else if (data.type === M.UNDO) undoOrRedo(false);
21948
22029
  else if (data.type === M.REDO) undoOrRedo(true);
21949
22030
  else if (data.type === M.EXPORT_SVG) exportSvg();
22031
+ else if (data.type === M.WIRE_STYLE && typeof data.style === "string") applyWireStyle(data.style);
21950
22032
  });
21951
22033
 
21952
22034
  if (typeof GraphViewer === "undefined") {
@@ -21998,6 +22080,10 @@ var WT = "allow-scripts", GT = 1e4, KT = te(function({ xml: e, serverUrl: t, tit
21998
22080
  markClean: () => x({ type: zT.CLEAN }),
21999
22081
  undo: () => x({ type: zT.UNDO }),
22000
22082
  redo: () => x({ type: zT.REDO }),
22083
+ setWireStyle: (e) => x({
22084
+ type: zT.WIRE_STYLE,
22085
+ style: e
22086
+ }),
22001
22087
  exportSvg: () => S(zT.EXPORT_SVG, zT.SVG)
22002
22088
  })), w(() => {
22003
22089
  let e = v.current;
@@ -22010,11 +22096,20 @@ var WT = "allow-scripts", GT = 1e4, KT = te(function({ xml: e, serverUrl: t, tit
22010
22096
  else if (n.type === zT.FAILED) {
22011
22097
  let e = typeof n.message == "string" ? n.message : "The diagram could not be drawn.";
22012
22098
  _(e), y.current.onRendered?.(e);
22013
- } else n.type === zT.CHANGED ? y.current.onTouchUpChange?.({
22014
- dirty: n.dirty === !0,
22015
- canUndo: n.canUndo === !0,
22016
- canRedo: n.canRedo === !0
22017
- }) : n.type === zT.FOCUS ? d.current !== null && document.activeElement !== d.current && d.current.focus({ preventScroll: !0 }) : n.type === zT.ESCAPE ? y.current.onEscape?.() : n.type === zT.PAGE_LOCKED ? y.current.onPageLocked?.() : n.type === zT.SAVED && typeof n.xml == "string" && typeof n.page == "number" ? (e.get(zT.SAVED)?.resolve({
22099
+ } else if (n.type === zT.CHANGED) {
22100
+ let e = [
22101
+ "straight",
22102
+ "orthogonal",
22103
+ "curved",
22104
+ "mixed"
22105
+ ].includes(n.wireStyle) ? n.wireStyle : void 0;
22106
+ y.current.onTouchUpChange?.({
22107
+ dirty: n.dirty === !0,
22108
+ canUndo: n.canUndo === !0,
22109
+ canRedo: n.canRedo === !0,
22110
+ ...e ? { wireStyle: e } : {}
22111
+ });
22112
+ } else n.type === zT.FOCUS ? d.current !== null && document.activeElement !== d.current && d.current.focus({ preventScroll: !0 }) : n.type === zT.ESCAPE ? y.current.onEscape?.() : n.type === zT.PAGE_LOCKED ? y.current.onPageLocked?.() : n.type === zT.SAVED && typeof n.xml == "string" && typeof n.page == "number" ? (e.get(zT.SAVED)?.resolve({
22018
22113
  page: n.page,
22019
22114
  xml: n.xml
22020
22115
  }), e.delete(zT.SAVED)) : n.type === zT.SVG && typeof n.svg == "string" && typeof n.page == "number" && (e.get(zT.SVG)?.resolve({
@@ -22328,6 +22423,38 @@ function cE({ path: e, xml: t, variant: n, fallback: r, onTouchUpDirtyChange: i
22328
22423
  title: "Redo (⇧⌘Z / Ctrl+Y)",
22329
22424
  children: "↷ redo"
22330
22425
  }),
22426
+ /* @__PURE__ */ k("label", {
22427
+ className: "inline-flex items-center gap-1 text-xs text-zinc-500 dark:text-zinc-400",
22428
+ title: "How the selected wires are drawn — or every wire of the page when none is selected — and new wires too",
22429
+ children: ["wires", /* @__PURE__ */ k("select", {
22430
+ className: Ce,
22431
+ "aria-label": "Wire style",
22432
+ value: S.wireStyle ?? "orthogonal",
22433
+ onChange: (t) => {
22434
+ let n = t.target.value;
22435
+ n !== "mixed" && le(e).current?.setWireStyle(n);
22436
+ },
22437
+ children: [
22438
+ /* @__PURE__ */ O("option", {
22439
+ value: "straight",
22440
+ children: "straight"
22441
+ }),
22442
+ /* @__PURE__ */ O("option", {
22443
+ value: "orthogonal",
22444
+ children: "orthogonal"
22445
+ }),
22446
+ /* @__PURE__ */ O("option", {
22447
+ value: "curved",
22448
+ children: "curved"
22449
+ }),
22450
+ S.wireStyle === "mixed" && /* @__PURE__ */ O("option", {
22451
+ value: "mixed",
22452
+ disabled: !0,
22453
+ children: "mixed"
22454
+ })
22455
+ ]
22456
+ })]
22457
+ }),
22331
22458
  /* @__PURE__ */ O("button", {
22332
22459
  type: "button",
22333
22460
  className: Ce,