mirror of
https://github.com/penpot/penpot.git
synced 2026-02-12 14:42:56 +00:00
WIP
This commit is contained in:
@@ -25,7 +25,8 @@
|
||||
(defn append
|
||||
[{index :index items :items :as stack} value]
|
||||
|
||||
(if (and (some? stack) (not= value (peek stack)))
|
||||
(if (and (some? stack)
|
||||
(not= value (peek stack)))
|
||||
(let [items (cond-> items
|
||||
(> index 0)
|
||||
(subvec 0 (inc index))
|
||||
@@ -35,7 +36,6 @@
|
||||
|
||||
:always
|
||||
(conj value))
|
||||
|
||||
index (min (dec MAX-UNDO-SIZE) (inc index))]
|
||||
{:index index
|
||||
:items items})
|
||||
|
||||
@@ -56,32 +56,32 @@
|
||||
(path/update-geometry))))
|
||||
(pcb/resize-parents [shape-id])))))
|
||||
|
||||
(defn save-path-content
|
||||
([]
|
||||
(save-path-content {}))
|
||||
([{:keys [preserve-move-to] :or {preserve-move-to false}}]
|
||||
(ptk/reify ::save-path-content
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [content (st/get-path state :content)
|
||||
content (if (and (not preserve-move-to)
|
||||
(= (-> content last :command) :move-to))
|
||||
(into [] (take (dec (count content)) content))
|
||||
content)]
|
||||
(-> state
|
||||
(st/set-content content))))
|
||||
;; (defn save-path-content
|
||||
;; ([]
|
||||
;; (save-path-content {}))
|
||||
;; ([{:keys [preserve-move-to] :or {preserve-move-to false}}]
|
||||
;; (ptk/reify ::save-path-content
|
||||
;; ptk/UpdateEvent
|
||||
;; (update [_ state]
|
||||
;; (let [content (st/get-path state :content)
|
||||
;; content (if (and (not preserve-move-to)
|
||||
;; (= (-> content last :command) :move-to))
|
||||
;; (into [] (take (dec (count content)) content))
|
||||
;; content)]
|
||||
;; (-> state
|
||||
;; (st/set-content content))))
|
||||
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
(let [page-id (:current-page-id state)
|
||||
objects (dsh/lookup-page-objects state page-id)
|
||||
id (dm/get-in state [:workspace-local :edition])
|
||||
old-content (dm/get-in state [:workspace-local :edit-path id :old-content])
|
||||
shape (st/get-path state)]
|
||||
;; ptk/WatchEvent
|
||||
;; (watch [it state _]
|
||||
;; (let [page-id (:current-page-id state)
|
||||
;; objects (dsh/lookup-page-objects state page-id)
|
||||
;; id (dm/get-in state [:workspace-local :edition])
|
||||
;; old-content (dm/get-in state [:workspace-local :edit-path id :old-content])
|
||||
;; shape (st/get-path state)]
|
||||
|
||||
(if (and (some? old-content) (some? (:id shape)))
|
||||
(let [changes (generate-path-changes it objects page-id id old-content (:content shape))]
|
||||
(rx/of (dch/commit-changes changes)))
|
||||
(rx/empty)))))))
|
||||
;; (if (and (some? old-content) (some? (:id shape)))
|
||||
;; (let [changes (generate-path-changes it objects page-id id old-content (:content shape))]
|
||||
;; (rx/of (dch/commit-changes changes)))
|
||||
;; (rx/empty)))))))
|
||||
|
||||
|
||||
|
||||
@@ -121,13 +121,15 @@
|
||||
(ptk/reify ::finish-drag
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [id (st/get-path-id state)
|
||||
(let [id (st/get-path-id state)
|
||||
|
||||
modifiers (get-in state [:workspace-local :edit-path id :content-modifiers])
|
||||
content (-> (st/get-path state :content)
|
||||
(path/apply-content-modifiers modifiers))
|
||||
content (-> (st/get-path state :content)
|
||||
(path/apply-content-modifiers modifiers))
|
||||
|
||||
handler (get-in state [:workspace-local :edit-path id :drag-handler])]
|
||||
handler (get-in state [:workspace-local :edit-path id :drag-handler])]
|
||||
|
||||
(prn "finish-drag")
|
||||
(-> state
|
||||
(st/set-content content)
|
||||
(update-in [:workspace-local :edit-path id] dissoc :drag-handler)
|
||||
@@ -424,6 +426,8 @@
|
||||
old-content (get local :old-content)
|
||||
edit-mode (get local :edit-mode)]
|
||||
|
||||
(prn "check-changed-content" old-content)
|
||||
(prn "check-changed-content" content)
|
||||
(cond
|
||||
(and (not= content old-content) (not empty-content?))
|
||||
(let [page-id (:current-page-id state)
|
||||
|
||||
@@ -298,8 +298,8 @@
|
||||
edit-path (dm/get-in state [:workspace-local :edit-path id])
|
||||
content (st/get-path state :content)
|
||||
state (cond-> state
|
||||
(cfh/path-shape? objects id)
|
||||
(st/set-content (path/close-subpaths content)))]
|
||||
#_(cfh/path-shape? objects id)
|
||||
#_(st/set-content (path/close-subpaths content)))]
|
||||
|
||||
(cond-> state
|
||||
(or (not edit-path)
|
||||
|
||||
@@ -10,7 +10,9 @@
|
||||
[app.common.data.undo-stack :as u]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.workspace.common :as dwc]
|
||||
[app.main.data.changes :as dch]
|
||||
[app.main.data.workspace.edition :as-alias dwe]
|
||||
[app.main.data.helpers :as dsh]
|
||||
[app.main.data.workspace.pages :as-alias dwpg]
|
||||
[app.main.data.workspace.path.changes :as changes]
|
||||
[app.main.data.workspace.path.common :as common]
|
||||
@@ -57,44 +59,63 @@
|
||||
(ptk/reify ::undo-path
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [id (st/get-path-id state)
|
||||
undo-stack (-> (get-in state [:workspace-local :edit-path id :undo-stack])
|
||||
(u/undo))
|
||||
entry (u/peek undo-stack)]
|
||||
(cond-> state
|
||||
(some? entry)
|
||||
(-> (load-entry entry)
|
||||
(d/assoc-in-when
|
||||
[:workspace-local :edit-path id :undo-stack]
|
||||
undo-stack)))))
|
||||
(let [id (st/get-path-id state)]
|
||||
(update-in state [:workspace-local :edit-path id :undo-stack] u/undo)))
|
||||
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [id (st/get-path-id state)
|
||||
undo-stack (get-in state [:workspace-local :edit-path id :undo-stack])]
|
||||
(if (> (:index undo-stack) 0)
|
||||
(rx/of (changes/save-path-content {:preserve-move-to true}))
|
||||
(rx/of (changes/save-path-content {:preserve-move-to true})
|
||||
(common/finish-path)
|
||||
(dwc/show-toolbar)))))))
|
||||
(watch [it state _]
|
||||
(let [id (st/get-path-id state)
|
||||
shape (st/get-path state)
|
||||
|
||||
page-id (:current-page-id state)
|
||||
objects (dsh/lookup-page-objects state page-id)
|
||||
|
||||
edition? (= (get-in state [:workspace-local :edition]) id)
|
||||
|
||||
ustack (get-in state [:workspace-local :edit-path id :undo-stack])
|
||||
entry (u/peek ustack)
|
||||
|
||||
old-content (get shape :content)
|
||||
new-content (get entry :content)
|
||||
changes (changes/generate-path-changes it objects page-id id old-content new-content)]
|
||||
|
||||
(rx/concat
|
||||
(rx/of #(load-entry % entry))
|
||||
(if edition?
|
||||
(rx/of (dch/commit-changes changes))
|
||||
(rx/empty))
|
||||
(if (zero? (:index ustack))
|
||||
(rx/of (common/finish-path)
|
||||
(dwc/show-toolbar))
|
||||
(rx/empty)))))))
|
||||
|
||||
(defn redo-path []
|
||||
(ptk/reify ::redo-path
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [id (st/get-path-id state)
|
||||
undo-stack (-> (get-in state [:workspace-local :edit-path id :undo-stack])
|
||||
(u/redo))
|
||||
entry (u/peek undo-stack)]
|
||||
(let [id (st/get-path-id state)
|
||||
ustack (-> (get-in state [:workspace-local :edit-path id :undo-stack])
|
||||
(u/redo))
|
||||
entry (u/peek ustack)]
|
||||
(-> state
|
||||
(load-entry entry)
|
||||
(d/assoc-in-when
|
||||
[:workspace-local :edit-path id :undo-stack]
|
||||
undo-stack))))
|
||||
(d/assoc-in-when [:workspace-local :edit-path id :undo-stack] ustack))))
|
||||
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
(rx/of (changes/save-path-content)))))
|
||||
(watch [it state _]
|
||||
|
||||
(let [id (st/get-path-id state)
|
||||
shape (st/get-path state)
|
||||
|
||||
page-id (:current-page-id state)
|
||||
objects (dsh/lookup-page-objects state page-id)
|
||||
|
||||
ustack (get-in state [:workspace-local :edit-path id :undo-stack])
|
||||
entry (u/peek ustack)
|
||||
old-content (get shape :content)
|
||||
new-content (get entry :content)
|
||||
changes (changes/generate-path-changes it objects page-id id old-content new-content)]
|
||||
|
||||
(rx/of (dch/commit-changes changes))))))
|
||||
|
||||
(defn merge-head
|
||||
"Joins the head with the previous undo in one. This is done so when the user changes a
|
||||
@@ -149,6 +170,7 @@
|
||||
(ptk/reify ::start-path-undo
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
|
||||
(let [undo-lock (get-in state [:workspace-local :edit-path (st/get-path-id state) :undo-lock])]
|
||||
(cond-> state
|
||||
(not undo-lock)
|
||||
|
||||
Reference in New Issue
Block a user