Skip to content

Commit

Permalink
✨ Page functions for plugins api
Browse files Browse the repository at this point in the history
  • Loading branch information
Alotor committed Jul 22, 2024
1 parent d13b9ef commit 6454e87
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
4 changes: 2 additions & 2 deletions frontend/src/app/main/data/workspace.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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 [_]
Expand Down
22 changes: 21 additions & 1 deletion frontend/src/app/plugins/api.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
14 changes: 13 additions & 1 deletion frontend/src/app/plugins/file.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion frontend/src/app/plugins/page.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6454e87

Please sign in to comment.