🐛 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)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 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"

View File

@@ -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}]

View File

@@ -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?))]

View File

@@ -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)))))]

View File

@@ -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

View File

@@ -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)))))))))}))))))