Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When I do undo it add extra one time inner text every time in inline blot #4292

Open
sagar-devineglobe opened this issue Jul 5, 2024 · 0 comments

Comments

@sagar-devineglobe
Copy link

import Quill from "quill"

import { MODAL_TYPE } from "~utils"

const chipHTML = (modalType: string, value: any) => {
switch (modalType) {
case MODAL_TYPE.DATE_TIME_FIELD:
return ' ' + value.format + ""
case MODAL_TYPE.DROPDOWN_FIELD:
return 'default ' + value.placeholder + ""
case MODAL_TYPE.CLIPBOARD:
return '' + value.type.toLowerCase() + ""
case MODAL_TYPE.CURSOR:
return '' + value.type.toLowerCase() + ""
case MODAL_TYPE.PARAGRAPH_FIELD:
case MODAL_TYPE.TEXT_FIELD:
return 'default ' + value.default + ""
default:
return ""
}
}

const Inline = Quill.import("blots/inline") as any
const generateUniqueId = () =>
shortcut-command-user-${Math.random().toString(36).substring(2, 11)}

class ChipBlot extends Inline {
static create(value) {
let node = super.create()
node.setAttribute("contenteditable", "false")
node.dataset.id = generateUniqueId()
node.setAttribute("data-value", JSON.stringify(value))
node.classList.add(ChipBlot.className)
const innerHTML = chipHTML(value.data.type, value.data)
node.innerHTML = innerHTML
return node
}

static formats(node) {
const data = JSON.parse(node.getAttribute("data-value"))
return data
}
static value(domNode) {
return domNode.dataset.id
}
}

ChipBlot.blotName = "chip"
ChipBlot.tagName = "span"
ChipBlot.className = "chip"

export default ChipBlot

version ^2.0.2

next js 14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant