Browse Source

improve(plugin): support slash command hooks

charlie 4 years ago
parent
commit
9b0d5aa50e

+ 6 - 1
src/main/frontend/commands.cljs

@@ -10,6 +10,7 @@
             [goog.object :as gobj]
             [frontend.format :as format]
             [frontend.handler.common :as common-handler]
+            [frontend.handler.plugin :as plugin-handler]
             [frontend.handler.draw :as draw]
             [frontend.handler.notification :as notification]
             [promesa.core :as p]))
@@ -175,7 +176,8 @@
      ]
     (markdown-headings)
     ;; Allow user to modify or extend, should specify how to extend.
-    (state/get-commands))
+    (state/get-commands)
+    (state/get-plugins-commands))
    (remove nil?)
    (util/distinct-by-last-wins first)))
 
@@ -386,6 +388,9 @@
 
 (defmulti handle-step first)
 
+(defmethod handle-step :editor/hook [[_ event {:keys [pid] :as payload}]]
+  (plugin-handler/hook-plugin-editor event payload pid))
+
 (defmethod handle-step :editor/input [[_ value option]]
   (when-let [input-id (state/get-edit-input-id)]
     (insert! input-id value option)))

+ 1 - 2
src/main/frontend/components/header.cljs

@@ -159,8 +159,7 @@
        {:on-double-click (fn [^js e]
                            (when-let [target (.-target e)]
                              (when (and (util/electron?)
-                                        (or (.. target -classList (contains "cp__header"))
-                                            (. target (closest "#search"))))
+                                        (or (.. target -classList (contains "cp__header"))))
                                (js/window.apis.toggleMaxOrMinActiveWindow))))}
        (left-menu-button {:on-click (fn []
                                       (open-fn)

+ 4 - 0
src/main/frontend/components/page.cljs

@@ -14,6 +14,7 @@
             [clojure.string :as string]
             [frontend.components.block :as block]
             [frontend.components.editor :as editor]
+            [frontend.components.plugins :as plugins]
             [frontend.components.reference :as reference]
             [frontend.components.svg :as svg]
             [frontend.components.export :as export]
@@ -359,6 +360,9 @@
                      svg/search]
                     (when (not config/mobile?)
                       (presentation repo page))
+
+                    (plugins/hook-ui-slot :page-file-mounted nil)
+
                     (ui/dropdown-with-links
                       (fn [{:keys [toggle-fn]}]
                         [:a.opacity-30.hover:opacity-100