فهرست منبع

fix: save whiteboard when inactive for 3s

Peng Xiao 3 سال پیش
والد
کامیت
44e0f0be26

+ 1 - 12
src/main/frontend/handler/whiteboard.cljs

@@ -2,7 +2,6 @@
   (:require [datascript.core :as d]
             [frontend.db.model :as model]
             [frontend.db.utils :as db-utils]
-            [frontend.handler.editor :as editor-handler]
             [frontend.handler.route :as route-handler]
             [frontend.modules.outliner.core :as outliner]
             [frontend.modules.outliner.file :as outliner-file]
@@ -30,17 +29,6 @@
 ;;           (and (.-classList el) (.. el -classList (contains "whiteboard"))) true
 ;;           :else (recur (.-parentElement el)))))
 
-(defn get-tldr-app
-  []
-  js/window.tln)
-
-(defn tldraw-idle?
-  "return true when tldraw is active and idle. nil when tldraw is 
-   not active."
-  []
-  (when-let [^js app (get-tldr-app)]
-    (.. app -selectedTool (isIn "idle"))))
-
 (defn- block->shape [block]
   (:block/properties block))
 
@@ -116,6 +104,7 @@
   (let [{:keys [pages assets]} (js->clj tldr :keywordize-keys true)
         page (first pages)
         tx (tldr-page->blocks-tx page-name (assoc page :assets assets))]
+    (state/set-last-transact-time! (state/get-current-repo) (util/time-ms))
     (db-utils/transact! tx)))
 
 (defn get-default-tldr

+ 4 - 4
src/main/frontend/modules/outliner/file.cljs

@@ -40,12 +40,12 @@
   [repo page-db-id]
   (let [page-block (db/pull repo '[*] page-db-id)
         page-db-id (:db/id page-block)
+        whiteboard? (:block/whiteboard? page-block)
         blocks-count (model/get-page-blocks-count repo page-db-id)]
-    (if (and (> blocks-count 500)
-             (not (state/input-idle? repo :diff 3000))) ; long page
+    (if (and (or (> blocks-count 500) whiteboard?)
+             (not (state/input-idle? repo :diff 3000))) ; long page or whiteboard
       (async/put! (state/get-file-write-chan) [repo page-db-id])
-      (let [whiteboard? (:block/whiteboard? page-block)
-            pull-keys (if whiteboard? whiteboard-blocks-pull-keys-with-persisted-ids '[*])
+      (let [pull-keys (if whiteboard? whiteboard-blocks-pull-keys-with-persisted-ids '[*])
             blocks (model/get-page-blocks-no-cache repo (:block/name page-block) {:pull-keys pull-keys})
             blocks (if whiteboard? (map cleanup-whiteboard-block blocks) blocks)]
         (when-not (and (= 1 (count blocks))

+ 1 - 1
src/main/frontend/modules/shortcut/before.cljs

@@ -35,6 +35,6 @@
   (fn [e]
     (when (and (or (contains? #{:srs :page-histories} (state/get-modal-id))
                    (not (state/block-component-editing?)))
-               (not (and (whiteboard/tldraw-idle?)
+               (not (and (state/tldraw-idle?)
                          (not (state/editing?)))))
       (f e))))

+ 20 - 10
src/main/frontend/state.cljs

@@ -1,20 +1,20 @@
 (ns frontend.state
   (:require [cljs-bean.core :as bean]
             [cljs.core.async :as async]
-            [clojure.string :as string]
             [cljs.spec.alpha :as s]
+            [clojure.string :as string]
             [dommy.core :as dom]
-            [medley.core :as medley]
             [electron.ipc :as ipc]
+            [frontend.mobile.util :as mobile-util]
             [frontend.storage :as storage]
             [frontend.util :as util]
             [frontend.util.cursor :as cursor]
             [goog.dom :as gdom]
             [goog.object :as gobj]
-            [promesa.core :as p]
-            [rum.core :as rum]
             [logseq.graph-parser.config :as gp-config]
-            [frontend.mobile.util :as mobile-util]))
+            [medley.core :as medley]
+            [promesa.core :as p]
+            [rum.core :as rum]))
 
 ;; Stores main application state
 (defonce ^:large-vars/data-var state
@@ -1396,6 +1396,16 @@ Similar to re-frame subscriptions"
         (set-state! [:plugin/installed-hooks hook-or-all] (disj coll pid))))
     true))
 
+(defn active-tldraw-app
+  []
+  ^js js/window.tln)
+
+(defn tldraw-idle?
+  "return true when tldraw is active and idle. nil when tldraw is 
+   not active."
+  []
+  (when-let [app (active-tldraw-app)]
+    (.. app -selectedTool (isIn "idle"))))
 
 (defn set-graph-syncing?
   [value]
@@ -1445,11 +1455,11 @@ Similar to re-frame subscriptions"
            :or {diff 1000}}]
   (when repo
     (or
-      (when-let [last-time (get-in @state [:editor/last-input-time repo])]
-        (let [now (util/time-ms)]
-          (>= (- now last-time) diff)))
-      ;; not in editing mode
-      (not (get-edit-input-id)))))
+     (when-let [last-time (get-in @state [:editor/last-input-time repo])]
+       (let [now (util/time-ms)]
+         (>= (- now last-time) diff)))
+     ;; not in editing mode
+     (not (or (get-edit-input-id) (active-tldraw-app))))))
 
 (defn set-nfs-refreshing!
   [value]

+ 2 - 0
tldraw/apps/tldraw-logseq/src/lib/shapes/LogseqPortalShape.tsx

@@ -30,6 +30,7 @@ export interface LogseqPortalShapeProps extends TLBoxShapeProps, CustomStyleProp
   blockType?: 'P' | 'B'
   collapsed?: boolean
   compact?: boolean
+  borderRadius?: number
   collapsedHeight?: number
   scaleLevel?: SizeLevel
 }
@@ -186,6 +187,7 @@ export class LogseqPortalShape extends TLBoxShape<LogseqPortalShapeProps> {
     stroke: 'var(--ls-primary-text-color)',
     fill: 'var(--ls-secondary-background-color)',
     noFill: false,
+    borderRadius: 8,
     strokeWidth: 2,
     strokeType: 'line',
     opacity: 1,

+ 4 - 3
tldraw/packages/react/src/components/ui/SelectionForeground/SelectionForeground.tsx

@@ -22,7 +22,8 @@ export const SelectionForeground = observer(function SelectionForeground<S exten
 
   const canResize = shapes.length === 1 ? shapes[0].canResize : [true, true]
 
-  const editing = !!app.editingShape
+  // @ts-expect-error ???
+  const borderRadius = app.editingShape?.props['borderRadius'] ?? 0
 
   return (
     <SVGContainer>
@@ -30,8 +31,8 @@ export const SelectionForeground = observer(function SelectionForeground<S exten
         className="tl-bounds-fg"
         width={Math.max(width, 1)}
         height={Math.max(height, 1)}
-        rx={editing ? 8 : 0}
-        ry={editing ? 8 : 0}
+        rx={borderRadius}
+        ry={borderRadius}
         pointerEvents="none"
       />
       <EdgeHandle

+ 15 - 5
tldraw/packages/react/src/hooks/usePreventNavigation.ts

@@ -32,19 +32,29 @@ export function usePreventNavigation(rCanvas: React.RefObject<HTMLDivElement>):
 
     if (!elm) return () => void null
 
-    elm.addEventListener('touchstart', preventGestureNavigation)
+    elm.addEventListener('touchstart', preventGestureNavigation, {
+      passive: true,
+    })
 
     // @ts-ignore
-    elm.addEventListener('gestureend', preventGestureNavigation)
+    elm.addEventListener('gestureend', preventGestureNavigation, {
+      passive: true,
+    })
 
     // @ts-ignore
-    elm.addEventListener('gesturechange', preventGestureNavigation)
+    elm.addEventListener('gesturechange', preventGestureNavigation, {
+      passive: true,
+    })
 
     // @ts-ignore
-    elm.addEventListener('gesturestart', preventGestureNavigation)
+    elm.addEventListener('gesturestart', preventGestureNavigation, {
+      passive: true,
+    })
 
     // @ts-ignore
-    elm.addEventListener('touchstart', preventNavigation)
+    elm.addEventListener('touchstart', preventNavigation, {
+      passive: true,
+    })
 
     return () => {
       if (elm) {