From 055360facb5d8d0e2db00897d6e1f75f68d1c86d Mon Sep 17 00:00:00 2001 From: Mason Freed Date: Fri, 2 Apr 2021 16:24:26 -0700 Subject: [PATCH 1/8] Add updated imperative slot assignment API --- dom.bs | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/dom.bs b/dom.bs index ae34beba1..7a7a42f85 100644 --- a/dom.bs +++ b/dom.bs @@ -2192,6 +2192,10 @@ steps:

  • If the open flag is set and shadow's mode is not "open", then return null.

  • +
  • If shadow's slot assignment is "manual", + then return the slot in shadow's descendants whose manually assigned nodes + contains slottable, if any, and null otherwise.

  • +
  • Return the first slot in tree order in shadow's descendants whose name is slottable's name, if any, and null otherwise.

  • @@ -2203,14 +2207,27 @@ for a given slot slot, run these steps:

    1. Let result be an empty list.

    2. -
    3. If slot's root is not a shadow root, then return +

    4. Let root be slot's root.

    5. + +
    6. If root is not a shadow root, then return result.

    7. -
    8. Let host be slot's root's - host.

    9. +
    10. Let host be root's host.

    11. -

      For each slottable child of host, slottable, in +

      If root's slot assignment is "manual", + then:

      + +
        +
      1. Let result be an empty list.

      2. + +
      3. For each slottable in slot's manually assigned nodes, + if slottable's parent is host, add slottable to array.

      4. +
      +
    12. + +
    13. +

      Otherwise, for each slottable child of host, slottable, in tree order:

        @@ -2447,7 +2464,8 @@ before a child, with an optional suppress observers flag, run
      1. Otherwise, insert node into parent's children before child's index. -

      2. If parent is a shadow host and node is a +

      3. If parent is a shadow host whose shadow root's + slot assignment is "name" and node is a slottable, then assign a slot for node.

      4. If parent's root is a shadow root, and @@ -5706,11 +5724,13 @@ invoked, must return a new {{DocumentFragment}} node whose no [Exposed=Window] interface ShadowRoot : DocumentFragment { readonly attribute ShadowRootMode mode; + readonly attribute SlotAssignmentMode slotAssignment; readonly attribute Element host; attribute EventHandler onslotchange; }; enum ShadowRootMode { "open", "closed" }; +enum SlotAssignmentMode { "manual", "name" };

        {{ShadowRoot}} nodes are simply known as @@ -5729,6 +5749,9 @@ It is initially set to false.

        +

        Shadow roots have an associated slot assignment +("manual" or "name").

        +

        A shadow root's get the parent algorithm, given an event, returns null if event's composed flag is unset and shadow root is the root of event's path's first struct's @@ -5746,6 +5769,9 @@ null if event's composed flag is unset and shadow roo onslotchange event handler, whose event handler event type is {{HTMLSlotElement/slotchange}}. +

        The slotAssignment attribute's getter must +return this's slot assignment.

        +

        In shadow-including tree order is @@ -5869,6 +5895,7 @@ interface Element : Node { dictionary ShadowRootInit { required ShadowRootMode mode; boolean delegatesFocus = false; + SlotAssignmentMode slotAssignment = "name"; }; @@ -6753,6 +6780,9 @@ invoked, must run these steps: "custom", then set shadow's available to element internals to true. +

      5. Set shadow's slot assignment to init's + {{ShadowRootInit/slotAssignment}}. +

      6. Set this's shadow root to shadow.

      7. Return shadow. @@ -10087,6 +10117,7 @@ Manish Tripathi, Marcos Caceres, Mark Miller, Martijn van der Ven, +Mason Freed, Mats Palmgren, Mounir Lamouri, Michael Stramel, @@ -10150,6 +10181,7 @@ Yehuda Katz, Yoav Weiss, Yoichi Osato, Yoshinori Sano, +Yu Han, Yusuke Abe, and Zack Weinberg for being awesome! From d45e54e2e55a6e59e27ea862b9e841fc6d1fa0b9 Mon Sep 17 00:00:00 2001 From: Mason Freed Date: Fri, 2 Apr 2021 16:28:54 -0700 Subject: [PATCH 2/8] Fix array typo --- dom.bs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dom.bs b/dom.bs index 7a7a42f85..42e42416f 100644 --- a/dom.bs +++ b/dom.bs @@ -2222,7 +2222,8 @@ for a given slot slot, run these steps:

      8. Let result be an empty list.

      9. For each slottable in slot's manually assigned nodes, - if slottable's parent is host, add slottable to array.

      10. + if slottable's parent is host, add slottable + to result.

    14. From eb1e6fc98ae68f8c45df128346e59b179dc705c5 Mon Sep 17 00:00:00 2001 From: Mason Freed Date: Tue, 6 Apr 2021 16:44:48 -0700 Subject: [PATCH 3/8] Add step to remove a node --- dom.bs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dom.bs b/dom.bs index 42e42416f..d540be622 100644 --- a/dom.bs +++ b/dom.bs @@ -2683,6 +2683,9 @@ indicated in the remove algorithm below.
    15. Remove node from its parent's children. +

    16. If node is an {{HTMLSlotElement}}, set node's manually assigned nodes + to an empty set. +

    17. If node is assigned, then run assign slottables for node's assigned slot. From 7915e2b40cd38b3ee563421dc19d34c3f598da21 Mon Sep 17 00:00:00 2001 From: Mason Freed Date: Fri, 9 Apr 2021 13:20:46 -0700 Subject: [PATCH 4/8] Add manual slot assignment, and remove removal step --- dom.bs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/dom.bs b/dom.bs index d540be622..ba916d721 100644 --- a/dom.bs +++ b/dom.bs @@ -2175,6 +2175,11 @@ Unless stated otherwise it is null. A slottable is assigned if its assigned slot is non-null.

      +

      A slottable has an associated +manual slot assignment (null +or a slot). Unless stated otherwise, it is null. The manual slot assignment is +a weak reference to the slot, such that it can be garbage collected if not referenced elsewhere.

      +
      Finding slots and slottables

      To find a slot for a given slottable @@ -2683,9 +2688,6 @@ indicated in the remove algorithm below.

    18. Remove node from its parent's children. -

    19. If node is an {{HTMLSlotElement}}, set node's manually assigned nodes - to an empty set. -

    20. If node is assigned, then run assign slottables for node's assigned slot. From a0c69d93320c9740033aa2defc76ae3ef7f6e0e9 Mon Sep 17 00:00:00 2001 From: Mason Freed Date: Fri, 9 Apr 2021 14:40:25 -0700 Subject: [PATCH 5/8] Move weak ref stuff to a note --- dom.bs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dom.bs b/dom.bs index ba916d721..5e5258eea 100644 --- a/dom.bs +++ b/dom.bs @@ -2177,8 +2177,10 @@ non-null.

      A slottable has an associated manual slot assignment (null -or a slot). Unless stated otherwise, it is null. The manual slot assignment is -a weak reference to the slot, such that it can be garbage collected if not referenced elsewhere.

      +or a slot). Unless stated otherwise, it is null.

      + +

      The manual slot assignment can be implemented using a weak reference +to the slot, because this variable is not directly accessible from script.

      Finding slots and slottables
      From cf6dd5abbb9a946f8580fda88e02363bb6f44f74 Mon Sep 17 00:00:00 2001 From: Mason Freed Date: Mon, 12 Apr 2021 15:53:10 -0700 Subject: [PATCH 6/8] name -> named --- dom.bs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dom.bs b/dom.bs index 5e5258eea..0232a3316 100644 --- a/dom.bs +++ b/dom.bs @@ -2473,7 +2473,7 @@ before a child, with an optional suppress observers flag, run children before child's index.
    21. If parent is a shadow host whose shadow root's - slot assignment is "name" and node is a + slot assignment is "named" and node is a slottable, then assign a slot for node.

    22. If parent's root is a shadow root, and @@ -5738,7 +5738,7 @@ interface ShadowRoot : DocumentFragment { }; enum ShadowRootMode { "open", "closed" }; -enum SlotAssignmentMode { "manual", "name" }; +enum SlotAssignmentMode { "manual", "named" };

      {{ShadowRoot}} nodes are simply known as @@ -5758,7 +5758,7 @@ It is initially set to false.

      consequences for innerHTML. -->

      Shadow roots have an associated slot assignment -("manual" or "name").

      +("manual" or "named").

      A shadow root's get the parent algorithm, given an event, returns null if event's composed flag is unset and shadow root is the @@ -5903,7 +5903,7 @@ interface Element : Node { dictionary ShadowRootInit { required ShadowRootMode mode; boolean delegatesFocus = false; - SlotAssignmentMode slotAssignment = "name"; + SlotAssignmentMode slotAssignment = "named"; }; From 39f9ba9c34c86f7e8fa4cbb6c7770fa9a2c37bda Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Wed, 14 Apr 2021 12:05:54 +0200 Subject: [PATCH 7/8] a bunch of editorial nits --- dom.bs | 58 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/dom.bs b/dom.bs index 0232a3316..5882dc55f 100644 --- a/dom.bs +++ b/dom.bs @@ -2175,12 +2175,11 @@ Unless stated otherwise it is null. A slottable is assigned if its assigned slot is non-null.

      -

      A slottable has an associated -manual slot assignment (null -or a slot). Unless stated otherwise, it is null.

      +

      A slottable has an associated manual slot assignment (null +or a slot). Unless stated otherwise, it is null. -

      The manual slot assignment can be implemented using a weak reference -to the slot, because this variable is not directly accessible from script.

      +

      A slottable's manual slot assignment can be implemented using a weak +reference to the slot, because this variable is not directly accessible from script.

      Finding slots and slottables
      @@ -2199,9 +2198,10 @@ steps:

    23. If the open flag is set and shadow's mode is not "open", then return null.

    24. -
    25. If shadow's slot assignment is "manual", - then return the slot in shadow's descendants whose manually assigned nodes - contains slottable, if any, and null otherwise.

    26. +
    27. If shadow's slot assignment is "manual", then + return the slot in shadow's descendants whose + manually assigned nodes contains slottable, if any, and null + otherwise.

    28. Return the first slot in tree order in shadow's descendants whose name is slottable's @@ -2214,36 +2214,34 @@ for a given slot slot, run these steps:

      1. Let result be an empty list.

      2. -
      3. Let root be slot's root.

      4. +
      5. Let root be slot's root. -

      6. If root is not a shadow root, then return - result.

      7. +
      8. If root is not a shadow root, then return result. -

      9. Let host be root's host.

      10. +
      11. Let host be root's host.

      12. -

        If root's slot assignment is "manual", - then:

        +

        If root's slot assignment is "manual", then:

          -
        1. Let result be an empty list.

        2. +
        3. Let result be « ». -

        4. For each slottable in slot's manually assigned nodes, - if slottable's parent is host, add slottable - to result.

        5. +
        6. For each slottable slottable of slot's + manually assigned nodes, if slottable's parent is + host, append slottable to result.

      13. -

        Otherwise, for each slottable child of host, slottable, in - tree order:

        +

        Otherwise, for each slottable child slottable of + host, in tree order:

        1. Let foundSlot be the result of finding a slot given - slottable.

        2. + slottable. -
        3. If foundSlot is slot, then append slottable to - result.

        4. +
        5. If foundSlot is slot, then append + slottable to result.

      14. @@ -5777,8 +5775,8 @@ null if event's composed flag is unset and shadow roo onslotchange event handler, whose event handler event type is {{HTMLSlotElement/slotchange}}. -

        The slotAssignment attribute's getter must -return this's slot assignment.

        +

        The slotAssignment getter steps are to return +this's slot assignment.


        @@ -6779,17 +6777,17 @@ invoked, must run these steps:
      15. Let shadow be a new shadow root whose node document is this's node document, host is this, - and mode is init's {{ShadowRootInit/mode}}. + and mode is init["{{ShadowRootInit/mode}}"]. -

      16. Set shadow's delegates focus to init's - {{ShadowRootInit/delegatesFocus}}. +

      17. Set shadow's delegates focus to + init["{{ShadowRootInit/delegatesFocus}}"].

      18. If this's custom element state is "precustomized" or "custom", then set shadow's available to element internals to true. -

      19. Set shadow's slot assignment to init's - {{ShadowRootInit/slotAssignment}}. +

      20. Set shadow's slot assignment to + init["{{ShadowRootInit/slotAssignment}}"].

      21. Set this's shadow root to shadow. From dfc9b44563ab1b3349b5df19fe356b8fecc95dfc Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Thu, 15 Apr 2021 09:23:08 +0200 Subject: [PATCH 8/8] nits --- dom.bs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dom.bs b/dom.bs index 5882dc55f..697e0a6cd 100644 --- a/dom.bs +++ b/dom.bs @@ -2228,9 +2228,8 @@ for a given slot slot, run these steps:

      22. For each slottable slottable of slot's manually assigned nodes, if slottable's parent is - host, append slottable to result.

      23. + host, append slottable to result.
      -
    29. Otherwise, for each slottable child slottable of @@ -5756,7 +5755,7 @@ It is initially set to false.

      consequences for innerHTML. -->

      Shadow roots have an associated slot assignment -("manual" or "named").

      +("manual" or "named").

      A shadow root's get the parent algorithm, given an event, returns null if event's composed flag is unset and shadow root is the