diff --git a/common/src/app/common/types/path.cljc b/common/src/app/common/types/path.cljc index 8f6d2c7b5a..c33d80095b 100644 --- a/common/src/app/common/types/path.cljc +++ b/common/src/app/common/types/path.cljc @@ -34,7 +34,7 @@ (def schema:segments impl/schema:segments) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; TRANSFORMATIONS +;; CONSTRUCTORS & TYPE METHODS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defn content? @@ -55,6 +55,10 @@ [data] (impl/from-string data)) +(defn from-plain + [data] + (impl/from-plain data)) + (defn check-content [content] (impl/check-content content)) @@ -189,6 +193,12 @@ [content] (some-> content segment/get-points)) +(defn calc-selrect + "Calculate selrect from a content. The content can be in a PathData + instance or plain vector of segments." + [content] + (segment/content->selrect content)) + (defn- calc-bool-content* "Calculate the boolean content from shape and objects. Returns plain vector of segments" diff --git a/common/src/app/common/types/shape.cljc b/common/src/app/common/types/shape.cljc index d9e36f1105..0ab6b79581 100644 --- a/common/src/app/common/types/shape.cljc +++ b/common/src/app/common/types/shape.cljc @@ -22,7 +22,6 @@ [app.common.types.fills :refer [schema:fill fill->color]] [app.common.types.grid :as ctg] [app.common.types.path :as path] - [app.common.types.path.segment :as path.segment] [app.common.types.plugins :as ctpg] [app.common.types.shape.attrs :refer [default-color]] [app.common.types.shape.blur :as ctsb] @@ -588,12 +587,16 @@ (defn setup-path [{:keys [content selrect points] :as shape}] (let [selrect (or selrect - (path.segment/content->selrect content) + (path/calc-selrect content) (grc/make-rect)) - points (or points (grc/rect->points selrect))] + points (or points + (grc/rect->points selrect)) + ;; Ensure we hace correct type here for Path Data + content (path/content content)] (-> shape (assoc :selrect selrect) - (assoc :points points)))) + (assoc :points points) + (assoc :content content)))) (defn- setup-image [{:keys [metadata] :as shape}] diff --git a/frontend/src/app/main/data/workspace/drawing/common.cljs b/frontend/src/app/main/data/workspace/drawing/common.cljs index 77dd595852..70f826e593 100644 --- a/frontend/src/app/main/data/workspace/drawing/common.cljs +++ b/frontend/src/app/main/data/workspace/drawing/common.cljs @@ -9,7 +9,6 @@ [app.common.files.helpers :as cfh] [app.common.geom.shapes :as gsh] [app.common.types.modifiers :as ctm] - [app.common.types.path :as path] [app.common.types.shape :as cts] [app.main.data.helpers :as dsh] [app.main.data.workspace.shapes :as dwsh] @@ -72,10 +71,6 @@ (-> (assoc :height 17 :width 4 :grow-type :auto-width) (cts/setup-shape)) - (or (cfh/path-shape? shape) - (cfh/bool-shape? shape)) - (update :content path/content) - :always (dissoc :initialized? :click-draw?))] diff --git a/frontend/src/app/main/data/workspace/modifiers.cljs b/frontend/src/app/main/data/workspace/modifiers.cljs index 74b0ea8c7d..23b751c72e 100644 --- a/frontend/src/app/main/data/workspace/modifiers.cljs +++ b/frontend/src/app/main/data/workspace/modifiers.cljs @@ -19,7 +19,6 @@ [app.common.types.component :as ctk] [app.common.types.container :as ctn] [app.common.types.modifiers :as ctm] - [app.common.types.path :as path] [app.common.types.shape :as shape] [app.common.types.shape-tree :as ctst] [app.common.types.shape.attrs :refer [editable-attrs]] @@ -797,13 +796,11 @@ text-shape? (cfh/text-shape? shape) pos-data (when ^boolean text-shape? (dm/get-in text-modifiers [shape-id :position-data]))] + (-> shape (gsh/transform-shape modifiers) (cond-> (d/not-empty? pos-data) (assoc-position-data pos-data shape)) - (cond-> (or (cfh/path-shape? shape) - (cfh/bool-shape? shape)) - (update :content path/content)) (cond-> text-shape? (update-grow-type shape)))))] diff --git a/frontend/src/app/main/data/workspace/path/drawing.cljs b/frontend/src/app/main/data/workspace/path/drawing.cljs index fecee394ce..85ae357533 100644 --- a/frontend/src/app/main/data/workspace/path/drawing.cljs +++ b/frontend/src/app/main/data/workspace/path/drawing.cljs @@ -326,7 +326,7 @@ (ptk/reify ::handle-new-shape ptk/UpdateEvent (update [_ state] - (let [shape (cts/setup-shape {:type :path :content (path/content nil)})] + (let [shape (cts/setup-shape {:type :path})] (update state :workspace-drawing assoc :object shape))) ptk/WatchEvent diff --git a/frontend/src/app/plugins/shape.cljs b/frontend/src/app/plugins/shape.cljs index a12ce086b9..73384ea344 100644 --- a/frontend/src/app/plugins/shape.cljs +++ b/frontend/src/app/plugins/shape.cljs @@ -22,7 +22,6 @@ [app.common.types.fills :as types.fills] [app.common.types.grid :as ctg] [app.common.types.path :as path] - [app.common.types.path.segment :as path.segm] [app.common.types.shape :as cts] [app.common.types.shape.blur :as ctsb] [app.common.types.shape.export :as ctse] @@ -1345,22 +1344,29 @@ (cond-> (or (cfh/path-shape? data) (cfh/bool-shape? data)) (crc/add-properties! {:name "content" - :get #(-> % u/proxy->shape :content .toString) + :get #(-> % u/proxy->shape :content str) :set (fn [_ value] - (let [content (svg.path/parse value)] + (let [segments (if (string? value) + (svg.path/parse value) + value)] (cond - (not (cfh/path-shape? data)) - (u/display-not-valid :content-type type) - - ;; FIXME: revisit path content validation - (not (sm/validate ::path/content content)) - (u/display-not-valid :content value) - (not (r/check-permission plugin-id "content:write")) (u/display-not-valid :content "Plugin doesn't have 'content:write' permission") + (not (cfh/path-shape? data)) + (u/display-not-valid :content-type type) + + (not (sm/validate path/schema:segments segments)) + (u/display-not-valid :content segments) + :else - (let [selrect (path.segm/content->selrect content) - points (grc/rect->points selrect)] - (st/emit! (dwsh/update-shapes [id] (fn [shape] (assoc shape :content content :selrect selrect :points points))))))))})))))) + (let [selrect (path/calc-selrect segments) + content (path/from-plain segments) + points (grc/rect->points selrect)] + (st/emit! (dwsh/update-shapes [id] + (fn [shape] + (-> shape + (assoc :content content) + (assoc :selrect selrect) + (assoc :points points)))))))))}))))))