Skip to content

Commit aa0c736

Browse files
committed
add one svg to linked-blocks
1 parent e057167 commit aa0c736

File tree

8 files changed

+224
-1153
lines changed

8 files changed

+224
-1153
lines changed

examples/linked-block.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
const block2 = Metro.linkedBlock.create({
108108
content: `Block ${blockCount}`,
109109
container,
110-
top: 200,
110+
top: 50,
111111
left: 1100,
112112
resizable: true,
113113
});
@@ -185,7 +185,7 @@
185185
const block2 = Metro.linkedBlock.create({
186186
content: `Block ${blockCount}`,
187187
container,
188-
top: 400,
188+
top: 350,
189189
left: 1100,
190190
resizable: true,
191191
});

lib/metro.css

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -66425,7 +66425,7 @@ label:has(input) {
6642566425
:root {
6642666426
--linked-block-point-size: 7px;
6642766427
--linked-block-point-color: #b1b1b1;
66428-
--linked-block-line-width: 1px;
66428+
--linked-block-line-width: 2px;
6642966429
--linked-block-min-size: 100px;
6643066430
--linked-block-border-radius: 4px;
6643166431
--linked-block-background: var(--default-background);
@@ -66450,6 +66450,7 @@ label:has(input) {
6645066450
border: 1px solid var(--linked-block-border-color);
6645166451
border-radius: var(--linked-block-border-radius);
6645266452
user-select: none;
66453+
z-index: 1;
6645366454
}
6645466455
.linked-block .north-side,
6645566456
.linked-block .east-side,
@@ -66554,14 +66555,7 @@ label:has(input) {
6655466555
left: 0;
6655566556
width: 100%;
6655666557
height: 100%;
66557-
pointer-events: none;
66558-
cursor: pointer;
66559-
}
66560-
.connection-line .cl-line,
66561-
.connection-line .cl-curve {
66562-
transition: stroke 0.2s ease, stroke-width 0.2s ease;
66563-
stroke-width: 8px;
66564-
stroke: transparent;
66558+
z-index: 0;
6656566559
}
6656666560
.connection-line .cl-line {
6656766561
stroke-width: var(--linked-block-line-width);
@@ -66571,31 +66565,15 @@ label:has(input) {
6657166565
stroke-width: var(--linked-block-line-width);
6657266566
stroke: var(--linked-block-line-color);
6657366567
}
66574-
.connector-delete-btn {
66575-
position: absolute;
66576-
display: none;
66577-
width: 24px;
66578-
height: 24px;
66579-
border: 1px solid var(--linked-block-border-color);
66580-
border-radius: 50%;
66581-
background: var(--linked-block-background);
66568+
.connection-line .cl-line,
66569+
.connection-line .cl-curve {
66570+
transition: stroke 0.2s ease, stroke-width 0.2s ease;
66571+
fill: none;
6658266572
cursor: pointer;
66583-
z-index: 1000;
66584-
padding: 2px;
66585-
transition: all 0.2s ease;
66586-
}
66587-
.connector-delete-btn:hover {
66588-
background: #ff6b6b;
66589-
border-color: #ff5252;
66590-
transform: scale(1.1);
66591-
}
66592-
.connector-delete-btn svg {
66593-
width: 100%;
66594-
height: 100%;
66595-
fill: var(--linked-block-line-color);
6659666573
}
66597-
.connector-delete-btn:hover svg {
66598-
fill: white;
66574+
.connection-line .cl-line.selected-path,
66575+
.connection-line .cl-curve.selected-path {
66576+
stroke: #0a87c1;
6659966577
}
6660066578

6660166579
/* source/components/list/list.less */

lib/metro.css.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/metro.js

Lines changed: 91 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝
99

1010
* Metro UI v5.1.17 Components Library (https://metroui.org.ua)
11-
* Build: 19.08.2025, 09:35:25
11+
* Build: 19.08.2025, 11:53:09
1212
* Copyright 2012-2025 by Serhii Pimenov
1313
* Licensed under MIT
1414
*/
@@ -11308,7 +11308,7 @@
1130811308
(($7) => {
1130911309
"use strict";
1131011310
globalThis["__version__"] = "5.1.17";
11311-
globalThis["__build_time__"] = "19.08.2025, 09:35:25";
11311+
globalThis["__build_time__"] = "19.08.2025, 11:53:09";
1131211312
const meta_init = $7.meta("metro:init").attr("content");
1131311313
const meta_cloak = $7.meta("metro:cloak").attr("content");
1131411314
const meta_cloak_duration = $7.meta("metro:cloak_duration").attr("content");
@@ -11657,7 +11657,7 @@
1165711657
const normalizeComponentName2 = (name2) => typeof name2 !== "string" ? void 0 : name2.replace(/-/g, "").toLowerCase();
1165811658
const Metro2 = {
1165911659
version: "5.1.17",
11660-
build_time: "19.08.2025, 09:35:25",
11660+
build_time: "19.08.2025, 11:53:09",
1166111661
buildNumber: 0,
1166211662
isTouchable: isTouch3,
1166311663
fullScreenEnabled: document.fullscreenEnabled,
@@ -31378,7 +31378,8 @@
3137831378
this._super(elem, options, ConnectorDefaultConfig, {
3137931379
connections: /* @__PURE__ */ new Map(),
3138031380
svgElement: null,
31381-
observers: /* @__PURE__ */ new Map()
31381+
observers: /* @__PURE__ */ new Map(),
31382+
deleteButton: null
3138231383
});
3138331384
return this;
3138431385
},
@@ -31409,22 +31410,33 @@
3140931410
console.warn("Connector: PointA and PointB are required to create connection");
3141031411
return;
3141131412
}
31412-
this.svgElement = this._createSVG(o2.id, o2.type);
31413-
$7(o2.container).append(this.svgElement);
31414-
this.update();
31413+
const sharedSvg = this._getOrCreateSharedSVG(o2.container);
31414+
this.svgElement = sharedSvg;
31415+
const shape = this._createShape(o2.id, o2.type, sharedSvg);
3141531416
this.connections.set(o2.id, {
3141631417
pointA: o2.pointA,
3141731418
pointB: o2.pointB,
3141831419
type: o2.type,
31419-
svg: this.svgElement
31420+
svg: sharedSvg,
31421+
shape
3142031422
});
31423+
this.update();
3142131424
},
3142231425
_createEvents: function() {
3142331426
const element2 = this.element;
3142431427
const o2 = this.options;
31428+
const self = this;
3142531429
if (o2.autoUpdate) {
3142631430
this._setupAutoUpdate();
3142731431
}
31432+
$7(document).on("click", ".cl-curve, .cl-line", (e2) => {
31433+
const target = $7(e2.target);
31434+
$7(target).toggleClass("selected-path");
31435+
e2.stopPropagation();
31436+
});
31437+
$7(document).on("click", (e2) => {
31438+
$7(".cl-line, .cl-curve").removeClass("selected-path");
31439+
});
3142831440
},
3142931441
_setupAutoUpdate: function() {
3143031442
const o2 = this.options;
@@ -31462,42 +31474,75 @@
3146231474
setTimeout(() => self.update(), 10);
3146331475
});
3146431476
},
31477+
// ... existing code ...
3146531478
_createSVG: (id, type) => {
3146631479
let svg;
3146731480
if (type === "line") {
3146831481
svg = $7(`
3146931482
<svg id="${id}" class="connection-line">
31470-
<line class="cl-line"
31471-
stroke="var(--linked-block-line-color)"
31472-
stroke-width="var(--linked-block-line-width)"/>
31483+
<line class="cl-line"/>
3147331484
</svg>
3147431485
`);
3147531486
} else {
3147631487
svg = $7(`
3147731488
<svg id="${id}" class="connection-line">
31478-
<path class="cl-curve"
31479-
stroke="var(--linked-block-line-color)"
31480-
stroke-width="var(--linked-block-line-width)"
31481-
fill="none"/>
31489+
<path class="cl-curve"/>
3148231490
</svg>
3148331491
`);
3148431492
}
3148531493
return svg;
3148631494
},
31495+
_getOrCreateSharedSVG: (container) => {
31496+
const $container = $7(container);
31497+
let svg = $container.children("svg.connection-line").first();
31498+
if (!svg.length) {
31499+
if ($container.css("position") === "static") {
31500+
$container.css("position", "relative");
31501+
}
31502+
const ns = "http://www.w3.org/2000/svg";
31503+
const svgEl = document.createElementNS(ns, "svg");
31504+
svgEl.setAttribute("xmlns", ns);
31505+
svgEl.setAttribute("class", "connection-line");
31506+
svg = $7(svgEl).css({
31507+
position: "absolute",
31508+
top: 0,
31509+
left: 0,
31510+
width: "100%",
31511+
height: "100%",
31512+
zIndex: 0
31513+
});
31514+
$container.append(svg);
31515+
}
31516+
return svg;
31517+
},
31518+
_createShape: (id, type, svg) => {
31519+
const ns = "http://www.w3.org/2000/svg";
31520+
let el;
31521+
if (type === "line") {
31522+
el = document.createElementNS(ns, "line");
31523+
el.setAttribute("class", "cl-line");
31524+
} else {
31525+
el = document.createElementNS(ns, "path");
31526+
el.setAttribute("class", "cl-curve");
31527+
}
31528+
el.setAttribute("data-conn-id", id);
31529+
svg[0].appendChild(el);
31530+
return $7(el);
31531+
},
3148731532
// Публічні методи
3148831533
update: function() {
3148931534
const o2 = this.options;
3149031535
const connection = this.connections.get(o2.id);
3149131536
if (!connection) return;
3149231537
switch (o2.type) {
3149331538
case "line":
31494-
this._updateLine(connection.pointA, connection.pointB, connection.svg);
31539+
this._updateLine(connection.pointA, connection.pointB, connection.shape);
3149531540
break;
3149631541
case "curve":
31497-
this._updateCurve(connection.pointA, connection.pointB, connection.svg);
31542+
this._updateCurve(connection.pointA, connection.pointB, connection.shape);
3149831543
break;
3149931544
case "zigzag":
31500-
this._updateZigzag(connection.pointA, connection.pointB, connection.svg);
31545+
this._updateZigzag(connection.pointA, connection.pointB, connection.shape);
3150131546
break;
3150231547
}
3150331548
this._fireEvent("connector-update", {
@@ -31513,14 +31558,19 @@
3151331558
const o2 = this.options;
3151431559
const oldType = o2.type;
3151531560
o2.type = type;
31516-
const oldSvg = this.svgElement;
31517-
this.svgElement = this._createSVG(o2.id, type);
31518-
oldSvg.replaceWith(this.svgElement);
31561+
const connection = this.connections.get(o2.id);
31562+
const oldShape = connection?.shape;
31563+
const svg = connection?.svg || this.svgElement || this._getOrCreateSharedSVG(o2.container);
31564+
const newShape = this._createShape(o2.id, type, svg);
31565+
if (oldShape && oldShape.length) {
31566+
oldShape.remove();
31567+
}
3151931568
this.connections.set(o2.id, {
31520-
...this.connections.get(o2.id),
31569+
...connection,
3152131570
type,
3152231571
old: oldType,
31523-
svg: this.svgElement
31572+
svg,
31573+
shape: newShape
3152431574
});
3152531575
this.update();
3152631576
},
@@ -31540,10 +31590,11 @@
3154031590
this.update();
3154131591
},
3154231592
// Приватні методи оновлення
31543-
_updateLine: (pointA, pointB, svg) => {
31593+
_updateLine: (pointA, pointB, shape) => {
3154431594
const point1 = $7(pointA);
3154531595
const point2 = $7(pointB);
31546-
const line = svg.find(".cl-line");
31596+
const line = shape;
31597+
const svg = line.closest("svg");
3154731598
const rect1 = point1.offset();
3154831599
const rect2 = point2.offset();
3154931600
const svgRect = svg.offset();
@@ -31562,12 +31613,13 @@
3156231613
y2: y22
3156331614
});
3156431615
},
31565-
_updateCurve: function(pointA, pointB, svg) {
31616+
_updateCurve: function(pointA, pointB, shape) {
3156631617
const point1 = $7(pointA);
3156731618
const point2 = $7(pointB);
3156831619
const parent1 = point1.parent();
3156931620
const parent2 = point2.parent();
31570-
const path = svg.find(".cl-curve");
31621+
const path = shape;
31622+
const svg = path.closest("svg");
3157131623
const coords = this._getCoordinates(point1, point2, svg);
3157231624
const { x1, y1, x2: x22, y2: y22 } = coords;
3157331625
const dx = x22 - x1;
@@ -31623,12 +31675,13 @@
3162331675
const pathData = `M ${x1} ${y1} C ${cp1x} ${cp1y} ${cp2x} ${cp2y} ${x22} ${y22}`;
3162431676
path.attr("d", pathData);
3162531677
},
31626-
_updateZigzag: function(pointA, pointB, svg) {
31678+
_updateZigzag: function(pointA, pointB, shape) {
3162731679
const point1 = $7(pointA);
3162831680
const point2 = $7(pointB);
3162931681
const parent1 = point1.parent();
3163031682
const parent2 = point2.parent();
31631-
const path = svg.find(".cl-curve");
31683+
const path = shape;
31684+
const svg = path.closest("svg");
3163231685
const coords = this._getCoordinates(point1, point2, svg);
3163331686
const { x1, y1, x2: x22, y2: y22 } = coords;
3163431687
let pathData;
@@ -31793,8 +31846,16 @@
3179331846
destroy: function() {
3179431847
const o2 = this.options;
3179531848
this._cleanupAutoUpdate();
31849+
const connection = this.connections.get(o2.id);
31850+
if (connection?.shape) {
31851+
const svg = connection.svg || this.svgElement;
31852+
connection.shape.remove();
31853+
if (svg && svg.find(".cl-line, .cl-curve").length === 0) {
31854+
svg.remove();
31855+
}
31856+
}
3179631857
if (this.svgElement) {
31797-
this.svgElement.remove();
31858+
this.svgElement = null;
3179831859
}
3179931860
this.connections.delete(o2.id);
3180031861
this._fireEvent("connector-destroy", {

lib/metro.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)