Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: collapsable headings

ammarahm-edbc90cdd4b4a2
diff --git a/apps/mobile/html/Web.bundle/site/index.css b/apps/mobile/html/Web.bundle/site/index.css
index c91febba0..1d359be3a 100644
--- a/apps/mobile/html/Web.bundle/site/index.css
+++ b/apps/mobile/html/Web.bundle/site/index.css
@@ -97,4 +97,3 @@ body {
border-radius: 5;
margin-top: 0;
}
-
diff --git a/apps/mobile/html/Web.bundle/site/index.html b/apps/mobile/html/Web.bundle/site/index.html
new file mode 100644
index 000000000..8045ac712
--- /dev/null
+++ b/apps/mobile/html/Web.bundle/site/index.html
@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+ <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1.0">
+ <meta charset="utf-8" />
+ <title>Notesnook Editor</title>
+ <link rel="stylesheet" href="./index.css">
+</head>
+
+<body>
+ <div class="app-main">
+ <input id="image-input" accept='image/png, image/gif, image/jpeg, image/bmp, image/x-icon' type="file"
+ name="name" style="display: none;" />
+ <div id="titlebar">
+ <form id="formBox">
+ <textarea maxlength="150" id="titleInput" placeholder="Note title"></textarea>
+ <div id="textCopy"></div>
+ </form>
+ <div class="info-bar">
+ <div style="display:flex;">
+ <p id="infowords"></p>
+ <p id="infodate"></p>
+ <p id="infosaved"></p>
+ </div>
+ </div>
+ </div>
+ <textarea hidden id="tiny_textarea"></textarea>
+ </div>
+ <script>
+ let editor = null;
+ let isLoading = true;
+ let regex = /\n/gm;
+ </script>
+ <script src="./compressor.min.js"></script>
+ <script src="./listeners.js"></script>
+ <script src="./dist/main.js"></script>
+ <script src="./constants.js"></script>
+ <script src="./init.js"></script>
+ <script>
+ attachMessageListener()
+ init_tiny("calc(100vh - 55px)");
+ </script>
+
+</body>
+
+</html>
\ No newline at end of file
diff --git a/apps/mobile/html/Web.bundle/site/init.js b/apps/mobile/html/Web.bundle/site/init.js
index 1295f5ec4..5810371a0 100755
--- a/apps/mobile/html/Web.bundle/site/init.js
+++ b/apps/mobile/html/Web.bundle/site/init.js
@@ -13,6 +13,55 @@ function reactNativeEventHandler(type, value) {
}
let changeTimer = null;
+const COLLAPSED_KEY = 'c';
+const HIDDEN_KEY = 'h';
+const collapsibleTags = {HR: 1, H2: 2, H3: 3, H4: 4, H5: 5, H6: 6};
+let styleElement;
+function addStyle() {
+ if (!styleElement) {
+ let doc = editor.dom.doc;
+ styleElement = doc.head.appendChild(document.createElement('style'));
+ }
+ styleElement.innerHTML =
+ '.mce-content-body .c::before{' +
+ 'background-color:' +
+ pageTheme.colors.accent +
+ ';border-radius:3px;color:white}';
+ console.log('adding style');
+}
+
+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);
+ }
+ addStyle();
+ if (!sibling.nextSibling) break;
+ sibling = sibling.nextSibling;
+ }
+}
function init_tiny(size) {
tinymce.init({
@@ -35,6 +84,42 @@ function init_tiny(size) {
textpattern_patterns: markdownPatterns,
contextmenu: false,
content_style: `
+ .mce-content-body *::before {
+ font-size: 11px;
+ font-weight: normal;
+ letter-spacing: 1.1px;
+ padding: 1px 3px 1px 3px;
+ margin-left: -12px;
+ margin-right: 5px;
+ cursor: row-resize;
+ margin-top:-3px;
+ vertical-align:middle;
+ }
+
+ .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;
+ }
+
+ .h {
+ display: none;
+ }
.img_float_left {
float:left;
}
@@ -188,6 +273,45 @@ function init_tiny(size) {
}
});
+
+editor.on('NewBlock', function (e) {
+ const {newBlock} = e;
+ let target;
+ if (newBlock) {
+ target = newBlock.previousElementSibling;
+ }
+ if (target && target.classList.contains(COLLAPSED_KEY)) {
+ target.classList.remove(COLLAPSED_KEY);
+ collapseElement(target);
+ }
+});
+
+editor.on('mousedown', function (e) {
+ const {target} = e;
+ if (
+ e.offsetX < 6 &&
+ collapsibleTags[target.tagName] &&
+ target.parentElement &&
+ target.parentElement.tagName === 'BODY'
+ ) {
+ 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);
+ console.log('element has collapsed');
+ reactNativeEventHandler('tiny', editor.getContent());
+ });
+ }
+});
+
+
+
editor.on('ScrollIntoView', function (e) {
e.preventDefault();