fix: contedtable
This commit is contained in:
37
bo/src/composable/useConteditable.ts
Normal file
37
bo/src/composable/useConteditable.ts
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user