Browse Source

Merge branch 'feat/db' into refactor/db-properties-schema

Tienson Qin 1 year ago
parent
commit
912ddd6ca2

+ 2 - 0
.carve/ignore

@@ -84,3 +84,5 @@ frontend.worker.rtc.op-mem-layer/_sync-loop
 frontend.db-worker/init
 ;; WIP fn, remove when it's ready
 frontend.worker.rtc.asset-sync/<loop-for-assets-sync
+;; Future use?
+frontend.worker.rtc.hash/hash-blocks

+ 1 - 3
deps/db/src/logseq/db/frontend/delete_blocks.cljs

@@ -2,7 +2,6 @@
   "Delete refs/macros when deleting blocks"
   (:require [logseq.common.util :as common-util]
             [logseq.common.util.block-ref :as block-ref]
-            [logseq.graph-parser.property :as gp-property]
             [datascript.core :as d]
             [clojure.string :as string]))
 
@@ -19,8 +18,7 @@
                                 (let [refs (:block/_refs block)]
                                   (map (fn [ref]
                                          (let [id (:db/id ref)
-                                               block-content (gp-property/remove-properties
-                                                              (:block/format block) (:block/content block))
+                                               block-content (:block/content ref)
                                                new-content (some-> (:block/content ref)
                                                                    (string/replace (re-pattern (common-util/format "(?i){{embed \\(\\(%s\\)\\)\\s?}}" (str (:block/uuid block))))
                                                                                    block-content)

+ 2 - 2
deps/outliner/src/logseq/outliner/core.cljs

@@ -85,7 +85,7 @@
   (let [updated-at (common-util/time-ms)]
     (assoc block :block/updated-at updated-at)))
 
-(defn filter-top-level-blocks
+(defn- filter-top-level-blocks
   [blocks]
   (let [parent-ids (set/intersection (set (map (comp :db/id :block/parent) blocks))
                                      (set (map :db/id blocks)))]
@@ -964,7 +964,7 @@
           (otree/-save new-right-node txs-state conn repo date-formatter {}))))
     @txs-state))
 
-(defn- ^:large-vars/cleanup-todo delete-blocks
+(defn ^:api ^:large-vars/cleanup-todo delete-blocks
   "Delete blocks from the tree.
   `blocks` need to be sorted by left&parent(from top to bottom)"
   [repo conn date-formatter blocks delete-opts]

+ 3 - 3
packages/ui/yarn.lock

@@ -8907,9 +8907,9 @@ tar-stream@^2.1.4:
     readable-stream "^3.1.1"
 
 tar@^6.2.0:
-  version "6.2.0"
-  resolved "https://registry.yarnpkg.com/tar/-/tar-6.2.0.tgz#b14ce49a79cb1cd23bc9b016302dea5474493f73"
-  integrity sha512-/Wo7DcT0u5HUV486xg675HtjNd3BXZ6xDbzsCUZPt5iw8bTQ63bP0Raut3mvro9u+CUyq7YQd8Cx55fsZXxqLQ==
+  version "6.2.1"
+  resolved "https://registry.yarnpkg.com/tar/-/tar-6.2.1.tgz#717549c541bc3c2af15751bea94b1dd068d4b03a"
+  integrity sha512-DZ4yORTwrbTj/7MZYq2w+/ZFdI6OZ/f9SFHR+71gIVUZhOQPHzVCLpvRnPgyaMpfWxxk/4ONva3GQSyNIKRv6A==
   dependencies:
     chownr "^2.0.0"
     fs-minipass "^2.0.0"

+ 2 - 2
src/main/frontend/common.css

@@ -567,8 +567,8 @@ a.navigation {
 /* text mark/highlight */
 
 mark {
-  background: var(--ls-page-mark-bg-color);
-  color: var(--ls-page-mark-color);
+  background: var(--ls-page-mark-bg-color, #fef3ac);
+  color: var(--ls-page-mark-color, #262626);
   padding: 2px 4px;
   border-radius: 3px;
 }

+ 32 - 21
src/main/frontend/components/block.cljs

@@ -60,6 +60,7 @@
             [frontend.state :as state]
             [frontend.template :as template]
             [frontend.ui :as ui]
+            [logseq.shui.ui :as shui]
             [frontend.util :as util]
             [frontend.extensions.pdf.utils :as pdf-utils]
             [frontend.util.clock :as clock]
@@ -78,7 +79,7 @@
             [logseq.common.util.block-ref :as block-ref]
             [logseq.common.util.page-ref :as page-ref]
             [logseq.common.util.macro :as macro-util]
-            [logseq.shui.core :as shui]
+            [logseq.shui.core :as shui-core]
             [medley.core :as medley]
             [promesa.core :as p]
             [reitit.frontend.easy :as rfe]
@@ -2153,12 +2154,30 @@
         [:button.p-1.mr-2 p])]
      [:code "Property name begins with a non-numeric character and can contain alphanumeric characters and . * + ! - _ ? $ % & = < >. If -, + or . are the first character, the second character (if any) must be non-numeric."]]))
 
+(rum/defc timestamp-editor
+  [ast *show-datapicker?]
+
+  (let [*trigger-ref (rum/use-ref nil)]
+    (rum/use-effect!
+      (fn []
+        (let [pid (shui/popup-show!
+                    (.closest (rum/deref *trigger-ref) "a")
+                    (datetime-comp/date-picker nil nil (repeated/timestamp->map ast))
+                    {:id :timestamp-editor
+                     :align :start
+                     :root-props {:onOpenChange #(reset! *show-datapicker? %)}
+                     :content-props {:onEscapeKeyDown #(reset! *show-datapicker? false)}})]
+          #(do (shui/popup-hide! pid)
+               (reset! *show-datapicker? false))))
+      [])
+    [:i {:ref *trigger-ref}]))
+
 (rum/defcs timestamp-cp
   < rum/reactive
   (rum/local false ::show-datepicker?)
   [state block typ ast]
   (let [ts-block-id (get-in (state/sub [:editor/set-timestamp-block]) [:block :block/uuid])
-        active? (= (get block :block/uuid) ts-block-id)
+        _active? (= (get block :block/uuid) ts-block-id)
         *show-datapicker? (get state ::show-datepicker?)]
     [:div.flex.flex-col.gap-4.timestamp
      [:div.text-sm.flex.flex-row
@@ -2166,24 +2185,16 @@
        (str typ ": ")]
       [:a.opacity-80.hover:opacity-100
        {:on-pointer-down (fn [e]
-                         (util/stop e)
-                         (state/clear-editor-action!)
-                         (editor-handler/escape-editing false)
-                         (if active?
-                           (do
-                             (reset! *show-datapicker? false)
-                             (reset! commands/*current-command nil)
-                             (state/set-timestamp-block! nil))
-                           (do
-                             (reset! *show-datapicker? true)
-                             (reset! commands/*current-command typ)
-                             (state/set-timestamp-block! {:block block
-                                                          :typ typ}))))}
-       [:span.time-start "<"] [:time (repeated/timestamp->text ast)] [:span.time-stop ">"]]]
-     ;; date-picker in rendering-mode
-     (if (and active? @*show-datapicker?)
-       (datetime-comp/date-picker nil nil (repeated/timestamp->map ast))
-       (reset! *show-datapicker? false))]))
+                           (util/stop e)
+                           (state/clear-editor-action!)
+                           (editor-handler/escape-editing false)
+                           (reset! *show-datapicker? true)
+                           (reset! commands/*current-command typ)
+                           (state/set-timestamp-block! {:block block
+                                                        :typ typ}))}
+       [:span.time-start "<"] [:time (repeated/timestamp->text ast)] [:span.time-stop ">"]
+       (when (and _active? @*show-datapicker?)
+         (timestamp-editor ast *show-datapicker?))]]]))
 
 (defn- target-forbidden-edit?
   [target]
@@ -3218,7 +3229,7 @@
                         (config/db-based-graph? (state/get-current-repo))
                         (assoc-in [:block :properties]
                                   (db-pu/readable-properties (get-in config [:block :block/properties]))))]
-        (shui/table-v2 {:data (concat [[header]] groups)}
+        (shui-core/table-v2 {:data (concat [[header]] groups)}
                        (make-shui-context v2-config inline)))
     1 (let [tr (fn [elm cols]
                  (->elem

+ 8 - 0
src/main/frontend/components/block.css

@@ -223,6 +223,14 @@
   &.as-heading {
     @apply flex w-full;
   }
+
+  &:has(.dsl-query) {
+    @apply flex flex-row w-full;
+  }
+
+  .dsl-query {
+    @apply w-full;
+  }
 }
 
 .block-control, .block-control:hover {

+ 9 - 210
src/main/frontend/components/datepicker.css

@@ -1,210 +1,9 @@
-/*----------------------------------------------------------------------------------------
- Stylesheet for re-com.date Date Picker variants inline-picker & dropdown-picker
- Day8 variation loosely based on:
- Copyright 2013 Dan Grossman ( http://www.dangrossman.info )
- Licensed under the Apache License v2.0
- http://www.apache.org/licenses/LICENSE-2.0
- Built for http://www.improvely.com
- http://eternicode.github.io/bootstrap-datepicker
-----------------------------------------------------------------------------------------*/
-
-.noselect {
-  user-select: none;
-}
-
-.datepicker.single .calendar {
-  float: none;
-}
-
-.datepicker .calendar {
-  display: none;
-  max-width: 200px;
-}
-
-.datepicker .calendar.single .calendar-date {
-  border: none;
-}
-
-.datepicker .calendar th,
-.datepicker .calendar td {
-  white-space: nowrap;
-  text-align: center;
-  min-width: 32px;
-}
-
-.datepicker .calendar-date {
-  border: 1px solid #ddd;
-  padding: 4px;
-  border-radius: 4px;
-}
-
-.datepicker .calendar-time {
-  text-align: center;
-  margin: 8px auto 0 auto;
-  line-height: 30px;
-}
-
-.datepicker {
-  position: absolute;
-  top: 100px;
-  left: 20px;
-  padding: 10px;
-  line-height: 16px;
-  border-radius: 4px;
-}
-
-.datepicker table {
-  width: 100%;
-  margin: 0;
-  border-collapse: separate;
-  border-spacing: 0;
-  background: transparent;
-  border: none;
-}
-
-.datepicker td,
-.datepicker th {
-  text-align: center;
-  width: 27px;
-  height: 26px;
-  max-width: 27px;
-  max-height: 26px;
-  min-width: 27px;
-  min-height: 26px;
-  padding: 4px;
-  cursor: default;
-  white-space: nowrap;
-  font-weight: normal;
-}
-
-.datepicker td.off {
-  padding: 4px;
-  color: #999;
-}
-
-.datepicker td.disabled {
-  color: #999;
-}
-
-.datepicker th.disabled {
-  color: #999;
-}
-
-.datepicker td.available:hover,
-.datepicker th.available:hover {
-  @apply rounded bg-gray-07 cursor-pointer;
-}
-
-.datepicker td.in-range {
-  background: #ebf4f8;
-  border-radius: 0;
-}
-
-.datepicker td.start-date {
-  border-radius: 4px 0 0 4px;
-}
-
-.datepicker td.end-date {
-  border-radius: 0 4px 4px 0;
-}
-
-.datepicker td.start-date.end-date {
-  border-radius: 4px;
-}
-
-.datepicker td.active,
-.datepicker td.active:hover {
-  @apply bg-accent/90 border border-accent text-accent-foreground;
-}
-
-/* Introduced by Day8 from http://eternicode.github.io/bootstrap-datepicker */
-.datepicker td.today,
-.datepicker td.today:hover {
-  background-color: #ffcd70;
-  border-color: #f59e00;
-  border-radius: 18px;
-  color: #fff;
-}
-
-.datepicker th.day-enabled,
-label.day-enabled {
-  font-weight: normal;
-  font-size: 10px;
-  color: #333;
-}
-
-.datepicker th.selectable {
-  @apply font-normal text-accent;
-}
-
-.datepicker th.day-disabled {
-  font-weight: normal;
-  font-size: 10px;
-  color: #999;
-}
-
-.datepicker td.week,
-.datepicker th.week {
-  font-size: 80%;
-  color: #ccc;
-}
-
-.datepicker th.month {
-  width: auto;
-  font-size: 14px;
-  color: var(--ls-title-text-color);
-}
-
-.dropdown-button {
-  cursor: pointer;
-  height: 32px;
-  font-size: 13px;
-  font-weight: normal;
-}
-
-.dropdown-button.activator {
-  width: 40px;
-  color: #777;
-  /* background-color: #F7F7F7 */
-}
-
-.table-condensed > thead > tr > th,
-.table-condensed > tbody > tr > th,
-.table-condensed > tfoot > tr > th,
-.table-condensed > thead > tr > td,
-.table-condensed > tbody > tr > td,
-.table-condensed > tfoot > tr > td {
-  padding: 5px;
-}
-
-.dark-theme .datepicker {
-  background: var(--ls-secondary-background-color);
-}
-
-.dark-theme .datepicker th.day-disabled,
-.dark-theme .datepicker th.disabled,
-.dark-theme .datepicker td.disabled,
-.dark-theme .datepicker td.off {
-  color: #666;
-}
-
-.dark-theme .datepicker th.day-enabled,
-.dark-theme label.day-enabled {
-  color: currentColor;
-}
-
-.datepicker tr:nth-child(odd),
-.datepicker tr:nth-child(even),
-.dark-theme .datepicker tr:nth-child(odd),
-.dark-theme .datepicker tr:nth-child(even) {
-  background: transparent;
-}
-
-.datepicker th,
-.datepicker tr,
-.datepicker td,
-.dark-theme .datepicker th,
-.dark-theme .datepicker tr,
-.dark-theme .datepicker td {
-  border-bottom: none;
-}
+#time-repeater {
+ input.form-input, select.form-select {
+   @apply h-8 mt-0;
+ }
+
+ select.form-select {
+   @apply leading-none;
+ }
+}

+ 5 - 3
src/main/frontend/components/datetime.cljs

@@ -46,7 +46,7 @@
   [{:keys [num duration kind]}]
   (let [show? (rum/react *show-repeater?)]
     (if (or show? (and num duration kind))
-      [:div.w.full.flex.flex-row.justify-left
+      [:div.w.full.flex.flex-row.justify-left.items-center
        [:input#repeater-num.form-input.w-8.mr-2.px-1.sm:w-20.sm:px-2.text-center
         {:default-value num
          :on-change (fn [event]
@@ -90,7 +90,7 @@
   [e]
   (when e (util/stop e))
   (let [{:keys [repeater] :as timestamp} @*timestamp
-        date (:date-picker/date @state/state)
+        date (-> (:date-picker/date @state/state) date/js-date->goog-date)
         timestamp (assoc timestamp :date (or date (t/today)))
         kind (if (= "w" (:duration repeater)) "++" ".+")
         timestamp (assoc-in timestamp [:repeater :kind] kind)
@@ -162,7 +162,8 @@
                                 format
                                 {:command :page-ref})
                               (state/clear-editor-action!)
-                              (reset! commands/*current-command nil))))]
+                              (reset! commands/*current-command nil))
+                            (state/set-state! :date-picker/date d)))]
     [:div#date-time-picker.flex.flex-col.sm:flex-row
      ;; inline container
      [:div.border-red-500
@@ -170,6 +171,7 @@
         {:mode "single"
          :initial-focus true
          :show-week-number true
+         :selected _date
          :on-select select-handler!
          :on-day-key-down (fn [^js d _ ^js e]
                             (when (= "Enter" (.-key e))

+ 45 - 38
src/main/frontend/components/query/builder.cljs

@@ -11,6 +11,7 @@
             [frontend.components.select :as component-select]
             [frontend.state :as state]
             [frontend.util :as util]
+            [logseq.shui.ui :as shui]
             [frontend.search :as search]
             [frontend.mixins :as mixins]
             [logseq.graph-parser.db :as gp-db]
@@ -75,50 +76,58 @@
       :aria-label "Full text search"
       :on-change #(reset! *input-value (util/evalue %))}]))
 
-(defonce *shown-datepicker (atom nil))
 (defonce *between-dates (atom {}))
 (rum/defcs datepicker < rum/reactive
-  (rum/local nil ::input-value)
-  {:init (fn [state]
-           (when (:auto-focus (last (:rum/args state)))
-             (reset! *shown-datepicker (first (:rum/args state))))
-           state)
-   :will-unmount (fn [state]
-                   (swap! *between-dates dissoc (first (:rum/args state)))
-                   state)}
+                        (rum/local nil ::input-value)
+                        {:will-unmount (fn [state]
+                                         (swap! *between-dates dissoc (first (:rum/args state)))
+                                         state)}
   [state id placeholder {:keys [auto-focus]}]
-  (let [*input-value (::input-value state)
-        show? (= id (rum/react *shown-datepicker))]
+  (let [*input-value (::input-value state)]
     [:div.ml-4
      [:input.query-builder-datepicker.form-input.block.sm:text-sm.sm:leading-5
       {:auto-focus (or auto-focus false)
        :placeholder placeholder
        :aria-label placeholder
-       :value @*input-value
-       :on-click #(reset! *shown-datepicker id)}]
-     (when show?
-       (ui/datepicker nil {:on-change (fn [_e date]
-                                        (let [journal-date (date/journal-name date)]
-                                          (reset! *input-value journal-date)
-                                          (reset! *shown-datepicker nil)
-                                          (swap! *between-dates assoc id journal-date)))}))]))
+       :value (some-> @*input-value (first))
+       :on-focus (fn [^js e]
+                   (js/setTimeout
+                     #(shui/popup-show! (.-target e)
+                        (let [select-handle! (fn [^js d]
+                                               (let [gd (date/js-date->goog-date d)
+                                                     journal-date (date/js-date->journal-title gd)]
+                                                 (reset! *input-value [journal-date d])
+                                                 (swap! *between-dates assoc id journal-date))
+                                               (shui/popup-hide!))]
+                          (shui/calendar
+                            {:mode "single"
+                             :initial-focus true
+                             :selected (some-> @*input-value (second))
+                             :on-select select-handle!
+                             :on-day-key-down (fn [^js d _ ^js e]
+                                                (when (= "Enter" (.-key e))
+                                                  (select-handle! d)
+                                                  (util/stop e)))}))
+                        {:id :query-datepicker
+                         :align :start}) 16))}]]))
 
 (rum/defcs between <
   (rum/local nil ::start)
   (rum/local nil ::end)
   [state {:keys [tree loc] :as opts}]
-  [:div.between-date {:on-pointer-down (fn [e] (util/stop-propagation e))}
+  [:div.between-date.p-4 {:on-pointer-down (fn [e] (util/stop-propagation e))}
    [:div.flex.flex-row
     [:div.font-medium.mt-2 "Between: "]
     (datepicker :start "Start date" (merge opts {:auto-focus true}))
     (datepicker :end "End date" opts)]
-   (ui/button "Submit"
-     :on-click (fn []
-                 (let [{:keys [start end]} @*between-dates]
-                   (when (and start end)
-                     (let [clause [:between [:page-ref start] [:page-ref end]]]
-                       (append-tree! tree opts loc clause)
-                       (reset! *between-dates {}))))))])
+   [:p.pt-2
+    (ui/button "Submit"
+      :on-click (fn []
+                  (let [{:keys [start end]} @*between-dates]
+                    (when (and start end)
+                      (let [clause [:between [:page-ref start] [:page-ref end]]]
+                        (append-tree! tree opts loc clause)
+                        (reset! *between-dates {}))))))]])
 
 (rum/defc property-select
   [*mode *property]
@@ -280,21 +289,19 @@
              (append-tree! *tree opts loc [(keyword value)])
 
              :else
-             (do (reset! *mode value)
-                 ((:toggle-fn opts)))))
+             (reset! *mode value)))
          {:input-default-placeholder "Add filter/operator"})])]))
 
 (rum/defc add-filter
   [*find *tree loc clause]
-  (ui/dropdown
-   (fn [{:keys [toggle-fn]}]
-     [:a.flex.add-filter {:title "Add clause"
-                          :on-click toggle-fn}
-      (ui/icon "plus" {:style {:font-size 20}})])
-   (fn [{:keys [toggle-fn]}]
-     (picker *find *tree loc clause {:toggle-fn toggle-fn}))
-   {:modal-class (util/hiccup->class
-                  "origin-top-right.absolute.left-0.mt-2.ml-2.rounded-md.shadow-lg")}))
+  [:a.flex.add-filter
+   {:title "Add clause"
+    :on-click (fn [^js e]
+                (shui/popup-show! (.-target e)
+                  (fn [{:keys [id]}]
+                    (picker *find *tree loc clause {:toggle-fn #(shui/popup-hide! id)}))
+                  {}))}
+   (ui/icon "plus" {:style {:font-size 20}})])
 
 (declare clauses-group)
 

+ 7 - 0
src/main/frontend/date.cljs

@@ -172,6 +172,13 @@
   [date]
   (journal-name (tc/to-local-date date)))
 
+(defn js-date->goog-date
+  [d]
+  (cond
+    (some->> d (instance? js/Date))
+    (goog.date.Date. (.getFullYear d) (.getMonth d) (.getDate d))
+    :else d))
+
 (comment
   (def default-formatter (tf/formatter "MMM do, yyyy"))
   (def zh-formatter (tf/formatter "YYYY年MM月dd日"))

+ 1 - 55
src/main/frontend/handler/ui.cljs

@@ -1,6 +1,5 @@
 (ns ^:no-doc frontend.handler.ui
-  (:require [cljs-time.core :refer [days plus weeks]]
-            [clojure.string :as string]
+  (:require [clojure.string :as string]
             [dommy.core :as dom]
             [electron.ipc :as ipc]
             [frontend.config :as config]
@@ -238,59 +237,6 @@
                       @current-idx))
           (on-chosen-open-link (nth matched @current-idx) false))))))
 
-;; date-picker
-;; TODO: find a better way
-(def *internal-model (rum/cursor state/state :date-picker/date))
-
-(defn- non-edit-input?
-  []
-  (when-let [elem js/document.activeElement]
-    (and (util/input? elem)
-         (when-let [id (gobj/get elem "id")]
-           (not (string/starts-with? id "edit-block-"))))))
-
-(defn- input-or-select?
-  []
-  (when-let [elem js/document.activeElement]
-    (or (non-edit-input?)
-        (util/select? elem))))
-
-(defn- inc-date [date n] (plus date (days n)))
-
-(defn- inc-week [date n] (plus date (weeks n)))
-
-(defn shortcut-complete
-  [state e]
-  (let [{:keys [on-change deadline-or-schedule?]} (last (:rum/args state))]
-    (when (and on-change
-               (not (input-or-select?)))
-      (when-not deadline-or-schedule?
-        (on-change e @*internal-model)))))
-
-(defn shortcut-prev-day
-  [_state e]
-  (when-not (input-or-select?)
-    (util/stop e)
-    (swap! *internal-model inc-date -1)))
-
-(defn shortcut-next-day
-  [_state e]
-  (when-not (input-or-select?)
-    (util/stop e)
-    (swap! *internal-model inc-date 1)))
-
-(defn shortcut-prev-week
-  [_state e]
-  (when-not (input-or-select?)
-    (util/stop e)
-    (swap! *internal-model inc-week -1)))
-
-(defn shortcut-next-week
-  [_state e]
-  (when-not (input-or-select?)
-    (util/stop e)
-    (swap! *internal-model inc-week 1)))
-
 (defn toggle-cards!
   []
   (if (and (= :srs (:modal/id @state/state)) (:modal/show? @state/state))

+ 1 - 24
src/main/frontend/modules/shortcut/config.cljs

@@ -51,25 +51,7 @@
 ;;  * :file-graph? - Optional boolean to identify a command to only be run in file graphs
 ;;    and warned gracefully in db graphs
 (def ^:large-vars/data-var all-built-in-keyboard-shortcuts
-  ;; BUG: Actually, "enter" is registered by mixin behind a "when inputing" guard
-  ;; So this setting item does not cover all cases.
-  ;; See-also: frontend.components.datetime/time-repeater
-  {:date-picker/complete                    {:binding "enter"
-                                             :fn      ui-handler/shortcut-complete}
-
-   :date-picker/prev-day                    {:binding "left"
-                                             :fn      ui-handler/shortcut-prev-day}
-
-   :date-picker/next-day                    {:binding "right"
-                                             :fn      ui-handler/shortcut-next-day}
-
-   :date-picker/prev-week                   {:binding ["up" "ctrl+p"]
-                                             :fn      ui-handler/shortcut-prev-week}
-
-   :date-picker/next-week                   {:binding ["down" "ctrl+n"]
-                                             :fn      ui-handler/shortcut-next-week}
-
-   :pdf/previous-page                       {:binding "alt+p"
+  {:pdf/previous-page                       {:binding "alt+p"
                                              :fn      pdf-utils/prev-page}
 
    :pdf/next-page                           {:binding "alt+n"
@@ -953,11 +935,6 @@
       :auto-complete/shift-complete
       :auto-complete/meta-complete
       :auto-complete/open-link
-      :date-picker/prev-day
-      :date-picker/next-day
-      :date-picker/prev-week
-      :date-picker/next-week
-      :date-picker/complete
       :git/commit
       :dev/show-block-data
       :dev/show-block-ast

+ 0 - 3
src/main/frontend/ui.cljs

@@ -27,7 +27,6 @@
             [frontend.rum :as r]
             [frontend.state :as state]
             [frontend.storage :as storage]
-            [frontend.ui.date-picker]
             [frontend.util :as util]
             [frontend.util.cursor :as cursor]
             [goog.dom :as gdom]
@@ -583,8 +582,6 @@
        (when empty-placeholder
          empty-placeholder))]))
 
-(def datepicker frontend.ui.date-picker/date-picker)
-
 (defn toggle
   ([on? on-click] (toggle on? on-click false))
   ([on? on-click small?]

+ 0 - 189
src/main/frontend/ui/date_picker.cljs

@@ -1,189 +0,0 @@
-(ns ^:no-doc frontend.ui.date-picker
-  (:require [cljs-time.core       :refer [after? before? day day-of-week days first-day-of-the-month minus month months plus year]]
-            [cljs-time.format     :refer [formatter unparse]]
-            [frontend.modules.shortcut.core :as shortcut]
-            [frontend.state :as state]
-            [frontend.util  :as util    :refer [deref-or-value now->utc]]
-            [rum.core :as rum]))
-
-;; Adapted from re-com date-picker
-
-;; TODO: add left, right, up, down, enter bindings
-
-;; Loosely based on ideas: https://github.com/dangrossman/bootstrap-daterangepicker
-
-;; --- cljs-time facades ------------------------------------------------------
-
-(def ^:const month-format (formatter "MMMM yyyy"))
-
-(def ^:const week-format (formatter "ww"))
-
-(defn- month-label [date] (unparse month-format date))
-
-(defn- dec-month [date] (minus date (months 1)))
-
-(defn- inc-month [date] (plus date (months 1)))
-
-(defn- inc-date [date n] (plus date (days n)))
-
-(defn previous
-  "If date fails pred, subtract period until true, otherwise answer date"
-  ;; date   - a date object that satisfies cljs-time.core/DateTimeProtocol.
-  ;;          If omitted, use now->utc, which returns a goog.date.UtcDateTime version of now with time removed.
-  ;; pred   - can be one of cljs-time.predicate e.g. sunday? but any valid pred is supported.
-  ;; period - a period which will be subtracted see cljs-time.core periods
-  ;; Note:  If period and pred do not represent same granularity, some steps may be skipped
-                                        ;         e.g Pass a Wed date, specify sunday? as pred and a period (days 2) will skip one Sunday.
-  ([pred]
-   (previous pred (now->utc)))
-  ([pred date]
-   (previous pred date (days 1)))
-  ([pred date period]
-   (if (pred date)
-     date
-     (recur pred (minus date period) period))))
-
-(defn- =date [date1 date2]
-  (and
-   (= (year date1)  (year date2))
-   (= (month date1) (month date2))
-   (= (day date1)   (day date2))))
-
-(defn- <=date [date1 date2]
-  (or (=date date1 date2) (before? date1 date2)))
-
-(defn- >=date [date1 date2]
-  (or (=date date1 date2) (after? date1 date2)))
-
-(def ^:private days-vector
-  [{:key :Mo :short-name "M" :name "MON"}
-   {:key :Tu :short-name "T" :name "TUE"}
-   {:key :We :short-name "W" :name "WED"}
-   {:key :Th :short-name "T" :name "THU"}
-   {:key :Fr :short-name "F" :name "FRI"}
-   {:key :Sa :short-name "S" :name "SAT"}
-   {:key :Su :short-name "S" :name "SUN"}])
-
-(defn- rotate
-  [n coll]
-  (let [c (count coll)]
-    (take c (drop (mod n c) (cycle coll)))))
-
-(defn- is-day-pred [d]
-  #(= (day-of-week %) (inc d)))
-
-;; ----------------------------------------------------------------------------
-
-(def *internal-model (rum/cursor state/state :date-picker/date))
-
-(defn- main-div-with
-  [table-div class style attr]
-  [:div.rc-datepicker-wrapper
-   [:div {:style {:border-radius 4}}
-    [:div (merge
-           {:class (str "rc-datepicker datepicker noselect " class)
-            :style (merge {:font-size "13px"
-                           :position  "static"}
-                          style)}
-           attr)
-     table-div]]])
-
-(rum/defc table-thead
-  "Answer 2 x rows showing month with nav buttons and days NOTE: not internationalized"
-  [display-month {show-weeks? :show-weeks? minimum :minimum maximum :maximum start-of-week :start-of-week}]
-  (let [prev-date     (dec-month display-month)
-        minimum       (deref-or-value minimum)
-        maximum       (deref-or-value maximum)
-        prev-enabled? (if minimum (after? prev-date (dec-month minimum)) true)
-        next-date     (inc-month display-month)
-        next-enabled? (if maximum (before? next-date maximum) true)
-        template-row  (if show-weeks? [:tr [:th]] [:tr])]
-    [:thead
-     (conj template-row
-           [:th {:class (str "prev " (if prev-enabled? "available selectable" "disabled"))
-                 :style {:padding "0px"}
-                 :on-click #(when prev-enabled? (reset! *internal-model prev-date))}
-            [:span.font-bold "<"]]
-           [:th {:class "month" :col-span "5"} (month-label display-month)]
-           [:th {:class (str "next " (if next-enabled? "available selectable" "disabled"))
-                 :style {:padding "0px"}
-                 :on-click #(when next-enabled? (reset! *internal-model next-date))}
-            [:span.font-bold ">"]])
-     (conj template-row
-           (for [day (rotate start-of-week days-vector)]
-             ^{:key (:key day)} [:th {:class "day-enabled"} (str (:name day))]))]))
-
-(defn- table-td
-  [date focus-month selected today {minimum :minimum maximum :maximum :as attributes} disabled? on-change]
-  ;;following can be simplified and terse
-  (let [minimum       (deref-or-value minimum)
-        maximum       (deref-or-value maximum)
-        enabled-min   (if minimum (>=date date minimum) true)
-        enabled-max   (if maximum (<=date date maximum) true)
-        enabled-day   (and enabled-min enabled-max)
-        disabled-day? (if enabled-day
-                        (not ((:selectable-fn attributes) date))
-                        true)
-        classes       (cond disabled?                    "off"
-                            disabled-day?                "off"
-                            (= focus-month (month date)) "available"
-                            :else                        "available off")
-        classes       (cond (and selected (=date selected date)) (str classes " active start-date end-date")
-                            (and today (=date date today))       (str classes " today")
-                            :else                                classes)
-        on-click      (fn [e]
-                        (when-not (or disabled? disabled-day?)
-                          (reset! *internal-model date)
-                          (on-change e date)))]
-    [:td {:class    classes
-          :on-click on-click} (day date)]))
-
-(defn- week-td [date]
-  [:td {:class "week"} (unparse week-format date)])
-
-(defn- table-tr
-  "Return 7 columns of date cells from date inclusive"
-  [date focus-month selected attributes disabled? on-change]
-                                        ;  {:pre [(sunday? date)]}
-  (let [table-row (if (:show-weeks? attributes) [:tr (week-td date)] [:tr])
-        row-dates (map #(inc-date date %) (range 7))
-        today     (when (:show-today? attributes) (now->utc))]
-    (into table-row (map #(table-td % focus-month selected today attributes disabled? on-change) row-dates))))
-
-(rum/defc table-tbody
-  "Return matrix of 6 rows x 7 cols table cells representing 41 days from start-date inclusive"
-  [display-month selected attributes disabled? on-change]
-  (let [start-of-week   (:start-of-week attributes)
-        current-start   (previous (is-day-pred start-of-week) display-month)
-        focus-month     (month display-month)
-        row-start-dates (map #(inc-date current-start (* 7 %)) (range 6))]
-    (into [:tbody] (map #(table-tr % focus-month selected attributes disabled? on-change) row-start-dates))))
-
-(defn- configure
-  "Augment passed attributes with extra info/defaults"
-  [attributes]
-  (let [selectable-fn (if (-> attributes :selectable-fn fn?)
-                        (:selectable-fn attributes)
-                        (constantly true))]
-    (merge attributes {:selectable-fn selectable-fn})))
-
-
-(rum/defc date-picker < rum/reactive
-  {:init (fn [state]
-           (reset! *internal-model (first (:rum/args state)))
-           state)}
-  (shortcut/mixin :shortcut.handler/date-picker false)
-  [_model {:keys [on-change disabled? start-of-week class style attr]
-           :or   {start-of-week (state/get-start-of-week)} ;; Default to Sunday
-           :as   args}]
-  (let [internal-model (util/react *internal-model)
-        display-month (first-day-of-the-month (or internal-model (now->utc)))
-        props-with-defaults (merge args {:start-of-week start-of-week})
-        configuration       (configure props-with-defaults)]
-    (main-div-with
-     [:table.table-auto {:class "table-condensed"}
-      (table-thead display-month configuration)
-      (table-tbody display-month internal-model configuration disabled? on-change)]
-     class
-     style
-     attr)))

+ 0 - 30
src/main/frontend/util.cljc

@@ -591,12 +591,6 @@
         #{"INPUT" "TEXTAREA"}
         (gobj/get node "tagName")))))
 
-#?(:cljs
-   (defn select?
-     [node]
-     (when node
-       (= "SELECT" (gobj/get node "tagName")))))
-
 #?(:cljs
    (defn details-or-summary?
      [node]
@@ -762,30 +756,6 @@
            end   (get-selection-end input)]
        (safe-set-range-text! input text start end "end"))))
 
-;; copied from re_com
-#?(:cljs
-   (defn deref-or-value
-     "Takes a value or an atom
-      If it's a value, returns it
-      If it's a Reagent object that supports IDeref, returns the value inside it by derefing
-      "
-     [val-or-atom]
-     (if (satisfies? IDeref val-or-atom)
-       @val-or-atom
-       val-or-atom)))
-
-;; copied from re_com
-#?(:cljs
-   (defn now->utc
-     "Return a goog.date.UtcDateTime based on local date/time."
-     []
-     (let [local-date-time (js/goog.date.DateTime.)]
-       (js/goog.date.UtcDateTime.
-        (.getYear local-date-time)
-        (.getMonth local-date-time)
-        (.getDate local-date-time)
-        0 0 0 0))))
-
 (defn safe-subvec [xs start end]
   (if (or (neg? start)
           (> start end)

+ 1 - 6
src/resources/dicts/en.edn

@@ -648,12 +648,7 @@
  ;; Commands are nested for now to stay in sync with the shortcuts system.
  ;; Other languages should not nest keys under :commands
  :commands
- {:date-picker/complete         "Date picker: Choose selected day"
-  :date-picker/prev-day         "Date picker: Select previous day"
-  :date-picker/next-day         "Date picker: Select next day"
-  :date-picker/prev-week        "Date picker: Select previous week"
-  :date-picker/next-week        "Date picker: Select next week"
-  :pdf/previous-page            "Pdf: Previous page of current pdf doc"
+ {:pdf/previous-page            "Pdf: Previous page of current pdf doc"
   :pdf/next-page                "Pdf: Next page of current pdf doc"
   :pdf/close                    "Pdf: Close current pdf doc"
   :pdf/find                     "Pdf: Search text of current pdf doc"

+ 4 - 4
src/resources/tutorials/tutorial-sk.md

@@ -1,11 +1,11 @@
 ## Ahoj, vitaj v Logseq!
-- Logseq je [open-source](https://github.com/logseq/logseq) platforma určená na zdielanie _znalostí_ a spoluprácu s dôrazom na _ochranu súkromia_.
-- Toto je trojminutový návod ako používať Logseq. Poďme na to!
+- Logseq je [open-source](https://github.com/logseq/logseq) platforma určená na zdieľanie _znalostí_ a spoluprácu s dôrazom na _ochranu súkromia_.
+- Toto je trojminútový návod ako používať Logseq. Poďme na to!
 - Tu je niekoľko tipov, ktoré môžu byť užitočné.
   #+BEGIN_TIP
   Kliknutím upravíte ľubovoľný blok.
-  Stlačním klávesi `Enter` vytvoríte nový blok.
-  Stlačním klávesovej kombinácie `Shift+Enter` vytvoríte nový riadok.
+  Stlačením klávesu `Enter` vytvoríte nový blok.
+  Stlačením klávesovej kombinácie `Shift+Enter` vytvoríte nový riadok.
   Stlačením `/` zobrazíte všetky príkazy.
   #+END_TIP
 - 1. Vytvorme stránku [[Ako vytvoriť poznámky?]]. Môžete na ňu kliknúť a prejsť na danú stránku, alebo ju môžete otvoriť pomocou klávesovej skratky `Shift+Click` na pravom bočnom paneli! Teraz by ste mali vidieť _Prepojené referencie_ aj _Neprepojené referencie_.

+ 2 - 59
src/test/frontend/util_test.cljs

@@ -1,8 +1,7 @@
 (ns frontend.util-test
   (:require [cljs.test :refer [deftest is testing]]
             [frontend.util :as util]
-            [frontend.config :as config]
-            [frontend.modules.shortcut.data-helper :as shortcut-data-helper]))
+            [frontend.config :as config]))
 
 (deftest test-find-first
   (testing "find-first"
@@ -76,63 +75,7 @@
       (is (= (m+ 3 5) 8))
       (is (= @actual-ops 4))
       (is (= (m+ 3 5) 8))
-      (is (= @actual-ops 4))))
-
-  (testing "memoize-last nested mapping test"
-    (let [actual-ops (atom 0)
-          flatten-f (util/memoize-last (fn [& args]
-                                         (swap! actual-ops inc) ;; side effect for counting
-                                         (apply #'shortcut-data-helper/flatten-bindings-by-id (conj (vec args) nil true))))
-          target (atom {:part1 {:date-picker/complete {:binding "enter"
-                                                       :fn      "ui-handler/shortcut-complete"}
-                                :date-picker/prev-day {:binding "left"
-                                                       :fn      "ui-handler/shortcut-prev-day"}}
-                        :part2 {:date-picker/next-day  {:binding "right"
-                                                        :fn      "ui-handler/shortcut-next-day"}
-                                :date-picker/prev-week {:binding ["up" "ctrl+p"]
-                                                        :fn      "ui-handler/shortcut-prev-week"}}})]
-      (is (= (flatten-f @target) {:date-picker/complete  "enter"
-                                  :date-picker/prev-day  "left"
-                                  :date-picker/next-day  "right"
-                                  :date-picker/prev-week ["up" "ctrl+p"]}))
-      (is (= @actual-ops 1))
-      (is (= (flatten-f @target) {:date-picker/complete  "enter"
-                                  :date-picker/prev-day  "left"
-                                  :date-picker/next-day  "right"
-                                  :date-picker/prev-week ["up" "ctrl+p"]}))
-      (is (= @actual-ops 1))
-      ;; edit value
-      (swap! target assoc-in [:part1 :date-picker/complete :binding] "tab")
-      (is (= (flatten-f @target) {:date-picker/complete  "tab"
-                                  :date-picker/prev-day  "left"
-                                  :date-picker/next-day  "right"
-                                  :date-picker/prev-week ["up" "ctrl+p"]}))
-      (is (= @actual-ops 2))
-      (is (= (flatten-f @target) {:date-picker/complete  "tab"
-                                  :date-picker/prev-day  "left"
-                                  :date-picker/next-day  "right"
-                                  :date-picker/prev-week ["up" "ctrl+p"]}))
-      (is (= @actual-ops 2))
-      (is (= (flatten-f @target) {:date-picker/complete  "tab"
-                                  :date-picker/prev-day  "left"
-                                  :date-picker/next-day  "right"
-                                  :date-picker/prev-week ["up" "ctrl+p"]}))
-      (is (= @actual-ops 2))
-      ;; edit key
-      (swap! target assoc :part3 {:date-picker/next-week {:binding "down"
-                                                          :fn      "ui-handler/shortcut-next-week"}})
-      (is (= (flatten-f @target) {:date-picker/complete  "tab"
-                                  :date-picker/prev-day  "left"
-                                  :date-picker/next-day  "right"
-                                  :date-picker/prev-week ["up" "ctrl+p"]
-                                  :date-picker/next-week "down"}))
-      (is (= @actual-ops 3))
-      (is (= (flatten-f @target) {:date-picker/complete  "tab"
-                                  :date-picker/prev-day  "left"
-                                  :date-picker/next-day  "right"
-                                  :date-picker/prev-week ["up" "ctrl+p"]
-                                  :date-picker/next-week "down"}))
-      (is (= @actual-ops 3)))))
+      (is (= @actual-ops 4)))))
 
 (deftest test-media-format-from-input
   (testing "predicate file type from ext (html5 supported)"

+ 3 - 3
yarn.lock

@@ -7663,9 +7663,9 @@ [email protected]:
     sucrase "^3.32.0"
 
 tar@^6.1.11:
-  version "6.2.0"
-  resolved "https://registry.yarnpkg.com/tar/-/tar-6.2.0.tgz#b14ce49a79cb1cd23bc9b016302dea5474493f73"
-  integrity sha512-/Wo7DcT0u5HUV486xg675HtjNd3BXZ6xDbzsCUZPt5iw8bTQ63bP0Raut3mvro9u+CUyq7YQd8Cx55fsZXxqLQ==
+  version "6.2.1"
+  resolved "https://registry.yarnpkg.com/tar/-/tar-6.2.1.tgz#717549c541bc3c2af15751bea94b1dd068d4b03a"
+  integrity sha512-DZ4yORTwrbTj/7MZYq2w+/ZFdI6OZ/f9SFHR+71gIVUZhOQPHzVCLpvRnPgyaMpfWxxk/4ONva3GQSyNIKRv6A==
   dependencies:
     chownr "^2.0.0"
     fs-minipass "^2.0.0"