🐛 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 <niwi@niwi.nz>
This commit is contained in:
Andrey Antukh
2026-03-10 11:56:22 +00:00
committed by Alonso Torres
parent 37cf099126
commit ec4f685aac
5 changed files with 15 additions and 9 deletions

View File

@@ -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)

View File

@@ -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]

View File

@@ -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

View File

@@ -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

View File

@@ -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(