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 default color to highlight/change text color
ammarahm-ed26310a381b3b
diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/coloritem.js b/apps/mobile/src/views/Editor/tiny/toolbar/coloritem.jsindex bd599bed2..cb71fbc10 100644--- a/apps/mobile/src/views/Editor/tiny/toolbar/coloritem.js+++ b/apps/mobile/src/views/Editor/tiny/toolbar/coloritem.js@@ -1,86 +1,93 @@-import React, { useEffect, useState } from 'react';-import { View,TouchableOpacity } from 'react-native';+import React, {useEffect, useState} from 'react';+import {View, TouchableOpacity} from 'react-native';import Icon from 'react-native-vector-icons/MaterialCommunityIcons';-import { useTracked } from '../../../../provider';-import { eSubscribeEvent, eUnSubscribeEvent } from '../../../../services/EventManager';-import { normalize, SIZE } from '../../../../utils/SizeUtils';-import { formatSelection, properties, rgbToHex } from './constants';-import { execCommands } from './commands';+import {useTracked} from '../../../../provider';+import {+ eSendEvent,+ eSubscribeEvent,+ eUnSubscribeEvent+} from '../../../../services/EventManager';+import {normalize, SIZE} from '../../../../utils/SizeUtils';+import {formatSelection, properties, rgbToHex} from './constants';+import {execCommands} from './commands';+import {MMKV} from '../../../../utils/mmkv';const ColorItem = ({value, format}) => {- const [state] = useTracked();- const {colors} = state;- const [selected, setSelected] = useState(false);-- useEffect(() => {- eSubscribeEvent('onSelectionChange', onSelectionChange);- return () => {- eUnSubscribeEvent('onSelectionChange', onSelectionChange);- };- }, [selected]);-- useEffect(() => {- onSelectionChange(properties.selection);- }, []);-- const onSelectionChange = (data) => {- if (properties.pauseSelectionChange) return;- checkForChanges(data);- };-- const checkForChanges = (data) => {- properties.selection = data;- let formats = Object.keys(data);- let _color;- if (data[format] !== null) {+ const [state] = useTracked();+ const {colors} = state;+ const [selected, setSelected] = useState(false);- if (data[format]?.startsWith('#')) {- _color = data[format];- } else {- _color = rgbToHex(data[format]);- }- }- if (formats.indexOf(format) > -1 && _color === value) {- setSelected(true);- return;- }- setSelected(false);- };-- const onPress = () => {- if (selected) {- formatSelection(format, null);- } else {- formatSelection(execCommands[format](value));- }- };-- return (- <TouchableOpacity- onPress={onPress}- activeOpacity={0.8}- style={{- backgroundColor: value,- borderWidth: 1,- borderColor: colors.nav,- borderRadius: 5,- height: normalize(40),- width: normalize(40),- marginRight: 5,- }}>- <View- style={{- height: 40,- width: 40,- borderRadius: 5,- justifyContent: 'center',- alignItems: 'center',- backgroundColor: selected ? 'rgba(0,0,0,0.1)' : 'transparent',- }}>- {selected && <Icon name="check" size={SIZE.lg} color="white" />}- </View>- </TouchableOpacity>- );+ useEffect(() => {+ eSubscribeEvent('onSelectionChange', onSelectionChange);+ return () => {+ eUnSubscribeEvent('onSelectionChange', onSelectionChange);+ };+ }, [selected]);++ useEffect(() => {+ onSelectionChange(properties.selection);+ }, []);++ const onSelectionChange = data => {+ if (properties.pauseSelectionChange) return;+ checkForChanges(data);+ };++ const checkForChanges = data => {+ properties.selection = data;+ let formats = Object.keys(data);+ let _color;+ if (data[format] !== null) {+ if (data[format]?.startsWith('#')) {+ _color = data[format];+ } else {+ _color = rgbToHex(data[format]);+ }+ }+ if (formats.indexOf(format) > -1 && _color === value) {+ setSelected(true);+ return;+ }+ setSelected(false);};- export default ColorItem;\ No newline at end of file+ const onPress = async () => {+ if (selected) {+ formatSelection(format, null);+ await MMKV.removeItem(`d${format}`);+ } else {+ formatSelection(execCommands[format](value));+ await MMKV.setItem(`d${format}`, value);+ }+ eSendEvent('onColorChange');+ };++ return (+ <TouchableOpacity+ onPress={onPress}+ activeOpacity={0.8}+ style={{+ backgroundColor: value,+ borderWidth: 1,+ borderColor: colors.nav,+ borderRadius: 5,+ height: normalize(40),+ width: normalize(40),+ marginRight: 5+ }}>+ <View+ style={{+ height: 40,+ width: 40,+ borderRadius: 5,+ justifyContent: 'center',+ alignItems: 'center',+ backgroundColor: selected ? 'rgba(0,0,0,0.1)' : 'transparent'+ }}>+ {selected && <Icon name="check" size={SIZE.lg} color="white" />}+ </View>+ </TouchableOpacity>+ );+};++export default ColorItem;diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/commands.js b/apps/mobile/src/views/Editor/tiny/toolbar/commands.jsindex e6d182f6f..ebe808fc5 100644--- a/apps/mobile/src/views/Editor/tiny/toolbar/commands.js+++ b/apps/mobile/src/views/Editor/tiny/toolbar/commands.js@@ -25,6 +25,10 @@ export const execCommands = {`tinymce.activeEditor.execCommand('ForeColor',false, '${color}');`,hilitecolor: color =>`tinymce.activeEditor.execCommand('HiliteColor',false, '${color}');`,+ dforecolor: color =>+ `tinymce.activeEditor.execCommand('ForeColor',false, '${color}');`,+ dhilitecolor: color =>+ `tinymce.activeEditor.execCommand('HiliteColor',false, '${color}');`,fontname: fontname =>`tinymce.activeEditor.execCommand('FontName',false, '${fontname}');`,diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/config.js b/apps/mobile/src/views/Editor/tiny/toolbar/config.jsindex 1849998a0..15a5f8fda 100644--- a/apps/mobile/src/views/Editor/tiny/toolbar/config.js+++ b/apps/mobile/src/views/Editor/tiny/toolbar/config.js@@ -188,6 +188,11 @@ export const TOOLBAR_CONFIG = [}],[+ {+ format: 'dhilitecolor',+ type: 'format',+ fullname: 'Default Highlight Color'+ },{format: 'hilitecolor',type: 'tooltip',@@ -201,6 +206,11 @@ export const TOOLBAR_CONFIG = [};})},+ {+ format: 'dforecolor',+ type: 'format',+ fullname: 'Default Text Color'+ },{format: 'forecolor',type: 'tooltip',diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/item.js b/apps/mobile/src/views/Editor/tiny/toolbar/item.jsindex 7d30c7ab4..c7466f9cf 100644--- a/apps/mobile/src/views/Editor/tiny/toolbar/item.js+++ b/apps/mobile/src/views/Editor/tiny/toolbar/item.js@@ -16,6 +16,7 @@ import PremiumService from '../../../../services/PremiumService';import {editing, showTooltip, TOOLTIP_POSITIONS} from '../../../../utils';import {db} from '../../../../utils/DB';import {eShowGetPremium} from '../../../../utils/Events';+import {MMKV} from '../../../../utils/mmkv';import {normalize, SIZE} from '../../../../utils/SizeUtils';import {sleep} from '../../../../utils/TimeUtils';import {EditorWebView} from '../../Functions';@@ -55,6 +56,7 @@ const ToolbarItem = ({const [currentText, setCurrentText] = useState(null);useEffect(() => {+ if (/^(dhilitecolor|dforecolor)$/.test(format)) return;eSubscribeEvent('onSelectionChange', onSelectionChange);return () => {eUnSubscribeEvent('onSelectionChange', onSelectionChange);@@ -62,9 +64,30 @@ const ToolbarItem = ({}, [selected]);useEffect(() => {+ if (/^(dhilitecolor|dforecolor)$/.test(format)) return;onSelectionChange(properties.selection, true);}, []);+ useEffect(() => {+ if (/^(dhilitecolor|dforecolor)$/.test(format)) {+ onColorChange();+ eSubscribeEvent('onColorChange', onColorChange);+ }+ return () => {+ eUnSubscribeEvent('onColorChange', onColorChange);+ };+ }, []);++ const onColorChange = async () => {+ console.log('color change');+ if (/^(dhilitecolor|dforecolor)$/.test(format)) {+ let _color = await MMKV.getItem(format);+ let defColor =+ format === 'dhilitecolor' ? colors.accent + '60' : colors.accent;+ setColor(_color || defColor);+ }+ };+const checkForChanges = data => {properties.selection = data;let formats = Object.keys(data);@@ -272,6 +295,10 @@ const ToolbarItem = ({}}+ if (/^(dhilitecolor|dforecolor)$/.test(format)) {+ value = color;+ }+if (format === 'pre') {if (selected) {formatSelection(tiny.pre);@@ -293,13 +320,10 @@ const ToolbarItem = ({focusEditor(format);editing.tooltip = null;};-return (<View><PressableButton- type={selected ? 'shade' : 'transparent'}- customColor={selected && color}- customSelectedColor={selected && color}+ type={selected && !color ? 'shade' : 'transparent'}customOpacity={0.12}onLongPress={event => {showTooltip(event, fullname, TOOLTIP_POSITIONS.TOP);@@ -307,81 +331,96 @@ const ToolbarItem = ({onPress={e => onPress(e)}customStyle={{borderRadius: 0,- flexDirection: 'column',justifyContent: 'center',alignItems: 'center',height: normalize(50),- minWidth: 60+ minWidth: /^(dhilitecolor|dforecolor)$/.test(format) ? 30 : 60}}>- {type === 'tooltip' && (- <ToolbarItemPin format={format} color={selected && color} />- )}-- {/^(h1|h2|h3|h4|h5|h6|p)$/.test(format) ? (- <Heading- size={SIZE.md + 2}- color={selected ? colors.accent : colors.pri}>- {format.slice(0, 1).toUpperCase() + format.slice(1)}- </Heading>- ) : /^(ol|ul|cl)$/.test(format) ? (- <ToolbarListFormat- format={format}- selected={selected}- formatValue={formatValue || icon || 'default'}- />- ) : format === 'fontsize' ? (- <Paragraph- size={SIZE.md}- color={selected ? colors.accent : colors.pri}>- {formatValue || currentText || '12pt'}- </Paragraph>- ) : text && groupFormat !== 'header' ? (- <Paragraph- color={selected ? colors.accent : colors.pri}+ {/^(dhilitecolor|dforecolor)$/.test(format) ? (+ <Viewstyle={{- paddingHorizontal: 12,- fontFamily:- format === 'fontname' &&- formatValue &&- formatValue !== '-apple-system'- ? formatValue- : format === 'fontname' && icon !== '-apple-system' && icon- ? icon- : null+ backgroundColor: color,+ height: 30,+ width: 30,+ marginLeft: 10,+ borderRadius: 2.5}}- size={text.includes('%') ? SIZE.sm : SIZE.md}>- {currentText || text}- </Paragraph>- ) : (- <Icon- name={- valueIcon- ? TOOLBAR_ICONS[icon || valueIcon]- : TOOLBAR_ICONS[format === '' ? groupDefault : format]- }- size={SIZE.xl}- allowFontScaling={false}- color={selected ? (color ? color : colors.accent) : colors.pri}/>- )}-- {type === 'tooltip' && (- <Icon- name="menu-right"- size={SIZE.sm}- allowFontScaling={false}- color={colors.icon}- style={{- position: 'absolute',- transform: [- {- rotateZ: '-45deg'+ ) : (+ <>+ {type === 'tooltip' && (+ <ToolbarItemPin format={format} color={selected && color} />+ )}++ {/^(h1|h2|h3|h4|h5|h6|p)$/.test(format) ? (+ <Heading+ size={SIZE.md + 2}+ color={selected ? colors.accent : colors.pri}>+ {format.slice(0, 1).toUpperCase() + format.slice(1)}+ </Heading>+ ) : /^(ol|ul|cl)$/.test(format) ? (+ <ToolbarListFormat+ format={format}+ selected={selected}+ formatValue={formatValue || icon || 'default'}+ />+ ) : format === 'fontsize' ? (+ <Paragraph+ size={SIZE.md}+ color={selected ? colors.accent : colors.pri}>+ {formatValue || currentText || '12pt'}+ </Paragraph>+ ) : text && groupFormat !== 'header' ? (+ <Paragraph+ color={selected ? colors.accent : colors.pri}+ style={{+ paddingHorizontal: 12,+ fontFamily:+ format === 'fontname' &&+ formatValue &&+ formatValue !== '-apple-system'+ ? formatValue+ : format === 'fontname' &&+ icon !== '-apple-system' &&+ icon+ ? icon+ : null+ }}+ size={text.includes('%') ? SIZE.sm : SIZE.md}>+ {currentText || text}+ </Paragraph>+ ) : (+ <Icon+ name={+ valueIcon+ ? TOOLBAR_ICONS[icon || valueIcon]+ : TOOLBAR_ICONS[format === '' ? groupDefault : format]}- ],- top: 0,- right: 0- }}- />+ size={SIZE.xl}+ allowFontScaling={false}+ color={selected ? (color ? color : colors.accent) : colors.pri}+ />+ )}++ {type === 'tooltip' && (+ <Icon+ name="menu-right"+ size={SIZE.sm}+ allowFontScaling={false}+ color={colors.icon}+ style={{+ position: 'absolute',+ transform: [+ {+ rotateZ: '-45deg'+ }+ ],+ top: 0,+ right: 0+ }}+ />+ )}+ </>)}</PressableButton></View>