Skip to content

Commit

Permalink
Merge branch 'master' into feat/custom-children-list-style
Browse files Browse the repository at this point in the history
  • Loading branch information
xyhp915 committed Apr 25, 2023
2 parents eb36479 + f0faf65 commit 2f6377e
Show file tree
Hide file tree
Showing 57 changed files with 890 additions and 762 deletions.
1 change: 1 addition & 0 deletions deps/db/src/logseq/db/rules.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
[(str ?val) ?str-val]
(or [(= ?v ?val)]
[(contains? ?v ?val)]
;; For integer pages that aren't strings
[(contains? ?v ?str-val)])]

:page-ref
Expand Down
12 changes: 12 additions & 0 deletions e2e-tests/whiteboards.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ test('undo the delete action', async ({ page }) => {
await expect(page.locator('.logseq-tldraw .tl-line-container')).toHaveCount(1)
})

test('locked elements should not be removed', async ({ page }) => {
await page.keyboard.press('Escape')
await page.waitForTimeout(1000)
await page.click('.logseq-tldraw .tl-box-container:first-of-type')
await page.keyboard.press(`${modKey}+l`)
await page.keyboard.press('Delete')
await page.keyboard.press(`${modKey}+Shift+l`)

await expect(page.locator('.logseq-tldraw .tl-box-container')).toHaveCount(2)

})

test('move arrow to back', async ({ page }) => {
await page.keyboard.press('Escape')
await page.waitForTimeout(1000)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"@capawesome/capacitor-background-task": "^2.0.0",
"@excalidraw/excalidraw": "0.12.0",
"@hugotomazi/capacitor-navigation-bar": "^2.0.0",
"@logseq/capacitor-file-sync": "0.0.22",
"@logseq/capacitor-file-sync": "0.0.24",
"@logseq/diff-merge": "^0.0.2",
"@logseq/react-tweet-embed": "1.3.1-1",
"@sentry/react": "^6.18.2",
Expand Down
8 changes: 4 additions & 4 deletions src/main/frontend/components/block.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2932,7 +2932,8 @@
custom-query? (boolean (:custom-query? config))]
(if (and (or ref? custom-query?) (not (:ref-query-child? config)))
(ui/lazy-visible
(fn [] (block-container-inner state repo config block)))
(fn [] (block-container-inner state repo config block))
{:debug-id (str "block-container-ref " (:db/id block))})
(block-container-inner state repo config block))))

(defn divide-lists
Expand Down Expand Up @@ -3360,7 +3361,7 @@
"More"

@*loading?
(ui/lazy-loading-placeholder)
(ui/lazy-loading-placeholder 88)

:else
"")})]))))
Expand Down Expand Up @@ -3452,8 +3453,7 @@
(rum/with-key
(breadcrumb-with-container blocks (assoc config :top-level? top-level?))
(:db/id parent)))))
{:debug-id page
:trigger-once? false})])))))]
{:debug-id page})])))))]

(and (:ref? config) (:group-by-page? config))
[:div.flex.flex-col
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/components/encryption.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
[:span.px-3.flex (ui/icon "key")]
[:p.dark:text-gray-100
[:span "Please make sure you "]
"remember the password you have set, "
"remember the password you have set, as we are unable to reset or retrieve it in case you forget it, "
[:span "and we recommend you "]
"keep a secure backup "
[:span "of the password."]]]
Expand Down
3 changes: 1 addition & 2 deletions src/main/frontend/components/journal.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@
(blocks-cp repo page)
(ui/lazy-visible
(fn [] (blocks-cp repo page))
{:trigger-once? false
:debug-id (str "journal-blocks " page)}))
{:debug-id (str "journal-blocks " page)}))

{})

Expand Down
3 changes: 1 addition & 2 deletions src/main/frontend/components/query.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -253,5 +253,4 @@
(ui/lazy-visible
(fn []
(custom-query* config q (::query-triggered? state)))
{:debug-id q
:trigger-once? false})))
{:debug-id q})))
28 changes: 18 additions & 10 deletions src/main/frontend/components/query_table.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
[frontend.format.block :as block]
[medley.core :as medley]
[rum.core :as rum]
[logseq.graph-parser.text :as text]
[frontend.modules.outliner.tree :as tree]))

;; Util fns
Expand All @@ -27,7 +28,7 @@
(map #(medley/dissoc-in % ks) result)
result)))

(defn- sort-by-fn [sort-by-column item]
(defn- sort-by-fn [sort-by-column item {:keys [page?]}]
(case sort-by-column
:created-at
(:block/created-at item)
Expand All @@ -36,7 +37,7 @@
:block
(:block/content item)
:page
(:block/name item)
(if page? (:block/name item) (get-in item [:block/page :block/name]))
(get-in item [:block/properties sort-by-column])))

(defn- locale-compare
Expand All @@ -46,11 +47,12 @@
(< x y)
(.localeCompare (str x) (str y) (state/sub :preferred-language) #js {:numeric true})))

(defn- sort-result [result {:keys [sort-by-column sort-desc? sort-nlp-date?]}]
(defn- sort-result [result {:keys [sort-by-column sort-desc? sort-nlp-date? page?]}]
(if (some? sort-by-column)
(let [comp-fn (if sort-desc? #(locale-compare %2 %1) locale-compare)]
(sort-by (fn [item]
(block/normalize-block (sort-by-fn sort-by-column item) sort-nlp-date?))
(block/normalize-block (sort-by-fn sort-by-column item {:page? page?})
sort-nlp-date?))
comp-fn
result))
result))
Expand Down Expand Up @@ -115,7 +117,7 @@
(defn- build-column-value
"Builds a column's tuple value for a query table given a row, column and
options"
[row column {:keys [page? ->elem map-inline config]}]
[row column {:keys [page? ->elem map-inline config comma-separated-property?]}]
(case column
:page
[:string (if page?
Expand Down Expand Up @@ -143,9 +145,13 @@
[:string (when-let [updated-at (:block/updated-at row)]
(date/int->local-time-2 updated-at))]

[:string (or (get-in row [:block/properties-text-values column])
;; Fallback to property relationships for page blocks
(get-in row [:block/properties column]))]))
[:string (if comma-separated-property?
;; Return original properties since comma properties need to
;; return collections for display purposes
(get-in row [:block/properties column])
(or (get-in row [:block/properties-text-values column])
;; Fallback to original properties for page blocks
(get-in row [:block/properties column])))]))

(rum/defcs result-table < rum/reactive
(rum/local false ::select?)
Expand All @@ -165,7 +171,8 @@
;; Sort state needs to be in sync between final result and sortable title
;; as user needs to know if there result is sorted
sort-state (get-sort-state current-block)
result' (sort-result result sort-state)]
result' (sort-result result (assoc sort-state :page? page?))
property-separated-by-commas? (partial text/separated-by-commas? (state/get-config))]
[:div.overflow-x-auto {:on-mouse-down (fn [e] (.stopPropagation e))
:style {:width "100%"}
:class (when-not page? "query-table")}
Expand All @@ -188,7 +195,8 @@
{:page? page?
:->elem ->elem
:map-inline map-inline
:config config})]
:config config
:comma-separated-property? (property-separated-by-commas? column)})]
[:td.whitespace-nowrap {:on-mouse-down (fn []
(reset! *mouse-down? true)
(reset! select? false))
Expand Down
8 changes: 7 additions & 1 deletion src/main/frontend/components/scheduled_deadlines.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
(not (true? (state/scheduled-deadlines-disabled?)))
(= (string/lower-case page-name) (string/lower-case (date/journal-name)))))

(rum/defc scheduled-and-deadlines < rum/reactive db-mixins/query
(rum/defc scheduled-and-deadlines-inner < rum/reactive db-mixins/query
[page-name]
(let [scheduled-or-deadlines (when (scheduled-or-deadlines? page-name)
(db/get-date-scheduled-or-deadlines (string/capitalize page-name)))]
Expand All @@ -33,3 +33,9 @@
{})]
(content/content page-name {:hiccup ref-hiccup}))]
{:title-trigger? true})])))

(rum/defc scheduled-and-deadlines
[page-name]
(ui/lazy-visible
(fn [] (scheduled-and-deadlines-inner page-name))
{:debug-id "scheduled-and-deadlines"}))
7 changes: 7 additions & 0 deletions src/main/frontend/db/react.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@

(defonce query-state (atom {}))

;; Current dynamic component
(def ^:dynamic *query-component*)

;; Which reactive queries are triggered by the current component
(def ^:dynamic *reactive-queries*)

;; component -> query-key
(defonce query-components (atom {}))

Expand Down Expand Up @@ -156,11 +160,14 @@
transform-fn identity}} query & inputs]
{:pre [(s/valid? ::react-query-keys k)]}
(let [kv? (and (vector? k) (= :kv (first k)))
origin-key k
k (vec (cons repo k))]
(when-let [db (conn/get-db repo)]
(let [result-atom (get-query-cached-result k)]
(when-let [component *query-component*]
(add-query-component! k component))
(when-let [queries *reactive-queries*]
(swap! queries conj origin-key))
(if (and use-cache? result-atom)
result-atom
(let [{:keys [result time]} (util/with-time
Expand Down
8 changes: 6 additions & 2 deletions src/main/frontend/db_mixins.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
(:require [frontend.db.react :as react]))

(def query
{:wrap-render
{:init
(fn [state]
(assoc state :reactive-queries (atom #{})))
:wrap-render
(fn [render-fn]
(fn [state]
(binding [react/*query-component* (:rum/react-component state)]
(binding [react/*query-component* (:rum/react-component state)
react/*reactive-queries* (:reactive-queries state)]
(render-fn state))))
:will-unmount
(fn [state]
Expand Down
13 changes: 7 additions & 6 deletions src/main/frontend/fs/capacitor_fs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"")
(string/replace (re-pattern (str "(?i)" (gstring/regExpEscape (str "." ext)) "$"))
""))]
(util/safe-path-join repo-dir (str bak-dir "/" relative-path))))
(path/path-join repo-dir bak-dir relative-path)))

(defn- truncate-old-versioned-files!
"reserve the latest 6 version files"
Expand All @@ -174,7 +174,8 @@
dir (case dir
:backup-dir (get-backup-dir repo-dir path backup-dir ext)
:version-file-dir (get-backup-dir repo-dir path version-file-dir ext))
new-path (util/safe-path-join dir (str (string/replace (.toISOString (js/Date.)) ":" "_") "." (mobile-util/platform) "." ext))]
new-path (path/path-join dir (str (string/replace (.toISOString (js/Date.)) ":" "_") "." (mobile-util/platform) "." ext))]

(<write-file-with-utf8 new-path content)
(truncate-old-versioned-files! dir)))

Expand All @@ -187,14 +188,14 @@
(string/includes? repo-dir divider-schema))
repo-dir (if-not dir-schema?
(str file-schema divider-schema repo-dir) repo-dir)
backup-root (util/safe-path-join repo-dir backup-dir)
backup-root (path/path-join repo-dir backup-dir)
backup-dir-parent (util/node-path.dirname file-path)
backup-dir-parent (string/replace backup-dir-parent repo-dir "")
backup-dir-name (util/node-path.name file-path)
file-extname (.extname util/node-path file-path)
file-root (util/safe-path-join backup-root backup-dir-parent backup-dir-name)
file-path (util/safe-path-join file-root
(str (string/replace (.toISOString (js/Date.)) ":" "_") "." (mobile-util/platform) file-extname))]
file-root (path/path-join backup-root backup-dir-parent backup-dir-name)
file-path (path/path-join file-root
(str (string/replace (.toISOString (js/Date.)) ":" "_") "." (mobile-util/platform) file-extname))]
(<write-file-with-utf8 file-path content)
(truncate-old-versioned-files! file-root)))

Expand Down
1 change: 1 addition & 0 deletions src/main/frontend/modules/shortcut/config.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@
[:editor/bold
:editor/insert-link
:editor/italics
:editor/strike-through
:editor/highlight]

:shortcut.category/navigating
Expand Down
56 changes: 28 additions & 28 deletions src/main/frontend/ui.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,8 +1065,8 @@
(progress-bar width)])

(rum/defc lazy-loading-placeholder
[]
[:div.shadow.rounded-md.p-4.w-full.mx-auto.mb-5.fade-in {:style {:height 88}}
[height]
[:div.shadow.rounded-md.p-4.w-full.mx-auto.mb-5.fade-in {:style {:height height}}
[:div.animate-pulse.flex.space-x-4
[:div.flex-1.space-y-3.py-1
[:div.h-2.bg-base-4.rounded]
Expand All @@ -1076,37 +1076,37 @@
[:div.h-2.bg-base-4.rounded.col-span-1]]
[:div.h-2.bg-base-4.rounded]]]]])

(rum/defcs lazy-visible-inner
[state visible? content-fn ref]
[:div.lazy-visibility
{:ref ref
:style {:min-height 24}}
(if visible?
(when (fn? content-fn)
[:div.fade-enter
{:ref #(when-let [^js cls (and % (.-classList %))]
(.add cls "fade-enter-active"))}
(content-fn)])
(lazy-loading-placeholder))])
(rum/defc lazy-visible-inner
[visible? content-fn ref]
(let [[set-ref rect] (r/use-bounding-client-rect)
placeholder-height (or (when rect (.-height rect)) 88)]
[:div.lazy-visibility {:ref ref}
[:div {:ref set-ref}
(if visible?
(when (fn? content-fn)
[:div.fade-enter
{:ref #(when-let [^js cls (and % (.-classList %))]
(.add cls "fade-enter-active"))}
(content-fn)])
(lazy-loading-placeholder placeholder-height))]]))

(rum/defc lazy-visible
([content-fn]
(lazy-visible content-fn nil))
([content-fn {:keys [trigger-once? _debug-id]
:or {trigger-once? true}}]
(if (or (util/mobile?) (mobile-util/native-platform?))
(content-fn)
(let [[visible? set-visible!] (rum/use-state false)
inViewState (useInView #js {:rootMargin "100px"
:triggerOnce trigger-once?
:onChange (fn [in-view? entry]
(let [self-top (.-top (.-boundingClientRect entry))]
(when (or (and (not visible?) in-view?)
;; hide only the components below the current top for better ux
(and visible? (not in-view?) (> self-top 0)))
(set-visible! in-view?))))})
ref (.-ref inViewState)]
(lazy-visible-inner visible? content-fn ref)))))
:or {trigger-once? false}}]
(let [[visible? set-visible!] (rum/use-state false)
root-margin 100
inViewState (useInView #js {:rootMargin (str root-margin "px")
:triggerOnce trigger-once?
:onChange (fn [in-view? entry]
(let [self-top (.-top (.-boundingClientRect entry))]
(when (or (and (not visible?) in-view?)
;; hide only the components below the current top for better ux
(and visible? (not in-view?) (> self-top root-margin)))
(set-visible! in-view?))))})
ref (.-ref inViewState)]
(lazy-visible-inner visible? content-fn ref))))

(rum/defc portal
([children]
Expand Down
7 changes: 0 additions & 7 deletions src/main/frontend/util.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -528,13 +528,6 @@
(if (string? s)
(string/lower-case s) s))

#?(:cljs
(defn safe-path-join [prefix & paths]
(let [path (apply node-path.join (cons prefix paths))]
(if (and (electron?) (gstring/caseInsensitiveStartsWith path "file://"))
(gp-util/safe-decode-uri-component (subs path 7))
path))))

(defn trim-safe
[s]
(when s
Expand Down
Loading

0 comments on commit 2f6377e

Please sign in to comment.