Fix linter issues on frontend (part 1).

This commit is contained in:
Andrey Antukh 2021-06-17 13:26:38 +02:00 committed by Andrés Moya
parent 09314c8926
commit e90185b553
53 changed files with 324 additions and 748 deletions

View file

@ -1,14 +1,22 @@
{:lint-as {potok.core/reify clojure.core/reify {:lint-as
promesa.core/let clojure.core/let {promesa.core/let clojure.core/let
rumext.alpha/defc clojure.core/defn rumext.alpha/defc clojure.core/defn
app.common.data/export clojure.core/def app.common.data/export clojure.core/def
app.db/with-atomic clojure.core/with-open} app.db/with-atomic clojure.core/with-open}
:hooks :hooks
{:analyze-call {app.common.data/export hooks.export/export}} {:analyze-call {app.common.data/export hooks.export/export
potok.core/reify hooks.export/potok-reify}}
:output :output
{:exclude-files ["data_readers.clj"]} {:exclude-files
["data_readers.clj"
"app/util/perf.cljs"
"app/util/import/.*"
"app/worker/.*"
"app/main/ui.*"
"app/libs/.*"
]}
:linters :linters
{:unsorted-required-namespaces {:unsorted-required-namespaces

View file

@ -9,3 +9,13 @@
(api/token-node (symbol (name (:value sname)))) (api/token-node (symbol (name (:value sname))))
sname])] sname])]
{:node result})) {:node result}))
(defn potok-reify
[{:keys [:node]}]
(let [[rnode rtype & other] (:children node)
result (api/list-node
(into [(api/token-node (symbol "deftype"))
(api/token-node (gensym (name (:k rtype))))
(api/vector-node [])]
other))]
{:node result}))

View file

@ -6,9 +6,8 @@
(ns app.config (ns app.config
(:require (:require
[app.common.data :as d]
[app.common.uri :as u]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.uri :as u]
[app.common.version :as v] [app.common.version :as v]
[app.util.avatars :as avatars] [app.util.avatars :as avatars]
[app.util.dom :as dom] [app.util.dom :as dom]

View file

@ -12,7 +12,6 @@
[app.main.data.events :as ev] [app.main.data.events :as ev]
[app.main.data.messages :as dm] [app.main.data.messages :as dm]
[app.main.data.users :as du] [app.main.data.users :as du]
[app.main.repo :as rp]
[app.main.store :as st] [app.main.store :as st]
[app.main.ui :as ui] [app.main.ui :as ui]
[app.main.ui.confirm] [app.main.ui.confirm]
@ -21,11 +20,9 @@
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.i18n :as i18n] [app.util.i18n :as i18n]
[app.util.logging :as log] [app.util.logging :as log]
[app.util.object :as obj]
[app.util.router :as rt] [app.util.router :as rt]
[app.util.storage :refer [storage]] [app.util.storage :refer [storage]]
[app.util.theme :as theme] [app.util.theme :as theme]
[app.util.timers :as ts]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[potok.core :as ptk] [potok.core :as ptk]
@ -81,7 +78,7 @@
(defn initialize (defn initialize
[] []
(letfn [(on-profile [profile] (letfn [(on-profile [_profile]
(rx/of (rt/initialize-router ui/routes) (rx/of (rt/initialize-router ui/routes)
(rt/initialize-history on-navigate)))] (rt/initialize-history on-navigate)))]
(ptk/reify ::initialize (ptk/reify ::initialize
@ -90,7 +87,7 @@
(assoc state :session-id (uuid/next))) (assoc state :session-id (uuid/next)))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ stream]
(rx/merge (rx/merge
(rx/of (rx/of
(ptk/event ::ev/initialize) (ptk/event ::ev/initialize)

View file

@ -6,28 +6,11 @@
(ns app.main.data.comments (ns app.main.data.comments
(:require (:require
[cuerdas.core :as str]
[app.common.data :as d] [app.common.data :as d]
[app.common.exceptions :as ex]
[app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as geom]
[app.common.math :as mth]
[app.common.pages :as cp]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.uuid :as uuid]
[app.config :as cfg]
[app.main.constants :as c]
[app.main.repo :as rp] [app.main.repo :as rp]
[app.main.store :as st]
[app.main.streams :as ms]
[app.main.worker :as uw]
[app.util.router :as rt]
[app.util.timers :as ts]
[app.util.webapi :as wapi]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[clojure.set :as set]
[potok.core :as ptk])) [potok.core :as ptk]))
(s/def ::content ::us/string) (s/def ::content ::us/string)
@ -91,7 +74,7 @@
(ptk/reify ::create-thread (ptk/reify ::create-thread
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/mutation :create-comment-thread params) (->> (rp/mutation :create-comment-thread params)
(rx/mapcat #(rp/query :comment-thread {:file-id (:file-id %) :id (:id %)})) (rx/mapcat #(rp/query :comment-thread {:file-id (:file-id %) :id (:id %)}))
(rx/map #(partial created %))))))) (rx/map #(partial created %)))))))
@ -101,7 +84,7 @@
(us/assert ::comment-thread thread) (us/assert ::comment-thread thread)
(ptk/reify ::update-comment-thread-status (ptk/reify ::update-comment-thread-status
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [done #(d/update-in-when % [:comment-threads id] assoc :count-unread-comments 0)] (let [done #(d/update-in-when % [:comment-threads id] assoc :count-unread-comments 0)]
(->> (rp/mutation :update-comment-thread-status {:id id}) (->> (rp/mutation :update-comment-thread-status {:id id})
(rx/map (constantly done))))))) (rx/map (constantly done)))))))
@ -117,7 +100,7 @@
(d/update-in-when state [:comment-threads id] assoc :is-resolved is-resolved)) (d/update-in-when state [:comment-threads id] assoc :is-resolved is-resolved))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/mutation :update-comment-thread {:id id :is-resolved is-resolved}) (->> (rp/mutation :update-comment-thread {:id id :is-resolved is-resolved})
(rx/ignore))))) (rx/ignore)))))
@ -130,7 +113,7 @@
(update-in state [:comments (:id thread)] assoc (:id comment) comment))] (update-in state [:comments (:id thread)] assoc (:id comment) comment))]
(ptk/reify ::create-comment (ptk/reify ::create-comment
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(rx/concat (rx/concat
(->> (rp/mutation :add-comment {:thread-id (:id thread) :content content}) (->> (rp/mutation :add-comment {:thread-id (:id thread) :content content})
(rx/map #(partial created %))) (rx/map #(partial created %)))
@ -145,7 +128,7 @@
(d/update-in-when state [:comments thread-id id] assoc :content content)) (d/update-in-when state [:comments thread-id id] assoc :content content))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/mutation :update-comment {:id id :content content}) (->> (rp/mutation :update-comment {:id id :content content})
(rx/ignore))))) (rx/ignore)))))
@ -160,7 +143,7 @@
(update :comment-threads dissoc id))) (update :comment-threads dissoc id)))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/mutation :delete-comment-thread {:id id}) (->> (rp/mutation :delete-comment-thread {:id id})
(rx/ignore))))) (rx/ignore)))))
@ -173,7 +156,7 @@
(d/update-in-when state [:comments thread-id] dissoc id)) (d/update-in-when state [:comments thread-id] dissoc id))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/mutation :delete-comment {:id id}) (->> (rp/mutation :delete-comment {:id id})
(rx/ignore))))) (rx/ignore)))))
@ -184,7 +167,7 @@
(assoc-in state [:comment-threads id] thread))] (assoc-in state [:comment-threads id] thread))]
(ptk/reify ::refresh-comment-thread (ptk/reify ::refresh-comment-thread
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/query :comment-thread {:file-id file-id :id id}) (->> (rp/query :comment-thread {:file-id file-id :id id})
(rx/map #(partial fetched %))))))) (rx/map #(partial fetched %)))))))
@ -195,7 +178,7 @@
(assoc state :comment-threads (d/index-by :id data)))] (assoc state :comment-threads (d/index-by :id data)))]
(ptk/reify ::retrieve-comment-threads (ptk/reify ::retrieve-comment-threads
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/query :comment-threads {:file-id file-id}) (->> (rp/query :comment-threads {:file-id file-id})
(rx/map #(partial fetched %))))))) (rx/map #(partial fetched %)))))))
@ -206,7 +189,7 @@
(update state :comments assoc thread-id (d/index-by :id comments)))] (update state :comments assoc thread-id (d/index-by :id comments)))]
(ptk/reify ::retrieve-comments (ptk/reify ::retrieve-comments
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/query :comments {:thread-id thread-id}) (->> (rp/query :comments {:thread-id thread-id})
(rx/map #(partial fetched %))))))) (rx/map #(partial fetched %)))))))
@ -216,7 +199,7 @@
(us/assert ::us/uuid team-id) (us/assert ::us/uuid team-id)
(ptk/reify ::retrieve-unread-comment-threads (ptk/reify ::retrieve-unread-comment-threads
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [fetched #(assoc %2 :comment-threads (d/index-by :id %1))] (let [fetched #(assoc %2 :comment-threads (d/index-by :id %1))]
(->> (rp/query :unread-comment-threads {:team-id team-id}) (->> (rp/query :unread-comment-threads {:team-id team-id})
(rx/map #(partial fetched %))))))) (rx/map #(partial fetched %)))))))
@ -320,7 +303,7 @@
(defn apply-filters (defn apply-filters
[cstate profile threads] [cstate profile threads]
(let [{:keys [show mode open]} cstate] (let [{:keys [show mode]} cstate]
(cond->> threads (cond->> threads
(= :pending show) (= :pending show)
(filter (comp not :is-resolved)) (filter (comp not :is-resolved))

View file

@ -7,23 +7,16 @@
(ns app.main.data.dashboard (ns app.main.data.dashboard
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.pages :as cp]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.main.repo :as rp]
[app.main.data.events :as ev]
[app.main.data.users :as du]
[app.main.data.fonts :as df] [app.main.data.fonts :as df]
[app.main.data.media :as di]
[app.main.data.users :as du]
[app.main.repo :as rp]
[app.util.i18n :as i18n :refer [tr]] [app.util.i18n :as i18n :refer [tr]]
[app.util.router :as rt] [app.util.router :as rt]
[app.util.time :as dt]
[app.util.timers :as ts]
[app.util.avatars :as avatars]
[app.main.data.media :as di]
[app.main.data.messages :as dm]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[cuerdas.core :as str]
[potok.core :as ptk])) [potok.core :as ptk]))
;; --- Specs ;; --- Specs
@ -44,13 +37,13 @@
::modified-at])) ::modified-at]))
(s/def ::project (s/def ::project
(s/keys ::req-un [::id (s/keys :req-un [::id
::name ::name
::team-id ::team-id
::profile-id ::profile-id
::created-at ::created-at
::modified-at ::modified-at
::is-pinned])) ::is-pinned]))
(s/def ::file (s/def ::file
(s/keys :req-un [::id (s/keys :req-un [::id
@ -109,7 +102,7 @@
[] []
(ptk/reify ::fetch-team-members (ptk/reify ::fetch-team-members
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(->> (rp/query :team-members {:team-id team-id}) (->> (rp/query :team-members {:team-id team-id})
(rx/map team-members-fetched)))))) (rx/map team-members-fetched))))))
@ -127,7 +120,7 @@
[] []
(ptk/reify ::fetch-team-stats (ptk/reify ::fetch-team-stats
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(->> (rp/query :team-stats {:team-id team-id}) (->> (rp/query :team-stats {:team-id team-id})
(rx/map team-stats-fetched)))))) (rx/map team-stats-fetched))))))
@ -146,7 +139,7 @@
[] []
(ptk/reify ::fetch-projects (ptk/reify ::fetch-projects
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(->> (rp/query :projects {:team-id team-id}) (->> (rp/query :projects {:team-id team-id})
(rx/map projects-fetched)))))) (rx/map projects-fetched))))))
@ -173,7 +166,7 @@
(dissoc state :dashboard-search-result)) (dissoc state :dashboard-search-result))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state) (let [team-id (:current-team-id state)
params (assoc params :team-id team-id)] params (assoc params :team-id team-id)]
(->> (rp/query :search-files params) (->> (rp/query :search-files params)
@ -202,7 +195,7 @@
(us/assert ::us/uuid project-id) (us/assert ::us/uuid project-id)
(ptk/reify ::fetch-files (ptk/reify ::fetch-files
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/query :project-files {:project-id project-id}) (->> (rp/query :project-files {:project-id project-id})
(rx/map #(files-fetched project-id %)))))) (rx/map #(files-fetched project-id %))))))
@ -219,7 +212,7 @@
[] []
(ptk/reify ::fetch-shared-files (ptk/reify ::fetch-shared-files
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(->> (rp/query :team-shared-files {:team-id team-id}) (->> (rp/query :team-shared-files {:team-id team-id})
(rx/map shared-files-fetched)))))) (rx/map shared-files-fetched))))))
@ -240,7 +233,7 @@
[] []
(ptk/reify ::fetch-recent-files (ptk/reify ::fetch-recent-files
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(->> (rp/query :team-recent-files {:team-id team-id}) (->> (rp/query :team-recent-files {:team-id team-id})
(rx/map recent-files-fetched)))))) (rx/map recent-files-fetched))))))
@ -293,7 +286,7 @@
(us/assert string? name) (us/assert string? name)
(ptk/reify ::create-team (ptk/reify ::create-team
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [{:keys [on-success on-error] (let [{:keys [on-success on-error]
:or {on-success identity :or {on-success identity
on-error rx/throw}} (meta params)] on-error rx/throw}} (meta params)]
@ -313,7 +306,7 @@
(assoc-in state [:teams id :name] name)) (assoc-in state [:teams id :name] name))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/mutation! :update-team params) (->> (rp/mutation! :update-team params)
(rx/ignore))))) (rx/ignore)))))
@ -322,7 +315,7 @@
(us/assert ::di/file file) (us/assert ::di/file file)
(ptk/reify ::update-team-photo (ptk/reify ::update-team-photo
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [on-success di/notify-finished-loading (let [on-success di/notify-finished-loading
on-error #(do (di/notify-finished-loading) on-error #(do (di/notify-finished-loading)
(di/process-error %)) (di/process-error %))
@ -344,7 +337,7 @@
(us/assert ::us/keyword role) (us/assert ::us/keyword role)
(ptk/reify ::update-team-member-role (ptk/reify ::update-team-member-role
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state) (let [team-id (:current-team-id state)
params (assoc params :team-id team-id)] params (assoc params :team-id team-id)]
(->> (rp/mutation! :update-team-member-role params) (->> (rp/mutation! :update-team-member-role params)
@ -357,7 +350,7 @@
(us/assert ::us/uuid member-id) (us/assert ::us/uuid member-id)
(ptk/reify ::delete-team-member (ptk/reify ::delete-team-member
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state) (let [team-id (:current-team-id state)
params (assoc params :team-id team-id)] params (assoc params :team-id team-id)]
(->> (rp/mutation! :delete-team-member params) (->> (rp/mutation! :delete-team-member params)
@ -370,7 +363,7 @@
(us/assert (s/nilable ::us/uuid) reassign-to) (us/assert (s/nilable ::us/uuid) reassign-to)
(ptk/reify ::leave-team (ptk/reify ::leave-team
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [{:keys [on-success on-error] (let [{:keys [on-success on-error]
:or {on-success identity :or {on-success identity
on-error rx/throw}} (meta params) on-error rx/throw}} (meta params)
@ -391,7 +384,7 @@
(us/assert ::us/keyword role) (us/assert ::us/keyword role)
(ptk/reify ::invite-team-member (ptk/reify ::invite-team-member
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [{:keys [on-success on-error] (let [{:keys [on-success on-error]
:or {on-success identity :or {on-success identity
on-error rx/throw}} (meta params) on-error rx/throw}} (meta params)
@ -408,7 +401,7 @@
(us/assert ::team params) (us/assert ::team params)
(ptk/reify ::delete-team (ptk/reify ::delete-team
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [{:keys [on-success on-error] (let [{:keys [on-success on-error]
:or {on-success identity :or {on-success identity
on-error rx/throw}} (meta params)] on-error rx/throw}} (meta params)]
@ -434,7 +427,7 @@
[] []
(ptk/reify ::create-project (ptk/reify ::create-project
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [name (name (gensym (str (tr "dashboard.new-project-prefix") " "))) (let [name (name (gensym (str (tr "dashboard.new-project-prefix") " ")))
team-id (:current-team-id state) team-id (:current-team-id state)
params {:name name params {:name name
@ -461,7 +454,7 @@
(us/assert ::us/uuid id) (us/assert ::us/uuid id)
(ptk/reify ::duplicate-project (ptk/reify ::duplicate-project
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [{:keys [on-success on-error] (let [{:keys [on-success on-error]
:or {on-success identity :or {on-success identity
on-error rx/throw}} (meta params) on-error rx/throw}} (meta params)
@ -480,7 +473,7 @@
(us/assert ::us/uuid team-id) (us/assert ::us/uuid team-id)
(ptk/reify ::move-project (ptk/reify ::move-project
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [{:keys [on-success on-error] (let [{:keys [on-success on-error]
:or {on-success identity :or {on-success identity
on-error rx/throw}} (meta params)] on-error rx/throw}} (meta params)]
@ -491,7 +484,7 @@
(rx/catch on-error)))))) (rx/catch on-error))))))
(defn toggle-project-pin (defn toggle-project-pin
[{:keys [id is-pinned team-id] :as project}] [{:keys [id is-pinned] :as project}]
(us/assert ::project project) (us/assert ::project project)
(ptk/reify ::toggle-project-pin (ptk/reify ::toggle-project-pin
ptk/UpdateEvent ptk/UpdateEvent
@ -499,7 +492,7 @@
(assoc-in state [:dashboard-projects id :is-pinned] (not is-pinned))) (assoc-in state [:dashboard-projects id :is-pinned] (not is-pinned)))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [project (get-in state [:dashboard-projects id]) (let [project (get-in state [:dashboard-projects id])
params (select-keys project [:id :is-pinned :team-id])] params (select-keys project [:id :is-pinned :team-id])]
(->> (rp/mutation :update-project-pin params) (->> (rp/mutation :update-project-pin params)
@ -508,7 +501,7 @@
;; --- EVENT: rename-project ;; --- EVENT: rename-project
(defn rename-project (defn rename-project
[{:keys [id name team-id] :as params}] [{:keys [id name] :as params}]
(us/assert ::project params) (us/assert ::project params)
(ptk/reify ::rename-project (ptk/reify ::rename-project
ptk/UpdateEvent ptk/UpdateEvent
@ -518,7 +511,7 @@
(update :dashboard-local dissoc :project-for-edit))) (update :dashboard-local dissoc :project-for-edit)))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [params {:id id :name name}] (let [params {:id id :name name}]
(->> (rp/mutation :rename-project params) (->> (rp/mutation :rename-project params)
(rx/ignore)))))) (rx/ignore))))))
@ -526,7 +519,7 @@
;; --- EVENT: delete-project ;; --- EVENT: delete-project
(defn delete-project (defn delete-project
[{:keys [id team-id] :as params}] [{:keys [id] :as params}]
(us/assert ::project params) (us/assert ::project params)
(ptk/reify ::delete-project (ptk/reify ::delete-project
ptk/UpdateEvent ptk/UpdateEvent
@ -534,14 +527,14 @@
(update state :dashboard-projects dissoc id)) (update state :dashboard-projects dissoc id))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state s] (watch [_ _ _]
(->> (rp/mutation :delete-project {:id id}) (->> (rp/mutation :delete-project {:id id})
(rx/ignore))))) (rx/ignore)))))
;; --- EVENT: delete-file ;; --- EVENT: delete-file
(defn file-deleted (defn file-deleted
[team-id project-id] [_team-id project-id]
(ptk/reify ::file-deleted (ptk/reify ::file-deleted
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
@ -558,7 +551,7 @@
(d/update-when :dashboard-recent-files dissoc id))) (d/update-when :dashboard-recent-files dissoc id)))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state s] (watch [_ state _]
(let [team-id (uuid/uuid (get-in state [:route :path-params :team-id]))] (let [team-id (uuid/uuid (get-in state [:route :path-params :team-id]))]
(->> (rp/mutation :delete-file {:id id}) (->> (rp/mutation :delete-file {:id id})
(rx/map #(file-deleted team-id project-id))))))) (rx/map #(file-deleted team-id project-id)))))))
@ -576,7 +569,7 @@
(d/update-in-when [:dashboard-recent-files id :name] (constantly name)))) (d/update-in-when [:dashboard-recent-files id :name] (constantly name))))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [params (select-keys params [:id :name])] (let [params (select-keys params [:id :name])]
(->> (rp/mutation :rename-file params) (->> (rp/mutation :rename-file params)
(rx/ignore)))))) (rx/ignore))))))
@ -594,7 +587,7 @@
(d/update-in-when [:dashboard-recent-files id :is-shared] (constantly is-shared)))) (d/update-in-when [:dashboard-recent-files id :is-shared] (constantly is-shared))))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [params {:id id :is-shared is-shared}] (let [params {:id id :is-shared is-shared}]
(->> (rp/mutation :set-file-shared params) (->> (rp/mutation :set-file-shared params)
(rx/ignore)))))) (rx/ignore))))))
@ -621,7 +614,7 @@
(us/assert ::us/uuid project-id) (us/assert ::us/uuid project-id)
(ptk/reify ::create-file (ptk/reify ::create-file
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [{:keys [on-success on-error] (let [{:keys [on-success on-error]
:or {on-success identity :or {on-success identity
on-error rx/throw}} (meta params) on-error rx/throw}} (meta params)
@ -642,7 +635,7 @@
(us/assert ::name name) (us/assert ::name name)
(ptk/reify ::duplicate-file (ptk/reify ::duplicate-file
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [{:keys [on-success on-error] (let [{:keys [on-success on-error]
:or {on-success identity :or {on-success identity
on-error rx/throw}} (meta params) on-error rx/throw}} (meta params)
@ -663,7 +656,7 @@
(us/assert ::us/uuid project-id) (us/assert ::us/uuid project-id)
(ptk/reify ::move-files (ptk/reify ::move-files
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [{:keys [on-success on-error] (let [{:keys [on-success on-error]
:or {on-success identity :or {on-success identity
on-error rx/throw}} (meta params)] on-error rx/throw}} (meta params)]
@ -682,7 +675,7 @@
(us/assert ::file file) (us/assert ::file file)
(ptk/reify ::go-to-workspace (ptk/reify ::go-to-workspace
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [pparams {:project-id project-id :file-id id}] (let [pparams {:project-id project-id :file-id id}]
(rx/of (rt/nav :workspace pparams)))))) (rx/of (rt/nav :workspace pparams))))))
@ -691,14 +684,14 @@
([project-id] ([project-id]
(ptk/reify ::go-to-files (ptk/reify ::go-to-files
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(rx/of (rt/nav :dashboard-files {:team-id team-id (rx/of (rt/nav :dashboard-files {:team-id team-id
:project-id project-id})))))) :project-id project-id}))))))
([team-id project-id] ([team-id project-id]
(ptk/reify ::go-to-files (ptk/reify ::go-to-files
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(rx/of (rt/nav :dashboard-files {:team-id team-id (rx/of (rt/nav :dashboard-files {:team-id team-id
:project-id project-id})))))) :project-id project-id}))))))
@ -707,7 +700,7 @@
([term] ([term]
(ptk/reify ::go-to-search (ptk/reify ::go-to-search
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(if (empty? term) (if (empty? term)
(rx/of (rt/nav :dashboard-search (rx/of (rt/nav :dashboard-search
@ -720,13 +713,13 @@
([] ([]
(ptk/reify ::go-to-projects (ptk/reify ::go-to-projects
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(rx/of (rt/nav :dashboard-projects {:team-id team-id})))))) (rx/of (rt/nav :dashboard-projects {:team-id team-id}))))))
([team-id] ([team-id]
(ptk/reify ::go-to-projects (ptk/reify ::go-to-projects
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(du/set-current-team! team-id) (du/set-current-team! team-id)
(rx/of (rt/nav :dashboard-projects {:team-id team-id})))))) (rx/of (rt/nav :dashboard-projects {:team-id team-id}))))))
@ -734,7 +727,7 @@
[] []
(ptk/reify ::go-to-team-members (ptk/reify ::go-to-team-members
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(rx/of (rt/nav :dashboard-team-members {:team-id team-id})))))) (rx/of (rt/nav :dashboard-team-members {:team-id team-id}))))))
@ -742,6 +735,6 @@
[] []
(ptk/reify ::go-to-team-settings (ptk/reify ::go-to-team-settings
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(rx/of (rt/nav :dashboard-team-settings {:team-id team-id})))))) (rx/of (rt/nav :dashboard-team-settings {:team-id team-id}))))))

View file

@ -8,14 +8,14 @@
(:require (:require
["ua-parser-js" :as UAParser] ["ua-parser-js" :as UAParser]
[app.common.data :as d] [app.common.data :as d]
[app.main.repo :as rp]
[app.config :as cf] [app.config :as cf]
[app.main.repo :as rp]
[app.util.globals :as g] [app.util.globals :as g]
[app.util.http :as http] [app.util.http :as http]
[app.util.i18n :as i18n]
[app.util.object :as obj] [app.util.object :as obj]
[app.util.storage :refer [storage]] [app.util.storage :refer [storage]]
[app.util.time :as dt] [app.util.time :as dt]
[app.util.i18n :as i18n]
[beicon.core :as rx] [beicon.core :as rx]
[lambdaisland.uri :as u] [lambdaisland.uri :as u]
[potok.core :as ptk])) [potok.core :as ptk]))
@ -139,7 +139,7 @@
:project-id (:project-id data)}})) :project-id (:project-id data)}}))
(defn- event->generic-action (defn- event->generic-action
[event name] [_ name]
{:type "action" {:type "action"
:name name :name name
:props {}}) :props {}})
@ -176,7 +176,7 @@
[_ {:keys [buffer] :as params}] [_ {:keys [buffer] :as params}]
(ptk/reify ::persistence (ptk/reify ::persistence
ptk/EffectEvent ptk/EffectEvent
(effect [_ state stream] (effect [_ state _]
(let [profile-id (:profile-id state) (let [profile-id (:profile-id state)
events (into [] (take max-buffer-size) @buffer)] events (into [] (take max-buffer-size) @buffer)]
(when (seq events) (when (seq events)
@ -191,7 +191,7 @@
(let [buffer (atom #queue [])] (let [buffer (atom #queue [])]
(ptk/reify ::initialize (ptk/reify ::initialize
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ stream]
(->> (rx/merge (->> (rx/merge
(->> (rx/from-atom buffer) (->> (rx/from-atom buffer)
(rx/filter #(pos? (count %))) (rx/filter #(pos? (count %)))
@ -202,7 +202,7 @@
(rx/map #(ptk/event ::persistence {:buffer buffer})))) (rx/map #(ptk/event ::persistence {:buffer buffer}))))
ptk/EffectEvent ptk/EffectEvent
(effect [_ state stream] (effect [_ _ stream]
(let [events (methods process-event) (let [events (methods process-event)
session (atom nil) session (atom nil)

View file

@ -8,16 +8,14 @@
(:require (:require
["opentype.js" :as ot] ["opentype.js" :as ot]
[app.common.data :as d] [app.common.data :as d]
[app.common.spec :as us]
[app.common.media :as cm] [app.common.media :as cm]
[app.common.spec :as us]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.main.fonts :as fonts] [app.main.fonts :as fonts]
[app.main.repo :as rp] [app.main.repo :as rp]
[app.util.i18n :as i18n :refer [tr]]
[app.util.logging :as log] [app.util.logging :as log]
[beicon.core :as rx]
[cljs.spec.alpha :as s]
[app.util.webapi :as wa] [app.util.webapi :as wa]
[beicon.core :as rx]
[cuerdas.core :as str] [cuerdas.core :as str]
[potok.core :as ptk])) [potok.core :as ptk]))
@ -62,7 +60,7 @@
(assoc state :dashboard-fonts (d/index-by :id fonts))) (assoc state :dashboard-fonts (d/index-by :id fonts)))
ptk/EffectEvent ptk/EffectEvent
(effect [_ state stream] (effect [_ _ _]
(let [fonts (->> fonts (let [fonts (->> fonts
(map adapt-font-id) (map adapt-font-id)
(group-by :font-id) (group-by :font-id)
@ -73,7 +71,7 @@
[team-id] [team-id]
(ptk/reify ::load-team-fonts (ptk/reify ::load-team-fonts
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/query :font-variants {:team-id team-id}) (->> (rp/query :font-variants {:team-id team-id})
(rx/map fonts-fetched))))) (rx/map fonts-fetched)))))
@ -121,7 +119,7 @@
(parse-font [{:keys [data] :as params}] (parse-font [{:keys [data] :as params}]
(try (try
(assoc params :font (ot/parse data)) (assoc params :font (ot/parse data))
(catch :default e (catch :default _e
(log/warn :msg (str/fmt "skiping file %s, unsupported format" (:name params))) (log/warn :msg (str/fmt "skiping file %s, unsupported format" (:name params)))
nil))) nil)))
@ -204,7 +202,7 @@
fonts)))) fonts))))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(->> (rp/mutation! :update-font {:id id :name name :team-id team-id}) (->> (rp/mutation! :update-font {:id id :name name :team-id team-id})
(rx/ignore)))))) (rx/ignore))))))
@ -218,10 +216,10 @@
(update [_ state] (update [_ state]
(update state :dashboard-fonts (update state :dashboard-fonts
(fn [variants] (fn [variants]
(d/removem (fn [[id variant]] (d/removem (fn [[_id variant]]
(= (:font-id variant) font-id)) variants)))) (= (:font-id variant) font-id)) variants))))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(->> (rp/mutation! :delete-font {:id font-id :team-id team-id}) (->> (rp/mutation! :delete-font {:id font-id :team-id team-id})
(rx/ignore)))))) (rx/ignore))))))
@ -238,7 +236,7 @@
(= (:id variant) id)) (= (:id variant) id))
variants)))) variants))))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(->> (rp/mutation! :delete-font-variant {:id id :team-id team-id}) (->> (rp/mutation! :delete-font-variant {:id id :team-id team-id})
(rx/ignore)))))) (rx/ignore))))))

View file

@ -1,270 +0,0 @@
;; 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) UXBOX Labs SL
(ns app.main.data.history
(:require
[beicon.core :as rx]
[cljs.spec.alpha :as s]
[potok.core :as ptk]
[app.common.spec :as us]
[app.common.pages :as cp]
[app.main.repo :as rp]
[app.util.data :refer [replace-by-id index-by]]))
;; --- Schema
(s/def ::pinned boolean?)
(s/def ::id uuid?)
(s/def ::label string?)
(s/def ::project uuid?)
(s/def ::created-at inst?)
(s/def ::modified-at inst?)
(s/def ::version number?)
(s/def ::user uuid?)
(s/def ::shapes
(s/every ::cp/minimal-shape :kind vector?))
(s/def ::data
(s/keys :req-un [::shapes]))
(s/def ::history-entry
(s/keys :req-un [::id
::pinned
::label
::project
::created-at
::modified-at
::version
::user
::data]))
(s/def ::history-entries
(s/every ::history-entry))
;; --- Initialize History State
(declare fetch-history)
(declare fetch-pinned-history)
(defn initialize
[id]
(us/verify ::us/uuid id)
(ptk/reify ::initialize
ptk/UpdateEvent
(update [_ state]
(update-in state [:workspace id]
assoc :history {:selected nil
:pinned #{}
:items #{}
:byver {}}))
ptk/WatchEvent
(watch [_ state stream]
(rx/of (fetch-history id)
(fetch-pinned-history id)))))
;; --- Watch Page Changes
(defn watch-page-changes
[id]
(us/verify ::us/uuid id)
(reify
ptk/WatchEvent
(watch [_ state stream]
#_(let [stopper (rx/filter #(= % ::stop-page-watcher) stream)]
(->> stream
(rx/filter dp/page-persisted?)
(rx/debounce 1000)
(rx/flat-map #(rx/of (fetch-history id)
(fetch-pinned-history id)))
(rx/take-until stopper))))))
;; --- Pinned Page History Fetched
(defn pinned-history-fetched
[items]
(us/verify ::history-entries items)
(ptk/reify ::pinned-history-fetched
ptk/UpdateEvent
(update [_ state]
(let [pid (get-in state [:workspace :current])
items-map (index-by :version items)
items-set (into #{} items)]
(update-in state [:workspace pid :history]
(fn [history]
(-> history
(assoc :pinned items-set)
(update :byver merge items-map))))))))
;; --- Fetch Pinned Page History
(defn fetch-pinned-history
[id]
(us/verify ::us/uuid id)
(ptk/reify ::fetch-pinned-history
ptk/WatchEvent
(watch [_ state s]
(let [params {:page id :pinned true}]
#_(->> (rp/req :fetch/page-history params)
(rx/map :payload)
(rx/map pinned-history-fetched))))))
;; --- Page History Fetched
(defn history-fetched
[items]
(us/verify ::history-entries items)
(ptk/reify ::history-fetched
ptk/UpdateEvent
(update [_ state]
(let [pid (get-in state [:workspace :current])
versions (into #{} (map :version) items)
items-map (index-by :version items)
min-version (apply min versions)
max-version (apply max versions)]
(update-in state [:workspace pid :history]
(fn [history]
(-> history
(assoc :min-version min-version)
(assoc :max-version max-version)
(update :byver merge items-map)
(update :items #(reduce conj % items)))))))))
;; --- Fetch Page History
(defn fetch-history
([id]
(fetch-history id nil))
([id {:keys [since max]}]
(us/verify ::us/uuid id)
(ptk/reify ::fetch-history
ptk/WatchEvent
(watch [_ state s]
(let [params (merge {:page id
:max (or max 20)}
(when since
{:since since}))]
#_(->> (rp/req :fetch/page-history params)
(rx/map :payload)
(rx/map history-fetched)))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Context Aware Events
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; --- Select Section
(deftype SelectSection [section]
ptk/UpdateEvent
(update [_ state]
(assoc-in state [:workspace :history :section] section)))
(defn select-section
[section]
{:pre [(keyword? section)]}
(SelectSection. section))
;; --- Load More
(def load-more
(ptk/reify ::load-more
ptk/WatchEvent
(watch [_ state stream]
(let [pid (get-in state [:workspace :current])
since (get-in state [:workspace pid :history :min-version])]
(rx/of (fetch-history pid {:since since}))))))
;; --- Select Page History
(defn select
[version]
(us/verify int? version)
(ptk/reify ::select
ptk/UpdateEvent
(update [_ state]
#_(let [pid (get-in state [:workspace :current])
item (get-in state [:workspace pid :history :byver version])
page (-> (get-in state [:pages pid])
(assoc :history true
:data (:data item)))]
(-> state
(dp/unpack-page page)
(assoc-in [:workspace pid :history :selected] version))))))
;; --- Apply Selected History
(def apply-selected
(ptk/reify ::apply-selected
ptk/UpdateEvent
(update [_ state]
(let [pid (get-in state [:workspace :current])]
(-> state
(update-in [:pages pid] dissoc :history)
(assoc-in [:workspace pid :history :selected] nil))))
ptk/WatchEvent
(watch [_ state s]
#_(let [pid (get-in state [:workspace :current])]
(rx/of (dp/persist-page pid))))))
;; --- Deselect Page History
(def deselect
(ptk/reify ::deselect
ptk/UpdateEvent
(update [_ state]
#_(let [pid (get-in state [:workspace :current])
packed (get-in state [:packed-pages pid])]
(-> (dp/unpack-page state packed)
(assoc-in [:workspace pid :history :selected] nil))))))
;; --- Refresh Page History
(def refres-history
(ptk/reify ::refresh-history
ptk/WatchEvent
(watch [_ state stream]
(let [pid (get-in state [:workspace :current])
history (get-in state [:workspace pid :history])
maxitems (count (:items history))]
(rx/of (fetch-history pid {:max maxitems})
(fetch-pinned-history pid))))))
;; --- History Item Updated
(defn history-updated
[item]
(us/verify ::history-entry item)
(ptk/reify ::history-item-updated
ptk/UpdateEvent
(update [_ state]
(let [pid (get-in state [:workspace :current])]
(update-in state [:workspace pid :history]
(fn [history]
(-> history
(update :items #(into #{} (replace-by-id item) %))
(update :pinned #(into #{} (replace-by-id item) %))
(assoc-in [:byver (:version item)] item))))))))
(defn history-updated?
[v]
(= ::history-item-updated (ptk/type v)))
;; --- Update History Item
(defn update-history-item
[item]
(ptk/reify ::update-history-item
ptk/WatchEvent
(watch [_ state stream]
(rx/concat
#_(->> (rp/req :update/page-history item)
(rx/map :payload)
(rx/map history-updated))
(->> (rx/filter history-updated? stream)
(rx/take 1)
(rx/map (constantly refres-history)))))))

View file

@ -6,22 +6,14 @@
(ns app.main.data.media (ns app.main.data.media
(:require (:require
[app.common.data :as d]
[app.common.media :as cm]
[app.common.spec :as us]
[app.common.uuid :as uuid]
[app.common.exceptions :as ex] [app.common.exceptions :as ex]
[app.common.media :as cm]
[app.main.data.messages :as dm] [app.main.data.messages :as dm]
[app.main.repo :as rp]
[app.main.store :as st] [app.main.store :as st]
[app.util.i18n :refer [tr]] [app.util.i18n :refer [tr]]
[app.util.router :as r]
[app.util.router :as rt]
[app.util.time :as ts]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[cuerdas.core :as str] [cuerdas.core :as str]))
[potok.core :as ptk]))
;; --- Predicates ;; --- Predicates

View file

@ -7,10 +7,7 @@
(ns app.main.data.messages (ns app.main.data.messages
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.exceptions :as ex]
[app.common.pages :as cp]
[app.common.spec :as us] [app.common.spec :as us]
[app.config :as cfg]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[potok.core :as ptk])) [potok.core :as ptk]))
@ -54,7 +51,7 @@
(assoc state :message message))) (assoc state :message message)))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ stream]
(when (:timeout data) (when (:timeout data)
(let [stoper (rx/filter (ptk/type? ::show) stream)] (let [stoper (rx/filter (ptk/type? ::show) stream)]
(->> (rx/of hide) (->> (rx/of hide)
@ -68,7 +65,7 @@
(d/update-when state :message assoc :status :hide)) (d/update-when state :message assoc :status :hide))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ stream]
(let [stoper (rx/filter (ptk/type? ::show) stream)] (let [stoper (rx/filter (ptk/type? ::show) stream)]
(->> (rx/of #(dissoc % :message)) (->> (rx/of #(dissoc % :message))
(rx/delay default-animation-timeout) (rx/delay default-animation-timeout)
@ -78,7 +75,7 @@
[tag] [tag]
(ptk/reify ::hide-tag (ptk/reify ::hide-tag
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [message (get state :message)] (let [message (get state :message)]
(when (= (:tag message) tag) (when (= (:tag message) tag)
(rx/of hide)))))) (rx/of hide))))))
@ -127,7 +124,7 @@
:tag tag}))) :tag tag})))
(defn assign-exception (defn assign-exception
[{:keys [type] :as error}] [error]
(ptk/reify ::assign-exception (ptk/reify ::assign-exception
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]

View file

@ -7,10 +7,10 @@
(ns app.main.data.modal (ns app.main.data.modal
(:refer-clojure :exclude [update]) (:refer-clojure :exclude [update])
(:require (:require
[potok.core :as ptk]
[app.main.store :as st]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[cljs.core :as c])) [app.main.store :as st]
[cljs.core :as c]
[potok.core :as ptk]))
(defonce components (atom {})) (defonce components (atom {}))
@ -29,7 +29,7 @@
:allow-click-outside false}))))) :allow-click-outside false})))))
(defn update-props (defn update-props
([type props] ([_type props]
(ptk/reify ::update-modal-props (ptk/reify ::update-modal-props
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]

View file

@ -8,7 +8,6 @@
(:refer-clojure :exclude [meta reset!]) (:refer-clojure :exclude [meta reset!])
(:require (:require
["mousetrap" :as mousetrap] ["mousetrap" :as mousetrap]
[app.common.data :as d]
[app.common.spec :as us] [app.common.spec :as us]
[app.config :as cfg] [app.config :as cfg]
[app.util.logging :as log] [app.util.logging :as log]
@ -164,8 +163,8 @@
(update :shortcuts (fnil conj '()) [key shortcuts]))) (update :shortcuts (fnil conj '()) [key shortcuts])))
ptk/EffectEvent ptk/EffectEvent
(effect [_ state stream] (effect [_ state _]
(let [[key shortcuts] (peek (:shortcuts state))] (let [[_key shortcuts] (peek (:shortcuts state))]
(reset! shortcuts))))) (reset! shortcuts)))))
(defn pop-shortcuts (defn pop-shortcuts
@ -179,7 +178,7 @@
(pop shortcuts) (pop shortcuts)
shortcuts))))) shortcuts)))))
ptk/EffectEvent ptk/EffectEvent
(effect [_ state stream] (effect [_ state _]
(let [[key* shortcuts] (peek (:shortcuts state))] (let [[key* shortcuts] (peek (:shortcuts state))]
(when (not= key key*) (when (not= key key*)
(reset! shortcuts)))))) (reset! shortcuts))))))

View file

@ -6,24 +6,20 @@
(ns app.main.data.users (ns app.main.data.users
(:require (:require
[app.config :as cf]
[app.common.data :as d] [app.common.data :as d]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.config :as cf]
[app.main.data.events :as ev] [app.main.data.events :as ev]
[app.main.data.media :as di] [app.main.data.media :as di]
[app.main.data.modal :as modal] [app.main.data.modal :as modal]
[app.main.data.messages :as dm]
[app.main.repo :as rp] [app.main.repo :as rp]
[app.main.store :as st] [app.util.i18n :as i18n]
[app.util.avatars :as avatars]
[app.util.i18n :as i18n :refer [tr]]
[app.util.router :as rt] [app.util.router :as rt]
[app.util.storage :refer [storage]] [app.util.storage :refer [storage]]
[app.util.theme :as theme] [app.util.theme :as theme]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[cuerdas.core :as str]
[potok.core :as ptk])) [potok.core :as ptk]))
;; --- COMMON SPECS ;; --- COMMON SPECS
@ -75,7 +71,7 @@
[] []
(ptk/reify ::fetch-teams (ptk/reify ::fetch-teams
ptk/WatchEvent ptk/WatchEvent
(watch [_ state s] (watch [_ _ _]
(->> (rp/query! :teams) (->> (rp/query! :teams)
(rx/map teams-fetched))))) (rx/map teams-fetched)))))
@ -95,7 +91,7 @@
(assoc :profile profile))) (assoc :profile profile)))
ptk/EffectEvent ptk/EffectEvent
(effect [_ state stream] (effect [_ state _]
(let [profile (:profile state)] (let [profile (:profile state)]
(when (not= uuid/zero (:id profile)) (when (not= uuid/zero (:id profile))
(swap! storage assoc :profile profile) (swap! storage assoc :profile profile)
@ -107,7 +103,7 @@
[] []
(ptk/reify ::fetch-profile (ptk/reify ::fetch-profile
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/query! :profile) (->> (rp/query! :profile)
(rx/map profile-fetched))))) (rx/map profile-fetched)))))
@ -120,7 +116,7 @@
[] []
(ptk/reify ::initialize-profile (ptk/reify ::initialize-profile
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ stream]
(rx/merge (rx/merge
(rx/of (fetch-profile)) (rx/of (fetch-profile))
(->> stream (->> stream
@ -141,7 +137,7 @@
(-deref [_] profile) (-deref [_] profile)
ptk/WatchEvent ptk/WatchEvent
(watch [this state stream] (watch [_ _ _]
(let [team-id (get-current-team-id profile) (let [team-id (get-current-team-id profile)
profile (with-meta profile profile (with-meta profile
{::ev/source "login"})] {::ev/source "login"})]
@ -166,7 +162,7 @@
(us/verify ::login-params data) (us/verify ::login-params data)
(ptk/reify ::login (ptk/reify ::login
ptk/WatchEvent ptk/WatchEvent
(watch [this state s] (watch [_ _ _]
(let [{:keys [on-error on-success] (let [{:keys [on-error on-success]
:or {on-error rx/throw :or {on-error rx/throw
on-success identity}} (meta data) on-success identity}} (meta data)
@ -186,7 +182,7 @@
[{:keys [profile] :as tdata}] [{:keys [profile] :as tdata}]
(ptk/reify ::login-from-token (ptk/reify ::login-from-token
ptk/WatchEvent ptk/WatchEvent
(watch [this state s] (watch [_ _ _]
(rx/of (logged-in (rx/of (logged-in
(with-meta profile (with-meta profile
{::ev/source "login-with-token"})))))) {::ev/source "login-with-token"}))))))
@ -201,11 +197,11 @@
(select-keys state [:route :router :session-id :history])) (select-keys state [:route :router :session-id :history]))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state s] (watch [_ _ _]
(rx/of (rt/nav :auth-login))) (rx/of (rt/nav :auth-login)))
ptk/EffectEvent ptk/EffectEvent
(effect [_ state s] (effect [_ _ _]
(reset! storage {}) (reset! storage {})
(i18n/reset-locale)))) (i18n/reset-locale))))
@ -213,7 +209,7 @@
[] []
(ptk/reify ::logout (ptk/reify ::logout
ptk/WatchEvent ptk/WatchEvent
(watch [_ state s] (watch [_ _ _]
(->> (rp/mutation :logout) (->> (rp/mutation :logout)
(rx/delay-at-least 300) (rx/delay-at-least 300)
(rx/catch (constantly (rx/of 1))) (rx/catch (constantly (rx/of 1)))
@ -234,7 +230,7 @@
(s/assert ::register data) (s/assert ::register data)
(ptk/reify ::register (ptk/reify ::register
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [{:keys [on-error on-success] (let [{:keys [on-error on-success]
:or {on-error identity :or {on-error identity
on-success identity}} (meta data)] on-success identity}} (meta data)]
@ -249,7 +245,7 @@
(us/assert ::profile data) (us/assert ::profile data)
(ptk/reify ::update-profile (ptk/reify ::update-profile
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ stream]
(let [mdata (meta data) (let [mdata (meta data)
on-success (:on-success mdata identity) on-success (:on-success mdata identity)
on-error (:on-error mdata #(rx/throw %))] on-error (:on-error mdata #(rx/throw %))]
@ -273,7 +269,7 @@
(us/assert ::us/email email) (us/assert ::us/email email)
(ptk/reify ::request-email-change (ptk/reify ::request-email-change
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [{:keys [on-error on-success] (let [{:keys [on-error on-success]
:or {on-error identity :or {on-error identity
on-success identity}} (meta data)] on-success identity}} (meta data)]
@ -286,7 +282,7 @@
(def cancel-email-change (def cancel-email-change
(ptk/reify ::cancel-email-change (ptk/reify ::cancel-email-change
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/mutation :cancel-email-change {}) (->> (rp/mutation :cancel-email-change {})
(rx/map (constantly (fetch-profile))))))) (rx/map (constantly (fetch-profile)))))))
@ -302,7 +298,7 @@
(us/verify ::update-password data) (us/verify ::update-password data)
(ptk/reify ::update-password (ptk/reify ::update-password
ptk/WatchEvent ptk/WatchEvent
(watch [_ state s] (watch [_ _ _]
(let [{:keys [on-error on-success] (let [{:keys [on-error on-success]
:or {on-error identity :or {on-error identity
on-success identity}} (meta data) on-success identity}} (meta data)
@ -321,7 +317,7 @@
([{:keys [version]}] ([{:keys [version]}]
(ptk/reify ::mark-oboarding-as-viewed (ptk/reify ::mark-oboarding-as-viewed
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [version (or version (:main @cf/version)) (let [version (or version (:main @cf/version))
props (-> (get-in state [:profile :props]) props (-> (get-in state [:profile :props])
(assoc :onboarding-viewed true) (assoc :onboarding-viewed true)
@ -336,7 +332,7 @@
(us/verify ::di/blob file) (us/verify ::di/blob file)
(ptk/reify ::update-photo (ptk/reify ::update-photo
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [on-success di/notify-finished-loading (let [on-success di/notify-finished-loading
on-error #(do (di/notify-finished-loading) on-error #(do (di/notify-finished-loading)
(di/process-error %)) (di/process-error %))
@ -364,7 +360,7 @@
(assoc state :users)))] (assoc state :users)))]
(ptk/reify ::fetch-team-users (ptk/reify ::fetch-team-users
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/query :team-users {:team-id team-id}) (->> (rp/query :team-users {:team-id team-id})
(rx/map #(partial fetched %))))))) (rx/map #(partial fetched %)))))))
@ -374,7 +370,7 @@
[params] [params]
(ptk/reify ::request-account-deletion (ptk/reify ::request-account-deletion
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [{:keys [on-error on-success] (let [{:keys [on-error on-success]
:or {on-error rx/throw :or {on-error rx/throw
on-success identity}} (meta params)] on-success identity}} (meta params)]
@ -395,7 +391,7 @@
(us/verify ::request-profile-recovery data) (us/verify ::request-profile-recovery data)
(ptk/reify ::request-profile-recovery (ptk/reify ::request-profile-recovery
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [{:keys [on-error on-success] (let [{:keys [on-error on-success]
:or {on-error rx/throw :or {on-error rx/throw
on-success identity}} (meta data)] on-success identity}} (meta data)]
@ -411,19 +407,17 @@
(s/keys :req-un [::password ::token])) (s/keys :req-un [::password ::token]))
(defn recover-profile (defn recover-profile
[{:keys [token password] :as data}] [data]
(us/verify ::recover-profile data) (us/verify ::recover-profile data)
(ptk/reify ::recover-profile (ptk/reify ::recover-profile
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [{:keys [on-error on-success] (let [{:keys [on-error on-success]
:or {on-error rx/throw :or {on-error rx/throw
on-success identity}} (meta data)] on-success identity}} (meta data)]
(->> (rp/mutation :recover-profile data) (->> (rp/mutation :recover-profile data)
(rx/tap on-success) (rx/tap on-success)
(rx/catch (fn [err] (rx/catch on-error))))))
(on-error)
(rx/empty))))))))
;; --- EVENT: crete-demo-profile ;; --- EVENT: crete-demo-profile
@ -431,7 +425,7 @@
[] []
(ptk/reify ::create-demo-profile (ptk/reify ::create-demo-profile
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/mutation :create-demo-profile {}) (->> (rp/mutation :create-demo-profile {})
(rx/map login))))) (rx/map login)))))

View file

@ -7,7 +7,6 @@
(ns app.main.data.viewer (ns app.main.data.viewer
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.exceptions :as ex]
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
@ -15,8 +14,6 @@
[app.main.data.comments :as dcm] [app.main.data.comments :as dcm]
[app.main.data.fonts :as df] [app.main.data.fonts :as df]
[app.main.repo :as rp] [app.main.repo :as rp]
[app.main.store :as st]
[app.util.avatars :as avatars]
[app.util.router :as rt] [app.util.router :as rt]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
@ -27,7 +24,7 @@
(s/def ::id ::us/uuid) (s/def ::id ::us/uuid)
(s/def ::name ::us/string) (s/def ::name ::us/string)
(s/def ::project (s/keys ::req-un [::id ::name])) (s/def ::project (s/keys :req-un [::id ::name]))
(s/def ::file (s/keys :req-un [::id ::name])) (s/def ::file (s/keys :req-un [::id ::name]))
(s/def ::page ::cp/page) (s/def ::page ::cp/page)
@ -60,10 +57,10 @@
(s/def ::initialize-params (s/def ::initialize-params
(s/keys :req-un [::page-id ::file-id] (s/keys :req-un [::page-id ::file-id]
:opt-in [::token])) :opt-un [::token]))
(defn initialize (defn initialize
[{:keys [page-id file-id token] :as params}] [{:keys [page-id file-id] :as params}]
(us/assert ::initialize-params params) (us/assert ::initialize-params params)
(ptk/reify ::initialize (ptk/reify ::initialize
ptk/UpdateEvent ptk/UpdateEvent
@ -78,7 +75,7 @@
lstate))))) lstate)))))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(rx/of (fetch-bundle params) (rx/of (fetch-bundle params)
(fetch-comment-threads params))))) (fetch-comment-threads params)))))
@ -86,14 +83,14 @@
(s/def ::fetch-bundle-params (s/def ::fetch-bundle-params
(s/keys :req-un [::page-id ::file-id] (s/keys :req-un [::page-id ::file-id]
:opt-in [::token])) :opt-un [::token]))
(defn fetch-bundle (defn fetch-bundle
[{:keys [page-id file-id token] :as params}] [{:keys [page-id file-id token] :as params}]
(us/assert ::fetch-bundle-params params) (us/assert ::fetch-bundle-params params)
(ptk/reify ::fetch-file (ptk/reify ::fetch-file
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [params (cond-> {:page-id page-id (let [params (cond-> {:page-id page-id
:file-id file-id} :file-id file-id}
(string? token) (assoc :token token))] (string? token) (assoc :token token))]
@ -145,7 +142,7 @@
(ptk/reify ::fetch-comment-threads (ptk/reify ::fetch-comment-threads
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/query :comment-threads {:file-id file-id}) (->> (rp/query :comment-threads {:file-id file-id})
(rx/map #(partial fetched %)) (rx/map #(partial fetched %))
(rx/catch on-error)))))) (rx/catch on-error))))))
@ -156,7 +153,7 @@
(assoc-in state [:comment-threads id] thread))] (assoc-in state [:comment-threads id] thread))]
(ptk/reify ::refresh-comment-thread (ptk/reify ::refresh-comment-thread
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/query :comment-thread {:file-id file-id :id id}) (->> (rp/query :comment-thread {:file-id file-id :id id})
(rx/map #(partial fetched %))))))) (rx/map #(partial fetched %)))))))
@ -167,7 +164,7 @@
(update state :comments assoc thread-id (d/index-by :id comments)))] (update state :comments assoc thread-id (d/index-by :id comments)))]
(ptk/reify ::retrieve-comments (ptk/reify ::retrieve-comments
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/query :comments {:thread-id thread-id}) (->> (rp/query :comments {:thread-id thread-id})
(rx/map #(partial fetched %))))))) (rx/map #(partial fetched %)))))))
@ -175,7 +172,7 @@
[] []
(ptk/reify ::create-share-link (ptk/reify ::create-share-link
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [file-id (:current-file-id state) (let [file-id (:current-file-id state)
page-id (:current-page-id state)] page-id (:current-page-id state)]
(->> (rp/mutation! :create-file-share-token {:file-id file-id (->> (rp/mutation! :create-file-share-token {:file-id file-id
@ -187,7 +184,7 @@
[] []
(ptk/reify ::delete-share-link (ptk/reify ::delete-share-link
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [file-id (:current-file-id state) (let [file-id (:current-file-id state)
page-id (:current-page-id state) page-id (:current-page-id state)
token (get-in state [:viewer-data :token]) token (get-in state [:viewer-data :token])
@ -246,7 +243,7 @@
(def select-prev-frame (def select-prev-frame
(ptk/reify ::select-prev-frame (ptk/reify ::select-prev-frame
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [route (:route state) (let [route (:route state)
screen (-> route :data :name keyword) screen (-> route :data :name keyword)
qparams (:query-params route) qparams (:query-params route)
@ -260,7 +257,7 @@
(def select-next-frame (def select-next-frame
(ptk/reify ::select-prev-frame (ptk/reify ::select-prev-frame
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [route (:route state) (let [route (:route state)
screen (-> route :data :name keyword) screen (-> route :data :name keyword)
qparams (:query-params route) qparams (:query-params route)
@ -296,7 +293,7 @@
(assoc-in state [:viewer-local :interactions-show?] true)) (assoc-in state [:viewer-local :interactions-show?] true))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ stream]
(let [stopper (rx/filter (ptk/type? ::flash-interactions) stream)] (let [stopper (rx/filter (ptk/type? ::flash-interactions) stream)]
(->> (rx/of flash-done) (->> (rx/of flash-done)
(rx/delay 500) (rx/delay 500)
@ -314,7 +311,7 @@
[index] [index]
(ptk/reify ::go-to-frame (ptk/reify ::go-to-frame
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [route (:route state) (let [route (:route state)
screen (-> route :data :name keyword) screen (-> route :data :name keyword)
qparams (:query-params route) qparams (:query-params route)
@ -326,7 +323,7 @@
(us/verify ::us/uuid frame-id) (us/verify ::us/uuid frame-id)
(ptk/reify ::go-to-frame (ptk/reify ::go-to-frame
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [frames (get-in state [:viewer-data :frames]) (let [frames (get-in state [:viewer-data :frames])
index (d/index-of-pred frames #(= (:id %) frame-id))] index (d/index-of-pred frames #(= (:id %) frame-id))]
(when index (when index
@ -337,13 +334,11 @@
[section] [section]
(ptk/reify ::go-to-section (ptk/reify ::go-to-section
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [route (:route state) (let [route (:route state)
screen (-> route :data :name keyword)
pparams (:path-params route) pparams (:path-params route)
qparams (:query-params route)] qparams (:query-params route)]
(rx/of (rx/of (rt/nav :viewer pparams (assoc qparams :section section)))))))
(rt/nav :viewer pparams (assoc qparams :section section)))))))
(defn set-current-frame [frame-id] (defn set-current-frame [frame-id]
@ -422,6 +417,6 @@
([{:keys [team-id]}] ([{:keys [team-id]}]
(ptk/reify ::go-to-dashboard (ptk/reify ::go-to-dashboard
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (or team-id (get-in state [:viewer-data :project :team-id]))] (let [team-id (or team-id (get-in state [:viewer-data :project :team-id]))]
(rx/of (rt/nav :dashboard-projects {:team-id team-id}))))))) (rx/of (rt/nav :dashboard-projects {:team-id team-id})))))))

View file

@ -6,15 +6,9 @@
(ns app.main.data.viewer.shortcuts (ns app.main.data.viewer.shortcuts
(:require (:require
[app.config :as cfg]
[app.main.data.workspace.colors :as mdc]
[app.main.data.shortcuts :as ds] [app.main.data.shortcuts :as ds]
[app.main.data.shortcuts :refer [c-mod]]
[app.main.data.viewer :as dv] [app.main.data.viewer :as dv]
[app.main.store :as st] [app.main.store :as st]))
[app.util.dom :as dom]
[beicon.core :as rx]
[potok.core :as ptk]))
(def shortcuts (def shortcuts
{:increase-zoom {:tooltip "+" {:increase-zoom {:tooltip "+"

View file

@ -38,7 +38,6 @@
[app.main.worker :as uw] [app.main.worker :as uw]
[app.util.http :as http] [app.util.http :as http]
[app.util.i18n :as i18n] [app.util.i18n :as i18n]
[app.util.logging :as log]
[app.util.router :as rt] [app.util.router :as rt]
[app.util.webapi :as wapi] [app.util.webapi :as wapi]
[beicon.core :as rx] [beicon.core :as rx]
@ -134,7 +133,7 @@
(or layout default-layout)))) (or layout default-layout))))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(if (and layout-name (contains? layout-names layout-name)) (if (and layout-name (contains? layout-names layout-name))
(rx/of (ensure-layout layout-name)) (rx/of (ensure-layout layout-name))
(rx/of (ensure-layout :layers)))))) (rx/of (ensure-layout :layers))))))
@ -153,7 +152,7 @@
:workspace-presence {})) :workspace-presence {}))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ stream]
(rx/merge (rx/merge
(rx/of (dwp/fetch-bundle project-id file-id)) (rx/of (dwp/fetch-bundle project-id file-id))
@ -162,7 +161,7 @@
(rx/filter (ptk/type? ::dwp/bundle-fetched)) (rx/filter (ptk/type? ::dwp/bundle-fetched))
(rx/take 1) (rx/take 1)
(rx/map deref) (rx/map deref)
(rx/mapcat (fn [{:keys [project] :as bundle}] (rx/mapcat (fn [bundle]
(rx/merge (rx/merge
(rx/of (dwn/initialize file-id) (rx/of (dwn/initialize file-id)
(dwp/initialize-file-persistence file-id) (dwp/initialize-file-persistence file-id)
@ -188,7 +187,7 @@
:workspace-libraries (d/index-by :id libraries))) :workspace-libraries (d/index-by :id libraries)))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(let [file-id (:id file) (let [file-id (:id file)
ignore-until (:ignore-sync-until file) ignore-until (:ignore-sync-until file)
needs-update? (some #(and (> (:modified-at %) (:synced-at %)) needs-update? (some #(and (> (:modified-at %) (:synced-at %))
@ -199,7 +198,7 @@
(rx/of (dwl/notify-sync-file file-id))))))) (rx/of (dwl/notify-sync-file file-id)))))))
(defn finalize-file (defn finalize-file
[project-id file-id] [_project-id file-id]
(ptk/reify ::finalize (ptk/reify ::finalize
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
@ -210,7 +209,7 @@
:workspace-persistence)) :workspace-persistence))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(rx/of (dwn/finalize file-id) (rx/of (dwn/finalize file-id)
::dwp/finalize)))) ::dwp/finalize))))
@ -262,7 +261,7 @@
{:id id :file-id file-id}) {:id id :file-id file-id})
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [pages (get-in state [:workspace-data :pages-index]) (let [pages (get-in state [:workspace-data :pages-index])
unames (dwc/retrieve-used-names pages) unames (dwc/retrieve-used-names pages)
name (dwc/generate-unique-name unames "Page") name (dwc/generate-unique-name unames "Page")
@ -280,7 +279,7 @@
[page-id] [page-id]
(ptk/reify ::duplicate-page (ptk/reify ::duplicate-page
ptk/WatchEvent ptk/WatchEvent
(watch [this state stream] (watch [this state _]
(let [id (uuid/next) (let [id (uuid/next)
pages (get-in state [:workspace-data :pages-index]) pages (get-in state [:workspace-data :pages-index])
unames (dwc/retrieve-used-names pages) unames (dwc/retrieve-used-names pages)
@ -306,7 +305,7 @@
(us/verify string? name) (us/verify string? name)
(ptk/reify ::rename-page (ptk/reify ::rename-page
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [page (get-in state [:workspace-data :pages-index id]) (let [page (get-in state [:workspace-data :pages-index id])
rchg {:type :mod-page rchg {:type :mod-page
:id id :id id
@ -327,7 +326,7 @@
[id] [id]
(ptk/reify ::delete-page (ptk/reify ::delete-page
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [page (get-in state [:workspace-data :pages-index id]) (let [page (get-in state [:workspace-data :pages-index id])
rchg {:type :del-page rchg {:type :del-page
:id id} :id id}
@ -353,7 +352,7 @@
(assoc-in state [:workspace-file :name] name)) (assoc-in state [:workspace-file :name] name))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(let [params {:id id :name name}] (let [params {:id id :name name}]
(->> (rp/mutation :rename-file params) (->> (rp/mutation :rename-file params)
(rx/ignore)))))) (rx/ignore))))))
@ -368,7 +367,7 @@
(defn initialize-viewport (defn initialize-viewport
[{:keys [width height] :as size}] [{:keys [width height] :as size}]
(letfn [(update* [{:keys [vbox vport] :as local}] (letfn [(update* [{:keys [vport] :as local}]
(let [wprop (/ (:width vport) width) (let [wprop (/ (:width vport) width)
hprop (/ (:height vport) height)] hprop (/ (:height vport) height)]
(-> local (-> local
@ -433,7 +432,7 @@
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(update state :workspace-local (update state :workspace-local
(fn [{:keys [vbox vport left-sidebar? zoom] :as local}] (fn [{:keys [vport left-sidebar? zoom] :as local}]
(if (or (mth/almost-zero? width) (mth/almost-zero? height)) (if (or (mth/almost-zero? width) (mth/almost-zero? height))
;; If we have a resize to zero just keep the old value ;; If we have a resize to zero just keep the old value
local local
@ -452,7 +451,7 @@
(defn start-panning [] (defn start-panning []
(ptk/reify ::start-panning (ptk/reify ::start-panning
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state stream]
(let [stopper (->> stream (rx/filter (ptk/type? ::finish-panning))) (let [stopper (->> stream (rx/filter (ptk/type? ::finish-panning)))
zoom (-> (get-in state [:workspace-local :zoom]) gpt/point)] zoom (-> (get-in state [:workspace-local :zoom]) gpt/point)]
(when-not (get-in state [:workspace-local :panning]) (when-not (get-in state [:workspace-local :panning])
@ -580,7 +579,7 @@
(mth/nan? (:height srect))) (mth/nan? (:height srect)))
state state
(update state :workspace-local (update state :workspace-local
(fn [{:keys [vbox vport] :as local}] (fn [{:keys [vport] :as local}]
(let [srect (gal/adjust-to-viewport vport srect {:padding 40}) (let [srect (gal/adjust-to-viewport vport srect {:padding 40})
zoom (/ (:width vport) (:width srect))] zoom (/ (:width vport) (:width srect))]
(-> local (-> local
@ -600,7 +599,7 @@
(map #(get objects %)) (map #(get objects %))
(gsh/selection-rect))] (gsh/selection-rect))]
(update state :workspace-local (update state :workspace-local
(fn [{:keys [vbox vport] :as local}] (fn [{:keys [vport] :as local}]
(let [srect (gal/adjust-to-viewport vport srect {:padding 40}) (let [srect (gal/adjust-to-viewport vport srect {:padding 40})
zoom (/ (:width vport) (:width srect))] zoom (/ (:width vport) (:width srect))]
(-> local (-> local
@ -615,7 +614,7 @@
(us/verify ::shape-attrs attrs) (us/verify ::shape-attrs attrs)
(ptk/reify ::update-shape (ptk/reify ::update-shape
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(rx/of (dch/update-shapes [id] #(merge % attrs)))))) (rx/of (dch/update-shapes [id] #(merge % attrs))))))
(defn start-rename-shape (defn start-rename-shape
@ -631,7 +630,7 @@
(ptk/reify ::end-rename-shape (ptk/reify ::end-rename-shape
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(update-in state [:workspace-local] dissoc :shape-for-rename)))) (update state :workspace-local dissoc :shape-for-rename))))
;; --- Update Selected Shapes attrs ;; --- Update Selected Shapes attrs
@ -640,45 +639,17 @@
(us/verify ::shape-attrs attrs) (us/verify ::shape-attrs attrs)
(ptk/reify ::update-selected-shapes (ptk/reify ::update-selected-shapes
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [selected (wsh/lookup-selected state)] (let [selected (wsh/lookup-selected state)]
(rx/from (map #(update-shape % attrs) selected)))))) (rx/from (map #(update-shape % attrs) selected))))))
;; --- Shape Movement (using keyboard shorcuts)
(declare initial-selection-align)
(defn- get-displacement-with-grid
"Retrieve the correct displacement delta point for the
provided direction speed and distances thresholds."
[shape direction options]
(let [grid-x (:grid-x options 10)
grid-y (:grid-y options 10)
x-mod (mod (:x shape) grid-x)
y-mod (mod (:y shape) grid-y)]
(case direction
:up (gpt/point 0 (- (if (zero? y-mod) grid-y y-mod)))
:down (gpt/point 0 (- grid-y y-mod))
:left (gpt/point (- (if (zero? x-mod) grid-x x-mod)) 0)
:right (gpt/point (- grid-x x-mod) 0))))
(defn- get-displacement
"Retrieve the correct displacement delta point for the
provided direction speed and distances thresholds."
[shape direction]
(case direction
:up (gpt/point 0 (- 1))
:down (gpt/point 0 1)
:left (gpt/point (- 1) 0)
:right (gpt/point 1 0)))
;; --- Delete Selected ;; --- Delete Selected
(def delete-selected (def delete-selected
"Deselect all and remove all selected shapes." "Deselect all and remove all selected shapes."
(ptk/reify ::delete-selected (ptk/reify ::delete-selected
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [selected (wsh/lookup-selected state)] (let [selected (wsh/lookup-selected state)]
(rx/of (dwc/delete-shapes selected) (rx/of (dwc/delete-shapes selected)
(dws/deselect-all)))))) (dws/deselect-all))))))
@ -692,7 +663,7 @@
(us/verify ::loc loc) (us/verify ::loc loc)
(ptk/reify ::vertical-order-selected (ptk/reify ::vertical-order-selected
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
selected (wsh/lookup-selected state) selected (wsh/lookup-selected state)
@ -901,7 +872,7 @@
(ptk/reify ::relocate-shapes (ptk/reify ::relocate-shapes
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
@ -1012,7 +983,7 @@
[parent-id to-index] [parent-id to-index]
(ptk/reify ::relocate-selected-shapes (ptk/reify ::relocate-selected-shapes
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [selected (wsh/lookup-selected state)] (let [selected (wsh/lookup-selected state)]
(rx/of (relocate-shapes selected parent-id to-index)))))) (rx/of (relocate-shapes selected parent-id to-index))))))
@ -1021,7 +992,7 @@
[] []
(ptk/reify ::start-editing-selected (ptk/reify ::start-editing-selected
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [selected (wsh/lookup-selected state)] (let [selected (wsh/lookup-selected state)]
(if-not (= 1 (count selected)) (if-not (= 1 (count selected))
(rx/empty) (rx/empty)
@ -1049,7 +1020,7 @@
[id index] [id index]
(ptk/reify ::relocate-pages (ptk/reify ::relocate-pages
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [cidx (-> (get-in state [:workspace-data :pages]) (let [cidx (-> (get-in state [:workspace-data :pages])
(d/index-of id)) (d/index-of id))
rchg {:type :mov-page rchg {:type :mov-page
@ -1072,7 +1043,7 @@
(us/verify ::gal/align-axis axis) (us/verify ::gal/align-axis axis)
(ptk/reify :align-objects (ptk/reify :align-objects
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
selected (wsh/lookup-selected state) selected (wsh/lookup-selected state)
@ -1103,7 +1074,7 @@
(us/verify ::gal/dist-axis axis) (us/verify ::gal/dist-axis axis)
(ptk/reify :align-objects (ptk/reify :align-objects
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
selected (wsh/lookup-selected state) selected (wsh/lookup-selected state)
@ -1121,7 +1092,7 @@
[id lock] [id lock]
(ptk/reify ::set-shape-proportion-lock (ptk/reify ::set-shape-proportion-lock
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(letfn [(assign-proportions [shape] (letfn [(assign-proportions [shape]
(if-not lock (if-not lock
(assoc shape :proportion-lock false) (assoc shape :proportion-lock false)
@ -1142,7 +1113,7 @@
(us/verify ::position position) (us/verify ::position position)
(ptk/reify ::update-position (ptk/reify ::update-position
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
shape (get objects id) shape (get objects id)
@ -1164,7 +1135,7 @@
(s/assert ::shape-attrs flags) (s/assert ::shape-attrs flags)
(ptk/reify ::update-shape-flags (ptk/reify ::update-shape-flags
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [update-fn (let [update-fn
(fn [obj] (fn [obj]
(cond-> obj (cond-> obj
@ -1184,7 +1155,7 @@
[project-id] [project-id]
(ptk/reify ::navigate-to-project (ptk/reify ::navigate-to-project
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [page-ids (get-in state [:projects project-id :pages]) (let [page-ids (get-in state [:projects project-id :pages])
params {:project project-id :page (first page-ids)}] params {:project project-id :page (first page-ids)}]
(rx/of (rt/nav :workspace/page params)))))) (rx/of (rt/nav :workspace/page params))))))
@ -1193,7 +1164,7 @@
([] ([]
(ptk/reify ::go-to-page (ptk/reify ::go-to-page
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [project-id (:current-project-id state) (let [project-id (:current-project-id state)
file-id (:current-file-id state) file-id (:current-file-id state)
page-id (get-in state [:workspace-data :pages 0]) page-id (get-in state [:workspace-data :pages 0])
@ -1205,7 +1176,7 @@
(us/verify ::us/uuid page-id) (us/verify ::us/uuid page-id)
(ptk/reify ::go-to-page (ptk/reify ::go-to-page
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [project-id (:current-project-id state) (let [project-id (:current-project-id state)
file-id (:current-file-id state) file-id (:current-file-id state)
pparams {:file-id file-id :project-id project-id} pparams {:file-id file-id :project-id project-id}
@ -1217,10 +1188,10 @@
(us/verify ::layout-flag layout) (us/verify ::layout-flag layout)
(ptk/reify ::go-to-layout (ptk/reify ::go-to-layout
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [project-id (get-in state [:workspace-project :id]) (let [project-id (get-in state [:workspace-project :id])
file-id (get-in state [:workspace-file :id]) file-id (get-in state [:workspace-file :id])
page-id (get-in state [:current-page-id]) page-id (get state :current-page-id)
pparams {:file-id file-id :project-id project-id} pparams {:file-id file-id :project-id project-id}
qparams {:page-id page-id :layout (name layout)}] qparams {:page-id page-id :layout (name layout)}]
(rx/of (rt/nav :workspace pparams qparams)))))) (rx/of (rt/nav :workspace pparams qparams))))))
@ -1228,7 +1199,7 @@
(def go-to-file (def go-to-file
(ptk/reify ::go-to-file (ptk/reify ::go-to-file
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [{:keys [id project-id data] :as file} (:workspace-file state) (let [{:keys [id project-id data] :as file} (:workspace-file state)
page-id (get-in data [:pages 0]) page-id (get-in data [:pages 0])
pparams {:project-id project-id :file-id id} pparams {:project-id project-id :file-id id}
@ -1240,7 +1211,7 @@
([{:keys [file-id page-id]}] ([{:keys [file-id page-id]}]
(ptk/reify ::go-to-viewer (ptk/reify ::go-to-viewer
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [{:keys [current-file-id current-page-id]} state (let [{:keys [current-file-id current-page-id]} state
params {:file-id (or file-id current-file-id) params {:file-id (or file-id current-file-id)
:page-id (or page-id current-page-id)}] :page-id (or page-id current-page-id)}]
@ -1252,7 +1223,7 @@
([{:keys [team-id]}] ([{:keys [team-id]}]
(ptk/reify ::go-to-dashboard (ptk/reify ::go-to-dashboard
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(when-let [team-id (or team-id (:current-team-id state))] (when-let [team-id (or team-id (:current-team-id state))]
(rx/of ::dwp/force-persist (rx/of ::dwp/force-persist
(rt/nav :dashboard-projects {:team-id team-id}))))))) (rt/nav :dashboard-projects {:team-id team-id})))))))
@ -1261,7 +1232,7 @@
[] []
(ptk/reify ::go-to-dashboard (ptk/reify ::go-to-dashboard
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(rx/of ::dwp/force-persist (rx/of ::dwp/force-persist
(rt/nav :dashboard-fonts {:team-id team-id})))))) (rt/nav :dashboard-fonts {:team-id team-id}))))))
@ -1291,7 +1262,7 @@
(us/verify ::cp/minimal-shape shape) (us/verify ::cp/minimal-shape shape)
(ptk/reify ::show-shape-context-menu (ptk/reify ::show-shape-context-menu
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [selected (wsh/lookup-selected state)] (let [selected (wsh/lookup-selected state)]
(rx/concat (rx/concat
(when-not (selected (:id shape)) (when-not (selected (:id shape))
@ -1383,7 +1354,7 @@
(ptk/reify ::copy-selected (ptk/reify ::copy-selected
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [objects (wsh/lookup-page-objects state) (let [objects (wsh/lookup-page-objects state)
selected (->> (wsh/lookup-selected state) selected (->> (wsh/lookup-selected state)
(cp/clean-loops objects)) (cp/clean-loops objects))
@ -1410,7 +1381,7 @@
(def paste (def paste
(ptk/reify ::paste (ptk/reify ::paste
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(try (try
(let [clipboard-str (wapi/read-from-clipboard) (let [clipboard-str (wapi/read-from-clipboard)
@ -1449,7 +1420,7 @@
[event in-viewport?] [event in-viewport?]
(ptk/reify ::paste-from-event (ptk/reify ::paste-from-event
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(try (try
(let [objects (wsh/lookup-page-objects state) (let [objects (wsh/lookup-page-objects state)
paste-data (wapi/read-from-paste-event event) paste-data (wapi/read-from-paste-event event)
@ -1487,8 +1458,8 @@
(defn selected-frame? [state] (defn selected-frame? [state]
(let [selected (wsh/lookup-selected state) (let [selected (wsh/lookup-selected state)
objects (wsh/lookup-page-objects state)] objects (wsh/lookup-page-objects state)]
(and (and (= 1 (count selected)) (and (= 1 (count selected))
(= :frame (get-in objects [(first selected) :type])))))) (= :frame (get-in objects [(first selected) :type])))))
(defn- paste-shape (defn- paste-shape
[{:keys [selected objects images] :as data} in-viewport?] [{:keys [selected objects images] :as data} in-viewport?]
@ -1569,7 +1540,6 @@
;; Procceed with the standard shape paste procediment. ;; Procceed with the standard shape paste procediment.
(do-paste [it state mouse-pos media] (do-paste [it state mouse-pos media]
(let [media-idx (d/index-by :prev-id media) (let [media-idx (d/index-by :prev-id media)
page-id (:current-page-id state)
;; Calculate position for the pasted elements ;; Calculate position for the pasted elements
[frame-id parent-id delta index] (calculate-paste-position state mouse-pos in-viewport?) [frame-id parent-id delta index] (calculate-paste-position state mouse-pos in-viewport?)
@ -1619,7 +1589,7 @@
(dwc/select-shapes selected))))] (dwc/select-shapes selected))))]
(ptk/reify ::paste-shape (ptk/reify ::paste-shape
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [file-id (:current-file-id state) (let [file-id (:current-file-id state)
mouse-pos (deref ms/mouse-position)] mouse-pos (deref ms/mouse-position)]
(if (= file-id (:file-id data)) (if (= file-id (:file-id data))
@ -1643,7 +1613,7 @@
(s/assert string? text) (s/assert string? text)
(ptk/reify ::paste-text (ptk/reify ::paste-text
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [id (uuid/next) (let [id (uuid/next)
{:keys [x y]} @ms/mouse-position {:keys [x y]} @ms/mouse-position
width (max 8 (min (* 7 (count text)) 700)) width (max 8 (min (* 7 (count text)) 700))
@ -1672,7 +1642,7 @@
(s/assert string? text) (s/assert string? text)
(ptk/reify ::paste-svg (ptk/reify ::paste-svg
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [position (deref ms/mouse-position) (let [position (deref ms/mouse-position)
file-id (:current-file-id state)] file-id (:current-file-id state)]
(->> (dwp/parse-svg ["svg" text]) (->> (dwp/parse-svg ["svg" text])
@ -1682,7 +1652,7 @@
[image] [image]
(ptk/reify ::paste-bin-impl (ptk/reify ::paste-bin-impl
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [file-id (get-in state [:workspace-file :id]) (let [file-id (get-in state [:workspace-file :id])
params {:file-id file-id params {:file-id file-id
:blobs [image] :blobs [image]
@ -1707,7 +1677,7 @@
[] []
(ptk/reify ::start-create-interaction (ptk/reify ::start-create-interaction
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state stream]
(let [initial-pos @ms/mouse-position (let [initial-pos @ms/mouse-position
selected (wsh/lookup-selected state) selected (wsh/lookup-selected state)
stopper (rx/filter ms/mouse-up? stream)] stopper (rx/filter ms/mouse-up? stream)]
@ -1744,7 +1714,7 @@
(assoc-in [:workspace-local :draw-interaction-to-frame] nil))) (assoc-in [:workspace-local :draw-interaction-to-frame] nil)))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [position @ms/mouse-position (let [position @ms/mouse-position
page-id (:current-page-id state) page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
@ -1772,7 +1742,7 @@
[color] [color]
(ptk/reify ::change-canvas-color (ptk/reify ::change-canvas-color
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [page-id (get state :current-page-id) (let [page-id (get state :current-page-id)
options (wsh/lookup-page-options state page-id) options (wsh/lookup-page-options state page-id)
previus-color (:background options)] previus-color (:background options)]
@ -1787,7 +1757,6 @@
:value previus-color}] :value previus-color}]
:origin it})))))) :origin it}))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Exports ;; Exports
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View file

@ -255,7 +255,7 @@
(declare fetch-libraries-content) (declare fetch-libraries-content)
(declare bundle-fetched) (declare bundle-fetched)
(defn- fetch-bundle (defn fetch-bundle
[project-id file-id] [project-id file-id]
(ptk/reify ::fetch-bundle (ptk/reify ::fetch-bundle
ptk/WatchEvent ptk/WatchEvent

View file

@ -10,7 +10,6 @@
[cuerdas.core :as str] [cuerdas.core :as str]
[app.common.data :as d] [app.common.data :as d]
[app.main.ui.icons :as i] [app.main.ui.icons :as i]
[app.main.data.history :as udh]
[app.main.data.workspace :as dw] [app.main.data.workspace :as dw]
[app.main.refs :as refs] [app.main.refs :as refs]
[app.main.store :as st] [app.main.store :as st]

View file

@ -6,9 +6,8 @@
(ns app.util.avatars (ns app.util.avatars
(:require (:require
[cuerdas.core :as str]
[app.util.object :as obj] [app.util.object :as obj]
["randomcolor" :as rdcolor])) [cuerdas.core :as str]))
(defn generate* (defn generate*
[{:keys [name color size] [{:keys [name color size]

View file

@ -33,7 +33,7 @@
color {:color (:stroke-color shape) color {:color (:stroke-color shape)
:opacity (:stroke-opacity shape) :opacity (:stroke-opacity shape)
:gradient (:stroke-color-gradient shape)}] :gradient (:stroke-color-gradient shape)}]
(if-not (= :none (:stroke-style shape)) (when-not (= :none (:stroke-style shape))
(str/format "%spx %s %s" width style (uc/color->background color))))) (str/format "%spx %s %s" width style (uc/color->background color)))))
(def styles-data (def styles-data

View file

@ -7,9 +7,8 @@
(ns app.util.color (ns app.util.color
"Color conversion utils." "Color conversion utils."
(:require (:require
[cuerdas.core :as str]
[app.common.math :as math]
[app.util.object :as obj] [app.util.object :as obj]
[cuerdas.core :as str]
[goog.color :as gcolor])) [goog.color :as gcolor]))
(defn rgb->str (defn rgb->str
@ -31,7 +30,7 @@
[v] [v]
(try (try
(into [] (gcolor/hexToRgb v)) (into [] (gcolor/hexToRgb v))
(catch :default e [0 0 0]))) (catch :default _e [0 0 0])))
(defn rgb->hex (defn rgb->hex
[[r g b]] [[r g b]]
@ -49,7 +48,7 @@
(defn hex->hsl [hex] (defn hex->hsl [hex]
(try (try
(into [] (gcolor/hexToHsl hex)) (into [] (gcolor/hexToHsl hex))
(catch :default e [0 0 0]))) (catch :default _e [0 0 0])))
(defn hex->hsla (defn hex->hsla
[^string data ^number opacity] [^string data ^number opacity]
@ -96,7 +95,7 @@
c (nth v 2)] c (nth v 2)]
(str a a b b c c)) (str a a b b c c))
:default :else
v)) v))
(defn prepend-hash (defn prepend-hash
@ -135,7 +134,7 @@
:else "transparent"))) :else "transparent")))
(defn multiple? [{:keys [id file-id value color gradient opacity]}] (defn multiple? [{:keys [id file-id value color gradient]}]
(or (= value :multiple) (or (= value :multiple)
(= color :multiple) (= color :multiple)
(= gradient :multiple) (= gradient :multiple)
@ -144,7 +143,7 @@
(defn color? [^string color-str] (defn color? [^string color-str]
(and (not (nil? color-str)) (and (not (nil? color-str))
(not (empty? color-str)) (seq color-str)
(gcolor/isValidColor color-str))) (gcolor/isValidColor color-str)))
(defn parse-color [^string color-str] (defn parse-color [^string color-str]

View file

@ -39,7 +39,7 @@
(reduce #(dissoc! %1 %2) (transient data) keys))) (reduce #(dissoc! %1 %2) (transient data) keys)))
(defn dissoc-in (defn dissoc-in
[m [k & ks :as keys]] [m [k & ks :as _keys]]
(if ks (if ks
(if-let [nextmap (get m k)] (if-let [nextmap (get m k)]
(let [newmap (dissoc-in nextmap ks)] (let [newmap (dissoc-in nextmap ks)]

View file

@ -1,9 +1,9 @@
(ns app.util.debug (ns app.util.debug
"Debugging utils" "Debugging utils"
(:require (:require
[app.util.timers :as timers]
[app.util.object :as obj]
[app.common.math :as mth] [app.common.math :as mth]
[app.util.object :as obj]
[app.util.timers :as timers]
[cljs.pprint :refer [pprint]])) [cljs.pprint :refer [pprint]]))
(def debug-options #{:bounding-boxes :group :events :rotation-handler :resize-handler :selection-center :export :import #_:simple-selection}) (def debug-options #{:bounding-boxes :group :events :rotation-handler :resize-handler :selection-center :export :import #_:simple-selection})

View file

@ -7,9 +7,8 @@
(ns app.util.dom.dnd (ns app.util.dom.dnd
"Drag & Drop interop helpers." "Drag & Drop interop helpers."
(:require (:require
[app.common.transit :as t] [app.common.transit :as t]
[app.util.data :refer (read-string)] [cuerdas.core :as str]))
[cuerdas.core :as str]))
;; This is the official documentation for the dnd API: ;; This is the official documentation for the dnd API:
;; https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API ;; https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API
@ -40,7 +39,7 @@
(defn trace (defn trace
;; This function is useful to debug the dnd interface behaviour when something weird occurs. ;; This function is useful to debug the dnd interface behaviour when something weird occurs.
[event data label] [event data label]
(let [currentTarget (.-currentTarget event) (let [;;currentTarget (.-currentTarget event)
relatedTarget (.-relatedTarget event)] relatedTarget (.-relatedTarget event)]
(js/console.log (js/console.log
label label

View file

@ -10,17 +10,14 @@
[app.common.spec :as us] [app.common.spec :as us]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.i18n :refer [tr]] [app.util.i18n :refer [tr]]
[app.util.timers :as tm]
[beicon.core :as rx]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[cuerdas.core :as str] [cuerdas.core :as str]
[potok.core :as ptk]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
;; --- Handlers Helpers ;; --- Handlers Helpers
(defn- interpret-problem (defn- interpret-problem
[acc {:keys [path pred val via in] :as problem}] [acc {:keys [path pred via] :as problem}]
(cond (cond
(and (empty? path) (and (empty? path)
(list? pred) (list? pred)
@ -28,8 +25,8 @@
(let [path (conj path (last (last pred)))] (let [path (conj path (last (last pred)))]
(assoc-in acc path {:code ::missing :type :builtin})) (assoc-in acc path {:code ::missing :type :builtin}))
(and (not (empty? path)) (and (seq path)
(not (empty? via))) (seq via))
(assoc-in acc path {:code (last via) :type :builtin}) (assoc-in acc path {:code (last via) :type :builtin})
:else acc)) :else acc))
@ -37,7 +34,7 @@
(declare create-form-mutator) (declare create-form-mutator)
(defn use-form (defn use-form
[& {:keys [spec validators initial] :as opts}] [& {:keys [initial] :as opts}]
(let [state (mf/useState 0) (let [state (mf/useState 0)
render (aget state 1) render (aget state 1)
state-ref (mf/use-ref {:data (if (fn? initial) (initial) initial) state-ref (mf/use-ref {:data (if (fn? initial) (initial) initial)
@ -126,9 +123,8 @@
(defn on-input-blur (defn on-input-blur
[form field] [form field]
(fn [event] (fn [_]
(let [target (dom/get-target event) (let [touched (get @form :touched)]
touched (get @form :touched)]
(when-not (get touched field) (when-not (get touched field)
(swap! form assoc-in [:touched field] true))))) (swap! form assoc-in [:touched field] true)))))
@ -136,9 +132,8 @@
(mf/defc field-error (mf/defc field-error
[{:keys [form field type] [{:keys [form field type]
:or {only (constantly true)}
:as props}] :as props}]
(let [{:keys [code message] :as error} (get-in form [:errors field]) (let [{:keys [message] :as error} (get-in form [:errors field])
touched? (get-in form [:touched field]) touched? (get-in form [:touched field])
show? (and touched? error message show? (and touched? error message
(cond (cond

View file

@ -6,8 +6,8 @@
(ns app.util.geom.grid (ns app.util.geom.grid
(:require (:require
[app.common.math :as mth] [app.common.geom.point :as gpt]
[app.common.geom.point :as gpt])) [app.common.math :as mth]))
(def ^:private default-items 12) (def ^:private default-items 12)
@ -35,7 +35,7 @@
margin) margin)
gutter (if (= :stretch type) (/ (- width (* item-width size) (* margin 2)) (dec size)) gutter) gutter (if (= :stretch type) (/ (- width (* item-width size) (* margin 2)) (dec size)) gutter)
next-x (fn [cur-val] (+ initial-offset x (* (+ item-width gutter) cur-val))) next-x (fn [cur-val] (+ initial-offset x (* (+ item-width gutter) cur-val)))
next-y (fn [cur-val] y)] next-y (fn [_] y)]
[size item-width item-height next-x next-y])) [size item-width item-height next-x next-y]))
(defn- calculate-row-grid (defn- calculate-row-grid
@ -49,7 +49,7 @@
:center (/ (- height (* item-height size) (* gutter (dec size))) 2) :center (/ (- height (* item-height size) (* gutter (dec size))) 2)
margin) margin)
gutter (if (= :stretch type) (/ (- height (* item-height size) (* margin 2)) (dec size)) gutter) gutter (if (= :stretch type) (/ (- height (* item-height size) (* margin 2)) (dec size)) gutter)
next-x (fn [cur-val] x) next-x (fn [_] x)
next-y (fn [cur-val] (+ initial-offset y (* (+ item-height gutter) cur-val)))] next-y (fn [cur-val] (+ initial-offset y (* (+ item-height gutter) cur-val)))]
[size item-width item-height next-x next-y])) [size item-width item-height next-x next-y]))
@ -91,7 +91,7 @@
([shape coord] ([shape coord]
(mapcat #(grid-snap-points shape % coord) (:grids shape))) (mapcat #(grid-snap-points shape % coord) (:grids shape)))
([shape {:keys [type display params] :as grid} coord] ([shape {:keys [type params] :as grid} coord]
(when (:display grid) (when (:display grid)
(case type (case type
:square :square

View file

@ -6,10 +6,8 @@
(ns app.util.geom.snap-points (ns app.util.geom.snap-points
(:require (:require
[cljs.spec.alpha :as s] [app.common.geom.point :as gpt]
[clojure.set :as set] [app.common.geom.shapes :as gsh]))
[app.common.geom.shapes :as gsh]
[app.common.geom.point :as gpt]))
(defn- selrect-snap-points [{:keys [x y width height]}] (defn- selrect-snap-points [{:keys [x y width height]}]
#{(gpt/point x y) #{(gpt/point x y)

View file

@ -13,7 +13,6 @@
[app.config :as cfg] [app.config :as cfg]
[app.util.cache :as c] [app.util.cache :as c]
[app.util.globals :as globals] [app.util.globals :as globals]
[app.util.object :as obj]
[app.util.time :as dt] [app.util.time :as dt]
[app.util.webapi :as wapi] [app.util.webapi :as wapi]
[beicon.core :as rx] [beicon.core :as rx]
@ -55,8 +54,8 @@
{"x-frontend-version" (:full @cfg/version)}) {"x-frontend-version" (:full @cfg/version)})
(defn fetch (defn fetch
[{:keys [method uri query headers body timeout mode omit-default-headers] [{:keys [method uri query headers body mode omit-default-headers]
:or {timeout 10000 mode :cors headers {}}}] :or {mode :cors headers {}}}]
(rx/Observable.create (rx/Observable.create
(fn [subscriber] (fn [subscriber]
(let [controller (js/AbortController.) (let [controller (js/AbortController.)
@ -134,7 +133,7 @@
(assoc headers "content-type" "application/transit+json")))) (assoc headers "content-type" "application/transit+json"))))
(defn conditional-decode-transit (defn conditional-decode-transit
[{:keys [body headers status] :as response}] [{:keys [body headers] :as response}]
(let [contentype (get headers "content-type")] (let [contentype (get headers "content-type")]
(if (and (str/starts-with? contentype "application/transit+json") (if (and (str/starts-with? contentype "application/transit+json")
(pos? (count body))) (pos? (count body)))

View file

@ -11,7 +11,6 @@
[app.util.globals :as globals] [app.util.globals :as globals]
[app.util.object :as obj] [app.util.object :as obj]
[app.util.storage :refer [storage]] [app.util.storage :refer [storage]]
[beicon.core :as rx]
[cuerdas.core :as str] [cuerdas.core :as str]
[goog.object :as gobj] [goog.object :as gobj]
[okulary.core :as l] [okulary.core :as l]
@ -91,7 +90,7 @@
(deftype C [val] (deftype C [val]
IDeref IDeref
(-deref [o] val)) (-deref [_] val))
(defn ^boolean c? (defn ^boolean c?
[r] [r]

View file

@ -6,9 +6,10 @@
(ns app.util.logging) (ns app.util.logging)
(defn- log-expr [form level keyvals] (defn- log-expr [_form level keyvals]
(let [keyvals-map (apply array-map keyvals) (let [keyvals-map (apply array-map keyvals)
formatter (::formatter keyvals-map 'identity)] ;;formatter (::formatter keyvals-map 'identity)
]
`(log ~(::logger keyvals-map (str *ns*)) `(log ~(::logger keyvals-map (str *ns*))
~level ~level
~(-> keyvals-map ~(-> keyvals-map

View file

@ -11,11 +11,9 @@
(ns app.util.logging (ns app.util.logging
(:require (:require
[goog.log :as glog] [app.common.exceptions :as ex]
[goog.debug.Console :as Console]
[cuerdas.core :as str] [cuerdas.core :as str]
[goog.object :as gobj]) [goog.log :as glog])
(:import [goog.debug Console])
(:require-macros [app.util.logging])) (:require-macros [app.util.logging]))
(defn- logger-name (defn- logger-name
@ -158,7 +156,7 @@
specials)))))) specials))))))
(defn default-handler (defn default-handler
[{:keys [message exception level logger-name]}] [{:keys [message level logger-name]}]
(let [header-styles (str "font-weight: 600; color: " (level->color level)) (let [header-styles (str "font-weight: 600; color: " (level->color level))
normal-styles (str "font-weight: 300; color: " (get colors :gray6)) normal-styles (str "font-weight: 300; color: " (get colors :gray6))
level-name (level->short-name level) level-name (level->short-name level)
@ -174,7 +172,7 @@
(doseq [[type n v] specials] (doseq [[type n v] specials]
(case type (case type
:js (js/console.log n v) :js (js/console.log n v)
:error (if (instance? cljs.core.ExceptionInfo v) :error (if (ex/ex-info? v)
(js/console.error (pr-str v)) (js/console.error (pr-str v))
(js/console.error v)))) (js/console.error v))))
(js/console.groupEnd message)) (js/console.groupEnd message))

View file

@ -8,9 +8,8 @@
"A collection of helpers for work with javascript objects." "A collection of helpers for work with javascript objects."
(:refer-clojure :exclude [set! get get-in merge clone contains?]) (:refer-clojure :exclude [set! get get-in merge clone contains?])
(:require (:require
[cuerdas.core :as str] ["lodash/omit" :as omit]
[goog.object :as gobj] [cuerdas.core :as str]))
["lodash/omit" :as omit]))
(defn new [] #js {}) (defn new [] #js {})

View file

@ -7,12 +7,7 @@
(ns app.util.path.commands (ns app.util.path.commands
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]))
[app.common.geom.shapes.path :as gshp]
[app.util.svg :as usvg]
[cuerdas.core :as str]
[clojure.set :as set]
[app.common.math :as mth]))
(defn command->point (defn command->point
([prev-pos {:keys [relative params] :as command}] ([prev-pos {:keys [relative params] :as command}]
@ -179,7 +174,7 @@
"Returns the commands involving a point with its indices" "Returns the commands involving a point with its indices"
[content point] [content point]
(->> (d/enumerate content) (->> (d/enumerate content)
(filterv (fn [[idx cmd]] (= (command->point cmd) point))))) (filterv (fn [[_ cmd]] (= (command->point cmd) point)))))
(defn prefix->coords [prefix] (defn prefix->coords [prefix]
@ -192,7 +187,7 @@
(when (and (some? index) (when (and (some? index)
(some? prefix) (some? prefix)
(contains? content index)) (contains? content index))
(let [[cx cy :as coords] (prefix->coords prefix)] (let [[cx cy] (prefix->coords prefix)]
(if (= :curve-to (get-in content [index :command])) (if (= :curve-to (get-in content [index :command]))
(gpt/point (get-in content [index :params cx]) (gpt/point (get-in content [index :params cx])
(get-in content [index :params cy])) (get-in content [index :params cy]))

View file

@ -6,10 +6,8 @@
(ns app.util.path.format (ns app.util.path.format
(:require (:require
[app.common.data :as d]
[app.util.path.commands :as upc] [app.util.path.commands :as upc]
[cuerdas.core :as str] [cuerdas.core :as str]))
[app.util.path.subpaths :as ups]))
(defn command->param-list [command] (defn command->param-list [command]
(let [params (:params command)] (let [params (:params command)]
@ -47,7 +45,7 @@
(:x params) "," (:x params) ","
(:y params))))) (:y params)))))
(defn command->string [{:keys [command relative params] :as entry}] (defn command->string [{:keys [command relative] :as entry}]
(let [command-str (case command (let [command-str (case command
:move-to "M" :move-to "M"
:close-path "Z" :close-path "Z"

View file

@ -6,13 +6,8 @@
(ns app.util.path.geom (ns app.util.path.geom
(:require (:require
[app.common.data :as d]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes.path :as gshp] [app.common.geom.shapes.path :as gshp]
[app.util.svg :as usvg]
[cuerdas.core :as str]
[clojure.set :as set]
[app.common.math :as mth]
[app.util.path.commands :as upc])) [app.util.path.commands :as upc]))
(defn calculate-opposite-handler (defn calculate-opposite-handler

View file

@ -8,13 +8,10 @@
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes.path :as gshp]
[app.common.math :as mth]
[app.util.path.arc-to-curve :refer [a2c]] [app.util.path.arc-to-curve :refer [a2c]]
[app.util.path.commands :as upc] [app.util.path.commands :as upc]
[app.util.path.geom :as upg] [app.util.path.geom :as upg]
[app.util.svg :as usvg] [app.util.svg :as usvg]
[clojure.set :as set]
[cuerdas.core :as str])) [cuerdas.core :as str]))
;; ;;
@ -52,7 +49,7 @@
current current
remain)) remain))
(cond-> result (cond-> result
(not (empty? current)) (conj current)))))) (seq current) (conj current))))))
;; Path specification ;; Path specification
;; https://www.w3.org/TR/SVG11/paths.html ;; https://www.w3.org/TR/SVG11/paths.html
@ -72,7 +69,7 @@
:relative relative :relative relative
:params params})))) :params params}))))
(defmethod parse-command "Z" [cmd] (defmethod parse-command "Z" [_]
[{:command :close-path}]) [{:command :close-path}])
(defmethod parse-command "L" [cmd] (defmethod parse-command "L" [cmd]
@ -204,7 +201,7 @@
;; prev-start : previous move-to necesary for Z commands ;; prev-start : previous move-to necesary for Z commands
;; prev-cc : previous command control point for cubic beziers ;; prev-cc : previous command control point for cubic beziers
;; prev-qc : previous command control point for quadratic curves ;; prev-qc : previous command control point for quadratic curves
(fn [[result prev-pos prev-start prev-cc prev-qc] [command prev]] (fn [[result prev-pos prev-start prev-cc prev-qc] [command _prev]]
(let [command (assoc command :prev-pos prev-pos) (let [command (assoc command :prev-pos prev-pos)
command command

View file

@ -40,14 +40,14 @@
height (* radius 2) height (* radius 2)
c bezier-circle-c c bezier-circle-c
c1x (+ x (* (/ width 2) (- 1 c))) c1x (+ x (* (/ width 2) (- 1 c)))
c2x (+ x (* (/ width 2) (+ 1 c))) c2x (+ x (* (/ width 2) (+ 1 c)))
c1y (+ y (* (/ height 2) (- 1 c))) c1y (+ y (* (/ height 2) (- 1 c)))
c2y (+ y (* (/ height 2) (+ 1 c))) c2y (+ y (* (/ height 2) (+ 1 c)))
h1 (case corner h1 (case corner
:top-left (assoc from :y c1y) :top-left (assoc from :y c1y)
:top-right (assoc from :x c2x) :top-right (assoc from :x c2x)
:bottom-right (assoc from :y c2y) :bottom-right (assoc from :y c2y)
:bottom-left (assoc from :x c1x)) :bottom-left (assoc from :x c1x))
@ -67,14 +67,13 @@
ex (+ x width) ex (+ x width)
ey (+ y height) ey (+ y height)
pc (gpt/point mx my)
p1 (gpt/point mx y) p1 (gpt/point mx y)
p2 (gpt/point ex my) p2 (gpt/point ex my)
p3 (gpt/point mx ey) p3 (gpt/point mx ey)
p4 (gpt/point x my) p4 (gpt/point x my)
c bezier-circle-c c bezier-circle-c
c1x (+ x (* (/ width 2) (- 1 c))) c1x (+ x (* (/ width 2) (- 1 c)))
c2x (+ x (* (/ width 2) (+ 1 c))) c2x (+ x (* (/ width 2) (+ 1 c)))
c1y (+ y (* (/ height 2) (- 1 c))) c1y (+ y (* (/ height 2) (- 1 c)))
c2y (+ y (* (/ height 2) (+ 1 c)))] c2y (+ y (* (/ height 2) (+ 1 c)))]
@ -90,7 +89,7 @@
[x y width height r1 r2 r3 r4] [x y width height r1 r2 r3 r4]
(let [p1 (gpt/point x (+ y r1)) (let [p1 (gpt/point x (+ y r1))
p2 (gpt/point (+ x r1) y) p2 (gpt/point (+ x r1) y)
p3 (gpt/point (+ width x (- r2)) y) p3 (gpt/point (+ width x (- r2)) y)
p4 (gpt/point (+ width x) (+ y r2)) p4 (gpt/point (+ width x) (+ y r2))

View file

@ -6,14 +6,7 @@
(ns app.util.path.simplify-curve (ns app.util.path.simplify-curve
(:require (:require
[app.common.data :as d] [app.util.path.path-impl-simplify :as impl-simplify]))
[app.common.geom.point :as gpt]
[app.common.geom.shapes.path :as gshp]
[app.util.path.path-impl-simplify :as impl-simplify]
[app.util.svg :as usvg]
[cuerdas.core :as str]
[clojure.set :as set]
[app.common.math :as mth]))
(defn simplify (defn simplify
"Simplifies a drawing done with the pen tool" "Simplifies a drawing done with the pen tool"

View file

@ -80,13 +80,7 @@
in the same vector that results from te previous->next points but with fixed length." in the same vector that results from te previous->next points but with fixed length."
[content point] [content point]
(let [make-curve-cmd (fn [cmd h1 h2] (let [indices (upc/point-indices content point)
(-> cmd
(update :params assoc
:c1x (:x h1) :c1y (:y h1)
:c2x (:x h2) :c2y (:y h2))))
indices (upc/point-indices content point)
vectors (->> indices (mapv (fn [index] vectors (->> indices (mapv (fn [index]
(let [cmd (nth content index) (let [cmd (nth content index)
prev-i (dec index) prev-i (dec index)
@ -151,10 +145,10 @@
(let [add-curve (let [add-curve
(fn [content {:keys [index command prev-p next-c next-i]}] (fn [content {:keys [index command prev-p next-c next-i]}]
(cond-> content (cond-> content
(and (= :line-to (:command command))) (= :line-to (:command command))
(update index #(line->curve prev-p %)) (update index #(line->curve prev-p %))
(and (= :line-to (:command next-c))) (= :line-to (:command next-c))
(update next-i #(line->curve point %))))] (update next-i #(line->curve point %))))]
(->> vectors (reduce add-curve content)))))) (->> vectors (reduce add-curve content))))))
@ -292,7 +286,7 @@
;; If have a curve the first handler will be relative to the previous ;; If have a curve the first handler will be relative to the previous
;; point. We change the handler to the new previous point ;; point. We change the handler to the new previous point
(and curve? (not (empty? subpath)) (not= old-prev-point new-prev-point)) (and curve? (seq subpath) (not= old-prev-point new-prev-point))
(update :params merge last-handler)) (update :params merge last-handler))
head-idx (dec (count result)) head-idx (dec (count result))
@ -394,7 +388,7 @@
result (cond-> result result (cond-> result
(and (nil? set-a) (nil? set-b)) (and (nil? set-a) (nil? set-b))
(conj #{point-a point-b}) (conj #{point-a point-b})
(and (some? set-a) (nil? set-b)) (and (some? set-a) (nil? set-b))
(add-to-set set-a point-b) (add-to-set set-a point-b)

View file

@ -7,13 +7,11 @@
(ns app.util.router (ns app.util.router
(:refer-clojure :exclude [resolve]) (:refer-clojure :exclude [resolve])
(:require (:require
[app.common.data :as d]
[app.config :as cfg]
[app.common.uri :as u] [app.common.uri :as u]
[app.config :as cfg]
[app.util.browser-history :as bhistory] [app.util.browser-history :as bhistory]
[app.util.timers :as ts] [app.util.timers :as ts]
[beicon.core :as rx] [beicon.core :as rx]
[cuerdas.core :as str]
[goog.events :as e] [goog.events :as e]
[potok.core :as ptk] [potok.core :as ptk]
[reitit.core :as r])) [reitit.core :as r]))
@ -83,7 +81,7 @@
(dissoc state :exception)) (dissoc state :exception))
ptk/EffectEvent ptk/EffectEvent
(effect [_ state stream] (effect [_ state _]
(ts/asap (ts/asap
#(let [router (:router state) #(let [router (:router state)
history (:history state) history (:history state)
@ -106,7 +104,7 @@
(deftype NavigateNewWindow [id params qparams] (deftype NavigateNewWindow [id params qparams]
ptk/EffectEvent ptk/EffectEvent
(effect [_ state stream] (effect [_ state _]
(let [router (:router state) (let [router (:router state)
path (resolve router id params qparams) path (resolve router id params qparams)
uri (-> (u/uri cfg/public-uri) uri (-> (u/uri cfg/public-uri)

View file

@ -6,15 +6,15 @@
(ns app.util.simple-math (ns app.util.simple-math
(:require (:require
[cljs.spec.alpha :as s] [app.common.data :as d]
[clojure.string :refer [index-of]] [app.common.exceptions :as ex]
[cuerdas.core :as str] [cljs.spec.alpha :as s]
[instaparse.core :as insta] [clojure.string :refer [index-of]]
[app.common.data :as d] [cuerdas.core :as str]
[app.common.exceptions :as ex])) [instaparse.core :as insta]))
(def parser (def parser
(insta/parser (insta/parser
"opt-expr = '' | expr "opt-expr = '' | expr
expr = term (<spaces> ('+'|'-') <spaces> expr)* | expr = term (<spaces> ('+'|'-') <spaces> expr)* |
('+'|'-'|'*'|'/') <spaces> factor ('+'|'-'|'*'|'/') <spaces> factor

View file

@ -6,20 +6,10 @@
(ns app.util.storage (ns app.util.storage
(:require (:require
[app.common.exceptions :as ex]
[app.common.transit :as t] [app.common.transit :as t]
[app.util.globals :as g] [app.util.globals :as g]
[app.util.timers :as tm])) [app.util.timers :as tm]))
(defn- ^boolean is-worker?
[]
(or (= *target* "nodejs")
(not (exists? js/window))))
(defn- decode
[v]
(ex/ignoring (t/decode-str v)))
(defn- persist (defn- persist
[storage prev curr] [storage prev curr]
(run! (fn [key] (run! (fn [key]
@ -43,7 +33,7 @@
val (.getItem ^js storage key)] val (.getItem ^js storage key)]
(try (try
(assoc res (t/decode-str key) (t/decode-str val)) (assoc res (t/decode-str key) (t/decode-str val))
(catch :default e (catch :default _e
res)))) res))))
{} {}
(range len))))) (range len)))))

View file

@ -6,12 +6,12 @@
(ns app.util.svg (ns app.util.svg
(:require (:require
[app.common.uuid :as uuid]
[app.common.data :as d] [app.common.data :as d]
[app.common.geom.matrix :as gmt] [app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.math :as mth] [app.common.math :as mth]
[app.common.uuid :as uuid]
[cuerdas.core :as str])) [cuerdas.core :as str]))
;; Regex for XML ids per Spec ;; Regex for XML ids per Spec
@ -539,11 +539,6 @@
(str/camel) (str/camel)
(keyword)))) (keyword))))
(lowercase-key [key]
(-> (d/name key)
(str/lower)
(keyword)))
(format-styles [style-str] (format-styles [style-str]
(->> (str/split style-str ";") (->> (str/split style-str ";")
(map str/trim) (map str/trim)
@ -593,7 +588,7 @@
(defn replace-attrs-ids (defn replace-attrs-ids
"Replaces the ids inside a property" "Replaces the ids inside a property"
[attrs ids-mapping] [attrs ids-mapping]
(if (and ids-mapping (not (empty? ids-mapping))) (if (and ids-mapping (seq ids-mapping))
(update-attr-ids attrs (fn [id] (get ids-mapping id id))) (update-attr-ids attrs (fn [id] (get ids-mapping id id)))
;; Ids-mapping is null ;; Ids-mapping is null
attrs)) attrs))
@ -606,7 +601,7 @@
(reduce visit-node result (:content node))))] (reduce visit-node result (:content node))))]
(visit-node {} content))) (visit-node {} content)))
(defn extract-defs [{:keys [tag attrs content] :as node}] (defn extract-defs [{:keys [attrs] :as node}]
(if-not (map? node) (if-not (map? node)
[{} node] [{} node]
@ -646,7 +641,7 @@
(cond (cond
(nil? to-check) (nil? to-check)
result result
(checked? to-check) (checked? to-check)
(recur result (recur result
checked? checked?
@ -672,7 +667,7 @@
scale-x (/ width svg-width) scale-x (/ width svg-width)
scale-y (/ height svg-height)] scale-y (/ height svg-height)]
(gmt/multiply (gmt/multiply
(gmt/matrix) (gmt/matrix)
@ -735,7 +730,7 @@
(let [process-matrix (let [process-matrix
(fn [[_ type params]] (fn [[_ type params]]
(let [params (->> (re-seq number-regex params) (let [params (->> (re-seq number-regex params)
(filter #(-> % first empty? not)) (filter #(-> % first seq))
(map (comp d/parse-double first)))] (map (comp d/parse-double first)))]
{:type type :params params})) {:type type :params params}))
@ -761,7 +756,7 @@
(str (format-move head) (str (format-move head)
(->> other (map format-line) (str/join " "))))) (->> other (map format-line) (str/join " ")))))
(defn polyline->path [{:keys [attrs tag] :as node}] (defn polyline->path [{:keys [attrs] :as node}]
(let [tag :path (let [tag :path
attrs (-> attrs attrs (-> attrs
(dissoc :points) (dissoc :points)
@ -769,14 +764,14 @@
(assoc node :attrs attrs :tag tag))) (assoc node :attrs attrs :tag tag)))
(defn polygon->path [{:keys [attrs tag] :as node}] (defn polygon->path [{:keys [attrs] :as node}]
(let [tag :path (let [tag :path
attrs (-> attrs attrs (-> attrs
(dissoc :points) (dissoc :points)
(assoc :d (str (points->path (:points attrs)) "Z")))] (assoc :d (str (points->path (:points attrs)) "Z")))]
(assoc node :attrs attrs :tag tag))) (assoc node :attrs attrs :tag tag)))
(defn line->path [{:keys [attrs tag] :as node}] (defn line->path [{:keys [attrs] :as node}]
(let [tag :path (let [tag :path
{:keys [x1 y1 x2 y2]} attrs {:keys [x1 y1 x2 y2]} attrs
attrs (-> attrs attrs (-> attrs
@ -868,7 +863,7 @@
:ratio (calculate-ratio (:width svg-data) (:height svg-data))}] :ratio (calculate-ratio (:width svg-data) (:height svg-data))}]
(letfn [(fix-length [prop-length val] (letfn [(fix-length [prop-length val]
(* (get viewbox prop-length) (/ val 100.))) (* (get viewbox prop-length) (/ val 100.)))
(fix-coord [prop-coord prop-length val] (fix-coord [prop-coord prop-length val]
(+ (get viewbox prop-coord) (+ (get viewbox prop-coord)
(fix-length prop-length val))) (fix-length prop-length val)))
@ -896,7 +891,7 @@
(fix-percent-attrs-viewbox [attrs] (fix-percent-attrs-viewbox [attrs]
(d/mapm fix-percent-attr-viewbox attrs)) (d/mapm fix-percent-attr-viewbox attrs))
(fix-percent-attr-numeric [attr-key attr-val] (fix-percent-attr-numeric [_ attr-val]
(let [is-percent? (str/ends-with? attr-val "%")] (let [is-percent? (str/ends-with? attr-val "%")]
(if is-percent? (if is-percent?
(str (let [attr-num (d/parse-double attr-val)] (str (let [attr-num (d/parse-double attr-val)]

View file

@ -9,14 +9,7 @@
(:require (:require
["./text_editor_impl.js" :as impl] ["./text_editor_impl.js" :as impl]
["draft-js" :as draft] ["draft-js" :as draft]
[app.common.attrs :as attrs] [app.common.text :as txt]))
[app.common.data :as d]
[app.common.text :as txt]
[app.common.uuid :as uuid]
[app.util.array :as arr]
[app.util.object :as obj]
[clojure.walk :as walk]
[cuerdas.core :as str]))
;; --- CONVERSION ;; --- CONVERSION

View file

@ -8,13 +8,11 @@
(ns app.util.theme (ns app.util.theme
"A theme manager." "A theme manager."
(:require (:require
[cuerdas.core :as str]
[rumext.alpha :as mf]
[beicon.core :as rx]
[goog.object :as gobj]
[app.config :as cfg] [app.config :as cfg]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.storage :refer [storage]])) [app.util.storage :refer [storage]]
[beicon.core :as rx]
[rumext.alpha :as mf]))
(defonce theme (get @storage ::theme cfg/default-theme)) (defonce theme (get @storage ::theme cfg/default-theme))
(defonce theme-sub (rx/subject)) (defonce theme-sub (rx/subject))

View file

@ -6,21 +6,21 @@
(ns app.util.time (ns app.util.time
(:require (:require
[cuerdas.core :as str]
["luxon" :as lxn]
["date-fns/formatDistanceToNowStrict" :default dateFnsFormatDistanceToNowStrict] ["date-fns/formatDistanceToNowStrict" :default dateFnsFormatDistanceToNowStrict]
["date-fns/locale/el" :default dateFnsLocalesEl]
["date-fns/locale/fr" :default dateFnsLocalesFr]
["date-fns/locale/ca" :default dateFnsLocalesCa] ["date-fns/locale/ca" :default dateFnsLocalesCa]
["date-fns/locale/de" :default dateFnsLocalesDe] ["date-fns/locale/de" :default dateFnsLocalesDe]
["date-fns/locale/ro" :default dateFnsLocalesRo] ["date-fns/locale/el" :default dateFnsLocalesEl]
["date-fns/locale/pt-BR" :default dateFnsLocalesPtBr]
["date-fns/locale/en-US" :default dateFnsLocalesEnUs] ["date-fns/locale/en-US" :default dateFnsLocalesEnUs]
["date-fns/locale/zh-CN" :default dateFnsLocalesZhCn]
["date-fns/locale/es" :default dateFnsLocalesEs] ["date-fns/locale/es" :default dateFnsLocalesEs]
["date-fns/locale/tr" :default dateFnsLocalesTr] ["date-fns/locale/fr" :default dateFnsLocalesFr]
["date-fns/locale/pt-BR" :default dateFnsLocalesPtBr]
["date-fns/locale/ro" :default dateFnsLocalesRo]
["date-fns/locale/ru" :default dateFnsLocalesRu] ["date-fns/locale/ru" :default dateFnsLocalesRu]
[app.util.object :as obj])) ["date-fns/locale/tr" :default dateFnsLocalesTr]
["date-fns/locale/zh-CN" :default dateFnsLocalesZhCn]
["luxon" :as lxn]
[app.util.object :as obj]
[cuerdas.core :as str]))
(def DateTime lxn/DateTime) (def DateTime lxn/DateTime)
(def Duration lxn/Duration) (def Duration lxn/Duration)

View file

@ -6,8 +6,8 @@
(ns app.util.uri (ns app.util.uri
(:require (:require
[cuerdas.core :as str] [app.util.object :as obj]
[app.util.object :as obj])) [cuerdas.core :as str]))
(defn uri-name [url] (defn uri-name [url]
(let [query-idx (str/last-index-of url "?") (let [query-idx (str/last-index-of url "?")

View file

@ -11,8 +11,7 @@
[app.common.exceptions :as ex] [app.common.exceptions :as ex]
[app.util.object :as obj] [app.util.object :as obj]
[beicon.core :as rx] [beicon.core :as rx]
[cuerdas.core :as str] [cuerdas.core :as str]))
[promesa.core :as p]))
(defn- file-reader (defn- file-reader
[f] [f]
@ -136,7 +135,7 @@
(rx/create (rx/create
(fn [subs] (fn [subs]
(let [obs (js/ResizeObserver. (let [obs (js/ResizeObserver.
(fn [entries x] (fn [entries _]
(rx/push! subs entries)))] (rx/push! subs entries)))]
(.observe ^js obs node) (.observe ^js obs node)
(fn [] (fn []

View file

@ -8,11 +8,8 @@
"A interface to webworkers exposed functionality." "A interface to webworkers exposed functionality."
(:require (:require
[app.common.transit :as t] [app.common.transit :as t]
[app.common.uri :as u]
[app.config :as cfg]
[beicon.core :as rx] [beicon.core :as rx]
[goog.events :as ev] [goog.events :as ev])
[potok.core :as ptk])
(:import (:import
goog.net.WebSocket goog.net.WebSocket
goog.net.WebSocket.EventType)) goog.net.WebSocket.EventType))

View file

@ -82,7 +82,7 @@
worker)) worker))
(defn- handle-response (defn- handle-response
[{:keys [payload error dropped] :as response}] [{:keys [payload error dropped]}]
(when-not dropped (when-not dropped
(if-let [{:keys [data message]} error] (if-let [{:keys [data message]} error]
(throw (ex-info message data)) (throw (ex-info message data))

View file

@ -8,10 +8,9 @@
"Helpers for make zip file (using jszip)." "Helpers for make zip file (using jszip)."
(:require (:require
["jszip" :as zip] ["jszip" :as zip]
[app.common.data :as d] [app.util.http :as http]
[beicon.core :as rx] [beicon.core :as rx]
[promesa.core :as p] [promesa.core :as p]))
[app.util.http :as http]))
(defn compress-files (defn compress-files
[files] [files]

View file

@ -6,23 +6,16 @@
(ns app.worker (ns app.worker
(:require (:require
[app.common.exceptions :as ex]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.transit :as t] [app.common.transit :as t]
[app.common.uuid :as uuid]
[app.util.object :as obj]
[app.util.worker :as w]
[app.worker.impl :as impl]
[app.worker.selection]
[app.worker.import]
[app.worker.export] [app.worker.export]
[app.worker.impl :as impl]
[app.worker.import]
[app.worker.selection]
[app.worker.snaps] [app.worker.snaps]
[app.worker.thumbnails] [app.worker.thumbnails]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[cuerdas.core :as str]
[promesa.core :as p])) [promesa.core :as p]))
;; --- Messages Handling ;; --- Messages Handling
@ -38,7 +31,7 @@
(s/def ::message (s/def ::message
(s/keys (s/keys
:req-opt [::buffer?] :opt-un [::buffer?]
:req-un [::payload ::sender-id])) :req-un [::payload ::sender-id]))
(def buffer (rx/subject)) (def buffer (rx/subject))
@ -86,7 +79,7 @@
(defn- drop-message (defn- drop-message
"Sends to the client a notifiction that its messages have been dropped" "Sends to the client a notifiction that its messages have been dropped"
[{:keys [sender-id payload] :as message}] [{:keys [sender-id] :as message}]
(us/assert ::message message) (us/assert ::message message)
(.postMessage js/self (t/encode-str {:reply-to sender-id (.postMessage js/self (t/encode-str {:reply-to sender-id
:dropped true}))) :dropped true})))
@ -105,7 +98,7 @@
;; we also store the last message processed in order to detect ;; we also store the last message processed in order to detect
;; posible infinite loops ;; posible infinite loops
(rx/scan (rx/scan
(fn [[messages dropped last] message] (fn [[messages dropped _last] message]
(let [cmd (get-in message [:payload :cmd]) (let [cmd (get-in message [:payload :cmd])
;; The previous message is dropped ;; The previous message is dropped