fix: contedtable

This commit is contained in:
2026-03-13 13:56:42 +01:00
parent da165c1a98
commit baaa3efcdd
6 changed files with 108 additions and 23 deletions

View File

@@ -0,0 +1,37 @@
import { ref, type Ref } from 'vue'
import DOMPurify from 'dompurify'
import { useProductStore } from '@/stores/product'
export function useEditable() {
const isEditing = ref(false)
const productStore = useProductStore()
const removeAttribute = (editableRef: HTMLElement | null) => {
if (!editableRef) return
isEditing.value = true
Array.from(editableRef.children).forEach(item => {
item.setAttribute('contenteditable', 'true')
console.log('lllllll')
})
}
const setAttribute = async (editableRef: HTMLElement | null): Promise<string | undefined> => {
if (!editableRef) return
Array.from(editableRef.children).forEach(item => {
item.setAttribute('contenteditable', 'false')
})
isEditing.value = false
const html = editableRef.innerHTML
const cleanHtml = DOMPurify.sanitize(html)
await productStore.saveProductDescription(cleanHtml)
return cleanHtml
}
return {
isEditing,
removeAttribute,
setAttribute
}
}