A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
fix: make diff resolver work with tinymce
thecodrrc14f81a09bfd
diff --git a/apps/web/src/components/spliteditor/deltatoggle.js b/apps/web/src/components/spliteditor/contenttoggle.jssimilarity index 81%rename from apps/web/src/components/spliteditor/deltatoggle.jsrename to apps/web/src/components/spliteditor/contenttoggle.jsindex 47550e512..9aff896db 100644--- a/apps/web/src/components/spliteditor/deltatoggle.js+++ b/apps/web/src/components/spliteditor/contenttoggle.js@@ -4,8 +4,9 @@ import { timeConverter } from "../../utils/time";import { store as notestore } from "../../stores/note-store";import { db } from "../../common";import { hashNavigate } from "../../navigation";+import diff from "./differ";-function DeltaToggle(props) {+function ContentToggle(props) {const {isSelected,isOtherSelected,@@ -21,7 +22,7 @@ function DeltaToggle(props) {async (selectedContent, otherContent) => {selectedContent = {data: selectedContent,- type: "delta",+ type: "tiny",resolved: true,};@@ -33,7 +34,7 @@ function DeltaToggle(props) {if (otherContent) {otherContent = {data: otherContent,- type: "delta",+ type: "tiny",};await db.notes.add({...note,@@ -60,10 +61,10 @@ function DeltaToggle(props) {mr={2}onClick={async () => {const { selectedEditor, otherEditor } = editors();- // await resolveConflict(- // deltaTransformer.cleanDifference(selectedEditor.getContents()),- // deltaTransformer.cleanDifference(otherEditor.getContents())- // );+ await resolveConflict(+ diff.clean(selectedEditor.getContent({ format: "html" })),+ diff.clean(otherEditor.getContent({ format: "html" }))+ );}}p={1}px={2}@@ -75,10 +76,10 @@ function DeltaToggle(props) {variant="primary"onClick={async () => {if (isOtherSelected) {- // const { selectedEditor } = editors();- // await resolveConflict(- // deltaTransformer.cleanDifference(selectedEditor.getContents())- // );+ const { selectedEditor } = editors();+ await resolveConflict(+ diff.clean(selectedEditor.getContent({ format: "html" }))+ );} else {onToggle();}@@ -105,4 +106,4 @@ function DeltaToggle(props) {</Flex>);}-export default DeltaToggle;+export default ContentToggle;diff --git a/apps/web/src/components/spliteditor/differ.js b/apps/web/src/components/spliteditor/differ.jsindex 41961f260..a48081187 100644--- a/apps/web/src/components/spliteditor/differ.js+++ b/apps/web/src/components/spliteditor/differ.js@@ -659,7 +659,9 @@if (non_tags.length !== 0) {var val = non_tags.join("");if (val.trim()) {- rendering += `<span class="diff-${tag} ${class_name}">${val}</span>`;+ rendering += `<span class="diff-${tag} ${+ class_name || ""+ }">${val}</span>`;}}@@ -880,8 +882,6 @@before = html_to_tokens(before);after = html_to_tokens(after);ops = calculate_operations(before, after);-- console.log("NEW", ops);return render_operations_dual_pane(before, after, ops);}@@ -894,6 +894,20 @@diff.calculate_operations = calculate_operations;diff.render_operations = render_operations;diff.diff_dual_pane = diff_dual_pane;+ diff.clean = function (html) {+ const tokens = html_to_tokens(html);+ let isDiffSpanOpen = false;+ return tokens.reduce((result, token) => {+ if (token.includes(`span class="diff-`)) {+ isDiffSpanOpen = true;+ return result;+ } else if (isDiffSpanOpen && token.includes("</span>")) {+ isDiffSpanOpen = false;+ return result;+ }+ return result + token;+ }, "");+ };if (typeof define === "function") {// eslint-disable-next-line no-undefdiff --git a/apps/web/src/components/spliteditor/index.js b/apps/web/src/components/spliteditor/index.jsindex 001346879..4bf6ff76f 100644--- a/apps/web/src/components/spliteditor/index.js+++ b/apps/web/src/components/spliteditor/index.js@@ -1,7 +1,7 @@import React, { useState, useRef, useEffect } from "react";import { Flex, Box, Text } from "rebass";import SimpleEditor from "./simpleeditor";-import DeltaToggle from "./deltatoggle";+import ContentToggle from "./content-toggle";import { store as notesStore } from "../../stores/note-store";import { db } from "../../common";import { useStore as useAppStore } from "../../stores/app-store";@@ -70,7 +70,7 @@ function SplitEditor(props) {width={["100%", "100%", "50%"]}flex="1 1 auto">- <DeltaToggle+ <ContentTogglelabel="Current note"dateEdited={localContent.dateEdited}isSelected={selectedDelta === 0}@@ -78,8 +78,8 @@ function SplitEditor(props) {onToggle={() => setSelectedDelta((s) => (s === 0 ? -1 : 0))}note={conflictedNote}editors={() => ({- selectedEditor: remoteEditor.current.quill,- otherEditor: localEditor.current.quill,+ selectedEditor: remoteEditor.current.editor,+ otherEditor: localEditor.current.editor,})}sx={{borderStyle: "solid",@@ -112,7 +112,7 @@ function SplitEditor(props) {height={["50%", "50%", "100%"]}width={["100%", "100%", "50%"]}>- <DeltaToggle+ <ContentTogglesx={{alignItems: "flex-end",borderStyle: "solid",@@ -130,8 +130,8 @@ function SplitEditor(props) {dateEdited={remoteContent.dateEdited}onToggle={() => setSelectedDelta((s) => (s === 1 ? -1 : 1))}editors={() => ({- selectedEditor: localEditor.current.quill,- otherEditor: remoteEditor.current.quill,+ selectedEditor: localEditor.current.editor,+ otherEditor: remoteEditor.current.editor,})}/><Box px={2} overflowY="auto">diff --git a/apps/web/src/views/home.js b/apps/web/src/views/home.jsindex 65d0e14de..ec21a3a04 100644--- a/apps/web/src/views/home.js+++ b/apps/web/src/views/home.js@@ -11,10 +11,10 @@ function Home() {(async function () {await db.notes.init();store.refresh();- // const note = db.notes.note("7d91f4af509bfc824d005262").data;+ // const note = db.notes.note("f90f344ee3c13c2f686bd5c1").data;// const data = await db.content.raw(note.contentId);- // const note2 = db.notes.note("7a9dc2c53a534e578f28861b").data;+ // const note2 = db.notes.note("3e9a515cc63199a101ec49bb").data;// const data2 = await db.content.raw(note2.contentId);// const data3 = { ...data, conflicted: data2 };