Skip to content

Commit 37808ad

Browse files
committed
Add declarative shadow root support
Corresponding HTML PR: whatwg/html#5465. Tests: https://wpt.fyi/results/shadow-dom/declarative. Closes whatwg#831. nits Fix up use of init Convert tri-state to boolean Address comment
1 parent 3bddf91 commit 37808ad

File tree

1 file changed

+77
-20
lines changed

1 file changed

+77
-20
lines changed

dom.bs

+77-20
Original file line numberDiff line numberDiff line change
@@ -4473,6 +4473,26 @@ dom-Range-extractContents, dom-Range-cloneContents -->
44734473
<a for=tree>children</a> of <var>node</var> and append them to <var>copy</var>, with
44744474
<var>document</var> as specified and the <i>clone children flag</i> being set.
44754475

4476+
<li>
4477+
<p>If <var>node</var> is a <a for=Element>shadow host</a> whose <a for=/>shadow root</a>'s
4478+
<a for=ShadowRoot>clonable</a> is true:
4479+
4480+
<ol>
4481+
<li><p>Run <a>attach a shadow root</a> with <var>copy</var>, <var>node</var>'s
4482+
<a for=Element>shadow root</a>'s <a for=ShadowRoot>mode</a>, true, <var>node</var>'s
4483+
<a for=Element>shadow root</a>'s <a for=ShadowRoot>delegates focus</a>, <var>node</var>'s
4484+
<a for=Element>shadow root</a>'s <a for=ShadowRoot>slot assignment</a>.
4485+
4486+
<li><p>If <var>node</var>'s <a for=Element>shadow root</a>'s <a for=ShadowRoot>declarative</a> is
4487+
true, then set <var>copy</var>'s <a for=Element>shadow root</a>'s
4488+
<a for=ShadowRoot>declarative</a> to true.
4489+
4490+
<li><p>If the <i>clone children flag</i> is set, <a lt="clone a node">clone</a> all the
4491+
<a>children</a> of <var>node</var>'s <a for=Element>shadow root</a> and <a>append</a> the
4492+
resulting clones to <var>copy</var>'s <a for=Element>shadow root</a>, with <var>document</var> as
4493+
specified, and the <i>clone children flag</i> set.
4494+
</ol>
4495+
44764496
<li>Return <var>copy</var>.
44774497
</ol>
44784498

@@ -4973,8 +4993,9 @@ known as <dfn export id=concept-document lt="document">documents</dfn>.
49734993
<dfn export for=Document id=concept-document-content-type>content type</dfn> (a string),
49744994
<dfn export for=Document id=concept-document-url>URL</dfn> (a <a for=/>URL</a>),
49754995
<dfn export for=Document id=concept-document-origin>origin</dfn> (an <a for=/>origin</a>),
4976-
<dfn export for=Document id=concept-document-type>type</dfn> ("<code>xml</code>" or "<code>html</code>"), and
4977-
<dfn export for=Document id=concept-document-mode>mode</dfn> ("<code>no-quirks</code>", "<code>quirks</code>", or "<code>limited-quirks</code>").
4996+
<dfn export for=Document id=concept-document-type>type</dfn> ("<code>xml</code>" or "<code>html</code>"),
4997+
<dfn export for=Document id=concept-document-mode>mode</dfn> ("<code>no-quirks</code>", "<code>quirks</code>", or "<code>limited-quirks</code>"), and
4998+
<dfn export for=Document>allow declarative shadow roots</dfn> (a boolean).
49784999
[[!ENCODING]]
49795000
[[!URL]]
49805001
[[!HTML]]
@@ -4983,8 +5004,8 @@ known as <dfn export id=concept-document lt="document">documents</dfn>.
49835004
<a for=/>encoding</a>, <a for=Document>content type</a> is
49845005
"<code>application/xml</code>", <a for=Document>URL</a> is "<code>about:blank</code>",
49855006
<a for=Document>origin</a> is an <a>opaque origin</a>,
4986-
<a for=Document>type</a> is "<code>xml</code>", and its
4987-
<a for=Document>mode</a> is "<code>no-quirks</code>".
5007+
<a for=Document>type</a> is "<code>xml</code>", <a for=Document>mode</a> is "<code>no-quirks</code>",
5008+
and <a for=Document>allow declarative shadow roots</a> is false.
49885009

49895010
<p>A <a>document</a> is said to be an <dfn export>XML document</dfn> if its <a for=Document>type</a>
49905011
is "<code>xml</code>"; otherwise an <dfn export>HTML document</dfn>. Whether a <a>document</a> is an
@@ -5857,13 +5878,19 @@ It is initially set to false.</p>
58575878
<p><a for=/>Shadow roots</a> have an associated
58585879
<dfn export for=ShadowRoot>available to element internals</dfn>. It is initially set to false.</p>
58595880

5881+
<p><a for=/>Shadow roots</a> have an associated <dfn export for=ShadowRoot>declarative</dfn>
5882+
(a boolean). It is initially set to false.</p>
5883+
58605884
<p><a for=/>Shadow roots</a>'s associated <a for=DocumentFragment>host</a> is never null.</p>
58615885
<!-- If we ever change this, e.g., add a ShadowRoot object constructor, that would have serious
58625886
consequences for innerHTML. -->
58635887

58645888
<p><a for=/>Shadow roots</a> have an associated <dfn for=ShadowRoot>slot assignment</dfn>
58655889
("<code>manual</code>" or "<code>named</code>").
58665890

5891+
<p><a for=/>Shadow roots</a> have an associated <dfn for=ShadowRoot>clonable</dfn> (a boolean).
5892+
It is initially set to false.</p>
5893+
58675894
<p>A <a for=/>shadow root</a>'s <a>get the parent</a> algorithm, given an <var>event</var>, returns
58685895
null if <var>event</var>'s <a>composed flag</a> is unset and <a for=/>shadow root</a> is the
58695896
<a for=tree>root</a> of <var>event</var>'s <a for=Event>path</a>'s first struct's
@@ -6010,6 +6037,7 @@ dictionary ShadowRootInit {
60106037
required ShadowRootMode mode;
60116038
boolean delegatesFocus = false;
60126039
SlotAssignmentMode slotAssignment = "named";
6040+
boolean clonable = false;
60136041
};
60146042
</pre>
60156043

@@ -6857,23 +6885,38 @@ are:
68576885
"<code>span</code>"
68586886
</ul>
68596887

6888+
<div algorithm>
68606889
<p>The <dfn method for=Element><code>attachShadow(<var>init</var>)</code></dfn> method steps are:
68616890

68626891
<ol>
6863-
<li><p>If <a>this</a>'s <a for=Element>namespace</a> is not the <a>HTML namespace</a>,
6892+
<li><p>Run <a>attach a shadow root</a> with <a>this</a>, <var>init</var>["{{ShadowRootInit/mode}}"],
6893+
<var>init</var>["{{ShadowRootInit/clonable}}"], <var>init</var>["{{ShadowRootInit/delegatesFocus}}"],
6894+
and <var>init</var>["{{ShadowRootInit/slotAssignment}}"].
6895+
6896+
<li><p>Return <a>this</a>'s <a for=Element>shadow root</a>.
6897+
</ol>
6898+
</div>
6899+
6900+
<div algorithm>
6901+
<p>To <dfn id=concept-attach-a-shadow-root>attach a shadow root</dfn>, given an
6902+
<a for=/>element</a> <var>element</var>, a string <var>mode</var>, a boolean <var>clonable</var>,
6903+
a boolean <var>delegatesFocus</var>, and a boolean <var>slotAssignment</var>:
6904+
6905+
<ol>
6906+
<li><p>If <var>element</var>'s <a for=Element>namespace</a> is not the <a>HTML namespace</a>,
68646907
then <a>throw</a> a "{{NotSupportedError!!exception}}" {{DOMException}}.
68656908

68666909
<li><p>If <a>this</a>'s <a for=Element>local name</a> is not a <a>valid shadow host name</a>, then
68676910
<a>throw</a> a "{{NotSupportedError!!exception}}" {{DOMException}}.
68686911

68696912
<li>
6870-
<p>If <a>this</a>'s <a for=Element>local name</a> is a <a>valid custom element name</a>, or
6871-
<a>this</a>'s <a for=Element><code>is</code> value</a> is not null, then:
6913+
<p>If <var>element</var>'s <a for=Element>local name</a> is a <a>valid custom element name</a>, or
6914+
<var>element</var>'s <a for=Element><code>is</code> value</a> is non-null, then:
68726915

68736916
<ol>
68746917
<li><p>Let <var>definition</var> be the result of
68756918
<a lt="look up a custom element definition">looking up a custom element definition</a> given
6876-
<a>this</a>'s <a for=Node>node document</a>, its <a for=Element>namespace</a>, its
6919+
<var>element</var>'s <a for=Node>node document</a>, its <a for=Element>namespace</a>, its
68776920
<a for=Element>local name</a>, and its <a for=Element><code>is</code> value</a>.
68786921

68796922
<li><p>If <var>definition</var> is not null and <var>definition</var>'s
@@ -6882,38 +6925,52 @@ are:
68826925
</ol>
68836926
</li>
68846927

6885-
<li><p>If <a>this</a> is a <a for=Element>shadow host</a>, then <a>throw</a> an
6886-
"{{NotSupportedError!!exception}}" {{DOMException}}.
6928+
<li>
6929+
<p>If <var>element</var> is a <a for=Element>shadow host</a>, then:
6930+
6931+
<ol>
6932+
<li><p>If <var>element</var>'s <a for=Element>shadow root</a>'s <a for=ShadowRoot>declarative</a>
6933+
is false, then <a>throw</a> an "{{NotSupportedError!!exception}}" {{DOMException}}.
6934+
6935+
<li><p>Otherwise, <a for=/>remove</a> all of <var>element</var>'s
6936+
<a for=Element>shadow root</a>'s <a>children</a>, in <a>tree order</a>, and return.
6937+
6938+
<p class=note>This means that if multiple declarative shadow roots are contained within a single
6939+
shadow host, only the last one will remain.
6940+
</ol>
68876941

68886942
<li><p>Let <var>shadow</var> be a new <a for=/>shadow root</a> whose <a for=Node>node document</a>
6889-
is <a>this</a>'s <a for=Node>node document</a>, <a for=DocumentFragment>host</a> is <a>this</a>,
6890-
and <a for=ShadowRoot>mode</a> is <var>init</var>["{{ShadowRootInit/mode}}"].
6943+
is <var>element</var>'s <a for=Node>node document</a>, <a for=DocumentFragment>host</a> is
6944+
<var>element</var>, and <a for=ShadowRoot>mode</a> is <var>mode</var>.
68916945

6892-
<li><p>Set <var>shadow</var>'s <a for=ShadowRoot>delegates focus</a> to
6893-
<var>init</var>["{{ShadowRootInit/delegatesFocus}}"].
6946+
<li><p>Set <var>shadow</var>'s <a for=ShadowRoot>delegates focus</a> to <var>delegatesFocus</var>.
68946947

68956948
<li><p>If <a>this</a>'s <a for=Element>custom element state</a> is "<code>precustomized</code>" or
68966949
"<code>custom</code>", then set <var>shadow</var>'s
68976950
<a for=ShadowRoot>available to element internals</a> to true.
68986951

6899-
<li><p>Set <var>shadow</var>'s <a for=ShadowRoot>slot assignment</a> to
6900-
<var>init</var>["{{ShadowRootInit/slotAssignment}}"].
6952+
<li><p>Set <var>shadow</var>'s <a for=ShadowRoot>slot assignment</a> to <var>slotAssignment</var>.
69016953

6902-
<li><p>Set <a>this</a>'s <a for=Element>shadow root</a> to <var>shadow</var>.
6954+
<li><p>Set <var>shadow</var>'s <a for=ShadowRoot>declarative</a> to false.
69036955

6904-
<li><p>Return <var>shadow</var>.
6956+
<li><p>Set <var>shadow</var>'s <a for=ShadowRoot>clonable</a> to <var>clonable</var>.
6957+
6958+
<li><p>Set <var>element</var>'s <a for=Element>shadow root</a> to <var>shadow</var>.
69056959
</ol>
6960+
</div>
69066961

6962+
<div algorithm>
69076963
<p>The <dfn attribute for=Element><code>shadowRoot</code></dfn> getter steps are:
69086964

69096965
<ol>
69106966
<li><p>Let <var>shadow</var> be <a>this</a>'s <a for=Element>shadow root</a>.
69116967

69126968
<li><p>If <var>shadow</var> is null or its <a for=ShadowRoot>mode</a> is "<code>closed</code>",
6913-
then return null.</p></li>
6969+
then return null.
69146970

69156971
<li><p>Return <var>shadow</var>.
69166972
</ol>
6973+
</div>
69176974

69186975
<hr>
69196976

@@ -10223,7 +10280,7 @@ Manish Tripathi,
1022310280
Marcos Caceres,
1022410281
Mark Miller,
1022510282
Martijn van der Ven,
10226-
Mason Freed,
10283+
Mason Freed,<!-- mfreed7; GitHub -->
1022710284
Mats Palmgren,
1022810285
Mounir Lamouri,
1022910286
Michael Stramel,

0 commit comments

Comments
 (0)