mirror of
https://github.com/penpot/penpot.git
synced 2025-01-23 23:18:48 -05:00
✨ Add undo block api to plugins
This commit is contained in:
parent
aa90232bf9
commit
60c63e4558
2 changed files with 55 additions and 1 deletions
|
@ -30,6 +30,7 @@
|
||||||
[app.plugins.file :as file]
|
[app.plugins.file :as file]
|
||||||
[app.plugins.fonts :as fonts]
|
[app.plugins.fonts :as fonts]
|
||||||
[app.plugins.format :as format]
|
[app.plugins.format :as format]
|
||||||
|
[app.plugins.history :as history]
|
||||||
[app.plugins.library :as library]
|
[app.plugins.library :as library]
|
||||||
[app.plugins.page :as page]
|
[app.plugins.page :as page]
|
||||||
[app.plugins.parser :as parser]
|
[app.plugins.parser :as parser]
|
||||||
|
@ -394,4 +395,5 @@
|
||||||
{:name "currentUser" :get #(.getCurrentUser ^js %)}
|
{:name "currentUser" :get #(.getCurrentUser ^js %)}
|
||||||
{:name "activeUsers" :get #(.getActiveUsers ^js %)}
|
{:name "activeUsers" :get #(.getActiveUsers ^js %)}
|
||||||
{:name "fonts" :get (fn [_] (fonts/fonts-subcontext plugin-id))}
|
{:name "fonts" :get (fn [_] (fonts/fonts-subcontext plugin-id))}
|
||||||
{:name "library" :get (fn [_] (library/library-subcontext plugin-id))}))
|
{:name "library" :get (fn [_] (library/library-subcontext plugin-id))}
|
||||||
|
{:name "history" :get (fn [_] (history/history-subcontext plugin-id))}))
|
||||||
|
|
52
frontend/src/app/plugins/history.cljs
Normal file
52
frontend/src/app/plugins/history.cljs
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
;; 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.history
|
||||||
|
(:require
|
||||||
|
[app.common.record :as crc]
|
||||||
|
[app.main.data.workspace.undo :as dwu]
|
||||||
|
[app.main.store :as st]
|
||||||
|
[app.plugins.register :as r]
|
||||||
|
[app.plugins.utils :as u]))
|
||||||
|
|
||||||
|
(deftype HistorySubcontext [$plugin]
|
||||||
|
Object
|
||||||
|
(undoBlockBegin
|
||||||
|
[_]
|
||||||
|
(cond
|
||||||
|
(not (r/check-permission $plugin "content:write"))
|
||||||
|
(u/display-not-valid :resize "Plugin doesn't have 'content:write' permission")
|
||||||
|
|
||||||
|
:else
|
||||||
|
(let [id (js/Symbol)]
|
||||||
|
(st/emit! (dwu/start-undo-transaction id))
|
||||||
|
id)))
|
||||||
|
|
||||||
|
(undoBlockFinish
|
||||||
|
[_ block-id]
|
||||||
|
(cond
|
||||||
|
(not (r/check-permission $plugin "content:write"))
|
||||||
|
(u/display-not-valid :resize "Plugin doesn't have 'content:write' permission")
|
||||||
|
|
||||||
|
(not block-id)
|
||||||
|
(u/display-not-valid :undoBlockFinish block-id)
|
||||||
|
|
||||||
|
:else
|
||||||
|
(st/emit! (dwu/commit-undo-transaction block-id)))))
|
||||||
|
|
||||||
|
(crc/define-properties!
|
||||||
|
HistorySubcontext
|
||||||
|
{:name js/Symbol.toStringTag
|
||||||
|
:get (fn [] (str "HistorySubcontext"))})
|
||||||
|
|
||||||
|
(defn history-subcontext? [p]
|
||||||
|
(instance? HistorySubcontext p))
|
||||||
|
|
||||||
|
(defn history-subcontext
|
||||||
|
[plugin-id]
|
||||||
|
(HistorySubcontext. plugin-id))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue