2022-10-01 19:56:38 +05:30
|
|
|
import {createApp} from 'vue';
|
2021-10-15 08:05:26 +05:30
|
|
|
import {svgs} from '../svg.js';
|
|
|
|
|
2021-10-16 22:58:04 +05:30
|
|
|
export const vueDelimiters = ['${', '}'];
|
2021-10-15 08:05:26 +05:30
|
|
|
|
|
|
|
let vueEnvInited = false;
|
2021-10-16 22:58:04 +05:30
|
|
|
export function initVueEnv() {
|
2021-10-15 08:05:26 +05:30
|
|
|
if (vueEnvInited) return;
|
|
|
|
vueEnvInited = true;
|
|
|
|
|
2022-10-01 19:56:38 +05:30
|
|
|
// 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 08:05:26 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
let vueSvgInited = false;
|
2022-10-01 19:56:38 +05:30
|
|
|
export function initVueSvg(app) {
|
2021-10-15 08:05:26 +05:30
|
|
|
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 19:56:38 +05:30
|
|
|
app.component(name, {
|
2021-10-15 08:05:26 +05:30
|
|
|
props: {
|
|
|
|
size: {
|
|
|
|
type: String,
|
|
|
|
default: '16',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
template,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-16 22:58:04 +05:30
|
|
|
export function initVueApp(el, opts = {}) {
|
2021-10-15 08:05:26 +05:30
|
|
|
if (typeof el === 'string') {
|
|
|
|
el = document.querySelector(el);
|
|
|
|
}
|
|
|
|
if (!el) return null;
|
|
|
|
|
2022-10-01 19:56:38 +05:30
|
|
|
return createApp(
|
|
|
|
Object.assign({delimiters: vueDelimiters}, opts)
|
|
|
|
).mount(el);
|
2021-10-15 08:05:26 +05:30
|
|
|
}
|