@@ -9,12 +9,18 @@ import { useReaderSettings, WEBVIEW_FONT_FAMILIES } from "@/lib/readerSettings";
99import { useColorScheme } from "@/lib/useColorScheme" ;
1010import { useQuery } from "@tanstack/react-query" ;
1111
12+ import {
13+ useCreateHighlight ,
14+ useDeleteHighlight ,
15+ useUpdateHighlight ,
16+ } from "@karakeep/shared-react/hooks/highlights" ;
1217import { useTRPC } from "@karakeep/shared-react/trpc" ;
1318import { BookmarkTypes , ZBookmark } from "@karakeep/shared/types/bookmarks" ;
1419
1520import FullPageError from "../FullPageError" ;
1621import FullPageSpinner from "../ui/FullPageSpinner" ;
1722import BookmarkAssetImage from "./BookmarkAssetImage" ;
23+ import BookmarkHtmlHighlighterDom from "./BookmarkHtmlHighlighterDom" ;
1824import { PDFViewer } from "./PDFViewer" ;
1925
2026export function BookmarkLinkBrowserPreview ( {
@@ -80,6 +86,16 @@ export function BookmarkLinkReaderPreview({
8086 } ) ,
8187 ) ;
8288
89+ const { data : highlights } = useQuery (
90+ api . highlights . getForBookmark . queryOptions ( {
91+ bookmarkId : bookmark . id ,
92+ } ) ,
93+ ) ;
94+
95+ const { mutate : createHighlight } = useCreateHighlight ( ) ;
96+ const { mutate : updateHighlight } = useUpdateHighlight ( ) ;
97+ const { mutate : deleteHighlight } = useDeleteHighlight ( ) ;
98+
8399 if ( isLoading ) {
84100 return < FullPageSpinner /> ;
85101 }
@@ -92,74 +108,44 @@ export function BookmarkLinkReaderPreview({
92108 throw new Error ( "Wrong content type rendered" ) ;
93109 }
94110
95- const fontFamily = WEBVIEW_FONT_FAMILIES [ readerSettings . fontFamily ] ;
96- const fontSize = readerSettings . fontSize ;
97- const lineHeight = readerSettings . lineHeight ;
111+ const contentStyle : React . CSSProperties = {
112+ fontFamily : WEBVIEW_FONT_FAMILIES [ readerSettings . fontFamily ] ,
113+ fontSize : `${ readerSettings . fontSize } px` ,
114+ lineHeight : String ( readerSettings . lineHeight ) ,
115+ color : isDark ? "#e5e7eb" : "#374151" ,
116+ padding : "16px" ,
117+ background : isDark ? "#000000" : "#ffffff" ,
118+ } ;
98119
99120 return (
100121 < View className = "flex-1 bg-background" >
101- < WebView
102- originWhitelist = { [ "*" ] }
103- source = { {
104- html : `
105- <!DOCTYPE html>
106- <html>
107- <head>
108- <meta name="viewport" content="width=device-width, initial-scale=1.0">
109- <style>
110- body {
111- font-family: ${ fontFamily } ;
112- font-size: ${ fontSize } px;
113- line-height: ${ lineHeight } ;
114- color: ${ isDark ? "#e5e7eb" : "#374151" } ;
115- margin: 0;
116- padding: 16px;
117- background: ${ isDark ? "#000000" : "#ffffff" } ;
118- }
119- p { margin: 0 0 1em 0; }
120- h1, h2, h3, h4, h5, h6 { margin: 1.5em 0 0.5em 0; line-height: 1.2; }
121- img { max-width: 100%; height: auto; border-radius: 8px; }
122- a { color: #3b82f6; text-decoration: none; }
123- a:hover { text-decoration: underline; }
124- blockquote {
125- border-left: 4px solid ${ isDark ? "#374151" : "#e5e7eb" } ;
126- margin: 1em 0;
127- padding-left: 1em;
128- color: ${ isDark ? "#9ca3af" : "#6b7280" } ;
129- }
130- pre, code {
131- font-family: ui-monospace, Menlo, Monaco, 'Courier New', monospace;
132- background: ${ isDark ? "#1f2937" : "#f3f4f6" } ;
133- }
134- pre {
135- padding: 1em;
136- border-radius: 6px;
137- overflow-x: auto;
138- }
139- code {
140- padding: 0.2em 0.4em;
141- border-radius: 3px;
142- font-size: 0.9em;
143- }
144- pre code {
145- padding: 0;
146- background: none;
147- }
148- </style>
149- </head>
150- <body>
151- ${ bookmarkWithContent . content . htmlContent }
152- </body>
153- </html>
154- ` ,
155- } }
156- style = { {
157- flex : 1 ,
158- backgroundColor : isDark ? "#000000" : "#ffffff" ,
159- } }
160- showsVerticalScrollIndicator = { false }
161- showsHorizontalScrollIndicator = { false }
162- decelerationRate = { 0.998 }
122+ < BookmarkHtmlHighlighterDom
123+ htmlContent = { bookmarkWithContent . content . htmlContent ?? "" }
124+ contentStyle = { contentStyle }
125+ highlights = { highlights ?. highlights ?? [ ] }
126+ onHighlight = { ( h ) =>
127+ createHighlight ( {
128+ startOffset : h . startOffset ,
129+ endOffset : h . endOffset ,
130+ color : h . color ,
131+ bookmarkId : bookmark . id ,
132+ text : h . text ,
133+ note : h . note ?? null ,
134+ } )
135+ }
136+ onUpdateHighlight = { ( h ) =>
137+ updateHighlight ( {
138+ highlightId : h . id ,
139+ color : h . color ,
140+ note : h . note ,
141+ } )
142+ }
143+ onDeleteHighlight = { ( h ) =>
144+ deleteHighlight ( {
145+ highlightId : h . id ,
146+ } )
147+ }
148+ dom = { { scrollEnabled : true } }
163149 />
164150 </ View >
165151 ) ;
0 commit comments