diff --git a/examples/responsive/.babelrc b/examples/responsive/.babelrc new file mode 100644 index 000000000..a6f4434e2 --- /dev/null +++ b/examples/responsive/.babelrc @@ -0,0 +1,4 @@ +{ + "presets": ["next/babel"], + "plugins": ["inline-react-svg"] +} diff --git a/examples/responsive/.gitignore b/examples/responsive/.gitignore new file mode 100644 index 000000000..922d92a57 --- /dev/null +++ b/examples/responsive/.gitignore @@ -0,0 +1,25 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# next.js +/.next/ +/out/ + +# production +/build + +# misc +.DS_Store +.env* + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/examples/responsive/README.md b/examples/responsive/README.md new file mode 100644 index 000000000..7513716f5 --- /dev/null +++ b/examples/responsive/README.md @@ -0,0 +1,5 @@ +# Landing + +This is the source code for the landing page demo seen [here](https://craft.js.org/) + +> The code is admittedly a bit messy and is scheduled for a clean up. In the mean time, feel free to submit an issue if you encounter any confusing/weird/wtf bits ... or even better, submit a pull request! :clap: diff --git a/examples/responsive/components/selectors/Button/ButtonSettings.tsx b/examples/responsive/components/selectors/Button/ButtonSettings.tsx new file mode 100644 index 000000000..2f2ba3658 --- /dev/null +++ b/examples/responsive/components/selectors/Button/ButtonSettings.tsx @@ -0,0 +1,65 @@ +import React from 'react'; + +import { ToolbarSection, ToolbarItem } from '../../editor'; +import { ToolbarRadio } from '../../editor/Toolbar/ToolbarRadio'; + +export const ButtonSettings = () => { + return ( + + { + return ( + + + + T + + + + ); + }} + > + + + + { + return `${margin[0] || 0}px ${margin[1] || 0}px ${margin[2] || 0}px ${ + margin[3] || 0 + }px`; + }} + > + + + + + + + + + + + + + ); +}; diff --git a/examples/responsive/components/selectors/Button/index.tsx b/examples/responsive/components/selectors/Button/index.tsx new file mode 100644 index 000000000..aa21c6366 --- /dev/null +++ b/examples/responsive/components/selectors/Button/index.tsx @@ -0,0 +1,73 @@ +import { UserComponent, useNode } from '@craftjs/core'; +import cx from 'classnames'; +import React from 'react'; +import styled from 'styled-components'; + +import { ButtonSettings } from './ButtonSettings'; + +import { Text } from '../Text'; + +type ButtonProps = { + background?: Record<'r' | 'g' | 'b' | 'a', number>; + color?: Record<'r' | 'g' | 'b' | 'a', number>; + buttonStyle?: string; + margin?: any[]; + text?: string; + textComponent?: any; +}; + +const StyledButton = styled.button` + background: ${(props) => + props.buttonStyle === 'full' + ? `rgba(${Object.values(props.background)})` + : 'transparent'}; + border: 2px solid transparent; + border-color: ${(props) => + props.buttonStyle === 'outline' + ? `rgba(${Object.values(props.background)})` + : 'transparent'}; + margin: ${({ margin }) => + `${margin[0]}px ${margin[1]}px ${margin[2]}px ${margin[3]}px`}; +`; + +export const Button: UserComponent = (props: any) => { + const { + connectors: { connect }, + } = useNode((node) => ({ + selected: node.events.selected, + })); + + const { text, textComponent, color, ...otherProps } = props; + return ( + + + + ); +}; + +Button.craft = { + displayName: 'Button', + props: { + background: { r: 255, g: 255, b: 255, a: 0.5 }, + color: { r: 92, g: 90, b: 90, a: 1 }, + buttonStyle: 'full', + text: 'Button', + margin: ['5', '0', '5', '0'], + textComponent: { + ...Text.craft.props, + textAlign: 'center', + }, + }, + related: { + toolbar: ButtonSettings, + }, +}; diff --git a/examples/responsive/components/selectors/Container/ContainerSettings.tsx b/examples/responsive/components/selectors/Container/ContainerSettings.tsx new file mode 100644 index 000000000..618c54e96 --- /dev/null +++ b/examples/responsive/components/selectors/Container/ContainerSettings.tsx @@ -0,0 +1,125 @@ +import React from 'react'; + +import { ToolbarSection, ToolbarItem } from '../../editor'; +import { ToolbarRadio } from '../../editor/Toolbar/ToolbarRadio'; + +export const ContainerSettings = () => { + return ( + + { + return `${width || 0} x ${height || 0}`; + }} + > + + + + { + return ( + + + + T + + + + ); + }} + > + + + + { + return `${margin[0] || 0}px ${margin[1] || 0}px ${margin[2] || 0}px ${ + margin[3] || 0 + }px`; + }} + > + + + + + + { + return `${padding[0] || 0}px ${padding[1] || 0}px ${ + padding[2] || 0 + }px ${padding[3] || 0}px`; + }} + > + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ); +}; diff --git a/examples/responsive/components/selectors/Container/index.tsx b/examples/responsive/components/selectors/Container/index.tsx new file mode 100644 index 000000000..a64b865c1 --- /dev/null +++ b/examples/responsive/components/selectors/Container/index.tsx @@ -0,0 +1,90 @@ +import React from 'react'; + +import { ContainerSettings } from './ContainerSettings'; + +export type ContainerProps = { + background: Record<'r' | 'g' | 'b' | 'a', number>; + color: Record<'r' | 'g' | 'b' | 'a', number>; + flexDirection: string; + alignItems: string; + justifyContent: string; + fillSpace: string; + width: string; + height: string; + padding: string[]; + margin: string[]; + marginTop: number; + marginLeft: number; + marginBottom: number; + marginRight: number; + shadow: number; + children: React.ReactNode; + radius: number; +}; + +const defaultProps = { + flexDirection: 'column', + alignItems: 'flex-start', + justifyContent: 'flex-start', + fillSpace: 'no', + padding: ['0', '0', '0', '0'], + margin: ['0', '0', '0', '0'], + background: { r: 255, g: 255, b: 255, a: 1 }, + color: { r: 0, g: 0, b: 0, a: 1 }, + shadow: 0, + radius: 0, + width: '100%', + height: 'auto', +}; + +export const Container = (props: Partial) => { + props = { + ...defaultProps, + ...props, + }; + const { + flexDirection, + alignItems, + justifyContent, + fillSpace, + background, + color, + padding, + margin, + shadow, + radius, + children, + } = props; + return ( + + {children} + + ); +}; + +Container.craft = { + displayName: 'Container', + props: defaultProps, + rules: { + canDrag: () => true, + }, + related: { + toolbar: ContainerSettings, + }, +}; diff --git a/examples/responsive/components/selectors/Text/TextSettings.tsx b/examples/responsive/components/selectors/Text/TextSettings.tsx new file mode 100644 index 000000000..b26a18f62 --- /dev/null +++ b/examples/responsive/components/selectors/Text/TextSettings.tsx @@ -0,0 +1,79 @@ +import React from 'react'; + +import { capitalize, weightDescription } from '../../../utils/text'; +import { ToolbarSection, ToolbarItem } from '../../editor'; +import { ToolbarRadio } from '../../editor/Toolbar/ToolbarRadio'; + +export const TextSettings = () => { + return ( + + { + return `${fontSize || ''}, ${weightDescription( + fontWeight + )}, ${capitalize(textAlign)}`; + }} + > + + + + + + + + + + + + + { + return `${margin[0] || 0}px ${margin[1] || 0}px ${margin[2] || 0}px ${ + margin[3] || 0 + }px`; + }} + > + + + + + + { + return ( + + + T + + + ); + }} + > + + + + + ); +}; diff --git a/examples/responsive/components/selectors/Text/index.tsx b/examples/responsive/components/selectors/Text/index.tsx new file mode 100644 index 000000000..6bef80b20 --- /dev/null +++ b/examples/responsive/components/selectors/Text/index.tsx @@ -0,0 +1,69 @@ +import { useNode, useEditor } from '@craftjs/core'; +import React from 'react'; +import ContentEditable from 'react-contenteditable'; + +import { TextSettings } from './TextSettings'; + +export type TextProps = { + fontSize: string; + textAlign: string; + fontWeight: string; + color: Record<'r' | 'g' | 'b' | 'a', string>; + shadow: number; + text: string; + margin: [string, string, string, string]; +}; + +export const Text = ({ + fontSize, + textAlign, + fontWeight, + color, + shadow, + text, + margin, +}: Partial) => { + const { + connectors: { connect }, + setProp, + } = useNode(); + const { enabled } = useEditor((state) => ({ + enabled: state.options.enabled, + })); + return ( + { + setProp((prop) => (prop.text = e.target.value), 500); + }} // use true to disable editing + tagName="h2" // Use a custom HTML tag (uses a div by default) + style={{ + width: '100%', + margin: `${margin[0]}px ${margin[1]}px ${margin[2]}px ${margin[3]}px`, + color: `rgba(${Object.values(color)})`, + fontSize: `${fontSize}px`, + textShadow: `0px 0px 2px rgba(0,0,0,${(shadow || 0) / 100})`, + fontWeight, + textAlign, + }} + /> + ); +}; + +Text.craft = { + displayName: 'Text', + props: { + fontSize: '15', + textAlign: 'left', + fontWeight: '500', + color: { r: 92, g: 90, b: 90, a: 1 }, + margin: [0, 0, 0, 0], + shadow: 0, + text: 'Text', + }, + related: { + toolbar: TextSettings, + }, +}; diff --git a/examples/responsive/components/selectors/index.ts b/examples/responsive/components/selectors/index.ts new file mode 100644 index 000000000..8dd533d20 --- /dev/null +++ b/examples/responsive/components/selectors/index.ts @@ -0,0 +1,2 @@ +export * from './Container'; +export * from './Text'; diff --git a/examples/responsive/next-env.d.ts b/examples/responsive/next-env.d.ts new file mode 100644 index 000000000..4f11a03dc --- /dev/null +++ b/examples/responsive/next-env.d.ts @@ -0,0 +1,5 @@ +/// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/examples/responsive/next.config.js b/examples/responsive/next.config.js new file mode 100644 index 000000000..ea48d4656 --- /dev/null +++ b/examples/responsive/next.config.js @@ -0,0 +1,4 @@ +module.exports = { + assetPrefix: + process.env.NODE_ENV === 'production' ? '/examples/landing' : '/', +}; diff --git a/examples/responsive/package.json b/examples/responsive/package.json new file mode 100644 index 000000000..a6da0d08d --- /dev/null +++ b/examples/responsive/package.json @@ -0,0 +1,50 @@ +{ + "name": "example-responsive", + "version": "0.2.0", + "private": true, + "scripts": { + "start": "next dev -p 3002", + "build": "next build", + "export": "next export", + "clean": "rimraf lib .next out dist" + }, + "dependencies": { + "@craftjs/core": "workspace:*", + "@craftjs/layers": "workspace:*", + "@material-ui/core": "4.5.2", + "@material-ui/icons": "4.5.1", + "autoprefixer": "latest", + "classnames": "2.2.6", + "cssnano": "4.1.10", + "debounce": "1.2.0", + "lzutf8": "0.5.5", + "next": "13.1.6", + "next-seo": "4.24.0", + "postcss": "latest", + "re-resizable": "6.1.0", + "react": "18.2.0", + "react-color": "2.17.3", + "react-contenteditable": "3.3.2", + "react-dom": "18.2.0", + "react-frame-component": "^5.2.6", + "react-loading": "2.0.3", + "react-rnd": "10.1.1", + "react-youtube": "7.9.0", + "styled-components": "4.4.1" + }, + "devDependencies": { + "@babel/core": "7.7.5", + "@fullhuman/postcss-purgecss": "1.3.0", + "@types/classnames": "2.2.9", + "@types/node": "12.12.5", + "@types/react": "18.0.27", + "@types/react-color": "3.0.1", + "@types/styled-components": "4.4.1", + "babel-plugin-inline-react-svg": "2.0.1", + "cross-env": "6.0.3", + "postcss-import": "12.0.1", + "postcss-preset-env": "6.7.0", + "tailwindcss": "latest", + "typescript": "4.9.5" + } +} diff --git a/examples/responsive/pages/_app.tsx b/examples/responsive/pages/_app.tsx new file mode 100644 index 000000000..97a6c4d58 --- /dev/null +++ b/examples/responsive/pages/_app.tsx @@ -0,0 +1,21 @@ +import React from 'react'; + +import '../styles/app.css'; + +function MyApp({ Component, pageProps }) { + return ; +} + +// Only uncomment this method if you have blocking data requirements for +// every single page in your application. This disables the ability to +// perform automatic static optimization, causing every page in your app to +// be server-side rendered. +// +// MyApp.getInitialProps = async (appContext) => { +// // calls page's `getInitialProps` and fills `appProps.pageProps` +// const appProps = await App.getInitialProps(appContext); +// +// return { ...appProps } +// } + +export default MyApp; diff --git a/examples/responsive/pages/_document.tsx b/examples/responsive/pages/_document.tsx new file mode 100644 index 000000000..0da52da1b --- /dev/null +++ b/examples/responsive/pages/_document.tsx @@ -0,0 +1,32 @@ +import Document, { DocumentContext, DocumentInitialProps } from 'next/document'; +import { ServerStyleSheet } from 'styled-components'; + +export default class MyDocument extends Document { + static async getInitialProps( + ctx: DocumentContext + ): Promise { + const sheet = new ServerStyleSheet(); + const originalRenderPage = ctx.renderPage; + + try { + ctx.renderPage = () => + originalRenderPage({ + enhanceApp: (App) => (props) => + sheet.collectStyles(), + }); + + const initialProps = await Document.getInitialProps(ctx); + return { + ...initialProps, + styles: ( + <> + {initialProps.styles} + {sheet.getStyleElement()} + > + ), + }; + } finally { + sheet.seal(); + } + } +} diff --git a/examples/responsive/pages/index.tsx b/examples/responsive/pages/index.tsx new file mode 100644 index 000000000..016384e53 --- /dev/null +++ b/examples/responsive/pages/index.tsx @@ -0,0 +1,102 @@ +import { Editor, Frame, Element } from '@craftjs/core'; +import { Button, ButtonGroup, createMuiTheme } from '@material-ui/core'; +import { ThemeProvider } from '@material-ui/core/styles'; +import React, { useState } from 'react'; + +import { Container, Text } from '../components/selectors'; +import IFrame from 'react-frame-component'; + +const theme = createMuiTheme({ + typography: { + fontFamily: [ + 'acumin-pro', + 'Roboto', + '"Helvetica Neue"', + 'Arial', + 'sans-serif', + ].join(','), + }, +}); + +function App() { + const breakpoints = { + sm: '640px', // small devices i.e phones + md: '1280px', // medium devices i.e tablets + lg: '1536px', // large devices i.e computers,laptops... + }; + + const [breakpoint, setBreakpoint] = useState('lg'); + + return ( + + + + + + setBreakpoint('sm')}>Mobile + setBreakpoint('md')}>Tablet + setBreakpoint('lg')}>Desktop + + + + + + + + + + This text is red on mobile, white on tablets & black on + desktops + + + + + + + + + + ); +} + +import type { ReactNode } from 'react'; +import { useFrame } from 'react-frame-component'; +import { useLayoutEffect } from 'react'; +function AddStyles({ children }: { children: ReactNode }) { + const { document: doc } = useFrame(); // then this.$refs.iframe.... + useLayoutEffect(() => { + // this covers development case as well as part of production + document.head.querySelectorAll('style').forEach((style) => { + if (style.id === 'colors') return; + const frameStyles = style.cloneNode(true); + doc?.head.append(frameStyles); + }); + if (process && process.env.NODE_ENV === 'production') { + document.head.querySelectorAll('link[as="style"]').forEach((ele) => { + if (ele.id === 'colors') return; + doc?.head.append(ele.cloneNode(true)); + }); + document.head + .querySelectorAll('link[rel="stylesheet"]') + .forEach((ele) => { + if (ele.id === 'colors') return; + doc?.head.append(ele.cloneNode(true)); + }); + } + }, [doc]); + + return <>{children}>; +} + +import dynamic from 'next/dynamic'; + +export default dynamic(() => Promise.resolve(App), { ssr: false }); diff --git a/examples/responsive/postcss.config.js b/examples/responsive/postcss.config.js new file mode 100644 index 000000000..12a703d90 --- /dev/null +++ b/examples/responsive/postcss.config.js @@ -0,0 +1,6 @@ +module.exports = { + plugins: { + tailwindcss: {}, + autoprefixer: {}, + }, +}; diff --git a/examples/responsive/public/favicon.ico b/examples/responsive/public/favicon.ico new file mode 100644 index 000000000..4965832f2 Binary files /dev/null and b/examples/responsive/public/favicon.ico differ diff --git a/examples/responsive/public/icons/arrow-up.svg b/examples/responsive/public/icons/arrow-up.svg new file mode 100644 index 000000000..ed732073b --- /dev/null +++ b/examples/responsive/public/icons/arrow-up.svg @@ -0,0 +1,4 @@ + + Arrow Up + + \ No newline at end of file diff --git a/examples/responsive/public/icons/arrow.svg b/examples/responsive/public/icons/arrow.svg new file mode 100644 index 000000000..9ae5d222f --- /dev/null +++ b/examples/responsive/public/icons/arrow.svg @@ -0,0 +1,4 @@ + + ChevronDownMedium + + \ No newline at end of file diff --git a/examples/responsive/public/icons/button.svg b/examples/responsive/public/icons/button.svg new file mode 100644 index 000000000..c89dd41c2 --- /dev/null +++ b/examples/responsive/public/icons/button.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/responsive/public/icons/check.svg b/examples/responsive/public/icons/check.svg new file mode 100644 index 000000000..6f218c3c9 --- /dev/null +++ b/examples/responsive/public/icons/check.svg @@ -0,0 +1,5 @@ + + + S Checkmark 18 N + + \ No newline at end of file diff --git a/examples/responsive/public/icons/customize.svg b/examples/responsive/public/icons/customize.svg new file mode 100644 index 000000000..3559166f4 --- /dev/null +++ b/examples/responsive/public/icons/customize.svg @@ -0,0 +1,6 @@ + + + + S Edit 18 N + + \ No newline at end of file diff --git a/examples/responsive/public/icons/delete.svg b/examples/responsive/public/icons/delete.svg new file mode 100644 index 000000000..dd8f05646 --- /dev/null +++ b/examples/responsive/public/icons/delete.svg @@ -0,0 +1,11 @@ + + + + + S Delete 18 N + + \ No newline at end of file diff --git a/examples/responsive/public/icons/edit.svg b/examples/responsive/public/icons/edit.svg new file mode 100644 index 000000000..ee11f9ef8 --- /dev/null +++ b/examples/responsive/public/icons/edit.svg @@ -0,0 +1,11 @@ + + + + + S Edit 18 N + + \ No newline at end of file diff --git a/examples/responsive/public/icons/layers.svg b/examples/responsive/public/icons/layers.svg new file mode 100644 index 000000000..9ac9c11a3 --- /dev/null +++ b/examples/responsive/public/icons/layers.svg @@ -0,0 +1,12 @@ + + + + + S Layers 18 N + + + diff --git a/examples/responsive/public/icons/move.svg b/examples/responsive/public/icons/move.svg new file mode 100644 index 000000000..62da1e0d5 --- /dev/null +++ b/examples/responsive/public/icons/move.svg @@ -0,0 +1,11 @@ + + + + + S Move 18 N + + \ No newline at end of file diff --git a/examples/responsive/public/icons/square.svg b/examples/responsive/public/icons/square.svg new file mode 100644 index 000000000..6eabc77db --- /dev/null +++ b/examples/responsive/public/icons/square.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/responsive/public/icons/toolbox/button.svg b/examples/responsive/public/icons/toolbox/button.svg new file mode 100644 index 000000000..7b0dc08ea --- /dev/null +++ b/examples/responsive/public/icons/toolbox/button.svg @@ -0,0 +1,12 @@ + + + + + S Button 18 N + + + \ No newline at end of file diff --git a/examples/responsive/public/icons/toolbox/container.svg b/examples/responsive/public/icons/toolbox/container.svg new file mode 100644 index 000000000..bb1559f0d --- /dev/null +++ b/examples/responsive/public/icons/toolbox/container.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/responsive/public/icons/toolbox/link.svg b/examples/responsive/public/icons/toolbox/link.svg new file mode 100644 index 000000000..1a0707929 --- /dev/null +++ b/examples/responsive/public/icons/toolbox/link.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/responsive/public/icons/toolbox/rectangle.svg b/examples/responsive/public/icons/toolbox/rectangle.svg new file mode 100644 index 000000000..94abe1f8a --- /dev/null +++ b/examples/responsive/public/icons/toolbox/rectangle.svg @@ -0,0 +1,11 @@ + + + + + S Rectangle 18 N + + \ No newline at end of file diff --git a/examples/responsive/public/icons/toolbox/redo.svg b/examples/responsive/public/icons/toolbox/redo.svg new file mode 100644 index 000000000..4026d152e --- /dev/null +++ b/examples/responsive/public/icons/toolbox/redo.svg @@ -0,0 +1,4 @@ + + Redo + + \ No newline at end of file diff --git a/examples/responsive/public/icons/toolbox/text-fill.svg b/examples/responsive/public/icons/toolbox/text-fill.svg new file mode 100644 index 000000000..6b9e72932 --- /dev/null +++ b/examples/responsive/public/icons/toolbox/text-fill.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/responsive/public/icons/toolbox/text.svg b/examples/responsive/public/icons/toolbox/text.svg new file mode 100644 index 000000000..9422b1082 --- /dev/null +++ b/examples/responsive/public/icons/toolbox/text.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/responsive/public/icons/toolbox/undo.svg b/examples/responsive/public/icons/toolbox/undo.svg new file mode 100644 index 000000000..77eb5dd98 --- /dev/null +++ b/examples/responsive/public/icons/toolbox/undo.svg @@ -0,0 +1,4 @@ + + Undo + + \ No newline at end of file diff --git a/examples/responsive/public/icons/toolbox/video-fill.svg b/examples/responsive/public/icons/toolbox/video-fill.svg new file mode 100644 index 000000000..903451cc9 --- /dev/null +++ b/examples/responsive/public/icons/toolbox/video-fill.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/responsive/public/icons/toolbox/video-line.svg b/examples/responsive/public/icons/toolbox/video-line.svg new file mode 100644 index 000000000..eddc516b5 --- /dev/null +++ b/examples/responsive/public/icons/toolbox/video-line.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/responsive/public/icons/type.svg b/examples/responsive/public/icons/type.svg new file mode 100644 index 000000000..c6b2de334 --- /dev/null +++ b/examples/responsive/public/icons/type.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/responsive/public/icons/youtube.svg b/examples/responsive/public/icons/youtube.svg new file mode 100644 index 000000000..c48243850 --- /dev/null +++ b/examples/responsive/public/icons/youtube.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/responsive/seo/googlee6ec608adf0c9ed0.html b/examples/responsive/seo/googlee6ec608adf0c9ed0.html new file mode 100644 index 000000000..9be2f3abb --- /dev/null +++ b/examples/responsive/seo/googlee6ec608adf0c9ed0.html @@ -0,0 +1 @@ +google-site-verification: googlee6ec608adf0c9ed0.html diff --git a/examples/responsive/seo/sitemap.xml b/examples/responsive/seo/sitemap.xml new file mode 100644 index 000000000..358b6301a --- /dev/null +++ b/examples/responsive/seo/sitemap.xml @@ -0,0 +1,16 @@ + + + + https://craft.js.org/ + 2020-01-04T06:39:23+00:00 + + + + https://craft.js.org/r/ + 2020-01-04T06:39:23+00:00 + + \ No newline at end of file diff --git a/examples/responsive/seo/urllist.txt b/examples/responsive/seo/urllist.txt new file mode 100755 index 000000000..724eb487e --- /dev/null +++ b/examples/responsive/seo/urllist.txt @@ -0,0 +1 @@ +https://craft.js.org/ diff --git a/examples/responsive/styles/app.css b/examples/responsive/styles/app.css new file mode 100644 index 000000000..982abed39 --- /dev/null +++ b/examples/responsive/styles/app.css @@ -0,0 +1,41 @@ +/* purgecss start ignore */ +@tailwind base; +@tailwind components; +@import url('https://use.typekit.net/mpa1wkh.css'); +html, +body { + font-family: 'acumin-pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', + 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', + 'Helvetica Neue', sans-serif; + color: rgb(75, 75, 75); + background: #e0e0e0; +} +/* purgecss end ignore */ + +@tailwind utilities; + +.component-selected { + @apply relative; +} +.component-selected::after { + content: ' '; + @apply border-primary border border-dashed w-full h-full absolute left-0 top-0 pointer-events-none block; +} + +.transition { + transition: 0.4s cubic-bezier(0.19, 1, 0.22, 1); +} + +#carbonads * { + margin: initial; + padding: initial; +} + +#carbonads { + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, + Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', Helvetica, Arial, + sans-serif; + + padding: 10px 0.5rem; + border-top: 1px solid rgb(0 0 0 / 6%); +} diff --git a/examples/responsive/tailwind.config.js b/examples/responsive/tailwind.config.js new file mode 100644 index 000000000..a65c8a297 --- /dev/null +++ b/examples/responsive/tailwind.config.js @@ -0,0 +1,20 @@ +module.exports = { + purge: ['./pages/**/*.{js,ts,jsx,tsx}', './components/**/*.{js,ts,jsx,tsx}'], + theme: { + extend: { + colors: { + primary: '#2680eb', + 'dar-gray': '#4b4b4b', + 'light-gray-0': '#eaeaea', + 'light-gray-1': 'rgb(75,75,75)', + 'light-gray-2': 'rgb(128,128,128)', + 'renderer-gray': 'rgb(224, 224, 224)', + red: '#e34850', + 'green-400': '#2d9d78', + 'green-500': '#268e6c', + }, + }, + }, + variants: {}, + plugins: [], +}; diff --git a/examples/responsive/tsconfig.json b/examples/responsive/tsconfig.json new file mode 100644 index 000000000..ae305af4c --- /dev/null +++ b/examples/responsive/tsconfig.json @@ -0,0 +1,38 @@ +{ + "compilerOptions": { + "target": "esnext", + "module": "esnext", + "jsx": "preserve", + "lib": [ + "dom", + "es2017" + ], + "baseUrl": ".", + "moduleResolution": "node", + "strict": true, + "allowJs": true, + "noEmit": true, + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, + "skipLibCheck": true, + "noUnusedLocals": false, + "noUnusedParameters": true, + "isolatedModules": true, + "removeComments": false, + "preserveConstEnums": true, + "sourceMap": true, + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true, + "noImplicitAny": false, + "strictNullChecks": false, + "incremental": true + }, + "include": [ + "next-env.d.ts", + "**/*.ts", + "**/*.tsx" + ], + "exclude": [ + "node_modules" + ] +} diff --git a/examples/responsive/types/svg.d.ts b/examples/responsive/types/svg.d.ts new file mode 100644 index 000000000..cdb2b1a9a --- /dev/null +++ b/examples/responsive/types/svg.d.ts @@ -0,0 +1,4 @@ +declare module '*.svg' { + const content: string; + export default content; +} diff --git a/examples/responsive/utils/numToMeasurement.ts b/examples/responsive/utils/numToMeasurement.ts new file mode 100644 index 000000000..b83421aaf --- /dev/null +++ b/examples/responsive/utils/numToMeasurement.ts @@ -0,0 +1,32 @@ +export const isPercentage = (val: string) => + typeof val === 'string' && val.indexOf('%') > -1; + +export const percentToPx = (value: any, comparativeValue: number) => { + if (value.indexOf('px') > -1 || value === 'auto' || !comparativeValue) + return value; + const percent = parseInt(value); + return (percent / 100) * comparativeValue + 'px'; +}; +export const pxToPercent = (value: any, comparativeValue: number) => { + const val = (Math.abs(value) / comparativeValue) * 100; + if (value < 0) return -1 * val; + else return Math.round(val); +}; +export const getElementDimensions = (element: HTMLElement) => { + const computedStyle = getComputedStyle(element); + + let height = element.clientHeight, + width = element.clientWidth; // width with padding + + height -= + parseFloat(computedStyle.paddingTop) + + parseFloat(computedStyle.paddingBottom); + width -= + parseFloat(computedStyle.paddingLeft) + + parseFloat(computedStyle.paddingRight); + + return { + width, + height, + }; +}; diff --git a/examples/responsive/utils/text.ts b/examples/responsive/utils/text.ts new file mode 100644 index 000000000..25ec5787a --- /dev/null +++ b/examples/responsive/utils/text.ts @@ -0,0 +1,4 @@ +export const capitalize = (text: string) => + text[0].toUpperCase() + text.substr(1, text.length); +export const weightDescription = (weight: number) => + weight === 400 ? 'Regular' : weight === 500 ? 'Medium' : 'Bold'; diff --git a/yarn.lock b/yarn.lock index 0e94ac3d9..4b37d659d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10877,6 +10877,48 @@ clsx@latest: languageName: unknown linkType: soft +"example-responsive@workspace:examples/responsive": + version: 0.0.0-use.local + resolution: "example-responsive@workspace:examples/responsive" + dependencies: + "@babel/core": 7.7.5 + "@craftjs/core": "workspace:*" + "@craftjs/layers": "workspace:*" + "@fullhuman/postcss-purgecss": 1.3.0 + "@material-ui/core": 4.5.2 + "@material-ui/icons": 4.5.1 + "@types/classnames": 2.2.9 + "@types/node": 12.12.5 + "@types/react": 18.0.27 + "@types/react-color": 3.0.1 + "@types/styled-components": 4.4.1 + autoprefixer: latest + babel-plugin-inline-react-svg: 2.0.1 + classnames: 2.2.6 + cross-env: 6.0.3 + cssnano: 4.1.10 + debounce: 1.2.0 + lzutf8: 0.5.5 + next: 13.1.6 + next-seo: 4.24.0 + postcss: latest + postcss-import: 12.0.1 + postcss-preset-env: 6.7.0 + re-resizable: 6.1.0 + react: 18.2.0 + react-color: 2.17.3 + react-contenteditable: 3.3.2 + react-dom: 18.2.0 + react-frame-component: ^5.2.6 + react-loading: 2.0.3 + react-rnd: 10.1.1 + react-youtube: 7.9.0 + styled-components: 4.4.1 + tailwindcss: latest + typescript: 4.9.5 + languageName: unknown + linkType: soft + "execa@npm:5.0.0, execa@npm:^5.0.0": version: 5.0.0 resolution: "execa@npm:5.0.0" @@ -20143,6 +20185,17 @@ clsx@latest: languageName: node linkType: hard +"react-frame-component@npm:^5.2.6": + version: 5.2.6 + resolution: "react-frame-component@npm:5.2.6" + peerDependencies: + prop-types: ^15.5.9 + react: ">= 16.3" + react-dom: ">= 16.3" + checksum: 6669a0acc1532b53e80b14688b06d64bfab88103a1e4377a386f4350a51d76494b48ac1b8f6818bd60ae2d37cce015314ce725d807be72e9fe9258e9303bb6ec + languageName: node + linkType: hard + "react-helmet-async@npm:*, react-helmet-async@npm:^1.3.0": version: 1.3.0 resolution: "react-helmet-async@npm:1.3.0"
+ T +