upend/ui/src/main.ts

37 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-09-25 01:11:04 +02:00
import * as Vue from "vue";
import {DirectiveBinding} from "vue";
import App from "./App.vue";
import router from "./router";
2020-09-25 01:11:04 +02:00
import {defineCustomElements, setAssetPath, SlInput,} from "@shoelace-style/shoelace";
// TODO: Remove when UI settles!
defineCustomElements();
setAssetPath(`${window.location.origin}/${process.env.VUE_APP_ASSET_PATH}/`);
2020-09-25 01:11:04 +02:00
const app = Vue.createApp(App);
app.use(router);
app.mount("#app");
app.config.isCustomElement = (tag: string) => Boolean(tag.match(/^sl-/));
2020-09-25 01:11:04 +02:00
app.directive("sl-model", {
beforeMount: (element: Element, binding: DirectiveBinding<string>) => {
element.addEventListener("slInput", (event) => {
const slElement = event?.target as
| typeof SlInput.prototype
| undefined;
const value = slElement?.value;
if (value && binding.instance) {
(binding.instance.$data as { [key: string]: unknown })[binding.arg as string] = value;
}
});
},
updated: (element: Element, binding: DirectiveBinding<string>) => {
const slElement = element as typeof SlInput.prototype | undefined;
if (slElement) {
slElement.value = (binding.instance?.$data as { [key: string]: unknown })[binding.arg as string] as string;
}
},
});