Skip to content

Commit

Permalink
Address recent PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
obetomuniz committed May 8, 2020
1 parent 94c7720 commit e836308
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 47 deletions.
3 changes: 1 addition & 2 deletions assets/src/edit-story/app/font/actions/useLoadFontFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function useLoadFontFiles() {
async ({
font: { family, service, variants },
fontWeight,
isItalic,
fontStyle,
content,
}) => {
if (!family || service !== 'fonts.google.com') {
Expand All @@ -63,7 +63,6 @@ function useLoadFontFiles() {

const handle = cleanForSlug(family);
const elementId = `${handle}-css`;
const fontStyle = isItalic ? 'italic' : 'normal';
const fontFaceSet = `
${fontStyle || ''} ${fontWeight || ''} 0 '${family}'
`.trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const DEFAULT_FONT = {
service: 'fonts.google.com',
},
fontWeight: 400,
isItalic: true,
fontStyle: 'normal',
content: 'Fill in some text',
};

Expand Down
3 changes: 2 additions & 1 deletion assets/src/edit-story/components/library/text/fontPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { useEffect } from 'react';
import { useFont } from '../../../app';
import { ALLOWED_EDITOR_PAGE_WIDTHS, PAGE_WIDTH } from '../../../constants';
import { FontPropType } from '../../../types';
import stripHTML from '../../../utils/stripHTML';

const PREVIEW_EM_SCALE = ALLOWED_EDITOR_PAGE_WIDTHS[0] / PAGE_WIDTH;

Expand Down Expand Up @@ -63,7 +64,7 @@ function FontPreview({ title, font, fontSize, fontWeight, content, onClick }) {
{
font,
fontWeight,
content,
content: stripHTML(content),
},
]);
}, [font, fontWeight, content, maybeEnqueueFontStyle]);
Expand Down
30 changes: 18 additions & 12 deletions assets/src/edit-story/components/panels/textStyle/font.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { PAGE_HEIGHT } from '../../../constants';
import { useFont } from '../../../app/font';
import { getCommonValue } from '../utils';
import objectPick from '../../../utils/objectPick';
import stripHTML from '../../../utils/stripHTML';
import useRichTextFormatting from './useRichTextFormatting';
import getFontWeights from './getFontWeights';

Expand Down Expand Up @@ -66,6 +67,7 @@ function FontControls({ selectedElements, pushUpdate }) {
getFontByName,
fontFamily,
]);
const fontStyle = isItalic ? 'italic' : 'normal';

return (
<>
Expand All @@ -90,12 +92,14 @@ function FontControls({ selectedElements, pushUpdate }) {
};

await maybeEnqueueFontStyle(
selectedElements.map(({ content }) => ({
font: newFont,
isItalic,
fontWeight,
content,
}))
selectedElements.map(({ content }) => {
return {
font: newFont,
fontStyle,
fontWeight,
content: stripHTML(content),
};
})
);

pushUpdate(
Expand All @@ -119,12 +123,14 @@ function FontControls({ selectedElements, pushUpdate }) {
value={fontWeight}
onChange={async (value) => {
await maybeEnqueueFontStyle(
selectedElements.map(({ font, content }) => ({
font,
isItalic,
fontWeight: parseInt(value),
content,
}))
selectedElements.map(({ font, content }) => {
return {
font,
fontStyle,
fontWeight: parseInt(value),
content: stripHTML(content),
};
})
);
handleSelectFontWeight(value);
}}
Expand Down
15 changes: 9 additions & 6 deletions assets/src/edit-story/components/panels/textStyle/textStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { ReactComponent as ItalicIcon } from '../../../icons/italic_icon.svg';
import { ReactComponent as UnderlineIcon } from '../../../icons/underline_icon.svg';
import { getCommonValue } from '../utils';
import { useFont } from '../../../app/font';
import stripHTML from '../../../utils/stripHTML';
import useRichTextFormatting from './useRichTextFormatting';

const BoxedNumeric = styled(Numeric)`
Expand Down Expand Up @@ -143,12 +144,14 @@ function StylePanel({ selectedElements, pushUpdate }) {
iconHeight={10}
onChange={async (value) => {
await maybeEnqueueFontStyle(
selectedElements.map(({ font, content }) => ({
font,
isItalic: value,
fontWeight,
content,
}))
selectedElements.map(({ font, content }) => {
return {
font,
fontStyle: value ? 'italic' : 'normal',
fontWeight,
content: stripHTML(content),
};
})
);
handleClickItalic(value);
}}
Expand Down
22 changes: 11 additions & 11 deletions assets/src/edit-story/elements/text/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
getHTMLInfo,
} from '../../components/richText/htmlManipulation';
import createSolid from '../../utils/createSolid';
import stripHTML from '../../utils/stripHTML';
import { getHighlightLineheight, generateParagraphTextStyle } from './util';

const HighlightWrapperElement = styled.div`
Expand Down Expand Up @@ -103,8 +104,14 @@ function TextDisplay({
} = useUnits();

const { font } = rest;
const isItalic = useMemo(() => getHTMLInfo(content).isItalic, [content]);
const fontWeight = useMemo(() => getHTMLInfo(content).fontWeight, [content]);
const fontFaceSetConfigs = useMemo(
() => ({
fontStyle: getHTMLInfo(content).isItalic ? 'italic' : 'normal',
fontWeight: getHTMLInfo(content).fontWeight,
content: stripHTML(content),
}),
[content]
);

const props = {
font,
Expand All @@ -120,15 +127,8 @@ function TextDisplay({
actions: { maybeEnqueueFontStyle },
} = useFont();
useEffect(() => {
maybeEnqueueFontStyle([
{
font,
fontWeight,
isItalic,
content,
},
]);
}, [font, fontWeight, isItalic, content, maybeEnqueueFontStyle]);
maybeEnqueueFontStyle([{ ...fontFaceSetConfigs, font }]);
}, [font, fontFaceSetConfigs, maybeEnqueueFontStyle]);

useTransformHandler(id, (transform) => {
const target = ref.current;
Expand Down
27 changes: 13 additions & 14 deletions assets/src/edit-story/elements/text/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import StoryPropTypes from '../../types';
import { BACKGROUND_TEXT_MODE } from '../../constants';
import useUnmount from '../../utils/useUnmount';
import createSolid from '../../utils/createSolid';
import stripHTML from '../../utils/stripHTML';
import calcRotatedResizeOffset from '../../utils/calcRotatedResizeOffset';
import { generateParagraphTextStyle, getHighlightLineheight } from './util';

Expand Down Expand Up @@ -92,9 +93,15 @@ function TextEdit({
},
box: { x, y, height, rotationAngle },
}) {
const { font, fontSize } = rest;
const isItalic = useMemo(() => getHTMLInfo(content).isItalic, [content]);
const fontWeight = useMemo(() => getHTMLInfo(content).fontWeight, [content]);
const { font } = rest;
const fontFaceSetConfigs = useMemo(
() => ({
fontStyle: getHTMLInfo(content).isItalic ? 'italic' : 'normal',
fontWeight: getHTMLInfo(content).fontWeight,
content: stripHTML(content),
}),
[content]
);

const {
actions: { dataToEditorX, dataToEditorY, editorToDataX, editorToDataY },
Expand Down Expand Up @@ -200,24 +207,16 @@ function TextEdit({
[handleResize]
);
// Also invoke if the raw element height ever changes
useEffect(handleResize, [
elementHeight,
font,
fontWeight,
isItalic,
fontSize,
]);
useEffect(handleResize, [elementHeight]);

useEffect(() => {
maybeEnqueueFontStyle([
{
...fontFaceSetConfigs,
font,
fontWeight,
isItalic,
content,
},
]);
}, [font, fontWeight, isItalic, content, maybeEnqueueFontStyle]);
}, [font, fontFaceSetConfigs, maybeEnqueueFontStyle]);

return (
<Wrapper ref={wrapperRef} onClick={onClick}>
Expand Down

0 comments on commit e836308

Please sign in to comment.