From 689d0046ade833e262dd8bdbecf7596566ad0afb Mon Sep 17 00:00:00 2001 From: Sergio Alvarenga Date: Fri, 15 Nov 2024 15:18:47 +0100 Subject: [PATCH 1/6] fix error: TypeError: event.target.closest(...) is null --- packages/plugins/src/menu/Help.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/plugins/src/menu/Help.ts b/packages/plugins/src/menu/Help.ts index e5b9ef26aa..2e2705eb9b 100644 --- a/packages/plugins/src/menu/Help.ts +++ b/packages/plugins/src/menu/Help.ts @@ -43,12 +43,14 @@ async function getLinkedPages(path: string[]): Promise { } const page = path[path.length - 1].replace(/ /g, '-'); - const res = await fetch(`/public/md/${page}.md`); + const res = await fetch(`/openscd/public/md/${page}.md`); const md = await res.text(); + const MD_LINK = `$1` const unlinkedMd = md.replace( /\[([^\]]*)\]\(https:..github.com.openscd.open-scd.wiki.([^)]*)\)/g, - `$1` + MD_LINK ); + const header = html`
${page === 'Home' ? aboutBox(edition.version) : html``} ${unsafeHTML(marked.parse(unlinkedMd))} From d4376a36b0e09e5df0cd3db65b98fee9c8083a00 Mon Sep 17 00:00:00 2001 From: Sergio Alvarenga Date: Fri, 15 Nov 2024 16:38:58 +0100 Subject: [PATCH 2/6] refactoring - Help.ts: move regex into explainatory variables - finder-list.ts: remove unnecessary Fn --- packages/openscd/src/finder-list.ts | 9 ++++----- packages/plugins/src/menu/Help.ts | 15 ++++++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/openscd/src/finder-list.ts b/packages/openscd/src/finder-list.ts index f4bcfcf5c0..a98582e53b 100644 --- a/packages/openscd/src/finder-list.ts +++ b/packages/openscd/src/finder-list.ts @@ -91,9 +91,6 @@ export class FinderList extends LitElement { return path.join('/'); } - getDisplayString(entry: string, path: string[]): string { - return entry; - } @query('div') container!: Element; @@ -153,9 +150,11 @@ export class FinderList extends LitElement { html` JSON.stringify(p)) + .map(p => { + return JSON.stringify(p) + }) .includes(JSON.stringify(path.concat(entry)))} - >${this.getDisplayString(entry, path)}${entry}` )} `; diff --git a/packages/plugins/src/menu/Help.ts b/packages/plugins/src/menu/Help.ts index 2e2705eb9b..d4514a6cd9 100644 --- a/packages/plugins/src/menu/Help.ts +++ b/packages/plugins/src/menu/Help.ts @@ -9,6 +9,10 @@ import { newWizardEvent, Wizard } from '@openscd/open-scd/src/foundation.js'; import { openSCDIcon } from '@openscd/open-scd/src/icons/icons.js'; import { Directory } from '@openscd/open-scd/src/finder-list.js'; +const GITHUB_WIKI_LINK_PATTERN = /https:\/\/github\.com\/openscd\/open-scd\/wiki\/([^)]*)/g; +const MD_LINK_TITLE_PATTERN =/[^\\]]*/; +const HYPHEN_PATTERN = /-/g; + function aboutBox(version: string) { return html`
@@ -45,10 +49,10 @@ async function getLinkedPages(path: string[]): Promise { const page = path[path.length - 1].replace(/ /g, '-'); const res = await fetch(`/openscd/public/md/${page}.md`); const md = await res.text(); - const MD_LINK = `$1` + const MD_LINK_REPLACEMENT = `$1` const unlinkedMd = md.replace( - /\[([^\]]*)\]\(https:..github.com.openscd.open-scd.wiki.([^)]*)\)/g, - MD_LINK + new RegExp(`\\[(${MD_LINK_TITLE_PATTERN.source})\\]\\(${GITHUB_WIKI_LINK_PATTERN.source}\\)`, 'g'), + MD_LINK_REPLACEMENT ); const header = html`
@@ -56,8 +60,9 @@ async function getLinkedPages(path: string[]): Promise { ${unsafeHTML(marked.parse(unlinkedMd))}
`; const entries = Array.from( - md.matchAll(/\(https:..github.com.openscd.open-scd.wiki.([^)]*)\)/g) - ).map(([_, child]) => child.replace(/-/g, ' ')); + md.matchAll( new RegExp(`\\(${GITHUB_WIKI_LINK_PATTERN.source}\\)`, 'g')) + + ).map(([_, child]) => child.replace(HYPHEN_PATTERN, ' ')); return { path, header, entries }; } From 291dbf6cea249df58d55604febbea6527578faf9 Mon Sep 17 00:00:00 2001 From: Sergio Alvarenga Date: Mon, 18 Nov 2024 09:57:21 +0100 Subject: [PATCH 3/6] fix failing test Test was failing for previously removing the "getDisplayString" method --- packages/openscd/test/unit/finder-list.test.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/openscd/test/unit/finder-list.test.ts b/packages/openscd/test/unit/finder-list.test.ts index d7a62c0b35..5af6bd1718 100644 --- a/packages/openscd/test/unit/finder-list.test.ts +++ b/packages/openscd/test/unit/finder-list.test.ts @@ -30,9 +30,6 @@ function getTitle(path: Path): string { return `Testing ${path[path.length - 1]}`; } -function getDisplayString(entry: string, path: string[]) { - return 'Testing ' + path.length + ' ' + entry; -} async function read(path: Path): Promise { const dir = path[path.length - 1]; @@ -111,9 +108,8 @@ describe('finder-list', () => { .property('children') .to.have.lengthOf(pathA.length)); - describe('when provided with .getTitle and .getDisplayString methods', () => { + describe('when provided with .getTitle method', () => { beforeEach(async () => { - element.getDisplayString = getDisplayString; element.getTitle = getTitle; element.requestUpdate(); await element.updateComplete; @@ -126,7 +122,7 @@ describe('finder-list', () => { .to.satisfy((l: string) => l.startsWith('Testing ')); }); - it('overrides list-item text content using .getDisplayString', () => { + it('overrides list-item text content using', () => { expect(element.container.querySelector('mwc-list-item')) .property('text') .to.satisfy((t: string) => t.startsWith('Testing ')); From a0c86a0dd068fe46bb9592a2d0a03dd8b5d41bf8 Mon Sep 17 00:00:00 2001 From: Sergio Alvarenga Date: Mon, 18 Nov 2024 15:15:26 +0100 Subject: [PATCH 4/6] refactorings --- packages/plugins/src/menu/Help.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/plugins/src/menu/Help.ts b/packages/plugins/src/menu/Help.ts index d4514a6cd9..664b4c1ca0 100644 --- a/packages/plugins/src/menu/Help.ts +++ b/packages/plugins/src/menu/Help.ts @@ -10,7 +10,7 @@ import { openSCDIcon } from '@openscd/open-scd/src/icons/icons.js'; import { Directory } from '@openscd/open-scd/src/finder-list.js'; const GITHUB_WIKI_LINK_PATTERN = /https:\/\/github\.com\/openscd\/open-scd\/wiki\/([^)]*)/g; -const MD_LINK_TITLE_PATTERN =/[^\\]]*/; +const MD_LINK_TITLE_PATTERN ='([^\\]]*)'; const HYPHEN_PATTERN = /-/g; function aboutBox(version: string) { @@ -49,9 +49,9 @@ async function getLinkedPages(path: string[]): Promise { const page = path[path.length - 1].replace(/ /g, '-'); const res = await fetch(`/openscd/public/md/${page}.md`); const md = await res.text(); - const MD_LINK_REPLACEMENT = `$1` + const MD_LINK_REPLACEMENT = `$1` const unlinkedMd = md.replace( - new RegExp(`\\[(${MD_LINK_TITLE_PATTERN.source})\\]\\(${GITHUB_WIKI_LINK_PATTERN.source}\\)`, 'g'), + new RegExp(`\\[${MD_LINK_TITLE_PATTERN}\\]\\(${GITHUB_WIKI_LINK_PATTERN.source}\\)`, 'g'), MD_LINK_REPLACEMENT ); From 5ec582d3af8e3f2c76eeed3d51657e51f5bfa7a2 Mon Sep 17 00:00:00 2001 From: Sergio Alvarenga Date: Mon, 18 Nov 2024 15:17:34 +0100 Subject: [PATCH 5/6] reinstate deleted Fn --- packages/openscd/src/finder-list.ts | 9 +++++---- packages/openscd/test/unit/finder-list.test.ts | 8 ++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/openscd/src/finder-list.ts b/packages/openscd/src/finder-list.ts index a98582e53b..f4bcfcf5c0 100644 --- a/packages/openscd/src/finder-list.ts +++ b/packages/openscd/src/finder-list.ts @@ -91,6 +91,9 @@ export class FinderList extends LitElement { return path.join('/'); } + getDisplayString(entry: string, path: string[]): string { + return entry; + } @query('div') container!: Element; @@ -150,11 +153,9 @@ export class FinderList extends LitElement { html` { - return JSON.stringify(p) - }) + .map(p => JSON.stringify(p)) .includes(JSON.stringify(path.concat(entry)))} - >${entry}${this.getDisplayString(entry, path)}` )} `; diff --git a/packages/openscd/test/unit/finder-list.test.ts b/packages/openscd/test/unit/finder-list.test.ts index 5af6bd1718..d7a62c0b35 100644 --- a/packages/openscd/test/unit/finder-list.test.ts +++ b/packages/openscd/test/unit/finder-list.test.ts @@ -30,6 +30,9 @@ function getTitle(path: Path): string { return `Testing ${path[path.length - 1]}`; } +function getDisplayString(entry: string, path: string[]) { + return 'Testing ' + path.length + ' ' + entry; +} async function read(path: Path): Promise { const dir = path[path.length - 1]; @@ -108,8 +111,9 @@ describe('finder-list', () => { .property('children') .to.have.lengthOf(pathA.length)); - describe('when provided with .getTitle method', () => { + describe('when provided with .getTitle and .getDisplayString methods', () => { beforeEach(async () => { + element.getDisplayString = getDisplayString; element.getTitle = getTitle; element.requestUpdate(); await element.updateComplete; @@ -122,7 +126,7 @@ describe('finder-list', () => { .to.satisfy((l: string) => l.startsWith('Testing ')); }); - it('overrides list-item text content using', () => { + it('overrides list-item text content using .getDisplayString', () => { expect(element.container.querySelector('mwc-list-item')) .property('text') .to.satisfy((t: string) => t.startsWith('Testing ')); From 7684d1392a9c3ee8e42abfd35f8befed91fa2f46 Mon Sep 17 00:00:00 2001 From: Sergio Alvarenga Date: Wed, 26 Feb 2025 15:35:05 +0100 Subject: [PATCH 6/6] feat: update release please action --- .github/workflows/release-please.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index fec867a86e..3f6d7fa74c 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -12,16 +12,16 @@ jobs: release-please: runs-on: ubuntu-latest steps: - - uses: google-github-actions/release-please-action@v4 + - uses: googleapis/release-please-action@v4 id: release with: release-type: node command: manifest token: ${{ secrets.GITHUB_TOKEN }} # The logic below handles the npm publication: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 if: ${{ steps.release.outputs.releases_created }} - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v4 with: node-version: 18 registry-url: "https://registry.npmjs.org"