0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-13 10:38:13 -05:00

Experiment for data definition

This commit is contained in:
alonso.torres 2024-04-15 17:48:03 +02:00 committed by Andrey Antukh
parent 127b481c38
commit 432e894344
2 changed files with 43 additions and 17 deletions

View file

@ -49,7 +49,10 @@
new-theme (get-in new-val [:profile :theme])]
(if (identical? old-theme new-theme)
::not-changed
new-theme)))
(if (= new-theme "default")
"dark"
new-theme))))
(defmethod handle-state-change :default
[_ _ _]

View file

@ -8,36 +8,59 @@
"RPC for plugins runtime."
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.record :as crc]
[app.plugins.utils :as utils]
[app.util.object :as obj]
[cuerdas.core :as str]))
(defn- fills
[shape]
(defn- make-fills
[fills]
;; TODO: Transform explicitly?
(apply array
(->> (:fills shape)
(->> fills
(map #(clj->js % {:keyword-fn (fn [k] (str/camel (name k)))})))))
(deftype ShapeProxy
[id
name
type
fills
_data])
(deftype ShapeProxy [_data]
Object
(clone [_] (.log js/console (clj->js _data)))
(delete [_] (.log js/console (clj->js _data)))
(appendChild [_] (.log js/console (clj->js _data))))
(crc/define-properties!
ShapeProxy
{:name js/Symbol.toStringTag
:get (fn [] (str "ShapeProxy"))})
(defn get-data
([this attr]
(-> this
(obj/get "_data")
(get attr)))
([this attr transform-fn]
(-> this
(get-data attr)
(transform-fn))))
(defn data->shape-proxy
[data]
(utils/hide-data!
(->ShapeProxy (dm/str (:id data))
(:name data)
(d/name (:type data))
(fills data)
data)))
(-> (->ShapeProxy data)
(js/Object.defineProperties
#js {"_data" #js {:enumerable false}
:id
#js {:get #(get-data (js* "this") :id str)
:enumerable true}
:name
#js {:get #(get-data (js* "this") :name)
;;:set (fn [] (prn "SET NAME"))
:enumerable true}
:fills
#js {:get #(get-data (js* "this") :fills make-fills)
;;:set (fn [] (prn "SET FILLS"))
:enumerable true}}
)))