From d0dd89ed44cdf5fd5d5ade677c572ea94a59aba7 Mon Sep 17 00:00:00 2001 From: Ben Date: Sun, 18 May 2025 14:53:00 +0300 Subject: [PATCH 1/2] feat: add documents URL support --- web/src/__tests__/shared.test.ts | 15 ++++++++++++--- web/src/shared.ts | 6 +++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/web/src/__tests__/shared.test.ts b/web/src/__tests__/shared.test.ts index 6db7e73..dc5df7e 100644 --- a/web/src/__tests__/shared.test.ts +++ b/web/src/__tests__/shared.test.ts @@ -12,22 +12,31 @@ describe('getSimplePDFElements', () => { PDF link Regular link with class - SimplePDF form link + SimplePDF form link + SimplePDF document link PDF link with class exclusion SimplePDF form link with exclusion Regular link containing .pdf Should not be opened with SimplePDF Should not be opened with SimplePDF + Should not be opened with SimplePDF + Should not be opened with SimplePDF `, { url: 'http://localhost' }, ); const detectedElements = getSimplePDFElements(dom.window.document); - expect(detectedElements).toHaveLength(4); + expect(detectedElements).toHaveLength(5); expect(detectedElements.map(({ innerHTML }) => innerHTML)).toStrictEqual( - expect.arrayContaining(['Button with class', 'PDF link', 'Regular link with class', 'SimplePDF form link']), + expect.arrayContaining([ + 'Button with class', + 'PDF link', + 'Regular link with class', + 'SimplePDF form link', + 'SimplePDF document link', + ]), ); }); }); diff --git a/web/src/shared.ts b/web/src/shared.ts index a97d089..a35b005 100644 --- a/web/src/shared.ts +++ b/web/src/shared.ts @@ -32,8 +32,8 @@ const editorContext: EditorContext = { }, }; -const isFormLink = (url: string) => { - const regex = /^https:\/\/[^.]+\.simplepdf\.com\/[^\/]+\/form\/.+/; +const isSimplePDFLink = (url: string) => { + const regex = /^https:\/\/[^.]+\.simplepdf\.com(\/[^\/]+)?\/(form|documents)\/.+/; return regex.test(url); }; @@ -122,7 +122,7 @@ export const getSimplePDFElements = (document: Document): Element[] => { return false; } - return isPDFLink(anchor.href) || anchor.classList.contains('simplepdf') || isFormLink(anchor.href); + return isPDFLink(anchor.href) || anchor.classList.contains('simplepdf') || isSimplePDFLink(anchor.href); }); return anchorsWithPDF; From ffc85c1635360abd03e482c6b6ce1a9aee13c531 Mon Sep 17 00:00:00 2001 From: Ben Date: Sun, 18 May 2025 14:54:21 +0300 Subject: [PATCH 2/2] chore: publish @simplepdf/web-embed-pdf@1.8.4 --- web/package-lock.json | 4 ++-- web/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/web/package-lock.json b/web/package-lock.json index 3ba9aa5..31f21dd 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -1,12 +1,12 @@ { "name": "@simplepdf/web-embed-pdf", - "version": "1.8.3", + "version": "1.8.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@simplepdf/web-embed-pdf", - "version": "1.8.3", + "version": "1.8.4", "license": "MIT", "devDependencies": { "@rollup/plugin-terser": "^0.4.4", diff --git a/web/package.json b/web/package.json index 1a41324..3a83ecd 100644 --- a/web/package.json +++ b/web/package.json @@ -1,6 +1,6 @@ { "name": "@simplepdf/web-embed-pdf", - "version": "1.8.3", + "version": "1.8.4", "description": "SimplePDF straight into your website", "repository": { "type": "git",