Skip to content

Commit

Permalink
fix(NcRichText): apply interactivity
Browse files Browse the repository at this point in the history
Signed-off-by: DorraJaouad <dorra.jaoued7@gmail.com>
  • Loading branch information
DorraJaouad committed Apr 5, 2024
1 parent 5e9e8a5 commit 24c4aeb
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions src/components/NcRichText/NcRichText.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,28 @@ Table row | value A | value B
}
},
methods: {
handleInteraction(event) {
const uncheckedItem = '- [ ] ' + event.label + '\n'
const checkedItem = '- [x] ' + event.label + '\n'
this.text = event.value
? this.text.replace(uncheckedItem, checkedItem)
: this.text.replace(checkedItem, uncheckedItem)
handleInteraction(id) {
const index = this.$children[0].$children.findIndex(child => child.$options.propsData.id === id)
if (index === -1 ) {
return
}
let checkBoxIndex = 0
lines = this.text.split('\n')
for (let i = 0; i < lines.length; i++) {
if (lines[i].includes('[ ]') || lines[i].includes('[x]')) {
if (checkBoxIndex === index) {
const isChecked = lines[i].includes('[x]')
if (isChecked) {
lines[i] = lines[i].replace('[x]', '[ ]')
} else {
lines[i] = lines[i].replace('[ ]', '[x]')
}
break
}
checkBoxIndex++
}
}
this.text = lines.join('\n')
},
},
}
Expand Down Expand Up @@ -458,7 +473,9 @@ export default {
const nestedListIndex = labelParts.findIndex((child) => child.tag === 'ul' || child.tag === 'li')
if (nestedListIndex !== -1) {
nestedList = labelParts[nestedListIndex]
nestedList.data.attrs.style = 'margin-inline-start: 20px;'
if (nestedList.data?.attrs) {
nestedList.data.attrs.style = 'margin-inline-start: 20px;'
}
labelParts.splice(nestedListIndex)
}
Expand All @@ -470,8 +487,8 @@ export default {
disabled: !this.interactive,
},
on: {
'update:checked': (value) => {
this.$emit('interact:todo', { id, label: labelParts.join(''), value })
'update:checked': () => {
this.$emit('interact:todo', id)
},
},
}, labelParts)
Expand Down

0 comments on commit 24c4aeb

Please sign in to comment.