2020-06-28 21:07:42 +00:00
|
|
|
import $ from 'jquery'
|
|
|
|
import 'jquery-contextmenu'
|
2020-06-29 20:15:58 +00:00
|
|
|
import copy from 'copy-text-to-clipboard'
|
2021-11-06 13:36:10 +00:00
|
|
|
import axios from "axios";
|
|
|
|
import qs from "querystring";
|
2020-06-28 21:07:42 +00:00
|
|
|
|
2020-11-14 07:15:54 +00:00
|
|
|
function renderTree(tree) {
|
2020-06-29 20:15:58 +00:00
|
|
|
if (!tree) return []
|
2020-07-09 20:16:17 +00:00
|
|
|
|
|
|
|
let recRenderTree = (tree, indent) => {
|
|
|
|
return _.flatMapDeep(tree, (item) => [
|
2020-11-14 07:15:54 +00:00
|
|
|
_.repeat(" ", item.indented - indent) + item.text,
|
2020-07-09 20:16:17 +00:00
|
|
|
recRenderTree(item.children, indent),
|
|
|
|
])
|
|
|
|
}
|
|
|
|
|
|
|
|
return recRenderTree(tree, tree[0].indented)
|
2020-06-28 21:07:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function connectContextMenu(editor) {
|
|
|
|
$.contextMenu({
|
|
|
|
selector: '.marker',
|
2020-06-29 20:15:58 +00:00
|
|
|
items: {
|
|
|
|
createNewPage: {
|
|
|
|
name: 'Create page from item',
|
|
|
|
callback: function (key, opt) {
|
2021-11-06 13:36:10 +00:00
|
|
|
console.log('Create page from item')
|
|
|
|
editor.flat(this, {base: true}).then(result => {
|
|
|
|
let data = {
|
|
|
|
'json': 1,
|
|
|
|
'p': result.title,
|
|
|
|
'summary': "",
|
|
|
|
'content': JSON.stringify(result.children),
|
|
|
|
};
|
|
|
|
console.log(data)
|
|
|
|
return axios.post('/save/', qs.encode(data))
|
|
|
|
}).then()
|
2020-06-29 20:15:58 +00:00
|
|
|
},
|
|
|
|
className: 'action-new-page'
|
|
|
|
},
|
|
|
|
copy: {
|
|
|
|
name: 'Copy',
|
|
|
|
callback: function (key, opt) {
|
2020-11-16 21:38:38 +00:00
|
|
|
editor.flat(this).then(result => {
|
|
|
|
let data = JSON.stringify(result);
|
|
|
|
copy(data)
|
2020-06-29 20:15:58 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
className: 'action-copy'
|
|
|
|
},
|
|
|
|
copyLine: {
|
|
|
|
name: 'Copy line',
|
|
|
|
callback: function (key, opt) {
|
|
|
|
editor.copy(this, {recursive: false}).then(result => {
|
|
|
|
copy(result.text)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
className: 'action-copy-line'
|
2020-10-21 18:49:23 +00:00
|
|
|
},
|
|
|
|
zoom: {
|
|
|
|
name: 'Zoom in',
|
|
|
|
callback: function (key, opt) {
|
|
|
|
editor.zoomin(this).then(id => {
|
2020-11-11 21:16:07 +00:00
|
|
|
location.href = '/edit/' + id;
|
2020-10-21 18:49:23 +00:00
|
|
|
})
|
|
|
|
}
|
2020-11-04 22:41:03 +00:00
|
|
|
},
|
|
|
|
debug: {
|
|
|
|
name: 'Debug block',
|
|
|
|
callback: function (key, opt) {
|
2020-11-11 21:16:07 +00:00
|
|
|
editor.copy(this, {recursive: true}).then(console.log)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
addCheckbox: {
|
|
|
|
name: 'Add checkbox',
|
|
|
|
visible: function (key, opt) {
|
|
|
|
let item = $(this).parents('.list-item')
|
|
|
|
let id = item.attr('data-id')
|
|
|
|
let [found] = editor.actions.hasCheckbox.call(editor, id)
|
|
|
|
return !found
|
|
|
|
},
|
|
|
|
callback: function (key, opt) {
|
|
|
|
let item = $(this).parents('.list-item')
|
|
|
|
let id = item.attr('data-id')
|
|
|
|
editor.actions.addCheckbox.call(editor, id)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
removeCheckbox: {
|
|
|
|
name: 'Remove checkbox',
|
|
|
|
visible: function (key, opt) {
|
|
|
|
let item = $(this).parents('.list-item')
|
|
|
|
let id = item.attr('data-id')
|
|
|
|
let [found] = editor.actions.hasCheckbox.call(editor, id)
|
|
|
|
return found
|
|
|
|
},
|
|
|
|
callback: function (key, opt) {
|
|
|
|
let item = $(this).parents('.list-item')
|
|
|
|
let id = item.attr('data-id')
|
|
|
|
editor.actions.removeCheckbox.call(editor, id)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
markTodo: {
|
|
|
|
name: 'Mark To Do',
|
|
|
|
visible: function (key, opt) {
|
|
|
|
let item = $(this).parents('.list-item')
|
|
|
|
let id = item.attr('data-id')
|
|
|
|
let [found, todo] = editor.actions.hasCheckbox.call(editor, id)
|
|
|
|
return found && !todo
|
|
|
|
},
|
|
|
|
callback: function (key, opt) {
|
|
|
|
let item = $(this).parents('.list-item')
|
|
|
|
let id = item.attr('data-id')
|
|
|
|
editor.actions.markTodo.call(editor, id)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
markDone: {
|
|
|
|
name: 'Mark Done',
|
|
|
|
visible: function (key, opt) {
|
|
|
|
let item = $(this).parents('.list-item')
|
|
|
|
let id = item.attr('data-id')
|
|
|
|
let [found, todo] = editor.actions.hasCheckbox.call(editor, id)
|
|
|
|
return found && todo
|
|
|
|
},
|
|
|
|
callback: function (key, opt) {
|
|
|
|
let item = $(this).parents('.list-item')
|
|
|
|
let id = item.attr('data-id')
|
|
|
|
editor.actions.markDone.call(editor, id)
|
|
|
|
}
|
|
|
|
},
|
2020-11-14 07:18:20 +00:00
|
|
|
removeCompleted: {
|
|
|
|
name: 'Remove completed',
|
|
|
|
callback: function (key, opt) {
|
|
|
|
let item = $(this).parents('.list-item')
|
|
|
|
let id = item.attr('data-id')
|
|
|
|
editor.actions.removeCompleted.call(editor, id)
|
|
|
|
editor.render()
|
|
|
|
}
|
|
|
|
},
|
2020-11-11 21:16:07 +00:00
|
|
|
sort: {
|
|
|
|
name: 'Sort',
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
name: 'Title (A-Z)',
|
|
|
|
callback: function (key, opt) {
|
|
|
|
let item = $(this).parents('.list-item')
|
|
|
|
let id = item.attr('data-id')
|
|
|
|
editor.actions.sort.call(editor, id, 'text', 'asc')
|
|
|
|
editor.render()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Title (Z-A)',
|
|
|
|
callback: function (key, opt) {
|
|
|
|
let item = $(this).parents('.list-item')
|
|
|
|
let id = item.attr('data-id')
|
|
|
|
editor.actions.sort.call(editor, id, 'text', 'desc')
|
|
|
|
editor.render()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Checked first',
|
|
|
|
callback: function (key, opt) {
|
|
|
|
let item = $(this).parents('.list-item')
|
|
|
|
let id = item.attr('data-id')
|
|
|
|
editor.actions.sort.call(editor, id, 'todo', 'desc')
|
|
|
|
editor.render()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Unchecked first',
|
|
|
|
callback: function (key, opt) {
|
|
|
|
let item = $(this).parents('.list-item')
|
|
|
|
let id = item.attr('data-id')
|
|
|
|
editor.actions.sort.call(editor, id, 'todo', 'asc')
|
|
|
|
editor.render()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
|
2020-11-03 20:23:43 +00:00
|
|
|
// TODO
|
|
|
|
// - Sort
|
|
|
|
// - Date (on item) (new-old)
|
|
|
|
// - Date (on item) (old-new)
|
|
|
|
// - Updated (new to old)
|
|
|
|
// - Updated (old to new)
|
|
|
|
// - Created (new to old)
|
|
|
|
// - Created (old to new)
|
|
|
|
// - Reverse
|
|
|
|
// - Move To
|
|
|
|
// - Indent
|
2020-06-29 20:15:58 +00:00
|
|
|
}
|
2020-06-28 21:07:42 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
connectContextMenu: connectContextMenu
|
|
|
|
}
|