diff --git a/.gitignore b/.gitignore index 60561d6bcf..15e8533e3f 100644 --- a/.gitignore +++ b/.gitignore @@ -57,6 +57,7 @@ /frontend/package-lock.json /frontend/resources/fonts/experiments /frontend/resources/public/* +/frontend/src/app/render_wasm/api/shared.js /frontend/storybook-static/ /frontend/target/ /frontend/test-results/ diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index ee4a3a8d5b..08cd678244 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -1777,6 +1777,13 @@ in the destination shape will not be copied." [changes dest-shape origin-shape dest-root origin-root container omit-touched?] + ;; (when (or (= #uuid "fe6ff6fc-0062-8060-8001-ad3331737f7d" (:id origin-shape)) + ;; (= #uuid "fe6ff6fc-0062-8060-8001-ad3331737f7d" (:id dest-shape))) + ;; (println "=========================") + ;; (app.common.pprint/pprint origin-shape) + ;; (println "-------------------------") + ;; (app.common.pprint/pprint dest-shape)) + (shape-log :info (:id dest-shape) container :msg (str "SYNC " (:name origin-shape) @@ -1789,7 +1796,12 @@ " " (pretty-uuid (:id dest-shape)))) - (let [;; To synchronize geometry attributes we need to make a prior + (let [is-my-shape? (or (= #uuid "fe6ff6fc-0062-8060-8001-ad3331737f7d" (:id origin-shape)) + (= #uuid "fe6ff6fc-0062-8060-8001-ad3331737f7d" (:id dest-shape))) + + is-my-shape? (= #uuid "fe6ff6fc-0062-8060-8001-ad3331737f7d" (:id dest-shape)) + + ;; To synchronize geometry attributes we need to make a prior ;; operation, because coordinates are absolute, but we need to ;; sync only the position relative to the origin of the component. ;; We solve this by moving the origin shape so it is aligned with @@ -1804,24 +1816,33 @@ uoperations '()] (let [attr (first attrs)] - (if (nil? attr) - (cond-> changes - (seq roperations) - (add-update-attr-changes dest-shape container roperations uoperations) - :always - (check-detached-main dest-shape origin-shape) - :always - (generate-update-tokens container dest-shape origin-shape touched omit-touched? nil)) - (let [attr-group (get ctk/sync-attrs attr) + (if (nil? attr) + (do + + (app.common.pprint/pprint roperations) + + (cond-> changes + (seq roperations) + (add-update-attr-changes dest-shape container roperations uoperations) + :always + (check-detached-main dest-shape origin-shape) + :always + (generate-update-tokens container dest-shape origin-shape touched omit-touched? nil))) + + (let [attr-group + (get ctk/sync-attrs attr) + ;; position-data is a special case because can be affected by - ;; :geometry-group and :content-group so, if the position-data - ;; changes but the geometry is touched we need to reset the position-data - ;; so it's calculated again - reset-pos-data? (and (cfh/text-shape? origin-shape) - (= attr :position-data) - (not= (:position-data origin-shape) (:position-data dest-shape)) - (touched :geometry-group)) + ;; :geometry-group and :content-group so, if the + ;; position-data changes but the geometry is touched + ;; we need to reset the position-data so it's + ;; calculated again + reset-pos-data? + (and (cfh/text-shape? origin-shape) + (= attr :position-data) + (not= (:position-data origin-shape) (:position-data dest-shape)) + (touched :geometry-group)) ;; On texts, when we want to omit the touched attrs, both text (the actual letters) ;; and attrs (bold, font, etc) are in the same attr :content. @@ -1843,25 +1864,41 @@ ;; the attributes, omiting the other part (not text-content-change?))) - attr-val (when-not skip-operations? - (cond - ;; If position data changes and the geometry group is touched - ;; we need to put to nil so we can regenerate it - reset-pos-data? - nil + _ (when (and is-my-shape? (= attr :type)) + (prn "PROCESS ATTR" attr (touched attr-group) omit-touched?)) - text-content-change? - (text-change-value (:content dest-shape) - (:content origin-shape) - touched) + attr-val + (when-not skip-operations? + (cond + ;; If position data changes and the geometry group is touched + ;; we need to put to nil so we can regenerate it + reset-pos-data? + nil - :else - (get origin-shape attr))) + text-content-change? + (text-change-value (:content dest-shape) + (:content origin-shape) + touched) + + :else + (get origin-shape attr))) ;; If the final attr-value is the actual value, skip - skip-operations? (or skip-operations? - (= attr-val (get dest-shape attr))) + skip-operations? + (or skip-operations? + (= attr-val (get dest-shape attr))) + _ (when (and is-my-shape? (not skip-operations?)) + (println "ATTR:" attr " FROM:" (get dest-shape attr) " TO:" attr-val) + #_(when (nil? attr-val) + (prn (:id dest-shape)))) + + ;; _ (when (and (not skip-operations?) (= attr :type)) + ;; (println "=========================") + ;; (prn + ;; #_(app.common.pprint/pprint origin-shape) + ;; #_(println "-------------------------") + ;; #_(app.common.pprint/pprint dest-shape)) ;; On a text-partial-change, we want to force a position-data reset ;; so it's calculated again diff --git a/common/src/app/common/types/component.cljc b/common/src/app/common/types/component.cljc index 01968f1373..add8e96c34 100644 --- a/common/src/app/common/types/component.cljc +++ b/common/src/app/common/types/component.cljc @@ -47,7 +47,7 @@ {:name :name-group :fills :fill-group :hide-fill-on-export :fill-group - :content :content-group + :content :geometry-group :position-data :content-group :hidden :visibility-group :blocked :modifiable-group diff --git a/common/src/app/common/types/path.cljc b/common/src/app/common/types/path.cljc index be0e15b1aa..67d8031efb 100644 --- a/common/src/app/common/types/path.cljc +++ b/common/src/app/common/types/path.cljc @@ -190,10 +190,14 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defn get-points - "Returns points for the given segment, faster version of - the `content->points`." + "Returns points for the given content. Accepts PathData instances or + plain segment vectors. Returns nil for nil content." [content] - (some-> content segment/get-points)) + (when (some? content) + (let [content (if (impl/path-data? content) + content + (impl/path-data content))] + (segment/get-points content)))) (defn calc-selrect "Calculate selrect from a content. The content can be in a PathData diff --git a/common/src/app/common/types/path/impl.cljc b/common/src/app/common/types/path/impl.cljc index 8b2ed4a315..959a11bf6f 100644 --- a/common/src/app/common/types/path/impl.cljc +++ b/common/src/app/common/types/path/impl.cljc @@ -52,14 +52,15 @@ [target key & expr] (if (:ns &env) (let [target (with-meta target {:tag 'js})] - `(let [~'cache (.-cache ~target) - ~'result (.get ~'cache ~key)] - (if ~'result - (do - ~'result) - (let [~'result (do ~@expr)] - (.set ~'cache ~key ~'result) - ~'result)))) + `(let [~'cache (.-cache ~target)] + (if (some? ~'cache) + (let [~'result (.get ~'cache ~key)] + (if ~'result + ~'result + (let [~'result (do ~@expr)] + (.set ~'cache ~key ~'result) + ~'result))) + (do ~@expr)))) `(do ~@expr))) (defn- impl-transform-segment diff --git a/common/test/common_tests/types/path_data_test.cljc b/common/test/common_tests/types/path_data_test.cljc index 5e6298191e..672df228d8 100644 --- a/common/test/common_tests/types/path_data_test.cljc +++ b/common/test/common_tests/types/path_data_test.cljc @@ -279,6 +279,12 @@ (t/is (some? points)) (t/is (= 3 (count points)))))) +(t/deftest path-get-points-plain-vector-safe + (t/testing "path/get-points does not throw for plain vector content" + (let [points (path/get-points sample-content)] + (t/is (some? points)) + (t/is (= 3 (count points)))))) + (defn calculate-extremities "Calculate extremities for the provided content. A legacy implementation used mainly as reference for testing" diff --git a/docs/_includes/layouts/base.njk b/docs/_includes/layouts/base.njk index a4ecabe2e7..8bc9f9f663 100644 --- a/docs/_includes/layouts/base.njk +++ b/docs/_includes/layouts/base.njk @@ -70,9 +70,11 @@