mirror of
https://github.com/penpot/penpot.git
synced 2025-02-09 00:28:20 -05:00
Merge remote-tracking branch 'origin/staging' into develop
This commit is contained in:
commit
a907041564
6 changed files with 56 additions and 35 deletions
|
@ -17,7 +17,9 @@
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[cuerdas.core :as str]))
|
[cuerdas.core :as str]))
|
||||||
|
|
||||||
;; --- Auxiliary Functions
|
(set! *assert* js/goog.DEBUG)
|
||||||
|
|
||||||
|
;; --- Auxiliar Functions
|
||||||
|
|
||||||
(s/def ::platform #{:windows :linux :macos :other})
|
(s/def ::platform #{:windows :linux :macos :other})
|
||||||
(s/def ::browser #{:chrome :firefox :safari :edge :other})
|
(s/def ::browser #{:chrome :firefox :safari :edge :other})
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
(when (= :browser @cf/target)
|
(when (= :browser @cf/target)
|
||||||
(log/info :message "Welcome to penpot"
|
(log/info :message "Welcome to penpot"
|
||||||
:version (:full @cf/version)
|
:version (:full @cf/version)
|
||||||
|
:asserts *assert*
|
||||||
:build-date cf/build-date
|
:build-date cf/build-date
|
||||||
:public-uri (str @cf/public-uri)))
|
:public-uri (str @cf/public-uri)))
|
||||||
|
|
||||||
|
|
|
@ -1318,7 +1318,6 @@
|
||||||
(watch [_ _ _]
|
(watch [_ _ _]
|
||||||
(try
|
(try
|
||||||
(let [clipboard-str (wapi/read-from-clipboard)
|
(let [clipboard-str (wapi/read-from-clipboard)
|
||||||
|
|
||||||
paste-transit-str
|
paste-transit-str
|
||||||
(->> clipboard-str
|
(->> clipboard-str
|
||||||
(rx/filter t/transit?)
|
(rx/filter t/transit?)
|
||||||
|
@ -1578,6 +1577,19 @@
|
||||||
{:type "root"
|
{:type "root"
|
||||||
:children [{:type "paragraph-set" :children paragraphs}]}))
|
:children [{:type "paragraph-set" :children paragraphs}]}))
|
||||||
|
|
||||||
|
(defn calculate-paste-position [state]
|
||||||
|
(cond
|
||||||
|
;; Pasting inside a frame
|
||||||
|
(selected-frame? state)
|
||||||
|
(let [page-selected (wsh/lookup-selected state)
|
||||||
|
page-objects (wsh/lookup-page-objects state)
|
||||||
|
frame-id (first page-selected)
|
||||||
|
frame-object (get page-objects frame-id)]
|
||||||
|
(gsh/center-shape frame-object))
|
||||||
|
|
||||||
|
:else
|
||||||
|
(deref ms/mouse-position)))
|
||||||
|
|
||||||
(defn paste-text
|
(defn paste-text
|
||||||
[text]
|
[text]
|
||||||
(us/assert! (string? text) "expected string as first argument")
|
(us/assert! (string? text) "expected string as first argument")
|
||||||
|
@ -1585,28 +1597,23 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(let [id (uuid/next)
|
(let [id (uuid/next)
|
||||||
{:keys [x y]} @ms/mouse-position
|
|
||||||
width (max 8 (min (* 7 (count text)) 700))
|
width (max 8 (min (* 7 (count text)) 700))
|
||||||
height 16
|
height 16
|
||||||
page-id (:current-page-id state)
|
{:keys [x y]} (calculate-paste-position state)
|
||||||
frame-id (-> (wsh/lookup-page-objects state page-id)
|
|
||||||
(ctst/top-nested-frame @ms/mouse-position))
|
shape {:id id
|
||||||
shape (cts/setup-rect-selrect
|
|
||||||
{:id id
|
|
||||||
:type :text
|
:type :text
|
||||||
:name "Text"
|
:name "Text"
|
||||||
:x x
|
:x x
|
||||||
:y y
|
:y y
|
||||||
:frame-id frame-id
|
|
||||||
:width width
|
:width width
|
||||||
:height height
|
:height height
|
||||||
:grow-type (if (> (count text) 100) :auto-height :auto-width)
|
:grow-type (if (> (count text) 100) :auto-height :auto-width)
|
||||||
:content (as-content text)})
|
:content (as-content text)}]
|
||||||
undo-id (uuid/next)]
|
|
||||||
(rx/of (dwu/start-undo-transaction undo-id)
|
(rx/of (dwu/start-undo-transaction)
|
||||||
(dws/deselect-all)
|
(dwsh/create-and-add-shape :text x y shape)
|
||||||
(dwsh/add-shape shape)
|
(dwu/commit-undo-transaction))))))
|
||||||
(dwu/commit-undo-transaction undo-id))))))
|
|
||||||
|
|
||||||
;; TODO: why not implement it in terms of upload-media-workspace?
|
;; TODO: why not implement it in terms of upload-media-workspace?
|
||||||
(defn- paste-svg
|
(defn- paste-svg
|
||||||
|
@ -1615,7 +1622,7 @@
|
||||||
(ptk/reify ::paste-svg
|
(ptk/reify ::paste-svg
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(let [position (deref ms/mouse-position)
|
(let [position (calculate-paste-position state)
|
||||||
file-id (:current-file-id state)]
|
file-id (:current-file-id state)]
|
||||||
(->> (dwm/svg->clj ["svg" text])
|
(->> (dwm/svg->clj ["svg" text])
|
||||||
(rx/map #(dwm/svg-uploaded % file-id position)))))))
|
(rx/map #(dwm/svg-uploaded % file-id position)))))))
|
||||||
|
@ -1626,9 +1633,10 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(let [file-id (get-in state [:workspace-file :id])
|
(let [file-id (get-in state [:workspace-file :id])
|
||||||
|
position (calculate-paste-position state)
|
||||||
params {:file-id file-id
|
params {:file-id file-id
|
||||||
:blobs [image]
|
:blobs [image]
|
||||||
:position @ms/mouse-position}]
|
:position position}]
|
||||||
(rx/of (dwm/upload-media-workspace params))))))
|
(rx/of (dwm/upload-media-workspace params))))))
|
||||||
|
|
||||||
(defn toggle-distances-display [value]
|
(defn toggle-distances-display [value]
|
||||||
|
|
|
@ -327,10 +327,15 @@
|
||||||
page-id (:current-page-id state)
|
page-id (:current-page-id state)
|
||||||
frame-id (-> (wsh/lookup-page-objects state page-id)
|
frame-id (-> (wsh/lookup-page-objects state page-id)
|
||||||
(ctst/top-nested-frame {:x frame-x :y frame-y}))
|
(ctst/top-nested-frame {:x frame-x :y frame-y}))
|
||||||
|
page-objects (wsh/lookup-page-objects state)
|
||||||
|
page-selected (wsh/lookup-selected state)
|
||||||
|
base (cph/get-base-shape page-objects page-selected)
|
||||||
|
parent-id (:parent-id base)
|
||||||
|
|
||||||
shape (-> (cts/make-minimal-shape type)
|
shape (-> (cts/make-minimal-shape type)
|
||||||
(merge data)
|
(merge data)
|
||||||
(merge {:x x :y y})
|
(merge {:x x :y y})
|
||||||
(assoc :frame-id frame-id)
|
(assoc :frame-id frame-id :parent-id parent-id)
|
||||||
(cts/setup-rect-selrect))]
|
(cts/setup-rect-selrect))]
|
||||||
(rx/of (add-shape shape))))))
|
(rx/of (add-shape shape))))))
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
[app.common.pages.changes-builder :as pcb]
|
[app.common.pages.changes-builder :as pcb]
|
||||||
|
[app.common.pages.helpers :as cph]
|
||||||
[app.common.spec :refer [max-safe-int min-safe-int]]
|
[app.common.spec :refer [max-safe-int min-safe-int]]
|
||||||
[app.common.types.shape :as cts]
|
[app.common.types.shape :as cts]
|
||||||
[app.common.types.shape-tree :as ctst]
|
[app.common.types.shape-tree :as ctst]
|
||||||
|
@ -186,12 +187,13 @@
|
||||||
(assoc :x offset-x :y offset-y)))
|
(assoc :x offset-x :y offset-y)))
|
||||||
(cts/setup-rect-selrect))))
|
(cts/setup-rect-selrect))))
|
||||||
|
|
||||||
(defn create-svg-root [frame-id svg-data]
|
(defn create-svg-root [frame-id parent-id svg-data]
|
||||||
(let [{:keys [name x y width height offset-x offset-y]} svg-data]
|
(let [{:keys [name x y width height offset-x offset-y]} svg-data]
|
||||||
(-> {:id (uuid/next)
|
(-> {:id (uuid/next)
|
||||||
:type :group
|
:type :group
|
||||||
:name name
|
:name name
|
||||||
:frame-id frame-id
|
:frame-id frame-id
|
||||||
|
:parent-id parent-id
|
||||||
:width width
|
:width width
|
||||||
:height height
|
:height height
|
||||||
:x (+ x offset-x)
|
:x (+ x offset-x)
|
||||||
|
@ -476,7 +478,7 @@
|
||||||
(rx/reduce (fn [acc [url image]] (assoc acc url image)) {})))
|
(rx/reduce (fn [acc [url image]] (assoc acc url image)) {})))
|
||||||
|
|
||||||
(defn create-svg-shapes
|
(defn create-svg-shapes
|
||||||
[svg-data {:keys [x y] :as position} objects frame-id selected center?]
|
[svg-data {:keys [x y] :as position} objects frame-id parent-id selected center?]
|
||||||
(try
|
(try
|
||||||
(let [[vb-x vb-y vb-width vb-height] (svg-dimensions svg-data)
|
(let [[vb-x vb-y vb-width vb-height] (svg-dimensions svg-data)
|
||||||
x (if center?
|
x (if center?
|
||||||
|
@ -507,7 +509,7 @@
|
||||||
|
|
||||||
svg-data (assoc svg-data :defs def-nodes)
|
svg-data (assoc svg-data :defs def-nodes)
|
||||||
|
|
||||||
root-shape (create-svg-root frame-id svg-data)
|
root-shape (create-svg-root frame-id parent-id svg-data)
|
||||||
root-id (:id root-shape)
|
root-id (:id root-shape)
|
||||||
|
|
||||||
;; In penpot groups have the size of their children. To respect the imported svg size and empty space let's create a transparent shape as background to respect the imported size
|
;; In penpot groups have the size of their children. To respect the imported svg size and empty space let's create a transparent shape as background to respect the imported size
|
||||||
|
@ -553,10 +555,13 @@
|
||||||
objects (wsh/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
frame-id (ctst/top-nested-frame objects position)
|
frame-id (ctst/top-nested-frame objects position)
|
||||||
selected (wsh/lookup-selected state)
|
selected (wsh/lookup-selected state)
|
||||||
|
page-objects (wsh/lookup-page-objects state)
|
||||||
|
page-selected (wsh/lookup-selected state)
|
||||||
|
base (cph/get-base-shape page-objects page-selected)
|
||||||
|
parent-id (:parent-id base)
|
||||||
|
|
||||||
[new-shape new-children]
|
[new-shape new-children]
|
||||||
(create-svg-shapes svg-data position objects frame-id selected true)
|
(create-svg-shapes svg-data position objects frame-id parent-id selected true)
|
||||||
|
|
||||||
changes (-> (pcb/empty-changes it page-id)
|
changes (-> (pcb/empty-changes it page-id)
|
||||||
(pcb/with-objects objects)
|
(pcb/with-objects objects)
|
||||||
(pcb/add-object new-shape))
|
(pcb/add-object new-shape))
|
||||||
|
@ -579,4 +584,3 @@
|
||||||
|
|
||||||
(rx/of (dch/commit-changes changes)
|
(rx/of (dch/commit-changes changes)
|
||||||
(dws/select-shapes (d/ordered-set (:id new-shape))))))))
|
(dws/select-shapes (d/ordered-set (:id new-shape))))))))
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,7 @@
|
||||||
(if-let [enabled-features @cfg/features]
|
(if-let [enabled-features @cfg/features]
|
||||||
(doseq [f enabled-features]
|
(doseq [f enabled-features]
|
||||||
(toggle-feature! f))
|
(toggle-feature! f))
|
||||||
|
|
||||||
(when *assert*
|
(when *assert*
|
||||||
;; By default, all features disabled, except in development
|
;; By default, all features disabled, except in development
|
||||||
;; environment, that are enabled except components-v2
|
;; environment, that are enabled except components-v2
|
||||||
|
|
Loading…
Add table
Reference in a new issue