2019-12-13 18:08:06 +00:00
|
|
|
import Vue from 'vue';
|
|
|
|
import VueApollo from 'vue-apollo';
|
2020-08-17 21:09:56 +00:00
|
|
|
import Translate from '~/vue_shared/translate';
|
2019-12-13 18:08:06 +00:00
|
|
|
import createDefaultClient from '~/lib/graphql';
|
|
|
|
|
2020-09-05 00:08:43 +00:00
|
|
|
import { SNIPPET_LEVELS_MAP, SNIPPET_VISIBILITY_PRIVATE } from '~/snippets/constants';
|
2019-12-13 18:08:06 +00:00
|
|
|
|
|
|
|
Vue.use(VueApollo);
|
|
|
|
Vue.use(Translate);
|
|
|
|
|
2020-10-19 12:09:20 +00:00
|
|
|
export default function appFactory(el, Component) {
|
2019-12-13 18:08:06 +00:00
|
|
|
if (!el) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const apolloProvider = new VueApollo({
|
2020-09-24 12:09:37 +00:00
|
|
|
defaultClient: createDefaultClient({}, { batchMax: 1 }),
|
2019-12-13 18:08:06 +00:00
|
|
|
});
|
|
|
|
|
2020-09-05 00:08:43 +00:00
|
|
|
const {
|
|
|
|
visibilityLevels = '[]',
|
|
|
|
selectedLevel,
|
|
|
|
multipleLevelsRestricted,
|
|
|
|
...restDataset
|
|
|
|
} = el.dataset;
|
|
|
|
|
2020-11-03 15:09:05 +00:00
|
|
|
return new Vue({
|
|
|
|
el,
|
|
|
|
apolloProvider,
|
|
|
|
provide: {
|
2020-09-05 00:08:43 +00:00
|
|
|
visibilityLevels: JSON.parse(visibilityLevels),
|
|
|
|
selectedLevel: SNIPPET_LEVELS_MAP[selectedLevel] ?? SNIPPET_VISIBILITY_PRIVATE,
|
|
|
|
multipleLevelsRestricted: 'multipleLevelsRestricted' in el.dataset,
|
|
|
|
},
|
2019-12-13 18:08:06 +00:00
|
|
|
render(createElement) {
|
2020-03-24 15:08:44 +00:00
|
|
|
return createElement(Component, {
|
2019-12-13 18:08:06 +00:00
|
|
|
props: {
|
2020-09-05 00:08:43 +00:00
|
|
|
...restDataset,
|
2019-12-13 18:08:06 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
2020-03-24 15:08:44 +00:00
|
|
|
}
|