Compare commits

..

1 Commits

Author SHA1 Message Date
Eva Marco
3330449e31 🐛 Fix shadow token reference validation 2026-01-20 09:43:59 +01:00
8 changed files with 41 additions and 62 deletions

View File

@@ -17,12 +17,14 @@
(defn generate-path-changes
"Generates changes to update the new content of the shape"
[it objects page-id shape-id old-content new-content]
[it objects page-id shape old-content new-content]
(assert (path/content? old-content))
(assert (path/content? new-content))
(let [;; We set the old values so the update-shapes works
(let [shape-id (:id shape)
;; We set the old values so the update-shapes works
objects
(update objects shape-id
(fn [shape]
@@ -80,7 +82,7 @@
shape (st/get-path state)]
(if (and (some? old-content) (some? (:id shape)))
(let [changes (generate-path-changes it objects page-id id old-content (:content shape))]
(let [changes (generate-path-changes it objects page-id shape old-content (:content shape))]
(rx/of (dch/commit-changes changes)))
(rx/empty)))))))

View File

@@ -65,45 +65,14 @@
point-change (->> (map hash-map old-points new-points) (reduce merge))]
(when (and (some? new-content) (some? shape))
(let [changes (changes/generate-path-changes it objects page-id id (:content shape) new-content)]
(let [changes (changes/generate-path-changes it objects page-id shape (:content shape) new-content)]
(if (empty? new-content)
(rx/of (dch/commit-changes changes)
(dwe/clear-edition-mode))
(rx/of (dch/commit-changes changes)
(selection/update-selection id point-change)
(selection/update-selection point-change)
(fn [state] (update-in state [:workspace-local :edit-path id] dissoc :content-modifiers :moving-nodes :moving-handler))))))))))))
(defn apply-content-modifiers2
[shape-id old-content]
(ptk/reify ::apply-content-modifiers2
ptk/WatchEvent
(watch [it state _]
(let [ ;; FIXME: hide under getter function under state
content-modifiers
(dm/get-in state [:workspace-local :edit-path shape-id :content-modifiers])]
(if (nil? content-modifiers)
(rx/of (dwe/clear-edition-mode))
(let [page-id (get state :current-page-id)
objects (dsh/lookup-page-objects state page-id)
new-content (path/apply-content-modifiers old-content content-modifiers)
point-change (->> (map hash-map
(path.segment/get-points old-content)
(path.segment/get-points new-content))
(reduce merge))
changes (changes/generate-path-changes it objects page-id shape-id old-content new-content)]
(if (empty? new-content)
(rx/of (dch/commit-changes changes)
(dwe/clear-edition-mode))
(rx/of (dch/commit-changes changes)
(selection/update-selection shape-id point-change)
(fn [state]
(update-in state [:workspace-local :edit-path shape-id]
dissoc :content-modifiers :moving-nodes :moving-handler))))))))))
(defn modify-content-point
[content {dx :x dy :y} modifiers point]
(let [point-indices (path.segment/point-indices content point) ;; [indices]
@@ -366,21 +335,22 @@
(watch [_ _ _]
(rx/of (ptk/data-event :layout/update {:ids [id]})))))
(defn- split-segments
[shape-id {:keys [from-p to-p t]}]
(defn split-segments
[{:keys [from-p to-p t]}]
(ptk/reify ::split-segments
ptk/WatchEvent
(watch [it state _]
(let [page-id (get state :current-page-id)
objects (dsh/lookup-page-objects state page-id)
shape (get objects shape-id)
old-content (get shape :content)
new-content (-> old-content
(path.segment/split-segments #{from-p to-p} t)
(path/content))
changes (changes/generate-path-changes it objects page-id shape-id old-content new-content)]
ptk/UpdateEvent
(update [_ state]
(let [id (st/get-path-id state)
content (st/get-path state :content)]
(-> state
(assoc-in [:workspace-local :edit-path id :old-content] content)
(st/set-content (-> content
(path.segment/split-segments #{from-p to-p} t)
(path/content))))))
(rx/of (dch/commit-changes changes))))))
ptk/WatchEvent
(watch [_ _ _]
(rx/of (changes/save-path-content {:preserve-move-to true})))))
(defn create-node-at-position
[event]
@@ -389,4 +359,4 @@
(watch [_ state _]
(let [id (st/get-path-id state)]
(rx/of (dwsh/update-shapes [id] path/convert-to-path)
(split-segments id event))))))
(split-segments event))))))

View File

@@ -149,11 +149,12 @@
(rx/of (clear-area-selection))))))))
(defn update-selection
[id point-change]
[point-change]
(ptk/reify ::update-selection
ptk/UpdateEvent
(update [_ state]
(let [selected-points (dm/get-in state [:workspace-local :edit-path id :selected-points] #{})
(let [id (st/get-path-id state)
selected-points (dm/get-in state [:workspace-local :edit-path id :selected-points] #{})
selected-points (into #{} (map point-change) selected-points)]
(-> state
(assoc-in [:workspace-local :edit-path id :selected-points] selected-points))))))

View File

@@ -10,7 +10,7 @@
[app.common.types.path.shape-to-path :as stp]))
(defn get-path-id
"Retrieves the currently editing shape path id"
"Retrieves the currently editing path id"
[state]
(or (dm/get-in state [:workspace-local :edition])
(dm/get-in state [:workspace-drawing :object :id])))

View File

@@ -44,7 +44,7 @@
(path/close-subpaths))
changes
(changes/generate-path-changes it objects page-id (:id shape) (:content shape) new-content)]
(changes/generate-path-changes it objects page-id shape (:content shape) new-content)]
(rx/concat
(rx/of (dwsh/update-shapes [id] path/convert-to-path)

View File

@@ -52,7 +52,8 @@
(let [form (mf/use-ctx context)
disabled? (or (and (some? form)
(or (not (:valid @form))
(seq (:external-errors @form))))
(seq (:reference-errors @form))
(seq (:extra-errors @form))))
(true? disabled))
handle-key-down-save
(mf/use-fn

View File

@@ -332,6 +332,7 @@
message (tr "workspace.tokens.resolved-value" (or resolved-value value))]
(swap! form update :errors dissoc :value)
(swap! form update :extra-errors dissoc :value)
(swap! form update :reference-errors dissoc :reference)
(if (= input-value (str resolved-value))
(reset! hint* {})
(reset! hint* {:message message :type "hint"})))))))]

View File

@@ -101,13 +101,6 @@
active-tab* (mf/use-state #(if (cft/is-reference? token) :reference :composite))
active-tab (deref active-tab*)
on-toggle-tab
(mf/use-fn
(mf/deps)
(fn [new-tab]
(let [new-tab (keyword new-tab)]
(reset! active-tab* new-tab))))
token
(mf/with-memo [token]
(or token {:type token-type}))
@@ -144,6 +137,17 @@
(fm/use-form :schema schema
:initial initial)
on-toggle-tab
(mf/use-fn
(mf/deps form)
(fn [new-tab]
(let [new-tab (keyword new-tab)]
(if (= new-tab :reference)
(swap! form assoc-in [:reference-errors :reference]
{:message "Need valid reference"})
(swap! form update :reference-errors dissoc :reference))
(reset! active-tab* new-tab))))
warning-name-change?
(not= (get-in @form [:data :name])
(:name initial))