0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-08 16:00:19 -05:00

Add undo block api to plugins

This commit is contained in:
alonso.torres 2024-07-26 12:08:54 +02:00
parent aa90232bf9
commit 60c63e4558
2 changed files with 55 additions and 1 deletions

View file

@ -30,6 +30,7 @@
[app.plugins.file :as file]
[app.plugins.fonts :as fonts]
[app.plugins.format :as format]
[app.plugins.history :as history]
[app.plugins.library :as library]
[app.plugins.page :as page]
[app.plugins.parser :as parser]
@ -394,4 +395,5 @@
{:name "currentUser" :get #(.getCurrentUser ^js %)}
{:name "activeUsers" :get #(.getActiveUsers ^js %)}
{: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))}))

View 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))