mirror of
https://github.com/penpot/penpot.git
synced 2025-01-24 07:29:08 -05:00
✨ Update content of path shapes in plugins
This commit is contained in:
parent
bf66e12075
commit
98c550b20e
3 changed files with 125 additions and 95 deletions
|
@ -93,7 +93,7 @@
|
|||
(let [page-id (:current-page-id state)
|
||||
objects (wsh/lookup-page-objects state)
|
||||
name (-> bool-type d/name str/capital)
|
||||
ids (->> (d/nilv ids (wsh/lookup-selected state))
|
||||
ids (->> (or ids (wsh/lookup-selected state))
|
||||
(cph/clean-loops objects))
|
||||
ordered-indexes (cph/order-by-indexed-shapes objects ids)
|
||||
shapes (->> ordered-indexes
|
||||
|
|
|
@ -274,7 +274,7 @@
|
|||
(watch [it state _]
|
||||
(let [page-id (:current-page-id state)
|
||||
objects (wsh/lookup-page-objects state page-id)
|
||||
selected (->> (d/nilv ids (wsh/lookup-selected state))
|
||||
selected (->> (or ids (wsh/lookup-selected state))
|
||||
(cfh/clean-loops objects)
|
||||
(remove #(ctn/has-any-copy-parent? objects (get objects %))))
|
||||
shapes (shapes-for-grouping objects selected)
|
||||
|
|
|
@ -10,8 +10,11 @@
|
|||
[app.common.colors :as clr]
|
||||
[app.common.data :as d]
|
||||
[app.common.files.helpers :as cfh]
|
||||
[app.common.geom.rect :as grc]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.record :as crc]
|
||||
[app.common.spec :as us]
|
||||
[app.common.svg.path.legacy-parser2 :as spp]
|
||||
[app.common.text :as txt]
|
||||
[app.common.types.shape :as cts]
|
||||
[app.common.types.shape.layout :as ctl]
|
||||
|
@ -26,13 +29,30 @@
|
|||
[app.main.store :as st]
|
||||
[app.plugins.flex :as flex]
|
||||
[app.plugins.grid :as grid]
|
||||
[app.plugins.utils :as utils :refer [locate-objects locate-shape proxy->shape array-to-js]]
|
||||
[app.plugins.utils :as u]
|
||||
[app.util.object :as obj]
|
||||
[app.util.path.format :as upf]
|
||||
[app.util.text-editor :as ted]))
|
||||
|
||||
(declare shape-proxy)
|
||||
|
||||
(defn parse-command
|
||||
[entry]
|
||||
(update entry
|
||||
:command
|
||||
#(case %
|
||||
"M" :move-to
|
||||
"Z" :close-path
|
||||
"L" :line-to
|
||||
"H" :line-to-horizontal
|
||||
"V" :line-to-vertical
|
||||
"C" :curve-to
|
||||
"S" :smooth-curve-to
|
||||
"Q" :quadratic-bezier-curve-to
|
||||
"T" :smooth-quadratic-bezier-curve-to
|
||||
"A" :elliptical-arc
|
||||
(keyword %))))
|
||||
|
||||
(defn text-props
|
||||
[shape]
|
||||
(d/merge
|
||||
|
@ -60,68 +80,68 @@
|
|||
;; Only for frames + groups + booleans
|
||||
(getChildren
|
||||
[_]
|
||||
(let [shape (locate-shape $file $page $id)]
|
||||
(let [shape (u/locate-shape $file $page $id)]
|
||||
(if (or (cfh/frame-shape? shape) (cfh/group-shape? shape) (cfh/svg-raw-shape? shape) (cfh/bool-shape? shape))
|
||||
(apply array (->> (locate-shape $file $page $id)
|
||||
(apply array (->> (u/locate-shape $file $page $id)
|
||||
:shapes
|
||||
(map #(shape-proxy $file $page %))))
|
||||
(utils/display-not-valid :getChildren (:type shape)))))
|
||||
(u/display-not-valid :getChildren (:type shape)))))
|
||||
|
||||
(appendChild
|
||||
[_ child]
|
||||
(let [shape (locate-shape $file $page $id)]
|
||||
(let [shape (u/locate-shape $file $page $id)]
|
||||
(if (or (cfh/frame-shape? shape) (cfh/group-shape? shape) (cfh/svg-raw-shape? shape) (cfh/bool-shape? shape))
|
||||
(let [child-id (obj/get child "$id")]
|
||||
(st/emit! (udw/relocate-shapes #{child-id} $id 0)))
|
||||
(utils/display-not-valid :appendChild (:type shape)))))
|
||||
(u/display-not-valid :appendChild (:type shape)))))
|
||||
|
||||
(insertChild
|
||||
[_ index child]
|
||||
(let [shape (locate-shape $file $page $id)]
|
||||
(let [shape (u/locate-shape $file $page $id)]
|
||||
(if (or (cfh/frame-shape? shape) (cfh/group-shape? shape) (cfh/svg-raw-shape? shape) (cfh/bool-shape? shape))
|
||||
(let [child-id (obj/get child "$id")]
|
||||
(st/emit! (udw/relocate-shapes #{child-id} $id index)))
|
||||
(utils/display-not-valid :insertChild (:type shape)))))
|
||||
(u/display-not-valid :insertChild (:type shape)))))
|
||||
|
||||
;; Only for frames
|
||||
(addFlexLayout
|
||||
[_]
|
||||
(let [shape (locate-shape $file $page $id)]
|
||||
(let [shape (u/locate-shape $file $page $id)]
|
||||
(if (cfh/frame-shape? shape)
|
||||
(do (st/emit! (dwsl/create-layout-from-id $id :flex :from-frame? true :calculate-params? false))
|
||||
(grid/grid-layout-proxy $file $page $id))
|
||||
(utils/display-not-valid :addFlexLayout (:type shape)))))
|
||||
(u/display-not-valid :addFlexLayout (:type shape)))))
|
||||
|
||||
(addGridLayout
|
||||
[_]
|
||||
(let [shape (locate-shape $file $page $id)]
|
||||
(let [shape (u/locate-shape $file $page $id)]
|
||||
(if (cfh/frame-shape? shape)
|
||||
(do (st/emit! (dwsl/create-layout-from-id $id :grid :from-frame? true :calculate-params? false))
|
||||
(grid/grid-layout-proxy $file $page $id))
|
||||
(utils/display-not-valid :addGridLayout (:type shape)))))
|
||||
(u/display-not-valid :addGridLayout (:type shape)))))
|
||||
|
||||
;; Make masks for groups
|
||||
(makeMask
|
||||
[_]
|
||||
(let [shape (locate-shape $file $page $id)]
|
||||
(let [shape (u/locate-shape $file $page $id)]
|
||||
(if (cfh/group-shape? shape)
|
||||
(st/emit! (dwg/mask-group #{$id}))
|
||||
(utils/display-not-valid :makeMask (:type shape)))))
|
||||
(u/display-not-valid :makeMask (:type shape)))))
|
||||
|
||||
(removeMask
|
||||
[_]
|
||||
(let [shape (locate-shape $file $page $id)]
|
||||
(let [shape (u/locate-shape $file $page $id)]
|
||||
(if (cfh/mask-shape? shape)
|
||||
(st/emit! (dwg/unmask-group #{$id}))
|
||||
(utils/display-not-valid :removeMask (:type shape)))))
|
||||
(u/display-not-valid :removeMask (:type shape)))))
|
||||
|
||||
;; Only for path and bool shapes
|
||||
(toD
|
||||
[_]
|
||||
(let [shape (locate-shape $file $page $id)]
|
||||
(let [shape (u/locate-shape $file $page $id)]
|
||||
(if (cfh/path-shape? shape)
|
||||
(upf/format-path (:content shape))
|
||||
(utils/display-not-valid :makeMask (:type shape))))))
|
||||
(u/display-not-valid :makeMask (:type shape))))))
|
||||
|
||||
(crc/define-properties!
|
||||
ShapeProxy
|
||||
|
@ -140,7 +160,7 @@
|
|||
(assert (uuid? page-id))
|
||||
(assert (uuid? id))
|
||||
|
||||
(let [data (locate-shape file-id page-id id)]
|
||||
(let [data (u/locate-shape file-id page-id id)]
|
||||
(-> (ShapeProxy. file-id page-id id)
|
||||
(crc/add-properties!
|
||||
{:name "$id" :enumerable false :get (constantly id)}
|
||||
|
@ -148,37 +168,37 @@
|
|||
{:name "$page" :enumerable false :get (constantly page-id)}
|
||||
|
||||
{:name "id"
|
||||
:get #(-> % proxy->shape :id str)}
|
||||
:get #(-> % u/proxy->shape :id str)}
|
||||
|
||||
{:name "type"
|
||||
:get #(-> % proxy->shape :type name)}
|
||||
:get #(-> % u/proxy->shape :type name)}
|
||||
|
||||
{:name "name"
|
||||
:get #(-> % proxy->shape :name)
|
||||
:get #(-> % u/proxy->shape :name)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsh/update-shapes [id] #(assoc % :name value)))))}
|
||||
|
||||
{:name "blocked"
|
||||
:get #(-> % proxy->shape :blocked boolean)
|
||||
:get #(-> % u/proxy->shape :blocked boolean)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsh/update-shapes [id] #(assoc % :blocked value)))))}
|
||||
|
||||
{:name "hidden"
|
||||
:get #(-> % proxy->shape :hidden boolean)
|
||||
:get #(-> % u/proxy->shape :hidden boolean)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsh/update-shapes [id] #(assoc % :hidden value)))))}
|
||||
|
||||
{:name "proportionLock"
|
||||
:get #(-> % proxy->shape :proportion-lock boolean)
|
||||
:get #(-> % u/proxy->shape :proportion-lock boolean)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsh/update-shapes [id] #(assoc % :proportion-lock value)))))}
|
||||
|
||||
{:name "constraintsHorizontal"
|
||||
:get #(-> % proxy->shape :constraints-h d/name)
|
||||
:get #(-> % u/proxy->shape :constraints-h d/name)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (keyword value)]
|
||||
|
@ -186,7 +206,7 @@
|
|||
(st/emit! (dwsh/update-shapes [id] #(assoc % :constraints-h value))))))}
|
||||
|
||||
{:name "constraintsVertical"
|
||||
:get #(-> % proxy->shape :constraints-v d/name)
|
||||
:get #(-> % u/proxy->shape :constraints-v d/name)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (keyword value)]
|
||||
|
@ -194,64 +214,64 @@
|
|||
(st/emit! (dwsh/update-shapes [id] #(assoc % :constraints-v value))))))}
|
||||
|
||||
{:name "borderRadius"
|
||||
:get #(-> % proxy->shape :rx)
|
||||
:get #(-> % u/proxy->shape :rx)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
shape (proxy->shape self)]
|
||||
shape (u/proxy->shape self)]
|
||||
(when (us/safe-int? value)
|
||||
(when (or (not (ctsr/has-radius? shape)) (ctsr/radius-4? shape))
|
||||
(st/emit! (dwsh/update-shapes [id] ctsr/switch-to-radius-1)))
|
||||
(st/emit! (dwsh/update-shapes [id] #(ctsr/set-radius-1 % value))))))}
|
||||
|
||||
{:name "borderRadiusTopLeft"
|
||||
:get #(-> % proxy->shape :r1)
|
||||
:get #(-> % u/proxy->shape :r1)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
shape (proxy->shape self)]
|
||||
shape (u/proxy->shape self)]
|
||||
(when (us/safe-int? value)
|
||||
(when (or (not (ctsr/has-radius? shape)) (not (ctsr/radius-4? shape)))
|
||||
(st/emit! (dwsh/update-shapes [id] ctsr/switch-to-radius-4)))
|
||||
(st/emit! (dwsh/update-shapes [id] #(ctsr/set-radius-4 % :r1 value))))))}
|
||||
|
||||
{:name "borderRadiusTopRight"
|
||||
:get #(-> % proxy->shape :r2)
|
||||
:get #(-> % u/proxy->shape :r2)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
shape (proxy->shape self)]
|
||||
shape (u/proxy->shape self)]
|
||||
(when (us/safe-int? value)
|
||||
(when (or (not (ctsr/has-radius? shape)) (not (ctsr/radius-4? shape)))
|
||||
(st/emit! (dwsh/update-shapes [id] ctsr/switch-to-radius-4)))
|
||||
(st/emit! (dwsh/update-shapes [id] #(ctsr/set-radius-4 % :r2 value))))))}
|
||||
|
||||
{:name "borderRadiusBottomRight"
|
||||
:get #(-> % proxy->shape :r3)
|
||||
:get #(-> % u/proxy->shape :r3)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
shape (proxy->shape self)]
|
||||
shape (u/proxy->shape self)]
|
||||
(when (us/safe-int? value)
|
||||
(when (or (not (ctsr/has-radius? shape)) (not (ctsr/radius-4? shape)))
|
||||
(st/emit! (dwsh/update-shapes [id] ctsr/switch-to-radius-4)))
|
||||
(st/emit! (dwsh/update-shapes [id] #(ctsr/set-radius-4 % :r3 value))))))}
|
||||
|
||||
{:name "borderRadiusBottomLeft"
|
||||
:get #(-> % proxy->shape :r4)
|
||||
:get #(-> % u/proxy->shape :r4)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
shape (proxy->shape self)]
|
||||
shape (u/proxy->shape self)]
|
||||
(when (us/safe-int? value)
|
||||
(when (or (not (ctsr/has-radius? shape)) (not (ctsr/radius-4? shape)))
|
||||
(st/emit! (dwsh/update-shapes [id] ctsr/switch-to-radius-4)))
|
||||
(st/emit! (dwsh/update-shapes [id] #(ctsr/set-radius-4 % :r4 value))))))}
|
||||
|
||||
{:name "opacity"
|
||||
:get #(-> % proxy->shape :opacity)
|
||||
:get #(-> % u/proxy->shape :opacity)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (and (us/safe-number? value) (>= value 0) (<= value 1))
|
||||
(st/emit! (dwsh/update-shapes [id] #(assoc % :opacity value))))))}
|
||||
|
||||
{:name "blendMode"
|
||||
:get #(-> % proxy->shape :blend-mode (d/nilv :normal) d/name)
|
||||
:get #(-> % u/proxy->shape :blend-mode (d/nilv :normal) d/name)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (keyword value)]
|
||||
|
@ -259,7 +279,7 @@
|
|||
(st/emit! (dwsh/update-shapes [id] #(assoc % :blend-mode value))))))}
|
||||
|
||||
{:name "shadows"
|
||||
:get #(-> % proxy->shape :shadow array-to-js)
|
||||
:get #(-> % u/proxy->shape :shadow u/array-to-js)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (mapv (fn [val]
|
||||
|
@ -273,12 +293,12 @@
|
|||
:blur 4
|
||||
:spread 0
|
||||
:hidden false}
|
||||
(utils/from-js val #{:style :type})))
|
||||
(u/from-js val #{:style :type})))
|
||||
value)]
|
||||
(st/emit! (dwsh/update-shapes [id] #(assoc % :shadow value)))))}
|
||||
|
||||
{:name "blur"
|
||||
:get #(-> % proxy->shape :blur utils/to-js)
|
||||
:get #(-> % u/proxy->shape :blur u/to-js)
|
||||
:set (fn [self value]
|
||||
(if (nil? value)
|
||||
(st/emit! (dwsh/update-shapes [id] #(dissoc % :blur)))
|
||||
|
@ -289,26 +309,26 @@
|
|||
:type :layer-blur
|
||||
:value 4
|
||||
:hidden false}
|
||||
(utils/from-js value))]
|
||||
(u/from-js value))]
|
||||
(st/emit! (dwsh/update-shapes [id] #(assoc % :blur value))))))}
|
||||
|
||||
{:name "exports"
|
||||
:get #(-> % proxy->shape :exports array-to-js)
|
||||
:get #(-> % u/proxy->shape :exports u/array-to-js)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (mapv #(utils/from-js %) value)]
|
||||
value (mapv #(u/from-js %) value)]
|
||||
(st/emit! (dwsh/update-shapes [id] #(assoc % :exports value)))))}
|
||||
|
||||
;; Geometry properties
|
||||
{:name "x"
|
||||
:get #(-> % proxy->shape :x)
|
||||
:get #(-> % u/proxy->shape :x)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (udw/update-position id {:x value}))))}
|
||||
|
||||
{:name "y"
|
||||
:get #(-> % proxy->shape :y)
|
||||
:get #(-> % u/proxy->shape :y)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
|
@ -316,90 +336,90 @@
|
|||
|
||||
{:name "parentX"
|
||||
:get (fn [self]
|
||||
(let [shape (proxy->shape self)
|
||||
(let [shape (u/proxy->shape self)
|
||||
parent-id (:parent-id shape)
|
||||
parent (locate-shape (obj/get self "$file") (obj/get self "$page") parent-id)]
|
||||
parent (u/locate-shape (obj/get self "$file") (obj/get self "$page") parent-id)]
|
||||
(- (:x shape) (:x parent))))
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
parent-id (-> self proxy->shape :parent-id)
|
||||
parent (locate-shape (obj/get self "$file") (obj/get self "$page") parent-id)
|
||||
parent-id (-> self u/proxy->shape :parent-id)
|
||||
parent (u/locate-shape (obj/get self "$file") (obj/get self "$page") parent-id)
|
||||
parent-x (:x parent)]
|
||||
(st/emit! (udw/update-position id {:x (+ parent-x value)}))))}
|
||||
|
||||
{:name "parentY"
|
||||
:get (fn [self]
|
||||
(let [shape (proxy->shape self)
|
||||
(let [shape (u/proxy->shape self)
|
||||
parent-id (:parent-id shape)
|
||||
parent (locate-shape (obj/get self "$file") (obj/get self "$page") parent-id)
|
||||
parent (u/locate-shape (obj/get self "$file") (obj/get self "$page") parent-id)
|
||||
parent-y (:y parent)]
|
||||
(- (:y shape) parent-y)))
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
parent-id (-> self proxy->shape :parent-id)
|
||||
parent (locate-shape (obj/get self "$file") (obj/get self "$page") parent-id)
|
||||
parent-id (-> self u/proxy->shape :parent-id)
|
||||
parent (u/locate-shape (obj/get self "$file") (obj/get self "$page") parent-id)
|
||||
parent-y (:y parent)]
|
||||
(st/emit! (udw/update-position id {:y (+ parent-y value)}))))}
|
||||
|
||||
{:name "frameX"
|
||||
:get (fn [self]
|
||||
(let [shape (proxy->shape self)
|
||||
(let [shape (u/proxy->shape self)
|
||||
frame-id (:parent-id shape)
|
||||
frame (locate-shape (obj/get self "$file") (obj/get self "$page") frame-id)
|
||||
frame (u/locate-shape (obj/get self "$file") (obj/get self "$page") frame-id)
|
||||
frame-x (:x frame)]
|
||||
(- (:x shape) frame-x)))
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
frame-id (-> self proxy->shape :frame-id)
|
||||
frame (locate-shape (obj/get self "$file") (obj/get self "$page") frame-id)
|
||||
frame-id (-> self u/proxy->shape :frame-id)
|
||||
frame (u/locate-shape (obj/get self "$file") (obj/get self "$page") frame-id)
|
||||
frame-x (:x frame)]
|
||||
(st/emit! (udw/update-position id {:x (+ frame-x value)}))))}
|
||||
|
||||
{:name "frameY"
|
||||
:get (fn [self]
|
||||
(let [shape (proxy->shape self)
|
||||
(let [shape (u/proxy->shape self)
|
||||
frame-id (:parent-id shape)
|
||||
frame (locate-shape (obj/get self "$file") (obj/get self "$page") frame-id)
|
||||
frame (u/locate-shape (obj/get self "$file") (obj/get self "$page") frame-id)
|
||||
frame-y (:y frame)]
|
||||
(- (:y shape) frame-y)))
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
frame-id (-> self proxy->shape :frame-id)
|
||||
frame (locate-shape (obj/get self "$file") (obj/get self "$page") frame-id)
|
||||
frame-id (-> self u/proxy->shape :frame-id)
|
||||
frame (u/locate-shape (obj/get self "$file") (obj/get self "$page") frame-id)
|
||||
frame-y (:y frame)]
|
||||
(st/emit! (udw/update-position id {:y (+ frame-y value)}))))}
|
||||
|
||||
{:name "width"
|
||||
:get #(-> % proxy->shape :width)}
|
||||
:get #(-> % u/proxy->shape :width)}
|
||||
|
||||
{:name "height"
|
||||
:get #(-> % proxy->shape :height)}
|
||||
:get #(-> % u/proxy->shape :height)}
|
||||
|
||||
{:name "flipX"
|
||||
:get #(-> % proxy->shape :flip-x)}
|
||||
:get #(-> % u/proxy->shape :flip-x)}
|
||||
|
||||
{:name "flipY"
|
||||
:get #(-> % proxy->shape :flip-y)}
|
||||
:get #(-> % u/proxy->shape :flip-y)}
|
||||
|
||||
;; Strokes and fills
|
||||
{:name "fills"
|
||||
:get #(if (cfh/text-shape? data)
|
||||
(-> % proxy->shape text-props :fills array-to-js)
|
||||
(-> % proxy->shape :fills array-to-js))
|
||||
(-> % u/proxy->shape text-props :fills u/array-to-js)
|
||||
(-> % u/proxy->shape :fills u/array-to-js))
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (mapv #(utils/from-js %) value)]
|
||||
value (mapv #(u/from-js %) value)]
|
||||
(st/emit! (dwsh/update-shapes [id] #(assoc % :fills value)))))}
|
||||
|
||||
{:name "strokes"
|
||||
:get #(-> % proxy->shape :strokes array-to-js)
|
||||
:get #(-> % u/proxy->shape :strokes u/array-to-js)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (mapv #(utils/from-js % #{:stroke-style :stroke-alignment}) value)]
|
||||
value (mapv #(u/from-js % #{:stroke-style :stroke-alignment}) value)]
|
||||
(st/emit! (dwsh/update-shapes [id] #(assoc % :strokes value)))))}
|
||||
|
||||
{:name "layoutChild"
|
||||
|
@ -408,7 +428,7 @@
|
|||
(let [file-id (obj/get self "$file")
|
||||
page-id (obj/get self "$page")
|
||||
id (obj/get self "$id")
|
||||
objects (locate-objects file-id page-id)]
|
||||
objects (u/locate-objects file-id page-id)]
|
||||
(when (ctl/any-layout-immediate-child-id? objects id)
|
||||
(flex/layout-child-proxy file-id page-id id))))}
|
||||
|
||||
|
@ -418,7 +438,7 @@
|
|||
(let [file-id (obj/get self "$file")
|
||||
page-id (obj/get self "$page")
|
||||
id (obj/get self "$id")
|
||||
objects (locate-objects file-id page-id)]
|
||||
objects (u/locate-objects file-id page-id)]
|
||||
(when (ctl/grid-layout-immediate-child-id? objects id)
|
||||
(grid/layout-cell-proxy file-id page-id id))))})
|
||||
|
||||
|
@ -433,7 +453,7 @@
|
|||
{:name "grid"
|
||||
:get
|
||||
(fn [self]
|
||||
(let [layout (-> self proxy->shape :layout)
|
||||
(let [layout (-> self u/proxy->shape :layout)
|
||||
file-id (obj/get self "$file")
|
||||
page-id (obj/get self "$page")
|
||||
id (obj/get self "$id")]
|
||||
|
@ -443,7 +463,7 @@
|
|||
{:name "flex"
|
||||
:get
|
||||
(fn [self]
|
||||
(let [layout (-> self proxy->shape :layout)
|
||||
(let [layout (-> self u/proxy->shape :layout)
|
||||
file-id (obj/get self "$file")
|
||||
page-id (obj/get self "$page")
|
||||
id (obj/get self "$id")]
|
||||
|
@ -451,14 +471,14 @@
|
|||
(flex/flex-layout-proxy file-id page-id id))))}
|
||||
|
||||
{:name "guides"
|
||||
:get #(-> % proxy->shape :grids array-to-js)
|
||||
:get #(-> % u/proxy->shape :grids u/array-to-js)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (mapv #(utils/from-js %) value)]
|
||||
value (mapv #(u/from-js %) value)]
|
||||
(st/emit! (dwsh/update-shapes [id] #(assoc % :grids value)))))}
|
||||
|
||||
{:name "horizontalSizing"
|
||||
:get #(-> % proxy->shape :layout-item-h-sizing (d/nilv :fix) d/name)
|
||||
:get #(-> % u/proxy->shape :layout-item-h-sizing (d/nilv :fix) d/name)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
|
@ -467,7 +487,7 @@
|
|||
(st/emit! (dwsl/update-layout #{id} {:layout-item-h-sizing value})))))}
|
||||
|
||||
{:name "verticalSizing"
|
||||
:get #(-> % proxy->shape :layout-item-v-sizing (d/nilv :fix) d/name)
|
||||
:get #(-> % u/proxy->shape :layout-item-v-sizing (d/nilv :fix) d/name)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
|
@ -478,14 +498,14 @@
|
|||
(cond-> (cfh/text-shape? data)
|
||||
(crc/add-properties!
|
||||
{:name "characters"
|
||||
:get #(-> % proxy->shape :content txt/content->text)
|
||||
:get #(-> % u/proxy->shape :content txt/content->text)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
;; The user is currently editing the text. We need to update the
|
||||
;; editor as well
|
||||
(when (contains? (:workspace-editor-state @st/state) id)
|
||||
(let [shape (proxy->shape self)
|
||||
(let [shape (u/proxy->shape self)
|
||||
editor
|
||||
(-> shape
|
||||
(txt/change-text value)
|
||||
|
@ -496,7 +516,7 @@
|
|||
(st/emit! (dwsh/update-shapes [id] #(txt/change-text % value)))))}
|
||||
|
||||
{:name "growType"
|
||||
:get #(-> % proxy->shape :grow-type d/name)
|
||||
:get #(-> % u/proxy->shape :grow-type d/name)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
|
@ -505,63 +525,63 @@
|
|||
(st/emit! (dwsh/update-shapes [id] #(assoc % :grow-type value))))))}
|
||||
|
||||
{:name "fontId"
|
||||
:get #(-> % proxy->shape text-props :font-id)
|
||||
:get #(-> % u/proxy->shape text-props :font-id)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwt/update-attrs id {:font-id value}))))}
|
||||
|
||||
{:name "fontFamily"
|
||||
:get #(-> % proxy->shape text-props :font-family)
|
||||
:get #(-> % u/proxy->shape text-props :font-family)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwt/update-attrs id {:font-id value}))))}
|
||||
|
||||
{:name "fontVariantId"
|
||||
:get #(-> % proxy->shape text-props :font-variant-id)
|
||||
:get #(-> % u/proxy->shape text-props :font-variant-id)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwt/update-attrs id {:font-id value}))))}
|
||||
|
||||
{:name "fontSize"
|
||||
:get #(-> % proxy->shape text-props :font-size)
|
||||
:get #(-> % u/proxy->shape text-props :font-size)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwt/update-attrs id {:font-id value}))))}
|
||||
|
||||
{:name "fontWeight"
|
||||
:get #(-> % proxy->shape text-props :font-weight)
|
||||
:get #(-> % u/proxy->shape text-props :font-weight)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwt/update-attrs id {:font-id value}))))}
|
||||
|
||||
{:name "fontStyle"
|
||||
:get #(-> % proxy->shape text-props :font-style)
|
||||
:get #(-> % u/proxy->shape text-props :font-style)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwt/update-attrs id {:font-style value}))))}
|
||||
|
||||
{:name "lineHeight"
|
||||
:get #(-> % proxy->shape text-props :line-height)
|
||||
:get #(-> % u/proxy->shape text-props :line-height)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwt/update-attrs id {:line-height value}))))}
|
||||
|
||||
{:name "letterSpacing"
|
||||
:get #(-> % proxy->shape text-props :letter-spacing)
|
||||
:get #(-> % u/proxy->shape text-props :letter-spacing)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwt/update-attrs id {:letter-spacing value}))))}
|
||||
|
||||
{:name "textTransform"
|
||||
:get #(-> % proxy->shape text-props :text-transform)
|
||||
:get #(-> % u/proxy->shape text-props :text-transform)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
|
@ -570,4 +590,14 @@
|
|||
(cond-> (or (cfh/path-shape? data) (cfh/bool-shape? data))
|
||||
(crc/add-properties!
|
||||
{:name "content"
|
||||
:get #(-> % proxy->shape :content array-to-js)}))))))
|
||||
:get #(-> % u/proxy->shape :content u/array-to-js)
|
||||
:set
|
||||
(fn [_ value]
|
||||
(let [content
|
||||
(->> value
|
||||
(map u/from-js)
|
||||
(mapv parse-command)
|
||||
(spp/simplify-commands))
|
||||
selrect (gsh/content->selrect content)
|
||||
points (grc/rect->points selrect)]
|
||||
(st/emit! (dwsh/update-shapes [id] (fn [shape] (assoc shape :content content :selrect selrect :points points))))))}))))))
|
||||
|
|
Loading…
Add table
Reference in a new issue