From 1e50fd935512172d97d923b62e25bd064d850ca0 Mon Sep 17 00:00:00 2001 From: Sergio Alvarenga <71974638+salvar3nga@users.noreply.github.com> Date: Tue, 18 Feb 2025 17:16:22 +0100 Subject: [PATCH 1/2] chore: update release please version to 0.37.2 (#1627) * chore: release 0.37.2 Release-As: 0.37.2 --------- Co-authored-by: Sergio Alvarenga From 00c4dc06f6d0cf1c39e4822a5b21d650d698785e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Russ?= Date: Wed, 19 Feb 2025 10:07:49 +0100 Subject: [PATCH 2/2] Fix: inconsistent plugin activation behaviour caused by refactoring (#1626) --- package-lock.json | 115 - packages/core/foundation/plugin.ts | 24 +- packages/openscd/package.json | 1 + packages/openscd/src/addons/Layout.ts | 352 +-- .../plugin-manager/custom-plugin-dialog.ts | 207 ++ .../addons/plugin-manager/plugin-manager.ts | 186 ++ packages/openscd/src/open-scd.ts | 105 +- packages/openscd/src/plugin.ts | 24 +- packages/openscd/src/plugins.ts | 73 +- .../__snapshots__/open-scd.test.snap.js | 2684 +++++------------ packages/openscd/test/unit/Plugging.test.ts | 617 ++-- .../editors/__snapshots__/IED.test.snap.js | 1 - 12 files changed, 1664 insertions(+), 2725 deletions(-) create mode 100644 packages/openscd/src/addons/plugin-manager/custom-plugin-dialog.ts create mode 100644 packages/openscd/src/addons/plugin-manager/plugin-manager.ts diff --git a/package-lock.json b/package-lock.json index af9e7b65be..abba14296e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2604,12 +2604,6 @@ "node": ">=6.9.0" } }, - "node_modules/@import-maps/resolve": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@import-maps/resolve/-/resolve-1.0.1.tgz", - "integrity": "sha512-tWZNBIS1CoekcwlMuyG2mr0a1Wo5lb5lEHwwWvZo+5GLgr3e9LLDTtmgtCWEwBpXMkxn9D+2W9j2FY6eZQq0tA==", - "dev": true - }, "node_modules/@isaacs/cliui": { "version": "8.0.2", "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", @@ -8731,114 +8725,6 @@ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", "dev": true }, - "node_modules/@web/dev-server-import-maps": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/@web/dev-server-import-maps/-/dev-server-import-maps-0.2.1.tgz", - "integrity": "sha512-iGM7s4qenmTDUWC2iV0HoQ1NR5lAyRxVHOpWzTsFH/TnUZzP+YuL6QIFtB2v2v7URfhGL2l2WPIibmliToITcg==", - "dev": true, - "dependencies": { - "@import-maps/resolve": "^1.0.1", - "@types/parse5": "^6.0.1", - "@web/dev-server-core": "^0.7.2", - "@web/parse5-utils": "^2.1.0", - "parse5": "^6.0.1", - "picomatch": "^2.2.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@web/dev-server-import-maps/node_modules/@web/dev-server-core": { - "version": "0.7.5", - "resolved": "https://registry.npmjs.org/@web/dev-server-core/-/dev-server-core-0.7.5.tgz", - "integrity": "sha512-Da65zsiN6iZPMRuj4Oa6YPwvsmZmo5gtPWhW2lx3GTUf5CAEapjVpZVlUXnKPL7M7zRuk72jSsIl8lo+XpTCtw==", - "dev": true, - "dependencies": { - "@types/koa": "^2.11.6", - "@types/ws": "^7.4.0", - "@web/parse5-utils": "^2.1.0", - "chokidar": "^4.0.1", - "clone": "^2.1.2", - "es-module-lexer": "^1.0.0", - "get-stream": "^6.0.0", - "is-stream": "^2.0.0", - "isbinaryfile": "^5.0.0", - "koa": "^2.13.0", - "koa-etag": "^4.0.0", - "koa-send": "^5.0.1", - "koa-static": "^5.0.0", - "lru-cache": "^8.0.4", - "mime-types": "^2.1.27", - "parse5": "^6.0.1", - "picomatch": "^2.2.2", - "ws": "^7.5.10" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@web/dev-server-import-maps/node_modules/@web/parse5-utils": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/@web/parse5-utils/-/parse5-utils-2.1.0.tgz", - "integrity": "sha512-GzfK5disEJ6wEjoPwx8AVNwUe9gYIiwc+x//QYxYDAFKUp4Xb1OJAGLc2l2gVrSQmtPGLKrTRcW90Hv4pEq1qA==", - "dev": true, - "dependencies": { - "@types/parse5": "^6.0.1", - "parse5": "^6.0.1" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@web/dev-server-import-maps/node_modules/chokidar": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-4.0.3.tgz", - "integrity": "sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA==", - "dev": true, - "dependencies": { - "readdirp": "^4.0.1" - }, - "engines": { - "node": ">= 14.16.0" - }, - "funding": { - "url": "https://paulmillr.com/funding/" - } - }, - "node_modules/@web/dev-server-import-maps/node_modules/es-module-lexer": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.6.0.tgz", - "integrity": "sha512-qqnD1yMU6tk/jnaMosogGySTZP8YtUgAffA9nMN+E/rjxcfRQ6IEk7IiozUjgxKoFHBGjTLnrHB/YC45r/59EQ==", - "dev": true - }, - "node_modules/@web/dev-server-import-maps/node_modules/lru-cache": { - "version": "8.0.5", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-8.0.5.tgz", - "integrity": "sha512-MhWWlVnuab1RG5/zMRRcVGXZLCXrZTgfwMikgzCegsPnG62yDQo5JnqKkrK4jO5iKqDAZGItAqN5CtKBCBWRUA==", - "dev": true, - "engines": { - "node": ">=16.14" - } - }, - "node_modules/@web/dev-server-import-maps/node_modules/parse5": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/parse5/-/parse5-6.0.1.tgz", - "integrity": "sha512-Ofn/CTFzRGTTxwpNEs9PP93gXShHcTq255nzRYSKe8AkVpZY7e1fpmTfOyoIvjP5HG7Z2ZM7VS9PPhQGW2pOpw==", - "dev": true - }, - "node_modules/@web/dev-server-import-maps/node_modules/readdirp": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.1.1.tgz", - "integrity": "sha512-h80JrZu/MHUZCyHu5ciuoI0+WxsCxzxJTILn6Fs8rxSnFPh+UVHYfeIxK1nVGugMqkfC4vJcBOYbkfkwYK0+gw==", - "dev": true, - "engines": { - "node": ">= 14.18.0" - }, - "funding": { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - }, "node_modules/@web/dev-server-rollup": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/@web/dev-server-rollup/-/dev-server-rollup-0.4.1.tgz", @@ -31694,7 +31580,6 @@ "@typescript-eslint/eslint-plugin": "^4.29.2", "@typescript-eslint/parser": "^4.29.2", "@web/dev-server-esbuild": "^0.2.16", - "@web/dev-server-import-maps": "^0.2.1", "@web/test-runner": "^0.13.22", "@web/test-runner-playwright": "^0.11.0", "concurrently": "^6.2.1", diff --git a/packages/core/foundation/plugin.ts b/packages/core/foundation/plugin.ts index 300bb19adc..712c666912 100644 --- a/packages/core/foundation/plugin.ts +++ b/packages/core/foundation/plugin.ts @@ -1,12 +1,28 @@ import { targetLocales } from '../locales.js'; export type Plugin = { + // name defines the name of the plugin name: string; - translations?: Record<(typeof targetLocales)[number], string>; + // src defines the path to the plugins source file src: string; - icon: string; - requireDoc?: boolean; + // kind defines the type of the plugin + kind: PluginKind; + // activeByDefault configures if the plugin should be active by default + // this is will be user when users resets the plugins + activeByDefault: boolean; + // icon stores the icon name of the Material Icon + icon?: string; + // active shows if the plugin currently is active active?: boolean; - position: ('top' | 'middle' | 'bottom') | number; + // requireDoc shows if the plugin requires a document to be loaded + requireDoc?: boolean; + // position defines the position of menu plugins + position?: MenuPosition + translations?: Record<(typeof targetLocales)[number], string>; }; + export type PluginSet = { menu: Plugin[]; editor: Plugin[] }; +export type PluginKind = 'editor' | 'menu' | 'validator'; +export const menuPosition = ['top', 'middle', 'bottom'] as const; +export type MenuPosition = (typeof menuPosition)[number]; + diff --git a/packages/openscd/package.json b/packages/openscd/package.json index 2c57aedc35..4b64689d4a 100644 --- a/packages/openscd/package.json +++ b/packages/openscd/package.json @@ -60,6 +60,7 @@ "test:manual": "web-test-runner --manual", "test:watch": "web-test-runner --watch", "test:unit": "web-test-runner --watch --group unit", + "test:unit:headless": "web-test-runner --watch --group unit --concurrency 1 --headless", "test:integration": "web-test-runner --watch --group integration", "doc:clean": "npx rimraf doc", "doc:typedoc": "typedoc --plugin none --out doc --entryPointStrategy expand ./src", diff --git a/packages/openscd/src/addons/Layout.ts b/packages/openscd/src/addons/Layout.ts index 68055f25f7..78c0cce4b3 100644 --- a/packages/openscd/src/addons/Layout.ts +++ b/packages/openscd/src/addons/Layout.ts @@ -54,10 +54,41 @@ import '@material/mwc-select'; import '@material/mwc-textfield'; import { nothing } from 'lit'; +import {OscdPluginManager} from "./plugin-manager/plugin-manager.js"; +import "./plugin-manager/plugin-manager.js"; +import {OscdCustomPluginDialog} from "./plugin-manager/custom-plugin-dialog.js"; +import "./plugin-manager/custom-plugin-dialog.js"; + @customElement('oscd-layout') export class OscdLayout extends LitElement { + /** The `XMLDocument` to be edited */ + @property({ attribute: false }) doc: XMLDocument | null = null; + /** The name of the current [[`doc`]] */ + @property({ type: String }) docName = ''; + /** Index of the last [[`EditorAction`]] applied. */ + @property({ type: Number }) editCount = -1; + /** The currently active editor tab. */ + @property({ type: Number }) activeTab = 0; + + /** The plugins to render the layout. */ + @property({ type: Array }) plugins: Plugin[] = []; + + /** The open-scd host element */ + @property({ type: Object }) host!: HTMLElement; + + @property({ type: Object }) historyState!: HistoryState; + + @state() validated: Promise = Promise.resolve(); + @state() shouldValidate = false; + + @query('#menu') menuUI!: Drawer; + @query('#pluginManager') pluginUI!: OscdPluginManager; + @query('#pluginList') pluginList!: List; + @query('#pluginAdd') pluginDownloadUI!: OscdCustomPluginDialog; + + render(): TemplateResult { return html`
= Promise.resolve(); + private renderPlugging(): TemplateResult { + return html` ${this.renderPluginUI()} ${this.renderDownloadUI()} `; + } - @state() - shouldValidate = false; + /** Renders the "Add Custom Plug-in" UI*/ + protected renderDownloadUI(): TemplateResult { + return html` + + ` + } - @query('#menu') - menuUI!: Drawer; - @query('#pluginManager') - pluginUI!: Dialog; - @query('#pluginList') - pluginList!: List; - @query('#pluginAdd') - pluginDownloadUI!: Dialog; + /** + * Renders the plug-in management UI (turning plug-ins on/off) + */ + protected renderPluginUI(): TemplateResult { + return html` + + ` + } // Computed properties get validators(): Plugin[] { return this.plugins.filter( - plugin => plugin.installed && plugin.kind === 'validator' + plugin => plugin.active && plugin.kind === 'validator' ); } get menuEntries(): Plugin[] { return this.plugins.filter( - plugin => plugin.installed && plugin.kind === 'menu' + plugin => plugin.active && plugin.kind === 'menu' ); } get topMenu(): Plugin[] { @@ -226,7 +238,7 @@ export class OscdLayout extends LitElement { get editors(): Plugin[] { return this.plugins.filter( - plugin => plugin.installed && plugin.kind === 'editor' + plugin => plugin.active && plugin.kind === 'editor' ); } @@ -250,50 +262,6 @@ export class OscdLayout extends LitElement { fn(); } - private handleAddPlugin() { - const pluginSrcInput = ( - this.pluginDownloadUI.querySelector('#pluginSrcInput') - ); - const pluginNameInput = ( - this.pluginDownloadUI.querySelector('#pluginNameInput') - ); - const pluginKindList = ( - this.pluginDownloadUI.querySelector('#pluginKindList') - ); - const requireDoc = ( - this.pluginDownloadUI.querySelector('#requireDoc') - ); - const positionList =