toddle RTE

  • tomthebigtree-1168449588626210876

    Tom Ireland

    1 year ago

    I’m on a mission to try and create some form of rich text editor within my app and have been looking at examples like Prosemirror, Slate and Lexical to try and figure out how they have been built. 🤯

    I’m curious to know how possible it might be to create something using toddle as it is or if I’d need to rely on custom code to do this, or if it simply wouldn’t be possible at all just now?

    Just thinking about things like @Andreas Møller ‘s form builder example, it must be possible, right?

    Slate looks like it uses something similar to web components to structure the editor. So wondering if it’s possible to fashion something basic at least. Any thoughts and has anyone had a go at this?
  • tomthebigtree-1168449865781616650

    Tom Ireland

    1 year ago

    I have been looking at contenteditable but struggling to even get data out of an element, so not off to a great start. 🤣
  • jacobkofoed-1168468775700545627

    Jacob Kofoed

    1 year ago

    We are using contentedible for toddle. You have to use the input event, not change. Then use “event.target.innerHTML
  • tomthebigtree-1168481893050761286

    Tom Ireland

    1 year ago

    Aye, so event.target.innerHTML would be a custom action, right, @Jacob Kofoed ?
  • jacobkofoed-1168485483584700416

    Jacob Kofoed

    1 year ago

    I’m not using any custom action for it, but I’ll double check. If it not on the event, then maybe try “Get “ with path “event.target.innerHTML” on the event
  • tomthebigtree-1168537412243300425

    Tom Ireland

    1 year ago

    @Jacob Kofoed - Yes, that would be interesting to know. I only thought I could achieve that with a custom action. I'm just trying a simple example with a div with attribute contenteditable set to true. If I add an input event to the div I don't see the option for the event as you say. I can certainly add to the Get path but not sure what the object should be.
  • tomthebigtree-1168634341476286515

    Tom Ireland

    1 year ago

    Took a break for a bit, did some reading and managed to make some positive progress. Looks like if I set my input event to set variable with formula Get where object is linked to result of Get element by id and the path is innerText, I can extract the text from the text node inside the div. I only noticed this by monitoring the console and doing log to console with the variable as data because it doesn't show up in the variable in the editor for some reason.

    Well, actually, innerText does show a result in the variable but if I do innerHTML is just says Null but if you bind the variable to a text element, the text does display as HTML object. Not sure why it doesn't show the HTML in the variable in the editor. Is that a bug or expected behaviour, @Jacob Kofoed ? Can provide an example if needed.
  • raphaelwalters-1168835363591159838

    Raphael Walters

    1 year ago

    Really interested to see how you get on with this. It's a problem my future self will have to solve.
  • tomthebigtree-1168837807893123103

    Tom Ireland

    1 year ago

    I'm interested in how I'll get on with it as well. 🤣 I've been looking at all sorts like JSON RTE examples, Prosemirror, Trix, Lexical, DraftJS, etc. Everyone has their own unique take on solving this problem. It's just trying to work out how to do that in toddle, which is not an easy task and I'm likely trying to bite off something that I definitely don't have the skills to chew on right now.

    Some stuff that is done in JS is already possible in toddle, so it's trying to unravel that and understand how things are working and what the limitations are. Currently exploring text formatting in blocks and just getting that output in a way that's useful.

    Interestingly, I am able to use toddle formulas to grab stuff from the DOM like text from an element, which I didn't think was possible until yesterday. 🙌
  • raphaelwalters-1168838775825248286

    Raphael Walters

    1 year ago

    Well done Sir! Sounds like you're already well on your way to figuring it out, which given the complexity of the task is no mean feat! 🙌
  • tomthebigtree-1168844776200736828

    Tom Ireland

    1 year ago

    Well, I wouldn't say well on my way but on some path to somewhere (hopefully). 😄
    😆2
  • tomthebigtree-1169559392845299762

    Tom Ireland

    1 year ago

    @Raphael Walters - So you know, I managed to figure out how to get text out from contenteditable div and push that to a key/value pair in an object based on input and keydown events. 🙌 Nothing major but now at least I know I can get values into JSON format. Next is to figure out how to map all this stuff to some kind of schema to do formatting, then figure out how to get it back out again. 😬
    💪1
  • tomthebigtree-1169560095282184283

    Tom Ireland

    1 year ago

    @Jacob Kofoed - Do you know if it's possible "out of the box" to render text back to the page in HTML e.g. <strong>Some bold text</strong>. I could probably figure out how to wrap some text with <strong> tags as a text string and then use your HTML rendering custom action example but wonder if there's a simpler way? 🤔
  • jacobkofoed-1169561821779349566

    Jacob Kofoed

    1 year ago

    What format is your data in? If you have it in JSON, then you could recursively loop over your nodes and render the values to your own toddle-components

    {
    type: "element",
    tag: "strong",
    nodes: [
    {
    type: "text",
    value: "Some bold text"
    }
    ]
    }


    I can try to send you an example if you have your data in somewhat this format. If the input is HTML, then I think the easiest is to just use a custom action to set the HTML directly to the page as in this video:

    https://www.youtube.com/watch?v=6pVjgsyCe54&t=21s
  • andreasmoller-1169563101339844608

    Andreas Møller

    1 year ago

    Contentful has an interesting model for storing rich text which is easy to work with in toddle:
    https://www.contentful.com/developers/docs/concepts/rich-text/
    👍1
    🤯1
  • andreasmoller-1169563365958488064

    Andreas Møller

    1 year ago

    I would recommend looking into that.
    Storing HTML is good for compatibility with different platforms, but it opens op for a ton of issues, including some serious security concerns.
  • tomthebigtree-1169565161137381377

    Tom Ireland

    1 year ago

    @Jacob Kofoed - The format is text currently. I'm experimenting with a contenteditable div that (on Enter after writing some text), it sets a JSON object with a key e.g. value and the value being the text typed in. I have not expanded on that in terms of fleshing out the element schema yet.


    This is interesting. Not quite sure what you mean but now very curious. 🤔 😄

    @Andreas Møller - Funnily enough, I had come across that but my brain doesn't grasp how I make all that work...yet. If I could make it so that I didn't have to render any HTML for the reasons you mentioned and just output formatting using JSON as some kind of block/component that looks/acts like HTML and let toddle take care of the rest, that'd be awesome. As you can probably tell, this is a confusing but very interesting problem to chew on for me.
  • tomthebigtree-1169565546057039932

    Tom Ireland

    1 year ago

    The cool thing is that you could make a very cool editor that is extendable in toddle, share it, etc. How awesome would that be?!
  • andreasmoller-1169565668111298580

    Andreas Møller

    1 year ago

    We have a contentful-block component we use for rendering our docs and blog.
    🙌2
  • You can copy that if you like 🙂
  • tomthebigtree-1169565834750988339

    Tom Ireland

    1 year ago

    Oooh! That sounds interesting and I'd love to take a look at that. 🙂
    👍2
  • tomthebigtree-1169618268538032199

    Tom Ireland

    1 year ago

    @Andreas Møller - Re the component you mentioned, is this available somewhere or is it something you cover in a YT video?
  • andreasmoller-1169622405912735784

    Andreas Møller

    1 year ago

  • andreasmoller-1169623134559805451

    Andreas Møller

    1 year ago

    The block attribute should be a reich text block from contentful, in this case you find them on "content" inside the body on each item: https://preview.contentful.com/spaces/lizv2opdd3ay/environments/master/entries?content_type=docs&fields.slug=advanced-api-configuration&access_token=TlsHmDUeQY4b2LanaRcjzVLb7AS-lGs6FJBhkUUMxb4
  • Does that make sense?
  • includes is just the whole "includes" object from the api.
  • tomthebigtree-1169630541121847466

    Tom Ireland

    1 year ago

    Woah! That's incredible! Thanks so much for sharing. The video certainly helped in terms of visualising what's actually happening - it would have taken a while otherwise 💯 . I've definitely learned something new today regarding how this is possible and that you can have the same component inside itself. 🤯 Very cool to get a sneak peek at the toddle machine as well, which just demonstrates the power of toddle and how you're building toddle with toddle! 🙌 @Andreas Møller , sir, I really appreciate the share and this certainly gets me well on my way to making some positive progress. I'll be sure to showcase how I get on. 🤘
  • andreasmoller-1169636302497513542

    Andreas Møller

    1 year ago

    Just a word of warning.
    You can create an infinite loop by placing the same comonent inside it self 🙂
  • tomthebigtree-1169637498541047928

    Tom Ireland

    1 year ago

    Okay, @Andreas Møller - and that will implode the whole universe, right? I'm guessing you're speaking from experience here? 😄 I assume the solution is delete the page component or component itself? Could that impact toddle itself? I wouldn't want to have anything be affected by me messing around. 😬
  • lucasg-1169644500868677663

    Lucas G

    1 year ago

    Wow you’ve got quite the project Tom. Wonder which way this will end up turning out!
    I just used tiptap but maybe it being built with toddle is the way to go hmm 🤔
  • tomthebigtree-1169698546044379146

    Tom Ireland

    1 year ago

    @Lucas G - I have no idea. Hopefully, well. 😄 Be curious to see what you build if you do have a go yourself.
  • lucasg-1169720603390001183

    Lucas G

    1 year ago

    I played around very briefly with using tiptap for a rte field. Obviously not native built but I might go that route when it comes to actually implementing it.

    I’m going to start building my app soon so I haven’t gave this part much thought yet
    🤘1
  • tomthebigtree-1169957912274272257

    Tom Ireland

    1 year ago

    This is an example of some block-based text editing I've managed to cobble together based on some of the ideas @Andreas Møller shared yesterday. Still got to figure out a few things like how to style a block and do marks (bold, etc.) within a block but pleased with how it works in principle. Outputs a paragraph in this case and just using toddle out of the box - no custom code.
    🔥2
  • andreasmoller-1169984155690483723

    Andreas Møller

    1 year ago

    Nice!
  • tomthebigtree-1169989216046956594

    Tom Ireland

    1 year ago

    Made some progress over lunch. Swapped out text element for input as that enabled simpler focus and prevented weirdness with text. A couple of events to handle contenteditable and prevention of Enter taking a new line on contenteditable element and this is now working very well.
    👍1
  • andreasmoller-1169999759826747515

    Andreas Møller

    1 year ago

    Not just great tech. Also a gripping story
    📖1
  • lucasg-1170728072656470146

    Lucas G

    1 year ago

    Just tried to use external libraries for an RTE but styles aren't properly applying. I tested it just typing up the html in notepad locally and it works in browser but for some reason it's not fully working in toddle.
    https://rte-shared_components.toddle.site/RTE
  • Those are 2 examples/libraries. I'm probably doing something wrong
  • andreasmoller-1170728417411485766

    Andreas Møller

    1 year ago

    We use a reset stylesheet that might not be compatible.
  • lucasg-1170728491768094842

    Lucas G

    1 year ago

    Ah
  • andreasmoller-1170728658567188580

    Andreas Møller

    1 year ago

    The best option is probably to wrap it In a webcomponent.
  • lucasg-1170732253249278043

    Lucas G

    1 year ago

    No making them components didn't help
  • tomthebigtree-1171187560123473992

    Tom Ireland

    1 year ago

    @Lucas G / @Raphael Walters - If you're interested, I managed to make some progress in the last 30 mins after taking a break from it today. I was struggling to figure out how to update blocks (by updating a specific item in the block array) but a React post I read helped me understand it better. This is the result (I can now set a paragraph block to be a heading 1). This gives me the recipe for building out all of the other element formatting options now and I'll look to refactor that into a component formula to make that work better, have a menu of options or incorporate slash commands, etc.
    🤯3
  • tomthebigtree-1171187952857124884

    Tom Ireland

    1 year ago

    I still need to sort out the focus and placeholder stuff but it's progress, which is key!
  • raphaelwalters-1171204740705697862

    Raphael Walters

    1 year ago

    Loving the progress you're making with this @Tom Ireland 💪 . Really looking forward to see where you are going to take this. Out of curiosity, what made you think to check out some React post or was it coincidental?
  • tomthebigtree-1171322402345594960

    Tom Ireland

    1 year ago

    Thanks, mate. Curiosity never kills the cat, my friend. Basically, it was because @Andreas Møller had said that you should be able to do things you can do in React/Angular in toddle and I came across a React-specific post on using map, so I knew it was possible - I just had to figure out how to do the comparison stuff. Was quite simple after that. 🤯
  • andreasmoller-1171339839522742292

    Andreas Møller

    1 year ago

    👍
  • tomthebigtree-1171346685742546994

    Tom Ireland

    1 year ago

    Got to love some early morning progress. Still lots of bits and bobs to sort out, but the basics are now working! 🙌
    👏1
  • svenning-1171358336520822804

    svenning

    1 year ago

    Wow, this is still super impressive @Tom Ireland !
  • tomthebigtree-1171359050055811082

    Tom Ireland

    1 year ago

    Thanks, Kasper. 🙂 More to come! 😉
  • raphaelwalters-1171362636588388393

    Raphael Walters

    1 year ago

    Looking forward to your tutorial on this! 😉
  • tomthebigtree-1171380236601008158

    Tom Ireland

    1 year ago

    🫣 Maybe? 😄 Aye, it would be good to create something for folk to get started eh? What a showcase item as well - "Create a Notion-style text editor in toddle".
  • andreasmoller-1171381285890052168

    Andreas Møller

    1 year ago

    Yes! that would be incredible
    📹3
  • tomthebigtree-1171455999702487134

    Tom Ireland

    1 year ago

    Lunchtime progress update. Nothing major. Just some styling choices and events to show/hide action icons, command menu, etc. Still need to figure out removal of placeholder after input problem. 🤔
    🔥1
  • victoruxui-1176365435306909757

    Victor Giron

    1 year ago

    I think this is the reason the icon font is not working (tabler icon) right? so the rel=stylesheet doesn't get applied. What would be the best way to do it in a webcomponent?
  • lucasg-1176592967901921362

    Lucas G

    1 year ago

    Yeah it's soon getting time for me to work on this too
  • lucasg-1177029720592879726

    Lucas G

    1 year ago

    I tired the web component approach and couldn’t get it to work. Going to need help with this one ☝️
  • lucasg-1180003341665828874

    Lucas G

    1 year ago

    Also tried the ol' execCommand through custom actions approach and had a similar result as using an external editor library..
  • 😭
  • tomthebigtree-1182236518706843718

    Tom Ireland

    1 year ago

    @Andreas Møller - Following your awesome example via Loom, as you know I have set up my v1 for a toddle rte component but I'm struggling to think about how I might achieve formatting marks e.g. bold, etc. I can see how it would be simple enough to bring in a JSON structure for formatting like Contentful but I'm finding it challenging to figure out how to apply that based on user input.

    I know I can probably use styles to apply mark formatting and I now know how to do text selection and have some kind of component toolbar interaction but I cannot seem to work out how I would have a block update the JSON structure to apply marks formatting and then reapply that in the block component. Do you or the team have any pointers?

    This has been bugging me for a bit and I think figuring that out would unlock the whole formatting thing and open up the scope for various editing capabilities. Man, this rte stuff is hard!
  • tomthebigtree-1182237224566263868

    Tom Ireland

    1 year ago

    E.g. if I have user input on a block like This is some bold text, that creates a JSON object to apply the relevant output e.g. a paragraph. If the user highlights bold, I can use my text selection work I've already done to get that and show a toolbar (as an example) but then I don't know how to update the existing JSON object to show that the text formatting has changed and then apply it to the same block. Know what I mean?
  • tomthebigtree-1182237585297395763

    Tom Ireland

    1 year ago

    I have to work out how to split it I think and then piece it back together with the appropriate output in the component.
  • firdaus___-1207088171993661483

    Mr

    1 year ago

    thank you for this 🤩
  • Tod-1207088173562335283

    Tod

    1 year ago

    Great energy @Mr! Your continuous contribution to the toddle Community just made you advance to Community Level 5!
  • andreasmoller-1209079953837129748

    Andreas Møller

    1 year ago

    I created a package called quill, if you just want a quick RTE that works.
    🙌1
  • rscott-1209177710275076208

    Bishop

    1 year ago

    Have you tried just inserting one like editorjs? Its super configurable and that's what I'm hoping to use. You can make your own actions on selection etc.
  • danishnizzle-1271916116175753309

    danishnizzle

    7 months ago

    This was huge for me just now, thank you! PS - found it through the AI agent, you guys have really built a special platform and end user experience here 🙂
  • andreasmoller-1271916238851014827

    Andreas Møller

    7 months ago

    Thanks!

Stop scrolling. Start building.

toddle is a visual web app builder that rivals custom code — but accessible to your entire team!

Try toddle — it's free!

© Copyright 2024 toddle. All rights reserved.