Refactor IDE index to support EE specific code
**Why?** - The web terminal feature is EE specific and will need to inject some specific options / functions into certain components.
This commit is contained in:
parent
62dde35069
commit
d9bb488a1e
|
@ -8,9 +8,21 @@ import { convertPermissionToBoolean } from '../lib/utils/common_utils';
|
||||||
|
|
||||||
Vue.use(Translate);
|
Vue.use(Translate);
|
||||||
|
|
||||||
export function initIde(el) {
|
/**
|
||||||
|
* 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 {(e:Element) => Object} options.extraInitialData -
|
||||||
|
* Function that returns extra properties to seed initial data.
|
||||||
|
*/
|
||||||
|
export function initIde(el, options = {}) {
|
||||||
if (!el) return null;
|
if (!el) return null;
|
||||||
|
|
||||||
|
const {
|
||||||
|
extraInitialData = () => ({}),
|
||||||
|
} = options;
|
||||||
|
|
||||||
return new Vue({
|
return new Vue({
|
||||||
el,
|
el,
|
||||||
store,
|
store,
|
||||||
|
@ -32,6 +44,7 @@ export function initIde(el) {
|
||||||
});
|
});
|
||||||
this.setInitialData({
|
this.setInitialData({
|
||||||
clientsidePreviewEnabled: convertPermissionToBoolean(el.dataset.clientsidePreviewEnabled),
|
clientsidePreviewEnabled: convertPermissionToBoolean(el.dataset.clientsidePreviewEnabled),
|
||||||
|
...extraInitialData(el),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -52,3 +65,18 @@ export function resetServiceWorkersPublicPath() {
|
||||||
const webpackAssetPath = `${relativeRootPath}/assets/webpack/`;
|
const webpackAssetPath = `${relativeRootPath}/assets/webpack/`;
|
||||||
__webpack_public_path__ = webpackAssetPath; // eslint-disable-line camelcase
|
__webpack_public_path__ = webpackAssetPath; // eslint-disable-line camelcase
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the IDE.
|
||||||
|
*
|
||||||
|
* @param {Objects} options - Extra options for the IDE (Used by EE).
|
||||||
|
*/
|
||||||
|
export function startIde(options) {
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
const ideElement = document.getElementById('ide');
|
||||||
|
if (ideElement) {
|
||||||
|
resetServiceWorkersPublicPath();
|
||||||
|
initIde(ideElement, options);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -1,9 +1,3 @@
|
||||||
import { initIde, resetServiceWorkersPublicPath } from '~/ide/index';
|
import { startIde } from '~/ide/index';
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
startIde();
|
||||||
const ideElement = document.getElementById('ide');
|
|
||||||
if (ideElement) {
|
|
||||||
resetServiceWorkersPublicPath();
|
|
||||||
initIde(ideElement);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
Loading…
Reference in New Issue