-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable injecting custom content into various reader UI parts
- Loading branch information
Showing
9 changed files
with
83 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React, { memo, useEffect, useRef } from 'react'; | ||
|
||
let CustomSections = memo(({ type, ...props }) => { | ||
let sectionRef = useRef(); | ||
useEffect(() => { | ||
sectionRef.current.replaceChildren(); | ||
let finished = false; | ||
let append = (...args) => { | ||
if (finished) { | ||
throw new Error('Append must be called directly and synchronously in the event'); | ||
} | ||
let section = document.createElement('div'); | ||
section.className = 'section'; | ||
section.append(...args); | ||
sectionRef.current.append(section); | ||
}; | ||
let event = new CustomEvent(`customEvent`, { detail: { type: `render${type}`, doc: document, append, params: props } }); | ||
window.dispatchEvent(event); | ||
finished = true; | ||
}); | ||
return ( | ||
<div ref={sectionRef} className="custom-sections"/> | ||
); | ||
}); | ||
|
||
export default CustomSections; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -246,3 +246,7 @@ body.freeze { | |
content: '⧉'; | ||
} | ||
} | ||
|
||
.custom-sections:empty { | ||
display: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,12 @@ | |
color: #c0c0c0; | ||
} | ||
} | ||
|
||
.custom-sections { | ||
display: flex; | ||
padding: 0 3px; | ||
gap: 3px; | ||
} | ||
} | ||
|
||
.text { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters