Merge branch 'staging' of github.com:xwiki-labs/cryptpad into staging

This commit is contained in:
yflory
2019-08-12 12:15:17 +02:00
26 changed files with 485 additions and 244 deletions

View File

@@ -230,9 +230,15 @@ define([
if (!Visible.currently()) { to = window.setTimeout(interval, Thumb.UPDATE_FIRST); }
};
var addThumbnail = function (err, thumb, $span, cb) {
var u8 = Nacl.util.decodeBase64(thumb.split(',')[1]);
var blob = new Blob([u8], {
type: 'image/png'
});
var url = URL.createObjectURL(blob);
var img = new Image();
img.src = thumb.slice(0,5) === 'data:' ? thumb : 'data:image/png;base64,'+thumb;
img.src = url;
$span.find('.cp-icon').hide();
$span.prepend(img);
cb($(img));

View File

@@ -573,9 +573,9 @@ define([
onFriendShare.reg(saveValue);
var getLinkValue = function (initValue) {
var val = initValue || {};
var edit = initValue ? val.edit : Util.isChecked($(link).find('#cp-share-editable-true'));
var embed = initValue ? val.embed : Util.isChecked($(link).find('#cp-share-embed'));
var present = initValue ? val.present : Util.isChecked($(link).find('#cp-share-present'));
var edit = val.edit !== undefined ? val.edit : Util.isChecked($(link).find('#cp-share-editable-true'));
var embed = val.embed !== undefined ? val.embed : Util.isChecked($(link).find('#cp-share-embed'));
var present = val.present !== undefined ? val.present : Util.isChecked($(link).find('#cp-share-present'));
var hash = (!hashes.viewHash || (edit && hashes.editHash)) ? hashes.editHash : hashes.viewHash;
var href = origin + pathname + '#' + hash;
@@ -2104,6 +2104,9 @@ define([
};
UIElements.createNewPadModal = function (common) {
// if in drive, show new pad modal instead
if ($("body.cp-app-drive").length !== 0) { return void $(".cp-app-drive-element-row.cp-app-drive-new-ghost").click(); }
var $modal = UIElements.createModal({
id: 'cp-app-toolbar-creation-dialog',
$body: $('body')
@@ -2766,8 +2769,12 @@ define([
UIElements.displayCrowdfunding(common);
modal.delete();
});
var waitingForStoringCb = false;
$(store).click(function () {
if (waitingForStoringCb) { return; }
waitingForStoringCb = true;
common.getSframeChannel().query("Q_AUTOSTORE_STORE", null, function (err, obj) {
waitingForStoringCb = false;
var error = err || (obj && obj.error);
if (error) {
if (error === 'E_OVER_LIMIT') {
@@ -2854,11 +2861,27 @@ define([
'aria-labelledBy': 'dropdownMenu',
'style': 'display:block;position:static;margin-bottom:5px;'
}, [
h('li', h('a.dropdown-item', {
h('li', h('a.cp-app-code-context-saveindrive.dropdown-item', {
'tabindex': '-1',
}, Messages.pad_mediatagImport))
'data-icon': "fa-cloud-upload",
}, Messages.pad_mediatagImport)),
h('li', h('a.cp-app-code-context-download.dropdown-item', {
'tabindex': '-1',
'data-icon': "fa-download",
}, Messages.download_mt_button)),
])
]);
// create the icon for each contextmenu option
$(menu).find("li a.dropdown-item").each(function (i, el) {
var $icon = $("<span>");
if ($(el).attr('data-icon')) {
var font = $(el).attr('data-icon').indexOf('cptools') === 0 ? 'cptools' : 'fa';
$icon.addClass(font).addClass($(el).attr('data-icon'));
} else {
$icon.text($(el).text());
}
$(el).prepend($icon);
});
var m = createContextMenu(menu);
mediatagContextMenu = m;
@@ -2868,7 +2891,13 @@ define([
e.stopPropagation();
m.hide();
var $mt = $menu.data('mediatag');
common.importMediaTag($mt);
if ($(this).hasClass("cp-app-code-context-saveindrive")) {
common.importMediaTag($mt);
}
else if ($(this).hasClass("cp-app-code-context-download")) {
var media = $mt[0]._mediaObject;
window.saveAs(media._blob.content, media.name);
}
});
return m;

View File

@@ -319,6 +319,12 @@ define([], function () {
return window.innerHeight < 800 || window.innerWidth < 800;
};
Util.stripTags = function (text) {
var div = document.createElement("div");
div.innerHTML = text;
return div.innerText;
};
return Util;
});
}(self));

View File

@@ -15,6 +15,7 @@ define([
var DiffDOM = window.diffDOM;
var renderer = new Marked.Renderer();
var restrictedRenderer = new Marked.Renderer();
var Mermaid = {
init: function () {}
@@ -61,13 +62,18 @@ define([
return h('div.cp-md-toc', content).outerHTML;
};
DiffMd.render = function (md, sanitize) {
DiffMd.render = function (md, sanitize, restrictedMd) {
Marked.setOptions({
renderer: restrictedMd ? restrictedRenderer : renderer,
});
var r = Marked(md, {
sanitize: sanitize
});
// Add Table of Content
r = r.replace(/<div class="cp-md-toc"><\/div>/g, getTOC());
if (!restrictedMd) {
r = r.replace(/<div class="cp-md-toc"><\/div>/g, getTOC());
}
toc = [];
return r;
@@ -83,12 +89,7 @@ define([
return defaultCode.apply(renderer, arguments);
}
};
var stripTags = function (text) {
var div = document.createElement("div");
div.innerHTML = text;
return div.innerText;
};
restrictedRenderer.code = renderer.code;
renderer.heading = function (text, level) {
var i = 0;
@@ -105,10 +106,13 @@ define([
toc.push({
level: level,
id: id,
title: stripTags(text)
title: Util.stripTags(text)
});
return "<h" + level + " id=\"" + id + "\"><a href=\"#" + id + "\" class=\"anchor\"></a>" + text + "</h" + level + ">";
};
restrictedRenderer.heading = function (text) {
return text;
};
// Tasks list
var checkedTaskItemPtn = /^\s*(<p>)?\[[xX]\](<\/p>)?\s*/;
@@ -138,6 +142,13 @@ define([
var cls = (isCheckedTaskItem || isUncheckedTaskItem || hasBogusInput) ? ' class="todo-list-item"' : '';
return '<li'+ cls + '>' + text + '</li>\n';
};
restrictedRenderer.listitem = function (text) {
if (bogusCheckPtn.test(text)) {
text = text.replace(bogusCheckPtn, '');
}
return '<li>' + text + '</li>\n';
};
renderer.image = function (href, title, text) {
if (href.slice(0,6) === '/file/') {
// DEPRECATED
@@ -162,12 +173,19 @@ define([
out += this.options.xhtml ? '/>' : '>';
return out;
};
restrictedRenderer.image = renderer.image;
var renderParagraph = function (p) {
return /<media\-tag[\s\S]*>/i.test(p)? p + '\n': '<p>' + p + '</p>\n';
};
renderer.paragraph = function (p) {
if (p === '[TOC]') {
return '<p><div class="cp-md-toc"></div></p>';
}
return /<media\-tag[\s\S]*>/i.test(p)? p + '\n': '<p>' + p + '</p>\n';
return renderParagraph(p);
};
restrictedRenderer.paragraph = function (p) {
return renderParagraph(p);
};
var MutationObserver = window.MutationObserver;

View File

@@ -30,9 +30,22 @@
};
var isplainTextFile = function (metadata) {
// does its type begins with "text/"
if (metadata.type.indexOf("text/") === 0) { return true; }
// no type and no file extension -> let's guess it's plain text
var parsedName = /^(\.?.+?)(\.[^.]+)?$/.exec(metadata.name) || [];
if (!metadata.type && !parsedName[2]) { return true; }
// other exceptions
if (metadata.type === 'application/x-javascript') { return true; }
if (metadata.type === 'application/xml') { return true; }
return false;
};
// Default config, can be overriden per media-tag call
var config = {
allowed: [
'text/plain',
'image/png',
'image/jpeg',
'image/jpg',
@@ -53,6 +66,23 @@
text: "Download"
},
Plugins: {
/**
* @param {object} metadataObject {name, metadatatype, owners} containing metadata of the file
* @param {strint} url Url of the blob object
* @param {Blob} content Blob object containing the data of the file
* @param {object} cfg Object {Plugins, allowed, download, pdf} containing infos about plugins
* @param {function} cb Callback function: (err, pluginElement) => {}
*/
text: function (metadata, url, content, cfg, cb) {
var plainText = document.createElement('div');
plainText.className = "plain-text-reader";
var reader = new FileReader();
reader.addEventListener('loadend', function (e) {
plainText.innerText = e.srcElement.result;
cb(void 0, plainText);
});
reader.readAsText(content);
},
image: function (metadata, url, content, cfg, cb) {
var img = document.createElement('img');
img.setAttribute('src', url);
@@ -271,6 +301,9 @@
var blob = decrypted.content;
var mediaType = getType(mediaObject, metadata, cfg);
if (isplainTextFile(metadata)) {
mediaType = "text";
}
if (mediaType === 'application') {
mediaType = mediaObject.extension;

View File

@@ -151,7 +151,7 @@ define([
});
try {
var $d = $(d);
DiffMd.apply(DiffMd.render(md || '', true), $d, common);
DiffMd.apply(DiffMd.render(md || '', true, true), $d, common);
$d.addClass("cp-app-contacts-content");
// override link clicking, because we're in an iframe
@@ -197,7 +197,7 @@ define([
var getChat = function (id) {
return $messages.find(dataQuery(id));
};
var scrollChatToBottom = function () {
var $messagebox = $('.cp-app-contacts-messages');
$messagebox.scrollTop($messagebox[0].scrollHeight);

View File

@@ -6,141 +6,141 @@ define([
// mode language (extension)
var list = Modes.list = [
"APL apl .apl",
"ASCII-Armor asciiarmor",
"ASN.1 asn.1",
"ASCII-Armor asciiarmor .asc",
"ASN.1 asn.1 .asn1",
"Asterisk asterisk",
"Brainfuck brainfuck .b",
"C text/x-csrc .c",
"C text/x-c++src .cpp",
"C-like clike",
"Clojure clojure",
"CMake cmake",
"COBOL cobol",
"CoffeeScript coffeescript",
"Common_Lisp commonlisp",
"Crystal crystal",
"C-like clike .c",
"Clojure clojure .clj",
"CMake cmake _", /* no extension */
"COBOL cobol .cbl",
"CoffeeScript coffeescript .coffee",
"Common_Lisp commonlisp .lisp",
"Crystal crystal .cr",
"CSS css .css",
"Cypher cypher",
"D d",
"Dart dart",
"Diff diff",
"Django django",
"Dockerfile dockerfile",
"DTD dtd",
"Dylan dylan",
"EBNF ebnf",
"ECL ecl",
"Eiffel eiffel",
"Cypher cypher .cypher",
"D d .d",
"Dart dart .dart",
"Diff diff .diff",
"Django django .py",
"Dockerfile dockerfile _", /* no extension */
"DTD dtd .dtd",
"Dylan dylan .dylan",
"EBNF ebnf .ebnf",
"ECL ecl .ecl",
"Eiffel eiffel .e",
"Elm elm .elm",
"Erlang erlang",
"Factor factor",
"FCL fcl",
"Forth forth",
"Fortran fortran",
"GAS gas",
"Gherkin gherkin",
"Go go",
"Groovy groovy",
"Haml haml",
"Handlebars handlebars",
"Erlang erlang .erl",
"Factor factor .factor",
"FCL fcl .fcl",
"Forth forth .fs",
"Fortran fortran .f90",
"GAS gas .gas",
"Gherkin gherkin .feature",
"Go go .go",
"Groovy groovy .groovy",
"Haml haml .haml",
"Handlebars handlebars .hbs",
"Haskell haskell .hs",
"Haskell-Literate haskell-literate",
"Haxe haxe",
"Haskell-Literate haskell-literate .lhs",
"Haxe haxe .hx",
"HTML htmlmixed .html",
"HTTP http",
"IDL idl",
"JADE jade",
"HTTP http _", /* no extension */
"IDL idl .idl",
"JADE jade .jade",
"Java text/x-java .java",
"JavaScript javascript .js",
"Jinja2 jinja2",
"Jinja2 jinja2 .j2",
"JSX jsx .jsx",
"Julia julia",
"LiveScript livescript",
"Lua lua",
"Julia julia .jl",
"LiveScript livescript .ls",
"Lua lua .lua",
"Markdown gfm .md",
//"markdown markdown .md",
"Mathematica mathematica",
"mIRC mirc",
"ML mllike",
"Modelica modelica",
"MscGen mscgen",
"MUMPS mumps",
"Nginx nginx",
"NSIS nsis",
"N-Triples ntriples",
"Mathematica mathematica .nb",
"mIRC mirc .irc",
"ML mllike _", /* no extension */
"Modelica modelica .mo",
"MscGen mscgen .mscgen",
"MUMPS mumps .m",
"Nginx nginx .conf",
"NSIS nsis .nsi",
"N-Triples ntriples .nq",
"Objective-C text/x-objectivec .m",
"Octave octave",
"Octave octave .m",
"Org-mode orgmode .org",
"Oz oz",
"Pascal pascal",
"PEG.js pegjs",
"Perl perl",
"PHP php",
"Pig pig",
"PowerShell powershell",
"Properties properties",
"Protocol_Buffers protobuf",
"Puppet puppet",
"Oz oz .oz",
"Pascal pascal .pas",
"PEG.js pegjs .pegjs",
"Perl perl .pl",
"PHP php .php",
"Pig pig .pig",
"PowerShell powershell .ps1",
"Properties properties .properties",
"Protocol_Buffers protobuf .proto",
"Puppet puppet .pp",
"Python python .py",
"Q q",
"R r",
"RPM rpm",
"RST rst",
"Ruby ruby",
"Rust rust",
"Sass sass",
"Q q .q",
"R r .r",
"RPM rpm .rpm",
"RST rst .rst",
"Ruby ruby .rb",
"Rust rust .rs",
"Sass sass .sass",
"Scheme scheme .scm",
"Shell shell .sh",
"Sieve sieve",
"Slim slim",
"Smalltalk smalltalk",
"Smarty smarty",
"Solr solr",
"Soy soy",
"SPARQL sparql",
"Spreadsheet spreadsheet",
"SQL sql",
"sTeX stex",
"Stylus stylus",
"Swift swift",
"Tcl tcl",
"Sieve sieve .sieve",
"Slim slim .slim",
"Smalltalk smalltalk _", /* no extension */
"Smarty smarty _", /* no extension */
"Solr solr _", /* no extension */
"Soy soy .soy",
"SPARQL sparql .rq",
"Spreadsheet spreadsheet .xls",
"SQL sql .sql",
"sTeX stex .stex",
"Stylus stylus .styl",
"Swift swift .swift",
"Tcl tcl .tcl",
"Text text .txt",
"Textile textile",
"TiddlyWiki tiddlywiki",
"Tiki tiki",
"TOML toml",
"Tornado tornado",
"troff troff",
"Textile textile .textile",
"TiddlyWiki tiddlywiki .tw",
"Tiki tiki _", /* no extension */
"TOML toml .toml",
"Tornado tornado .tornado",
"troff troff .troff",
"TTCN ttcn",
"TTCN-cfg ttcn-cfg",
"Turtle turtle",
"Twig twig",
"Visual_Basic vb",
"VBScript vbscript",
"Velocity velocity",
"Verilog verilog",
"VHDL vhdl",
"Vue vue",
"XML xml",
"Turtle turtle .ttl",
"Twig twig .twig",
"Visual_Basic vb .vb",
"VBScript vbscript .vbs",
"Velocity velocity .vm",
"Verilog verilog .v",
"VHDL vhdl .vhdl",
"Vue vue .vue",
"XML xml .xml",
//"xwiki xwiki21",
"XQuery xquery",
"XQuery xquery .xquery",
"YAML yaml .yaml",
"YAML_Frontmatter yaml-frontmatter",
"Z80 z80"
"YAML_Frontmatter yaml-frontmatter _", /* no extension */
"Z80 z80 .z80"
].map(function (line) {
var kv = line.split(/\s/);
return {
language: kv[0].replace(/_/g, ' '),
mode: kv[1],
ext: kv[2],
ext: kv[2] === '_' ? '' : kv[2],
};
});
Modes.extensionOf = function (mode) {
var ext = '';
var ext;
list.some(function (o) {
if (o.mode !== mode) { return; }
ext = o.ext || '';
ext = o.ext;
return true;
});
return ext;

View File

@@ -401,7 +401,7 @@ define([
var ext = (typeof(extension) === 'function') ? extension() : extension;
var suggestion = title.suggestTitle('cryptpad-document');
UI.prompt(Messages.exportPrompt,
Util.fixFileName(suggestion) + '.' + ext, function (filename)
Util.fixFileName(suggestion) + ext, function (filename)
{
if (!(typeof(filename) === 'string' && filename)) { return; }
if (async) {
@@ -454,7 +454,7 @@ define([
return;
}
if (!mediaTagEmbedder) { console.log('mediaTagEmbedder missing'); return; }
if (data.type !== 'file') { console.log('unhandled embed type ' + data.type); return; }
if (data.type !== 'file') { console.log('unhandled embed type ' + data.type); return; }
var privateDat = cpNfInner.metadataMgr.getPrivateData();
var origin = privateDat.fileHost || privateDat.origin;
var src = data.src = origin + data.src;

View File

@@ -39,7 +39,8 @@ define([
};
module.getContentExtension = function (mode) {
return (Modes.extensionOf(mode) || '.txt').slice(1);
var ext = Modes.extensionOf(mode);
return ext !== undefined ? ext : '.txt';
};
module.fileExporter = function (content) {
return new Blob([ content ], { type: 'text/plain;charset=utf-8' });
@@ -98,9 +99,17 @@ define([
// lines beginning with a hash are potentially valuable
// works for markdown, python, bash, etc.
var hash = /^#+(.*?)$/;
var hashAndLink = /^#+\s*\[(.*?)\]\(.*\)\s*$/;
if (hash.test(line)) {
// test for link inside the title, and set text just to the name of the link
if (hashAndLink.test(line)) {
line.replace(hashAndLink, function (a, one) {
text = Util.stripTags(one);
});
return true;
}
line.replace(hash, function (a, one) {
text = one;
text = Util.stripTags(one);
});
return true;
}
@@ -386,21 +395,32 @@ define([
exp.mkIndentSettings = function (metadataMgr) {
var setIndentation = function (units, useTabs, fontSize, spellcheck) {
if (typeof(units) !== 'number') { return; }
var doc = editor.getDoc();
editor.setOption('indentUnit', units);
editor.setOption('tabSize', units);
editor.setOption('indentWithTabs', useTabs);
editor.setOption('spellcheck', spellcheck);
if (!useTabs) {
editor.setOption("extraKeys", {
Tab: function() {
editor.replaceSelection(Array(units + 1).join(" "));
editor.setOption("extraKeys", {
Tab: function() {
if (doc.somethingSelected()) {
editor.execCommand("indentMore");
}
});
} else {
editor.setOption("extraKeys", {
Tab: undefined,
});
}
else {
if (!useTabs) { editor.execCommand("insertSoftTab"); }
else { editor.execCommand("insertTab"); }
}
},
"Shift-Tab": function () {
editor.execCommand("indentLess");
},
"Backspace": function () {
var cursor = doc.getCursor();
var line = doc.getLine(cursor.line);
if (line.substring(0, cursor.ch).trim() === "") { editor.execCommand("indentLess"); }
else { editor.execCommand("delCharBefore"); }
},
});
$('.CodeMirror').css('font-size', fontSize+'px');
};