0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-09 08:20:45 -05:00

📎 Cosmetic changes on text shape component.

This commit is contained in:
Andrey Antukh 2020-11-25 16:30:30 +01:00 committed by Hirunatan
parent 6c07cfcd25
commit 76d8ca1e72
2 changed files with 67 additions and 62 deletions

View file

@ -2,24 +2,27 @@
;; 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) 2016-2019 Andrey Antukh <niwi@niwi.nz>
;; 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.ui.shapes.text
(:require
[clojure.set :as set]
[promesa.core :as p]
[cuerdas.core :as str]
[rumext.alpha :as mf]
[app.common.data :as d]
[app.common.geom.matrix :as gmt]
[app.common.geom.shapes :as geom]
[app.main.data.fetch :as df]
[app.main.fonts :as fonts]
[app.main.ui.context :as muc]
[app.main.ui.shapes.group :refer [mask-id-ctx]]
[app.common.data :as d]
[app.common.geom.shapes :as geom]
[app.common.geom.matrix :as gmt]
[app.util.object :as obj]
[app.util.color :as uc]
[app.util.text :as ut]))
[app.util.object :as obj]
[app.util.text :as ut]
[clojure.set :as set]
[cuerdas.core :as str]
[promesa.core :as p]
[rumext.alpha :as mf]))
;; --- Text Editor Rendering

View file

@ -11,32 +11,32 @@
(:require
["slate" :as slate]
["slate-react" :as rslate]
[goog.events :as events]
[goog.object :as gobj]
[cuerdas.core :as str]
[rumext.alpha :as mf]
[beicon.core :as rx]
[app.util.color :as color]
[app.util.dom :as dom]
[app.util.text :as ut]
[app.util.object :as obj]
[app.util.color :as uc]
[app.util.timers :as timers]
[app.common.data :as d]
[app.common.geom.shapes :as geom]
[app.main.refs :as refs]
[app.main.store :as st]
[app.main.fonts :as fonts]
[app.main.data.workspace :as dw]
[app.main.data.workspace.common :as dwc]
[app.main.data.workspace.texts :as dwt]
[app.main.ui.cursors :as cur]
[app.main.ui.workspace.shapes.common :as common]
[app.main.ui.shapes.text :as text]
[app.main.ui.keyboard :as kbd]
[app.main.fonts :as fonts]
[app.main.refs :as refs]
[app.main.store :as st]
[app.main.ui.context :as muc]
[app.main.ui.cursors :as cur]
[app.main.ui.keyboard :as kbd]
[app.main.ui.shapes.filters :as filters]
[app.main.ui.shapes.shape :refer [shape-container]])
[app.main.ui.shapes.shape :refer [shape-container]]
[app.main.ui.shapes.text :as text]
[app.main.ui.workspace.shapes.common :as common]
[app.util.color :as color]
[app.util.color :as uc]
[app.util.dom :as dom]
[app.util.object :as obj]
[app.util.text :as ut]
[app.util.timers :as timers]
[beicon.core :as rx]
[cuerdas.core :as str]
[goog.events :as events]
[goog.object :as gobj]
[rumext.alpha :as mf])
(:import
goog.events.EventType
goog.events.KeyCodes))
@ -59,16 +59,15 @@
(mf/defc text-wrapper
{::mf/wrap-props false}
[props]
(let [{:keys [id x1 y1 content group grow-type width height ] :as shape} (unchecked-get props "shape")
(let [shape (unchecked-get props "shape")
selected-iref (mf/use-memo (mf/deps (:id shape))
#(refs/make-selected-ref (:id shape)))
selected? (mf/deref selected-iref)
edition (mf/deref refs/selected-edition)
current-transform (mf/deref refs/current-transform)
render-editor (mf/use-state false)
edition? (= edition id)
edition? (= edition (:id shape))
embed-resources? (mf/use-ctx muc/embed-ctx)
@ -80,17 +79,20 @@
(dom/stop-propagation event)
(dom/prevent-default event)
(when selected?
(st/emit! (dw/start-edition-mode (:id shape)))))]
(st/emit! (dw/start-edition-mode (:id shape)))))
(mf/use-effect
(mf/deps shape edition selected? current-transform)
(fn [] (let [check? (and (#{:auto-width :auto-height} (:grow-type shape))
check?
(and (#{:auto-width :auto-height} (:grow-type shape))
selected?
(not edition?)
(not embed-resources?)
(nil? current-transform))
result (timers/schedule #(reset! render-editor check?))]
#(rx/dispose! result))))
(nil? current-transform))]
(mf/use-effect
(mf/deps check?)
(fn []
(let [sem (timers/schedule #(reset! render-editor check?))]
#(rx/dispose! sem))))
[:> shape-container {:shape shape
:on-double-click on-double-click