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
feat: add collapsible headers in editor
thecodrrcd01c55b5666
diff --git a/apps/web/src/components/editor/editor.css b/apps/web/src/components/editor/editor.cssindex 3338d3b1f..5aca3e8e5 100644--- a/apps/web/src/components/editor/editor.css+++ b/apps/web/src/components/editor/editor.css@@ -81,3 +81,45 @@ tox-tbtn tox-tbtn--select {.mce-content-body[data-mce-placeholder]:not(.mce-visualblocks)::before {margin-top: 15px !important;}++.mce-content-body *::before {+ font-size: 12px;+ font-weight: normal;+ color: var(--fontTertiary);+ letter-spacing: 1.2px;+ padding: 1px 3px 1px 3px;+ margin-left: -31px;+ margin-right: 7px;+ cursor: row-resize;+}++.mce-content-body h2::before {+ content: "H2";+}++.mce-content-body h3::before {+ content: "H3";+}++.mce-content-body h4::before {+ content: "H4";+}++.mce-content-body h5::before {+ content: "H5";+}++.mce-content-body blockquote::before {+ content: "QUOTE";+ margin-left: 0px !important;+}++.mce-content-body .c::before {+ color: var(--static);+ background-color: var(--primary);+ border-radius: 5px;+}++.h {+ display: none;+}diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.jsindex 30c4f8765..b8f1add00 100644--- a/apps/web/src/components/editor/index.js+++ b/apps/web/src/components/editor/index.js@@ -114,15 +114,25 @@ function Editor({ noteId, nonce }) {variant="columnFill"className="editor"sx={{- mx: 3,+ mx: [3, 3, 0],alignSelf: ["stretch", "stretch", "center"],}}animate={{- marginRight: isFocusMode && !isTablet ? "25%" : "15px",- marginLeft: isFocusMode && !isTablet ? "25%" : "15px",+ paddingRight:+ isFocusMode && !isTablet+ ? "25%"+ : isTablet || isMobile+ ? "20px"+ : "35px",+ paddingLeft:+ isFocusMode && !isTablet+ ? "25%"+ : isTablet || isMobile+ ? "20px"+ : "35px",}}transition={{ duration: 0.3, ease: "easeOut" }}- maxWidth={isFocusMode ? "auto" : "900px"}+ maxWidth={isFocusMode ? "auto" : "935px"}width={["100%", "100%", isFocusMode ? "50%" : "100%"]}mt={[0, 0, 25]}>diff --git a/apps/web/src/components/editor/tinymce.js b/apps/web/src/components/editor/tinymce.jsindex 3d779dbf5..e142c7751 100644--- a/apps/web/src/components/editor/tinymce.js+++ b/apps/web/src/components/editor/tinymce.js@@ -39,12 +39,11 @@ const markdownPatterns = [{ start: "**", end: "**", format: "bold" },{ start: "~~", end: "~~", format: "strikethrough" },{ start: "`", end: "`", format: "code" },- { start: "#", format: "h1" },- { start: "##", format: "h2" },- { start: "###", format: "h3" },- { start: "####", format: "h4" },- { start: "#####", format: "h5" },- { start: "######", format: "h6" },+ { start: "## ", format: "h2" },+ { start: "### ", format: "h3" },+ { start: "#### ", format: "h4" },+ { start: "##### ", format: "h5" },+ { start: "###### ", format: "h6" },{ start: "* ", cmd: "InsertUnorderedList" },{ start: "- ", cmd: "InsertUnorderedList" },{ start: "> ", format: "blockquote" },@@ -100,6 +99,42 @@ function useSkin() {: [host + "/skins/notesnook-dark", host + "/skins/notesnook"];}+const COLLAPSED_KEY = "c";+const HIDDEN_KEY = "h";+const collapsibleTags = { HR: 1, H2: 2, H3: 3, H4: 4, H5: 5 };++function toggleElementVisibility(element, toggleState) {+ if (!toggleState) element.classList.remove(HIDDEN_KEY);+ else element.classList.add(HIDDEN_KEY);+}++function collapseElement(target) {+ let sibling = target.nextSibling;+ const isTargetCollapsed = target.classList.contains(COLLAPSED_KEY);+ let skip = false;++ while (+ sibling &&+ (!collapsibleTags[sibling.tagName] ||+ collapsibleTags[sibling.tagName] > collapsibleTags[target.tagName])+ ) {+ const isCollapsed = sibling.classList.contains(COLLAPSED_KEY);+ if (!isTargetCollapsed) {+ if (isCollapsed) {+ skip = true;+ toggleElementVisibility(sibling, isTargetCollapsed);+ } else if (skip && collapsibleTags[sibling.tagName]) {+ skip = false;+ }+ }+ if (!skip) {+ toggleElementVisibility(sibling, isTargetCollapsed);+ }+ if (!sibling.nextSibling) break;+ sibling = sibling.nextSibling;+ }+}+function TinyMCE(props) {const {changeInterval,@@ -199,6 +234,14 @@ function TinyMCE(props) {block: "nearest",});});+ editor.on("NewBlock", (e) => {+ const { newBlock } = e;+ const target = newBlock?.previousElementSibling;+ if (target?.classList.contains(COLLAPSED_KEY)) {+ target.classList.remove(COLLAPSED_KEY);+ collapseElement(target);+ }+ });},toolbar_persist: true,toolbar_sticky: false,@@ -207,8 +250,31 @@ function TinyMCE(props) {fixed_toolbar_container: "#editorToolbar",autoresize_bottom_margin: 100,}}+ // onNodeChange={(e) => {++ // }}+ onClick={(e, editor) => {+ const { target } = e;+ if (+ e.offsetX < 0 &&+ collapsibleTags[target.tagName] &&+ target.parentElement.tagName === "DIV"+ ) {+ e.preventDefault();+ e.stopImmediatePropagation();+ e.stopPropagation();+ editor.undoManager.transact(() => {+ if (target.classList.contains(COLLAPSED_KEY)) {+ target.classList.remove(COLLAPSED_KEY);+ } else {+ target.classList.add(COLLAPSED_KEY);+ }+ collapseElement(target);+ onSave();+ });+ }+ }}onBeforeExecCommand={async (command) => {- console.log(command);if (premiumCommands.some((cmd) => {let isPremium = command.command === cmd && !command?.value?.paste;