Skip to content

Commit

Permalink
Expose real element from Svelte component
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardocavazza committed Jul 16, 2024
1 parent adeabbe commit 2ef631a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/healthy-pots-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chialab/plasma': patch
---

Expose real element from Svelte component.
9 changes: 8 additions & 1 deletion src/svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ export function generateSvelteComponent(entry: Entry, options: SvelteTransformOp
slots.push('<slot />');

const markup = `<!-- svelte-ignore attribute_avoid_is -->
<${definition.extend ?? definition.name}${
<${definition.extend ?? definition.name}
bind:this={__element}${
definition.extend
? `
is="${definition.name}"`
Expand Down Expand Up @@ -225,6 +226,11 @@ export function generateSvelteComponent(entry: Entry, options: SvelteTransformOp
};
}
let __element;
export function getElement() {
return __element;
}
${props.map((propName) => `export let ${propName} = undefined;`).join('\n ')}
</script>
Expand Down Expand Up @@ -278,6 +284,7 @@ export type ${declaration.name}Slots = typeof __propDef.slots;
export class ${declaration.name} extends SvelteComponent<${declaration.name}Props, ${declaration.name}Events, ${
declaration.name
}Slots> {
getElement(): Base${declaration.name};
}
`;

Expand Down

0 comments on commit 2ef631a

Please sign in to comment.