mirror of
https://github.com/rowtype-yoga/purescript-nextjs.git
synced 2024-11-25 06:07:08 +03:00
Initial commit
This commit is contained in:
parent
722a9d89e0
commit
effdca14bd
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/bower_components/
|
||||
/node_modules/
|
||||
/.pulp-cache/
|
||||
/output/
|
||||
/generated-docs/
|
||||
/.psc-package/
|
||||
/.psc*
|
||||
/.purs*
|
||||
/.psa*
|
||||
/.spago
|
12
package.json
Normal file
12
package.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "purescript-nextjs",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
105
packages.dhall
Normal file
105
packages.dhall
Normal file
@ -0,0 +1,105 @@
|
||||
{-
|
||||
Welcome to your new Dhall package-set!
|
||||
|
||||
Below are instructions for how to edit this file for most use
|
||||
cases, so that you don't need to know Dhall to use it.
|
||||
|
||||
## Use Cases
|
||||
|
||||
Most will want to do one or both of these options:
|
||||
1. Override/Patch a package's dependency
|
||||
2. Add a package not already in the default package set
|
||||
|
||||
This file will continue to work whether you use one or both options.
|
||||
Instructions for each option are explained below.
|
||||
|
||||
### Overriding/Patching a package
|
||||
|
||||
Purpose:
|
||||
- Change a package's dependency to a newer/older release than the
|
||||
default package set's release
|
||||
- Use your own modified version of some dependency that may
|
||||
include new API, changed API, removed API by
|
||||
using your custom git repo of the library rather than
|
||||
the package set's repo
|
||||
|
||||
Syntax:
|
||||
where `entityName` is one of the following:
|
||||
- dependencies
|
||||
- repo
|
||||
- version
|
||||
-------------------------------
|
||||
let upstream = --
|
||||
in upstream
|
||||
with packageName.entityName = "new value"
|
||||
-------------------------------
|
||||
|
||||
Example:
|
||||
-------------------------------
|
||||
let upstream = --
|
||||
in upstream
|
||||
with halogen.version = "master"
|
||||
with halogen.repo = "https://example.com/path/to/git/repo.git"
|
||||
|
||||
with halogen-vdom.version = "v4.0.0"
|
||||
with halogen-vdom.dependencies = [ "extra-dependency" ] # halogen-vdom.dependencies
|
||||
-------------------------------
|
||||
|
||||
### Additions
|
||||
|
||||
Purpose:
|
||||
- Add packages that aren't already included in the default package set
|
||||
|
||||
Syntax:
|
||||
where `<version>` is:
|
||||
- a tag (i.e. "v4.0.0")
|
||||
- a branch (i.e. "master")
|
||||
- commit hash (i.e. "701f3e44aafb1a6459281714858fadf2c4c2a977")
|
||||
-------------------------------
|
||||
let upstream = --
|
||||
in upstream
|
||||
with new-package-name =
|
||||
{ dependencies =
|
||||
[ "dependency1"
|
||||
, "dependency2"
|
||||
]
|
||||
, repo =
|
||||
"https://example.com/path/to/git/repo.git"
|
||||
, version =
|
||||
"<version>"
|
||||
}
|
||||
-------------------------------
|
||||
|
||||
Example:
|
||||
-------------------------------
|
||||
let upstream = --
|
||||
in upstream
|
||||
with benchotron =
|
||||
{ dependencies =
|
||||
[ "arrays"
|
||||
, "exists"
|
||||
, "profunctor"
|
||||
, "strings"
|
||||
, "quickcheck"
|
||||
, "lcg"
|
||||
, "transformers"
|
||||
, "foldable-traversable"
|
||||
, "exceptions"
|
||||
, "node-fs"
|
||||
, "node-buffer"
|
||||
, "node-readline"
|
||||
, "datetime"
|
||||
, "now"
|
||||
]
|
||||
, repo =
|
||||
"https://github.com/hdgarrood/purescript-benchotron.git"
|
||||
, version =
|
||||
"v7.0.0"
|
||||
}
|
||||
-------------------------------
|
||||
-}
|
||||
let upstream =
|
||||
https://github.com/purescript/package-sets/releases/download/psc-0.15.4-20220822/packages.dhall
|
||||
sha256:908b4ffbfba37a0a4edf806513a555d0dbcdd0cde7abd621f8d018d2e8ecf828
|
||||
|
||||
in upstream
|
26
spago.dhall
Normal file
26
spago.dhall
Normal file
@ -0,0 +1,26 @@
|
||||
{-
|
||||
Welcome to a Spago project!
|
||||
You can edit this file as you like.
|
||||
|
||||
Need help? See the following resources:
|
||||
- Spago documentation: https://github.com/purescript/spago
|
||||
- Dhall language tour: https://docs.dhall-lang.org/tutorials/Language-Tour.html
|
||||
|
||||
When creating a new Spago project, you can use
|
||||
`spago init --no-comments` or `spago init -C`
|
||||
to generate this file without the comments in this block.
|
||||
-}
|
||||
{ name = "my-project"
|
||||
, dependencies =
|
||||
[ "aff-promise"
|
||||
, "console"
|
||||
, "effect"
|
||||
, "functions"
|
||||
, "nullable"
|
||||
, "prelude"
|
||||
, "react-basic"
|
||||
, "react-basic-hooks"
|
||||
]
|
||||
, packages = ./packages.dhall
|
||||
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
|
||||
}
|
5
src/Next/Document.js
Normal file
5
src/Next/Document.js
Normal file
@ -0,0 +1,5 @@
|
||||
import document from "next/document";
|
||||
export var _html = document.Html;
|
||||
export var _head = document.Head;
|
||||
export var _main = document.Main;
|
||||
export var _nextScript = document.NextScript;
|
61
src/Next/Document.purs
Normal file
61
src/Next/Document.purs
Normal file
@ -0,0 +1,61 @@
|
||||
module Next.Document where
|
||||
|
||||
import Prim.Row (class Union)
|
||||
import React.Basic.Hooks (JSX, ReactComponent, element)
|
||||
|
||||
-- | Components
|
||||
type Props_html =
|
||||
( children :: Array JSX
|
||||
)
|
||||
|
||||
html
|
||||
:: forall attrs attrs_
|
||||
. Union attrs attrs_ Props_html
|
||||
=> Record attrs
|
||||
-> JSX
|
||||
html attrs = element _html attrs
|
||||
|
||||
foreign import _html :: forall attrs. ReactComponent attrs
|
||||
|
||||
type Props_head =
|
||||
( children :: Array JSX
|
||||
, nonce :: String
|
||||
, crossOrigin :: String
|
||||
)
|
||||
|
||||
head
|
||||
:: forall attrs attrs_
|
||||
. Union attrs attrs_ Props_head
|
||||
=> Record attrs
|
||||
-> JSX
|
||||
head attrs = element _head attrs
|
||||
|
||||
foreign import _head :: forall attrs. ReactComponent attrs
|
||||
|
||||
type Props_main =
|
||||
( children :: Array JSX
|
||||
)
|
||||
|
||||
main
|
||||
:: forall attrs attrs_
|
||||
. Union attrs attrs_ Props_main
|
||||
=> Record attrs
|
||||
-> JSX
|
||||
main attrs = element _main attrs
|
||||
|
||||
foreign import _main :: forall attrs. ReactComponent attrs
|
||||
|
||||
type Props_nextScript =
|
||||
( children :: Array JSX
|
||||
, nonce :: String
|
||||
, crossOrigin :: String
|
||||
)
|
||||
|
||||
nextScript
|
||||
:: forall attrs attrs_
|
||||
. Union attrs attrs_ Props_nextScript
|
||||
=> Record attrs
|
||||
-> JSX
|
||||
nextScript attrs = element _nextScript attrs
|
||||
|
||||
foreign import _nextScript :: forall attrs. ReactComponent attrs
|
29
src/Next/Head.js
Normal file
29
src/Next/Head.js
Normal file
@ -0,0 +1,29 @@
|
||||
import React from "react";
|
||||
import head from "next/head";
|
||||
|
||||
function onlyReactElement(list, child) {
|
||||
if (typeof child === 'string' || typeof child === 'number') {
|
||||
return list;
|
||||
}
|
||||
if (child.type === React.Fragment) {
|
||||
return list.concat(React.Children.toArray(child.props.children).reduce((fragmentList, fragmentChild) => {
|
||||
if (typeof fragmentChild === 'string' || typeof fragmentChild === 'number') {
|
||||
return fragmentList;
|
||||
}
|
||||
return fragmentList.concat(fragmentChild);
|
||||
}, []));
|
||||
}
|
||||
return list.concat(child);
|
||||
}
|
||||
|
||||
export function _head(props) {
|
||||
var children = React.Children.toArray(props.children)
|
||||
.reduce(onlyReactElement, [])
|
||||
.map(child => {
|
||||
if(typeof child.type === 'object' && child.type.render) {
|
||||
return child.type.render(Object.assign({ key: child.key }, child.props), child.ref)
|
||||
}
|
||||
else { return child }
|
||||
})
|
||||
return head({children })
|
||||
}
|
17
src/Next/Head.purs
Normal file
17
src/Next/Head.purs
Normal file
@ -0,0 +1,17 @@
|
||||
module Next.Head where
|
||||
|
||||
import Prim.Row (class Union)
|
||||
import React.Basic.Hooks (JSX, ReactComponent, element)
|
||||
|
||||
type Props_head =
|
||||
( children :: Array JSX
|
||||
)
|
||||
|
||||
head
|
||||
:: forall attrs attrs_
|
||||
. Union attrs attrs_ Props_head
|
||||
=> Record attrs
|
||||
-> JSX
|
||||
head attrs = element _head attrs
|
||||
|
||||
foreign import _head :: forall attrs. ReactComponent attrs
|
1
src/Next/Link.js
Normal file
1
src/Next/Link.js
Normal file
@ -0,0 +1 @@
|
||||
export { default as _link} from "next/link"
|
24
src/Next/Link.purs
Normal file
24
src/Next/Link.purs
Normal file
@ -0,0 +1,24 @@
|
||||
module Next.Link where
|
||||
|
||||
import Prim.Row (class Union)
|
||||
import React.Basic.Hooks (JSX, ReactComponent, element)
|
||||
|
||||
type Props_link =
|
||||
( children :: JSX
|
||||
, href :: String
|
||||
, as :: String
|
||||
, passHref :: Boolean
|
||||
, prefetch :: Boolean
|
||||
, replace :: Boolean
|
||||
, scroll :: Boolean
|
||||
, shallow :: Boolean
|
||||
)
|
||||
|
||||
link
|
||||
:: forall attrs attrs_
|
||||
. Union attrs attrs_ Props_link
|
||||
=> Record attrs
|
||||
-> JSX
|
||||
link attrs = element _link attrs
|
||||
|
||||
foreign import _link :: forall attrs. ReactComponent attrs
|
22
src/Next/Router.js
Normal file
22
src/Next/Router.js
Normal file
@ -0,0 +1,22 @@
|
||||
export { useRouter as useRouter_ } from 'next/router'
|
||||
import router from "next/router";
|
||||
|
||||
export function _on(event) {
|
||||
return function(cb) {
|
||||
return function() {
|
||||
router.events.on(event, cb);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export function _off(event) {
|
||||
return function(cb) {
|
||||
return function() {
|
||||
router.events.off(event, cb);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export const query = (router) => router.query
|
||||
|
||||
export const push = (router) => (route) => () => router.push(route)
|
35
src/Next/Router.purs
Normal file
35
src/Next/Router.purs
Normal file
@ -0,0 +1,35 @@
|
||||
module Next.Router where
|
||||
|
||||
import Prelude
|
||||
import Effect (Effect)
|
||||
import Effect.Uncurried (mkEffectFn1)
|
||||
import React.Basic.Hooks (Hook, unsafeHook)
|
||||
|
||||
foreign import data Router :: Type
|
||||
|
||||
foreign import useRouter_ :: Effect Router
|
||||
|
||||
useRouter :: Hook (UseRouter) Router
|
||||
useRouter = unsafeHook useRouter_
|
||||
|
||||
foreign import data UseRouter :: Type -> Type
|
||||
|
||||
foreign import query :: forall q. Router -> q
|
||||
|
||||
foreign import push :: Router -> String -> Effect Unit
|
||||
|
||||
foreign import _on :: forall a. String -> a -> Effect Unit
|
||||
|
||||
foreign import _off :: forall a. String -> a -> Effect Unit
|
||||
|
||||
event :: forall a. String -> a -> Effect (Effect Unit)
|
||||
event name cb = _on name cb $> _off name cb
|
||||
|
||||
onRouteChangeStart :: (String -> Effect Unit) -> Effect (Effect Unit)
|
||||
onRouteChangeStart = event "routeChangeStart" <<< mkEffectFn1
|
||||
|
||||
routeChangeComplete :: (String -> Effect Unit) -> Effect (Effect Unit)
|
||||
routeChangeComplete = event "routeChangeComplete" <<< mkEffectFn1
|
||||
|
||||
routeChangeError :: forall r. ({ cancelled :: Boolean | r } -> Effect Unit) -> Effect (Effect Unit)
|
||||
routeChangeError = event "routeChangeError" <<< mkEffectFn1
|
2
src/Next/SWR.js
Normal file
2
src/Next/SWR.js
Normal file
@ -0,0 +1,2 @@
|
||||
export { default as useSWR_ , SWRConfig as swrConfig } from 'swr'
|
||||
|
42
src/Next/SWR.purs
Normal file
42
src/Next/SWR.purs
Normal file
@ -0,0 +1,42 @@
|
||||
module NextUI.SWR where
|
||||
|
||||
import Prelude
|
||||
|
||||
import Control.Promise (Promise)
|
||||
import Data.Function.Uncurried (Fn2)
|
||||
import Data.Nullable (Nullable)
|
||||
import Effect (Effect)
|
||||
import Effect.Uncurried (EffectFn1, EffectFn2, mkEffectFn1, runEffectFn2)
|
||||
import React.Basic.Hooks (Hook, ReactComponent, unsafeHook)
|
||||
|
||||
type SWR d err = { "data" :: d, error :: err }
|
||||
|
||||
-- const fetcher = (...args) => fetch(...args).then((res) => res.json())
|
||||
|
||||
-- function Profile() {
|
||||
-- const { data, error } = useSWR('/api/profile-data', fetcher)
|
||||
|
||||
-- if (error) return <div>Failed to load</div>
|
||||
-- if (!data) return <div>Loading...</div>
|
||||
|
||||
-- return (
|
||||
-- <div>
|
||||
-- <h1>{data.name}</h1>
|
||||
-- <p>{data.bio}</p>
|
||||
-- </div>
|
||||
-- )
|
||||
|
||||
foreign import useSWR_
|
||||
:: forall d err
|
||||
. EffectFn2
|
||||
String
|
||||
(EffectFn1 String (Promise d))
|
||||
(SWR d err)
|
||||
|
||||
useSWR :: forall d err. String -> (String -> Effect (Promise d)) -> Hook (UseSWR d) (SWR d err)
|
||||
useSWR url fetch = unsafeHook do
|
||||
runEffectFn2 useSWR_ url (mkEffectFn1 fetch)
|
||||
|
||||
foreign import data UseSWR :: Type -> Type -> Type
|
||||
|
||||
foreign import swrConfig :: forall props. ReactComponent { | props }
|
2
src/Next/Script.js
Normal file
2
src/Next/Script.js
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
export { default as script } from 'next/script';
|
7
src/Next/Script.purs
Normal file
7
src/Next/Script.purs
Normal file
@ -0,0 +1,7 @@
|
||||
module Next.Script where
|
||||
|
||||
import Prelude
|
||||
|
||||
import React.Basic (ReactComponent)
|
||||
|
||||
foreign import script :: forall props. ReactComponent { | props }
|
11
test/Main.purs
Normal file
11
test/Main.purs
Normal file
@ -0,0 +1,11 @@
|
||||
module Test.Main where
|
||||
|
||||
import Prelude
|
||||
|
||||
import Effect (Effect)
|
||||
import Effect.Class.Console (log)
|
||||
|
||||
main :: Effect Unit
|
||||
main = do
|
||||
log "🍝"
|
||||
log "You should add some tests."
|
Loading…
Reference in New Issue
Block a user