1- import { useEffect , useLayoutEffect , useMemo , useRef , useState } from "preact/hooks" ;
1+ import { useEffect , useRef , useState } from "preact/hooks" ;
22import FNote from "../../../entities/fnote" ;
33import Icon from "../../react/Icon" ;
44import { ViewModeProps } from "../interface" ;
@@ -11,9 +11,7 @@ import tree from "../../../services/tree";
1111import link from "../../../services/link" ;
1212import { t } from "../../../services/i18n" ;
1313import attribute_renderer from "../../../services/attribute_renderer" ;
14- import froca from "../../../services/froca" ;
15- import { RawHtmlBlock } from "../../react/RawHtml" ;
16- import { escapeHtml } from "../../../services/utils" ;
14+ import { useFilteredNoteIds } from "./utils" ;
1715
1816export function ListView ( { note, noteIds : unfilteredNoteIds , highlightedTokens } : ViewModeProps < { } > ) {
1917 const [ isExpanded ] = useNoteLabelBoolean ( note , "expanded" ) ;
@@ -37,82 +35,6 @@ export function ListView({ note, noteIds: unfilteredNoteIds, highlightedTokens }
3735 ) ;
3836}
3937
40- interface NotesWithContent {
41- note : FNote ;
42- content : string ;
43- }
44-
45- export function ListPrintView ( { note, noteIds : unfilteredNoteIds , onReady } : ViewModeProps < { } > ) {
46- const noteIds = useFilteredNoteIds ( note , unfilteredNoteIds ) ;
47- const [ notesWithContent , setNotesWithContent ] = useState < NotesWithContent [ ] > ( ) ;
48-
49- useLayoutEffect ( ( ) => {
50- froca . getNotes ( noteIds ) . then ( async ( notes ) => {
51- const notesWithContent : NotesWithContent [ ] = [ ] ;
52-
53- async function processNote ( note : FNote , depth : number ) {
54- const content = await content_renderer . getRenderedContent ( note , {
55- trim : false ,
56- noChildrenList : true
57- } ) ;
58-
59- const contentEl = content . $renderedContent [ 0 ] ;
60-
61- // Create page title element
62- const pageTitleEl = document . createElement ( "h1" ) ;
63- pageTitleEl . textContent = note . title ;
64- contentEl . prepend ( pageTitleEl ) ;
65-
66- // Rewrite heading tags to ensure proper hierarchy in print view.
67- const headings = contentEl . querySelectorAll ( "h1, h2, h3, h4, h5, h6" )
68- for ( const headingEl of headings ) {
69- const currentLevel = parseInt ( headingEl . tagName . substring ( 1 ) , 10 ) ;
70- const newLevel = Math . min ( currentLevel + depth , 6 ) ;
71- const newHeadingEl = document . createElement ( `h${ newLevel } ` ) ;
72- newHeadingEl . innerHTML = headingEl . innerHTML ;
73- headingEl . replaceWith ( newHeadingEl ) ;
74- }
75-
76- notesWithContent . push ( { note, content : contentEl . innerHTML } ) ;
77-
78- if ( note . hasChildren ( ) ) {
79- const imageLinks = note . getRelations ( "imageLink" ) ;
80- const childNotes = await note . getChildNotes ( ) ;
81- const filteredChildNotes = childNotes . filter ( ( childNote ) => ! imageLinks . find ( ( rel ) => rel . value === childNote . noteId ) ) ;
82- for ( const childNote of filteredChildNotes ) {
83- await processNote ( childNote , depth + 1 ) ;
84- }
85- }
86- }
87-
88- for ( const note of notes ) {
89- await processNote ( note , 1 ) ;
90- }
91- setNotesWithContent ( notesWithContent ) ;
92- } ) ;
93- } , [ noteIds ] ) ;
94-
95- useEffect ( ( ) => {
96- if ( notesWithContent && onReady ) {
97- onReady ( ) ;
98- }
99- } , [ notesWithContent , onReady ] ) ;
100-
101- return (
102- < div class = "note-list list-print-view" >
103- < div class = "note-list-container use-tn-links" >
104- < h1 > { note . title } </ h1 >
105-
106- { notesWithContent ?. map ( ( { note : childNote , content } ) => (
107- < section id = { `note-${ childNote . noteId } ` } class = "note" >
108- < RawHtmlBlock html = { content } />
109- </ section >
110- ) ) }
111- </ div >
112- </ div >
113- ) ;
114- }
115-
11638export function GridView ( { note, noteIds : unfilteredNoteIds , highlightedTokens } : ViewModeProps < { } > ) {
11739 const noteIds = useFilteredNoteIds ( note , unfilteredNoteIds ) ;
11840 const { pageNotes, ...pagination } = usePagination ( note , noteIds ) ;
@@ -252,17 +174,6 @@ function NoteChildren({ note, parentNote, highlightedTokens }: { note: FNote, pa
252174 return childNotes ?. map ( childNote => < ListNoteCard note = { childNote } parentNote = { parentNote } highlightedTokens = { highlightedTokens } /> )
253175}
254176
255- /**
256- * Filters the note IDs for the legacy view to filter out subnotes that are already included in the note content such as images, included notes.
257- */
258- function useFilteredNoteIds ( note : FNote , noteIds : string [ ] ) {
259- return useMemo ( ( ) => {
260- const includedLinks = note ? note . getRelations ( ) . filter ( ( rel ) => rel . name === "imageLink" || rel . name === "includeNoteLink" ) : [ ] ;
261- const includedNoteIds = new Set ( includedLinks . map ( ( rel ) => rel . value ) ) ;
262- return noteIds . filter ( ( noteId ) => ! includedNoteIds . has ( noteId ) && noteId !== "_hidden" ) ;
263- } , noteIds ) ;
264- }
265-
266177function getNotePath ( parentNote : FNote , childNote : FNote ) {
267178 if ( parentNote . type === "search" ) {
268179 // for search note parent, we want to display a non-search path
0 commit comments