Skip to content

Commit 0c397ae

Browse files
author
Cameron Stitt
committed
Make passed 23673slots render through slotted option
1 parent 370e117 commit 0c397ae

File tree

5 files changed

+38
-10
lines changed

5 files changed

+38
-10
lines changed

src/compiler/compile/render_dom/index.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -460,15 +460,21 @@ export default function dom(
460460
${dev_props_check}
461461
462462
if (options) {
463+
this.$$.slotted = {};
464+
463465
if (options.target) {
464466
@insert(options.target, this, options.anchor);
465467
}
466468
467-
${(props.length > 0 || uses_props) && deindent`
468469
if (options.props) {
470+
for (const key in options.props.$$slots) {
471+
this.$$.slotted[key] = options.props.$$slots[key][0]();
472+
this.$$.slotted[key].c();
473+
}
474+
${(props.length > 0 || uses_props) && deindent`
469475
this.$set(options.props);
470-
@flush();
471-
}`}
476+
@flush();`}
477+
}
472478
}
473479
}
474480

src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,15 @@ export default class InlineComponentWrapper extends Wrapper {
449449
);
450450
}
451451

452-
block.builders.mount.add_line(
453-
`@mount_component(${name}, ${parent_node || '#target'}, ${parent_node ? 'null' : 'anchor'});`
454-
);
452+
if (component.compile_options.customElement) {
453+
block.builders.mount.add_line(
454+
`@insert(${ parent_node || '#target'}, ${name}, ${parent_node ? 'null' : 'anchor'});`
455+
)
456+
} else {
457+
block.builders.mount.add_line(
458+
`@mount_component(${name}, ${parent_node || '#target'}, ${parent_node ? 'null' : 'anchor'});`
459+
);
460+
}
455461

456462
block.builders.intro.add_block(deindent`
457463
@transition_in(${name}.$$.fragment, #local);

src/runtime/internal/Component.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ if (typeof HTMLElement !== 'undefined') {
146146
// @ts-ignore todo: improve typings
147147
for (const key in this.$$.slotted) {
148148
// @ts-ignore todo: improve typings
149-
this.appendChild(this.$$.slotted[key]);
149+
this.$$.slotted[key].m(this, null);
150150
}
151151
}
152152

@@ -155,6 +155,11 @@ if (typeof HTMLElement !== 'undefined') {
155155
}
156156

157157
$destroy() {
158+
// @ts-ignore todo: improve typings
159+
for (const key in this.$$.slotted) {
160+
// @ts-ignore todo: improve typings
161+
this.$$.slotted[key].d();
162+
}
158163
destroy_component(this, 1);
159164
this.$destroy = noop;
160165
}

test/custom-elements/samples/nested-slots/test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ export default async function (target) {
77

88
const block = el.shadowRoot.children[0];
99

10-
const [slot] = block.children;
10+
const h1 = block.shadowRoot.children[0];
11+
12+
const [slot] = h1.children;
1113

1214
assert.equal(slot.assignedNodes().length, 1);
13-
}
15+
}

test/js/samples/css-shadow-dom-keyframes/expected.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,22 @@ class Component extends SvelteElement {
4444
init(this, { target: this.shadowRoot }, null, create_fragment, safe_not_equal, []);
4545

4646
if (options) {
47+
this.$$.slotted = {};
48+
4749
if (options.target) {
4850
insert(options.target, this, options.anchor);
4951
}
52+
53+
if (options.props) {
54+
for (const key in options.props.$$slots) {
55+
this.$$.slotted[key] = options.props.$$slots[key][0]();
56+
this.$$.slotted[key].c();
57+
}
58+
}
5059
}
5160
}
5261
}
5362

5463
customElements.define("custom-element", Component);
5564

56-
export default Component;
65+
export default Component;

0 commit comments

Comments
 (0)