How do I update attributes for a Mark?
See original GitHub issueHi - I am trying to create a text highlight feature where a user can select some text and add a highlight color to it.
I created a custom mark as follows -
export default class annotation extends Mark
{
get name()
{
return 'annotation'
}
get schema()
{
return {
attrs: {
"highlight-color" : {
default: "default"
},
},
// inclusive: false,
parseDOM: [
{
tag: 'annotation',
getAttrs: dom => ({
"highlight-color" :dom.getAttribute('highlight-color'),
}),
},
],
toDOM: node => ['annotation', {
"highlight-color" : node.attrs["highlight-color"]
}, 0],
}
}
commands({ type, schema })
{
return attrs =>
{
return updateMark(type, attrs);
}
}
get view()
{
return hightlight;
}
I created a custom Vue component to render it
<template>
<span class="highlight" @click="changeColor()">
<span :class="[colorClass]"
>
{{ node.textContent }}
</span>
</span>
</template>
<script>
export default {
name: "Hightlight",
props: ['node', 'updateAttrs', 'editable', 'options', 'view', 'getPos'],
computed:
{
colorClass : function()
{
return this.node.attrs["highlight-color"];
}
},
mounted()
{
console.log(this.node);
},
methods : {
changeColor : function()
{
console.log("Change Color");
let newClass = "yellow"
**HOW DO I SET THIS NEW CLASS ON THE MARK??**
}
}
}
</script>
I’m trying to add a new class to the mark based on user interaction. How do I update the color class? I tried using the “updateAttrs” prop but I keep getting “this.getPos is not a function”.
I am a bit lost so any help/direction would be really helpful.
Thanks!
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:12 (3 by maintainers)
Top Results From Across the Web
Updating mark attributes - Discuss - ProseMirror
I'm making a storytelling application that uses ProseMirror with a custom mark. This mark has one attribute, targetCharacters, ...
Read more >updateAttributes – Tiptap Editor
The updateAttributes command sets attributes of a node or mark to new values. Not passed attributes won't be touched.
Read more >How to Update Attributes through Import
4. Mark Update Existing Records, Validate Only, and select Attribute Import ID for the Use field. User-added image. 5. Select the File Layout...
Read more >Solved: How to Update attributes in an Online Feature Laye...
I have a large feature layer hosted in ArcGIS Online. I want to select a subset by matching a field attribute to a...
Read more >The attribute doesn't show up in the “Update Attributes” screen
To use this feature, you need to go to the products grid, mark the products that you want to update and click on...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve released a new version with a fix for
getPos()
. You should now be able to callupdateAttrs()
for marks. Currently this is limited to the parent node of a mark because of the current implementation ofgetMarkRange
. https://github.com/scrumpy/tiptap/blob/master/packages/tiptap-utils/src/utils/getMarkRange.jsBut it should be absolutely possible to extend
getMarkRange
to lookup in its siblings to improve it even further. Maybe someone will create a PR for that 😅Got it working with Marks for now with custom component. Am storing only the highlight-id in the attributes which I don’t really need to update. I am querying my API with the ID to render additional details like color etc. (Storing them outside of the document made the most sense for my use case).
The approach for creating slices and replacing data ended up causing a lot more issues, and marks seem the right way to go for this.
Thanks a lot for all the help!
In case it helps anyone else - here is the code I’m using for now -
HighlightView.vue