Skip to content

Commit

Permalink
fix(block-editor): Fix Open link in new window checkbox in the block …
Browse files Browse the repository at this point in the history
…editor. Don't save the selection. #25842

* Fixed target on link url in block editor - images

* Resolved comments on PR
  • Loading branch information
KevinDavilaDotCMS authored Oct 2, 2023
1 parent ed071e0 commit 46e4e00
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,16 @@ export class BubbleLinkFormView {
}

setLinkValues({ link, blank = false }) {
if (link.length > 0) {
const href = this.formatLink(link);
this.isImageNode()
? this.editor.commands.setImageLink({ href })
: this.editor.commands.setLink({ href, target: blank ? '_blank' : '_top' });
if (!link.length) {
return;
}

const href = this.formatLink(link);
const linkValue = { href, target: blank ? '_blank' : '_top' };

this.isImageNode()
? this.editor.commands.setImageLink(linkValue)
: this.editor.commands.setLink(linkValue);
}

removeLink() {
Expand Down Expand Up @@ -239,10 +243,10 @@ export class BubbleLinkFormView {
}

getLinkProps(): NodeProps {
const { href: link = '', target } = this.editor.isActive('link')
const { href: link = '', target = '_top' } = this.editor.isActive('link')
? this.editor.getAttributes('link')
: this.editor.getAttributes(ImageNode.name);
const blank = target ? target === '_blank' : true;
const blank = target === '_blank';

return { link, blank };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { DotCMSContentlet } from '@dotcms/dotcms-models';
const LANGUAGE_ID = 'language_id';

export const imageLinkElement = (attrs, newAttrs): DOMOutputSpec => {
const { href = null } = newAttrs;
const { href = null, target } = newAttrs;

return ['a', { href }, imageElement(attrs, newAttrs)];
return ['a', { href, target }, imageElement(attrs, newAttrs)];
};

export const imageElement = (attrs, newAttrs): DOMOutputSpec => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ declare module '@tiptap/core' {
/**
* Set Image Link mark
*/
setImageLink: (attributes: { href: string }) => ReturnType;
setImageLink: (attributes: { href: string; target?: string }) => ReturnType;
/**
* Unset Image Link mark
*/
Expand Down Expand Up @@ -62,6 +62,11 @@ export const ImageNode = Image.extend({
default: null,
parseHTML: (element) => element.getAttribute('data'),
renderHTML: (attributes) => ({ data: JSON.stringify(attributes.data) })
},
target: {
default: null,
parseHTML: (element) => element.getAttribute('target'),
renderHTML: (attributes) => ({ target: attributes.target })
}
};
},
Expand Down
2 changes: 1 addition & 1 deletion dotCMS/src/main/webapp/html/dotcms-block-editor.js

Large diffs are not rendered by default.

0 comments on commit 46e4e00

Please sign in to comment.