question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

updateAttrs on EditorMenus ?

See original GitHub issue

In #622 there was getNodeAttr added. But to update a node, such as setting the alt of an image, we need updateAttrs? I assumed I could do something like this, but that fails:

  <editor-menu-bubble
      v-slot="{ commands, isActive, getNodeAttrs, updateAttrs, getMarkAttrs, menu }"
      :editor="editor"
      keep-in-bounds
    >
      <div>
 
      </div>
    </editor-menu-bubble>

<script>
[...]
  imageAlt: {
      get () {
        return this.getNodeAttrs('image').alt // .alt , .src  or .title
      },
      set (value) {
        const alt = value
        this.updateAttrs({ alt )
        console.log('alt was set to',  this.getNodeAttrs('image').alt)
      }
    },
[...]
</script>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
gambolputtycommented, Apr 23, 2020

You could create a command that updates the node:

  commands ({ type, schema }) {
    return {
      updateNode: attrs => {
        return (state, dispatch) => {
          const { node, from } = state.selection // must be a node selection, so make sure "node" is present 

          const tr = state.tr
          tr.setNodeMarkup(from, null, Object.assign({}, node.attrs, attrs))
          dispatch(tr)

          return true
        }
      }
    }
  }

Then in my Vue component I call this:

methods: {
    updateNode (value) {
      const command = this.editor.commands.updateNode
      command({ myAttr: value })
    }
  }

Hope that helps!

1reaction
hanspagelcommented, Jan 7, 2021

Thanks @gambolputty for sharing! We’ve also added something like that to the upcoming tiptap v2. 👀

Closing this here for now. ✌️

Read more comments on GitHub >

github_iconTop Results From Across the Web

updateAttrs on EditorMenus ? · Issue #676 · ueberdosis/tiptap
In #622 there was getNodeAttr added. But to update a node, such as setting the alt of an image, we need updateAttrs?
Read more >
Create menus – Tiptap Editor
Most editor menus use icons for their buttons. In some of our demos, we use the open source icon set Remix Icon, which...
Read more >
terminal initialRows still isn't working completely right C++ - GitAnswer
tiptap updateAttrs on EditorMenus ? - TypeScript · Allow control over when two values are equal (for dirty checking and to possibly prevent...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found