-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed title and headings editable in reference bible
- Loading branch information
Showing
4 changed files
with
95 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
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
80 changes: 80 additions & 0 deletions
80
renderer/src/components/EditorPage/Scribex/ReferenceRecursiveBlock.jsx
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,80 @@ | ||
/* eslint-disable react/prop-types */ | ||
/* eslint-disable no-unused-vars */ | ||
import React, { useEffect, useState } from 'react'; | ||
import { HtmlPerfEditor } from '@xelah/type-perf-html'; | ||
|
||
const getTarget = ({ content }) => { | ||
const div = document.createElement('div'); | ||
div.innerHTML = content; | ||
|
||
const { target } = div.firstChild?.dataset || {}; | ||
|
||
return target; | ||
}; | ||
|
||
export default function ReferenceRecursiveBlock({ | ||
htmlPerf, | ||
onHtmlPerf, | ||
sequenceIds, | ||
addSequenceId, | ||
options, | ||
content, | ||
style, | ||
contentEditable, | ||
index, | ||
verbose, | ||
setFootNote, | ||
...props | ||
}) { | ||
useEffect(() => { | ||
if (verbose) console.log('Block: Mount/First Render', index); | ||
return () => { | ||
if (verbose) console.log('Block: UnMount/Destroyed', index); | ||
}; | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
console.log({ contentEditable }); | ||
const checkReturnKeyPress = (event) => { | ||
if (event.key === 'Enter') { | ||
let activeTextArea = document.activeElement; | ||
if (activeTextArea.children.length > 1) { | ||
const lineBreak = activeTextArea.children[1]?.outerHTML; | ||
const newLine = lineBreak.replace(/<br\s*\/?>/gi, ' '); | ||
activeTextArea.children[1].outerHTML = newLine; | ||
} | ||
} | ||
}; | ||
|
||
let component; | ||
|
||
let editable = !!content.match(/data-type="paragraph"/); | ||
|
||
if (editable) { | ||
component = ( | ||
<div | ||
contentEditable={contentEditable} | ||
onKeyUp={checkReturnKeyPress} | ||
{...props} | ||
/> | ||
); | ||
} | ||
|
||
if (!editable) { | ||
const sequenceId = getTarget({ content }); | ||
|
||
if (sequenceId && !options.preview) { | ||
const _props = { | ||
sequenceIds: [...sequenceIds, sequenceId], | ||
addSequenceId, | ||
htmlPerf, | ||
onHtmlPerf, | ||
onInput: props?.onInput, | ||
options, | ||
}; | ||
component = <HtmlPerfEditor {..._props} />; | ||
} | ||
component ||= <div {...props} contentEditable={false} />; | ||
} | ||
|
||
return <>{component}</>; | ||
} |
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