mirror of
https://github.com/penpot/penpot.git
synced 2026-03-23 20:01:12 +01:00
The main idea behind this, is move all plugin related stuff from app.main.data.plugins into app.plugins.* and make them more consistent. Also the intention that put all plugins related state under specific prefix on the state.
50 lines
1.2 KiB
Clojure
50 lines
1.2 KiB
Clojure
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
;;
|
|
;; Copyright (c) KALEIDOS INC
|
|
|
|
(ns app.plugins.flags
|
|
(:require
|
|
[app.common.data.macros :as dm]
|
|
[app.main.store :as st]
|
|
[app.plugins.utils :as u]
|
|
[app.util.object :as obj]
|
|
[potok.v2.core :as ptk]))
|
|
|
|
(defn natural-child-ordering?
|
|
[plugin-id]
|
|
(boolean
|
|
(dm/get-in @st/state [:plugins :flags plugin-id :natural-child-ordering])))
|
|
|
|
(defn clear
|
|
[id]
|
|
(ptk/reify ::reset
|
|
ptk/UpdateEvent
|
|
(update [_ state]
|
|
(update-in state [:plugins :flags] assoc id {}))))
|
|
|
|
(defn- set-flag
|
|
[id key value]
|
|
(ptk/reify ::set-flag
|
|
ptk/UpdateEvent
|
|
(update [_ state]
|
|
(update-in state [:plugins :flags id] assoc key value))))
|
|
|
|
(defn flags-proxy
|
|
[plugin-id]
|
|
(obj/reify {:name "FlagProxy"}
|
|
:naturalChildOrdering
|
|
{:this false
|
|
:get
|
|
(fn [] (natural-child-ordering? plugin-id))
|
|
|
|
:set
|
|
(fn [value]
|
|
(cond
|
|
(not (boolean? value))
|
|
(u/display-not-valid :naturalChildOrdering value)
|
|
|
|
:else
|
|
(st/emit! (set-flag plugin-id :natural-child-ordering value))))}))
|