mirror of
https://github.com/penpot/penpot.git
synced 2025-03-11 23:31:21 -05:00
commit
7d8a62664a
7 changed files with 56 additions and 103 deletions
|
@ -27,7 +27,8 @@
|
|||
[app.common.types.shape :as cts]
|
||||
[app.common.types.shape-tree :as ctst]
|
||||
[app.common.types.typographies-list :as ctyl]
|
||||
[app.common.types.typography :as ctt]))
|
||||
[app.common.types.typography :as ctt]
|
||||
[clojure.set :as set]))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; SCHEMAS
|
||||
|
@ -665,7 +666,7 @@
|
|||
(when page-id
|
||||
(let [page (ctpl/get-page file-data page-id)
|
||||
shape-and-parents (map #(ctn/get-shape page %)
|
||||
(into [id] (cph/get-parent-ids (:objects page) id)))
|
||||
(cons id (cph/get-parent-ids (:objects page) id)))
|
||||
need-sync? (fn [operation]
|
||||
; We need to trigger a sync if the shape has changed any
|
||||
; attribute that participates in components synchronization.
|
||||
|
@ -677,6 +678,34 @@
|
|||
(map :id))]
|
||||
(into #{} xform shape-and-parents))))))
|
||||
|
||||
(defmethod components-changed :mov-objects
|
||||
[file-data {:keys [page-id _component-id parent-id shapes] :as change}]
|
||||
(when page-id
|
||||
(let [page (ctpl/get-page file-data page-id)
|
||||
|
||||
xform (comp (filter :main-instance?)
|
||||
(map :id))
|
||||
|
||||
check-shape
|
||||
(fn [shape-id others]
|
||||
(let [all-parents (map (partial ctn/get-shape page)
|
||||
(concat others (cph/get-parent-ids (:objects page) shape-id)))]
|
||||
(into #{} xform all-parents)))]
|
||||
|
||||
(reduce #(set/union %1 (check-shape %2 []))
|
||||
(check-shape parent-id [parent-id])
|
||||
shapes))))
|
||||
|
||||
(defmethod components-changed :del-obj
|
||||
[file-data {:keys [id page-id _component-id] :as change}]
|
||||
(when page-id
|
||||
(let [page (ctpl/get-page file-data page-id)
|
||||
shape-and-parents (map (partial ctn/get-shape page)
|
||||
(cons id (cph/get-parent-ids (:objects page) id)))
|
||||
xform (comp (filter :main-instance?)
|
||||
(map :id))]
|
||||
(into #{} xform shape-and-parents))))
|
||||
|
||||
(defmethod components-changed :default
|
||||
[_ _]
|
||||
nil)
|
||||
|
|
|
@ -172,10 +172,6 @@
|
|||
[{:keys [redo-changes undo-changes
|
||||
origin save-undo? file-id undo-group tags stack-undo?]
|
||||
:or {save-undo? true stack-undo? false tags #{} undo-group (uuid/next)}}]
|
||||
(log/debug :msg "commit-changes"
|
||||
:js/undo-group (str undo-group)
|
||||
:js/redo-changes redo-changes
|
||||
:js/undo-changes undo-changes)
|
||||
(let [error (volatile! nil)
|
||||
page-id (:current-page-id @st/state)
|
||||
frames (changed-frames redo-changes (wsh/lookup-page-objects @st/state))]
|
||||
|
@ -195,6 +191,10 @@
|
|||
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(log/info :msg "commit-changes"
|
||||
:js/undo-group (str undo-group)
|
||||
:js/redo-changes redo-changes
|
||||
:js/undo-changes undo-changes)
|
||||
(let [current-file-id (get state :current-file-id)
|
||||
file-id (or file-id current-file-id)
|
||||
path (if (= file-id current-file-id)
|
||||
|
|
|
@ -871,7 +871,10 @@
|
|||
workspace-data-s
|
||||
(->> (rx/concat
|
||||
(rx/of nil)
|
||||
(rx/from-atom refs/workspace-data {:emit-current-value? true})))
|
||||
(rx/from-atom refs/workspace-data {:emit-current-value? true}))
|
||||
;; Need to get the file data before the change, so deleted shapes
|
||||
;; still exist, for example
|
||||
(rx/buffer 3 1))
|
||||
|
||||
change-s
|
||||
(->> stream
|
||||
|
@ -880,16 +883,17 @@
|
|||
(rx/observe-on :async))
|
||||
|
||||
check-changes
|
||||
(fn [[event data]]
|
||||
(fn [[event [old-data _mid_data _new-data]]]
|
||||
(let [{:keys [changes save-undo? undo-group]} (deref event)
|
||||
components-changed (reduce #(into %1 (ch/components-changed data %2))
|
||||
components-changed (reduce #(into %1 (ch/components-changed old-data %2))
|
||||
#{}
|
||||
changes)]
|
||||
(when (and (d/not-empty? components-changed) save-undo?)
|
||||
(log/info :msg "DETECTED COMPONENTS CHANGED"
|
||||
:ids (map str components-changed))
|
||||
:ids (map str components-changed)
|
||||
:undo-group undo-group)
|
||||
(run! st/emit!
|
||||
(map #(update-component-sync % (:id data) undo-group)
|
||||
(map #(update-component-sync % (:id old-data) undo-group)
|
||||
components-changed)))))]
|
||||
|
||||
(when components-v2
|
||||
|
|
|
@ -376,6 +376,7 @@
|
|||
(some? id)
|
||||
(d/toggle-selection id shift?))]
|
||||
|
||||
;; Take the first mouse position and start a move or a duplicate
|
||||
(when (or (d/not-empty? selected) (some? id))
|
||||
(->> ms/mouse-position
|
||||
(rx/map #(gpt/to-vec initial %))
|
||||
|
|
|
@ -8,10 +8,14 @@
|
|||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.data.macros :as dm]
|
||||
[app.common.logging :as log]
|
||||
[app.common.pages.changes :as cpc]
|
||||
[app.common.schema :as sm]
|
||||
[potok.core :as ptk]))
|
||||
|
||||
;; Change this to :info :debug or :trace to debug this module
|
||||
(log/set-level! :warn)
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Undo / Redo
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
@ -74,7 +78,9 @@
|
|||
(-> state
|
||||
(update-in [:workspace-undo :transaction :undo-changes] #(into undo-changes %))
|
||||
(update-in [:workspace-undo :transaction :redo-changes] #(into % redo-changes))
|
||||
(assoc-in [:workspace-undo :transaction :undo-group] undo-group)
|
||||
(cond->
|
||||
(nil? (get-in state [:workspace-undo :transaction :undo-group]))
|
||||
(assoc-in [:workspace-undo :transaction :undo-group] undo-group))
|
||||
(assoc-in [:workspace-undo :transaction :tags] tags)))
|
||||
|
||||
(defn append-undo
|
||||
|
@ -107,6 +113,7 @@
|
|||
(ptk/reify ::start-undo-transaction
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(log/info :msg "start-undo-transaction")
|
||||
;; We commit the old transaction before starting the new one
|
||||
(let [current-tx (get-in state [:workspace-undo :transaction])
|
||||
pending-tx (get-in state [:workspace-undo :transactions-pending])]
|
||||
|
@ -119,12 +126,14 @@
|
|||
(ptk/reify ::discard-undo-transaction
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(log/info :msg "discard-undo-transaction")
|
||||
(update state :workspace-undo dissoc :transaction :transactions-pending))))
|
||||
|
||||
(defn commit-undo-transaction [id]
|
||||
(ptk/reify ::commit-undo-transaction
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(log/info :msg "commit-undo-transaction")
|
||||
(let [state (update-in state [:workspace-undo :transactions-pending] disj id)]
|
||||
(if (empty? (get-in state [:workspace-undo :transactions-pending]))
|
||||
(-> state
|
||||
|
|
|
@ -1,89 +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) KALEIDOS INC
|
||||
|
||||
(ns app.main.ui.workspace.effects
|
||||
(:require
|
||||
[app.main.data.workspace :as dw]
|
||||
[app.main.data.workspace.selection :as dws]
|
||||
[app.main.refs :as refs]
|
||||
[app.main.store :as st]
|
||||
[app.util.dom :as dom]
|
||||
[app.util.keyboard :as kbd]
|
||||
[rumext.v2 :as mf]))
|
||||
|
||||
(defn use-pointer-enter
|
||||
[{:keys [id]}]
|
||||
(mf/use-callback
|
||||
(mf/deps id)
|
||||
(fn []
|
||||
(st/emit! (dws/change-hover-state id true)))))
|
||||
|
||||
(defn use-pointer-leave
|
||||
[{:keys [id]}]
|
||||
(mf/use-callback
|
||||
(mf/deps id)
|
||||
(fn []
|
||||
(st/emit! (dws/change-hover-state id false)))))
|
||||
|
||||
(defn use-pointer-down
|
||||
[{:keys [id type blocked]}]
|
||||
(mf/use-callback
|
||||
(mf/deps id type blocked)
|
||||
(fn [event]
|
||||
(let [selected @refs/selected-shapes
|
||||
edition @refs/selected-edition
|
||||
selected? (contains? selected id)
|
||||
drawing? @refs/selected-drawing-tool
|
||||
button (.-which (.-nativeEvent event))
|
||||
shift? (kbd/shift? event)
|
||||
|
||||
allow-click? (and (not blocked)
|
||||
(not drawing?)
|
||||
(not edition))]
|
||||
|
||||
(when (and (= button 1) allow-click?)
|
||||
(cond
|
||||
(and (= type :frame) selected?)
|
||||
(do
|
||||
(dom/prevent-default event)
|
||||
(dom/stop-propagation event)
|
||||
(st/emit! (dw/start-move-selected)))
|
||||
|
||||
(not= type :frame)
|
||||
(do
|
||||
(dom/prevent-default event)
|
||||
(dom/stop-propagation event)
|
||||
|
||||
(let [toggle-selected? (and selected? shift?)
|
||||
deselect? (and (not selected?) (seq selected) (not shift?))]
|
||||
(apply
|
||||
st/emit!
|
||||
(cond-> []
|
||||
;; Deselect shapes before doing a selection or click outside
|
||||
deselect?
|
||||
(conj (dw/deselect-all))
|
||||
|
||||
;; Shift click to add a shape to the selection
|
||||
toggle-selected?
|
||||
(conj (dw/select-shape id true))
|
||||
|
||||
;; Simple click to select
|
||||
(not selected?)
|
||||
(conj (dw/select-shape id))
|
||||
|
||||
;; Mouse down to start moving a shape
|
||||
(not= edition id)
|
||||
(conj (dw/start-move-selected))))))))))))
|
||||
|
||||
(defn use-double-click
|
||||
"This effect will consume the event and stop the propagation so double clicks on shapes
|
||||
will not select the frame"
|
||||
[{:keys [id]}]
|
||||
(mf/use-callback
|
||||
(mf/deps id)
|
||||
(fn [event]
|
||||
(dom/stop-propagation event)
|
||||
(dom/prevent-default event))))
|
|
@ -49,8 +49,7 @@
|
|||
(dom/prevent-default event)
|
||||
(dom/stop-propagation event)
|
||||
(when-not workspace-read-only?
|
||||
(st/emit! (dw/start-rename-page-item id))
|
||||
(st/emit! (dw/hide-context-menu)))))
|
||||
(st/emit! (dw/start-rename-page-item id)))))
|
||||
|
||||
on-blur
|
||||
(mf/use-callback
|
||||
|
|
Loading…
Add table
Reference in a new issue