Files
pages/templates/pages/editor.gohtml
T
Anya Tokugawa 96065d1e89
Build and publish container images / images (push) Successful in 9m28s
Release container images / release (push) Successful in 19s
fix(revisions): connect safe restore UI and readable change history
2026-11-10 11:34:28 +09:00

452 lines
11 KiB
Go Template
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{{ define "editor.gohtml" }}
<!DOCTYPE html>
<html lang="{{ .Locale }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ .Title }}</title>
<link
rel="stylesheet"
href="/static/css/main.css"
>
<link
rel="stylesheet"
href="/static/css/modes.css"
>
<link rel="stylesheet" href="/static/css/theme/base.css">
<link rel="stylesheet" href="/static/css/content-viewer.css">
{{ if .CSVEditor }}<link rel="stylesheet" href="/static/css/csv-editor.css?v=1">{{ end }}
{{ if .SlidesEnabled }}<link rel="stylesheet" href="/static/css/slides.css?v=1"><script defer src="/static/js/slides.js?v=1"></script>{{ end }}
<link rel="stylesheet" href="{{ .ThemeCSS }}">
<script defer src="/static/js/content-viewer.js?v=macro-projection-1"></script>
<script
type="module"
src="/static/vendor/codemirror/editor.bundle.js?v=csv-edit-1"
></script>
<link
rel="stylesheet"
href="/static/vendor/codemirror/editor.css?v=priority-ux-1"
>
</head>
<body class="mode-editor{{ if .CSVEditor }} csv-editor{{ end }}">
<header class="topbar">
<div class="brand">
<a href="/">{{ .WikiName }}</a>
</div>
<div class="editor-head">
<div class="editor-head-left">
<label class="editor-change-message"><span>{{ T "history.message" }}</span><input id="revision-message" type="text" maxlength="1000" placeholder="{{ T "history.message_optional" }}"></label>
<button type="button" class="editor-action-icon" data-editor-action="tools" title="{{ T "editor.tools" }}" aria-label="{{ T "editor.tools" }}">+</button>
<button type="button" class="editor-action-icon" data-editor-action="language" title="{{ T "editor.language" }}" aria-label="{{ T "editor.language" }}">文</button>
<button type="button" class="editor-action-icon" data-editor-action="restore" title="{{ T "editor.restore" }}" aria-label="{{ T "editor.restore" }}">↶</button>
<a
href="#"
class="editor-action-icon"
data-editor-action="save"
title="{{ T "editor.save" }}"
aria-label="{{ T "editor.save" }}"
>
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M5 4h12l2 2v14H5zM8 4v6h8V4M8 20v-6h8v6"/>
</svg>
</a>
<a
href="#"
class="editor-action-icon"
data-editor-action="rename"
title="{{ T "editor.rename" }}"
aria-label="{{ T "editor.rename" }}"
>
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="m4 16-1 5 5-1L19 9l-4-4zM13 7l4 4"/>
</svg>
</a>
<a
href="/r/history/{{ .ObjectUUID }}"
class="editor-action-icon"
title="{{ T "editor.history" }}"
aria-label="{{ T "editor.history" }}"
>
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M4 5v5h5M5.5 9a8 8 0 1 1-.5 6M12 7v5l3 2"/>
</svg>
</a>
<a
href="#"
class="editor-action-icon danger"
data-editor-action="delete"
title="{{ T "editor.delete" }}"
aria-label="{{ T "editor.delete" }}"
>
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M4 7h16M9 7V4h6v3M6 7l1 13h10l1-13M10 11v5M14 11v5"/>
</svg>
</a>
<a
href="/l/uuid:{{ .ObjectUUID }}"
class="editor-action-icon"
title="{{ T "editor.links" }}"
aria-label="{{ T "editor.links" }}"
>
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M10 13a4 4 0 0 0 5.7 0l2.3-2.3A4 4 0 0 0 12.3 5L11 6.3M14 11a4 4 0 0 0-5.7 0L6 13.3A4 4 0 0 0 11.7 19l1.3-1.3"/>
</svg>
</a>
<a
href="{{ .Path }}"
class="editor-action-icon"
title="{{ T "editor.close" }}"
aria-label="{{ T "editor.close" }}"
>
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M6 6l12 12M18 6 6 18"/>
</svg>
</a>
</div>
<div class="editor-head-right">
{{ if and (ne .EditType "code") (ne .EditType "plain") }}
{{ if .SlidesEnabled }}<button type="button" class="editor-action-icon" data-editor-action="slides" aria-pressed="false" title="{{ T "slides.preview" }}" aria-label="{{ T "slides.preview" }}"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M3 4h18v12H3zM12 16v5m-5 0 5-5 5 5M8 8h8m-8 4h5"/></svg></button>{{ end }}
<button
type="button"
class="editor-format-icon {{ if eq .EditType "html" }}active{{ end }}"
data-editor-action="html"
title="{{ T "editor.use_html" }}"
aria-label="{{ T "editor.use_html" }}"
aria-pressed="{{ if eq .EditType "html" }}true{{ else }}false{{ end }}"
>
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M8 8 4 12l4 4M16 8l4 4-4 4M14 5l-4 14"/>
</svg>
</button>
<button
type="button"
class="editor-format-icon {{ if eq .EditType "markdown" }}active{{ end }}"
data-editor-action="markdown"
title="{{ T "editor.use_markdown" }}"
aria-label="{{ T "editor.use_markdown" }}"
aria-pressed="{{ if eq .EditType "markdown" }}true{{ else }}false{{ end }}"
>
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M4 7v10M4 7l4 5 4-5v10M16 7v7M13 11l3 3 3-3M16 14v3"/>
</svg>
</button>
{{ end }}
<button
type="button"
id="preview-toggle"
class="editor-preview-toggle"
data-editor-action="preview"
aria-controls="preview"
aria-pressed="true"
aria-label="{{ T "editor.hide_preview" }}"
title="{{ T "editor.hide_preview" }}"
data-hide-label="{{ if .CSVEditor }}{{ T "editor.csv_source" }}{{ else }}{{ T "editor.hide_preview" }}{{ end }}"
data-show-label="{{ if .CSVEditor }}{{ T "editor.csv_table" }}{{ else }}{{ T "editor.show_preview" }}{{ end }}"
>
<svg viewBox="0 0 24 24" aria-hidden="true">
<rect x="3" y="4" width="18" height="16" rx="2"/>
<path d="M14 4v16"/>
<path class="preview-pane-fill" d="M15 6h4v12h-4z"/>
</svg>
</button>
</div>
</div>
{{ template "auth-menu" . }}</header>
<main class="container">
<section class="card">
<div class="editor-grid">
<textarea
id="editor"
class="editor"
hidden
>{{ .Body }}</textarea>
<div class="editor-pane">
<div
id="editor-mount"
data-keymap="{{ .EditorKeymap }}"
data-preview-default="{{ .EditorPreviewDefault }}"
data-syntax="{{ .EditorSyntax }}"
data-autocomplete="{{ .EditorAutocomplete }}"
data-base-revision="{{ .BaseRevision }}"
data-domain="{{ .Context.Domain.UUID }}"
data-owner="{{ if .AuthUser }}{{ .AuthUser.UUID }}{{ end }}"
data-csv="{{ .CSVEditor }}"
></div>
<div
id="editor-statusbar"
class="editor-statusbar"
>
<div class="editor-status-left">
<span id="editor-vim-mode">
MODE
</span>
<span id="editor-format-status">
{{ if .CSVEditor }}CSV{{ else }}{{ .EditType }}{{ end }}
</span>
</div>
<div class="editor-status-right">
<span id="editor-save-status" role="status" aria-live="polite"></span>
<span id="editor-cursor">
Ln 1, Col 1
</span>
</div>
</div>
</div>
<article
id="preview"
class="preview"
></article>
</div>
<textarea hidden id="editor-base">{{ .BaseBody }}</textarea>
<input
type="hidden"
id="object-uuid"
value="{{ .ObjectUUID }}"
>
<input
type="hidden"
id="edit-type"
value="{{ .EditType }}"
>
<input
type="hidden"
id="page-language"
value="{{ .PageLanguage }}"
>
<input
type="hidden"
id="page-content-type"
value="{{ .PageContentType }}"
>
<input
type="hidden"
id="page-filename"
value="{{ .PageFilename }}"
>
</section>
</main>
<script src="/static/js/editor-core.js?v=priority-ux-1"></script>
{{ if .CSVEditor }}<script>window.PagesCSVSource = {{ .Body }};</script><script src="/static/js/csv-core.js?v=2"></script><script src="/static/js/csv-editor.js?v=2"></script>{{ end }}
<script src="/static/js/editor.js?v=revision-message-1"></script>
<script src="/static/js/path-actions.js"></script>
<script>
window.PagesWikiCurrentPath = "{{ .Path }}";
window.addEventListener(
"DOMContentLoaded",
() => {
const textarea =
document.getElementById("editor")
const mount =
document.getElementById("editor-mount")
if (!textarea || !mount || !window.PagesWikiEditor) {
return
}
const cm =
window.PagesWikiEditor.create(
mount,
window.PagesEditor?.text() ?? textarea.value,
"{{ .EditType }}",
{
keymap: mount.dataset.keymap,
syntax: mount.dataset.syntax === "true",
autocomplete: mount.dataset.autocomplete === "true",
preserveLineEndings: mount.dataset.csv === "true",
}
)
window.PagesWikiCodeMirror =
cm
cm.focus()
setTimeout(() => {
// Do not steal focus from a table cell or toolbar clicked while
// the editor was initializing.
if (document.activeElement === document.body || mount.contains(document.activeElement)) cm.focus()
}, 0)
window.PagesWikiGetEditorText =
() => window.PagesWikiCodeMirror.state.doc.toString()
}
)
function setEditorPreviewVisible(visible) {
const grid =
document.querySelector(".editor-grid")
const preview =
document.getElementById("preview")
const toggle =
document.getElementById("preview-toggle")
if (!grid || !preview || !toggle) {
return
}
const hidden =
!visible
grid.classList.toggle(
"preview-hidden",
hidden
)
grid.style.gridTemplateColumns =
hidden ? "1fr" : ""
preview.hidden =
hidden
toggle.setAttribute(
"aria-pressed",
hidden ? "false" : "true"
)
const label =
hidden
? toggle.dataset.showLabel
: toggle.dataset.hideLabel
toggle.setAttribute(
"aria-label",
label
)
toggle.title =
label
try {
localStorage.setItem(
"pageswiki.editor.preview",
hidden ? "hidden" : "visible"
)
} catch (_) {
// Preview state persistence is optional.
}
if (
window.PagesWikiCodeMirror
&&
window.PagesWikiCodeMirror.requestMeasure
) {
window.PagesWikiCodeMirror.requestMeasure()
}
if (
!hidden
&&
window.PagesEditor
&&
window.PagesEditor.renderPreview
) {
window.PagesEditor.renderPreview()
}
}
function toggleEditorPreview() {
const grid =
document.querySelector(".editor-grid")
if (!grid) {
return
}
setEditorPreviewVisible(
grid.classList.contains("preview-hidden")
)
}
window.addEventListener(
"DOMContentLoaded",
() => {
const mount = document.getElementById("editor-mount")
let visible = mount?.dataset.previewDefault !== "hidden"
try {
const saved = localStorage.getItem("pageswiki.editor.preview")
if (saved) visible = saved !== "hidden"
} catch (_) {
// Keep Preview visible when storage is unavailable.
}
setEditorPreviewVisible(visible)
}
)
function switchEditorFormat(format) {
if (window.PagesEditor?.switchFormat) return window.PagesEditor.switchFormat(format)
const url =
new URL(location.href)
url.searchParams.set(
"edittype",
format
)
location.href =
url.toString()
}
</script>
</body>
</html>
{{ end }}