Skip to content
This repository was archived by the owner on Nov 27, 2025. It is now read-only.

Commit c39cd6c

Browse files
authored
fix: openscd forgets disabled plugins (#1618)
1 parent dc78329 commit c39cd6c

File tree

11 files changed

+1359
-81
lines changed

11 files changed

+1359
-81
lines changed

package-lock.json

Lines changed: 116 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openscd/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,4 @@
172172
],
173173
"commitUrlFormat": "https://github.com/openscd/open-scd/commits/{{hash}}"
174174
}
175-
}
175+
}

packages/openscd/src/open-scd.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ export class OpenSCD extends LitElement {
254254

255255
private resetPlugins(): void {
256256
this.storePlugins(
257-
(builtinPlugins as Plugin[]).concat(this.parsedPlugins).map(plugin => {
257+
(this.getBuiltInPlugins() as Plugin[]).concat(this.parsedPlugins).map(plugin => {
258258
return {
259259
...plugin,
260260
installed: plugin.default ?? false,
@@ -316,7 +316,7 @@ export class OpenSCD extends LitElement {
316316
const isBuiltIn = !plugin?.official
317317
if (!isBuiltIn){ return plugin };
318318

319-
const builtInPlugin = [...builtinPlugins, ...this.parsedPlugins]
319+
const builtInPlugin = [...this.getBuiltInPlugins(), ...this.parsedPlugins]
320320
.find(p => p.src === plugin.src);
321321

322322
return <Plugin>{
@@ -367,14 +367,14 @@ export class OpenSCD extends LitElement {
367367
const localPluginConfigs = this.getPluginConfigsFromLocalStorage()
368368

369369
const overwritesOfBultInPlugins = localPluginConfigs.filter((p) => {
370-
return builtinPlugins.some(b => b.src === p.src)
370+
return this.getBuiltInPlugins().some(b => b.src === p.src)
371371
})
372372

373373
const userInstalledPlugins = localPluginConfigs.filter((p) => {
374-
return !builtinPlugins.some(b => b.src === p.src)
374+
return !this.getBuiltInPlugins().some(b => b.src === p.src)
375375
})
376376

377-
const mergedBuiltInPlugins = builtinPlugins.map((builtInPlugin) => {
377+
const mergedBuiltInPlugins = this.getBuiltInPlugins().map((builtInPlugin) => {
378378
const noopOverwrite = {}
379379
const overwrite = overwritesOfBultInPlugins
380380
.find(p => p.src === builtInPlugin.src)
@@ -404,6 +404,10 @@ export class OpenSCD extends LitElement {
404404
this.storePlugins(newPlugins);
405405
}
406406

407+
protected getBuiltInPlugins(): CorePlugin[] {
408+
return builtinPlugins as CorePlugin[]
409+
}
410+
407411
private addContent(plugin: Omit<Plugin, 'content'>): Plugin {
408412
const tag = this.pluginTag(plugin.src);
409413

packages/openscd/src/plugins.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function generatePluginPath(plugin: string): string {
1+
export function generatePluginPath(plugin: string): string {
22
return location.origin+location.pathname+plugin;
33
}
44

packages/openscd/test/mock-open-scd.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@ import {
44
html,
55
queryAssignedNodes,
66
query,
7+
property
78
} from 'lit-element';
89
import { OscdWizards } from '../src/addons/Wizards.js';
910
import { WizardFactory } from '../src/foundation.js';
1011
import { OpenSCD } from '../src/open-scd.js';
1112
import { WizardDialog } from '../src/wizard-dialog.js';
1213
import { OscdHistory } from '../src/addons/History.js';
1314
import { OscdLayout } from '../src/addons/Layout.js';
15+
// import type { Plugin } from '@openscd/core';
16+
import { Plugin } from '../src/plugin';
1417

1518
@customElement('mock-open-scd')
1619
export class MockOpenSCD extends OpenSCD {
20+
21+
@property({ attribute: false })
22+
mockPlugins: Plugin[] = []
23+
1724
@queryAssignedNodes()
1825
_plugins!: Array<HTMLElement>;
1926

@@ -32,10 +39,17 @@ export class MockOpenSCD extends OpenSCD {
3239

3340
render(): TemplateResult {
3441
return html`
35-
${this.renderHosting()}
36-
${super.render()}`;
42+
${this.renderHosting()}
43+
${super.render()}
44+
`;
45+
}
46+
47+
protected getBuiltInPlugins(): Plugin[]{
48+
return this.mockPlugins;
3749
}
3850

51+
52+
3953
getPlugin<T extends HTMLElement>(name: string): T | undefined {
4054
return this._plugins.find(
4155
p => p.tagName.toLowerCase() === name.toLowerCase()

0 commit comments

Comments
 (0)