-
-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f70795e
commit b40536e
Showing
2 changed files
with
9 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters