diff --git a/src/components/Base.tsx b/src/components/Base.tsx index e515835..5e3181e 100644 --- a/src/components/Base.tsx +++ b/src/components/Base.tsx @@ -19,14 +19,13 @@ import { useElementSelectionContext, } from '../contexts/ElementSelectionContext'; import ElementSelector from './utils/ElementSelector'; -import { setFormatsAndPushToAry } from '../features/formatter'; -import { getAbsoluteCSSSelector } from '../utils/CSSUtils'; import TemplateCustomizer from './tabitems/template/TemplateCustomizer'; import Scrollable from './tabitems/common/Scrollable'; import LayerCustomizer from './tabitems/layer/LayerCustomizer'; import { UIUpdaterContext, useUIUpdater } from '../contexts/UIUpdater'; import t from '../features/translator'; import usePropsContext, { PropsContext } from '../contexts/PropsContext'; +import Controller from './Controller'; const Wrapper = styled.div` width: 100%; @@ -69,27 +68,13 @@ const Base = ({}: /* categoryMap */ BaseProps) => { const elementSelection = useElementSelectionContext(); const updater = useUIUpdater(); const props = usePropsContext(); - const [fontPermissionGranted, setFontPermissionGranted] = useState(true); - - const onChange = (key: string, value: string, id: number | string) => { - if (elementSelection.selectedElement) { - setFormatsAndPushToAry([ - { - id, - cssSelector: - getAbsoluteCSSSelector(elementSelection.selectedElement) + - elementSelection.selectedPseudoClass, - values: [{ key, value }], - }, - ]); - updater.formatChanged(); - } - }; + const [fontPermissionGranted, setFontPermissionGranted] = + useState(true); const tabs = { //templates.json: , - fonts: , - blocks: , + fonts: , + blocks: , templates: , layers: , settings: , @@ -121,7 +106,7 @@ const Base = ({}: /* categoryMap */ BaseProps) => { } catch { setFontPermissionGranted(false); } - } + }; useEffect(() => { (async () => { @@ -134,20 +119,25 @@ const Base = ({}: /* categoryMap */ BaseProps) => { + - { fontPermissionGranted && + {fontPermissionGranted && ( - } - { !fontPermissionGranted && + )} + {!fontPermissionGranted && ( <> - {t('need_to_grant_for_access_local_font')} - + + {t('need_to_grant_for_access_local_font')} + + - } + )} diff --git a/src/components/ChangeStyleCategory.tsx b/src/components/ChangeStyleCategory.tsx index 354cc61..b65b0d2 100644 --- a/src/components/ChangeStyleCategory.tsx +++ b/src/components/ChangeStyleCategory.tsx @@ -1,137 +1,140 @@ -import styled from 'styled-components'; -import Title from 'antd/lib/typography/Title'; -import React, { useContext } from 'react'; -import { ChangeStyleElement, LayoutPart } from '../types/ChangeStyleElement'; -import { Collapse, Input, InputNumber } from 'antd'; -import { CSSParseResultElementType } from '../types/RestaSetting'; -import t from '../features/translator'; -import { setFormatAndPushToAry } from '../features/formatter'; -import InputNumberWithUnit from './controls/InputNumberWithUnit'; -import Select from './controls/Select'; -import { getAbsoluteCSSSelector } from '../utils/CSSUtils'; -import { ElementSelectionContext } from '../contexts/ElementSelectionContext'; - -const Wrapper = styled.div``; - -const CollapseWrapper = styled.div` - background-color: white; - border-radius: 8px; -`; - -const Description = styled.p` - font-size: 10pt; - padding-bottom: 12px; -`; - -const { Panel } = Collapse; - -interface CategoryProps { - searchText: string; - title: string; - elements: ChangeStyleElement[]; -} - -const ChangeStyleCategory = ({ - searchText, - title, - elements, -}: CategoryProps) => { - const elementSelection = useContext(ElementSelectionContext); - - const onChange = (key: string, value: string, id: number | string) => { - if (elementSelection.selectedElement) { - setFormatAndPushToAry( - getAbsoluteCSSSelector(elementSelection.selectedElement), - key, - value, - id, - ); - } - }; - - const filter = (element: ChangeStyleElement) => { - if (searchText.length == 0) { - return true; - } - return ( - t(element.name).includes(searchText) || element.key.includes(searchText) - ); - }; - - const isNumberWithUnit = (parts: LayoutPart[]) => { - return ( - parts.length == 2 && - parts[0].type === CSSParseResultElementType.NUMBER && - parts[1].type === CSSParseResultElementType.SELECT - ); - }; - - return ( - - - {t(title)} - - - - {elements.filter(filter).map((element, index) => ( - - {t(element.description)} - {isNumberWithUnit(element.parts) && ( - - )} - {!isNumberWithUnit(element.parts) && - element.parts.map((part, index) => ( - <> - {part.type === CSSParseResultElementType.SELECT && ( - - onChange( - element.key, - value.currentTarget.value, - element.id, - ) - } - /> - )} - {part.type === CSSParseResultElementType.NUMBER && ( - - onChange( - element.key, - value?.toString() ?? '', - element.id, - ) - } - /> - )} - {part.type === CSSParseResultElementType.RAWTEXT && ( - {part.text} - )} - - ))} - - ))} - - - - ); -}; - -export default ChangeStyleCategory; +import styled from 'styled-components'; +import Title from 'antd/lib/typography/Title'; +import React, { useContext } from 'react'; +import { ChangeStyleElement, LayoutPart } from '../types/ChangeStyleElement'; +import { Collapse, Input, InputNumber } from 'antd'; +import { CSSParseResultElementType } from '../types/RestaSetting'; +import t from '../features/translator'; +import { setFormatAndPushToAry } from '../features/formatter'; +import InputNumberWithUnit from './controls/InputNumberWithUnit'; +import Select from './controls/Select'; +import { getAbsoluteCSSSelector } from '../utils/CSSUtils'; +import { ElementSelectionContext } from '../contexts/ElementSelectionContext'; +import { PropsContext } from '../contexts/PropsContext'; + +const Wrapper = styled.div``; + +const CollapseWrapper = styled.div` + background-color: white; + border-radius: 8px; +`; + +const Description = styled.p` + font-size: 10pt; + padding-bottom: 12px; +`; + +const { Panel } = Collapse; + +interface CategoryProps { + searchText: string; + title: string; + elements: ChangeStyleElement[]; +} + +const ChangeStyleCategory = ({ + searchText, + title, + elements, +}: CategoryProps) => { + const elementSelection = useContext(ElementSelectionContext); + const prop = useContext(PropsContext); + + const onChange = (key: string, value: string, id: number | string) => { + if (elementSelection.selectedElement) { + setFormatAndPushToAry( + getAbsoluteCSSSelector(elementSelection.selectedElement), + key, + value, + id, + prop, + ); + } + }; + + const filter = (element: ChangeStyleElement) => { + if (searchText.length == 0) { + return true; + } + return ( + t(element.name).includes(searchText) || element.key.includes(searchText) + ); + }; + + const isNumberWithUnit = (parts: LayoutPart[]) => { + return ( + parts.length == 2 && + parts[0].type === CSSParseResultElementType.NUMBER && + parts[1].type === CSSParseResultElementType.SELECT + ); + }; + + return ( + + + {t(title)} + + + + {elements.filter(filter).map((element, index) => ( + + {t(element.description)} + {isNumberWithUnit(element.parts) && ( + + )} + {!isNumberWithUnit(element.parts) && + element.parts.map((part, index) => ( + <> + {part.type === CSSParseResultElementType.SELECT && ( + + onChange( + element.key, + value.currentTarget.value, + element.id, + ) + } + /> + )} + {part.type === CSSParseResultElementType.NUMBER && ( + + onChange( + element.key, + value?.toString() ?? '', + element.id, + ) + } + /> + )} + {part.type === CSSParseResultElementType.RAWTEXT && ( + {part.text} + )} + + ))} + + ))} + + + + ); +}; + +export default ChangeStyleCategory; diff --git a/src/components/Controller.tsx b/src/components/Controller.tsx new file mode 100644 index 0000000..68ec12e --- /dev/null +++ b/src/components/Controller.tsx @@ -0,0 +1,18 @@ +import { useContext, useEffect } from 'react'; +import { PropsContext } from '../contexts/PropsContext'; +import { loadFormat, loadImportedStyle } from '../features/format_manager'; + +export default function Controller() { + const prop = useContext(PropsContext); + + prop.setCurrentUrl(window.location.href); + prop.setEditedUrl(window.location.href); + + useEffect(() => { + // do something + loadFormat(prop); + loadImportedStyle(prop); + }, []); + + return null; +} diff --git a/src/components/ToolBar.tsx b/src/components/ToolBar.tsx index e96bd5e..c2a1ffb 100644 --- a/src/components/ToolBar.tsx +++ b/src/components/ToolBar.tsx @@ -73,18 +73,30 @@ const ToolBar = () => { type="ghost" size={'small'} disabled={!context.executor.isUndoable} - icon={} + icon={ + + } onClick={context.executor.undo} />