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 6128974
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 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 @@ -470,8 +485,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 6128974

Please sign in to comment.