mirror of
https://github.com/penpot/penpot.git
synced 2026-03-28 14:20:27 +01:00
81 lines
1.8 KiB
Clojure
81 lines
1.8 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) UXBOX Labs SL
|
|
|
|
(ns app.main.data.modal
|
|
(:refer-clojure :exclude [update])
|
|
(:require
|
|
[app.common.uuid :as uuid]
|
|
[app.main.store :as st]
|
|
[cljs.core :as c]
|
|
[potok.core :as ptk]))
|
|
|
|
(defonce components (atom {}))
|
|
|
|
;; TODO: rename `:type` to `:name`
|
|
|
|
(defn show
|
|
([props]
|
|
(show (uuid/next) (:type props) props))
|
|
([type props]
|
|
(show (uuid/next) type props))
|
|
([id type props]
|
|
(ptk/reify ::show-modal
|
|
IDeref
|
|
(-deref [_]
|
|
(merge (dissoc props :type) {:name type}))
|
|
|
|
ptk/UpdateEvent
|
|
(update [_ state]
|
|
(assoc state ::modal {:id id
|
|
:type type
|
|
:props props
|
|
:allow-click-outside false})))))
|
|
|
|
(defn update-props
|
|
([_type props]
|
|
(ptk/reify ::update-modal-props
|
|
ptk/UpdateEvent
|
|
(update [_ state]
|
|
(cond-> state
|
|
(::modal state)
|
|
(update-in [::modal :props] merge props))))))
|
|
|
|
(defn hide
|
|
[]
|
|
(ptk/reify ::hide-modal
|
|
ptk/UpdateEvent
|
|
(update [_ state]
|
|
(dissoc state ::modal))))
|
|
|
|
(defn update
|
|
[options]
|
|
(ptk/reify ::update-modal
|
|
ptk/UpdateEvent
|
|
(update [_ state]
|
|
(cond-> state
|
|
(::modal state)
|
|
(c/update ::modal merge options)))))
|
|
|
|
(defn show!
|
|
[type props]
|
|
(st/emit! (show type props)))
|
|
|
|
(defn update-props!
|
|
[type props]
|
|
(st/emit! (update-props type props)))
|
|
|
|
(defn allow-click-outside!
|
|
[]
|
|
(st/emit! (update {:allow-click-outside true})))
|
|
|
|
(defn disallow-click-outside!
|
|
[]
|
|
(st/emit! (update {:allow-click-outside false})))
|
|
|
|
(defn hide!
|
|
[]
|
|
(st/emit! (hide)))
|