import React, {Fragment, useState, useEffect} from 'react'; import {observer, inject} from "mobx-react"; import {f7, List, ListItem, Icon, Row, Button, Page, Navbar, Segmented, BlockTitle, NavRight, Link, Toggle} from 'framework7-react'; import { useTranslation } from 'react-i18next'; import {Device} from '../../../../../common/mobile/utils/device'; import { ThemeColorPalette, CustomColorPicker } from '../../../../../common/mobile/lib/component/ThemeColorPalette.jsx'; import { LocalStorage } from '../../../../../common/mobile/utils/LocalStorage'; const EditCell = props => { const isAndroid = Device.android; const { t } = useTranslation(); const _t = t('View.Edit', {returnObjects: true}); const storeCellSettings = props.storeCellSettings; const storeWorksheets = props.storeWorksheets; const wsProps = storeWorksheets.wsProps; const cellStyles = storeCellSettings.cellStyles; const styleName = storeCellSettings.styleName; const fontInfo = storeCellSettings.fontInfo; const fontName = fontInfo.name || _t.textFonts; const fontSize = fontInfo.size; const fontColor = storeCellSettings.fontColor; const displaySize = typeof fontSize === 'undefined' ? _t.textAuto : fontSize + ' ' + _t.textPt; const fillColor = storeCellSettings.fillColor; const isBold = storeCellSettings.isBold; const isItalic = storeCellSettings.isItalic; const isUnderline = storeCellSettings.isUnderline; const fontColorPreview = fontColor !== 'auto' ? : ; const fillColorPreview = fillColor !== 'transparent' ? : ; return ( {!wsProps.FormatCells && <> {props.toggleBold(!isBold)}}>B {props.toggleItalic(!isItalic)}}>I {props.toggleUnderline(!isUnderline)}} style={{textDecoration: "underline"}}>U {!isAndroid ? {fontColorPreview} : fontColorPreview } {!isAndroid ? {fillColorPreview} : fillColorPreview } {!isAndroid ? : null } {!isAndroid ? : null } {!isAndroid ? : null } {!isAndroid ? : null } {_t.textCellStyles} {cellStyles.length ? ( {cellStyles.map((elem, index) => { return ( props.onStyleClick(elem.name)}> ) })} ) : null} >} ) }; const PageFontsCell = props => { const isAndroid = Device.android; const { t } = useTranslation(); const _t = t('View.Edit', {returnObjects: true}); const storeTextSettings = props.storeTextSettings; const storeCellSettings = props.storeCellSettings; const fontInfo = storeCellSettings.fontInfo; const size = fontInfo.size; const displaySize = typeof size === 'undefined' ? _t.textAuto : size + ' ' + _t.textPt; const curFontName = fontInfo.name; const fonts = storeCellSettings.fontsArray; const arrayRecentFonts = storeTextSettings.arrayRecentFonts; 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; useEffect(() => { setRecent(getImageUri(arrayRecentFonts)); return () => { } }, []); const addRecentStorage = () => { let arr = []; arrayRecentFonts.forEach(item => arr.push(item)); setRecent(getImageUri(arrayRecentFonts)); LocalStorage.setItem('sse-settings-recent-fonts', JSON.stringify(arr)); } const [stateRecent, setRecent] = useState([]); const [vlFonts, setVlFonts] = useState({ vlData: { items: [], } }); 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(); }); }; const renderExternal = (vl, vlData) => { setVlFonts((prevState) => { let fonts = [...prevState.vlData.items]; fonts.splice(vlData.fromIndex, vlData.toIndex, ...vlData.items); let images = getImageUri(fonts); return {vlData: { items: fonts, images, }}; }); }; const storeFocusObjects = props.storeFocusObjects; if ((storeFocusObjects.focusOn !== 'cell') && Device.phone) { $$('.sheet-modal.modal-in').length > 0 && f7.sheet.close(); return null; } return ( {Device.phone && } {!isAndroid && {displaySize}} {props.onFontSize(size, true)}}> {isAndroid ? : ' - '} {isAndroid && {displaySize}} {props.onFontSize(size, false)}}> {isAndroid ? : ' + '} {_t.textFonts} {!!arrayRecentFonts.length && {arrayRecentFonts.map((item,index) => ( { props.onFontClick(item.name); }}> ))} } {vlFonts.vlData.items.map((item, index) => ( { props.onFontClick(item.name); storeTextSettings.addFontToRecent(item); addRecentStorage(); }}> ))} ); }; const PageTextColorCell = props => { const { t } = useTranslation(); const _t = t("View.Edit", { returnObjects: true }); const storePalette = props.storePalette; const storeCellSettings = props.storeCellSettings; const customColors = storePalette.customColors; const fontColor = storeCellSettings.fontColor; const changeColor = (color, effectId, effectValue) => { if (color !== 'empty') { if (effectId !== undefined ) { const newColor = {color: color, effectId: effectId, effectValue: effectValue}; storeCellSettings.changeFontColor(newColor); props.onTextColor(newColor); } else { storeCellSettings.changeFontColor(color); props.onTextColor(color); } } else { // open custom color menu props.f7router.navigate('/edit-cell-text-custom-color/', {props: {onTextColor: props.onTextColor}}); } }; const storeFocusObjects = props.storeFocusObjects; if ((storeFocusObjects.focusOn !== 'cell') && Device.phone) { $$('.sheet-modal.modal-in').length > 0 && f7.sheet.close(); return null; } return ( {Device.phone && } { props.onTextColorAuto(); }}> ); }; const PageFillColorCell = props => { const { t } = useTranslation(); const _t = t("View.Edit", { returnObjects: true }); const storePalette = props.storePalette; const storeCellSettings = props.storeCellSettings; const customColors = storePalette.customColors; const fillColor = storeCellSettings.fillColor; const changeColor = (color, effectId, effectValue) => { if (color !== 'empty') { if (effectId !== undefined ) { const newColor = {color: color, effectId: effectId, effectValue: effectValue}; storeCellSettings.changeFillColor(newColor); props.onFillColor(newColor); } else { storeCellSettings.changeFillColor(color); props.onFillColor(color); } } else { // open custom color menu props.f7router.navigate('/edit-cell-fill-custom-color/', {props: {onFillColor: props.onFillColor}}); } }; const storeFocusObjects = props.storeFocusObjects; if ((storeFocusObjects.focusOn !== 'cell') && Device.phone) { $$('.sheet-modal.modal-in').length > 0 && f7.sheet.close(); return null; } return ( {Device.phone && } ); }; const PageCustomTextColorCell = props => { const { t } = useTranslation(); const _t = t('View.Edit', {returnObjects: true}); let fontColor = props.storeCellSettings.fontColor; if (typeof fontColor === 'object') { fontColor = fontColor.color; } const autoColor = fontColor === 'auto' ? window.getComputedStyle(document.getElementById('font-color-auto')).backgroundColor : null; const onAddNewColor = (colors, color) => { props.storePalette.changeCustomColors(colors); props.onTextColor(color); props.storeCellSettings.changeFontColor(color); props.f7router.back(); }; return ( {Device.phone && } ) }; const PageCustomFillColorCell = props => { const { t } = useTranslation(); const _t = t('View.Edit', {returnObjects: true}); let fillColor = props.storeCellSettings.fillColor; if (typeof fillColor === 'object') { fillColor = fillColor.color; } const onAddNewColor = (colors, color) => { props.storePalette.changeCustomColors(colors); props.onFillColor(color); props.storeCellSettings.changeFillColor(color); props.f7router.back(); }; return ( {Device.phone && } ) }; const PageTextFormatCell = props => { const { t } = useTranslation(); const _t = t('View.Edit', {returnObjects: true}); const isAndroid = Device.android; const storeCellSettings = props.storeCellSettings; const hAlignStr = storeCellSettings.hAlignStr; const vAlignStr = storeCellSettings.vAlignStr; const isWrapText = storeCellSettings.isWrapText; const storeFocusObjects = props.storeFocusObjects; if ((storeFocusObjects.focusOn !== 'cell') && Device.phone) { $$('.sheet-modal.modal-in').length > 0 && f7.sheet.close(); return null; } return ( {Device.phone && } { props.onHAlignChange('left'); }}> {!isAndroid ? : null } { props.onHAlignChange('center'); }}> {!isAndroid ? : null } { props.onHAlignChange('right'); }}> {!isAndroid ? : null } { props.onHAlignChange('justify'); }}> {!isAndroid ? : null } { props.onVAlignChange('top'); }}> {!isAndroid ? : null} { props.onVAlignChange('center'); }}> {!isAndroid ? : null} { props.onVAlignChange('bottom'); }}> {!isAndroid ? : null} {!isAndroid ? : null} {props.onWrapTextChange(!isWrapText)}} /> ) }; const PageTextOrientationCell = props => { const { t } = useTranslation(); const _t = t('View.Edit', {returnObjects: true}); const isAndroid = Device.android; const storeCellSettings = props.storeCellSettings; const orientationStr = storeCellSettings.orientationStr; const storeFocusObjects = props.storeFocusObjects; if ((storeFocusObjects.focusOn !== 'cell') && Device.phone) { $$('.sheet-modal.modal-in').length > 0 && f7.sheet.close(); return null; } return ( {Device.phone && } : null} onChange={() => { props.onTextOrientationChange('horizontal'); }}> {!isAndroid ? : null } : null} onChange={() => { props.onTextOrientationChange('anglecount'); }}> {!isAndroid ? : null } : null} onChange={() => { props.onTextOrientationChange('angleclock'); }}> {!isAndroid ? : null } : null} onChange={() => { props.onTextOrientationChange('vertical'); }}> {!isAndroid ? : null } : null} onChange={() => { props.onTextOrientationChange('rotateup'); }}> {!isAndroid ? : null } : null} onChange={() => { props.onTextOrientationChange('rotatedown'); }}> {!isAndroid ? : null } ) }; const PageBorderStyleCell = props => { const { t } = useTranslation(); const _t = t('View.Edit', {returnObjects: true}); const storeCellSettings = props.storeCellSettings; const borderInfo = storeCellSettings.borderInfo; const borderSizes = { 7: `${_t.textThin}`, 12: `${_t.textMedium}`, 13: `${_t.textThick}` }; const storeFocusObjects = props.storeFocusObjects; if ((storeFocusObjects.focusOn !== 'cell') && Device.phone) { $$('.sheet-modal.modal-in').length > 0 && f7.sheet.close(); return null; } const displayBorderColor = `#${(typeof borderInfo.color === "object" ? borderInfo.color.color : borderInfo.color)}`; return ( {Device.phone && } { storeCellSettings.changeBorderStyle('none'); props.onBorderStyle('none', borderInfo); }}> { storeCellSettings.changeBorderStyle('all'); props.onBorderStyle('all', borderInfo); }}> { storeCellSettings.changeBorderStyle('outer'); props.onBorderStyle('outer', borderInfo); }}> { storeCellSettings.changeBorderStyle('2'); props.onBorderStyle('2', borderInfo); }}> { storeCellSettings.changeBorderStyle('0'); props.onBorderStyle('0', borderInfo); }}> { storeCellSettings.changeBorderStyle('3'); props.onBorderStyle('3', borderInfo); }}> { storeCellSettings.changeBorderStyle('1'); props.onBorderStyle('1', borderInfo); }}> { storeCellSettings.changeBorderStyle('inner'); props.onBorderStyle('inner', borderInfo); }}> { storeCellSettings.changeBorderStyle('6'); props.onBorderStyle('6', borderInfo); }}> { storeCellSettings.changeBorderStyle('7'); props.onBorderStyle('7', borderInfo); }}> { storeCellSettings.changeBorderStyle('5'); props.onBorderStyle('5', borderInfo); }}> { storeCellSettings.changeBorderStyle('4'); props.onBorderStyle('4', borderInfo); }}> ) }; const PageBorderColorCell = props => { const { t } = useTranslation(); const storePalette = props.storePalette; const storeCellSettings = props.storeCellSettings; const borderInfo = storeCellSettings.borderInfo; const borderColor = borderInfo.color; const borderStyle = storeCellSettings.borderStyle; const customColors = storePalette.customColors; const changeColor = (color, effectId, effectValue) => { if (color !== 'empty') { storeCellSettings.setAutoColor(null); if (effectId !== undefined ) { const newColor = {color: color, effectId: effectId, effectValue: effectValue}; storeCellSettings.changeBorderColor(newColor); props.onBorderStyle(borderStyle, borderInfo); } else { storeCellSettings.changeBorderColor(color); props.onBorderStyle(borderStyle, borderInfo); } } else { // open custom color menu props.f7router.navigate('/edit-border-custom-color-cell/', {props: {onBorderStyle: props.onBorderStyle}}); } }; return ( {Device.phone && } { storeCellSettings.setAutoColor('auto'); }}> ); }; const PageCustomBorderColorCell = props => { const { t } = useTranslation(); const _t = t('View.Edit', {returnObjects: true}); const storeCellSettings = props.storeCellSettings; const storePalette = props.storePalette; const borderInfo = storeCellSettings.borderInfo; let borderColor = borderInfo.color; if(typeof borderColor === "object") { borderColor = borderInfo.color.color; } const borderStyle = storeCellSettings.borderStyle; const autoColor = storeCellSettings.colorAuto === 'auto' ? window.getComputedStyle(document.getElementById('font-color-auto')).backgroundColor : null; const onAddNewColor = (colors, color) => { storePalette.changeCustomColors(colors); storeCellSettings.changeBorderColor(color); props.onBorderStyle(borderStyle, borderInfo); props.f7router.back(); }; return ( {Device.phone && } ) }; const PageBorderSizeCell = props => { const { t } = useTranslation(); const _t = t('View.Edit', {returnObjects: true}); const storeCellSettings = props.storeCellSettings; const borderInfo = storeCellSettings.borderInfo; const borderStyle = storeCellSettings.borderStyle; const borderSizes = { 7: `${_t.textThin}`, 12: `${_t.textMedium}`, 13: `${_t.textThick}` } return ( {Device.phone && } {Object.keys(borderSizes).map(key => { return ( { storeCellSettings.changeBorderSize(+key); props.onBorderStyle(borderStyle, borderInfo); }}> ) })} ) } const PageFormatCell = props => { const { t } = useTranslation(); const _t = t('View.Edit', {returnObjects: true}); return ( {Device.phone && } props.onCellFormat('General')}> props.onCellFormat('0.00')}> props.onCellFormat('# ?/?')}> props.onCellFormat('0.00E+00')}> props.onCellFormat('0.00%')}> props.onCellFormat('@')}> ) } const PageAccountingFormatCell = props => { const { t } = useTranslation(); const _t = t('View.Edit', {returnObjects: true}); return ( {Device.phone && } props.onAccountingCellFormat(1033)}> props.onAccountingCellFormat(1031)}> props.onAccountingCellFormat(2057)}> props.onAccountingCellFormat(1049)}> props.onAccountingCellFormat(1041)}> ) } const PageCurrencyFormatCell = props => { const { t } = useTranslation(); const _t = t('View.Edit', {returnObjects: true}); return ( {Device.phone && } props.onCellFormat('[$$-409]#,##0.00')}> props.onCellFormat('#,##0.00\ [$€-407]')}> props.onCellFormat('[$£-809]#,##0.00')}> props.onCellFormat('#,##0.00\ [$₽-419]')}> props.onCellFormat('[$¥-411]#,##0.00')}> ) } const PageDateFormatCell = props => { const { t } = useTranslation(); const _t = t('View.Edit', {returnObjects: true}); const dateFormats = props.dateFormats; return ( {Device.phone && } {dateFormats.map((format, index) => { return ( props.onCellFormat(format.value)}> ) })} ) } const PageTimeFormatCell = props => { const { t } = useTranslation(); const _t = t('View.Edit', {returnObjects: true}); const timeFormats = props.timeFormats; return ( {Device.phone && } {timeFormats.map((format, index) => { return ( props.onCellFormat(format.value)}> ) })} ) } const PageEditCell = inject("storeCellSettings", "storeWorksheets")(observer(EditCell)); const TextColorCell = inject("storeCellSettings", "storePalette", "storeFocusObjects")(observer(PageTextColorCell)); const FillColorCell = inject("storeCellSettings", "storePalette", "storeFocusObjects")(observer(PageFillColorCell)); const CustomTextColorCell = inject("storeCellSettings", "storePalette", "storeFocusObjects")(observer(PageCustomTextColorCell)); const CustomFillColorCell = inject("storeCellSettings", "storePalette", "storeFocusObjects")(observer(PageCustomFillColorCell)); const FontsCell = inject("storeCellSettings", "storeTextSettings" , "storeFocusObjects")(observer(PageFontsCell)); const TextFormatCell = inject("storeCellSettings", "storeFocusObjects")(observer(PageTextFormatCell)); const TextOrientationCell = inject("storeCellSettings", "storeFocusObjects")(observer(PageTextOrientationCell)); const BorderStyleCell = inject("storeCellSettings", "storeFocusObjects")(observer(PageBorderStyleCell)); const BorderColorCell = inject("storeCellSettings", "storePalette")(observer(PageBorderColorCell)); const CustomBorderColorCell = inject("storeCellSettings", "storePalette")(observer(PageCustomBorderColorCell)); const BorderSizeCell = inject("storeCellSettings")(observer(PageBorderSizeCell)); export { PageEditCell as EditCell, TextColorCell, FillColorCell, CustomFillColorCell, CustomTextColorCell, FontsCell, TextFormatCell, TextOrientationCell, BorderStyleCell, BorderColorCell, CustomBorderColorCell, BorderSizeCell, PageFormatCell, PageAccountingFormatCell, PageCurrencyFormatCell, PageDateFormatCell, PageTimeFormatCell };