2022-10-01 17:26:38 +03:00
|
|
|
import {createApp} from 'vue';
|
2021-10-15 05:35:26 +03:00
|
|
|
import {svgs} from '../svg.js';
|
|
|
|
|
2021-10-16 20:28:04 +03:00
|
|
|
export const vueDelimiters = ['${', '}'];
|
2021-10-15 05:35:26 +03:00
|
|
|
|
|
|
|
let vueEnvInited = false;
|
2021-10-16 20:28:04 +03:00
|
|
|
export function initVueEnv() {
|
2021-10-15 05:35:26 +03:00
|
|
|
if (vueEnvInited) return;
|
|
|
|
vueEnvInited = true;
|
|
|
|
|
2022-10-01 17:26:38 +03:00
|
|
|
// As far as I could tell, this is no longer possible.
|
|
|
|
// But there seem not to be a guide what to do instead.
|
|
|
|
// const isProd = window.config.runModeIsProd;
|
|
|
|
// Vue.config.devtools = !isProd;
|
2021-10-15 05:35:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
let vueSvgInited = false;
|
2022-10-01 17:26:38 +03:00
|
|
|
export function initVueSvg(app) {
|
2021-10-15 05:35:26 +03:00
|
|
|
if (vueSvgInited) return;
|
|
|
|
vueSvgInited = true;
|
|
|
|
|
|
|
|
// register svg icon vue components, e.g. <octicon-repo size="16"/>
|
|
|
|
for (const [name, htmlString] of Object.entries(svgs)) {
|
|
|
|
const template = htmlString
|
|
|
|
.replace(/height="[0-9]+"/, 'v-bind:height="size"')
|
|
|
|
.replace(/width="[0-9]+"/, 'v-bind:width="size"');
|
|
|
|
|
2022-10-01 17:26:38 +03:00
|
|
|
app.component(name, {
|
2021-10-15 05:35:26 +03:00
|
|
|
props: {
|
|
|
|
size: {
|
|
|
|
type: String,
|
|
|
|
default: '16',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
template,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-16 20:28:04 +03:00
|
|
|
export function initVueApp(el, opts = {}) {
|
2021-10-15 05:35:26 +03:00
|
|
|
if (typeof el === 'string') {
|
|
|
|
el = document.querySelector(el);
|
|
|
|
}
|
|
|
|
if (!el) return null;
|
|
|
|
|
2022-10-01 17:26:38 +03:00
|
|
|
return createApp(
|
2022-10-10 15:02:20 +03:00
|
|
|
{delimiters: vueDelimiters, ...opts}
|
2022-10-01 17:26:38 +03:00
|
|
|
).mount(el);
|
2021-10-15 05:35:26 +03:00
|
|
|
}
|