From ec4f685aacbccaa81f01fc60b27b01c16c40bac8 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 10 Mar 2026 11:56:22 +0000 Subject: [PATCH] :bug: Fix penpot.openPage() to navigate in same tab by default - Change the default for the newWindow param from true to false, so openPage() navigates in the same tab instead of opening a new one - Accept a UUID string as the page argument in addition to a Page object, avoiding the need to call penpot.getPage(uuid) first - Add validation error when an invalid page argument is passed Signed-off-by: Andrey Antukh --- CHANGES.md | 1 + frontend/src/app/plugins/api.cljs | 11 ++++++++--- frontend/src/app/plugins/page.cljs | 2 +- plugins/libs/plugin-types/index.d.ts | 6 +++--- plugins/libs/plugins-runtime/src/lib/api/index.ts | 4 ++-- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c5fff1ab55..5f4a379a22 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -22,6 +22,7 @@ - Fix Alt/Option to draw shapes from center point (by @offreal) [Github #8361](https://github.com/penpot/penpot/pull/8361) - Add token name on broken token pill on sidebar [Taiga #13527](https://tree.taiga.io/project/penpot/issue/13527) +- Fix `penpot.openPage()` plugin API not navigating in the same tab; change default to same-tab navigation and allow passing a UUID string instead of a Page object [Github #8520](https://github.com/penpot/penpot/issues/8520) ## 2.14.0 (Unreleased) diff --git a/frontend/src/app/plugins/api.cljs b/frontend/src/app/plugins/api.cljs index 16706eacbd..4c982db774 100644 --- a/frontend/src/app/plugins/api.cljs +++ b/frontend/src/app/plugins/api.cljs @@ -542,9 +542,14 @@ :openPage (fn [page new-window] - (let [id (obj/get page "$id") - new-window (if (boolean? new-window) new-window true)] - (st/emit! (dcm/go-to-workspace :page-id id ::rt/new-window new-window)))) + (let [id (cond + (page/page-proxy? page) (obj/get page "$id") + (string? page) (uuid/parse* page) + :else nil) + new-window (if (boolean? new-window) new-window false)] + (if (nil? id) + (u/display-not-valid :openPage "Expected a Page object or a page UUID string") + (st/emit! (dcm/go-to-workspace :page-id id ::rt/new-window new-window))))) :alignHorizontal (fn [shapes direction] diff --git a/frontend/src/app/plugins/page.cljs b/frontend/src/app/plugins/page.cljs index e6c9f95bab..b0302a1939 100644 --- a/frontend/src/app/plugins/page.cljs +++ b/frontend/src/app/plugins/page.cljs @@ -269,7 +269,7 @@ (u/display-not-valid :openPage "Plugin doesn't have 'content:read' permission") :else - (let [new-window (if (boolean? new-window) new-window true)] + (let [new-window (if (boolean? new-window) new-window false)] (st/emit! (dcm/go-to-workspace :page-id id ::rt/new-window new-window))))) :createFlow diff --git a/plugins/libs/plugin-types/index.d.ts b/plugins/libs/plugin-types/index.d.ts index 2f33f6e1c4..381de47fc7 100644 --- a/plugins/libs/plugin-types/index.d.ts +++ b/plugins/libs/plugin-types/index.d.ts @@ -1256,15 +1256,15 @@ export interface Context { /** * Changes the current open page to given page. Requires `content:read` permission. - * @param page the page to open - * @param newWindow if true opens the page in a new window + * @param page the page to open (a Page object or a page UUID string) + * @param newWindow if true opens the page in a new window, defaults to false * * @example * ```js * context.openPage(page); * ``` */ - openPage(page: Page, newWindow?: boolean): void; + openPage(page: Page | string, newWindow?: boolean): void; /** * Aligning will move all the selected layers to a position relative to one diff --git a/plugins/libs/plugins-runtime/src/lib/api/index.ts b/plugins/libs/plugins-runtime/src/lib/api/index.ts index 01dd9008de..c31298e1d8 100644 --- a/plugins/libs/plugins-runtime/src/lib/api/index.ts +++ b/plugins/libs/plugins-runtime/src/lib/api/index.ts @@ -323,9 +323,9 @@ export function createApi( return plugin.context.createPage(); }, - openPage(page: Page, newWindow?: boolean): void { + openPage(page: Page | string, newWindow?: boolean): void { checkPermission('content:read'); - plugin.context.openPage(page, newWindow ?? true); + plugin.context.openPage(page, newWindow ?? false); }, alignHorizontal(