Merge pull request #1841 from ONLYOFFICE/feature/fix-bugs
Feature/fix bugs
This commit is contained in:
commit
b6bda16dad
|
@ -31,7 +31,8 @@ import { Device } from '../../../../common/mobile/utils/device';
|
||||||
"storeChartSettings",
|
"storeChartSettings",
|
||||||
"storeApplicationSettings",
|
"storeApplicationSettings",
|
||||||
"storeLinkSettings",
|
"storeLinkSettings",
|
||||||
"storeToolbarSettings"
|
"storeToolbarSettings",
|
||||||
|
"storeNavigation"
|
||||||
)
|
)
|
||||||
class MainController extends Component {
|
class MainController extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
@ -750,6 +751,12 @@ class MainController extends Component {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.api.asc_registerCallback('asc_onReplaceAll', this.onApiTextReplaced.bind(this));
|
this.api.asc_registerCallback('asc_onReplaceAll', this.onApiTextReplaced.bind(this));
|
||||||
|
|
||||||
|
const storeNavigation = this.props.storeNavigation;
|
||||||
|
|
||||||
|
this.api.asc_registerCallback('asc_onViewerBookmarksUpdate', (bookmarks) => {
|
||||||
|
storeNavigation.initBookmarks(bookmarks);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onApiTextReplaced(found, replaced) {
|
onApiTextReplaced(found, replaced) {
|
||||||
|
|
|
@ -9,6 +9,46 @@ class NavigationController extends Component {
|
||||||
this.updateNavigation = this.updateNavigation.bind(this);
|
this.updateNavigation = this.updateNavigation.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateViewerNavigation(bookmarks) {
|
||||||
|
let count = bookmarks.length,
|
||||||
|
prevLevel = -1,
|
||||||
|
headerLevel = -1,
|
||||||
|
firstHeader = true,
|
||||||
|
arrHeaders = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < count; i++) {
|
||||||
|
let level = bookmarks[i].level - 1,
|
||||||
|
hasParent = true;
|
||||||
|
|
||||||
|
if (level > prevLevel && i > 0)
|
||||||
|
arrHeaders[i - 1]['hasSubItems'] = true;
|
||||||
|
|
||||||
|
if (headerLevel < 0 || level <= headerLevel) {
|
||||||
|
if (i > 0 || firstHeader)
|
||||||
|
headerLevel = level;
|
||||||
|
hasParent = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
arrHeaders.push({
|
||||||
|
name: bookmarks[i].description,
|
||||||
|
level: level,
|
||||||
|
index: i,
|
||||||
|
hasParent: hasParent,
|
||||||
|
isEmptyItem: !bookmarks[i].description
|
||||||
|
});
|
||||||
|
|
||||||
|
prevLevel = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count > 0 && !firstHeader) {
|
||||||
|
arrHeaders[0]['hasSubItems'] = false;
|
||||||
|
arrHeaders[0]['isNotHeader'] = true;
|
||||||
|
arrHeaders[0]['name'] = t('Settings.textBeginningDocument');
|
||||||
|
}
|
||||||
|
|
||||||
|
return arrHeaders;
|
||||||
|
}
|
||||||
|
|
||||||
updateNavigation() {
|
updateNavigation() {
|
||||||
const api = Common.EditorApi.get();
|
const api = Common.EditorApi.get();
|
||||||
const navigationObject = api.asc_ShowDocumentOutline();
|
const navigationObject = api.asc_ShowDocumentOutline();
|
||||||
|
@ -60,6 +100,8 @@ class NavigationController extends Component {
|
||||||
|
|
||||||
if (navigationObject) {
|
if (navigationObject) {
|
||||||
navigationObject.goto(index);
|
navigationObject.goto(index);
|
||||||
|
} else {
|
||||||
|
api.asc_viewerNavigateTo(index);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -69,11 +111,13 @@ class NavigationController extends Component {
|
||||||
<NavigationPopover
|
<NavigationPopover
|
||||||
onSelectItem={this.onSelectItem}
|
onSelectItem={this.onSelectItem}
|
||||||
updateNavigation={this.updateNavigation}
|
updateNavigation={this.updateNavigation}
|
||||||
|
updateViewerNavigation={this.updateViewerNavigation}
|
||||||
/>
|
/>
|
||||||
:
|
:
|
||||||
<NavigationSheet
|
<NavigationSheet
|
||||||
onSelectItem={this.onSelectItem}
|
onSelectItem={this.onSelectItem}
|
||||||
updateNavigation={this.updateNavigation}
|
updateNavigation={this.updateNavigation}
|
||||||
|
updateViewerNavigation={this.updateViewerNavigation}
|
||||||
onclosed={this.props.onclosed}
|
onclosed={this.props.onclosed}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
|
@ -16,6 +16,7 @@ import {storePalette} from "./palette";
|
||||||
import {storeReview} from '../../../../common/mobile/lib/store/review';
|
import {storeReview} from '../../../../common/mobile/lib/store/review';
|
||||||
import {storeComments} from "../../../../common/mobile/lib/store/comments";
|
import {storeComments} from "../../../../common/mobile/lib/store/comments";
|
||||||
import {storeToolbarSettings} from "./toolbar";
|
import {storeToolbarSettings} from "./toolbar";
|
||||||
|
import { storeNavigation } from './navigation';
|
||||||
|
|
||||||
export const stores = {
|
export const stores = {
|
||||||
storeAppOptions: new storeAppOptions(),
|
storeAppOptions: new storeAppOptions(),
|
||||||
|
@ -35,5 +36,6 @@ export const stores = {
|
||||||
storeReview: new storeReview(),
|
storeReview: new storeReview(),
|
||||||
storeComments: new storeComments(),
|
storeComments: new storeComments(),
|
||||||
storeToolbarSettings: new storeToolbarSettings(),
|
storeToolbarSettings: new storeToolbarSettings(),
|
||||||
|
storeNavigation: new storeNavigation()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
16
apps/documenteditor/mobile/src/store/navigation.js
Normal file
16
apps/documenteditor/mobile/src/store/navigation.js
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import {action, observable, makeObservable} from 'mobx';
|
||||||
|
|
||||||
|
export class storeNavigation {
|
||||||
|
constructor() {
|
||||||
|
makeObservable(this, {
|
||||||
|
bookmarks: observable,
|
||||||
|
initBookmarks: action
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
bookmarks = [];
|
||||||
|
|
||||||
|
initBookmarks(bookmarks) {
|
||||||
|
this.bookmarks = bookmarks;
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,17 +2,22 @@ import React, { useState, useEffect } from "react";
|
||||||
import { Device } from '../../../../../common/mobile/utils/device';
|
import { Device } from '../../../../../common/mobile/utils/device';
|
||||||
import {f7, View, List, ListItem, Icon, Row, Button, Page, Navbar, NavRight, Segmented, BlockTitle, Link, ListButton, Toggle, Actions, ActionsButton, ActionsGroup, Sheet} from 'framework7-react';
|
import {f7, View, List, ListItem, Icon, Row, Button, Page, Navbar, NavRight, Segmented, BlockTitle, Link, ListButton, Toggle, Actions, ActionsButton, ActionsGroup, Sheet} from 'framework7-react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { inject, observer } from "mobx-react";
|
||||||
|
|
||||||
const NavigationPopover = props => {
|
const NavigationPopover = inject('storeNavigation')(observer(props => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const _t = t('Settings', {returnObjects: true});
|
const _t = t('Settings', {returnObjects: true});
|
||||||
const api = Common.EditorApi.get();
|
const api = Common.EditorApi.get();
|
||||||
|
const storeNavigation = props.storeNavigation;
|
||||||
|
const bookmarks = storeNavigation.bookmarks;
|
||||||
const navigationObject = api.asc_ShowDocumentOutline();
|
const navigationObject = api.asc_ShowDocumentOutline();
|
||||||
const [currentPosition, setCurrentPosition] = useState(navigationObject ? navigationObject.get_CurrentPosition() : null);
|
const [currentPosition, setCurrentPosition] = useState(navigationObject ? navigationObject.get_CurrentPosition() : bookmarks.length ? bookmarks[0] : null);
|
||||||
let arrHeaders = [];
|
let arrHeaders = [];
|
||||||
|
|
||||||
if(currentPosition) {
|
if(navigationObject) {
|
||||||
arrHeaders = props.updateNavigation();
|
arrHeaders = props.updateNavigation();
|
||||||
|
} else if(bookmarks.length) {
|
||||||
|
arrHeaders = props.updateViewerNavigation(bookmarks);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -37,17 +42,21 @@ const NavigationPopover = props => {
|
||||||
}
|
}
|
||||||
</Page>
|
</Page>
|
||||||
)
|
)
|
||||||
}
|
}));
|
||||||
|
|
||||||
const NavigationSheet = props => {
|
const NavigationSheet = inject('storeNavigation')(observer(props => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const api = Common.EditorApi.get();
|
const api = Common.EditorApi.get();
|
||||||
|
const storeNavigation = props.storeNavigation;
|
||||||
|
const bookmarks = storeNavigation.bookmarks;
|
||||||
const navigationObject = api.asc_ShowDocumentOutline();
|
const navigationObject = api.asc_ShowDocumentOutline();
|
||||||
const [currentPosition, setCurrentPosition] = useState(navigationObject ? navigationObject.get_CurrentPosition() : null);
|
const [currentPosition, setCurrentPosition] = useState(navigationObject ? navigationObject.get_CurrentPosition() : bookmarks.length ? bookmarks[0] : null);
|
||||||
let arrHeaders = [];
|
let arrHeaders = [];
|
||||||
|
|
||||||
if(currentPosition) {
|
if(navigationObject) {
|
||||||
arrHeaders = props.updateNavigation();
|
arrHeaders = props.updateNavigation();
|
||||||
|
} else if(bookmarks.length) {
|
||||||
|
arrHeaders = props.updateViewerNavigation(bookmarks);
|
||||||
}
|
}
|
||||||
|
|
||||||
const [stateHeight, setHeight] = useState('45%');
|
const [stateHeight, setHeight] = useState('45%');
|
||||||
|
@ -122,7 +131,7 @@ const NavigationSheet = props => {
|
||||||
}
|
}
|
||||||
</Sheet>
|
</Sheet>
|
||||||
)
|
)
|
||||||
}
|
}));
|
||||||
|
|
||||||
export {
|
export {
|
||||||
NavigationPopover,
|
NavigationPopover,
|
||||||
|
|
|
@ -48,7 +48,7 @@ const PageApplicationSettings = props => {
|
||||||
</ListItem>
|
</ListItem>
|
||||||
<ListItem title={t('View.Settings.textDarkTheme')}>
|
<ListItem title={t('View.Settings.textDarkTheme')}>
|
||||||
<Toggle checked={isThemeDark}
|
<Toggle checked={isThemeDark}
|
||||||
onToggleChange={toggle => {Themes.switchDarkTheme(!toggle), setIsThemeDark(!toggle)}}>
|
onToggleChange={() => {Themes.switchDarkTheme(!isThemeDark), setIsThemeDark(!isThemeDark)}}>
|
||||||
</Toggle>
|
</Toggle>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
</List>
|
</List>
|
||||||
|
|
|
@ -93,7 +93,7 @@ const PageApplicationSettings = props => {
|
||||||
</ListItem>
|
</ListItem>
|
||||||
<ListItem title={t('View.Settings.textDarkTheme')}>
|
<ListItem title={t('View.Settings.textDarkTheme')}>
|
||||||
<Toggle checked={isThemeDark}
|
<Toggle checked={isThemeDark}
|
||||||
onToggleChange={toggle => {Themes.switchDarkTheme(!toggle), setIsThemeDark(!toggle)}}>
|
onToggleChange={() => {Themes.switchDarkTheme(!isThemeDark), setIsThemeDark(!isThemeDark)}}>
|
||||||
</Toggle>
|
</Toggle>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
</List>
|
</List>
|
||||||
|
|
Loading…
Reference in a new issue