+ content-type="html" :ui="{ base: 'p-8 sm:px-16' }" class="w-full min-h-74"
+ placeholder="Write there ...">
@@ -362,13 +362,7 @@ const productID = ref(0)
const translating = ref(false)
const activeTab = ref('description')
-const usageRef = ref(null)
-const originalUsage = ref('')
const isEditing = ref(false)
-const usageEdit = useEditable(usageRef)
-const descriptionRef = ref(null)
-const descriptionEdit = useEditable(descriptionRef)
-const originalDescription = ref('')
const translateToSelectedLanguage = async () => {
if (toLangId.value && productID.value) {
@@ -377,8 +371,6 @@ const translateToSelectedLanguage = async () => {
await productStore.translateProductDescription(productID.value, toLangId.value)
} finally {
translating.value = false
- enableEdit()
- enableDescriptionEdit()
}
}
if (productStore.productDescription) {
@@ -389,7 +381,6 @@ const translateToSelectedLanguage = async () => {
const fetchForLanguage = async (langId: number | null) => {
if (productID.value) {
await productStore.getProductDescription(langId, productID.value)
- removeInlineStylesFromAll(productStore.productDescription)
}
}
@@ -409,116 +400,4 @@ const items = ref([
{ label: 'Description', slot: 'description', name: 'description' },
{ label: 'Usage', slot: 'usage', name: 'usage' }
])
-
-// text edit
-const enableEdit = () => {
- console.log(usageRef.value, 'usageRef');
-
- if (usageRef.value) {
- originalUsage.value = usageRef.value.innerHTML
- }
- isEditing.value = true
- usageEdit.enableEdit()
-}
-
-const enableDescriptionEdit = () => {
- console.log(usageRef.value, 'usageRef');
-
- if (descriptionRef.value) {
- originalDescription.value = descriptionRef.value.innerHTML
- }
- descriptionEdit.enableEdit()
-}
-
-const saveText = () => {
- if (usageRef.value) {
- productStore.productDescription.usage = usageRef.value.innerHTML
- }
-
- usageEdit.disableEdit()
- isEditing.value = false
-
- productStore.saveProductDescription(productID.value, toLangId.value)
-}
-
-const cancelEdit = () => {
- if (usageRef.value) {
- usageRef.value.innerHTML = originalUsage.value
- }
- usageEdit.disableEdit()
- isEditing.value = false
-}
-
-const saveDescription = async () => {
- if (descriptionRef.value) {
- productStore.productDescription.description = descriptionRef.value.innerHTML
- }
-
- descriptionEdit.disableEdit()
-
- await productStore.saveProductDescription(productID.value, toLangId.value)
- toLangId.value = settingStore.shopDefaultLanguage
- isTranslations.value = false
-}
-
-const cancelDescriptionEdit = () => {
- if (descriptionRef.value) {
- descriptionRef.value.innerHTML = originalDescription.value
- }
- descriptionEdit.disableEdit()
-}
-
-function removeInlineStylesFromAll(product) {
- if (!product) return
- const removeStyles = (html: string) => {
- if (!html) return ''
- const div = document.createElement('div')
- div.innerHTML = html
-
- div.querySelectorAll('*').forEach(el => {
- const bg = el.style.background || el.style.backgroundColor
- if (bg) {
- el.style.background = ''
- el.style.backgroundColor = ''
- }
- })
- div.querySelectorAll('p').forEach(p => {
- if (p.querySelector('img')) {
- p.style.display = 'flex'
- p.style.gap = '20px'
- p.style.padding = '30px 0'
- }
- })
- div.querySelectorAll('table').forEach(table => {
- table.querySelectorAll('tbody').forEach(tbody => {
- tbody.style.setProperty('background-color', '#F8FAFC', 'important')
- tbody.querySelectorAll('tr').forEach(tr => {
- tr.querySelectorAll('td').forEach(td => {
- td.style.setProperty('padding', '10px', 'important')
- td.style.setProperty('border-top', '1pt solid black', 'important')
- td.style.setProperty('border-left', '1pt solid black', 'important')
- td.style.setProperty('border-bottom', '1pt solid black', 'important')
- td.style.setProperty('border-right', '1pt solid black', 'important')
-
- td.querySelectorAll('p').forEach(p => {
- p.style.setProperty('display', 'flex', 'important')
- p.style.setProperty('padding', '0px', 'important')
- p.style.setProperty('align-items', 'start', 'important')
- p.style.setProperty('color', 'black', 'important')
- p.style.setProperty('font-size', '14px', 'important')
- p.querySelectorAll('span').forEach(span => {
- span.style.setProperty('color', 'black', 'important')
- span.style.setProperty('font-size', '14px', 'important')
- })
- })
- })
- })
- })
- })
- return div.innerHTML
- }
- product.description = removeStyles(product.description)
- product.description_short = removeStyles(product.description_short)
- product.usage = removeStyles(product.usage)
-}