From 8de63bb4467e3dbb7302fa0924bda4def8218300 Mon Sep 17 00:00:00 2001 From: joostdecock Date: Wed, 6 Sep 2023 08:57:43 +0200 Subject: [PATCH] feat(core): Do not render snippets by default when complete is false --- packages/core/src/snippet.mjs | 5 ++++- packages/core/src/svg.mjs | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/core/src/snippet.mjs b/packages/core/src/snippet.mjs index 80b1389d4f6..ab8f36bcdb1 100644 --- a/packages/core/src/snippet.mjs +++ b/packages/core/src/snippet.mjs @@ -11,13 +11,16 @@ import { Point } from './point.mjs' * @constructor * @param {string} def - The id of the snippet in the SVG defs section * @param {Point} anchor - The Point to anchor this Snippet on + * @param {boolean} force - Whether to force rendering of this snippet when complete is falsy (or not) * @return {Snippet} this - The Snippet instance */ -export function Snippet(def, anchor) { +export function Snippet(def, anchor, force = false) { this.def = def this.anchor = anchor this.attributes = new Attributes() + if (force) this.attributes.set('data-force', 1) + return this } diff --git a/packages/core/src/svg.mjs b/packages/core/src/svg.mjs index d87cb79609d..32771c4e74f 100644 --- a/packages/core/src/svg.mjs +++ b/packages/core/src/svg.mjs @@ -336,6 +336,8 @@ Svg.prototype.__renderPart = function (part) { * @return {string} svg - The SVG markup for the snippet */ Svg.prototype.__renderSnippet = function (snippet) { + // If complete is not set, only render snippets with the data-force attribute + if (!this.pattern.settings[0].complete && !snippet.attributes.get('data-force')) return '' let x = round(snippet.anchor.x) let y = round(snippet.anchor.y) let scale = snippet.attributes.get('data-scale') || 1