Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(preview-support): add copied marker as part of djs-visual #906

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions assets/diagram-js.css
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,17 @@ svg.new-parent {
stroke: none !important;
}

marker.djs-dragger circle,
marker.djs-dragger path,
marker.djs-dragger polygon,
marker.djs-dragger polyline,
marker.djs-dragger rect {
.djs-dragger marker circle,
.djs-dragger marker path,
.djs-dragger marker polygon,
.djs-dragger marker polyline,
.djs-dragger marker rect {
fill: var(--element-dragger-color) !important;
stroke: none !important;
}

marker.djs-dragger text,
marker.djs-dragger tspan {
.djs-dragger marker text,
.djs-dragger marker tspan {
fill: none !important;
stroke: var(--element-dragger-color) !important;
}
Expand Down
2 changes: 0 additions & 2 deletions lib/features/complex-preview/ComplexPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ export default class ComplexPreview {
this._markers.forEach(([ element, marker ]) => this._canvas.removeMarker(element, marker));

this._markers = [];

this._previewSupport.cleanUp();
}

show() {
Expand Down
36 changes: 12 additions & 24 deletions lib/features/preview-support/PreviewSupport.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import {
forEach
} from 'min-dash';

import {
append as svgAppend,
attr as svgAttr,
classes as svgClasses,
clone as svgClone,
create as svgCreate,
remove as svgRemove
} from 'tiny-svg';

import { query as domQuery } from 'min-dom';
Expand Down Expand Up @@ -57,12 +52,6 @@
this._styles = styles;

this._clonedMarkers = {};

var self = this;

eventBus.on('drag.cleanup', function() {
self.cleanUp();
});
}

PreviewSupport.$inject = [
Expand All @@ -72,14 +61,10 @@
'styles'
];

// Markers are cleaned up with visuals, keep stub for compatibility
// cf. https://github.com/camunda/camunda-modeler/issues/4307
PreviewSupport.prototype.cleanUp = function() {
var self = this;

forEach(self._clonedMarkers, function(clonedMarker) {
svgRemove(clonedMarker);
});

self._clonedMarkers = {};
console.warn('PreviewSupport#cleanUp is deprecated and will be removed in future versions. You do not need to manually clean up previews anymore. cf. https://github.com/bpmn-io/diagram-js/pull/906');

Check warning on line 67 in lib/features/preview-support/PreviewSupport.js

View check run for this annotation

Codecov / codecov/patch

lib/features/preview-support/PreviewSupport.js#L67

Added line #L67 was not covered by tests
};

/**
Expand Down Expand Up @@ -154,7 +139,7 @@
* @param {SVGElement} gfx
* @param {string} [className="djs-dragger"]
*/
PreviewSupport.prototype._cloneMarkers = function(gfx, className = 'djs-dragger') {
PreviewSupport.prototype._cloneMarkers = function(gfx, className = 'djs-dragger', rootGfx = gfx) {
var self = this;

if (gfx.childNodes) {
Expand All @@ -163,7 +148,7 @@
for (var i = 0; i < gfx.childNodes.length; i++) {

// recursively clone markers of child nodes
self._cloneMarkers(gfx.childNodes[ i ], className);
self._cloneMarkers(gfx.childNodes[ i ], className, rootGfx);
}
}

Expand All @@ -175,7 +160,8 @@
if (svgAttr(gfx, markerType)) {
var marker = getMarker(gfx, markerType, self._canvas.getContainer());

self._cloneMarker(gfx, marker, markerType, className);
// Only clone marker if it is already present on the DOM
marker && self._cloneMarker(rootGfx, gfx, marker, markerType, className);
}
});
};
Expand All @@ -188,11 +174,13 @@
* @param {string} markerType
* @param {string} [className="djs-dragger"]
*/
PreviewSupport.prototype._cloneMarker = function(gfx, marker, markerType, className = 'djs-dragger') {
PreviewSupport.prototype._cloneMarker = function(parentGfx, gfx, marker, markerType, className = 'djs-dragger') {
var markerId = marker.id + '-' + className;

var clonedMarker = this._clonedMarkers[ markerId ];

parentGfx = parentGfx || this._canvas._svg;

if (!clonedMarker) {
clonedMarker = svgClone(marker);

Expand All @@ -204,12 +192,12 @@

this._clonedMarkers[ markerId ] = clonedMarker;

var defs = domQuery('defs', this._canvas._svg);
var defs = domQuery(':scope > defs', parentGfx);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the support for :scope within CSS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything except IE11

image


if (!defs) {
defs = svgCreate('defs');

svgAppend(this._canvas._svg, defs);
svgAppend(parentGfx, defs);
}

svgAppend(defs, clonedMarker);
Expand Down
17 changes: 15 additions & 2 deletions test/spec/features/complex-preview/ComplexPreviewSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,19 @@ describe('features/complex-preview', function() {

// given
complexPreview.create({
created: [
newShape
moved: [
{
element: shape1,
delta: { x: 100, y: 100 }
},
{
element: shape2,
delta: { x: 100, y: 100 }
},
{
element: connection,
delta: { x: 100, y: 100 }
}
]
});

Expand All @@ -240,6 +251,8 @@ describe('features/complex-preview', function() {
expect(layer).to.exist;

expect(layer.childNodes).to.have.length(0);
expect(domQuery('marker#marker-start-djs-dragging-clone', canvas.getContainer())).not.to.exist;
expect(domQuery('marker#marker-end-djs-dragging-clone', canvas.getContainer())).not.to.exist;
}));

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ MarkerRenderer.prototype.addMarker = function(gfx, markerType) {

svgAppend(marker, circle);

defs = domQuery('defs', this._canvas._svg);
defs = domQuery(':scope > defs', this._canvas._svg);

if (!defs) {
defs = svgCreate('defs');
Expand Down