From e2b28b3b3c3c895c56b791aa7960185c17c3d3de Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 21 Nov 2023 12:35:27 +0100 Subject: [PATCH 1/6] :sparkles: Set grid editor shortcuts --- .../data/workspace/grid_layout/shortcuts.cljs | 74 +++++++++++++++++++ .../src/app/main/ui/workspace/viewport.cljs | 2 +- .../app/main/ui/workspace/viewport/hooks.cljs | 9 ++- 3 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 frontend/src/app/main/data/workspace/grid_layout/shortcuts.cljs diff --git a/frontend/src/app/main/data/workspace/grid_layout/shortcuts.cljs b/frontend/src/app/main/data/workspace/grid_layout/shortcuts.cljs new file mode 100644 index 000000000..5cb77ac72 --- /dev/null +++ b/frontend/src/app/main/data/workspace/grid_layout/shortcuts.cljs @@ -0,0 +1,74 @@ +;; This Source Code Form is subject to the terms of the Mozilla Public +;; License, v. 2.0. If a copy of the MPL was not distributed with this +;; file, You can obtain one at http://mozilla.org/MPL/2.0/. +;; +;; Copyright (c) KALEIDOS INC + +(ns app.main.data.workspace.grid-layout.shortcuts + (:require + [app.main.data.shortcuts :as ds] + [app.main.data.workspace :as dw] + [app.main.data.workspace.path :as drp] + [app.main.store :as st] + [beicon.core :as rx] + [potok.core :as ptk])) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Shortcuts +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;; Shortcuts format https://github.com/ccampbell/mousetrap + +(defn esc-pressed [] + (ptk/reify ::esc-pressed + ptk/WatchEvent + (watch [_ state _] + ;; Not interrupt when we're editing a path + (let [edition-id (or (get-in state [:workspace-drawing :object :id]) + (get-in state [:workspace-local :edition])) + path-edit-mode (get-in state [:workspace-local :edit-path edition-id :edit-mode])] + (if-not (= :draw path-edit-mode) + (rx/of :interrupt) + (rx/empty)))))) + +(def shortcuts + { + + :escape {:tooltip (ds/esc) + :command ["escape" "enter" "v"] + :fn #(st/emit! (esc-pressed))} + + :undo {:tooltip (ds/meta "Z") + :command (ds/c-mod "z") + :fn #(st/emit! (drp/undo-path))} + + :redo {:tooltip (ds/meta "Y") + :command [(ds/c-mod "shift+z") (ds/c-mod "y")] + :fn #(st/emit! (drp/redo-path))} + + ;; ZOOM + + :increase-zoom {:tooltip "+" + :command "+" + :fn #(st/emit! (dw/increase-zoom nil))} + + :decrease-zoom {:tooltip "-" + :command "-" + :fn #(st/emit! (dw/decrease-zoom nil))} + + :reset-zoom {:tooltip (ds/shift "0") + :command "shift+0" + :fn #(st/emit! dw/reset-zoom)} + + :fit-all {:tooltip (ds/shift "1") + :command "shift+1" + :fn #(st/emit! dw/zoom-to-fit-all)} + + :zoom-selected {:tooltip (ds/shift "2") + :command "shift+2" + :fn #(st/emit! dw/zoom-to-selected-shape)} + }) + +(defn get-tooltip [shortcut] + (assert (contains? shortcuts shortcut) (str shortcut)) + (get-in shortcuts [shortcut :tooltip])) diff --git a/frontend/src/app/main/ui/workspace/viewport.cljs b/frontend/src/app/main/ui/workspace/viewport.cljs index 08f9fdc18..34b4948d9 100644 --- a/frontend/src/app/main/ui/workspace/viewport.cljs +++ b/frontend/src/app/main/ui/workspace/viewport.cljs @@ -267,7 +267,7 @@ (hooks/setup-keyboard alt? mod? space? z? shift?) (hooks/setup-hover-shapes page-id move-stream base-objects transform selected mod? hover hover-ids hover-top-frame-id @hover-disabled? focus zoom show-measures?) (hooks/setup-viewport-modifiers modifiers base-objects) - (hooks/setup-shortcuts node-editing? drawing-path? text-editing?) + (hooks/setup-shortcuts node-editing? drawing-path? text-editing? grid-editing?) (hooks/setup-active-frames base-objects hover-ids selected active-frames zoom transform vbox) [:div.viewport {:style #js {"--zoom" zoom}} diff --git a/frontend/src/app/main/ui/workspace/viewport/hooks.cljs b/frontend/src/app/main/ui/workspace/viewport/hooks.cljs index 8e0fa07c3..3f863cd25 100644 --- a/frontend/src/app/main/ui/workspace/viewport/hooks.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/hooks.cljs @@ -17,6 +17,7 @@ [app.common.uuid :as uuid] [app.main.data.shortcuts :as dsc] [app.main.data.workspace :as dw] + [app.main.data.workspace.grid-layout.shortcuts :as gsc] [app.main.data.workspace.path.shortcuts :as psc] [app.main.data.workspace.shortcuts :as wsc] [app.main.data.workspace.text.shortcuts :as tsc] @@ -359,15 +360,19 @@ ;; this shortcuts outside the viewport? (defn setup-shortcuts - [path-editing? drawing-path? text-editing?] + [path-editing? drawing-path? text-editing? grid-editing?] (hooks/use-shortcuts ::workspace wsc/shortcuts) (mf/use-effect - (mf/deps path-editing? drawing-path?) + (mf/deps path-editing? drawing-path? grid-editing?) (fn [] (cond + grid-editing? + (do (st/emit! (dsc/push-shortcuts ::grid gsc/shortcuts)) + #(st/emit! (dsc/pop-shortcuts ::grid))) (or drawing-path? path-editing?) (do (st/emit! (dsc/push-shortcuts ::path psc/shortcuts)) #(st/emit! (dsc/pop-shortcuts ::path))) text-editing? (do (st/emit! (dsc/push-shortcuts ::text tsc/shortcuts)) #(st/emit! (dsc/pop-shortcuts ::text))))))) + From 1b312cdfc308bfffdc452991689f261acf0ceb3d Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 21 Nov 2023 12:35:56 +0100 Subject: [PATCH 2/6] :sparkles: Add collapse button to sources --- .../src/app/main/ui/viewer/inspect/code.cljs | 54 ++++++++++++++----- .../src/app/main/ui/viewer/inspect/code.scss | 35 ++++++++++++ 2 files changed, 75 insertions(+), 14 deletions(-) diff --git a/frontend/src/app/main/ui/viewer/inspect/code.cljs b/frontend/src/app/main/ui/viewer/inspect/code.cljs index be7f42553..49aa6eb8b 100644 --- a/frontend/src/app/main/ui/viewer/inspect/code.cljs +++ b/frontend/src/app/main/ui/viewer/inspect/code.cljs @@ -27,6 +27,7 @@ [app.main.ui.icons :as i] [app.main.ui.shapes.text.fontfaces :refer [shapes->fonts]] [app.util.code-gen :as cg] + [app.util.dom :as dom] [app.util.http :as http] [app.util.webapi :as wapi] [beicon.core :as rx] @@ -115,6 +116,10 @@ fontfaces-css* (mf/use-state nil) images-data* (mf/use-state nil) + collapsed* (mf/use-state #{}) + collapsed-css? (contains? @collapsed* :css) + collapsed-markup? (contains? @collapsed* :markup) + style-type (deref style-type*) markup-type (deref markup-type*) fontfaces-css (deref fontfaces-css*) @@ -205,7 +210,16 @@ ;;(mf/use-callback ;; (fn [] ;; (st/emit! (dp/open-preview-selected)))) - ] + + handle-collapse + (mf/use-callback + (fn [e] + (let [panel-type (keyword (dom/get-data (dom/get-current-target e) "type"))] + (swap! collapsed* + (fn [collapsed] + (if (contains? collapsed panel-type) + (disj collapsed panel-type) + (conj collapsed panel-type)))))))] (mf/use-effect (mf/deps fonts) @@ -242,12 +256,15 @@ [:div {:class (stl/css :code-block)} [:div {:class (stl/css :code-row-lang)} + [:button {:class (stl/css :toggle-btn) + :data-type "css" + :on-click handle-collapse} + [:span {:class (stl/css-case + :collapsabled-icon true + :rotated collapsed-css?)} + i/arrow-refactor]] [:span {:class (stl/css :code-lang)} "CSS"] - ;; Active select when we have more than one option - ;; [:& select {:default-value style-type - ;; :class (stl/css :code-lang-select) - ;; :options [{:label "CSS" :value "css"}] - ;; :on-change set-style}] + [:div {:class (stl/css :action-btns)} [:button {:class (stl/css :expand-button) :on-click on-expand} @@ -256,10 +273,11 @@ [:& copy-button {:data style-code :on-copied on-style-copied}]]] - [:div {:class (stl/css :code-row-display) - :style #js {"--code-height" (str (or style-size 400) "px")}} - [:& code-block {:type style-type - :code style-code}]] + (when-not collapsed-css? + [:div {:class (stl/css :code-row-display) + :style #js {"--code-height" (str (or style-size 400) "px")}} + [:& code-block {:type style-type + :code style-code}]]) [:div {:class (stl/css :resize-area) :on-pointer-down on-style-pointer-down @@ -268,6 +286,13 @@ [:div {:class (stl/css :code-block)} [:div {:class (stl/css :code-row-lang)} + [:button {:class (stl/css :toggle-btn) + :data-type "markup" + :on-click handle-collapse} + [:span {:class (stl/css-case + :collapsabled-icon true + :rotated collapsed-markup?)} + i/arrow-refactor]] [:& select {:default-value markup-type :class (stl/css :code-lang-select) :options [{:label "HTML" :value "html"} @@ -282,10 +307,11 @@ [:& copy-button {:data #(replace-map markup-code images-data) :on-copied on-markup-copied}]]] - [:div {:class (stl/css :code-row-display) - :style #js {"--code-height" (str (or markup-size 400) "px")}} - [:& code-block {:type markup-type - :code markup-code}]] + (when-not collapsed-markup? + [:div {:class (stl/css :code-row-display) + :style #js {"--code-height" (str (or markup-size 400) "px")}} + [:& code-block {:type markup-type + :code markup-code}]]) [:div {:class (stl/css :resize-area) :on-pointer-down on-markup-pointer-down diff --git a/frontend/src/app/main/ui/viewer/inspect/code.scss b/frontend/src/app/main/ui/viewer/inspect/code.scss index 6623a558e..1eb6f5db3 100644 --- a/frontend/src/app/main/ui/viewer/inspect/code.scss +++ b/frontend/src/app/main/ui/viewer/inspect/code.scss @@ -31,6 +31,8 @@ .action-btns { display: flex; gap: $s-4; + flex: 1; + justify-content: end; .expand-button { @extend .button-tertiary; height: $s-32; @@ -56,3 +58,36 @@ } } } + +.toggle-btn { + @include buttonStyle; + display: flex; + align-items: center; + padding: 0; + color: var(--title-foreground-color); + stroke: var(--title-foreground-color); + .collapsabled-icon { + @include flexCenter; + height: $s-24; + border-radius: $br-8; + svg { + @extend .button-icon-small; + transform: rotate(90deg); + stroke: var(--icon-foreground); + } + &.rotated svg { + transform: rotate(0deg); + } + } + &:hover { + color: var(--title-foreground-color-hover); + stroke: var(--title-foreground-color-hover); + .title { + color: var(--title-foreground-color-hover); + stroke: var(--title-foreground-color-hover); + } + .collapsabled-icon svg { + stroke: var(--title-foreground-color-hover); + } + } +} From 055d8feceadc62f547bd18dcdd5561280f30d303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Tue, 21 Nov 2023 09:28:44 +0100 Subject: [PATCH 3/6] :bug: Skip validation in files with components v1 --- common/src/app/common/files/validate.cljc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/common/src/app/common/files/validate.cljc b/common/src/app/common/files/validate.cljc index e6fa1a897..2d7b27b55 100644 --- a/common/src/app/common/files/validate.cljc +++ b/common/src/app/common/files/validate.cljc @@ -461,15 +461,16 @@ "Validate full referential integrity and semantic coherence on file data. Raises a validation exception on first error found." - [{:keys [data] :as file} libraries] + [{:keys [data features] :as file} libraries] + (when (contains? features "components/v2") - (doseq [page (filter :id (ctpl/pages-seq data))] - (validate-shape! uuid/zero file page libraries)) + (doseq [page (filter :id (ctpl/pages-seq data))] + (validate-shape! uuid/zero file page libraries)) - (doseq [component (vals (:components data))] - (validate-component! component file)) + (doseq [component (vals (:components data))] + (validate-component! component file))) - file) + file) (defn validate-file "Validate structure, referencial integrity and semantic coherence of From c25f2408578e4e7bbb99d9968fbfbfe6c8a75eb0 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 21 Nov 2023 11:37:20 +0100 Subject: [PATCH 4/6] :bug: Clean fdata from nils --- backend/src/app/rpc/commands/files_update.clj | 3 ++- common/src/app/common/files/changes.cljc | 2 +- common/src/app/common/files/defaults.cljc | 2 +- common/src/app/common/files/migrations.cljc | 4 +++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/backend/src/app/rpc/commands/files_update.clj b/backend/src/app/rpc/commands/files_update.clj index 883937c68..ff44a1007 100644 --- a/backend/src/app/rpc/commands/files_update.clj +++ b/backend/src/app/rpc/commands/files_update.clj @@ -290,7 +290,8 @@ (-> data (blob/decode) (assoc :id (:id file)) - (pmg/migrate-data)))) + (pmg/migrate-data) + (d/without-nils)))) ;; WARNING: this ruins performance; maybe we need to find ;; some other way to do general validation diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index 600de124b..1c5d01e6e 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -618,7 +618,7 @@ (defmethod process-change :del-media [data {:keys [id]}] - (update data :media dissoc id)) + (d/update-when data :media dissoc id)) ;; -- Components diff --git a/common/src/app/common/files/defaults.cljc b/common/src/app/common/files/defaults.cljc index ff8c0e829..862330dad 100644 --- a/common/src/app/common/files/defaults.cljc +++ b/common/src/app/common/files/defaults.cljc @@ -6,4 +6,4 @@ (ns app.common.files.defaults) -(def version 36) +(def version 37) diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index 2bb858420..46e5a1110 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -651,7 +651,6 @@ (migrate) (assoc :version 35))) - (defmethod migrate 36 [data] (letfn [(update-container [container] @@ -663,3 +662,6 @@ (update :pages-index update-vals update-container) (update :components update-vals update-container)))) +(defmethod migrate 37 + [data] + (d/without-nils data)) From 668fe2fc2475d4800d23a4ee039a32a2ef12cc4f Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 21 Nov 2023 13:35:19 +0100 Subject: [PATCH 5/6] :sparkles: Adjust error reporting thresholds --- backend/src/app/loggers/database.clj | 2 +- common/src/app/common/exceptions.cljc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/app/loggers/database.clj b/backend/src/app/loggers/database.clj index 8319e7566..77694da27 100644 --- a/backend/src/app/loggers/database.clj +++ b/backend/src/app/loggers/database.clj @@ -71,7 +71,7 @@ (when-let [data (some-> data (dissoc ::s/problems ::s/value ::s/spec ::sm/explain :hint))] {:data (pp/pprint-str data :width 200)}) - (when-let [explain (ex/explain data {:level 10 :length 50})] + (when-let [explain (ex/explain data {:level 8 :length 20})] {:explain explain}))))) (defn error-record? diff --git a/common/src/app/common/exceptions.cljc b/common/src/app/common/exceptions.cljc index fa3b932fb..b68a77d1a 100644 --- a/common/src/app/common/exceptions.cljc +++ b/common/src/app/common/exceptions.cljc @@ -93,7 +93,7 @@ explain? true chain? true data-length 10 - data-level 5}}] + data-level 4}}] (letfn [(print-trace-element [^StackTraceElement e] (let [class (.getClassName e) @@ -127,7 +127,7 @@ (-> (ex-message cause) (str/lines) (first) - (str/prune 100))) + (str/prune 130))) (when-let [^StackTraceElement e (first (.getStackTrace ^Throwable cause))] (printf " (%s:%d)" (or (.getFileName e) "") (.getLineNumber e))) From 264a3cf9a3b92cbda83a6785f0c8e268bf7633af Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 21 Nov 2023 13:39:31 +0100 Subject: [PATCH 6/6] :paperclip: Adjust exporter and frontend build scripts --- exporter/scripts/build | 2 +- frontend/scripts/build | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/exporter/scripts/build b/exporter/scripts/build index a4c9df9dc..118bacad9 100755 --- a/exporter/scripts/build +++ b/exporter/scripts/build @@ -10,7 +10,7 @@ rm -rf target export NODE_ENV=production; # Build the application -clojure -M:dev:shadow-cljs release main; +clojure -J-Xms100M -J-Xmx1000M -J-XX:+UseSerialGC -M:dev:shadow-cljs release main; # Remove source rm -rf target/app; diff --git a/frontend/scripts/build b/frontend/scripts/build index 21e972c0b..238687b6a 100755 --- a/frontend/scripts/build +++ b/frontend/scripts/build @@ -11,7 +11,7 @@ yarn install || exit 1; yarn run build:clean || exit 1; yarn run build:styles || exit 1; -clojure -J-Xms100M -J-Xmx800M -J-XX:+UseSerialGC -M:dev:shadow-cljs release main --config-merge "{:release-version \"${CURRENT_HASH}\"}" $EXTRA_PARAMS || exit 1 +clojure -J-Xms100M -J-Xmx1000M -J-XX:+UseSerialGC -M:dev:shadow-cljs release main --config-merge "{:release-version \"${CURRENT_HASH}\"}" $EXTRA_PARAMS || exit 1 yarn run build:assets || exit 1; yarn run build:copy || exit 1;