From 9b8f22c68db53ce4bc8d5bccb7e3296325005039 Mon Sep 17 00:00:00 2001 From: Samuel JD <40059405+samueljd@users.noreply.github.com> Date: Tue, 15 Oct 2024 10:40:35 +0530 Subject: [PATCH 1/2] Lexical Scribe editor integration. (#369) fix for usfm error handling fix scroll issue, disabled non available books. --- .gitignore | 2 + package.json | 8 +- .../Navigation/reference/SelectBook.js | 2 + .../TextEditor/BibleNavigationX.jsx | 251 -- .../TextEditor/BibleNavigationX/SelectBook.js | 166 ++ .../BibleNavigationX/SelectChapter.js | 87 + .../SelectReference.module.css | 14 + .../TextEditor/BibleNavigationX/index.js | 198 ++ .../EditorPage/TextEditor/Buttons.jsx | 120 - .../EditorPage/TextEditor/Editor.jsx | 184 -- .../EditorPage/TextEditor/EditorMenuBar.jsx | 23 +- .../EditorPage/TextEditor/EmptyScreen.jsx | 37 + .../EditorPage/TextEditor/InsertMenu.jsx | 35 - .../EditorPage/TextEditor/LexicalEditor.jsx | 85 + .../TextEditor/NotesEditorHeader.jsx | 27 + .../EditorPage/TextEditor/Popup.jsx | 116 - .../EditorPage/TextEditor/RecursiveBlock.jsx | 137 - .../EditorPage/TextEditor/cacheUtils.js | 129 + .../EditorPage/TextEditor/conversionUtils.js | 45 + .../EditorPage/TextEditor/hooks/saveToFile.js | 6 +- .../TextEditor/hooks/useReadUsfmFile.js | 47 +- .../EditorPage/TextEditor/index.jsx | 174 +- .../EditorPage/TextEditor/updateAndSave.js | 15 + .../TextEditor/utils/IntersectionObserver.js | 36 - .../TextEditor/utils/getReferences.js | 64 - .../TextEditor/utils/insertFunctionMap.js | 18 - .../src/components/hooks/scribex/htmlmap.js | 55 - .../src/components/hooks/scribex/htmlmap.json | 44 - .../components/hooks/scribex/saveToFile.js | 42 - .../src/components/hooks/scribex/usePerf.js | 123 - .../hooks/scribex/useReadUsfmFile.js | 57 - .../src/layouts/editor/SectionContainer.js | 14 + .../modules/editorsidebar/EditorSideBar.js | 23 +- styles/globals.css | 2443 ++++++++++++++++- yarn.lock | 580 +++- 35 files changed, 3953 insertions(+), 1454 deletions(-) delete mode 100644 renderer/src/components/EditorPage/TextEditor/BibleNavigationX.jsx create mode 100644 renderer/src/components/EditorPage/TextEditor/BibleNavigationX/SelectBook.js create mode 100644 renderer/src/components/EditorPage/TextEditor/BibleNavigationX/SelectChapter.js create mode 100644 renderer/src/components/EditorPage/TextEditor/BibleNavigationX/SelectReference.module.css create mode 100644 renderer/src/components/EditorPage/TextEditor/BibleNavigationX/index.js delete mode 100644 renderer/src/components/EditorPage/TextEditor/Buttons.jsx delete mode 100644 renderer/src/components/EditorPage/TextEditor/Editor.jsx create mode 100644 renderer/src/components/EditorPage/TextEditor/EmptyScreen.jsx delete mode 100644 renderer/src/components/EditorPage/TextEditor/InsertMenu.jsx create mode 100644 renderer/src/components/EditorPage/TextEditor/LexicalEditor.jsx create mode 100644 renderer/src/components/EditorPage/TextEditor/NotesEditorHeader.jsx delete mode 100644 renderer/src/components/EditorPage/TextEditor/Popup.jsx delete mode 100644 renderer/src/components/EditorPage/TextEditor/RecursiveBlock.jsx create mode 100644 renderer/src/components/EditorPage/TextEditor/cacheUtils.js create mode 100644 renderer/src/components/EditorPage/TextEditor/conversionUtils.js create mode 100644 renderer/src/components/EditorPage/TextEditor/updateAndSave.js delete mode 100644 renderer/src/components/EditorPage/TextEditor/utils/IntersectionObserver.js delete mode 100644 renderer/src/components/EditorPage/TextEditor/utils/getReferences.js delete mode 100644 renderer/src/components/EditorPage/TextEditor/utils/insertFunctionMap.js delete mode 100644 renderer/src/components/hooks/scribex/htmlmap.js delete mode 100644 renderer/src/components/hooks/scribex/htmlmap.json delete mode 100644 renderer/src/components/hooks/scribex/saveToFile.js delete mode 100644 renderer/src/components/hooks/scribex/usePerf.js delete mode 100644 renderer/src/components/hooks/scribex/useReadUsfmFile.js diff --git a/.gitignore b/.gitignore index a0f608045..7c1e5ffa6 100755 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,8 @@ Autogrpha-DB/ /app/**/*.map /.next .next +.yalc +yalc.lock # testing /coverage diff --git a/package.json b/package.json index 8152c91ed..2be57c813 100644 --- a/package.json +++ b/package.json @@ -88,6 +88,7 @@ "@babel/eslint-parser": "^7.5.4", "@babel/preset-env": "^7.25.4", "@babel/preset-react": "^7.17.12", + "@capacitor/cli": "5.4.2", "@mui/icons-material": "^5.8.4", "@netlify/plugin-nextjs": "^4.8.0", "@playwright/test": "^1.36.2", @@ -127,6 +128,8 @@ "@mui/icons-material": "^5.x" }, "dependencies": { + "@babel/plugin-proposal-private-property-in-object": "^7.21.11", + "@biblionexus-foundation/scribe-editor": "0.1.2-scribe-v1", "@capacitor/app": "5.0.6", "@capacitor/core": "5.4.2", "@capacitor/haptics": "5.0.6", @@ -222,6 +225,7 @@ "react-router": "^5.2.0", "react-router-dom": "^5.2.0", "react-scripts": "5.0.1", + "sj-usfm-grammar": "^3.0.3", "styled-components": "^5.3.6", "tc-ui-toolkit": "5.3.3", "terser-webpack-plugin": "^5.3.10", @@ -230,9 +234,9 @@ "typescript": "^4.9.5", "use-deep-compare": "^1.1.0", "usfm-editor": "0.8.7", - "usfm-grammar": "^2.3.0", + "usfm-grammar": "^2.3.1", "uuid": "^9.0.1", - "wavesurfer.js": "^6.6.2", + "wavesurfer.js": "^6.6.4", "webpack-node-externals": "^3.0.0", "winston": "^3.7.2", "word-aligner": "1.0.0", diff --git a/renderer/src/components/EditorPage/Navigation/reference/SelectBook.js b/renderer/src/components/EditorPage/Navigation/reference/SelectBook.js index 2256f55f7..cb28054e0 100644 --- a/renderer/src/components/EditorPage/Navigation/reference/SelectBook.js +++ b/renderer/src/components/EditorPage/Navigation/reference/SelectBook.js @@ -14,6 +14,7 @@ export default function SelectBook({ selectedBooks, setSelectedBooks, scope, + setBook, existingScope = [], disableScope = {}, call = '', @@ -37,6 +38,7 @@ export default function SelectBook({ function bookSelect(e, bookId) { e.preventDefault(); onChangeBook(bookId, selectedBooks[0]); + setBook(bookId); if (multiSelectBook === false) { selectBook(); } } diff --git a/renderer/src/components/EditorPage/TextEditor/BibleNavigationX.jsx b/renderer/src/components/EditorPage/TextEditor/BibleNavigationX.jsx deleted file mode 100644 index 4be5cb2b0..000000000 --- a/renderer/src/components/EditorPage/TextEditor/BibleNavigationX.jsx +++ /dev/null @@ -1,251 +0,0 @@ -import PropTypes from 'prop-types'; -import { Dialog, Transition } from '@headlessui/react'; -import React, { - Fragment, useContext, useEffect, useRef, useState, -} from 'react'; -import { XMarkIcon, ChevronDownIcon } from '@heroicons/react/24/solid'; -import * as localforage from 'localforage'; -import SelectBook from '@/components/EditorPage/Navigation/reference/SelectBook'; -import SelectVerse from '@/components/EditorPage/Navigation/reference/SelectVerse'; - -import { ReferenceContext } from '@/components/context/ReferenceContext'; - -export default function BibleNavigationX(props) { - const { - showVerse, chapterNumber, setChapterNumber, verseNumber, setVerseNumber, - } = props; - const supportedBooks = null; // if empty array or null then all books available - - const { - state: { - bookId, - bookList, - bookName, - chapter, - verse, - chapterList, - verseList, - languageId, - // closeNavigation, - }, actions: { - onChangeBook, - onChangeChapter, - onChangeVerse, - applyBooksFilter, - setCloseNavigation, - }, - } = useContext(ReferenceContext); - - useEffect(() => { - applyBooksFilter(supportedBooks); - }, [applyBooksFilter, supportedBooks]); - - const [openBook, setOpenBook] = useState(false); - const [openVerse, setOpenVerse] = useState(false); - const cancelButtonRef = useRef(null); - - const [multiSelectVerse] = useState(false); - const [multiSelectBook] = useState(false); - const [selectedVerses, setSelectedVerses] = useState([]); - const [selectedBooks, setSelectedBooks] = useState([]); - const [verselectActive, setVerseSelectActive] = useState(false); - - function closeBooks() { - setOpenBook(false); - } - - function openBooks() { - setSelectedBooks([(bookId.toUpperCase())]); - setOpenBook(true); - } - - function closeVerses() { - setOpenVerse(false); - if (multiSelectVerse) { setVerseSelectActive(true); } - } - - function selectBook() { - setOpenBook(false); - setOpenVerse(true); - if (multiSelectVerse) { setSelectedVerses([]); } - } - - useEffect(() => { - const getSupportedBooks = async () => { - const refs = await localforage.getItem('refBibleBurrito'); - refs?.forEach((ref) => { - if (languageId !== null) { - if (ref.value.languages[0].tag === languageId) { - const supportedBooks = []; - Object.entries((ref.value.type.flavorType.currentScope)).forEach( - ([key]) => { - supportedBooks.push(key.toLowerCase()); - }, - ); - applyBooksFilter(supportedBooks); - } - } - }); - }; - getSupportedBooks(); - }, [languageId, applyBooksFilter]); - - useEffect(() => { - async function setReference() { - await localforage.setItem('navigationHistory', [bookId, chapter, verse]); - } - setReference(); - }, [bookId, chapter, verse]); - - useEffect(() => { - if (openBook === false && openVerse === false) { - setCloseNavigation(true); - } - if (openBook || openVerse) { - setCloseNavigation(false); - } - }, [openVerse, openBook, setCloseNavigation]); - - return ( - <> -