This commit is contained in:
parent
c0850e44c4
commit
78cdbcfa72
5
editor/package-lock.json
generated
5
editor/package-lock.json
generated
|
@ -4252,6 +4252,11 @@
|
||||||
"minimist": "^1.2.5"
|
"minimist": "^1.2.5"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"moment": {
|
||||||
|
"version": "2.26.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/moment/-/moment-2.26.0.tgz",
|
||||||
|
"integrity": "sha512-oIixUO+OamkUkwjhAVE18rAMfRJNsNe/Stid/gwHSOfHrOtw9EhAY2AHvdKZ/k/MggcYELFCJz/Sn2pL8b8JMw=="
|
||||||
|
},
|
||||||
"move-concurrently": {
|
"move-concurrently": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz",
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
"fuse.js": "^6.0.0",
|
"fuse.js": "^6.0.0",
|
||||||
"jquery-contextmenu": "^2.9.2",
|
"jquery-contextmenu": "^2.9.2",
|
||||||
"lunr": "^2.3.8",
|
"lunr": "^2.3.8",
|
||||||
|
"moment": "^2.26.0",
|
||||||
"mustache": "^4.0.1",
|
"mustache": "^4.0.1",
|
||||||
"node-sass": "^4.14.1",
|
"node-sass": "^4.14.1",
|
||||||
"sass-loader": "^7.3.1",
|
"sass-loader": "^7.3.1",
|
||||||
|
|
|
@ -8,12 +8,24 @@ function createTitleSearch() {
|
||||||
keys: ['title'],
|
keys: ['title'],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let commands = [
|
||||||
|
{title: 'Current Time', name: 'time'},
|
||||||
|
{title: 'Today', name: 'today'},
|
||||||
|
{title: 'Tomorrow', name: 'tomorrow'},
|
||||||
|
{title: 'Yesterday', name: 'yesterday'},
|
||||||
|
{title: 'TODO', name: 'todo'},
|
||||||
|
{title: 'Page Reference', name: 'page_reference'},
|
||||||
|
];
|
||||||
|
|
||||||
const fuseIndex = Fuse.createIndex(options.keys, documents)
|
const fuseIndex = Fuse.createIndex(options.keys, documents)
|
||||||
let fuse = new Fuse(documents, options, fuseIndex)
|
let titleFuse = new Fuse(documents, options, fuseIndex)
|
||||||
|
let commandFuse = new Fuse(commands, {keys: ['title', 'name']})
|
||||||
|
|
||||||
resolve({
|
resolve({
|
||||||
documents,
|
documents,
|
||||||
search: fuse,
|
titleSearch: titleFuse,
|
||||||
|
commandSearch: commandFuse,
|
||||||
|
commands: commands,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -7,10 +7,12 @@ import createPageSearch from './fuse';
|
||||||
import Mustache from 'mustache';
|
import Mustache from 'mustache';
|
||||||
import 'jquery-contextmenu';
|
import 'jquery-contextmenu';
|
||||||
import getCaretCoordinates from './caret-position'
|
import getCaretCoordinates from './caret-position'
|
||||||
|
import moment from 'moment'
|
||||||
import './styles.scss';
|
import './styles.scss';
|
||||||
import '../node_modules/jquery-contextmenu/dist/jquery.contextMenu.css';
|
import '../node_modules/jquery-contextmenu/dist/jquery.contextMenu.css';
|
||||||
|
|
||||||
|
moment.locale('nl')
|
||||||
|
|
||||||
function addSaver(editor, saveUrl, page, beforeSave) {
|
function addSaver(editor, saveUrl, page, beforeSave) {
|
||||||
return {
|
return {
|
||||||
save() {
|
save() {
|
||||||
|
@ -61,6 +63,28 @@ function addIndicator(editor, indicator) {
|
||||||
}
|
}
|
||||||
|
|
||||||
let holder = document.getElementById('editor');
|
let holder = document.getElementById('editor');
|
||||||
|
|
||||||
|
function showSearchResults(searchTool, query, input, value, resultType) {
|
||||||
|
let results = searchTool(query)
|
||||||
|
|
||||||
|
if (results.length === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let pos = getCaretCoordinates(input, value.selectionEnd, {})
|
||||||
|
let off = $(input).offset()
|
||||||
|
pos.top += off.top + pos.height
|
||||||
|
pos.left += off.left
|
||||||
|
|
||||||
|
const $lc = $('#link-complete')
|
||||||
|
$lc.data('result-type', resultType)
|
||||||
|
$lc.offset(pos)
|
||||||
|
|
||||||
|
var template = document.getElementById('link-template').innerHTML;
|
||||||
|
var rendered = Mustache.render(template, {results: results}, {}, ['[[', ']]']);
|
||||||
|
$lc.html(rendered).fadeIn()
|
||||||
|
}
|
||||||
|
|
||||||
if (holder) {
|
if (holder) {
|
||||||
let editor = listEditor(holder, JSON.parse(holder.dataset.input));
|
let editor = listEditor(holder, JSON.parse(holder.dataset.input));
|
||||||
|
|
||||||
|
@ -89,7 +113,7 @@ if (holder) {
|
||||||
|
|
||||||
if (event.key === 'Enter') {
|
if (event.key === 'Enter') {
|
||||||
const linkName = $popup.find('li.selected').text()
|
const linkName = $popup.find('li.selected').text()
|
||||||
$popup.trigger('popup:selected', [linkName])
|
$popup.trigger('popup:selected', [linkName, $popup.data('result-type')])
|
||||||
$popup.fadeOut()
|
$popup.fadeOut()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -123,20 +147,56 @@ if (holder) {
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
createPageSearch().then(function ({search}) {
|
createPageSearch().then(function ({titleSearch, commandSearch, commands}) {
|
||||||
editor.on('start-editing', function (input) {
|
editor.on('start-editing', function (input) {
|
||||||
const $lc = $('#link-complete')
|
const $lc = $('#link-complete')
|
||||||
|
|
||||||
$lc.on('popup:selected', function (event, linkName) {
|
$lc.on('popup:selected', function (event, linkName, resultType) {
|
||||||
let value = input.value
|
let value = input.value
|
||||||
let end = input.selectionEnd
|
let end = input.selectionEnd
|
||||||
let start = value.lastIndexOf("[[", end)
|
if (resultType === 'link') {
|
||||||
end += 2
|
let start = value.lastIndexOf("[[", end)
|
||||||
let startAndLink = value.substring(0, start) + "[[" + linkName + "]]"
|
end += 2
|
||||||
input.value = startAndLink + value.substring(end)
|
let startAndLink = value.substring(0, start) + "[[" + linkName + "]]"
|
||||||
input.selectionStart = startAndLink.length
|
input.value = startAndLink + value.substring(end)
|
||||||
input.selectionEnd = startAndLink.length
|
input.selectionStart = startAndLink.length
|
||||||
input.focus()
|
input.selectionEnd = startAndLink.length
|
||||||
|
input.focus()
|
||||||
|
} else if (resultType === 'command') {
|
||||||
|
let start = value.lastIndexOf("/", end)
|
||||||
|
let commandResult = ""
|
||||||
|
let prefix = false
|
||||||
|
let adjustment = 0
|
||||||
|
|
||||||
|
let now = moment()
|
||||||
|
|
||||||
|
if (linkName === "Current Time") {
|
||||||
|
commandResult = now.format('HH:mm')
|
||||||
|
} else if (linkName === "Today") {
|
||||||
|
commandResult = "[[" + now.format('D MMMM YYYY') + "]]"
|
||||||
|
} else if (linkName === "Tomorrow") {
|
||||||
|
commandResult = "[[" + now.add(1, 'day').format('D MMMM YYYY') + "]]"
|
||||||
|
} else if (linkName === "Yesterday") {
|
||||||
|
commandResult = "[[" + now.add(-1, 'day').format('D MMMM YYYY') + "]]"
|
||||||
|
} else if (linkName === "TODO") {
|
||||||
|
commandResult = "#[[TODO]] "
|
||||||
|
prefix = true
|
||||||
|
} else if (linkName === "Page Reference") {
|
||||||
|
commandResult = "[[]]"
|
||||||
|
adjustment = -2
|
||||||
|
}
|
||||||
|
|
||||||
|
let startAndLink = prefix
|
||||||
|
? commandResult + value.substring(0, start)
|
||||||
|
: value.substring(0, start) + commandResult
|
||||||
|
|
||||||
|
input.value = startAndLink + value.substring(end)
|
||||||
|
|
||||||
|
input.selectionStart = startAndLink.length + adjustment
|
||||||
|
input.selectionEnd = startAndLink.length + adjustment
|
||||||
|
|
||||||
|
input.focus()
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -164,34 +224,34 @@ if (holder) {
|
||||||
$(input).on('keyup', function () {
|
$(input).on('keyup', function () {
|
||||||
let value = input.value
|
let value = input.value
|
||||||
let end = input.selectionEnd
|
let end = input.selectionEnd
|
||||||
|
|
||||||
|
let insideLink = true
|
||||||
|
let insideSearch = false
|
||||||
|
|
||||||
let start = value.lastIndexOf("[[", end)
|
let start = value.lastIndexOf("[[", end)
|
||||||
if (start < 0) {
|
if (start < 0) {
|
||||||
return true
|
insideLink = false
|
||||||
}
|
}
|
||||||
|
|
||||||
let linkEnd = value.lastIndexOf("]]", end - 1)
|
let linkEnd = value.lastIndexOf("]]", end - 1)
|
||||||
if (start < linkEnd) {
|
if (insideLink && start < linkEnd) {
|
||||||
return true
|
insideLink = false
|
||||||
}
|
|
||||||
let query = value.substring(start+2, end);
|
|
||||||
let results = search.search(query)
|
|
||||||
|
|
||||||
if (results.length === 0) {
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let pos = getCaretCoordinates(input, value.selectionEnd, {})
|
if (!insideLink) {
|
||||||
let off = $(input).offset()
|
start = value.lastIndexOf("/", end)
|
||||||
pos.top += off.top + pos.height
|
insideSearch = start >= 0
|
||||||
pos.left += off.left
|
}
|
||||||
|
|
||||||
const $lc = $('#link-complete')
|
if (insideSearch) {
|
||||||
$lc.offset(pos)
|
let query = value.substring(start + 1, end);
|
||||||
|
showSearchResults(query => commandSearch.search(query), query, input, value, 'command');
|
||||||
var template = document.getElementById('link-template').innerHTML;
|
return true
|
||||||
var rendered = Mustache.render(template, {results: results}, {}, ['[[', ']]']);
|
} else if (insideLink) {
|
||||||
$lc.html(rendered).fadeIn()
|
let query = value.substring(start + 2, end);
|
||||||
return true
|
showSearchResults(query => titleSearch.search(query), query, input, value, 'link');
|
||||||
|
return true
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user