diff --git a/frontend/src/app/plugins/api.cljs b/frontend/src/app/plugins/api.cljs index dc1eed755..cefacb0af 100644 --- a/frontend/src/app/plugins/api.cljs +++ b/frontend/src/app/plugins/api.cljs @@ -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))})) diff --git a/frontend/src/app/plugins/history.cljs b/frontend/src/app/plugins/history.cljs new file mode 100644 index 000000000..decc741a8 --- /dev/null +++ b/frontend/src/app/plugins/history.cljs @@ -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)) + +