0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-13 16:21:57 -05:00

Changes after review

This commit is contained in:
alonso.torres 2020-09-10 21:34:58 +02:00 committed by Alonso Torres
parent e737ec0311
commit d6fc98c70b
7 changed files with 87 additions and 69 deletions

View file

@ -32,7 +32,8 @@
[app.main.ui.settings.delete-account]
[app.main.ui.settings.change-email]
[app.main.ui.confirm]
[app.main.ui.workspace.colorpicker]))
[app.main.ui.workspace.colorpicker]
[app.main.ui.workspace.libraries]))
(declare reinit)

View file

@ -21,7 +21,8 @@
[app.util.time :as dt]
[app.common.uuid :as uuid]
[app.main.data.workspace.common :as dwc]
[app.main.data.workspace.texts :as dwt]))
[app.main.data.workspace.texts :as dwt]
[app.main.data.modal :as md]))
(declare create-color-result)
@ -201,15 +202,14 @@
(st/emit!
(if shift?
(change-stroke-selected color)
(change-fill-selected color)
)
(fn [state] (update state :workspace-local dissoc :modal))))]
(change-fill-selected color))
(md/hide-modal)))]
(ptk/reify ::start-picker
ptk/UpdateEvent
(update [_ state]
(-> state
(assoc-in [:workspace-local :picking-color?] true)
(assoc-in [:workspace-local :modal] {:id (random-uuid)
:type :colorpicker
:props {:on-change handle-change-color}
:allow-click-outside true}))))))
(assoc ::md/modal {:id (random-uuid)
:type :colorpicker
:props {:on-change handle-change-color}
:allow-click-outside true}))))))

View file

@ -0,0 +1,37 @@
;; 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/.
;;
;; This Source Code Form is "Incompatible With Secondary Licenses", as
;; defined by the Mozilla Public License, v. 2.0.
;;
;; Copyright (c) 2020 UXBOX Labs SL
(ns app.main.data.modal
(:require
[potok.core :as ptk]))
(defn show-modal [id type props]
(ptk/reify ::show-modal
ptk/UpdateEvent
(update [_ state]
(-> state
(assoc ::modal {:id id
:type type
:props props
:allow-click-outside false})))))
(defn hide-modal []
(ptk/reify ::hide-modal
ptk/UpdateEvent
(update [_ state]
(-> state
(dissoc ::modal)))))
(defn update-modal [options]
(ptk/reify ::update-modal
ptk/UpdateEvent
(update [_ state]
(-> state
(update ::modal merge options)))))

View file

@ -80,18 +80,6 @@
(def current-hover
(l/derived :hover workspace-local))
(def picking-color?
(l/derived :picking-color? workspace-local))
(def picked-color
(l/derived :picked-color workspace-local))
(def picked-color-select
(l/derived :picked-color-select workspace-local))
(def picked-shift?
(l/derived :picked-shift? workspace-local))
(def workspace-layout
(l/derived :workspace-layout st/state))

View file

@ -16,49 +16,26 @@
[app.main.ui.keyboard :as k]
[app.util.dom :as dom]
[app.main.refs :as refs]
[potok.core :as ptk])
[potok.core :as ptk]
[app.main.data.modal :as mdm])
(:import goog.events.EventType))
(defonce components (atom {}))
(defn show-modal [id type props]
(ptk/reify ::show-modal
ptk/UpdateEvent
(update [_ state]
(-> state
(assoc-in [:workspace-local :modal] {:id id
:type type
:props props
:allow-click-outside false})))))
(defn hide-modal []
(ptk/reify ::hide-modal
ptk/UpdateEvent
(update [_ state]
(-> state
(update :workspace-local dissoc :modal)))))
(defn update-modal [options]
(ptk/reify ::hide-modal
ptk/UpdateEvent
(update [_ state]
(-> state
(update-in [:workspace-local :modal] merge options)))))
(defn show!
([type props]
(let [id (random-uuid)]
(st/emit! (show-modal id type props)))))
(st/emit! (mdm/show-modal id type props)))))
(defn allow-click-outside! []
(st/emit! (update-modal {:allow-click-outside true})))
(st/emit! (mdm/update-modal {:allow-click-outside true})))
(defn disallow-click-outside! []
(st/emit! (update-modal {:allow-click-outside false})))
(st/emit! (mdm/update-modal {:allow-click-outside false})))
(defn hide!
[]
(st/emit! (hide-modal)))
(st/emit! (mdm/hide-modal)))
(defn- on-esc-clicked
[event]
@ -117,10 +94,11 @@
(def modal-ref
(l/derived :modal refs/workspace-local))
(l/derived ::mdm/modal st/state))
(mf/defc modal
[]
(let [modal (mf/deref modal-ref)]
(println "modal" modal)
(when modal [:& modal-wrapper {:data modal
:key (:id modal)}])))

View file

@ -114,18 +114,18 @@
(defn- render-text-node
([node] (render-text-node 0 node))
([index {:keys [type text children] :as node}]
(mf/html
(let [embed-resources? (mf/use-ctx muc/embed-ctx)
embeded-fonts (mf/use-state nil)]
(mf/use-effect
(mf/deps node)
(fn []
(when (and embed-resources? (= type "root"))
(let [font-to-embed (get-all-fonts node)
embeded (map embed-font font-to-embed)]
(-> (p/all embeded)
(p/then (fn [result] (reset! embeded-fonts (str/join "\n" result)))))))))
(let [embed-resources? (mf/use-ctx muc/embed-ctx)
embeded-fonts (mf/use-state nil)]
(mf/use-effect
(mf/deps node)
(fn []
(when (and embed-resources? (= type "root"))
(let [font-to-embed (get-all-fonts node)
embeded (map embed-font font-to-embed)]
(-> (p/all embeded)
(p/then (fn [result] (reset! embeded-fonts (str/join "\n" result)))))))))
(mf/html
(if (string? text)
(let [style (generate-text-styles (clj->js node))]
[:span {:style style :key index} text])
@ -138,10 +138,9 @@
{:key index
:style style
:xmlns "http://www.w3.org/1999/xhtml"}
[:*
(when (not (nil? @embeded-fonts))
(when (not (nil? @embeded-fonts))
[:style @embeded-fonts])
children]])
children])
"paragraph-set"
(let [style #js {:display "inline-block"

View file

@ -24,6 +24,21 @@
[app.main.refs :as refs]
[app.util.i18n :as i18n :refer [t]]))
;; --- Refs
(def picking-color?
(l/derived :picking-color? refs/workspace-local))
(def picked-color
(l/derived :picked-color refs/workspace-local))
(def picked-color-select
(l/derived :picked-color-select refs/workspace-local))
(def picked-shift?
(l/derived :picked-shift? refs/workspace-local))
;; --- Color Picker Modal
(mf/defc value-selector [{:keys [hue saturation value on-change]}]
@ -102,10 +117,10 @@
shared-libs (mf/deref refs/workspace-libraries)
recent-colors (mf/deref refs/workspace-recent-colors)
picking-color? (mf/deref refs/picking-color?)
picked-color (mf/deref refs/picked-color)
picked-color-select (mf/deref refs/picked-color-select)
picked-shift? (mf/deref refs/picked-shift?)
picking-color? (mf/deref picking-color?)
picked-color (mf/deref picked-color)
picked-color-select (mf/deref picked-color-select)
picked-shift? (mf/deref picked-shift?)
locale (mf/deref i18n/locale)