w3c / edit-context

EditContext API
https://w3c.github.io/edit-context/
Other
28 stars 7 forks source link

Can EditContext works as normally even in designMode if set to the documentElement and/or body? #74

Closed masayuki-nakano closed 9 months ago

masayuki-nakano commented 11 months ago
<script>
addEventListener("load", () => {
  document.designMode = "on";
  document.documentElement.editContext = new EditContext();
}, {once: true});
</script>

and/or

<script>
addEventListener("load", () => {
  document.designMode = "on";
  document.body.editContext = new EditContext();
}, {once: true});
</script>

Then, the document should work as currently? Or should it work as EditContext application? (I think that the latter is terrible if the document has multiple <body> elements.)

johanneswilm commented 11 months ago

From a JavaScript developer perspective the answer to this question is mainly of academic interest as there is no reason to enable both at the same time. So just decide on either way, make it consistent and don't waste too much time on it.

dandclark commented 11 months ago

Setting document.documentElement.editContext won't work because <html> isn't in a valid shadow host name, but we do need to decide what should happen for editContext set on <body> when designMode is set. I'm not yet sure what is best here.

johanneswilm commented 11 months ago

Is there any real-world usecase of why a JS developer would choose to do this?

If not, given that designMode will be for the entire document whereas EditContext will just be for an element within the document, I would say that designMode should always win.

masayuki-nakano commented 10 months ago

Well, I like the approach that EditContext won't work with designMode because it makes the implementations simpler.

On the other hand, <html> cannot have EditContext under the current draft. So, when web apps want to make all things in a document editable with EditContext, they need to set the .editContext of the <body>. However, <body> may not cover all of the view port. Is it okay for web developers? I have no idea about the difference of <html> vs. <body>.

smaug---- commented 10 months ago

Setting document.documentElement.editContext won't work because <html> ...

Nit, documentElement may not be <html> , it can be anything.

dandclark commented 10 months ago

Notes from 2023-11-09 WG meeting:

[17:59] dandclark: cE=false with nested cE=true works [17:59] dandclark: EC should work the same way, make it possible to nest [17:59] dandclark: is in line with previous resolution [18:00] dandclark: if no CE=false, then EC is ignored johanneswilm: resolve on dandclark's comment above

It's not present in the notes, but it was decided that if designMode is on it "wins" over EditContext and EditContext is ignored. The exception is if there is a contenteditable="false" subtree in the DOM, which still turns off editability in that subtree if designMode is on. Inside that subtree, new editing hosts can be created with either contenteditable="" or with EditContext.