mirror of
https://github.com/penpot/penpot.git
synced 2025-08-03 03:18:29 +02:00
🎉 Enable auto-flows
This commit is contained in:
parent
925058467f
commit
38952b6734
6 changed files with 122 additions and 42 deletions
|
@ -9,6 +9,7 @@
|
|||
[app.common.data :as d]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.spec :as us]
|
||||
[app.common.types.interactions :as cti]
|
||||
[app.common.uuid :as uuid]
|
||||
[cuerdas.core :as str]))
|
||||
|
||||
|
@ -476,3 +477,10 @@
|
|||
(let [path-split (split-path path)]
|
||||
(merge-path-item (first path-split) name)))
|
||||
|
||||
(defn connected-frame?
|
||||
"Check if some frame is origin or destination of any navigate interaction
|
||||
in the page"
|
||||
[frame-id objects]
|
||||
(let [children (get-object-with-children frame-id objects)]
|
||||
(or (some cti/flow-origin? (map :interactions children))
|
||||
(some #(cti/flow-to? % frame-id) (map :interactions (vals objects))))))
|
||||
|
|
|
@ -326,7 +326,35 @@
|
|||
|
||||
;; -- Helpers for interactions
|
||||
|
||||
(defn add-interaction
|
||||
[interactions interaction]
|
||||
(conj (or interactions []) interaction))
|
||||
|
||||
(defn remove-interaction
|
||||
[interactions index]
|
||||
(let [interactions (or interactions [])]
|
||||
(into (subvec interactions 0 index)
|
||||
(subvec interactions (inc index)))))
|
||||
|
||||
(defn update-interaction
|
||||
[interactions index update-fn]
|
||||
(update interactions index update-fn))
|
||||
|
||||
(defn actionable?
|
||||
"Check if there is any interaction that is clickable by the user"
|
||||
[interactions]
|
||||
(some #(= (:event-type %) :click) interactions))
|
||||
|
||||
(defn flow-origin?
|
||||
"Check if there is any interaction of type :navigate that goes outside"
|
||||
[interactions]
|
||||
(some #(and (= (:action-type %) :navigate)
|
||||
(some? (:destination %)))
|
||||
interactions))
|
||||
|
||||
(defn flow-to?
|
||||
"Check if there is any interaction of type :navigate that goes to the given frame"
|
||||
[interactions frame-id]
|
||||
(some #(and (= (:action-type %) :navigate)
|
||||
(= (:destination %) frame-id))
|
||||
interactions))
|
||||
|
|
|
@ -77,11 +77,11 @@
|
|||
|
||||
(defn add-flow
|
||||
[flows flow]
|
||||
(conj flows flow))
|
||||
(conj (or flows []) flow))
|
||||
|
||||
(defn remove-flow
|
||||
[flows flow-id]
|
||||
(vec (remove #(= (:id %) flow-id) flows)))
|
||||
(d/removev #(= (:id %) flow-id) flows))
|
||||
|
||||
(defn update-flow
|
||||
[flows flow-id update-fn]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue