0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-21 06:02:32 -05:00

Fix linter issues on frontend (part 1).

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

View file

@ -1,14 +1,22 @@
{:lint-as {potok.core/reify clojure.core/reify
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
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}}
:output
{:exclude-files ["data_readers.clj"]}
{:exclude-files
["data_readers.clj"
"app/util/perf.cljs"
"app/util/import/.*"
"app/worker/.*"
"app/main/ui.*"
"app/libs/.*"
]}
:linters
{:unsorted-required-namespaces

View file

@ -9,3 +9,13 @@
(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}))

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

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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