Preserve referenced SVG definitions when pasting across documents - #1104
Merged
Conversation
Reviewer's GuideImplements a versioned, cross-document-aware SVG clipboard format that collects and pastes recursively referenced defs while preserving existing in-document behavior and extension hooks. Sequence diagram for cross-document SVG paste with defs and conflict resolutionsequenceDiagram
actor User
participant Editor
participant SvgCanvas
participant pasteElementsMethod
participant clipboard_js as clipboard_js
User->>Editor: trigger paste
Editor->>SvgCanvas: pasteElements(type, x, y)
SvgCanvas->>pasteElementsMethod: pasteElementsMethod(type, x, y)
pasteElementsMethod->>sessionStorage: getItem(CLIPBOARD_ID)
pasteElementsMethod->>clipboard_js: normalizeClipboardData(parsed)
clipboard_js-->>pasteElementsMethod: clipboard
pasteElementsMethod->>clipboard_js: getClipboardDocumentId(svgContent)
clipboard_js-->>pasteElementsMethod: sourceDocumentId
pasteElementsMethod->>pasteElementsMethod: [decide same vs cross document]
alt cross-document with dependencies
pasteElementsMethod->>pasteElementsMethod: pasteAcrossDocuments(clipboard, type, x, y)
pasteElementsMethod->>clipboard_js: indexDependencies(clipboard.dependencies)
pasteElementsMethod->>clipboard_js: getTargetElementsById()
pasteElementsMethod->>clipboard_js: createEquivalenceChecker(...)
pasteElementsMethod->>clipboard_js: collectReachableRoots(...)
pasteElementsMethod->>clipboard_js: resolveUseConflicts(conflicts)
clipboard_js->>SvgCanvas: call('resolveClipboardConflicts', { conflicts })
SvgCanvas->>Editor: resolveClipboardConflicts
Editor->>Editor: seConfirm(message, options)
Editor-->>SvgCanvas: 'use-existing'|'replace-existing'|'keep-both'|'cancel'
SvgCanvas-->>clipboard_js: policy
clipboard_js-->>pasteElementsMethod: policy
opt policy !== 'cancel'
pasteElementsMethod->>clipboard_js: remapJsonReferences(...)
pasteElementsMethod->>clipboard_js: remapJsonElementIds(...)
pasteElementsMethod->>SvgCanvas: addSVGElementsFromJson(dependency)
SvgCanvas-->>pasteElementsMethod: insertedDependencies
pasteElementsMethod->>SvgCanvas: addSVGElementsFromJson(element)
SvgCanvas-->>pasteElementsMethod: pasted
pasteElementsMethod->>SvgCanvas: setUseData(svgContent)
pasteElementsMethod->>SvgCanvas: addCommandToHistory(BatchCommand)
pasteElementsMethod->>SvgCanvas: call('changed', pasted)
end
else same-document or legacy clipboard
pasteElementsMethod->>pasteElementsMethod: pasteInSameDocument(elements,...)
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
jfhenon
approved these changes
Aug 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR description
Summary
Cross-document paste previously copied only the selected SVG elements. References to external definitions such as
symbol,gradient,filter,mask,clipPath, andpatterncould therefore become unresolved in the target document.This PR introduces a versioned clipboard payload that includes the recursively referenced definitions required by the copied elements.
Behavior
defs.usetarget has the same ID but different content:usereferences correctly during paste, undo, and redo.Tests
useelement whosesymbolreferences a gradient.Verification completed:
Checklist
Note that we require UI tests to ensure that the added feature will not be
nixed by some future fix and that there is at least some test-as-documentation
to indicate how the fix or enhancement is expected to behave.
npm test, ensuring linting passes and that Cypress UI tests keepcoverage to at least the same percent (reflected in the coverage badge
that should be updated after the tests run)
help both for future users and for the PR reviewer.
Summary by Sourcery
Add versioned SVG clipboard payloads that include required defs and support cross-document paste with dependency resolution and conflict handling.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests: