Skip to content

Commit f80f0aa

Browse files
committed
Manage slot manipulation centrally and special case replace operations
This is an attempt at fixing WICG/webcomponents#764. I first wrote an algorithm that combined the operations done by remove and insert. I then used that for replace and replace all. I then abstracted it to avoid duplication. I'm a little worried that this is not correct as this delays assigning slotables to a slot quite a bit, which I think might be observable in some cases.
1 parent 42d2485 commit f80f0aa

File tree

1 file changed

+42
-24
lines changed

1 file changed

+42
-24
lines changed

dom.bs

+42-24
Original file line numberDiff line numberDiff line change
@@ -2203,6 +2203,36 @@ steps:
22032203
<li><p>If <var>slot</var> is non-null, then run <a>assign slotables</a> for <var>slot</var>.
22042204
</ol>
22052205

2206+
<p>To <dfn noexport>update slots</dfn>, given <var>removedNodes</var>, <var>parent</var>, and
2207+
<var>addedNodes</var>, run these steps:
2208+
2209+
<ol>
2210+
<li>
2211+
<p>For each <var>removedNode</var> in <var>removedNodes</var>:
2212+
2213+
<ol>
2214+
<li><p>If <var>removedNode</var> is <a for=slotable>assigned</a>, then run
2215+
<a>assign slotables</a> for <var>removedNode</var>'s <a>assigned slot</a>.
2216+
2217+
<li><p>If <var>removedNode</var> has an <a>inclusive descendant</a> that is a <a>slot</a>, then
2218+
run <a>assign slotables for a tree</a> with <var>removedNode</var>.
2219+
</ol>
2220+
2221+
<li><p>If <var>parent</var>'s <a for=tree>root</a> is a <a for=/>shadow root</a> and
2222+
<var>parent</var> is a <a>slot</a> whose <a for=slot>assigned nodes</a> is the empty list, then run
2223+
<a>signal a slot change</a> for <var>parent</var>.
2224+
2225+
<li><p>Run <a>assign slotables for a tree</a> with <var>parent</var>'s <a for=tree>root</a>.
2226+
2227+
<li>
2228+
<p>For each <var>addedNode</var> in <var>addedNodes</var>:
2229+
2230+
<ol>
2231+
<li><p>If <var>parent</var> is a <a for=Element>shadow host</a> and <var>addedNode</var> is a
2232+
<a>slotable</a>, then <a>assign a slot</a> for <var>addedNode</var>.
2233+
</ol>
2234+
</ol>
2235+
22062236
<h5 id=signaling-slot-change>Signaling slot change</h5>
22072237

22082238
<p>Each <a>unit of related similar-origin browsing contexts</a> has a
@@ -2382,17 +2412,11 @@ before a <var>child</var>, with an optional <i>suppress observers flag</i>, run
23822412
<li><p>Otherwise, <a for=set>insert</a> <var>node</var> into <var>parent</var>'s
23832413
<a for=tree>children</a> before <var>child</var>'s <a for=tree>index</a>.
23842414

2385-
<li><p>If <var>parent</var> is a <a for=Element>shadow host</a> and <var>node</var> is a
2386-
<a>slotable</a>, then <a>assign a slot</a> for <var>node</var>.
2387-
23882415
<li>If <var>node</var> is a {{Text}} node, run the <a>child text content change steps</a> for
23892416
<var>parent</var>.
23902417

2391-
<li><p>If <var>parent</var>'s <a for=tree>root</a> is a <a for=/>shadow root</a>, and
2392-
<var>parent</var> is a <a>slot</a> whose <a for=slot>assigned nodes</a> is the empty list,
2393-
then run <a>signal a slot change</a> for <var>parent</var>.
2394-
2395-
<li><p>Run <a>assign slotables for a tree</a> with <var>node</var>'s <a for=tree>root</a>.
2418+
<li><p>If the <i>suppress observers flag</i> is unset, then <a>update slots</a> with « »,
2419+
<var>parent</var>, and « <var>node</var> ».
23962420

23972421
<li>
23982422
<p>For each <a>shadow-including inclusive descendant</a> <var>inclusiveDescendant</var> of
@@ -2422,7 +2446,7 @@ before a <var>child</var>, with an optional <i>suppress observers flag</i>, run
24222446
</li>
24232447
</ol>
24242448

2425-
<li><p>If <i>suppress observers flag</i> is unset, then <a>queue a tree mutation record</a> for
2449+
<li><p>If the <i>suppress observers flag</i> is unset, then <a>queue a tree mutation record</a> for
24262450
<var>parent</var> with <var>nodes</var>, « », <var>previousSibling</var>, and <var>child</var>.
24272451
</ol>
24282452

@@ -2541,6 +2565,9 @@ within a <var>parent</var>, run these steps:
25412565
<li><p><a for=/>Insert</a> <var>node</var> into <var>parent</var> before <var>reference child</var>
25422566
with the <i>suppress observers flag</i> set.
25432567

2568+
<li><p><a>Update slots</a> with « <var>removedNodes</var> », <var>parent</var>, and
2569+
« <var>nodes</var> ».
2570+
25442571
<li><p><a>Queue a tree mutation record</a> for <var>parent</var> with <var>nodes</var>,
25452572
<var>removedNodes</var>, <var>previousSibling</var>, and <var>reference child</var>.
25462573

@@ -2574,6 +2601,9 @@ To <dfn export for=Node id=concept-node-replace-all>replace all</dfn> with a
25742601
<li><p>If <var>node</var> is not null, then <a for=/>insert</a> <var>node</var> into
25752602
<var>parent</var> before null with the <i>suppress observers flag</i> set.
25762603

2604+
<li><p>If the <i>suppress observers flag</i> is unset, then <a>update slots</a> with
2605+
« <var>removedNodes</var> », <var>parent</var>, and « <var>addedNodes</var> ».
2606+
25772607
<li><p><a>Queue a tree mutation record</a> for <var>parent</var> with <var>addedNodes</var>,
25782608
<var>removedNodes</var>, null, and null.
25792609
</ol>
@@ -2634,20 +2664,8 @@ with an optional <i>suppress observers flag</i>, run these steps:
26342664

26352665
<li><a for=set>Remove</a> <var>node</var> from its <var>parent</var>'s <a for=tree>children</a>.
26362666

2637-
<li><p>If <var>node</var> is <a for=slotable>assigned</a>, then run <a>assign slotables</a> for
2638-
<var>node</var>'s <a>assigned slot</a>.
2639-
2640-
<li><p>If <var>parent</var>'s <a for=tree>root</a> is a <a for=/>shadow root</a>, and
2641-
<var>parent</var> is a <a>slot</a> whose <a for=slot>assigned nodes</a> is the empty list,
2642-
then run <a>signal a slot change</a> for <var>parent</var>.
2643-
2644-
<li><p>If <var>node</var> has an <a>inclusive descendant</a> that is a <a>slot</a>, then:
2645-
2646-
<ol>
2647-
<li><p>Run <a>assign slotables for a tree</a> with <var>parent</var>'s <a for=tree>root</a>.
2648-
2649-
<li><p>Run <a>assign slotables for a tree</a> with <var>node</var>.
2650-
</ol>
2667+
<li><p>If the <i>suppress observers flag</i> is unset, then <a>update slots</a> with
2668+
« <var>node</var> », <var>parent</var>, and « ».
26512669

26522670
<li><p>Run the <a>removing steps</a> with <var>node</var> and <var>parent</var>.
26532671

@@ -2683,7 +2701,7 @@ with an optional <i>suppress observers flag</i>, run these steps:
26832701
<a for="transient registered observer">source</a> is <var>registered</var> to <var>node</var>'s
26842702
<a>registered observer list</a>.
26852703

2686-
<li><p>If <i>suppress observers flag</i> is unset, then <a>queue a tree mutation record</a> for
2704+
<li><p>If the <i>suppress observers flag</i> is unset, then <a>queue a tree mutation record</a> for
26872705
<var>parent</var> with « », « <var>node</var> », <var>oldPreviousSibling</var>, and
26882706
<var>oldNextSibling</var>.
26892707

0 commit comments

Comments
 (0)