mirror of
https://github.com/penpot/penpot.git
synced 2025-07-15 07:05:17 +02:00
✨ Add to plugin api: upload media, group and ungroup
This commit is contained in:
parent
75d8965365
commit
21d38a058b
6 changed files with 148 additions and 51 deletions
|
@ -7,7 +7,13 @@
|
|||
(ns app.plugins.utils
|
||||
"RPC for plugins runtime."
|
||||
(:require
|
||||
[app.util.object :as obj]))
|
||||
[app.common.data.macros :as dm]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.util.object :as obj]
|
||||
[cuerdas.core :as str]))
|
||||
|
||||
(def uuid-regex
|
||||
#"\w{8}-\w{4}-\w{4}-\w{4}-\w{12}")
|
||||
|
||||
(defn get-data
|
||||
([self attr]
|
||||
|
@ -27,4 +33,37 @@
|
|||
(fn [self]
|
||||
(get-data self attr transform-fn))))
|
||||
|
||||
(defn from-js
|
||||
"Converts the object back to js"
|
||||
[obj]
|
||||
(let [ret (js->clj obj {:keyword-fn (fn [k] (str/camel (name k)))})]
|
||||
(reduce-kv
|
||||
(fn [m k v]
|
||||
(let [v (cond (map? v)
|
||||
(from-js v)
|
||||
|
||||
(and (string? v) (re-matches uuid-regex v))
|
||||
(uuid/uuid v)
|
||||
|
||||
:else v)]
|
||||
(assoc m (keyword (str/kebab k)) v)))
|
||||
{}
|
||||
ret)))
|
||||
|
||||
|
||||
(defn to-js
|
||||
"Converts to javascript an camelize the keys"
|
||||
[obj]
|
||||
(let [result
|
||||
(reduce-kv
|
||||
(fn [m k v]
|
||||
(let [v (cond (object? v) (to-js v)
|
||||
(uuid? v) (dm/str v)
|
||||
:else v)]
|
||||
(assoc m (str/camel (name k)) v)))
|
||||
{}
|
||||
obj)]
|
||||
(clj->js result)))
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue