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: improve tables support in editor
ammarahm-edd5469ea4c818
diff --git a/apps/mobile/html/Web.bundle/site/constants.js b/apps/mobile/html/Web.bundle/site/constants.jsindex b3d5e29a1..796d4717e 100755--- a/apps/mobile/html/Web.bundle/site/constants.js+++ b/apps/mobile/html/Web.bundle/site/constants.js@@ -18,7 +18,7 @@ let pageTheme = {pri: 'black',sec: 'white',factor: 1,- border:"#E8E8E8"+ border: '#E8E8E8'}};@@ -114,6 +114,9 @@ function light() {);}+let styleElementDocument = null;+let styleElementEditorDocument = null;+function setTheme() {if (pageTheme.colors.night) {dark();@@ -122,8 +125,7 @@ function setTheme() {}addStyle();- let css = document.createElement('style');- css.type = 'text/css';+let node = `#titleInput {@@ -467,7 +469,10 @@ code {.tox-checklist li.tox-checklist--checked::before,.checklist li.checked::before {- content: url('data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2216%22%20height%3D%2216%22%20viewBox%3D%220%200%2016%2016%22%3E%3Cg%20id%3D%22checklist-checked%22%20fill%3D%22none%22%20fill-rule%3D%22evenodd%22%3E%3Crect%20id%3D%22Rectangle%22%20width%3D%2216%22%20height%3D%2216%22%20fill%3D%22%23${pageTheme.colors.accent.replace("#","")}%22%20fill-rule%3D%22nonzero%22%20rx%3D%222%22%2F%3E%3Cpath%20id%3D%22Path%22%20fill%3D%22%23FFF%22%20fill-rule%3D%22nonzero%22%20d%3D%22M11.5703186%2C3.14417309%20C11.8516238%2C2.73724603%2012.4164781%2C2.62829933%2012.83558%2C2.89774797%20C13.260121%2C3.17069355%2013.3759736%2C3.72932262%2013.0909105%2C4.14168582%20L7.7580587%2C11.8560195%20C7.43776896%2C12.3193404%206.76483983%2C12.3852142%206.35607322%2C11.9948725%20L3.02491697%2C8.8138662%20C2.66090143%2C8.46625845%202.65798871%2C7.89594698%203.01850234%2C7.54483354%20C3.373942%2C7.19866177%203.94940006%2C7.19592841%204.30829608%2C7.5386474%20L6.85276923%2C9.9684299%20L11.5703186%2C3.14417309%20Z%22%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E%0A');+ content: url('data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2216%22%20height%3D%2216%22%20viewBox%3D%220%200%2016%2016%22%3E%3Cg%20id%3D%22checklist-checked%22%20fill%3D%22none%22%20fill-rule%3D%22evenodd%22%3E%3Crect%20id%3D%22Rectangle%22%20width%3D%2216%22%20height%3D%2216%22%20fill%3D%22%23${pageTheme.colors.accent.replace(+ '#',+ ''+ )}%22%20fill-rule%3D%22nonzero%22%20rx%3D%222%22%2F%3E%3Cpath%20id%3D%22Path%22%20fill%3D%22%23FFF%22%20fill-rule%3D%22nonzero%22%20d%3D%22M11.5703186%2C3.14417309%20C11.8516238%2C2.73724603%2012.4164781%2C2.62829933%2012.83558%2C2.89774797%20C13.260121%2C3.17069355%2013.3759736%2C3.72932262%2013.0909105%2C4.14168582%20L7.7580587%2C11.8560195%20C7.43776896%2C12.3193404%206.76483983%2C12.3852142%206.35607322%2C11.9948725%20L3.02491697%2C8.8138662%20C2.66090143%2C8.46625845%202.65798871%2C7.89594698%203.01850234%2C7.54483354%20C3.373942%2C7.19866177%203.94940006%2C7.19592841%204.30829608%2C7.5386474%20L6.85276923%2C9.9684299%20L11.5703186%2C3.14417309%20Z%22%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E%0A');}.tox-checklist li.tox-checklist--checked,@@ -500,28 +505,48 @@ table[data-mce-selected] {min-width: 100% !important;}-.mce-content-body td,-.mce-content-body th {+tr td,+tr th {padding: 5px !important;border: 1px solid ${pageTheme.colors.border} !important;+}++thead tr td,+tbody tr td,+thead tr th,+tbody tr th {border-left: none !important;border-top: none !important;}+tfoot tr td,+tfoot tr th, {+ border-left: none !important;+}++table caption,+thead td {+ border-bottom: 1px solid ${pageTheme.colors.border} !important;+}++tfoot td {+ border-top: 1px solid ${pageTheme.colors.border} !important;+}+.mce-content-body td:last-child {border-right: none !important;}-.mce-content-body tr:last-child td {+.mce-content-body tbody tr:last-child td {border-bottom: none !important;}.mce-content-body tr:nth-child(even) {- background-color: ${pageTheme.colors.nav}+ background-color: ${pageTheme.colors.nav};}-table caption {- border-bottom: 1px solid ${pageTheme.colors.border} !important;+table thead {+ font-weight: bold !important;}.mce-content-body .table-container {@@ -570,61 +595,67 @@ th {.mce-content-bodytable[data-mce-selected]- tbodytr[data-mce-active]td:not([data-mce-active]),.mce-content-bodytable[data-mce-selected]- tbodytr[data-mce-active]th:not([data-mce-active]) {- border-bottom: 1px solid ${pageTheme.colors.accent + "B3"} !important;- border-top: 1px solid ${pageTheme.colors.accent + "B3"} !important;+ border-bottom: 1px solid ${pageTheme.colors.accent + 'B3'} !important;+ border-top: 1px solid ${pageTheme.colors.accent + 'B3'} !important;}.mce-content-bodytable[data-mce-selected]- tbodytr[data-mce-active]td:not([data-mce-active]):first-child,.mce-content-bodytable[data-mce-selected]- tbodytr[data-mce-active]th:not([data-mce-active]):first-child {- border-left: 1px solid ${pageTheme.colors.accent + "B3"} !important;+ border-left: 1px solid ${pageTheme.colors.accent + 'B3'} !important;}.mce-content-bodytable[data-mce-selected]- tbodytr[data-mce-active]td:not([data-mce-active]):last-child,.mce-content-bodytable[data-mce-selected]- tbodytr[data-mce-active]th:not([data-mce-active]):last-child {- border-right: 1px solid ${pageTheme.colors.accent + "B3"} !important;+ border-right: 1px solid ${pageTheme.colors.accent + 'B3'} !important;}.mce-content-body table[data-mce-selected] tbody td[data-mce-active],.mce-content-body table[data-mce-selected] tbody th[data-mce-active] {- border: 2px solid ${pageTheme.colors.accent + "B3"} !important;+ border: 2px solid ${pageTheme.colors.accent + 'B3'} !important;background-color: ${pageTheme.colors.shade};}`;+if (tinymce.activeEditor) {let editorHead =tinymce.activeEditor.contentDocument.getElementsByTagName('head')[0];- let css2 = document.createElement('style');- css2.appendChild(document.createTextNode(node2));- editorHead.appendChild(css2);++ if (!styleElementEditorDocument) {+ styleElementEditorDocument = document.createElement('style');+ styleElementEditorDocument.innerHTML = node2;+ editorHead.appendChild(styleElementEditorDocument);+ } else {+ styleElementEditorDocument.innerHTML = node2;+ }}- css.appendChild(document.createTextNode(node));- document.getElementsByTagName('head')[0].appendChild(css);+ if (!styleElementDocument) {+ styleElementDocument = document.createElement('style');+ styleElementDocument.type = 'text/css';+ styleElementDocument.innerHTML = node;+ document.getElementsByTagName('head')[0].appendChild(styleElementDocument);+ } else {+ styleElementDocument.innerHTML = node;+ }}var minifyImg = function (diff --git a/apps/mobile/html/Web.bundle/site/init.js b/apps/mobile/html/Web.bundle/site/init.jsindex f64ee4526..d50ba55b4 100755--- a/apps/mobile/html/Web.bundle/site/init.js+++ b/apps/mobile/html/Web.bundle/site/init.js@@ -316,6 +316,49 @@ strong {}`;+function tableCellNodeOptions() {+ let node = findNodeParent('td');+ if (!node) {+ node = findNodeParent('th');+ }+ if (!node) return;+ let properties = {+ width: node.style.width,+ height: node.style.height,+ backgroundColor: node.style.backgroundColor,+ cellType: tinymce.activeEditor.queryCommandValue('mceTableCellType'),+ colType: tinymce.activeEditor.queryCommandValue('mceTableColType')+ };+ reactNativeEventHandler('tablecelloptions', properties);+}++function findNodeParent(nodeName) {+ let node = editor.selection.getNode();+ console.log('finding node', node);+ let levels = 5;+ for (let i = 0; i < levels; i++) {+ if (!node) return;+ if (node.nodeName.toLowerCase() === nodeName) {+ return node;+ } else {+ node = node.parentNode;+ }+ }+ return null;+}++function tableRowNodeOptions() {+ let node = findNodeParent('tr');++ if (node) {+ let properties = {+ backgroundColor: node.style.backgroundColor,+ rowType: tinymce.activeEditor.queryCommandValue('mceTableRowType')+ };+ reactNativeEventHandler('tablerowoptions', properties);+ }+}+function init_tiny(size) {loadFontSize();console.log('init tinymce');@@ -344,15 +387,14 @@ function init_tiny(size) {content_style: content_style,browser_spellcheck: true,autoresize_bottom_margin: 120,- table_toolbar:- 'tablecellprops | tableinsertrowbefore tableinsertrowafter tabledeleterow | tableinsertcolbefore tableinsertcolafter tabledeletecol',+ table_toolbar: 'tcellprops trowprops | tableinsertrowafter tableinsertcolafter tabledeleterow tabledeletecol | tableconfig',imagetools_toolbar:'imagedownload | rotateleft rotateright flipv fliph | imageopts ',placeholder: 'Start writing your note here',object_resizing: true,- table_responsive_width:false,- table_sizing_mode:"fixed",- table_column_resizing:"resizetable",+ table_responsive_width: false,+ table_sizing_mode: 'fixed',+ table_column_resizing: 'resizetable',resize: true,mobile: {resize: false,@@ -429,16 +471,40 @@ function setup_tiny(_editor) {tooltip: 'Image properties',onAction: function () {reactNativeEventHandler('imageoptions');- },- onclick: function () {- reactNativeEventHandler('imageoptions');+ }+ });++ editor.ui.registry.addButton('tableconfig', {+ icon: 'more-drawer',+ tooltip: 'Table properties',+ onAction: function (e) {+ console.log(e, 'event');+ reactNativeEventHandler('tableconfig');+ }+ });++ editor.ui.registry.addButton('trowprops', {+ icon: 'table-row-properties',+ tooltip: 'Row properties',+ onAction: function (e) {+ tableRowNodeOptions()+ editor.blur();+ }+ });++ editor.ui.registry.addButton('tcellprops', {+ icon: 'table-cell-properties',+ tooltip: 'Cell properties',+ onAction: function (e) {+ tableCellNodeOptions()+ editor.blur();}});editor.ui.registry.addButton('imagedownload', {icon: 'save',tooltip: 'Download image',- onAction: function () {+ onAction: function (e) {let node = tinymce.activeEditor.selection.getNode();if (node.tagName === 'IMG' && node.dataset && node.dataset.hash) {window.ReactNativeWebView.postMessage(@@ -449,8 +515,7 @@ function setup_tiny(_editor) {}));}- },- onclick: function () {}+ }});editor.ui.registry.addButton('imagepreview', {@@ -478,8 +543,7 @@ function setup_tiny(_editor) {);xhr.send();}- },- onclick: function () {}+ }});}@@ -616,7 +680,7 @@ function selectchange() {currentFormats.current = {index: range.startOffset,- length: range.endOffset - range.startOffset,+ length: range.endOffset - range.startOffset};currentFormats.fontsize = editor.selection.getNode().style.fontSize;@@ -669,5 +733,5 @@ function selectchange() {}currentFormats.node = editor.selection.getNode().nodeName;reactNativeEventHandler('selectionchange', currentFormats);- },50);+ }, 50);}diff --git a/apps/mobile/src/views/Editor/EditorHeader.js b/apps/mobile/src/views/Editor/EditorHeader.jsindex 628569b48..076f40fe8 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,@@ -8,17 +8,17 @@ import {Vibration,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} from '../../provider/stores';-import {DDS} from '../../services/DeviceDetection';+import { DDS } from '../../services/DeviceDetection';import {eSendEvent,eSubscribeEvent,@@ -26,8 +26,8 @@ import {ToastEvent} from '../../services/EventManager';import Navigation from '../../services/Navigation';-import {editing, getElevation, SUBSCRIPTION_STATUS} from '../../utils';-import {db} from '../../utils/database';+import { editing, SUBSCRIPTION_STATUS } from '../../utils';+import { db } from '../../utils/database';import {eClearEditor,eCloseFullscreenEditor,@@ -37,9 +37,8 @@ import {eOpenPremiumDialog,eOpenPublishNoteDialog} from '../../utils/Events';-import {tabBarRef} from '../../utils/Refs';-import {SIZE} from '../../utils/SizeUtils';-import {EditorTitle} from './EditorTitle';+import { tabBarRef } from '../../utils/Refs';+import { EditorTitle } from './EditorTitle';import {clearEditor,clearTimer,@@ -49,12 +48,12 @@ import {setColors,startClosingSession} from './Functions';-import {ProgressCircle} from './ProgressCircle';-import tiny, {safeKeyboardDismiss} from './tiny/tiny';-import {endSearch} from './tiny/toolbar/commands';-import {toolbarRef} from './tiny/toolbar/constants';+import { ProgressCircle } from './ProgressCircle';+import tiny, { safeKeyboardDismiss } from './tiny/tiny';+import { endSearch } from './tiny/toolbar/commands';+import { toolbarRef } from './tiny/toolbar/constants';import picker from './tiny/toolbar/picker';-import {useEditorTags} from './useEditorTags';+import { useEditorTags } from './useEditorTags';const EditorHeader = () => {const [state] = useTracked();diff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.jsindex 1f3af905d..97b745870 100644--- a/apps/mobile/src/views/Editor/Functions.js+++ b/apps/mobile/src/views/Editor/Functions.js@@ -1,4 +1,4 @@-import {createRef} from 'react';+import React, {createRef} from 'react';import {Platform} from 'react-native';import {presentDialog} from '../../components/Dialog/functions';import {useEditorStore, useMenuStore, useTagStore} from '../../provider/stores';@@ -6,7 +6,8 @@ import {DDS} from '../../services/DeviceDetection';import {eSendEvent,eSubscribeEvent,- eUnSubscribeEvent+ eUnSubscribeEvent,+ presentSheet} from '../../services/EventManager';import Navigation from '../../services/Navigation';import PremiumService from '../../services/PremiumService';@@ -26,8 +27,10 @@ import {MMKV} from '../../utils/mmkv';import {tabBarRef} from '../../utils/Refs';import {normalize} from '../../utils/SizeUtils';import {sleep, timeConverter} from '../../utils/TimeUtils';+import {TableCellProperties} from './TableCellProperties';+import {TableRowProperties} from './TableRowProperties';import tiny from './tiny/tiny';-import {IMAGE_TOOLTIP_CONFIG} from './tiny/toolbar/config';+import {IMAGE_TOOLTIP_CONFIG, TABLE_TOOLTIP_CONFIG} from './tiny/toolbar/config';export let EditorWebView = createRef();export const editorTitleInput = createRef();@@ -365,7 +368,7 @@ const checkStatus = async noreset => {webviewInit = true;clearTimeout(webviewTimer);webviewTimer = null;- console.log('webviewOk:',webviewOK);+ console.log('webviewOk:', webviewOK);resolve(true);eUnSubscribeEvent('webviewOk', onWebviewOk);};@@ -452,8 +455,29 @@ export const _onMessage = async evt => {}switch (message.type) {+ case 'tableconfig':+ showTableOptionsTooltip();+ break;+ case 'tablecelloptions':+ console.log(message.value);+ eSendEvent('updatecell', message.value);+ presentSheet({+ noIcon: true,+ noProgress: true,+ component: <TableCellProperties data={message.value} />+ });+ break;+ case 'tablerowoptions':+ console.log("tablerowoptions", message.value);+ eSendEvent('updaterow', message.value);+ presentSheet({+ noIcon: true,+ noProgress: true,+ component: <TableRowProperties data={message.value} />+ });+ break;case 'selectionvalue':- eSendEvent('selectionvalue',message.value);+ eSendEvent('selectionvalue', message.value);console.log(message.value);break;case 'history':@@ -617,6 +641,12 @@ function showImageOptionsTooltip() {eSendEvent('showTooltip', IMAGE_TOOLTIP_CONFIG);}+function showTableOptionsTooltip() {+ editing.tooltip = 'tableconfig';+ console.log('showTooltip');+ eSendEvent('showTooltip', TABLE_TOOLTIP_CONFIG);+}+function onNoteChange() {clearTimeout(timer);timer = null;diff --git a/apps/mobile/src/views/Editor/TableCellProperties.js b/apps/mobile/src/views/Editor/TableCellProperties.jsnew file mode 100644index 000000000..68a0d46ed--- /dev/null+++ b/apps/mobile/src/views/Editor/TableCellProperties.js@@ -0,0 +1,245 @@+import React, {useEffect, useState} from 'react';+import {View} from 'react-native';+import {ScrollView} from 'react-native-gesture-handler';+import {ActionIcon} from '../../components/ActionIcon';+import {Button} from '../../components/Button';+import {PressableButton} from '../../components/PressableButton';+import Heading from '../../components/Typography/Heading';+import Paragraph from '../../components/Typography/Paragraph';+import {useTracked} from '../../provider';+import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager';+import {SIZE} from '../../utils/SizeUtils';+import {EditorWebView} from './Functions';+import tiny from './tiny/tiny';+import ColorItem from './tiny/toolbar/coloritem';+import {editor_colors} from './tiny/toolbar/constants';++export const TableCellProperties = ({data}) => {+ const [state] = useTracked();+ const {colors} = state;+ const [cellOptions, setCellOptions] = useState(data);+ console.log(data);++ const onUpdateCell = data => {+ setCellOptions(data);+ };++ useEffect(() => {+ eSubscribeEvent('updatecell', onUpdateCell);+ return () => {+ eUnSubscribeEvent('updatecell', onUpdateCell);+ };+ }, []);++ function increaseWidth() {+ let width = cellOptions.width;+ if (!width.includes('px')) width = '100px';+ width = width.slice(0, width.length - 2);+ width = parseFloat(width);+ width = width + 10;+ width = width + 'px';+ console.log(width, 'final');+ tiny.call(+ EditorWebView,+ `(function() {+ let node = editor.selection.getNode();+ node.style.width = "${width}";+ tableCellNodeOptions();+ editor.fire("input");+ })()`+ );+ }++ function decreaseWidth() {+ let width = cellOptions.width;+ if (!width.includes('px')) width = '100px';+ width = width.slice(0, width.length - 2);++ width = parseFloat(width);+ width = width - 10;+ width = width + 'px';+ tiny.call(+ EditorWebView,+ `(function() {+ let node = editor.selection.getNode();+ node.style.width = "${width}";+ tableCellNodeOptions();+ editor.fire("input");+ })()`+ );+ }++ function changeCellType(type) {+ tiny.call(+ EditorWebView,+ `+ tinymce.activeEditor.execCommand('mceTableCellType', false, { type: '${type}' });+ tableCellNodeOptions();+ editor.fire("input");+ `+ );+ }++ function changeColType(type) {+ tiny.call(+ EditorWebView,+ `+ tinymce.activeEditor.execCommand('mceTableColType', false, { type: '${type}' });+ tableCellNodeOptions();+ editor.fire("input");+ `+ );+ }++ return (+ <View+ style={{+ paddingHorizontal: 12+ }}>+ <Heading size={SIZE.md}>Column Width</Heading>+ <View+ style={{+ flexDirection: 'row',+ alignItems: 'center',+ justifyContent: 'space-between',+ borderRadius: 5,+ height: 50+ }}>+ <Paragraph size={SIZE.md + 2} color={colors.icon}>+ {cellOptions?.width}+ </Paragraph>++ <View+ style={{+ flexDirection: 'row'+ }}>+ <ActionIcon+ customStyle={{+ marginRight: 10+ }}+ onPress={increaseWidth}+ type="grayBg"+ name="plus"+ size={SIZE.lg}+ color={colors.accent}+ />++ <ActionIcon+ onPress={decreaseWidth}+ type="grayBg"+ name="minus"+ size={SIZE.lg}+ color={colors.accent}+ />+ </View>+ </View>++ <Heading+ style={{+ marginBottom: 10+ }}+ size={SIZE.md}>+ Cell type+ </Heading>++ <View+ style={{+ flexDirection: 'row',+ marginBottom: 10+ }}>+ <Button+ type={cellOptions.cellType === 'th' ? 'shade' : 'grayBg'}+ icon={cellOptions.cellType === 'th' && 'check'}+ height={40}+ onPress={() => {+ changeCellType('th');+ }}+ style={{+ marginRight: 10+ }}+ title="Header"+ />++ <Button+ type={cellOptions.cellType === 'td' ? 'shade' : 'grayBg'}+ icon={cellOptions.cellType === 'td' && 'check'}+ height={40}+ onPress={() => {+ changeCellType('td');+ }}+ style={{+ marginRight: 10+ }}+ title="Body"+ />+ </View>++ <Heading+ style={{+ marginBottom: 10+ }}+ size={SIZE.md}>+ Column type+ </Heading>++ <View+ style={{+ flexDirection: 'row',+ marginBottom: 10+ }}>+ <Button+ type={cellOptions.colType === 'th' ? 'shade' : 'grayBg'}+ icon={cellOptions.colType === 'th' && 'check'}+ height={40}+ onPress={() => {+ changeColType('th');+ }}+ style={{+ marginRight: 10+ }}+ title="Header"+ />++ <Button+ type={cellOptions.colType === 'td' ? 'shade' : 'grayBg'}+ icon={cellOptions.colType === 'td' && 'check'}+ height={40}+ onPress={() => {+ changeColType('td');+ }}+ style={{+ marginRight: 10+ }}+ title="Body"+ />+ </View>++ <Heading size={SIZE.md}>Cell background color</Heading>+ <ScrollView+ horizontal+ showsHorizontalScrollIndicator={false}+ style={{+ flexDirection: 'row',+ marginTop: 10+ }}>+ {editor_colors.map(item => (+ <ColorItem+ value={item}+ checked={item === cellOptions.backgroundColor}+ onCustomPress={color => {+ tiny.call(+ EditorWebView,+ `(function() {+ let node = editor.selection.getNode();+ node.style.backgroundColor = "${color}";+ tableCellNodeOptions();+ editor.fire("input");+ })()`+ );+ }}+ />+ ))}+ </ScrollView>+ </View>+ );+};diff --git a/apps/mobile/src/views/Editor/TableRowProperties.js b/apps/mobile/src/views/Editor/TableRowProperties.jsnew file mode 100644index 000000000..0d8905a7a--- /dev/null+++ b/apps/mobile/src/views/Editor/TableRowProperties.js@@ -0,0 +1,167 @@+import React, {useEffect, useState} from 'react';+import {View} from 'react-native';+import {ScrollView} from 'react-native-gesture-handler';+import {Button} from '../../components/Button';+import Heading from '../../components/Typography/Heading';+import {useTracked} from '../../provider';+import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager';+import {SIZE} from '../../utils/SizeUtils';+import {EditorWebView} from './Functions';+import tiny from './tiny/tiny';+import ColorItem from './tiny/toolbar/coloritem';+import {editor_colors} from './tiny/toolbar/constants';++export const TableRowProperties = ({data}) => {+ const [state] = useTracked();+ const {colors} = state;+ const [rowOptions, setRowOptions] = useState(data);+ console.log(data);++ const onUpdateRow = data => {+ setRowOptions(data);+ };++ useEffect(() => {+ eSubscribeEvent('updaterow', onUpdateRow);+ return () => {+ eUnSubscribeEvent('updaterow', onUpdateRow);+ };+ }, []);++ const changeRowType = type => {+ tiny.call(+ EditorWebView,+ `+ tinymce.activeEditor.execCommand('mceTableRowType', false, { type: '${type}' });+ tableRowNodeOptions();+ editor.fire("input");+ `+ );+ };++ return (+ <View+ style={{+ paddingHorizontal: 12+ }}>+ <Heading size={SIZE.md}>Row type</Heading>++ <View+ style={{+ flexDirection: 'row',+ marginVertical: 10+ }}>+ <Button+ type={rowOptions.rowType === 'header' ? 'shade' : 'grayBg'}+ icon={rowOptions.rowType === 'header' && 'check'}+ height={40}+ onPress={() => {+ changeRowType('header');+ }}+ style={{+ marginRight: 10+ }}+ title="Header"+ />++ <Button+ type={rowOptions.rowType === 'body' ? 'shade' : 'grayBg'}+ icon={rowOptions.rowType === 'body' && 'check'}+ height={40}+ onPress={() => {+ changeRowType('body');+ }}+ style={{+ marginRight: 10+ }}+ title="Body"+ />++ <Button+ type={rowOptions.rowType === 'footer' ? 'shade' : 'grayBg'}+ icon={rowOptions.rowType === 'footer' && 'check'}+ height={40}+ onPress={() => {+ changeRowType('footer');+ }}+ style={{+ marginRight: 10+ }}+ title="Footer"+ />+ </View>++ <Heading size={SIZE.md}>Row background color</Heading>+ <ScrollView+ horizontal+ showsHorizontalScrollIndicator={false}+ style={{+ flexDirection: 'row',+ marginTop: 10+ }}>+ {editor_colors.map(item => (+ <ColorItem+ value={item}+ checked={item === rowOptions.backgroundColor}+ onCustomPress={color => {+ tiny.call(+ EditorWebView,+ `(function() {+ let node = findNodeParent('tr');+ if (node) {+ node.style.backgroundColor = "${color}";+ tableRowNodeOptions();+ editor.fire("input");+ }++ })()`+ );+ }}+ />+ ))}+ </ScrollView>++ <Heading+ style={{+ marginTop: 10+ }}+ size={SIZE.md}>+ Column background color+ </Heading>+ <ScrollView+ horizontal+ showsHorizontalScrollIndicator={false}+ style={{+ flexDirection: 'row',+ marginTop: 10+ }}>+ {editor_colors.map(item => (+ <ColorItem+ value={item}+ checked={item === rowOptions.backgroundColor}+ onCustomPress={color => {+ tiny.call(+ EditorWebView,+ `(function() {+ let node = findNodeParent('table');+ if (node) {+ node.childNodes.forEach(n => {+ if (n.childNodes && n.childNodes.length > 0) {+ n.childNodes.forEach(n => {+ if (n.childNodes && n.childNodes.length > 0) {+ n.childNodes[0].style.backgroundColor = '${color}';+ }+ });+ }+ });+ }++ })()`+ );+ }}+ />+ ))}+ </ScrollView>+ </View>+ );+};diff --git a/apps/mobile/src/views/Editor/tiny/tiny.js b/apps/mobile/src/views/Editor/tiny/tiny.jsindex a44d402da..a5459b77f 100644--- a/apps/mobile/src/views/Editor/tiny/tiny.js+++ b/apps/mobile/src/views/Editor/tiny/tiny.js@@ -178,7 +178,10 @@ function call(webview, func, noqueue) {}export function safeKeyboardDismiss() {+ console.log('keyboard state', editing.keyboardState)+ if (!editing.keyboardState) return;if (Platform.OS === "android") {+textInput.current?.focus();textInput.current?.blur();} else {diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/coloritem.js b/apps/mobile/src/views/Editor/tiny/toolbar/coloritem.jsindex 3bea03b6c..6ef197738 100644--- a/apps/mobile/src/views/Editor/tiny/toolbar/coloritem.js+++ b/apps/mobile/src/views/Editor/tiny/toolbar/coloritem.js@@ -12,12 +12,13 @@ import {formatSelection, properties, rgbToHex} from './constants';import {execCommands} from './commands';import {MMKV} from '../../../../utils/mmkv';-const ColorItem = ({value, format}) => {+const ColorItem = ({value, format, onCustomPress, checked}) => {const [state] = useTracked();const {colors} = state;const [selected, setSelected] = useState(false);useEffect(() => {+ if (onCustomPress) return;eSubscribeEvent('onSelectionChange', onSelectionChange);return () => {eUnSubscribeEvent('onSelectionChange', onSelectionChange);@@ -25,6 +26,7 @@ const ColorItem = ({value, format}) => {}, [selected]);useEffect(() => {+ if (onCustomPress) return;onSelectionChange(properties.selection);}, []);@@ -52,8 +54,12 @@ const ColorItem = ({value, format}) => {};const onPress = async () => {+ if (onCustomPress) {+ onCustomPress(value);+ return;+ }if (selected) {- formatSelection(format, null);+ formatSelection(execCommands[format](''));await MMKV.removeItem(`d${format}`);} else {formatSelection(execCommands[format](value));@@ -62,29 +68,35 @@ const ColorItem = ({value, format}) => {eSendEvent('onColorChange');};+ const isNil = value === '';+ const isChecked = value !== '' && (selected || checked);+return (<TouchableOpacityonPress={onPress}activeOpacity={0.8}style={{- backgroundColor: value,+ backgroundColor: isNil ? 'transparent' : value,borderWidth: 1,borderColor: colors.nav,borderRadius: 5,height: normalize(40),width: normalize(40),- marginRight: 5+ marginRight: 5,+ overflow:'hidden'}}><Viewstyle={{- height: 40,- width: 40,+ height: "100%",+ width:"100%",borderRadius: 5,justifyContent: 'center',alignItems: 'center',- backgroundColor: selected ? 'rgba(0,0,0,0.1)' : 'transparent'+ backgroundColor: isChecked ? 'rgba(0,0,0,0.1)' : 'transparent'}}>- {selected? <Icon name="check" size={SIZE.lg} color="white" /> : null}+ {isNil ? <Icon color="red" size={SIZE.lg} name="close" /> : null}++ {isChecked ? <Icon name="check" size={SIZE.lg} color="white" /> : null}</View></TouchableOpacity>);diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/commands.js b/apps/mobile/src/views/Editor/tiny/toolbar/commands.jsindex 03714526b..16f7c2e43 100644--- a/apps/mobile/src/views/Editor/tiny/toolbar/commands.js+++ b/apps/mobile/src/views/Editor/tiny/toolbar/commands.js@@ -89,11 +89,14 @@ export const execCommands = {pre: `tinymce.activeEditor.execCommand('mceInsertCodeBlock')`,+ tablecellprops:`tableCellNodeOptions()`,tableprops: "tinymce.activeEditor.execCommand('mceTableProps');",tabledelete: "tinymce.activeEditor.execCommand('mceTableDelete');",tablesplitcell: "tinymce.activeEditor.execCommand('mceTableSplitCells');",tablemergecell: "tinymce.activeEditor.execCommand('mceTableMergeCells');",- tablerowprops: "tinymce.activeEditor.execCommand('mceTableRowProps');",+ tablerowprops: `tableRowNodeOptions()`,+ tableinsertrowbefore:`tinymce.activeEditor.execCommand('mceTableInsertRowBefore');`,+ tableinsertcolbefore:`tinymce.activeEditor.execCommand('mceTableInsertColBefore');`,imageResize25: () => setImageSize(0.25),imageResize50: () => setImageSize(0.5),imageResize100: () => setImageSize(1),diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/config.js b/apps/mobile/src/views/Editor/tiny/toolbar/config.jsindex 560eb90f8..8f1d8aabb 100644--- a/apps/mobile/src/views/Editor/tiny/toolbar/config.js+++ b/apps/mobile/src/views/Editor/tiny/toolbar/config.js@@ -6,6 +6,45 @@ import {editor_colors} from './constants';+export const TABLE_TOOLTIP_CONFIG = {+ type: 'tableconfig',+ title: 'tableconfig',+ pageX: 0,+ default: null,+ data: [+ {+ format: 'tableinsertrowbefore',+ type: 'format',+ fullname: 'Insert row before',+ premium: false+ },+ {+ format: 'tableinsertcolbefore',+ type: 'format',+ fullname: 'Insert column before',+ premium: false+ },+ {+ format: 'tablesplitcell',+ type: 'format',+ fullname: 'Split Cell',+ premium: false+ },+ {+ format: 'tablemergecell',+ type: 'format',+ fullname: 'Merge Cell',+ premium: false+ },+ {+ format: 'tabledelete',+ type: 'format',+ fullname: 'Delete table',+ premium: false+ }+ ]+};+export const IMAGE_TOOLTIP_CONFIG = {data: [{@@ -62,7 +101,6 @@ export const IMAGE_TOOLTIP_CONFIG = {};export const TOOLBAR_CONFIG = [-'seperator',[{@@ -346,72 +384,15 @@ export const TOOLBAR_CONFIG = [fullname: 'Subscript'}],-'seperator',[{format: 'table',- type: 'tooltip',+ type: 'sheet',fullname: 'Table',groupType: 'table',premium: true},- {- format: 'tableconfig',- type: 'tooltip',- fullname: 'Table',- groupType: 'tableconfig',- group: [- {- format: 'tableprops',- type: 'format',- fullname: 'Table Settings',- premium: true- },- {- format: 'tablerowprops',- type: 'format',- fullname: 'Table Row Settings',- premium: true- },- {- format: 'tablesplitcell',- type: 'format',- fullname: 'Table Split Cell',- premium: true- },- {- format: 'tablemergecell',- type: 'format',- fullname: 'Table Merge Cell',- premium: true- }- ],- premium: true- },-- {- format: 'tabledelete',- type: 'format',- fullname: 'Remove Table',- premium: true- }- ],-- 'seperator',- [- /* {- format: 'filepicker',- type: 'format',- fullname: 'Attach file',- premium: true- },- {- format: 'image',- type: 'format',- fullname: 'Image',- premium: true- }, */{format: 'video',type: 'format',diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/constants.js b/apps/mobile/src/views/Editor/tiny/toolbar/constants.jsindex 39abe2ac6..7c5ce37f7 100644--- a/apps/mobile/src/views/Editor/tiny/toolbar/constants.js+++ b/apps/mobile/src/views/Editor/tiny/toolbar/constants.js@@ -125,6 +125,7 @@ export const font_names = Platform.select({});export const editor_colors = [+ '','#000000','#e60000','#ff9900',@@ -220,12 +221,19 @@ export const TOOLBAR_ICONS = {table: 'table-plus',settings: 'cog-outline',magnify: 'magnify',- tableprops: 'table-settings',+ //tableprops: 'table-settings',+ tablecellprops: 'table-column',tabledelete: 'table-remove',tablesplitcell: 'table-split-cell',tablemergecell: 'table-merge-cells',tablerowprops: 'table-row',- tablecolumnprops: 'table-column',+ tableinsertrowbefore: 'table-row-plus-before',+ tableinsertrowafter: 'table-row-plus-after',+ tabledeleterow: 'table-row-remove',+ tableinsertcolbefore: 'table-column-plus-before',+ tableinsertcolafter: 'table-column-plus-after',+ tabledeletecol: 'table-column-remove',+ //tablecolumnprops: 'table-column',tableconfig: 'table-cog',imagepreview: 'fullscreen',removeimage: 'delete',@@ -234,7 +242,7 @@ export const TOOLBAR_ICONS = {imagefloatnone: 'format-float-none','line-break': 'keyboard-return',code: 'code-tags',- filepicker:'attachment',- undo:'undo-variant',- redo:'redo-variant'+ filepicker: 'attachment',+ undo: 'undo-variant',+ redo: 'redo-variant'};diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/item.js b/apps/mobile/src/views/Editor/tiny/toolbar/item.jsindex 3f237d113..f5b8f4434 100644--- a/apps/mobile/src/views/Editor/tiny/toolbar/item.js+++ b/apps/mobile/src/views/Editor/tiny/toolbar/item.js@@ -8,7 +8,7 @@ import { useTracked } from '../../../../provider';import { useUserStore } from '../../../../provider/stores';import {eSendEvent, eSubscribeEvent,- eUnSubscribeEvent, ToastEvent+ eUnSubscribeEvent, presentSheet, ToastEvent} from '../../../../services/EventManager';import PremiumService from '../../../../services/PremiumService';import { editing, showTooltip, TOOLTIP_POSITIONS } from '../../../../utils';@@ -23,6 +23,7 @@ import {} from './constants';import ToolbarItemPin from './itempin';import ToolbarListFormat from './listformat';+import { Table } from './table';const ToolbarItem = ({format,@@ -201,6 +202,8 @@ const ToolbarItem = ({checkForChanges(data);};++const onPress = async event => {if (premium && !isPro) {let user = await db.user.getUser();@@ -215,6 +218,15 @@ const ToolbarItem = ({}return;}++ if (format === 'table') {+ presentSheet({+ noProgress:true,+ noIcon:true,+ component:<Table/>+ })+ }+if (type === 'settings') {if (editing.isFocused) {safeKeyboardDismiss();diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/table.js b/apps/mobile/src/views/Editor/tiny/toolbar/table.jsnew file mode 100644index 000000000..9e7956a66--- /dev/null+++ b/apps/mobile/src/views/Editor/tiny/toolbar/table.js@@ -0,0 +1,89 @@+import React, {useState} from 'react';+import {View} from 'react-native';+import {PressableButton} from '../../../../components/PressableButton';+import Heading from '../../../../components/Typography/Heading';+import Paragraph from '../../../../components/Typography/Paragraph';+import {useTracked} from '../../../../provider';+import {eSendEvent} from '../../../../services/EventManager';+import {eCloseProgressDialog} from '../../../../utils/Events';+import {SIZE} from '../../../../utils/SizeUtils';+import {execCommands} from './commands';+import {formatSelection} from './constants';++export const Table = () => {+ const [state] = useTracked();+ const {colors} = state;+ const [width, setWidth] = useState(400);+ const itemWidth = width / 5;++ const rightCells = [5, 10, 15, 20, 25];+ const bottomCells = [21, 22, 23, 24, 25];+ const cells = [+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,+ 22, 23, 24, 25+ ];++ function getRowColumns(index) {+ let columnCount = 5;+ let rowNumber = Math.floor(index / columnCount);+ let columnNumber = index - rowNumber * columnCount;++ return `${rowNumber + 1} x ${columnNumber + 1}`;+ }++ return (+ <View+ onLayout={e => {+ setWidth(e.nativeEvent.layout.width - 24);+ }}+ style={{+ paddingHorizontal: 12+ }}>+ <Heading size={SIZE.md}>Select rows x columns</Heading>++ <View+ style={{+ flexDirection: 'row',+ flexWrap: 'wrap',+ zIndex: 10,+ width: '100%',+ justifyContent: 'center',+ marginTop: 10+ }}>+ {cells.map((item, index) => (+ <PressableButton+ key={item.toString()}+ onPress={() => {+ let columnCount = 5;+ let rowNumber = Math.floor(index / columnCount);+ let columnNumber = index - rowNumber * columnCount;+ formatSelection(+ execCommands.table(rowNumber + 1, columnNumber + 1)+ );+ eSendEvent(eCloseProgressDialog);+ }}+ type="gray"+ customStyle={{+ width: itemWidth,+ height: 35,+ borderWidth: 1,+ borderColor: colors.border,+ marginHorizontal: 0,+ marginVertical: 0,+ borderRadius: 0,+ borderBottomWidth: bottomCells.includes(item) ? 1 : 0,+ borderRightWidth: rightCells.includes(item) ? 1 : 0,+ borderTopLeftRadius: item === 1 ? 5 : 0,+ borderTopRightRadius: item === 5 ? 5 : 0,+ borderBottomLeftRadius: item === 21 ? 5 : 0,+ borderBottomRightRadius: item === 25 ? 5 : 0+ }}>+ <Paragraph size={SIZE.sm} color={colors.pri}>+ {getRowColumns(index)}+ </Paragraph>+ </PressableButton>+ ))}+ </View>+ </View>+ );+};