Skip to content

Commit

Permalink
Replace old plugin code
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianallgeier committed Apr 5, 2023
1 parent f70795e commit b40536e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 65 deletions.
69 changes: 4 additions & 65 deletions panel/src/config/plugins.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,11 @@
import store from "@/store/store.js";
import section from "../mixins/section.js";
import Plugins from "@/panel/plugins.js";

export default {
install(app) {
const components = { ...app.options.components };

const mixins = {
section: section
};

/**
* Components
*/
for (const [name, options] of Object.entries(
window.panel.plugins.components
)) {
// make sure component has something to show
if (!options.template && !options.render && !options.extends) {
store.dispatch(
"notification/error",
`Neither template or render method provided nor extending a component when loading plugin component "${name}". The component has not been registered.`
);
continue;
}

// resolve extending via component name
if (typeof options?.extends === "string") {
// only extend if referenced component exists
if (components[options.extends]) {
options.extends = components[options.extends].extend({
options,
components: {
...components,
...(options.components || {})
}
});
} else {
// if component doesn't exist, don't extend
window.console.warn(
`Problem with plugin trying to register component "${name}": cannot extend non-existent component "${options.extends}"`
);
options.extends = null;
}
}

if (options.template) {
options.render = null;
}

if (options.mixins) {
options.mixins = options.mixins.map((mixin) =>
typeof mixin === "string" ? mixins[mixin] : mixin
);
}

if (components[name]) {
window.console.warn(`Plugin is replacing "${name}"`);
}

app.component(name, options);
components[name] = app.options.components[name];
}

/**
* `Vue.use`
* Temporary polyfill until this is all
* bundled under window.panel
*/
for (const plugin of window.panel.plugins.use) {
app.use(plugin);
}
window.panel.plugins = Plugins(app, window.panel.plugins);
}
};
5 changes: 5 additions & 0 deletions panel/src/panel/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ export const installPlugins = (app, plugins) => {
return plugins;
};

/**
* The plugin module installs all
* given plugins and makes them accessible
* at window.panel.plugins
*/
export default (app, plugins = {}) => {
plugins = {
components: {},
Expand Down

0 comments on commit b40536e

Please sign in to comment.