Skip to content

Commit 8b06a37

Browse files
authored
Feat: Editor plugins can be rendered without an active document
1 parent 0543988 commit 8b06a37

File tree

9 files changed

+281
-32
lines changed

9 files changed

+281
-32
lines changed

package-lock.json

Lines changed: 204 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openscd/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@
3939
"@material/mwc-textarea": "0.22.1",
4040
"@material/mwc-textfield": "0.22.1",
4141
"@material/mwc-top-app-bar-fixed": "0.22.1",
42+
"@openscd/core": "*",
43+
"@openscd/xml": "*",
4244
"ace-custom-element": "^1.6.5",
4345
"lit": "^2.2.7",
4446
"lit-translate": "^1.2.1",
4547
"marked": "^4.0.10",
46-
"panzoom": "^9.4.2",
47-
"@openscd/core": "*",
48-
"@openscd/xml": "*"
48+
"panzoom": "^9.4.2"
4949
},
5050
"scripts": {
5151
"clean": "rimraf build",
@@ -85,6 +85,7 @@
8585
"@typescript-eslint/parser": "^4.29.2",
8686
"@web/dev-server-esbuild": "^0.2.16",
8787
"@web/test-runner": "^0.13.22",
88+
"@web/test-runner-playwright": "^0.11.0",
8889
"concurrently": "^6.2.1",
8990
"deepmerge": "^4.2.2",
9091
"es-dev-server": "^2.1.0",
@@ -171,4 +172,4 @@
171172
],
172173
"commitUrlFormat": "https://github.com/openscd/open-scd/commits/{{hash}}"
173174
}
174-
}
175+
}

packages/openscd/src/addons/Layout.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -468,18 +468,33 @@ export class OscdLayout extends LitElement {
468468

469469
/** Renders the enabled editor plugins and a tab bar to switch between them*/
470470
protected renderContent(): TemplateResult {
471+
const hasActiveDoc = Boolean(this.doc);
472+
473+
const activeEditors = this.editors
474+
.filter(editor => {
475+
// this is necessary because `requireDoc` can be undefined
476+
// and that is not the same as false
477+
const doesNotRequireDoc = editor.requireDoc === false
478+
return doesNotRequireDoc || hasActiveDoc
479+
})
480+
.map(this.renderEditorTab)
471481

472-
if(!this.doc) return html``;
482+
const hasActiveEditors = activeEditors.length > 0;
483+
if(!hasActiveEditors){ return html``; }
473484

474485
return html`
475486
<mwc-tab-bar @MDCTabBar:activated=${(e: CustomEvent) => (this.activeTab = e.detail.index)}>
476-
${this.editors.map(this.renderEditorTab)}
487+
${activeEditors}
477488
</mwc-tab-bar>
478-
${renderEditorContent(this.editors, this.activeTab)}
489+
${renderEditorContent(this.editors, this.activeTab, this.doc)}
479490
`;
480491

481-
function renderEditorContent(editors: Plugin[], activeTab: number){
482-
const content = editors[activeTab]?.content;
492+
function renderEditorContent(editors: Plugin[], activeTab: number, doc: XMLDocument | null){
493+
const editor = editors[activeTab];
494+
const requireDoc = editor?.requireDoc
495+
if(requireDoc && !doc) { return html`` }
496+
497+
const content = editor?.content;
483498
if(!content) { return html`` }
484499

485500
return html`${content}`;
@@ -633,6 +648,14 @@ export class OscdLayout extends LitElement {
633648
class="${plugin.official ? 'official' : 'external'}"
634649
value="${plugin.src}"
635650
?selected=${plugin.installed}
651+
@request-selected=${(e: CustomEvent<{source: string}>) => {
652+
if(e.detail.source !== 'interaction'){
653+
e.preventDefault();
654+
e.stopPropagation();
655+
e.stopImmediatePropagation();
656+
return false;
657+
}
658+
}}
636659
hasMeta
637660
left
638661
>

packages/openscd/src/open-scd.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,12 @@ export class OpenSCD extends LitElement {
488488

489489
private addContent(plugin: Omit<Plugin, 'content'>): Plugin {
490490
const tag = pluginTag(plugin.src);
491+
491492
if (!loadedPlugins.has(tag)) {
492493
loadedPlugins.add(tag);
493494
import(plugin.src).then(mod => customElements.define(tag, mod.default));
494495
}
496+
495497
return {
496498
...plugin,
497499
content: staticTagHtml`<${tag}

0 commit comments

Comments
 (0)