Merge pull request #3383 from penpot/niwinz-bugfixes-2023-w26-2

🐛 Bugfixes
This commit is contained in:
Alejandro 2023-07-06 18:27:04 +02:00 committed by GitHub
commit 44514a0961
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 12326 additions and 7185 deletions

View file

@ -98,9 +98,13 @@
[:file-id ::sm/uuid]
[:share-id {:optional true} ::sm/uuid]])
(def ^:private valid-fetch-bundle-params?
(sm/pred-fn schema:fetch-bundle))
(defn- fetch-bundle
[{:keys [file-id share-id] :as params}]
(dm/assert! (sm/valid? schema:fetch-bundle params))
(dm/assert! (valid-fetch-bundle-params? params))
(ptk/reify ::fetch-bundle
ptk/WatchEvent
(watch [_ state _]

View file

@ -147,18 +147,20 @@
(defn rename-color
[file-id id new-name]
(dm/assert! (uuid? file-id))
(dm/assert! (uuid? id))
(dm/assert! (string? new-name))
(dm/verify! (uuid? file-id))
(dm/verify! (uuid? id))
(dm/verify! (string? new-name))
(ptk/reify ::rename-color
ptk/WatchEvent
(watch [it state _]
(when (and (some? new-name) (not= "" new-name))
(let [data (get state :workspace-data)
object (get-in data [:colors id])
new-object (assoc object :name new-name)]
(do-update-color it state new-object file-id))))))
(let [new-name (str/trim new-name)]
(if (str/empty? new-name)
(rx/empty)
(let [data (get state :workspace-data)
object (get-in data [:colors id])
object (assoc object :name new-name)]
(do-update-color it state object file-id)))))))
(defn delete-color
[{:keys [id] :as params}]

View file

@ -155,6 +155,9 @@
(defmethod ptk/handle-error ::exceptional-state
[error]
(when-let [cause (::instance error)]
(js/console.log (.-stack cause)))
(ts/schedule
#(st/emit! (rt/assign-exception error))))

View file

@ -27,7 +27,7 @@
(log/set-level! :info)
(def google-fonts
(preload-gfonts "fonts/gfonts.2022.07.11.json"))
(preload-gfonts "fonts/gfonts.2023.07.07.json"))
(def local-fonts
[{:id "sourcesanspro"

View file

@ -545,16 +545,16 @@
(mf/defc viewer-page
[{:keys [file-id] :as props}]
(mf/use-effect
(mf/deps file-id)
(fn []
(st/emit! (dv/initialize props))
(fn []
(st/emit! (dv/finalize props)))))
(mf/with-effect [file-id]
(st/emit! (dv/initialize props))
(fn []
(st/emit! (dv/finalize props))))
(if-let [data (mf/deref refs/viewer-data)]
(let [key (str (get-in data [:file :id]))]
[:& viewer {:params props :data data :key key}])
[:div.loader-content.viewer-loader
i/loader-pencil]))

View file

@ -7,11 +7,12 @@
(ns app.main.ui.viewer.share-link
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.logging :as log]
[app.config :as cf]
[app.main.data.common :as dc]
[app.main.data.events :as ev]
[app.main.data.messages :as dm]
[app.main.data.messages :as msg]
[app.main.data.modal :as modal]
[app.main.refs :as refs]
[app.main.store :as st]
@ -25,52 +26,72 @@
(log/set-level! :warn)
(defn prepare-params
(defn- prepare-params
[{:keys [pages who-comment who-inspect]}]
{:pages pages
:who-comment who-comment
:who-inspect who-inspect})
(mf/defc share-link-dialog
{::mf/register modal/components
::mf/register-as :share-link}
::mf/register-as :share-link
::mf/wrap-props false}
[{:keys [file page]}]
(let [current-page page
(let [current-page page
current-page-id (:id page)
slinks (mf/deref refs/share-links)
router (mf/deref refs/router)
route (mf/deref refs/route)
zoom-type (mf/deref refs/viewer-zoom-type)
page-ids (dm/get-in file [:data :pages])
link (mf/use-state nil)
confirm (mf/use-state false)
open-ops (mf/use-state false)
perms-visible* (mf/use-state false)
perms-visible? (deref perms-visible*)
opts* (mf/use-state
confirm* (mf/use-state false)
confirm? (deref confirm*)
options* (mf/use-state
{:pages-mode "current"
:all-pages false
:pages #{(:id page)}
:who-comment "team"
:who-inspect "team"})
options (deref options*)
opts (deref opts*)
current-link
(mf/with-memo [slinks options page-ids]
(let [{:keys [pages who-comment who-inspect] :as params} (prepare-params options)
slink (d/seek #(and (= (:who-inspect %) who-inspect)
(= (:who-comment %) who-comment)
(= (:pages %) pages))
slinks)]
(when slink
(let [pparams (:path-params route)
page-id (d/seek #(contains? (:pages slink) %) page-ids)
qparams (-> (:query-params route)
(assoc :share-id (:id slink))
(assoc :page-id page-id)
(assoc :index "0"))
qparams (if (nil? zoom-type)
(dissoc qparams :zoom)
(assoc qparams :zoom zoom-type))
selected-pages (:pages opts)
file-pages (->> (get-in file [:data :pages])
(map #(get-in file [:data :pages-index %])))
href (rt/resolve router :viewer pparams qparams)]
(dm/str (assoc cf/public-uri :fragment href))))))
close
on-close
(fn [event]
(dom/prevent-default event)
(st/emit! (modal/hide))
(modal/disallow-click-outside!))
toggle-all
(fn []
(reset! confirm false)
(swap! opts*
on-toggle-all
(fn [_event]
(reset! confirm* false)
(swap! options*
(fn [state]
(if (= true (:all-pages state))
(if (true? (:all-pages state))
(-> state
(assoc :all-pages false)
(assoc :pages #{(:id page)}))
@ -78,30 +99,29 @@
(assoc :all-pages true)
(assoc :pages (into #{} (get-in file [:data :pages]))))))))
mark-checked-page
(mf/use-fn
(mf/deps selected-pages)
(fn [event id]
(let [target (dom/get-target event)
not-checked? (.-checked ^js target)
dif-pages? (not= id (first selected-pages))
no-one-page (< 1 (count selected-pages))
should-change (or no-one-page dif-pages?)]
(when should-change
(reset! confirm false)
(swap! opts*
(fn [state]
(let [actual-pages (:pages state)
updated-pages (if not-checked?
(conj actual-pages id)
(disj actual-pages id))]
on-mark-checked-page
(fn [event]
(let [target (dom/get-target event)
checked? (dom/checked? target)
page-id (parse-uuid (dom/get-data target "page-id"))
dif-pages? (not= page-id (first (:pages options)))
no-one-page (< 1 (count (:pages options)))
should-change? (or ^boolean no-one-page
^boolean dif-pages?)]
(when ^boolean should-change?
(reset! confirm* false)
(swap! options*
(fn [{:keys [pages] :as state}]
(let [pages (if checked?
(conj pages page-id)
(disj pages page-id))]
(-> state
(assoc :pages updated-pages)
(assoc :all-pages (= (count updated-pages) (count file-pages)))))))))))
(assoc :pages pages)
(assoc :all-pages (= (count pages) (count page-ids))))))))))
create-link
(fn [_]
(let [params (prepare-params opts)
(let [params (prepare-params options)
params (assoc params :file-id (:id file))]
(st/emit! (dc/create-share-link params)
(ptk/event ::ev/event {::ev/name "create-shared-link"
@ -111,53 +131,35 @@
copy-link
(fn [_]
(wapi/write-to-clipboard @link)
(st/emit! (dm/show {:type :info
:content (tr "common.share-link.link-copied-success")
:timeout 1000})))
(wapi/write-to-clipboard current-link)
(st/emit! (msg/show {:type :info
:content (tr "common.share-link.link-copied-success")
:timeout 1000})))
try-delete-link
(fn [_]
(reset! confirm true))
(reset! confirm* true))
delete-link
(fn [_]
(let [params (prepare-params opts)
(let [params (prepare-params options)
slink (d/seek #(= (:flags %) (:flags params)) slinks)]
(reset! confirm false)
(reset! confirm* false)
(st/emit! (dc/delete-share-link slink))))
manage-open-ops
toggle-perms-visibility
(fn [_]
(swap! open-ops not))
(swap! perms-visible* not))
on-who-change
(fn [type event]
(let [target (dom/get-target event)
value (dom/get-value target)
value (keyword value)]
(reset! confirm false)
(reset! confirm* false)
(if (= type :comment)
(swap! opts* assoc :who-comment (d/name value))
(swap! opts* assoc :who-inspect (d/name value)))))]
(mf/use-effect
(mf/deps file slinks opts)
(fn []
(let [{:keys [pages who-comment who-inspect] :as params} (prepare-params opts)
slink (d/seek #(and (= (:who-inspect %) who-inspect) (= (:who-comment %) who-comment) (= (:pages %) pages)) slinks)
href (when slink
(let [pparams (:path-params route)
qparams (-> (:query-params route)
(assoc :share-id (:id slink))
(assoc :index "0"))
qparams (if (nil? zoom-type)
(dissoc qparams :zoom)
(assoc qparams :zoom zoom-type))
href (rt/resolve router :viewer pparams qparams)]
(assoc cf/public-uri :fragment href)))]
(reset! link (some-> href str)))))
(swap! options* assoc :who-comment (d/name value))
(swap! options* assoc :who-inspect (d/name value)))))]
[:div.modal-overlay.transparent.share-modal
[:div.modal-container.share-link-dialog
@ -165,37 +167,38 @@
[:div.title
[:h2 (tr "common.share-link.title")]
[:div.modal-close-button
{:on-click close
{:on-click on-close
:title (tr "labels.close")}
i/close]]]
[:div.modal-content
[:div.share-link-section
(when (and (not @confirm) (some? @link))
(when (and (not confirm?) (some? current-link))
[:div.custom-input.with-icon
[:input {:type "text"
:value (or @link "")
:value (or current-link "")
:placeholder (tr "common.share-link.placeholder")
:read-only true}]
[:div.help-icon {:title (tr "viewer.header.share.copy-link")
:on-click copy-link}
i/copy]])
[:div.hint-wrapper
(when (not @confirm) [:div.hint (tr "common.share-link.permissions-hint")])
(when (not ^boolean confirm?)
[:div.hint (tr "common.share-link.permissions-hint")])
(cond
(true? @confirm)
(true? confirm?)
[:div.confirm-dialog
[:div.description (tr "common.share-link.confirm-deletion-link-description")]
[:div.actions
[:input.btn-secondary
{:type "button"
:on-click #(reset! confirm false)
:on-click #(reset! confirm* false)
:value (tr "labels.cancel")}]
[:input.btn-warning
{:type "button"
:on-click delete-link
:value (tr "common.share-link.destroy-link")}]]]
(some? @link)
(some? current-link)
[:input.btn-secondary
{:type "button"
:class "primary"
@ -210,16 +213,15 @@
:value (tr "common.share-link.get-link")}])]]]
[:div.modal-content.ops-section
[:div.manage-permissions
{:on-click manage-open-ops}
{:on-click toggle-perms-visibility}
[:span.icon i/picker-hsv]
[:div.title (tr "common.share-link.manage-ops")]]
(when @open-ops
(when ^boolean perms-visible?
[:*
(let [all-selected? (:all-pages opts)
pages (->> (get-in file [:data :pages])
(map #(get-in file [:data :pages-index %])))
selected selected-pages]
(let [all-selected? (:all-pages options)
pages (->> (get-in file [:data :pages])
(map #(get-in file [:data :pages-index %])))
selected (:pages options)]
[:*
[:div.view-mode
[:div.subtitle
@ -229,10 +231,11 @@
(if (= 1 (count pages))
[:div.input-checkbox.check-primary
[:input {:type "checkbox"
:id (str "page-" (:id current-page))
:on-change #(mark-checked-page % (:id current-page))
:id (dm/str "page-" current-page-id)
:data-page-id (dm/str current-page-id)
:on-change on-mark-checked-page
:checked true}]
[:label {:for (str "page-" (:id current-page))} (:name current-page)]
[:label {:for (str "page-" current-page-id)} (:name current-page)]
[:span (str " " (tr "common.share-link.current-tag"))]]
[:*
@ -242,29 +245,30 @@
:id "view-all"
:checked all-selected?
:name "pages-mode"
:on-change toggle-all}]
:on-change on-toggle-all}]
[:label {:for "view-all"} (tr "common.share-link.view-all")]]
[:span.count-pages (tr "common.share-link.page-shared" (i18n/c (count selected)))]]
[:ul.pages-selection
(for [page pages]
[:li.input-checkbox.check-primary {:key (str (:id page))}
(for [{:keys [id name]} pages]
[:li.input-checkbox.check-primary {:key (dm/str id)}
[:input {:type "checkbox"
:id (str "page-" (:id page))
:on-change #(mark-checked-page % (:id page))
:checked (contains? selected (:id page))}]
(if (= (:id current-page) (:id page))
:id (dm/str "page-" id)
:data-page-id (dm/str id)
:on-change on-mark-checked-page
:checked (contains? selected id)}]
(if (= current-page-id id)
[:*
[:label {:for (str "page-" (:id page))} (:name page)]
[:span.current-tag (str " " (tr "common.share-link.current-tag"))]]
[:label {:for (str "page-" (:id page))} (:name page)])])]])]]])
[:label {:for (dm/str "page-" id)} name]
[:span.current-tag (dm/str " " (tr "common.share-link.current-tag"))]]
[:label {:for (dm/str "page-" id)} name])])]])]]])
[:div.access-mode
[:div.subtitle
[:span.icon i/chat]
(tr "common.share-link.permissions-can-comment")]
[:div.items
[:select.input-select {:on-change (partial on-who-change :comment)
:value (:who-comment opts)}
:value (:who-comment options)}
[:option {:value "team"} (tr "common.share-link.team-members")]
[:option {:value "all"} (tr "common.share-link.all-users")]]]]
[:div.inspect-mode
@ -273,7 +277,7 @@
(tr "common.share-link.permissions-can-inspect")]
[:div.items
[:select.input-select {:on-change (partial on-who-change :inspect)
:value (:who-inspect opts)}
:value (:who-inspect options)}
[:option {:value "team"} (tr "common.share-link.team-members")]
[:option {:value "all"} (tr "common.share-link.all-users")]]]]])]]]))

View file

@ -57,7 +57,7 @@
{::mf/wrap [mf/memo]}
[{:keys [font current? on-click style]}]
(let [item-ref (mf/use-ref)
on-click (mf/use-callback (mf/deps font) #(on-click font))]
on-click (mf/use-fn (mf/deps font) #(on-click font))]
(mf/use-effect
(mf/deps current?)
@ -108,7 +108,7 @@
(into [] (filter #(some? (get fontsdb (:id %))))))
select-next
(mf/use-callback
(mf/use-fn
(mf/deps fonts)
(fn [event]
(dom/stop-propagation event)
@ -116,7 +116,7 @@
(swap! selected get-next-font fonts)))
select-prev
(mf/use-callback
(mf/use-fn
(mf/deps fonts)
(fn [event]
(dom/stop-propagation event)
@ -124,7 +124,7 @@
(swap! selected get-prev-font fonts)))
on-key-down
(mf/use-callback
(mf/use-fn
(mf/deps fonts)
(fn [event]
(cond
@ -135,54 +135,45 @@
:else (dom/focus! (mf/ref-val input)))))
on-filter-change
(mf/use-callback
(mf/use-fn
(mf/deps)
(fn [event]
(let [value (dom/get-target-val event)]
(swap! state assoc :term value))))
on-select-and-close
(mf/use-callback
(mf/use-fn
(mf/deps on-select on-close)
(fn [font]
(on-select font)
(on-close)))]
(mf/use-effect
(fn []
(st/emit! (fts/load-recent-fonts))))
(mf/with-effect []
(st/emit! (fts/load-recent-fonts)))
(mf/use-effect
(mf/deps fonts)
(fn []
(let [key (events/listen js/document "keydown" on-key-down)]
#(events/unlistenByKey key))))
(mf/with-effect [fonts]
(let [key (events/listen js/document "keydown" on-key-down)]
#(events/unlistenByKey key)))
(mf/use-effect
(mf/deps @selected)
(fn []
(when-let [inst (mf/ref-val flist)]
(when-let [index (:index @selected)]
(.scrollToRow ^js inst index)))))
(mf/with-effect [@selected]
(when-let [inst (mf/ref-val flist)]
(when-let [index (:index @selected)]
(.scrollToRow ^js inst index))))
(mf/use-effect
(mf/deps @selected)
(fn []
(on-select @selected)))
(mf/with-effect [@selected]
(on-select @selected))
(mf/use-effect
(fn []
(st/emit! (dsc/push-shortcuts :typography {}))
(fn []
(st/emit! (dsc/pop-shortcuts :typography)))))
(mf/with-effect []
(st/emit! (dsc/push-shortcuts :typography {}))
(fn []
(st/emit! (dsc/pop-shortcuts :typography))))
(mf/use-effect
(fn []
(let [index (d/index-of-pred fonts #(= (:id %) (:id current-font)))
inst (mf/ref-val flist)]
(tm/schedule
#(let [offset (.getOffsetForRow ^js inst #js {:alignment "center" :index index})]
(.scrollToPosition ^js inst offset))))))
(mf/with-effect []
(let [index (d/index-of-pred fonts #(= (:id %) (:id current-font)))
inst (mf/ref-val flist)]
(tm/schedule
#(let [offset (.getOffsetForRow ^js inst #js {:alignment "center" :index index})]
(.scrollToPosition ^js inst offset)))))
[:div.font-selector
[:div.font-selector-dropdown
@ -193,8 +184,8 @@
:spell-check false
:on-change on-filter-change}]
(when (and recent-fonts show-recent)
[:hr]
[*
[:*
[:hr]
[:p.title (tr "workspace.options.recent-fonts")]
(for [[idx font] (d/enumerate recent-fonts)]
[:& font-item {:key (dm/str "font-" idx)
@ -270,7 +261,7 @@
open-selector? (mf/use-state false)
change-font
(mf/use-callback
(mf/use-fn
(mf/deps on-change fonts recent-fonts)
(fn [new-font-id]
(let [{:keys [family] :as font} (get fonts new-font-id)
@ -283,14 +274,14 @@
(mf/set-ref-val! last-font font))))
on-font-size-change
(mf/use-callback
(mf/use-fn
(mf/deps on-change)
(fn [new-font-size]
(when-not (str/empty? new-font-size)
(on-change {:font-size (str new-font-size)}))))
on-font-variant-change
(mf/use-callback
(mf/use-fn
(mf/deps font on-change)
(fn [event]
(let [new-variant-id (dom/get-target-val event)
@ -303,7 +294,7 @@
(dom/blur! (dom/get-target event)))))
on-font-select
(mf/use-callback
(mf/use-fn
(mf/deps change-font)
(fn [font*]
(when (not= font font*)
@ -313,7 +304,7 @@
(on-blur))))
on-font-selector-close
(mf/use-callback
(mf/use-fn
(fn []
(reset! open-selector? false)
(when (some? on-blur)
@ -476,7 +467,7 @@
open? (deref open*)
on-name-blur
(mf/use-callback
(mf/use-fn
(mf/deps on-change)
(fn [event]
(let [name (dom/get-target-val event)]