vite-plugin-symfony
Version:
A Vite plugin to integrate easily Vite in your Symfony application
60 lines (59 loc) • 1.56 kB
JavaScript
// src/stimulus/helpers/svelte4/render_controller.ts
import { Controller } from "@hotwired/stimulus";
var render_controller_default = class extends Controller {
app;
props;
intro;
static values = {
component: String,
props: Object,
intro: Boolean
};
connect() {
this.element.innerHTML = "";
this.props = this.propsValue ?? void 0;
this.intro = this.introValue ?? void 0;
this.dispatchEvent("connect");
const importedSvelteModule = window.resolveSvelteComponent(this.componentValue);
const onload = (svelteModule) => {
const Component = svelteModule.default;
this._destroyIfExists();
this.app = new Component({
target: this.element,
props: this.props,
intro: this.intro
});
this.element.root = this.app;
this.dispatchEvent("mount", {
component: Component
});
};
if (typeof importedSvelteModule === "function") {
importedSvelteModule().then(onload);
} else {
onload(importedSvelteModule);
}
}
disconnect() {
this._destroyIfExists();
this.dispatchEvent("unmount");
}
_destroyIfExists() {
if (this.element.root !== void 0) {
this.element.root.$destroy();
delete this.element.root;
}
}
dispatchEvent(name, payload = {}) {
const detail = {
componentName: this.componentValue,
props: this.props,
intro: this.intro,
...payload
};
this.dispatch(name, { detail, prefix: "svelte" });
}
};
export {
render_controller_default as default
};