mirror of
https://github.com/penpot/penpot.git
synced 2025-05-11 06:06:38 +02:00
🎉 Introduce ordered-set type and use it for workspace selected.
This commit is contained in:
parent
778bfbab59
commit
1dd1b9d987
9 changed files with 78 additions and 23 deletions
|
@ -43,6 +43,7 @@
|
||||||
lambdaisland/uri {:mvn/version "1.3.45"
|
lambdaisland/uri {:mvn/version "1.3.45"
|
||||||
:exclusions [org.clojure/data.json]}
|
:exclusions [org.clojure/data.json]}
|
||||||
|
|
||||||
|
frankiesardo/linked {:mvn/version "1.3.0"}
|
||||||
danlentz/clj-uuid {:mvn/version "0.1.9"}
|
danlentz/clj-uuid {:mvn/version "0.1.9"}
|
||||||
org.jsoup/jsoup {:mvn/version "1.13.1"}
|
org.jsoup/jsoup {:mvn/version "1.13.1"}
|
||||||
org.im4java/im4java {:mvn/version "1.4.0"}
|
org.im4java/im4java {:mvn/version "1.4.0"}
|
||||||
|
|
|
@ -2,17 +2,22 @@
|
||||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
;; 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/.
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
;;
|
;;
|
||||||
;; Copyright (c) 2019 Andrey Antukh <niwi@niwi.nz>
|
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||||
|
;; defined by the Mozilla Public License, v. 2.0.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) 2020 UXBOX Labs SL
|
||||||
|
|
||||||
(ns uxbox.util.transit
|
(ns uxbox.util.transit
|
||||||
(:require
|
(:require
|
||||||
[cognitect.transit :as t]
|
[cognitect.transit :as t]
|
||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
|
[linked.core :as lk]
|
||||||
[uxbox.util.time :as dt]
|
[uxbox.util.time :as dt]
|
||||||
[uxbox.util.data :as data]
|
[uxbox.util.data :as data]
|
||||||
[uxbox.common.geom.point :as gpt]
|
[uxbox.common.geom.point :as gpt]
|
||||||
[uxbox.common.geom.matrix :as gmt])
|
[uxbox.common.geom.matrix :as gmt])
|
||||||
(:import
|
(:import
|
||||||
|
linked.set.LinkedSet
|
||||||
java.io.ByteArrayInputStream
|
java.io.ByteArrayInputStream
|
||||||
java.io.ByteArrayOutputStream
|
java.io.ByteArrayOutputStream
|
||||||
java.io.File
|
java.io.File
|
||||||
|
@ -42,14 +47,24 @@
|
||||||
(def matrix-read-handler
|
(def matrix-read-handler
|
||||||
(t/read-handler gmt/map->Matrix))
|
(t/read-handler gmt/map->Matrix))
|
||||||
|
|
||||||
|
(def ordered-set-write-handler
|
||||||
|
(t/write-handler
|
||||||
|
(constantly "ordered-set")
|
||||||
|
(fn [v] (vec v))))
|
||||||
|
|
||||||
|
(def ordered-set-read-handler
|
||||||
|
(t/read-handler #(into (lk/set) %)))
|
||||||
|
|
||||||
(def +read-handlers+
|
(def +read-handlers+
|
||||||
(assoc dt/+read-handlers+
|
(assoc dt/+read-handlers+
|
||||||
"matrix" matrix-read-handler
|
"matrix" matrix-read-handler
|
||||||
|
"ordered-set" ordered-set-read-handler
|
||||||
"point" point-read-handler))
|
"point" point-read-handler))
|
||||||
|
|
||||||
(def +write-handlers+
|
(def +write-handlers+
|
||||||
(assoc dt/+write-handlers+
|
(assoc dt/+write-handlers+
|
||||||
File file-write-handler
|
File file-write-handler
|
||||||
|
LinkedSet ordered-set-write-handler
|
||||||
Matrix matrix-write-handler
|
Matrix matrix-write-handler
|
||||||
Point point-write-handler))
|
Point point-write-handler))
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,27 @@
|
||||||
"Data manipulation and query helper functions."
|
"Data manipulation and query helper functions."
|
||||||
(:refer-clojure :exclude [concat read-string])
|
(:refer-clojure :exclude [concat read-string])
|
||||||
(:require [clojure.set :as set]
|
(:require [clojure.set :as set]
|
||||||
|
[linked.set :as lks]
|
||||||
#?(:cljs [cljs.reader :as r]
|
#?(:cljs [cljs.reader :as r]
|
||||||
:clj [clojure.edn :as r])
|
:clj [clojure.edn :as r])
|
||||||
#?(:cljs [cljs.core :as core]
|
#?(:cljs [cljs.core :as core]
|
||||||
:clj [clojure.core :as core])))
|
:clj [clojure.core :as core]))
|
||||||
|
#?(:clj
|
||||||
|
(:import linked.set.LinkedSet)))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;; Data Structures
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(defn ordered-set
|
||||||
|
([] lks/empty-linked-set)
|
||||||
|
([a] (conj lks/empty-linked-set a))
|
||||||
|
([a & xs] (apply conj lks/empty-linked-set a xs)))
|
||||||
|
|
||||||
|
(defn ordered-set?
|
||||||
|
[o]
|
||||||
|
#?(:cljs (instance? lks/LinkedSet o)
|
||||||
|
:clj (instance? LinkedSet o)))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Data Structures Manipulation
|
;; Data Structures Manipulation
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
expound/expound {:mvn/version "0.8.4"}
|
expound/expound {:mvn/version "0.8.4"}
|
||||||
|
|
||||||
danlentz/clj-uuid {:mvn/version "0.1.9"}
|
danlentz/clj-uuid {:mvn/version "0.1.9"}
|
||||||
|
frankiesardo/linked {:mvn/version "1.3.0"}
|
||||||
|
|
||||||
funcool/beicon {:mvn/version "2020.05.08-2"}
|
funcool/beicon {:mvn/version "2020.05.08-2"}
|
||||||
funcool/cuerdas {:mvn/version "2020.03.26-3"}
|
funcool/cuerdas {:mvn/version "2020.03.26-3"}
|
||||||
|
|
|
@ -77,7 +77,7 @@
|
||||||
(def workspace-default
|
(def workspace-default
|
||||||
{:zoom 1
|
{:zoom 1
|
||||||
:flags #{}
|
:flags #{}
|
||||||
:selected #{}
|
:selected (d/ordered-set)
|
||||||
:expanded {}
|
:expanded {}
|
||||||
:drawing nil
|
:drawing nil
|
||||||
:drawing-tool nil
|
:drawing-tool nil
|
||||||
|
@ -505,7 +505,7 @@
|
||||||
:id id}]
|
:id id}]
|
||||||
|
|
||||||
(rx/of (dwc/commit-changes [rchange] [uchange] {:commit-local? true})
|
(rx/of (dwc/commit-changes [rchange] [uchange] {:commit-local? true})
|
||||||
(dws/select-shapes #{id})
|
(dws/select-shapes (d/ordered-set id))
|
||||||
(when (= :text (:type attrs))
|
(when (= :text (:type attrs))
|
||||||
(start-edition-mode id)))))))
|
(start-edition-mode id)))))))
|
||||||
|
|
||||||
|
@ -1155,7 +1155,7 @@
|
||||||
selected (->> rchanges
|
selected (->> rchanges
|
||||||
(filter #(selected (:old-id %)))
|
(filter #(selected (:old-id %)))
|
||||||
(map #(get-in % [:obj :id]))
|
(map #(get-in % [:obj :id]))
|
||||||
(into #{}))]
|
(into (d/ordered-set)))]
|
||||||
(rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true})
|
(rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true})
|
||||||
(dws/select-shapes selected))))))
|
(dws/select-shapes selected))))))
|
||||||
|
|
||||||
|
@ -1273,7 +1273,7 @@
|
||||||
uchanges (conj uchanges {:type :del-obj :id id})]
|
uchanges (conj uchanges {:type :del-obj :id id})]
|
||||||
|
|
||||||
(rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true})
|
(rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true})
|
||||||
(dws/select-shapes #{id}))))))))
|
(dws/select-shapes (d/ordered-set id)))))))))
|
||||||
|
|
||||||
(def ungroup-selected
|
(def ungroup-selected
|
||||||
(ptk/reify ::ungroup-selected
|
(ptk/reify ::ungroup-selected
|
||||||
|
|
|
@ -27,6 +27,9 @@
|
||||||
(s/def ::set-of-uuid
|
(s/def ::set-of-uuid
|
||||||
(s/every uuid? :kind set?))
|
(s/every uuid? :kind set?))
|
||||||
|
|
||||||
|
(s/def ::ordered-set-of-uuid
|
||||||
|
(s/every uuid? :kind d/ordered-set?))
|
||||||
|
|
||||||
(s/def ::set-of-string
|
(s/def ::set-of-string
|
||||||
(s/every string? :kind set?))
|
(s/every string? :kind set?))
|
||||||
|
|
||||||
|
@ -128,7 +131,7 @@
|
||||||
|
|
||||||
(defn select-shapes
|
(defn select-shapes
|
||||||
[ids]
|
[ids]
|
||||||
(us/verify ::set-of-uuid ids)
|
(us/verify ::ordered-set-of-uuid ids)
|
||||||
(ptk/reify ::select-shapes
|
(ptk/reify ::select-shapes
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -147,10 +150,9 @@
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(update state :workspace-local #(-> %
|
(update state :workspace-local #(-> %
|
||||||
(assoc :selected #{})
|
(assoc :selected (d/ordered-set))
|
||||||
(dissoc :selected-frame))))))
|
(dissoc :selected-frame))))))
|
||||||
|
|
||||||
|
|
||||||
;; --- Select Shapes (By selrect)
|
;; --- Select Shapes (By selrect)
|
||||||
|
|
||||||
(def select-shapes-by-current-selrect
|
(def select-shapes-by-current-selrect
|
||||||
|
@ -294,7 +296,7 @@
|
||||||
selected (->> rchanges
|
selected (->> rchanges
|
||||||
(filter #(selected (:old-id %)))
|
(filter #(selected (:old-id %)))
|
||||||
(map #(get-in % [:obj :id]))
|
(map #(get-in % [:obj :id]))
|
||||||
(into #{}))]
|
(into (d/ordered-set)))]
|
||||||
|
|
||||||
(rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true})
|
(rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true})
|
||||||
(select-shapes selected))))))
|
(select-shapes selected))))))
|
||||||
|
|
|
@ -10,12 +10,13 @@
|
||||||
(ns uxbox.main.ui.workspace.sidebar.options.interactions
|
(ns uxbox.main.ui.workspace.sidebar.options.interactions
|
||||||
(:require
|
(:require
|
||||||
[rumext.alpha :as mf]
|
[rumext.alpha :as mf]
|
||||||
[uxbox.main.ui.icons :as i]
|
[uxbox.common.data :as d]
|
||||||
[uxbox.common.pages-helpers :as cph]
|
[uxbox.common.pages-helpers :as cph]
|
||||||
[uxbox.main.data.workspace :as dw]
|
[uxbox.main.data.workspace :as dw]
|
||||||
[uxbox.main.refs :as refs]
|
[uxbox.main.refs :as refs]
|
||||||
[uxbox.main.store :as st]
|
[uxbox.main.store :as st]
|
||||||
[uxbox.main.ui.components.dropdown :refer [dropdown]]
|
[uxbox.main.ui.components.dropdown :refer [dropdown]]
|
||||||
|
[uxbox.main.ui.icons :as i]
|
||||||
[uxbox.util.dom :as dom]
|
[uxbox.util.dom :as dom]
|
||||||
[uxbox.util.i18n :as i18n :refer [t]]))
|
[uxbox.util.i18n :as i18n :refer [t]]))
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@
|
||||||
show-frames-dropdown? (mf/use-state false)
|
show-frames-dropdown? (mf/use-state false)
|
||||||
|
|
||||||
on-set-blur #(reset! show-frames-dropdown? false)
|
on-set-blur #(reset! show-frames-dropdown? false)
|
||||||
on-navigate #(st/emit! (dw/select-shapes #{(:id destination)}))
|
on-navigate #(st/emit! (dw/select-shapes (d/ordered-set (:id destination))))
|
||||||
|
|
||||||
on-select-destination
|
on-select-destination
|
||||||
(fn [dest]
|
(fn [dest]
|
||||||
|
|
|
@ -2,11 +2,17 @@
|
||||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
;; 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/.
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
;;
|
;;
|
||||||
;; Copyright (c) 2016-2017 Andrey Antukh <niwi@niwi.nz>
|
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||||
|
;; defined by the Mozilla Public License, v. 2.0.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) 2020 UXBOX Labs SL
|
||||||
|
|
||||||
(ns uxbox.util.transit
|
(ns uxbox.util.transit
|
||||||
"A lightweight abstraction for transit serialization."
|
"A lightweight abstraction for transit serialization."
|
||||||
(:require [cognitect.transit :as t]
|
(:require
|
||||||
|
[cognitect.transit :as t]
|
||||||
|
[linked.core :as lk]
|
||||||
|
[linked.set :as lks]
|
||||||
[uxbox.common.geom.point :as gpt]
|
[uxbox.common.geom.point :as gpt]
|
||||||
[uxbox.common.geom.matrix :as gmt]
|
[uxbox.common.geom.matrix :as gmt]
|
||||||
[uxbox.util.time :as dt]))
|
[uxbox.util.time :as dt]))
|
||||||
|
@ -51,10 +57,19 @@
|
||||||
(fn [value]
|
(fn [value]
|
||||||
(gmt/map->Matrix value))))
|
(gmt/map->Matrix value))))
|
||||||
|
|
||||||
|
(def ordered-set-write-handler
|
||||||
|
(t/write-handler
|
||||||
|
(constantly "ordered-set")
|
||||||
|
(fn [v] (vec v))))
|
||||||
|
|
||||||
|
(def ordered-set-read-handler
|
||||||
|
(t/read-handler #(into (lk/set) %)))
|
||||||
|
|
||||||
;; --- Transit Handlers
|
;; --- Transit Handlers
|
||||||
|
|
||||||
(def ^:privare +read-handlers+
|
(def ^:privare +read-handlers+
|
||||||
{"u" uuid
|
{"u" uuid
|
||||||
|
"ordered-set" ordered-set-read-handler
|
||||||
"jsonblob" blob-read-handler
|
"jsonblob" blob-read-handler
|
||||||
"matrix" matrix-read-handler
|
"matrix" matrix-read-handler
|
||||||
"point" point-read-handler})
|
"point" point-read-handler})
|
||||||
|
@ -62,6 +77,7 @@
|
||||||
(def ^:privare +write-handlers+
|
(def ^:privare +write-handlers+
|
||||||
{gmt/Matrix matrix-write-handler
|
{gmt/Matrix matrix-write-handler
|
||||||
Blob blob-write-handler
|
Blob blob-write-handler
|
||||||
|
lks/LinkedSet ordered-set-write-handler
|
||||||
gpt/Point point-write-handler})
|
gpt/Point point-write-handler})
|
||||||
|
|
||||||
;; --- Public Api
|
;; --- Public Api
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
(:require
|
(:require
|
||||||
[cljs.spec.alpha :as s]
|
[cljs.spec.alpha :as s]
|
||||||
[okulary.core :as l]
|
[okulary.core :as l]
|
||||||
|
[uxbox.common.data :as d]
|
||||||
[uxbox.common.exceptions :as ex]
|
[uxbox.common.exceptions :as ex]
|
||||||
[uxbox.common.geom.shapes :as geom]
|
[uxbox.common.geom.shapes :as geom]
|
||||||
[uxbox.common.pages :as cp]
|
[uxbox.common.pages :as cp]
|
||||||
|
@ -57,7 +58,8 @@
|
||||||
(= frame-id (:frame-id shape)))
|
(= frame-id (:frame-id shape)))
|
||||||
(geom/overlaps? shape rect)))]
|
(geom/overlaps? shape rect)))]
|
||||||
|
|
||||||
(into #{} (comp (map #(unchecked-get % "data"))
|
(into (d/ordered-set)
|
||||||
|
(comp (map #(unchecked-get % "data"))
|
||||||
(filter matches?)
|
(filter matches?)
|
||||||
(map :id))
|
(map :id))
|
||||||
result))))
|
result))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue