diff --git a/src/main/frontend/components/editor.cljs b/src/main/frontend/components/editor.cljs index b1a4d19d86..e5d2ed0b11 100644 --- a/src/main/frontend/components/editor.cljs +++ b/src/main/frontend/components/editor.cljs @@ -646,21 +646,24 @@ (mixins/event-mixin setup-key-listener!) (shortcut/mixin :shortcut.handler/block-editing-only) lifecycle/lifecycle - [state {:keys [format block]} id _config] + [state {:keys [format block parent-block]} id _config] (let [content (state/sub-edit-content id) - heading-class (get-editor-style-class block content format)] + heading-class (get-editor-style-class block content format) + opts (cond-> + {:id id + :cacheMeasurements (editor-row-height-unchanged?) ;; check when content updated (as the content variable is binded) + :default-value (or content "") + :minRows (if (state/enable-grammarly?) 2 1) + :on-click (editor-handler/editor-on-click! id) + :on-change (editor-handler/editor-on-change! block id search-timeout) + :on-paste (paste-handler/editor-on-paste! id) + :auto-focus false + :class heading-class} + (some? parent-block) + (assoc :parentblockid (str (:block/uuid parent-block))))] [:div.editor-inner {:class (if block "block-editor" "non-block-editor")} - (ui/ls-textarea - {:id id - :cacheMeasurements (editor-row-height-unchanged?) ;; check when content updated (as the content variable is binded) - :default-value (or content "") - :minRows (if (state/enable-grammarly?) 2 1) - :on-click (editor-handler/editor-on-click! id) - :on-change (editor-handler/editor-on-change! block id search-timeout) - :on-paste (paste-handler/editor-on-paste! id) - :auto-focus false - :class heading-class}) + (ui/ls-textarea opts) (mock-textarea content) (modals id format) diff --git a/src/main/frontend/components/property.cljs b/src/main/frontend/components/property.cljs index 7720b54877..c3756c7008 100644 --- a/src/main/frontend/components/property.cljs +++ b/src/main/frontend/components/property.cljs @@ -237,24 +237,25 @@ k (get (:block/properties block) k)) dom-id (str "ls-property-" k) - editor-id (str "property-" (:db/id block) "-" k) + editor-id (str "ls-property-" (:db/id property) "-" k) editing? (state/sub [:editor/editing? editor-id]) schema (:block/schema property) edit-fn (fn [editor-id id v] (let [v (str v) cursor-range (util/caret-range (gdom/getElement (or id dom-id)))] - (state/set-editing! editor-id v block cursor-range) + (state/set-editing! editor-id v property cursor-range) (js/setTimeout (fn [] - (state/set-editor-action-data! {:block block - :property property + (state/set-editor-action-data! {:block property :pos 0}) - (state/set-editor-action! :property-value-search) - (state/set-state! :ui/editing-property property)) + (state/set-editor-action! :property-value-search)) 50))) multiple-values? (= :many (:cardinality schema)) - type (:type schema)] + type (:type schema) + editor-args {:block property + :parent-block block + :format :markdown}] (cond multiple-values? (let [v' (if (coll? v) v (when v [v])) @@ -268,8 +269,7 @@ editor-id' (str editor-id idx) editing? (state/sub [:editor/editing? editor-id'])] (if editing? - (editor-box {:format :markdown - :block block} editor-id' {}) + (editor-box editor-args editor-id' {}) (multiple-value-item block property item dom-id' editor-id' {:page-cp page-cp :edit-fn edit-fn :inline-text inline-text})))) @@ -289,12 +289,10 @@ :style {:margin-left -4}} (ui/icon "circle-plus")]]]]))] (when new-editing? - (editor-box {:format :markdown - :block block} editor-id' {}))]) + (editor-box editor-args editor-id' {}))]) editing? - (editor-box {:format :markdown - :block block} editor-id {}) + (editor-box editor-args editor-id {}) :else [:div.flex.flex-1.property-value-content @@ -319,7 +317,7 @@ [:div (for [[prop-uuid-or-built-in-prop v] properties] (if (uuid? prop-uuid-or-built-in-prop) - (when-let [property (db/pull [:block/uuid prop-uuid-or-built-in-prop])] + (when-let [property (db/sub-block (:db/id (db/entity [:block/uuid prop-uuid-or-built-in-prop])))] [:div.grid.grid-cols-4.gap-1 [:div.property-key.col-span-1 (property-key block property)] diff --git a/src/main/frontend/db/model.cljs b/src/main/frontend/db/model.cljs index 2964911538..916887edd2 100644 --- a/src/main/frontend/db/model.cljs +++ b/src/main/frontend/db/model.cljs @@ -419,7 +419,9 @@ independent of format as format specific heading characters are stripped" {:query-fn (fn [_] (let [e (db-utils/entity id) children (map :db/id (sort-by-left (:block/_parent e) e))] - [e {:content (:block/content e) + [e {:original-name (:block/original-name e) + :schema (:block/schema e) + :content (:block/content e) :marker (:block/marker e) :priority (:block/priority e) :properties (:block/properties e) @@ -1421,6 +1423,7 @@ independent of format as format specific heading characters are stripped" (not (contains? built-in-pages name)) (not (whiteboard-page? page)) (not (:block/_namespace page)) + (not (contains? #{"property"} (:block/type page))) ;; a/b/c might be deleted but a/b/c/d still exists (for backward compatibility) (not (and (string/includes? name "/") (not (:block/journal? page)))) diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index 082fa94495..2ca91e9985 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -27,7 +27,6 @@ [frontend.handler.route :as route-handler] [frontend.handler.db-based.editor :as db-editor-handler] [frontend.handler.file-based.editor :as file-editor-handler] - [frontend.handler.property :as property-handler] [frontend.mobile.util :as mobile-util] [frontend.modules.outliner.core :as outliner-core] [frontend.modules.outliner.transaction :as outliner-tx] @@ -1162,17 +1161,13 @@ (defn save-block-aux! [block value opts] - (let [entity (db/entity [:block/uuid (:block/uuid block)]) - editing-property (:ui/editing-property @state/state)] - (when (:db/id entity) + (let [entity (db/entity [:block/uuid (:block/uuid block)])] + (when (and (:db/id entity) + (not (contains? #{"property"} (:block/type entity)))) (let [value (string/trim value)] - (if editing-property - (property-handler/add-property! (state/get-current-repo) entity - (:block/name editing-property) - value) - ;; FIXME: somehow frontend.components.editor's will-unmount event will loop forever - ;; maybe we shouldn't save the block/file in "will-unmount" event? - (save-block-if-changed! block value opts)))))) + ;; FIXME: somehow frontend.components.editor's will-unmount event will loop forever + ;; maybe we shouldn't save the block/file in "will-unmount" event? + (save-block-if-changed! block value opts))))) (defn save-block! ([repo block-or-uuid content] diff --git a/src/main/frontend/handler/editor/lifecycle.cljs b/src/main/frontend/handler/editor/lifecycle.cljs index d660cd7aea..a39074f4ab 100644 --- a/src/main/frontend/handler/editor/lifecycle.cljs +++ b/src/main/frontend/handler/editor/lifecycle.cljs @@ -1,9 +1,14 @@ (ns ^:no-doc frontend.handler.editor.lifecycle (:require [frontend.handler.editor :as editor-handler :refer [get-state]] [frontend.handler.editor.keyboards :as keyboards-handler] + [frontend.handler.property :as property-handler] [frontend.state :as state :refer [sub]] [frontend.util :as util] - [goog.dom :as gdom])) + [goog.dom :as gdom] + [dommy.core :as d] + [goog.object :as gobj] + [clojure.string :as string] + [frontend.db :as db])) (defn did-mount! [state] @@ -34,13 +39,22 @@ (defn will-unmount [state] - (let [{:keys [value]} (get-state)] + (let [{:keys [block value node]} (get-state) + property? (= "property" (:block/type block)) + repo (state/get-current-repo)] (editor-handler/clear-when-saved!) (when (and (not (contains? #{:insert :indent-outdent :auto-save :undo :redo :delete} (state/get-editor-op))) ;; Don't trigger auto-save if the latest op is undo or redo (not (contains? #{:undo :redo} (state/get-editor-latest-op)))) - (editor-handler/save-block! (get-state) value))) + (if property? + (let [parent-block (when-let [id (d/attr node "parentblockid")] + (when (util/uuid-string? id) + (db/entity [:block/uuid (uuid id)]))) + property (:block/name block)] + (when (and parent-block property) + (property-handler/add-property! repo parent-block property value))) + (editor-handler/save-block! (get-state) value)))) state) (def lifecycle diff --git a/src/main/frontend/modules/outliner/core.cljs b/src/main/frontend/modules/outliner/core.cljs index 7a5b91cb87..b7d0bac903 100644 --- a/src/main/frontend/modules/outliner/core.cljs +++ b/src/main/frontend/modules/outliner/core.cljs @@ -13,6 +13,7 @@ [frontend.state :as state] [frontend.util :as util] [frontend.util.property-edit :as property-edit] + [frontend.config :as config] [logseq.graph-parser.util :as gp-util] [cljs.spec.alpha :as s])) @@ -190,11 +191,12 @@ (swap! txs-state into txs))) ;; Remove orphaned refs from block - (let [remove-self-page #(remove (fn [b] - (= (:db/id b) (:db/id (:block/page block-entity)))) %) - old-refs (remove-self-page (:block/refs block-entity)) - new-refs (remove-self-page (:block/refs m))] - (remove-orphaned-page-refs! (:db/id block-entity) txs-state old-refs new-refs))) + (when-not (config/db-based-graph? (state/get-current-repo)) + (let [remove-self-page #(remove (fn [b] + (= (:db/id b) (:db/id (:block/page block-entity)))) %) + old-refs (remove-self-page (:block/refs block-entity)) + new-refs (remove-self-page (:block/refs m))] + (remove-orphaned-page-refs! (:db/id block-entity) txs-state old-refs new-refs)))) (swap! txs-state conj (dissoc m :db/other-tx)) diff --git a/src/main/frontend/state.cljs b/src/main/frontend/state.cljs index 78271f1520..f6c708da21 100644 --- a/src/main/frontend/state.cljs +++ b/src/main/frontend/state.cljs @@ -1872,8 +1872,7 @@ Similar to re-frame subscriptions" (assoc :editor/editing? {edit-input-id true} :editor/set-timestamp-block nil - :cursor-range cursor-range - :ui/editing-property nil)))) + :cursor-range cursor-range)))) (set-state! :editor/block block) (set-state! :editor/content content :path-in-sub-atom edit-input-id) (set-state! :editor/last-key-code nil)