mirror of
https://github.com/penpot/penpot.git
synced 2025-01-24 15:39:50 -05:00
✨ Add infor for users
This commit is contained in:
parent
98c550b20e
commit
3e2ccbc85f
5 changed files with 105 additions and 14 deletions
|
@ -2016,16 +2016,18 @@
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(defn change-canvas-color
|
(defn change-canvas-color
|
||||||
[color]
|
([color]
|
||||||
(ptk/reify ::change-canvas-color
|
(change-canvas-color nil color))
|
||||||
ptk/WatchEvent
|
([page-id color]
|
||||||
(watch [it state _]
|
(ptk/reify ::change-canvas-color
|
||||||
(let [page (wsh/lookup-page state)
|
ptk/WatchEvent
|
||||||
changes (-> (pcb/empty-changes it)
|
(watch [it state _]
|
||||||
(pcb/with-page page)
|
(let [page-id (or page-id (:current-page-id state))
|
||||||
(pcb/set-page-option :background (:color color)))]
|
page (wsh/lookup-page state page-id)
|
||||||
|
changes (-> (pcb/empty-changes it)
|
||||||
(rx/of (dch/commit-changes changes))))))
|
(pcb/with-page page)
|
||||||
|
(pcb/set-page-option :background (:color color)))]
|
||||||
|
(rx/of (dch/commit-changes changes)))))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Read only
|
;; Read only
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
[app.plugins.library :as library]
|
[app.plugins.library :as library]
|
||||||
[app.plugins.page :as page]
|
[app.plugins.page :as page]
|
||||||
[app.plugins.shape :as shape]
|
[app.plugins.shape :as shape]
|
||||||
|
[app.plugins.user :as user]
|
||||||
[app.plugins.utils :as utils]
|
[app.plugins.utils :as utils]
|
||||||
[app.plugins.viewport :as viewport]
|
[app.plugins.viewport :as viewport]
|
||||||
[app.util.object :as obj]
|
[app.util.object :as obj]
|
||||||
|
@ -92,6 +93,18 @@
|
||||||
"dark"
|
"dark"
|
||||||
(get-in @st/state [:profile :theme]))))
|
(get-in @st/state [:profile :theme]))))
|
||||||
|
|
||||||
|
(getCurrentUser
|
||||||
|
[_]
|
||||||
|
(user/current-user-proxy (:session-id @st/state)))
|
||||||
|
|
||||||
|
(getActiveUsers
|
||||||
|
[_]
|
||||||
|
(apply array
|
||||||
|
(->> (:workspace-presence @st/state)
|
||||||
|
(vals)
|
||||||
|
(remove #(= (:id %) (:session-id @st/state)))
|
||||||
|
(map #(user/active-user-proxy (:id %))))))
|
||||||
|
|
||||||
(uploadMediaUrl
|
(uploadMediaUrl
|
||||||
[_ name url]
|
[_ name url]
|
||||||
(let [file-id (:current-file-id @st/state)]
|
(let [file-id (:current-file-id @st/state)]
|
||||||
|
@ -190,4 +203,6 @@
|
||||||
{:name "currentPage" :get #(.getPage ^js %)}
|
{:name "currentPage" :get #(.getPage ^js %)}
|
||||||
{:name "selection" :get #(.getSelectedShapes ^js %)}
|
{:name "selection" :get #(.getSelectedShapes ^js %)}
|
||||||
{:name "viewport" :get #(.getViewport ^js %)}
|
{:name "viewport" :get #(.getViewport ^js %)}
|
||||||
|
{:name "currentUser" :get #(.getCurrentUser ^js %)}
|
||||||
|
{:name "activeUsers" :get #(.getActiveUsers ^js %)}
|
||||||
{:name "library" :get (fn [_] (library/library-subcontext))}))
|
{:name "library" :get (fn [_] (library/library-subcontext))}))
|
||||||
|
|
|
@ -7,11 +7,14 @@
|
||||||
(ns app.plugins.page
|
(ns app.plugins.page
|
||||||
"RPC for plugins runtime."
|
"RPC for plugins runtime."
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.colors :as cc]
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.record :as crc]
|
[app.common.record :as crc]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
|
[app.main.data.workspace :as dw]
|
||||||
|
[app.main.store :as st]
|
||||||
[app.plugins.shape :as shape]
|
[app.plugins.shape :as shape]
|
||||||
[app.plugins.utils :refer [locate-page proxy->page]]
|
[app.plugins.utils :as u]
|
||||||
[app.util.object :as obj]))
|
[app.util.object :as obj]))
|
||||||
|
|
||||||
(deftype PageProxy [$file $id]
|
(deftype PageProxy [$file $id]
|
||||||
|
@ -29,7 +32,7 @@
|
||||||
[_]
|
[_]
|
||||||
;; Returns a lazy (iterable) of all available shapes
|
;; Returns a lazy (iterable) of all available shapes
|
||||||
(when (and (some? $file) (some? $id))
|
(when (and (some? $file) (some? $id))
|
||||||
(let [page (locate-page $file $id)]
|
(let [page (u/locate-page $file $id)]
|
||||||
(apply array (sequence (map shape/shape-proxy) (keys (:objects page))))))))
|
(apply array (sequence (map shape/shape-proxy) (keys (:objects page))))))))
|
||||||
|
|
||||||
(crc/define-properties!
|
(crc/define-properties!
|
||||||
|
@ -48,8 +51,22 @@
|
||||||
:get #(dm/str (obj/get % "$id"))}
|
:get #(dm/str (obj/get % "$id"))}
|
||||||
|
|
||||||
{:name "name"
|
{:name "name"
|
||||||
:get #(-> % proxy->page :name)}
|
:get #(-> % u/proxy->page :name)
|
||||||
|
:set
|
||||||
|
(fn [_ value]
|
||||||
|
(if (string? value)
|
||||||
|
(st/emit! (dw/rename-page id value))
|
||||||
|
(u/display-not-valid :page-name value)))}
|
||||||
|
|
||||||
{:name "root"
|
{:name "root"
|
||||||
:enumerable false
|
:enumerable false
|
||||||
:get #(.getRoot ^js %)}))
|
:get #(.getRoot ^js %)}
|
||||||
|
|
||||||
|
{:name "background"
|
||||||
|
:enumerable false
|
||||||
|
:get #(or (-> % u/proxy->page :options :background) cc/canvas)
|
||||||
|
:set
|
||||||
|
(fn [_ value]
|
||||||
|
(if (and (some? value) (string? value) (cc/valid-hex-color? value))
|
||||||
|
(st/emit! (dw/change-canvas-color id {:color value}))
|
||||||
|
(u/display-not-valid :page-background-color value)))}))
|
||||||
|
|
48
frontend/src/app/plugins/user.cljs
Normal file
48
frontend/src/app/plugins/user.cljs
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) KALEIDOS INC
|
||||||
|
|
||||||
|
(ns app.plugins.user
|
||||||
|
(:require
|
||||||
|
[app.common.record :as crc]
|
||||||
|
[app.config :as cfg]
|
||||||
|
[app.plugins.utils :as u]
|
||||||
|
[app.util.object :as obj]))
|
||||||
|
|
||||||
|
(deftype CurrentUserProxy [$session])
|
||||||
|
(deftype ActiveUserProxy [$session])
|
||||||
|
|
||||||
|
(defn add-user-properties
|
||||||
|
[user-proxy]
|
||||||
|
(let [session-id (obj/get user-proxy "$session")]
|
||||||
|
(crc/add-properties!
|
||||||
|
user-proxy
|
||||||
|
{:name "id"
|
||||||
|
:get (fn [_] (-> (u/locate-profile session-id) :id str))}
|
||||||
|
|
||||||
|
{:name "name"
|
||||||
|
:get (fn [_] (-> (u/locate-profile session-id) :fullname))}
|
||||||
|
|
||||||
|
{:name "avatarUrl"
|
||||||
|
:get (fn [_] (cfg/resolve-profile-photo-url (u/locate-profile session-id)))}
|
||||||
|
|
||||||
|
{:name "color"
|
||||||
|
:get (fn [_] (-> (u/locate-presence session-id) :color))}
|
||||||
|
|
||||||
|
{:name "sessionId"
|
||||||
|
:get (fn [_] (str session-id))})))
|
||||||
|
|
||||||
|
(defn current-user-proxy
|
||||||
|
[session-id]
|
||||||
|
(-> (CurrentUserProxy. session-id)
|
||||||
|
(add-user-properties)))
|
||||||
|
|
||||||
|
(defn active-user-proxy
|
||||||
|
[session-id]
|
||||||
|
(-> (ActiveUserProxy. session-id)
|
||||||
|
(add-user-properties)
|
||||||
|
(crc/add-properties!
|
||||||
|
{:name "position" :get (fn [_] (-> (u/locate-presence session-id) :point u/to-js))}
|
||||||
|
{:name "zoom" :get (fn [_] (-> (u/locate-presence session-id) :zoom))})))
|
|
@ -53,6 +53,15 @@
|
||||||
(assert (uuid? id) "Component not valid uuid")
|
(assert (uuid? id) "Component not valid uuid")
|
||||||
(dm/get-in (locate-file file-id) [:data :components id]))
|
(dm/get-in (locate-file file-id) [:data :components id]))
|
||||||
|
|
||||||
|
(defn locate-presence
|
||||||
|
[session-id]
|
||||||
|
(dm/get-in @st/state [:workspace-presence session-id]))
|
||||||
|
|
||||||
|
(defn locate-profile
|
||||||
|
[session-id]
|
||||||
|
(let [{:keys [profile-id]} (locate-presence session-id)]
|
||||||
|
(dm/get-in @st/state [:users profile-id])))
|
||||||
|
|
||||||
(defn proxy->file
|
(defn proxy->file
|
||||||
[proxy]
|
[proxy]
|
||||||
(let [id (obj/get proxy "$id")]
|
(let [id (obj/get proxy "$id")]
|
||||||
|
|
Loading…
Add table
Reference in a new issue