Re: [whatwg/dom] Introduce `moveBefore()` state-preserving atomic move API (PR #1307)

@annevk commented on this pull request.



> @@ -2845,6 +2911,101 @@ before a <var>child</var>, with an optional <i>suppress observers flag</i>, run
 </ol>
 
 
+<p><a lt="Other applicable specifications">Specifications</a> may define <dfn export
+id=concept-moving-steps-ext>moving steps</dfn> for all or some <a for=/>nodes</a>. The algorithm is
+passed a <a for=/>node</a> <var ignore>movedNode</var>, and a <a for=/>node</a>-or-null <var
+ignore>oldParent</var> as indicated in the <a for=/>move</a> algorithm below. Like the <span
+data-x="concept-insertion-steps-ext">insertion steps</span>, these steps must not modify the
+<a>node tree</a> that <var>insertedNode</var> <a>participates</a> in, create
+<a for=/>browsing contexts</a>, <a lt="fire an event">fire events</a>, or otherwise execute
+JavaScript. These steps may queue tasks to do these things asynchronously, however.
+
+
+<p>To <dfn export id=concept-node-move>move</dfn> a <var>node</var> into a <var>newParent</var>
+before a <var>child</var>, run these steps:

```suggestion
before a <var>child</var>:
```

> + <li><p>If <var>parent</var> is not a {{Document}}, {{DocumentFragment}}, or {{Element}}
+ <a for=/>node</a>, then <a>throw</a> a "{{HierarchyRequestError!!exception}}" {{DOMException}}.
+
+ <li><p>If <var>node</var> is a <a>host-including inclusive ancestor</a> of <var>parent</var>, then
+ <a>throw</a> a "{{HierarchyRequestError!!exception}}" {{DOMException}}.
+
+ <li><p>If <var>child</var> is non-null and its <a for=tree>parent</a> is not <var>parent</var>,
+ then <a>throw</a> a "{{NotFoundError!!exception}}" {{DOMException}}.
+
+ <li><p>If <var>node</var> is not an {{Element}} or a {{CharacterData}} <a for=/>node</a>, then
+ <a>throw</a> a "{{HierarchyRequestError!!exception}}" {{DOMException}}.</p></li>
+
+ <li><p>If <var>node</var> is a {{Text}} <a for=/>node</a> and <var>parent</var> is a
+ <a>document</a>, then <a>throw</a> a "{{HierarchyRequestError!!exception}}" {{DOMException}}.
+
+ <li><p>If <var>parent</var> is a {{Document}}, <var>node</var> is an {{Element}}

```suggestion
 <li><p>If <var>parent</var> is a <a>document</a>, <var>node</var> is an {{Element}}
```

> +   <var>inclusiveDescendant</var>, callback name "<code>connectedMoveCallback</code>", and an empty
+   argument list.

```suggestion
   <var>inclusiveDescendant</var>, callback name "<code>connectedMoveCallback</code>", and « ».
```
We also have to clean this up elsewhere, but that can be done separately. New algorithms should do it right from the start though.

> @@ -8163,6 +8320,31 @@ but not its <a for=range>end node</a>, or vice versa.
  </ul>
 </div>
 
+<p>The <dfn>live range pre-removing steps</dfn> given a <a>node</a> <var>node</var>, are as follows:

Should this not be pre-remove steps?

> @@ -4118,6 +4264,7 @@ interface Node : EventTarget {
   [CEReactions] Node appendChild(Node node);
   [CEReactions] Node replaceChild(Node node, Node child);
   [CEReactions] Node removeChild(Node child);
+  [CEReactions] Node moveBefore(Node node, Node? child);

I think we should put this method on `ParentNode`. That would also allow us to simplify the validity checks a bit.

> @@ -2652,6 +2652,63 @@ of a <var>node</var> into a <var>parent</var> before a <var>child</var>, run the
  <!-- Technically this is post-insert. -->
 </ol>
 
+<p>To <dfn export for=Node id=concept-node-ensure-pre-move-validity>ensure pre-move validity</dfn>
+of a <var>node</var> into a <var>parent</var> before a <var>child</var>, run these steps:
+
+<ol>
+ <li>
+  <p>If any of the following conditions are true</p>
+
+  <ul>
+   <li><p><var>parent</var> is <a>connected</a> and <var>node</var> is not <a>connected</a>; or</p></li>
+
+   <li><p><var>parent</var> is not <a>connected</a> and <var>node</var> is <a>connected</a>,</p></li>
+  </ul>

I'm not sure I hold a strong opinion, but I do like the symmetry Olli is suggesting.

> @@ -4118,6 +4264,7 @@ interface Node : EventTarget {
   [CEReactions] Node appendChild(Node node);
   [CEReactions] Node replaceChild(Node node, Node child);
   [CEReactions] Node removeChild(Node child);
+  [CEReactions] Node moveBefore(Node node, Node? child);

It also needs a "web developer" intro box.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/pull/1307#pullrequestreview-2499291985
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/dom/pull/1307/review/2499291985@github.com>

Received on Thursday, 12 December 2024 12:35:51 UTC