From 77564531eb119ff4061755ba7d7f3713faf7bb95 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 10 Jan 2024 11:27:13 +0100 Subject: [PATCH 1/9] :bug: Fix incorrect features setup on persist-temp-file rpc method --- backend/src/app/rpc/commands/files_temp.clj | 101 +++++++++++--------- 1 file changed, 58 insertions(+), 43 deletions(-) diff --git a/backend/src/app/rpc/commands/files_temp.clj b/backend/src/app/rpc/commands/files_temp.clj index 54e5d8b3d0..2d339f0ccb 100644 --- a/backend/src/app/rpc/commands/files_temp.clj +++ b/backend/src/app/rpc/commands/files_temp.clj @@ -8,11 +8,13 @@ (:require [app.common.exceptions :as ex] [app.common.features :as cfeat] - [app.common.files.changes :as fch] - [app.common.spec :as us] + [app.common.files.changes :as cpc] + [app.common.schema :as sm] [app.common.uuid :as uuid] [app.config :as cf] [app.db :as db] + [app.db.sql :as sql] + [app.features.fdata :as fdata] [app.rpc :as-alias rpc] [app.rpc.commands.files :as files] [app.rpc.commands.files-create :as files.create] @@ -21,28 +23,26 @@ [app.rpc.commands.teams :as teams] [app.rpc.doc :as-alias doc] [app.util.blob :as blob] + [app.util.pointer-map :as pmap] [app.util.services :as sv] [app.util.time :as dt] - [clojure.set :as set] - [clojure.spec.alpha :as s])) - + [clojure.set :as set])) ;; --- MUTATION COMMAND: create-temp-file -(s/def ::create-page ::us/boolean) - -(s/def ::create-temp-file - (s/keys :req [::rpc/profile-id] - :req-un [::files/name - ::files/project-id] - :opt-un [::files/id - ::files/is-shared - ::files/features - ::create-page])) +(def ^:private schema:create-temp-file + [:map {:title "create-temp-file"} + [:name :string] + [:project-id ::sm/uuid] + [:id {:optional true} ::sm/uuid] + [:is-shared :boolean] + [:features ::cfeat/features] + [:create-page :boolean]]) (sv/defmethod ::create-temp-file {::doc/added "1.17" - ::doc/module :files} + ::doc/module :files + ::sm/params schema:create-temp-file} [cfg {:keys [::rpc/profile-id project-id] :as params}] (db/tx-run! cfg (fn [{:keys [::db/conn] :as cfg}] (projects/check-edition-permissions! conn profile-id project-id) @@ -72,16 +72,18 @@ ;; --- MUTATION COMMAND: update-temp-file -(s/def ::update-temp-file - (s/keys :req [::rpc/profile-id] - :req-un [::files.update/changes - ::files.update/revn - ::files.update/session-id - ::files/id])) + +(def ^:private schema:update-temp-file + [:map {:title "update-temp-file"} + [:changes [:vector ::cpc/change]] + [:revn {:min 0} :int] + [:session-id ::sm/uuid] + [:id ::sm/uuid]]) (sv/defmethod ::update-temp-file {::doc/added "1.17" - ::doc/module :files} + ::doc/module :files + ::sm/params schema:update-temp-file} [cfg {:keys [::rpc/profile-id session-id id revn changes] :as params}] (db/tx-run! cfg (fn [{:keys [::db/conn]}] (db/insert! conn :file-change @@ -98,37 +100,50 @@ ;; --- MUTATION COMMAND: persist-temp-file (defn persist-temp-file - [conn {:keys [id] :as params}] - (let [file (db/get-by-id conn :file id) - revs (db/query conn :file-change - {:file-id id} - {:order-by [[:revn :asc]]}) - revn (count revs)] + [{:keys [::db/conn] :as cfg} {:keys [id] :as params}] + (let [file (files/get-file cfg id + :migrate? false + :lock-for-update? true)] (when (nil? (:deleted-at file)) (ex/raise :type :validation :code :cant-persist-already-persisted-file)) + (let [changes (->> (db/cursor conn + (sql/select :file-change {:file-id id} + {:order-by [[:revn :asc]]}) + {:chunk-size 10}) + (sequence (mapcat (comp blob/decode :changes)))) + + file (update file :data cpc/process-changes changes) + + file (if (contains? (:features file) "fdata/objects-map") + (fdata/enable-objects-map file) + file) + + file (if (contains? (:features file) "fdata/pointer-map") + (binding [pmap/*tracked* (pmap/create-tracked)] + (let [file (fdata/enable-pointer-map file)] + (fdata/persist-pointers! cfg id) + file)) + file)] - (let [data - (->> revs - (mapcat #(->> % :changes blob/decode)) - (fch/process-changes (blob/decode (:data file))))] (db/update! conn :file {:deleted-at nil - :revn revn - :data (blob/encode data)} - {:id id})) - nil)) + :revn 1 + :data (blob/encode (:data file))} + {:id id}) + nil))) -(s/def ::persist-temp-file - (s/keys :req [::rpc/profile-id] - :req-un [::files/id])) +(def ^:private schema:persist-temp-file + [:map {:title "persist-temp-file"} + [:id ::sm/uuid]]) (sv/defmethod ::persist-temp-file {::doc/added "1.17" - ::doc/module :files} + ::doc/module :files + ::sm/params schema:persist-temp-file} [cfg {:keys [::rpc/profile-id id] :as params}] - (db/tx-run! cfg (fn [{:keys [::db/conn]}] + (db/tx-run! cfg (fn [{:keys [::db/conn] :as cfg}] (files/check-edition-permissions! conn profile-id id) - (persist-temp-file conn params)))) + (persist-temp-file cfg params)))) From fede8c997529a3bcd9718a331e74597d7070f644 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 10 Jan 2024 13:44:00 +0100 Subject: [PATCH 2/9] :sparkles: Setup better media max file-size on devenv --- backend/scripts/repl | 4 ++++ backend/scripts/start-dev | 3 +++ backend/src/app/config.clj | 2 ++ backend/src/app/media.clj | 18 ++++++++---------- docker/devenv/files/nginx.conf | 2 +- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/backend/scripts/repl b/backend/scripts/repl index e2cd441c02..2a89163a5e 100755 --- a/backend/scripts/repl +++ b/backend/scripts/repl @@ -32,6 +32,10 @@ export PENPOT_FLAGS="\ disable-soft-file-schema-validation \ disable-soft-file-validation"; + +# Setup default upload media file size to 100MiB +export PENPOT_MEDIA_MAX_FILE_SIZE=104857600 + # export PENPOT_DATABASE_URI="postgresql://172.17.0.1:5432/penpot" # export PENPOT_DATABASE_USERNAME="penpot" # export PENPOT_DATABASE_PASSWORD="penpot" diff --git a/backend/scripts/start-dev b/backend/scripts/start-dev index 59a8a189bd..8dafad2500 100755 --- a/backend/scripts/start-dev +++ b/backend/scripts/start-dev @@ -34,6 +34,9 @@ export OPTIONS=" -J-XX:+UnlockDiagnosticVMOptions \ -J-XX:+DebugNonSafepoints" +# Setup default upload media file size to 100MiB +export PENPOT_MEDIA_MAX_FILE_SIZE=104857600 + # Setup HEAP # export OPTIONS="$OPTIONS -J-Xms50m -J-Xmx1024m" # export OPTIONS="$OPTIONS -J-Xms1100m -J-Xmx1100m -J-XX:+AlwaysPreTouch" diff --git a/backend/src/app/config.clj b/backend/src/app/config.clj index ef021d7c1b..b4fe60c652 100644 --- a/backend/src/app/config.clj +++ b/backend/src/app/config.clj @@ -79,6 +79,8 @@ :telemetry-uri "https://telemetry.penpot.app/" + :media-max-file-size (* 1024 1024 30) ; 30MiB + :ldap-user-query "(|(uid=:username)(mail=:username))" :ldap-attrs-username "uid" :ldap-attrs-email "mail" diff --git a/backend/src/app/media.clj b/backend/src/app/media.clj index a9a559e5bc..8d2315352a 100644 --- a/backend/src/app/media.clj +++ b/backend/src/app/media.clj @@ -32,9 +32,6 @@ org.im4java.core.IMOperation org.im4java.core.Info)) -(def default-max-file-size - (* 1024 1024 30)) ; 30 MiB - (s/def ::path fs/path?) (s/def ::filename string?) (s/def ::size integer?) @@ -83,13 +80,14 @@ (defn validate-media-size! [upload] - (when (> (:size upload) (cf/get :media-max-file-size default-max-file-size)) - (ex/raise :type :restriction - :code :media-max-file-size-reached - :hint (str/ffmt "the uploaded file size % is greater than the maximum %" - (:size upload) - default-max-file-size))) - upload) + (let [max-size (cf/get :media-max-file-size)] + (when (> (:size upload) max-size) + (ex/raise :type :restriction + :code :media-max-file-size-reached + :hint (str/ffmt "the uploaded file size % is greater than the maximum %" + (:size upload) + max-size))) + upload)) (defmulti process :cmd) (defmulti process-error class) diff --git a/docker/devenv/files/nginx.conf b/docker/devenv/files/nginx.conf index ab2c5ea6e9..d291512c84 100644 --- a/docker/devenv/files/nginx.conf +++ b/docker/devenv/files/nginx.conf @@ -49,7 +49,7 @@ http { listen 3449 default_server; server_name _; - client_max_body_size 30M; + client_max_body_size 100M; charset utf-8; proxy_http_version 1.1; From d8aba5f64515cd566351893130a3d34204717374 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 10 Jan 2024 13:52:06 +0100 Subject: [PATCH 3/9] :arrow_up: Update versions on devenv Dockerfile --- docker/devenv/Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docker/devenv/Dockerfile b/docker/devenv/Dockerfile index ed491092d2..ef47e54b68 100644 --- a/docker/devenv/Dockerfile +++ b/docker/devenv/Dockerfile @@ -4,10 +4,10 @@ LABEL maintainer="Andrey Antukh " ARG DEBIAN_FRONTEND=noninteractive ENV NODE_VERSION=v20.10.0 \ - CLOJURE_VERSION=1.11.1.1347 \ - CLJKONDO_VERSION=2023.09.07 \ - BABASHKA_VERSION=1.3.184 \ - CLJFMT_VERSION=0.11.2 \ + CLOJURE_VERSION=1.11.1.1429 \ + CLJKONDO_VERSION=2023.12.15 \ + BABASHKA_VERSION=1.3.187 \ + CLJFMT_VERSION=0.12.0 \ LANG=en_US.UTF-8 \ LC_ALL=en_US.UTF-8 From 5ec1272d6806156ad00229de81db8c7f1ca85e6f Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 10 Jan 2024 14:26:39 +0100 Subject: [PATCH 4/9] :bug: Update rumext that fixes issue with :htmlFor prop --- frontend/deps.edn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/deps.edn b/frontend/deps.edn index 6c57b02a68..61ca3089d1 100644 --- a/frontend/deps.edn +++ b/frontend/deps.edn @@ -19,8 +19,8 @@ :git/url "https://github.com/funcool/beicon.git"} funcool/rumext - {:git/tag "v2.9.2" - :git/sha "faa6e6c" + {:git/tag "v2.9.3" + :git/sha "9047337" :git/url "https://github.com/funcool/rumext.git"} instaparse/instaparse {:mvn/version "1.4.12"} From e8563872924d00b0dda0dd9ebbcc749d154a6c49 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 10 Jan 2024 14:26:58 +0100 Subject: [PATCH 5/9] :paperclip: Add better key formatting on radio-buttons react component --- frontend/src/app/main/ui/components/forms.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/app/main/ui/components/forms.cljs b/frontend/src/app/main/ui/components/forms.cljs index 88cd4fd425..9ce9ae13d3 100644 --- a/frontend/src/app/main/ui/components/forms.cljs +++ b/frontend/src/app/main/ui/components/forms.cljs @@ -268,7 +268,7 @@ (let [image? (some? image) value' (encode-fn value) checked? (= value current-value) - key (str/ffmt "%-%" name value')] + key (str/ffmt "%-%" (d/name name) (d/name value'))] [:label {:for key :key key :style {:background-image (when image? (str/ffmt "url(%)" image))} From 3d66a4b7be2f6311e59784c6e08b4a3b7c2690e6 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 10 Jan 2024 14:27:41 +0100 Subject: [PATCH 6/9] :lipstick: Split large lines on onboarding questions compomponent --- .../src/app/main/ui/onboarding/questions.cljs | 41 ++++++++++++++----- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/frontend/src/app/main/ui/onboarding/questions.cljs b/frontend/src/app/main/ui/onboarding/questions.cljs index cead11ff45..fd3fcca94c 100644 --- a/frontend/src/app/main/ui/onboarding/questions.cljs +++ b/frontend/src/app/main/ui/onboarding/questions.cljs @@ -47,19 +47,38 @@ [:h1 {:class (stl/css :modal-title)} (tr "questions.lets-get-started")] [:p {:class (stl/css :modal-text)} (tr "questions.your-feedback-will-help-us")] [:h3 {:class (stl/css :modal-subtitle)} (tr "questions.questions-how-are-you-planning-to-use-penpot")] - [:& fm/select {:options [{:label (tr "questions.select-option") :value "" :key "questions-how-are-you-planning-to-use-penpot" :disabled true} - {:label (tr "questions.discover-more-about-penpot") :value "discover-more-about-penpot" :key "discover-more-about-penpot"} - {:label (tr "questions.test-penpot-to-see-if-its-a-fit-for-team") :value "test-penpot-to-see-if-its-a-fit-for-team" :key "test-penpot-to-see-if-its-a-fit-for-team"} - {:label (tr "questions.start-to-work-on-my-project") :value "start-to-work-on-my-project" :key "start-to-work-on-my-project"} - {:label (tr "questions.get-the-code-from-my-team-project") :value "get-the-code-from-my-team-project" :key "get-the-code-from-my-team-project"} - {:label (tr "questions.leave-feedback-for-my-team-project") :value "leave-feedback-for-my-team-project" :key "leave-feedback-for-my-team-project"} - {:label (tr "questions.work-in-concept-ideas") :value "work-in-concept-ideas" :key "work-in-concept-ideas"} - {:label (tr "questions.try-out-before-using-penpot-on-premise") :value "try-out-before-using-penpot-on-premise" :key "try-out-before-using-penpot-on-premise"}] - :default "" - :name :planning}]]) + [:& fm/select + {:options [{:label (tr "questions.select-option") + :value "" :key "questions-how-are-you-planning-to-use-penpot" + :disabled true} + {:label (tr "questions.discover-more-about-penpot") + :value "discover-more-about-penpot" + :key "discover-more-about-penpot"} + {:label (tr "questions.test-penpot-to-see-if-its-a-fit-for-team") + :value "test-penpot-to-see-if-its-a-fit-for-team" + :key "test-penpot-to-see-if-its-a-fit-for-team"} + {:label (tr "questions.start-to-work-on-my-project") + :value "start-to-work-on-my-project" + :key "start-to-work-on-my-project"} + {:label (tr "questions.get-the-code-from-my-team-project") + :value "get-the-code-from-my-team-project" + :key "get-the-code-from-my-team-project"} + {:label (tr "questions.leave-feedback-for-my-team-project") + :value "leave-feedback-for-my-team-project" + :key "leave-feedback-for-my-team-project"} + {:label (tr "questions.work-in-concept-ideas") + :value "work-in-concept-ideas" + :key "work-in-concept-ideas"} + {:label (tr "questions.try-out-before-using-penpot-on-premise") + :value "try-out-before-using-penpot-on-premise" + :key "try-out-before-using-penpot-on-premise"}] + :default "" + :name :planning}]]) (s/def ::questions-form-step-2 - (s/keys :req-un [::experience-branding-illustrations-marketing-pieces ::experience-interface-design-visual-assets-design-systems ::experience-interface-wireframes-user-journeys-flows-navigation-trees])) + (s/keys :req-un [::experience-branding-illustrations-marketing-pieces + ::experience-interface-design-visual-assets-design-systems + ::experience-interface-wireframes-user-journeys-flows-navigation-trees])) (mf/defc step-2 [{:keys [on-next on-prev form] :as props}] From b63a8d34b5416237cf006b2240f7c58f221a3846 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 10 Jan 2024 14:36:30 +0100 Subject: [PATCH 7/9] :bug: Fix debug reset file version method --- backend/src/app/http/debug.clj | 14 +++++++------- backend/src/app/srepl/helpers.clj | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/src/app/http/debug.clj b/backend/src/app/http/debug.clj index 19d6529fcd..1630289046 100644 --- a/backend/src/app/http/debug.clj +++ b/backend/src/app/http/debug.clj @@ -412,13 +412,13 @@ :code :invalid-version :hint "provided invalid version")) - (srepl/update-file! cfg - :id file-id - :update-fn (fn [file] - (update file :data assoc :version version)) - :migrate? false - :inc-revn? false - :save? true) + (binding [srepl/*system* cfg] + (srepl/update-file! :id file-id + :update-fn (fn [file] + (update file :data assoc :version version)) + :migrate? false + :inc-revn? false + :save? true)) {::rres/status 200 ::rres/headers {"content-type" "text/plain"} ::rres/body "OK"})) diff --git a/backend/src/app/srepl/helpers.clj b/backend/src/app/srepl/helpers.clj index f42fcf26c6..f1a267e48d 100644 --- a/backend/src/app/srepl/helpers.clj +++ b/backend/src/app/srepl/helpers.clj @@ -154,7 +154,7 @@ (dissoc file :data)))] - (db/tx-run! main/system + (db/tx-run! (or *system* main/system) (fn [system] (binding [*system* system] (try From 67b3040327c2a32662bd4df9a96dd87284e8ec69 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 10 Jan 2024 10:44:31 +0100 Subject: [PATCH 8/9] :bug: Fix problem with text content and multiple selection --- common/src/app/common/attrs.cljc | 15 +++- common/src/app/common/text.cljc | 65 +++++++++++++++- .../src/app/main/data/workspace/colors.cljs | 3 +- .../main/data/workspace/text/shortcuts.cljs | 7 +- .../src/app/main/data/workspace/texts.cljs | 74 ++----------------- .../workspace/sidebar/options/menus/text.cljs | 8 +- .../sidebar/options/shapes/multiple.cljs | 52 +++++++------ .../sidebar/options/shapes/text.cljs | 11 +-- 8 files changed, 129 insertions(+), 106 deletions(-) diff --git a/common/src/app/common/attrs.cljc b/common/src/app/common/attrs.cljc index d414628bea..0c25331785 100644 --- a/common/src/app/common/attrs.cljc +++ b/common/src/app/common/attrs.cljc @@ -7,7 +7,8 @@ (ns app.common.attrs (:require [app.common.geom.shapes :as gsh] - [app.common.math :as mth])) + [app.common.math :as mth] + [app.common.text :as txt])) (defn- get-attr [obj attr] @@ -113,3 +114,15 @@ (persistent! result))))) +(defn get-text-attrs-multi + "Gets the multi attributes for a text shape. Splits the content by type and gets the attributes depending + on the node type" + [{:keys [content]} defaults attrs] + (let [root-attrs (->> attrs (filter (set txt/root-attrs))) + paragraph-attrs (->> attrs (filter (set txt/paragraph-attrs))) + text-node-attrs (->> attrs (filter (set txt/text-node-attrs)))] + (merge + defaults + (get-attrs-multi (->> (txt/node-seq txt/is-root-node? content)) root-attrs) + (get-attrs-multi (->> (txt/node-seq txt/is-paragraph-node? content)) paragraph-attrs) + (get-attrs-multi (->> (txt/node-seq txt/is-text-node? content)) text-node-attrs)))) diff --git a/common/src/app/common/text.cljc b/common/src/app/common/text.cljc index 35e220ab56..b5b12c5d5a 100644 --- a/common/src/app/common/text.cljc +++ b/common/src/app/common/text.cljc @@ -13,6 +13,67 @@ [clojure.walk :as walk] [cuerdas.core :as str])) +;; -- Attrs + +(def text-typography-attrs + [:typography-ref-id + :typography-ref-file]) + +(def text-fill-attrs + [:fill-color + :fill-opacity + :fill-color-ref-id + :fill-color-ref-file + :fill-color-gradient]) + +(def text-font-attrs + [:font-id + :font-family + :font-variant-id + :font-size + :font-weight + :font-style]) + +(def text-align-attrs + [:text-align]) + +(def text-direction-attrs + [:text-direction]) + +(def text-spacing-attrs + [:line-height + :letter-spacing]) + +(def text-valign-attrs + [:vertical-align]) + +(def text-decoration-attrs + [:text-decoration]) + +(def text-transform-attrs + [:text-transform]) + +(def shape-attrs + [:grow-type]) + +(def root-attrs + text-valign-attrs) + +(def paragraph-attrs + (d/concat-vec + text-align-attrs + text-direction-attrs)) + +(def text-node-attrs + (d/concat-vec + text-typography-attrs + text-font-attrs + text-spacing-attrs + text-decoration-attrs + text-transform-attrs)) + +(def text-all-attrs (d/concat-set shape-attrs root-attrs paragraph-attrs text-node-attrs)) + (def default-text-attrs {:typography-ref-file nil :typography-ref-id nil @@ -30,8 +91,6 @@ :fills [{:fill-color clr/black :fill-opacity 1}]}) -(def text-attrs (keys default-text-attrs)) - (def typography-fields [:font-id :font-family @@ -274,7 +333,7 @@ [node] (letfn [(rec-style-text-map [acc node style] - (let [node-style (merge style (select-keys node text-attrs)) + (let [node-style (merge style (select-keys node text-all-attrs)) head (or (-> acc first) [{} ""]) [head-style head-text] head diff --git a/frontend/src/app/main/data/workspace/colors.cljs b/frontend/src/app/main/data/workspace/colors.cljs index 61ec72a63a..e20b9019b7 100644 --- a/frontend/src/app/main/data/workspace/colors.cljs +++ b/frontend/src/app/main/data/workspace/colors.cljs @@ -11,6 +11,7 @@ [app.common.data.macros :as dm] [app.common.files.helpers :as cfh] [app.common.schema :as sm] + [app.common.text :as txt] [app.common.types.component :as ctk] [app.main.broadcast :as mbc] [app.main.data.events :as ev] @@ -673,7 +674,7 @@ (:fills (dwt/current-text-values {:editor-state (dm/get-in state [:workspace-editor-state (:id shape)]) :shape shape - :attrs (conj dwt/text-fill-attrs :fills)})) + :attrs (conj txt/text-fill-attrs :fills)})) (:fills shape)) fill (first fills) single? (and (= 1 (count selected)) diff --git a/frontend/src/app/main/data/workspace/text/shortcuts.cljs b/frontend/src/app/main/data/workspace/text/shortcuts.cljs index cd280aba2e..80d7005fb0 100644 --- a/frontend/src/app/main/data/workspace/text/shortcuts.cljs +++ b/frontend/src/app/main/data/workspace/text/shortcuts.cljs @@ -7,6 +7,7 @@ (ns app.main.data.workspace.text.shortcuts (:require [app.common.data :as d] + [app.common.text :as txt] [app.main.data.shortcuts :as ds] [app.main.data.workspace.texts :as dwt] [app.main.data.workspace.undo :as dwu] @@ -116,15 +117,15 @@ (d/merge (dwt/current-root-values {:shape shape - :attrs dwt/root-attrs}) + :attrs txt/root-attrs}) (dwt/current-paragraph-values {:editor-state editor-state :shape shape - :attrs dwt/paragraph-attrs}) + :attrs txt/paragraph-attrs}) (dwt/current-text-values {:editor-state editor-state :shape shape - :attrs dwt/text-attrs})))) + :attrs txt/text-node-attrs})))) (defn- update-attrs [shape props] (let [text-values (calculate-text-values shape) diff --git a/frontend/src/app/main/data/workspace/texts.cljs b/frontend/src/app/main/data/workspace/texts.cljs index c741a4e62b..5f7bfb4997 100644 --- a/frontend/src/app/main/data/workspace/texts.cljs +++ b/frontend/src/app/main/data/workspace/texts.cljs @@ -33,66 +33,6 @@ [cuerdas.core :as str] [potok.v2.core :as ptk])) -;; -- Attrs - -(def text-typography-attrs - [:typography-ref-id - :typography-ref-file]) - -(def text-fill-attrs - [:fill-color - :fill-opacity - :fill-color-ref-id - :fill-color-ref-file - :fill-color-gradient]) - -(def text-font-attrs - [:font-id - :font-family - :font-variant-id - :font-size - :font-weight - :font-style]) - -(def text-align-attrs - [:text-align]) - -(def text-direction-attrs - [:text-direction]) - -(def text-spacing-attrs - [:line-height - :letter-spacing]) - -(def text-valign-attrs - [:vertical-align]) - -(def text-decoration-attrs - [:text-decoration]) - -(def text-transform-attrs - [:text-transform]) - -(def shape-attrs - [:grow-type]) - -(def root-attrs text-valign-attrs) - -(def paragraph-attrs - (d/concat-vec - text-align-attrs - text-direction-attrs)) - -(def text-attrs - (d/concat-vec - text-typography-attrs - text-font-attrs - text-spacing-attrs - text-decoration-attrs - text-transform-attrs)) - -(def attrs (d/concat-set shape-attrs root-attrs paragraph-attrs text-attrs)) - ;; -- Editor (defn update-editor @@ -611,17 +551,17 @@ ptk/WatchEvent (watch [_ _ _] (rx/concat - (let [attrs (select-keys attrs root-attrs)] + (let [attrs (select-keys attrs txt/root-attrs)] (if-not (empty? attrs) (rx/of (update-root-attrs {:id id :attrs attrs})) (rx/empty))) - (let [attrs (select-keys attrs paragraph-attrs)] + (let [attrs (select-keys attrs txt/paragraph-attrs)] (if-not (empty? attrs) (rx/of (update-paragraph-attrs {:id id :attrs attrs})) (rx/empty))) - (let [attrs (select-keys attrs text-attrs)] + (let [attrs (select-keys attrs txt/text-node-attrs)] (if-not (empty? attrs) (rx/of (update-text-attrs {:id id :attrs attrs})) (rx/empty))))))) @@ -683,7 +623,7 @@ values (current-text-values {:editor-state (dm/get-in state [:workspace-editor-state (:id shape)]) :shape shape - :attrs text-attrs}) + :attrs txt/text-node-attrs}) multiple? (or (> 1 (count shapes)) (d/seek (partial = :multiple) @@ -691,9 +631,9 @@ values (-> (d/without-nils values) (select-keys - (d/concat-vec text-font-attrs - text-spacing-attrs - text-transform-attrs))) + (d/concat-vec txt/text-font-attrs + txt/text-spacing-attrs + txt/text-transform-attrs))) typ-id (uuid/next) typ (-> (if multiple? diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/text.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/text.cljs index 882eb4aee8..74496773ad 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/text.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/text.cljs @@ -212,7 +212,7 @@ (mf/deps values) (fn [ids attrs] (st/emit! (dwt/save-font (-> (merge txt/default-text-attrs values attrs) - (select-keys dwt/text-attrs))) + (select-keys txt/text-node-attrs))) (dwt/update-all-attrs ids attrs)))) on-change @@ -242,9 +242,9 @@ (fn [_] (let [set-values (-> (d/without-nils values) (select-keys - (d/concat-vec dwt/text-font-attrs - dwt/text-spacing-attrs - dwt/text-transform-attrs))) + (d/concat-vec txt/text-font-attrs + txt/text-spacing-attrs + txt/text-transform-attrs))) typography (merge txt/default-typography set-values) typography (dwt/generate-typography-name typography) id (uuid/next)] diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/multiple.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/multiple.cljs index 736a71c304..f669bc4d9d 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/multiple.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/multiple.cljs @@ -14,7 +14,6 @@ [app.common.types.component :as ctk] [app.common.types.shape.attrs :refer [editable-attrs]] [app.common.types.shape.layout :as ctl] - [app.main.data.workspace.texts :as dwt] [app.main.refs :as refs] [app.main.ui.hooks :as hooks] [app.main.ui.workspace.sidebar.options.menus.blur :refer [blur-attrs blur-menu]] @@ -163,7 +162,7 @@ :shadow shadow-attrs :blur blur-attrs :stroke stroke-attrs - :text dwt/attrs + :text txt/text-all-attrs :exports exports-attrs :layout-container layout-container-flex-attrs :layout-item layout-item-attrs}) @@ -211,32 +210,41 @@ :else (attrs/get-attrs-multi [v1 v2] attrs))) extract-attrs - (fn [[ids values] {:keys [id type content] :as shape}] + (fn [[ids values] {:keys [id type] :as shape}] (let [read-mode (get-in type->read-mode [type attr-group]) editable-attrs (filter (get editable-attrs (:type shape)) attrs)] (case read-mode - :ignore [ids values] + :ignore + [ids values] - :shape (let [;; Get the editable attrs from the shape, ensuring that all attributes - ;; are present, with value nil if they are not present in the shape. - shape-values (merge - (into {} (map #(vector % nil)) editable-attrs) - (cond - (= attr-group :measure) (select-measure-keys shape) - :else (select-keys shape editable-attrs)))] - [(conj ids id) - (merge-attrs values shape-values)]) + :shape + (let [;; Get the editable attrs from the shape, ensuring that all attributes + ;; are present, with value nil if they are not present in the shape. + shape-values (merge + (into {} (map #(vector % nil)) editable-attrs) + (cond + (= attr-group :measure) (select-measure-keys shape) + :else (select-keys shape editable-attrs)))] + [(conj ids id) + (merge-attrs values shape-values)]) - :text [(conj ids id) - (-> values - (merge-attrs (select-keys shape attrs)) - (merge-attrs (merge - (select-keys txt/default-text-attrs attrs) - (attrs/get-attrs-multi (txt/node-seq content) attrs))))] + :text + (let [shape-attrs (select-keys shape attrs) - :children (let [children (->> (:shapes shape []) (map #(get objects %))) - [new-ids new-values] (get-attrs* children objects attr-group)] - [(d/concat-vec ids new-ids) (merge-attrs values new-values)]) + content-attrs + (attrs/get-text-attrs-multi shape txt/default-text-attrs attrs) + + new-values + (-> values + (merge-attrs shape-attrs) + (merge-attrs content-attrs))] + [(conj ids id) + new-values]) + + :children + (let [children (->> (:shapes shape []) (map #(get objects %))) + [new-ids new-values] (get-attrs* children objects attr-group)] + [(d/concat-vec ids new-ids) (merge-attrs values new-values)]) [])))] diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/text.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/text.cljs index 990c8bfe74..955db7652b 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/text.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/text.cljs @@ -7,8 +7,9 @@ (ns app.main.ui.workspace.sidebar.options.shapes.text (:require [app.common.data :as d] + [app.common.text :as txt] [app.common.types.shape.layout :as ctl] - [app.main.data.workspace.texts :as dwt :refer [text-fill-attrs root-attrs paragraph-attrs text-attrs]] + [app.main.data.workspace.texts :as dwt] [app.main.refs :as refs] [app.main.ui.hooks :as hooks] [app.main.ui.workspace.sidebar.options.menus.blur :refer [blur-menu]] @@ -56,7 +57,7 @@ fill-values (-> (dwt/current-text-values {:editor-state editor-state :shape shape - :attrs (conj text-fill-attrs :fills)}) + :attrs (conj txt/text-fill-attrs :fills)}) (d/update-in-when [:fill-color-gradient :type] keyword)) fill-values (if (not (contains? fill-values :fills)) @@ -71,15 +72,15 @@ (select-keys shape fill-attrs) (dwt/current-root-values {:shape shape - :attrs root-attrs}) + :attrs txt/root-attrs}) (dwt/current-paragraph-values {:editor-state editor-state :shape shape - :attrs paragraph-attrs}) + :attrs txt/paragraph-attrs}) (dwt/current-text-values {:editor-state editor-state :shape shape - :attrs text-attrs})) + :attrs txt/text-node-attrs})) layout-item-values (select-keys shape layout-item-attrs)] [:* From 21bd59defd4fd93180d61835e5d480216f3dbb45 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 10 Jan 2024 11:09:01 +0100 Subject: [PATCH 9/9] :bug: Fix problems uploading graphics in components v1 --- frontend/src/app/main/data/workspace/media.cljs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/main/data/workspace/media.cljs b/frontend/src/app/main/data/workspace/media.cljs index 12a50de5ad..d3b18e1a63 100644 --- a/frontend/src/app/main/data/workspace/media.cljs +++ b/frontend/src/app/main/data/workspace/media.cljs @@ -240,7 +240,8 @@ (let [params (assoc params :force-media true :local? false - :on-image #(st/emit! (dwl/add-media %)))] + :on-image #(st/emit! (dwl/add-media %)) + :on-svg #(st/emit! (dwl/add-media %)))] (process-media-objects params))) (defn upload-media-workspace