mirror of
https://github.com/penpot/penpot.git
synced 2025-01-23 23:18:48 -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]
|
||||
[cuerdas.core :as str]))
|
||||
|
||||
;; --- Auxiliary Functions
|
||||
(set! *assert* js/goog.DEBUG)
|
||||
|
||||
;; --- Auxiliar Functions
|
||||
|
||||
(s/def ::platform #{:windows :linux :macos :other})
|
||||
(s/def ::browser #{:chrome :firefox :safari :edge :other})
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
(when (= :browser @cf/target)
|
||||
(log/info :message "Welcome to penpot"
|
||||
:version (:full @cf/version)
|
||||
:asserts *assert*
|
||||
:build-date cf/build-date
|
||||
:public-uri (str @cf/public-uri)))
|
||||
|
||||
|
|
|
@ -1318,7 +1318,6 @@
|
|||
(watch [_ _ _]
|
||||
(try
|
||||
(let [clipboard-str (wapi/read-from-clipboard)
|
||||
|
||||
paste-transit-str
|
||||
(->> clipboard-str
|
||||
(rx/filter t/transit?)
|
||||
|
@ -1578,6 +1577,19 @@
|
|||
{:type "root"
|
||||
: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
|
||||
[text]
|
||||
(us/assert! (string? text) "expected string as first argument")
|
||||
|
@ -1585,28 +1597,23 @@
|
|||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [id (uuid/next)
|
||||
{:keys [x y]} @ms/mouse-position
|
||||
width (max 8 (min (* 7 (count text)) 700))
|
||||
height 16
|
||||
page-id (:current-page-id state)
|
||||
frame-id (-> (wsh/lookup-page-objects state page-id)
|
||||
(ctst/top-nested-frame @ms/mouse-position))
|
||||
shape (cts/setup-rect-selrect
|
||||
{:id id
|
||||
:type :text
|
||||
:name "Text"
|
||||
:x x
|
||||
:y y
|
||||
:frame-id frame-id
|
||||
:width width
|
||||
:height height
|
||||
:grow-type (if (> (count text) 100) :auto-height :auto-width)
|
||||
:content (as-content text)})
|
||||
undo-id (uuid/next)]
|
||||
(rx/of (dwu/start-undo-transaction undo-id)
|
||||
(dws/deselect-all)
|
||||
(dwsh/add-shape shape)
|
||||
(dwu/commit-undo-transaction undo-id))))))
|
||||
{:keys [x y]} (calculate-paste-position state)
|
||||
|
||||
shape {:id id
|
||||
:type :text
|
||||
:name "Text"
|
||||
:x x
|
||||
:y y
|
||||
:width width
|
||||
:height height
|
||||
:grow-type (if (> (count text) 100) :auto-height :auto-width)
|
||||
:content (as-content text)}]
|
||||
|
||||
(rx/of (dwu/start-undo-transaction)
|
||||
(dwsh/create-and-add-shape :text x y shape)
|
||||
(dwu/commit-undo-transaction))))))
|
||||
|
||||
;; TODO: why not implement it in terms of upload-media-workspace?
|
||||
(defn- paste-svg
|
||||
|
@ -1615,7 +1622,7 @@
|
|||
(ptk/reify ::paste-svg
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [position (deref ms/mouse-position)
|
||||
(let [position (calculate-paste-position state)
|
||||
file-id (:current-file-id state)]
|
||||
(->> (dwm/svg->clj ["svg" text])
|
||||
(rx/map #(dwm/svg-uploaded % file-id position)))))))
|
||||
|
@ -1626,9 +1633,10 @@
|
|||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [file-id (get-in state [:workspace-file :id])
|
||||
position (calculate-paste-position state)
|
||||
params {:file-id file-id
|
||||
:blobs [image]
|
||||
:position @ms/mouse-position}]
|
||||
:position position}]
|
||||
(rx/of (dwm/upload-media-workspace params))))))
|
||||
|
||||
(defn toggle-distances-display [value]
|
||||
|
|
|
@ -327,10 +327,15 @@
|
|||
page-id (:current-page-id state)
|
||||
frame-id (-> (wsh/lookup-page-objects state page-id)
|
||||
(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)
|
||||
(merge data)
|
||||
(merge {:x x :y y})
|
||||
(assoc :frame-id frame-id)
|
||||
(assoc :frame-id frame-id :parent-id parent-id)
|
||||
(cts/setup-rect-selrect))]
|
||||
(rx/of (add-shape shape))))))
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
[app.common.geom.point :as gpt]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[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.types.shape :as cts]
|
||||
[app.common.types.shape-tree :as ctst]
|
||||
|
@ -186,12 +187,13 @@
|
|||
(assoc :x offset-x :y offset-y)))
|
||||
(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]
|
||||
(-> {:id (uuid/next)
|
||||
:type :group
|
||||
:name name
|
||||
:frame-id frame-id
|
||||
:parent-id parent-id
|
||||
:width width
|
||||
:height height
|
||||
:x (+ x offset-x)
|
||||
|
@ -476,7 +478,7 @@
|
|||
(rx/reduce (fn [acc [url image]] (assoc acc url image)) {})))
|
||||
|
||||
(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
|
||||
(let [[vb-x vb-y vb-width vb-height] (svg-dimensions svg-data)
|
||||
x (if center?
|
||||
|
@ -507,7 +509,7 @@
|
|||
|
||||
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)
|
||||
|
||||
;; 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,19 +555,22 @@
|
|||
objects (wsh/lookup-page-objects state page-id)
|
||||
frame-id (ctst/top-nested-frame objects position)
|
||||
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]
|
||||
(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)
|
||||
(pcb/with-objects objects)
|
||||
(pcb/add-object new-shape))
|
||||
|
||||
changes
|
||||
(reduce (fn [changes [index new-child]]
|
||||
(-> changes
|
||||
(pcb/add-object new-child)
|
||||
(pcb/change-parent (:parent-id new-child) [new-child] index)))
|
||||
(-> changes
|
||||
(pcb/add-object new-child)
|
||||
(pcb/change-parent (:parent-id new-child) [new-child] index)))
|
||||
changes
|
||||
(d/enumerate new-children))
|
||||
|
||||
|
@ -579,4 +584,3 @@
|
|||
|
||||
(rx/of (dch/commit-changes changes)
|
||||
(dws/select-shapes (d/ordered-set (:id new-shape))))))))
|
||||
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
(if-let [enabled-features @cfg/features]
|
||||
(doseq [f enabled-features]
|
||||
(toggle-feature! f))
|
||||
|
||||
(when *assert*
|
||||
;; By default, all features disabled, except in development
|
||||
;; environment, that are enabled except components-v2
|
||||
|
|
Loading…
Add table
Reference in a new issue