mirror of
https://github.com/penpot/penpot.git
synced 2025-08-03 15:08:33 +02:00
✨ Add usability improvements to schema validation subsystem
This commit is contained in:
parent
83c6354a0a
commit
37e4939af7
40 changed files with 759 additions and 511 deletions
|
@ -17,38 +17,40 @@
|
|||
[beicon.core :as rx]
|
||||
[potok.core :as ptk]))
|
||||
|
||||
(def schema:comment-thread
|
||||
[:map {:title "CommentThread"}
|
||||
[:id ::sm/uuid]
|
||||
[:page-id ::sm/uuid]
|
||||
[:file-id ::sm/uuid]
|
||||
[:project-id ::sm/uuid]
|
||||
[:owner-id ::sm/uuid]
|
||||
[:page-name :string]
|
||||
[:file-name :string]
|
||||
[:seqn :int]
|
||||
[:content :string]
|
||||
[:participants ::sm/set-of-uuid]
|
||||
[:created-at ::sm/inst]
|
||||
[:modified-at ::sm/inst]
|
||||
[:position ::gpt/point]
|
||||
[:count-unread-comments {:optional true} :int]
|
||||
[:count-comments {:optional true} :int]])
|
||||
(def ^:private schema:comment-thread
|
||||
(sm/define
|
||||
[:map {:title "CommentThread"}
|
||||
[:id ::sm/uuid]
|
||||
[:page-id ::sm/uuid]
|
||||
[:file-id ::sm/uuid]
|
||||
[:project-id ::sm/uuid]
|
||||
[:owner-id ::sm/uuid]
|
||||
[:page-name :string]
|
||||
[:file-name :string]
|
||||
[:seqn :int]
|
||||
[:content :string]
|
||||
[:participants ::sm/set-of-uuid]
|
||||
[:created-at ::sm/inst]
|
||||
[:modified-at ::sm/inst]
|
||||
[:position ::gpt/point]
|
||||
[:count-unread-comments {:optional true} :int]
|
||||
[:count-comments {:optional true} :int]]))
|
||||
|
||||
(def schema:comment
|
||||
[:map {:title "CommentThread"}
|
||||
[:id ::sm/uuid]
|
||||
[:thread-id ::sm/uuid]
|
||||
[:owner-id ::sm/uuid]
|
||||
[:created-at ::sm/inst]
|
||||
[:modified-at ::sm/inst]
|
||||
[:content :string]])
|
||||
(def ^:private schema:comment
|
||||
(sm/define
|
||||
[:map {:title "Comment"}
|
||||
[:id ::sm/uuid]
|
||||
[:thread-id ::sm/uuid]
|
||||
[:owner-id ::sm/uuid]
|
||||
[:created-at ::sm/inst]
|
||||
[:modified-at ::sm/inst]
|
||||
[:content :string]]))
|
||||
|
||||
(def comment-thread?
|
||||
(sm/pred-fn schema:comment-thread))
|
||||
(def check-comment-thread!
|
||||
(sm/check-fn schema:comment-thread))
|
||||
|
||||
(def comment?
|
||||
(sm/pred-fn schema:comment))
|
||||
(def check-comment!
|
||||
(sm/check-fn schema:comment))
|
||||
|
||||
(declare create-draft-thread)
|
||||
(declare retrieve-comment-threads)
|
||||
|
@ -68,16 +70,20 @@
|
|||
(update-in [:comments id] assoc (:id comment) comment)))))
|
||||
|
||||
|
||||
(def schema:create-thread-on-workspace
|
||||
[:map
|
||||
[:page-id ::sm/uuid]
|
||||
[:file-id ::sm/uuid]
|
||||
[:position ::gpt/point]
|
||||
[:content :string]])
|
||||
(def ^:private
|
||||
schema:create-thread-on-workspace
|
||||
(sm/define
|
||||
[:map {:title "created-thread-on-workspace"}
|
||||
[:page-id ::sm/uuid]
|
||||
[:file-id ::sm/uuid]
|
||||
[:position ::gpt/point]
|
||||
[:content :string]]))
|
||||
|
||||
(defn create-thread-on-workspace
|
||||
[params]
|
||||
(dm/assert! (sm/valid? schema:create-thread-on-workspace params))
|
||||
(dm/assert!
|
||||
(sm/check! schema:create-thread-on-workspace params))
|
||||
|
||||
(ptk/reify ::create-thread-on-workspace
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
|
@ -107,17 +113,21 @@
|
|||
(update :workspace-drawing dissoc :comment)
|
||||
(update-in [:comments id] assoc (:id comment) comment)))))
|
||||
|
||||
(def schema:create-thread-on-viewer
|
||||
[:map
|
||||
[:page-id ::sm/uuid]
|
||||
[:file-id ::sm/uuid]
|
||||
[:frame-id ::sm/uuid]
|
||||
[:position ::gpt/point]
|
||||
[:content :string]])
|
||||
(def ^:private
|
||||
schema:create-thread-on-viewer
|
||||
(sm/define
|
||||
[:map {:title "created-thread-on-viewer"}
|
||||
[:page-id ::sm/uuid]
|
||||
[:file-id ::sm/uuid]
|
||||
[:frame-id ::sm/uuid]
|
||||
[:position ::gpt/point]
|
||||
[:content :string]]))
|
||||
|
||||
(defn create-thread-on-viewer
|
||||
[params]
|
||||
(dm/assert! (sm/valid? schema:create-thread-on-viewer params))
|
||||
(dm/assert!
|
||||
(sm/check! schema:create-thread-on-viewer params))
|
||||
|
||||
(ptk/reify ::create-thread-on-viewer
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
|
@ -146,7 +156,11 @@
|
|||
|
||||
(defn update-comment-thread
|
||||
[{:keys [id is-resolved] :as thread}]
|
||||
(dm/assert! (comment-thread? thread))
|
||||
|
||||
(dm/assert!
|
||||
"expected valid comment thread"
|
||||
(check-comment-thread! thread))
|
||||
|
||||
(ptk/reify ::update-comment-thread
|
||||
IDeref
|
||||
(-deref [_] {:is-resolved is-resolved})
|
||||
|
@ -168,8 +182,14 @@
|
|||
|
||||
(defn add-comment
|
||||
[thread content]
|
||||
(dm/assert! (comment-thread? thread))
|
||||
(dm/assert! (string? content))
|
||||
|
||||
(dm/assert!
|
||||
"expected valid comment thread"
|
||||
(check-comment-thread! thread))
|
||||
|
||||
(dm/assert!
|
||||
"expected valid content"
|
||||
(string? content))
|
||||
|
||||
(letfn [(created [comment state]
|
||||
(update-in state [:comments (:id thread)] assoc (:id comment) comment))]
|
||||
|
@ -189,7 +209,10 @@
|
|||
|
||||
(defn update-comment
|
||||
[{:keys [id content thread-id] :as comment}]
|
||||
(dm/assert! (comment? comment))
|
||||
(dm/assert!
|
||||
"expected valid comment"
|
||||
(check-comment! comment))
|
||||
|
||||
(ptk/reify ::update-comment
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
|
@ -204,7 +227,9 @@
|
|||
|
||||
(defn delete-comment-thread-on-workspace
|
||||
[{:keys [id] :as thread}]
|
||||
(dm/assert! (comment-thread? thread))
|
||||
(dm/assert!
|
||||
"expected valid comment thread"
|
||||
(check-comment-thread! thread))
|
||||
(ptk/reify ::delete-comment-thread-on-workspace
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
|
@ -222,7 +247,9 @@
|
|||
|
||||
(defn delete-comment-thread-on-viewer
|
||||
[{:keys [id] :as thread}]
|
||||
(dm/assert! (comment-thread? thread))
|
||||
(dm/assert!
|
||||
"expected valid comment thread"
|
||||
(check-comment-thread! thread))
|
||||
(ptk/reify ::delete-comment-thread-on-viewer
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
|
@ -241,7 +268,9 @@
|
|||
|
||||
(defn delete-comment
|
||||
[{:keys [id thread-id] :as comment}]
|
||||
(dm/assert! (comment? comment))
|
||||
(dm/assert!
|
||||
"expected valid comment"
|
||||
(check-comment! comment))
|
||||
(ptk/reify ::delete-comment
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
|
@ -256,7 +285,9 @@
|
|||
|
||||
(defn refresh-comment-thread
|
||||
[{:keys [id file-id] :as thread}]
|
||||
(dm/assert! (comment-thread? thread))
|
||||
(dm/assert!
|
||||
"expected valid comment thread"
|
||||
(check-comment-thread! thread))
|
||||
(letfn [(fetched [thread state]
|
||||
(assoc-in state [:comment-threads id] thread))]
|
||||
(ptk/reify ::refresh-comment-thread
|
||||
|
@ -338,7 +369,9 @@
|
|||
|
||||
(defn open-thread
|
||||
[{:keys [id] :as thread}]
|
||||
(dm/assert! (comment-thread? thread))
|
||||
(dm/assert!
|
||||
"expected valid comment thread"
|
||||
(check-comment-thread! thread))
|
||||
(ptk/reify ::open-comment-thread
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
|
@ -379,15 +412,18 @@
|
|||
(update [_ state]
|
||||
(update state :comments-local merge params))))
|
||||
|
||||
(def schema:create-draft
|
||||
[:map
|
||||
[:page-id ::sm/uuid]
|
||||
[:file-id ::sm/uuid]
|
||||
[:position ::gpt/point]])
|
||||
(def ^:private
|
||||
schema:create-draft
|
||||
(sm/define
|
||||
[:map {:title "create-draft"}
|
||||
[:page-id ::sm/uuid]
|
||||
[:file-id ::sm/uuid]
|
||||
[:position ::gpt/point]]))
|
||||
|
||||
(defn create-draft
|
||||
[params]
|
||||
(dm/assert! (sm/valid? schema:create-draft params))
|
||||
(dm/assert!
|
||||
(sm/check! schema:create-draft params))
|
||||
(ptk/reify ::create-draft
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
|
@ -452,11 +488,14 @@
|
|||
(filter #(contains? (:participants %) (:id profile))))))
|
||||
|
||||
(defn update-comment-thread-frame
|
||||
([thread ]
|
||||
([thread]
|
||||
(update-comment-thread-frame thread uuid/zero))
|
||||
|
||||
([thread frame-id]
|
||||
(dm/assert! (comment-thread? thread))
|
||||
(dm/assert!
|
||||
"expected valid comment thread"
|
||||
(check-comment-thread! thread))
|
||||
|
||||
(ptk/reify ::update-comment-thread-frame
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
|
@ -473,7 +512,10 @@
|
|||
(defn detach-comment-thread
|
||||
"Detach comment threads that are inside a frame when that frame is deleted"
|
||||
[ids]
|
||||
(dm/assert! (sm/coll-of-uuid? ids))
|
||||
(dm/assert!
|
||||
"expected a valid coll of uuid's"
|
||||
(sm/check-coll-of-uuid! ids))
|
||||
|
||||
(ptk/reify ::detach-comment-thread
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
|
|
|
@ -468,7 +468,10 @@
|
|||
[{:keys [emails role team-id resend?] :as params}]
|
||||
(dm/assert! (keyword? role))
|
||||
(dm/assert! (uuid? team-id))
|
||||
(dm/assert! (sm/set-of-emails? emails))
|
||||
|
||||
(dm/assert!
|
||||
"expected a valid set of emails"
|
||||
(sm/check-set-of-emails! emails))
|
||||
|
||||
(ptk/reify ::invite-team-members
|
||||
IDeref
|
||||
|
@ -487,7 +490,10 @@
|
|||
|
||||
(defn copy-invitation-link
|
||||
[{:keys [email team-id] :as params}]
|
||||
(dm/assert! (sm/email? email))
|
||||
(dm/assert!
|
||||
"expected a valid email"
|
||||
(sm/check-email! email))
|
||||
|
||||
(dm/assert! (uuid? team-id))
|
||||
|
||||
(ptk/reify ::copy-invitation-link
|
||||
|
@ -515,7 +521,10 @@
|
|||
|
||||
(defn update-team-invitation-role
|
||||
[{:keys [email team-id role] :as params}]
|
||||
(dm/assert! (sm/email? email))
|
||||
(dm/assert!
|
||||
"expected a valid email"
|
||||
(sm/check-email! email))
|
||||
|
||||
(dm/assert! (uuid? team-id))
|
||||
(dm/assert! (keyword? role)) ;; FIXME validate role
|
||||
|
||||
|
@ -534,7 +543,7 @@
|
|||
|
||||
(defn delete-team-invitation
|
||||
[{:keys [email team-id] :as params}]
|
||||
(dm/assert! (sm/email? email))
|
||||
(dm/assert! (sm/check-email! email))
|
||||
(dm/assert! (uuid? team-id))
|
||||
(ptk/reify ::delete-team-invitation
|
||||
ptk/WatchEvent
|
||||
|
@ -891,9 +900,12 @@
|
|||
|
||||
(defn move-files
|
||||
[{:keys [ids project-id] :as params}]
|
||||
(dm/assert! (sm/set-of-uuid? ids))
|
||||
(dm/assert! (uuid? project-id))
|
||||
|
||||
(dm/assert!
|
||||
"expected a valid set of uuids"
|
||||
(sm/check-set-of-uuid! ids))
|
||||
|
||||
(ptk/reify ::move-files
|
||||
IDeref
|
||||
(-deref [_]
|
||||
|
|
|
@ -18,38 +18,37 @@
|
|||
(def default-animation-timeout 600)
|
||||
(def default-timeout 5000)
|
||||
|
||||
(def schema:message
|
||||
[:map {:title "Message"}
|
||||
[:type [::sm/one-of #{:success :error :info :warning}]]
|
||||
[:status {:optional true}
|
||||
[::sm/one-of #{:visible :hide}]]
|
||||
[:position {:optional true}
|
||||
[::sm/one-of #{:fixed :floating :inline}]]
|
||||
[:controls {:optional true}
|
||||
[::sm/one-of #{:none :close :inline-actions :bottom-actions}]]
|
||||
[:tag {:optional true}
|
||||
[:or :string :keyword]]
|
||||
[:timeout {:optional true}
|
||||
[:maybe :int]]
|
||||
[:actions {:optional true}
|
||||
[:vector
|
||||
[:map
|
||||
[:label :string]
|
||||
[:callback ::sm/fn]]]]
|
||||
[:links {:optional true}
|
||||
[:vector
|
||||
[:map
|
||||
[:label :string]
|
||||
[:callback ::sm/fn]]]]])
|
||||
|
||||
(def message?
|
||||
(sm/pred-fn schema:message))
|
||||
(def ^:private
|
||||
schema:message
|
||||
(sm/define
|
||||
[:map {:title "Message"}
|
||||
[:type [::sm/one-of #{:success :error :info :warning}]]
|
||||
[:status {:optional true}
|
||||
[::sm/one-of #{:visible :hide}]]
|
||||
[:position {:optional true}
|
||||
[::sm/one-of #{:fixed :floating :inline}]]
|
||||
[:controls {:optional true}
|
||||
[::sm/one-of #{:none :close :inline-actions :bottom-actions}]]
|
||||
[:tag {:optional true}
|
||||
[:or :string :keyword]]
|
||||
[:timeout {:optional true}
|
||||
[:maybe :int]]
|
||||
[:actions {:optional true}
|
||||
[:vector
|
||||
[:map
|
||||
[:label :string]
|
||||
[:callback ::sm/fn]]]]
|
||||
[:links {:optional true}
|
||||
[:vector
|
||||
[:map
|
||||
[:label :string]
|
||||
[:callback ::sm/fn]]]]]))
|
||||
|
||||
(defn show
|
||||
[data]
|
||||
(dm/assert!
|
||||
"expected valid message map"
|
||||
(message? data))
|
||||
(sm/check! schema:message data))
|
||||
|
||||
(ptk/reify ::show
|
||||
ptk/UpdateEvent
|
||||
|
|
|
@ -127,16 +127,17 @@
|
|||
|
||||
;; --- EVENT: push
|
||||
|
||||
(def schema:shortcuts
|
||||
[:map-of
|
||||
:keyword
|
||||
[:map
|
||||
[:command [:or :string [:vector :any]]]
|
||||
[:fn {:optional true} fn?]
|
||||
[:tooltip {:optional true} :string]]])
|
||||
(def ^:private
|
||||
schema:shortcuts
|
||||
(sm/define
|
||||
[:map-of :keyword
|
||||
[:map
|
||||
[:command [:or :string [:vector :any]]]
|
||||
[:fn {:optional true} fn?]
|
||||
[:tooltip {:optional true} :string]]]))
|
||||
|
||||
(def shortcuts?
|
||||
(sm/pred-fn schema:shortcuts))
|
||||
(def check-shortcuts!
|
||||
(sm/check-fn schema:shortcuts))
|
||||
|
||||
(defn- wrap-cb
|
||||
[key cb]
|
||||
|
@ -169,8 +170,11 @@
|
|||
|
||||
(defn push-shortcuts
|
||||
[key shortcuts]
|
||||
(dm/assert! (keyword? key))
|
||||
(dm/assert! (shortcuts? shortcuts))
|
||||
|
||||
(dm/assert!
|
||||
"expected valid parameters"
|
||||
(and (keyword? key)
|
||||
(check-shortcuts! shortcuts)))
|
||||
|
||||
(ptk/reify ::push-shortcuts
|
||||
ptk/UpdateEvent
|
||||
|
|
|
@ -26,17 +26,19 @@
|
|||
|
||||
;; --- SCHEMAS
|
||||
|
||||
(def schema:profile
|
||||
[:map {:title "Profile"}
|
||||
[:id ::sm/uuid]
|
||||
[:created-at {:optional true} :any]
|
||||
[:fullname {:optional true} :string]
|
||||
[:email {:optional true} :string]
|
||||
[:lang {:optional true} :string]
|
||||
[:theme {:optional true} :string]])
|
||||
(def ^:private
|
||||
schema:profile
|
||||
(sm/define
|
||||
[:map {:title "Profile"}
|
||||
[:id ::sm/uuid]
|
||||
[:created-at {:optional true} :any]
|
||||
[:fullname {:optional true} :string]
|
||||
[:email {:optional true} :string]
|
||||
[:lang {:optional true} :string]
|
||||
[:theme {:optional true} :string]]))
|
||||
|
||||
(def profile?
|
||||
(sm/pred-fn schema:profile))
|
||||
(def check-profile!
|
||||
(sm/check-fn schema:profile))
|
||||
|
||||
;; --- HELPERS
|
||||
|
||||
|
@ -289,7 +291,10 @@
|
|||
|
||||
(defn update-profile
|
||||
[data]
|
||||
(dm/assert! (profile? data))
|
||||
(dm/assert!
|
||||
"expected valid profile data"
|
||||
(check-profile! data))
|
||||
|
||||
(ptk/reify ::update-profile
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ stream]
|
||||
|
@ -343,9 +348,13 @@
|
|||
;; Social registered users don't have old-password
|
||||
[:password-old {:optional true} [:maybe :string]]])
|
||||
|
||||
|
||||
(defn update-password
|
||||
[data]
|
||||
(dm/assert! (sm/valid? schema:update-password data))
|
||||
(dm/assert!
|
||||
"expected valid parameters"
|
||||
(sm/check! schema:update-password data))
|
||||
|
||||
(ptk/reify ::update-password
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
|
@ -475,14 +484,19 @@
|
|||
|
||||
;; --- EVENT: request-profile-recovery
|
||||
|
||||
(def schema:request-profile-recovery
|
||||
[:map {:closed true}
|
||||
[:email ::sm/email]])
|
||||
(def ^:private
|
||||
schema:request-profile-recovery
|
||||
(sm/define
|
||||
[:map {:title "request-profile-recovery" :closed true}
|
||||
[:email ::sm/email]]))
|
||||
|
||||
;; FIXME: check if we can use schema for proper filter
|
||||
(defn request-profile-recovery
|
||||
[data]
|
||||
(dm/assert! (sm/valid? schema:request-profile-recovery data))
|
||||
|
||||
(dm/assert!
|
||||
"expected valid parameters"
|
||||
(sm/check! schema:request-profile-recovery data))
|
||||
|
||||
(ptk/reify ::request-profile-recovery
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
|
@ -496,14 +510,19 @@
|
|||
|
||||
;; --- EVENT: recover-profile (Password)
|
||||
|
||||
(def schema:recover-profile
|
||||
[:map {:closed true}
|
||||
[:password :string]
|
||||
[:token :string]])
|
||||
(def ^:private
|
||||
schema:recover-profile
|
||||
(sm/define
|
||||
[:map {:title "recover-profile" :closed true}
|
||||
[:password :string]
|
||||
[:token :string]]))
|
||||
|
||||
(defn recover-profile
|
||||
[data]
|
||||
(dm/assert! (sm/valid? schema:recover-profile data))
|
||||
(dm/assert!
|
||||
"expected valid arguments"
|
||||
(sm/check! schema:recover-profile data))
|
||||
|
||||
(ptk/reify ::recover-profile
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
|
|
|
@ -46,15 +46,20 @@
|
|||
(declare zoom-to-fill)
|
||||
(declare zoom-to-fit)
|
||||
|
||||
(def schema:initialize
|
||||
[:map
|
||||
[:file-id ::sm/uuid]
|
||||
[:share-id {:optional true} [:maybe ::sm/uuid]]
|
||||
[:page-id {:optional true} ::sm/uuid]])
|
||||
(def ^:private
|
||||
schema:initialize
|
||||
(sm/define
|
||||
[:map {:title "initialize"}
|
||||
[:file-id ::sm/uuid]
|
||||
[:share-id {:optional true} [:maybe ::sm/uuid]]
|
||||
[:page-id {:optional true} ::sm/uuid]]))
|
||||
|
||||
(defn initialize
|
||||
[{:keys [file-id share-id interactions-show?] :as params}]
|
||||
(dm/assert! (sm/valid? schema:initialize params))
|
||||
(dm/assert!
|
||||
"expected valid params"
|
||||
(sm/check! schema:initialize params))
|
||||
|
||||
(ptk/reify ::initialize
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
|
@ -92,18 +97,20 @@
|
|||
|
||||
;; --- Data Fetching
|
||||
|
||||
(def schema:fetch-bundle
|
||||
[:map
|
||||
[:page-id ::sm/uuid]
|
||||
[:file-id ::sm/uuid]
|
||||
[:share-id {:optional true} ::sm/uuid]])
|
||||
|
||||
(def ^:private valid-fetch-bundle-params?
|
||||
(sm/pred-fn schema:fetch-bundle))
|
||||
(def ^:private
|
||||
schema:fetch-bundle
|
||||
(sm/define
|
||||
[:map {:title "fetch-bundle"}
|
||||
[:page-id ::sm/uuid]
|
||||
[:file-id ::sm/uuid]
|
||||
[:share-id {:optional true} ::sm/uuid]]))
|
||||
|
||||
(defn- fetch-bundle
|
||||
[{:keys [file-id share-id] :as params}]
|
||||
(dm/assert! (valid-fetch-bundle-params? params))
|
||||
|
||||
(dm/assert!
|
||||
"expected valid params"
|
||||
(sm/check! schema:fetch-bundle params))
|
||||
|
||||
(ptk/reify ::fetch-bundle
|
||||
ptk/WatchEvent
|
||||
|
@ -486,9 +493,11 @@
|
|||
(go-to-frame frame-id nil))
|
||||
|
||||
([frame-id animation]
|
||||
(dm/assert! (uuid? frame-id))
|
||||
(dm/assert! (or (nil? animation)
|
||||
(ctsi/animation? animation)))
|
||||
(dm/assert!
|
||||
"expected valid parameters"
|
||||
(and (uuid? frame-id)
|
||||
(or (nil? animation)
|
||||
(ctsi/check-animation! animation))))
|
||||
|
||||
(ptk/reify ::go-to-frame
|
||||
ptk/UpdateEvent
|
||||
|
@ -587,7 +596,7 @@
|
|||
(dm/assert! (or (nil? background-overlay)
|
||||
(boolean? background-overlay)))
|
||||
(dm/assert! (or (nil? animation)
|
||||
(ctsi/animation? animation)))
|
||||
(ctsi/check-animation! animation)))
|
||||
(ptk/reify ::open-overlay
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
|
@ -617,7 +626,7 @@
|
|||
(dm/assert! (or (nil? background-overlay)
|
||||
(boolean? background-overlay)))
|
||||
(dm/assert! (or (nil? animation)
|
||||
(ctsi/animation? animation)))
|
||||
(ctsi/check-animation! animation)))
|
||||
|
||||
(ptk/reify ::toggle-overlay
|
||||
ptk/UpdateEvent
|
||||
|
@ -645,7 +654,7 @@
|
|||
([frame-id animation]
|
||||
(dm/assert! (uuid? frame-id))
|
||||
(dm/assert! (or (nil? animation)
|
||||
(ctsi/animation? animation)))
|
||||
(ctsi/check-animation! animation)))
|
||||
|
||||
(ptk/reify ::close-overlay
|
||||
ptk/UpdateEvent
|
||||
|
|
|
@ -669,8 +669,11 @@
|
|||
|
||||
(defn update-shape
|
||||
[id attrs]
|
||||
(dm/assert! (uuid? id))
|
||||
(dm/assert! (cts/valid-shape-attrs? attrs))
|
||||
(dm/assert!
|
||||
"expected valid parameters"
|
||||
(and (cts/check-shape-attrs! attrs)
|
||||
(uuid? id)))
|
||||
|
||||
(ptk/reify ::update-shape
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
|
@ -712,7 +715,10 @@
|
|||
|
||||
(defn update-selected-shapes
|
||||
[attrs]
|
||||
(dm/assert! (cts/valid-shape-attrs? attrs))
|
||||
(dm/assert!
|
||||
"expected valid shape attrs"
|
||||
(cts/check-shape-attrs! attrs))
|
||||
|
||||
(ptk/reify ::update-selected-shapes
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
|
|
|
@ -53,7 +53,11 @@
|
|||
([ids update-fn] (update-shapes ids update-fn nil))
|
||||
([ids update-fn {:keys [reg-objects? save-undo? stack-undo? attrs ignore-tree page-id ignore-remote? ignore-touched undo-group]
|
||||
:or {reg-objects? false save-undo? true stack-undo? false ignore-remote? false ignore-touched false}}]
|
||||
(dm/assert! (sm/coll-of-uuid? ids))
|
||||
|
||||
(dm/assert!
|
||||
"expected a valid set of uuid's"
|
||||
(sm/check-set-of-uuid! ids))
|
||||
|
||||
(dm/assert! (fn? update-fn))
|
||||
|
||||
(ptk/reify ::update-shapes
|
||||
|
@ -212,8 +216,8 @@
|
|||
(try
|
||||
(dm/assert!
|
||||
"expect valid vector of changes"
|
||||
(and (cpc/valid-changes? redo-changes)
|
||||
(cpc/valid-changes? undo-changes)))
|
||||
(and (cpc/check-changes! redo-changes)
|
||||
(cpc/check-changes! undo-changes)))
|
||||
|
||||
(update-in state path (fn [file]
|
||||
(-> file
|
||||
|
|
|
@ -278,7 +278,10 @@
|
|||
|
||||
(defn add-shadow
|
||||
[ids shadow]
|
||||
(dm/assert! (sm/coll-of-uuid? ids))
|
||||
(dm/assert!
|
||||
"expected a valid coll of uuid's"
|
||||
(sm/check-coll-of-uuid! ids))
|
||||
|
||||
(ptk/reify ::add-shadow
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
|
|
|
@ -81,7 +81,10 @@
|
|||
|
||||
(defn center-to-comment-thread
|
||||
[{:keys [position] :as thread}]
|
||||
(dm/assert! (dcm/comment-thread? thread))
|
||||
(dm/assert!
|
||||
"expected valid comment thread"
|
||||
(dcm/check-comment-thread! thread))
|
||||
|
||||
(ptk/reify ::center-to-comment-thread
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
|
@ -97,7 +100,9 @@
|
|||
|
||||
(defn navigate
|
||||
[thread]
|
||||
(dm/assert! (dcm/comment-thread? thread))
|
||||
(dm/assert!
|
||||
"expected valid comment thread"
|
||||
(dcm/check-comment-thread! thread))
|
||||
(ptk/reify ::open-comment-thread
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ stream]
|
||||
|
@ -118,36 +123,41 @@
|
|||
(update-comment-thread-position thread [new-x new-y] nil))
|
||||
|
||||
([thread [new-x new-y] frame-id]
|
||||
(dm/assert! (dcm/comment-thread? thread))
|
||||
(ptk/reify ::update-comment-thread-position
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
(let [thread-id (:id thread)
|
||||
page (wsh/lookup-page state)
|
||||
page-id (:id page)
|
||||
objects (wsh/lookup-page-objects state page-id)
|
||||
new-frame-id (if (nil? frame-id)
|
||||
(ctst/get-frame-id-by-position objects (gpt/point new-x new-y))
|
||||
(:frame-id thread))
|
||||
thread (assoc thread
|
||||
:position (gpt/point new-x new-y)
|
||||
:frame-id new-frame-id)
|
||||
(dm/assert!
|
||||
"expected valid comment thread"
|
||||
(dcm/check-comment-thread! thread))
|
||||
(ptk/reify ::update-comment-thread-position
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
(let [thread-id (:id thread)
|
||||
page (wsh/lookup-page state)
|
||||
page-id (:id page)
|
||||
objects (wsh/lookup-page-objects state page-id)
|
||||
new-frame-id (if (nil? frame-id)
|
||||
(ctst/get-frame-id-by-position objects (gpt/point new-x new-y))
|
||||
(:frame-id thread))
|
||||
thread (assoc thread
|
||||
:position (gpt/point new-x new-y)
|
||||
:frame-id new-frame-id)
|
||||
|
||||
changes
|
||||
(-> (pcb/empty-changes it)
|
||||
(pcb/with-page page)
|
||||
(pcb/update-page-option :comment-threads-position assoc thread-id (select-keys thread [:position :frame-id])))]
|
||||
changes
|
||||
(-> (pcb/empty-changes it)
|
||||
(pcb/with-page page)
|
||||
(pcb/update-page-option :comment-threads-position assoc thread-id (select-keys thread [:position :frame-id])))]
|
||||
|
||||
(rx/merge
|
||||
(rx/of (dwc/commit-changes changes))
|
||||
(->> (rp/cmd! :update-comment-thread-position thread)
|
||||
(rx/catch #(rx/throw {:type :update-comment-thread-position}))
|
||||
(rx/ignore))))))))
|
||||
(rx/merge
|
||||
(rx/of (dwc/commit-changes changes))
|
||||
(->> (rp/cmd! :update-comment-thread-position thread)
|
||||
(rx/catch #(rx/throw {:type :update-comment-thread-position}))
|
||||
(rx/ignore))))))))
|
||||
|
||||
;; Move comment threads that are inside a frame when that frame is moved"
|
||||
(defmethod ptk/resolve ::move-frame-comment-threads
|
||||
[_ ids]
|
||||
(dm/assert! (sm/coll-of-uuid? ids))
|
||||
(dm/assert!
|
||||
"expected a valid coll of uuid's"
|
||||
(sm/check-coll-of-uuid! ids))
|
||||
|
||||
(ptk/reify ::move-frame-comment-threads
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
(defn update-guides [guide]
|
||||
(dm/assert!
|
||||
"expected valid guide"
|
||||
(ctp/guide? guide))
|
||||
(ctp/check-page-guide! guide))
|
||||
|
||||
(ptk/reify ::update-guides
|
||||
ptk/WatchEvent
|
||||
|
@ -40,7 +40,7 @@
|
|||
(defn remove-guide [guide]
|
||||
(dm/assert!
|
||||
"expected valid guide"
|
||||
(ctp/guide? guide))
|
||||
(ctp/check-page-guide! guide))
|
||||
|
||||
(ptk/reify ::remove-guide
|
||||
ptk/UpdateEvent
|
||||
|
|
|
@ -114,7 +114,10 @@
|
|||
|
||||
(defn add-recent-color
|
||||
[color]
|
||||
(dm/assert! (ctc/valid-recent-color? color))
|
||||
(dm/assert!
|
||||
"expected valid recent color map"
|
||||
(ctc/check-recent-color! color))
|
||||
|
||||
(ptk/reify ::add-recent-color
|
||||
ptk/WatchEvent
|
||||
(watch [it _ _]
|
||||
|
@ -144,8 +147,11 @@
|
|||
|
||||
(defn update-color
|
||||
[color file-id]
|
||||
(dm/assert! (ctc/valid-color? color))
|
||||
(dm/assert! (uuid? file-id))
|
||||
|
||||
(dm/assert!
|
||||
"expected valid parameters"
|
||||
(and (ctc/check-color! color)
|
||||
(uuid? file-id)))
|
||||
|
||||
(ptk/reify ::update-color
|
||||
ptk/WatchEvent
|
||||
|
@ -183,7 +189,10 @@
|
|||
|
||||
(defn add-media
|
||||
[media]
|
||||
(dm/assert! (ctf/valid-media-object? media))
|
||||
(dm/assert!
|
||||
"expected valid media object"
|
||||
(ctf/check-media-object! media))
|
||||
|
||||
(ptk/reify ::add-media
|
||||
ptk/WatchEvent
|
||||
(watch [it _ _]
|
||||
|
@ -227,7 +236,10 @@
|
|||
([typography] (add-typography typography true))
|
||||
([typography edit?]
|
||||
(let [typography (update typography :id #(or % (uuid/next)))]
|
||||
(dm/assert! (ctt/typography? typography))
|
||||
(dm/assert!
|
||||
"expected valid typography"
|
||||
(ctt/check-typography! typography))
|
||||
|
||||
(ptk/reify ::add-typography
|
||||
IDeref
|
||||
(-deref [_] typography)
|
||||
|
@ -256,8 +268,11 @@
|
|||
|
||||
(defn update-typography
|
||||
[typography file-id]
|
||||
(dm/assert! (ctt/typography? typography))
|
||||
(dm/assert! (uuid? file-id))
|
||||
|
||||
(dm/assert!
|
||||
"expected valid typography and file-id"
|
||||
(and (ctt/check-typography! typography)
|
||||
(uuid? file-id)))
|
||||
|
||||
(ptk/reify ::update-typography
|
||||
ptk/WatchEvent
|
||||
|
@ -607,7 +622,7 @@
|
|||
(defn ext-library-changed
|
||||
[library-id modified-at revn changes]
|
||||
(dm/assert! (uuid? library-id))
|
||||
(dm/assert! (ch/valid-changes? changes))
|
||||
(dm/assert! (ch/check-changes! changes))
|
||||
(ptk/reify ::ext-library-changed
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
|
|
|
@ -163,15 +163,6 @@
|
|||
(rx/merge-map svg->clj)
|
||||
(rx/do on-svg)))))
|
||||
|
||||
(def schema:process-media-objects
|
||||
[:map
|
||||
[:file-id ::sm/uuid]
|
||||
[:local? :boolean]
|
||||
[:name {:optional true} :string]
|
||||
[:data {:optional true} :any] ; FIXME
|
||||
[:uris {:optional true} [:sequential :string]]
|
||||
[:mtype {:optional true} :string]])
|
||||
|
||||
(defn handle-media-error [error on-error]
|
||||
(if (ex/ex-info? error)
|
||||
(handle-media-error (ex-data error) on-error)
|
||||
|
@ -205,10 +196,22 @@
|
|||
(.error js/console "ERROR" error)
|
||||
(rx/of (msg/error (tr "errors.cannot-upload")))))))
|
||||
|
||||
|
||||
(def ^:private
|
||||
schema:process-media-objects
|
||||
(sm/define
|
||||
[:map {:title "process-media-objects"}
|
||||
[:file-id ::sm/uuid]
|
||||
[:local? :boolean]
|
||||
[:name {:optional true} :string]
|
||||
[:data {:optional true} :any] ; FIXME
|
||||
[:uris {:optional true} [:sequential :string]]
|
||||
[:mtype {:optional true} :string]]))
|
||||
|
||||
(defn- process-media-objects
|
||||
[{:keys [uris on-error] :as params}]
|
||||
(dm/assert!
|
||||
(and (sm/valid? schema:process-media-objects params)
|
||||
(and (sm/check! schema:process-media-objects params)
|
||||
(or (contains? params :blobs)
|
||||
(contains? params :uris))))
|
||||
|
||||
|
@ -392,14 +395,18 @@
|
|||
:on-svg #(st/emit! (process-svg-component %)))]
|
||||
(process-media-objects params)))
|
||||
|
||||
(def schema:clone-media-object
|
||||
[:map
|
||||
[:file-id ::sm/uuid]
|
||||
[:object-id ::sm/uuid]])
|
||||
(def ^:private
|
||||
schema:clone-media-object
|
||||
(sm/define
|
||||
[:map {:title "clone-media-object"}
|
||||
[:file-id ::sm/uuid]
|
||||
[:object-id ::sm/uuid]]))
|
||||
|
||||
(defn clone-media-object
|
||||
[{:keys [file-id object-id] :as params}]
|
||||
(dm/assert! (sm/valid? schema:clone-media-object params))
|
||||
(dm/assert!
|
||||
(sm/check! schema:clone-media-object params))
|
||||
|
||||
(ptk/reify ::clone-media-objects
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
|
|
|
@ -184,18 +184,23 @@
|
|||
:updated-at (dt/now)
|
||||
:page-id page-id))))))
|
||||
|
||||
(def schema:handle-file-change
|
||||
[:map
|
||||
[:type :keyword]
|
||||
[:profile-id ::sm/uuid]
|
||||
[:file-id ::sm/uuid]
|
||||
[:session-id ::sm/uuid]
|
||||
[:revn :int]
|
||||
[:changes ::cpc/changes]])
|
||||
(def ^:private
|
||||
schema:handle-file-change
|
||||
(sm/define
|
||||
[:map {:title "handle-file-change"}
|
||||
[:type :keyword]
|
||||
[:profile-id ::sm/uuid]
|
||||
[:file-id ::sm/uuid]
|
||||
[:session-id ::sm/uuid]
|
||||
[:revn :int]
|
||||
[:changes ::cpc/changes]]))
|
||||
|
||||
(defn handle-file-change
|
||||
[{:keys [file-id changes] :as msg}]
|
||||
(dm/assert! (sm/valid? schema:handle-file-change msg))
|
||||
(dm/assert!
|
||||
"expected valid arguments"
|
||||
(sm/check! schema:handle-file-change msg))
|
||||
|
||||
(ptk/reify ::handle-file-change
|
||||
IDeref
|
||||
(-deref [_] {:changes changes})
|
||||
|
@ -241,19 +246,24 @@
|
|||
(when-not (empty? changes-by-pages)
|
||||
(rx/from (map process-page-changes changes-by-pages))))))))
|
||||
|
||||
(def schema:handle-library-change
|
||||
[:map
|
||||
[:type :keyword]
|
||||
[:profile-id ::sm/uuid]
|
||||
[:file-id ::sm/uuid]
|
||||
[:session-id ::sm/uuid]
|
||||
[:revn :int]
|
||||
[:modified-at ::sm/inst]
|
||||
[:changes ::cpc/changes]])
|
||||
(def ^:private
|
||||
schema:handle-library-change
|
||||
(sm/define
|
||||
[:map {:title "handle-library-change"}
|
||||
[:type :keyword]
|
||||
[:profile-id ::sm/uuid]
|
||||
[:file-id ::sm/uuid]
|
||||
[:session-id ::sm/uuid]
|
||||
[:revn :int]
|
||||
[:modified-at ::sm/inst]
|
||||
[:changes ::cpc/changes]]))
|
||||
|
||||
(defn handle-library-change
|
||||
[{:keys [file-id modified-at changes revn] :as msg}]
|
||||
(dm/assert! (sm/valid? schema:handle-library-change msg))
|
||||
(dm/assert!
|
||||
"expected valid arguments"
|
||||
(sm/check! schema:handle-library-change msg))
|
||||
|
||||
(ptk/reify ::handle-library-change
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
[app.common.data.macros :as dm]
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.main.data.workspace.changes :as dch]
|
||||
[app.main.data.workspace.path.common :refer [content?]]
|
||||
[app.main.data.workspace.path.common :refer [check-path-content!]]
|
||||
[app.main.data.workspace.path.helpers :as helpers]
|
||||
[app.main.data.workspace.path.state :as st]
|
||||
[app.main.data.workspace.state-helpers :as wsh]
|
||||
|
@ -19,8 +19,12 @@
|
|||
(defn generate-path-changes
|
||||
"Generates changes to update the new content of the shape"
|
||||
[it objects page-id shape old-content new-content]
|
||||
(dm/assert! (content? old-content))
|
||||
(dm/assert! (content? new-content))
|
||||
|
||||
(dm/assert!
|
||||
"expected valid path content"
|
||||
(and (check-path-content! old-content)
|
||||
(check-path-content! new-content)))
|
||||
|
||||
(let [shape-id (:id shape)
|
||||
|
||||
[old-points old-selrect]
|
||||
|
|
|
@ -22,23 +22,27 @@
|
|||
:elliptical-arc
|
||||
:close-path})
|
||||
|
||||
(def schema:content
|
||||
[:vector {:title "PathContent"}
|
||||
[:map {:title "PathContentEntry"}
|
||||
[:command [::sm/one-of valid-commands]]
|
||||
;; FIXME: remove the `?` from prop name
|
||||
[:relative? {:optional true} :boolean]
|
||||
[:params {:optional true}
|
||||
[:map {:title "PathContentEntryParams"}
|
||||
[:x :double]
|
||||
[:y :double]
|
||||
[:c1x {:optional true} :double]
|
||||
[:c1y {:optional true} :double]
|
||||
[:c2x {:optional true} :double]
|
||||
[:c2y {:optional true} :double]]]]])
|
||||
;; FIXME: should this schema be defined on common.types ?
|
||||
|
||||
(def content?
|
||||
(sm/pred-fn schema:content))
|
||||
(def ^:private
|
||||
schema:path-content
|
||||
(sm/define
|
||||
[:vector {:title "PathContent"}
|
||||
[:map {:title "PathContentEntry"}
|
||||
[:command [::sm/one-of valid-commands]]
|
||||
;; FIXME: remove the `?` from prop name
|
||||
[:relative? {:optional true} :boolean]
|
||||
[:params {:optional true}
|
||||
[:map {:title "PathContentEntryParams"}
|
||||
[:x :double]
|
||||
[:y :double]
|
||||
[:c1x {:optional true} :double]
|
||||
[:c1y {:optional true} :double]
|
||||
[:c2x {:optional true} :double]
|
||||
[:c2y {:optional true} :double]]]]]))
|
||||
|
||||
(def check-path-content!
|
||||
(sm/check-fn schema:path-content))
|
||||
|
||||
(defn init-path []
|
||||
(ptk/reify ::init-path))
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
[app.main.data.workspace.drawing.common :as dwdc]
|
||||
[app.main.data.workspace.edition :as dwe]
|
||||
[app.main.data.workspace.path.changes :as changes]
|
||||
[app.main.data.workspace.path.common :as common :refer [content?]]
|
||||
[app.main.data.workspace.path.common :as common :refer [check-path-content!]]
|
||||
[app.main.data.workspace.path.helpers :as helpers]
|
||||
[app.main.data.workspace.path.state :as st]
|
||||
[app.main.data.workspace.path.streams :as streams]
|
||||
|
@ -262,7 +262,11 @@
|
|||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [content (get-in state [:workspace-drawing :object :content] [])]
|
||||
(dm/assert! (content? content))
|
||||
|
||||
(dm/assert!
|
||||
"expected valid path content"
|
||||
(check-path-content! content))
|
||||
|
||||
(if (> (count content) 1)
|
||||
(assoc-in state [:workspace-drawing :object :initialized?] true)
|
||||
state)))
|
||||
|
|
|
@ -238,7 +238,7 @@
|
|||
[file-id {:keys [revn changes]}]
|
||||
(dm/assert! (uuid? file-id))
|
||||
(dm/assert! (int? revn))
|
||||
(dm/assert! (cpc/valid-changes? changes))
|
||||
(dm/assert! (cpc/check-changes! changes))
|
||||
|
||||
(ptk/reify ::shapes-changes-persisted
|
||||
ptk/UpdateEvent
|
||||
|
|
|
@ -27,9 +27,6 @@
|
|||
[beicon.core :as rx]
|
||||
[potok.core :as ptk]))
|
||||
|
||||
(def valid-shape-map?
|
||||
(sm/pred-fn ::cts/shape))
|
||||
|
||||
(defn add-shape
|
||||
([shape]
|
||||
(add-shape shape {}))
|
||||
|
@ -37,7 +34,7 @@
|
|||
|
||||
(dm/verify!
|
||||
"expected a valid shape"
|
||||
(cts/valid-shape? shape))
|
||||
(cts/check-shape! shape))
|
||||
|
||||
(ptk/reify ::add-shape
|
||||
ptk/WatchEvent
|
||||
|
@ -94,7 +91,10 @@
|
|||
([ids] (delete-shapes nil ids {}))
|
||||
([page-id ids] (delete-shapes page-id ids {}))
|
||||
([page-id ids options]
|
||||
(dm/assert! (sm/set-of-uuid? ids))
|
||||
(dm/assert!
|
||||
"expected a valid set of uuid's"
|
||||
(sm/check-set-of-uuid! ids))
|
||||
|
||||
(ptk/reify ::delete-shapes
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
|
@ -376,7 +376,7 @@
|
|||
|
||||
(dm/assert!
|
||||
"expected valid shape-attrs value for `flags`"
|
||||
(cts/valid-shape-attrs? flags))
|
||||
(cts/check-shape-attrs! flags))
|
||||
|
||||
(ptk/reify ::update-shape-flags
|
||||
ptk/WatchEvent
|
||||
|
|
|
@ -24,13 +24,15 @@
|
|||
;; Undo / Redo
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(def schema:undo-entry
|
||||
[:map
|
||||
[:undo-changes [:vector ::cpc/change]]
|
||||
[:redo-changes [:vector ::cpc/change]]])
|
||||
(def ^:private
|
||||
schema:undo-entry
|
||||
(sm/define
|
||||
[:map {:title "undo-entry"}
|
||||
[:undo-changes [:vector ::cpc/change]]
|
||||
[:redo-changes [:vector ::cpc/change]]]))
|
||||
|
||||
(def undo-entry?
|
||||
(sm/pred-fn schema:undo-entry))
|
||||
(def check-undo-entry!
|
||||
(sm/check-fn schema:undo-entry))
|
||||
|
||||
(def MAX-UNDO-SIZE 50)
|
||||
|
||||
|
@ -89,8 +91,12 @@
|
|||
|
||||
(defn append-undo
|
||||
[entry stack?]
|
||||
(dm/assert! (boolean? stack?))
|
||||
(dm/assert! (undo-entry? entry))
|
||||
(dm/assert!
|
||||
"expected valid undo entry"
|
||||
(check-undo-entry! entry))
|
||||
|
||||
(dm/assert!
|
||||
(boolean? stack?))
|
||||
|
||||
(ptk/reify ::append-undo
|
||||
ptk/UpdateEvent
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
|
||||
(ns app.main.ui.dashboard.project-menu
|
||||
(:require
|
||||
[app.common.data.macros :as dm]
|
||||
[app.common.schema :as sm]
|
||||
[app.main.data.dashboard :as dd]
|
||||
[app.main.data.messages :as msg]
|
||||
[app.main.data.modal :as modal]
|
||||
|
@ -21,19 +19,8 @@
|
|||
[app.util.router :as rt]
|
||||
[rumext.v2 :as mf]))
|
||||
|
||||
(def schema:project-menu
|
||||
[:map {:title "UIProjectMenu"}
|
||||
[:project some?]
|
||||
[:show? :boolean]
|
||||
[:on-menu-close {:optional true} ::sm/fn]
|
||||
[:on-error {:optional true} ::sm/fn]
|
||||
[:top {:optional true} [:maybe :double]]
|
||||
[:left {:optional true} [:maybe :double]]
|
||||
[:on-import {:optional true} ::sm/fn]])
|
||||
|
||||
(mf/defc project-menu
|
||||
[{:keys [project show? on-edit on-menu-close top left on-import] :as props}]
|
||||
(dm/assert! (sm/valid? schema:project-menu props))
|
||||
(let [top (or top 0)
|
||||
left (or left 0)
|
||||
|
||||
|
|
|
@ -24,23 +24,24 @@
|
|||
|
||||
;; --- Messages Handling
|
||||
|
||||
(def schema:message
|
||||
[:map {:title "WorkerMessage"}
|
||||
[:sender-id ::sm/uuid]
|
||||
[:payload
|
||||
[:map
|
||||
[:cmd :keyword]]]
|
||||
[:buffer? {:optional true} :boolean]])
|
||||
|
||||
(def message?
|
||||
(sm/pred-fn schema:message))
|
||||
(def ^:private
|
||||
schema:message
|
||||
(sm/define
|
||||
[:map {:title "WorkerMessage"}
|
||||
[:sender-id ::sm/uuid]
|
||||
[:payload
|
||||
[:map
|
||||
[:cmd :keyword]]]
|
||||
[:buffer? {:optional true} :boolean]]))
|
||||
|
||||
(def buffer (rx/subject))
|
||||
|
||||
(defn- handle-message
|
||||
"Process the message and returns to the client"
|
||||
[{:keys [sender-id payload transfer] :as message}]
|
||||
(dm/assert! (message? message))
|
||||
(dm/assert!
|
||||
"expected valid message"
|
||||
(sm/check! schema:message message))
|
||||
(letfn [(post [msg]
|
||||
(let [msg (-> msg (assoc :reply-to sender-id) (wm/encode))]
|
||||
(.postMessage js/self msg)))
|
||||
|
@ -86,7 +87,9 @@
|
|||
(defn- drop-message
|
||||
"Sends to the client a notification that its messages have been dropped"
|
||||
[{:keys [sender-id] :as message}]
|
||||
(dm/assert! (message? message))
|
||||
(dm/assert!
|
||||
"expected valid message"
|
||||
(sm/check! schema:message message))
|
||||
(.postMessage js/self (wm/encode {:reply-to sender-id
|
||||
:dropped true})))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue