|
|
@@ -718,57 +718,57 @@
|
|
|
(defn ^:export insert_block
|
|
|
[block-uuid-or-page-name content ^js opts]
|
|
|
(this-as this
|
|
|
- (when (string/blank? block-uuid-or-page-name)
|
|
|
- (throw (js/Error. "Page title or block UUID shouldn't be empty.")))
|
|
|
-
|
|
|
- (p/let [block? (util/uuid-string? (str block-uuid-or-page-name))
|
|
|
- block (<pull-block (str block-uuid-or-page-name))]
|
|
|
- (if (and block? (not block))
|
|
|
- (throw (js/Error. "Block not exists"))
|
|
|
- (p/let [{:keys [before sibling focus customUUID properties autoOrderedList]} (bean/->clj opts)
|
|
|
- [page-name block-uuid] (if (util/uuid-string? block-uuid-or-page-name)
|
|
|
- [nil (uuid block-uuid-or-page-name)]
|
|
|
- [block-uuid-or-page-name nil])
|
|
|
- page-name (when page-name (util/page-name-sanity-lc page-name))
|
|
|
- _ (when (and page-name
|
|
|
- (nil? (ldb/get-page (db/get-db) page-name)))
|
|
|
- (page-handler/<create! block-uuid-or-page-name {}))
|
|
|
- custom-uuid (or customUUID (:id properties))
|
|
|
- custom-uuid (when custom-uuid (sdk-utils/uuid-or-throw-error custom-uuid))
|
|
|
- edit-block? (if (nil? focus) true focus)
|
|
|
- _ (when (and custom-uuid (db-model/query-block-by-uuid custom-uuid))
|
|
|
- (throw (js/Error.
|
|
|
- (util/format "Custom block UUID already exists (%s)." custom-uuid))))
|
|
|
- block-uuid' (if (and (not sibling) before block-uuid)
|
|
|
- (let [block (db/entity [:block/uuid block-uuid])
|
|
|
- first-child (ldb/get-first-child (db/get-db) (:db/id block))]
|
|
|
- (if first-child
|
|
|
- (:block/uuid first-child)
|
|
|
- block-uuid))
|
|
|
- block-uuid)
|
|
|
- insert-at-first-child? (not= block-uuid' block-uuid)
|
|
|
- [sibling? before?] (if insert-at-first-child?
|
|
|
- [true true]
|
|
|
- [sibling before])
|
|
|
- db-base? (db-graph?)
|
|
|
- before? (if (and (false? sibling?) before? (not insert-at-first-child?))
|
|
|
- false
|
|
|
- before?)
|
|
|
- new-block (editor-handler/api-insert-new-block!
|
|
|
- content
|
|
|
- {:block-uuid block-uuid'
|
|
|
- :sibling? sibling?
|
|
|
- :before? before?
|
|
|
- :edit-block? edit-block?
|
|
|
- :page page-name
|
|
|
- :custom-uuid custom-uuid
|
|
|
- :ordered-list? (if (boolean? autoOrderedList) autoOrderedList false)
|
|
|
- :properties (when (not db-base?)
|
|
|
- (merge properties
|
|
|
- (when custom-uuid {:id custom-uuid})))})
|
|
|
- _ (when (and db-base? (some? properties))
|
|
|
- (api-block/save-db-based-block-properties! new-block properties this))]
|
|
|
- (bean/->js (sdk-utils/normalize-keyword-for-json new-block)))))))
|
|
|
+ (when (string/blank? block-uuid-or-page-name)
|
|
|
+ (throw (js/Error. "Page title or block UUID shouldn't be empty.")))
|
|
|
+
|
|
|
+ (p/let [block? (util/uuid-string? (str block-uuid-or-page-name))
|
|
|
+ block (<pull-block (str block-uuid-or-page-name))]
|
|
|
+ (if (and block? (not block))
|
|
|
+ (throw (js/Error. "Block not exists"))
|
|
|
+ (p/let [{:keys [before sibling focus customUUID properties autoOrderedList]} (bean/->clj opts)
|
|
|
+ [page-name block-uuid] (if (util/uuid-string? block-uuid-or-page-name)
|
|
|
+ [nil (uuid block-uuid-or-page-name)]
|
|
|
+ [block-uuid-or-page-name nil])
|
|
|
+ page-name (when page-name (util/page-name-sanity-lc page-name))
|
|
|
+ _ (when (and page-name
|
|
|
+ (nil? (ldb/get-page (db/get-db) page-name)))
|
|
|
+ (page-handler/<create! block-uuid-or-page-name {}))
|
|
|
+ custom-uuid (or customUUID (:id properties))
|
|
|
+ custom-uuid (when custom-uuid (sdk-utils/uuid-or-throw-error custom-uuid))
|
|
|
+ edit-block? (if (nil? focus) true focus)
|
|
|
+ _ (when (and custom-uuid (db-model/query-block-by-uuid custom-uuid))
|
|
|
+ (throw (js/Error.
|
|
|
+ (util/format "Custom block UUID already exists (%s)." custom-uuid))))
|
|
|
+ block-uuid' (if (and (not sibling) before block-uuid)
|
|
|
+ (let [block (db/entity [:block/uuid block-uuid])
|
|
|
+ first-child (ldb/get-first-child (db/get-db) (:db/id block))]
|
|
|
+ (if first-child
|
|
|
+ (:block/uuid first-child)
|
|
|
+ block-uuid))
|
|
|
+ block-uuid)
|
|
|
+ insert-at-first-child? (not= block-uuid' block-uuid)
|
|
|
+ [sibling? before?] (if insert-at-first-child?
|
|
|
+ [true true]
|
|
|
+ [sibling before])
|
|
|
+ db-base? (db-graph?)
|
|
|
+ before? (if (and (false? sibling?) before? (not insert-at-first-child?))
|
|
|
+ false
|
|
|
+ before?)
|
|
|
+ new-block (editor-handler/api-insert-new-block!
|
|
|
+ content
|
|
|
+ {:block-uuid block-uuid'
|
|
|
+ :sibling? sibling?
|
|
|
+ :before? before?
|
|
|
+ :edit-block? edit-block?
|
|
|
+ :page page-name
|
|
|
+ :custom-uuid custom-uuid
|
|
|
+ :ordered-list? (if (boolean? autoOrderedList) autoOrderedList false)
|
|
|
+ :properties (when (not db-base?)
|
|
|
+ (merge properties
|
|
|
+ (when custom-uuid {:id custom-uuid})))})
|
|
|
+ _ (when (and db-base? (some? properties))
|
|
|
+ (api-block/save-db-based-block-properties! new-block properties this))]
|
|
|
+ (bean/->js (sdk-utils/normalize-keyword-for-json new-block)))))))
|
|
|
|
|
|
(def ^:export insert_batch_block
|
|
|
(fn [block-uuid ^js batch-blocks ^js opts]
|
|
|
@@ -892,11 +892,11 @@
|
|
|
(defn ^:export get_property
|
|
|
[k]
|
|
|
(this-as this
|
|
|
- (p/let [prop (-get-property this k)]
|
|
|
- (some-> prop
|
|
|
- (assoc :type (:logseq.property/type prop))
|
|
|
- (sdk-utils/normalize-keyword-for-json)
|
|
|
- (bean/->js)))))
|
|
|
+ (p/let [prop (-get-property this k)]
|
|
|
+ (some-> prop
|
|
|
+ (assoc :type (:logseq.property/type prop))
|
|
|
+ (sdk-utils/normalize-keyword-for-json)
|
|
|
+ (bean/->js)))))
|
|
|
|
|
|
(defn ^:export upsert_property
|
|
|
"schema:
|
|
|
@@ -920,7 +920,7 @@
|
|
|
schema (cond-> schema
|
|
|
(string? (:cardinality schema))
|
|
|
(-> (assoc :db/cardinality (keyword (:cardinality schema)))
|
|
|
- (dissoc :cardinality))
|
|
|
+ (dissoc :cardinality))
|
|
|
|
|
|
(string? (:type schema))
|
|
|
(-> (assoc :logseq.property/type (keyword (:type schema)))
|
|
|
@@ -935,70 +935,70 @@
|
|
|
(defn ^:export remove_property
|
|
|
[k]
|
|
|
(this-as this
|
|
|
- (p/let [prop (-get-property this k)]
|
|
|
- (when-let [uuid (and (api-block/plugin-property-key? (:db/ident prop))
|
|
|
- (:block/uuid prop))]
|
|
|
- (page-common-handler/<delete! uuid nil nil)))))
|
|
|
+ (p/let [prop (-get-property this k)]
|
|
|
+ (when-let [uuid (and (api-block/plugin-property-key? (:db/ident prop))
|
|
|
+ (:block/uuid prop))]
|
|
|
+ (page-common-handler/<delete! uuid nil nil)))))
|
|
|
|
|
|
;; block properties
|
|
|
(defn ^:export upsert_block_property
|
|
|
[block-uuid key ^js value]
|
|
|
(this-as this
|
|
|
- (p/let [keyname (api-block/sanitize-user-property-name key)
|
|
|
- block-uuid (sdk-utils/uuid-or-throw-error block-uuid)
|
|
|
- repo (state/get-current-repo)
|
|
|
- block (db-async/<get-block repo block-uuid :children? false)
|
|
|
- db-base? (db-graph?)
|
|
|
- key' (-> (if (keyword? keyname) (name keyname) keyname) (util/trim-safe))
|
|
|
- value (bean/->clj value)]
|
|
|
- (when block
|
|
|
- (if db-base?
|
|
|
- (p/do!
|
|
|
- (api-block/save-db-based-block-properties! block {key' value} this))
|
|
|
- (property-handler/set-block-property! repo block-uuid key' value))))))
|
|
|
+ (p/let [keyname (api-block/sanitize-user-property-name key)
|
|
|
+ block-uuid (sdk-utils/uuid-or-throw-error block-uuid)
|
|
|
+ repo (state/get-current-repo)
|
|
|
+ block (db-async/<get-block repo block-uuid :children? false)
|
|
|
+ db-base? (db-graph?)
|
|
|
+ key' (-> (if (keyword? keyname) (name keyname) keyname) (util/trim-safe))
|
|
|
+ value (bean/->clj value)]
|
|
|
+ (when block
|
|
|
+ (if db-base?
|
|
|
+ (p/do!
|
|
|
+ (api-block/save-db-based-block-properties! block {key' value} this))
|
|
|
+ (property-handler/set-block-property! repo block-uuid key' value))))))
|
|
|
|
|
|
(defn ^:export remove_block_property
|
|
|
[block-uuid key]
|
|
|
(this-as this
|
|
|
- (p/let [key (api-block/sanitize-user-property-name key)
|
|
|
- block-uuid (sdk-utils/uuid-or-throw-error block-uuid)
|
|
|
- _ (db-async/<get-block (state/get-current-repo) block-uuid :children? false)
|
|
|
- db? (config/db-based-graph? (state/get-current-repo))
|
|
|
- key-ns? (and (keyword? key) (namespace key))
|
|
|
- key (if key-ns? key (if (keyword? key) (name key) key))
|
|
|
- key (if (and db? (not key-ns?))
|
|
|
- (api-block/get-db-ident-for-user-property-name
|
|
|
- key (api-block/resolve-property-prefix-for-db this))
|
|
|
- key)]
|
|
|
- (property-handler/remove-block-property!
|
|
|
- (state/get-current-repo)
|
|
|
- block-uuid key))))
|
|
|
+ (p/let [key (api-block/sanitize-user-property-name key)
|
|
|
+ block-uuid (sdk-utils/uuid-or-throw-error block-uuid)
|
|
|
+ _ (db-async/<get-block (state/get-current-repo) block-uuid :children? false)
|
|
|
+ db? (config/db-based-graph? (state/get-current-repo))
|
|
|
+ key-ns? (and (keyword? key) (namespace key))
|
|
|
+ key (if key-ns? key (if (keyword? key) (name key) key))
|
|
|
+ key (if (and db? (not key-ns?))
|
|
|
+ (api-block/get-db-ident-for-user-property-name
|
|
|
+ key (api-block/resolve-property-prefix-for-db this))
|
|
|
+ key)]
|
|
|
+ (property-handler/remove-block-property!
|
|
|
+ (state/get-current-repo)
|
|
|
+ block-uuid key))))
|
|
|
|
|
|
(defn ^:export get_block_property
|
|
|
[block-uuid key]
|
|
|
(this-as this
|
|
|
- (p/let [block-uuid (sdk-utils/uuid-or-throw-error block-uuid)
|
|
|
- _ (db-async/<get-block (state/get-current-repo) block-uuid :children? false)]
|
|
|
- (when-let [properties (some-> block-uuid (db-model/get-block-by-uuid) (:block/properties))]
|
|
|
- (when (seq properties)
|
|
|
- (let [key (api-block/sanitize-user-property-name key)
|
|
|
- property-name (if (keyword? key) (name key) key)
|
|
|
- ident (api-block/get-db-ident-for-user-property-name
|
|
|
- property-name (api-block/resolve-property-prefix-for-db this))
|
|
|
- property-value (or (get properties key)
|
|
|
- (get properties (keyword property-name))
|
|
|
- (get properties ident))
|
|
|
- property-value (if-let [property-id (:db/id property-value)]
|
|
|
- (db/pull property-id) property-value)
|
|
|
- property-value (cond-> property-value
|
|
|
- (map? property-value)
|
|
|
- (assoc
|
|
|
- :value (or (:logseq.property/value property-value)
|
|
|
- (:block/title property-value))
|
|
|
- :ident ident))
|
|
|
- parsed-value (api-block/parse-property-json-value-if-need ident property-value)]
|
|
|
- (or parsed-value
|
|
|
- (bean/->js (sdk-utils/normalize-keyword-for-json property-value)))))))))
|
|
|
+ (p/let [block-uuid (sdk-utils/uuid-or-throw-error block-uuid)
|
|
|
+ _ (db-async/<get-block (state/get-current-repo) block-uuid :children? false)]
|
|
|
+ (when-let [properties (some-> block-uuid (db-model/get-block-by-uuid) (:block/properties))]
|
|
|
+ (when (seq properties)
|
|
|
+ (let [key (api-block/sanitize-user-property-name key)
|
|
|
+ property-name (if (keyword? key) (name key) key)
|
|
|
+ ident (api-block/get-db-ident-for-user-property-name
|
|
|
+ property-name (api-block/resolve-property-prefix-for-db this))
|
|
|
+ property-value (or (get properties key)
|
|
|
+ (get properties (keyword property-name))
|
|
|
+ (get properties ident))
|
|
|
+ property-value (if-let [property-id (:db/id property-value)]
|
|
|
+ (db/pull property-id) property-value)
|
|
|
+ property-value (cond-> property-value
|
|
|
+ (map? property-value)
|
|
|
+ (assoc
|
|
|
+ :value (or (:logseq.property/value property-value)
|
|
|
+ (:block/title property-value))
|
|
|
+ :ident ident))
|
|
|
+ parsed-value (api-block/parse-property-json-value-if-need ident property-value)]
|
|
|
+ (or parsed-value
|
|
|
+ (bean/->js (sdk-utils/normalize-keyword-for-json property-value)))))))))
|
|
|
|
|
|
(def ^:export get_block_properties
|
|
|
(fn [block-uuid]
|