Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
96065d1e89 | ||
|
|
2cbaa9342d |
No files matched your search
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -13,8 +14,24 @@ import (
|
|||||||
|
|
||||||
// HTMLToMarkdownAuthoring keeps source HTML when conversion loses structure,
|
// HTMLToMarkdownAuthoring keeps source HTML when conversion loses structure,
|
||||||
// attributes, comments or text. This is not a sanitization boundary.
|
// attributes, comments or text. This is not a sanitization boundary.
|
||||||
|
var nestedListGap = regexp.MustCompile(`\n[\t ]*\n([\t ]+(?:[-+*]|[0-9]+\.) )`)
|
||||||
|
|
||||||
|
func authoringMarkdown(source string) (string, error) {
|
||||||
|
md, err := HTMLToMarkdown(source)
|
||||||
|
if err != nil {
|
||||||
|
return md, err
|
||||||
|
}
|
||||||
|
// The converter inserts a loose-list gap before nested lists. Only accept
|
||||||
|
// tightening when the resulting DOM matches; code and real paragraphs stay protected.
|
||||||
|
tight := nestedListGap.ReplaceAllString(md, "\n$1")
|
||||||
|
if tight != md && htmlStructure(source) == htmlStructure(MarkdownToHTML(tight)) {
|
||||||
|
return tight, nil
|
||||||
|
}
|
||||||
|
return md, nil
|
||||||
|
}
|
||||||
|
|
||||||
func HTMLToMarkdownAuthoring(source string) (string, error) {
|
func HTMLToMarkdownAuthoring(source string) (string, error) {
|
||||||
converted, err := HTMLToMarkdown(source)
|
converted, err := authoringMarkdown(source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@@ -30,7 +47,7 @@ func HTMLToMarkdownAuthoring(source string) (string, error) {
|
|||||||
if strings.TrimSpace(raw) == "" {
|
if strings.TrimSpace(raw) == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
md, e := HTMLToMarkdown(raw)
|
md, e := authoringMarkdown(raw)
|
||||||
if e != nil || htmlStructure(raw) != htmlStructure(MarkdownToHTML(md)) {
|
if e != nil || htmlStructure(raw) != htmlStructure(MarkdownToHTML(md)) {
|
||||||
md = rawHTMLBlock(raw)
|
md = rawHTMLBlock(raw)
|
||||||
}
|
}
|
||||||
@@ -171,6 +188,22 @@ func htmlStructure(source string) string {
|
|||||||
literal = literal || n.Data == "pre" || n.Data == "code" || n.Data == "script" || n.Data == "style"
|
literal = literal || n.Data == "pre" || n.Data == "code" || n.Data == "script" || n.Data == "style"
|
||||||
data := n.Data
|
data := n.Data
|
||||||
if n.Type == html.TextNode && !literal {
|
if n.Type == html.TextNode && !literal {
|
||||||
|
// Formatting whitespace beside a nested block is not an inline word
|
||||||
|
// separator. Keep all whitespace between inline siblings significant.
|
||||||
|
if n.Parent != nil && n.Parent.Data == "li" {
|
||||||
|
isList := func(x *html.Node) bool {
|
||||||
|
return x != nil && x.Type == html.ElementNode && (x.Data == "ul" || x.Data == "ol")
|
||||||
|
}
|
||||||
|
if isList(n.NextSibling) {
|
||||||
|
data = strings.TrimRight(data, " \t\r\n")
|
||||||
|
}
|
||||||
|
if isList(n.PrevSibling) {
|
||||||
|
data = strings.TrimLeft(data, " \t\r\n")
|
||||||
|
}
|
||||||
|
if data == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
if strings.TrimSpace(data) == "" && n.Parent != nil {
|
if strings.TrimSpace(data) == "" && n.Parent != nil {
|
||||||
switch n.Parent.Data {
|
switch n.Parent.Data {
|
||||||
case "ul", "ol", "table", "thead", "tbody", "tfoot", "tr":
|
case "ul", "ol", "table", "thead", "tbody", "tfoot", "tr":
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package grammaratur
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAuthoringNestedLists(t *testing.T) {
|
||||||
|
for _, source := range []string{
|
||||||
|
"<ul><li>Parent<ul><li>Child</li></ul></li></ul>",
|
||||||
|
"<ul>\n<li>Parent\n<ul>\n<li>Child</li>\n</ul>\n</li>\n</ul>",
|
||||||
|
"<ul><li>Parent<ul><li>Child<ul><li>Grandchild</li></ul></li></ul></li><li>Sibling</li></ul>",
|
||||||
|
"<ol><li>Parent<ul><li>Child</li></ul></li></ol>",
|
||||||
|
"<ul><li><strong>Parent</strong><ul><li>Child</li></ul></li></ul>",
|
||||||
|
} {
|
||||||
|
md, err := HTMLToMarkdownAuthoring(source)
|
||||||
|
if htmlStructure(source) != htmlStructure(MarkdownAuthoringHTML(md)) {
|
||||||
|
t.Errorf("list structure changed: %q", md)
|
||||||
|
}
|
||||||
|
if err != nil || strings.Contains(md, "{=html}") {
|
||||||
|
plain, _ := HTMLToMarkdown(source)
|
||||||
|
t.Errorf("source=%q md=%q plain=%q rendered=%q err=%v", source, md, plain, MarkdownToHTML(plain), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAuthoringNestedListPreservesAttributes(t *testing.T) {
|
||||||
|
source := `<ul><li data-custom="keep">Parent<ul><li>Child</li></ul></li></ul>`
|
||||||
|
md, err := HTMLToMarkdownAuthoring(source)
|
||||||
|
if err != nil || MarkdownAuthoringHTML(md) != source {
|
||||||
|
t.Fatalf("protected list changed: %q %v", md, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -330,6 +330,8 @@ var translations = map[string]map[string]string{
|
|||||||
"viewer.metadata_unavailable": "The metadata queue is unavailable. Download is still available.",
|
"viewer.metadata_unavailable": "The metadata queue is unavailable. Download is still available.",
|
||||||
"viewer.archive_truncated": "The listing limit was reached. Download the archive for the complete contents.",
|
"viewer.archive_truncated": "The listing limit was reached. Download the archive for the complete contents.",
|
||||||
"history.title": "Revision History",
|
"history.title": "Revision History",
|
||||||
|
"history.message": "Change message",
|
||||||
|
"history.message_optional": "Optional summary of changes",
|
||||||
"history.older": "Older revisions",
|
"history.older": "Older revisions",
|
||||||
"history.newest": "Newest revisions",
|
"history.newest": "Newest revisions",
|
||||||
"history.view": "View",
|
"history.view": "View",
|
||||||
@@ -1120,6 +1122,8 @@ var translations = map[string]map[string]string{
|
|||||||
"viewer.metadata_unavailable": "メタデータの待ち行列を利用できません。ダウンロードは利用できます。",
|
"viewer.metadata_unavailable": "メタデータの待ち行列を利用できません。ダウンロードは利用できます。",
|
||||||
"viewer.archive_truncated": "表示件数の上限に達しました。全内容はダウンロードして確認してください。",
|
"viewer.archive_truncated": "表示件数の上限に達しました。全内容はダウンロードして確認してください。",
|
||||||
"history.title": "リビジョン履歴",
|
"history.title": "リビジョン履歴",
|
||||||
|
"history.message": "更新メッセージ",
|
||||||
|
"history.message_optional": "変更内容(任意)",
|
||||||
"history.older": "以前のリビジョン",
|
"history.older": "以前のリビジョン",
|
||||||
"history.newest": "最新のリビジョン",
|
"history.newest": "最新のリビジョン",
|
||||||
"history.view": "表示",
|
"history.view": "表示",
|
||||||
|
|||||||
@@ -50,6 +50,18 @@ func (s *Server) handleRevisionBrowser(
|
|||||||
}
|
}
|
||||||
|
|
||||||
next := ""
|
next := ""
|
||||||
|
heads := map[string]string{}
|
||||||
|
canRestore := s.authorizeObjectForRequest(r, "write", objectUUID) == nil
|
||||||
|
if canRestore {
|
||||||
|
for _, revision := range page.Items {
|
||||||
|
if _, ok := heads[revision.Language]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if head, e := s.store.GetRevisionMetadataForExactLanguage(objectUUID, revision.Language); e == nil {
|
||||||
|
heads[revision.Language] = head.UUID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if page.Next != "" {
|
if page.Next != "" {
|
||||||
next = revisionPageURL(r, page.Next)
|
next = revisionPageURL(r, page.Next)
|
||||||
}
|
}
|
||||||
@@ -62,12 +74,14 @@ func (s *Server) handleRevisionBrowser(
|
|||||||
s.getSystemNavItems(s.domainUUIDForRequest(r)),
|
s.getSystemNavItems(s.domainUUIDForRequest(r)),
|
||||||
NavContext{},
|
NavContext{},
|
||||||
),
|
),
|
||||||
"Title": "Revision History",
|
"Title": "Revision History",
|
||||||
"ObjectUUID": objectUUID,
|
"ObjectUUID": objectUUID,
|
||||||
"Revisions": page.Items,
|
"CanRestore": canRestore,
|
||||||
"NextURL": next,
|
"RevisionHeads": heads,
|
||||||
"NewestURL": revisionPageURL(r, ""),
|
"Revisions": page.Items,
|
||||||
"HasPrevious": before != "",
|
"NextURL": next,
|
||||||
|
"NewestURL": revisionPageURL(r, ""),
|
||||||
|
"HasPrevious": before != "",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1,63 +1,61 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"pageswiki/internal/store"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Server) handleRestoreRevisionAPI(
|
func (s *Server) handleRestoreRevisionAPI(w http.ResponseWriter, r *http.Request) {
|
||||||
w http.ResponseWriter,
|
|
||||||
r *http.Request,
|
|
||||||
) {
|
|
||||||
if r.Method != http.MethodPost {
|
if r.Method != http.MethodPost {
|
||||||
w.Header().Set("Allow", "POST")
|
w.Header().Set("Allow", "POST")
|
||||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
http.Error(w, "method not allowed", 405)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
var input struct {
|
||||||
revisionUUID :=
|
Revision string `json:"revision_uuid"`
|
||||||
r.URL.Query().Get("revision")
|
Expected string `json:"base_revision_uuid"`
|
||||||
|
Message string `json:"message"`
|
||||||
metadata, err :=
|
}
|
||||||
s.store.GetRevisionMetadata(
|
if !taskJSON(w, r, &input) {
|
||||||
revisionUUID,
|
return
|
||||||
)
|
}
|
||||||
|
if input.Expected == "" {
|
||||||
|
http.Error(w, "base revision required", 428)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(input.Message) > 4096 {
|
||||||
|
http.Error(w, "message too long", 422)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
metadata, err := s.store.GetRevisionMetadata(input.Revision)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(
|
http.NotFound(w, r)
|
||||||
w,
|
|
||||||
err.Error(),
|
|
||||||
500,
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if s.authorizeObjectForRequest(r, "write", metadata.ObjectUUID) != nil {
|
if s.authorizeObjectForRequest(r, "read", metadata.ObjectUUID) != nil || s.authorizeObjectForRequest(r, "write", metadata.ObjectUUID) != nil {
|
||||||
http.Error(w, "forbidden", http.StatusForbidden)
|
http.Error(w, "forbidden", 403)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Authorize metadata before hydrating the potentially large source body.
|
revision, err := s.store.GetRevision(input.Revision)
|
||||||
revision, err := s.store.GetRevision(revisionUUID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "revision unavailable", http.StatusInternalServerError)
|
http.Error(w, "revision unavailable", 500)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
message := strings.TrimSpace(input.Message)
|
||||||
|
if message == "" {
|
||||||
|
message = "Restore revision " + revision.UUID
|
||||||
|
}
|
||||||
|
saved, err := s.store.SaveRevisionContentIfHead(revision.ObjectUUID, []byte(revision.Body), message, revision.Language, revision.ContentType, revision.Filename, input.Expected)
|
||||||
|
if errors.Is(err, store.ErrRevisionConflict) {
|
||||||
|
http.Error(w, "revision changed; reload history", 412)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = s.store.SaveRevisionContent(
|
|
||||||
revision.ObjectUUID,
|
|
||||||
[]byte(revision.Body),
|
|
||||||
"restore revision",
|
|
||||||
revision.Language,
|
|
||||||
revision.ContentType,
|
|
||||||
revision.Filename,
|
|
||||||
)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(
|
http.Error(w, "restore failed", 500)
|
||||||
w,
|
|
||||||
err.Error(),
|
|
||||||
500,
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
w.Header().Set("Cache-Control", "no-store")
|
||||||
_, _ = w.Write([]byte("ok"))
|
writeEventJSON(w, 200, map[string]string{"revision_uuid": saved.UUID, "object_uuid": revision.ObjectUUID})
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http/httptest"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestRevisionRestoreAppendAndConflict(t *testing.T) {
|
||||||
|
s, token, domain := configFixture(t)
|
||||||
|
object, err := s.store.CreatePageAtPathInDomain(domain, "/restore-ui")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
old, err := s.store.SaveRevisionContent(object, []byte("<p>Old</p>"), "first", "ja", "text/html", "note.html")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
head, err := s.store.SaveRevisionContent(object, []byte("<p>New</p>"), "second", "ja", "text/html", "note.html")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
s.mux.HandleFunc("/_/api/v1/revisions/restore", s.handleRestoreRevisionAPI)
|
||||||
|
s.mux.HandleFunc("/r/history/", s.handleRevisionBrowser)
|
||||||
|
post := func(payload map[string]string) *httptest.ResponseRecorder {
|
||||||
|
body, _ := json.Marshal(payload)
|
||||||
|
r := httptest.NewRequest("POST", "http://localhost/_/api/v1/revisions/restore", bytes.NewReader(body))
|
||||||
|
r.Header.Set("Authorization", "Bearer "+token)
|
||||||
|
r.Header.Set("Content-Type", "application/json")
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
s.withAuthorization(s.mux).ServeHTTP(w, r)
|
||||||
|
return w
|
||||||
|
}
|
||||||
|
page := configRequest(s, token, "GET", "/r/history/"+object, nil)
|
||||||
|
if page.Code != 200 || !strings.Contains(page.Body.String(), `data-restore-revision="`+old.UUID+`"`) || !strings.Contains(page.Body.String(), "data-revision-time") {
|
||||||
|
t.Fatal(page.Code, page.Body)
|
||||||
|
}
|
||||||
|
payload := map[string]string{"revision_uuid": old.UUID, "base_revision_uuid": head.UUID, "message": "元の内容へ復元"}
|
||||||
|
w := post(payload)
|
||||||
|
if w.Code != 200 {
|
||||||
|
t.Fatal(w.Code, w.Body)
|
||||||
|
}
|
||||||
|
restored, err := s.store.GetRevisionForExactLanguage(object, "ja")
|
||||||
|
if err != nil || restored.UUID == old.UUID || restored.UUID == head.UUID || restored.Body != old.Body || restored.Message != payload["message"] {
|
||||||
|
t.Fatal(restored, err)
|
||||||
|
}
|
||||||
|
if _, err = s.store.GetRevision(head.UUID); err != nil {
|
||||||
|
t.Fatal("previous head lost", err)
|
||||||
|
}
|
||||||
|
w = post(payload)
|
||||||
|
if w.Code != 412 {
|
||||||
|
t.Fatal("stale restore", w.Code, w.Body)
|
||||||
|
}
|
||||||
|
delete(payload, "base_revision_uuid")
|
||||||
|
w = post(payload)
|
||||||
|
if w.Code != 428 {
|
||||||
|
t.Fatal("missing precondition", w.Code, w.Body)
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+1
-1
@@ -27,7 +27,7 @@
|
|||||||
d.querySelector('.feed-row').click();await wait(()=>d.querySelector('#feed-reader .feed-body'));
|
d.querySelector('.feed-row').click();await wait(()=>d.querySelector('#feed-reader .feed-body'));
|
||||||
d.querySelector('#feed-reader .feed-actions button:last-child').click();await wait(()=>d.querySelector('#feed-reader form'));
|
d.querySelector('#feed-reader .feed-actions button:last-child').click();await wait(()=>d.querySelector('#feed-reader form'));
|
||||||
assert(!['rgba(0, 0, 0, 0)','transparent'].includes(w.getComputedStyle(d.querySelector('.feed-capture')).backgroundColor),'Capture dialog background transparent');
|
assert(!['rgba(0, 0, 0, 0)','transparent'].includes(w.getComputedStyle(d.querySelector('.feed-capture')).backgroundColor),'Capture dialog background transparent');
|
||||||
const form=d.querySelector('#feed-reader form'),inputs=form.querySelectorAll('input');assert(inputs[2].value==='/notes/{YYYY}/{MM}/{DD}/{Subject}','Wiki default not filled');assert(form.closest('dialog').open&&d.querySelector('#feed-reader .feed-body'),'Capture replaced article');assert(form.querySelector('a[href="/-/sys/config?panel=organizer"]'),'Default settings link missing');await wait(()=>form.querySelector('output').textContent.includes('/rss-'));assert(!form.querySelector('output').textContent.includes('{'),'Template not expanded');inputs[2].value='/notes/feed-ui';inputs[2].dispatchEvent(new w.Event('input'));await wait(()=>form.querySelector('output').textContent.startsWith('/notes/feed-ui/rss-'));inputs[5].checked=true;form.requestSubmit();await wait(()=>d.querySelector('#feed-reader a[href^="/v/uuid:"]'));d.querySelector('.feed-capture button').click();await wait(()=>!d.querySelector('.feed-capture'));assert(d.querySelector('#feed-reader .feed-body'),'Closing capture lost article');
|
const form=d.querySelector('#feed-reader form'),inputs=form.querySelectorAll('input');assert(inputs[2].value==='/notes/{YYYY}/{MM}/{DD}/{Subject}','Wiki default not filled');assert(form.closest('dialog').open&&d.querySelector('#feed-reader .feed-body'),'Capture replaced article');assert(form.querySelector('a[href="/-/sys/config?panel=organizer"]'),'Default settings link missing');await wait(()=>form.querySelector('output').textContent.includes('/rss-'));assert(!form.querySelector('output').textContent.includes('{'),'Template not expanded');inputs[2].value='/notes/feed-ui';inputs[2].dispatchEvent(new w.Event('input'));await wait(()=>form.querySelector('output').textContent.startsWith('/notes/feed-ui/rss-'));inputs[5].checked=true;form.requestSubmit();await wait(()=>d.querySelector('#feed-reader a[href^="/o/uuid:"]'));d.querySelector('.feed-capture button').click();await wait(()=>!d.querySelector('.feed-capture'));assert(d.querySelector('#feed-reader .feed-body'),'Closing capture lost article');
|
||||||
const search=d.querySelector('#feed-toolbar input');search.value='';search.dispatchEvent(new w.Event('input',{bubbles:true}));await wait(()=>d.querySelectorAll('.feed-row').length===100);d.querySelector('.feed-row').click();await wait(()=>d.querySelector('#feed-reader .feed-body'));
|
const search=d.querySelector('#feed-toolbar input');search.value='';search.dispatchEvent(new w.Event('input',{bubbles:true}));await wait(()=>d.querySelectorAll('.feed-row').length===100);d.querySelector('.feed-row').click();await wait(()=>d.querySelector('#feed-reader .feed-body'));
|
||||||
assert(d.documentElement.scrollWidth<=w.innerWidth,'Reader overflow');
|
assert(d.documentElement.scrollWidth<=w.innerWidth,'Reader overflow');
|
||||||
d.getElementById('feed-opml').click();await wait(()=>d.getElementById('feed-opml-file'));
|
d.getElementById('feed-opml').click();await wait(()=>d.getElementById('feed-opml-file'));
|
||||||
|
|||||||
@@ -5,3 +5,6 @@ body.mode-editor .page-html {
|
|||||||
body.mode-view textarea.editor {
|
body.mode-view textarea.editor {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
.editor-change-message { display:flex; align-items:center; gap:.35rem; min-width:0; font-size:.8rem; }
|
||||||
|
.editor-change-message input { width:clamp(8rem,16vw,16rem); min-width:0; padding:.3rem .5rem; color:var(--fg); background:var(--bg); border:1px solid var(--border); border-radius:.3rem; }
|
||||||
|
@media(max-width:760px) { .editor-change-message span { display:none; } .editor-change-message input { width:8rem; } }
|
||||||
+6
-1
@@ -252,6 +252,10 @@ window.PagesEditor = {
|
|||||||
if (this.saving) return false
|
if (this.saving) return false
|
||||||
if (!this.dirty) return !this.paused
|
if (!this.dirty) return !this.paused
|
||||||
if (!manual && this.paused) return false
|
if (!manual && this.paused) return false
|
||||||
|
const messageField=document.getElementById('revision-message')
|
||||||
|
const changeMessage=messageField?.value.trim()||''
|
||||||
|
// A supplied message belongs to the next explicit save, not autosave.
|
||||||
|
if (!manual && changeMessage) return false
|
||||||
if (manual) this.mergeAttempts=0
|
if (manual) this.mergeAttempts=0
|
||||||
this.persist()
|
this.persist()
|
||||||
this.saving = true
|
this.saving = true
|
||||||
@@ -261,11 +265,12 @@ window.PagesEditor = {
|
|||||||
try {
|
try {
|
||||||
body = await this.canonical(text,format)
|
body = await this.canonical(text,format)
|
||||||
const data = await this.post('/_/api/v1/revisions/save',{
|
const data = await this.post('/_/api/v1/revisions/save',{
|
||||||
object_uuid:this.value('object-uuid'),body,message:manual?'manual-save':'autosave',
|
object_uuid:this.value('object-uuid'),body,message:manual?(changeMessage||'manual-save'):'autosave',
|
||||||
lang:this.value('page-language')||'und',content_type:this.value('page-content-type'),filename:this.value('page-filename'),
|
lang:this.value('page-language')||'und',content_type:this.value('page-content-type'),filename:this.value('page-filename'),
|
||||||
base_revision_uuid:this.baseRevision,editor_principal_uuid:this.owner,
|
base_revision_uuid:this.baseRevision,editor_principal_uuid:this.owner,
|
||||||
})
|
})
|
||||||
if (!data.revision_uuid) throw {kind:'failed'}
|
if (!data.revision_uuid) throw {kind:'failed'}
|
||||||
|
if (manual && messageField?.value.trim()===changeMessage) messageField.value=''
|
||||||
this.baseRevision = data.revision_uuid
|
this.baseRevision = data.revision_uuid
|
||||||
this.baseBody = typeof data.body==='string' ? data.body : body
|
this.baseBody = typeof data.body==='string' ? data.body : body
|
||||||
this.initialText = text; this.initialFormat = format
|
this.initialText = text; this.initialFormat = format
|
||||||
|
|||||||
+1
-1
@@ -273,7 +273,7 @@
|
|||||||
form.onsubmit=async event=>{event.preventDefault();if(busy||resolved===null||!form.reportValidity())return;const body='Source: '+item.url+'\nFeed: '+item.feed+'\n\n'+notes.value+(copy.checked?'\n\n'+item.body:'');const spec={title:title.value,notes:notes.value,prefix:resolved,body,task:task.checked};const fingerprint=JSON.stringify(spec);if(!pending||pending.fingerprint!==fingerprint)pending={fingerprint,request_id:requestID};busy=true;save.disabled=true;
|
form.onsubmit=async event=>{event.preventDefault();if(busy||resolved===null||!form.reportValidity())return;const body='Source: '+item.url+'\nFeed: '+item.feed+'\n\n'+notes.value+(copy.checked?'\n\n'+item.body:'');const spec={title:title.value,notes:notes.value,prefix:resolved,body,task:task.checked};const fingerprint=JSON.stringify(spec);if(!pending||pending.fingerprint!==fingerprint)pending={fingerprint,request_id:requestID};busy=true;save.disabled=true;
|
||||||
try{let data;if(task.checked){const input={request_id:pending.request_id,title:title.value,notes:(notes.value+'\nSource: '+item.url).trim()};if(spec.prefix){input.wiki_prefix=spec.prefix;input.wiki_body=body;}const res=await fetch('/_/api/v1/extension/organizer.tasks/capture',{method:'POST',credentials:'same-origin',headers:{'Content-Type':'application/json'},body:JSON.stringify(input)});data=await res.json().catch(()=>({}));if(!res.ok||res.redirected)throw Error(t('Capture failed: ','作成に失敗: ')+(data.error||res.status));}
|
try{let data;if(task.checked){const input={request_id:pending.request_id,title:title.value,notes:(notes.value+'\nSource: '+item.url).trim()};if(spec.prefix){input.wiki_prefix=spec.prefix;input.wiki_body=body;}const res=await fetch('/_/api/v1/extension/organizer.tasks/capture',{method:'POST',credentials:'same-origin',headers:{'Content-Type':'application/json'},body:JSON.stringify(input)});data=await res.json().catch(()=>({}));if(!res.ok||res.redirected)throw Error(t('Capture failed: ','作成に失敗: ')+(data.error||res.status));}
|
||||||
else data=await post('note',{request_id:pending.request_id,source:item.source,id:item.id,path:spec.prefix.replace(/\/$/,'')+'/rss-'+pending.request_id,title:title.value,body,confirm_publication:confirm.checked});
|
else data=await post('note',{request_id:pending.request_id,source:item.source,id:item.id,path:spec.prefix.replace(/\/$/,'')+'/rss-'+pending.request_id,title:title.value,body,confirm_publication:confirm.checked});
|
||||||
dialog.replaceChildren(el('h2',t('Created','作成しました')));if(data.item){const a=el('a',t('Open task','タスクを開く'));a.href='/v/plan/task/'+encodeURIComponent(data.item.uuid);dialog.append(a);}const page=data.page_uuid||data.item?.page_uuid;if(page){const a=el('a',t('Open Wiki','Wikiを開く'));a.href='/v/uuid:'+encodeURIComponent(page);dialog.append(el('p'),a);}const done=button(t('Close','閉じる'),'',close);dialog.append(el('p'),done);done.focus();
|
dialog.replaceChildren(el('h2',t('Created','作成しました')));if(data.item){const a=el('a',t('Open task','タスクを開く'));a.href='/v/plan/task/'+encodeURIComponent(data.item.uuid);dialog.append(a);}const page=data.page_uuid||data.item?.page_uuid;if(page){const a=el('a',t('Open Wiki','Wikiを開く'));a.href='/o/uuid:'+encodeURIComponent(page);dialog.append(el('p'),a);}const done=button(t('Close','閉じる'),'',close);dialog.append(el('p'),done);done.focus();
|
||||||
}catch(e){notice.textContent=e.message;}finally{busy=false;save.disabled=resolved===null;}
|
}catch(e){notice.textContent=e.message;}finally{busy=false;save.disabled=resolved===null;}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,7 +122,7 @@
|
|||||||
for(const task of data.items){const row=el('li');row.dataset.task=task.uuid;
|
for(const task of data.items){const row=el('li');row.dataset.task=task.uuid;
|
||||||
const title=link(task.title,'/v/plan/task/'+encodeURIComponent(task.uuid));title.title=task.title;window.PagesTaskPresentation?.render(title,task.title,false);
|
const title=link(task.title,'/v/plan/task/'+encodeURIComponent(task.uuid));title.title=task.title;window.PagesTaskPresentation?.render(title,task.title,false);
|
||||||
row.append(el('span',task.status==='done'?'✓':task.status==='cancelled'?'−':task.status==='doing'?'◐':'○'),title);
|
row.append(el('span',task.status==='done'?'✓':task.status==='cancelled'?'−':task.status==='doing'?'◐':'○'),title);
|
||||||
if(task.page_uuid){const note=link('▣','/v/uuid:'+encodeURIComponent(task.page_uuid));note.title=note.ariaLabel=t('Open linked Wiki page','関連Wikiページを開く');note.className='dashboard-note';row.append(note);}if(task.due_on)row.append(el('time',task.due_on));ul.append(row);
|
if(task.page_uuid){const note=link('▣','/o/uuid:'+encodeURIComponent(task.page_uuid));note.title=note.ariaLabel=t('Open linked Wiki page','関連Wikiページを開く');note.className='dashboard-note';row.append(note);}if(task.due_on)row.append(el('time',task.due_on));ul.append(row);
|
||||||
}
|
}
|
||||||
list.append(ul);if(!data.items.length&&!append)list.append(el('p',t('No matching tasks.','該当するタスクはありません。')));
|
list.append(ul);if(!data.items.length&&!append)list.append(el('p',t('No matching tasks.','該当するタスクはありません。')));
|
||||||
if(data.next){const more=button(t('Load more','続きを表示'),t('Load more','続きを表示'),()=>{more.disabled=true;tasks(tab,true,data.next).finally(()=>{more.disabled=false;});});more.dataset.more='true';panel.append(more);}
|
if(data.next){const more=button(t('Load more','続きを表示'),t('Load more','続きを表示'),()=>{more.disabled=true;tasks(tab,true,data.next).finally(()=>{more.disabled=false;});});more.dataset.more='true';panel.append(more);}
|
||||||
|
|||||||
+20
-44
@@ -1,44 +1,20 @@
|
|||||||
console.log("revisions.js loaded")
|
(() => {
|
||||||
|
'use strict';
|
||||||
async function restoreRevision(
|
const ja=document.documentElement.lang.startsWith('ja'),t=(en,jp)=>ja?jp:en;
|
||||||
revisionUUID,
|
for(const node of document.querySelectorAll('[data-revision-time]')){
|
||||||
) {
|
const date=new Date(Number(node.dataset.revisionTime)*1000);
|
||||||
|
if(!Number.isNaN(date.valueOf())){node.dateTime=date.toISOString();node.textContent=date.toLocaleString(undefined,{year:'numeric',month:'2-digit',day:'2-digit',hour:'2-digit',minute:'2-digit',second:'2-digit',timeZoneName:'short'});node.title=date.toISOString();}
|
||||||
if (
|
}
|
||||||
!confirm(
|
let busy=false;
|
||||||
"restore revision?"
|
document.addEventListener('click',async event=>{
|
||||||
)
|
const button=event.target.closest('[data-restore-revision]');if(!button||busy)return;
|
||||||
) {
|
const message=prompt(t('Restore as a new revision. Enter a change message:','新しいリビジョンとして復元します。更新メッセージを入力してください。'),t('Restore revision ','リビジョンを復元: ')+button.dataset.restoreRevision);
|
||||||
return
|
if(message===null)return;
|
||||||
}
|
busy=true;button.disabled=true;
|
||||||
|
try{
|
||||||
const res = await fetch(
|
const response=await fetch('/_/api/v1/revisions/restore',{method:'POST',credentials:'same-origin',headers:{'Content-Type':'application/json'},body:JSON.stringify({revision_uuid:button.dataset.restoreRevision,base_revision_uuid:button.dataset.baseRevision,message}),signal:AbortSignal.timeout(30000)});
|
||||||
"/_/api/v1/revisions/restore",
|
if(response.redirected||!response.ok)throw Error(response.status===412?t('Changed elsewhere. Reload history before restoring.','別の画面で更新されました。履歴を再読み込みしてから復元してください。'):t('Restore failed. Check your login and permissions.','復元できませんでした。ログイン状態と権限を確認してください。'));
|
||||||
{
|
location.reload();
|
||||||
method: "POST",
|
}catch(error){alert(error.message);}finally{busy=false;button.disabled=false;}
|
||||||
headers: {
|
});
|
||||||
"Content-Type":
|
})();
|
||||||
"application/json",
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
revision_uuid:
|
|
||||||
revisionUUID,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!res.ok) {
|
|
||||||
|
|
||||||
alert(
|
|
||||||
"restore failed",
|
|
||||||
)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
alert(
|
|
||||||
"revision restored",
|
|
||||||
)
|
|
||||||
|
|
||||||
location.reload()
|
|
||||||
}
|
|
||||||
@@ -53,6 +53,7 @@
|
|||||||
|
|
||||||
<div class="editor-head-left">
|
<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="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="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>
|
<button type="button" class="editor-action-icon" data-editor-action="restore" title="{{ T "editor.restore" }}" aria-label="{{ T "editor.restore" }}">↶</button>
|
||||||
@@ -277,7 +278,7 @@ Ln 1, Col 1
|
|||||||
|
|
||||||
<script src="/static/js/editor-core.js?v=priority-ux-1"></script>
|
<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 }}
|
{{ 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=slides-1"></script>
|
<script src="/static/js/editor.js?v=revision-message-1"></script>
|
||||||
<script src="/static/js/path-actions.js"></script>
|
<script src="/static/js/path-actions.js"></script>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,4 +6,4 @@
|
|||||||
<main id="feeds-app" data-timezone="{{ .FeedTimezone }}" data-writable="{{ .FeedWritable }}" data-tasks="{{ .TasksEnabled }}" data-wiki-prefix="{{ .FeedWikiPrefix }}" data-share-x="{{ .FeedShareX }}" data-link-mode="{{ .FeedLinkMode }}">
|
<main id="feeds-app" data-timezone="{{ .FeedTimezone }}" data-writable="{{ .FeedWritable }}" data-tasks="{{ .TasksEnabled }}" data-wiki-prefix="{{ .FeedWikiPrefix }}" data-share-x="{{ .FeedShareX }}" data-link-mode="{{ .FeedLinkMode }}">
|
||||||
<div id="feed-toolbar"></div><p id="feed-status" role="status" aria-live="polite"></p>
|
<div id="feed-toolbar"></div><p id="feed-status" role="status" aria-live="polite"></p>
|
||||||
<div class="feed-layout"><aside id="feed-sources" aria-label="{{ T "feeds.title" }}"></aside><section class="feed-index"><div id="feed-columns" aria-hidden="true"></div><div id="feed-rows" tabindex="0" role="listbox" aria-label="{{ T "feeds.title" }}"></div><button type="button" id="feed-more" hidden>↓</button></section><article id="feed-reader" tabindex="0"></article></div>
|
<div class="feed-layout"><aside id="feed-sources" aria-label="{{ T "feeds.title" }}"></aside><section class="feed-index"><div id="feed-columns" aria-hidden="true"></div><div id="feed-rows" tabindex="0" role="listbox" aria-label="{{ T "feeds.title" }}"></div><button type="button" id="feed-more" hidden>↓</button></section><article id="feed-reader" tabindex="0"></article></div>
|
||||||
</main><script src="/static/js/feeds.js?v=11" defer></script></body></html>{{ end }}
|
</main><script src="/static/js/feeds.js?v=12" defer></script></body></html>{{ end }}
|
||||||
@@ -4,4 +4,4 @@
|
|||||||
{{ template "organizer-nav" . }}
|
{{ template "organizer-nav" . }}
|
||||||
<main id="organizer-dashboard" data-writable="{{ .TaskWritable }}" data-calendar="{{ .CalendarEnabled }}" data-today="{{ .Today }}" data-timezone="{{ .Timezone }}">
|
<main id="organizer-dashboard" data-writable="{{ .TaskWritable }}" data-calendar="{{ .CalendarEnabled }}" data-today="{{ .Today }}" data-timezone="{{ .Timezone }}">
|
||||||
<header class="dashboard-toolbar"><div><h1>{{ T "organizer.dashboard" }}</h1><small>{{ .Today }} · {{ .Timezone }}</small></div><div id="dashboard-controls"></div></header><p id="dashboard-status" role="status" aria-live="polite"></p><div id="dashboard-grid"></div>
|
<header class="dashboard-toolbar"><div><h1>{{ T "organizer.dashboard" }}</h1><small>{{ .Today }} · {{ .Timezone }}</small></div><div id="dashboard-controls"></div></header><p id="dashboard-status" role="status" aria-live="polite"></p><div id="dashboard-grid"></div>
|
||||||
</main><script src="/static/js/task-presentation.js?v=1" defer></script><script src="/static/js/dashboard-commands.js?v=1" defer></script><script src="/static/js/organizer-dashboard.js?v=4" defer></script><script src="/static/js/task-productivity.js?v=8" defer></script></body></html>{{ end }}
|
</main><script src="/static/js/task-presentation.js?v=1" defer></script><script src="/static/js/dashboard-commands.js?v=1" defer></script><script src="/static/js/organizer-dashboard.js?v=5" defer></script><script src="/static/js/task-productivity.js?v=8" defer></script></body></html>{{ end }}
|
||||||
@@ -80,6 +80,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{ if .ObjectUUID }}
|
{{ if .ObjectUUID }}
|
||||||
|
<a class="breadcrumb-action-icon" href="/r/history/{{ .ObjectUUID }}" title="{{ T "history.title" }}" aria-label="{{ T "history.title" }}"><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>
|
||||||
{{ if and .SlidesEnabled (eq .ContentView.Kind "html") }}<a class="breadcrumb-action-icon" href="/v/slides{{ .Path }}" title="{{ T "slides.title" }}" aria-label="{{ T "slides.title" }}"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M3 4h18v12H3zM12 16v5m-5 0 5-5 5 5M8 8h8m-8 4h5"/></svg></a>{{ end }}
|
{{ if and .SlidesEnabled (eq .ContentView.Kind "html") }}<a class="breadcrumb-action-icon" href="/v/slides{{ .Path }}" title="{{ T "slides.title" }}" aria-label="{{ T "slides.title" }}"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M3 4h18v12H3zM12 16v5m-5 0 5-5 5 5M8 8h8m-8 4h5"/></svg></a>{{ end }}
|
||||||
<a class="breadcrumb-action-icon" href="/_/view/print/uuid:{{ .ObjectUUID }}" title="{{ T "viewer.print" }}" aria-label="{{ T "viewer.print" }}">
|
<a class="breadcrumb-action-icon" href="/_/view/print/uuid:{{ .ObjectUUID }}" title="{{ T "viewer.print" }}" aria-label="{{ T "viewer.print" }}">
|
||||||
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M7 9V4h10v5M7 17H5a2 2 0 0 1-2-2v-4a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v4a2 2 0 0 1-2 2h-2M7 14h10v6H7z"></path></svg>
|
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M7 9V4h10v5M7 17H5a2 2 0 0 1-2-2v-4a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v4a2 2 0 0 1-2 2h-2M7 14h10v6H7z"></path></svg>
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
<a
|
<a
|
||||||
href="/r/history/{{ .Revision.ObjectUUID }}"
|
href="/r/history/{{ .Revision.ObjectUUID }}"
|
||||||
>
|
>
|
||||||
History
|
{{ T "history.title" }}
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
</nav>
|
</nav>
|
||||||
@@ -52,6 +52,8 @@ History
|
|||||||
<h1>Revision View</h1>
|
<h1>Revision View</h1>
|
||||||
|
|
||||||
<div class="revision-meta">
|
<div class="revision-meta">
|
||||||
|
<div><time data-revision-time="{{ .Revision.CreatedAt }}">{{ .Revision.CreatedAt }}</time> · {{ .Revision.Language }}</div>
|
||||||
|
<div>{{ T "history.message" }}: {{ if .Revision.Message }}{{ .Revision.Message }}{{ else }}—{{ end }}</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
Revision UUID:
|
Revision UUID:
|
||||||
@@ -166,6 +168,7 @@ Raw HTML Source
|
|||||||
|
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
|
<script src="/static/js/revisions.js?v=2" defer></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
@@ -66,17 +66,20 @@ Object UUID:
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
{{ $r.CreatedAt }}
|
<time data-revision-time="{{ $r.CreatedAt }}">{{ $r.CreatedAt }}</time>
|
||||||
· {{ $r.Language }}
|
· {{ $r.Language }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="revision-message">
|
<div class="revision-message">
|
||||||
{{ $r.Message }}
|
{{ if $r.Message }}{{ $r.Message }}{{ else }}—{{ end }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="revision-actions">
|
<div class="revision-actions">
|
||||||
|
{{ if $.CanRestore }}{{ $head := index $.RevisionHeads $r.Language }}{{ if $head }}{{ if ne $head $r.UUID }}
|
||||||
|
<button type="button" data-restore-revision="{{ $r.UUID }}" data-base-revision="{{ $head }}">{{ T "editor.restore" }}</button>
|
||||||
|
{{ end }}{{ end }}{{ end }}
|
||||||
|
|
||||||
<a
|
<a
|
||||||
class="button"
|
class="button"
|
||||||
@@ -112,6 +115,7 @@ Object UUID:
|
|||||||
</nav>
|
</nav>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
|
<script src="/static/js/revisions.js?v=2" defer></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
Reference in new issue
Block a user