[RFC] find a good API for using Vue.js node views
See original GitHub issueI am not happy how node view templates work in tiptap 1 and tiptap 2 and looking for a better solution.
There are a few requirements that make using node views more comfortable:
- set
white-space: normal
on node view wrapper - set
white-space: pre-wrap
on node view content - set a custom dragstart event listener (for better dragging support)
- a parent contenteditable=“false” has to be enabled again for node view content (based on isEditable)
Here are two solutions I’ve tried already:
1. provide a NodeViewWrapper and NodeViewContent component
usage:
<template>
<node-view-wrapper>
<node-view-content />
</node-view-wrapper>
</template>
rendered:
<div contenteditable="false" style="white-space: normal" :onDragStart="handleDragStart" contenteditable="false">
<div contenteditable="true" style="white-space: pre-wrap" :contenteditable="isEditable"></div>
</div>
good
- simple template
bad
<node-view-wrapper>
can’t be<node-view-content>
at the same time- currently both components are injected because with that I can bind the
handleDragStart
method. that’s why we can’t import them (which might be less confusing) but maybe there is a better way for doing that like adding the event handler afterwards
2. using data attributes
usage:
<template>
<div data-node-view contenteditable="false">
<div data-node-view-content :contenteditable="isEditable" />
</div>
</template>
tiptap provides some basic styling
[data-node-view] {
white-space: normal;
}
[data-node-view-content] {
white-space: pre-wrap;
}
good
- flexible
bad
- contenteditable has to be set manually
- missing
handleDragStart
event handler but maybe we can add it afterwards
What you you think? How do you imagine using node views? How could a nice API look like?
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Vue 3.0 Discards Class-Based API for Reusable, Composable ...
The Vue team recently opened an RFC which describes the proposed function-based component API for the upcoming Vue 3.
Read more >How To Use an API with Vue.js - RapidAPI
In this blog post, we are going to take a dig at integrating public APIs with a simple Vue.js application to fetch and...
Read more >Composition API FAQ - Vue.js
What is Composition API? #. Composition API is a set of APIs that allows us to author Vue components using imported functions instead...
Read more >Vue 3: Smaller, Faster & Stronger. A look at the new features ...
This presentation will cover: ✓ Vue. js release history ✓ Request for Comments ( RFC ) process ✓ Smaller ( Global API Change,...
Read more >Vue 3 & A First Look at the Composition API - YouTube
Vue 3 will be released in 2020 and it'll add one pretty neat nice feature: The Composition API. Time for a first look...
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
this is now implemented and released in vue-2 and vue-3.
I think it’s a good idea to revisit this, even if you ultimately don’t change it, as I’m also not convinced the API is ideal and think (at least in vue 3) it doesn’t “feel right” with the magic components.
Also removing the need to extend the component in the node view implementation will help to prevent problems like https://github.com/ueberdosis/tiptap-next/issues/179
I wander if you could just add the
data-node-view
,contenteditable="false"
attributes andhandleDragStart
during the “unwrapping” of the component (in vue 3) as its always thefirstChild
with simple DOM mutations? Obviously would need checking that vue didn’t then undo these. (As an aside we should also ensure that there is only one top level node in the component in vue 3)For the contentDom, could that be done with a slot? (the slot itself doesn’t create a dom node so we would have full control)
So with both it would be something like:
or just a slot (https://v3.vuejs.org/guide/component-slots.html#scoped-slots):