mirror of
https://github.com/penpot/penpot.git
synced 2025-12-12 06:24:17 +01:00
✨ Changes WASM serialization mechanism
This commit is contained in:
@@ -517,8 +517,7 @@
|
|||||||
(when verify?
|
(when verify?
|
||||||
(check-changes items))
|
(check-changes items))
|
||||||
|
|
||||||
(binding [*touched-changes* (volatile! #{})
|
(binding [*touched-changes* (volatile! #{})]
|
||||||
cts/*wasm-sync* (not cts/*wasm-sync-override*)]
|
|
||||||
(let [result (reduce #(or (process-change %1 %2) %1) data items)
|
(let [result (reduce #(or (process-change %1 %2) %1) data items)
|
||||||
result (reduce process-touched-change result @*touched-changes*)]
|
result (reduce process-touched-change result @*touched-changes*)]
|
||||||
;; Validate result shapes (only on the backend)
|
;; Validate result shapes (only on the backend)
|
||||||
|
|||||||
@@ -36,12 +36,7 @@
|
|||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[clojure.set :as set]))
|
[clojure.set :as set]))
|
||||||
|
|
||||||
(defonce ^:dynamic *wasm-sync* false)
|
(defonce ^:dynamic *shape-changes* nil)
|
||||||
|
|
||||||
;; This is a temporary workaround so the changes-builder doesn't generate updates
|
|
||||||
;; in the WASM model.
|
|
||||||
(defonce ^:dynamic *wasm-sync-override* false)
|
|
||||||
|
|
||||||
(defonce wasm-enabled? false)
|
(defonce wasm-enabled? false)
|
||||||
(defonce wasm-create-shape (constantly nil))
|
(defonce wasm-create-shape (constantly nil))
|
||||||
|
|
||||||
|
|||||||
@@ -7,14 +7,19 @@
|
|||||||
(ns app.main.data.changes
|
(ns app.main.data.changes
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
|
[app.common.data.macros :as dm]
|
||||||
[app.common.files.changes :as cpc]
|
[app.common.files.changes :as cpc]
|
||||||
[app.common.logging :as log]
|
[app.common.logging :as log]
|
||||||
[app.common.time :as ct]
|
[app.common.time :as ct]
|
||||||
|
[app.common.types.shape :as cts]
|
||||||
[app.common.types.shape-tree :as ctst]
|
[app.common.types.shape-tree :as ctst]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.main.data.event :as ev]
|
[app.main.data.event :as ev]
|
||||||
[app.main.data.helpers :as dsh]
|
[app.main.data.helpers :as dsh]
|
||||||
|
[app.main.features :as features]
|
||||||
[app.main.worker :as mw]
|
[app.main.worker :as mw]
|
||||||
|
[app.render-wasm.api :as wasm.api]
|
||||||
|
[app.render-wasm.shape :as wasm.shape]
|
||||||
[beicon.v2.core :as rx]
|
[beicon.v2.core :as rx]
|
||||||
[potok.v2.core :as ptk]))
|
[potok.v2.core :as ptk]))
|
||||||
|
|
||||||
@@ -99,7 +104,29 @@
|
|||||||
pids (into #{} xf:map-page-id redo-changes)]
|
pids (into #{} xf:map-page-id redo-changes)]
|
||||||
(reduce #(ctst/update-object-indices %1 %2) fdata pids)))]
|
(reduce #(ctst/update-object-indices %1 %2) fdata pids)))]
|
||||||
|
|
||||||
(update-in state [:files file-id :data] apply-changes)))))
|
(if (features/active-feature? state "render-wasm/v1")
|
||||||
|
;; Update the wasm model
|
||||||
|
(let [shape-changes (volatile! {})
|
||||||
|
|
||||||
|
state
|
||||||
|
(binding [cts/*shape-changes* shape-changes]
|
||||||
|
(update-in state [:files file-id :data] apply-changes))]
|
||||||
|
|
||||||
|
(let [objects (dm/get-in state [:files file-id :data :pages-index (:current-page-id state) :objects])]
|
||||||
|
(run!
|
||||||
|
(fn [[shape-id props]]
|
||||||
|
(wasm.api/use-shape shape-id)
|
||||||
|
(let [shape (get objects shape-id)]
|
||||||
|
(run! (partial wasm.shape/set-shape-wasm-attr! shape) props)))
|
||||||
|
@shape-changes))
|
||||||
|
|
||||||
|
(wasm.api/update-shape-tiles)
|
||||||
|
(wasm.api/request-render "set-wasm-attrs")
|
||||||
|
|
||||||
|
state)
|
||||||
|
|
||||||
|
;; wasm renderer deactivated
|
||||||
|
(update-in state [:files file-id :data] apply-changes))))))
|
||||||
|
|
||||||
(defn commit
|
(defn commit
|
||||||
"Create a commit event instance"
|
"Create a commit event instance"
|
||||||
|
|||||||
@@ -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.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]]
|
||||||
[app.common.types.shape.layout :as ctl]
|
[app.common.types.shape.layout :as ctl]
|
||||||
@@ -232,16 +231,17 @@
|
|||||||
(update-vals #(map second %)))]
|
(update-vals #(map second %)))]
|
||||||
|
|
||||||
;; Props are grouped by id and then assoc to the shape the new value
|
;; Props are grouped by id and then assoc to the shape the new value
|
||||||
(doseq [[id properties] wasm-props]
|
(run! (fn [[id properties]]
|
||||||
(let [shape
|
(let [shape
|
||||||
(->> properties
|
(->> properties
|
||||||
(reduce
|
(reduce
|
||||||
(fn [shape {:keys [property value]}]
|
(fn [shape {:keys [property value]}]
|
||||||
(assoc shape property value))
|
(assoc shape property value))
|
||||||
(get objects id)))]
|
(get objects id)))]
|
||||||
|
|
||||||
;; With the new values to the shape change multi props
|
;; With the new values to the shape change multi props
|
||||||
(wasm.shape/set-wasm-multi-attrs! shape (->> properties (map :property)))))))
|
(wasm.shape/set-wasm-multi-attrs! shape (->> properties (map :property)))))
|
||||||
|
wasm-props)))
|
||||||
|
|
||||||
(defn clear-local-transform []
|
(defn clear-local-transform []
|
||||||
(ptk/reify ::clear-local-transform
|
(ptk/reify ::clear-local-transform
|
||||||
@@ -649,8 +649,7 @@
|
|||||||
(let [objects (dsh/lookup-page-objects state)
|
(let [objects (dsh/lookup-page-objects state)
|
||||||
|
|
||||||
ignore-tree
|
ignore-tree
|
||||||
(binding [shape/*wasm-sync* false]
|
(calculate-ignore-tree modif-tree objects)
|
||||||
(calculate-ignore-tree modif-tree objects))
|
|
||||||
|
|
||||||
options
|
options
|
||||||
(-> params
|
(-> params
|
||||||
|
|||||||
@@ -78,20 +78,19 @@
|
|||||||
(not-empty))
|
(not-empty))
|
||||||
|
|
||||||
changes
|
changes
|
||||||
(binding [cts/*wasm-sync-override* true]
|
(-> (pcb/empty-changes it page-id)
|
||||||
(-> (pcb/empty-changes it page-id)
|
(pcb/set-save-undo? save-undo?)
|
||||||
(pcb/set-save-undo? save-undo?)
|
(pcb/set-stack-undo? stack-undo?)
|
||||||
(pcb/set-stack-undo? stack-undo?)
|
(cls/generate-update-shapes ids
|
||||||
(cls/generate-update-shapes ids
|
update-fn
|
||||||
update-fn
|
objects
|
||||||
objects
|
{:attrs attrs
|
||||||
{:attrs attrs
|
:changed-sub-attr changed-sub-attr
|
||||||
:changed-sub-attr changed-sub-attr
|
:ignore-tree ignore-tree
|
||||||
:ignore-tree ignore-tree
|
:ignore-touched ignore-touched
|
||||||
:ignore-touched ignore-touched
|
:with-objects? with-objects?})
|
||||||
:with-objects? with-objects?})
|
(cond-> undo-group
|
||||||
(cond-> undo-group
|
(pcb/set-undo-group undo-group)))
|
||||||
(pcb/set-undo-group undo-group))))
|
|
||||||
|
|
||||||
changes
|
changes
|
||||||
(add-undo-group changes state)]
|
(add-undo-group changes state)]
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
[app.common.geom.rect :as grc]
|
[app.common.geom.rect :as grc]
|
||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
[app.common.logic.shapes :as cls]
|
[app.common.logic.shapes :as cls]
|
||||||
[app.common.types.shape :as cts]
|
|
||||||
[app.common.types.shape.layout :as ctl]
|
[app.common.types.shape.layout :as ctl]
|
||||||
[app.common.types.token :as tk]
|
[app.common.types.token :as tk]
|
||||||
[app.main.constants :refer [size-presets]]
|
[app.main.constants :refer [size-presets]]
|
||||||
@@ -295,9 +294,8 @@
|
|||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps ids)
|
(mf/deps ids)
|
||||||
(fn [value attr]
|
(fn [value attr]
|
||||||
(binding [cts/*wasm-sync* true]
|
(st/emit! (udw/trigger-bounding-box-cloaking ids)
|
||||||
(st/emit! (udw/trigger-bounding-box-cloaking ids)
|
(udw/update-dimensions ids attr value))))
|
||||||
(udw/update-dimensions ids attr value)))))
|
|
||||||
|
|
||||||
on-size-change
|
on-size-change
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
@@ -306,16 +304,14 @@
|
|||||||
(if (or (string? value) (int? value))
|
(if (or (string? value) (int? value))
|
||||||
(do
|
(do
|
||||||
(st/emit! (udw/trigger-bounding-box-cloaking ids))
|
(st/emit! (udw/trigger-bounding-box-cloaking ids))
|
||||||
(binding [cts/*wasm-sync* true]
|
(run! #(do-size-change value attr) shapes))
|
||||||
(run! #(do-size-change value attr) shapes)))
|
|
||||||
(do
|
(do
|
||||||
(let [resolved-value (:resolved-value (first value))]
|
(let [resolved-value (:resolved-value (first value))]
|
||||||
(st/emit! (udw/trigger-bounding-box-cloaking ids)
|
(st/emit! (udw/trigger-bounding-box-cloaking ids)
|
||||||
(dwta/toggle-token {:token (first value)
|
(dwta/toggle-token {:token (first value)
|
||||||
:attrs #{attr}
|
:attrs #{attr}
|
||||||
:shape-ids ids}))
|
:shape-ids ids}))
|
||||||
(binding [cts/*wasm-sync* true]
|
(run! #(do-size-change resolved-value attr) shapes))))))
|
||||||
(run! #(do-size-change resolved-value attr) shapes)))))))
|
|
||||||
|
|
||||||
on-proportion-lock-change
|
on-proportion-lock-change
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
@@ -337,16 +333,14 @@
|
|||||||
(if (or (string? value) (int? value))
|
(if (or (string? value) (int? value))
|
||||||
(do
|
(do
|
||||||
(st/emit! (udw/trigger-bounding-box-cloaking ids))
|
(st/emit! (udw/trigger-bounding-box-cloaking ids))
|
||||||
(binding [cts/*wasm-sync* true]
|
(run! #(do-position-change %1 value attr) shapes))
|
||||||
(run! #(do-position-change %1 value attr) shapes)))
|
|
||||||
(do
|
(do
|
||||||
(let [resolved-value (:resolved-value (first value))]
|
(let [resolved-value (:resolved-value (first value))]
|
||||||
(st/emit! (udw/trigger-bounding-box-cloaking ids)
|
(st/emit! (udw/trigger-bounding-box-cloaking ids)
|
||||||
(dwta/toggle-token {:token (first value)
|
(dwta/toggle-token {:token (first value)
|
||||||
:attrs #{attr}
|
:attrs #{attr}
|
||||||
:shape-ids ids}))
|
:shape-ids ids}))
|
||||||
(binding [cts/*wasm-sync* true]
|
(run! #(do-position-change %1 resolved-value attr) shapes))))))
|
||||||
(run! #(do-position-change %1 resolved-value attr) shapes)))))))
|
|
||||||
|
|
||||||
;; ROTATION
|
;; ROTATION
|
||||||
do-rotation-change
|
do-rotation-change
|
||||||
@@ -362,16 +356,14 @@
|
|||||||
(if (or (string? value) (int? value))
|
(if (or (string? value) (int? value))
|
||||||
(do
|
(do
|
||||||
(st/emit! (udw/trigger-bounding-box-cloaking ids))
|
(st/emit! (udw/trigger-bounding-box-cloaking ids))
|
||||||
(binding [cts/*wasm-sync* true]
|
(run! #(do-rotation-change value) shapes))
|
||||||
(run! #(do-rotation-change value) shapes)))
|
|
||||||
(do
|
(do
|
||||||
(let [resolved-value (:resolved-value (first value))]
|
(let [resolved-value (:resolved-value (first value))]
|
||||||
(st/emit! (udw/trigger-bounding-box-cloaking ids)
|
(st/emit! (udw/trigger-bounding-box-cloaking ids)
|
||||||
(dwta/toggle-token {:token (first value)
|
(dwta/toggle-token {:token (first value)
|
||||||
:attrs #{:rotation}
|
:attrs #{:rotation}
|
||||||
:shape-ids ids}))
|
:shape-ids ids}))
|
||||||
(binding [cts/*wasm-sync* true]
|
(run! #(do-rotation-change resolved-value) shapes))))))
|
||||||
(run! #(do-rotation-change resolved-value) shapes)))))))
|
|
||||||
|
|
||||||
on-width-change
|
on-width-change
|
||||||
(mf/use-fn (mf/deps on-size-change) #(on-size-change % :width))
|
(mf/use-fn (mf/deps on-size-change) #(on-size-change % :width))
|
||||||
|
|||||||
@@ -113,8 +113,7 @@
|
|||||||
objects-modified
|
objects-modified
|
||||||
(mf/with-memo
|
(mf/with-memo
|
||||||
[base-objects wasm-modifiers]
|
[base-objects wasm-modifiers]
|
||||||
(binding [cts/*wasm-sync* false]
|
(apply-modifiers-to-selected selected base-objects wasm-modifiers))
|
||||||
(apply-modifiers-to-selected selected base-objects wasm-modifiers)))
|
|
||||||
|
|
||||||
selected-shapes (->> selected
|
selected-shapes (->> selected
|
||||||
(into [] (keep (d/getf objects-modified)))
|
(into [] (keep (d/getf objects-modified)))
|
||||||
|
|||||||
@@ -6,14 +6,12 @@
|
|||||||
|
|
||||||
(ns app.render-wasm.shape
|
(ns app.render-wasm.shape
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.transit :as t]
|
[app.common.transit :as t]
|
||||||
[app.common.types.shape :as shape]
|
[app.common.types.shape :as shape]
|
||||||
[app.common.types.shape.layout :as ctl]
|
[app.common.types.shape.layout :as ctl]
|
||||||
[app.main.refs :as refs]
|
[app.main.refs :as refs]
|
||||||
[app.render-wasm.api :as api]
|
[app.render-wasm.api :as api]
|
||||||
[beicon.v2.core :as rx]
|
|
||||||
[cljs.core :as c]
|
[cljs.core :as c]
|
||||||
[cuerdas.core :as str]))
|
[cuerdas.core :as str]))
|
||||||
|
|
||||||
@@ -121,7 +119,7 @@
|
|||||||
|
|
||||||
;; --- SHAPE IMPL
|
;; --- SHAPE IMPL
|
||||||
|
|
||||||
(defn- set-wasm-single-attr!
|
(defn set-shape-wasm-attr!
|
||||||
[shape k]
|
[shape k]
|
||||||
(let [v (get shape k)
|
(let [v (get shape k)
|
||||||
id (get shape :id)]
|
id (get shape :id)]
|
||||||
@@ -233,51 +231,12 @@
|
|||||||
(let [shape-id (dm/get-prop shape :id)]
|
(let [shape-id (dm/get-prop shape :id)]
|
||||||
(when (shape-in-current-page? shape-id)
|
(when (shape-in-current-page? shape-id)
|
||||||
(api/use-shape shape-id)
|
(api/use-shape shape-id)
|
||||||
(let [result
|
(run! (partial set-shape-wasm-attr! shape) properties))))
|
||||||
(->> properties
|
|
||||||
(mapcat #(set-wasm-single-attr! shape %)))
|
|
||||||
pending (-> (d/index-by :key :callback result) vals)]
|
|
||||||
(if (and pending (seq pending))
|
|
||||||
(->> (rx/from pending)
|
|
||||||
(rx/mapcat (fn [callback] (callback)))
|
|
||||||
(rx/reduce conj [])
|
|
||||||
(rx/subs!
|
|
||||||
(fn [_]
|
|
||||||
(api/update-shape-tiles)
|
|
||||||
(api/clear-drawing-cache)
|
|
||||||
(api/request-render "set-wasm-attrs-pending"))))
|
|
||||||
(do
|
|
||||||
(api/update-shape-tiles)
|
|
||||||
(api/request-render "set-wasm-attrs")))))))
|
|
||||||
|
|
||||||
(defn set-wasm-attrs!
|
|
||||||
[shape k v]
|
|
||||||
(let [shape-id (dm/get-prop shape :id)
|
|
||||||
old-value (get shape k)]
|
|
||||||
(when (and (shape-in-current-page? shape-id)
|
|
||||||
(not (identical? old-value v)))
|
|
||||||
(let [shape (assoc shape k v)]
|
|
||||||
(api/use-shape shape-id)
|
|
||||||
(let [result (set-wasm-single-attr! shape k)
|
|
||||||
pending (-> (d/index-by :key :callback result) vals)]
|
|
||||||
(if (and pending (seq pending))
|
|
||||||
(->> (rx/from pending)
|
|
||||||
(rx/mapcat (fn [callback] (callback)))
|
|
||||||
(rx/reduce conj [])
|
|
||||||
(rx/subs!
|
|
||||||
(fn [_]
|
|
||||||
(api/update-shape-tiles)
|
|
||||||
(api/clear-drawing-cache)
|
|
||||||
(api/request-render "set-wasm-attrs-pending"))))
|
|
||||||
(do
|
|
||||||
(api/update-shape-tiles)
|
|
||||||
(api/request-render "set-wasm-attrs"))))))))
|
|
||||||
|
|
||||||
(defn- impl-assoc
|
(defn- impl-assoc
|
||||||
[self k v]
|
[self k v]
|
||||||
(when ^boolean shape/*wasm-sync*
|
(when shape/*shape-changes*
|
||||||
(binding [shape/*wasm-sync* false]
|
(vswap! shape/*shape-changes* update (:id self) (fnil conj #{}) k))
|
||||||
(set-wasm-attrs! self k v)))
|
|
||||||
|
|
||||||
(case k
|
(case k
|
||||||
:id
|
:id
|
||||||
@@ -299,10 +258,14 @@
|
|||||||
|
|
||||||
(defn- impl-dissoc
|
(defn- impl-dissoc
|
||||||
[self k]
|
[self k]
|
||||||
(when ^boolean shape/*wasm-sync*
|
#_(when ^boolean shape/*wasm-sync*
|
||||||
(binding [shape/*wasm-sync* false]
|
(binding [shape/*wasm-sync* false]
|
||||||
(when (shape-in-current-page? (.-id ^ShapeProxy self))
|
(when (shape-in-current-page? (.-id ^ShapeProxy self))
|
||||||
(set-wasm-attrs! self k nil))))
|
(set-wasm-attrs! self k nil))))
|
||||||
|
|
||||||
|
(when shape/*shape-changes*
|
||||||
|
(vswap! shape/*shape-changes* update (:id self) (fnil conj #{}) k))
|
||||||
|
|
||||||
(case k
|
(case k
|
||||||
:id
|
:id
|
||||||
(ShapeProxy. nil
|
(ShapeProxy. nil
|
||||||
|
|||||||
Reference in New Issue
Block a user