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

Add ParentNode.prototype.replaceContents(nodes) #755

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions dom.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2839,6 +2839,7 @@ interface mixin ParentNode {

[CEReactions, Unscopable] void prepend((Node or DOMString)... nodes);
[CEReactions, Unscopable] void append((Node or DOMString)... nodes);
[CEReactions, Unscopable] void replaceContents((Node or DOMString)... nodes);
Copy link
Member

Choose a reason for hiding this comment

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

I think per the discussion we ended up with replaceChildren() as a name, as "contents" doesn't always refer to nodes. Did I miss something?


Element? querySelector(DOMString selectors);
[NewObject] NodeList querySelectorAll(DOMString selectors);
Expand Down Expand Up @@ -2878,6 +2879,15 @@ Element includes ParentNode;
the <a>node tree</a> are violated.
<!-- "NotFoundError" is impossible -->

<dt><code><var>node</var> . <a method for=ParentNode lt="replaceContents()">replaceContents</a>(<var>nodes</var>)</code>
<dd>
<p>Inserts <var>nodes</var> after the <a>last child</a> of <var>node</var>, while replacing
Copy link
Member

Choose a reason for hiding this comment

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

This needs rewording.

strings in <var>nodes</var> with equivalent {{Text}} <a for=/>nodes</a>.

<p><a>Throws</a> a "{{HierarchyRequestError!!exception}}" {{DOMException}} if the constraints of
the <a>node tree</a> are violated.
<!-- "NotFoundError" is impossible -->

<dt><code><var>node</var> . <a method for=ParentNode lt="querySelector()">querySelector</a>(<var>selectors</var>)</code>
<dd>
Returns the first <a for="/">element</a> that is a
Expand Down Expand Up @@ -2925,6 +2935,45 @@ must run these steps:
<li><p><a>Append</a> <var>node</var> to <a>context object</a>.
</ol>

<p>The <dfn method for=ParentNode><code>replaceContents(<var>nodes</var>)</code></dfn> method, when invoked,
must run these steps:

<ol>
<li><a for=/>Remove</a> all
<var>parent</var>'s <a>children</a>, in
<a>tree order</a>, with the
<i>suppress observers flag</i> set.
Copy link
Member

Choose a reason for hiding this comment

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

I think we should strive to use the https://dom.spec.whatwg.org/#concept-node-replace-all primitive here, which would take care of most of the work, preceded by a call to https://dom.spec.whatwg.org/#converting-nodes-into-a-node.

And I guess we need to run https://dom.spec.whatwg.org/#concept-node-ensure-pre-insertion-validity as well.


<li><p>If <var>node</var> is not null, then <a for=/>insert</a> <var>node</var> into
<var>parent</var> before null with the <i>suppress observers flag</i> set.

<li><p><a>Queue a tree mutation record</a> for <var>parent</var> with <var>addedNodes</var>,
<var>removedNodes</var>, null, and null.

<li>Let <var>removedNodes</var> be <var>context object</var>'s
<a>children</a>.

<li>Let <var>node</var> be the result of <a>converting nodes into a node</a> given
<var>nodes</var> and <a>context object</a>'s <a for=Node>node document</a>.

<li>Let <var>addedNodes</var> be the empty list if <var>node</var> is
null, <var>node</var>'s <a>children</a> if
<var>node</var> is a {{DocumentFragment}}
<a>node</a>, and a list containing <var>node</var>
otherwise.

<li><a for=/>Remove</a> all
<var>context object</var>'s <a>children</a>, in
<a>tree order</a>, with the
<i>suppress observers flag</i> set.

<li><p><a>Append</a> <var>addedNodes</var> to <a>context object</a>, with the
<i>suppress observers flag</i> set.

<li><p><a>Queue a tree mutation record</a> for <var>context object</var> with
<var>addedNodes</var>, <var>removedNodes</var>, null, and null.
</ol>

<p>The <dfn method for=ParentNode><code>querySelector(<var>selectors</var>)</code></dfn> method,
when invoked, must return the first result of running <a>scope-match a selectors string</a>
<var>selectors</var> against <a>context object</a>, if the result is not an empty list, and null
Expand Down