0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-13 16:21:57 -05:00

Merge pull request #1048 from penpot/niwinz-bugfixes-20210617

 Fix linter issues on frontend
This commit is contained in:
Andrés Moya 2021-06-18 11:25:49 +02:00 committed by GitHub
commit b994363972
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
265 changed files with 1992 additions and 3104 deletions

View file

@ -33,11 +33,20 @@ jobs:
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
# run backend lint
- run:
name: common lint
working_directory: "./common"
command: "clj-kondo --parallel --lint src/"
- run:
name: frontend lint
working_directory: "./frontend"
command: "clj-kondo --parallel --lint src/"
- run:
name: backend lint
working_directory: "./backend"
command: "clj-kondo --lint src/"
command: "clj-kondo --parallel --lint src/"
# run backend test
- run:
@ -62,11 +71,6 @@ jobs:
JAVA_HOME: /usr/lib/jvm/openjdk16
PATH: /usr/local/nodejs/bin/:/usr/local/bin:/bin:/usr/bin:/usr/lib/jvm/openjdk16/bin
# - run:
# name: common lint
# working_directory: "./common"
# command: "clj-kondo --lint src/"
- run:
working_directory: "./common"
name: common tests

View file

@ -1,14 +1,30 @@
{:lint-as {potok.core/reify clojure.core/reify
promesa.core/let clojure.core/let
rumext.alpha/defc clojure.core/defn
app.common.data/export clojure.core/def
app.db/with-atomic clojure.core/with-open}
{:lint-as
{promesa.core/let clojure.core/let
rumext.alpha/defc clojure.core/defn
rumext.alpha/fnc clojure.core/fn
app.common.data/export clojure.core/def
app.db/with-atomic clojure.core/with-open}
: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
cljs.core/specify! hooks.export/clojure-specify
app.util.services/defmethod hooks.export/service-defmethod
}}
:output
{:exclude-files ["data_readers.clj"]}
{:exclude-files
["data_readers.clj"
"app/util/perf.cljs"
"app/common/exceptions.cljc"
"app/util/import/.*"
"app/worker/export.cljs"
"app/worker/import.cljs"
"app/libs/.*"
"app/main/data/workspace/path/selection.cljs"
"app/main/data/workspace/transforms.cljs"
]}
:linters
{:unsorted-required-namespaces
@ -21,12 +37,12 @@
:single-key-in
{:level :warning}
:redundant-do
{:level :off}
:unused-binding
{:exclude-destructured-as true
:exclude-destructured-keys-in-fn-args false
}
:unresolved-symbol
{:exclude ['(app.util.services/defmethod)
]}}}
}}

View file

@ -9,3 +9,41 @@
(api/token-node (symbol (name (:value sname))))
sname])]
{: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}))
(defn clojure-specify
[{:keys [:node]}]
(let [[rnode rtype & other] (:children node)
result (api/list-node
(into [(api/token-node (symbol "extend-type"))
(api/token-node (gensym (:string-value rtype)))]
other))]
{:node result}))
(defn service-defmethod
[{:keys [:node]}]
(let [[rnode rtype & other] (:children node)
rsym (gensym (name (:k rtype)))
result (api/list-node
[(api/token-node (symbol "do"))
(api/list-node
[(api/token-node (symbol "declare"))
(api/token-node rsym)])
(api/list-node
(into [(api/token-node (symbol "defmethod"))
(api/token-node rsym)
rtype]
other))])]
{:node result}))

View file

@ -169,7 +169,7 @@
(s/keys :req-un [::profile-id ::file-id ::library-id]))
(sv/defmethod ::unlink-file-from-library
[{:keys [pool] :as cfg} {:keys [profile-id file-id library-id] :as params}]
[{:keys [pool] :as cfg} {:keys [profile-id file-id] :as params}]
(db/with-atomic [conn pool]
(files/check-edition-permissions! conn profile-id file-id)
(unlink-file-from-library conn params)))
@ -189,7 +189,7 @@
(s/keys :req-un [::profile-id ::file-id ::library-id]))
(sv/defmethod ::update-sync
[{:keys [pool] :as cfg} {:keys [profile-id file-id library-id] :as params}]
[{:keys [pool] :as cfg} {:keys [profile-id file-id] :as params}]
(db/with-atomic [conn pool]
(files/check-edition-permissions! conn profile-id file-id)
(update-sync conn params)))
@ -209,7 +209,7 @@
(s/keys :req-un [::profile-id ::file-id ::date]))
(sv/defmethod ::ignore-sync
[{:keys [pool] :as cfg} {:keys [profile-id file-id date] :as params}]
[{:keys [pool] :as cfg} {:keys [profile-id file-id] :as params}]
(db/with-atomic [conn pool]
(files/check-edition-permissions! conn profile-id file-id)
(ignore-sync conn params)))

View file

@ -48,7 +48,7 @@
:opt-un [::invitation-token]))
(sv/defmethod ::login-with-ldap {:auth false :rlimit :password}
[{:keys [pool session tokens] :as cfg} {:keys [email password invitation-token] :as params}]
[{:keys [pool session tokens] :as cfg} params]
(db/with-atomic [conn pool]
(let [info (authenticate params)
cfg (assoc cfg :conn conn)]

View file

@ -167,7 +167,7 @@
:opt-un [::name]))
(sv/defmethod ::duplicate-file
[{:keys [pool] :as cfg} {:keys [profile-id file-id name] :as params}]
[{:keys [pool] :as cfg} {:keys [profile-id file-id] :as params}]
(db/with-atomic [conn pool]
(let [file (db/get-by-id conn :file file-id)
index {file-id (uuid/next)}
@ -187,7 +187,7 @@
:opt-un [::name]))
(sv/defmethod ::duplicate-project
[{:keys [pool] :as cfg} {:keys [profile-id project-id name] :as params}]
[{:keys [pool] :as cfg} {:keys [profile-id project-id] :as params}]
(db/with-atomic [conn pool]
(let [project (db/get-by-id conn :project project-id)]
(teams/check-edition-permissions! conn profile-id (:team-id project))

View file

@ -131,8 +131,7 @@
:opt-un [::accept-newsletter-subscription]))
(sv/defmethod ::register-profile {:auth false :rlimit :password}
[{:keys [pool tokens session] :as cfg} params]
[{:keys [pool] :as cfg} params]
(when-not (:accept-terms-and-privacy params)
(ex/raise :type :validation
:code :invalid-terms-and-privacy))
@ -292,7 +291,7 @@
:opt-un [::scope ::invitation-token]))
(sv/defmethod ::login {:auth false :rlimit :password}
[{:keys [pool session tokens] :as cfg} {:keys [email password scope] :as params}]
[{:keys [pool session tokens] :as cfg} {:keys [email password] :as params}]
(letfn [(check-password [profile password]
(when (= (:password profile) "!")
(ex/raise :type :validation
@ -343,7 +342,7 @@
(s/keys :req-un [::profile-id]))
(sv/defmethod ::logout
[{:keys [pool session] :as cfg} {:keys [profile-id] :as params}]
[{:keys [session] :as cfg} _]
(with-meta {}
{:transform-response (:delete session)}))
@ -376,7 +375,7 @@
(s/keys :req-un [::profile-id ::password ::old-password]))
(sv/defmethod ::update-profile-password {:rlimit :password}
[{:keys [pool] :as cfg} {:keys [password profile-id] :as params}]
[{:keys [pool] :as cfg} {:keys [password] :as params}]
(db/with-atomic [conn pool]
(let [profile (validate-password! conn params)]
(update-profile-password! conn (assoc profile :password password))

View file

@ -232,7 +232,7 @@
(update data :objects update-objects)))
(sv/defmethod ::page
[{:keys [pool] :as cfg} {:keys [profile-id file-id id strip-thumbnails]}]
[{:keys [pool] :as cfg} {:keys [profile-id file-id strip-thumbnails]}]
(db/with-atomic [conn pool]
(check-edition-permissions! conn profile-id file-id)
(let [cfg (assoc cfg :conn conn)
@ -260,7 +260,7 @@
(s/keys :req-un [::profile-id ::team-id]))
(sv/defmethod ::shared-files
[{:keys [pool] :as cfg} {:keys [profile-id team-id] :as params}]
[{:keys [pool] :as cfg} {:keys [team-id] :as params}]
(into [] decode-row-xf (db/exec! pool [sql:shared-files team-id])))
@ -285,7 +285,7 @@
(s/keys :req-un [::profile-id ::team-id]))
(sv/defmethod ::team-shared-files
[{:keys [pool] :as cfg} {:keys [profile-id team-id] :as params}]
[{:keys [pool] :as cfg} {:keys [team-id] :as params}]
(db/exec! pool [sql:team-shared-files team-id]))

View file

@ -11,8 +11,8 @@
(:require-macros [app.common.data]))
(:require
[app.common.math :as mth]
[cljs.analyzer.api :as aapi]
[clojure.set :as set]
#?(:clj [cljs.analyzer.api :as aapi])
#?(:cljs [cljs.reader :as r]
:clj [clojure.edn :as r])
#?(:cljs [cljs.core :as core]
@ -275,7 +275,7 @@
;; Data Parsing / Conversion
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn- nan?
(defn nan?
[v]
(not= v v))
@ -506,7 +506,7 @@
(defn- extract-numeric-suffix
[basename]
(if-let [[match p1 p2] (re-find #"(.*)-([0-9]+)$" basename)]
(if-let [[_ p1 p2] (re-find #"(.*)-([0-9]+)$" basename)]
[p1 (+ 1 (parse-integer p2))]
[basename 1]))

View file

@ -31,7 +31,7 @@
(defn str->matrix
[matrix-str]
(let [params (->> (re-seq number-regex matrix-str)
(filter #(-> % first empty? not))
(filter #(-> % first seq))
(map (comp d/parse-double first)))]
(apply matrix params)))
@ -52,12 +52,11 @@
"Given two TRANSLATE matrixes (only e and f have significative
values), combine them. Quicker than multiplying them, for this
precise case."
([{m1a :a m1b :b m1c :c m1d :d m1e :e m1f :f}
{m2a :a m2b :b m2c :c m2d :d m2e :e m2f :f}]
([{m1e :e m1f :f} {m2e :e m2f :f}]
(Matrix.
1
0
0
1
0
0
1
(+ m1e m2e)
(+ m1f m2f)))

View file

@ -32,13 +32,10 @@
(when verify?
(us/assert ::spec/changes items))
(let [pages (into #{} (map :page-id) items)
result (->> items
(reduce #(or (process-change %1 %2) %1) data))]
(let [result (reduce #(or (process-change %1 %2) %1) data items)]
;; Validate result shapes (only on the backend)
#?(:clj
(doseq [page-id pages]
(doseq [page-id (into #{} (map :page-id) items)]
(let [page (get-in result [:pages-index page-id])]
(doseq [[id shape] (:objects page)]
(when-not (= shape (get-in data [:pages-index page-id :objects id]))

View file

@ -395,11 +395,11 @@
:internal.media-object/mtype]))
(s/def ::media-object-update
(s/keys :req-un [::id]
:req-opt [::name
:internal.media-object/width
:internal.media-object/height
:internal.media-object/mtype]))
(s/keys :req-un [::id]
:opt-un [::name
:internal.media-object/width
:internal.media-object/height
:internal.media-object/mtype]))
(s/def :internal.file/colors
(s/map-of ::uuid ::color))

View file

@ -15,11 +15,11 @@
;; NOTE: don't remove this, causes exception on advanced build
;; because of some strange interaction with cljs.spec.alpha and
;; modules spliting.
[expound.alpha]
[app.common.exceptions :as ex]
[app.common.geom.point :as gpt]
[app.common.uuid :as uuid]
[cuerdas.core :as str]))
[cuerdas.core :as str]
[expound.alpha]))
(s/check-asserts true)

View file

@ -7,7 +7,7 @@
(ns app.common.uuid
(:refer-clojure :exclude [next uuid zero?])
(:require
[app.common.data :as d]
#?(:clj [app.common.data :as d])
#?(:clj [clj-uuid :as impl])
#?(:clj [clojure.core :as c])
#?(:cljs [app.common.uuid-impl :as impl])

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -7,10 +7,10 @@
(ns app.main.data.modal
(:refer-clojure :exclude [update])
(:require
[potok.core :as ptk]
[app.main.store :as st]
[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 {}))
@ -29,7 +29,7 @@
:allow-click-outside false})))))
(defn update-props
([type props]
([_type props]
(ptk/reify ::update-modal-props
ptk/UpdateEvent
(update [_ state]

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -10,14 +10,13 @@
[app.common.pages :as cp]
[app.common.pages.spec :as spec]
[app.common.spec :as us]
[app.main.data.workspace.undo :as dwu]
[app.main.data.workspace.state-helpers :as wsh]
[app.main.worker :as uw]
[app.main.data.workspace.undo :as dwu]
[app.main.store :as st]
[app.main.worker :as uw]
[app.util.logging :as log]
[beicon.core :as rx]
[cljs.spec.alpha :as s]
[clojure.set :as set]
[potok.core :as ptk]))
;; Change this to :info :debug or :trace to debug this module
@ -59,29 +58,29 @@
attrs)
uops (cond-> uops
(not (empty? uops))
(seq uops)
(conj {:type :set-touched :touched (:touched old-obj)}))
change {:type :mod-obj :page-id page-id :id id}]
(cond-> changes
(not (empty? rops))
(seq rops)
(update :redo-changes conj (assoc change :operations rops))
(not (empty? uops))
(seq uops)
(update :undo-changes conj (assoc change :operations uops)))))
(defn update-shapes
([ids f] (update-shapes ids f nil))
([ids f {:keys [reg-objects? save-undo? keys]
:or {reg-objects? false save-undo? true attrs nil}}]
:or {reg-objects? false save-undo? true}}]
(us/assert ::coll-of-uuid ids)
(us/assert fn? f)
(ptk/reify ::update-shapes
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state)
changes {:redo-changes []
@ -107,7 +106,7 @@
[page-id changes]
(ptk/reify ::update-indices
ptk/EffectEvent
(effect [_ state stream]
(effect [_ _ _]
(uw/ask! {:cmd :update-page-indices
:page-id page-id
:changes changes}))))
@ -147,7 +146,7 @@
state))))
ptk/WatchEvent
(watch [it state stream]
(watch [_ _ _]
(when-not @error
(let [;; adds page-id to page changes (that have the `id` field instead)
add-page-id
@ -163,7 +162,7 @@
(group-by :page-id))
process-page-changes
(fn [[page-id changes]]
(fn [[page-id _changes]]
(update-indices page-id redo-changes))]
(rx/concat
(rx/from (map process-page-changes changes-by-pages))

View file

@ -7,23 +7,13 @@
(ns app.main.data.workspace.colors
(:require
[app.common.data :as d]
[app.common.pages :as cp]
[app.common.spec :as us]
[app.common.uuid :as uuid]
[app.main.data.modal :as md]
[app.main.data.workspace.changes :as dch]
[app.main.data.workspace.state-helpers :as wsh]
[app.main.data.workspace.texts :as dwt]
[app.main.repo :as rp]
[app.main.store :as st]
[app.main.streams :as ms]
[app.util.color :as color]
[app.util.i18n :refer [tr]]
[app.util.router :as rt]
[app.util.time :as dt]
[beicon.core :as rx]
[cljs.spec.alpha :as s]
[clojure.set :as set]
[potok.core :as ptk]))
(def clear-color-for-rename
@ -38,17 +28,16 @@
[file-id color-id name]
(ptk/reify ::rename-color
ptk/WatchEvent
(watch [_ state stream]
(watch [_ _ _]
(->> (rp/mutation! :rename-color {:id color-id :name name})
(rx/map (partial rename-color-result file-id))))))
(defn rename-color-result
[file-id color]
[_file-id color]
(ptk/reify ::rename-color-result
ptk/UpdateEvent
(update [_ state]
(-> state
(update-in [:workspace-file :colors] #(d/replace-by-id % color))))))
(update-in state [:workspace-file :colors] #(d/replace-by-id % color)))))
(defn change-palette-size
[size]
@ -125,7 +114,7 @@
[ids color]
(ptk/reify ::change-fill
ptk/WatchEvent
(watch [_ state s]
(watch [_ state _]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
@ -157,32 +146,29 @@
[ids color]
(ptk/reify ::change-stroke
ptk/WatchEvent
(watch [_ state s]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
(watch [_ _ _]
(let [attrs (cond-> {}
(contains? color :color)
(assoc :stroke-color (:color color))
attrs (cond-> {}
(contains? color :color)
(assoc :stroke-color (:color color))
(contains? color :id)
(assoc :stroke-color-ref-id (:id color))
(contains? color :id)
(assoc :stroke-color-ref-id (:id color))
(contains? color :file-id)
(assoc :stroke-color-ref-file (:file-id color))
(contains? color :file-id)
(assoc :stroke-color-ref-file (:file-id color))
(contains? color :gradient)
(assoc :stroke-color-gradient (:gradient color))
(contains? color :gradient)
(assoc :stroke-color-gradient (:gradient color))
(contains? color :opacity)
(assoc :stroke-opacity (:opacity color)))]
(contains? color :opacity)
(assoc :stroke-opacity (:opacity color)))]
(rx/of (dch/update-shapes ids (fn [shape]
(cond-> (d/merge shape attrs)
(= (:stroke-style shape) :none)
(assoc :stroke-style :solid
:stroke-width 1
:stroke-opacity 1)))))))))
(rx/of (dch/update-shapes ids (fn [shape]
(cond-> (d/merge shape attrs)
(= (:stroke-style shape) :none)
(assoc :stroke-style :solid
:stroke-width 1
:stroke-opacity 1)))))))))
(defn picker-for-selected-shape

View file

@ -6,19 +6,14 @@
(ns app.main.data.workspace.comments
(:require
[app.common.data :as d]
[app.common.exceptions :as ex]
[app.common.math :as mth]
[app.common.spec :as us]
[app.main.constants :as c]
[app.main.data.comments :as dcm]
[app.main.data.workspace :as dw]
[app.main.data.workspace.common :as dwc]
[app.main.data.comments :as dcm]
[app.main.store :as st]
[app.main.streams :as ms]
[app.util.router :as rt]
[beicon.core :as rx]
[cljs.spec.alpha :as s]
[potok.core :as ptk]))
(declare handle-interrupt)
@ -29,7 +24,7 @@
(us/assert ::us/uuid file-id)
(ptk/reify ::initialize-comments
ptk/WatchEvent
(watch [_ state stream]
(watch [_ _ stream]
(let [stoper (rx/filter #(= ::finalize %) stream)]
(rx/merge
(rx/of (dcm/retrieve-comment-threads file-id))
@ -47,8 +42,8 @@
[]
(ptk/reify ::handle-interrupt
ptk/WatchEvent
(watch [_ state stream]
(let [local (:comments-local state)]
(watch [_ state _]
(let [local (:comments-local state)]
(cond
(:draft local) (rx/of (dcm/close-thread))
(:open local) (rx/of (dcm/close-thread))
@ -62,7 +57,7 @@
[position]
(ptk/reify ::handle-comment-layer-click
ptk/WatchEvent
(watch [_ state stream]
(watch [_ state _]
(let [local (:comments-local state)]
(if (some? (:open local))
(rx/of (dcm/close-thread))
@ -74,14 +69,13 @@
(rx/of (dcm/create-draft params))))))))
(defn center-to-comment-thread
[{:keys [id position] :as thread}]
[{:keys [position] :as thread}]
(us/assert ::dcm/comment-thread thread)
(ptk/reify :center-to-comment-thread
ptk/UpdateEvent
(update [_ state]
(update state :workspace-local
(fn [{:keys [vbox vport zoom] :as local}]
(prn "center-to-comment-thread" vbox)
(fn [{:keys [vbox zoom] :as local}]
(let [pw (/ 50 zoom)
ph (/ 200 zoom)
nw (mth/round (- (/ (:width vbox) 2) pw))
@ -93,11 +87,11 @@
(update local :vbox assoc :x nx :y ny)))))))
(defn navigate
[{:keys [project-id file-id page-id] :as thread}]
[thread]
(us/assert ::dcm/comment-thread thread)
(ptk/reify ::navigate
ptk/WatchEvent
(watch [_ state stream]
(watch [_ _ stream]
(let [pparams {:project-id (:project-id thread)
:file-id (:file-id thread)}
qparams {:page-id (:page-id thread)}]

View file

@ -40,15 +40,13 @@
[{:keys [file] :as bundle}]
(ptk/reify ::setup-selection-index
ptk/WatchEvent
(watch [it state stream]
(watch [_ _ _]
(let [msg {:cmd :initialize-indices
:file-id (:id file)
:data (:data file)}]
(->> (uw/ask! msg)
(rx/map (constantly ::index-initialized)))))))
;; --- Common Helpers & Events
(defn get-frame-at-point
@ -59,7 +57,7 @@
(defn- extract-numeric-suffix
[basename]
(if-let [[match p1 p2] (re-find #"(.*)-([0-9]+)$" basename)]
(if-let [[_ p1 p2] (re-find #"(.*)-([0-9]+)$" basename)]
[p1 (+ 1 (d/parse-integer p2))]
[basename 1]))
@ -112,7 +110,7 @@
(def undo
(ptk/reify ::undo
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [edition (get-in state [:workspace-local :edition])
drawing (get state :workspace-drawing)]
;; Editors handle their own undo's
@ -131,7 +129,7 @@
(def redo
(ptk/reify ::redo
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [edition (get-in state [:workspace-local :edition])
drawing (get state :workspace-drawing)]
(when-not (or (some? edition) (not-empty drawing))
@ -180,10 +178,10 @@
(assoc-in state [:workspace-local :selected] ids))
ptk/WatchEvent
(watch [it state stream]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)]
(rx/of (expand-all-parents ids objects))))))
(watch [_ state _]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)]
(rx/of (expand-all-parents ids objects))))))
(declare clear-edition-mode)
@ -202,12 +200,11 @@
state)))
ptk/WatchEvent
(watch [it state stream]
(let [objects (wsh/lookup-page-objects state)]
(->> stream
(rx/filter interrupt?)
(rx/take 1)
(rx/map (constantly clear-edition-mode)))))))
(watch [_ _ stream]
(->> stream
(rx/filter interrupt?)
(rx/take 1)
(rx/map (constantly clear-edition-mode))))))
;; If these event change modules review /src/app/main/data/workspace/path/undo.cljs
(def clear-edition-mode
@ -282,7 +279,7 @@
(us/verify ::shape-attrs attrs)
(ptk/reify ::add-shape
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
@ -313,7 +310,7 @@
(defn move-shapes-into-frame [frame-id shapes]
(ptk/reify ::move-shapes-into-frame
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
to-move-shapes (->> (cp/select-toplevel-shapes objects {:include-frames? false})
@ -349,7 +346,7 @@
(us/assert ::set-of-uuid ids)
(ptk/reify ::delete-shapes
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
@ -504,7 +501,7 @@
[type frame-x frame-y data]
(ptk/reify ::create-and-add-shape
ptk/WatchEvent
(watch [it state stream]
(watch [_ state _]
(let [{:keys [width height]} data
[vbc-x vbc-y] (viewport-center state)
@ -524,7 +521,7 @@
[image {:keys [x y]}]
(ptk/reify ::image-uploaded
ptk/WatchEvent
(watch [it state stream]
(watch [_ _ _]
(let [{:keys [name width height id mtype]} image
shape {:name name
:width width

View file

@ -7,17 +7,15 @@
(ns app.main.data.workspace.drawing
"Drawing interactions."
(:require
[beicon.core :as rx]
[potok.core :as ptk]
[app.common.spec :as us]
[app.common.pages :as cp]
[app.common.uuid :as uuid]
[app.main.data.workspace.common :as dwc]
[app.main.data.workspace.selection :as dws]
[app.main.data.workspace.path :as path]
[app.main.data.workspace.drawing.box :as box]
[app.main.data.workspace.drawing.common :as common]
[app.main.data.workspace.drawing.curve :as curve]
[app.main.data.workspace.drawing.box :as box]))
[app.main.data.workspace.path :as path]
[beicon.core :as rx]
[potok.core :as ptk]))
(declare start-drawing)
(declare handle-drawing)
@ -38,7 +36,7 @@
(update :workspace-layout disj :scale-text)))
ptk/WatchEvent
(watch [_ state stream]
(watch [_ _ stream]
(let [stoper (rx/filter (ptk/type? ::clear-drawing) stream)]
(rx/merge
(when (= tool :path)
@ -88,16 +86,17 @@
(update-in state [:workspace-drawing :object] merge data)))
ptk/WatchEvent
(watch [_ state stream]
(rx/of (case type
:path
(path/handle-new-shape)
(watch [_ _ _]
(rx/of
(case type
:path
(path/handle-new-shape)
:curve
(curve/handle-drawing-curve)
:curve
(curve/handle-drawing-curve)
;; default
(box/handle-drawing-box))))))
;; default
(box/handle-drawing-box))))))

View file

@ -21,7 +21,7 @@
(defn truncate-zero [num default]
(if (mth/almost-zero? num) default num))
(defn resize-shape [{:keys [x y width height transform transform-inverse] :as shape} point lock?]
(defn resize-shape [{:keys [x y width height] :as shape} point lock?]
(let [;; The new shape behaves like a resize on the bottom-right corner
initial (gpt/point (+ x width) (+ y height))
shapev (gpt/point width height)
@ -53,9 +53,7 @@
(ptk/reify ::handle-drawing-box
ptk/WatchEvent
(watch [_ state stream]
(let [{:keys [flags]} (:workspace-local state)
stoper? #(or (ms/mouse-up? %) (= % :interrupt))
(let [stoper? #(or (ms/mouse-up? %) (= % :interrupt))
stoper (rx/filter stoper? stream)
initial @ms/mouse-position

View file

@ -6,15 +6,13 @@
(ns app.main.data.workspace.drawing.common
(:require
[beicon.core :as rx]
[potok.core :as ptk]
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh]
[app.main.data.workspace.common :as dwc]
[app.main.data.workspace.selection :as dws]
[app.main.data.workspace.undo :as dwu]
[app.main.streams :as ms]
[app.main.worker :as uw]))
[app.main.worker :as uw]
[beicon.core :as rx]
[potok.core :as ptk]))
(def clear-drawing
(ptk/reify ::clear-drawing
@ -25,7 +23,7 @@
(def handle-finish-drawing
(ptk/reify ::handle-finish-drawing
ptk/WatchEvent
(watch [_ state stream]
(watch [_ state _]
(let [shape (get-in state [:workspace-drawing :object])]
(rx/concat
(when (:initialized? shape)

View file

@ -6,7 +6,6 @@
(ns app.main.data.workspace.drawing.curve
(:require
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh]
[app.common.geom.shapes.path :as gsp]
[app.common.pages :as cp]
@ -19,7 +18,7 @@
(def simplify-tolerance 0.3)
(defn stoper-event? [{:keys [type shift] :as event}]
(defn stoper-event? [{:keys [type] :as event}]
(ms/mouse-event? event) (= type :up))
(defn initialize-drawing [state]
@ -73,9 +72,8 @@
(defn handle-drawing-curve []
(ptk/reify ::handle-drawing-curve
ptk/WatchEvent
(watch [_ state stream]
(let [{:keys [flags]} (:workspace-local state)
stoper (rx/filter stoper-event? stream)
(watch [_ _ stream]
(let [stoper (rx/filter stoper-event? stream)
mouse (rx/sample 10 ms/mouse-position)]
(rx/concat
(rx/of initialize-drawing)

View file

@ -6,11 +6,11 @@
(ns app.main.data.workspace.grid
(:require
[beicon.core :as rx]
[potok.core :as ptk]
[app.common.data :as d]
[app.common.spec :as us]
[app.main.data.workspace.changes :as dch]))
[app.main.data.workspace.changes :as dch]
[beicon.core :as rx]
[potok.core :as ptk]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Grid
@ -40,7 +40,7 @@
(us/assert ::us/uuid frame-id)
(ptk/reify ::add-frame-grid
ptk/WatchEvent
(watch [it state stream]
(watch [_ state _]
(let [page-id (:current-page-id state)
data (get-in state [:workspace-data :pages-index page-id])
params (or (get-in data [:options :saved-grids :square])
@ -56,21 +56,21 @@
[frame-id index]
(ptk/reify ::set-frame-grid
ptk/WatchEvent
(watch [it state stream]
(watch [_ _ _]
(rx/of (dch/update-shapes [frame-id] (fn [o] (update o :grids (fnil #(d/remove-at-index % index) []))))))))
(defn set-frame-grid
[frame-id index data]
(ptk/reify ::set-frame-grid
ptk/WatchEvent
(watch [it state stream]
(watch [_ _ _]
(rx/of (dch/update-shapes [frame-id] #(assoc-in % [:grids index] data))))))
(defn set-default-grid
[type params]
(ptk/reify ::set-default-grid
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [pid (:current-page-id state)
prev-value (get-in state [:workspace-data :pages-index pid :options :saved-grids type])]
(rx/of (dch/commit-changes

View file

@ -1,3 +1,9 @@
;; 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.workspace.groups
(:require
[app.common.data :as d]
@ -5,7 +11,6 @@
[app.common.pages :as cp]
[app.main.data.workspace.changes :as dch]
[app.main.data.workspace.common :as dwc]
[app.main.data.workspace.selection :as dws]
[app.main.data.workspace.state-helpers :as wsh]
[beicon.core :as rx]
[potok.core :as ptk]))
@ -22,7 +27,6 @@
[shapes prefix keep-name]
(let [selrect (gsh/selection-rect shapes)
frame-id (-> shapes first :frame-id)
parent-id (-> shapes first :parent-id)
group-name (if (and keep-name
(= (count shapes) 1)
(= (:type (first shapes)) :group))
@ -166,7 +170,7 @@
(def group-selected
(ptk/reify ::group-selected
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
selected (wsh/lookup-selected state)
@ -183,7 +187,7 @@
(def ungroup-selected
(ptk/reify ::ungroup-selected
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
selected (wsh/lookup-selected state)
@ -200,7 +204,7 @@
(def mask-group
(ptk/reify ::mask-group
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
selected (wsh/lookup-selected state)
@ -257,7 +261,7 @@
(def unmask-group
(ptk/reify ::unmask-group
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
selected (wsh/lookup-selected state)]

View file

@ -46,7 +46,7 @@
(:component-id change)
:objects
(:id change)])
:default nil))
:else nil))
prefix (if (:component-id change) "[C] " "[P] ")
@ -90,7 +90,7 @@
(us/assert ::cp/color color)
(ptk/reify ::add-color
ptk/WatchEvent
(watch [it state s]
(watch [it _ _]
(let [rchg {:type :add-color
:color color}
uchg {:type :del-color
@ -104,7 +104,7 @@
(us/assert ::cp/recent-color color)
(ptk/reify ::add-recent-color
ptk/WatchEvent
(watch [it state s]
(watch [it _ _]
(let [rchg {:type :add-recent-color
:color color}]
(rx/of (dch/commit-changes {:redo-changes [rchg]
@ -123,7 +123,7 @@
(us/assert ::us/uuid file-id)
(ptk/reify ::update-color
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [[path name] (cp/parse-path-name (:name color))
color (assoc color :path path :name name)
prev (get-in state [:workspace-data :colors id])
@ -141,7 +141,7 @@
(us/assert ::us/uuid id)
(ptk/reify ::delete-color
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [prev (get-in state [:workspace-data :colors id])
rchg {:type :del-color
:id id}
@ -156,7 +156,7 @@
(us/assert ::cp/media-object media)
(ptk/reify ::add-media
ptk/WatchEvent
(watch [it state stream]
(watch [it _ _]
(let [obj (select-keys media [:id :name :width :height :mtype])
rchg {:type :add-media
:object obj}
@ -172,7 +172,7 @@
(us/assert ::us/string new-name)
(ptk/reify ::rename-media
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [object (get-in state [:workspace-data :media id])
[path name] (cp/parse-path-name new-name)
@ -195,7 +195,7 @@
(us/assert ::us/uuid id)
(ptk/reify ::delete-media
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [prev (get-in state [:workspace-data :media id])
rchg {:type :del-media
:id id}
@ -212,7 +212,7 @@
(us/assert ::cp/typography typography)
(ptk/reify ::add-typography
ptk/WatchEvent
(watch [it state s]
(watch [it _ _]
(let [rchg {:type :add-typography
:typography typography}
uchg {:type :del-typography
@ -230,7 +230,7 @@
(us/assert ::us/uuid file-id)
(ptk/reify ::update-typography
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [[path name] (cp/parse-path-name (:name typography))
typography (assoc typography :path path :name name)
prev (get-in state [:workspace-data :typographies (:id typography)])
@ -248,7 +248,7 @@
(us/assert ::us/uuid id)
(ptk/reify ::delete-typography
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [prev (get-in state [:workspace-data :typographies id])
rchg {:type :del-typography
:id id}
@ -262,7 +262,7 @@
"Add a new component to current file library, from the currently selected shapes."
(ptk/reify ::add-component
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [file-id (:current-file-id state)
page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
@ -285,7 +285,7 @@
(us/assert ::us/string new-name)
(ptk/reify ::rename-component
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [[path name] (cp/parse-path-name new-name)
component (get-in state [:workspace-data :components id])
objects (get component :objects)
@ -315,7 +315,7 @@
[{:keys [id] :as params}]
(ptk/reify ::duplicate-component
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [component (cp/get-component id
(:current-file-id state)
(dwlh/get-local-file state)
@ -324,7 +324,7 @@
unames (set (map :name all-components))
new-name (dwc/generate-unique-name unames (:name component))
[new-shape new-shapes updated-shapes]
[new-shape new-shapes _updated-shapes]
(dwlh/duplicate-component component)
rchanges [{:type :add-component
@ -346,7 +346,7 @@
(us/assert ::us/uuid id)
(ptk/reify ::delete-component
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [component (get-in state [:workspace-data :components id])
rchanges [{:type :del-component
@ -371,7 +371,7 @@
(us/assert ::us/point position)
(ptk/reify ::instantiate-component
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [local-library (dwlh/get-local-file state)
libraries (get state :workspace-libraries)
component (cp/get-component component-id file-id local-library libraries)
@ -449,7 +449,7 @@
(us/assert ::us/uuid id)
(ptk/reify ::detach-component
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
shapes (cp/get-object-with-children id objects)
@ -511,13 +511,13 @@
(us/assert ::us/uuid file-id)
(ptk/reify ::nav-to-component-file
ptk/WatchEvent
(watch [it state stream]
(let [file (get-in state [:workspace-libraries file-id])
(watch [_ state _]
(let [file (get-in state [:workspace-libraries file-id])
pparams {:project-id (:project-id file)
:file-id (:id file)}
qparams {:page-id (first (get-in file [:data :pages]))
:layout :assets}]
(st/emit! (rt/nav-new-window :workspace pparams qparams))))))
(rx/of (rt/nav-new-window :workspace pparams qparams))))))
(defn ext-library-changed
[file-id modified-at revn changes]
@ -540,7 +540,7 @@
(us/assert ::us/uuid id)
(ptk/reify ::reset-component
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(log/info :msg "RESET-COMPONENT of shape" :id (str id))
(let [local-library (dwlh/get-local-file state)
libraries (dwlh/get-libraries state)
@ -574,7 +574,7 @@
(us/assert ::us/uuid id)
(ptk/reify ::update-component
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(log/info :msg "UPDATE-COMPONENT of shape" :id (str id))
(let [page-id (get state :current-page-id)
local-library (dwlh/get-local-file state)
@ -642,7 +642,7 @@
state))
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(log/info :msg "SYNC-FILE"
:file (dwlh/pretty-file file-id state)
:library (dwlh/pretty-file library-id state))
@ -702,7 +702,7 @@
(us/assert ::us/uuid library-id)
(ptk/reify ::sync-file-2nd-stage
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(log/info :msg "SYNC-FILE (2nd stage)"
:file (dwlh/pretty-file file-id state)
:library (dwlh/pretty-file library-id state))
@ -727,7 +727,7 @@
(assoc-in state [:workspace-file :ignore-sync-until] (dt/now)))
ptk/WatchEvent
(watch [it state stream]
(watch [_ state _]
(rp/mutation :ignore-sync
{:file-id (get-in state [:workspace-file :id])
:date (dt/now)}))))
@ -737,7 +737,7 @@
(us/assert ::us/uuid file-id)
(ptk/reify ::notify-sync-file
ptk/WatchEvent
(watch [it state stream]
(watch [_ state _]
(let [libraries-need-sync (filter #(> (:modified-at %) (:synced-at %))
(vals (get state :workspace-libraries)))
do-update #(do (apply st/emit! (map (fn [library]

View file

@ -90,7 +90,7 @@
(assert (nil? (:shape-ref shape)))
(let [;; Ensure that the component root is not an instance and
;; it's no longer tied to a frame.
update-new-shape (fn [new-shape original-shape]
update-new-shape (fn [new-shape _original-shape]
(cond-> new-shape
true
(-> (assoc :frame-id nil)
@ -338,10 +338,10 @@
(defmulti generate-sync-shape
"Generate changes to synchronize one shape with all assets of the given type
that is using, in the given library."
(fn [type library-id state container shape] type))
(fn [type _library-id _state _container _shape] type))
(defmethod generate-sync-shape :components
[_ library-id state container shape]
[_ _ state container shape]
(generate-sync-shape-direct container
(:id shape)
(get-local-file state)
@ -666,7 +666,7 @@
[(d/concat rchanges child-rchanges)
(d/concat uchanges child-uchanges)]))
(defn- generate-sync-shape-inverse
(defn generate-sync-shape-inverse
"Generate changes to update the component a shape is linked to, from
the values in the shape and all its children."
[page-id shape-id local-library libraries]
@ -886,10 +886,10 @@
set-remote-synced?
(assoc :remote-synced? true))))
update-original-shape (fn [original-shape new-shape]
update-original-shape (fn [original-shape _new-shape]
original-shape)
[new-shape new-shapes _]
[_ new-shapes _]
(cp/clone-object component-shape
(:id parent-shape)
(get component :objects)
@ -939,7 +939,7 @@
(cp/get-parents (:id component-parent-shape)
(:objects component))))
update-new-shape (fn [new-shape original-shape]
update-new-shape (fn [new-shape _original-shape]
(reposition-shape new-shape
root-instance
root-main))
@ -950,7 +950,7 @@
:shape-ref (:id new-shape))
original-shape))
[new-shape new-shapes updated-shapes]
[_new-shape new-shapes updated-shapes]
(cp/clone-object shape
(:id component-parent-shape)
(get page :objects)
@ -1141,33 +1141,6 @@
:remote-synced? (:remote-synced? shape)}]})]]
[rchanges uchanges]))))
(defn- set-touched-shapes-group
[shape container]
(if-not (:shape-ref shape)
empty-changes
(do
(log/info :msg (str "SET-TOUCHED-SHAPES-GROUP "
(if (cp/page? container) "[P] " "[C] ")
(:name shape)))
(let [rchanges [(make-change
container
{:type :mod-obj
:id (:id shape)
:operations
[{:type :set-touched
:touched (cp/set-touched-group
(:touched shape)
:shapes-group)}]})]
uchanges [(make-change
container
{:type :mod-obj
:id (:id shape)
:operations
[{:type :set-touched
:touched (:touched shape)}]})]]
[rchanges uchanges]))))
(defn- update-attrs
"The main function that implements the attribute sync algorithm. Copy
attributes that have changed in the origin shape to the dest shape.

View file

@ -16,11 +16,7 @@
[app.main.data.workspace.changes :as dch]
[app.main.data.workspace.libraries :as dwl]
[app.main.data.workspace.persistence :as dwp]
[app.main.repo :as rp]
[app.main.store :as st]
[app.main.streams :as ms]
[app.util.avatars :as avatars]
[app.util.i18n :as i18n :refer [tr]]
[app.util.time :as dt]
[app.util.websockets :as ws]
[beicon.core :as rx]
@ -104,7 +100,7 @@
[file-id]
(ptk/reify ::send-keepalive
ptk/EffectEvent
(effect [_ state stream]
(effect [_ state _]
(when-let [ws (get-in state [:ws file-id])]
(ws/send! ws {:type :keepalive})))))
@ -112,9 +108,8 @@
[file-id point]
(ptk/reify ::handle-pointer-update
ptk/EffectEvent
(effect [_ state stream]
(effect [_ state _]
(let [ws (get-in state [:ws file-id])
sid (:session-id state)
pid (:current-page-id state)
msg {:type :pointer-update
:page-id pid
@ -128,7 +123,7 @@
[file-id]
(ptk/reify ::finalize
ptk/WatchEvent
(watch [_ state stream]
(watch [_ state _]
(when-let [ws (get-in state [:ws file-id])]
(ws/-close ws))
(rx/of ::finalize))))
@ -187,7 +182,7 @@
(update state :workspace-presence update-presence))))))
(defn handle-pointer-update
[{:keys [page-id profile-id session-id x y] :as msg}]
[{:keys [page-id session-id x y] :as msg}]
(ptk/reify ::handle-pointer-update
ptk/UpdateEvent
(update [_ state]
@ -213,7 +208,7 @@
(us/assert ::file-change-event msg)
(ptk/reify ::handle-file-change
ptk/WatchEvent
(watch [_ state stream]
(watch [_ _ _]
(let [changes-by-pages (group-by :page-id changes)
process-page-changes
(fn [[page-id changes]]
@ -239,7 +234,7 @@
(us/assert ::library-change-event msg)
(ptk/reify ::handle-library-change
ptk/WatchEvent
(watch [_ state stream]
(watch [_ state _]
(when (contains? (:workspace-libraries state) file-id)
(rx/of (dwl/ext-library-changed file-id modified-at revn changes)
(dwl/notify-sync-file file-id))))))

View file

@ -84,7 +84,7 @@
(assoc-in state (st/get-path state :content) content)))
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [objects (wsh/lookup-page-objects state)
page-id (:current-page-id state)
id (get-in state [:workspace-local :edition])

View file

@ -16,7 +16,8 @@
[state]
(dissoc state :last-point :prev-handler :drag-handler :preview))
(defn finish-path [source]
(defn finish-path
[_source]
(ptk/reify ::finish-path
ptk/UpdateEvent
(update [_ state]

View file

@ -17,7 +17,6 @@
[app.main.data.workspace.path.spec :as spec]
[app.main.data.workspace.path.state :as st]
[app.main.data.workspace.path.streams :as streams]
[app.main.data.workspace.path.tools :as tools]
[app.main.data.workspace.path.undo :as undo]
[app.main.data.workspace.state-helpers :as wsh]
[app.main.streams :as ms]
@ -60,9 +59,8 @@
state)))))
(defn drag-handler
([{:keys [x y alt? shift?] :as position}]
([position]
(drag-handler nil nil :c1 position))
([position index prefix {:keys [x y alt? shift?]}]
(ptk/reify ::drag-handler
ptk/UpdateEvent
@ -110,7 +108,7 @@
(update-in (st/get-path state) helpers/update-selrect))))
ptk/WatchEvent
(watch [_ state stream]
(watch [_ state _]
(let [id (st/get-path-id state)
handler (get-in state [:workspace-local :edit-path id :prev-handler])]
;; Update the preview because can be outdated after the dragging
@ -124,9 +122,6 @@
ptk/WatchEvent
(watch [_ state stream]
(let [id (st/get-path-id state)
zoom (get-in state [:workspace-local :zoom])
start-position @ms/mouse-position
stop-stream
(->> stream (rx/filter #(or (helpers/end-path-event? %)
(ms/mouse-up? %))))
@ -166,9 +161,7 @@
(ptk/reify ::start-path-from-point
ptk/WatchEvent
(watch [_ state stream]
(let [start-point @ms/mouse-position
zoom (get-in state [:workspace-local :zoom])
mouse-up (->> stream (rx/filter #(or (helpers/end-path-event? %)
(let [mouse-up (->> stream (rx/filter #(or (helpers/end-path-event? %)
(ms/mouse-up? %))))
content (get-in state (st/get-path state :content))
points (upg/content->points content)
@ -195,7 +188,7 @@
(rx/merge-map #(rx/empty))))
(defn make-drag-stream
[stream snap-toggled zoom points down-event]
[stream snap-toggled _zoom points down-event]
(let [mouse-up (->> stream (rx/filter #(or (helpers/end-path-event? %)
(ms/mouse-up? %))))
@ -211,7 +204,7 @@
(rx/of (finish-drag)))))))
(defn handle-drawing-path
[id]
[_id]
(ptk/reify ::handle-drawing-path
ptk/UpdateEvent
(update [_ state]
@ -278,11 +271,11 @@
state)))
ptk/WatchEvent
(watch [_ state stream]
(->> (rx/of (setup-frame-path)
dwdc/handle-finish-drawing
(dwc/start-edition-mode shape-id)
(change-edit-mode :draw))))))
(watch [_ _ _]
(rx/of (setup-frame-path)
dwdc/handle-finish-drawing
(dwc/start-edition-mode shape-id)
(change-edit-mode :draw)))))
(defn handle-new-shape
"Creates a new path shape"
@ -333,7 +326,7 @@
(defn check-changed-content []
(ptk/reify ::check-changed-content
ptk/WatchEvent
(watch [_ state stream]
(watch [_ state _]
(let [id (st/get-path-id state)
content (get-in state (st/get-path state :content))
old-content (get-in state [:workspace-local :edit-path id :old-content])
@ -354,7 +347,7 @@
id (assoc-in [:workspace-local :edit-path id :edit-mode] mode))))
ptk/WatchEvent
(watch [_ state stream]
(watch [_ state _]
(let [id (st/get-path-id state)]
(cond
(and id (= :move mode)) (rx/of (common/finish-path "change-edit-mode"))

View file

@ -8,11 +8,9 @@
(:require
[app.common.data :as d]
[app.common.geom.point :as gpt]
[app.common.math :as mth]
[app.main.data.workspace.common :as dwc]
[app.main.data.workspace.changes :as dch]
[app.main.data.workspace.common :as dwc]
[app.main.data.workspace.path.changes :as changes]
[app.main.data.workspace.path.common :as common]
[app.main.data.workspace.path.drawing :as drawing]
[app.main.data.workspace.path.helpers :as helpers]
[app.main.data.workspace.path.selection :as selection]
@ -47,7 +45,7 @@
(defn apply-content-modifiers []
(ptk/reify ::apply-content-modifiers
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [objects (wsh/lookup-page-objects state)
id (st/get-path-id state)
@ -137,7 +135,7 @@
[position shift?]
(ptk/reify ::start-move-path-point
ptk/WatchEvent
(watch [it state stream]
(watch [_ state _]
(let [id (get-in state [:workspace-local :edition])
selected-points (get-in state [:workspace-local :edit-path id :selected-points] #{})
selected? (contains? selected-points position)]
@ -151,7 +149,7 @@
[start-position]
(ptk/reify ::drag-selected-points
ptk/WatchEvent
(watch [it state stream]
(watch [_ state stream]
(let [stopper (->> stream (rx/filter ms/mouse-up?))
id (get-in state [:workspace-local :edition])
snap-toggled (get-in state [:workspace-local :edit-path id :snap-toggled])
@ -206,7 +204,7 @@
state)))
ptk/WatchEvent
(watch [it state stream]
(watch [_ state stream]
(let [id (get-in state [:workspace-local :edition])
current-move (get-in state [:workspace-local :edit-path id :current-move])]
(if (= same-event current-move)
@ -240,7 +238,7 @@
[index prefix]
(ptk/reify ::start-move-handler
ptk/WatchEvent
(watch [it state stream]
(watch [_ state stream]
(let [id (get-in state [:workspace-local :edition])
cx (d/prefix-keyword prefix :x)
cy (d/prefix-keyword prefix :y)
@ -297,7 +295,7 @@
(assoc-in [:workspace-local :edit-path id :edit-mode] :draw))))
ptk/WatchEvent
(watch [it state stream]
(watch [_ state stream]
(let [mode (get-in state [:workspace-local :edit-path id :edit-mode])]
(rx/concat
(rx/of (undo/start-path-undo))
@ -327,5 +325,5 @@
(update-in (st/get-path state :content) upt/split-segments #{from-p to-p} t))))
ptk/WatchEvent
(watch [it state stream]
(watch [_ _ _]
(rx/of (changes/save-path-content {:preserve-move-to true})))))

View file

@ -6,25 +6,23 @@
(ns app.main.data.workspace.path.helpers
(:require
[app.common.data :as d]
[app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh]
[app.common.math :as mth]
[app.main.data.workspace.path.common :as common]
[app.main.data.workspace.path.state :refer [get-path]]
[app.main.streams :as ms]
[app.util.path.commands :as upc]
[app.util.path.subpaths :as ups]
[potok.core :as ptk]))
(defn end-path-event? [{:keys [type shift] :as event}]
(defn end-path-event? [event]
(or (= (ptk/type event) ::common/finish-path)
(= (ptk/type event) :esc-pressed)
(= :app.main.data.workspace.common/clear-edition-mode (ptk/type event))
(= :app.main.data.workspace/finalize-page (ptk/type event))
(= event :interrupt) ;; ESC
(and (ms/mouse-double-click? event))))
(ms/mouse-double-click? event)))
(defn content-center
[content]
@ -35,7 +33,6 @@
(defn content->points+selrect
"Given the content of a shape, calculate its points and selrect"
[shape content]
(let [{:keys [flip-x flip-y]} shape
transform
(cond-> (:transform shape (gmt/matrix))

View file

@ -22,7 +22,7 @@
(defn esc-pressed []
(ptk/reify :esc-pressed
ptk/WatchEvent
(watch [_ state stream]
(watch [_ state _]
;; Not interrupt when we're editing a path
(let [edition-id (or (get-in state [:workspace-drawing :object :id])
(get-in state [:workspace-local :edition]))

View file

@ -40,8 +40,8 @@
(s/def ::content-entry
(s/keys :req-un [::command]
:req-opt [::params
::relative?]))
:opt-un [::params
::relative?]))
(s/def ::content
(s/coll-of ::content-entry :kind vector?))

View file

@ -6,17 +6,16 @@
(ns app.main.data.workspace.path.streams
(:require
[app.main.data.workspace.path.helpers :as helpers]
[app.main.data.workspace.path.state :as state]
[app.common.geom.point :as gpt]
[app.common.math :as mth]
[app.main.data.workspace.path.state :as state]
[app.main.snap :as snap]
[app.main.store :as st]
[app.main.streams :as ms]
[app.util.path.geom :as upg]
[beicon.core :as rx]
[potok.core :as ptk]
[app.common.math :as mth]
[app.main.snap :as snap]
[okulary.core :as l]
[app.util.path.geom :as upg]))
[potok.core :as ptk]))
(defonce drag-threshold 5)
@ -50,7 +49,7 @@
(if (= value ::empty)
not-drag-stream
(rx/empty)))))
(->> position-stream
(rx/merge-map (fn [] to-stream)))))))
@ -107,7 +106,7 @@
(<= (- 180 rot-angle) 5))]
(cond
snap-opposite-angle?
snap-opposite-angle?
(let [rot-handler (gpt/rotate handler node (- 180 (* rot-sign rot-angle)))
snap (gpt/to-vec handler rot-handler)]
(merge position (gpt/add position snap)))
@ -122,7 +121,7 @@
(rx/map check-path-snap))))
(defn position-stream
[snap-toggled points]
[snap-toggled _points]
(let [zoom (get-in @st/state [:workspace-local :zoom] 1)
;; ranges (snap/create-ranges points)
d-pos (/ snap/snap-path-accuracy zoom)

View file

@ -6,11 +6,9 @@
(ns app.main.data.workspace.path.tools
(:require
[app.common.geom.point :as gpt]
[app.main.data.workspace.changes :as dch]
[app.main.data.workspace.common :as dwc]
[app.main.data.workspace.path.changes :as changes]
[app.main.data.workspace.path.common :as common]
[app.main.data.workspace.path.state :as st]
[app.main.data.workspace.state-helpers :as wsh]
[app.util.path.subpaths :as ups]
@ -25,7 +23,7 @@
([points tool-fn]
(ptk/reify ::process-path-tool
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [objects (wsh/lookup-page-objects state)
id (st/get-path-id state)
page-id (:current-page-id state)
@ -33,7 +31,7 @@
selected-points (get-in state [:workspace-local :edit-path id :selected-points] #{})
points (or points selected-points)]
(when (and (not (empty? points)) (some? shape))
(when (and (seq points) (some? shape))
(let [new-content (-> (tool-fn (:content shape) points)
(ups/close-subpaths))
[rch uch] (changes/generate-path-changes objects page-id shape (:content shape) new-content)]

View file

@ -9,8 +9,8 @@
[app.common.data :as d]
[app.common.data.undo-stack :as u]
[app.common.uuid :as uuid]
[app.main.data.workspace.path.state :as st]
[app.main.data.workspace.path.changes :as changes]
[app.main.data.workspace.path.state :as st]
[app.main.store :as store]
[beicon.core :as rx]
[okulary.core :as l]
@ -64,7 +64,7 @@
undo-stack)))))
ptk/WatchEvent
(watch [_ state stream]
(watch [_ _ _]
(rx/of (changes/save-path-content {:preserve-move-to true})))))
(defn redo-path []
@ -82,7 +82,7 @@
undo-stack))))
ptk/WatchEvent
(watch [_ state stream]
(watch [_ _ _]
(rx/of (changes/save-path-content)))))
(defn merge-head
@ -92,10 +92,9 @@
(ptk/reify ::add-undo-entry
ptk/UpdateEvent
(update [_ state]
(let [id (st/get-path-id state)
entry (make-entry state)
(let [id (st/get-path-id state)
stack (get-in state [:workspace-local :edit-path id :undo-stack])
head (u/peek stack)
head (u/peek stack)
stack (-> stack (u/undo) (u/fixup head))]
(-> state
(d/assoc-in-when
@ -145,7 +144,7 @@
assoc
:undo-lock lock
:undo-stack (u/make-stack)))))
ptk/WatchEvent
(watch [_ state stream]
(let [undo-lock (get-in state [:workspace-local :edit-path (st/get-path-id state) :undo-lock])]

View file

@ -8,8 +8,6 @@
(:require
[app.common.data :as d]
[app.common.exceptions :as ex]
[app.common.geom.point :as gpt]
[app.common.media :as cm]
[app.common.pages :as cp]
[app.common.spec :as us]
[app.common.uuid :as uuid]
@ -26,11 +24,9 @@
[app.main.refs :as refs]
[app.main.repo :as rp]
[app.main.store :as st]
[app.util.avatars :as avatars]
[app.util.http :as http]
[app.util.i18n :as i18n :refer [tr]]
[app.util.object :as obj]
[app.util.router :as rt]
[app.util.time :as dt]
[app.util.uri :as uu]
[beicon.core :as rx]
@ -52,7 +48,7 @@
[file-id]
(ptk/reify ::initialize-persistence
ptk/EffectEvent
(effect [_ state stream]
(effect [_ _ stream]
(let [stoper (rx/filter #(= ::finalize %) stream)
forcer (rx/filter #(= ::force-persist %) stream)
notifier (->> stream
@ -120,12 +116,11 @@
(ptk/reify ::persist-changes
ptk/UpdateEvent
(update [_ state]
(let [conj (fnil conj [])
into* (fnil into [])]
(let [into* (fnil into [])]
(update-in state [:workspace-persistence :queue] into* changes)))
ptk/WatchEvent
(watch [it state stream]
(watch [_ state _]
(let [sid (:session-id state)
file (get state :workspace-file)
queue (get-in state [:workspace-persistence :queue] [])
@ -176,7 +171,7 @@
(us/verify ::us/uuid file-id)
(ptk/reify ::persist-synchronous-changes
ptk/WatchEvent
(watch [it state stream]
(watch [_ state _]
(let [sid (:session-id state)
file (get-in state [:workspace-libraries file-id])
@ -255,11 +250,11 @@
(declare fetch-libraries-content)
(declare bundle-fetched)
(defn- fetch-bundle
(defn fetch-bundle
[project-id file-id]
(ptk/reify ::fetch-bundle
ptk/WatchEvent
(watch [it state stream]
(watch [_ _ _]
(->> (rx/zip (rp/query :file {:id file-id})
(rp/query :team-users {:file-id file-id})
(rp/query :project {:id project-id})
@ -285,7 +280,7 @@
(assoc-in state [:workspace-file :is-shared] is-shared))
ptk/WatchEvent
(watch [it state stream]
(watch [_ _ _]
(let [params {:id id :is-shared is-shared}]
(->> (rp/mutation :set-file-shared params)
(rx/ignore))))))
@ -300,7 +295,7 @@
(us/assert ::us/uuid team-id)
(ptk/reify ::fetch-shared-files
ptk/WatchEvent
(watch [it state stream]
(watch [_ _ _]
(->> (rp/query :team-shared-files {:team-id team-id})
(rx/map shared-files-fetched)))))
@ -320,7 +315,7 @@
[file-id library-id]
(ptk/reify ::link-file-to-library
ptk/WatchEvent
(watch [it state stream]
(watch [_ _ _]
(let [fetched #(assoc-in %2 [:workspace-libraries (:id %1)] %1)
params {:file-id file-id
:library-id library-id}]
@ -332,7 +327,7 @@
[file-id library-id]
(ptk/reify ::unlink-file-from-library
ptk/WatchEvent
(watch [it state stream]
(watch [_ _ _]
(let [unlinked #(d/dissoc-in % [:workspace-libraries library-id])
params {:file-id file-id
:library-id library-id}]
@ -348,7 +343,7 @@
(->> (rx/of (-> (tubax/xml->clj text)
(assoc :name name))))
(catch :default err
(catch :default _err
(rx/throw {:type :svg-parser}))))
(defn fetch-svg [name uri]
@ -458,7 +453,7 @@
(s/def ::process-media-objects
(s/and
(s/keys :req-un [::file-id ::local?]
:opt-in [::name ::data ::uris ::mtype])
:opt-un [::name ::data ::uris ::mtype])
(fn [props]
(or (contains? props :blobs)
(contains? props :uris)))))
@ -468,7 +463,7 @@
(us/assert ::process-media-objects params)
(ptk/reify ::process-media-objects
ptk/WatchEvent
(watch [it state stream]
(watch [_ _ _]
(rx/concat
(rx/of (dm/show {:content (tr "media.loading")
:type :info
@ -515,7 +510,7 @@
(us/assert ::clone-media-objects-params params)
(ptk/reify ::clone-media-objects
ptk/WatchEvent
(watch [it state stream]
(watch [_ _ _]
(let [{:keys [on-success on-error]
:or {on-success identity
on-error identity}} (meta params)
@ -548,7 +543,7 @@
[ids]
(ptk/reify ::remove-thumbnails
ptk/WatchEvent
(watch [_ state stream]
(watch [_ _ _]
;; Removes the thumbnail while it's regenerated
(rx/of (dch/update-shapes
ids

View file

@ -61,7 +61,7 @@
:height (mth/abs (- end-y start-y))}))]
(ptk/reify ::handle-selection
ptk/WatchEvent
(watch [_ state stream]
(watch [_ _ stream]
(let [stop? (fn [event] (or (dwc/interrupt? event) (ms/mouse-up? event)))
stoper (->> stream (rx/filter stop?))]
(rx/concat
@ -100,7 +100,7 @@
(conj selected id))))))
ptk/WatchEvent
(watch [_ state stream]
(watch [_ state _]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)]
(rx/of (dwc/expand-all-parents [id] objects)))))))
@ -136,7 +136,7 @@
(assoc-in state [:workspace-local :selected] ids))
ptk/WatchEvent
(watch [_ state stream]
(watch [_ state _]
(let [objects (wsh/lookup-page-objects state)]
(rx/of (dwc/expand-all-parents ids objects))))))
@ -144,7 +144,7 @@
[]
(ptk/reify ::select-all
ptk/WatchEvent
(watch [_ state stream]
(watch [_ state _]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
new-selected (let [selected-objs
@ -204,7 +204,7 @@
[preserve?]
(ptk/reify ::select-shapes-by-current-selrect
ptk/WatchEvent
(watch [_ state stream]
(watch [_ state _]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state)
selected (wsh/lookup-selected state)
@ -224,25 +224,23 @@
(rx/map select-shapes))))))))
(defn select-inside-group
([group-id position] (select-inside-group group-id position false))
([group-id position deep-children]
(ptk/reify ::select-inside-group
ptk/WatchEvent
(watch [_ state stream]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
group (get objects group-id)
children (map #(get objects %) (:shapes group))
[group-id position]
(ptk/reify ::select-inside-group
ptk/WatchEvent
(watch [_ state _]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
group (get objects group-id)
children (map #(get objects %) (:shapes group))
;; We need to reverse the children because if two children
;; overlap we want to select the one that's over (and it's
;; in the later vector position
selected (->> children
reverse
;; We need to reverse the children because if two children
;; overlap we want to select the one that's over (and it's
;; in the later vector position
selected (->> children
reverse
(d/seek #(geom/has-point? % position)))]
(when selected
(rx/of (select-shape (:id selected)))))))))
(when selected
(rx/of (select-shape (:id selected))))))))
;; --- Duplicate Shapes
(declare prepare-duplicate-change)
@ -321,7 +319,6 @@
name (dwc/generate-unique-name names (:name obj))
renamed-obj (assoc obj :id id :name name)
moved-obj (geom/move renamed-obj delta)
frames (cp/select-frames objects)
parent-id (or parent-id frame-id)
children-changes
@ -378,7 +375,7 @@
(def duplicate-selected
(ptk/reify ::duplicate-selected
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
selected (wsh/lookup-selected state)

View file

@ -10,14 +10,13 @@
[app.main.data.workspace :as dw]
[app.main.data.workspace.colors :as mdc]
[app.main.data.workspace.common :as dwc]
[app.main.data.workspace.undo :as dwu]
[app.main.data.workspace.drawing :as dwd]
[app.main.data.workspace.libraries :as dwl]
[app.main.data.workspace.texts :as dwtxt]
[app.main.data.workspace.transforms :as dwt]
[app.main.data.workspace.undo :as dwu]
[app.main.store :as st]
[app.util.dom :as dom]
[potok.core :as ptk]))
[app.util.dom :as dom]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Shortcuts

View file

@ -9,7 +9,6 @@
[app.common.data :as d]
[app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt]
[app.common.geom.proportions :as gpr]
[app.common.geom.shapes :as gsh]
[app.common.pages :as cp]
[app.common.uuid :as uuid]
@ -18,14 +17,12 @@
[app.main.data.workspace.state-helpers :as wsh]
[app.main.repo :as rp]
[app.util.color :as uc]
[app.util.object :as obj]
[app.util.path.parser :as upp]
[app.util.svg :as usvg]
[app.util.uri :as uu]
[beicon.core :as rx]
[cuerdas.core :as str]
[potok.core :as ptk]
[promesa.core :as p]))
[potok.core :as ptk]))
(defonce default-rect {:x 0 :y 0 :width 1 :height 1 :rx 0 :ry 0})
(defonce default-circle {:r 0 :cx 0 :cy 0})
@ -163,7 +160,7 @@
(gsh/setup-selrect))))
(defn create-path-shape [name frame-id svg-data {:keys [attrs] :as data}]
(when (and (contains? attrs :d) (not (empty? (:d attrs)) ))
(when (and (contains? attrs :d) (seq (:d attrs)))
(let [svg-transform (usvg/parse-transform (:transform attrs))
path-content (upp/parse-path (:d attrs))
content (cond-> path-content
@ -387,7 +384,7 @@
[svg-data file-id position]
(ptk/reify ::svg-uploaded
ptk/WatchEvent
(watch [it state stream]
(watch [_ _ _]
;; Once the SVG is uploaded, we need to extract all the bitmap
;; images and upload them separatelly, then proceed to create
;; all shapes.
@ -414,7 +411,7 @@
[svg-data {:keys [x y] :as position}]
(ptk/reify ::create-svg-shapes
ptk/WatchEvent
(watch [it state stream]
(watch [it state _]
(try
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)

View file

@ -16,17 +16,11 @@
[app.main.data.workspace.common :as dwc]
[app.main.data.workspace.selection :as dws]
[app.main.data.workspace.state-helpers :as wsh]
[app.main.data.workspace.transforms :as dwt]
[app.main.data.workspace.undo :as dwu]
[app.main.fonts :as fonts]
[app.util.object :as obj]
[app.util.router :as rt]
[app.util.text-editor :as ted]
[app.util.timers :as ts]
[app.util.router :as rt]
[beicon.core :as rx]
[cljs.spec.alpha :as s]
[cuerdas.core :as str]
[goog.object :as gobj]
[potok.core :as ptk]))
(defn update-editor
@ -42,7 +36,7 @@
[]
(ptk/reify ::focus-editor
ptk/EffectEvent
(effect [_ state stream]
(effect [_ state _]
(when-let [editor (:workspace-editor state)]
(ts/schedule #(.focus ^js editor))))))
@ -59,7 +53,7 @@
[{:keys [id] :as shape}]
(ptk/reify ::finalize-editor-state
ptk/WatchEvent
(watch [_ state stream]
(watch [_ state _]
(let [content (-> (get-in state [:workspace-editor-state id])
(ted/get-editor-current-content))]
@ -88,7 +82,7 @@
decorator))))
ptk/WatchEvent
(watch [_ state stream]
(watch [_ _ stream]
;; We need to finalize editor on two main events: (1) when user
;; explicitly navigates to other section or page; (2) when user
;; leaves the editor.
@ -149,7 +143,7 @@
[{:keys [id attrs]}]
(ptk/reify ::update-root-attrs
ptk/WatchEvent
(watch [_ state stream]
(watch [_ state _]
(let [objects (wsh/lookup-page-objects state)
shape (get objects id)
@ -168,7 +162,7 @@
(d/update-in-when state [:workspace-editor-state id] ted/update-editor-current-block-data attrs))
ptk/WatchEvent
(watch [_ state stream]
(watch [_ state _]
(when-not (some? (get-in state [:workspace-editor-state id]))
(let [objects (wsh/lookup-page-objects state)
shape (get objects id)
@ -195,7 +189,7 @@
(d/update-in-when state [:workspace-editor-state id] ted/update-editor-current-inline-styles attrs))
ptk/WatchEvent
(watch [_ state stream]
(watch [_ state _]
(when-not (some? (get-in state [:workspace-editor-state id]))
(let [objects (wsh/lookup-page-objects state)
shape (get objects id)
@ -232,7 +226,7 @@
(defn resize-text-batch [changes]
(ptk/reify ::resize-text-batch
ptk/WatchEvent
(watch [_ state stream]
(watch [_ state _]
(let [page-id (:current-page-id state)
objects (get-in state [:workspace-data :pages-index page-id :objects])]
(if-not (every? #(contains? objects(first %)) changes)

View file

@ -11,7 +11,6 @@
[app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh]
[app.common.math :as mth]
[app.common.pages :as cp]
[app.common.spec :as us]
[app.main.data.workspace.changes :as dch]
@ -19,13 +18,10 @@
[app.main.data.workspace.selection :as dws]
[app.main.data.workspace.state-helpers :as wsh]
[app.main.data.workspace.undo :as dwu]
[app.main.refs :as refs]
[app.main.snap :as snap]
[app.main.store :as st]
[app.main.streams :as ms]
[app.util.path.shapes-to-path :as ups]
[beicon.core :as rx]
[beicon.core :as rx]
[cljs.spec.alpha :as s]
[potok.core :as ptk]))

View file

@ -6,21 +6,10 @@
(ns app.main.data.workspace.undo
(:require
[app.common.data :as d]
[app.common.geom.proportions :as gpr]
[app.common.geom.shapes :as gsh]
[app.common.pages :as cp]
[app.common.pages.spec :as spec]
[app.common.spec :as us]
[app.common.uuid :as uuid]
[app.main.worker :as uw]
[app.main.streams :as ms]
[app.util.logging :as log]
[app.util.timers :as ts]
[beicon.core :as rx]
[cljs.spec.alpha :as s]
[clojure.set :as set]
[cuerdas.core :as str]
[potok.core :as ptk]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -42,7 +31,7 @@
(subvec undo (- cnt MAX-UNDO-SIZE))
undo)))
(defn- materialize-undo
(defn materialize-undo
[changes index]
(ptk/reify ::materialize-undo
ptk/UpdateEvent
@ -51,15 +40,6 @@
(update :workspace-data cp/process-changes changes)
(assoc-in [:workspace-undo :index] index)))))
(defn- reset-undo
[index]
(ptk/reify ::reset-undo
ptk/UpdateEvent
(update [_ state]
(-> state
(update :workspace-undo dissoc :undo-index)
(update-in [:workspace-undo :items] (fn [queue] (into [] (take (inc index) queue))))))))
(defn- add-undo-entry
[state entry]
(if (and entry
@ -81,7 +61,7 @@
(update-in [:workspace-undo :transaction :undo-changes] #(into undo-changes %))
(update-in [:workspace-undo :transaction :redo-changes] #(into % redo-changes))))
(defn- append-undo
(defn append-undo
[entry]
(us/assert ::undo-entry entry)
(ptk/reify ::append-undo

View file

@ -17,7 +17,6 @@
[app.main.ui.shapes.circle :as circle]
[app.main.ui.shapes.embed :as embed]
[app.main.ui.shapes.export :as use]
[app.main.ui.shapes.filters :as filters]
[app.main.ui.shapes.frame :as frame]
[app.main.ui.shapes.group :as group]
[app.main.ui.shapes.image :as image]

View file

@ -7,9 +7,9 @@
(ns app.main.fonts
"A fonts loading macros."
(:require
[cuerdas.core :as str]
[clojure.data.json :as json]
[clojure.java.io :as io]
[clojure.data.json :as json]))
[cuerdas.core :as str]))
(defn- parse-gfont-variant
[variant]

View file

@ -15,7 +15,6 @@
[app.util.http :as http]
[app.util.logging :as log]
[app.util.object :as obj]
[app.util.timers :as ts]
[beicon.core :as rx]
[clojure.set :as set]
[cuerdas.core :as str]
@ -104,7 +103,7 @@
[url on-loaded]
(let [node (create-link-element url)
head (.-head ^js js/document)]
(gev/listenOnce node "load" (fn [event]
(gev/listenOnce node "load" (fn [_]
(when (fn? on-loaded)
(on-loaded))))
(dom/append-child! head node)))
@ -140,7 +139,7 @@
(str base ":" variants "&display=block")))
(defmethod load-font :google
[{:keys [id family variants ::on-loaded] :as font}]
[{:keys [id ::on-loaded] :as font}]
(when (exists? js/window)
(log/debug :action "load-font" :font-id id :backend "google")
(let [url (generate-gfonts-url font)]
@ -183,11 +182,13 @@
(str/join "\n")))
(defmethod load-font :custom
[{:keys [id family variants ::on-loaded] :as font}]
[{:keys [id ::on-loaded] :as font}]
(when (exists? js/window)
(js/console.log "[debug:fonts]: loading custom font" id)
(let [css (generate-custom-font-css font)]
(add-font-css! css))))
(add-font-css! css)
(when (fn? on-loaded)
(on-loaded)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; LOAD API

View file

@ -10,11 +10,8 @@
(:require
[app.common.data :as d]
[app.common.pages :as cp]
[app.common.uuid :as uuid]
[app.main.constants :as c]
[app.main.data.workspace.state-helpers :as wsh]
[app.main.store :as st]
[beicon.core :as rx]
[okulary.core :as l]))
;; ---- Global refs

View file

@ -9,7 +9,6 @@
["react-dom/server" :as rds]
[app.config :as cfg]
[app.main.exports :as exports]
[app.main.exports :as svg]
[app.main.fonts :as fonts]
[app.util.http :as http]
[beicon.core :as rx]
@ -31,16 +30,13 @@
[]))
(defn populate-images-cache
([data]
(populate-images-cache data nil))
([data {:keys [resolve-media?] :or {resolve-media? false}}]
(let [images (->> (:objects data)
(vals)
(mapcat get-image-data))]
(->> (rx/from images)
(rx/map #(cfg/resolve-file-media %))
(rx/flat-map http/fetch-data-uri)))))
[data]
(let [images (->> (:objects data)
(vals)
(mapcat get-image-data))]
(->> (rx/from images)
(rx/map #(cfg/resolve-file-media %))
(rx/flat-map http/fetch-data-uri))))
(defn populate-fonts-cache [data]
(let [texts (->> (:objects data)

View file

@ -10,9 +10,7 @@
[app.common.uri :as u]
[app.config :as cfg]
[app.util.http :as http]
[app.util.time :as dt]
[beicon.core :as rx]
[cuerdas.core :as str]))
[beicon.core :as rx]))
(defn handle-response
[{:keys [status body] :as response}]
@ -86,7 +84,7 @@
([id params] (mutation id params)))
(defmethod mutation :login-with-oauth
[id {:keys [provider] :as params}]
[_ {:keys [provider] :as params}]
(let [uri (u/join base-uri "api/auth/oauth/" (d/name provider))
params (dissoc params :provider)]
(->> (http/send! {:method :post :uri uri :query params})
@ -94,7 +92,7 @@
(rx/mapcat handle-response))))
(defmethod mutation :send-feedback
[id params]
[_ params]
(->> (http/send! {:method :post
:uri (u/join base-uri "api/feedback")
:body (http/transit-data params)})
@ -102,7 +100,7 @@
(rx/mapcat handle-response)))
(defmethod query :export
[id params]
[_ params]
(->> (http/send! {:method :post
:uri (u/join base-uri "export")
:body (http/transit-data params)

View file

@ -19,24 +19,24 @@
[beicon.core :as rx]
[clojure.set :as set]))
(defonce ^:private snap-accuracy 5)
(defonce ^:private snap-path-accuracy 10)
(defonce ^:private snap-distance-accuracy 10)
(def ^:const snap-accuracy 5)
(def ^:const snap-path-accuracy 10)
(def ^:const snap-distance-accuracy 10)
(defn- remove-from-snap-points
[remove-id?]
(fn [query-result]
(->> query-result
(map (fn [[value data]] [value (remove (comp remove-id? second) data)]))
(filter (fn [[_ data]] (not (empty? data)))))))
(filter (fn [[_ data]] (seq data))))))
(defn- flatten-to-points
[query-result]
(mapcat (fn [[v data]] (map (fn [[point _]] point) data)) query-result))
(mapcat (fn [[_ data]] (map (fn [[point _]] point) data)) query-result))
(defn- calculate-distance [query-result point coord]
(->> query-result
(map (fn [[value data]] [(mth/abs (- value (coord point))) [(coord point) value]]))))
(map (fn [[value _]] [(mth/abs (- value (coord point))) [(coord point) value]]))))
(defn- get-min-distance-snap [points coord]
(fn [query-result]
@ -45,7 +45,7 @@
(apply min-key first)
second)))
(defn- snap-frame-id [shapes]
(defn snap-frame-id [shapes]
(let [frames (into #{} (map :frame-id shapes))]
(cond
;; Only shapes from one frame. The common is the only one
@ -286,8 +286,9 @@
(fn [matches other]
(let [matches (into {} matches)
other (into {} other)
keys (set/union (keys matches) (keys other))]
other (into {} other)
keys (set/union (set (keys matches))
(set (keys other)))]
(into {}
(map (fn [key]
[key
@ -308,7 +309,7 @@
min-match-coord
(fn [matches]
(if (and (seq matches) (not (empty? matches)))
(if (seq matches)
(->> matches (reduce get-min))
default))]

View file

@ -75,12 +75,12 @@
(logjs "state" (get-in @state [:workspace-data :pages-index page-id :objects]))))
(defn ^:export dump-object [name]
(let [page-id (get @state :current-page-id)]
(let [objects (get-in @state [:workspace-data :pages-index page-id :objects])
target (or (d/seek (fn [[id shape]] (= name (:name shape))) objects)
(get objects (uuid name)))]
(->> target
(logjs "state")))))
(let [page-id (get @state :current-page-id)
objects (get-in @state [:workspace-data :pages-index page-id :objects])
target (or (d/seek (fn [[_ shape]] (= name (:name shape))) objects)
(get objects (uuid name)))]
(->> target
(logjs "state"))))
(defn ^:export dump-tree
([] (dump-tree false false))
@ -89,7 +89,7 @@
(let [page-id (get @state :current-page-id)
objects (get-in @state [:workspace-data :pages-index page-id :objects])
components (get-in @state [:workspace-data :components])
libraries (get-in @state [:workspace-libraries])
libraries (get @state :workspace-libraries)
root (d/seek #(nil? (:parent-id %)) (vals objects))]
(letfn [(show-shape [shape-id level objects]

View file

@ -7,12 +7,10 @@
(ns app.main.streams
"User interaction events and streams."
(:require
[beicon.core :as rx]
[app.main.store :as st]
[app.main.refs :as refs]
[app.common.geom.point :as gpt]
[app.util.globals :as globals]
[app.util.keyboard :as kbd]))
[app.util.keyboard :as kbd]
[beicon.core :as rx]))
;; --- User Events

View file

@ -6,15 +6,12 @@
(ns app.main.ui
(:require
[app.config :as cf]
[app.common.data :as d]
[app.common.exceptions :as ex]
[app.common.spec :as us]
[app.common.uuid :as uuid]
[app.config :as cfg]
[app.main.data.users :as du]
[app.main.data.messages :as dm]
[app.config :as cf]
[app.main.data.events :as ev]
[app.main.data.messages :as dm]
[app.main.data.users :as du]
[app.main.refs :as refs]
[app.main.store :as st]
[app.main.ui.auth :refer [auth]]
@ -32,8 +29,6 @@
[app.main.ui.static :as static]
[app.main.ui.viewer :refer [viewer-page]]
[app.main.ui.workspace :as workspace]
[app.util.i18n :as i18n :refer [tr t]]
[app.util.router :as rt]
[app.util.timers :as ts]
[cljs.pprint :refer [pprint]]
[cljs.spec.alpha :as s]
@ -60,11 +55,11 @@
(def routes
[["/auth"
["/login" :auth-login]
(when cfg/registration-enabled
(when cf/registration-enabled
["/register" :auth-register])
(when cfg/registration-enabled
(when cf/registration-enabled
["/register/validate" :auth-register-validate])
(when cfg/registration-enabled
(when cf/registration-enabled
["/register/success" :auth-register-success])
["/recovery/request" :auth-recovery-request]
["/recovery" :auth-recovery]
@ -102,9 +97,8 @@
(mf/defc on-main-error
[{:keys [error] :as props}]
(let [data (ex-data error)]
(mf/use-effect #(ptk/handle-error error))
[:span "Internal application errror"]))
(mf/use-effect #(ptk/handle-error error))
[:span "Internal application errror"])
(mf/defc main-page
{::mf/wrap [#(mf/catch % {:fallback on-main-error})]}
@ -211,14 +205,14 @@
(derive :service-unavailable ::exceptional-state)
(defmethod ptk/handle-error ::exceptional-state
[{:keys [status] :as error}]
[error]
(ts/schedule
(st/emitf (dm/assign-exception error))))
;; We receive a explicit authentication error; this explicitly clears
;; all profile data and redirect the user to the login page.
(defmethod ptk/handle-error :authentication
[error]
[_]
(ts/schedule (st/emitf (du/logout))))
;; Error that happens on an active bussines model validation does not
@ -245,7 +239,7 @@
;; Error on parsing an SVG
(defmethod ptk/handle-error :svg-parser
[error]
[_]
(ts/schedule
(st/emitf
(dm/show {:content "SVG is invalid or malformed"
@ -261,7 +255,7 @@
context (str/fmt "ns: '%s'\nname: '%s'\nfile: '%s:%s'"
(:ns context)
(:name context)
(str cfg/public-uri "js/cljs-runtime/" (:file context))
(str cf/public-uri "js/cljs-runtime/" (:file context))
(:line context))]
(ts/schedule
(st/emitf

View file

@ -6,38 +6,27 @@
(ns app.main.ui.auth
(:require
[app.common.uuid :as uuid]
[app.main.data.messages :as dm]
[app.main.data.users :as du]
[app.main.repo :as rp]
[app.main.store :as st]
[app.main.ui.auth.login :refer [login-page]]
[app.main.ui.auth.recovery :refer [recovery-page]]
[app.main.ui.auth.recovery-request :refer [recovery-request-page]]
[app.main.ui.auth.register :refer [register-page register-success-page register-validate-page]]
[app.main.ui.icons :as i]
[app.util.dom :as dom]
[app.util.forms :as fm]
[app.util.i18n :as i18n :refer [t]]
[app.util.router :as rt]
[app.util.timers :as ts]
[beicon.core :as rx]
[cljs.spec.alpha :as s]
[app.util.i18n :as i18n :refer [tr]]
[rumext.alpha :as mf]))
(mf/defc auth
[{:keys [route] :as props}]
(let [section (get-in route [:data :name])
locale (mf/deref i18n/locale)
params (:query-params route)]
(mf/use-effect
#(dom/set-html-title (t locale "title.default")))
#(dom/set-html-title (tr "title.default")))
[:div.auth
[:section.auth-sidebar
[:a.logo {:href "#/"} i/logo]
[:span.tagline (t locale "auth.sidebar-tagline")]]
[:a.logo {:href "https://penpot.app"} i/logo]
[:span.tagline (tr "auth.sidebar-tagline")]]
[:section.auth-content
(case section
@ -54,10 +43,10 @@
[:& login-page {:params params}]
:auth-recovery-request
[:& recovery-request-page {:locale locale}]
[:& recovery-request-page]
:auth-recovery
[:& recovery-page {:locale locale :params params}])
[:& recovery-page {:params params}])
[:div.terms-login
[:a {:href "https://penpot.app/terms.html" :target "_blank"} "Terms of service"]

View file

@ -16,8 +16,7 @@
[app.main.ui.icons :as i]
[app.main.ui.messages :as msgs]
[app.util.dom :as dom]
[app.util.i18n :refer [tr t]]
[app.util.object :as obj]
[app.util.i18n :refer [tr]]
[app.util.router :as rt]
[beicon.core :as rx]
[cljs.spec.alpha :as s]
@ -74,7 +73,7 @@
on-submit
(mf/use-callback
(mf/deps form)
(fn [event]
(fn [_]
(reset! error nil)
(let [params (with-meta (:clean-data @form)
{:on-error on-error})]

View file

@ -11,12 +11,9 @@
[app.main.data.users :as du]
[app.main.store :as st]
[app.main.ui.components.forms :as fm]
[app.main.ui.icons :as i]
[app.util.dom :as dom]
[app.util.i18n :as i18n :refer [t tr]]
[app.util.i18n :as i18n :refer [tr]]
[app.util.router :as rt]
[cljs.spec.alpha :as s]
[cuerdas.core :as str]
[rumext.alpha :as mf]))
(s/def ::password-1 ::us/not-empty-string)
@ -40,7 +37,7 @@
(assoc :password-1 {:message "errors.password-too-short"}))))
(defn- on-error
[form error]
[_form _error]
(st/emit! (dm/error (tr "auth.notifications.invalid-token-error"))))
(defn- on-success
@ -49,7 +46,7 @@
(rt/nav :auth-login)))
(defn- on-submit
[form event]
[form _event]
(let [mdata {:on-error on-error
:on-success on-success}
params {:token (get-in @form [:clean-data :token])
@ -57,7 +54,7 @@
(st/emit! (du/recover-profile (with-meta params mdata)))))
(mf/defc recovery-form
[{:keys [locale params] :as props}]
[{:keys [params] :as props}]
(let [form (fm/use-form :spec ::recovery-form
:validators [password-equality]
:initial params)]
@ -66,28 +63,28 @@
[:div.fields-row
[:& fm/input {:type "password"
:name :password-1
:label (t locale "auth.new-password")}]]
:label (tr "auth.new-password")}]]
[:div.fields-row
[:& fm/input {:type "password"
:name :password-2
:label (t locale "auth.confirm-password")}]]
:label (tr "auth.confirm-password")}]]
[:& fm/submit-button
{:label (t locale "auth.recovery-submit")}]]))
{:label (tr "auth.recovery-submit")}]]))
;; --- Recovery Request Page
(mf/defc recovery-page
[{:keys [locale params] :as props}]
[{:keys [params] :as props}]
[:section.generic-form
[:div.form-container
[:h1 "Forgot your password?"]
[:div.subtitle "Please enter your new password"]
[:& recovery-form {:locale locale :params params}]
[:& recovery-form {:params params}]
[:div.links
[:div.link-entry
[:a {:on-click #(st/emit! (rt/nav :auth-login))}
(t locale "profile.recovery.go-to-login")]]]]])
(tr "profile.recovery.go-to-login")]]]]])

View file

@ -12,12 +12,10 @@
[app.main.store :as st]
[app.main.ui.components.forms :as fm]
[app.main.ui.icons :as i]
[app.util.dom :as dom]
[app.util.i18n :as i18n :refer [tr t]]
[app.util.i18n :as i18n :refer [tr]]
[app.util.router :as rt]
[beicon.core :as rx]
[cljs.spec.alpha :as s]
[cuerdas.core :as str]
[rumext.alpha :as mf]))
(s/def ::email ::us/email)
@ -30,7 +28,7 @@
on-success
(mf/use-callback
(fn [data]
(fn [_ _]
(reset! submitted false)
(st/emit! (dm/info (tr "auth.notifications.recovery-token-sent"))
(rt/nav :auth-login))))

View file

@ -8,21 +8,18 @@
(:require
[app.common.spec :as us]
[app.config :as cf]
[app.main.data.users :as du]
[app.main.data.messages :as dm]
[app.main.store :as st]
[app.main.data.users :as du]
[app.main.repo :as rp]
[app.main.store :as st]
[app.main.ui.auth.login :as login]
[app.main.ui.components.forms :as fm]
[app.main.ui.icons :as i]
[app.main.ui.messages :as msgs]
[app.main.ui.auth.login :as login]
[app.util.dom :as dom]
[app.util.i18n :refer [tr t]]
[app.util.i18n :refer [tr]]
[app.util.router :as rt]
[app.util.timers :as tm]
[beicon.core :as rx]
[cljs.spec.alpha :as s]
[cuerdas.core :as str]
[rumext.alpha :as mf]))
(mf/defc demo-warning
@ -71,7 +68,7 @@
(st/emit! (dm/error (tr "errors.generic")))))
(defn- handle-prepare-register-success
[form {:keys [token] :as result}]
[_form {:keys [token] :as result}]
(st/emit! (rt/nav :auth-register-validate {} {:token token})))
(mf/defc register-form
@ -84,7 +81,7 @@
on-submit
(mf/use-callback
(fn [form event]
(fn [form _event]
(reset! submitted? true)
(let [params (:clean-data @form)]
(->> (rp/mutation :prepare-register-profile params)
@ -166,7 +163,7 @@
(st/emit! (dm/error (tr "errors.generic"))))))
(defn- handle-register-success
[form data]
[_form data]
(cond
(some? (:invitation-token data))
(let [token (:invitation-token data)]
@ -200,7 +197,7 @@
on-submit
(mf/use-callback
(fn [form event]
(fn [form _event]
(reset! submitted? true)
(let [params (:clean-data @form)]
(->> (rp/mutation :register-profile params)

View file

@ -6,23 +6,16 @@
(ns app.main.ui.auth.verify-token
(:require
[app.common.uuid :as uuid]
[app.main.data.messages :as dm]
[app.main.data.users :as du]
[app.main.repo :as rp]
[app.main.store :as st]
[app.main.ui.auth.login :refer [login-page]]
[app.main.ui.auth.recovery :refer [recovery-page]]
[app.main.ui.auth.recovery-request :refer [recovery-request-page]]
[app.main.ui.auth.register :refer [register-page]]
[app.main.ui.icons :as i]
[app.util.dom :as dom]
[app.util.forms :as fm]
[app.util.i18n :as i18n :refer [tr]]
[app.util.router :as rt]
[app.util.timers :as ts]
[beicon.core :as rx]
[cljs.spec.alpha :as s]
[rumext.alpha :as mf]))
(defmulti handle-token (fn [token] (:iss token)))
@ -34,7 +27,7 @@
(st/emit! (du/login-from-token data))))
(defmethod handle-token :change-email
[data]
[_data]
(let [msg (tr "dashboard.notifications.email-changed-successfully")]
(ts/schedule 100 #(st/emit! (dm/success msg)))
(st/emit! (rt/nav :settings-profile)
@ -57,7 +50,7 @@
(st/emit! (rt/nav :auth-register {} {:invitation-token token})))))
(defmethod handle-token :default
[tdata]
[_tdata]
(st/emit!
(rt/nav :auth-login)
(dm/warn (tr "errors.unexpected-token"))))

View file

@ -11,16 +11,13 @@
[app.main.data.modal :as modal]
[app.main.refs :as refs]
[app.main.store :as st]
[app.main.streams :as ms]
[app.main.ui.components.dropdown :refer [dropdown]]
[app.main.ui.context :as ctx]
[app.main.ui.icons :as i]
[app.util.dom :as dom]
[app.util.i18n :as i18n :refer [t tr]]
[app.util.i18n :as i18n :refer [tr]]
[app.util.keyboard :as kbd]
[app.util.object :as obj]
[app.util.time :as dt]
[cuerdas.core :as str]
[okulary.core :as l]
[rumext.alpha :as mf]))
@ -105,7 +102,7 @@
:on-focus on-focus
:on-change on-change}]
(when (or @show-buttons?
(not (empty? @content)))
(seq @content))
[:div.buttons
[:input.btn-primary {:type "button" :value "Post" :on-click on-submit}]
[:input.btn-secondary {:type "button" :value "Cancel" :on-click on-cancel}]])]))
@ -323,7 +320,7 @@
(mf/defc thread-bubble
{::mf/wrap [mf/memo]}
[{:keys [thread zoom open? on-click] :as params}]
[{:keys [thread zoom on-click] :as params}]
(let [pos (:position thread)
pos-x (* (:x pos) zoom)
pos-y (* (:y pos) zoom)

View file

@ -6,9 +6,9 @@
(ns app.main.ui.components.color-bullet
(:require
[rumext.alpha :as mf]
[app.util.color :as uc]
[app.util.i18n :as i18n :refer [tr]]
[app.util.color :as uc]))
[rumext.alpha :as mf]))
(mf/defc color-bullet [{:keys [color on-click]}]
(if (uc/multiple? color)
@ -31,7 +31,7 @@
(mf/defc color-name [{:keys [color size on-click on-double-click]}]
(let [color (if (string? color) {:color color :opacity 1} color)
{:keys [name color opacity gradient]} color
{:keys [name color gradient]} color
color-str (or name color (gradient-type->string (:type gradient)))]
(when (or (not size) (= size :big))
[:span.color-text {:on-click #(when on-click (on-click %))

View file

@ -6,16 +6,11 @@
(ns app.main.ui.components.color-input
(:require
[app.common.data :as d]
[app.common.math :as math]
[app.common.spec :as us]
[app.common.uuid :as uuid]
[app.util.color :as uc]
[app.util.dom :as dom]
[app.util.i18n :as i18n :refer [tr]]
[app.util.keyboard :as kbd]
[app.util.object :as obj]
[app.util.simple-math :as sm]
[app.util.i18n :as i18n :refer [tr]]
[rumext.alpha :as mf]))
(mf/defc color-input
@ -80,7 +75,7 @@
handle-blur
(mf/use-callback
(mf/deps parse-value apply-value update-input)
(fn [event]
(fn [_]
(let [new-value (parse-value)]
(if new-value
(apply-value new-value)

View file

@ -6,13 +6,12 @@
(ns app.main.ui.components.context-menu
(:require
[rumext.alpha :as mf]
[goog.object :as gobj]
[app.main.ui.components.dropdown :refer [dropdown']]
[app.main.ui.icons :as i]
[app.common.uuid :as uuid]
[app.util.dom :as dom]
[app.util.object :as obj]))
[app.util.object :as obj]
[goog.object :as gobj]
[rumext.alpha :as mf]))
(mf/defc context-menu
{::mf/wrap-props false}
@ -52,7 +51,7 @@
(- node-height)
0)]
(if (not= target-offset (:offset @local))
(when (not= target-offset (:offset @local))
(swap! local assoc :offset target-offset))))))
enter-submenu

View file

@ -6,11 +6,11 @@
(ns app.main.ui.components.copy-button
(:require
[beicon.core :as rx]
[rumext.alpha :as mf]
[app.util.webapi :as wapi]
[app.main.ui.icons :as i]
[app.util.timers :as timers]
[app.main.ui.icons :as i]))
[app.util.webapi :as wapi]
[beicon.core :as rx]
[rumext.alpha :as mf]))
(mf/defc copy-button [{:keys [data]}]
(let [just-copied (mf/use-state false)]
@ -24,9 +24,8 @@
[:button.copy-button
{:on-click #(when-not @just-copied
(do
(reset! just-copied true)
(wapi/write-to-clipboard data)))}
(reset! just-copied true)
(wapi/write-to-clipboard data))}
(if @just-copied
i/tick
i/copy)]))

View file

@ -1,11 +1,16 @@
;; 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.ui.components.dropdown
(:require
[rumext.alpha :as mf]
[app.common.uuid :as uuid]
[app.util.dom :as dom]
[app.util.keyboard :as kbd]
[goog.events :as events]
[goog.object :as gobj])
[goog.object :as gobj]
[rumext.alpha :as mf])
(:import goog.events.EventType))
(mf/defc dropdown'

View file

@ -7,7 +7,6 @@
(ns app.main.ui.components.editable-label
(:require
[app.main.ui.icons :as i]
[app.util.data :refer [classnames]]
[app.util.dom :as dom]
[app.util.keyboard :as kbd]
[app.util.timers :as timers]
@ -32,7 +31,7 @@
cancel-editing (fn []
(stop-editing)
(when on-cancel (on-cancel)))
on-dbl-click (fn [e] (when (not disable-dbl-click?) (start-editing)))
on-dbl-click (fn [_] (when (not disable-dbl-click?) (start-editing)))
on-key-up (fn [e]
(cond
(kbd/esc? e)

View file

@ -6,13 +6,13 @@
(ns app.main.ui.components.editable-select
(:require
[rumext.alpha :as mf]
[app.common.uuid :as uuid]
[app.common.data :as d]
[app.common.uuid :as uuid]
[app.main.ui.components.dropdown :refer [dropdown]]
[app.main.ui.icons :as i]
[app.util.dom :as dom]
[app.util.timers :as timers]
[app.main.ui.icons :as i]
[app.main.ui.components.dropdown :refer [dropdown]]))
[rumext.alpha :as mf]))
(mf/defc editable-select [{:keys [value type options class on-change placeholder]}]
(let [state (mf/use-state {:id (uuid/next)
@ -24,7 +24,7 @@
open-dropdown #(swap! state assoc :is-open? true)
close-dropdown #(swap! state assoc :is-open? false)
select-item (fn [value]
(fn [event]
(fn [_]
(swap! state assoc :current-value value)
(when on-change (on-change value))))

View file

@ -6,10 +6,9 @@
(ns app.main.ui.components.file-uploader
(:require
[rumext.alpha :as mf]
[app.main.data.workspace :as dw]
[app.main.store :as st]
[app.util.dom :as dom]))
[app.util.dom :as dom]
[rumext.alpha :as mf]))
(mf/defc file-uploader
{::mf/forward-ref true}

View file

@ -8,7 +8,6 @@
(:require
[app.util.dom :as dom]
[app.util.webapi :as wapi]
[beicon.core :as rx]
[rumext.alpha :as mf]))
(def fullscreen-context
@ -21,7 +20,7 @@
change
(mf/use-callback
(fn [event]
(fn [_]
(let [val (dom/fullscreen?)]
(reset! state val))))

View file

@ -132,7 +132,7 @@
handle-blur
(mf/use-callback
(mf/deps parse-value apply-value update-input)
(fn [event]
(fn [_]
(let [new-value (parse-value)]
(if new-value
(apply-value new-value)

View file

@ -6,10 +6,10 @@
(ns app.main.ui.components.select
(:require
[rumext.alpha :as mf]
[app.common.uuid :as uuid]
[app.main.ui.components.dropdown :refer [dropdown]]
[app.main.ui.icons :as i]
[app.main.ui.components.dropdown :refer [dropdown]]))
[rumext.alpha :as mf]))
(mf/defc select [{:keys [default-value options class on-change]}]
(let [state (mf/use-state {:id (uuid/next)
@ -17,9 +17,10 @@
:current-value default-value})
open-dropdown #(swap! state assoc :is-open? true)
close-dropdown #(swap! state assoc :is-open? false)
select-item (fn [value] (fn [event]
(swap! state assoc :current-value value)
(when on-change (on-change value))))
select-item (fn [value]
(fn [_]
(swap! state assoc :current-value value)
(when on-change (on-change value))))
as-key-value (fn [item] (if (map? item) [(:value item) (:label item)] [item item]))
value->label (into {} (->> options
(map as-key-value))) ]

View file

@ -8,7 +8,7 @@
(:require [rumext.alpha :as mf]))
(mf/defc tab-element
[{:keys [children id title]}]
[{:keys [children]}]
[:div.tab-element
[:div.tab-element-content children]])

View file

@ -57,10 +57,10 @@
(let [on-keydown
(fn [event]
(when (k/enter? event)
(do (dom/prevent-default event)
(dom/stop-propagation event)
(st/emit! (modal/hide))
(on-accept props))))
(dom/prevent-default event)
(dom/stop-propagation event)
(st/emit! (modal/hide))
(on-accept props)))
key (events/listen js/document EventType.KEYDOWN on-keydown)]
#(events/unlistenByKey key))))

View file

@ -6,9 +6,9 @@
(ns app.main.ui.cursors
(:require
[app.common.uri :as u]
[clojure.java.io :as io]
[cuerdas.core :as str]
[app.common.uri :as u]))
[cuerdas.core :as str]))
(def cursor-folder "images/cursors")

View file

@ -6,9 +6,10 @@
(ns app.main.ui.cursors
(:require-macros [app.main.ui.cursors :refer [cursor-ref cursor-fn]])
(:require [rumext.alpha :as mf]
[cuerdas.core :as str]
[app.util.timers :as ts]))
(:require
[app.util.timers :as ts]
[cuerdas.core :as str]
[rumext.alpha :as mf]))
;; Static cursors
(def comments (cursor-ref :comments 0 2 20))
@ -40,7 +41,7 @@
(mf/defc debug-preview
{::mf/wrap-props false}
[props]
[]
(let [rotation (mf/use-state 0)]
(mf/use-effect (fn [] (ts/interval 100 #(reset! rotation inc))))

View file

@ -6,9 +6,7 @@
(ns app.main.ui.dashboard
(:require
[app.common.exceptions :as ex]
[app.common.spec :as us]
[app.common.uuid :as uuid]
[app.config :as cf]
[app.main.data.dashboard :as dd]
[app.main.data.modal :as modal]
@ -16,19 +14,13 @@
[app.main.store :as st]
[app.main.ui.context :as ctx]
[app.main.ui.dashboard.files :refer [files-section]]
[app.main.ui.dashboard.fonts :refer [fonts-page font-providers-page]]
[app.main.ui.dashboard.libraries :refer [libraries-page]]
[app.main.ui.dashboard.projects :refer [projects-section]]
[app.main.ui.dashboard.fonts :refer [fonts-page font-providers-page]]
[app.main.ui.dashboard.search :refer [search-page]]
[app.main.ui.dashboard.sidebar :refer [sidebar]]
[app.main.ui.dashboard.team :refer [team-settings-page team-members-page]]
[app.main.ui.icons :as i]
[app.util.i18n :as i18n :refer [t]]
[app.util.router :as rt]
[app.util.timers :as tm]
[beicon.core :as rx]
[cuerdas.core :as str]
[okulary.core :as l]
[rumext.alpha :as mf]))
(defn ^boolean uuid-str?
@ -37,9 +29,8 @@
(boolean (re-seq us/uuid-rx s))))
(defn- parse-params
[route profile]
(let [route-name (get-in route [:data :name])
search-term (get-in route [:params :query :search-term])
[route]
(let [search-term (get-in route [:params :query :search-term])
team-id (get-in route [:params :path :team-id])
project-id (get-in route [:params :path :project-id])]
(cond->
@ -87,7 +78,7 @@
[{:keys [route] :as props}]
(let [profile (mf/deref refs/profile)
section (get-in route [:data :name])
params (parse-params route profile)
params (parse-params route)
project-id (:project-id params)
team-id (:team-id params)

View file

@ -6,29 +6,15 @@
(ns app.main.ui.dashboard.comments
(:require
[okulary.core :as l]
[app.common.data :as d]
[app.common.spec :as us]
[app.config :as cfg]
[app.main.data.dashboard :as dd]
[app.main.data.workspace :as dw]
[app.main.data.workspace.comments :as dwcm]
[app.main.data.comments :as dcm]
[app.main.data.workspace.comments :as dwcm]
[app.main.refs :as refs]
[app.main.repo :as rp]
[app.main.store :as st]
[app.main.ui.components.dropdown :refer [dropdown]]
[app.main.ui.comments :as cmt]
[app.main.ui.components.dropdown :refer [dropdown]]
[app.main.ui.icons :as i]
[app.util.dom :as dom]
[app.util.i18n :as i18n :refer [t tr]]
[app.util.object :as obj]
[app.util.router :as rt]
[app.util.time :as dt]
[app.util.timers :as tm]
[beicon.core :as rx]
[cljs.spec.alpha :as s]
[cuerdas.core :as str]
[app.util.i18n :as i18n :refer [tr]]
[rumext.alpha :as mf]))
(mf/defc comments-section

View file

@ -7,7 +7,6 @@
(ns app.main.ui.dashboard.files
(:require
[app.main.data.dashboard :as dd]
[app.main.data.modal :as modal]
[app.main.refs :as refs]
[app.main.store :as st]
[app.main.ui.dashboard.grid :refer [grid]]
@ -16,18 +15,12 @@
[app.main.ui.icons :as i]
[app.util.dom :as dom]
[app.util.i18n :as i18n :refer [tr]]
[app.util.keyboard :as kbd]
[app.util.router :as rt]
[okulary.core :as l]
[rumext.alpha :as mf]))
(mf/defc header
[{:keys [team project] :as props}]
[{:keys [project] :as props}]
(let [local (mf/use-state {:menu-open false
:edition false})
project-id (:id project)
team-id (:id team)
on-menu-click
(mf/use-callback
(fn [event]
@ -83,7 +76,7 @@
(if (:is-pinned project)
i/pin-fill
i/pin)]
[:div.icon.tooltip.tooltip-bottom
{:on-click on-menu-click :alt (tr "dashboard.options")}
i/actions]]]))

View file

@ -6,27 +6,22 @@
(ns app.main.ui.dashboard.fonts
(:require
[app.common.data :as d]
[app.common.media :as cm]
[app.common.uuid :as uuid]
[app.main.data.dashboard :as dd]
[app.main.data.fonts :as df]
[app.main.data.modal :as modal]
[app.main.ui.components.file-uploader :refer [file-uploader]]
[app.main.ui.components.context-menu :refer [context-menu]]
[app.main.store :as st]
[app.main.repo :as rp]
[app.main.refs :as refs]
[app.main.repo :as rp]
[app.main.store :as st]
[app.main.ui.components.context-menu :refer [context-menu]]
[app.main.ui.components.file-uploader :refer [file-uploader]]
[app.main.ui.icons :as i]
[app.util.dom :as dom]
[app.util.i18n :as i18n :refer [tr]]
[app.util.logging :as log]
[app.util.keyboard :as kbd]
[app.util.router :as rt]
[app.util.webapi :as wa]
[cuerdas.core :as str]
[app.util.logging :as log]
;; [app.util.router :as rt]
[beicon.core :as rx]
[okulary.core :as l]
[cuerdas.core :as str]
[rumext.alpha :as mf]))
(log/set-level! :trace)
@ -47,29 +42,29 @@
(mf/defc header
{::mf/wrap [mf/memo]}
[{:keys [section team] :as props}]
(let [go-fonts
(mf/use-callback
(mf/deps team)
(st/emitf (rt/nav :dashboard-fonts {:team-id (:id team)})))
;; (let [go-fonts
;; (mf/use-callback
;; (mf/deps team)
;; (st/emitf (rt/nav :dashboard-fonts {:team-id (:id team)})))
go-providers
(mf/use-callback
(mf/deps team)
(st/emitf (rt/nav :dashboard-font-providers {:team-id (:id team)})))]
;; go-providers
;; (mf/use-callback
;; (mf/deps team)
;; (st/emitf (rt/nav :dashboard-font-providers {:team-id (:id team)})))]
(use-set-page-title team section)
(use-set-page-title team section)
[:header.dashboard-header
[:div.dashboard-title
[:h1 (tr "labels.fonts")]]
[:nav
#_[:ul
[:li {:class (when (= section :fonts) "active")}
[:a {:on-click go-fonts} (tr "labels.custom-fonts")]]
[:li {:class (when (= section :providers) "active")}
[:a {:on-click go-providers} (tr "labels.font-providers")]]]]
[:header.dashboard-header
[:div.dashboard-title
[:h1 (tr "labels.fonts")]]
[:nav
#_[:ul
[:li {:class (when (= section :fonts) "active")}
[:a {:on-click go-fonts} (tr "labels.custom-fonts")]]
[:li {:class (when (= section :providers) "active")}
[:a {:on-click go-providers} (tr "labels.font-providers")]]]]
[:div]]))
[:div]])
(mf/defc font-variant-display-name
[{:keys [variant]}]
@ -88,9 +83,6 @@
on-click
(mf/use-callback #(dom/click (mf/ref-val input-ref)))
font-key-fn
(mf/use-callback (juxt :font-family :font-weight :font-style))
on-selected
(mf/use-callback
(mf/deps team installed-fonts)
@ -190,7 +182,7 @@
(reset! state (dom/get-target-val event)))
on-save
(fn [event]
(fn [_]
(let [font-family @state]
(when-not (str/blank? font-family)
(st/emit! (df/update-font
@ -204,7 +196,7 @@
(on-save event)))
on-cancel
(fn [event]
(fn [_]
(reset! edit? false)
(reset! state (:font-family font)))
@ -221,8 +213,7 @@
:title (tr "modals.delete-font.title")
:message (tr "modals.delete-font.message")
:accept-label (tr "labels.delete")
:on-accept (fn [props]
(delete-font-fn))})))
:on-accept (fn [_props] (delete-font-fn))})))
on-delete-variant
(fn [id]
@ -231,7 +222,7 @@
:title (tr "modals.delete-font-variant.title")
:message (tr "modals.delete-font-variant.message")
:accept-label (tr "labels.delete")
:on-accept (fn [props]
:on-accept (fn [_props]
(delete-variant-fn id))})))]
[:div.font-item.table-row
@ -276,7 +267,7 @@
(mf/defc installed-fonts
[{:keys [team fonts] :as props}]
[{:keys [fonts] :as props}]
(let [sterm (mf/use-state "")
matches?

View file

@ -7,11 +7,8 @@
(ns app.main.ui.dashboard.grid
(:require
[app.common.math :as mth]
[app.common.uuid :as uuid]
[app.config :as cfg]
[app.main.data.dashboard :as dd]
[app.main.data.messages :as dm]
[app.main.data.modal :as modal]
[app.main.fonts :as fonts]
[app.main.refs :as refs]
[app.main.store :as st]
@ -23,12 +20,10 @@
[app.util.dom.dnd :as dnd]
[app.util.i18n :as i18n :refer [tr]]
[app.util.keyboard :as kbd]
[app.util.router :as rt]
[app.util.time :as dt]
[app.util.timers :as ts]
[app.util.webapi :as wapi]
[beicon.core :as rx]
[cuerdas.core :as str]
[rumext.alpha :as mf]))
;; --- Grid Item Thumbnail
@ -59,7 +54,7 @@
(str (tr "ds.updated-at" time))))
(defn create-counter-element
[element file-count]
[_element file-count]
(let [counter-el (dom/create-element "div")]
(dom/set-property! counter-el "class" "drag-counter")
(dom/set-text! counter-el (str file-count))
@ -215,7 +210,7 @@
[:div.text (tr "dashboard.loading-files")]])
(mf/defc grid
[{:keys [id opts files] :as props}]
[{:keys [files] :as props}]
[:section.dashboard-grid
(cond
(nil? files)
@ -233,7 +228,7 @@
[:& empty-placeholder])])
(mf/defc line-grid-row
[{:keys [files team-id selected-files on-load-more dragging?] :as props}]
[{:keys [files selected-files on-load-more dragging?] :as props}]
(let [rowref (mf/use-ref)
width (mf/use-state nil)
@ -288,7 +283,7 @@
(tr "dashboard.show-all-files")]])]))
(mf/defc line-grid
[{:keys [project-id team-id opts files on-load-more] :as props}]
[{:keys [project-id team-id files on-load-more] :as props}]
(let [dragging? (mf/use-state false)
selected-files (mf/deref refs/dashboard-selected-files)
@ -326,7 +321,7 @@
on-drop
(mf/use-callback
(mf/deps files selected-files)
(fn [e]
(fn [_]
(reset! dragging? false)
(when (not= selected-project project-id)
(let [data {:ids (into #{} (keys selected-files))

View file

@ -7,7 +7,6 @@
(ns app.main.ui.dashboard.import
(:require
[app.main.ui.components.file-uploader :refer [file-uploader]]
[app.main.ui.icons :as i]
[app.main.worker :as uw]
[app.util.dom :as dom]
[app.util.logging :as log]

View file

@ -7,14 +7,11 @@
(ns app.main.ui.dashboard.libraries
(:require
[app.main.data.dashboard :as dd]
[app.main.refs :as refs]
[app.main.store :as st]
[app.main.ui.dashboard.grid :refer [grid]]
[app.main.ui.icons :as i]
[app.main.refs :as refs]
[app.util.dom :as dom]
[app.util.i18n :as i18n :refer [tr]]
[app.util.router :as rt]
[okulary.core :as l]
[rumext.alpha :as mf]))
(mf/defc libraries-page

View file

@ -10,7 +10,6 @@
[app.main.data.messages :as dm]
[app.main.data.modal :as modal]
[app.main.refs :as refs]
[app.main.repo :as rp]
[app.main.store :as st]
[app.main.ui.components.context-menu :refer [context-menu]]
[app.main.ui.context :as ctx]
@ -19,7 +18,6 @@
[app.util.dom :as dom]
[app.util.i18n :as i18n :refer [tr]]
[app.util.router :as rt]
[beicon.core :as rx]
[rumext.alpha :as mf]))
(mf/defc project-menu
@ -62,7 +60,7 @@
(dd/move-project (with-meta data mdata)))))
delete-fn
(fn [event]
(fn [_]
(st/emit! (dm/success (tr "dashboard.success-delete-project"))
(dd/delete-project project)
(dd/go-to-projects (:team-id project))))

View file

@ -6,8 +6,6 @@
(ns app.main.ui.dashboard.projects
(:require
[app.common.exceptions :as ex]
[app.main.constants :as c]
[app.main.data.dashboard :as dd]
[app.main.refs :as refs]
[app.main.store :as st]
@ -16,8 +14,7 @@
[app.main.ui.dashboard.project-menu :refer [project-menu]]
[app.main.ui.icons :as i]
[app.util.dom :as dom]
[app.util.i18n :as i18n :refer [t tr]]
[app.util.keyboard :as kbd]
[app.util.i18n :as i18n :refer [tr]]
[app.util.router :as rt]
[app.util.time :as dt]
[okulary.core :as l]
@ -38,7 +35,6 @@
[{:keys [project first? files] :as props}]
(let [locale (mf/deref i18n/locale)
project-id (:id project)
team-id (:team-id project)
file-count (or (:count project) 0)

Some files were not shown because too many files have changed in this diff Show more