onClick(color) }/>
7 |
8 |
28 |
29 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/color-palette/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
Color Palette
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
26 |
27 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/color-palette/plunker.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Color Palette",
3 | "files": [
4 | "index.html",
5 | "README.md",
6 | "app.riot",
7 | "color-palette.riot"
8 | ]
9 | }
10 |
--------------------------------------------------------------------------------
/deno/.gitignore:
--------------------------------------------------------------------------------
1 | public/*
2 |
--------------------------------------------------------------------------------
/deno/README.md:
--------------------------------------------------------------------------------
1 | # Deno SSR Example
2 |
3 | This example shows how you can render and hydrate a simple Riot.js application using [`deno`](https://deno.land/).
4 | **This demo works only on V8 based browser because [`importmap` is not yet 100% supported](https://caniuse.com/import-maps)**
5 |
6 | ## Run locally
7 |
8 | Download or clone this repo.
9 | Install packages.
10 |
11 | ```bash
12 | $ npm install
13 | ```
14 | And then run the oak server using
15 |
16 | ```bash
17 | $ npm start
18 | ```
19 |
20 | Use the following command to watch the frontend files and update
21 | ```bash
22 | $ npm watch
23 | ```
24 |
25 | Notice that Deno dosn't support (hmr) livereload yet
26 |
27 | - Open [http://localhost:3000/](http://localhost:3000/)
--------------------------------------------------------------------------------
/deno/import_map.json:
--------------------------------------------------------------------------------
1 | {
2 | "imports": {
3 | "@riotjs/ssr": "./node_modules/@riotjs/ssr/index.js"
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/deno/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
Riot Deno App
5 |
6 |
9 |
10 |
11 | <%= html %>
12 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/deno/index.ts:
--------------------------------------------------------------------------------
1 | import { Application } from 'https://deno.land/x/oak@v10.5.1/mod.ts'
2 | import { template } from 'https://cdn.pika.dev/lodash-es'
3 | import { renderAsyncFragments } from '@riotjs/ssr'
4 | import RootComponent from'./public/app.js'
5 | import importMap from './import_map.json' assert { type: 'json' }
6 | import routes from './src/routes.ts'
7 | import { toRegexp, match } from '@riotjs/route'
8 |
9 | const app = new Application()
10 | const page = await Deno.readTextFile('./index.html')
11 | const pages = Object.values(routes)
12 |
13 | app.use(async (ctx, next) => {
14 | // quick test to identify static assets
15 | if (ctx.request.url.pathname.includes('.')) return next()
16 |
17 | // generate the initial state
18 | const initialState = {
19 | initialRoute: ctx.request.url.pathname,
20 | base: ctx.request.url.origin,
21 | routes,
22 | }
23 |
24 | // generate the rendered html + css
25 | const { html, css } = await renderAsyncFragments('app', RootComponent, initialState)
26 |
27 | // send 404 if the current path doesn't match any of the routes
28 | if (!pages.some(page => match(initialState.initialRoute, toRegexp(page.path)))) {
29 | ctx.response.status = 404
30 | }
31 |
32 | // render the body
33 | ctx.response.body = template(page)({
34 | html,
35 | css,
36 | initialState: JSON.stringify(initialState)
37 | })
38 | })
39 |
40 | app.use(async (context, next) => {
41 | try {
42 | await context.send({
43 | root: `${ Deno.cwd() }/`,
44 | index: 'index.html',
45 | })
46 | } catch {
47 | next()
48 | }
49 | })
50 |
51 | console.log('App running on: http://localhost:3000')
52 |
53 | await app.listen({ port: 3000 })
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/deno/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "deno",
3 | "version": "1.0.0",
4 | "description": "Deno SSR Demo",
5 | "repository": "riot/examples",
6 | "main": "src/main.ts",
7 | "author": "Gianluca Guarini",
8 | "license": "MIT",
9 | "type": "module",
10 | "engines": {
11 | "node": ">=10.0.0"
12 | },
13 | "scripts": {
14 | "start": "npm run build && deno run --import-map=import_map.json --no-check=remote --allow-net --watch --allow-read index.ts",
15 | "clean": "rm -rf public/*",
16 | "build-browser": "rollup -c rollup.browser-config.js",
17 | "build-server": "rollup -c rollup.server-config.js",
18 | "build": "npm run clean && npm run build-browser && npm run build-server",
19 | "watch": "rollup -c -w"
20 | },
21 | "keywords": [
22 | "riot",
23 | "deno"
24 | ],
25 | "devDependencies": {
26 | "@riotjs/cli": "^9.0.5",
27 | "@riotjs/compiler": "^9.0.6",
28 | "@rollup/plugin-commonjs": "^25.0.7",
29 | "@rollup/plugin-node-resolve": "^15.2.3",
30 | "@rollup/plugin-typescript": "^11.1.5",
31 | "rollup-plugin-riot": "^9.0.2"
32 | },
33 | "dependencies": {
34 | "@riotjs/hydrate": "^9.0.0",
35 | "@riotjs/route": "^9.1.2",
36 | "@riotjs/ssr": "^9.0.0",
37 | "erre": "^3.0.1",
38 | "riot": "^9.1.2"
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/deno/rollup.browser-config.js:
--------------------------------------------------------------------------------
1 | import riot from 'rollup-plugin-riot'
2 | import commonjs from '@rollup/plugin-commonjs'
3 | import { nodeResolve } from '@rollup/plugin-node-resolve'
4 | import typescript from '@rollup/plugin-typescript'
5 |
6 | export default {
7 | input: 'src/main.ts',
8 | output: {
9 | file: 'public/main.js',
10 | format: 'esm',
11 | },
12 | onwarn: function(error) {
13 | if (/Circular dependency/.test(error.message)) return
14 | console.error(error.message)
15 | },
16 | plugins: [
17 | commonjs({
18 | ignore: ['url']
19 | }),
20 | nodeResolve(),
21 | riot(),
22 | typescript({
23 | include: "./src/**"
24 | })
25 | ]
26 | }
27 |
--------------------------------------------------------------------------------
/deno/rollup.server-config.js:
--------------------------------------------------------------------------------
1 | import riot from 'rollup-plugin-riot'
2 | import typescript from '@rollup/plugin-typescript'
3 |
4 | export default {
5 | input: 'src/app.riot',
6 | external: ['@riotjs/hydrate', 'erre', '@riotjs/route', 'riot'],
7 | output: {
8 | file: 'public/app.js',
9 | format: 'esm',
10 | },
11 | plugins: [
12 | riot(),
13 | typescript({
14 | include: "./src/**"
15 | })
16 | ]
17 | }
18 |
--------------------------------------------------------------------------------
/deno/src/app.riot:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {page.label}
6 |
7 |
8 |
9 |
10 |
11 | 🚀
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
95 |
96 |
169 |
170 |
--------------------------------------------------------------------------------
/deno/src/main.ts:
--------------------------------------------------------------------------------
1 | import hydrate from '@riotjs/hydrate'
2 | import App from './app.riot'
3 |
4 | const appNode = document.querySelector('app')
5 | appNode && hydrate(App)(appNode, window.__INITIAL_STATE__)
6 |
--------------------------------------------------------------------------------
/deno/src/pages/about.riot:
--------------------------------------------------------------------------------
1 |
2 | A modern runtime for JavaScript and TypeScript .
3 | Deno is a simple, modern and secure runtime for JavaScript, TypeScript, and WebAssembly that uses V8 and is built in Rust.
4 | Read More
5 |
--------------------------------------------------------------------------------
/deno/src/pages/home.riot:
--------------------------------------------------------------------------------
1 |
2 | Hello Deno :)
3 | Did you know that Riot.js components can be rendered also by Deno?
4 | What a great news!
5 |
--------------------------------------------------------------------------------
/deno/src/pages/not-found.riot:
--------------------------------------------------------------------------------
1 |
2 | Page not found
3 | Opsi, wrong page. Go back to {HOME.label} :(
4 |
5 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/deno/src/routes.ts:
--------------------------------------------------------------------------------
1 | export default {
2 | HOME: {
3 | path: '/',
4 | label: 'Home',
5 | component: 'home'
6 | },
7 | ABOUT: {
8 | path: '/about',
9 | label: 'What\'s Deno?',
10 | component: 'about'
11 | }
12 | }
--------------------------------------------------------------------------------
/deno/src/types/globals.d.ts:
--------------------------------------------------------------------------------
1 | interface Window {
2 | __INITIAL_STATE__: {
3 | initialRoute: string
4 | base: string
5 | routes: Record
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/deno/src/types/riot-file.d.ts:
--------------------------------------------------------------------------------
1 | declare module '*.riot' {
2 | import {RiotComponentWrapper} from 'riot'
3 | export default RiotComponentWrapper
4 | }
5 |
--------------------------------------------------------------------------------
/deno/src/types/riot-hydrate.d.ts:
--------------------------------------------------------------------------------
1 | declare module '@riotjs/hydrate' {
2 | import { RiotComponent, RiotComponentWrapper} from 'riot'
3 | export default function >(wrapper: RiotComponentWrapper): (
4 | el: Element,
5 | initialProps?: Props
6 | ) => Component
7 | }
8 |
--------------------------------------------------------------------------------
/deno/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "allowJs": true,
4 | "skipLibCheck": true,
5 | "esModuleInterop": true,
6 | "inlineSourceMap": true,
7 | "isolatedModules": true,
8 | "module": "esnext",
9 | "strict": true,
10 | "target": "esnext"
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/hooks/README.md:
--------------------------------------------------------------------------------
1 | # Riot Hooks Example
2 |
3 | This example shows how you can add hooks to the Riot.js components thanks to the fantastic [uhooks](https://github.com/WebReflection/uhooks) micro library.
4 | This is just a basic example that can be easily extended to match your needs.
5 |
6 | ## Have a play
7 |
8 | [Open this example on Plunker](https://riot.js.org/examples/plunker/?app=hooks)
9 |
10 |
--------------------------------------------------------------------------------
/hooks/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/hooks/my-tag.html:
--------------------------------------------------------------------------------
1 |
2 | Counter
3 | { count }
4 |
5 | +
6 | -
7 |
8 |
24 |
66 |
67 |
--------------------------------------------------------------------------------
/hooks/plunker.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Riot.js hooks",
3 | "files": [
4 | "index.html",
5 | "with-hooks.js",
6 | "my-tag.html",
7 | "README.md"
8 | ]
9 | }
10 |
--------------------------------------------------------------------------------
/hooks/with-hooks.js:
--------------------------------------------------------------------------------
1 | const IS_MOUNTED = Symbol()
2 |
3 | const withHook = setup => () => {
4 | const hooks = uhooks.hooked((props, component) => {
5 | Object.assign(component, setup(props))
6 | if (component[IS_MOUNTED]) component.update()
7 | })
8 |
9 | return {
10 | onBeforeMount(props) {
11 | hooks(props, this)
12 | this[IS_MOUNTED] = true
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/lazy-routes/.gitignore:
--------------------------------------------------------------------------------
1 | public/bundle.js
2 |
--------------------------------------------------------------------------------
/lazy-routes/README.md:
--------------------------------------------------------------------------------
1 | # Webpack
2 |
3 | This is a simple example demonstrates how to lazy load Riot.js components [@riotjs/lazy](https://www.npmjs.com/package/@riotjs/lazy).
4 |
5 | ## Run locally
6 |
7 | Download or clone this repo.
8 |
9 | Install packages.
10 |
11 | ```bash
12 | $ npm install
13 | ```
14 | And then run the server using `webpack-dev-server` or any possible way you know
15 |
16 | ```bash
17 | $ npm start
18 | ```
19 |
20 | - Open [http://localhost:3000/](http://localhost:3000/)
--------------------------------------------------------------------------------
/lazy-routes/app/about.riot:
--------------------------------------------------------------------------------
1 |
2 | My name is {props.name}
3 |
--------------------------------------------------------------------------------
/lazy-routes/app/app.riot:
--------------------------------------------------------------------------------
1 |
2 | {props.message}
3 |
4 |
5 |
6 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
33 |
34 |
51 |
--------------------------------------------------------------------------------
/lazy-routes/app/home.riot:
--------------------------------------------------------------------------------
1 |
2 | I am the home page
3 |
--------------------------------------------------------------------------------
/lazy-routes/app/loader.riot:
--------------------------------------------------------------------------------
1 |
2 | Loading...
3 |
--------------------------------------------------------------------------------
/lazy-routes/app/main.js:
--------------------------------------------------------------------------------
1 | import '@riotjs/hot-reload'
2 | import {component} from 'riot'
3 | import Random from './app.riot'
4 |
5 | component(Random)(document.getElementById('app'), {
6 | message: 'Lazy Routes Application'
7 | })
8 |
--------------------------------------------------------------------------------
/lazy-routes/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "riot-lazy-routes",
3 | "version": "0.0.1",
4 | "description": "Lazy routes example",
5 | "repository": "riot/examples",
6 | "main": "app/main.js",
7 | "author": "Gianluca Guarini",
8 | "license": "MIT",
9 | "scripts": {
10 | "start": "webpack serve --mode=development --port 3000"
11 | },
12 | "keywords": [
13 | "riot",
14 | "webpack"
15 | ],
16 | "devDependencies": {
17 | "@riotjs/compiler": "^9.0.6",
18 | "@riotjs/hot-reload": "^9.0.1",
19 | "@riotjs/webpack-loader": "^9.0.1",
20 | "webpack": "^5.89.0",
21 | "webpack-cli": "^5.1.4",
22 | "webpack-dev-server": "^4.15.1"
23 | },
24 | "dependencies": {
25 | "@riotjs/lazy": "9.0.0",
26 | "@riotjs/route": "^9.1.2",
27 | "riot": "^9.1.1"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/lazy-routes/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Riot app
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/lazy-routes/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require('path')
2 | const webpack = require('webpack')
3 |
4 | module.exports = {
5 | entry: './app/main.js',
6 | output: {
7 | path: path.resolve(__dirname, 'public'),
8 | publicPath: '/public/',
9 | filename: 'bundle.js'
10 | },
11 | resolve: {
12 | fallback: {
13 | url: false
14 | }
15 | },
16 | module: {
17 | rules: [
18 | {
19 | test: /\.riot$/,
20 | exclude: /node_modules/,
21 | use: [{
22 | loader: '@riotjs/webpack-loader',
23 | options: {
24 | hot: true
25 | }
26 | }]
27 | }
28 | ]
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/live-ajax-search/README.md:
--------------------------------------------------------------------------------
1 | # Mixins
2 |
3 | This is a simple example showing how it's simple to create a live ajax search. This script relies on the [The Open Movie Database API](www.omdbapi.com) making search queries based on the movies titles
4 |
5 | ## Have a play
6 |
7 | [Open this example on Plunker](https://riot.js.org/examples/plunker/?app=live-ajax-search)
8 |
9 | ## Run locally
10 |
11 | Install superstatic if you don't have.
12 |
13 | ```bash
14 | $ npm install -g superstatic
15 | ```
16 |
17 | Download or clone this repo, then run the command.
18 |
19 | ```bash
20 | $ cd to/this/dir
21 | $ superstatic
22 | ```
23 |
24 | Open the URL shown in your browser.
25 |
--------------------------------------------------------------------------------
/live-ajax-search/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/live-ajax-search/plunker.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Color Palette",
3 | "files": [
4 | "index.html",
5 | "README.md",
6 | "search.riot",
7 | "style.css",
8 | "puff.svg"
9 | ]
10 | }
11 |
--------------------------------------------------------------------------------
/live-ajax-search/puff.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/live-ajax-search/search.riot:
--------------------------------------------------------------------------------
1 |
2 |
3 | Search a movie
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | { state.error }
12 |
13 |
19 |
20 |
65 |
66 |
144 |
145 |
146 |
--------------------------------------------------------------------------------
/live-ajax-search/style.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | font-family: 'Helvetica Neue', Helvetica, Arial;
4 | font-weight: 300;
5 | background-size: cover;
6 | background-attachment: fixed;
7 | background-image: -webkit-radial-gradient(ellipse farthest-corner at top, #661141, #000000);
8 | background-image: radial-gradient(ellipse farthest-corner at top, #661141, #000000);
9 | color: white;
10 | }
11 |
--------------------------------------------------------------------------------
/live-editor/README.md:
--------------------------------------------------------------------------------
1 | # Live Editor
2 |
3 | This is a live editor for Riot tag.
4 |
5 | ## Have a play
6 |
7 | [Open this example on Plunker](https://riot.js.org/examples/plunker/?app=live-editor)
8 |
9 | ## Run locally
10 |
11 | Install superstatic if you don't have.
12 |
13 | ```bash
14 | $ npm install -g superstatic
15 | ```
16 |
17 | Download or clone this repo, then run the command.
18 |
19 | ```bash
20 | $ cd to/this/dir
21 | $ superstatic
22 | ```
23 |
24 | Open the URL shown in your browser.
25 |
--------------------------------------------------------------------------------
/live-editor/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Riot live editor
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/live-editor/live-editor.riot:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
47 |
48 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/live-editor/plunker.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Live Editor",
3 | "files": [
4 | "index.html",
5 | "README.md",
6 | "live-editor.riot",
7 | "stage.html",
8 | "sample.riot"
9 | ]
10 | }
11 |
--------------------------------------------------------------------------------
/live-editor/sample.riot:
--------------------------------------------------------------------------------
1 |
2 | { message }
3 |
4 |
5 | { tech.name }
6 |
7 |
8 |
9 |
20 |
21 |
26 |
27 |
--------------------------------------------------------------------------------
/live-editor/stage.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Riot live editor
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/live-editor/style.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | font-family: "myriad pro", "Tahoma", "sans-serif";
4 | }
5 |
--------------------------------------------------------------------------------
/modal/README.md:
--------------------------------------------------------------------------------
1 | # Riot Modal
2 |
3 | This a simple modal made with riot and [Animate.css](https://daneden.github.io/animate.css/).
4 | This demo also demonstrates the use of [slots](https://riot.js.org/documentation/#slots).
5 |
6 | [Demo](https://riot.js.org/examples/plunker/?app=modal)
7 |
8 |
--------------------------------------------------------------------------------
/modal/cool-modal.riot:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | { state.modal.message }
5 |
6 | Say hello!
7 | Close modal
8 |
9 |
10 |
11 |
31 |
32 |
45 |
46 |
--------------------------------------------------------------------------------
/modal/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/modal/modal.riot:
--------------------------------------------------------------------------------
1 |
2 |
3 |
{ props.title }
4 |
5 |
6 |
7 |
8 |
9 |
10 |
28 |
29 |
30 |
53 |
54 |
--------------------------------------------------------------------------------
/modal/plunker.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Riot Bug Reporter",
3 | "files": [
4 | "index.html",
5 | "modal.riot",
6 | "cool-modal.riot",
7 | "README.md"
8 | ]
9 | }
10 |
--------------------------------------------------------------------------------
/plunker/README.md:
--------------------------------------------------------------------------------
1 | # Plunker
2 |
3 | This is a tool to send code to Plunker.
4 |
5 | ## Use
6 |
7 | Open the url like this:
8 |
9 | ```
10 | https://riot.js.org/examples/plunker/?app=todo-app
11 | ```
12 |
13 | To work with this tool, follow the example folder. The `plunker.json` file
14 | looks like this:
15 |
16 | ```json
17 | {
18 | "title": "Todo App",
19 | "files": [
20 | "index.html",
21 | "README.md",
22 | "todo.css",
23 | "todo.tag"
24 | ]
25 | }
26 | ```
27 |
28 | ## Run locally
29 |
30 | Install superstatic if you don't already have it.
31 |
32 | ```bash
33 | $ npm install -g superstatic
34 | ```
35 |
36 | Download or clone this repo, then run the command.
37 |
38 | ```bash
39 | $ cd to/parent/dir
40 | $ superstatic
41 | ```
42 |
43 | Open the URL shown in your browser.
44 |
--------------------------------------------------------------------------------
/plunker/app.riot:
--------------------------------------------------------------------------------
1 |
2 | Now opening Plunker...
3 |
4 |
14 |
15 |
50 |
51 |
64 |
65 |
--------------------------------------------------------------------------------
/plunker/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Opening Plunker...
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/riot-config/.gitignore:
--------------------------------------------------------------------------------
1 | dist/
2 |
--------------------------------------------------------------------------------
/riot-config/README.md:
--------------------------------------------------------------------------------
1 | # How to use riot.config.js
2 |
3 | This is an example for showing how to use the `@riotjs/cli` together with a `riot.config.js` file.
4 |
5 | ## Run locally
6 |
7 | Download or clone this repo, then run the command.
8 |
9 | ```bash
10 | $ git clone https://github.com/riot/examples
11 | $ cd example/riot-config
12 | $ npm install
13 | $ npm run build
14 | ```
15 |
16 | Then `dist` directory will be made in your project.
17 |
18 | *Note* if you installed `riot` globally in your environment. You can use the command bellow instead of `$ npm run build`:
19 |
20 | ```bash
21 | $ riot --config riot.config.js src/main.js dist/main.js
22 | ```
23 |
24 | This says "compile `tag/*` files into `dist/` directory with the config file `riot.config.js`".
25 |
26 | ## Watch
27 |
28 | To watch your tag file and check it in your browser, run the command below:
29 |
30 | ```bash
31 | $ npm start
32 | ```
33 |
--------------------------------------------------------------------------------
/riot-config/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Riot with next standards
6 |
7 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/riot-config/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "riot-config-example",
3 | "version": "1.0.0",
4 | "description": "Riot with riot.config.js",
5 | "type": "module",
6 | "private": true,
7 | "scripts": {
8 | "start": "npm run watch & npm run server",
9 | "build": "npx riot --config riot.config.js src/main.js",
10 | "watch": "npx riot --config riot.config.js -w src/main.js",
11 | "server": "serve"
12 | },
13 | "devDependencies": {
14 | "@riotjs/cli": "^9.0.5",
15 | "@riotjs/compiler": "^9.0.6",
16 | "serve": "^14.2.1"
17 | },
18 | "license": "MIT"
19 | }
20 |
--------------------------------------------------------------------------------
/riot-config/riot.config.js:
--------------------------------------------------------------------------------
1 | export default {
2 | sourcemap: 'inline',
3 | output: 'dist/main.js',
4 | format: 'esm'
5 | }
6 |
--------------------------------------------------------------------------------
/riot-config/src/app.riot:
--------------------------------------------------------------------------------
1 |
2 | { title }
3 | This example shows how to use the riot.config.js:
4 |
5 |
12 |
13 |
23 |
24 |
--------------------------------------------------------------------------------
/riot-config/src/main.js:
--------------------------------------------------------------------------------
1 | import {component} from 'riot'
2 | import App from './app.riot'
3 |
4 | component(App)(document.getElementById('root'))
5 |
--------------------------------------------------------------------------------
/router-complex/README.md:
--------------------------------------------------------------------------------
1 | # Router - Complex example
2 |
3 | This is a relatively complex example for showing how to use Riot Router to handle the URL.
4 |
5 | ## Have a play
6 |
7 | [Open this example on Plunker](https://riot.js.org/examples/plunker/?app=router-complex)
8 |
9 | ## Run locally
10 |
11 | Install superstatic if you don't have.
12 |
13 | ```bash
14 | $ npm install -g superstatic
15 | ```
16 |
17 | Download or clone this repo, then run the command.
18 |
19 | ```bash
20 | $ cd to/this/dir
21 | $ superstatic
22 | ```
23 |
24 | Open the URL shown in your browser.
25 |
--------------------------------------------------------------------------------
/router-complex/app-help.riot:
--------------------------------------------------------------------------------
1 |
2 |
3 | Help
4 |
5 | { getHelpText(route) }
6 |
7 |
8 |
23 |
24 |
52 |
53 |
--------------------------------------------------------------------------------
/router-complex/app-main.riot:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
10 |
11 |
12 |
13 |
14 |
15 | { page.title }
16 | { page.body }
17 |
18 |
19 |
20 |
21 | {getSubPageDataById(route).title}
22 | {getSubPageDataById(route).body}
23 |
24 |
25 |
26 |
27 |
54 |
55 |
94 |
95 |
96 |
--------------------------------------------------------------------------------
/router-complex/app-navi.riot:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 | { link.name }
7 |
8 |
9 |
10 |
30 |
31 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/router-complex/app.riot:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
14 |
15 |
--------------------------------------------------------------------------------
/router-complex/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Riot Router: Complex example
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
30 |
31 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/router-complex/plunker.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Router - Complex example",
3 | "files": [
4 | "index.html",
5 | "README.md",
6 | "app.riot",
7 | "app-main.riot",
8 | "app-navi.riot",
9 | "app-help.riot"
10 | ]
11 | }
12 |
--------------------------------------------------------------------------------
/router-history-api/README.md:
--------------------------------------------------------------------------------
1 | # Router - History API
2 |
3 | This is basically equivalent to [Page Switcher example](../router-page-switcher/), but it uses HTML5 history API.
4 |
5 | ## Set up your server
6 |
7 | You need to set up your server ([Express](http://expressjs.com/) or anything) to redirect all to `index.html`. You can also try it with `superstatic`. Just write [superstatic.json](superstatic.json) like this.
8 |
9 | ## Have a play
10 |
11 | This demo is not available on Plunker.
12 |
13 | ## Run locally
14 |
15 | Install superstatic if you don't have.
16 |
17 | ```bash
18 | $ npm install -g superstatic
19 | ```
20 |
21 | Download or clone this repo, then run the command.
22 |
23 | ```bash
24 | $ cd to/this/dir
25 | $ superstatic
26 | ```
27 |
28 | Open the URL shown in your browser.
29 |
--------------------------------------------------------------------------------
/router-history-api/app.riot:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | { page.title }
6 |
7 |
8 |
9 |
10 | {getPageById(route).title}
11 | {getPageById(route).body}
12 |
13 |
14 |
35 |
36 |
58 |
59 |
--------------------------------------------------------------------------------
/router-history-api/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Riot Router Example: History API
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/router-history-api/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "router-history-api",
3 | "version": "1.0.0",
4 | "description": "Riot example",
5 | "private": true,
6 | "license": "MIT"
7 | }
8 |
--------------------------------------------------------------------------------
/router-history-api/plunker.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Router - Page switcher",
3 | "files": [
4 | "index.html",
5 | "README.md",
6 | "app.riot"
7 | ]
8 | }
9 |
--------------------------------------------------------------------------------
/router-history-api/superstatic.json:
--------------------------------------------------------------------------------
1 | {
2 | "rewrites": [
3 | { "source": "**/*", "destination": "index.html" }
4 | ]
5 | }
6 |
--------------------------------------------------------------------------------
/router-page-switcher/README.md:
--------------------------------------------------------------------------------
1 | # Router - Page switcher
2 |
3 | This is a simple example for showing how to use Riot Router to handle the URL.
4 |
5 | ## Have a play
6 |
7 | [Open this example on Plunker](https://riot.js.org/examples/plunker/?app=router-page-switcher)
8 |
9 | ## Run locally
10 |
11 | Install superstatic if you don't have.
12 |
13 | ```bash
14 | $ npm install -g superstatic
15 | ```
16 |
17 | Download or clone this repo, then run the command.
18 |
19 | ```bash
20 | $ cd to/this/dir
21 | $ superstatic
22 | ```
23 |
24 | Open the URL shown in your browser.
25 |
--------------------------------------------------------------------------------
/router-page-switcher/app.riot:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | { page.title }
6 |
7 |
8 |
9 |
10 | {getPageById(route).title}
11 | {getPageById(route).body}
12 |
13 |
14 |
39 |
40 |
62 |
63 |
--------------------------------------------------------------------------------
/router-page-switcher/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Riot Router Example: Page Switching
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/router-page-switcher/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "router-page-switcher",
3 | "version": "1.1.0",
4 | "description": "Riot example",
5 | "private": true,
6 | "license": "MIT"
7 | }
8 |
--------------------------------------------------------------------------------
/router-page-switcher/plunker.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Router - Page switcher",
3 | "files": [
4 | "index.html",
5 | "README.md",
6 | "app.riot"
7 | ]
8 | }
9 |
--------------------------------------------------------------------------------
/ssr/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | [
4 | "@babel/preset-env",
5 | {
6 | "modules": false,
7 | "targets": [
8 | "last 2 versions"
9 | ]
10 | }
11 | ]
12 | ]
13 | }
14 |
--------------------------------------------------------------------------------
/ssr/.gitignore:
--------------------------------------------------------------------------------
1 | public/bundle.js
2 |
--------------------------------------------------------------------------------
/ssr/README.md:
--------------------------------------------------------------------------------
1 | # SSR
2 |
3 | This example shows how you can render and hydrate a simple Riot.js application using `@riotjs/ssr`.
4 |
5 | ## Run locally
6 |
7 | Download or clone this repo.
8 |
9 | Install packages.
10 |
11 | ```bash
12 | $ npm install
13 | ```
14 | And then run the koa server using
15 |
16 | ```bash
17 | $ npm start
18 | ```
19 |
20 | - Open [http://localhost:3000/](http://localhost:3000/)
--------------------------------------------------------------------------------
/ssr/app/app.riot:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {page.label}
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
74 |
75 |
84 |
85 |
--------------------------------------------------------------------------------
/ssr/app/main.js:
--------------------------------------------------------------------------------
1 | import '@riotjs/hot-reload'
2 | import hydrate from '@riotjs/hydrate'
3 | import App from './app.riot'
4 |
5 | hydrate(App)(document.querySelector('app'), window.__INITIAL_STATE__)
6 |
--------------------------------------------------------------------------------
/ssr/app/pages/about.riot:
--------------------------------------------------------------------------------
1 |
2 | Something about me
3 | Here I describe who I am and what I do
4 |
--------------------------------------------------------------------------------
/ssr/app/pages/home.riot:
--------------------------------------------------------------------------------
1 |
2 | I am the home page
3 | Welcome
4 |
--------------------------------------------------------------------------------
/ssr/app/pages/not-found.riot:
--------------------------------------------------------------------------------
1 |
2 | Page not found
3 |
--------------------------------------------------------------------------------
/ssr/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Riot app
5 |
8 |
9 |
10 | <%= html %>
11 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/ssr/index.js:
--------------------------------------------------------------------------------
1 | const Koa = require('koa')
2 | const app = new Koa()
3 | const {readFileSync} = require('fs')
4 | const {template} = require('lodash')
5 | const {renderAsyncFragments} = require('@riotjs/ssr')
6 | const unregister = require('@riotjs/register')()
7 | const page = readFileSync('./index.html', 'utf8')
8 |
9 | const pages = [{
10 | path: '/',
11 | label: 'Home',
12 | component: 'home'
13 | }, {
14 | path: '/about',
15 | label: 'About',
16 | component: 'about'
17 | }]
18 |
19 | app.use(require('koa-static')('./public'))
20 |
21 | app.use(async ctx => {
22 | const initialState = {
23 | initialRoute: ctx.request.url,
24 | pages,
25 | }
26 | const App = require('./app/app.riot').default
27 | const {html, css} = await renderAsyncFragments('app', App, initialState)
28 |
29 | ctx.body = template(page)({
30 | html,
31 | initialState: JSON.stringify(initialState),
32 | css
33 | })
34 |
35 | unregister()
36 | })
37 |
38 | app.listen(3000)
39 |
40 | console.log('App running on: http://localhost:3000')
41 |
--------------------------------------------------------------------------------
/ssr/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ssr",
3 | "version": "0.0.1",
4 | "description": "SSR",
5 | "repository": "riot/examples",
6 | "main": "app/main.js",
7 | "author": "Gianluca Guarini",
8 | "license": "MIT",
9 | "engines": {
10 | "node": ">=10.0.0"
11 | },
12 | "scripts": {
13 | "start": "npm run build && node index",
14 | "build": "webpack -c webpack.config.js",
15 | "dev": "webpack -w -c webpack.config.js --mode=development"
16 | },
17 | "keywords": [
18 | "riot",
19 | "webpack"
20 | ],
21 | "devDependencies": {
22 | "@babel/core": "7.19.0",
23 | "@babel/preset-env": "7.19.0",
24 | "@riotjs/compiler": "^6.3.2",
25 | "@riotjs/hot-reload": "6.0.1",
26 | "@riotjs/webpack-loader": "^6.0.0",
27 | "babel-loader": "^8.2.5",
28 | "koa": "^2.13.4",
29 | "koa-static": "^5.0.0",
30 | "lodash": "^4.17.21",
31 | "riot": "^7.0.6",
32 | "webpack": "^5.74.0",
33 | "webpack-cli": "^4.10.0"
34 | },
35 | "dependencies": {
36 | "@riotjs/hydrate": "^6.0.1",
37 | "@riotjs/register": "^6.0.1",
38 | "@riotjs/route": "^8.0.2",
39 | "@riotjs/ssr": "^8.1.2",
40 | "erre": "^2.2.0"
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/ssr/public/bundle.js.LICENSE.txt:
--------------------------------------------------------------------------------
1 | /* Riot WIP, @license MIT */
2 |
--------------------------------------------------------------------------------
/ssr/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require('path')
2 | const webpack = require('webpack')
3 |
4 | module.exports = {
5 | entry: './app/main.js',
6 | mode: 'production',
7 | devtool: 'inline-source-map',
8 | externals: {
9 | 'url': 'URL'
10 | },
11 | performance: {
12 | hints: false
13 | },
14 | output: {
15 | path: path.resolve(__dirname, 'public'),
16 | publicPath: '/public/',
17 | filename: 'bundle.js'
18 | },
19 | module: {
20 | rules: [
21 | {
22 | test: /\.riot$/,
23 | exclude: /node_modules/,
24 | use: [{
25 | loader: '@riotjs/webpack-loader',
26 | options: {
27 | hot: true
28 | }
29 | }]
30 | },
31 | {
32 | test: /\.js$/,
33 | exclude: /node_modules/,
34 | use: {
35 | loader: 'babel-loader',
36 | options: {
37 | presets: ['@babel/preset-env']
38 | }
39 | }
40 | }
41 | ]
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/timer/README.md:
--------------------------------------------------------------------------------
1 | # Timer
2 |
3 | This is a simplest timer example on [README](https://github.com/riot/riot#tag-definition).
4 |
5 | ## Have a play
6 |
7 | [Open this example on Plunker](https://riot.js.org/examples/plunker/?app=timer)
8 |
9 | ## Run locally
10 |
11 | Install superstatic if you don't have.
12 |
13 | ```bash
14 | $ npm install -g superstatic
15 | ```
16 |
17 | Download or clone this repo, then run the command.
18 |
19 | ```bash
20 | $ cd to/this/dir
21 | $ superstatic
22 | ```
23 |
24 | Open the URL shown in your browser.
25 |
--------------------------------------------------------------------------------
/timer/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Riot Example: Timer
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/timer/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "timer",
3 | "version": "1.0.1",
4 | "description": "Riot example",
5 | "private": true,
6 | "scripts": {
7 | "test": "mocha -r esm -r test/register test/*.spec.js"
8 | },
9 | "devDependencies": {
10 | "@riotjs/ssr": "^6.0.0",
11 | "chai": "^4.2.0",
12 | "esm": "^3.2.25",
13 | "jsdom": "15.1.1",
14 | "jsdom-global": "3.0.2",
15 | "mocha": "^6.1.4",
16 | "riot": "^5.1.2"
17 | },
18 | "license": "MIT"
19 | }
20 |
--------------------------------------------------------------------------------
/timer/plunker.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Timer",
3 | "files": [
4 | "index.html",
5 | "README.md",
6 | "style.css",
7 | "timer.riot"
8 | ]
9 | }
10 |
--------------------------------------------------------------------------------
/timer/style.css:
--------------------------------------------------------------------------------
1 | body {
2 | font-family: 'myriad pro', sans-serif;
3 | font-size: 20px;
4 | border: 0;
5 | background: rgba(64, 139, 194, .2);
6 | margin: 0;
7 | padding: 100px;
8 | }
9 |
10 | timer {
11 | display: block;
12 | max-width: 300px;
13 | margin: 0 auto;
14 | border: 1px solid rgba(64, 139, 194, .5);
15 | border-radius: 6px;
16 | color: rgba(64, 139, 194, 1);
17 | height: 100px;
18 | line-height: 100px;
19 | text-align: center;
20 | background: white;
21 | }
22 | p {
23 | margin: 0;
24 | }
25 |
--------------------------------------------------------------------------------
/timer/test/register.js:
--------------------------------------------------------------------------------
1 | import jsdomGlobal from 'jsdom-global'
2 | import register from '@riotjs/ssr/register'
3 |
4 | jsdomGlobal()
5 | register()
--------------------------------------------------------------------------------
/timer/test/timer.spec.js:
--------------------------------------------------------------------------------
1 | import Timer from '../timer.riot'
2 | import {expect} from 'chai'
3 | import {component} from 'riot'
4 |
5 | describe('Application specs', function() {
6 | it('mounts the tag', function() {
7 | const tag = component(Timer)(document.createElement('div'))
8 |
9 | expect(tag.$('p').textContent).to.be.equal('Seconds Elapsed: 0')
10 |
11 | tag.unmount()
12 | })
13 |
14 | it('mounts the tag with options', function() {
15 | const tag = component(Timer)(document.createElement('div'), {
16 | start: 100
17 | })
18 |
19 | expect(tag.$('p').textContent).to.be.equal('Seconds Elapsed: 100')
20 |
21 | tag.unmount()
22 | })
23 |
24 | it('counts up the timer', function(done) {
25 | const tag = component(Timer)(document.createElement('div'))
26 | setTimeout(function() {
27 | expect(tag.$('p').textContent).to.be.equal('Seconds Elapsed: 1')
28 |
29 | tag.unmount()
30 | done()
31 | }, 1000)
32 | })
33 | })
34 |
--------------------------------------------------------------------------------
/timer/timer.riot:
--------------------------------------------------------------------------------
1 |
2 | Seconds Elapsed: { state.time }
3 |
4 |
22 |
23 |
--------------------------------------------------------------------------------
/todo-app-precompiled/README.md:
--------------------------------------------------------------------------------
1 | # Todo App (pre-compiled)
2 |
3 | This is a simple example with pre-compilation. It's basically equivalent to [the in-browser version](../todo-app).
4 |
5 | ## How to try and edit
6 |
7 | This demo is not available on Plunker.
8 |
9 | ## How to try locally
10 |
11 | Follow the instruction below.
12 |
13 | Install `riot` and `superstatic` if you don't have.
14 |
15 | ```bash
16 | $ npm install -g riot
17 | $ npm install -g superstatic
18 | ```
19 |
20 | Download or clone this repo, then run the command.
21 |
22 | ```bash
23 | $ cd to/this/dir
24 | $ superstatic
25 | ```
26 |
27 | Open the URL shown in your browser.
28 |
29 | ### Recompile the tag
30 |
31 | If you modify the files, you need to recompile it.
32 |
33 | ```bash
34 | $ riot todo.riot
35 | ```
36 |
37 | Then reload the page on your browser.
38 |
--------------------------------------------------------------------------------
/todo-app-precompiled/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Riot todo (pre-compiled)
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/todo-app-precompiled/todo.css:
--------------------------------------------------------------------------------
1 |
2 | body {
3 | font-family: 'myriad pro', sans-serif;
4 | font-size: 20px;
5 | border: 0;
6 | }
7 |
8 | todo {
9 | display: block;
10 | max-width: 400px;
11 | margin: 5% auto;
12 | }
13 |
14 | form input {
15 | font-size: 85%;
16 | padding: .4em;
17 | border: 1px solid #ccc;
18 | border-radius: 2px;
19 | }
20 |
21 | button {
22 | background-color: #1FADC5;
23 | border: 1px solid rgba(0,0,0,.2);
24 | font-size: 75%;
25 | color: #fff;
26 | padding: .4em 1.2em;
27 | border-radius: 2em;
28 | cursor: pointer;
29 | margin: 0 .23em;
30 | outline: none;
31 | }
32 |
33 | button[disabled] {
34 | background-color: #ddd;
35 | color: #aaa;
36 | }
37 |
38 | ul {
39 | padding: 0;
40 | }
41 |
42 | li {
43 | list-style-type: none;
44 | padding: .2em 0;
45 | }
46 |
47 | .completed {
48 | text-decoration: line-through;
49 | color: #ccc;
50 | }
51 |
52 | label {
53 | cursor: pointer;
54 | }
55 |
--------------------------------------------------------------------------------
/todo-app-precompiled/todo.js:
--------------------------------------------------------------------------------
1 | var todo = {
2 | 'css': null,
3 | 'exports': {
4 | onBeforeMount(props, state) {
5 | // initial state
6 | this.state = {
7 | items: props.items,
8 | text: ''
9 | };
10 | },
11 |
12 | edit(e) {
13 | // update only the text state
14 | this.update({
15 | text: e.target.value
16 | });
17 | },
18 |
19 | add(e) {
20 | e.preventDefault();
21 |
22 | if (this.state.text) {
23 | this.update({
24 | items: [...this.state.items, // add a new item
25 | {
26 | title: this.state.text
27 | }],
28 | text: ''
29 | });
30 | }
31 | },
32 |
33 | toggle(item) {
34 | item.done = !item.done; // trigger a component update
35 |
36 | this.update();
37 | }
38 |
39 | },
40 | 'template': function (template, expressionTypes, bindingTypes, getComponent) {
41 | return template(' ', [{
42 | 'redundantAttribute': 'expr0',
43 | 'selector': '[expr0]',
44 | 'expressions': [{
45 | 'type': expressionTypes.TEXT,
46 | 'childNodeIndex': 0,
47 | 'evaluate': function (_scope) {
48 | return _scope.props.title;
49 | }
50 | }]
51 | }, {
52 | 'type': bindingTypes.EACH,
53 | 'getKey': null,
54 | 'condition': null,
55 | 'template': template(' ', [{
56 | 'expressions': [{
57 | 'type': expressionTypes.ATTRIBUTE,
58 | 'name': 'hidden',
59 | 'evaluate': function (_scope) {
60 | return _scope.item.hidden;
61 | }
62 | }]
63 | }, {
64 | 'redundantAttribute': 'expr2',
65 | 'selector': '[expr2]',
66 | 'expressions': [{
67 | 'type': expressionTypes.TEXT,
68 | 'childNodeIndex': 1,
69 | 'evaluate': function (_scope) {
70 | return [_scope.item.title].join('');
71 | }
72 | }, {
73 | 'type': expressionTypes.ATTRIBUTE,
74 | 'name': 'class',
75 | 'evaluate': function (_scope) {
76 | return _scope.item.done ? 'completed' : null;
77 | }
78 | }]
79 | }, {
80 | 'redundantAttribute': 'expr3',
81 | 'selector': '[expr3]',
82 | 'expressions': [{
83 | 'type': expressionTypes.ATTRIBUTE,
84 | 'name': 'checked',
85 | 'evaluate': function (_scope) {
86 | return _scope.item.done;
87 | }
88 | }, {
89 | 'type': expressionTypes.EVENT,
90 | 'name': 'onclick',
91 | 'evaluate': function (_scope) {
92 | return () => _scope.toggle(_scope.item);
93 | }
94 | }]
95 | }]),
96 | 'redundantAttribute': 'expr1',
97 | 'selector': '[expr1]',
98 | 'itemName': 'item',
99 | 'indexName': null,
100 | 'evaluate': function (_scope) {
101 | return _scope.state.items;
102 | }
103 | }, {
104 | 'redundantAttribute': 'expr4',
105 | 'selector': '[expr4]',
106 | 'expressions': [{
107 | 'type': expressionTypes.EVENT,
108 | 'name': 'onsubmit',
109 | 'evaluate': function (_scope) {
110 | return _scope.add;
111 | }
112 | }]
113 | }, {
114 | 'redundantAttribute': 'expr5',
115 | 'selector': '[expr5]',
116 | 'expressions': [{
117 | 'type': expressionTypes.EVENT,
118 | 'name': 'onkeyup',
119 | 'evaluate': function (_scope) {
120 | return _scope.edit;
121 | }
122 | }]
123 | }, {
124 | 'redundantAttribute': 'expr6',
125 | 'selector': '[expr6]',
126 | 'expressions': [{
127 | 'type': expressionTypes.TEXT,
128 | 'childNodeIndex': 0,
129 | 'evaluate': function (_scope) {
130 | return ['Add #', _scope.state.items.length + 1].join('');
131 | }
132 | }, {
133 | 'type': expressionTypes.ATTRIBUTE,
134 | 'name': 'disabled',
135 | 'evaluate': function (_scope) {
136 | return !_scope.state.text;
137 | }
138 | }]
139 | }]);
140 | },
141 | 'name': 'todo'
142 | };
143 |
144 | export default todo;
145 |
--------------------------------------------------------------------------------
/todo-app-precompiled/todo.riot:
--------------------------------------------------------------------------------
1 |
2 | { props.title }
3 |
4 |
15 |
16 |
22 |
23 |
59 |
60 |
--------------------------------------------------------------------------------
/todo-app/README.md:
--------------------------------------------------------------------------------
1 | # Todo App
2 |
3 | This is a simple example with in-browser compilation.
4 |
5 | ## Have a play
6 |
7 | [Open this example on Plunker](https://riot.js.org/examples/plunker/?app=todo-app)
8 |
9 | ## Run locally
10 |
11 | Install superstatic if you don't have.
12 |
13 | ```bash
14 | $ npm install -g superstatic
15 | ```
16 |
17 | Download or clone this repo, then run the command.
18 |
19 | ```bash
20 | $ cd to/this/dir
21 | $ superstatic
22 | ```
23 |
24 | Open the URL shown in your browser.
25 |
--------------------------------------------------------------------------------
/todo-app/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Riot todo
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/todo-app/plunker.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Todo App",
3 | "files": [
4 | "index.html",
5 | "README.md",
6 | "todo.css",
7 | "todo.riot"
8 | ]
9 | }
10 |
--------------------------------------------------------------------------------
/todo-app/todo.css:
--------------------------------------------------------------------------------
1 |
2 | body {
3 | font-family: 'myriad pro', sans-serif;
4 | font-size: 20px;
5 | border: 0;
6 | }
7 |
8 | todo {
9 | display: block;
10 | max-width: 400px;
11 | margin: 5% auto;
12 | }
13 |
14 | form input {
15 | font-size: 85%;
16 | padding: .4em;
17 | border: 1px solid #ccc;
18 | border-radius: 2px;
19 | }
20 |
21 | button {
22 | background-color: #1FADC5;
23 | border: 1px solid rgba(0,0,0,.2);
24 | font-size: 75%;
25 | color: #fff;
26 | padding: .4em 1.2em;
27 | border-radius: 2em;
28 | cursor: pointer;
29 | margin: 0 .23em;
30 | outline: none;
31 | }
32 |
33 | button[disabled] {
34 | background-color: #ddd;
35 | color: #aaa;
36 | }
37 |
38 | ul {
39 | padding: 0;
40 | }
41 |
42 | li {
43 | list-style-type: none;
44 | padding: .2em 0;
45 | }
46 |
47 | .completed {
48 | text-decoration: line-through;
49 | color: #ccc;
50 | }
51 |
52 | label {
53 | cursor: pointer;
54 | }
55 |
--------------------------------------------------------------------------------
/todo-app/todo.riot:
--------------------------------------------------------------------------------
1 |
2 | { props.title }
3 |
4 |
15 |
16 |
22 |
23 |
59 |
60 |
--------------------------------------------------------------------------------
/typescript/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "browser": true,
4 | "es6": true
5 | },
6 | "parser": "@typescript-eslint/parser",
7 | "extends": [
8 | "plugin:@typescript-eslint/recommended",
9 | "eslint-config-riot"
10 | ],
11 | "parserOptions": {
12 | "ecmaVersion": 2018,
13 | "sourceType": "module"
14 | },
15 | "rules": {
16 | "indent": "off",
17 | "@typescript-eslint/indent": ["error", 2]
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/typescript/.gitignore:
--------------------------------------------------------------------------------
1 | public/bundle.js
2 | public/bundle.js.LICENSE.txt
3 |
--------------------------------------------------------------------------------
/typescript/README.md:
--------------------------------------------------------------------------------
1 | # Typescript
2 |
3 | This is a simple example of using webpack babel and typescript with riot.
4 |
5 | ## Run locally
6 |
7 | Download or clone this repo.
8 |
9 | Install packages.
10 |
11 | ```bash
12 | $ npm install
13 | ```
14 | And then run the server using `webpack-dev-server` or any possible way you know
15 |
16 | ```bash
17 | $ npm start
18 | ```
19 |
20 | Compile the source code enabling the type check
21 |
22 | ```bash
23 | $ npm run build
24 | ```
25 |
26 | - Open [http://localhost:3000/](http://localhost:3000/)
27 | - Open [http://localhost:3000/webpack-dev-server/](http://localhost:3000/webpack-dev-server/) for dev server with hot reloading.
28 |
--------------------------------------------------------------------------------
/typescript/app/RiotFile.d.ts:
--------------------------------------------------------------------------------
1 | declare module '*.riot' {
2 | import {RiotComponentWrapper} from 'riot'
3 |
4 | const componentWrapper: RiotComponentWrapper
5 |
6 | export default componentWrapper
7 | }
8 |
--------------------------------------------------------------------------------
/typescript/app/logs/logs.riot:
--------------------------------------------------------------------------------
1 |
2 | {title}
3 |
4 |
5 | Clear logs
6 |
7 |
8 |
11 |
12 |
27 |
28 |
--------------------------------------------------------------------------------
/typescript/app/logs/types.ts:
--------------------------------------------------------------------------------
1 | export interface Log {
2 | text: string;
3 | }
4 |
5 | export interface LogComponentProps {
6 | logs: Log[];
7 | onclear: () => void
8 | }
9 |
--------------------------------------------------------------------------------
/typescript/app/main.ts:
--------------------------------------------------------------------------------
1 | import '@riotjs/hot-reload'
2 | import Random from './random/random.riot'
3 | import { component } from 'riot'
4 |
5 | component(Random)(document.getElementById('app') || document.body, {
6 | title: 'Hi there!'
7 | })
8 |
--------------------------------------------------------------------------------
/typescript/app/random/random.riot:
--------------------------------------------------------------------------------
1 |
2 | { props.title }
3 |
4 |
5 | Generate
6 |
7 |
8 |
9 | { state.number }
10 |
11 |
12 |
13 |
14 |
48 |
49 |
--------------------------------------------------------------------------------
/typescript/app/random/types.ts:
--------------------------------------------------------------------------------
1 | export interface RandomComponentState {
2 | number: number | null;
3 | logs: { text: string }[];
4 | }
5 |
6 | export interface RandomComponentProps {
7 | title: string;
8 | }
9 |
--------------------------------------------------------------------------------
/typescript/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "riot-typescript",
3 | "version": "1.0.0",
4 | "description": "Typescript and riot",
5 | "repository": "riot/examples",
6 | "main": "app/main.ts",
7 | "license": "MIT",
8 | "engines": {
9 | "node": ">=10.0.0"
10 | },
11 | "scripts": {
12 | "start": "NODE_ENV=development webpack serve --mode development --hot",
13 | "build": "webpack build --mode production"
14 | },
15 | "keywords": [
16 | "riot",
17 | "typescript"
18 | ],
19 | "devDependencies": {
20 | "@riotjs/compiler": "^9.0.6",
21 | "@riotjs/dom-bindings": "^9.0.3",
22 | "@riotjs/hot-reload": "9.0.1",
23 | "@riotjs/webpack-loader": "^9.0.1",
24 | "@types/webpack-env": "^1.18.4",
25 | "@typescript-eslint/eslint-plugin": "^6.13.2",
26 | "@typescript-eslint/parser": "^6.13.2",
27 | "eslint": "^8.55.0",
28 | "eslint-config-riot": "^4.1.1",
29 | "strip-indent": "^4.0.0",
30 | "ts-loader": "^9.5.1",
31 | "typescript": "^5.3.3",
32 | "webpack": "^5.89.0",
33 | "webpack-cli": "^5.1.4",
34 | "webpack-dev-server": "^4.15.1"
35 | },
36 | "dependencies": {
37 | "riot": "^9.1.2"
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/typescript/public/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/riot/examples/47c377a0036d278a8b3e802a2fd2a08da3af33e1/typescript/public/.gitkeep
--------------------------------------------------------------------------------
/typescript/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Riot app
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/typescript/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "esnext",
4 | "module": "es2015",
5 | "strict": true,
6 | "sourceMap": true,
7 | "noUnusedLocals": false,
8 | "moduleResolution": "node",
9 | "esModuleInterop": true,
10 | "noImplicitThis": true
11 | },
12 | "include": [
13 | "app"
14 | ]
15 | }
16 |
--------------------------------------------------------------------------------
/typescript/webpack.config.js:
--------------------------------------------------------------------------------
1 | const {resolve} = require('path')
2 | const isDevelopment = process.env.NODE_ENV === 'development'
3 |
4 | module.exports = {
5 | entry: './app/main.ts',
6 | output: {
7 | path: resolve(__dirname, 'public'),
8 | publicPath: '/public',
9 | filename: 'bundle.js'
10 | },
11 | devServer: {
12 | port: 3000
13 | },
14 | mode: 'development',
15 | devtool: 'inline-source-map',
16 | module: {
17 | rules: [
18 | {
19 | test: /\.riot$/,
20 | exclude: /node_modules/,
21 | use: [{
22 | loader: 'ts-loader',
23 | options: {
24 | transpileOnly: isDevelopment,
25 | appendTsSuffixTo: [/\.riot$/]
26 | }
27 | }, {
28 | loader: '@riotjs/webpack-loader',
29 | options: {
30 | hot: isDevelopment
31 | }
32 | }]
33 | },
34 | {
35 | test: /\.ts$/,
36 | use: [{
37 | loader: 'ts-loader',
38 | options: {
39 | transpileOnly: isDevelopment
40 | }
41 | }]
42 | }
43 | ]
44 | },
45 | resolve: {
46 | extensions: ['.ts', '.js', '.riot']
47 | }
48 | }
49 |
--------------------------------------------------------------------------------