mirror of
https://github.com/penpot/penpot.git
synced 2025-05-19 17:56:13 +02:00
🔥 Remove unused code.
This commit is contained in:
parent
0dbcfcbc0b
commit
60b241e867
9 changed files with 49 additions and 136 deletions
|
@ -20,8 +20,7 @@
|
||||||
[app.util.router :as rt]
|
[app.util.router :as rt]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.util.time :as ts]
|
[app.util.time :as ts]
|
||||||
[app.util.router :as r]
|
[app.util.router :as r]))
|
||||||
[app.util.files :as files]))
|
|
||||||
|
|
||||||
;; --- Specs
|
;; --- Specs
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
|
[app.common.pages :as cp]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.main.data.workspace.common :as dwc]
|
[app.main.data.workspace.common :as dwc]
|
||||||
[app.main.data.workspace.persistence :as dwp]
|
[app.main.data.workspace.persistence :as dwp]
|
||||||
|
@ -26,8 +27,7 @@
|
||||||
[clojure.set :as set]
|
[clojure.set :as set]
|
||||||
[potok.core :as ptk]))
|
[potok.core :as ptk]))
|
||||||
|
|
||||||
;; TODO: this module need to be revisited.
|
(declare process-message)
|
||||||
|
|
||||||
(declare handle-presence)
|
(declare handle-presence)
|
||||||
(declare handle-pointer-update)
|
(declare handle-pointer-update)
|
||||||
(declare handle-file-change)
|
(declare handle-file-change)
|
||||||
|
@ -57,30 +57,45 @@
|
||||||
(->> (rx/timer interval interval)
|
(->> (rx/timer interval interval)
|
||||||
(rx/map #(send-keepalive file-id)))
|
(rx/map #(send-keepalive file-id)))
|
||||||
(->> (ws/-stream wsession)
|
(->> (ws/-stream wsession)
|
||||||
(rx/filter #(= :message (:type %)))
|
(rx/filter ws/message?)
|
||||||
(rx/map (comp t/decode :payload))
|
(rx/map (comp t/decode :payload))
|
||||||
(rx/filter #(s/valid? ::message %))
|
(rx/filter #(s/valid? ::message %))
|
||||||
(rx/map (fn [{:keys [type] :as msg}]
|
(rx/map process-message))
|
||||||
(case type
|
|
||||||
:presence (handle-presence msg)
|
|
||||||
:pointer-update (handle-pointer-update msg)
|
|
||||||
:file-change (handle-file-change msg)
|
|
||||||
::unknown))))
|
|
||||||
|
|
||||||
(->> stream
|
(->> stream
|
||||||
(rx/filter ms/pointer-event?)
|
(rx/filter ms/pointer-event?)
|
||||||
(rx/sample 50)
|
(rx/sample 50)
|
||||||
(rx/map #(handle-pointer-send file-id (:pt %)))))
|
(rx/map #(handle-pointer-send file-id (:pt %)))))
|
||||||
|
|
||||||
(rx/take-until stoper))))))
|
(rx/take-until stoper))))))
|
||||||
|
|
||||||
(defn send-keepalive
|
(defn- process-message
|
||||||
|
[{:keys [type] :as msg}]
|
||||||
|
(case type
|
||||||
|
:presence (handle-presence msg)
|
||||||
|
:pointer-update (handle-pointer-update msg)
|
||||||
|
:file-change (handle-file-change msg)
|
||||||
|
::unknown))
|
||||||
|
|
||||||
|
(defn- send-keepalive
|
||||||
[file-id]
|
[file-id]
|
||||||
(ptk/reify ::send-keepalive
|
(ptk/reify ::send-keepalive
|
||||||
ptk/EffectEvent
|
ptk/EffectEvent
|
||||||
(effect [_ state stream]
|
(effect [_ state stream]
|
||||||
(when-let [ws (get-in state [:ws file-id])]
|
(when-let [ws (get-in state [:ws file-id])]
|
||||||
(ws/-send ws (t/encode {:type :keepalive}))))))
|
(ws/send! ws {:type :keepalive})))))
|
||||||
|
|
||||||
|
(defn- handle-pointer-send
|
||||||
|
[file-id point]
|
||||||
|
(ptk/reify ::handle-pointer-update
|
||||||
|
ptk/EffectEvent
|
||||||
|
(effect [_ state stream]
|
||||||
|
(let [ws (get-in state [:ws file-id])
|
||||||
|
sid (:session-id state)
|
||||||
|
pid (:current-page-id state)
|
||||||
|
msg {:type :pointer-update
|
||||||
|
:page-id pid
|
||||||
|
:x (:x point)
|
||||||
|
:y (:y point)}]
|
||||||
|
(ws/send! ws msg)))))
|
||||||
|
|
||||||
;; --- Finalize Websocket
|
;; --- Finalize Websocket
|
||||||
|
|
||||||
|
@ -159,24 +174,19 @@
|
||||||
:updated-at (dt/now)
|
:updated-at (dt/now)
|
||||||
:page-id page-id))))))
|
:page-id page-id))))))
|
||||||
|
|
||||||
(defn handle-pointer-send
|
(s/def ::type keyword?)
|
||||||
[file-id point]
|
(s/def ::profile-id uuid?)
|
||||||
(ptk/reify ::handle-pointer-update
|
(s/def ::file-id uuid?)
|
||||||
ptk/EffectEvent
|
(s/def ::session-id uuid?)
|
||||||
(effect [_ state stream]
|
(s/def ::revn integer?)
|
||||||
(let [ws (get-in state [:ws file-id])
|
(s/def ::changes ::cp/changes)
|
||||||
sid (:session-id state)
|
|
||||||
pid (:current-page-id state)
|
|
||||||
msg {:type :pointer-update
|
|
||||||
:page-id pid
|
|
||||||
:x (:x point)
|
|
||||||
:y (:y point)}]
|
|
||||||
(ws/-send ws (t/encode msg))))))
|
|
||||||
|
|
||||||
;; TODO: add specs
|
(s/def ::file-change-event
|
||||||
|
(s/keys :req-un [::type ::profile-id ::file-id ::session-id ::revn ::changes]))
|
||||||
|
|
||||||
(defn handle-file-change
|
(defn handle-file-change
|
||||||
[{:keys [file-id changes] :as msg}]
|
[{:keys [file-id changes] :as msg}]
|
||||||
|
(us/assert ::file-change-event msg)
|
||||||
(ptk/reify ::handle-file-change
|
(ptk/reify ::handle-file-change
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
|
|
|
@ -178,15 +178,12 @@
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (dwc/lookup-page-objects state page-id)
|
||||||
group (get objects group-id)
|
group (get objects group-id)
|
||||||
children (map #(get objects %) (:shapes group))
|
children (map #(get objects %) (:shapes group))
|
||||||
|
selected (d/seek #(geom/has-point? % position) children)]
|
||||||
;; TODO: consider using d/seek instead of filter+first
|
|
||||||
selected (->> children (filter #(geom/has-point? % position)) first)]
|
|
||||||
(when selected
|
(when selected
|
||||||
(rx/of deselect-all (select-shape (:id selected))))))))
|
(rx/of deselect-all (select-shape (:id selected))))))))
|
||||||
|
|
||||||
|
|
||||||
;; --- Duplicate Shapes
|
;; --- Duplicate Shapes
|
||||||
;; (declare prepare-duplicate-changes)
|
|
||||||
(declare prepare-duplicate-change)
|
(declare prepare-duplicate-change)
|
||||||
(declare prepare-duplicate-frame-change)
|
(declare prepare-duplicate-frame-change)
|
||||||
(declare prepare-duplicate-shape-change)
|
(declare prepare-duplicate-shape-change)
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
[app.main.ui.workspace.shapes.common :as common]
|
[app.main.ui.workspace.shapes.common :as common]
|
||||||
[app.main.data.workspace.drawing :as dr]
|
[app.main.data.workspace.drawing :as dr]
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
[app.util.interop :as itr]
|
|
||||||
[app.main.streams :as ms]
|
[app.main.streams :as ms]
|
||||||
[app.util.timers :as ts]))
|
[app.util.timers :as ts]))
|
||||||
|
|
||||||
|
|
|
@ -1,31 +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) 2016 Andrey Antukh <niwi@niwi.nz>
|
|
||||||
|
|
||||||
(ns app.util.blob
|
|
||||||
"Helpers for work with HTML5 Blob objects.")
|
|
||||||
|
|
||||||
;; TODO: DEPRECATED
|
|
||||||
|
|
||||||
(defn ^boolean blob?
|
|
||||||
[v]
|
|
||||||
(instance? js/Blob v))
|
|
||||||
|
|
||||||
(defn create
|
|
||||||
"Create a blob from content."
|
|
||||||
([content]
|
|
||||||
(create content "application/octet-stream"))
|
|
||||||
([content mimetype]
|
|
||||||
(js/Blob. #js [content] #js {:type mimetype})))
|
|
||||||
|
|
||||||
(defn revoke-uri
|
|
||||||
[url]
|
|
||||||
(js/URL.revokeObjectURL url))
|
|
||||||
|
|
||||||
(defn create-uri
|
|
||||||
"Create a url from blob."
|
|
||||||
[b]
|
|
||||||
{:pre [(blob? b)]}
|
|
||||||
(js/URL.createObjectURL b))
|
|
|
@ -14,7 +14,6 @@
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.util.blob :as blob]
|
|
||||||
[app.util.transit :as ts]))
|
[app.util.transit :as ts]))
|
||||||
|
|
||||||
;; --- Deprecated methods
|
;; --- Deprecated methods
|
||||||
|
|
|
@ -1,44 +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) 2016 Andrey Antukh <niwi@niwi.nz>
|
|
||||||
|
|
||||||
(ns app.util.files
|
|
||||||
"A interop helpers for work with files."
|
|
||||||
(:require [beicon.core :as rx]
|
|
||||||
[cuerdas.core :as str]
|
|
||||||
[app.util.blob :as blob]))
|
|
||||||
|
|
||||||
;; TODO: DEPRECATED
|
|
||||||
|
|
||||||
(defn read-as-text
|
|
||||||
[file]
|
|
||||||
(rx/create
|
|
||||||
(fn [sink]
|
|
||||||
(let [fr (js/FileReader.)]
|
|
||||||
(aset fr "onload" #(sink (rx/end (.-result fr))))
|
|
||||||
(.readAsText fr file)
|
|
||||||
(constantly nil)))))
|
|
||||||
|
|
||||||
(defn read-as-dataurl
|
|
||||||
[file]
|
|
||||||
(rx/create
|
|
||||||
(fn [sick]
|
|
||||||
(let [fr (js/FileReader.)]
|
|
||||||
(aset fr "onload" #(sick (rx/end (.-result fr))))
|
|
||||||
(.readAsDataURL fr file))
|
|
||||||
(constantly nil))))
|
|
||||||
|
|
||||||
(defn get-image-size
|
|
||||||
[file]
|
|
||||||
(letfn [(on-load [sink img]
|
|
||||||
(let [size [(.-width img) (.-height img)]]
|
|
||||||
(sink (rx/end size))))
|
|
||||||
(on-subscribe [sink]
|
|
||||||
(let [img (js/Image.)
|
|
||||||
uri (blob/create-uri file)]
|
|
||||||
(set! (.-onload img) (partial on-load sink img))
|
|
||||||
(set! (.-src img) uri)
|
|
||||||
#(blob/revoke-uri uri)))]
|
|
||||||
(rx/create on-subscribe)))
|
|
|
@ -1,25 +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) 2016 Andrey Antukh <niwi@niwi.nz>
|
|
||||||
|
|
||||||
(ns app.util.interop
|
|
||||||
"Interop helpers.")
|
|
||||||
|
|
||||||
;; TODO: this can be optimized using es6-iterator-seq
|
|
||||||
(defn iterable->seq
|
|
||||||
"Convert an es6 iterable into cljs Seq."
|
|
||||||
[v]
|
|
||||||
(seq (js/Array.from v)))
|
|
||||||
|
|
||||||
(defn obj-assign!
|
|
||||||
([a b]
|
|
||||||
(js/Object.assign a b))
|
|
||||||
([a b & more]
|
|
||||||
(reduce obj-assign! (obj-assign! a b) more)))
|
|
||||||
|
|
||||||
(defn obj-assoc!
|
|
||||||
[obj attr value]
|
|
||||||
(unchecked-set obj attr value)
|
|
||||||
obj)
|
|
|
@ -10,9 +10,10 @@
|
||||||
(ns app.util.websockets
|
(ns app.util.websockets
|
||||||
"A interface to webworkers exposed functionality."
|
"A interface to webworkers exposed functionality."
|
||||||
(:require
|
(:require
|
||||||
[goog.events :as ev]
|
|
||||||
[app.config :as cfg]
|
[app.config :as cfg]
|
||||||
|
[app.util.transit :as t]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
|
[goog.events :as ev]
|
||||||
[potok.core :as ptk])
|
[potok.core :as ptk])
|
||||||
(:import
|
(:import
|
||||||
goog.Uri
|
goog.Uri
|
||||||
|
@ -63,3 +64,11 @@
|
||||||
(ev/unlistenByKey lk1)
|
(ev/unlistenByKey lk1)
|
||||||
(ev/unlistenByKey lk2)
|
(ev/unlistenByKey lk2)
|
||||||
(ev/unlistenByKey lk3)))))
|
(ev/unlistenByKey lk3)))))
|
||||||
|
|
||||||
|
(defn message?
|
||||||
|
[msg]
|
||||||
|
(= (:type msg) :message))
|
||||||
|
|
||||||
|
(defn send!
|
||||||
|
[ws msg]
|
||||||
|
(-send ws (t/encode msg)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue