Skip to content

Commit e1d7eac

Browse files
committed
upd linked-block
1 parent 6a8762c commit e1d7eac

File tree

8 files changed

+161
-126
lines changed

8 files changed

+161
-126
lines changed

examples/linked-block.html

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
<div class="text-bold ml-2" id="mouse-position">0:0</div>
2323
</div>
2424
<div class="app-bar-container gap-2" style="position: absolute; left: 50%; transform: translateX(-50%);">
25-
<button onclick="createBlocksZTop()">Z Top</button>
26-
<button onclick="createBlocksZBottom()">Z Bottom</button>
27-
<button onclick="createBlocksZSide()">Z Side</button>
25+
<button onclick="createBlocksSTop()">S Top</button>
26+
<button onclick="createBlocksSBottom()">S Bottom</button>
27+
<button onclick="createBlocksSSide()">S Side</button>
2828
<button onclick="createBlocksCTop()">C Top</button>
2929
<button onclick="createBlocksCBottom()">C Bottom</button>
3030
<button onclick="createBlocksCSide()">C Side</button>
@@ -34,7 +34,7 @@
3434
</div>
3535
</nav>
3636

37-
<main id="container" class="h-100 pos-relative" style="--linked-block-point-color: #ff0000; --linked-block-line-width: 2px"></main>
37+
<main id="container" class="h-100 pos-relative" style="--linked-block-point-color: #f00;"></main>
3838

3939
<script>
4040
window.metroLinkedBlockSetup = {
@@ -50,7 +50,7 @@
5050

5151
window.metroConnectorSetup = {
5252
deleteButton: true,
53-
// arrow: true,
53+
arrow: "end",
5454
// lineStyle: "dotted",
5555
// type: 'zigzag'
5656
}
@@ -77,14 +77,13 @@
7777
var blockCount = 0;
7878
var container = $('#container');
7979

80-
function createBlocksZTop () {
80+
function createBlocksSTop () {
8181
blockCount++;
8282
const block1 = Metro.linkedBlock.create({
8383
content: `Block ${blockCount}`,
8484
container,
8585
top: 100,
8686
left: 100,
87-
createConnectionType: "zigzag"
8887
});
8988
block1.addPoint("north")
9089

@@ -98,11 +97,11 @@
9897
block2.addPoint("north")
9998

10099
block1.connect(block2, {
101-
type: "zigzag"
100+
type: "step"
102101
})
103102
}
104103

105-
function createBlocksZBottom () {
104+
function createBlocksSBottom () {
106105
blockCount++;
107106
const block1 = Metro.linkedBlock.create({
108107
content: `Block ${blockCount}`,
@@ -122,11 +121,11 @@
122121
block2.addPoint("south")
123122

124123
block1.connect(block2.element, {
125-
type: "zigzag"
124+
type: "step"
126125
})
127126
}
128127

129-
function createBlocksZSide () {
128+
function createBlocksSSide () {
130129
blockCount++;
131130
const block1 = Metro.linkedBlock.create({
132131
content: `Block ${blockCount}`,
@@ -144,7 +143,7 @@
144143
});
145144

146145
block1.connect(block2.element, {
147-
type: "zigzag"
146+
type: "step"
148147
})
149148
}
150149

@@ -203,8 +202,6 @@
203202
container,
204203
top: 300,
205204
left: 900,
206-
canResize: false,
207-
canDrag: false,
208205
});
209206

210207
blockCount++;
@@ -213,9 +210,6 @@
213210
container,
214211
top: 350,
215212
left: 1100,
216-
canResize: true,
217-
canDrag: true,
218-
onePoint: true,
219213
});
220214

221215
block1.connect(block2.element, {

lib/metro.css

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66458,25 +66458,25 @@ label:has(input) {
6645866458

6645966459
/* source/components/linked-block/linked-block.less */
6646066460
:root {
66461-
--linked-block-point-size: 7px;
66462-
--linked-block-point-color: #b1b1b1;
66461+
--linked-block-point-size: 5px;
66462+
--linked-block-link-color: #b1b1b1;
6646366463
--linked-block-line-width: 1px;
66464-
--linked-block-min-width: 100px;
66465-
--linked-block-min-height: 20px;
6646666464
--linked-block-border-radius: 4px;
6646766465
--linked-block-points-gap: 4px;
6646866466
--linked-block-background: var(--default-background);
6646966467
--linked-block-color: #191919;
66470-
--linked-block-border-color: #b1b1b1;
66471-
--linked-block-line-color: #b1b1b1;
66468+
--linked-block-point-color: var(--linked-block-link-color);
66469+
--linked-block-border-color: var(--linked-block-link-color);
66470+
--linked-block-line-color: var(--linked-block-link-color);
6647266471
--linked-block-border-color-active: #676767;
6647366472
}
6647466473
.dark-side {
6647566474
--linked-block-background: var(--default-background);
6647666475
--linked-block-color: #ffffff;
66477-
--linked-block-border-color: #656a70;
66478-
--linked-block-line-color: #656a70;
66479-
--linked-block-point-color: #656a70;
66476+
--linked-block-link-color: #656a70;
66477+
--linked-block-border-color: var(--linked-block-link-color);
66478+
--linked-block-line-color: var(--linked-block-link-color);
66479+
--linked-block-point-color: var(--linked-block-link-color);
6648066480
--linked-block-border-color-active: #ffffff;
6648166481
}
6648266482
.linked-block {

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: 58 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -30962,7 +30962,7 @@
3096230962
resizeHotkey: null,
3096330963
dragHotkey: null,
3096430964
connectionType: "curve",
30965-
// line, curve, zigzag
30965+
// line, curve, step
3096630966
connectionStyle: "solid",
3096730967
// solid, dashed, dotted
3096830968
onePoint: false,
@@ -31704,15 +31704,16 @@
3170431704
pointA: null,
3170531705
pointB: null,
3170631706
type: "curve",
31707-
// line, curve, zigzag
31707+
// line, curve, step
3170831708
container: null,
3170931709
// контейнер для SVG
3171031710
autoUpdate: true,
3171131711
// автоматичне оновлення при переміщенні блоків
3171231712
id: null,
3171331713
// унікальний ID для з'єднання
3171431714
deleteButton: false,
31715-
arrow: false,
31715+
arrow: "none",
31716+
// none, end, start, both
3171631717
lineStyle: "solid",
3171731718
// solid, dashed, dotted
3171831719
onConnectorCreate: Metro2.noop,
@@ -31767,10 +31768,7 @@
3176731768
this.svgElement = sharedSvg;
3176831769
const shape = this._createShape(o2.id, o2.type, sharedSvg);
3176931770
const deleteBtn = this._createDeleteButton(sharedSvg, o2.id);
31770-
if (o2.arrow) {
31771-
const markerId = this._ensureArrowMarker(sharedSvg);
31772-
shape.attr("marker-end", `url(#${markerId})`);
31773-
}
31771+
this._applyArrows(shape, sharedSvg);
3177431772
this._applyLineStyle(shape, o2.lineStyle);
3177531773
this.connections.set(o2.id, {
3177631774
pointA: o2.pointA,
@@ -31857,46 +31855,52 @@
3185731855
}
3185831856
return svg;
3185931857
},
31858+
// Маркер-стрілка з вашого SVG, зменшений у 2 рази
3186031859
_ensureArrowMarker: (svg) => {
3186131860
const ns = "http://www.w3.org/2000/svg";
31862-
const markerId = "connector-arrow";
31861+
const markerId = Hooks.useId("connector-arrow");
3186331862
let defs = svg.find("defs");
3186431863
if (!defs.length) {
3186531864
const d4 = document.createElementNS(ns, "defs");
3186631865
svg[0].appendChild(d4);
3186731866
defs = $7(d4);
3186831867
}
31869-
let marker = defs.find(`#${markerId}`);
31868+
const marker = defs.find(`#${markerId}`);
3187031869
if (!marker.length) {
3187131870
const m5 = document.createElementNS(ns, "marker");
3187231871
m5.setAttribute("id", markerId);
31873-
m5.setAttribute("markerWidth", "6");
31874-
m5.setAttribute("markerHeight", "6");
31875-
m5.setAttribute("refX", "5");
31876-
m5.setAttribute("refY", "3");
31877-
m5.setAttribute("orient", "auto");
31878-
m5.setAttribute("markerUnits", "strokeWidth");
31879-
const line1 = document.createElementNS(ns, "line");
31880-
line1.setAttribute("x1", "1");
31881-
line1.setAttribute("y1", "1");
31882-
line1.setAttribute("x2", "5");
31883-
line1.setAttribute("y2", "3");
31884-
line1.setAttribute("stroke", "context-stroke");
31885-
line1.setAttribute("stroke-linecap", "round");
31886-
const line2 = document.createElementNS(ns, "line");
31887-
line2.setAttribute("x1", "1");
31888-
line2.setAttribute("y1", "5");
31889-
line2.setAttribute("x2", "5");
31890-
line2.setAttribute("y2", "3");
31891-
line2.setAttribute("stroke", "context-stroke");
31892-
line2.setAttribute("stroke-linecap", "round");
31893-
m5.appendChild(line1);
31894-
m5.appendChild(line2);
31872+
m5.setAttribute("markerWidth", "12");
31873+
m5.setAttribute("markerHeight", "12");
31874+
m5.setAttribute("viewBox", "0 0 8 8");
31875+
m5.setAttribute("refX", "6");
31876+
m5.setAttribute("refY", "4");
31877+
m5.setAttribute("orient", "auto-start-reverse");
31878+
m5.setAttribute("markerUnits", "userSpaceOnUse");
31879+
const path = document.createElementNS(ns, "path");
31880+
path.setAttribute(
31881+
"d",
31882+
"M1,8 c-0.04,0-0.08-0.016-0.11-0.045 c-0.048-0.05-0.055-0.125-0.018-0.185 L3.45,4 L0.87,0.23 c-0.038-0.058-0.03-0.135,0.018-0.185 c0.048-0.05,0.125-0.06,0.185-0.026 L7.4,3.54 c0.046,0.026,0.075,0.076,0.075,0.13 s-0.029,0.103-0.075,0.13 L1.06,7.32 C0.96,7.38,0.93,7.96,1,8z"
31883+
);
31884+
path.setAttribute("fill", "var(--linked-block-line-color)");
31885+
path.setAttribute("stroke", "none");
31886+
m5.appendChild(path);
3189531887
defs[0].appendChild(m5);
31896-
marker = $7(m5);
3189731888
}
3189831889
return markerId;
3189931890
},
31891+
_applyArrows: function(shape, svg) {
31892+
const o2 = this.options;
31893+
const value = o2.arrow === true ? "end" : o2.arrow || "none";
31894+
shape.removeAttr("marker-start").removeAttr("marker-end");
31895+
if (value === "none" || value === false) return;
31896+
const markerId = this._ensureArrowMarker(svg);
31897+
if (value === "start" || value === "both") {
31898+
shape.attr("marker-start", `url(#${markerId})`);
31899+
}
31900+
if (value === "end" || value === "both") {
31901+
shape.attr("marker-end", `url(#${markerId})`);
31902+
}
31903+
},
3190031904
_createShape: (id, type, svg) => {
3190131905
const ns = "http://www.w3.org/2000/svg";
3190231906
let el;
@@ -32065,7 +32069,7 @@
3206532069
const pathData = `M ${x1} ${y1} C ${cp1x} ${cp1y} ${cp2x} ${cp2y} ${x22} ${y22}`;
3206632070
path.attr("d", pathData);
3206732071
},
32068-
_updateZigzag: function(pointA, pointB, shape) {
32072+
_updateStep: function(pointA, pointB, shape) {
3206932073
const point1 = $7(pointA);
3207032074
const point2 = $7(pointB);
3207132075
const parent1 = point1.parent();
@@ -32256,7 +32260,7 @@
3225632260
},
3225732261
// Публічні методи
3225832262
setType: function(type) {
32259-
if (["line", "curve", "zigzag"].indexOf(type) === -1) {
32263+
if (["line", "curve", "step"].indexOf(type) === -1) {
3226032264
console.warn("Connector: \u043D\u0435\u0432\u0456\u0434\u043E\u043C\u0438\u0439 \u0442\u0438\u043F \u0437'\u0454\u0434\u043D\u0430\u043D\u043D\u044F:", type);
3226132265
return;
3226232266
}
@@ -32267,10 +32271,7 @@
3226732271
const oldShape = connection?.shape;
3226832272
const svg = connection?.svg || this.svgElement || this._getOrCreateSharedSVG(o2.container);
3226932273
const newShape = this._createShape(o2.id, type, svg);
32270-
if (o2.arrow) {
32271-
const markerId = this._ensureArrowMarker(svg);
32272-
newShape.attr("marker-end", `url(#${markerId})`);
32273-
}
32274+
this._applyArrows(newShape, svg);
3227432275
this._applyLineStyle(newShape, o2.lineStyle);
3227532276
if (oldShape?.length) {
3227632277
oldShape.remove();
@@ -32311,8 +32312,8 @@
3231132312
case "curve":
3231232313
this._updateCurve(connection.pointA, connection.pointB, connection.shape);
3231332314
break;
32314-
case "zigzag":
32315-
this._updateZigzag(connection.pointA, connection.pointB, connection.shape);
32315+
case "step":
32316+
this._updateStep(connection.pointA, connection.pointB, connection.shape);
3231632317
break;
3231732318
}
3231832319
this._positionDeleteButton(connection);
@@ -32334,13 +32335,30 @@
3233432335
this._applyLineStyle(connection.shape, o2.lineStyle);
3233532336
this.update();
3233632337
},
32338+
setArrow: function(value) {
32339+
const map = { true: "end", false: "none" };
32340+
const v5 = typeof value === "boolean" ? map[String(value)] : String(value || "none").toLowerCase();
32341+
if (!["none", "start", "end", "both"].includes(v5)) {
32342+
console.warn("Connector: \u043D\u0435\u0432\u0456\u0434\u043E\u043C\u0435 \u0437\u043D\u0430\u0447\u0435\u043D\u043D\u044F \u0434\u043B\u044F arrow:", value);
32343+
return;
32344+
}
32345+
this.options.arrow = v5;
32346+
const connection = this.connections.get(this.options.id);
32347+
if (connection?.shape && connection?.svg) {
32348+
this._applyArrows(connection.shape, connection.svg);
32349+
this.update();
32350+
}
32351+
},
3233732352
changeAttribute: function(attr, newValue) {
3233832353
if (attr === "data-type") {
3233932354
this.setType(newValue);
3234032355
}
3234132356
if (attr === "data-line-style") {
3234232357
this.setLineStyle(newValue);
3234332358
}
32359+
if (attr === "data-arrow") {
32360+
this.setArrow(newValue);
32361+
}
3234432362
},
3234532363
destroy: function() {
3234632364
const o2 = this.options;

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.

source/components/linked-block/linked-block.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
addButtons: "north east south west",
2727
resizeHotkey: null,
2828
dragHotkey: null,
29-
connectionType: "curve", // line, curve, zigzag
29+
connectionType: "curve", // line, curve, step
3030
connectionStyle: "solid", // solid, dashed, dotted
3131
onePoint: false,
3232
canDrag: true,

source/components/linked-block/linked-block.less

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
:root {
2-
--linked-block-point-size: 7px;
3-
--linked-block-point-color: #b1b1b1;
2+
--linked-block-point-size: 5px;
3+
--linked-block-link-color: #b1b1b1;
44
--linked-block-line-width: 1px;
5-
--linked-block-min-width: 100px;
6-
--linked-block-min-height: 20px;
75
--linked-block-border-radius: 4px;
86
--linked-block-points-gap: 4px;
97
--linked-block-background: var(--default-background);
108
--linked-block-color: #191919;
11-
--linked-block-border-color: #b1b1b1;
12-
--linked-block-line-color: #b1b1b1;
9+
--linked-block-point-color: var(--linked-block-link-color);
10+
--linked-block-border-color: var(--linked-block-link-color);
11+
--linked-block-line-color: var(--linked-block-link-color);
1312
--linked-block-border-color-active: #676767;
1413
}
1514

1615
.dark-side {
1716
--linked-block-background: var(--default-background);
1817
--linked-block-color: #ffffff;
19-
--linked-block-border-color: #656a70;
20-
--linked-block-line-color: #656a70;
21-
--linked-block-point-color: #656a70;
18+
--linked-block-link-color: #656a70;
19+
--linked-block-border-color: var(--linked-block-link-color);
20+
--linked-block-line-color: var(--linked-block-link-color);
21+
--linked-block-point-color: var(--linked-block-link-color);
2222
--linked-block-border-color-active: #ffffff;
2323
}
2424

0 commit comments

Comments
 (0)