From 13b8156937dc3203eb54cdf6021952e5944e1054 Mon Sep 17 00:00:00 2001 From: May Date: Sat, 22 Aug 2020 10:14:13 +1000 Subject: [PATCH] feat(tag blot): add tag blot #192 #192 --- src/blots/Tag.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/blots/Tag.ts diff --git a/src/blots/Tag.ts b/src/blots/Tag.ts new file mode 100644 index 00000000..4e52009d --- /dev/null +++ b/src/blots/Tag.ts @@ -0,0 +1,34 @@ +import { Quill } from 'react-quill' + +const Embed = Quill.import('blots/embed') + +interface TagParams { + displayName: string + id: string +} + +class Tag extends Embed { + static create(value: TagParams) { + const node = super.create(value) as HTMLElement + + node.setAttribute('href', `/tags/${value.id}`) + node.setAttribute('target', '_blank') + node.dataset.displayName = value.displayName + node.dataset.id = value.id + node.textContent = `#${value.displayName}` + + return node + } + + static value(domNode: HTMLElement) { + return domNode.dataset + } +} + +Tag.blotName = 'tag' +Tag.tagName = 'a' +Tag.className = 'tag' + +Quill.register('formats/tag', Tag) + +export default Tag