2021-10-14 22:35:26 -04:00
|
|
|
import Vue from 'vue';
|
|
|
|
import {svgs} from '../svg.js';
|
|
|
|
|
2021-10-16 13:28:04 -04:00
|
|
|
export const vueDelimiters = ['${', '}'];
|
2021-10-14 22:35:26 -04:00
|
|
|
|
|
|
|
let vueEnvInited = false;
|
2021-10-16 13:28:04 -04:00
|
|
|
export function initVueEnv() {
|
2021-10-14 22:35:26 -04:00
|
|
|
if (vueEnvInited) return;
|
|
|
|
vueEnvInited = true;
|
|
|
|
|
|
|
|
const isProd = window.config.IsProd;
|
|
|
|
Vue.config.productionTip = false;
|
|
|
|
Vue.config.devtools = !isProd;
|
|
|
|
}
|
|
|
|
|
|
|
|
let vueSvgInited = false;
|
2021-10-16 13:28:04 -04:00
|
|
|
export function initVueSvg() {
|
2021-10-14 22:35:26 -04: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"');
|
|
|
|
|
|
|
|
Vue.component(name, {
|
|
|
|
props: {
|
|
|
|
size: {
|
|
|
|
type: String,
|
|
|
|
default: '16',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
template,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-16 13:28:04 -04:00
|
|
|
export function initVueApp(el, opts = {}) {
|
2021-10-14 22:35:26 -04:00
|
|
|
if (typeof el === 'string') {
|
|
|
|
el = document.querySelector(el);
|
|
|
|
}
|
|
|
|
if (!el) return null;
|
|
|
|
|
|
|
|
return new Vue(Object.assign({
|
|
|
|
el,
|
|
|
|
delimiters: vueDelimiters,
|
|
|
|
}, opts));
|
|
|
|
}
|