Просмотр исходного кода

fix: a number of editing actions in publishing app

Creating items from cmdk, more property config fields, action items from
page title, adding rows to table and property related shortcuts
Gabriel Horner 1 год назад
Родитель
Сommit
c22dab0d2f

+ 1 - 1
src/main/frontend/components/cmdk/core.cljs

@@ -75,7 +75,7 @@
   (string/replace input #"^#+" ""))
 
 (defn create-items [q]
-  (when-not (string/blank? q)
+  (when (and (not (string/blank? q)) (not config/publishing?))
     (let [class? (string/starts-with? q "#")]
       (->> [{:text (if class? "Create tag" "Create page")       :icon "new-page"
              :icon-theme :gray

+ 1 - 1
src/main/frontend/components/page.cljs

@@ -427,7 +427,7 @@
   (rum/local false ::hover?)
   [state page whiteboard-page? sidebar? container-id]
   (let [*hover? (::hover? state)
-        hover? (rum/react *hover?)]
+        hover? (and (rum/react *hover?) (not config/publishing?))]
     [:div.ls-page-title.flex.flex-1.w-full.content.items-start.title
      {:class (when-not whiteboard-page? "title")
       :on-pointer-down (fn [e]

+ 28 - 25
src/main/frontend/components/property/config.cljs

@@ -352,7 +352,7 @@
       "Add choices")]))
 
 (rum/defc choices-sub-pane < rum/reactive db-mixins/query
-  [property]
+  [property {:keys [disabled?]}]
   (let [values (:property/closed-values property)
         choices (doall
                  (keep (fn [value]
@@ -386,29 +386,30 @@
                                                    {:outliner-op :save-block})))})])
 
      ;; add choice
-     (dropdown-editor-menuitem
-      {:icon :plus :title "Add choice"
-       :item-props {:on-click
-                    (fn [^js e]
-                      (p/let [values (db-async/<get-block-property-values (state/get-current-repo) (:db/ident property))
-                              existing-values (seq (:property/closed-values property))
-                              values (if (seq existing-values)
-                                       (let [existing-ids (set (map :db/id existing-values))]
-                                         (remove (fn [id] (existing-ids id)) values))
-                                       values)]
-                        (shui/popup-show! (.-target e)
-                                          (fn [{:keys [id]}]
-                                            (let [opts {:toggle-fn (fn [] (shui/popup-hide! id))}
-                                                  values' (->> (if (contains? db-property-type/user-ref-property-types (get-in property [:block/schema :type]))
-                                                                 (map #(:block/uuid (db/entity %)) values)
-                                                                 values)
-                                                               (remove string/blank?)
-                                                               distinct)]
-                                              (if (seq values')
-                                                (add-existing-values property values' opts)
-                                                (choice-base-edit-form property {:create? true}))))
-                                          {:id :ls-base-edit-form
-                                           :align "start"})))}})]))
+     (when-not disabled?
+       (dropdown-editor-menuitem
+        {:icon :plus :title "Add choice"
+         :item-props {:on-click
+                      (fn [^js e]
+                        (p/let [values (db-async/<get-block-property-values (state/get-current-repo) (:db/ident property))
+                                existing-values (seq (:property/closed-values property))
+                                values (if (seq existing-values)
+                                         (let [existing-ids (set (map :db/id existing-values))]
+                                           (remove (fn [id] (existing-ids id)) values))
+                                         values)]
+                          (shui/popup-show! (.-target e)
+                                            (fn [{:keys [id]}]
+                                              (let [opts {:toggle-fn (fn [] (shui/popup-hide! id))}
+                                                    values' (->> (if (contains? db-property-type/user-ref-property-types (get-in property [:block/schema :type]))
+                                                                   (map #(:block/uuid (db/entity %)) values)
+                                                                   values)
+                                                                 (remove string/blank?)
+                                                                 distinct)]
+                                                (if (seq values')
+                                                  (add-existing-values property values' opts)
+                                                  (choice-base-edit-form property {:create? true}))))
+                                            {:id :ls-base-edit-form
+                                             :align "start"})))}}))]))
 
 (def position-labels
   {:properties {:icon :layout-distribute-horizontal :title "Block properties"}
@@ -530,7 +531,7 @@
        (let [values (:property/closed-values property)]
          (dropdown-editor-menuitem {:icon :list :title "Available choices"
                                     :desc (when (seq values) (str (count values) " choices"))
-                                    :submenu-content (fn [] (choices-sub-pane property))})))
+                                    :submenu-content (fn [] (choices-sub-pane property {:disabled? config/publishing?}))})))
 
      (let [many? (db-property/many? property)]
        (dropdown-editor-menuitem {:icon :checks :title "Multiple values"
@@ -555,10 +556,12 @@
                           (let [position (:position property-schema)]
                             (dropdown-editor-menuitem {:icon :float-left :title "UI position" :desc (some->> position (get position-labels) (:title))
                                                        :item-props {:class "ui__position-trigger-item"}
+                                                       :disabled? config/publishing?
                                                        :submenu-content (fn [ops] (ui-position-sub-pane property (assoc ops :position position)))})))
 
                         (when (not (contains? #{:logseq.property/parent :logseq.property.class/properties} (:db/ident property)))
                           (dropdown-editor-menuitem {:icon :eye-off :title "Hide by default" :toggle-checked? (boolean (:hide? property-schema))
+                                                     :disabled? config/publishing?
                                                      :on-toggle-checked-change #(db-property-handler/upsert-property! (:db/ident property)
                                                                                                                       (assoc property-schema :hide? %) {})}))]
                        (remove nil?))]

+ 5 - 1
src/main/frontend/components/views.cljs

@@ -1248,5 +1248,9 @@
   (rum/local nil ::scroller-ref)
   [state view-entity option]
   (let [view-entity' (db/sub-block (:db/id view-entity))]
-    (rum/with-key (view-inner view-entity' option (::scroller-ref state))
+    (rum/with-key (view-inner view-entity'
+                              (cond-> option
+                                config/publishing?
+                                (dissoc :add-new-object!))
+                              (::scroller-ref state))
       (str "view-" (:db/id view-entity')))))

+ 58 - 54
src/main/frontend/handler/events.cljs

@@ -919,61 +919,65 @@
   (when-let [blocks (and block (db-model/get-block-immediate-children (state/get-current-repo) (:block/uuid block)))]
     (editor-handler/toggle-blocks-as-own-order-list! blocks)))
 
+(defn- editor-new-property [block target opts]
+  (let [editing-block (state/get-edit-block)
+        pos (state/get-edit-pos)
+        edit-block-or-selected (if editing-block
+                                 [editing-block]
+                                 (seq (keep #(db/entity [:block/uuid %]) (state/get-selection-block-ids))))
+        current-block (when-let [s (state/get-current-page)]
+                        (when (util/uuid-string? s)
+                          (db/entity [:block/uuid (uuid s)])))
+        blocks (or (when block [block])
+                   edit-block-or-selected
+                   (when current-block [current-block]))
+        opts' (cond-> opts
+                editing-block
+                (assoc :original-block editing-block
+                       :edit-original-block
+                       (fn [{:keys [editing-default-property?]}]
+                         (when editing-block
+                           (let [content (:block/title (db/entity (:db/id editing-block)))
+                                 esc? (= "Escape" (state/get-ui-last-key-code))
+                                 [content' pos] (cond
+                                                  esc?
+                                                  [nil pos]
+                                                  (and (>= (count content) pos)
+                                                       (>= pos 2)
+                                                       (= (util/nth-safe content (dec pos))
+                                                          (util/nth-safe content (- pos 2))
+                                                          ";"))
+                                                  [(str (common-util/safe-subs content 0 (- pos 2))
+                                                        (common-util/safe-subs content pos))
+                                                   (- pos 2)]
+                                                  :else
+                                                  [nil pos])]
+                             (when content'
+                               (if editing-default-property?
+                                 (editor-handler/save-block! (state/get-current-repo) (:block/uuid editing-block) content')
+                                 (editor-handler/edit-block! editing-block (or pos :max)
+                                                             (cond-> {}
+                                                               content'
+                                                               (assoc :custom-content content'))))))))))]
+    (when (seq blocks)
+      (let [target' (or target
+                        (some-> (state/get-edit-input-id)
+                                (gdom/getElement))
+                        (first (state/get-selection-blocks)))]
+        (if target'
+          (shui/popup-show! target'
+                            #(property-dialog/dialog blocks opts')
+                            {:align "start"
+                             :auto-focus? true})
+          (shui/dialog-open! #(property-dialog/dialog blocks opts')
+                             {:id :property-dialog
+                              :align "start"}))))))
+
 (defmethod handle :editor/new-property [[_ {:keys [block target] :as opts}]]
-  (p/do!
-   (editor-handler/save-current-block!)
-   (let [editing-block (state/get-edit-block)
-         pos (state/get-edit-pos)
-         edit-block-or-selected (if editing-block
-                                  [editing-block]
-                                  (seq (keep #(db/entity [:block/uuid %]) (state/get-selection-block-ids))))
-         current-block (when-let [s (state/get-current-page)]
-                         (when (util/uuid-string? s)
-                           (db/entity [:block/uuid (uuid s)])))
-         blocks (or (when block [block])
-                    edit-block-or-selected
-                    (when current-block [current-block]))
-         opts' (cond-> opts
-                 editing-block
-                 (assoc :original-block editing-block
-                        :edit-original-block
-                        (fn [{:keys [editing-default-property?]}]
-                          (when editing-block
-                            (let [content (:block/title (db/entity (:db/id editing-block)))
-                                  esc? (= "Escape" (state/get-ui-last-key-code))
-                                  [content' pos] (cond
-                                                   esc?
-                                                   [nil pos]
-                                                   (and (>= (count content) pos)
-                                                        (>= pos 2)
-                                                        (= (util/nth-safe content (dec pos))
-                                                           (util/nth-safe content (- pos 2))
-                                                           ";"))
-                                                   [(str (common-util/safe-subs content 0 (- pos 2))
-                                                         (common-util/safe-subs content pos))
-                                                    (- pos 2)]
-                                                   :else
-                                                   [nil pos])]
-                              (when content'
-                                (if editing-default-property?
-                                  (editor-handler/save-block! (state/get-current-repo) (:block/uuid editing-block) content')
-                                  (editor-handler/edit-block! editing-block (or pos :max)
-                                                              (cond-> {}
-                                                                content'
-                                                                (assoc :custom-content content'))))))))))]
-     (when (seq blocks)
-       (let [target' (or target
-                         (some-> (state/get-edit-input-id)
-                                 (gdom/getElement))
-                         (first (state/get-selection-blocks)))]
-         (if target'
-           (shui/popup-show! target'
-                             #(property-dialog/dialog blocks opts')
-                             {:align "start"
-                              :auto-focus? true})
-           (shui/dialog-open! #(property-dialog/dialog blocks opts')
-                              {:id :property-dialog
-                               :align "start"})))))))
+  (when-not config/publishing?
+    (p/do!
+     (editor-handler/save-current-block!)
+     (editor-new-property block target opts))))
 
 (defmethod handle :editor/upsert-type-block [[_ {:keys [block type lang update-current-block?]}]]
   (p/do!