diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index cae373da41..fd898824d1 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -479,8 +479,8 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defn create-page - [{:keys [file-id]}] - (let [id (uuid/next)] + [{:keys [page-id file-id]}] + (let [id (or page-id (uuid/next))] (ptk/reify ::create-page ev/Event (-data [_] diff --git a/frontend/src/app/plugins/api.cljs b/frontend/src/app/plugins/api.cljs index 9a944c48c2..27c149d8df 100644 --- a/frontend/src/app/plugins/api.cljs +++ b/frontend/src/app/plugins/api.cljs @@ -19,6 +19,7 @@ [app.common.types.shape :as cts] [app.common.uuid :as uuid] [app.main.data.changes :as ch] + [app.main.data.workspace :as dw] [app.main.data.workspace.bool :as dwb] [app.main.data.workspace.colors :as dwc] [app.main.data.workspace.groups :as dwg] @@ -347,7 +348,26 @@ (mapcat #(cfh/get-children-with-self objects (:id %)))) shapes)] (cg/generate-style-code - objects type shapes shapes-with-children {:with-prelude? prelude?})))))) + objects type shapes shapes-with-children {:with-prelude? prelude?}))))) + + (openViewer + [_] + (let [params {:page-id (:current-page-id @st/state) + :file-id (:current-file-id @st/state) + :section "interactions"}] + (st/emit! (dw/go-to-viewer params)))) + + (createPage + [_] + (let [file-id (:current-file-id @st/state) + id (uuid/next)] + (st/emit! (dw/create-page {:page-id id :file-id file-id})) + (page/page-proxy $plugin file-id id))) + + (openPage + [_ page] + (let [id (obj/get page "$id")] + (st/emit! (dw/go-to-page id))))) (defn create-context [plugin-id] diff --git a/frontend/src/app/plugins/file.cljs b/frontend/src/app/plugins/file.cljs index 5cc3810a7e..1f37f88f82 100644 --- a/frontend/src/app/plugins/file.cljs +++ b/frontend/src/app/plugins/file.cljs @@ -9,6 +9,7 @@ (:require [app.common.data.macros :as dm] [app.common.record :as crc] + [app.common.uuid :as uuid] [app.main.data.workspace :as dw] [app.main.store :as st] [app.plugins.page :as page] @@ -93,7 +94,18 @@ :else (let [file (u/proxy->file self)] - (apply array (keys (dm/get-in file [:data :plugin-data (keyword "shared" namespace)]))))))) + (apply array (keys (dm/get-in file [:data :plugin-data (keyword "shared" namespace)])))))) + + (createPage + [_] + (cond + (not (r/check-permission $plugin "content:write")) + (u/display-not-valid :createPage "Plugin doesn't have 'content:write' permission") + + :else + (let [page-id (uuid/next)] + (st/emit! (dw/create-page {:page-id page-id :file-id $id})) + (page/page-proxy $plugin $id page-id))))) (crc/define-properties! FileProxy diff --git a/frontend/src/app/plugins/page.cljs b/frontend/src/app/plugins/page.cljs index 712b6293ca..0ace08589f 100644 --- a/frontend/src/app/plugins/page.cljs +++ b/frontend/src/app/plugins/page.cljs @@ -131,7 +131,16 @@ :else (let [page (u/proxy->page self)] - (apply array (keys (dm/get-in page [:options :plugin-data (keyword "shared" namespace)]))))))) + (apply array (keys (dm/get-in page [:options :plugin-data (keyword "shared" namespace)])))))) + + (openPage + [_] + (cond + (not (r/check-permission $plugin "content:read")) + (u/display-not-valid :openPage "Plugin doesn't have 'content:read' permission") + + :else + (st/emit! (dw/go-to-page $id))))) (crc/define-properties! PageProxy