Skip to content

Commit

Permalink
Merge branch 'logseq:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Bad3r authored Sep 29, 2023
2 parents e74ff73 + 088ca5e commit 4a034a6
Show file tree
Hide file tree
Showing 15 changed files with 138 additions and 36 deletions.
4 changes: 4 additions & 0 deletions src/electron/electron/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@
{:role "about"
:label "About Logseq"
:click about-fn}]}))
;; Enable Cmd/Ctrl+= Zoom In
template (conj template
{:role "zoomin"
:accelerator "CommandOrControl+="})
menu (.buildFromTemplate Menu (clj->js template))]
(.setApplicationMenu Menu menu)))

Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/components/container.css
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ html[data-theme='dark'] {
}

&-btn {
@apply fixed bottom-4 right-8;
@apply fixed bottom-4 right-4 sm:right-8;

> .inner {
@apply font-bold
Expand Down
40 changes: 22 additions & 18 deletions src/main/frontend/components/editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -411,16 +411,6 @@
right-sidebar? (:ui/sidebar-open? @state/state)
editing-key (first (keys (:editor/editing? @state/state)))
*el (rum/use-ref nil)
_ (rum/use-effect! (fn []
(when-let [^js/HTMLElement cnt
(and right-sidebar? editing-key
(js/document.querySelector "#main-content-container"))]
(when (.contains cnt (js/document.querySelector (str "#" editing-key)))
(let [el (rum/deref *el)
ofx (- (.-scrollWidth cnt) (.-clientWidth cnt))]
(when (> ofx 0)
(set! (.-transform (.-style el)) (str "translateX(-" (+ ofx 20) "px)")))))))
[right-sidebar? editing-key])
y-overflow-vh? (or (< to-max-height Y-BOUNDARY-HEIGHT)
(> (- max-height' to-max-height) Y-BOUNDARY-HEIGHT))
to-max-height (if y-overflow-vh? max-height' to-max-height)
Expand All @@ -430,22 +420,36 @@
style (merge
{:top (+ top offset-top (if (int? y-diff) y-diff 0))
:max-height to-max-height
:max-width 700
:max-width 700
;; TODO: auto responsive fixed size
:width "fit-content"
:width "fit-content"
:z-index 11}
(when set-default-width?
{:width max-width})
(if (<= vw-max-width (+ left (if set-default-width? max-width 500)))
{:right 0}
{:left (if (or (nil? y-diff) (and y-diff (= y-diff 0))) left 0)}))]
{:left 0}))]

(rum/use-effect!
(fn []
(when-let [^js/HTMLElement cnt
(and right-sidebar? editing-key
(js/document.querySelector "#main-content-container"))]
(when (.contains cnt (js/document.querySelector (str "#" editing-key)))
(let [el (rum/deref *el)
ofx (- (.-scrollWidth cnt) (.-clientWidth cnt))]
(when (> ofx 0)
(set! (.-transform (.-style el))
(util/format "translate(-%spx, %s)" (+ ofx 20) (if y-overflow-vh? "calc(-100% - 2rem)" 0))))))))
[right-sidebar? editing-key y-overflow-vh?])

[:div.absolute.rounded-md.shadow-lg.absolute-modal
{:ref *el
{:ref *el
:data-modal-name modal-name
:class (if y-overflow-vh? "is-overflow-vh-y" "")
:on-mouse-down (fn [e]
(.stopPropagation e))
:style style}
:class (if y-overflow-vh? "is-overflow-vh-y" "")
:on-mouse-down (fn [e]
(.stopPropagation e))
:style style}
cp]))

(rum/defc transition-cp < rum/reactive
Expand Down
44 changes: 33 additions & 11 deletions src/main/frontend/components/page.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
(:require ["/frontend/utils" :as utils]
[clojure.string :as string]
[frontend.components.block :as component-block]
[frontend.components.query :as query]
[frontend.components.content :as content]
[frontend.components.editor :as editor]
[frontend.components.hierarchy :as hierarchy]
[frontend.components.plugins :as plugins]
[frontend.components.query :as query]
[frontend.components.reference :as reference]
[frontend.components.svg :as svg]
[frontend.components.scheduled-deadlines :as scheduled]
[frontend.components.svg :as svg]
[frontend.config :as config]
[frontend.context.i18n :refer [t]]
[frontend.date :as date]
Expand All @@ -21,6 +21,7 @@
[frontend.format.block :as block]
[frontend.handler.common :as common-handler]
[frontend.handler.config :as config-handler]
[frontend.handler.dnd :as dnd]
[frontend.handler.editor :as editor-handler]
[frontend.handler.graph :as graph-handler]
[frontend.handler.notification :as notification]
Expand All @@ -34,12 +35,13 @@
[frontend.util :as util]
[frontend.util.text :as text-util]
[goog.object :as gobj]
[logseq.graph-parser.mldoc :as gp-mldoc]
[logseq.graph-parser.util :as gp-util]
[logseq.graph-parser.util.page-ref :as page-ref]
[medley.core :as medley]
[promesa.core :as p]
[reitit.frontend.easy :as rfe]
[rum.core :as rum]
[logseq.graph-parser.util.page-ref :as page-ref]
[logseq.graph-parser.mldoc :as gp-mldoc]))
[rum.core :as rum]))

(defn- get-page-name
[state]
Expand Down Expand Up @@ -109,19 +111,39 @@

(rum/defc dummy-block
[page-name]
(let [handler-fn (fn []
(let [block (editor-handler/insert-first-page-block-if-not-exists! page-name {:redirect? false})]
(js/setTimeout #(editor-handler/edit-block! block :max (:block/uuid block)) 0)))]
[:div.ls-block.flex-1.flex-col.rounded-sm {:style {:width "100%"}}
(let [[hover set-hover!] (rum/use-state false)
click-handler-fn (fn []
(let [block (editor-handler/insert-first-page-block-if-not-exists! page-name {:redirect? false})]
(js/setTimeout #(editor-handler/edit-block! block :max (:block/uuid block)) 0)))
drop-handler-fn (fn [^js event]
(util/stop event)
(p/let [block-uuids (state/get-selection-block-ids)
lookup-refs (map (fn [id] [:block/uuid id]) block-uuids)
selected (db/pull-many (state/get-current-repo) '[*] lookup-refs)
blocks (if (seq selected) selected [@component-block/*dragging-block])
_ (editor-handler/insert-first-page-block-if-not-exists! page-name {:redirect? false})]
(js/setTimeout #(let [target-block (db/pull (:db/id (db/get-page page-name)))]
(dnd/move-blocks event blocks target-block :sibling))
0)))]
[:div.ls-block.flex-1.flex-col.rounded-sm
{:style {:width "100%"
;; The same as .dnd-separator
:border-top (if hover
"3px solid #ccc"
nil)}}
[:div.flex.flex-row
[:div.flex.flex-row.items-center.mr-2.ml-1 {:style {:height 24}}
[:span.bullet-container.cursor
[:span.bullet]]]
[:div.flex.flex-1 {:tabIndex 0
:on-key-press (fn [e]
(when (= "Enter" (util/ekey e))
(handler-fn)))
:on-click handler-fn}
(click-handler-fn)))
:on-click click-handler-fn
:on-drag-enter #(set-hover! true)
:on-drag-over #(util/stop %)
:on-drop drop-handler-fn
:on-drag-leave #(set-hover! false)}
[:span.opacity-70
"Click here to edit..."]]]]))

Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/components/whiteboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ input.tl-text-input {

.tl-action-bar {
left: 0.5rem;
bottom: 0.5rem;
bottom: 0;
}

.tl-primary-tools {
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/handler/dnd.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns frontend.handler.dnd
"Provides fns for drag n drop"
"Provides fns for drag and drop"
(:require [frontend.handler.editor :as editor-handler]
[frontend.handler.editor.property :as editor-property]
[frontend.modules.outliner.core :as outliner-core]
Expand Down
1 change: 1 addition & 0 deletions src/resources/dicts/en.edn
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@
:whiteboard/dashboard-card-edited "Edited "
:whiteboard/toggle-grid "Toggle grid"
:whiteboard/snap-to-grid "Snap to grid"
:whiteboard/toggle-pen-mode "Toggle pen mode"
:flashcards/modal-welcome-title "Time to create a card!"
:flashcards/modal-welcome-desc-1 "You can add \"#card\" to any block to turn it into a card or trigger \"/cloze\" to add some clozes."
:flashcards/modal-welcome-desc-2 "You can "
Expand Down
24 changes: 21 additions & 3 deletions tldraw/apps/tldraw-logseq/src/components/ActionBar/ActionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ export const ActionBar = observer(function ActionBar(): JSX.Element {
app.api.toggleSnapToGrid()
}, [app])

const togglePenMode = React.useCallback(() => {
app.api.togglePenMode()
}, [app])

return (
<div className="tl-action-bar" data-html2canvas-ignore="true">
{!app.readOnly && (
<div className="tl-toolbar tl-history-bar">
<div className="tl-toolbar tl-history-bar mr-2 mb-2">
<Button tooltip={t('whiteboard/undo')} onClick={undo}>
<TablerIcon name="arrow-back-up" />
</Button>
Expand All @@ -54,7 +58,7 @@ export const ActionBar = observer(function ActionBar(): JSX.Element {
</div>
)}

<div className={`tl-toolbar tl-zoom-bar ${app.readOnly ? '' : 'ml-4'}`}>
<div className={'tl-toolbar tl-zoom-bar mr-2 mb-2'}>
<Button tooltip={t('whiteboard/zoom-in')} onClick={zoomIn} id="tl-zoom-in">
<TablerIcon name="plus" />
</Button>
Expand All @@ -65,7 +69,7 @@ export const ActionBar = observer(function ActionBar(): JSX.Element {
<ZoomMenu />
</div>

<div className={'tl-toolbar tl-grid-bar ml-4'}>
<div className={'tl-toolbar tl-grid-bar mr-2 mb-2'}>
<ToggleInput
tooltip={t('whiteboard/toggle-grid')}
className="tl-button"
Expand All @@ -88,6 +92,20 @@ export const ActionBar = observer(function ActionBar(): JSX.Element {
</ToggleInput>
)}
</div>

{!app.readOnly && (
<div className="tl-toolbar tl-pen-mode-bar mb-2">
<ToggleInput
tooltip={t('whiteboard/toggle-pen-mode')}
className="tl-button"
pressed={app.settings.penMode}
id="tl-toggle-pen-mode"
onPressedChange={togglePenMode}
>
<TablerIcon name={app.settings.penMode ? "pencil" : "pencil-off"} />
</ToggleInput>
</div>
)}
</div>
)
})
2 changes: 1 addition & 1 deletion tldraw/apps/tldraw-logseq/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ html[data-theme='light'] {
}

.tl-action-bar {
@apply absolute bottom-0 flex items-center border-0 left-10 bottom-10;
@apply absolute flex items-center border-0 left-10 bottom-8 flex-wrap-reverse pr-12;

z-index: 100000;
user-select: none;
Expand Down
7 changes: 7 additions & 0 deletions tldraw/packages/core/src/lib/TLApi/TLApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ export class TLApi<S extends TLShape = TLShape, K extends TLEventMap = TLEventMa
return this
}


togglePenMode = (): this => {
const { settings } = this.app
settings.update({ penMode: !settings.penMode })
return this
}

setColor = (color: string): this => {
const { settings } = this.app

Expand Down
2 changes: 2 additions & 0 deletions tldraw/packages/core/src/lib/TLSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { observable, makeObservable, action } from 'mobx'
export interface TLSettingsProps {
mode: 'light' | 'dark'
showGrid: boolean
penMode: boolean
snapToGrid: boolean
color: string
scaleLevel: string
Expand All @@ -17,6 +18,7 @@ export class TLSettings implements TLSettingsProps {
@observable mode: 'dark' | 'light' = 'light'
@observable showGrid = true
@observable snapToGrid = true
@observable penMode = false
@observable scaleLevel = 'md'
@observable color = ''

Expand Down
1 change: 1 addition & 0 deletions tldraw/packages/react/src/components/AppCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const AppCanvas = observer(function InnerApp<S extends TLReactShape>(
shapes={app.shapes} // TODO: use shapes in viewport later?
assets={app.assets}
showGrid={app.settings.showGrid}
penMode={app.settings.penMode}
showSelection={app.showSelection}
showSelectionRotation={app.showSelectionRotation}
showResizeHandles={app.showResizeHandles}
Expand Down
1 change: 1 addition & 0 deletions tldraw/packages/react/src/components/Canvas/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface TLCanvasProps<S extends TLReactShape> {
cursorRotation: number
selectionRotation: number
onEditingEnd: () => void
penMode: boolean
showGrid: boolean
showSelection: boolean
showHandles: boolean
Expand Down
20 changes: 20 additions & 0 deletions tldraw/packages/react/src/hooks/useCanvasEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@ export function useCanvasEvents() {

const events = React.useMemo(() => {
const onPointerMove: TLReactCustomEvents['pointer'] = e => {
if (app.settings.penMode && (e.pointerType !== 'pen' || !e.isPrimary)) {
return
}

const { order = 0 } = e
callbacks.onPointerMove?.({ type: TLTargetType.Canvas, order }, e)
}

const onPointerDown: TLReactCustomEvents['pointer'] = e => {
if (app.settings.penMode && (e.pointerType !== 'pen' || !e.isPrimary)) {
return
}

const { order = 0 } = e
if (!order) e.currentTarget?.setPointerCapture(e.pointerId)

Expand All @@ -41,17 +49,29 @@ export function useCanvasEvents() {
}

const onPointerUp: TLReactCustomEvents['pointer'] = e => {
if (app.settings.penMode && (e.pointerType !== 'pen' || !e.isPrimary)) {
return
}

const { order = 0 } = e
if (!order) e.currentTarget?.releasePointerCapture(e.pointerId)
callbacks.onPointerUp?.({ type: TLTargetType.Canvas, order }, e)
}

const onPointerEnter: TLReactCustomEvents['pointer'] = e => {
if (app.settings.penMode && (e.pointerType !== 'pen' || !e.isPrimary)) {
return
}

const { order = 0 } = e
callbacks.onPointerEnter?.({ type: TLTargetType.Canvas, order }, e)
}

const onPointerLeave: TLReactCustomEvents['pointer'] = e => {
if (app.settings.penMode && (e.pointerType !== 'pen' || !e.isPrimary)) {
return
}

const { order = 0 } = e
callbacks.onPointerLeave?.({ type: TLTargetType.Canvas, order }, e)
}
Expand Down
Loading

0 comments on commit 4a034a6

Please sign in to comment.