2021-03-11 19:13:27 +05:30
|
|
|
import { identity } from 'lodash';
|
2018-05-09 12:01:36 +05:30
|
|
|
import Vue from 'vue';
|
2018-11-08 19:23:39 +05:30
|
|
|
import { mapActions } from 'vuex';
|
2021-02-22 17:27:13 +05:30
|
|
|
import PerformancePlugin from '~/performance/vue_performance_plugin';
|
2021-03-11 19:13:27 +05:30
|
|
|
import Translate from '~/vue_shared/translate';
|
2019-02-15 15:39:39 +05:30
|
|
|
import { parseBoolean } from '../lib/utils/common_utils';
|
2019-03-02 22:35:43 +05:30
|
|
|
import { resetServiceWorkersPublicPath } from '../lib/utils/webpack';
|
2021-03-11 19:13:27 +05:30
|
|
|
import ide from './components/ide.vue';
|
|
|
|
import { createRouter } from './ide_router';
|
2020-03-13 15:44:24 +05:30
|
|
|
import { DEFAULT_THEME } from './lib/themes';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { createStore } from './stores';
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
Vue.use(Translate);
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
Vue.use(PerformancePlugin, {
|
|
|
|
components: ['FileTree'],
|
|
|
|
});
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
/**
|
|
|
|
* Function that receives the default store and returns an extended one.
|
|
|
|
* @callback extendStoreCallback
|
|
|
|
* @param {Vuex.Store} store
|
|
|
|
* @param {Element} el
|
|
|
|
*/
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
/**
|
|
|
|
* Initialize the IDE on the given element.
|
|
|
|
*
|
|
|
|
* @param {Element} el - The element that will contain the IDE.
|
|
|
|
* @param {Object} options - Extra options for the IDE (Used by EE).
|
|
|
|
* @param {Component} options.rootComponent -
|
|
|
|
* Component that overrides the root component.
|
2019-03-02 22:35:43 +05:30
|
|
|
* @param {extendStoreCallback} options.extendStore -
|
2019-02-15 15:39:39 +05:30
|
|
|
* Function that receives the default store and returns an extended one.
|
2018-12-05 23:21:45 +05:30
|
|
|
*/
|
|
|
|
export function initIde(el, options = {}) {
|
2018-05-09 12:01:36 +05:30
|
|
|
if (!el) return null;
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
const { rootComponent = ide, extendStore = identity } = options;
|
2020-10-24 23:57:45 +05:30
|
|
|
const store = createStore();
|
2020-06-23 00:09:42 +05:30
|
|
|
const router = createRouter(store);
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
return new Vue({
|
|
|
|
el,
|
2019-02-15 15:39:39 +05:30
|
|
|
store: extendStore(store, el),
|
2018-05-09 12:01:36 +05:30
|
|
|
router,
|
2018-10-15 14:42:47 +05:30
|
|
|
created() {
|
2018-11-08 19:23:39 +05:30
|
|
|
this.setEmptyStateSvgs({
|
2018-10-15 14:42:47 +05:30
|
|
|
emptyStateSvgPath: el.dataset.emptyStateSvgPath,
|
|
|
|
noChangesStateSvgPath: el.dataset.noChangesStateSvgPath,
|
|
|
|
committedStateSvgPath: el.dataset.committedStateSvgPath,
|
2018-11-08 19:23:39 +05:30
|
|
|
pipelinesEmptyStateSvgPath: el.dataset.pipelinesEmptyStateSvgPath,
|
2018-11-18 11:00:15 +05:30
|
|
|
promotionSvgPath: el.dataset.promotionSvgPath,
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
this.setLinks({
|
2018-11-18 11:00:15 +05:30
|
|
|
webIDEHelpPagePath: el.dataset.webIdeHelpPagePath,
|
2021-04-29 21:17:54 +05:30
|
|
|
forkInfo: el.dataset.forkInfo ? JSON.parse(el.dataset.forkInfo) : null,
|
2018-11-18 11:00:15 +05:30
|
|
|
});
|
|
|
|
this.setInitialData({
|
2019-02-15 15:39:39 +05:30
|
|
|
clientsidePreviewEnabled: parseBoolean(el.dataset.clientsidePreviewEnabled),
|
2020-03-13 15:44:24 +05:30
|
|
|
renderWhitespaceInCode: parseBoolean(el.dataset.renderWhitespaceInCode),
|
|
|
|
editorTheme: window.gon?.user_color_scheme || DEFAULT_THEME,
|
2020-04-08 14:13:33 +05:30
|
|
|
codesandboxBundlerUrl: el.dataset.codesandboxBundlerUrl,
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
},
|
2021-03-08 18:12:59 +05:30
|
|
|
beforeDestroy() {
|
|
|
|
// This helps tests do Singleton cleanups which we don't really have responsibility to know about here.
|
|
|
|
this.$emit('destroy');
|
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
methods: {
|
2018-11-18 11:00:15 +05:30
|
|
|
...mapActions(['setEmptyStateSvgs', 'setLinks', 'setInitialData']),
|
2018-05-09 12:01:36 +05:30
|
|
|
},
|
2018-10-15 14:42:47 +05:30
|
|
|
render(createElement) {
|
2018-12-05 23:21:45 +05:30
|
|
|
return createElement(rootComponent);
|
2018-10-15 14:42:47 +05:30
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
/**
|
|
|
|
* Start the IDE.
|
|
|
|
*
|
|
|
|
* @param {Objects} options - Extra options for the IDE (Used by EE).
|
|
|
|
*/
|
|
|
|
export function startIde(options) {
|
2021-01-03 14:25:43 +05:30
|
|
|
const ideElement = document.getElementById('ide');
|
|
|
|
if (ideElement) {
|
|
|
|
resetServiceWorkersPublicPath();
|
|
|
|
initIde(ideElement, options);
|
|
|
|
}
|
2018-12-05 23:21:45 +05:30
|
|
|
}
|