-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docz): add some improvements for default package
- Loading branch information
1 parent
1a55f8b
commit 51188d4
Showing
12 changed files
with
139 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
{ | ||
"private": true, | ||
"license": "MIT", | ||
"scripts": { | ||
"bs": "lerna bootstrap" | ||
}, | ||
"devDependencies": { | ||
"lerna": "^2.9.0", | ||
"libundler": "^1.3.0", | ||
"typescript": "^2.7.2", | ||
"trash-cli": "^1.4.0" | ||
}, | ||
"workspaces": [ | ||
"packages/*", | ||
"examples/*" | ||
], | ||
"devDependencies": { | ||
"lerna": "^2.9.0" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,6 @@ | ||
{ | ||
"presets": [ | ||
"@babel/preset-env", | ||
["@babel/preset-env", { "modules": false }], | ||
"@babel/preset-react" | ||
], | ||
"plugins": [ | ||
["module-resolver", { | ||
"alias": { | ||
"playgrodd": "../../node_modules/playgrodd/dist/main/index.js" | ||
} | ||
}] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,29 @@ | ||
{ | ||
"name": "playgrodd-theme-default", | ||
"version": "0.0.1", | ||
"main": "./dist/index.js", | ||
"license": "MIT", | ||
"main": "dist/index.js", | ||
"umd:main": "dist/index.umd.js", | ||
"module": "dist/index.m.js", | ||
"source": "src/index.jsx", | ||
"scripts": { | ||
"build": "babel src --out-dir dist" | ||
"dev": "libundler watch", | ||
"build": "libundler build -s", | ||
"build:prod": "yarn run build -p --hash --gzip" | ||
}, | ||
"dependencies": { | ||
"playgrodd": "^0.0.1" | ||
"react": "^16.2.0", | ||
"react-dom": "^16.2.0" | ||
}, | ||
"peerDependencies": { | ||
"playgrodd": "^0.0.1", | ||
"react": "^16.2.0", | ||
"react-dom": "^16.2.0", | ||
"react-router-dom": "^4.2.2" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.0.0-beta.42", | ||
"@babel/core": "7.0.0-beta.42", | ||
"@babel/preset-env": "^7.0.0-beta.42", | ||
"@babel/preset-react": "^7.0.0-beta.42", | ||
"babel-plugin-module-resolver": "^3.1.0" | ||
"@babel/preset-react": "^7.0.0-beta.42" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,14 @@ | ||
import * as React from 'react' | ||
import { Subscribe } from 'unstated' | ||
import { Route } from 'react-router-dom' | ||
|
||
import { Doc } from '../documents' | ||
import { IComponent } from '../utils/components' | ||
import { DocumentsContainer } from '../documents/container' | ||
|
||
const components = __PLAYGRODD_COMPONENTS__ | ||
const loadDocument = (doc: Doc) => { | ||
const { route }: IComponent = components[doc.getName()] | ||
const sections = doc.getSections() | ||
|
||
return ( | ||
<Route | ||
exact | ||
key={route} | ||
path={route} | ||
render={() => | ||
sections.map(({ id, title, render: Component }) => ( | ||
<React.Fragment key={id}> | ||
{title && <h2>{title}</h2>} | ||
<Component /> | ||
</React.Fragment> | ||
)) | ||
} | ||
/> | ||
) | ||
} | ||
import { DocumentsContainer } from '../container' | ||
import { IDoc } from '../documents' | ||
|
||
export const Preview: React.SFC = () => ( | ||
<Subscribe to={[DocumentsContainer]}> | ||
{({ state }) => state.documents.map(loadDocument)} | ||
{({ state }) => { | ||
const documents: IDoc[] = Object.values(state.documents) | ||
return documents.length > 0 && documents.map(doc => doc.getName()) | ||
}} | ||
</Subscribe> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as React from 'react' | ||
import { Router } from 'react-router-dom' | ||
import { createBrowserHistory, History } from 'history' | ||
import { Provider } from 'unstated' | ||
|
||
import { container } from '../container' | ||
|
||
export const history: History = createBrowserHistory() | ||
|
||
export interface ICreateTheme { | ||
(WrappedComponent: React.ComponentType): React.ComponentType | ||
} | ||
|
||
export const createTheme: ICreateTheme = WrappedComponent => () => ( | ||
<Router history={history}> | ||
<Provider inject={[container]}> | ||
<WrappedComponent /> | ||
</Provider> | ||
</Router> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Container } from 'unstated' | ||
import { IDoc, IDocMap } from '../documents' | ||
|
||
export interface DocumentState { | ||
documents: IDocMap | undefined | ||
} | ||
|
||
export class DocumentsContainer extends Container<DocumentState> { | ||
constructor() { | ||
super() | ||
this.state = { | ||
documents: {}, | ||
} | ||
} | ||
|
||
public addDoc(doc: IDoc) { | ||
this.setState({ | ||
documents: Object.assign({}, this.state.documents, { | ||
[`${doc.getName()}`]: doc, | ||
}), | ||
}) | ||
} | ||
|
||
public getDocuments(): IDocMap | undefined { | ||
return this.state.documents | ||
} | ||
} | ||
|
||
export const container = new DocumentsContainer() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export { Preview } from './components/Preview' | ||
export { Playgrodd } from './components/Playgrodd' | ||
export { createTheme } from './components/create-theme' | ||
export { doc } from './documents' |
Oops, something went wrong.