improve(plugin): add batch block api & types

pull/1747/head
charlie 2021-06-10 15:16:00 +08:00
parent 5f81998d64
commit 6305545f26
3 changed files with 34 additions and 23 deletions

View File

@ -77,7 +77,7 @@ export type BlockUUID = string
export type BlockUUIDTuple = ['uuid', BlockUUID]
export type IEntityID = { id: BlockID }
export type IBatchBlock = { content: string, props?: Record<string, any>, children?: Array<IBatchBlock> }
export type IBatchBlock = { content: string, properties?: Record<string, any>, children?: Array<IBatchBlock> }
/**
* User's app configurations

View File

@ -431,7 +431,7 @@
(defmethod handle-step :editor/restore-saved-cursor [[_]]
(when-let [input-id (state/get-edit-input-id)]
(when-let [current-input (gdom/getElement input-id)]
(util/move-cursor-to current-input (:editor/last-saved-cursor @state/state)))))
(cursor/move-cursor-to current-input (:editor/last-saved-cursor @state/state)))))
(defmethod handle-step :editor/clear-current-slash [[_ space?]]
(when-let [input-id (state/get-edit-input-id)]

View File

@ -8,6 +8,7 @@
[frontend.modules.outliner.core :as outliner]
[frontend.modules.outliner.tree :as outliner-tree]
[frontend.util :as util]
[frontend.util.cursor :as cursor]
[electron.ipc :as ipc]
[promesa.core :as p]
[goog.dom :as gdom]
@ -190,7 +191,7 @@
(def ^:export get_editing_cursor_position
(fn []
(when-let [input-id (state/get-edit-input-id)]
(bean/->js (normalize-keyword-for-json (util/get-caret-pos (gdom/getElement input-id)))))))
(bean/->js (normalize-keyword-for-json (cursor/get-caret-pos (gdom/getElement input-id)))))))
(def ^:export get_editing_block_content
(fn []
@ -233,6 +234,16 @@
(bean/->js (normalize-keyword-for-json new-block)))))
(def ^:export insert_batch_block
(fn [block-uuid ^js batch-blocks ^js opts]
(when-let [block (db-model/query-block-by-uuid block-uuid)]
(when-let [bb (bean/->clj batch-blocks)]
(let [bb (if-not (vector? bb) (vector bb) bb)
{:keys [sibling]} (bean/->clj opts)
_ (editor-handler/paste-block-tree-after-target
(:db/id block) sibling bb (:block/format block))]
nil)))))
(def ^:export remove_block
(fn [block-uuid ^js opts]
(let [{:keys [includeChildren]} (bean/->clj opts)