瀏覽代碼

improve(plugin): add api of query element rect data from host

charlie 3 年之前
父節點
當前提交
2b826f17de
共有 3 個文件被更改,包括 14 次插入1 次删除
  1. 8 0
      libs/src/LSPlugin.ts
  2. 0 0
      resources/js/lsplugin.core.js
  3. 6 1
      src/main/logseq/api.cljs

+ 8 - 0
libs/src/LSPlugin.ts

@@ -360,10 +360,18 @@ export interface IAppProxy {
 
   // ui
   queryElementById: (id: string) => Promise<string | boolean>
+  queryElementRect: (selector: string) => Promise<DOMRectReadOnly | null>
+
+  /**
+   * @deprecated
+   * @param content
+   * @param status
+   */
   showMsg: (
     content: string,
     status?: 'success' | 'warning' | 'error' | string
   ) => void
+  
   setZoomFactor: (factor: number) => void
   setFullScreen: (flag: boolean | 'toggle') => void
   setLeftSidebarVisible: (flag: boolean | 'toggle') => void

File diff suppressed because it is too large
+ 0 - 0
resources/js/lsplugin.core.js


+ 6 - 1
src/main/logseq/api.cljs

@@ -796,9 +796,14 @@
 ;; helpers
 (defn ^:export query_element_by_id
   [id]
-  (let [^js el (gdom/getElement id)]
+  (when-let [^js el (gdom/getElement id)]
     (if el (str (.-tagName el) "#" id) false)))
 
+(defn ^:export query_element_rect
+  [selector]
+  (when-let [^js el (js/document.querySelector selector)]
+    (bean/->js (.toJSON (.getBoundingClientRect el)))))
+
 (defn ^:export set_focused_settings
   [pid]
   (when-let [plugin (state/get-plugin-by-id pid)]

Some files were not shown because too many files changed in this diff