Selaa lähdekoodia

remove :blocks-container-id usage

Tienson Qin 2 vuotta sitten
vanhempi
sitoutus
7138be295f

+ 1 - 2
deps/shui/src/logseq/shui/context.cljs

@@ -17,12 +17,11 @@
    :inline-block (inline->inline-block inline block-config)
    :map-inline-block (inline->map-inline-block inline block-config)
    ;; Currently frontend component are provided an object map containing at least the following keys:
-   ;; These will be passed through in a whitelisted fashion so as to be able to track the dependencies  
+   ;; These will be passed through in a whitelisted fashion so as to be able to track the dependencies
    ;; back to the core application
    ;; TODO: document the following
    :block (:block block-config)  ;; the db entity of the current block
    :block? (:block? block-config)
-   :blocks-container-id (:blocks-container-id block-config)
    :editor-box (:editor-box block-config)
    :id (:id block-config)
    :mode? (:mode? block-config)

+ 20 - 56
src/main/frontend/components/block.cljs

@@ -2088,8 +2088,7 @@
   (property-component/properties-area block
                                       edit-input-id
                                       (merge
-                                       {:blocks-container-id (:blocks-container-id config)
-                                        :inline-text inline-text
+                                       {:inline-text inline-text
                                         :page-cp page-cp
                                         :block-cp blocks-container
                                         :properties-cp db-properties-cp
@@ -2527,33 +2526,26 @@
 (rum/defcs single-block-cp-inner < rum/reactive db-mixins/query
   {:init (fn [state]
            (assoc state
-                  ::init-blocks-container-id (atom nil)
                   ::ref (atom nil)))}
   [state block-uuid]
   (let [*ref (::ref state)
         uuid (if (string? block-uuid) (uuid block-uuid) block-uuid)
-        *init-blocks-container-id (::init-blocks-container-id state)
         block-entity (db/entity [:block/uuid uuid])
         block-id (:db/id block-entity)
         block (db/sub-block block-id)
-        blocks-container-id (if @*init-blocks-container-id
-                              @*init-blocks-container-id
-                              (let [id' (state/next-blocks-container-id)]
-                                (reset! *init-blocks-container-id id')
-                                id'))
-        block-el-id (str "ls-block-" blocks-container-id "-" uuid)
+        block-el-id (str "ls-block-" uuid)
         config {:id (str uuid)
                 :db/id (:db/id block-entity)
                 :block/uuid uuid
                 :block? true
                 :editor-box (state/get-component :editor/box)}
-        edit-input-id (str "edit-block-" blocks-container-id "-" uuid)
+        edit-input-id (str "edit-block-" uuid)
         edit? (state/sub-editing? edit-input-id)
         block (block/parse-title-and-body block)]
     (when (:block/content block)
       [:div.single-block.ls-block
        {:class (str block-uuid)
-        :id (str "ls-block-" blocks-container-id "-" block-uuid)}
+        :id (str "ls-block-" block-uuid)}
        (block-content-or-editor config block edit-input-id block-el-id edit? true false *ref)])))
 
 (rum/defc single-block-cp
@@ -2846,11 +2838,11 @@
                                 (= editing-parent-node (.-previousSibling ref))))
                       (state/set-editing-ref! ref))))
                 state)}
-  [inner-state state repo config* block {:keys [blocks-container-id navigating-block navigated?]}]
+  [inner-state state repo config* block {:keys [navigating-block navigated?]}]
   (let [*ref (::ref inner-state)
         ref (rum/react *ref)
         ref? (:ref? config*)
-        edit-input-id (str "edit-block-" blocks-container-id "-" (:block/uuid block))
+        edit-input-id (str "edit-block-" (:block/uuid block))
         edit? (state/sub-editing? ref)
         custom-query? (boolean (:custom-query? config*))
         ref-or-custom-query? (or ref? custom-query?)
@@ -2858,7 +2850,6 @@
         {:block/keys [uuid pre-block? refs content properties]} block
         config (build-config config* block {:navigated? navigated? :navigating-block navigating-block})
         level (:level config)
-        blocks-container-id (:blocks-container-id config)
         heading? (pu/lookup properties :heading)
         *control-show? (get state ::control-show?)
         db-collapsed? (util/collapsed? block)
@@ -2876,7 +2867,7 @@
         embed? (:embed? config)
         reference? (:reference? config)
         whiteboard-block? (pu/shape-block? block)
-        block-id (str "ls-block-" blocks-container-id "-" uuid)
+        block-id (str "ls-block-" uuid)
         has-child? (first (:block/_parent (db/entity (:db/id block))))
         top? (:top? config)
         original-block (:original-block config)
@@ -2889,7 +2880,7 @@
         own-number-list? (:own-order-number-list? config)
         order-list? (boolean own-number-list?)
         selected? (when-not slide?
-                    (state/sub-block-selected? blocks-container-id uuid))]
+                    (state/sub-block-selected? uuid))]
     [:div.ls-block
      (cond->
       {:id block-id
@@ -2987,13 +2978,9 @@
 (rum/defcs block-container < rum/reactive db-mixins/query
   (rum/local false ::show-block-left-menu?)
   (rum/local false ::show-block-right-menu?)
-  (rum/local false ::blocks-container-id-changed?)
   {:init (fn [state]
            (let [[config block] (:rum/args state)
-                 block-id (:block/uuid block)
-                 container-id (if (:original-block config)
-                                (state/next-blocks-container-id)
-                                (:blocks-container-id config))]
+                 block-id (:block/uuid block)]
              (cond
                (root-block? config block)
                (state/set-collapsed-block! block-id false)
@@ -3006,8 +2993,7 @@
                nil)
              (assoc state
                     ::control-show? (atom false)
-                    ::navigating-block (atom (:block/uuid block))
-                    ::blocks-container-id (atom container-id))))
+                    ::navigating-block (atom (:block/uuid block)))))
    :will-unmount (fn [state]
                    ;; restore root block's collapsed state
                    (let [[config block] (:rum/args state)
@@ -3017,21 +3003,15 @@
                    state)}
   [state config block]
   (let [repo (state/get-current-repo)
-        *blocks-container-id (::blocks-container-id state)
-        *blocks-container-id-changed? (::blocks-container-id-changed? state)
         unloaded? (state/sub-block-unloaded? repo (str (:block/uuid block)))
         *navigating-block (get state ::navigating-block)
         navigating-block (rum/react *navigating-block)
         navigated? (and (not= (:block/uuid block) navigating-block) navigating-block)
         [original-block block] (build-block config block {:navigating-block navigating-block :navigated? navigated?})
-        _ (when (and original-block (false? @*blocks-container-id-changed?))
-            (reset! *blocks-container-id (state/next-blocks-container-id))
-            (reset! *blocks-container-id-changed? true))
-        config' (-> (if original-block
-                      (assoc config :original-block original-block)
-                      config)
-                    (assoc :blocks-container-id @*blocks-container-id))
-        opts {:blocks-container-id @*blocks-container-id}]
+        config' (if original-block
+                  (assoc config :original-block original-block)
+                  config)
+        opts {}]
     (if unloaded?
       [:div.ls-block.flex-1.flex-col.rounded-sm {:style {:width "100%"}}
        [:div.flex.flex-row
@@ -3441,9 +3421,7 @@
                   (assoc config :original-block original-block)
                   config)]
     (rum/with-key (block-container config' item)
-      (str (:blocks-container-id config')
-           "-"
-           (:block/uuid item)
+      (str (:block/uuid item)
            (when linked-block
              (str "-" (:block/uuid original-block)))))))
 
@@ -3500,10 +3478,7 @@
         *ref (::ref state)]
     [:<>
      (if (and hidden? (not (:disable-lazy-load? config)))
-       [:div {:key (str "item-"
-                    (:blocks-container-id config)
-                    "-"
-                    (:block/uuid item))}
+       [:div {:key (str "item-" (:block/uuid item))}
         {:style {:height 24}}]
        (block-item-inner config item (assoc opts :*ref *ref)))]))
 
@@ -3516,26 +3491,15 @@
         (block-item (assoc config :top? top?) item
                     {:top? top?
                      :bottom? bottom?})
-        (str "blocks-" (:blocks-container-id config)
-             "-"
-             (:block/uuid item))))))
+        (str "blocks-" (:block/uuid item))))))
 
 (rum/defcs blocks-container < rum/static
-  {:init (fn [state] (assoc state ::init-blocks-container-id (atom nil)))}
   [state blocks config]
-  (let [*init-blocks-container-id (::init-blocks-container-id state)
-        ;; blocks-container-id (if @*init-blocks-container-id
-        ;;                       @*init-blocks-container-id
-        ;;                       (let [id' (state/next-blocks-container-id)]
-        ;;                         (reset! *init-blocks-container-id id')
-        ;;                         id'))
-        blocks-container-id 0
-        config (assoc config :blocks-container-id blocks-container-id)
-        doc-mode? (:document/mode? config)]
+  (let [doc-mode? (:document/mode? config)]
     (when (seq blocks)
       [:div.blocks-container.flex-1
-         {:class (when doc-mode? "document-mode")}
-         (block-list config blocks)])))
+       {:class (when doc-mode? "document-mode")}
+       (block-list config blocks)])))
 
 (rum/defcs breadcrumb-with-container < rum/reactive db-mixins/query
   {:init (fn [state]

+ 3 - 8
src/main/frontend/components/property.cljs

@@ -442,7 +442,7 @@
 (defn- add-property-from-dropdown
   "Adds an existing or new property from dropdown. Used from a block or page context.
    For pages, used to add both schema properties or properties for a page"
-  [entity property-name {:keys [class-schema? blocks-container-id page-configure?
+  [entity property-name {:keys [class-schema? page-configure?
                                 *show-new-property-config?]}]
   (let [repo (state/get-current-repo)]
     ;; existing property selected or entered
@@ -456,7 +456,7 @@
                                                   ;; Only enter property names from sub-modal as inputting
                                                   ;; property values is buggy in sub-modal
                                                      :exit-edit? page-configure?})
-          (let [editor-id (str "ls-property-" blocks-container-id (:db/id entity) "-" (:db/id property))]
+          (let [editor-id (str "ls-property-" (:db/id entity) "-" (:db/id property))]
             (pv/set-editing! property editor-id "" ""))))
       ;; new property entered
       (if (db-property/valid-property-name? property-name)
@@ -715,9 +715,6 @@
 
 (rum/defcs ^:large-vars/cleanup-todo properties-area < rum/reactive
   (rum/local false ::hover?)
-  {:init (fn [state]
-           (assoc state ::blocks-container-id (or (:blocks-container-id (last (:rum/args state)))
-                                                  (state/next-blocks-container-id))))}
   [state target-block edit-input-id {:keys [in-block-container? page-configure? class-schema?] :as opts}]
   (let [*hover? (::hover? state)
         block (resolve-linked-block-if-exists target-block)
@@ -784,9 +781,7 @@
                                        (set/union properties (set cur-properties))
                                        (conj result [class cur-properties])))
                               result))
-        opts (assoc opts
-                    :blocks-container-id (::blocks-container-id state)
-                    :hover? @*hover?)]
+        opts (assoc opts :hover? @*hover?)]
     (when-not (and (empty? block-own-properties)
                    (empty? class->properties)
                    (not new-property?)

+ 3 - 6
src/main/frontend/components/property/value.cljs

@@ -378,7 +378,6 @@
     (when (seq children)
       [:div.property-block-container.w-full
        (block-cp children {:id (str (:block/uuid parent))
-                           :blocks-container-id (:blocks-container-id opts)
                            :editor-box editor-box
                            :in-property? true})])))
 
@@ -449,7 +448,6 @@
   [block property value {:keys [inline-text block-cp
                                 editor-id dom-id row?
                                 editor-box editor-args editing?
-                                blocks-container-id
                                 on-chosen]
                          :as opts}]
   (let [property (model/sub-block (:db/id property))
@@ -457,7 +455,7 @@
         schema (:block/schema property)
         type (get schema :type :default)
         multiple-values? (= :many (:cardinality schema))
-        editor-id (or editor-id (str "ls-property-" blocks-container-id "-" (:db/id block) "-" (:db/id property)))
+        editor-id (or editor-id (str "ls-property-" (:db/id block) "-" (:db/id property)))
         editing? (or editing? (state/sub-editing? editor-id))
         select-type? (select-type? type)
         select-opts {:on-chosen on-chosen}]
@@ -519,8 +517,7 @@
                    [:div.opacity-50.pointer.text-sm "Empty"])
                  (case type
                    :template
-                   (property-template-value {:blocks-container-id blocks-container-id
-                                             :editor-id editor-id}
+                   (property-template-value {:editor-id editor-id}
                                             value
                                             opts)
 
@@ -572,7 +569,7 @@
 
 (rum/defc property-value < rum/reactive
   [block property v opts]
-  (let [dom-id (str "ls-property-" (:blocks-container-id opts) "-" (:db/id block) "-" (:db/id property))
+  (let [dom-id (str "ls-property-" (:db/id block) "-" (:db/id property))
         editor-id (str dom-id "-editor")
         schema (:block/schema property)
         multiple-values? (= :many (:cardinality schema))

+ 8 - 6
src/main/frontend/components/right_sidebar.cljs

@@ -273,12 +273,14 @@
                [:button.button.close {:title (t :right-side-bar/pane-close)
                                       :on-click #(state/sidebar-remove-block! idx)} (ui/icon "x")]]]
              [:div.pt-4.p-1 {:role "region"
-                                          :id (str "sidebar-panel-content-" idx)
-                                          :aria-labelledby (str "sidebar-panel-header-" idx)
-                                          :class (util/classnames [{:hidden collapsed?
-                                                                    :initial (not collapsed?)
-                                                                    :p-4 (not (contains? #{:page :block :contents} block-type))}])}
-              (inner-component component (not drag-from))]
+                             :id (str "sidebar-panel-content-" idx)
+                             :aria-labelledby (str "sidebar-panel-header-" idx)
+                             :class (util/classnames [{:hidden collapsed?
+                                                       :initial (not collapsed?)
+                                                       :p-4 (not (contains? #{:page :block :contents} block-type))}])}
+              (ui/catch-error
+               [:span.warning "Something wrong happens"]
+               (inner-component component (not drag-from)))]
              (when drag-from (drop-area idx))])]
          (drop-indicator idx drag-to)]))))
 

+ 2 - 9
src/main/frontend/state.cljs

@@ -107,7 +107,6 @@
                                                true)
       :ui/scrolling?                         (atom false)
       :ui/new-property-input-id              nil
-      :ui/blocks-container-id                (atom 0)
       :document/mode?                        document-mode?
 
       :config                                {}
@@ -672,9 +671,9 @@ Similar to re-frame subscriptions"
        (distinct)))
 
 (defn sub-block-selected?
-  [container-id block-uuid]
+  [block-uuid]
   (rum/react
-   (rum/derived-atom [(:selection/blocks @state)] [::select-block container-id block-uuid]
+   (rum/derived-atom [(:selection/blocks @state)] [::select-block block-uuid]
      (fn [s]
        (contains? (set (get-selected-block-ids s)) block-uuid)))))
 
@@ -2292,12 +2291,6 @@ Similar to re-frame subscriptions"
      (fn [s]
        (contains? s (str block-uuid))))))
 
-(defn next-blocks-container-id
-  []
-  0
-  ;; (swap! (:ui/blocks-container-id @state) inc)
-  )
-
 (defn set-page-properties-changed!
   [page-name]
   (when-not (string/blank? page-name)