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.

Extend example in doc

See original GitHub issue

Hi there. Great job already! Thank you guys.

Would really love to see an example of how to pass a prop to a custom extension. for example i copied your TodoItem-extension and tried to pass an object in like this:

<ul data-type="todo_list">
    <li 
        :custom-prop="customProp"
        data-type="todo_item" 
        data-done="true">
         Buy beer
    </li>
</ul>

and then tried to use this custom-prop inside of the template logic of TodoItem, but it wasn’t available there. is there a way to achive something like this? an example-code for this in the doc would help not only me, but also other.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
philippkuehncommented, Aug 30, 2018

Ah, I think I know what you have tried to do. You wanted to pass custom props like this right?

<editor>
    <div slot="content" slot-scope="props">
      <ul data-type="todo_list">
        <li 
          :custom-prop="customProp"
          data-type="todo_item" 
          data-done="true">
            Buy beer
        </li>
      </ul>
    </div>
</editor>

You’ll have to add custom-prop to your schema correctly. Based on the todo_item extension this will look something like this:

get schema() {
  return {
    attrs: {
      done: {
        default: false,
      },
      customProp: {
        default: null,
      },
    },
    draggable: false,
    content: 'paragraph',
    toDOM(node) {
      const { done, customProp } = node.attrs

      return ['li', {
          'data-type': 'todo_item',
          'data-done': done.toString(),
          'custom-prop': customProp.toString(),
        },
        ['span', { class: 'todo-checkbox', contenteditable: 'false' }],
        ['div', { class: 'todo-content' }, 0],
      ]
    },
    parseDOM: [{
      priority: 51,
      tag: '[data-type="todo_item"]',
      getAttrs: dom => ({
        done: dom.getAttribute('data-done') === 'true',
        customProp: dom.getAttribute('custom-prop'),
      }),
    }],
  }
}

After that you will have access to customProp in your vue component:

get view() {
  return {
    props: ['node', 'updateAttrs', 'editable'],
    methods: {
      onChange() {
        this.updateAttrs({
          done: !this.node.attrs.done,
        })
      },
    },
    template: `
      <li data-type="todo_item" :data-done="node.attrs.done.toString()">
        <span class="todo-checkbox" contenteditable="false" @click="onChange"></span>
        <div class="todo-content" ref="content" :contenteditable="editable.toString()"></div>
        <div>
          {{ node.attrs.customProp }}
        </DIV>
      </li>
    `,
  }
}

Please note that customProp will not be reactive, because everything you pass to the editor will be parsed and rendered from Prosemirror. So any reactivity breaks here. If you need reactivity here, you’ll have to use some state management like Vuex.

0reactions
laurensiusadicommented, Apr 3, 2019

@rameezcubet You can bind v-model to a computed with get() and set() like this

computed: {
  customValue: { 
    get() {
      return this.$store.getters.customValue
    },
    set(customValue){
      this.$store.commit('setCustomValue', customValue)
    }
  }
},
Read more comments on GitHub >

github_iconTop Results From Across the Web

extend — Python Reference (The Right Way) 0.1 documentation
Extends the list by appending all the items from the iterable. Syntax¶. list. extend(iterable). iterable: Required. Any iterable type.
Read more >
jQuery.extend() | jQuery API Documentation
When two or more object arguments are supplied to $.extend() , properties from all of the objects are added to the target object....
Read more >
extends - The flexible, fast, and secure PHP template engine
In this example, the template will extend the "minimum.html" layout template if the standalone variable evaluates to true , and "base.html" otherwise. How...
Read more >
extends - JavaScript - MDN Web Docs - Mozilla
The extends keyword is used in class declarations or class expressions to create a class that is a child of another class.
Read more >
Sass: @extend
When one class extends another, Sass styles all elements that match the extender as though they also match the class being extended. When...
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 Hashnode Post

No results found