29 |
30 | // The NodeTree of the div is:
31 | {
32 | rootNodeId: "node-a",
33 | nodes: {
34 | "node-a" : {
35 | data: {
36 | type: "div",
37 | nodes: ["node-b", "node-c"]
38 | }
39 | },
40 | "node-b" : {
41 | data: {
42 | type: "h2",
43 | props: { children: "Hello" }
44 | }
45 | },
46 | "node-c" : {
47 | data: {
48 | type: "h2",
49 | props: { children: "World" }
50 | }
51 | }
52 | }
53 | }
54 | ```
--------------------------------------------------------------------------------
/packages/core/src/utils/mergeTrees.tsx:
--------------------------------------------------------------------------------
1 | import { Node, NodeTree } from '../interfaces';
2 |
3 | const mergeNodes = (rootNode: Node, childrenNodes: NodeTree[]) => {
4 | if (childrenNodes.length < 1) {
5 | return { [rootNode.id]: rootNode };
6 | }
7 | const nodes = childrenNodes.map(({ rootNodeId }) => rootNodeId);
8 | const nodeWithChildren = { ...rootNode, data: { ...rootNode.data, nodes } };
9 | const rootNodes = { [rootNode.id]: nodeWithChildren };
10 | return childrenNodes.reduce((accum, tree) => {
11 | const currentNode = tree.nodes[tree.rootNodeId];
12 | return {
13 | ...accum,
14 | ...tree.nodes,
15 | // set the parent id for the current node
16 | [currentNode.id]: {
17 | ...currentNode,
18 | data: {
19 | ...currentNode.data,
20 | parent: rootNode.id,
21 | },
22 | },
23 | };
24 | }, rootNodes);
25 | };
26 |
27 | export const mergeTrees = (
28 | rootNode: Node,
29 | childrenNodes: NodeTree[]
30 | ): NodeTree => ({
31 | rootNodeId: rootNode.id,
32 | nodes: mergeNodes(rootNode, childrenNodes),
33 | });
34 |
--------------------------------------------------------------------------------
/examples/basic/pages/_app.js:
--------------------------------------------------------------------------------
1 | import CssBaseline from '@material-ui/core/CssBaseline';
2 | import { ThemeProvider } from '@material-ui/core/styles';
3 | import App from 'next/app';
4 | import Head from 'next/head';
5 | import React from 'react';
6 |
7 | import theme from '../src/theme';
8 |
9 | import '../styles/main.css';
10 |
11 | export default class MyApp extends App {
12 | componentDidMount() {
13 | // Remove the server-side injected CSS.
14 | const jssStyles = document.querySelector('#jss-server-side');
15 | if (jssStyles) {
16 | jssStyles.parentElement.removeChild(jssStyles);
17 | }
18 | }
19 |
20 | render() {
21 | const { Component, pageProps } = this.props;
22 |
23 | return (
24 |
25 |
26 | My page
27 |
28 |
29 | {/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
30 |
31 |
32 |
33 |
34 | );
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/examples/landing/public/icons/move.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Previnash Wong Sze Chuan
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/examples/landing/utils/numToMeasurement.ts:
--------------------------------------------------------------------------------
1 | export const isPercentage = (val: string) =>
2 | typeof val === 'string' && val.indexOf('%') > -1;
3 |
4 | export const percentToPx = (value: any, comparativeValue: number) => {
5 | if (value.indexOf('px') > -1 || value === 'auto' || !comparativeValue)
6 | return value;
7 | const percent = parseInt(value);
8 | return (percent / 100) * comparativeValue + 'px';
9 | };
10 | export const pxToPercent = (value: any, comparativeValue: number) => {
11 | const val = (Math.abs(value) / comparativeValue) * 100;
12 | if (value < 0) return -1 * val;
13 | else return Math.round(val);
14 | };
15 | export const getElementDimensions = (element: HTMLElement) => {
16 | const computedStyle = getComputedStyle(element);
17 |
18 | let height = element.clientHeight,
19 | width = element.clientWidth; // width with padding
20 |
21 | height -=
22 | parseFloat(computedStyle.paddingTop) +
23 | parseFloat(computedStyle.paddingBottom);
24 | width -=
25 | parseFloat(computedStyle.paddingLeft) +
26 | parseFloat(computedStyle.paddingRight);
27 |
28 | return {
29 | width,
30 | height,
31 | };
32 | };
33 |
--------------------------------------------------------------------------------
/scripts/publish.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # https://github.com/vercel/next.js/blob/canary/publish-release.sh
4 |
5 | set -e
6 |
7 | yarn clean
8 |
9 | yarn build
10 |
11 | yarn test
12 |
13 | git describe --exact-match
14 |
15 | if [[ ! $? -eq 0 ]];then
16 | echo "Nothing to publish, exiting.."
17 | exit 0;
18 | fi
19 |
20 | if [[ -z "$NPM_TOKEN" ]];then
21 | echo "No NPM_TOKEN, exiting.."
22 | exit 0;
23 | fi
24 |
25 | echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
26 |
27 | if [[ $(git describe --exact-match 2> /dev/null || :) =~ -beta ]];
28 | then
29 | echo "Publishing packages"
30 | yarn run lerna publish from-git --yes # publish latest tagged commit
31 |
32 | if [[ ! $? -eq 0 ]];then
33 | exit 1;
34 | fi
35 | else
36 | echo "Did not publish packages"
37 | fi
38 |
39 | if [[ $(git describe --exact-match 2> /dev/null || :) =~ -alpha ]];
40 | then
41 | echo "Publishing alpha"
42 | yarn run lerna publish from-git --npm-tag next --yes
43 |
44 | # Make sure to exit script with code 1 if publish failed
45 | if [[ ! $? -eq 0 ]];then
46 | exit 1;
47 | fi
48 | else
49 | echo "Did not publish alpha"
50 | fi
51 |
--------------------------------------------------------------------------------
/packages/core/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Previnash Wong Sze Chuan
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/packages/layers/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Previnash Wong Sze Chuan
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/packages/utils/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Previnash Wong Sze Chuan
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/examples/landing/pages/_document.tsx:
--------------------------------------------------------------------------------
1 | import Document, { Html, Head, Main, NextScript } from 'next/document';
2 | import React from 'react';
3 | // Import styled components ServerStyleSheet
4 | import { ServerStyleSheet } from 'styled-components';
5 |
6 | export default class MyDocument extends Document {
7 | static getInitialProps({ renderPage }) {
8 | // Step 1: Create an instance of ServerStyleSheet
9 | const sheet = new ServerStyleSheet();
10 |
11 | // Step 2: Retrieve styles from components in the page
12 | const page = renderPage((App) => (props) =>
13 | sheet.collectStyles()
14 | );
15 |
16 | // Step 3: Extract the styles as