From 754c3019a71b8c23a4fc166bfa557d6405d892e2 Mon Sep 17 00:00:00 2001 From: Pascal Wilbrink Date: Mon, 27 Nov 2023 12:17:10 +0100 Subject: [PATCH] Chore: Added additional properties (#1369) * Chore: Added docs and locale properties to OpenSCD shell class * Removed dist classes * test: Fixed test * Removed dist folder --------- Co-authored-by: Juan Munoz --- packages/open-scd/src/Plugging.ts | 18 +++++++++++++++++- packages/open-scd/test/unit/Plugging.test.ts | 12 +++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/packages/open-scd/src/Plugging.ts b/packages/open-scd/src/Plugging.ts index 781da6cac..6e86d0fa9 100644 --- a/packages/open-scd/src/Plugging.ts +++ b/packages/open-scd/src/Plugging.ts @@ -99,7 +99,7 @@ function staticTagHtml( type PluginKind = 'editor' | 'menu' | 'validator'; const menuPosition = ['top', 'middle', 'bottom'] as const; -type MenuPosition = typeof menuPosition[number]; +type MenuPosition = (typeof menuPosition)[number]; export type Plugin = { name: string; @@ -239,6 +239,20 @@ export function Plugging< @query('#pluginAdd') pluginDownloadUI!: Dialog; + protected get locale(): string { + return navigator.language || 'en-US'; + } + + get docs(): Record { + const docs: Record = {}; + + if (this.doc) { + docs[this.docName] = this.doc; + } + + return docs; + } + private setPlugins(indices: Set) { const newPlugins = this.plugins.map((plugin, index) => { return { ...plugin, installed: indices.has(index) }; @@ -293,6 +307,8 @@ export function Plugging< .docId=${this.docId} .pluginId=${plugin.src} .nsdoc=${this.nsdoc} + .docs=${this.docs} + .locale=${this.locale} class="${classMap({ plugin: true, menu: plugin.kind === 'menu', diff --git a/packages/open-scd/test/unit/Plugging.test.ts b/packages/open-scd/test/unit/Plugging.test.ts index cbd9b6dfe..943392166 100644 --- a/packages/open-scd/test/unit/Plugging.test.ts +++ b/packages/open-scd/test/unit/Plugging.test.ts @@ -8,6 +8,7 @@ import { TextField } from '@material/mwc-textfield'; describe('PluggingElement', () => { let element: MockPlugger; let doc: XMLDocument; + const docName: string = 'testDoc'; afterEach(async () => { await new Promise(resolve => setTimeout(resolve, 50)); // await animation @@ -19,7 +20,7 @@ describe('PluggingElement', () => { .then(str => new DOMParser().parseFromString(str, 'application/xml')); element = ( await fixture( - html`` + html`` ) ); await element.updateComplete; @@ -28,6 +29,15 @@ describe('PluggingElement', () => { it('stores default plugins on load', () => expect(element).property('editors').to.have.lengthOf(6)); + it('has Locale property', async () => { + expect(element).to.have.property('locale'); + }); + + it('has docs property', () => { + expect(element).to.have.property(`docs`).that.is.a('Object'); + expect(element.docs[docName]).to.equal(doc); + }); + describe('plugin manager dialog', () => { let firstEditorPlugin: HTMLElement; let resetAction: HTMLElement;