Browse Source

fix: code cleanup

Peng Xiao 3 years ago
parent
commit
4d3decd218

+ 1 - 4
libs/package.json

@@ -12,8 +12,7 @@
     "dev:core": "npm run build:core -- --mode development --watch",
     "dev:core": "npm run build:core -- --mode development --watch",
     "build": "tsc && rm dist/*.js && npm run build:user",
     "build": "tsc && rm dist/*.js && npm run build:user",
     "lint": "prettier --check \"src/**/*.{ts, js}\"",
     "lint": "prettier --check \"src/**/*.{ts, js}\"",
-    "fix": "prettier --write \"src/**/*.{ts, js}\"",
-    "build:docs": "typedoc --plugin typedoc-plugin-lsp-docs src/LSPlugin.user.ts"
+    "fix": "prettier --write \"src/**/*.{ts, js}\""
   },
   },
   "dependencies": {
   "dependencies": {
     "csstype": "3.1.0",
     "csstype": "3.1.0",
@@ -33,8 +32,6 @@
     "prettier-config-standard": "^5.0.0",
     "prettier-config-standard": "^5.0.0",
     "ts-loader": "9.3.0",
     "ts-loader": "9.3.0",
     "typescript": "4.7.3",
     "typescript": "4.7.3",
-    "typedoc": "^0.22.15",
-    "typedoc-plugin-lsp-docs": "*",
     "webpack": "5.73.0",
     "webpack": "5.73.0",
     "webpack-bundle-analyzer": "4.5.0",
     "webpack-bundle-analyzer": "4.5.0",
     "webpack-cli": "4.9.2"
     "webpack-cli": "4.9.2"

+ 7 - 5
src/main/frontend/components/whiteboard.cljs

@@ -1,4 +1,5 @@
 (ns frontend.components.whiteboard
 (ns frontend.components.whiteboard
+  "Whiteboard related components"
   (:require [cljs.math :as math]
   (:require [cljs.math :as math]
             [frontend.components.page :as page]
             [frontend.components.page :as page]
             [frontend.components.reference :as reference]
             [frontend.components.reference :as reference]
@@ -7,6 +8,7 @@
             [frontend.handler.route :as route-handler]
             [frontend.handler.route :as route-handler]
             [frontend.handler.user :as user-handler]
             [frontend.handler.user :as user-handler]
             [frontend.handler.whiteboard :as whiteboard-handler]
             [frontend.handler.whiteboard :as whiteboard-handler]
+            [frontend.rum :refer [use-bounding-client-rect use-click-outside]]
             [frontend.state :as state]
             [frontend.state :as state]
             [frontend.ui :as ui]
             [frontend.ui :as ui]
             [frontend.util :as util]
             [frontend.util :as util]
@@ -43,8 +45,8 @@
 
 
 (rum/defc dropdown
 (rum/defc dropdown
   [label children show? outside-click-hander]
   [label children show? outside-click-hander]
-  (let [[anchor-ref anchor-rect] (util/use-component-size show?)
-        [content-ref content-rect] (util/use-component-size show?)
+  (let [[anchor-ref anchor-rect] (use-bounding-client-rect show?)
+        [content-ref content-rect] (use-bounding-client-rect show?)
         offset-x (when (and anchor-rect content-rect)
         offset-x (when (and anchor-rect content-rect)
                    (let [offset-x (+ (* 0.5 (- (.-width anchor-rect) (.-width content-rect)))
                    (let [offset-x (+ (* 0.5 (- (.-width anchor-rect) (.-width content-rect)))
                                      (.-x anchor-rect))
                                      (.-x anchor-rect))
@@ -54,7 +56,7 @@
                      offset-x))
                      offset-x))
         offset-y (when (and anchor-rect content-rect)
         offset-y (when (and anchor-rect content-rect)
                    (+ (.-y anchor-rect) (.-height anchor-rect) 8))
                    (+ (.-y anchor-rect) (.-height anchor-rect) 8))
-        click-outside-ref (util/use-click-outside outside-click-hander)
+        click-outside-ref (use-click-outside outside-click-hander)
         [d-open set-d-open] (rum/use-state false)
         [d-open set-d-open] (rum/use-state false)
         _ (rum/use-effect! (fn [] (js/setTimeout #(set-d-open show?) 100))
         _ (rum/use-effect! (fn [] (js/setTimeout #(set-d-open show?) 100))
                            [show?])]
                            [show?])]
@@ -166,12 +168,12 @@
 
 
 (rum/defc whiteboard-dashboard
 (rum/defc whiteboard-dashboard
   []
   []
-  (if (user-handler/alpha-user?)
+  (if (state/enable-whiteboards?)
     (let [whiteboards (->> (model/get-all-whiteboards (state/get-current-repo))
     (let [whiteboards (->> (model/get-all-whiteboards (state/get-current-repo))
                            (sort-by :block/updated-at)
                            (sort-by :block/updated-at)
                            reverse)
                            reverse)
           whiteboard-names (map :block/name whiteboards)
           whiteboard-names (map :block/name whiteboards)
-          [ref rect] (util/use-component-size)
+          [ref rect] (use-bounding-client-rect)
           [container-width] (when rect [(.-width rect) (.-height rect)])
           [container-width] (when rect [(.-width rect) (.-height rect)])
           cols (cond (< container-width 600) 1
           cols (cond (< container-width 600) 1
                      (< container-width 900) 2
                      (< container-width 900) 2

+ 1 - 0
src/main/frontend/extensions/tldraw.cljs

@@ -1,4 +1,5 @@
 (ns frontend.extensions.tldraw
 (ns frontend.extensions.tldraw
+  "Adapters related to tldraw"
   (:require ["/frontend/tldraw-logseq" :as TldrawLogseq]
   (:require ["/frontend/tldraw-logseq" :as TldrawLogseq]
             [frontend.components.block :as block]
             [frontend.components.block :as block]
             [frontend.components.page :as page]
             [frontend.components.page :as page]

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

@@ -1,4 +1,5 @@
 (ns frontend.handler.whiteboard
 (ns frontend.handler.whiteboard
+  "Whiteboard related handlers"
   (:require [datascript.core :as d]
   (:require [datascript.core :as d]
             [frontend.db.model :as model]
             [frontend.db.model :as model]
             [frontend.db.utils :as db-utils]
             [frontend.db.utils :as db-utils]
@@ -10,25 +11,6 @@
             [logseq.graph-parser.block :as gp-block]
             [logseq.graph-parser.block :as gp-block]
             [logseq.graph-parser.extract :as gp-extract]))
             [logseq.graph-parser.extract :as gp-extract]))
 
 
-;; (defn set-linked-page-or-block!
-;;   [page-or-block-id]
-;;   (when-let [app ^js (state/get-current-whiteboard)]
-;;     (let [shapes (:whiteboard/linked-shapes @state/state)]
-;;       (when (and (seq shapes) page-or-block-id)
-;;         (let [fs (first shapes)]
-;;           (.updateShapes app (clj->js
-;;                               [{:id (.-id fs)
-;;                                 :logseqLink page-or-block-id}])))))))
-
-
-;; (defn inside-whiteboard?
-;;   [el]
-;;   (println el)
-;;   (loop [el el]
-;;     (cond (nil? el) false
-;;           (and (.-classList el) (.. el -classList (contains "whiteboard"))) true
-;;           :else (recur (.-parentElement el)))))
-
 (defn- block->shape [block]
 (defn- block->shape [block]
   (:block/properties block))
   (:block/properties block))
 
 
@@ -155,25 +137,6 @@
        (create-new-whiteboard-page! page-name))
        (create-new-whiteboard-page! page-name))
      (create-new-whiteboard-page! nil))))
      (create-new-whiteboard-page! nil))))
 
 
-;; (defn ->logseq-portal-shape
-;;   [block-id point]
-;;   {:blockType "B"
-;;    :id (str (d/squuid))
-;;    :compact true
-;;    :pageId (str block-id)
-;;    :point point
-;;    :size [400, 0]
-;;    :type "logseq-portal"})
-
-;; (defn add-new-block-portal-shape!
-;;   "Given the block uuid and the point, add a new shape to the referenced block."
-;;   [block-uuid client-x client-y]
-;;   (let [api (get-tldr-api)
-;;         point (js->clj (.. (get-tldr-app) -viewport (getPagePoint #js[client-x client-y])))
-;;         shape (->logseq-portal-shape block-uuid point)]
-;;     (editor-handler/set-blocks-id! [block-uuid])
-;;     (.createShapes api (clj->js shape))))
-
 (defn- get-whiteboard-blocks
 (defn- get-whiteboard-blocks
   "Given a page, return all the logseq blocks (exlude all shapes)"
   "Given a page, return all the logseq blocks (exlude all shapes)"
   [page-name]
   [page-name]

+ 37 - 0
src/main/frontend/rum.cljs

@@ -97,3 +97,40 @@
          #(rum/set-ref! *mounted false))
          #(rum/set-ref! *mounted false))
        [])
        [])
     #(rum/deref *mounted)))
     #(rum/deref *mounted)))
+
+(defn use-bounding-client-rect
+  "Returns the bounding client rect for a given dom node
+   You can manually change the tick value, if you want to force refresh the value, you can manually change the tick value"
+  ([] (use-bounding-client-rect nil))
+  ([tick]
+   (let [[ref set-ref] (rum/use-state nil)
+         [rect set-rect] (rum/use-state nil)]
+     (rum/use-effect!
+      (if ref
+        (fn []
+          (let [update-rect #(set-rect (. ref getBoundingClientRect))
+                updator (fn [entries]
+                          (when (.-contentRect (first (js->clj entries))) (update-rect)))
+                observer (js/ResizeObserver. updator)]
+            (update-rect)
+            (.observe observer ref)
+            #(.disconnect observer)))
+        #())
+      [ref tick])
+     [set-ref rect])))
+
+(defn use-click-outside
+  "Returns a function that can be used to register a callback
+   that will be called when the user clicks outside the given dom node"
+  [handler]
+  (let [[ref set-ref] (rum/use-state nil)]
+    (rum/use-effect!
+     (fn []
+       (let [listener (fn [e]
+                        (when (and ref
+                                   (not (.. ref (contains (.-target e)))))
+                          (handler e)))]
+         (js/document.addEventListener "click" listener)
+         #(.removeEventListener js/document "click" listener)))
+     [ref])
+    set-ref))

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

@@ -1402,37 +1402,3 @@
                Math/floor
                Math/floor
                int
                int
                (#(str % " " (:name unit) (when (> % 1) "s") " ago"))))))))
                (#(str % " " (:name unit) (when (> % 1) "s") " ago"))))))))
-
-#?(:cljs
-   (defn use-component-size
-     ([] (use-component-size nil))
-     ([tick] (let [[ref set-ref] (rum/use-state nil)
-                   [rect set-rect] (rum/use-state nil)]
-               (rum/use-effect!
-                (if ref
-                  (fn []
-                    (let [update-rect #(set-rect (. ref getBoundingClientRect))
-                          updator (fn [entries]
-                                    (when (.-contentRect (first (js->clj entries))) (update-rect)))
-                          observer (js/ResizeObserver. updator)]
-                      (update-rect)
-                      (.observe observer ref)
-                      #(.disconnect observer)))
-                  #())
-                [ref tick])
-               [set-ref rect]))))
-
-#?(:cljs
-   (defn use-click-outside
-     [handler]
-     (let [[ref set-ref] (rum/use-state nil)]
-       (rum/use-effect!
-        (fn []
-          (let [listener (fn [e]
-                           (when (and ref
-                                      (not (.. ref (contains (.-target e)))))
-                             (handler e)))]
-            (js/document.addEventListener "click" listener)
-            #(.removeEventListener js/document "click" listener)))
-        [ref])
-       set-ref)))

+ 0 - 10
tldraw/lerna.json

@@ -1,10 +0,0 @@
-{
-  "version": "1.2.4",
-  "registry": "https://registry.npmjs.org/",
-  "publishConfig": {
-    "access": "public",
-    "directory": "dist"
-  },
-  "npmClient": "yarn",
-  "useWorkspaces": true
-}

+ 0 - 4
tldraw/package.json

@@ -24,22 +24,18 @@
     "pretty-quick": "pretty-quick --pattern 'tldraw/**/*.{js,jsx,ts,tsx,css,html}'"
     "pretty-quick": "pretty-quick --pattern 'tldraw/**/*.{js,jsx,ts,tsx,css,html}'"
   },
   },
   "devDependencies": {
   "devDependencies": {
-    "@swc-node/jest": "^1.5.2",
     "@types/node": "^17.0.42",
     "@types/node": "^17.0.42",
     "@types/react": "^17.0.0",
     "@types/react": "^17.0.0",
     "@types/react-dom": "^17.0.0",
     "@types/react-dom": "^17.0.0",
     "@typescript-eslint/eslint-plugin": "^5.36.1",
     "@typescript-eslint/eslint-plugin": "^5.36.1",
     "@typescript-eslint/parser": "^5.36.1",
     "@typescript-eslint/parser": "^5.36.1",
     "eslint": "^8.23.1",
     "eslint": "^8.23.1",
-    "init-package-json": "^3.0.2",
-    "lerna": "^5.5.1",
     "lint-staged": "^13.0.1",
     "lint-staged": "^13.0.1",
     "prettier": "^2.6.2",
     "prettier": "^2.6.2",
     "prettier-plugin-jsdoc": "^0.3.38",
     "prettier-plugin-jsdoc": "^0.3.38",
     "pretty-quick": "^3.1.3",
     "pretty-quick": "^3.1.3",
     "resize-observer-polyfill": "^1.5.1",
     "resize-observer-polyfill": "^1.5.1",
     "tslib": "^2.4.0",
     "tslib": "^2.4.0",
-    "typedoc": "^0.22.17",
     "typescript": "^4.8.2"
     "typescript": "^4.8.2"
   },
   },
   "dependencies": {
   "dependencies": {

+ 1 - 5
tldraw/packages/core/tsconfig.json

@@ -6,9 +6,5 @@
     "experimentalDecorators": true,
     "experimentalDecorators": true,
     "useDefineForClassFields": true
     "useDefineForClassFields": true
   },
   },
-  "references": [{ "path": "../utils/vec" }, { "path": "../utils/intersect" }],
-  "typedocOptions": {
-    "entryPoints": ["src/index.ts"],
-    "out": "docs"
-  }
+  "references": [{ "path": "../utils/vec" }, { "path": "../utils/intersect" }]
 }
 }

+ 1 - 5
tldraw/packages/react/tsconfig.json

@@ -10,9 +10,5 @@
     { "path": "../core" },
     { "path": "../core" },
     { "path": "../utils/vec" },
     { "path": "../utils/vec" },
     { "path": "../utils/intersect" }
     { "path": "../utils/intersect" }
-  ],
-  "typedocOptions": {
-    "entryPoints": ["src/index.ts"],
-    "out": "docs"
-  }
+  ]
 }
 }

+ 0 - 4
tldraw/packages/utils/curve/tsconfig.json

@@ -4,9 +4,5 @@
   "exclude": ["node_modules", "dist", "docs"],
   "exclude": ["node_modules", "dist", "docs"],
   "compilerOptions": {
   "compilerOptions": {
     "outDir": "./dist/types"
     "outDir": "./dist/types"
-  },
-  "typedocOptions": {
-    "entryPoints": ["src/index.ts"],
-    "out": "docs"
   }
   }
 }
 }

+ 1 - 5
tldraw/packages/utils/intersect/tsconfig.json

@@ -4,9 +4,5 @@
   "compilerOptions": {
   "compilerOptions": {
     "outDir": "./dist/types"
     "outDir": "./dist/types"
   },
   },
-  "references": [{ "path": "../vec" }],
-  "typedocOptions": {
-    "entryPoints": ["src/index.ts"],
-    "out": "docs"
-  }
+  "references": [{ "path": "../vec" }]
 }
 }

+ 0 - 4
tldraw/packages/utils/vec/tsconfig.json

@@ -4,9 +4,5 @@
   "exclude": ["node_modules", "dist", "docs"],
   "exclude": ["node_modules", "dist", "docs"],
   "compilerOptions": {
   "compilerOptions": {
     "outDir": "./dist/types"
     "outDir": "./dist/types"
-  },
-  "typedocOptions": {
-    "entryPoints": ["src/index.ts"],
-    "out": "docs"
   }
   }
 }
 }

File diff suppressed because it is too large
+ 1 - 1045
tldraw/yarn.lock


Some files were not shown because too many files changed in this diff