improve(plugin): add graph related api & types

pull/1747/head
charlie 2021-06-10 17:39:10 +08:00
parent 6305545f26
commit da1f415af3
5 changed files with 33 additions and 3 deletions

View File

@ -79,6 +79,10 @@ export type BlockUUIDTuple = ['uuid', BlockUUID]
export type IEntityID = { id: BlockID } export type IEntityID = { id: BlockID }
export type IBatchBlock = { content: string, properties?: Record<string, any>, children?: Array<IBatchBlock> } export type IBatchBlock = { content: string, properties?: Record<string, any>, children?: Array<IBatchBlock> }
export interface AppUserInfo {
[key: string]: any
}
/** /**
* User's app configurations * User's app configurations
*/ */
@ -91,6 +95,14 @@ export interface AppUserConfigs {
[key: string]: any [key: string]: any
} }
export interface AppGraphInfo {
name: string
url: string
path: string
[key: string]: any
}
/** /**
* Block - Logseq's fundamental data structure. * Block - Logseq's fundamental data structure.
*/ */
@ -148,7 +160,7 @@ export type BlockCursorPosition = { left: number, top: number, height: number, p
* App level APIs * App level APIs
*/ */
export interface IAppProxy { export interface IAppProxy {
getUserInfo: () => Promise<any> getUserInfo: () => Promise<AppUserInfo | null>
getUserConfigs: () => Promise<AppUserConfigs> getUserConfigs: () => Promise<AppUserConfigs>
@ -156,6 +168,9 @@ export interface IAppProxy {
relaunch: () => Promise<void> relaunch: () => Promise<void>
quit: () => Promise<void> quit: () => Promise<void>
// graph
getCurrentGraph: () => Promise<AppGraphInfo | null>
// router // router
pushState: (k: string, params?: {}) => void pushState: (k: string, params?: {}) => void
replaceState: (k: string, params?: {}) => void replaceState: (k: string, params?: {}) => void
@ -165,6 +180,7 @@ export interface IAppProxy {
setZoomFactor: (factor: number) => void setZoomFactor: (factor: number) => void
// events // events
onCurrentGraphChanged: IUserHook
onThemeModeChanged: IUserHook<{ mode: 'dark' | 'light' }> onThemeModeChanged: IUserHook<{ mode: 'dark' | 'light' }>
onBlockRendererMounted: IUserSlotHook<{ uuid: BlockUUID }> onBlockRendererMounted: IUserSlotHook<{ uuid: BlockUUID }>
onRouteChanged: IUserHook<{ path: string, template: string }> onRouteChanged: IUserHook<{ path: string, template: string }>

View File

@ -10,7 +10,7 @@
"electron:debug": "electron-forge start --inspect-electron", "electron:debug": "electron-forge start --inspect-electron",
"electron:make": "electron-forge make", "electron:make": "electron-forge make",
"electron:publish:github": "electron-forge publish", "electron:publish:github": "electron-forge publish",
"rebuild:better-sqlite3": "electron-rebuild -v 12 -f -w better-sqlite3", "rebuild:better-sqlite3": "electron-rebuild -v 13 -f -w better-sqlite3",
"postinstall": "install-app-deps" "postinstall": "install-app-deps"
}, },
"config": { "config": {

View File

@ -304,6 +304,7 @@
(theme/container (theme/container
{:theme theme {:theme theme
:route route-match :route route-match
:current-repo current-repo
:nfs-granted? granted? :nfs-granted? granted?
:db-restoring? db-restoring? :db-restoring? db-restoring?
:sidebar-open? sidebar-open? :sidebar-open? sidebar-open?

View File

@ -7,7 +7,7 @@
[frontend.components.svg :as svg])) [frontend.components.svg :as svg]))
(rum/defc container (rum/defc container
[{:keys [route theme on-click nfs-granted? db-restoring? sidebar-open? system-theme?] :as props} child] [{:keys [route theme on-click current-repo nfs-granted? db-restoring? sidebar-open? system-theme?] :as props} child]
(rum/use-effect! (rum/use-effect!
#(let [doc js/document.documentElement #(let [doc js/document.documentElement
cls (.-classList doc)] cls (.-classList doc)]
@ -22,6 +22,10 @@
#(plugin-handler/hook-plugin-app :sidebar-visible-changed {:visible sidebar-open?}) #(plugin-handler/hook-plugin-app :sidebar-visible-changed {:visible sidebar-open?})
[sidebar-open?]) [sidebar-open?])
(rum/use-effect!
#(plugin-handler/hook-plugin-app :current-graph-changed {})
[current-repo])
(rum/use-effect! (rum/use-effect!
#(let [db-restored? (false? db-restoring?)] #(let [db-restored? (false? db-restoring?)]
(if db-restoring? (if db-restoring?

View File

@ -8,6 +8,7 @@
[frontend.modules.outliner.core :as outliner] [frontend.modules.outliner.core :as outliner]
[frontend.modules.outliner.tree :as outliner-tree] [frontend.modules.outliner.tree :as outliner-tree]
[frontend.util :as util] [frontend.util :as util]
[frontend.config :as config]
[frontend.util.cursor :as cursor] [frontend.util.cursor :as cursor]
[electron.ipc :as ipc] [electron.ipc :as ipc]
[promesa.core :as p] [promesa.core :as p]
@ -62,6 +63,14 @@
:current-graph (state/get-current-repo) :current-graph (state/get-current-repo)
:me (state/get-me)})))) :me (state/get-me)}))))
(def ^:export get_current_graph
(fn []
(when-let [repo (state/get-current-repo)]
(when-not (= config/local-repo repo)
(bean/->js {:url repo
:name (util/node-path.basename repo)
:path (config/get-repo-dir repo)})))))
(def ^:export show_themes (def ^:export show_themes
(fn [] (fn []
(plugins/open-select-theme!))) (plugins/open-select-theme!)))