Commit 404f20a4 authored by Himanshu Kapoor's avatar Himanshu Kapoor

Make link toolbar button consistent with image button

parent 463f51d6
...@@ -43,7 +43,7 @@ export default { ...@@ -43,7 +43,7 @@ export default {
}, },
mounted() { mounted() {
this.tiptapEditor.on('selectionUpdate', ({ editor }) => { this.tiptapEditor.on('selectionUpdate', ({ editor }) => {
const { 'data-canonical-src': canonicalSrc, href } = editor.getAttributes(linkContentType); const { canonicalSrc, href } = editor.getAttributes(linkContentType);
this.linkHref = canonicalSrc || href; this.linkHref = canonicalSrc || href;
}); });
...@@ -56,7 +56,7 @@ export default { ...@@ -56,7 +56,7 @@ export default {
.unsetLink() .unsetLink()
.setLink({ .setLink({
href: this.linkHref, href: this.linkHref,
'data-canonical-src': this.linkHref, canonicalSrc: this.linkHref,
}) })
.run(); .run();
......
...@@ -38,11 +38,11 @@ export const tiptapExtension = Link.extend({ ...@@ -38,11 +38,11 @@ export const tiptapExtension = Link.extend({
}; };
}, },
}, },
'data-canonical-src': { canonicalSrc: {
default: null, default: null,
parseHTML: (element) => { parseHTML: (element) => {
return { return {
href: element.dataset.canonicalSrc, canonicalSrc: element.dataset.canonicalSrc,
}; };
}, },
}, },
...@@ -57,7 +57,7 @@ export const serializer = { ...@@ -57,7 +57,7 @@ export const serializer = {
return '['; return '[';
}, },
close(state, mark) { close(state, mark) {
const href = mark.attrs['data-canonical-src'] || mark.attrs.href; const href = mark.attrs.canonicalSrc || mark.attrs.href;
return `](${state.esc(href)}${mark.attrs.title ? ` ${state.quote(mark.attrs.title)}` : ''})`; return `](${state.esc(href)}${mark.attrs.title ? ` ${state.quote(mark.attrs.title)}` : ''})`;
}, },
}; };
...@@ -76,15 +76,17 @@ describe('content_editor/components/toolbar_link_button', () => { ...@@ -76,15 +76,17 @@ describe('content_editor/components/toolbar_link_button', () => {
expect(commands.unsetLink).toHaveBeenCalled(); expect(commands.unsetLink).toHaveBeenCalled();
expect(commands.setLink).toHaveBeenCalledWith({ expect(commands.setLink).toHaveBeenCalledWith({
href: 'https://example', href: 'https://example',
'data-canonical-src': 'https://example', canonicalSrc: 'https://example',
}); });
expect(commands.run).toHaveBeenCalled(); expect(commands.run).toHaveBeenCalled();
expect(wrapper.emitted().execute[0]).toEqual([{ contentType: 'link' }]);
}); });
describe('on selection update', () => { describe('on selection update', () => {
it('updates link input box with canonical-src if present', async () => { it('updates link input box with canonical-src if present', async () => {
jest.spyOn(editor, 'getAttributes').mockReturnValueOnce({ jest.spyOn(editor, 'getAttributes').mockReturnValueOnce({
'data-canonical-src': 'uploads/my-file.zip', canonicalSrc: 'uploads/my-file.zip',
href: '/username/my-project/uploads/abcdefgh133535/my-file.zip', href: '/username/my-project/uploads/abcdefgh133535/my-file.zip',
}); });
...@@ -130,9 +132,11 @@ describe('content_editor/components/toolbar_link_button', () => { ...@@ -130,9 +132,11 @@ describe('content_editor/components/toolbar_link_button', () => {
expect(commands.focus).toHaveBeenCalled(); expect(commands.focus).toHaveBeenCalled();
expect(commands.setLink).toHaveBeenCalledWith({ expect(commands.setLink).toHaveBeenCalledWith({
href: 'https://example', href: 'https://example',
'data-canonical-src': 'https://example', canonicalSrc: 'https://example',
}); });
expect(commands.run).toHaveBeenCalled(); expect(commands.run).toHaveBeenCalled();
expect(wrapper.emitted().execute[0]).toEqual([{ contentType: 'link' }]);
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment