From 04f33726873e51fa572c7407c167583e6f83326d Mon Sep 17 00:00:00 2001 From: bouncepaw Date: Mon, 5 Apr 2021 23:29:45 +0500 Subject: [PATCH] Organize the toolbar and add the link yourself button --- assets/assets.qtpl.go | 60 +++++----- assets/default.css | 5 +- assets/toolbar.js | 55 ++++----- views/mutators.qtpl | 40 ++++++- views/mutators.qtpl.go | 254 +++++++++++++++++++++++++---------------- 5 files changed, 250 insertions(+), 164 deletions(-) diff --git a/assets/assets.qtpl.go b/assets/assets.qtpl.go index 1a8bede..d6fc38c 100644 --- a/assets/assets.qtpl.go +++ b/assets/assets.qtpl.go @@ -177,11 +177,13 @@ header { width: 100%; margin-bottom: 1rem; } main { grid-column: 1 / span 1; grid-row: 1 / span 2; } .relative-hyphae { grid-column: 2 / span 1; grid-row: 1 / span 1; } .layout-card { width: 100%; } + .edit-toolbar { margin: 0 0 0 auto; } + .edit-toolbar__buttons { display: grid; grid-template-columns: 1fr 1fr; } } @media screen and (min-width: 1250px) { .layout { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); } - .layout-card { max-width: 16rem; } + .layout-card { max-width: 18rem; } .main-width { margin: 0 auto; } .backlinks { grid-column: 1 / span 1; margin-right: 0; } main { grid-column: 2 / span 1; } @@ -204,6 +206,7 @@ textarea {font-size:16px; font-family: 'PT Sans', 'Liberation Sans', sans-serif; .edit-form {height:70vh;} .edit-form textarea {width:100%;height:95%;} .edit-form__save { font-weight: bold; } +.edit-toolbar__buttons, .edit-toolbar__ad { margin: .5rem; } .icon {margin-right: .25rem; vertical-align: bottom; } @@ -433,34 +436,19 @@ function getSelectedText(el = editTextarea) { return text.substring(start, end) } -function insertTextAtCursor(text, cursorPosition = null, el = editTextarea) { - const [start, end] = [el.selectionStart, el.selectionEnd] - el.setRangeText(text, start, end, 'select') - el.focus() - if (cursorPosition == null) { - placeCursor(end + text.length) - } else { - placeCursor(end + cursorPosition) +function textInserter(text, cursorPosition = null, el = editTextarea) { + return function() { + const [start, end] = [el.selectionStart, el.selectionEnd] + el.setRangeText(text, start, end, 'select') + el.focus() + if (cursorPosition == null) { + placeCursor(end + text.length) + } else { + placeCursor(end + cursorPosition) + } } } -function wrapSelection(prefix, postfix = null, el = editTextarea) { - const [start, end] = [el.selectionStart, el.selectionEnd] - if (postfix == null) { - postfix = prefix - } - text = getSelectedText(el) - result = prefix + text + postfix - el.setRangeText(result, start, end, 'select') - el.focus() - placeCursor(end + (prefix + postfix).length) -} - -function insertDate() { - let date = new Date().toISOString().split('T')[0] - insertTextAtCursor(date) -} - function selectionWrapper(cursorPosition, prefix, postfix = null, el = editTextarea) { return function() { const [start, end] = [el.selectionStart, el.selectionEnd] @@ -485,14 +473,24 @@ const wrapBold = selectionWrapper(2, '**'), wrapHighlighted = selectionWrapper(2, '!!'), wrapLifted = selectionWrapper(1, '^'), wrapLowered = selectionWrapper(2, ',,'), - wrapStrikethrough = selectionWrapper(2, '~~') + wrapStrikethrough = selectionWrapper(2, '~~'), + wrapLink = selectionWrapper(2, '[[', ']]') -function insertHorizontalBar() { - insertTextAtCursor('----\n') +const insertHorizontalBar = textInserter('----\n'), + insertImgBlock = textInserter('img {\n\t\n}\n', 7), + insertTableBlock = textInserter('table {\n\t\n}\n', 9), + insertRocket = textInserter('=> '), + insertXcl = textInserter('<= ') + +function insertDate() { + let date = new Date().toISOString().split('T')[0] + textInserter(date)() } -function insertImgBlock() { - insertTextAtCursor('img {\n\t\n}\n', 7) +function insertUserlink() { + const userlink = document.querySelector('.header-links__entry_user a') + const userHypha = userlink.getAttribute('href').substring(7) // no /hypha/ + textInserter('[[' + userHypha + ']]')() } `) //line assets/assets.qtpl:14 diff --git a/assets/default.css b/assets/default.css index 4d06d76..84c6fb7 100644 --- a/assets/default.css +++ b/assets/default.css @@ -66,11 +66,13 @@ header { width: 100%; margin-bottom: 1rem; } main { grid-column: 1 / span 1; grid-row: 1 / span 2; } .relative-hyphae { grid-column: 2 / span 1; grid-row: 1 / span 1; } .layout-card { width: 100%; } + .edit-toolbar { margin: 0 0 0 auto; } + .edit-toolbar__buttons { display: grid; grid-template-columns: 1fr 1fr; } } @media screen and (min-width: 1250px) { .layout { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); } - .layout-card { max-width: 16rem; } + .layout-card { max-width: 18rem; } .main-width { margin: 0 auto; } .backlinks { grid-column: 1 / span 1; margin-right: 0; } main { grid-column: 2 / span 1; } @@ -93,6 +95,7 @@ textarea {font-size:16px; font-family: 'PT Sans', 'Liberation Sans', sans-serif; .edit-form {height:70vh;} .edit-form textarea {width:100%;height:95%;} .edit-form__save { font-weight: bold; } +.edit-toolbar__buttons, .edit-toolbar__ad { margin: .5rem; } .icon {margin-right: .25rem; vertical-align: bottom; } diff --git a/assets/toolbar.js b/assets/toolbar.js index fe0629f..ea5c8d4 100644 --- a/assets/toolbar.js +++ b/assets/toolbar.js @@ -11,34 +11,19 @@ function getSelectedText(el = editTextarea) { return text.substring(start, end) } -function insertTextAtCursor(text, cursorPosition = null, el = editTextarea) { - const [start, end] = [el.selectionStart, el.selectionEnd] - el.setRangeText(text, start, end, 'select') - el.focus() - if (cursorPosition == null) { - placeCursor(end + text.length) - } else { - placeCursor(end + cursorPosition) +function textInserter(text, cursorPosition = null, el = editTextarea) { + return function() { + const [start, end] = [el.selectionStart, el.selectionEnd] + el.setRangeText(text, start, end, 'select') + el.focus() + if (cursorPosition == null) { + placeCursor(end + text.length) + } else { + placeCursor(end + cursorPosition) + } } } -function wrapSelection(prefix, postfix = null, el = editTextarea) { - const [start, end] = [el.selectionStart, el.selectionEnd] - if (postfix == null) { - postfix = prefix - } - text = getSelectedText(el) - result = prefix + text + postfix - el.setRangeText(result, start, end, 'select') - el.focus() - placeCursor(end + (prefix + postfix).length) -} - -function insertDate() { - let date = new Date().toISOString().split('T')[0] - insertTextAtCursor(date) -} - function selectionWrapper(cursorPosition, prefix, postfix = null, el = editTextarea) { return function() { const [start, end] = [el.selectionStart, el.selectionEnd] @@ -59,12 +44,22 @@ const wrapBold = selectionWrapper(2, '**'), wrapHighlighted = selectionWrapper(2, '!!'), wrapLifted = selectionWrapper(1, '^'), wrapLowered = selectionWrapper(2, ',,'), - wrapStrikethrough = selectionWrapper(2, '~~') + wrapStrikethrough = selectionWrapper(2, '~~'), + wrapLink = selectionWrapper(2, '[[', ']]') -function insertHorizontalBar() { - insertTextAtCursor('----\n') +const insertHorizontalBar = textInserter('----\n'), + insertImgBlock = textInserter('img {\n\t\n}\n', 7), + insertTableBlock = textInserter('table {\n\t\n}\n', 9), + insertRocket = textInserter('=> '), + insertXcl = textInserter('<= ') + +function insertDate() { + let date = new Date().toISOString().split('T')[0] + textInserter(date)() } -function insertImgBlock() { - insertTextAtCursor('img {\n\t\n}\n', 7) +function insertUserlink() { + const userlink = document.querySelector('.header-links__entry_user a') + const userHypha = userlink.getAttribute('href').substring(7) // no /hypha/ + textInserter('[[' + userHypha + ']]')() } diff --git a/views/mutators.qtpl b/views/mutators.qtpl index 3c01602..904d988 100644 --- a/views/mutators.qtpl +++ b/views/mutators.qtpl @@ -1,14 +1,17 @@ {% import "net/http" %} {% import "github.com/bouncepaw/mycorrhiza/util" %} +{% import "github.com/bouncepaw/mycorrhiza/user" %} -{% func Toolbar() %} +{% func Toolbar(u *user.User) %} {% endfunc %} @@ -45,7 +75,7 @@ Cancel -{%s= Toolbar() %} +{%s= Toolbar(user.FromRequest(rq)) %} {% endfunc %} @@ -66,6 +96,6 @@

Note that the hypha is not saved yet. You can preview the changes ↓

{%s= renderedPage %}
-{%s= Toolbar() %} +{%s= Toolbar(user.FromRequest(rq)) %} {% endfunc %} diff --git a/views/mutators.qtpl.go b/views/mutators.qtpl.go index 97e8385..8df905c 100644 --- a/views/mutators.qtpl.go +++ b/views/mutators.qtpl.go @@ -10,32 +10,37 @@ import "net/http" //line views/mutators.qtpl:2 import "github.com/bouncepaw/mycorrhiza/util" -//line views/mutators.qtpl:4 +//line views/mutators.qtpl:3 +import "github.com/bouncepaw/mycorrhiza/user" + +//line views/mutators.qtpl:5 import ( qtio422016 "io" qt422016 "github.com/valyala/quicktemplate" ) -//line views/mutators.qtpl:4 +//line views/mutators.qtpl:5 var ( _ = qtio422016.Copy _ = qt422016.AcquireByteBuffer ) -//line views/mutators.qtpl:4 -func StreamToolbar(qw422016 *qt422016.Writer) { -//line views/mutators.qtpl:4 +//line views/mutators.qtpl:5 +func StreamToolbar(qw422016 *qt422016.Writer, u *user.User) { +//line views/mutators.qtpl:5 qw422016.N().S(` `) -//line views/mutators.qtpl:31 +//line views/mutators.qtpl:61 } -//line views/mutators.qtpl:31 -func WriteToolbar(qq422016 qtio422016.Writer) { -//line views/mutators.qtpl:31 +//line views/mutators.qtpl:61 +func WriteToolbar(qq422016 qtio422016.Writer, u *user.User) { +//line views/mutators.qtpl:61 qw422016 := qt422016.AcquireWriter(qq422016) -//line views/mutators.qtpl:31 - StreamToolbar(qw422016) -//line views/mutators.qtpl:31 +//line views/mutators.qtpl:61 + StreamToolbar(qw422016, u) +//line views/mutators.qtpl:61 qt422016.ReleaseWriter(qw422016) -//line views/mutators.qtpl:31 +//line views/mutators.qtpl:61 } -//line views/mutators.qtpl:31 -func Toolbar() string { -//line views/mutators.qtpl:31 +//line views/mutators.qtpl:61 +func Toolbar(u *user.User) string { +//line views/mutators.qtpl:61 qb422016 := qt422016.AcquireByteBuffer() -//line views/mutators.qtpl:31 - WriteToolbar(qb422016) -//line views/mutators.qtpl:31 +//line views/mutators.qtpl:61 + WriteToolbar(qb422016, u) +//line views/mutators.qtpl:61 qs422016 := string(qb422016.B) -//line views/mutators.qtpl:31 +//line views/mutators.qtpl:61 qt422016.ReleaseByteBuffer(qb422016) -//line views/mutators.qtpl:31 +//line views/mutators.qtpl:61 return qs422016 -//line views/mutators.qtpl:31 +//line views/mutators.qtpl:61 } -//line views/mutators.qtpl:33 +//line views/mutators.qtpl:63 func StreamEditHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaName, textAreaFill, warning string) { -//line views/mutators.qtpl:33 +//line views/mutators.qtpl:63 qw422016.N().S(` `) -//line views/mutators.qtpl:34 +//line views/mutators.qtpl:64 qw422016.N().S(NavHTML(rq, hyphaName, "edit")) -//line views/mutators.qtpl:34 +//line views/mutators.qtpl:64 qw422016.N().S(`

Edit `) -//line views/mutators.qtpl:37 +//line views/mutators.qtpl:67 qw422016.E().S(util.BeautifulName(hyphaName)) -//line views/mutators.qtpl:37 +//line views/mutators.qtpl:67 qw422016.N().S(`

`) -//line views/mutators.qtpl:38 +//line views/mutators.qtpl:68 qw422016.N().S(warning) -//line views/mutators.qtpl:38 +//line views/mutators.qtpl:68 qw422016.N().S(`

Cancel
`) -//line views/mutators.qtpl:48 - qw422016.N().S(Toolbar()) -//line views/mutators.qtpl:48 +//line views/mutators.qtpl:78 + qw422016.N().S(Toolbar(user.FromRequest(rq))) +//line views/mutators.qtpl:78 qw422016.N().S(`
`) -//line views/mutators.qtpl:50 +//line views/mutators.qtpl:80 } -//line views/mutators.qtpl:50 +//line views/mutators.qtpl:80 func WriteEditHTML(qq422016 qtio422016.Writer, rq *http.Request, hyphaName, textAreaFill, warning string) { -//line views/mutators.qtpl:50 +//line views/mutators.qtpl:80 qw422016 := qt422016.AcquireWriter(qq422016) -//line views/mutators.qtpl:50 +//line views/mutators.qtpl:80 StreamEditHTML(qw422016, rq, hyphaName, textAreaFill, warning) -//line views/mutators.qtpl:50 +//line views/mutators.qtpl:80 qt422016.ReleaseWriter(qw422016) -//line views/mutators.qtpl:50 +//line views/mutators.qtpl:80 } -//line views/mutators.qtpl:50 +//line views/mutators.qtpl:80 func EditHTML(rq *http.Request, hyphaName, textAreaFill, warning string) string { -//line views/mutators.qtpl:50 +//line views/mutators.qtpl:80 qb422016 := qt422016.AcquireByteBuffer() -//line views/mutators.qtpl:50 +//line views/mutators.qtpl:80 WriteEditHTML(qb422016, rq, hyphaName, textAreaFill, warning) -//line views/mutators.qtpl:50 +//line views/mutators.qtpl:80 qs422016 := string(qb422016.B) -//line views/mutators.qtpl:50 +//line views/mutators.qtpl:80 qt422016.ReleaseByteBuffer(qb422016) -//line views/mutators.qtpl:50 +//line views/mutators.qtpl:80 return qs422016 -//line views/mutators.qtpl:50 +//line views/mutators.qtpl:80 } -//line views/mutators.qtpl:52 +//line views/mutators.qtpl:82 func StreamPreviewHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaName, textAreaFill, warning string, renderedPage string) { -//line views/mutators.qtpl:52 +//line views/mutators.qtpl:82 qw422016.N().S(` `) -//line views/mutators.qtpl:53 +//line views/mutators.qtpl:83 qw422016.N().S(NavHTML(rq, hyphaName, "edit")) -//line views/mutators.qtpl:53 +//line views/mutators.qtpl:83 qw422016.N().S(`

Edit `) -//line views/mutators.qtpl:56 +//line views/mutators.qtpl:86 qw422016.E().S(util.BeautifulName(hyphaName)) -//line views/mutators.qtpl:56 +//line views/mutators.qtpl:86 qw422016.N().S(` (preview)

`) -//line views/mutators.qtpl:57 +//line views/mutators.qtpl:87 qw422016.N().S(warning) -//line views/mutators.qtpl:57 +//line views/mutators.qtpl:87 qw422016.N().S(`

Cancel

Note that the hypha is not saved yet. You can preview the changes ↓

`) -//line views/mutators.qtpl:67 +//line views/mutators.qtpl:97 qw422016.N().S(renderedPage) -//line views/mutators.qtpl:67 +//line views/mutators.qtpl:97 qw422016.N().S(`
`) -//line views/mutators.qtpl:69 - qw422016.N().S(Toolbar()) -//line views/mutators.qtpl:69 +//line views/mutators.qtpl:99 + qw422016.N().S(Toolbar(user.FromRequest(rq))) +//line views/mutators.qtpl:99 qw422016.N().S(`
`) -//line views/mutators.qtpl:71 +//line views/mutators.qtpl:101 } -//line views/mutators.qtpl:71 +//line views/mutators.qtpl:101 func WritePreviewHTML(qq422016 qtio422016.Writer, rq *http.Request, hyphaName, textAreaFill, warning string, renderedPage string) { -//line views/mutators.qtpl:71 +//line views/mutators.qtpl:101 qw422016 := qt422016.AcquireWriter(qq422016) -//line views/mutators.qtpl:71 +//line views/mutators.qtpl:101 StreamPreviewHTML(qw422016, rq, hyphaName, textAreaFill, warning, renderedPage) -//line views/mutators.qtpl:71 +//line views/mutators.qtpl:101 qt422016.ReleaseWriter(qw422016) -//line views/mutators.qtpl:71 +//line views/mutators.qtpl:101 } -//line views/mutators.qtpl:71 +//line views/mutators.qtpl:101 func PreviewHTML(rq *http.Request, hyphaName, textAreaFill, warning string, renderedPage string) string { -//line views/mutators.qtpl:71 +//line views/mutators.qtpl:101 qb422016 := qt422016.AcquireByteBuffer() -//line views/mutators.qtpl:71 +//line views/mutators.qtpl:101 WritePreviewHTML(qb422016, rq, hyphaName, textAreaFill, warning, renderedPage) -//line views/mutators.qtpl:71 +//line views/mutators.qtpl:101 qs422016 := string(qb422016.B) -//line views/mutators.qtpl:71 +//line views/mutators.qtpl:101 qt422016.ReleaseByteBuffer(qb422016) -//line views/mutators.qtpl:71 +//line views/mutators.qtpl:101 return qs422016 -//line views/mutators.qtpl:71 +//line views/mutators.qtpl:101 }