@alstar/studio 0.0.0-beta.7 → 0.0.0-beta.9
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/api/api-key.ts +1 -2
- package/api/backup.ts +38 -0
- package/api/index.ts +6 -3
- package/components/Backup.ts +10 -0
- package/components/BlockRenderer.ts +8 -8
- package/components/Render.ts +1 -1
- package/components/Settings.ts +3 -0
- package/components/SiteLayout.ts +1 -4
- package/index.ts +2 -2
- package/package.json +3 -3
- package/public/studio/{sortable-list.js → js/sortable-list.js} +12 -2
- package/public/studio/main.css +3 -4
- package/public/studio/main.js +4 -5
- package/utils/startup-log.ts +2 -1
- package/public/studio/entry.css +0 -7
- /package/public/studio/{admin-panel.css → css/admin-panel.css} +0 -0
- /package/public/studio/{blocks.css → css/blocks-field.css} +0 -0
- /package/public/studio/{settings.css → css/settings.css} +0 -0
- /package/public/studio/{markdown-editor.js → js/markdown-editor.js} +0 -0
package/api/api-key.ts
CHANGED
|
@@ -7,10 +7,9 @@ import crypto from 'node:crypto'
|
|
|
7
7
|
|
|
8
8
|
import { stripNewlines } from '../utils/strip-newlines.ts'
|
|
9
9
|
import { sql } from '../utils/sql.ts'
|
|
10
|
-
import { type Structure } from '../types.ts'
|
|
11
10
|
import Settings from '../components/Settings.ts'
|
|
12
11
|
|
|
13
|
-
export default (
|
|
12
|
+
export default () => {
|
|
14
13
|
const app = new Hono<{ Bindings: HttpBindings }>()
|
|
15
14
|
|
|
16
15
|
app.post('/api-key', async (c) => {
|
package/api/backup.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type HttpBindings } from '@hono/node-server'
|
|
2
|
+
import { Hono } from 'hono'
|
|
3
|
+
import { streamSSE } from 'hono/streaming'
|
|
4
|
+
import { DatabaseSync } from 'node:sqlite'
|
|
5
|
+
|
|
6
|
+
import { stripNewlines } from '../utils/strip-newlines.ts'
|
|
7
|
+
import { db } from '@alstar/db'
|
|
8
|
+
|
|
9
|
+
export default () => {
|
|
10
|
+
const app = new Hono<{ Bindings: HttpBindings }>()
|
|
11
|
+
|
|
12
|
+
app.post('/backup', async (c) => {
|
|
13
|
+
// const totalPagesTransferred = await backup(db.database, './backups/backup.db', {
|
|
14
|
+
// rate: 1, // Copy one page at a time.
|
|
15
|
+
// progress: ({ totalPages, remainingPages }) => {
|
|
16
|
+
// console.log('Backup in progress', { totalPages, remainingPages })
|
|
17
|
+
// },
|
|
18
|
+
// })
|
|
19
|
+
|
|
20
|
+
// console.log('Backup completed', totalPagesTransferred)
|
|
21
|
+
|
|
22
|
+
return c.html('good')
|
|
23
|
+
|
|
24
|
+
// return streamSSE(c, async (stream) => {
|
|
25
|
+
// await stream.writeSSE({
|
|
26
|
+
// event: 'datastar-patch-signals',
|
|
27
|
+
// data: `signals {}`,
|
|
28
|
+
// })
|
|
29
|
+
|
|
30
|
+
// await stream.writeSSE({
|
|
31
|
+
// event: 'datastar-patch-elements',
|
|
32
|
+
// data: `elements ${stripNewlines(Settings())}`,
|
|
33
|
+
// })
|
|
34
|
+
// })
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
return app
|
|
38
|
+
}
|
package/api/index.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import block from './block.ts'
|
|
2
2
|
import apiKey from './api-key.ts'
|
|
3
|
+
import type { Structure } from '../types.ts'
|
|
4
|
+
import backup from './backup.ts'
|
|
3
5
|
|
|
4
|
-
export const api = (structure) => {
|
|
6
|
+
export const api = (structure: Structure) => {
|
|
5
7
|
const app = block(structure)
|
|
6
|
-
|
|
7
|
-
app.route('/', apiKey(
|
|
8
|
+
|
|
9
|
+
app.route('/', apiKey())
|
|
10
|
+
app.route('/', backup())
|
|
8
11
|
|
|
9
12
|
return app
|
|
10
13
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { html } from 'hono/html'
|
|
2
|
+
|
|
3
|
+
export default () => {
|
|
4
|
+
return html`<article>
|
|
5
|
+
<header>Backup</header>
|
|
6
|
+
<form data-on-submit="@post('/admin/api/backup', { contentType: 'form' })">
|
|
7
|
+
<button type="submit">Backup database</button>
|
|
8
|
+
</form>
|
|
9
|
+
</article>`
|
|
10
|
+
}
|
|
@@ -8,15 +8,15 @@ export default (props: {
|
|
|
8
8
|
id?: number
|
|
9
9
|
structure: BlockDef
|
|
10
10
|
}) => {
|
|
11
|
-
const { entryId, parentId, structure
|
|
11
|
+
const { entryId, parentId, structure } = props
|
|
12
12
|
|
|
13
13
|
const entries = Object.entries(structure.fields)
|
|
14
14
|
|
|
15
|
-
return entries.map(([name, field]) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
return html`${entries.map(([name, field]) => {
|
|
16
|
+
try {
|
|
17
|
+
return Render({ entryId, parentId, structure: field, name })
|
|
18
|
+
} catch (error) {
|
|
19
|
+
return html`<p>Cound not render: "${name}"</p>`
|
|
20
|
+
}
|
|
21
|
+
})}`
|
|
22
22
|
}
|
package/components/Render.ts
CHANGED
|
@@ -21,7 +21,7 @@ export default (props: {
|
|
|
21
21
|
id?: number
|
|
22
22
|
name: string
|
|
23
23
|
sortOrder?: number
|
|
24
|
-
}): HtmlEscapedString | Promise<HtmlEscapedString>
|
|
24
|
+
}): HtmlEscapedString | Promise<HtmlEscapedString> => {
|
|
25
25
|
const { entryId, parentId, structure, name, id } = props
|
|
26
26
|
|
|
27
27
|
if (!structure) return html`<p>No block</p>`
|
package/components/Settings.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { db } from '@alstar/db'
|
|
|
2
2
|
import { html } from 'hono/html'
|
|
3
3
|
import { sql } from '../utils/sql.ts'
|
|
4
4
|
import * as icons from './icons.ts'
|
|
5
|
+
import Backup from './Backup.ts'
|
|
5
6
|
|
|
6
7
|
export default () => {
|
|
7
8
|
const apiKeys = db.database
|
|
@@ -93,6 +94,8 @@ export default () => {
|
|
|
93
94
|
</article>
|
|
94
95
|
</dialog>
|
|
95
96
|
</article>
|
|
97
|
+
|
|
98
|
+
<!-- {Backup()} -->
|
|
96
99
|
</div>
|
|
97
100
|
`
|
|
98
101
|
}
|
package/components/SiteLayout.ts
CHANGED
|
@@ -25,8 +25,6 @@ export default (props: {
|
|
|
25
25
|
|
|
26
26
|
<meta name="color-scheme" content="light dark" />
|
|
27
27
|
|
|
28
|
-
<link rel="stylesheet" href="/studio/main.css" />
|
|
29
|
-
|
|
30
28
|
<script
|
|
31
29
|
type="module"
|
|
32
30
|
src="https://cdn.jsdelivr.net/gh/starfederation/datastar@main/bundles/datastar.js"
|
|
@@ -42,9 +40,8 @@ export default (props: {
|
|
|
42
40
|
}
|
|
43
41
|
</script>
|
|
44
42
|
|
|
45
|
-
<script src="/studio/markdown-editor.js" type="module"></script>
|
|
46
|
-
<script src="/studio/sortable-list.js" type="module"></script>
|
|
47
43
|
<script src="/studio/main.js" type="module"></script>
|
|
44
|
+
<link href="/studio/main.css" rel="stylesheet" />
|
|
48
45
|
</head>
|
|
49
46
|
|
|
50
47
|
<body data-barba="wrapper">
|
package/index.ts
CHANGED
|
@@ -23,7 +23,7 @@ export let studioConfig: types.StudioConfig = {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const createStudio = async (config: types.StudioConfig) => {
|
|
26
|
-
createRefresher({ rootdir: '.' })
|
|
26
|
+
const refresher = await createRefresher({ rootdir: '.' })
|
|
27
27
|
|
|
28
28
|
loadDb('./studio.db')
|
|
29
29
|
createStudioTables()
|
|
@@ -84,7 +84,7 @@ const createStudio = async (config: types.StudioConfig) => {
|
|
|
84
84
|
})
|
|
85
85
|
})
|
|
86
86
|
|
|
87
|
-
startupLog({ port: studioConfig.port || 3000 })
|
|
87
|
+
startupLog({ port: studioConfig.port || 3000, refresherPort: refresher.port })
|
|
88
88
|
|
|
89
89
|
return app
|
|
90
90
|
}
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alstar/studio",
|
|
3
|
-
"version": "0.0.0-beta.
|
|
3
|
+
"version": "0.0.0-beta.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@hono/node-server": "^1.18.1",
|
|
8
8
|
"@starfederation/datastar-sdk": "1.0.0-RC.1",
|
|
9
9
|
"hono": "^4.8.12",
|
|
10
|
+
"@alstar/refresher": "0.0.0-beta.3",
|
|
10
11
|
"@alstar/ui": "0.0.0-beta.1",
|
|
11
|
-
"@alstar/db": "0.0.0-beta.1"
|
|
12
|
-
"@alstar/refresher": "0.0.0-beta.2"
|
|
12
|
+
"@alstar/db": "0.0.0-beta.1"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@types/node": "^24.1.0",
|
|
@@ -3,8 +3,10 @@ import Sortable from 'sortablejs'
|
|
|
3
3
|
class SortableList extends HTMLElement {
|
|
4
4
|
instance = null
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
mutationObserver
|
|
7
|
+
|
|
8
|
+
init() {
|
|
9
|
+
if (this.instance || !this.children.length) return
|
|
8
10
|
|
|
9
11
|
const { id } = this.dataset
|
|
10
12
|
|
|
@@ -32,8 +34,16 @@ class SortableList extends HTMLElement {
|
|
|
32
34
|
})
|
|
33
35
|
}
|
|
34
36
|
|
|
37
|
+
connectedCallback() {
|
|
38
|
+
this.mutationObserver = new MutationObserver(this.init.bind(this))
|
|
39
|
+
this.mutationObserver.observe(this, { childList: true })
|
|
40
|
+
|
|
41
|
+
this.init()
|
|
42
|
+
}
|
|
43
|
+
|
|
35
44
|
disconnectedCallback() {
|
|
36
45
|
this.instance?.destroy()
|
|
46
|
+
this.mutationObserver?.disconnect()
|
|
37
47
|
}
|
|
38
48
|
}
|
|
39
49
|
|
package/public/studio/main.css
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/* @import './../node_modules/@alstar/ui/red.css'; */
|
|
2
2
|
@import 'https://esm.sh/@alstar/ui/red.css';
|
|
3
|
-
@import './admin-panel.css';
|
|
4
|
-
@import './
|
|
5
|
-
@import './
|
|
6
|
-
@import './settings.css';
|
|
3
|
+
@import './css/admin-panel.css';
|
|
4
|
+
@import './css/blocks-field.css';
|
|
5
|
+
@import './css/settings.css';
|
|
7
6
|
|
|
8
7
|
body {
|
|
9
8
|
padding: 0;
|
package/public/studio/main.js
CHANGED
package/utils/startup-log.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import packageJSON from '../package.json' with { type: 'json' }
|
|
2
2
|
|
|
3
|
-
export default ({ port }: { port: number }) => {
|
|
3
|
+
export default ({ port, refresherPort }: { port: number, refresherPort: number }) => {
|
|
4
4
|
console.log('\x1b[32m%s\x1b[0m', '╭───────────────────────╮')
|
|
5
5
|
console.log('\x1b[32m%s\x1b[0m', '│ Alstar Studio │')
|
|
6
6
|
console.log('\x1b[32m%s\x1b[0m', `│ ${packageJSON.version}${' '.repeat(22 - packageJSON.version.length)}│`)
|
|
7
7
|
console.log('\x1b[32m%s\x1b[0m', `│ http://localhost:${port} │`)
|
|
8
|
+
console.log('\x1b[32m%s\x1b[0m', `│ Refresher port: ${refresherPort} │`)
|
|
8
9
|
console.log('\x1b[32m%s\x1b[0m', '╰───────────────────────╯')
|
|
9
10
|
}
|
package/public/studio/entry.css
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|