-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should we add components instead of scoped slots? #20
Comments
Well, maybe the architecture like in quasar framework WYSIWYG editor - it's quite thoughtful and adjusted to many use cases: https://quasar-framework.org/components/editor---wysiwyg.html BTW - I would LOVE if quasar editor would be replaced with tiptap editor... |
@qyloxe Thanks for your input! I do not like to configure everything as long arrays via props. That‘s the way most of all editors are configurable and that‘s why I started creating tiptap 🙌 For me it‘s very important to have full control over markup because you can use text editors for so many different use cases today, that it differs to much. |
I'm sort of putting something together that's more in keeping with injected components using prose mirror. I'll give you a shout @qyloxe if I make something public. Failing that, it's not too bad getting something up and running just using prose mirror as is in vue. Likewise @philippkuehn, if you're interested. Not a dig at your hard work, i think tiptap is decent but I couldn't figure out how to get it to do quite what I wanted it to do and my use case needs something pretty complex! |
@philippkuehn OK. Those editors work this way because they want you to respond to specific events in very specific, preconfigured context. If you want to allow different architectures then assuming that user should only respond to events this is obviously wrong. I understand that you do not want only events (as a block for describing dynamic behaviour) but you want the whole architectural flexibility. And I do like it :-) I like it, because you are using ProseMirror which is designed with similar flexibility in mind and you also want to "be free". So, lets imagine the most difficult scenario and try to design the correct architecture to model it in the desired environment. I propose to design an interface for three-way merge editor with custom nodes, marks, extensions, synchronized with other collaborators, preserving versions and themable, mobile and accesible. Oh, and also print friendly and possible to configure without much programming knowledge (UI is separated from behaviour). Let's start with something simple: option 1 for three-way merge:
option 2 for three-way merge:
In option1 the hidden "manager" is deducted from components hierarchy. In option 2, there could be many components and every one needs to specify his own "manager" explicitly. What is "manager"? Well, in every case you will need something for event processing, context preserving, communication bus, serialization, default configuration etc. In your present architecture, you have tightly coupled presentation hierarchy and behaviour (everything is in "editor" component). What I propose is separation of "manager" and "presentation" and what is needed from you, is to decide - on the architectural level: do you prefer hierarchical coupling (option 1) or "loose" coupling (option 2)? Every next decision could be derived from that one. |
@jaysaurus would love to hear what you trying to do! What wasn‘t possible with tiptap? |
@qyloxe Thanks for this write-up! Basically I'm thinking of these two solutions. I'm a fan of simplicity so I tend to option 1 even if option 2 is more "powerful". I will soon create a roadmap for v1 of tiptap and collect some features to implement and this one is definitely on the list. |
@philippkuehn just $0.02 more :-) with option 1 you end up with rather closed design. Why? Because your component will be definitely used in one of the VUE frameworks: quasar, nuxt, vuetify, bulma or whatnot. When used in framework, with option 1 it is extremely hard to decompose your component into said framework architecture. With option 2 you could easily write something like this:
so, option 2 is framework agnostic. In VUE it is rather easy to write with option 2 because you could use refs or private (in manager context) vue event bus or even vuex BUT using vuex is not architecturally clean, because there are people who use something else for state management. in option 2 it is easier to extend your components because one does not have to worry where he should put his component in your component hierarchy but only concentrate on following your easy and simple interface. In option 1 one need to think about structure (which is painful) in option 2 one can think about interaction (which is easy because one do not have to know all the quirks of the structure). In effect you will have more contributions and greater library of subcomponents, plugins, mixins and directives from community, where in option 1 you will have to "approve" or "check" or "review" each and every single contribution. More work IMO. OK, it was rather $0.06 ha ha |
@qyloxe Good points! I think option 2 is way harder to implement but we'll see. Have to fiddle around with it. |
@philippkuehn thanks! surely I plan to contribute something, because your work is remarkable and... enlightening ;) |
Hiya, the issue is kind of 2 fold
Either way, I'm midway through putting something together that only requires one simple mount and that should just work with templates etc without the need for creating lots of stuff in DOM. I'll be happy to share once I've got enough to present to you! :) I've already got a working bubble menu (with bold and italic marks) that is written with single page templates alone. Ideally, I just want to be able to expose the prosemirror's actual modules when and wherever they're needed rather than having the client have to dig for them. |
@jaysaurus Hey, thanks for your thoughts! To 1: I'm still not sure what you wanted to do with implementing text alignment and why it wasn't possible to add some classes. So I created a basic example for text-align on the demo page. I'm using inline styles there but you can achieve the same with adding classes. Basically I only needed to change two lines in the ParagraphNode extension to get this working. To 2: I didn't know stampit but it really looks like Vue :) Do you mean that the extensions should be written in that format instead of JS classes? |
Hiya, wow thank you for such a quick response!! to 1. I was aiming for something node independent. The idea being that - whatever types of block node - you could select any amount of text (be it h1, B, ul etc.) and align it accordingly. to 2. it sort of depends on how you want to build it really! You like using inheritance models so one option is to go down the stampit route (because it gives you true composition in JS rather than JS' long-suffering attempt to pretend it's classical, which of course it isn't!) Personally, I think we can use the Vue.js architecture as it is without introducing further complexity! I've thrown together the thing I'm working on as a generic example (apologies for the shonky css and the use of an id for a query selector, I'm really just prototyping at this stage but - hopefully - it gives you an idea of what I mean) |
addendum, ahhhhhh, vis a vis my first point; I think I see now having looked at your example. So in theory, you'd actually have to have each node type have it's own command for handling attribute changes... I see. I've been coming at it from the wrong angle (Prose Mirror likes to make things fiddly doesn't it haha!) furthermore, I see that the prose mirror schema has to explicitly know about what attributes a block can have. Hoo boy that was complicated 😖 I've managed to get the desired behaviour in my little sandbox example (https://gitlab.com/jaysaurus/vue-with-prose-mirror) using the below as an event: import { setBlockType } from 'prosemirror-commands'
function AlignmentFactory (className) {
function getSelectionObject ({ $anchor, $head }) {
return {
from: $anchor.pos <= $head.pos ? $anchor.parent : $head.parent,
to: $head.pos > $anchor.pos ? $head.parent : $anchor.parent,
fromFound: false,
toFound: false
}
}
return {
align (state, view) {
let { from, to, fromFound, toFound } = getSelectionObject(state.selection)
const commands = []
state.doc.descendants((node, pos) => {
if (!node.isInline && (node === from || (fromFound && !toFound))) {
if (!commands.filter(({type}) => type === node.type.name).length) {
const command = setBlockType(node.type, { class: className })
commands.push({ type: node.type.name, command })
}
fromFound = true
}
toFound = toFound || (from === to || node === to)
})
// Doesn't seem to work if i run the commands inside the descendants iteration so I run it here.
commands.forEach(({command}) => command(view.state, view.dispatch))
}
}
}
export { AlignmentFactory } (not up on my public gitlab instance but I can add it should you be interested) |
fixed in v1.0 |
Currently we're using scoped slots for content and menus.
There are two limitations for doing so:
marks
andnodes
like this<div v-if="marks">
. For one tick these values arenull
. It would be nice to render these slots only when these values are available but then we do not have access to the DOM element of this slot which is required for the menububble plugin.Maybe it would be nice to use components like this:
But I'm not sure how these components will work together and sync its editor state. With
provide
andinject
or an event bus or passing props? 🤷♂️The text was updated successfully, but these errors were encountered: