|
@@ -19,6 +19,7 @@
|
|
|
[frontend.handler.assets :as assets-handler]
|
|
|
[frontend.handler.block :as block-handler]
|
|
|
[frontend.handler.common :as common-handler]
|
|
|
+ [frontend.handler.editor.property :as editor-property]
|
|
|
[frontend.handler.export.html :as export-html]
|
|
|
[frontend.handler.export.text :as export-text]
|
|
|
[frontend.handler.notification :as notification]
|
|
@@ -62,10 +63,8 @@
|
|
|
(defonce *asset-uploading? (atom false))
|
|
|
(defonce *asset-uploading-process (atom 0))
|
|
|
|
|
|
-(declare set-block-property!)
|
|
|
-(declare remove-block-property!)
|
|
|
-(declare batch-add-block-property!)
|
|
|
-(declare batch-remove-block-property!)
|
|
|
+(def clear-selection! editor-property/clear-selection!)
|
|
|
+(def edit-block! editor-property/edit-block!)
|
|
|
|
|
|
(defn get-block-own-order-list-type
|
|
|
[block]
|
|
@@ -74,12 +73,12 @@
|
|
|
(defn set-block-own-order-list-type!
|
|
|
[block type]
|
|
|
(when-let [uuid (:block/uuid block)]
|
|
|
- (set-block-property! uuid :logseq.order-list-type (name type))))
|
|
|
+ (editor-property/set-block-property! uuid :logseq.order-list-type (name type))))
|
|
|
|
|
|
(defn remove-block-own-order-list-type!
|
|
|
[block]
|
|
|
(when-let [uuid (:block/uuid block)]
|
|
|
- (remove-block-property! uuid :logseq.order-list-type)))
|
|
|
+ (editor-property/remove-block-property! uuid :logseq.order-list-type)))
|
|
|
|
|
|
(defn own-order-number-list?
|
|
|
[block]
|
|
@@ -96,8 +95,8 @@
|
|
|
blocks-uuids (some->> blocks (map :block/uuid) (remove nil?))
|
|
|
order-list-prop :logseq.order-list-type]
|
|
|
(if has-ordered?
|
|
|
- (batch-remove-block-property! blocks-uuids order-list-prop)
|
|
|
- (batch-add-block-property! blocks-uuids order-list-prop "number")))))
|
|
|
+ (editor-property/batch-remove-block-property! blocks-uuids order-list-prop)
|
|
|
+ (editor-property/batch-add-block-property! blocks-uuids order-list-prop "number")))))
|
|
|
|
|
|
(defn get-selection-and-format
|
|
|
[]
|
|
@@ -234,69 +233,7 @@
|
|
|
(doseq [block blocks]
|
|
|
(gdom-classes/remove block "block-highlight"))))
|
|
|
|
|
|
-(defn- get-edit-input-id-with-block-id
|
|
|
- [block-id]
|
|
|
- (when-let [first-block (util/get-first-block-by-id block-id)]
|
|
|
- (string/replace (gobj/get first-block "id")
|
|
|
- "ls-block"
|
|
|
- "edit-block")))
|
|
|
-
|
|
|
-(defn clear-selection!
|
|
|
- []
|
|
|
- (state/clear-selection!))
|
|
|
-
|
|
|
-(defn- text-range-by-lst-fst-line [content [direction pos]]
|
|
|
- (case direction
|
|
|
- :up
|
|
|
- (let [last-new-line (or (string/last-index-of content \newline) -1)
|
|
|
- end (+ last-new-line pos 1)]
|
|
|
- (subs content 0 end))
|
|
|
- :down
|
|
|
- (-> (string/split-lines content)
|
|
|
- first
|
|
|
- (or "")
|
|
|
- (subs 0 pos))))
|
|
|
-
|
|
|
;; id: block dom id, "ls-block-counter-uuid"
|
|
|
-(defn edit-block!
|
|
|
- ([block pos id]
|
|
|
- (edit-block! block pos id nil))
|
|
|
- ([block pos id {:keys [custom-content tail-len move-cursor? retry-times]
|
|
|
- :or {tail-len 0
|
|
|
- move-cursor? true
|
|
|
- retry-times 0}
|
|
|
- :as opts}]
|
|
|
- (when-not (> retry-times 2)
|
|
|
- (when-not config/publishing?
|
|
|
- (when-let [block-id (:block/uuid block)]
|
|
|
- (let [block (or (db/pull [:block/uuid block-id]) block)
|
|
|
- edit-input-id (if (uuid? id)
|
|
|
- (get-edit-input-id-with-block-id id)
|
|
|
- (-> (str (subs id 0 (- (count id) 36)) block-id)
|
|
|
- (string/replace "ls-block" "edit-block")))
|
|
|
- content (or custom-content (:block/content block) "")
|
|
|
- content-length (count content)
|
|
|
- text-range (cond
|
|
|
- (vector? pos)
|
|
|
- (text-range-by-lst-fst-line content pos)
|
|
|
-
|
|
|
- (and (> tail-len 0) (>= (count content) tail-len))
|
|
|
- (subs content 0 (- (count content) tail-len))
|
|
|
-
|
|
|
- (or (= :max pos) (<= content-length pos))
|
|
|
- content
|
|
|
-
|
|
|
- :else
|
|
|
- (subs content 0 pos))
|
|
|
- content (-> (property/remove-built-in-properties (:block/format block)
|
|
|
- content)
|
|
|
- (drawer/remove-logbook))]
|
|
|
- (clear-selection!)
|
|
|
- (if edit-input-id
|
|
|
- (state/set-editing! edit-input-id content block text-range move-cursor?)
|
|
|
- ;; Block may not be rendered yet
|
|
|
- (js/setTimeout (fn [] (edit-block! block pos id (update opts :retry-times inc))) 10))))))))
|
|
|
-
|
|
|
(defn- another-block-with-same-id-exists?
|
|
|
[current-id block-id]
|
|
|
(when-let [id (and (string? block-id) (parse-uuid block-id))]
|
|
@@ -914,72 +851,6 @@
|
|
|
:block/properties-order (or (keys properties) [])
|
|
|
:block/content content})))
|
|
|
|
|
|
-(defn- batch-set-block-property!
|
|
|
- "col: a collection of [block-id property-key property-value]."
|
|
|
- [col]
|
|
|
- #_:clj-kondo/ignore
|
|
|
- (when-let [repo (state/get-current-repo)]
|
|
|
- (let [col' (group-by first col)]
|
|
|
- (outliner-tx/transact!
|
|
|
- {:outliner-op :save-block}
|
|
|
- (doseq [[block-id items] col']
|
|
|
- (let [block-id (if (string? block-id) (uuid block-id) block-id)
|
|
|
- new-properties (zipmap (map second items)
|
|
|
- (map last items))]
|
|
|
- (when-let [block (db/entity [:block/uuid block-id])]
|
|
|
- (let [format (:block/format block)
|
|
|
- content (:block/content block)
|
|
|
- properties (:block/properties block)
|
|
|
- properties-text-values (:block/properties-text-values block)
|
|
|
- properties (-> (merge properties new-properties)
|
|
|
- gp-util/remove-nils-non-nested)
|
|
|
- properties-text-values (-> (merge properties-text-values new-properties)
|
|
|
- gp-util/remove-nils-non-nested)
|
|
|
- property-ks (->> (concat (:block/properties-order block)
|
|
|
- (map second items))
|
|
|
- (filter (set (keys properties)))
|
|
|
- distinct
|
|
|
- vec)
|
|
|
- content (property/remove-properties format content)
|
|
|
- kvs (for [key property-ks] [key (or (get properties-text-values key)
|
|
|
- (get properties key))])
|
|
|
- content (property/insert-properties format content kvs)
|
|
|
- content (property/remove-empty-properties content)
|
|
|
- block {:block/uuid block-id
|
|
|
- :block/properties properties
|
|
|
- :block/properties-order property-ks
|
|
|
- :block/properties-text-values properties-text-values
|
|
|
- :block/content content}]
|
|
|
- (outliner-core/save-block! block)))))))
|
|
|
-
|
|
|
- (let [block-id (ffirst col)
|
|
|
- block-id (if (string? block-id) (uuid block-id) block-id)
|
|
|
- input-pos (or (state/get-edit-pos) :max)]
|
|
|
- ;; update editing input content
|
|
|
- (when-let [editing-block (state/get-edit-block)]
|
|
|
- (when (= (:block/uuid editing-block) block-id)
|
|
|
- (edit-block! editing-block
|
|
|
- input-pos
|
|
|
- (state/get-edit-input-id)))))))
|
|
|
-
|
|
|
-(defn batch-add-block-property!
|
|
|
- [block-ids property-key property-value]
|
|
|
- (batch-set-block-property! (map #(vector % property-key property-value) block-ids)))
|
|
|
-
|
|
|
-(defn batch-remove-block-property!
|
|
|
- [block-ids property-key]
|
|
|
- (batch-set-block-property! (map #(vector % property-key nil) block-ids)))
|
|
|
-
|
|
|
-(defn remove-block-property!
|
|
|
- [block-id key]
|
|
|
- (let [key (keyword key)]
|
|
|
- (batch-set-block-property! [[block-id key nil]])))
|
|
|
-
|
|
|
-(defn set-block-property!
|
|
|
- [block-id key value]
|
|
|
- (let [key (keyword key)]
|
|
|
- (batch-set-block-property! [[block-id key value]])))
|
|
|
-
|
|
|
(defn set-block-query-properties!
|
|
|
[block-id all-properties key add?]
|
|
|
(when-let [block (db/entity [:block/uuid block-id])]
|
|
@@ -993,8 +864,8 @@
|
|
|
(remove #{key} query-properties))
|
|
|
query-properties (vec query-properties)]
|
|
|
(if (seq query-properties)
|
|
|
- (set-block-property! block-id :query-properties (str query-properties))
|
|
|
- (remove-block-property! block-id :query-properties)))))
|
|
|
+ (editor-property/set-block-property! block-id :query-properties (str query-properties))
|
|
|
+ (editor-property/remove-block-property! block-id :query-properties)))))
|
|
|
|
|
|
(defn set-block-timestamp!
|
|
|
[block-id key value]
|
|
@@ -1038,7 +909,7 @@
|
|
|
[block-id :id (str block-id)])))
|
|
|
block-ids)
|
|
|
col (remove nil? col)]
|
|
|
- (batch-set-block-property! col)))
|
|
|
+ (editor-property/batch-set-block-property! col)))
|
|
|
|
|
|
(defn copy-block-ref!
|
|
|
([block-id]
|
|
@@ -2031,9 +1902,9 @@
|
|
|
:command :block-ref})
|
|
|
|
|
|
;; Save it so it'll be parsed correctly in the future
|
|
|
- (set-block-property! (:block/uuid chosen)
|
|
|
- :id
|
|
|
- uuid-string)
|
|
|
+ (editor-property/set-block-property! (:block/uuid chosen)
|
|
|
+ :id
|
|
|
+ uuid-string)
|
|
|
|
|
|
(when-let [input (gdom/getElement id)]
|
|
|
(.focus input)))))
|