create-tinybase 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.js +2 -2
- package/package.json +2 -2
- package/templates/index.html.hbs +55 -0
- package/templates/{base/package.json.hbs → package.json.hbs} +21 -8
- package/templates/public/favicon.svg +8 -0
- package/templates/src/App.tsx.hbs +47 -19
- package/templates/src/Buttons.tsx.hbs +26 -0
- package/templates/src/app.ts.hbs +36 -0
- package/templates/src/index.css.hbs +94 -66
- package/templates/src/index.tsx.hbs +12 -42
- package/templates/{base/vite.config.js.hbs → vite.config.js.hbs} +5 -3
- package/templates/base/index.html.hbs +0 -17
- package/templates/base/tsconfig.node.json.hbs +0 -9
- /package/templates/{base/.prettierrc.hbs → .prettierrc.hbs} +0 -0
- /package/templates/{base/README.md.hbs → README.md.hbs} +0 -0
- /package/templates/{base/eslint.config.js.hbs → eslint.config.js.hbs} +0 -0
- /package/templates/{base/tsconfig.json.hbs → tsconfig.json.hbs} +0 -0
package/cli.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{dirname as
|
|
3
|
-
`,questions:[{type:"text",name:"projectName",message:"Project name:",initial:"my-tinybase-app",validate:e=>e.length
|
|
2
|
+
import{existsSync as p}from"fs";import{dirname as m,join as o}from"path";import{createCLI as u}from"tinycreate";import{fileURLToPath as g}from"url";const d=m(g(import.meta.url)),y={welcomeMessage:`\u{1F389} Welcome to TinyBase!
|
|
3
|
+
`,questions:[{type:"text",name:"projectName",message:"Project name:",initial:"my-tinybase-app",validate:e=>{if(e.length===0)return"Project name is required";const t=o(process.cwd(),e);return p(t)?`Directory "${e}" already exists. Please choose a different name.`:!0}},{type:"select",name:"language",message:"Language:",choices:[{title:"TypeScript",value:"typescript"},{title:"JavaScript",value:"javascript"}],initial:0},{type:"select",name:"framework",message:"Framework:",choices:[{title:"React",value:"react"},{title:"Vanilla",value:"vanilla"}],initial:0},{type:"confirm",name:"prettier",message:"Include Prettier?",initial:!1},{type:"confirm",name:"eslint",message:"Include ESLint?",initial:!1}],createContext:e=>{const{projectName:t,language:s,framework:n,prettier:r,eslint:c}=e,a=s==="typescript",l=!a,i=n==="react";return{projectName:t,language:s,framework:n,prettier:r,eslint:c,typescript:a,javascript:l,react:i,ext:a?i?"tsx":"ts":i?"jsx":"js"}},createDirectories:async e=>{const{mkdir:t}=await import("fs/promises"),{join:s}=await import("path");await t(s(e,"src"),{recursive:!0}),await t(s(e,"public"),{recursive:!0})},getFiles:()=>[{template:"package.json.hbs",output:"package.json",prettier:!0},{template:"README.md.hbs",output:"README.md",prettier:!0}],processIncludedFile:(e,t)=>{const{javascript:s}=t,n=e.prettier??/\.(js|jsx|ts|tsx|css|json|html|md)$/.test(e.output),r=e.transpile??(/\.(ts|tsx)\.hbs$/.test(e.template)&&s===!0);return{...e,prettier:n,transpile:r}},templateRoot:o(d,"templates"),installCommand:"{pm} install",devCommand:"{pm} run dev",onSuccess:e=>{console.log("Next steps:"),console.log(` cd ${e}`),console.log(" npm install"),console.log(" npm run dev")}};u(y).catch(e=>{console.error(e),process.exit(1)});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-tinybase",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"author": "jamesgpearce",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"create-tinybase": "cli.js"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"tinycreate": "^0.1.
|
|
26
|
+
"tinycreate": "^0.1.1"
|
|
27
27
|
},
|
|
28
28
|
"engines": {
|
|
29
29
|
"node": ">=18.0.0"
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
8
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
9
|
+
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;800&display=swap" />
|
|
10
|
+
{{includeFile template="public/favicon.svg" output="public/favicon.svg"}}
|
|
11
|
+
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
|
12
|
+
<title>
|
|
13
|
+
TinyBase / {{#if typescript}}TypeScript{{else}}JavaScript{{/if}}{{#if react}} + React{{/if}}
|
|
14
|
+
</title>
|
|
15
|
+
</head>
|
|
16
|
+
|
|
17
|
+
<body>
|
|
18
|
+
{{#if react}}
|
|
19
|
+
<div id="app"></div>
|
|
20
|
+
{{else}}
|
|
21
|
+
<div id="app">
|
|
22
|
+
<header>
|
|
23
|
+
<h1>
|
|
24
|
+
<img src="/favicon.svg" />
|
|
25
|
+
TinyBase / {{#if typescript}}TypeScript{{else}}JavaScript{{/if}}
|
|
26
|
+
</h1>
|
|
27
|
+
</header>
|
|
28
|
+
<p>
|
|
29
|
+
This is more or less the simplest TinyBase app you could imagine. It
|
|
30
|
+
contains a handful of key-values and tables which are mutated with the
|
|
31
|
+
buttons below. There's no fancy rendering - just the raw JSON of the
|
|
32
|
+
underlying store. See the full set of
|
|
33
|
+
<a href="https://tinybase.org/demos/">TinyBase demos</a> for more
|
|
34
|
+
interesting examples!
|
|
35
|
+
</p>
|
|
36
|
+
<div id="buttons">
|
|
37
|
+
<button id="countButton">Increment number</button>
|
|
38
|
+
<button id="randomButton">Random number</button>
|
|
39
|
+
<button id="addPetButton">Add a pet</button>
|
|
40
|
+
</div>
|
|
41
|
+
<details open>
|
|
42
|
+
<summary>Values</summary>
|
|
43
|
+
<pre id="valuesJson"></pre>
|
|
44
|
+
</details>
|
|
45
|
+
<details open>
|
|
46
|
+
<summary>Tables</summary>
|
|
47
|
+
<pre id="tablesJson"></pre>
|
|
48
|
+
</details>
|
|
49
|
+
</div>
|
|
50
|
+
{{/if}}
|
|
51
|
+
{{includeFile template="src/index.tsx.hbs" output="src/index.{{ext}}"}}
|
|
52
|
+
<script type="module" src="/src/index.{{ext}}"></script>
|
|
53
|
+
</body>
|
|
54
|
+
|
|
55
|
+
</html>
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
"version": "1.0.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
{{#list}}
|
|
6
|
+
{{includeFile template="index.html.hbs" output="index.html"}}
|
|
6
7
|
"dev": "vite"
|
|
7
8
|
{{#if typescript}}
|
|
8
9
|
"build": "tsc && vite build"
|
|
@@ -26,8 +27,8 @@
|
|
|
26
27
|
"typescript": "^5.9.3"
|
|
27
28
|
"@types/node": "^25.0.3"
|
|
28
29
|
{{#if react}}
|
|
29
|
-
"@types/react": "^
|
|
30
|
-
"@types/react-dom": "^
|
|
30
|
+
"@types/react": "^19.2.7"
|
|
31
|
+
"@types/react-dom": "^19.2.3"
|
|
31
32
|
{{/if}}
|
|
32
33
|
{{/if}}
|
|
33
34
|
{{#if react}}
|
|
@@ -42,19 +43,31 @@
|
|
|
42
43
|
"typescript-eslint": "^8.51.0"
|
|
43
44
|
{{/if}}
|
|
44
45
|
{{#if react}}
|
|
45
|
-
"eslint-plugin-react": "
|
|
46
|
-
"eslint-plugin-react-hooks": "^
|
|
46
|
+
"eslint-plugin-react": "7.37.5"
|
|
47
|
+
"eslint-plugin-react-hooks": "^7.0.1"
|
|
47
48
|
{{/if}}
|
|
48
49
|
{{/if}}
|
|
49
50
|
{{/list}}
|
|
50
51
|
},
|
|
51
52
|
"dependencies": {
|
|
52
53
|
{{#list}}
|
|
53
|
-
"tinybase": "^
|
|
54
|
+
"tinybase": "^7.3.1"
|
|
54
55
|
{{#if react}}
|
|
55
|
-
"react": "^
|
|
56
|
-
"react-dom": "^
|
|
56
|
+
"react": "^19.2.3"
|
|
57
|
+
"react-dom": "^19.2.3"
|
|
57
58
|
{{/if}}
|
|
58
59
|
{{/list}}
|
|
59
60
|
}
|
|
60
|
-
}
|
|
61
|
+
}
|
|
62
|
+
{{#if prettier}}
|
|
63
|
+
{{includeFile template=".prettierrc.hbs" output=".prettierrc"}}
|
|
64
|
+
{{/if}}
|
|
65
|
+
{{#if eslint}}
|
|
66
|
+
{{includeFile template="eslint.config.js.hbs" output="eslint.config.js"}}
|
|
67
|
+
{{/if}}
|
|
68
|
+
{{#if react}}
|
|
69
|
+
{{includeFile template="vite.config.js.hbs" output="vite.config.js"}}
|
|
70
|
+
{{/if}}
|
|
71
|
+
{{#if typescript}}
|
|
72
|
+
{{includeFile template="tsconfig.json.hbs" output="tsconfig.json"}}
|
|
73
|
+
{{/if}}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<svg viewBox="0 0 680 680" xmlns="http://www.w3.org/2000/svg" style="width:680px;height:680px">
|
|
2
|
+
<path stroke="#fff" stroke-width="80" fill="none"
|
|
3
|
+
d="M340 617a84 241 90 11.01 0zM131 475a94 254 70 10428-124 114 286 70 01-428 124zm0-140a94 254 70 10428-124 114 286 70 01-428 124zm-12-127a94 254 70 00306 38 90 260 90 01-306-38zm221 3a74 241 90 11.01 0z" />
|
|
4
|
+
<path fill="#d81b60"
|
|
5
|
+
d="M131 475a94 254 70 10428-124 114 286 70 01-428 124zm0-140a94 254 70 10428-124 114 286 70 01-428 124z" />
|
|
6
|
+
<path
|
|
7
|
+
d="M249 619a94 240 90 00308-128 114 289 70 01-308 128zM119 208a94 254 70 00306 38 90 260 90 01-306-38zm221 3a74 241 90 11.01 0z" />
|
|
8
|
+
</svg>
|
|
@@ -1,24 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import {StrictMode} from 'react';
|
|
2
|
+
import {createStore} from 'tinybase';
|
|
3
|
+
import {Provider, useCreateStore} from 'tinybase/ui-react';
|
|
4
|
+
import {SortedTableInHtmlTable, ValuesInHtmlTable} from 'tinybase/ui-react-dom';
|
|
5
|
+
import {Inspector} from 'tinybase/ui-react-inspector';
|
|
6
|
+
import {Buttons} from './Buttons';
|
|
3
7
|
|
|
4
|
-
const
|
|
8
|
+
export const App = () => {
|
|
9
|
+
const store = useCreateStore(() => {
|
|
10
|
+
// Create the TinyBase Store and initialize the Store's data
|
|
11
|
+
return createStore()
|
|
12
|
+
.setValue('counter', 0)
|
|
13
|
+
.setRow('pets', '0', {name: 'fido', species: 'dog'})
|
|
14
|
+
.setTable('species', {
|
|
15
|
+
dog: {price: 5},
|
|
16
|
+
cat: {price: 4},
|
|
17
|
+
fish: {price: 2},
|
|
18
|
+
worm: {price: 1},
|
|
19
|
+
parrot: {price: 3},
|
|
20
|
+
});
|
|
21
|
+
});
|
|
5
22
|
|
|
6
|
-
|
|
23
|
+
return (
|
|
24
|
+
<StrictMode>
|
|
7
25
|
<Provider store={store}>
|
|
8
|
-
<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
26
|
+
<header>
|
|
27
|
+
<h1>
|
|
28
|
+
<img src="/favicon.svg" />
|
|
29
|
+
TinyBase / {{#if typescript}}TypeScript{{else}}JavaScript{{/if}} + React
|
|
30
|
+
</h1>
|
|
31
|
+
</header>
|
|
32
|
+
<p>
|
|
33
|
+
This is more or less the simplest TinyBase app you could imagine. It
|
|
34
|
+
contains a handful of key-values and tables which are mutated with the
|
|
35
|
+
buttons below, and rendered with plain table components. See the full
|
|
36
|
+
set of <a href="https://tinybase.org/demos/">TinyBase demos</a> for
|
|
37
|
+
more interesting examples!
|
|
38
|
+
</p>
|
|
39
|
+
<Buttons />
|
|
17
40
|
<div>
|
|
18
|
-
<
|
|
19
|
-
<
|
|
20
|
-
Increment
|
|
21
|
-
</button>
|
|
41
|
+
<h2>Values</h2>
|
|
42
|
+
<ValuesInHtmlTable />
|
|
22
43
|
</div>
|
|
23
|
-
|
|
24
|
-
|
|
44
|
+
<div>
|
|
45
|
+
<h2>Pets Table</h2>
|
|
46
|
+
<SortedTableInHtmlTable tableId="pets" cellId="name" limit={5} sortOnClick={true} className="sortedTable" paginator={true} />
|
|
47
|
+
</div>
|
|
48
|
+
<Inspector />
|
|
49
|
+
</Provider>
|
|
50
|
+
</StrictMode>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {useAddRowCallback, useSetValueCallback} from 'tinybase/ui-react';
|
|
2
|
+
import type {ValueOrUndefined} from 'tinybase';
|
|
3
|
+
|
|
4
|
+
// Convenience function for generating a random integer
|
|
5
|
+
const getRandom = (max = 100) => Math.floor(Math.random() * max);
|
|
6
|
+
|
|
7
|
+
export const Buttons = () => {
|
|
8
|
+
// Attach events to the buttons to mutate the data in the TinyBase Store
|
|
9
|
+
const handleCount = useSetValueCallback(
|
|
10
|
+
'counter',
|
|
11
|
+
() => (value: ValueOrUndefined) => ((value ?? 0) as number) + 1,
|
|
12
|
+
);
|
|
13
|
+
const handleRandom = useSetValueCallback('random', () => getRandom());
|
|
14
|
+
const handleAddPet = useAddRowCallback('pets', (_, store) => ({
|
|
15
|
+
name: ['fido', 'felix', 'bubbles', 'lowly', 'polly'][getRandom(5)],
|
|
16
|
+
species: store.getRowIds('species')[getRandom(5)],
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<div id="buttons">
|
|
21
|
+
<button onClick={handleCount}>Increment number</button>
|
|
22
|
+
<button onClick={handleRandom}>Random number</button>
|
|
23
|
+
<button onClick={handleAddPet}>Add a pet</button>
|
|
24
|
+
</div>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {createStore} from 'tinybase';
|
|
2
|
+
|
|
3
|
+
const onClick = (id: string, onClick: () => void) =>
|
|
4
|
+
document.getElementById(id)!.addEventListener('click', onClick);
|
|
5
|
+
|
|
6
|
+
const updateJson = (id: string, content: unknown) =>
|
|
7
|
+
(document.getElementById(id)!.innerText = JSON.stringify(content, null, 2));
|
|
8
|
+
|
|
9
|
+
const getRandom = (max = 100) => Math.floor(Math.random() * max);
|
|
10
|
+
|
|
11
|
+
export const app = () => {
|
|
12
|
+
const store = createStore();
|
|
13
|
+
|
|
14
|
+
onClick('countButton', () => store.setValue('counter', (value) => value + 1));
|
|
15
|
+
onClick('randomButton', () => store.setValue('random', getRandom()));
|
|
16
|
+
onClick('addPetButton', () =>
|
|
17
|
+
store.addRow('pets', {
|
|
18
|
+
name: ['fido', 'felix', 'bubbles', 'lowly', 'polly'][getRandom(5)],
|
|
19
|
+
species: store.getRowIds('species')[getRandom(5)],
|
|
20
|
+
}),
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
store.addValuesListener(() => updateJson('valuesJson', store.getValues()));
|
|
24
|
+
store.addTablesListener(() => updateJson('tablesJson', store.getTables()));
|
|
25
|
+
|
|
26
|
+
store
|
|
27
|
+
.setValue('counter', 0)
|
|
28
|
+
.setRow('pets', '0', {name: 'fido', species: 'dog'})
|
|
29
|
+
.setTable('species', {
|
|
30
|
+
dog: {price: 5},
|
|
31
|
+
cat: {price: 4},
|
|
32
|
+
fish: {price: 2},
|
|
33
|
+
worm: {price: 1},
|
|
34
|
+
parrot: {price: 3},
|
|
35
|
+
});
|
|
36
|
+
};
|
|
@@ -1,110 +1,138 @@
|
|
|
1
1
|
body {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
color: #bbb;
|
|
3
|
+
background: #111;
|
|
4
|
+
font-family: 'Inter', sans-serif;
|
|
5
|
+
user-select: none;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
#app {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
max-width: 40rem;
|
|
10
|
+
margin: 2rem auto;
|
|
11
|
+
display: grid;
|
|
12
|
+
grid-template-columns: 1fr;
|
|
13
|
+
column-gap: 2rem;
|
|
14
|
+
align-items: start;
|
|
15
|
+
row-gap: 1rem;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
a {
|
|
19
|
-
|
|
19
|
+
color: #bbb;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
h1 {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
font-weight: 600;
|
|
24
|
+
img {
|
|
25
|
+
margin-right: 1rem;
|
|
26
|
+
height: 2.5rem;
|
|
27
|
+
vertical-align: text-bottom;
|
|
28
|
+
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
h2 {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
font-weight: 800;
|
|
33
|
+
font-size: 1.3rem;
|
|
34
|
+
margin: 1rem 0 0;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
p {
|
|
38
|
+
margin: 0 0 1rem;
|
|
39
|
+
line-height: 1.5;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
details {
|
|
43
|
+
border: 1px solid #333;
|
|
44
|
+
border-radius: 0.25rem;
|
|
45
|
+
padding: 0.5rem;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
details summary {
|
|
49
|
+
cursor: pointer;
|
|
50
|
+
font-weight: 800;
|
|
51
|
+
margin: -0.5rem -0.5rem 0;
|
|
52
|
+
padding: 0.5rem;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
details[open] summary {
|
|
56
|
+
margin-bottom: 0.5rem;
|
|
57
|
+
border-bottom: 1px solid #333;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
pre {
|
|
61
|
+
margin: 0;
|
|
62
|
+
white-space: pre-wrap;
|
|
63
|
+
word-wrap: break-word;
|
|
36
64
|
}
|
|
37
65
|
|
|
38
66
|
#buttons {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
67
|
+
border: solid #666;
|
|
68
|
+
border-width: 1px 0;
|
|
69
|
+
text-align: center;
|
|
42
70
|
}
|
|
43
71
|
|
|
44
72
|
#buttons button {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
73
|
+
border: 1px solid #666;
|
|
74
|
+
border-radius: 0.25rem;
|
|
75
|
+
padding: 0.5rem 1rem;
|
|
76
|
+
background: #222;
|
|
77
|
+
color: #fff;
|
|
78
|
+
font-family: inherit;
|
|
79
|
+
font-weight: 800;
|
|
80
|
+
font-size: 0.8rem;
|
|
81
|
+
width: 10rem;
|
|
82
|
+
margin: 1rem;
|
|
55
83
|
}
|
|
56
84
|
#buttons button:hover {
|
|
57
|
-
|
|
85
|
+
border-color: #d81b60;
|
|
58
86
|
}
|
|
59
87
|
|
|
60
88
|
table {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
89
|
+
border-collapse: collapse;
|
|
90
|
+
font-size: inherit;
|
|
91
|
+
line-height: inherit;
|
|
92
|
+
margin-top: 0.5rem;
|
|
93
|
+
table-layout: fixed;
|
|
94
|
+
width: 100%;
|
|
95
|
+
margin-bottom: 2rem;
|
|
96
|
+
caption-side: bottom;
|
|
69
97
|
}
|
|
70
98
|
table caption {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
99
|
+
text-align: left;
|
|
100
|
+
button {
|
|
101
|
+
border: 0;
|
|
102
|
+
margin-right: 0.25rem;
|
|
103
|
+
}
|
|
76
104
|
}
|
|
77
105
|
table caption button {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
106
|
+
line-height: 0.7rem;
|
|
107
|
+
margin: 0 0.25rem 0 0;
|
|
108
|
+
vertical-align: middle;
|
|
81
109
|
}
|
|
82
110
|
th,
|
|
83
111
|
td {
|
|
84
|
-
|
|
85
|
-
|
|
112
|
+
padding: 0.25rem 0.5rem 0.25rem 0;
|
|
113
|
+
text-align: left;
|
|
86
114
|
}
|
|
87
115
|
thead th,
|
|
88
116
|
thead td {
|
|
89
|
-
|
|
90
|
-
|
|
117
|
+
border: solid #999;
|
|
118
|
+
border-width: 1px 0;
|
|
91
119
|
}
|
|
92
120
|
tbody th,
|
|
93
121
|
tbody td {
|
|
94
|
-
|
|
122
|
+
border-bottom: 1px solid #333;
|
|
95
123
|
}
|
|
96
124
|
|
|
97
125
|
table.sortedTable thead th {
|
|
98
|
-
|
|
126
|
+
cursor: pointer;
|
|
99
127
|
}
|
|
100
128
|
|
|
101
129
|
@media (min-width: 40rem) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
130
|
+
#app {
|
|
131
|
+
grid-template-columns: 1fr 1fr;
|
|
132
|
+
}
|
|
133
|
+
header,
|
|
134
|
+
p,
|
|
135
|
+
#buttons {
|
|
136
|
+
grid-column: span 2;
|
|
110
137
|
}
|
|
138
|
+
}
|
|
@@ -1,48 +1,18 @@
|
|
|
1
|
-
{{
|
|
2
|
-
|
|
1
|
+
{{includeFile template="src/index.css.hbs" output="src/index.css"}}
|
|
2
|
+
import './index.css';
|
|
3
3
|
{{#if react}}
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import ReactDOM from 'react-dom/client';
|
|
5
|
+
import {App} from './App';
|
|
6
|
+
{{includeFile template="src/App.tsx.hbs" output="src/App.{{ext}}"}}
|
|
7
|
+
{{includeFile template="src/Buttons.tsx.hbs" output="src/Buttons.{{ext}}"}}
|
|
6
8
|
|
|
7
9
|
addEventListener('load', () =>
|
|
8
|
-
|
|
10
|
+
ReactDOM.createRoot(document.getElementById('app')!).render(
|
|
11
|
+
<App />),
|
|
9
12
|
);
|
|
10
|
-
|
|
11
13
|
{{else}}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const onClick = (id: string, onClick: () => void) =>
|
|
15
|
-
document.getElementById(id)!.addEventListener('click', onClick);
|
|
16
|
-
|
|
17
|
-
const updateJson = (id: string, content: unknown) =>
|
|
18
|
-
(document.getElementById(id)!.innerText = JSON.stringify(content, null, 2));
|
|
19
|
-
|
|
20
|
-
const getRandom = (max = 100) => Math.floor(Math.random() * max);
|
|
21
|
-
|
|
22
|
-
addEventListener('load', () => {
|
|
23
|
-
const store = createStore();
|
|
24
|
-
|
|
25
|
-
onClick('countButton', () => store.setValue('counter', (value) => value + 1));
|
|
26
|
-
onClick('randomButton', () => store.setValue('random', getRandom()));
|
|
27
|
-
onClick('addPetButton', () =>
|
|
28
|
-
store.addRow('pets', {
|
|
29
|
-
name: ['fido', 'felix', 'bubbles', 'lowly', 'polly'][getRandom(5)],
|
|
30
|
-
species: store.getRowIds('species')[getRandom(5)],
|
|
31
|
-
}),
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
store.addValuesListener(() => updateJson('valuesJson', store.getValues()));
|
|
35
|
-
store.addTablesListener(() => updateJson('tablesJson', store.getTables()));
|
|
14
|
+
import {app} from './app';
|
|
15
|
+
{{includeFile template="src/app.ts.hbs" output="src/app.{{ext}}"}}
|
|
36
16
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
.setRow('pets', '0', {name: 'fido', species: 'dog'})
|
|
40
|
-
.setTable('species', {
|
|
41
|
-
dog: {price: 5},
|
|
42
|
-
cat: {price: 4},
|
|
43
|
-
fish: {price: 2},
|
|
44
|
-
worm: {price: 1},
|
|
45
|
-
parrot: {price: 3},
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
{{/if}}
|
|
17
|
+
addEventListener('load', app);
|
|
18
|
+
{{/if}}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{{addImport "import {defineConfig} from 'vite';"}}
|
|
2
|
-
{{#if
|
|
2
|
+
{{#if react}}
|
|
3
3
|
{{addImport "import react from '@vitejs/plugin-react';"}}
|
|
4
4
|
{{/if}}
|
|
5
5
|
|
|
6
6
|
export default defineConfig({
|
|
7
|
-
{{#if
|
|
8
|
-
plugins: [react(
|
|
7
|
+
{{#if react}}
|
|
8
|
+
plugins: [react({
|
|
9
|
+
jsxRuntime: 'automatic',
|
|
10
|
+
})],
|
|
9
11
|
{{/if}}
|
|
10
12
|
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<meta charset="UTF-8" />
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
-
<title>TinyBase</title>
|
|
8
|
-
</head>
|
|
9
|
-
|
|
10
|
-
<body>
|
|
11
|
-
{{#if react}}
|
|
12
|
-
<div id="app"></div>
|
|
13
|
-
{{/if}}
|
|
14
|
-
<script type="module" src="/src/index.{{ext}}"></script>
|
|
15
|
-
</body>
|
|
16
|
-
|
|
17
|
-
</html>
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|