Skip to content
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

New guide for the EditContext API #32027

Merged
merged 15 commits into from
Mar 18, 2024
Merged

Conversation

captainbrosset
Copy link
Contributor

@captainbrosset captainbrosset commented Jan 31, 2024

Description

This PR introduces a guide page for the EditContext API.

Motivation

I wrote the EditContext API reference docs recently, but didn't have the time to write a tutorial then. This PR introduces a longer tutorial that goes over all of the steps required to build a rich text editor by using the EditContext API. It puts all of the concepts together into one logical demo, so that users can understand how everything fits.

Additional details

Related issues and pull requests

mdn/mdn#493

@captainbrosset captainbrosset requested review from a team as code owners January 31, 2024 14:23
@captainbrosset captainbrosset requested review from wbamberg and bsmth and removed request for a team January 31, 2024 14:23
@github-actions github-actions bot added Content:WebAPI Web API docs size/l [PR only] 501-1000 LoC changed labels Jan 31, 2024
Copy link
Contributor

github-actions bot commented Jan 31, 2024

Preview URLs

External URLs (2)

URL: /en-US/docs/Web/API/EditContext_API/Guide
Title: Using the EditContext API

(comment last updated: 2024-03-18 21:36:15)

@captainbrosset
Copy link
Contributor Author

@dandclark could you please take a look at this new tutorial, and let me know if you see anything wrong with the steps and code?

Copy link
Contributor

@skyclouds2001 skyclouds2001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some macros usage and a typo fix

files/en-us/web/api/editcontext_api/guide/index.md Outdated Show resolved Hide resolved
files/en-us/web/api/editcontext_api/guide/index.md Outdated Show resolved Hide resolved
files/en-us/web/api/editcontext_api/guide/index.md Outdated Show resolved Hide resolved
files/en-us/web/api/editcontext_api/guide/index.md Outdated Show resolved Hide resolved
Copy link

@dandclark dandclark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for creating this, I think it will be really helpful for people.
I just had some small suggestions.
GitHub won't let me mark this Approved because I don't have the right permissions in the repo, but consider it approved from me. :)

files/en-us/web/api/editcontext_api/guide/index.md Outdated Show resolved Hide resolved
files/en-us/web/api/editcontext_api/guide/index.md Outdated Show resolved Hide resolved
files/en-us/web/api/editcontext_api/guide/index.md Outdated Show resolved Hide resolved
files/en-us/web/api/editcontext_api/guide/index.md Outdated Show resolved Hide resolved
@github-actions github-actions bot added size/m [PR only] 51-500 LoC changed and removed size/l [PR only] 501-1000 LoC changed labels Feb 1, 2024
@wbamberg
Copy link
Collaborator

wbamberg commented Feb 1, 2024

Thank you for this Patrick! I'll take a look.

@wbamberg
Copy link
Collaborator

I've had a read through this and more or less understand the pieces. I think it's great. But I had a question though - how closely tied do you want this tutorial to be, to the working example? Or to put things another way, do you expect that someone should just be able to follow this through, step by step, and have something working at each stage?

Because at the moment there's quite a bit of divergence between this guide and the working sample code, and there are things not covered, that people need to do if they are to have things work.

So for instance, in Make the editor editable you instantiate editContext, but it's inside an if block. So then in Render the text, if I naively add editContext.addEventListener("textupdate", (e) => {..., it won't work.

In your working example, of course, it's a bit different, you have the instantiation and the event listener inside an IIFE, so it works.

Quite often on MDN we make tutorials work step-by-step, like the WebGL tutorial for instance (https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Tutorial/Getting_started_with_WebGL). That tutorial tries to be very explicit about what code to add when, and when to check the result, and what you should see (and not see) at each point. It's not necessarily wrong, the way you have it, but it should anyway be an explicit choice.

An alternative I suppose is where you don't follow the tutorial step by step, but instead you have the code open next to the guide, and the guide talks through the code, which is closer to what you have here. But even then there are things missing - for example the guide talks about the CSS for the editor div and the custom highlight, but not for the tokens.

@github-actions github-actions bot added size/l [PR only] 501-1000 LoC changed and removed size/m [PR only] 51-500 LoC changed labels Mar 5, 2024
@captainbrosset
Copy link
Contributor Author

Great point @wbamberg. I decided to go with the latter option. There is a lot of code in the demo app that isn't necessarily related to the EditContext API, and I didn't want that to lead to a much longer tutorial that would contain unnecessary details.

So, I changed the way the code snippets are introduced, by instead saying things like "The demo app uses this event to do that", followed by code snippets that, now, don't need to be complete.

I hope this approach works. Let me know what you think.

Copy link
Collaborator

@wbamberg wbamberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hope these comments are helpful. Mostly I've tried to play reading the guide with the code alongside, and noting places where there was some friction.

One other comment that I could not fit anywhere else: the code has a "debug" mode that adds some complexity but is not explained in the guide. If it were up to me I would just omit the debug code. Or even maybe have a separate version of this demo with the debug code in?

files/en-us/web/api/editcontext_api/guide/index.md Outdated Show resolved Hide resolved
files/en-us/web/api/editcontext_api/guide/index.md Outdated Show resolved Hide resolved
files/en-us/web/api/editcontext_api/guide/index.md Outdated Show resolved Hide resolved
files/en-us/web/api/editcontext_api/guide/index.md Outdated Show resolved Hide resolved
files/en-us/web/api/editcontext_api/guide/index.md Outdated Show resolved Hide resolved
files/en-us/web/api/editcontext_api/guide/index.md Outdated Show resolved Hide resolved
files/en-us/web/api/editcontext_api/guide/index.md Outdated Show resolved Hide resolved
files/en-us/web/api/editcontext_api/guide/index.md Outdated Show resolved Hide resolved
@github-actions github-actions bot added size/m [PR only] 51-500 LoC changed and removed size/l [PR only] 501-1000 LoC changed labels Mar 18, 2024
@captainbrosset
Copy link
Contributor Author

@wbamberg thanks for the great review comments. I think I've addressed them all. Let me know what you think.

Copy link
Collaborator

@wbamberg wbamberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thank you Patrick, this looks great!

@wbamberg wbamberg merged commit 33b328b into mdn:main Mar 18, 2024
10 checks passed
@captainbrosset captainbrosset deleted the editcontext-guide branch March 19, 2024 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:WebAPI Web API docs size/m [PR only] 51-500 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants