🐛 Fix incorrect path data content initialization on pluings api

This commit is contained in:
Andrey Antukh 2025-09-15 10:11:49 +02:00 committed by Alonso Torres
parent 5ed870cc6e
commit 9f37175775
6 changed files with 39 additions and 28 deletions

View File

@ -34,7 +34,7 @@
(def schema:segments impl/schema:segments) (def schema:segments impl/schema:segments)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; TRANSFORMATIONS ;; CONSTRUCTORS & TYPE METHODS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn content? (defn content?
@ -55,6 +55,10 @@
[data] [data]
(impl/from-string data)) (impl/from-string data))
(defn from-plain
[data]
(impl/from-plain data))
(defn check-content (defn check-content
[content] [content]
(impl/check-content content)) (impl/check-content content))
@ -189,6 +193,12 @@
[content] [content]
(some-> content segment/get-points)) (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* (defn- calc-bool-content*
"Calculate the boolean content from shape and objects. Returns plain "Calculate the boolean content from shape and objects. Returns plain
vector of segments" vector of segments"

View File

@ -22,7 +22,6 @@
[app.common.types.fills :refer [schema:fill fill->color]] [app.common.types.fills :refer [schema:fill fill->color]]
[app.common.types.grid :as ctg] [app.common.types.grid :as ctg]
[app.common.types.path :as path] [app.common.types.path :as path]
[app.common.types.path.segment :as path.segment]
[app.common.types.plugins :as ctpg] [app.common.types.plugins :as ctpg]
[app.common.types.shape.attrs :refer [default-color]] [app.common.types.shape.attrs :refer [default-color]]
[app.common.types.shape.blur :as ctsb] [app.common.types.shape.blur :as ctsb]
@ -588,12 +587,16 @@
(defn setup-path (defn setup-path
[{:keys [content selrect points] :as shape}] [{:keys [content selrect points] :as shape}]
(let [selrect (or selrect (let [selrect (or selrect
(path.segment/content->selrect content) (path/calc-selrect content)
(grc/make-rect)) (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 (-> shape
(assoc :selrect selrect) (assoc :selrect selrect)
(assoc :points points)))) (assoc :points points)
(assoc :content content))))
(defn- setup-image (defn- setup-image
[{:keys [metadata] :as shape}] [{:keys [metadata] :as shape}]

View File

@ -9,7 +9,6 @@
[app.common.files.helpers :as cfh] [app.common.files.helpers :as cfh]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.types.modifiers :as ctm] [app.common.types.modifiers :as ctm]
[app.common.types.path :as path]
[app.common.types.shape :as cts] [app.common.types.shape :as cts]
[app.main.data.helpers :as dsh] [app.main.data.helpers :as dsh]
[app.main.data.workspace.shapes :as dwsh] [app.main.data.workspace.shapes :as dwsh]
@ -72,10 +71,6 @@
(-> (assoc :height 17 :width 4 :grow-type :auto-width) (-> (assoc :height 17 :width 4 :grow-type :auto-width)
(cts/setup-shape)) (cts/setup-shape))
(or (cfh/path-shape? shape)
(cfh/bool-shape? shape))
(update :content path/content)
:always :always
(dissoc :initialized? :click-draw?))] (dissoc :initialized? :click-draw?))]

View File

@ -19,7 +19,6 @@
[app.common.types.component :as ctk] [app.common.types.component :as ctk]
[app.common.types.container :as ctn] [app.common.types.container :as ctn]
[app.common.types.modifiers :as ctm] [app.common.types.modifiers :as ctm]
[app.common.types.path :as path]
[app.common.types.shape :as shape] [app.common.types.shape :as shape]
[app.common.types.shape-tree :as ctst] [app.common.types.shape-tree :as ctst]
[app.common.types.shape.attrs :refer [editable-attrs]] [app.common.types.shape.attrs :refer [editable-attrs]]
@ -797,13 +796,11 @@
text-shape? (cfh/text-shape? shape) text-shape? (cfh/text-shape? shape)
pos-data (when ^boolean text-shape? pos-data (when ^boolean text-shape?
(dm/get-in text-modifiers [shape-id :position-data]))] (dm/get-in text-modifiers [shape-id :position-data]))]
(-> shape (-> shape
(gsh/transform-shape modifiers) (gsh/transform-shape modifiers)
(cond-> (d/not-empty? pos-data) (cond-> (d/not-empty? pos-data)
(assoc-position-data pos-data shape)) (assoc-position-data pos-data shape))
(cond-> (or (cfh/path-shape? shape)
(cfh/bool-shape? shape))
(update :content path/content))
(cond-> text-shape? (cond-> text-shape?
(update-grow-type shape)))))] (update-grow-type shape)))))]

View File

@ -326,7 +326,7 @@
(ptk/reify ::handle-new-shape (ptk/reify ::handle-new-shape
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (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))) (update state :workspace-drawing assoc :object shape)))
ptk/WatchEvent ptk/WatchEvent

View File

@ -22,7 +22,6 @@
[app.common.types.fills :as types.fills] [app.common.types.fills :as types.fills]
[app.common.types.grid :as ctg] [app.common.types.grid :as ctg]
[app.common.types.path :as path] [app.common.types.path :as path]
[app.common.types.path.segment :as path.segm]
[app.common.types.shape :as cts] [app.common.types.shape :as cts]
[app.common.types.shape.blur :as ctsb] [app.common.types.shape.blur :as ctsb]
[app.common.types.shape.export :as ctse] [app.common.types.shape.export :as ctse]
@ -1345,22 +1344,29 @@
(cond-> (or (cfh/path-shape? data) (cfh/bool-shape? data)) (cond-> (or (cfh/path-shape? data) (cfh/bool-shape? data))
(crc/add-properties! (crc/add-properties!
{:name "content" {:name "content"
:get #(-> % u/proxy->shape :content .toString) :get #(-> % u/proxy->shape :content str)
:set :set
(fn [_ value] (fn [_ value]
(let [content (svg.path/parse value)] (let [segments (if (string? value)
(svg.path/parse value)
value)]
(cond (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")) (not (r/check-permission plugin-id "content:write"))
(u/display-not-valid :content "Plugin doesn't have 'content:write' permission") (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 :else
(let [selrect (path.segm/content->selrect content) (let [selrect (path/calc-selrect segments)
points (grc/rect->points selrect)] content (path/from-plain segments)
(st/emit! (dwsh/update-shapes [id] (fn [shape] (assoc shape :content content :selrect selrect :points points))))))))})))))) points (grc/rect->points selrect)]
(st/emit! (dwsh/update-shapes [id]
(fn [shape]
(-> shape
(assoc :content content)
(assoc :selrect selrect)
(assoc :points points)))))))))}))))))