From 640e5af6fec15531247e0907c6034fb8907ee6a4 Mon Sep 17 00:00:00 2001 From: Triston Armstrong Date: Tue, 8 Oct 2024 23:57:24 -0400 Subject: [PATCH] fix styling of markdown text --- .../MarkDownEditor/MarkDownEditor.tsx | 12 ++++- src/components/MarkDownEditor/md.css | 46 ++++++++++++++++- src/components/MiniMap.tsx | 50 ++++++++++++------- src/components/NoteCard.tsx | 15 ++++-- src/styles.css | 9 ++-- 5 files changed, 103 insertions(+), 29 deletions(-) diff --git a/src/components/MarkDownEditor/MarkDownEditor.tsx b/src/components/MarkDownEditor/MarkDownEditor.tsx index 95a9bc5..ddb4568 100644 --- a/src/components/MarkDownEditor/MarkDownEditor.tsx +++ b/src/components/MarkDownEditor/MarkDownEditor.tsx @@ -1,8 +1,15 @@ -import { Editor } from 'tiny-markdown-editor' +import { Editor, Listener } from 'tiny-markdown-editor' import './md.css' import { useEffect, useRef } from "kaioken" -export function MarkDownEditor({ initial }: { initial: string }) { +namespace MarkDownEditor { + export interface Props { + initial: string + onChange: Listener<'change'> + } +} + +export function MarkDownEditor({ initial, onChange }: MarkDownEditor.Props) { const elRef = useRef(null) useEffect(() => { @@ -11,6 +18,7 @@ export function MarkDownEditor({ initial }: { initial: string }) { element: elRef.current, content: initial }) + editor.addEventListener('change', onChange) }, []) return ( diff --git a/src/components/MarkDownEditor/md.css b/src/components/MarkDownEditor/md.css index c730965..4038560 100644 --- a/src/components/MarkDownEditor/md.css +++ b/src/components/MarkDownEditor/md.css @@ -1,3 +1,47 @@ .TinyMDE { - @apply h-full bg-transparent overflow-y-scroll; + @apply h-full bg-transparent overflow-y-scroll dark:text-gray-300 text-gray-600; +} + +.TMMark_TMH1, +.TMMark_TMH2, +.TMMark_TMH3, +.TMMark_TMH4, +.TMMark_TMH5, +.TMMark_TMH6, +.TMMark_TMOL, +.TMMark_TMUL { + @apply text-blue-500; +} + +.TMH1, +.TMH2, +.TMH3, +.TMH4, +.TMH5, +.TMH6 { + @apply uppercase; +} + +.TMLink { + @apply decoration-blue-500; +} + +.TMImage { + @apply decoration-green-500; +} + +.TMCode { + @apply text-blue-800 px-1; +} + +.TMBlockquote { + @apply border-blue-500 bg-blue-100 dark:bg-opacity-5; +} + +.TMFencedCodeBacktick { + @apply dark:bg-white dark:bg-opacity-10 px-1; +} + +.TMInfoString { + @apply text-blue-500; } diff --git a/src/components/MiniMap.tsx b/src/components/MiniMap.tsx index d037a83..1868fdb 100644 --- a/src/components/MiniMap.tsx +++ b/src/components/MiniMap.tsx @@ -21,6 +21,7 @@ export function MiniMap() { const width = canvasDimentsion.value.width / _MAP_SCALE_FACTOR const height = canvasDimentsion.value.height / _MAP_SCALE_FACTOR + useEffect(() => { function _handleScroll(_e: Event) { scrollX.value = window.scrollX @@ -31,8 +32,6 @@ export function MiniMap() { return () => window.removeEventListener('scroll', _handleScroll) }, []) - - return (
) @@ -74,29 +82,37 @@ export function MiniMap() { const note = notes.notes.value[noteKey] function _handleItemClick(_e: MouseEvent) { + const newLeft = note.position.x - ((viewportWidth / 2) - (note.dimensions.w / 2)) + const newTop = note.position.y - ((viewportHeight / 2) - (note.dimensions.h / 2)) window.scrollTo({ - left: note.position.x - ((viewportWidth / 2) - (note.dimensions.w / 2)), - top: note.position.y - ((viewportHeight / 2) - (note.dimensions.h / 2)), + left: newLeft, + top: newTop, behavior: 'smooth' }) } + const newWidth = note.dimensions.w / _MAP_SCALE_FACTOR + const newHeight = note.dimensions.h / _MAP_SCALE_FACTOR + const newTop = (note.position.y / _MAP_SCALE_FACTOR) + const newLeft = (note.position.x / _MAP_SCALE_FACTOR) + const newZIndex = LayerEnum.MINIMAP + 1 + return (
) })}
(null) const { debounce } = useDebounce() @@ -90,10 +89,16 @@ export function NoteCard({ key: itemKey, data: item }: NoteCard.NoteCardProps) { window.removeEventListener('mouseup', _handleResizeMouseUp) } + function _handleMdChange(e: ChangeEvent) { + NotesSigal.default.updateNoteProperty(itemKey, 'contents', e.content) + NotesSigal.default.notes.notify() + updateLocalStorage() + } + return (
focusedItem.value = itemKey} - className="overflow-hidden text-[#333] dark:bg-[#111] dark:border-[#1c1c1c] bg-[#eee] select-none transition flex flex-col justify-stretch shadow-md rounded border border-[#ddd] absolute" + className="overflow-hidden text-[#333] dark:bg-[#1a1a1a] dark:border-[#1c1c1c] bg-[#eee] select-none transition flex flex-col justify-stretch shadow-md rounded border border-[#ddd] absolute" style={{ zIndex: `${focusedItem.value == itemKey ? LayerEnum.CARD_ELEVATED : LayerEnum.CARD}`, width: `${item.dimensions.w}px`, @@ -115,7 +120,7 @@ export function NoteCard({ key: itemKey, data: item }: NoteCard.NoteCardProps) {

- + diff --git a/src/styles.css b/src/styles.css index df90cf6..2cad54e 100644 --- a/src/styles.css +++ b/src/styles.css @@ -13,14 +13,15 @@ box-sizing: border-box; } -*::-webkit-scrollbar { - display: none; -} - html { overflow: scroll; } +html, +body { + overscroll-behavior-x: none; +} + :root { font-family: Inter, Avenir, Helvetica, Arial, sans-serif; font-synthesis: none;