This commit is contained in:
Anya Tokugawa committed 2026-05-19 21:30:42 +09:00
commit fa6a4c650f
93 files changed
+6555

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
.dialog {
width: min(800px, 90vw);
border: 1px solid #333;
background: #1b1b1b;
color: #eee;
}
.dialog-body {
padding: 1rem;
}
.search-input {
width: 100%;
padding: 0.75rem;
background: #111;
color: #eee;
border: 1px solid #333;
}
.search-results {
margin-top: 1rem;
list-style: none;
padding: 0;
}
+10
View File
@@ -0,0 +1,10 @@
.tree {
list-style: none;
margin-left: 1rem;
padding-left: 1rem;
border-left: 1px solid #333;
}
.tree li {
margin: 0.4rem 0;
}
+53
View File
@@ -0,0 +1,53 @@
body {
background: #111;
color: #eee;
font-family: sans-serif;
margin: 0;
}
.topbar {
display: flex;
justify-content: space-between;
padding: 1rem;
border-bottom: 1px solid #333;
}
.topbar a {
color: #9ecbff;
text-decoration: none;
margin-right: 1rem;
}
.container {
padding: 1rem;
}
.card {
border: 1px solid #333;
background: #1b1b1b;
padding: 1rem;
margin-bottom: 1rem;
}
.editor-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 1rem;
}
.editor {
width: 100%;
min-height: 70vh;
background: #111;
color: #eee;
}
.preview {
border: 1px solid #333;
padding: 1rem;
overflow: auto;
}
.page-html {
line-height: 1.8;
}
+7
View File
@@ -0,0 +1,7 @@
body.mode-editor .page-html {
display: none;
}
body.mode-view textarea.editor {
display: none;
}
+55
View File
@@ -0,0 +1,55 @@
.diff-view {
margin: 0;
padding: 0;
white-space: pre-wrap;
font-family: monospace;
line-height: 1.0;
}
.diff-view div {
margin: 0;
padding: 0;
line-height: 1.0;
}
.diff-same {
color: #888;
}
.diff-add {
color: #7CFC7C;
opacity: 0.92;
}
.diff-del {
color: #FF7C7C;
opacity: 0.92;
}
.page-html {
line-height: 1.7;
}
.revision-textarea {
width: 100%;
min-height: 50vh;
background: #111;
color: #eee;
border: 1px solid #333;
padding: 1rem;
font-family: monospace;
white-space: pre;
margin-top: 1rem;
}
details summary {
cursor: pointer;
user-select: none;
}
.diff-line-no {
display: inline-block;
width: 4em;
color: #666;
user-select: none;
}
+163
View File
@@ -0,0 +1,163 @@
let dirty = false
async function renderMarkdownPreview() {
const editor =
document.getElementById(
"editor",
)
const preview =
document.getElementById(
"preview",
)
if (!editor || !preview) {
return
}
const res = await fetch(
"/_/api/v1/render/markdown",
{
method: "POST",
headers: {
"Content-Type":
"application/json",
},
body: JSON.stringify({
markdown:
editor.value,
}),
},
)
const data =
await res.json()
preview.innerHTML =
data.html
}
async function restoreRevision(
revisionUUID,
) {
const res = await fetch(
"/_/api/v1/revisions/restore?revision="
+ revisionUUID,
)
if (!res.ok) {
alert("restore failed")
return
}
location.reload()
}
async function openRevisionDialog() {
const objectUUID =
document.getElementById(
"object-uuid",
).value
const res = await fetch(
"/_/api/v1/revisions/list?uuid="
+ objectUUID,
)
const revisions =
await res.json()
const root =
document.getElementById(
"revision-list",
)
root.innerHTML = ""
revisions.forEach((r) => {
const div =
document.createElement("div")
div.className =
"revision-item"
const ts =
new Date(
r.created_at * 1000,
)
div.innerHTML =
"<code>"
+ r.uuid
+ "</code><br>"
+ ts.toLocaleString()
+ "<br>"
+ r.message
+ "<br><button onclick=\"restoreRevision('"
+ r.uuid
+ "')\">Restore</button>"
root.appendChild(div)
})
document.getElementById(
"revision-dialog",
).showModal()
}
window.addEventListener(
"beforeunload",
(ev) => {
if (!dirty) {
return
}
ev.preventDefault()
},
)
document.addEventListener(
"DOMContentLoaded",
() => {
const editor =
document.getElementById(
"editor",
)
if (editor) {
renderMarkdownPreview()
editor.addEventListener(
"input",
() => {
dirty = true
renderMarkdownPreview()
},
)
setInterval(
() => {
if (!dirty) {
return
}
saveRevision()
dirty = false
},
30000,
)
}
},
)
+315
View File
@@ -0,0 +1,315 @@
window.PagesEditor = {
autosaveTimer: null,
init() {
const editor =
document.getElementById(
"editor",
)
const preview =
document.getElementById(
"preview",
)
const editType =
document.getElementById(
"edit-type",
)
if (
!editor
||
!preview
) {
return
}
const renderPreview =
async () => {
if (
editType.value
===
"html"
) {
preview.innerHTML =
editor.value
return editor.value
}
const res =
await fetch(
"/_/api/v1/render/markdown",
{
method: "POST",
headers: {
"Content-Type":
"application/json",
},
body: JSON.stringify({
markdown:
editor.value,
}),
},
)
if (!res.ok) {
preview.innerText =
editor.value
return editor.value
}
const data =
await res.json()
preview.innerHTML =
data.html
return data.html
}
editor.addEventListener(
"input",
async () => {
await renderPreview()
clearTimeout(
this.autosaveTimer,
)
this.autosaveTimer =
setTimeout(
() => {
this.autosave()
},
3000,
)
},
)
document.addEventListener(
"keydown",
(ev) => {
if (
(ev.ctrlKey || ev.metaKey)
&&
ev.key === "s"
) {
ev.preventDefault()
this.saveNow()
}
},
)
renderPreview()
},
async getCanonicalHTML() {
const editor =
document.getElementById(
"editor",
)
const editType =
document.getElementById(
"edit-type",
)
if (
editType.value
===
"html"
) {
return editor.value
}
const res =
await fetch(
"/_/api/v1/render/markdown",
{
method: "POST",
headers: {
"Content-Type":
"application/json",
},
body: JSON.stringify({
markdown:
editor.value,
}),
},
)
if (!res.ok) {
return editor.value
}
const data =
await res.json()
return data.html
},
async autosave() {
const objectUUID =
document.getElementById(
"object-uuid",
)
if (
!objectUUID
||
!objectUUID.value
) {
return
}
const canonicalHTML =
await this.getCanonicalHTML()
await fetch(
"/_/api/v1/revisions/save",
{
method: "POST",
headers: {
"Content-Type":
"application/json",
},
body: JSON.stringify({
object_uuid:
objectUUID.value,
body:
canonicalHTML,
message:
"autosave",
}),
},
)
},
async saveNow() {
const objectUUID =
document.getElementById(
"object-uuid",
)
if (
!objectUUID
||
!objectUUID.value
) {
return
}
const canonicalHTML =
await this.getCanonicalHTML()
const res =
await fetch(
"/_/api/v1/revisions/save",
{
method: "POST",
headers: {
"Content-Type":
"application/json",
},
body: JSON.stringify({
object_uuid:
objectUUID.value,
body:
canonicalHTML,
message:
"manual-save",
}),
},
)
if (!res.ok) {
alert(
"save failed",
)
return
}
alert(
"saved",
)
},
}
document.addEventListener(
"DOMContentLoaded",
() => {
if (
document.body.classList.contains(
"mode-editor",
)
) {
PagesEditor.init()
}
},
)
document.addEventListener(
"DOMContentLoaded",
() => {
const sel =
document.getElementById(
"editor-type",
)
if (!sel) {
return
}
sel.addEventListener(
"change",
() => {
const u =
new URL(
location.href,
)
u.searchParams.set(
"edittype",
sel.value,
)
location.href =
u.toString()
},
)
},
)
+50
View File
@@ -0,0 +1,50 @@
console.log("navigation.js loaded")
function createChildPage() {
const name = prompt("child page name")
if (!name) return
let path = location.pathname
if (!path.endsWith("/")) path += "/"
location.href = "/e" + path + name
}
function selectObject(uuid) {
const input = document.getElementById("link-object-uuid")
if (input) input.value = uuid
}
async function bindPath() {
const objectUUID = document.getElementById("link-object-uuid")?.value
const path = document.getElementById("link-path")?.value
const res = await fetch("/_/api/v1/paths/bind", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({object_uuid: objectUUID, path: path}),
})
if (!res.ok) {
alert("bind failed")
return
}
location.href = path
}
document.addEventListener("keydown", (ev) => {
if (ev.target && ["TEXTAREA", "INPUT"].includes(ev.target.tagName)) return
if (ev.key === "c") location.href = "/new"
if (ev.key === "e" && !location.pathname.startsWith("/e/")) {
location.href = "/e" + location.pathname
}
if (ev.key === "^") {
const parts = location.pathname.split("/").filter(Boolean)
parts.pop()
location.href = "/" + parts.join("/")
}
})
+105
View File
@@ -0,0 +1,105 @@
window.PagesPathActions = {
async renameCurrentPath() {
const currentPath =
location.pathname.replace(
/^\/e/,
"",
)
const nextPath =
prompt(
"Rename path:",
currentPath,
)
if (
!nextPath
||
nextPath === currentPath
) {
return
}
const res =
await fetch(
"/_/api/v1/path/rename",
{
method: "POST",
headers: {
"Content-Type":
"application/json",
},
body: JSON.stringify({
old_path:
currentPath,
new_path:
nextPath,
}),
},
)
if (!res.ok) {
alert(
"rename failed",
)
return
}
location.href =
"/e" + nextPath
},
async removeCurrentPath() {
const currentPath =
location.pathname.replace(
/^\/e/,
"",
)
if (
!confirm(
"Remove path?\n\n" +
currentPath,
)
) {
return
}
const res =
await fetch(
"/_/api/v1/path/remove",
{
method: "POST",
headers: {
"Content-Type":
"application/json",
},
body: JSON.stringify({
path:
currentPath,
}),
},
)
if (!res.ok) {
alert(
"remove failed",
)
return
}
location.href = "/"
},
}
+44
View File
@@ -0,0 +1,44 @@
console.log("revisions.js loaded")
async function restoreRevision(
revisionUUID,
) {
if (
!confirm(
"restore revision?"
)
) {
return
}
const res = await fetch(
"/_/api/v1/revisions/restore",
{
method: "POST",
headers: {
"Content-Type":
"application/json",
},
body: JSON.stringify({
revision_uuid:
revisionUUID,
}),
},
)
if (!res.ok) {
alert(
"restore failed",
)
return
}
alert(
"revision restored",
)
location.reload()
}
+1
View File
@@ -0,0 +1 @@
console.log("search.js loaded")