Skip to content

Commit

Permalink
Merge pull request #52 from perimetre/3.3.0
Browse files Browse the repository at this point in the history
3.3.0
  • Loading branch information
adarleyjrr authored Dec 3, 2021
2 parents 18d2c74 + da9c607 commit 9245d95
Show file tree
Hide file tree
Showing 9 changed files with 14,649 additions and 9,951 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

## [3.3.0]

### Fixed

- Moved storybook libraries to `devDependencies` so they are not included in the package bundle
- Updated storybook libraries to fix vulnerabilities issues
- Removed `next` from `peerDependencies` since the components in the UI lib don't depend on it
- Moved `next` to `devDependencies` so it is not included in the package bundle
- Updated `next` to fix vulnerabilities issues
- Updated `formik` to fix vulnerabilities issues
- Updated `svgo` to fix vulnerabilities issues, and made code tweaks where it is used because the update involved breaking changes
- Updated other libraries to fix vulnerabilities issues

## [3.2.0] 2021-11-24

### Added
Expand Down
4 changes: 4 additions & 0 deletions next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
/// <reference types="next" />
/// <reference types="next/types/global" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
24,476 changes: 14,578 additions & 9,898 deletions package-lock.json

Large diffs are not rendered by default.

41 changes: 20 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@perimetre/ui",
"description": "A component library made by @perimetre",
"version": "3.2.0",
"version": "3.3.0",
"repository": {
"type": "git",
"url": "git+https://github.com/perimetre/ui.git"
Expand Down Expand Up @@ -44,7 +44,6 @@
"prepare": "npm run rollup:build"
},
"peerDependencies": {
"next": "10.x",
"react": "17.x",
"react-dom": "17.x",
"isomorphic-dompurify": "0.x"
Expand All @@ -59,10 +58,6 @@
"@rollup/plugin-commonjs": "^17.1.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^11.1.1",
"@storybook/addon-postcss": "^2.0.0",
"@storybook/addons": "^6.1.21",
"@storybook/storybook-deployer": "^2.8.7",
"@storybook/theming": "^6.1.21",
"@tailwindcss/line-clamp": "^0.2.0",
"@tailwindcss/typography": "^0.4.0",
"@tippyjs/react": "^4.2.0",
Expand All @@ -77,7 +72,7 @@
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.1",
"@types/styled-components": "^5.1.7",
"@types/svgo": "^1.3.3",
"@types/svgo": "^2.6.0",
"@types/yup": "^0.29.11",
"@whitespace/storybook-addon-html": "^4.2.0",
"babel-loader": "^8.2.2",
Expand All @@ -87,15 +82,14 @@
"draft-js": "^0.11.7",
"draftjs-to-html": "^0.9.1",
"draftjs-utils": "^0.10.2",
"formik": "^2.2.6",
"formik": "^2.2.9",
"framer-motion": "^3.3.0",
"hammerjs": "^2.0.8",
"html-react-parser": "^1.2.4",
"html-to-draftjs": "^1.5.0",
"lodash": "^4.17.20",
"nanoid": "^3.1.20",
"next": "10.0.5",
"postcss": "^8.2.8",
"postcss": "^8.4.4",
"postcss-combine-duplicated-selectors": "^10.0.2",
"postcss-combine-media-query": "^1.0.1",
"postcss-flexbugs-fixes": "^5.0.2",
Expand All @@ -106,11 +100,10 @@
"rollup": "^2.41.1",
"rollup-plugin-copy": "^3.4.0",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-postcss": "^4.0.0",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-typescript2": "^0.30.0",
"storybook": "^6.2.0-beta.10",
"styled-components": "^5.2.1",
"svgo": "^1.3.2",
"svgo": "^2.8.0",
"tailwindcss": "^2.0.3",
"tslib": "^2.1.0",
"typescript": "^4.2.2",
Expand All @@ -119,11 +112,15 @@
"devDependencies": {
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@storybook/addon-a11y": "^6.2.0-beta.10",
"@storybook/addon-actions": "^6.2.0-beta.10",
"@storybook/addon-essentials": "^6.2.0-beta.10",
"@storybook/addon-links": "^6.2.0-beta.10",
"@storybook/react": "^6.2.0-beta.10",
"@storybook/addon-a11y": "^6.4.4",
"@storybook/addon-actions": "^6.4.4",
"@storybook/addon-essentials": "^6.4.4",
"@storybook/addon-links": "^6.4.4",
"@storybook/addon-postcss": "^2.0.0",
"@storybook/addons": "^6.4.4",
"@storybook/react": "^6.4.4",
"@storybook/storybook-deployer": "^2.8.10",
"@storybook/theming": "^6.4.4",
"@typescript-eslint/eslint-plugin": "^4.14.1",
"@typescript-eslint/parser": "^4.14.1",
"eslint": "^7.18.0",
Expand All @@ -137,10 +134,12 @@
"http-server": "^0.12.3",
"husky": "^4.3.8",
"isomorphic-dompurify": "^0.13.0",
"next": "^12.0.4",
"prettier": "^2.2.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"storybook-addon-jsx": "^7.3.7-canary.137.616.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"storybook": "^6.4.4",
"storybook-addon-jsx": "^7.3.14",
"stylelint": "^13.9.0",
"stylelint-config-recommended": "^3.0.0",
"stylelint-config-styled-components": "^0.1.1"
Expand Down
2 changes: 0 additions & 2 deletions src/components/WYSIWYGInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,6 @@ export const WYSIWYGInput = forwardRef<WYSIWYGInputRef, WYSIWYGInputProps>(
};

if (!isEditorStateInitialized) {
console.log('resetting');
// setEditorState(EditorState.set(editorState, { decorator: defaultDecorators }));
updateFromHtml(defaultHtmlValue || '');
}

Expand Down
2 changes: 1 addition & 1 deletion src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AppProps } from 'next/dist/next-server/lib/router/router';
import { AppProps } from 'next/dist/pages/_app';
import React from 'react';
import '../styles/globals.css';

Expand Down
4 changes: 2 additions & 2 deletions src/pages/api/optimize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export default async (req: NextApiRequest, res: NextApiResponse) => {
res.status(404).end();
}

const { svgString, ...opts } = req.body;
const { svgString, datauri, ...opts } = req.body;

try {
res.status(200).json(await getSvgo(opts).optimize(svgString));
res.status(200).json(getSvgo(svgString, datauri, opts));
} catch (error) {
res.status(500).json({ error });
}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/optimize/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default function Home() {
setUriSvg('');
});
} else {
setOptimizedSvg({});
setOptimizedSvg(undefined);
setOriginalSvg('');
setUriSvg('');
}
Expand Down Expand Up @@ -231,7 +231,7 @@ export default function Home() {
<label className="pui-label-input" htmlFor="json">
Optimized SVG
</label>
<textarea readOnly rows={10} id="json" className="pui-text-input" value={optimizedSvg && optimizedSvg.data} />
<textarea readOnly rows={10} id="json" className="pui-text-input" value={optimizedSvg?.data || ''} />
</div>
<div>
<label className="pui-label-input" htmlFor="css">
Expand Down
54 changes: 29 additions & 25 deletions src/utils/svgo.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
import SVGOptimizer from 'svgo';
import { OptimizeOptions, optimize } from 'svgo';
import { nanoid } from 'nanoid';

/**
* Returns an instance of SVGO
*
* @param root0 The options setting
* @param root0.datauri Output as Data URI string.
* @param root0.prefixIds prefix IDs and classes with the SVG filename or an arbitrary string
* @param root0.removeOffCanvasPaths removes elements that are drawn outside of the viewbox
* @param root0.removeRasterImages remove raster images
* @param root0.removeXMLNS removes xmlns attribute (for inline svg)
* @param root0.removeColors remove color attributes (to make sure it works with all colors)
* @param svgString The SVG to be optimized
* @param datauri Output as Data URI string.
* @param root1 The options setting
* @param root1.prefixIds prefix IDs and classes with the SVG filename or an arbitrary string
* @param root1.removeOffCanvasPaths removes elements that are drawn outside of the viewbox
* @param root1.removeRasterImages remove raster images
* @param root1.removeXMLNS removes xmlns attribute (for inline svg)
* @param root1.removeColors remove color attributes (to make sure it works with all colors)
*/
export const getSvgo = ({
datauri,
prefixIds,
removeOffCanvasPaths,
removeRasterImages,
removeXMLNS,
removeColors
}: // eslint-disable-next-line @typescript-eslint/no-explicit-any
Record<string, any>) =>
new SVGOptimizer({
export const getSvgo = (
svgString: string | Buffer,
datauri: OptimizeOptions['datauri'],
{
prefixIds,
removeOffCanvasPaths,
removeRasterImages,
removeXMLNS,
removeColors
}: Record<string, boolean | undefined>
) =>
optimize(svgString, {
multipass: true,
datauri,
plugins: [
{ removeDimensions: false },
{ removeViewBox: false },
...(prefixIds ? [{ prefixIds: { delim: `_${nanoid(5)}_` } }] : []),
...(removeOffCanvasPaths ? [{ removeOffCanvasPaths: true }] : []),
...(removeRasterImages ? [{ removeRasterImages: true }] : []),
...(removeXMLNS ? [{ removeXMLNS: true }] : []),
...(removeColors ? [{ removeAttrs: { attrs: '(stroke|fill)' } }] : [])
{ name: 'removeDimensions', active: false },
{ name: 'removeViewBox', active: false },
{ name: 'prefixIds', params: { delim: `_${nanoid(5)}_` }, active: prefixIds },
{ name: 'removeOffCanvasPaths', active: removeOffCanvasPaths },
{ name: 'removeRasterImages', active: removeRasterImages },
{ name: 'removeXMLNS', active: removeXMLNS },
{ name: 'removeAttrs', params: { attrs: '(stroke|fill)' }, active: removeColors }
]
});

0 comments on commit 9245d95

Please sign in to comment.