mirror of https://github.com/logseq/logseq
improve(plugin): add graph related api & types
parent
6305545f26
commit
da1f415af3
|
@ -79,6 +79,10 @@ export type BlockUUIDTuple = ['uuid', BlockUUID]
|
|||
export type IEntityID = { id: BlockID }
|
||||
export type IBatchBlock = { content: string, properties?: Record<string, any>, children?: Array<IBatchBlock> }
|
||||
|
||||
export interface AppUserInfo {
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
/**
|
||||
* User's app configurations
|
||||
*/
|
||||
|
@ -91,6 +95,14 @@ export interface AppUserConfigs {
|
|||
[key: string]: any
|
||||
}
|
||||
|
||||
export interface AppGraphInfo {
|
||||
name: string
|
||||
url: string
|
||||
path: string
|
||||
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
/**
|
||||
* Block - Logseq's fundamental data structure.
|
||||
*/
|
||||
|
@ -148,7 +160,7 @@ export type BlockCursorPosition = { left: number, top: number, height: number, p
|
|||
* App level APIs
|
||||
*/
|
||||
export interface IAppProxy {
|
||||
getUserInfo: () => Promise<any>
|
||||
getUserInfo: () => Promise<AppUserInfo | null>
|
||||
|
||||
getUserConfigs: () => Promise<AppUserConfigs>
|
||||
|
||||
|
@ -156,6 +168,9 @@ export interface IAppProxy {
|
|||
relaunch: () => Promise<void>
|
||||
quit: () => Promise<void>
|
||||
|
||||
// graph
|
||||
getCurrentGraph: () => Promise<AppGraphInfo | null>
|
||||
|
||||
// router
|
||||
pushState: (k: string, params?: {}) => void
|
||||
replaceState: (k: string, params?: {}) => void
|
||||
|
@ -165,6 +180,7 @@ export interface IAppProxy {
|
|||
setZoomFactor: (factor: number) => void
|
||||
|
||||
// events
|
||||
onCurrentGraphChanged: IUserHook
|
||||
onThemeModeChanged: IUserHook<{ mode: 'dark' | 'light' }>
|
||||
onBlockRendererMounted: IUserSlotHook<{ uuid: BlockUUID }>
|
||||
onRouteChanged: IUserHook<{ path: string, template: string }>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
"electron:debug": "electron-forge start --inspect-electron",
|
||||
"electron:make": "electron-forge make",
|
||||
"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"
|
||||
},
|
||||
"config": {
|
||||
|
|
|
@ -304,6 +304,7 @@
|
|||
(theme/container
|
||||
{:theme theme
|
||||
:route route-match
|
||||
:current-repo current-repo
|
||||
:nfs-granted? granted?
|
||||
:db-restoring? db-restoring?
|
||||
:sidebar-open? sidebar-open?
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
[frontend.components.svg :as svg]))
|
||||
|
||||
(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!
|
||||
#(let [doc js/document.documentElement
|
||||
cls (.-classList doc)]
|
||||
|
@ -22,6 +22,10 @@
|
|||
#(plugin-handler/hook-plugin-app :sidebar-visible-changed {:visible sidebar-open?})
|
||||
[sidebar-open?])
|
||||
|
||||
(rum/use-effect!
|
||||
#(plugin-handler/hook-plugin-app :current-graph-changed {})
|
||||
[current-repo])
|
||||
|
||||
(rum/use-effect!
|
||||
#(let [db-restored? (false? db-restoring?)]
|
||||
(if db-restoring?
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
[frontend.modules.outliner.core :as outliner]
|
||||
[frontend.modules.outliner.tree :as outliner-tree]
|
||||
[frontend.util :as util]
|
||||
[frontend.config :as config]
|
||||
[frontend.util.cursor :as cursor]
|
||||
[electron.ipc :as ipc]
|
||||
[promesa.core :as p]
|
||||
|
@ -62,6 +63,14 @@
|
|||
:current-graph (state/get-current-repo)
|
||||
: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
|
||||
(fn []
|
||||
(plugins/open-select-theme!)))
|
||||
|
|
Loading…
Reference in New Issue