Merge branch 'main' into develop

This commit is contained in:
Andrey Antukh 2021-07-15 15:17:36 +02:00
commit 9ddcb036cf
8 changed files with 50 additions and 34 deletions

View file

@ -64,16 +64,21 @@
(comp (comp
(map :objects) (map :objects)
(mapcat vals) (mapcat vals)
(filter #(= :image (:type %))) (map (fn [{:keys [type] :as obj}]
(map :metadata) (case type
(map :id))) :path (get-in obj [:fill-image :id])
:image (get-in obj [:metadata :id])
nil)))
(filter uuid?)))
(defn- collect-used-media (defn- collect-used-media
[data] [data]
(let [pages (concat
(vals (:pages-index data))
(vals (:components data)))]
(-> #{} (-> #{}
(into collect-media-xf (vals (:pages-index data))) (into collect-media-xf pages)
(into collect-media-xf (vals (:components data))) (into (keys (:media data))))))
(into (keys (:media data)))))
(defn- process-file (defn- process-file
[{:keys [conn] :as cfg} {:keys [id data age] :as file}] [{:keys [conn] :as cfg} {:keys [id data age] :as file}]

View file

@ -293,23 +293,24 @@
(defmethod process-change :add-page (defmethod process-change :add-page
[data {:keys [id name page]}] [data {:keys [id name page]}]
(cond (when (and id name page)
(and (string? name) (uuid? id)) (ex/raise :type :conflict
:hint "name or page should be provided, never both"))
(letfn [(conj-if-not-exists [pages id]
(cond-> pages
(not (d/seek #(= % id) pages))
(conj id)))]
(if (and (string? name) (uuid? id))
(let [page (assoc init/empty-page-data (let [page (assoc init/empty-page-data
:id id :id id
:name name)] :name name)]
(-> data (-> data
(update :pages conj id) (update :pages conj-if-not-exists id)
(update :pages-index assoc id page))) (update :pages-index assoc id page)))
(map? page)
(-> data (-> data
(update :pages conj (:id page)) (update :pages conj-if-not-exists (:id page))
(update :pages-index assoc (:id page) page)) (update :pages-index assoc (:id page) page)))))
:else
(ex/raise :type :conflict
:hint "name or page should be provided, never both")))
(defmethod process-change :mod-page (defmethod process-change :mod-page
[data {:keys [id name]}] [data {:keys [id name]}]

View file

@ -99,7 +99,8 @@
;; Implemented with transient for performance ;; Implemented with transient for performance
(defn get-children (defn get-children
"Retrieve all children ids recursively for a given object" "Retrieve all children ids recursively for a given object. The
children's order will be breadth first."
[id objects] [id objects]
(loop [result (transient []) (loop [result (transient [])

View file

@ -141,6 +141,11 @@
(try (try
(us/assert ::spec/changes redo-changes) (us/assert ::spec/changes redo-changes)
(us/assert ::spec/changes undo-changes) (us/assert ::spec/changes undo-changes)
;; (prn "====== commit-changes ======" path)
;; (cljs.pprint/pprint redo-changes)
;; (cljs.pprint/pprint undo-changes)
(update-in state path cp/process-changes redo-changes false) (update-in state path cp/process-changes redo-changes false)
(catch :default e (catch :default e

View file

@ -350,6 +350,8 @@
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
ids (cp/clean-loops objects ids)
groups-to-unmask groups-to-unmask
(reduce (fn [group-ids id] (reduce (fn [group-ids id]
;; When the shape to delete is the mask of a masked group, ;; When the shape to delete is the mask of a masked group,
@ -387,10 +389,12 @@
ids) ids)
all-children all-children
(->> ids
(reduce (fn [res id] (reduce (fn [res id]
(into res (cp/get-children id objects))) (into res (cp/get-children id objects)))
(d/ordered-set) [])
ids) (reverse)
(into (d/ordered-set)))
empty-parents empty-parents
(into (d/ordered-set) empty-parents-xform all-parents) (into (d/ordered-set) empty-parents-xform all-parents)

View file

@ -6,7 +6,6 @@
(ns app.main.data.workspace.undo (ns app.main.data.workspace.undo
(:require (:require
[app.common.pages :as cp]
[app.common.pages.spec :as spec] [app.common.pages.spec :as spec]
[app.common.spec :as us] [app.common.spec :as us]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
@ -31,13 +30,13 @@
(subvec undo (- cnt MAX-UNDO-SIZE)) (subvec undo (- cnt MAX-UNDO-SIZE))
undo))) undo)))
;; TODO: Review the necessity of this method
(defn materialize-undo (defn materialize-undo
[changes index] [_changes index]
(ptk/reify ::materialize-undo (ptk/reify ::materialize-undo
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(-> state (-> state
(update :workspace-data cp/process-changes changes)
(assoc-in [:workspace-undo :index] index))))) (assoc-in [:workspace-undo :index] index)))))
(defn- add-undo-entry (defn- add-undo-entry

View file

@ -139,8 +139,8 @@
(d/without-keys dissoc-attrs) (d/without-keys dissoc-attrs)
(assoc :type :path) (assoc :type :path)
(assoc :content new-content) (assoc :content new-content)
(cond-> (= :image type) (cond-> (= :image type) (-> (assoc :fill-image metadata)
(assoc :fill-image metadata)))) (dissoc :metadata)))))
;; Do nothing if the shape is not of a correct type ;; Do nothing if the shape is not of a correct type
shape)) shape))

View file

@ -488,8 +488,9 @@
filter-values))) filter-values)))
(defn extract-ids [val] (defn extract-ids [val]
(when (some? val)
(->> (re-seq xml-id-regex val) (->> (re-seq xml-id-regex val)
(mapv second))) (mapv second))))
(defn fix-dot-number (defn fix-dot-number
"Fixes decimal numbers starting in dot but without leading 0" "Fixes decimal numbers starting in dot but without leading 0"