Merge branch 'staging' into develop

This commit is contained in:
Andrey Antukh 2023-02-20 13:29:03 +01:00
commit 788dc9b3f8
30 changed files with 255 additions and 93 deletions

View file

@ -34,6 +34,23 @@
(declare commit-changes)
(defn- add-group-id
[changes state]
(let [undo (:workspace-undo state)
items (:items undo)
index (or (:index undo) (dec (count items)))
prev-item (when-not (or (empty? items) (= index -1))
(get items index))
group-id (:group-id prev-item)
add-group-id? (and
(not (nil? group-id))
(= (get-in changes [:redo-changes 0 :type]) :mod-obj)
(= (get-in prev-item [:redo-changes 0 :type]) :add-obj)) ;; This is a copy-and-move with mouse+alt
]
(cond-> changes add-group-id? (assoc :group-id group-id))))
(def commit-changes? (ptk/type? ::commit-changes))
(defn update-shapes
@ -64,7 +81,8 @@
(-> (pcb/empty-changes it page-id)
(pcb/set-save-undo? save-undo?)
(pcb/with-objects objects))
ids)]
ids)
changes (add-group-id changes state)]
(rx/concat
(if (seq (:redo-changes changes))
(let [changes (cond-> changes reg-objects? (pcb/resize-parents ids))]
@ -147,7 +165,7 @@
(defn commit-changes
[{:keys [redo-changes undo-changes
origin save-undo? file-id]
origin save-undo? file-id group-id]
:or {save-undo? true}}]
(log/debug :msg "commit-changes"
:js/redo-changes redo-changes
@ -164,7 +182,8 @@
:changes redo-changes
:page-id page-id
:frames frames
:save-undo? save-undo?})
:save-undo? save-undo?
:group-id group-id})
ptk/UpdateEvent
(update [_ state]
@ -212,5 +231,6 @@
(when (and save-undo? (seq undo-changes))
(let [entry {:undo-changes undo-changes
:redo-changes redo-changes}]
:redo-changes redo-changes
:group-id group-id}]
(rx/of (dwu/append-undo entry)))))))))))

View file

@ -27,6 +27,7 @@
(defn interrupt? [e] (= e :interrupt))
(declare undo-to-index)
(defn- assure-valid-current-page
[]
@ -60,13 +61,25 @@
items (:items undo)
index (or (:index undo) (dec (count items)))]
(when-not (or (empty? items) (= index -1))
(let [changes (get-in items [index :undo-changes])]
(rx/of (dwu/materialize-undo changes (dec index))
(dch/commit-changes {:redo-changes changes
:undo-changes []
:save-undo? false
:origin it})
(assure-valid-current-page))))))))))
(let [item (get items index)
changes (:undo-changes item)
group-id (:group-id item)
find-first-group-idx (fn ffgidx[index]
(let [item (get items index)]
(if (= (:group-id item) group-id)
(ffgidx (dec index))
(inc index))))
undo-group-index (when group-id
(find-first-group-idx index))]
(if group-id
(rx/of (undo-to-index (dec undo-group-index)))
(rx/of (dwu/materialize-undo changes (dec index))
(dch/commit-changes {:redo-changes changes
:undo-changes []
:save-undo? false
:origin it})
(assure-valid-current-page)))))))))))
(def redo
(ptk/reify ::redo
@ -79,12 +92,24 @@
items (:items undo)
index (or (:index undo) (dec (count items)))]
(when-not (or (empty? items) (= index (dec (count items))))
(let [changes (get-in items [(inc index) :redo-changes])]
(rx/of (dwu/materialize-undo changes (inc index))
(dch/commit-changes {:redo-changes changes
:undo-changes []
:origin it
:save-undo? false}))))))))))
(let [item (get items (inc index))
changes (:redo-changes item)
group-id (:group-id item)
find-last-group-idx (fn flgidx [index]
(let [item (get items index)]
(if (= (:group-id item) group-id)
(flgidx (inc index))
(dec index))))
redo-group-index (when group-id
(find-last-group-idx (inc index)))]
(if group-id
(rx/of (undo-to-index redo-group-index))
(rx/of (dwu/materialize-undo changes (inc index))
(dch/commit-changes {:redo-changes changes
:undo-changes []
:origin it
:save-undo? false})))))))))))
(defn undo-to-index
"Repeat undoing or redoing until dest-index is reached."
@ -99,7 +124,7 @@
items (:items undo)
index (or (:index undo) (dec (count items)))]
(when (and (some? items)
(<= 0 dest-index (dec (count items))))
(<= -1 dest-index (dec (count items))))
(let [changes (vec (apply concat
(cond
(< dest-index index)

View file

@ -485,7 +485,10 @@
(gpt/subtract new-pos pt-obj)))))
(defn duplicate-selected [move-delta?]
(defn duplicate-selected
([move-delta?]
(duplicate-selected move-delta? false))
([move-delta? add-group-id?]
(ptk/reify ::duplicate-selected
ptk/WatchEvent
(watch [it state _]
@ -502,6 +505,8 @@
changes (->> (prepare-duplicate-changes objects page selected delta it)
(duplicate-changes-update-indices objects selected))
changes (cond-> changes add-group-id? (assoc :group-id (uuid/random)))
id-original (first selected)
new-selected (->> changes
@ -525,7 +530,7 @@
(select-shapes new-selected)
(ptk/data-event :layout/update frames)
(memorize-duplicated id-original id-duplicated)
(dwu/commit-undo-transaction undo-id)))))))))
(dwu/commit-undo-transaction undo-id))))))))))
(defn change-hover-state
[id value]

View file

@ -77,7 +77,7 @@
([attrs]
(add-shape attrs {}))
([attrs {:keys [no-select?]}]
([attrs {:keys [no-select? no-update-layout?]}]
(us/verify ::shape-attrs attrs)
(ptk/reify ::add-shape
ptk/WatchEvent
@ -108,7 +108,8 @@
(rx/concat
(rx/of (dwu/start-undo-transaction undo-id)
(dch/commit-changes changes)
(ptk/data-event :layout/update [(:parent-id shape)])
(when-not no-update-layout?
(ptk/data-event :layout/update [(:parent-id shape)]))
(when-not no-select?
(dws/select-shapes (d/ordered-set id)))
(dwu/commit-undo-transaction undo-id))
@ -387,8 +388,9 @@
undo-id (js/Symbol)]
(rx/of
(dwu/start-undo-transaction undo-id)
(add-shape shape)
(add-shape shape {:no-update-layout? true})
(move-shapes-into-frame (:id shape) selected)
(ptk/data-event :layout/update [(:id shape)])
(dwu/commit-undo-transaction undo-id)))))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -453,4 +455,3 @@
(map (fn [[page-id frame-ids]]
(dch/update-shapes frame-ids #(dissoc % :use-for-thumbnail?) {:page-id page-id})))))
(rx/of (dch/update-shapes selected #(update % :use-for-thumbnail? not))))))))

View file

@ -382,7 +382,7 @@
(if alt?
;; When alt is down we start a duplicate+move
(rx/of (start-move-duplicate initial)
(dws/duplicate-selected false))
(dws/duplicate-selected false true))
;; Otherwise just plain old move
(rx/of (start-move initial selected))))))

View file

@ -55,10 +55,11 @@
state))
(defn- accumulate-undo-entry
[state {:keys [undo-changes redo-changes]}]
[state {:keys [undo-changes redo-changes group-id]}]
(-> state
(update-in [:workspace-undo :transaction :undo-changes] #(into undo-changes %))
(update-in [:workspace-undo :transaction :redo-changes] #(into % redo-changes))))
(update-in [:workspace-undo :transaction :redo-changes] #(into % redo-changes))
(assoc-in [:workspace-undo :transaction :group-id] group-id)))
(defn append-undo
[entry]

View file

@ -15,11 +15,13 @@
(def actions (icon-xref :actions))
(def align-bottom (icon-xref :align-bottom))
(def align-content-column-around (icon-xref :align-content-column-around))
(def align-content-column-evenly (icon-xref :align-content-column-evenly))
(def align-content-column-between (icon-xref :align-content-column-between))
(def align-content-column-center (icon-xref :align-content-column-center))
(def align-content-column-end (icon-xref :align-content-column-end))
(def align-content-column-start (icon-xref :align-content-column-start))
(def align-content-row-around (icon-xref :align-content-row-around))
(def align-content-row-evenly (icon-xref :align-content-row-evenly))
(def align-content-row-between (icon-xref :align-content-row-between))
(def align-content-row-center (icon-xref :align-content-row-center))
(def align-content-row-end (icon-xref :align-content-row-end))
@ -126,11 +128,13 @@
(def infocard (icon-xref :infocard))
(def interaction (icon-xref :interaction))
(def justify-content-column-around (icon-xref :justify-content-column-around))
(def justify-content-column-evenly (icon-xref :justify-content-column-evenly))
(def justify-content-column-between (icon-xref :justify-content-column-between))
(def justify-content-column-center (icon-xref :justify-content-column-center))
(def justify-content-column-end (icon-xref :justify-content-column-end))
(def justify-content-column-start (icon-xref :justify-content-column-start))
(def justify-content-row-around (icon-xref :justify-content-row-around))
(def justify-content-row-evenly (icon-xref :justify-content-row-evenly))
(def justify-content-row-between (icon-xref :justify-content-row-between))
(def justify-content-row-center (icon-xref :justify-content-row-center))
(def justify-content-row-end (icon-xref :justify-content-row-end))

View file

@ -36,7 +36,7 @@
(next))]
[:div.modal-container.onboarding.onboarding-v2
[:div.modal-left.welcome
[:img {:src "images/onboarding-welcome.jpg" :border "0" :alt (tr "onboarding.welcome.alt")}]]
[:img {:src "images/onboarding-welcome.png" :border "0" :alt (tr "onboarding.welcome.alt")}]]
[:div.modal-right
[:div.release-container [:span.release "Version " (:main @cf/version)]]
[:div.right-content
@ -71,7 +71,7 @@
(next))]
[:div.modal-container.onboarding.onboarding-v2
[:div.modal-left.welcome
[:img {:src "images/onboarding-people.jpg" :border "0" :alt (tr "onboarding.welcome.alt")}]]
[:img {:src "images/onboarding-people.png" :border "0" :alt (tr "onboarding.welcome.alt")}]]
[:div.modal-right
[:div.release-container [:span.release "Version " (:main @cf/version)]]
[:div.right-content

View file

@ -124,11 +124,10 @@
(mf/fnc frame-shape
{::mf/wrap-props false}
[props]
(let [childs (unchecked-get props "childs")]
(let [shape (unchecked-get props "shape")
childs (unchecked-get props "childs")]
[:> frame-container props
[:g.frame-children
[:g.frame-children {:opacity (:opacity shape)}
(for [item childs]
[:& shape-wrapper {:key (dm/str (:id item)) :shape item}]
)]])))
[:& shape-wrapper {:key (dm/str (:id item)) :shape item}])]])))

View file

@ -21,8 +21,8 @@
:layout-gap-type ;; :simple, :multiple
:layout-gap ;; {:row-gap number , :column-gap number}
:layout-align-items ;; :start :end :center :stretch
:layout-justify-content ;; :start :center :end :space-between :space-around
:layout-align-content ;; :start :center :end :space-between :space-around :stretch (by default)
:layout-justify-content ;; :start :center :end :space-between :space-around :space-evenly
:layout-align-content ;; :start :center :end :space-between :space-around :space-evenly :stretch (by default)
:layout-wrap-type ;; :wrap, :nowrap
:layout-padding-type ;; :simple, :multiple
:layout-padding ;; {:p1 num :p2 num :p3 num :p4 num} number could be negative
@ -50,12 +50,14 @@
:end i/justify-content-column-end
:center i/justify-content-column-center
:space-around i/justify-content-column-around
:space-evenly i/justify-content-column-evenly
:space-between i/justify-content-column-between)
(case val
:start i/justify-content-row-start
:end i/justify-content-row-end
:center i/justify-content-row-center
:space-around i/justify-content-row-around
:space-evenly i/justify-content-row-evenly
:space-between i/justify-content-row-between))
:align-content (if is-col?
@ -64,6 +66,7 @@
:end i/align-content-column-end
:center i/align-content-column-center
:space-around i/align-content-column-around
:space-evenly i/align-content-column-evenly
:space-between i/align-content-column-between
:stretch nil)
@ -72,6 +75,7 @@
:end i/align-content-row-end
:center i/align-content-row-center
:space-around i/align-content-row-around
:space-evenly i/align-content-row-evenly
:space-between i/align-content-row-between
:stretch nil))
@ -140,16 +144,27 @@
(mf/defc align-content-row
[{:keys [is-col? align-content set-align-content] :as props}]
[:div.align-content-style
(for [align [:start :center :end :space-around :space-between]]
[:button.align-content.tooltip
{:class (dom/classnames :active (= align-content align)
:tooltip-bottom-left (not= align :start)
:tooltip-bottom (= align :start))
:alt (dm/str "Align content " (d/name align))
:on-click #(set-align-content align)
:key (dm/str "align-content" (d/name align))}
(get-layout-flex-icon :align-content align is-col?)])])
[:*
[:div.align-content-style
(for [align [:start :center :end]]
[:button.align-content.tooltip
{:class (dom/classnames :active (= align-content align)
:tooltip-bottom-left (not= align :start)
:tooltip-bottom (= align :start))
:alt (dm/str "Align content " (d/name align))
:on-click #(set-align-content align)
:key (dm/str "align-content" (d/name align))}
(get-layout-flex-icon :align-content align is-col?)])]
[:div.align-content-style
(for [align [:space-between :space-around :space-evenly]]
[:button.align-content.tooltip
{:class (dom/classnames :active (= align-content align)
:tooltip-bottom-left (not= align :start)
:tooltip-bottom (= align :start))
:alt (dm/str "Align content " (d/name align))
:on-click #(set-align-content align)
:key (dm/str "align-content" (d/name align))}
(get-layout-flex-icon :align-content align is-col?)])]])
(mf/defc justify-content-row
[{:keys [is-col? justify-content set-justify] :as props}]
@ -165,7 +180,7 @@
:key (dm/str "justify-content" (d/name justify))}
(get-layout-flex-icon :justify-content justify is-col?)])]
[:div.justify-content-style
(for [justify [:space-around :space-between]]
(for [justify [:space-between :space-around :space-evenly]]
[:button.justify.tooltip
{:class (dom/classnames :active (= justify-content justify)
:tooltip-bottom-left (not= justify :space-around)
@ -399,7 +414,7 @@
(when (= :wrap wrap-type)
[:div.layout-row
[:div.align-content.row-title "Content"]
[:div.btn-wrapper
[:div.btn-wrapper.align-content
[:& align-content-row {:is-col? is-col?
:align-content align-content
:set-align-content set-align-content}]]])