Skip to content

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

feat: custom toolbar & attachment progress

Ammar Ahmed473343f5e18a
diff --git a/apps/mobile/src/screens/editor/header.js b/apps/mobile/src/screens/editor/header.js
deleted file mode 100644
index aa2567308..000000000
--- a/apps/mobile/src/screens/editor/header.js
+++ /dev/null
@@ -1,349 +0,0 @@
-import { EV, EVENTS } from 'notes-core/common';
-import React, { useEffect, useRef } from 'react';
-import { BackHandler, InteractionManager, Platform, Vibration, View } from 'react-native';
-import { useSafeAreaInsets } from 'react-native-safe-area-context';
-import { notesnook } from '../../../e2e/test.ids';
-import { Properties } from '../../components/properties';
-import { IconButton } from '../../components/ui/icon-button';
-import { DDS } from '../../services/device-detection';
-import {
- eSendEvent,
- eSubscribeEvent,
- eUnSubscribeEvent,
- ToastEvent
-} from '../../services/event-manager';
-import Navigation from '../../services/navigation';
-import { useEditorStore } from '../../stores/use-editor-store';
-import { useSettingStore } from '../../stores/use-setting-store';
-import { useThemeStore } from '../../stores/use-theme-store';
-import { useUserStore } from '../../stores/use-user-store';
-import umami from '../../utils/analytics';
-import { SUBSCRIPTION_STATUS } from '../../utils/constants';
-import { db } from '../../utils/database';
-import {
- eClearEditor,
- eCloseFullscreenEditor,
- eOnLoadNote,
- eOpenFullscreenEditor,
- eOpenLoginDialog,
- eOpenPremiumDialog,
- eOpenPublishNoteDialog
-} from '../../utils/events';
-import { tabBarRef } from '../../utils/global-refs';
-import { ProgressCircle } from './progress';
-import picker from './tiptap/picker';
-import { editorController, editorState } from './tiptap/utils';
-import { EditorTitle } from './title';
-
-const EditorHeader = ({ editor }) => {
- const colors = useThemeStore(state => state.colors);
- const deviceMode = useSettingStore(state => state.deviceMode);
- const currentlyEditingNote = useEditorStore(state => state.currentEditingNote);
- const fullscreen = useSettingStore(state => state.fullscreen);
- const user = useUserStore(state => state.user);
- const insets = useSafeAreaInsets();
- const handleBack = useRef();
- const keyboardListener = useRef();
- const searchReplace = useEditorStore(state => state.searchReplace);
- const readonly = useEditorStore(state => state.readonly);
-
- const _onBackPress = async () => {
- setTimeout(async () => {
- if (deviceMode !== 'mobile' && fullscreen) {
- if (fullscreen) {
- eSendEvent(eCloseFullscreenEditor);
- }
- return;
- }
-
- if (deviceMode === 'mobile') {
- editorState().movedAway = true;
- tabBarRef.current?.goToPage(0);
- }
- eSendEvent('historyEvent', {
- undo: 0,
- redo: 0
- });
- setImmediate(() => useEditorStore.getState().setCurrentlyEditingNote(null));
- editorState().currentlyEditing = false;
- keyboardListener.current?.remove();
- editor?.reset();
- }, 1);
- };
-
- const publishNote = async () => {
- if (!user) {
- ToastEvent.show({
- heading: 'Login required',
- message: 'Login to publish',
- context: 'global',
- func: () => {
- eSendEvent(eOpenLoginDialog);
- },
- actionText: 'Login'
- });
- return;
- }
-
- if (!user.isEmailConfirmed) {
- ToastEvent.show({
- heading: 'Email not verified',
- message: 'Please verify your email first.',
- context: 'global'
- });
- return;
- }
-
- let note = db.notes.note(editorController.current?.note.current?.id)?.data;
- if (note.locked) {
- ToastEvent.show({
- heading: 'Locked notes cannot be published',
- type: 'error',
- context: 'global'
- });
- return;
- }
- if (editorState().isFocused) {
- editorState().isFocused = true;
- }
- eSendEvent(eOpenPublishNoteDialog, note);
- };
-
- const showActionsheet = async () => {
- let note = db.notes.note(editorController.current?.note?.current)?.data;
-
- if (!note) {
- ToastEvent.show({
- heading: 'Start writing to create a new note',
- type: 'success',
- context: 'global'
- });
-
- return;
- }
-
- if (editorState().isFocused || editorState().keyboardState) {
- editorState().isFocused = true;
- }
-
- Properties.present(note, ['Dark Mode']);
- };
-
- useEffect(() => {
- eSubscribeEvent(eOnLoadNote, load);
- eSubscribeEvent(eClearEditor, onCallClear);
- EV.subscribe(EVENTS.noteRemoved, onNoteRemoved);
- return () => {
- EV.unsubscribe(EVENTS.noteRemoved, onNoteRemoved);
- eUnSubscribeEvent(eClearEditor, onCallClear);
- eUnSubscribeEvent(eOnLoadNote, load);
- };
- }, []);
-
- const onNoteRemoved = async id => {};
-
- useEffect(() => {
- if (fullscreen && DDS.isTab) {
- handleBack.current = BackHandler.addEventListener('hardwareBackPress', _onBackPress);
- }
-
- return () => {
- if (handleBack.current) {
- handleBack.current.remove();
- handleBack.current = null;
- }
- };
- }, [fullscreen]);
-
- const load = async item => {
- //console.log(item.id);
- // await loadNote(item);
- console.log('load called');
- InteractionManager.runAfterInteractions(() => {
- //keyboardListener.current = Keyboard.addListener('keyboardDidShow', tiny.onKeyboardShow);
- if (!DDS.isTab) {
- handleBack.current = BackHandler.addEventListener(
- 'hardwareBackPress',
- _onHardwareBackPress
- );
- }
- });
- };
-
- const onCallClear = async value => {
- if (value === 'removeHandler') {
- if (handleBack.current) {
- handleBack.current.remove();
- handleBack.current = null;
- }
- return;
- }
- if (value === 'addHandler') {
- if (handleBack.current) {
- handleBack.current.remove();
- handleBack.current = null;
- }
-
- handleBack.current = BackHandler.addEventListener('hardwareBackPress', _onHardwareBackPress);
- return;
- }
- if (editorState().currentlyEditing) {
- await _onBackPress();
- }
- };
-
- const _onHardwareBackPress = async () => {
- if (editorState().currentlyEditing) {
- await _onBackPress();
- return true;
- }
- };
-
- return (
- <>
- <View
- style={{
- width: '100%',
- backgroundColor: colors.bg,
- marginTop: Platform.OS === 'ios' ? 0 : insets.top,
- flexDirection: 'row',
- paddingHorizontal: 12,
- height: 50,
- justifyContent: 'space-between',
- display: 'none'
- }}
- >
- <View
- style={{
- flexDirection: 'row',
- alignItems: 'center',
- flexGrow: 1,
- flexShrink: 1
- }}
- >
- {deviceMode !== 'mobile' && !fullscreen ? null : (
- <IconButton
- onLongPress={async () => {
- await _onBackPress();
- Navigation.popToTop();
- }}
- top={50}
- left={12}
- 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 ? (
- <IconButton
- name="crown"
- color={colors.yellow}
- customStyle={{
- marginLeft: 5
- }}
- top={50}
- onPress={async () => {
- if (editorState().isFocused) {
- editorState().isFocused = true;
- }
- umami.pageView('/pro-screen', '/editor');
- eSendEvent(eOpenPremiumDialog);
- }}
- />
- ) : null}
- <IconButton
- name="magnify"
- color={searchReplace ? colors.accent : colors.pri}
- customStyle={{
- marginLeft: 5
- }}
- type={searchReplace ? 'grayBg' : 'transparent'}
- top={50}
- buttom={10}
- onLongPress={() => {
- if (searchReplace) {
- //endSearch();
- Vibration.vibrate(5, false);
- }
- }}
- onPress={() => {
- useEditorStore.getState().setSearchReplace(true);
- }}
- />
-
- {currentlyEditingNote && !readonly && (
- <IconButton
- name="cloud-upload-outline"
- color={colors.pri}
- customStyle={{
- marginLeft: 5
- }}
- top={50}
- onPress={publishNote}
- />
- )}
-
- {!readonly && (
- <IconButton
- name="attachment"
- color={colors.pri}
- customStyle={{
- marginLeft: 5
- }}
- top={50}
- onPress={picker.pick}
- />
- )}
-
- {deviceMode !== 'mobile' && !fullscreen ? (
- <IconButton
- name="fullscreen"
- color={colors.pri}
- customStyle={{
- marginLeft: 5
- }}
- top={50}
- onPress={() => {
- eSendEvent(eOpenFullscreenEditor);
- editorState().isFullscreen = true;
- }}
- />
- ) : null}
-
- <IconButton
- name="dots-horizontal"
- color={colors.pri}
- customStyle={{
- marginLeft: 5
- }}
- top={50}
- right={50}
- onPress={showActionsheet}
- />
-
- <ProgressCircle />
- </>
- </View>
- </View>
- </>
- );
-};
-
-export default EditorHeader;
diff --git a/apps/mobile/src/screens/editor/historyview.js b/apps/mobile/src/screens/editor/historyview.js
deleted file mode 100644
index 24a4b9a30..000000000
--- a/apps/mobile/src/screens/editor/historyview.js
+++ /dev/null
@@ -1,85 +0,0 @@
-import React, { useEffect, useState } from 'react';
-import { Platform, View } from 'react-native';
-import { IconButton } from '../../components/ui/icon-button';
-import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
-import { useThemeStore } from '../../stores/use-theme-store';
-import useKeyboard from '../../utils/hooks/use-keyboard';
-import { SIZE } from '../../utils/size';
-import { editorState } from './tiptap/utils';
-
-const HistoryComponent = () => {
- const colors = useThemeStore(state => state.colors);
- const [historyState, setHistoryState] = useState({
- undo: false,
- redo: false
- });
- const keyboard = useKeyboard();
- editorState().keyboardState = keyboard.keyboardShown;
-
- const onHistoryChange = data => {
- setHistoryState(data);
- };
-
- useEffect(() => {
- eSubscribeEvent('historyEvent', onHistoryChange);
- return () => {
- eUnSubscribeEvent('historyEvent', onHistoryChange);
- };
- }, []);
-
- return (
- <View
- style={{
- flexDirection: 'row',
- height: 40,
- marginRight: 5
- }}
- >
- {Platform.OS === 'ios' && keyboard.keyboardShown ? (
- <IconButton
- name="keyboard-close"
- color={colors.pri}
- size={SIZE.lg}
- customStyle={{
- width: 35,
- height: 35
- }}
- onPress={() => {
- editorState().keyboardState = true;
- }}
- />
- ) : null}
-
- <IconButton
- name="undo-variant"
- disabled={!historyState.undo}
- color={colors.pri}
- size={SIZE.xl}
- customStyle={{
- width: 35,
- height: 35
- }}
- onPress={() => {
- if (!historyState.undo) return;
- // tiny.call(EditorWebView, tiny.undo);
- }}
- />
- <IconButton
- name="redo-variant"
- disabled={!historyState.redo}
- color={colors.pri}
- size={SIZE.xl}
- customStyle={{
- width: 35,
- height: 35
- }}
- onPress={() => {
- if (!historyState.redo) return;
- // tiny.call(EditorWebView, tiny.redo);
- }}
- />
- </View>
- );
-};
-
-export default HistoryComponent;
diff --git a/apps/mobile/src/screens/editor/index.js b/apps/mobile/src/screens/editor/index.js
index 3b185b1c3..654dced97 100755
--- a/apps/mobile/src/screens/editor/index.js
+++ b/apps/mobile/src/screens/editor/index.js
@@ -2,7 +2,6 @@ import React from 'react';
import { Linking, Platform } from 'react-native';
import WebView from 'react-native-webview';
import { notesnook } from '../../../e2e/test.ids';
-import { useUserStore } from '../../stores/use-user-store';
import { useEditor } from './tiptap/use-editor';
import { useEditorEvents } from './tiptap/use-editor-events';
import { editorController } from './tiptap/utils';
@@ -24,7 +23,6 @@ const onShouldStartLoadWithRequest = request => {
const Editor = React.memo(
() => {
- const premiumUser = useUserStore(state => state.premium);
const editor = useEditor();
const onMessage = useEditorEvents(editor);
editorController.current = editor;
@@ -62,7 +60,7 @@ const Editor = React.memo(
allowUniversalAccessFromFileURLs={true}
originWhitelist={['*']}
source={{
- uri: 'http://192.168.10.5:3000'
+ uri: 'http://localhost:3000'
}}
style={style}
autoManageStatusBarEnabled={false}
diff --git a/apps/mobile/src/screens/editor/progress.js b/apps/mobile/src/screens/editor/progress.js
index acf54f490..f4a1ff2dc 100644
--- a/apps/mobile/src/screens/editor/progress.js
+++ b/apps/mobile/src/screens/editor/progress.js
@@ -4,22 +4,16 @@ import * as Progress from 'react-native-progress';
import { useThemeStore } from '../../stores/use-theme-store';
import { useAttachmentStore } from '../../stores/use-attachment-store';
import { SIZE } from '../../utils/size';
+import { useSafeAreaInsets } from 'react-native-safe-area-context';
-export const ProgressCircle = () => {
+export const ProgressBar = () => {
const colors = useThemeStore(state => state.colors);
-
const loading = useAttachmentStore(state => state.loading);
const [prog, setProg] = useState(0);
const [visible, setVisible] = useState(false);
const timer = useRef();
-
- const formatText = progress => {
- progress = (progress * 100).toFixed(0);
- if (progress === 0) {
- progress = 10;
- }
- return progress + '%';
- };
+ const insets = useSafeAreaInsets();
+ const [width, setWidth] = useState(false);
useEffect(() => {
if (loading) {
@@ -49,20 +43,20 @@ export const ProgressCircle = () => {
<View
style={{
justifyContent: 'center',
- marginLeft: 10
+ position: 'absolute',
+ zIndex: 1,
+ marginTop: insets.top + 45,
+ width: '100%'
}}
+ onLayout={event => setWidth(event.nativeEvent.layout.width)}
>
- <Progress.Circle
+ <Progress.Bar
size={SIZE.xxl}
progress={prog}
- showsText
- textStyle={{
- fontSize: 7
- }}
color={colors.accent}
- formatText={formatText}
borderWidth={0}
- thickness={2}
+ height={1}
+ width={width || 400}
/>
</View>
) : null;
diff --git a/apps/mobile/src/screens/editor/tiptap/commands.ts b/apps/mobile/src/screens/editor/tiptap/commands.ts
index 7c21fd3ff..0052e19c5 100644
--- a/apps/mobile/src/screens/editor/tiptap/commands.ts
+++ b/apps/mobile/src/screens/editor/tiptap/commands.ts
@@ -8,6 +8,7 @@ import { Note } from './types';
import { getResponse, randId, textInput } from './utils';
import { Attachment, AttachmentProgress } from 'notesnook-editor/dist/extensions/attachment/index';
import { ImageAttributes } from 'notesnook-editor/dist/extensions/image/index';
+import { ToolbarGroupDefinition } from 'notesnook-editor/dist/toolbar/types';
type Action = { job: string; id: string };
@@ -16,6 +17,7 @@ export type Settings = {
fullscreen: boolean;
deviceMode: string;
premium: boolean;
+ tools: ToolbarGroupDefinition[];
};
async function call(webview: RefObject<WebView | undefined>, action?: Action) {
diff --git a/apps/mobile/src/screens/editor/tiptap/picker.js b/apps/mobile/src/screens/editor/tiptap/picker.js
index ed2455018..dbd0377b1 100644
--- a/apps/mobile/src/screens/editor/tiptap/picker.js
+++ b/apps/mobile/src/screens/editor/tiptap/picker.js
@@ -189,25 +189,11 @@ const pick = async options => {
return;
}
- if (options?.type.startsWith('image')) {
- if (options?.reupload) {
+ if (options?.type.startsWith('image') || options?.type === 'camera') {
+ if (options.type === 'image') {
gallery(options);
} else {
- presentSheet({
- context: options?.context,
- actionsArray: [
- {
- action: () => camera(options),
- actionText: 'Open camera',
- icon: 'camera'
- },
- {
- action: () => gallery(options),
- actionText: 'Select image from gallery',
- icon: 'image-multiple'
- }
- ]
- });
+ camera(options);
}
} else {
file(options);
diff --git a/apps/mobile/src/screens/editor/tiptap/useEditorEvents.ts b/apps/mobile/src/screens/editor/tiptap/useEditorEvents.ts
index ddbf13e1d..e5ecdfed9 100644
--- a/apps/mobile/src/screens/editor/tiptap/useEditorEvents.ts
+++ b/apps/mobile/src/screens/editor/tiptap/useEditorEvents.ts
@@ -27,6 +27,7 @@ import {
import filesystem from '../../../utils/filesystem';
import { tabBarRef } from '../../../utils/global-refs';
import { NoteType } from '../../../utils/types';
+import { useDragState } from '../../settings/editor/state';
import picker from './picker';
import { EditorMessage, useEditorType } from './types';
import { editorController, EditorEvents, editorState } from './utils';
@@ -118,23 +119,34 @@ export const useEditorEvents = (editor: useEditorType) => {
const currentEditingNote = useEditorStore(state => state.currentEditingNote);
const readonly = useEditorStore(state => state.readonly);
const isPremium = useUserStore(state => state.premium);
+ const tools = useDragState(state => state.data);
if (!editor) return null;
useEffect(() => {
+ console.log('setting settings');
editor.commands.setSettings({
deviceMode: deviceMode || 'mobile',
fullscreen: fullscreen,
premium: isPremium,
- readonly: readonly
+ readonly: readonly,
+ tools: tools
});
- }, [currentEditingNote, fullscreen, isPremium, readonly, editor.sessionId, editor.loading]);
+ }, [
+ currentEditingNote,
+ fullscreen,
+ isPremium,
+ readonly,
+ editor.sessionId,
+ editor.loading,
+ tools
+ ]);
const onBackPress = useCallback(async () => {
const editorHandledBack = await editor.commands.handleBack();
- if (editorHandledBack) {
- logger.info('editor handled back event');
- return;
- }
+ // if (!editorHandledBack) {
+ // logger.info('editor handled back event', editorHandledBack);
+ // return;
+ // }
setTimeout(async () => {
if (deviceMode !== 'mobile' && fullscreen) {
if (fullscreen) {
diff --git a/apps/mobile/src/screens/editor/title.js b/apps/mobile/src/screens/editor/title.js
deleted file mode 100644
index 2b798dcc7..000000000
--- a/apps/mobile/src/screens/editor/title.js
+++ /dev/null
@@ -1,68 +0,0 @@
-import React, { useEffect, useState } from 'react';
-import { TextInput, View } from 'react-native';
-import Animated, { FadeInUp, FadeOutUp } from 'react-native-reanimated';
-import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
-import { useThemeStore } from '../../stores/use-theme-store';
-import { SIZE } from '../../utils/size';
-
-export const EditorTitle = () => {
- const colors = useThemeStore(state => state.colors);
- const [title, setTitle] = useState(null);
- const [show, setShow] = useState(false);
- const onScroll = async data => {
- if (data.visible === undefined || data.visible === null) return;
- if (data.visible > 190) {
- setShow(true);
- } else {
- setShow(false);
- }
- if (title !== data.title) {
- setTitle(data.title);
- }
- };
-
- useEffect(() => {
- eSubscribeEvent('editorScroll', onScroll);
- return () => {
- eUnSubscribeEvent('editorScroll', onScroll);
- };
- }, []);
-
- return show ? (
- <Animated.View
- entering={FadeInUp}
- exiting={FadeOutUp}
- style={{
- paddingLeft: 0
- }}
- >
- <TextInput
- defaultValue={title}
- style={{
- fontFamily: 'OpenSans-SemiBold',
- fontSize: SIZE.xl,
- color: colors.heading,
- padding: 0,
- flexShrink: 1,
- flexWrap: 'wrap'
- }}
- placeholder="Note title"
- placeholderTextColor={colors.placeholder}
- onChangeText={text => {
- setTitle(text);
- // post('title', text);
- // _onMessage({
- // nativeEvent: {
- // data: JSON.stringify({
- // type: 'title',
- // value: text
- // })
- // }
- // });
- }}
- />
- </Animated.View>
- ) : (
- <View />
- );
-};
diff --git a/apps/mobile/src/screens/editor/wrapper.js b/apps/mobile/src/screens/editor/wrapper.js
index 9ca6db396..6a85a3a04 100644
--- a/apps/mobile/src/screens/editor/wrapper.js
+++ b/apps/mobile/src/screens/editor/wrapper.js
@@ -17,6 +17,7 @@ import { useThemeStore } from '../../stores/use-theme-store';
import { editorRef } from '../../utils/global-refs';
import useIsFloatingKeyboard from '../../utils/hooks/use-is-floating-keyboard';
import EditorOverlay from './loading';
+import { ProgressBar } from './progress';
import { editorController, editorState, textInput } from './tiptap/utils';
export const EditorWrapper = ({ width }) => {
@@ -74,6 +75,7 @@ export const EditorWrapper = ({ width }) => {
style={{ height: 1, padding: 0, width: 1, position: 'absolute' }}
blurOnSubmit={false}
/>
+ <ProgressBar />
<Editor key="editor" />
<EditorOverlay key="overlay" />
</KeyboardAvoidingView>
diff --git a/apps/mobile/src/screens/settings/editor/configuretoolbar.tsx b/apps/mobile/src/screens/settings/editor/configuretoolbar.tsx
index 88c4433a4..e3c5ae2e0 100644
--- a/apps/mobile/src/screens/settings/editor/configuretoolbar.tsx
+++ b/apps/mobile/src/screens/settings/editor/configuretoolbar.tsx
@@ -16,7 +16,9 @@ export const ConfigureToolbar = () => {
const colors = useThemeStore(state => state.colors);
const renderGroups = () => {
- return data.map((item, index) => <Group key={`group-${index}`} item={item} index={index} />);
+ return data.map((item, index) =>
+ index === 0 ? <View /> : <Group key={`group-${index}`} item={item} index={index} />
+ );
};
return (
diff --git a/apps/mobile/src/screens/settings/editor/state.ts b/apps/mobile/src/screens/settings/editor/state.ts
index 7ec8b9c88..f71e4b690 100644
--- a/apps/mobile/src/screens/settings/editor/state.ts
+++ b/apps/mobile/src/screens/settings/editor/state.ts
@@ -1,6 +1,8 @@
+import { ToolbarGroupDefinition } from 'notesnook-editor/dist/toolbar/types';
import create, { State } from 'zustand';
-import { presets, toolbarDefinition } from './toolbar-definition';
-
+import { persist } from 'zustand/middleware';
+import { MMKV } from '../../../utils/database/mmkv';
+import { presets } from './toolbar-definition';
export type ToolDefinition = string | string[];
export type DraggedItem = {
@@ -20,25 +22,42 @@ export type DraggableItem = {
export interface DragState extends State {
dragged: DraggedItem;
setDragged: (dragged: DraggedItem) => void;
- data: ToolDefinition[][];
- setData: (data: ToolDefinition[][]) => void;
+ data: ToolbarGroupDefinition[];
+ customPresetData: ToolbarGroupDefinition[];
+ setData: (data: ToolbarGroupDefinition[]) => void;
preset: 'default' | 'minimal' | 'custom';
setPreset: (preset: 'default' | 'minimal' | 'custom') => void;
}
-export const useDragState = create<DragState>((set, get) => ({
- preset: 'default',
- dragged: {},
- setDragged: dragged => {
- set({ dragged });
- },
- data: toolbarDefinition,
- setData: data => {
- //@ts-ignore
- presets['custom'] = data;
- set({ data, preset: 'custom' });
- },
- setPreset: preset => {
- set({ preset, data: presets[preset] });
- }
-}));
+export const useDragState = create<DragState>(
+ persist(
+ (set, get) => ({
+ preset: 'default',
+ dragged: {},
+ setDragged: dragged => {
+ set({ dragged });
+ },
+ data: presets['default'],
+ customPresetData: presets['custom'],
+ setData: data => {
+ //@ts-ignore
+ presets['custom'] = data;
+ console.log(presets['custom']);
+ set({ data: data, preset: 'custom', customPresetData: data });
+ },
+ setPreset: preset => {
+ set({ preset, data: preset === 'custom' ? get().customPresetData : presets[preset] });
+ }
+ }),
+ {
+ name: 'drag-state-storage', // unique name
+ //@ts-ignore
+ getStorage: () => MMKV,
+ onRehydrateStorage: state => {
+ return state => {
+ console.log(state, 'rehydrated drag state');
+ };
+ } // (optional) by default, 'localStorage' is used
+ }
+ )
+);
diff --git a/apps/mobile/src/screens/settings/editor/toolbardefinition.ts b/apps/mobile/src/screens/settings/editor/toolbardefinition.ts
index 40a5eefc3..655f48412 100644
--- a/apps/mobile/src/screens/settings/editor/toolbardefinition.ts
+++ b/apps/mobile/src/screens/settings/editor/toolbardefinition.ts
@@ -1,9 +1,19 @@
import { Icons } from 'notesnook-editor/dist/toolbar/icons';
import { useThemeStore } from '../../../stores/use-theme-store';
+import { ToolbarGroupDefinition, ToolDefinition } from 'notesnook-editor/dist/toolbar/types';
+import { ToolId } from 'notesnook-editor/dist/toolbar/tools';
-export const presets = {
+export const presets: { [name: string]: ToolbarGroupDefinition[] } = {
default: [
- ['insertBlock'],
+ [
+ 'insertBlock',
+ 'tableSettings',
+ 'imageSettings',
+ 'embedSettings',
+ 'attachmentSettings',
+ 'linkSettings',
+ 'codeRemove'
+ ],
[
'bold',
'italic',
@@ -13,12 +23,20 @@ export const presets = {
['fontSize'],
['headings', 'fontFamily'],
['numberedList', 'bulletList'],
- ['link'],
+ ['addLink'],
['alignCenter', ['alignLeft', 'alignRight', 'alignJustify', 'ltr', 'rtl']],
['clearformatting']
],
minimal: [
- ['insertBlock'],
+ [
+ 'insertBlock',
+ 'tableSettings',
+ 'imageSettings',
+ 'embedSettings',
+ 'attachmentSettings',
+ 'linkSettings',
+ 'codeRemove'
+ ],
[
'bold',
'italic',
@@ -26,7 +44,17 @@ export const presets = {
['strikethrough', 'subscript', 'superscript', 'highlight', 'textColor']
]
],
- custom: []
+ custom: [
+ [
+ 'insertBlock',
+ 'tableSettings',
+ 'imageSettings',
+ 'embedSettings',
+ 'attachmentSettings',
+ 'linkSettings',
+ 'codeRemove'
+ ]
+ ]
};
export function findToolById(id: keyof typeof tools): { title: string; icon: string } {
@@ -51,13 +79,14 @@ export function getUngroupedTools(toolDefinition: (string | string[])[][]): stri
const ungrouped = [];
let toolString = JSON.stringify(toolDefinition);
for (let key of keys) {
+ if (tools[key as ToolId].conditional) continue;
if (!toolString.includes(key)) ungrouped.push(key);
}
console.log(ungrouped);
return ungrouped;
}
-export const tools = {
+export const tools: Record<ToolId, ToolDefinition> = {
bold: {
icon: 'bold',
title: 'Bold'
@@ -74,14 +103,39 @@ export const tools = {
icon: 'strikethrough',
title: 'Strikethrough'
},
- link: {
+ addLink: {
icon: 'link',
title: 'Link'
},
+ editLink: {
+ icon: 'linkEdit',
+ title: 'Edit link',
+ conditional: true
+ },
+ removeLink: {
+ icon: 'linkRemove',
+ title: 'Remove link',
+ conditional: true
+ },
+ openLink: {
+ icon: 'openLink',
+ title: 'Open link',
+ conditional: true
+ },
+ linkSettings: {
+ icon: 'linkSettings',
+ title: 'Link settings',
+ conditional: true
+ },
code: {
icon: 'code',
title: 'Code'
},
+ codeRemove: {
+ icon: 'codeRemove',
+ title: 'Code',
+ conditional: true
+ },
clearformatting: {
icon: 'formatClear',
title: 'Clear all formatting'
@@ -149,9 +203,180 @@ export const tools = {
textColor: {
icon: 'textColor',
title: 'Text color'
+ },
+
+ tableSettings: {
+ icon: 'tableSettings',
+ title: 'Table settings',
+ conditional: true
+ },
+ columnProperties: {
+ icon: 'columnProperties',
+ title: 'Column properties',
+ conditional: true
+ },
+ rowProperties: {
+ icon: 'rowProperties',
+ title: 'Row properties',
+ conditional: true
+ },
+ cellProperties: {
+ icon: 'cellProperties',
+ title: 'Cell properties',
+ conditional: true
+ },
+ insertColumnLeft: {
+ icon: 'insertColumnLeft',
+ title: 'Insert column left',
+ conditional: true
+ },
+ insertColumnRight: {
+ icon: 'insertColumnRight',
+ title: 'Insert column right',
+ conditional: true
+ },
+ moveColumnLeft: {
+ icon: 'moveColumnLeft',
+ title: 'Move column left',
+ conditional: true
+ },
+ moveColumnRight: {
+ icon: 'moveColumnRight',
+ title: 'Move column right',
+ conditional: true
+ },
+ deleteColumn: {
+ icon: 'deleteColumn',
+ title: 'Delete column',
+ conditional: true
+ },
+ splitCells: {
+ icon: 'splitCells',
+ title: 'Split cells',
+ conditional: true
+ },
+ mergeCells: {
+ icon: 'mergeCells',
+ title: 'Merge cells',
+ conditional: true
+ },
+ insertRowAbove: {
+ icon: 'insertRowAbove',
+ title: 'Insert row above',
+ conditional: true
+ },
+ insertRowBelow: {
+ icon: 'insertRowBelow',
+ title: 'Insert row below',
+ conditional: true
+ },
+ moveRowUp: {
+ icon: 'moveRowUp',
+ title: 'Move row up',
+ conditional: true
+ },
+ moveRowDown: {
+ icon: 'moveRowDown',
+ title: 'Move row down',
+ conditional: true
+ },
+ deleteRow: {
+ icon: 'deleteRow',
+ title: 'Delete row',
+ conditional: true
+ },
+ deleteTable: {
+ icon: 'deleteTable',
+ title: 'Delete table',
+ conditional: true
+ },
+ cellBackgroundColor: {
+ icon: 'backgroundColor',
+ title: 'Cell background color',
+ conditional: true
+ },
+ cellBorderColor: {
+ icon: 'cellBorderColor',
+ title: 'Cell border color',
+ conditional: true
+ },
+ cellTextColor: {
+ icon: 'textColor',
+ title: 'Cell text color',
+ conditional: true
+ },
+ cellBorderWidth: {
+ icon: 'none',
+ title: 'Cell border width',
+ conditional: true
+ },
+
+ imageSettings: {
+ icon: 'imageSettings',
+ title: 'Image settings',
+ conditional: true
+ },
+ imageAlignCenter: {
+ icon: 'alignCenter',
+ title: 'Align center',
+ conditional: true
+ },
+ imageAlignLeft: {
+ icon: 'alignLeft',
+ title: 'Align left',
+ conditional: true
+ },
+ imageAlignRight: {
+ icon: 'alignRight',
+ title: 'Align right',
+ conditional: true
+ },
+ imageProperties: {
+ icon: 'more',
+ title: 'Image properties',
+ conditional: true
+ },
+ attachmentSettings: {
+ icon: 'attachmentSettings',
+ title: 'Attachment settings',
+ conditional: true
+ },
+ downloadAttachment: {
+ icon: 'download',
+ title: 'Download attachment',
+ conditional: true
+ },
+ removeAttachment: {
+ icon: 'delete',
+ title: 'Remove attachment',
+ conditional: true
+ },
+ embedSettings: {
+ icon: 'embedSettings',
+ title: 'Embed settings',
+ conditional: true
+ },
+ embedAlignCenter: {
+ icon: 'alignCenter',
+ title: 'Align center',
+ conditional: true
+ },
+ embedAlignLeft: {
+ icon: 'alignLeft',
+ title: 'Align left',
+ conditional: true
+ },
+ embedAlignRight: {
+ icon: 'alignRight',
+ title: 'Align right',
+ conditional: true
+ },
+ embedProperties: {
+ icon: 'more',
+ title: 'Embed properties',
+ conditional: true
}
};
-
export const toolbarDefinition = presets['default'];
export type FlattenedToolbarItemType = {
diff --git a/apps/mobile/src/utils/filesystem/download.js b/apps/mobile/src/utils/filesystem/download.js
index 81baf8bf7..738a42602 100644
--- a/apps/mobile/src/utils/filesystem/download.js
+++ b/apps/mobile/src/utils/filesystem/download.js
@@ -21,7 +21,6 @@ export async function downloadFile(filename, data, cancelToken) {
try {
let exists = await RNFetchBlob.fs.exists(path);
if (exists) {
- console.log(await RNFetchBlob.fs.readFile(path, 'utf8'));
console.log('file is downloaded');
return true;
}