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
add tags bar in editor
ammarahm-ed1e7eabf4525b
diff --git a/apps/mobile/android/app/src/main/assets/index.css b/apps/mobile/android/app/src/main/assets/index.cssindex 779b91ce0..e28e05807 100644--- a/apps/mobile/android/app/src/main/assets/index.css+++ b/apps/mobile/android/app/src/main/assets/index.css@@ -47,7 +47,6 @@ body {font-family: 'Open Sans';color: gray;font-size: 11.5px;- height: 13px;display: flex;padding-left: 4px !important;justify-content: space-between;@@ -61,11 +60,11 @@ body {#infowords,#infodate,#infosaved {font-family: 'Open Sans';- margin-right: 5px;+ margin:0px !important;+ margin-right: 5px !important;margin-left: 0px;border-radius: 5px;margin-top: 0;- height:16px;padding-top:2.5px;}diff --git a/apps/mobile/html/Web.bundle/site/constants.js b/apps/mobile/html/Web.bundle/site/constants.jsindex 52171dd21..15c26433c 100755--- a/apps/mobile/html/Web.bundle/site/constants.js+++ b/apps/mobile/html/Web.bundle/site/constants.js@@ -137,6 +137,74 @@ function setTheme() {.info-bar {color:${pageTheme.colors.icon};}++ .tag-bar-parent {+ width: 100%;+ display: flex;+ flex-direction: row;+ align-items: center;+ box-sizing: border-box;+ padding-right: 12px;+ padding-left: 12px;+ margin-bottom: 10px;+ margin-top: 10px;+ }++ .tag-bar {+ display: flex;+ flex-direction: row;+ align-items: center;+ overflow-x: scroll;+ overflow-y: hidden;+ }++ .tag {+ background-color: ${pageTheme.colors.nav};+ border-radius: 100px;+ margin-right: 5px;+ padding-left: 12px;+ padding-right: 12px;+ font-size: 12px;+ height: 30px;+ display: flex;+ align-items: center;+ }++ .tag:active {+ background-color: ${pageTheme.colors.transGray} !important;+ border-width: 2px;+ }++ .alttagnew {+ padding-left: 6px !important;+ padding-right: 12px !important;+ }+ .alttagnew svg {+ padding-right:3px;+ }++ .newtag {+ padding-left: 20px;+ padding-right: 20px;+ color:${pageTheme.colors.pri}+ }++ .tag svg {+ fill: ${pageTheme.colors.accent};+ width: 20px;+ height: 20px;+ }++ .hidden {+ display: none;+ }++ .tag p {+ margin: 0px !important;+ pointer-events: none;+ user-select: none;+ color: ${pageTheme.colors.icon}+ }#titlebar {display:flex !important;diff --git a/apps/mobile/html/Web.bundle/site/index.css b/apps/mobile/html/Web.bundle/site/index.cssindex 3a9173e4d..3c5c75128 100644--- a/apps/mobile/html/Web.bundle/site/index.css+++ b/apps/mobile/html/Web.bundle/site/index.css@@ -49,7 +49,6 @@ body {font-family: 'Open Sans';color: gray;font-size: 11.5px;- height: 13px;display: flex;padding-left: 14px !important;justify-content: space-between;@@ -65,11 +64,11 @@ body {#infodate,#infosaved {font-family: 'Open Sans';- margin-right: 5px;- margin-left: 0px;border-radius: 5px;+ margin:0px !important;margin-top: 0;- height: 16px;+ margin-right: 5px !important;+ margin-left: 0px;padding-top: 2.5px;}diff --git a/apps/mobile/html/Web.bundle/site/index.html b/apps/mobile/html/Web.bundle/site/index.htmlindex 657628116..6aae947d5 100644--- a/apps/mobile/html/Web.bundle/site/index.html+++ b/apps/mobile/html/Web.bundle/site/index.html@@ -13,11 +13,23 @@<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 class="tag-bar-parent hidden">+ <div style="margin: 0px !important;margin-right:5px !important;" class="tag newtag">+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"+ width="24" height="24" viewBox="0 0 24 24">+ <path d="M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z" />+ </svg>+ <p class="newtagp" ></p>+ </div>+ <div class="tag-bar"></div>+ </div><div id="titlebar"><div id="formBox">- <input maxlength="150" id="titleInput"- placeholder="Note title"></input>+ <input maxlength="150" id="titleInput" placeholder="Note title"></input></div>+++<div class="info-bar"><div style="display:flex;"><p id="infowords"></p>@@ -25,6 +37,7 @@<p style="display:none" id="infosaved"></p></div></div>+</div><textarea hidden id="tiny_textarea"></textarea></div>@@ -42,6 +55,63 @@<script>attachMessageListener()</script>+ <script>+ document.querySelector(".newtag").onclick = function () {+ reactNativeEventHandler("newtag", "new");+ }+ function clearNode(selector) {+ let node = document.querySelector(selector);+ if (node) {+ node.innerHTML = "";+ }+ }+ function onClick(event) {+ event.preventDefault();+ reactNativeEventHandler("notetag", event.target.dataset.tag);+ }++ function renderChildernInNode(data, parent, nodeName, classes) {+ if (data.length === 0) {+ let stag = document.querySelector(".newtagp");+ stag.innerText = " Add a tag"+ if (!stag.parentElement.classList.contains('alttagnew')) {+ stag.parentElement.classList.add("alttagnew");+ }+ } else {+ let stag = document.querySelector(".newtagp");++ stag.innerText = "";+ if (stag.parentElement.classList.contains('alttagnew')) {+ stag.parentElement.classList.remove("alttagnew")+ }+ }+ let parentNode = document.querySelector(parent);+ data.forEach(function (item) {+ let childNode = document.createElement(nodeName);+ let pNode = document.createElement('p');+ pNode.innerText = "#" + item.alias+ childNode.appendChild(pNode);+ childNode.dataset.tag = JSON.stringify(item);+ for (var i = 0; i < classes.length; i++) {+ childNode.classList.add(classes[i]);+ }+ childNode.ontouchend = onClick;+ parentNode.appendChild(childNode);+ })+ }+ function toggleNode(selector = "p", value) {+ let node = document.querySelector(selector);+ if (value === "hide" && !node.classList.contains('hidden')) {+ node.classList.add('hidden');+ return;+ }+ if (value === "show" && node.classList.contains('hidden')) {+ node.classList.remove('hidden');+ }++ }++ </script></body>diff --git a/apps/mobile/html/Web.bundle/site/init.js b/apps/mobile/html/Web.bundle/site/init.jsindex 852a62f53..edc948581 100755--- a/apps/mobile/html/Web.bundle/site/init.js+++ b/apps/mobile/html/Web.bundle/site/init.js@@ -163,7 +163,7 @@ function init_callback(_editor) {// });editor.on('NewBlock', function (e) {- console.log('New Block');+ console.log('New Block', e);const {newBlock} = e;let target;if (newBlock) {@@ -208,8 +208,10 @@ function init_callback(_editor) {e.preventDefault();}});+editor.on('ScrollIntoView', function (e) {e.preventDefault();+ console.log(e);e.elm.scrollIntoView({behavior: 'smooth',block: 'nearest'@@ -218,6 +220,7 @@ function init_callback(_editor) {editor.on('input ExecCommand ObjectResized Redo Undo', onChange);editor.on('keyup', e => {+ console.log('keyup: ', e);if (e.key !== 'Backspace') return;if (!editor.getHTML) return;onChange();@@ -494,11 +497,29 @@ function delay(base = 0) {if (prevCount > 70000) return base + 1000;}+let inputKeyTimer = 0;+function scrollSelectionIntoView(event) {+ if (navigator.vendor.match(/apple/i)) return;+ if (+ event.type === 'input' &&+ event.inputType !== 'deleteContentBackward' &&+ event.data &&+ event.data.endsWith('\n')+ ) {+ console.log(event);+ clearTimeout(inputKeyTimer);+ inputKeyTimer = setTimeout(() => {+ let node = editor.selection.getNode();+ if (node) {+ console.log(node, 'scrolling into view');+ node.scrollIntoView({behavior: 'smooth', block: 'nearest'});+ }+ }, 1);+ }+}+let noteedited = false;const onChange = function (event) {- // console.log(event.type, event.selectionChange);- // if (event.type === 'nodechange' && !event.selectionChange) return;-if (event.type && event.type.toLowerCase() === 'execcommand') {if (event.command.toLowerCase() === 'mcefocus' ||@@ -508,6 +529,8 @@ const onChange = function (event) {}}+ scrollSelectionIntoView(event);+if (isLoading) {isLoading = false;}@@ -585,12 +608,13 @@ function selectchange() {let node = editor.selection.getNode();currentFormats.hilitecolor = getNodeBg(node);currentFormats.forecolor = getNodeColor(node);-if (!currentFormats.hilitecolor || !currentFormats.forecolor) {- for (var i = 0; i < node.children.length; i++) {- let item = editor.selection.getNode().children.item(i);- currentFormats.hilitecolor = getNodeBg(item);- currentFormats.forecolor = getNodeColor(item);+ if (!/^(LI|UL|OL|DL|P|DIV)$/.test(node.nodeName)) {+ for (var i = 0; i < node.children.length; i++) {+ let item = editor.selection.getNode().children.item(i);+ currentFormats.hilitecolor = getNodeBg(item);+ currentFormats.forecolor = getNodeColor(item);+ }}}let range = editor.selection.getRng();diff --git a/apps/mobile/html/Web.bundle/site/plus.svg b/apps/mobile/html/Web.bundle/site/plus.svgnew file mode 100644index 000000000..2c2183906--- /dev/null+++ b/apps/mobile/html/Web.bundle/site/plus.svg@@ -0,0 +1 @@+<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path d="M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z" /></svg>\ No newline at end of filediff --git a/apps/mobile/src/views/Editor/EditorHeader.js b/apps/mobile/src/views/Editor/EditorHeader.jsindex 24aac0bff..d34410598 100644--- a/apps/mobile/src/views/Editor/EditorHeader.js+++ b/apps/mobile/src/views/Editor/EditorHeader.js@@ -1,5 +1,5 @@-import {EV, EVENTS} from 'notes-core/common';-import React, {useEffect, useRef} from 'react';+import { EV, EVENTS } from 'notes-core/common';+import React, { useEffect, useRef } from 'react';import {BackHandler,InteractionManager,@@ -7,17 +7,16 @@ import {Platform,View} from 'react-native';-import {useSafeAreaInsets} from 'react-native-safe-area-context';-import {notesnook} from '../../../e2e/test.ids';-import {ActionIcon} from '../../components/ActionIcon';-import {ActionSheetEvent} from '../../components/DialogManager/recievers';-import {useTracked} from '../../provider';+import { useSafeAreaInsets } from 'react-native-safe-area-context';+import { notesnook } from '../../../e2e/test.ids';+import { ActionIcon } from '../../components/ActionIcon';+import { ActionSheetEvent } from '../../components/DialogManager/recievers';+import { useTracked } from '../../provider';import {useEditorStore,- useSettingStore,- useUserStore+ useSettingStore, useUserStore} from '../../provider/stores';-import {DDS} from '../../services/DeviceDetection';+import { DDS } from '../../services/DeviceDetection';import {eSendEvent,eSubscribeEvent,@@ -25,8 +24,8 @@ import {ToastEvent} from '../../services/EventManager';import Navigation from '../../services/Navigation';-import {editing, SUBSCRIPTION_STATUS} from '../../utils';-import {db} from '../../utils/database';+import { editing, SUBSCRIPTION_STATUS } from '../../utils';+import { db } from '../../utils/database';import {eClearEditor,eCloseFullscreenEditor,@@ -36,22 +35,20 @@ import {eOpenPremiumDialog,eOpenPublishNoteDialog} from '../../utils/Events';-import {tabBarRef} from '../../utils/Refs';-import {EditorTitle} from './EditorTitle';+import { tabBarRef } from '../../utils/Refs';+import { EditorTitle } from './EditorTitle';import {clearEditor,- clearTimer,- EditorWebView,- getNote,+ clearTimer, getNote,loadNote,setColors,startClosingSession} from './Functions';-import HistoryComponent from './HistoryComponent';-import {ProgressCircle} from './ProgressCircle';-import tiny, {safeKeyboardDismiss} from './tiny/tiny';-import {toolbarRef} from './tiny/toolbar/constants';+import { ProgressCircle } from './ProgressCircle';+import tiny, { safeKeyboardDismiss } from './tiny/tiny';+import { toolbarRef } from './tiny/toolbar/constants';import picker from './tiny/toolbar/picker';+import { useEditorTags } from './useEditorTags';const EditorHeader = () => {const [state] = useTracked();@@ -66,6 +63,7 @@ const EditorHeader = () => {const handleBack = useRef();const keyboardListener = useRef();const closing = useRef(false);+ const editorTags = useEditorTags();useEffect(() => {setColors(colors);@@ -75,7 +73,7 @@ const EditorHeader = () => {editing.lastClosedTime = Date.now();if (deviceMode === 'mobile') {startClosingSession();- };+ }setTimeout(async () => {closing.current = true;if (deviceMode !== 'mobile' && fullscreen) {@@ -275,12 +273,7 @@ const EditorHeader = () => {<><Viewstyle={{- flexDirection: 'row',width: '100%',- height: 50,- justifyContent: 'space-between',- alignItems: 'center',- paddingHorizontal: 12,position: 'relative',backgroundColor: colors.bg,right: 0,@@ -290,110 +283,120 @@ const EditorHeader = () => {<Viewstyle={{flexDirection: 'row',+ paddingHorizontal: 12,+ width: '100%',+ height: 50,+ justifyContent: 'space-between',alignItems: 'center'}}>- {deviceMode !== 'mobile' && !fullscreen ? null : (- <ActionIcon- onLongPress={async () => {- await _onBackPress();- Navigation.popToTop();- }}- top={50}- left={50}- testID={notesnook.editor.back}- name="arrow-left"- color={colors.pri}- onPress={_onBackPress}- bottom={5}- customStyle={{- marginLeft: -5- }}- />- )}- {fullscreen ? <View style={{width: 20}} /> : null}- {deviceMode !== 'mobile' ? <EditorTitle /> : null}- </View>- <View- style={{- flexDirection: 'row'- }}>- <>- {!user ||- user?.subscription.type === SUBSCRIPTION_STATUS.BASIC ||- user?.subscription.type === SUBSCRIPTION_STATUS.TRIAL ? (+ <View+ style={{+ flexDirection: 'row',+ alignItems: 'center'+ }}>+ {deviceMode !== 'mobile' && !fullscreen ? null : (<ActionIcon- name="crown"- color={colors.yellow}- customStyle={{- marginLeft: 10+ onLongPress={async () => {+ await _onBackPress();+ Navigation.popToTop();}}top={50}- onPress={async () => {- if (editing.isFocused) {- safeKeyboardDismiss();- editing.isFocused = true;- }- eSendEvent(eOpenPremiumDialog);- }}- />- ) : null}- {currentlyEditingNote && (- <ActionIcon- name="cloud-upload-outline"+ left={50}+ testID={notesnook.editor.back}+ name="arrow-left"color={colors.pri}+ onPress={_onBackPress}+ bottom={5}customStyle={{- marginLeft: 10+ marginLeft: -5}}- top={50}- onPress={publishNote}/>)}+ {fullscreen ? <View style={{width: 20}} /> : null}+ {deviceMode !== 'mobile' ? <EditorTitle /> : null}+ </View>+ <View+ style={{+ flexDirection: 'row'+ }}>+ <>+ {!user ||+ user?.subscription.type === SUBSCRIPTION_STATUS.BASIC ||+ user?.subscription.type === SUBSCRIPTION_STATUS.TRIAL ? (+ <ActionIcon+ name="crown"+ color={colors.yellow}+ customStyle={{+ marginLeft: 10+ }}+ top={50}+ onPress={async () => {+ if (editing.isFocused) {+ safeKeyboardDismiss();+ editing.isFocused = true;+ }+ eSendEvent(eOpenPremiumDialog);+ }}+ />+ ) : null}+ {currentlyEditingNote && (+ <ActionIcon+ name="cloud-upload-outline"+ color={colors.pri}+ customStyle={{+ marginLeft: 10+ }}+ top={50}+ onPress={publishNote}+ />+ )}- {currentlyEditingNote && (- <ActionIcon- name="attachment"- color={colors.pri}- customStyle={{- marginLeft: 10- }}- top={50}- onPress={picker.pick}- />- )}+ {currentlyEditingNote && (+ <ActionIcon+ name="attachment"+ color={colors.pri}+ customStyle={{+ marginLeft: 10+ }}+ top={50}+ onPress={picker.pick}+ />+ )}++ {deviceMode !== 'mobile' && !fullscreen ? (+ <ActionIcon+ name="fullscreen"+ color={colors.pri}+ customStyle={{+ marginLeft: 10+ }}+ top={50}+ onPress={() => {+ eSendEvent(eOpenFullscreenEditor);+ editing.isFullscreen = true;+ }}+ />+ ) : null}- {deviceMode !== 'mobile' && !fullscreen ? (<ActionIcon- name="fullscreen"+ name="dots-horizontal"color={colors.pri}customStyle={{marginLeft: 10}}top={50}- onPress={() => {- eSendEvent(eOpenFullscreenEditor);- editing.isFullscreen = true;- }}+ right={50}+ onPress={showActionsheet}/>- ) : null}- <HistoryComponent />-- <ActionIcon- name="dots-horizontal"- color={colors.pri}- customStyle={{- marginLeft: 10- }}- top={50}- right={50}- onPress={showActionsheet}- />- <ProgressCircle />- </>+ <ProgressCircle />+ </>+ </View></View></View></>);};+export default EditorHeader;diff --git a/apps/mobile/src/views/Editor/useEditorTags.js b/apps/mobile/src/views/Editor/useEditorTags.jsnew file mode 100644index 000000000..65d3b25c9--- /dev/null+++ b/apps/mobile/src/views/Editor/useEditorTags.js@@ -0,0 +1,72 @@+import {useEffect, useState} from 'react';+import {useEditorStore, useTagStore} from '../../provider/stores';+import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager';+import {db} from '../../utils/database';+import {EditorWebView} from './Functions';+import tiny from './tiny/tiny';++export const useEditorTags = () => {+ const currentEditingNote = useEditorStore(state => state.currentEditingNote);+ const tags = useTagStore(state => state.tags);+ const [note, setNote] = useState(null);+ const [noteTags, setNoteTags] = useState([]);++ async function refreshNote() {+ let current = useEditorStore.getState().currentEditingNote;+ if (!current) {+ setNote(null);+ setNoteTags([]);+ return;+ }+ let note = db.notes.note(current)?.data;+ setNote(note ? {...note} : null);+ getTags(note);+ }++ useEffect(() => {+ refreshNote();+ }, [currentEditingNote, tags]);++ async function load(data) {+ if (!data) {+ if (!note) return;++ tiny.call(EditorWebView, renderTags(noteTags));+ }+ }++ useEffect(() => {+ eSubscribeEvent('updateTags', load);+ return () => {+ eUnSubscribeEvent('updateTags', load);+ };+ }, [noteTags]);++ function getTags(note) {+ if (!note || !note.tags) return [];+ let tags = note.tags+ .map(t => (db.tags.tag(t) ? {...db.tags.tag(t)} : null))+ .filter(t => t !== null);+ setNoteTags(tags);+ }++ useEffect(() => {+ tiny.call(EditorWebView, renderTags(noteTags));+ }, [noteTags]);++ const hideTagBar = `+ toggleNode(".tag-bar-parent","hide");+ clearNode(".tag-bar")`;+ const showTagBar = `+ toggleNode(".tag-bar-parent","show");+ clearNode(".tag-bar")`;+ const clearNode = `clearNode(".tag-bar")`;+ const renderTags = tags => `(function() {+ clearNode(".tag-bar");+ toggleNode(".tag-bar-parent","show")+ let items = ${JSON.stringify(tags)};+ renderChildernInNode(items, ".tag-bar", "div", ["tag"]);+ })();`;++ return [];+};