🐛 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
parent ebd17974a6
commit 33c5f82c43
5 changed files with 15 additions and 9 deletions

View File

@@ -41,6 +41,7 @@
- Fix crash in select component when options vector is empty [Github #8578](https://github.com/penpot/penpot/pull/8578)
- Fix scroll on colorpicker [Taiga #13623](https://tree.taiga.io/project/penpot/issue/13623)
- Fix crash when pasting non-map transit clipboard data [Github #8580](https://github.com/penpot/penpot/pull/8580)
- 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.13.3

View File

@@ -540,9 +540,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

@@ -336,9 +336,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(