Skip to content

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

add support for settings

ammarahm-ede497bbf98ff9
diff --git a/apps/mobile/android/app/src/main/assets/constants.js b/apps/mobile/android/app/src/main/assets/constants.js
index ded77646c..d425e5261 100755
--- a/apps/mobile/android/app/src/main/assets/constants.js
+++ b/apps/mobile/android/app/src/main/assets/constants.js
@@ -119,7 +119,7 @@ function setTheme() {
} else {
light();
}
-
+ addStyle();
let css = document.createElement('style');
css.type = 'text/css';
diff --git a/apps/mobile/android/app/src/main/assets/init.js b/apps/mobile/android/app/src/main/assets/init.js
index 8c8c7d84c..4b2410113 100755
--- a/apps/mobile/android/app/src/main/assets/init.js
+++ b/apps/mobile/android/app/src/main/assets/init.js
@@ -1,4 +1,3 @@
-
attachTitleInputListeners();
autosize();
function reactNativeEventHandler(type, value) {
@@ -6,28 +5,74 @@ function reactNativeEventHandler(type, value) {
window.ReactNativeWebView.postMessage(
JSON.stringify({
type: type,
- value: value
+ value: value,
})
);
}
}
+let DEFAULT_FONT_SIZE = '12pt';
+let EDITOR_SETTINGS = {
+ fontSize:12,
+ directionality:'ltr'
+}
+
+function loadSettings() {
+ let settings = localStorage.getItem('editorSettings');
+ if (settings) {
+ settings = JSON.parse(settings);
+ EDITOR_SETTINGS = settings;
+ }
+}
+
+function changeDirection(rtl) {
+ loadSettings();
+ EDITOR_SETTINGS.directionality = rtl? 'rtl' : "ltr";
+ localStorage.setItem('editorSettings', JSON.stringify(EDITOR_SETTINGS));
+ if (rtl) {
+ tinymce.activeEditor.execCommand('mceDirectionRTL');
+ } else {
+ tinymce.activeEditor.execCommand('mceDirectionLTR');
+ }
+ reactNativeEventHandler('editorSettings', EDITOR_SETTINGS);
+}
+
+function changeFontSize(size) {
+ loadSettings();
+ DEFAULT_FONT_SIZE = `${size}pt`;
+ EDITOR_SETTINGS.fontSize = size;
+ localStorage.setItem('editorSettings', JSON.stringify(EDITOR_SETTINGS));
+ addStyle();
+ reactNativeEventHandler('editorSettings', EDITOR_SETTINGS);
+}
+
+function loadFontSize() {
+ loadSettings();
+ DEFAULT_FONT_SIZE = EDITOR_SETTINGS.fontSize + 'pt';
+ reactNativeEventHandler('editorSettings', EDITOR_SETTINGS);
+}
+
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');
+ styleElement.innerHTML = `
+ body {
+ font-size:${DEFAULT_FONT_SIZE} !important;
+ }
+ .mce-content-body .c::before{
+ background-color:${pageTheme.colors.accent};
+ border-radius:3px;
+ color:white;
+ }
+ `;
}
function toggleElementVisibility(element, toggleState) {
@@ -64,10 +109,12 @@ function collapseElement(target) {
}
function init_tiny(size) {
+ loadFontSize();
tinymce.init({
selector: '#tiny_textarea',
menubar: false,
min_height: size,
+ directionality:EDITOR_SETTINGS.directionality,
skin_url: 'dist/skins/notesnook',
content_css: 'dist/skins/notesnook',
plugins: [
@@ -156,6 +203,7 @@ function init_tiny(size) {
}
body {
background-color:transparent !important;
+ font-size:${DEFAULT_FONT_SIZE}
}
iframe {
max-width:100% !important;
@@ -177,8 +225,7 @@ function init_tiny(size) {
autoresize_bottom_margin: 120,
table_toolbar:
'tablecellprops | tableinsertrowbefore tableinsertrowafter tabledeleterow | tableinsertcolbefore tableinsertcolafter tabledeletecol',
- imagetools_toolbar:
- 'rotateleft rotateright flipv fliph | imageopts ',
+ imagetools_toolbar: 'rotateleft rotateright flipv fliph | imageopts ',
placeholder: 'Start writing your note here',
object_resizing: true,
resize: true,
@@ -199,22 +246,25 @@ function init_tiny(size) {
icon: 'remove',
tooltip: 'Remove image',
onAction: function () {
- editor.undoManager.transact(function() {tinymce.activeEditor.execCommand('Delete');});
+ editor.undoManager.transact(function () {
+ tinymce.activeEditor.execCommand('Delete');
+ });
},
onclick: function () {
- editor.undoManager.transact(function() {tinymce.activeEditor.execCommand('Delete');});
-
- }
+ editor.undoManager.transact(function () {
+ tinymce.activeEditor.execCommand('Delete');
+ });
+ },
});
editor.ui.registry.addButton('imageopts', {
icon: 'image-options',
tooltip: 'Image properties',
onAction: function () {
- reactNativeEventHandler("imageoptions");
+ reactNativeEventHandler('imageoptions');
},
onclick: function () {
- reactNativeEventHandler("imageoptions");
- }
+ reactNativeEventHandler('imageoptions');
+ },
});
editor.ui.registry.addButton('imagepreview', {
@@ -243,7 +293,7 @@ function init_tiny(size) {
xhr.send();
}
},
- onclick: function () {}
+ onclick: function () {},
});
},
init_instance_callback: function (edit) {
@@ -273,76 +323,72 @@ 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('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('touchstart 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('touchstart 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();
e.elm.scrollIntoView({
behavior: 'smooth',
- block: 'nearest'
+ block: 'nearest',
});
});
editor.on('input', onChange);
editor.on('keyup', onChange);
editor.on('NodeChange', onChange);
- }
+ },
});
}
window.prevContent = '';
const onChange = function (event) {
- if (event.type === 'nodechange' && !event.selectionChange) return;
- if (isLoading) {
- isLoading = false;
- return;
- }
- if (editor.plugins.wordcount.getCount() === 0) return;
- clearTimeout(changeTimer);
- changeTimer = null;
- changeTimer = setTimeout(function () {
- selectchange();
- reactNativeEventHandler('tiny', editor.getContent());
- reactNativeEventHandler('history', {
- undo: editor.undoManager.hasUndo(),
- redo: editor.undoManager.hasRedo()
- });
+ if (event.type === 'nodechange' && !event.selectionChange) return;
+ if (isLoading) {
+ isLoading = false;
+ return;
+ }
+ if (editor.plugins.wordcount.getCount() === 0) return;
+ clearTimeout(changeTimer);
+ changeTimer = null;
+ changeTimer = setTimeout(function () {
+ selectchange();
+ reactNativeEventHandler('tiny', editor.getContent());
+ reactNativeEventHandler('history', {
+ undo: editor.undoManager.hasUndo(),
+ redo: editor.undoManager.hasRedo()
+ });
}, 1);
};
@@ -386,13 +432,13 @@ function selectchange() {
currentFormats.current = {
index: range.startOffset,
- length: range.endOffset - range.startOffset
+ length: range.endOffset - range.startOffset,
};
currentFormats.fontsize = editor.selection.getNode().style.fontSize;
if (currentFormats.fontsize === '') {
- currentFormats.fontsize = '12pt';
+ currentFormats.fontsize = DEFAULT_FONT_SIZE;
if (currentFormats.h2) {
currentFormats.fontsize = '18pt';
diff --git a/apps/mobile/html/Web.bundle/site/constants.js b/apps/mobile/html/Web.bundle/site/constants.js
index ded77646c..d425e5261 100755
--- a/apps/mobile/html/Web.bundle/site/constants.js
+++ b/apps/mobile/html/Web.bundle/site/constants.js
@@ -119,7 +119,7 @@ function setTheme() {
} else {
light();
}
-
+ addStyle();
let css = document.createElement('style');
css.type = 'text/css';
diff --git a/apps/mobile/html/Web.bundle/site/init.js b/apps/mobile/html/Web.bundle/site/init.js
index 8c8c7d84c..4b2410113 100755
--- a/apps/mobile/html/Web.bundle/site/init.js
+++ b/apps/mobile/html/Web.bundle/site/init.js
@@ -1,4 +1,3 @@
-
attachTitleInputListeners();
autosize();
function reactNativeEventHandler(type, value) {
@@ -6,28 +5,74 @@ function reactNativeEventHandler(type, value) {
window.ReactNativeWebView.postMessage(
JSON.stringify({
type: type,
- value: value
+ value: value,
})
);
}
}
+let DEFAULT_FONT_SIZE = '12pt';
+let EDITOR_SETTINGS = {
+ fontSize:12,
+ directionality:'ltr'
+}
+
+function loadSettings() {
+ let settings = localStorage.getItem('editorSettings');
+ if (settings) {
+ settings = JSON.parse(settings);
+ EDITOR_SETTINGS = settings;
+ }
+}
+
+function changeDirection(rtl) {
+ loadSettings();
+ EDITOR_SETTINGS.directionality = rtl? 'rtl' : "ltr";
+ localStorage.setItem('editorSettings', JSON.stringify(EDITOR_SETTINGS));
+ if (rtl) {
+ tinymce.activeEditor.execCommand('mceDirectionRTL');
+ } else {
+ tinymce.activeEditor.execCommand('mceDirectionLTR');
+ }
+ reactNativeEventHandler('editorSettings', EDITOR_SETTINGS);
+}
+
+function changeFontSize(size) {
+ loadSettings();
+ DEFAULT_FONT_SIZE = `${size}pt`;
+ EDITOR_SETTINGS.fontSize = size;
+ localStorage.setItem('editorSettings', JSON.stringify(EDITOR_SETTINGS));
+ addStyle();
+ reactNativeEventHandler('editorSettings', EDITOR_SETTINGS);
+}
+
+function loadFontSize() {
+ loadSettings();
+ DEFAULT_FONT_SIZE = EDITOR_SETTINGS.fontSize + 'pt';
+ reactNativeEventHandler('editorSettings', EDITOR_SETTINGS);
+}
+
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');
+ styleElement.innerHTML = `
+ body {
+ font-size:${DEFAULT_FONT_SIZE} !important;
+ }
+ .mce-content-body .c::before{
+ background-color:${pageTheme.colors.accent};
+ border-radius:3px;
+ color:white;
+ }
+ `;
}
function toggleElementVisibility(element, toggleState) {
@@ -64,10 +109,12 @@ function collapseElement(target) {
}
function init_tiny(size) {
+ loadFontSize();
tinymce.init({
selector: '#tiny_textarea',
menubar: false,
min_height: size,
+ directionality:EDITOR_SETTINGS.directionality,
skin_url: 'dist/skins/notesnook',
content_css: 'dist/skins/notesnook',
plugins: [
@@ -156,6 +203,7 @@ function init_tiny(size) {
}
body {
background-color:transparent !important;
+ font-size:${DEFAULT_FONT_SIZE}
}
iframe {
max-width:100% !important;
@@ -177,8 +225,7 @@ function init_tiny(size) {
autoresize_bottom_margin: 120,
table_toolbar:
'tablecellprops | tableinsertrowbefore tableinsertrowafter tabledeleterow | tableinsertcolbefore tableinsertcolafter tabledeletecol',
- imagetools_toolbar:
- 'rotateleft rotateright flipv fliph | imageopts ',
+ imagetools_toolbar: 'rotateleft rotateright flipv fliph | imageopts ',
placeholder: 'Start writing your note here',
object_resizing: true,
resize: true,
@@ -199,22 +246,25 @@ function init_tiny(size) {
icon: 'remove',
tooltip: 'Remove image',
onAction: function () {
- editor.undoManager.transact(function() {tinymce.activeEditor.execCommand('Delete');});
+ editor.undoManager.transact(function () {
+ tinymce.activeEditor.execCommand('Delete');
+ });
},
onclick: function () {
- editor.undoManager.transact(function() {tinymce.activeEditor.execCommand('Delete');});
-
- }
+ editor.undoManager.transact(function () {
+ tinymce.activeEditor.execCommand('Delete');
+ });
+ },
});
editor.ui.registry.addButton('imageopts', {
icon: 'image-options',
tooltip: 'Image properties',
onAction: function () {
- reactNativeEventHandler("imageoptions");
+ reactNativeEventHandler('imageoptions');
},
onclick: function () {
- reactNativeEventHandler("imageoptions");
- }
+ reactNativeEventHandler('imageoptions');
+ },
});
editor.ui.registry.addButton('imagepreview', {
@@ -243,7 +293,7 @@ function init_tiny(size) {
xhr.send();
}
},
- onclick: function () {}
+ onclick: function () {},
});
},
init_instance_callback: function (edit) {
@@ -273,76 +323,72 @@ 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('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('touchstart 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('touchstart 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();
e.elm.scrollIntoView({
behavior: 'smooth',
- block: 'nearest'
+ block: 'nearest',
});
});
editor.on('input', onChange);
editor.on('keyup', onChange);
editor.on('NodeChange', onChange);
- }
+ },
});
}
window.prevContent = '';
const onChange = function (event) {
- if (event.type === 'nodechange' && !event.selectionChange) return;
- if (isLoading) {
- isLoading = false;
- return;
- }
- if (editor.plugins.wordcount.getCount() === 0) return;
- clearTimeout(changeTimer);
- changeTimer = null;
- changeTimer = setTimeout(function () {
- selectchange();
- reactNativeEventHandler('tiny', editor.getContent());
- reactNativeEventHandler('history', {
- undo: editor.undoManager.hasUndo(),
- redo: editor.undoManager.hasRedo()
- });
+ if (event.type === 'nodechange' && !event.selectionChange) return;
+ if (isLoading) {
+ isLoading = false;
+ return;
+ }
+ if (editor.plugins.wordcount.getCount() === 0) return;
+ clearTimeout(changeTimer);
+ changeTimer = null;
+ changeTimer = setTimeout(function () {
+ selectchange();
+ reactNativeEventHandler('tiny', editor.getContent());
+ reactNativeEventHandler('history', {
+ undo: editor.undoManager.hasUndo(),
+ redo: editor.undoManager.hasRedo()
+ });
}, 1);
};
@@ -386,13 +432,13 @@ function selectchange() {
currentFormats.current = {
index: range.startOffset,
- length: range.endOffset - range.startOffset
+ length: range.endOffset - range.startOffset,
};
currentFormats.fontsize = editor.selection.getNode().style.fontSize;
if (currentFormats.fontsize === '') {
- currentFormats.fontsize = '12pt';
+ currentFormats.fontsize = DEFAULT_FONT_SIZE;
if (currentFormats.h2) {
currentFormats.fontsize = '18pt';
diff --git a/apps/mobile/src/views/Editor/EditorHeader.js b/apps/mobile/src/views/Editor/EditorHeader.js
index af356b74b..a5734cede 100644
--- a/apps/mobile/src/views/Editor/EditorHeader.js
+++ b/apps/mobile/src/views/Editor/EditorHeader.js
@@ -54,7 +54,7 @@ const EditorHeader = () => {
eSendEvent(eCloseFullscreenEditor);
return;
}
- tiny.call(EditorWebView,tiny.blur);
+ tiny.call(EditorWebView, tiny.blur);
setTimeout(async () => {
eSendEvent('showTooltip');
toolbarRef.current?.scrollTo({
@@ -82,7 +82,7 @@ const EditorHeader = () => {
ToastEvent.show({
heading: 'Note Saved',
type: 'success',
- duration:1500
+ duration: 1500,
});
}
await clearEditor();
@@ -139,13 +139,18 @@ const EditorHeader = () => {
await sleep(500);
editing.isFocused = true;
}
- ActionSheetEvent(
- note,
- true,
- true,
- ['Add to', 'Share', 'Export', 'Delete', 'Copy'],
- ['Dark Mode', 'Add to Vault', 'Pin', 'Favorite'],
- );
+ ActionSheetEvent(note, true, true, [
+ 'Add to notebook',
+ 'Share',
+ 'Export',
+ 'Delete',
+ 'Copy',
+ 'Dark Mode',
+ 'Add to Vault',
+ 'Pin',
+ 'Favorite',
+ 'Publish',
+ ]);
};
return (
diff --git a/apps/mobile/src/views/Editor/EditorSettings.js b/apps/mobile/src/views/Editor/EditorSettings.js
index 9b7c1b24d..0ffe2b970 100644
--- a/apps/mobile/src/views/Editor/EditorSettings.js
+++ b/apps/mobile/src/views/Editor/EditorSettings.js
@@ -1,28 +1,32 @@
-import React, { useEffect, useRef, useState } from 'react';
-import { View } from 'react-native';
+import React, {createRef, useEffect, useRef, useState} from 'react';
+import {View} from 'react-native';
+import Menu, {MenuItem} from 'react-native-reanimated-material-menu';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import ActionSheetWrapper from '../../components/ActionSheetComponent/ActionSheetWrapper';
+import {Button} from '../../components/Button';
import BaseDialog from '../../components/Dialog/base-dialog';
import DialogButtons from '../../components/Dialog/dialog-buttons';
import DialogContainer from '../../components/Dialog/dialog-container';
import DialogHeader from '../../components/Dialog/dialog-header';
import Input from '../../components/Input';
-import { PressableButton } from '../../components/PressableButton';
+import {PressableButton} from '../../components/PressableButton';
import Seperator from '../../components/Seperator';
import Paragraph from '../../components/Typography/Paragraph';
-import { useTracked } from '../../provider';
-import { useSettingStore } from '../../provider/stores';
-import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/EventManager';
-import SettingsService from '../../services/SettingsService';
-import { SIZE } from '../../utils/SizeUtils';
-import { sleep } from '../../utils/TimeUtils';
+import {useTracked} from '../../provider';
+import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager';
+import {SIZE} from '../../utils/SizeUtils';
+import {sleep} from '../../utils/TimeUtils';
+import {EditorWebView} from './Functions';
+import tiny from './tiny/tiny';
+import ToggleSwitch from 'toggle-switch-react-native';
export const EditorSettings = () => {
const [state, dispatch] = useTracked();
const {colors} = state;
-
- const settings = useSettingStore(state => state.settings);
-
+ const [settings, setSettings] = useState({
+ fontSize: 10,
+ directionality: 'ltr',
+ });
const [visible, setVisible] = useState(false);
const [savePreset, setSavePreset] = useState(false);
const actionSheetRef = useRef();
@@ -37,69 +41,121 @@ export const EditorSettings = () => {
setVisible(false);
};
+ const onSettingsRecieved = settings => {
+ setSettings(settings);
+ };
+
useEffect(() => {
+ eSubscribeEvent('editorSettingsEvent', onSettingsRecieved);
eSubscribeEvent('openEditorSettings', open);
eSubscribeEvent('closeEditorSettings', close);
return () => {
+ eUnSubscribeEvent('editorSettingsEvent', onSettingsRecieved);
eUnSubscribeEvent('openEditorSettings', open);
eUnSubscribeEvent('closeEditorSettings', close);
};
}, []);
- let presets = [
- {
- name: 'Poems',
- size: '12pt',
- fontname: {name: 'Times New Roman', value: 'times new roman'},
- line_break: 'paragraph',
- direction: 'ltr',
- forecolor: '#ff0000',
- hilitecolor: '#00ff00',
- },
- ];
-
- const SettingsButton = ({title, description, enabled, id}) => (
+ const SettingsButton = ({
+ title,
+ description,
+ enabled,
+ type,
+ items,
+ dropdownItemPress,
+ dropDownTitle,
+ style,
+ stub,
+ onPress,
+ }) => (
<PressableButton
- onPress={() => {
- let editorSettings = settings.editorSettings;
- if (!editorSettings) {
- editorSettings = {};
- }
- editorSettings[id] = !enabled;
- SettingsService.set('editorSettings', {...editorSettings});
- }}
+ onPress={onPress}
customStyle={{
flexDirection: 'row',
width: '100%',
- height: 40,
+ height: 50,
alignItems: 'center',
justifyContent: 'space-between',
+ borderRadius: 0,
+ paddingHorizontal: 12,
}}>
<View
style={{
- width: '90%',
+ flexGrow: 1,
}}>
<Paragraph size={SIZE.md}>{title}</Paragraph>
- <Paragraph color={colors.icon} size={SIZE.sm}>
- {description}
- </Paragraph>
+ {description && (
+ <Paragraph color={colors.icon} size={SIZE.sm}>
+ {description}
+ </Paragraph>
+ )}
</View>
- <Icon
- color={enabled ? colors.accent : colors.icon}
- size={SIZE.lg}
- name={
- !enabled ? 'checkbox-blank-circle-outline' : 'check-circle-outline'
- }
- />
+ {type === 'dropdown' ? (
+ <DropDownMenu
+ onPress={dropdownItemPress}
+ style={style}
+ stub={stub}
+ title={dropDownTitle}
+ items={items}
+ />
+ ) : (
+ <ToggleSwitch
+ isOn={enabled}
+ onColor={colors.accent}
+ offColor={colors.icon}
+ size="small"
+ animationSpeed={150}
+ onToggle={onPress}
+ />
+ )}
</PressableButton>
);
let settingsItems = [
{
- title: 'Disable gestures',
- description:
- 'Disable swipe left to exit editor & swipe down with two fingers to start new note.',
- id: 'disableGestures',
+ title: 'Font size',
+ id: 'fontSize',
+ type: 'dropdown',
+ items: [10, 12, 14, 16, 18],
+ stub: 'pt',
+ dropDownTitle: settings.fontSize + 'pt',
+ style: {
+ width: 70,
+ },
+ dropdownItemPress: item => {
+ tiny.call(
+ EditorWebView,
+ `
+ changeFontSize(${item})
+ `,
+ );
+ },
+ },
+ {
+ title: 'RTL Direction',
+ id: 'rtlDirection',
+ type: 'boolean',
+ enabled: settings.directionality === 'rtl',
+ onPress: () => {
+ tiny.call(
+ EditorWebView,
+ `
+ changeDirection(${settings.directionality === 'rtl' ? false : true})
+ `,
+ );
+ },
+ },
+ ];
+
+ let presets = [
+ {
+ name: 'Poems',
+ size: '12pt',
+ fontname: {name: 'Times New Roman', value: 'times new roman'},
+ line_break: 'paragraph',
+ direction: 'ltr',
+ forecolor: '#ff0000',
+ hilitecolor: '#00ff00',
},
];
@@ -110,10 +166,7 @@ export const EditorSettings = () => {
onClose={() => {
setVisible(false);
}}>
- <View
- style={{
- paddingHorizontal: 12,
- }}>
+ <View>
{savePreset && (
<BaseDialog
onRequestClose={() => {
@@ -135,29 +188,81 @@ export const EditorSettings = () => {
</BaseDialog>
)}
- <DialogHeader
- title="Editor settings"
- paragraph="Modify editor settings based on personal preference."
- button={{
- title: 'Save as Preset',
- onPress: () => {
- setSavePreset(true);
- },
- }}
- />
+ <View
+ style={{
+ paddingHorizontal: 12,
+ }}>
+ <DialogHeader
+ title="Editor settings"
+ paragraph="Modify editor settings based on personal preference."
+ /* button={{
+ title: 'Save as Preset',
+ onPress: () => {
+ setSavePreset(true);
+ },
+ }} */
+ />
+ </View>
+
<Seperator />
{settingsItems.map(item => (
- <SettingsButton
- title={item.title}
- description={item.description}
- enabled={
- settings?.editorSettings && settings?.editorSettings[item.id]
- }
- id={item.id}
- />
+ <SettingsButton {...item} />
))}
</View>
</ActionSheetWrapper>
)
);
};
+
+const DropDownMenu = ({items, onPress, style, title, stub}) => {
+ const [state, dispatch] = useTracked();
+ const {colors} = state;
+ const menuRef = useRef();
+
+ return (
+ <Menu
+ ref={menuRef}
+ animationDuration={200}
+ style={[
+ {
+ borderRadius: 5,
+ },
+ style,
+ ]}
+ button={
+ <Button
+ title={title}
+ iconPosition="right"
+ icon="chevron-down"
+ iconSize={SIZE.lg}
+ style={{
+ paddingRight: 0,
+ }}
+ onPress={() => {
+ menuRef.current?.show();
+ }}
+ textStyle={{
+ fontWeight: 'normal',
+ }}
+ width={null}
+ fontSize={SIZE.sm}
+ />
+ }>
+ {items.map((item, index) => (
+ <MenuItem
+ key={item.toString()}
+ onPress={() => {
+ onPress(item);
+ menuRef.current?.hide();
+ }}
+ textStyle={{
+ fontSize: SIZE.md,
+ color: colors.pri,
+ }}>
+ <Icon name={item.icon} size={SIZE.md} />
+ {item + stub}
+ </MenuItem>
+ ))}
+ </Menu>
+ );
+};
diff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.js
index d40c13c93..861f61bbb 100644
--- a/apps/mobile/src/views/Editor/Functions.js
+++ b/apps/mobile/src/views/Editor/Functions.js
@@ -27,6 +27,7 @@ export const editorTitleInput = createRef();
export const sourceUri =
Platform.OS === 'android' ? 'file:///android_asset/' : 'Web.bundle/site/';
+let EDITOR_SETTINGS = null;
let webviewOK = true;
let noteEdited = false;
let note = null;
@@ -176,15 +177,25 @@ export const loadNote = async item => {
await clearEditor();
}
clearNote();
+
noteEdited = false;
id = null;
if (Platform.OS === 'android') {
+ await sleep(100);
textInput.current?.focus();
EditorWebView.current?.requestFocus();
tiny.call(EditorWebView, tiny.focusEditor);
} else {
tiny.call(EditorWebView, tiny.focusEditor);
}
+ if (EDITOR_SETTINGS) {
+ tiny.call(
+ EditorWebView,
+ EDITOR_SETTINGS.directionality === 'rtl'
+ ? `tinymce.activeEditor.execCommand('mceDirectionRTL');`
+ : `tinymce.activeEditor.execCommand('mceDirectionLTR');`,
+ );
+ }
if (!webviewInit) {
EditorWebView.current?.reload();
}
@@ -300,6 +311,10 @@ export const _onMessage = async evt => {
case 'running':
webviewOK = true;
break;
+ case 'editorSettings':
+ EDITOR_SETTINGS = message.value;
+ eSendEvent('editorSettingsEvent', message.value);
+ break;
case 'imagepreview':
eSendEvent('ImagePreview', message.value);
break;
diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/config.js b/apps/mobile/src/views/Editor/tiny/toolbar/config.js
index f36380c45..631da913f 100644
--- a/apps/mobile/src/views/Editor/tiny/toolbar/config.js
+++ b/apps/mobile/src/views/Editor/tiny/toolbar/config.js
@@ -359,10 +359,10 @@ export const TOOLBAR_CONFIG = [
type: 'format',
fullname: 'Search & Replace',
},
- /* {
+ {
format: 'settings',
type: 'settings',
fullname: 'Editor Settings',
- }, */
+ },
],
];