What is the process for importing the nodeViewProps object from TipTap in a Vue 3 script setup?

Currently utilizing TipTap, a Rich Text Editor that implements props in vue components (composition api) by importing them as follows:

<script>
import { nodeViewProps } from '@tiptap/vue-3'

export default {

  props: nodeViewProps

}

</script>

Upon logging nodeViewProps, it displays an object of objects:

{0: false, 1: true, editor: {…}, node: {…}, decorations: {…}, selected: {…}, extension: {…}, …}
  0: false
  1: true
  decorations: {required: true, type: ƒ}
  deleteNode: {required: true, type: ƒ}
  editor: {required: true, type: ƒ}
  extension: {required: true, type: ƒ}
  getPos: {required: true, type: ƒ}
  node: {required: true, type: ƒ}
  selected: {required: true, type: ƒ}
  updateAttributes: {required: true, type: ƒ}
  [[Prototype]]: Object

The challenge lies in importing this prop object within the context of script setup. I've attempted various approaches without success:

<script setup>
import {nodeViewProps} from '@tiptap/vue-3'

const props = defineProps([
    nodeViewProps
])

const props = defineProps([
    'nodeViewProps'
])

const props = defineProps({
    nodeViewProps: nodeViewProps
})

const props = defineProps({
    node: nodeViewProps
})

</script>

Unfortunately, none of the above methods appear to be correct.

console.log(props.nodeViewProps)

This statement results in undefined being outputted.

Answer №1

Here is how it functions within the realm of script setup. Interestingly enough, there is no longer a requirement to import nodeViewProps. Instead, a default node prop object is automatically passed to your Vue component, which can be accessed as follows:

<script setup>
import {NodeViewWrapper} from '@tiptap/vue-3'


const props = defineProps({
    node: {
        type: Object,
        required: true
    },
    updateAttributes: {
        type: Function,
        required: true,
    }
})

const increase = () => {
    props.updateAttributes({
        count: props.node.attrs.count + 1,
    })
}
</script>

This particular component is sourced from their official documentation. In its original guise, it appears like this:

<template>
  <node-view-wrapper class="vue-component">
    <span class="label">Vue Component</span>

    <div class="content">
      <button @click="increase">
        This button has been clicked {{ node.attrs.count }} times.
      </button>
    </div>
  </node-view-wrapper>
</template>

<script>
import { NodeViewWrapper, nodeViewProps } from '@tiptap/vue-3'

export default {
  components: {
    NodeViewWrapper,
  },

  props: nodeViewProps,

  methods: {
    increase() {
      this.updateAttributes({
        count: this.node.attrs.count + 1,
      })
    },
  },
}
</script>

Answer №2

Another way to bring in all of the nodeViewProps is by using this flexible approach:

<script setup>
import { nodeViewProps } from '@tiptap/vue-3'
const props = defineProps(nodeViewProps)
</script>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The CSS classes for the dropzonejs are not being properly updated for editing purposes

I'm currently facing an issue where I am attempting to include an editable area inside a dropzone, but for some reason, the editable area is not visible within the dropzone and the CSS classes are not being applied. <a href="#" editable-text="us ...

How to toggle between checked and unchecked states using jQuery within AngularJS?

After reloading, the checkbox should maintain its checked or unchecked state. This functionality can be achieved using a directive controller. var checkboxValues = JSON.parse(localStorage.getItem('checkboxValues')) || {}, $checkboxes = $("#c ...

javascript ondrag while self-pressing

Within this div, I have a series of p elements. My goal is to drag the selected element into the input field. Here's an example: var input = document.getElementById("test"); input.addEventListener('drop', function (event) { event.pr ...

Ways to incorporate validation into Material-UI form input fields

I have a react functional component that utilizes Material UI form, which includes TextField. The onChange event is managed in the "Container Component". I have added required for client-side form validation, but it doesn't seem to be working. Do I ne ...

What is the most effective way to load data prior to the controller being loaded

Is there a way to fetch data from a service before the view and controller are loaded? I need assistance with this. resolve: { getAlbum: function(albumService){ return albumService.getAlbums(); },getAtum: function(albu ...

An element generated through JavaScript fails to display on the webpage

As I navigate through the code with a foreach() loop, my goal is to generate a new div every time a firebase document containing the user's email is encountered. The script involves a blend of react js and javascript as I am still learning the ropes o ...

How to change the date value in an HTML input field of type date using JavaScript

Struggling with manipulating an HTML date input type using javascript? You're not alone. The common approach to manipulating the date is like this: var c = new Date(); c.setDate(c.getDate() + 1); You can get the date from the input element: c = do ...

The node application route appears to be malfunctioning

Recently delving into the world of node JS, I encountered an issue while working on my application with the following 3 files. http.createServer(app).listen(**app.get('port')**, function(){ The error message reads 'undefined is not a func ...

I could use some assistance with implementing a remainder operator by incorporating it into an if statement and outputting the result to

let userInput = prompt('Please enter a number'); let userNumber = parseInt(userInput); let remainder = userNumber % 18; if (userNumber > 18) { console.log('You are old enough to drive!'); } else if (userNumber < 18 && userN ...

Looking for a Regex pattern for this example: 12345678/90 MM/DD/YYYY

I am having success with the first 10 digits spaced apart, but unfortunately my date regex is not working as expected. ^(\d{6}\s{2}|\d{8})\/(\d{1}\s|\d{2})\s\/(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))&bso ...

The Vue component is not displaying any data

Although Axios is successfully loading data, it's not displaying anything. Laravel Mix is also building without any errors. The code I have is as follows: index.html (body) <div id="app"> <posts></posts> </div> In app.j ...

ES6: Using DataURI to provide input results in undefined output

In my current project, I am facing a challenge. I am attempting to pass image dataURI as an input from a url link to the image. To achieve this task, I know that I have to utilize canvas and convert it from there. However, since this process involves an &a ...

Creating Bubble Charts using npm highcharts with error code #17

I am attempting to create a bubble chart using Highcharts with the npm version, but I keep encountering error #17. I have tried importing highcharts-more without success... Here are my imports: import $ from "jquery"; import _ from "underscore"; import L ...

The issue of JQuery selector failure within an AngularJS controller

In my current setup, I have viewA along with ControllerA. However, when an image is clicked on viewA, I need to switch over to another ViewB along with its corresponding ControllerB. In ViewB, there are multiple checkboxes which the user can interact wit ...

Contrast the values extracted from an array of objects with a string in React Native/Javascript

I am attempting to implement an If statement to compare a property from an object in an array with a String. I have set up a for-loop, but for some reason, the conditional statement does not seem to be triggering. Below is the code snippet I am using to sa ...

Encountering an issue in Vue where trying to set focus to a button results in the error "Cannot read property 'focus' of

I am a beginner with Vue and I have a component that triggers my generic 'Error' modal when the endpoint fails. Everything is working fine, but I am encountering the following error: Cannot read property 'focus' of undefined This erro ...

What is the best way to utilize jQuery.post in order to push JSON data to a php script?

I have a JSON object in my JavaScript code stored in the variable dataStore. I've confirmed that JSON.stringify is working correctly by testing it with console.log(). However, as someone new to jQuery and CGI applications, I may be missing something. ...

Utilizing Jquery to locate a link inside a Div and displaying it as specified in the HTML

Looking for a solution to make div elements clickable as links? The usual methods involving window.location or window.open may not be suitable if you have numerous divs with predefined targets. If you're not well-versed in Javascript, finding the righ ...

In search of a charts library that enables interactive, linked events

I need a library that can create charts similar to the "Annotated Time Lines" used in Google Finance. The library should not rely on Flash so it can work on all browsers and mobile devices like the iPad. I specifically need the ability to display linked ev ...

What steps should I follow to execute an external file in Gulp?

Currently, I am utilizing the "gulp-run" plugin to execute a .bat file. However, since that plugin has been deprecated, I am in search of the optimal method to run the .bat file. Code snippet: const gulp = require('gulp'); const run = require(& ...