2021-09-07 09:23:59 +00:00
|
|
|
import React, {Fragment, useState, useEffect} from 'react';
|
2021-02-09 18:42:00 +00:00
|
|
|
import {observer, inject} from "mobx-react";
|
2021-05-18 10:46:26 +00:00
|
|
|
import {f7, List, ListItem, Icon, Row, Button, Page, Navbar, NavRight, Segmented, BlockTitle, Link} from 'framework7-react';
|
2021-02-09 18:42:00 +00:00
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import {Device} from '../../../../../common/mobile/utils/device';
|
|
|
|
import { ThemeColorPalette, CustomColorPicker } from '../../../../../common/mobile/lib/component/ThemeColorPalette.jsx';
|
2021-08-13 13:11:40 +00:00
|
|
|
import { LocalStorage } from '../../../../../common/mobile/utils/LocalStorage';
|
2021-02-09 18:42:00 +00:00
|
|
|
|
|
|
|
const EditText = props => {
|
|
|
|
const isAndroid = Device.android;
|
|
|
|
const { t } = useTranslation();
|
|
|
|
const _t = t('View.Edit', {returnObjects: true});
|
|
|
|
const storeTextSettings = props.storeTextSettings;
|
|
|
|
const textIn = storeTextSettings.textIn;
|
|
|
|
|
|
|
|
const fontName = storeTextSettings.fontName || _t.textFonts;
|
|
|
|
const fontSize = storeTextSettings.fontSize;
|
|
|
|
const fontColor = storeTextSettings.textColor;
|
|
|
|
|
|
|
|
const displaySize = typeof fontSize === 'undefined' ? _t.textAuto : fontSize + ' ' + _t.textPt;
|
|
|
|
const isBold = storeTextSettings.isBold;
|
|
|
|
const isItalic = storeTextSettings.isItalic;
|
|
|
|
const isUnderline = storeTextSettings.isUnderline;
|
|
|
|
const paragraphAlign = storeTextSettings.paragraphAlign;
|
|
|
|
const paragraphValign = storeTextSettings.paragraphValign;
|
|
|
|
|
|
|
|
const fontColorPreview = fontColor !== 'auto' ?
|
|
|
|
<span className="color-preview" style={{ background: `#${(typeof fontColor === "object" ? fontColor.color : fontColor)}`}}></span> :
|
|
|
|
<span className="color-preview auto"></span>;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<List>
|
|
|
|
<ListItem title={fontName} link="/edit-text-fonts/" after={displaySize} routeProps={{
|
|
|
|
changeFontSize: props.changeFontSize,
|
2021-08-13 14:59:31 +00:00
|
|
|
changeFontFamily: props.changeFontFamily
|
2021-02-09 18:42:00 +00:00
|
|
|
}}/>
|
|
|
|
<ListItem className='buttons'>
|
|
|
|
<Row>
|
|
|
|
<a className={'button' + (isBold ? ' active' : '')} onClick={() => {props.toggleBold(!isBold)}}><b>B</b></a>
|
|
|
|
<a className={'button' + (isItalic ? ' active' : '')} onClick={() => {props.toggleItalic(!isItalic)}}><i>I</i></a>
|
|
|
|
<a className={'button' + (isUnderline ? ' active' : '')} onClick={() => {props.toggleUnderline(!isUnderline)}} style={{textDecoration: "underline"}}>U</a>
|
|
|
|
</Row>
|
|
|
|
</ListItem>
|
|
|
|
<ListItem title={_t.textTextColor} link="/edit-text-font-color/" routeProps={{
|
|
|
|
onTextColor: props.onTextColor
|
|
|
|
}}>
|
|
|
|
{!isAndroid ?
|
|
|
|
<Icon slot="media" icon="icon-text-color">{fontColorPreview}</Icon> :
|
|
|
|
fontColorPreview
|
|
|
|
}
|
|
|
|
</ListItem>
|
|
|
|
</List>
|
|
|
|
{textIn === 2 ? (
|
|
|
|
<Fragment>
|
|
|
|
<List>
|
|
|
|
<ListItem className='buttons'>
|
|
|
|
<Row>
|
|
|
|
<a className={'button' + (paragraphAlign === AscCommon.align_Left ? ' active' : '')} onClick={() => {props.onParagraphAlign('left')}}>
|
|
|
|
<Icon slot="media" icon="icon-text-align-left"></Icon>
|
|
|
|
</a>
|
|
|
|
<a className={'button' + (paragraphAlign === AscCommon.align_Center ? ' active' : '')} onClick={() => {props.onParagraphAlign('center')}}>
|
|
|
|
<Icon slot="media" icon="icon-text-align-center"></Icon>
|
|
|
|
</a>
|
|
|
|
<a className={'button' + (paragraphAlign === AscCommon.align_Right ? ' active' : '')} onClick={() => {props.onParagraphAlign('right')}}>
|
|
|
|
<Icon slot="media" icon="icon-text-align-right"></Icon>
|
|
|
|
</a>
|
|
|
|
<a className={'button' + (paragraphAlign === AscCommon.align_Justify ? ' active' : '')} onClick={() => {props.onParagraphAlign('justify')}}>
|
|
|
|
<Icon slot="media" icon="icon-text-align-jast"></Icon>
|
|
|
|
</a>
|
|
|
|
</Row>
|
|
|
|
</ListItem>
|
|
|
|
<ListItem className='buttons'>
|
|
|
|
<Row>
|
|
|
|
<a className={'button' + (paragraphValign === Asc.c_oAscVAlign.Top ? ' active' : '')} onClick={() => {props.onParagraphValign('top')}}>
|
|
|
|
<Icon slot="media" icon="icon-text-valign-top"></Icon>
|
|
|
|
</a>
|
|
|
|
<a className={'button' + (paragraphValign === Asc.c_oAscVAlign.Center ? ' active' : '')} onClick={() => {props.onParagraphValign('center')}}>
|
|
|
|
<Icon slot="media" icon="icon-text-valign-middle"></Icon>
|
|
|
|
</a>
|
|
|
|
<a className={'button' + (paragraphValign === Asc.c_oAscVAlign.Bottom ? ' active' : '')} onClick={() => {props.onParagraphValign('bottom')}}>
|
|
|
|
<Icon slot="media" icon="icon-text-valign-bottom"></Icon>
|
|
|
|
</a>
|
|
|
|
</Row>
|
|
|
|
</ListItem>
|
|
|
|
</List>
|
|
|
|
</Fragment>
|
|
|
|
) : null}
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const PageFonts = props => {
|
|
|
|
const isAndroid = Device.android;
|
|
|
|
const { t } = useTranslation();
|
|
|
|
const _t = t('View.Edit', {returnObjects: true});
|
|
|
|
const storeTextSettings = props.storeTextSettings;
|
|
|
|
const size = storeTextSettings.fontSize;
|
|
|
|
const displaySize = typeof size === 'undefined' ? _t.textAuto : size + ' ' + _t.textPt;
|
|
|
|
const curFontName = storeTextSettings.fontName;
|
|
|
|
const fonts = storeTextSettings.fontsArray;
|
2021-08-13 14:59:31 +00:00
|
|
|
const iconWidth = storeTextSettings.iconWidth;
|
|
|
|
const iconHeight = storeTextSettings.iconHeight;
|
|
|
|
const thumbs = storeTextSettings.thumbs;
|
|
|
|
const thumbIdx = storeTextSettings.thumbIdx;
|
|
|
|
const thumbCanvas = storeTextSettings.thumbCanvas;
|
|
|
|
const thumbContext = storeTextSettings.thumbContext;
|
|
|
|
const spriteCols = storeTextSettings.spriteCols;
|
|
|
|
const spriteThumbs = storeTextSettings.spriteThumbs;
|
2021-08-16 14:57:38 +00:00
|
|
|
const arrayRecentFonts = storeTextSettings.arrayRecentFonts;
|
2021-02-09 18:42:00 +00:00
|
|
|
|
2021-09-07 09:23:59 +00:00
|
|
|
useEffect(() => {
|
|
|
|
setRecent(getImageUri(arrayRecentFonts));
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
}
|
|
|
|
}, []);
|
|
|
|
|
2021-08-13 14:26:36 +00:00
|
|
|
const addRecentStorage = () => {
|
|
|
|
let arr = [];
|
2021-08-16 14:57:38 +00:00
|
|
|
arrayRecentFonts.forEach(item => arr.push(item));
|
2021-09-07 09:23:59 +00:00
|
|
|
setRecent(getImageUri(arrayRecentFonts));
|
2021-08-16 14:57:38 +00:00
|
|
|
LocalStorage.setItem('sse-settings-recent-fonts', JSON.stringify(arr));
|
2021-08-13 14:26:36 +00:00
|
|
|
}
|
2021-02-09 18:42:00 +00:00
|
|
|
|
2021-09-07 09:23:59 +00:00
|
|
|
const [stateRecent, setRecent] = useState([]);
|
2021-02-09 18:42:00 +00:00
|
|
|
const [vlFonts, setVlFonts] = useState({
|
|
|
|
vlData: {
|
|
|
|
items: [],
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-09-07 09:23:59 +00:00
|
|
|
const getImageUri = fonts => {
|
|
|
|
return fonts.map(font => {
|
|
|
|
thumbContext.clearRect(0, 0, thumbs[thumbIdx].width, thumbs[thumbIdx].height);
|
|
|
|
thumbContext.drawImage(spriteThumbs, 0, -thumbs[thumbIdx].height * Math.floor(font.imgidx / spriteCols));
|
|
|
|
|
|
|
|
return thumbCanvas.toDataURL();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-02-09 18:42:00 +00:00
|
|
|
const renderExternal = (vl, vlData) => {
|
|
|
|
setVlFonts((prevState) => {
|
|
|
|
let fonts = [...prevState.vlData.items];
|
|
|
|
fonts.splice(vlData.fromIndex, vlData.toIndex, ...vlData.items);
|
2021-09-07 09:23:59 +00:00
|
|
|
|
|
|
|
let images = getImageUri(fonts);
|
|
|
|
|
2021-02-09 18:42:00 +00:00
|
|
|
return {vlData: {
|
|
|
|
items: fonts,
|
2021-09-07 09:23:59 +00:00
|
|
|
images,
|
2021-02-09 18:42:00 +00:00
|
|
|
}};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Page>
|
2021-05-18 10:46:26 +00:00
|
|
|
<Navbar title={_t.textFonts} backLink={_t.textBack}>
|
|
|
|
{Device.phone &&
|
|
|
|
<NavRight>
|
|
|
|
<Link icon='icon-expand-down' sheetClose></Link>
|
|
|
|
</NavRight>
|
|
|
|
}
|
|
|
|
</Navbar>
|
2021-02-09 18:42:00 +00:00
|
|
|
<List>
|
|
|
|
<ListItem title={_t.textSize}>
|
|
|
|
{!isAndroid && <div slot='after-start'>{displaySize}</div>}
|
|
|
|
<div slot='after'>
|
|
|
|
<Segmented>
|
|
|
|
<Button outline className='decrement item-link' onClick={() => {props.changeFontSize(size, true)}}>
|
|
|
|
{isAndroid ? <Icon icon="icon-expand-down"></Icon> : ' - '}
|
|
|
|
</Button>
|
|
|
|
{isAndroid && <label>{displaySize}</label>}
|
|
|
|
<Button outline className='increment item-link' onClick={() => {props.changeFontSize(size, false)}}>
|
|
|
|
{isAndroid ? <Icon icon="icon-expand-up"></Icon> : ' + '}
|
|
|
|
</Button>
|
|
|
|
</Segmented>
|
|
|
|
</div>
|
|
|
|
</ListItem>
|
|
|
|
</List>
|
|
|
|
<BlockTitle>{_t.textFonts}</BlockTitle>
|
2021-08-16 14:57:38 +00:00
|
|
|
{!!arrayRecentFonts.length &&
|
2021-08-13 13:11:40 +00:00
|
|
|
<List>
|
2021-08-16 14:57:38 +00:00
|
|
|
{arrayRecentFonts.map((item, index) => (
|
|
|
|
<ListItem className="font-item" key={index} radio checked={curFontName === item.name} onClick={() => {
|
|
|
|
props.changeFontFamily(item.name);
|
|
|
|
}}>
|
2021-09-07 09:23:59 +00:00
|
|
|
<img src={stateRecent[index]} style={{width: `${iconWidth}px`, height: `${iconHeight}px`}} />
|
2021-08-16 14:57:38 +00:00
|
|
|
</ListItem>
|
2021-08-13 13:11:40 +00:00
|
|
|
))}
|
|
|
|
</List>
|
|
|
|
}
|
2021-02-09 18:42:00 +00:00
|
|
|
<List virtualList virtualListParams={{
|
|
|
|
items: fonts,
|
|
|
|
renderExternal: renderExternal
|
|
|
|
}}>
|
|
|
|
<ul>
|
|
|
|
{vlFonts.vlData.items.map((item, index) => (
|
2021-08-11 14:47:57 +00:00
|
|
|
<ListItem className="font-item" key={index} radio checked={curFontName === item.name} onClick={() => {
|
2021-08-16 14:57:38 +00:00
|
|
|
props.changeFontFamily(item.name);
|
|
|
|
storeTextSettings.addFontToRecent(item);
|
|
|
|
addRecentStorage();
|
2021-08-11 14:47:57 +00:00
|
|
|
}}>
|
2021-09-07 09:23:59 +00:00
|
|
|
<img src={vlFonts.vlData.images[index]} style={{width: `${iconWidth}px`, height: `${iconHeight}px`}} />
|
2021-08-11 14:47:57 +00:00
|
|
|
</ListItem>
|
2021-02-09 18:42:00 +00:00
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</List>
|
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const PageFontColor = props => {
|
|
|
|
const { t } = useTranslation();
|
|
|
|
const _t = t('View.Edit', {returnObjects: true});
|
|
|
|
const storeTextSettings = props.storeTextSettings;
|
|
|
|
const storePalette = props.storePalette;
|
|
|
|
const textColor = storeTextSettings.textColor;
|
|
|
|
const customColors = storePalette.customColors;
|
|
|
|
|
|
|
|
const changeColor = (color, effectId, effectValue) => {
|
|
|
|
if (color !== 'empty') {
|
|
|
|
if (effectId !== undefined) {
|
|
|
|
const newColor = {color: color, effectId: effectId, effectValue: effectValue};
|
|
|
|
props.onTextColor(newColor);
|
2021-02-17 11:28:02 +00:00
|
|
|
storeTextSettings.changeTextColor(newColor);
|
2021-02-09 18:42:00 +00:00
|
|
|
} else {
|
|
|
|
props.onTextColor(color);
|
2021-02-17 11:28:02 +00:00
|
|
|
storeTextSettings.changeTextColor(color);
|
2021-02-09 18:42:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// open custom color menu
|
2021-03-30 13:19:20 +00:00
|
|
|
props.f7router.navigate('/edit-text-custom-font-color/', {props: {onTextColor: props.onTextColor}});
|
2021-02-09 18:42:00 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Page>
|
2021-05-18 10:46:26 +00:00
|
|
|
<Navbar title={_t.textTextColor} backLink={_t.textBack}>
|
|
|
|
{Device.phone &&
|
|
|
|
<NavRight>
|
|
|
|
<Link icon='icon-expand-down' sheetClose></Link>
|
|
|
|
</NavRight>
|
|
|
|
}
|
|
|
|
</Navbar>
|
2021-02-09 18:42:00 +00:00
|
|
|
<ThemeColorPalette changeColor={changeColor} curColor={textColor} customColors={customColors} />
|
|
|
|
<List>
|
|
|
|
<ListItem title={_t.textAddCustomColor} link={'/edit-text-custom-font-color/'} routeProps={{
|
|
|
|
onTextColor: props.onTextColor
|
|
|
|
}}></ListItem>
|
|
|
|
</List>
|
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const PageCustomFontColor = props => {
|
|
|
|
const { t } = useTranslation();
|
|
|
|
const _t = t('View.Edit', {returnObjects: true});
|
|
|
|
const storeTextSettings = props.storeTextSettings;
|
|
|
|
const storePalette = props.storePalette;
|
|
|
|
let textColor = storeTextSettings.textColor;
|
|
|
|
|
|
|
|
if (typeof textColor === 'object') {
|
|
|
|
textColor = textColor.color;
|
|
|
|
}
|
|
|
|
|
|
|
|
const autoColor = textColor === 'auto' ? window.getComputedStyle(document.getElementById('font-color-auto')).backgroundColor : null;
|
|
|
|
|
|
|
|
const onAddNewColor = (colors, color) => {
|
|
|
|
storePalette.changeCustomColors(colors);
|
|
|
|
storeTextSettings.changeTextColor(color);
|
|
|
|
props.onTextColor(color);
|
|
|
|
props.f7router.back();
|
|
|
|
};
|
|
|
|
return (
|
|
|
|
<Page>
|
2021-05-18 10:46:26 +00:00
|
|
|
<Navbar title={_t.textCustomColor} backLink={_t.textBack}>
|
|
|
|
{Device.phone &&
|
|
|
|
<NavRight>
|
|
|
|
<Link icon='icon-expand-down' sheetClose></Link>
|
|
|
|
</NavRight>
|
|
|
|
}
|
|
|
|
</Navbar>
|
2021-02-09 18:42:00 +00:00
|
|
|
<CustomColorPicker autoColor={autoColor} currentColor={textColor} onAddNewColor={onAddNewColor}/>
|
|
|
|
</Page>
|
|
|
|
)
|
|
|
|
};
|
|
|
|
|
|
|
|
const EditTextContainer = inject("storeTextSettings", "storeFocusObjects")(observer(EditText));
|
|
|
|
const PageTextFonts = inject("storeTextSettings", "storeFocusObjects")(observer(PageFonts));
|
|
|
|
const PageTextFontColor = inject("storeTextSettings", "storePalette")(observer(PageFontColor));
|
|
|
|
const PageTextCustomFontColor = inject("storeTextSettings", "storePalette")(observer(PageCustomFontColor));
|
|
|
|
|
|
|
|
export {
|
|
|
|
EditTextContainer as EditText,
|
|
|
|
PageTextFonts,
|
|
|
|
PageTextFontColor,
|
|
|
|
PageTextCustomFontColor
|
|
|
|
};
|