Notepad/enter/.obsidian/plugins/obsidian-etherpad-plugin/main.js

1879 lines
210 KiB
JavaScript
Raw Permalink Normal View History

2023-08-28 11:00:03 +00:00
/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __export = (target, all) => {
__markAsModule(target);
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __reExport = (target, module2, desc) => {
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
for (let key of __getOwnPropNames(module2))
if (!__hasOwnProp.call(target, key) && key !== "default")
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
}
return target;
};
var __toModule = (module2) => {
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
};
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
// node_modules/underscore/underscore.js
var require_underscore = __commonJS({
"node_modules/underscore/underscore.js"(exports, module2) {
(function() {
var root = this;
var previousUnderscore = root._;
var breaker = {};
var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
var slice = ArrayProto.slice, unshift = ArrayProto.unshift, toString = ObjProto.toString, hasOwnProperty = ObjProto.hasOwnProperty;
var nativeForEach = ArrayProto.forEach, nativeMap = ArrayProto.map, nativeReduce = ArrayProto.reduce, nativeReduceRight = ArrayProto.reduceRight, nativeFilter = ArrayProto.filter, nativeEvery = ArrayProto.every, nativeSome = ArrayProto.some, nativeIndexOf = ArrayProto.indexOf, nativeLastIndexOf = ArrayProto.lastIndexOf, nativeIsArray = Array.isArray, nativeKeys = Object.keys, nativeBind = FuncProto.bind;
var _ = function(obj) {
return new wrapper(obj);
};
if (typeof exports !== "undefined") {
if (typeof module2 !== "undefined" && module2.exports) {
exports = module2.exports = _;
}
exports._ = _;
} else {
root["_"] = _;
}
_.VERSION = "1.3.3";
var each = _.each = _.forEach = function(obj, iterator, context) {
if (obj == null)
return;
if (nativeForEach && obj.forEach === nativeForEach) {
obj.forEach(iterator, context);
} else if (obj.length === +obj.length) {
for (var i = 0, l = obj.length; i < l; i++) {
if (i in obj && iterator.call(context, obj[i], i, obj) === breaker)
return;
}
} else {
for (var key in obj) {
if (_.has(obj, key)) {
if (iterator.call(context, obj[key], key, obj) === breaker)
return;
}
}
}
};
_.map = _.collect = function(obj, iterator, context) {
var results = [];
if (obj == null)
return results;
if (nativeMap && obj.map === nativeMap)
return obj.map(iterator, context);
each(obj, function(value, index, list) {
results[results.length] = iterator.call(context, value, index, list);
});
if (obj.length === +obj.length)
results.length = obj.length;
return results;
};
_.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) {
var initial = arguments.length > 2;
if (obj == null)
obj = [];
if (nativeReduce && obj.reduce === nativeReduce) {
if (context)
iterator = _.bind(iterator, context);
return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator);
}
each(obj, function(value, index, list) {
if (!initial) {
memo = value;
initial = true;
} else {
memo = iterator.call(context, memo, value, index, list);
}
});
if (!initial)
throw new TypeError("Reduce of empty array with no initial value");
return memo;
};
_.reduceRight = _.foldr = function(obj, iterator, memo, context) {
var initial = arguments.length > 2;
if (obj == null)
obj = [];
if (nativeReduceRight && obj.reduceRight === nativeReduceRight) {
if (context)
iterator = _.bind(iterator, context);
return initial ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator);
}
var reversed = _.toArray(obj).reverse();
if (context && !initial)
iterator = _.bind(iterator, context);
return initial ? _.reduce(reversed, iterator, memo, context) : _.reduce(reversed, iterator);
};
_.find = _.detect = function(obj, iterator, context) {
var result2;
any(obj, function(value, index, list) {
if (iterator.call(context, value, index, list)) {
result2 = value;
return true;
}
});
return result2;
};
_.filter = _.select = function(obj, iterator, context) {
var results = [];
if (obj == null)
return results;
if (nativeFilter && obj.filter === nativeFilter)
return obj.filter(iterator, context);
each(obj, function(value, index, list) {
if (iterator.call(context, value, index, list))
results[results.length] = value;
});
return results;
};
_.reject = function(obj, iterator, context) {
var results = [];
if (obj == null)
return results;
each(obj, function(value, index, list) {
if (!iterator.call(context, value, index, list))
results[results.length] = value;
});
return results;
};
_.every = _.all = function(obj, iterator, context) {
var result2 = true;
if (obj == null)
return result2;
if (nativeEvery && obj.every === nativeEvery)
return obj.every(iterator, context);
each(obj, function(value, index, list) {
if (!(result2 = result2 && iterator.call(context, value, index, list)))
return breaker;
});
return !!result2;
};
var any = _.some = _.any = function(obj, iterator, context) {
iterator || (iterator = _.identity);
var result2 = false;
if (obj == null)
return result2;
if (nativeSome && obj.some === nativeSome)
return obj.some(iterator, context);
each(obj, function(value, index, list) {
if (result2 || (result2 = iterator.call(context, value, index, list)))
return breaker;
});
return !!result2;
};
_.include = _.contains = function(obj, target) {
var found = false;
if (obj == null)
return found;
if (nativeIndexOf && obj.indexOf === nativeIndexOf)
return obj.indexOf(target) != -1;
found = any(obj, function(value) {
return value === target;
});
return found;
};
_.invoke = function(obj, method) {
var args = slice.call(arguments, 2);
return _.map(obj, function(value) {
return (_.isFunction(method) ? method || value : value[method]).apply(value, args);
});
};
_.pluck = function(obj, key) {
return _.map(obj, function(value) {
return value[key];
});
};
_.max = function(obj, iterator, context) {
if (!iterator && _.isArray(obj) && obj[0] === +obj[0])
return Math.max.apply(Math, obj);
if (!iterator && _.isEmpty(obj))
return -Infinity;
var result2 = { computed: -Infinity };
each(obj, function(value, index, list) {
var computed = iterator ? iterator.call(context, value, index, list) : value;
computed >= result2.computed && (result2 = { value, computed });
});
return result2.value;
};
_.min = function(obj, iterator, context) {
if (!iterator && _.isArray(obj) && obj[0] === +obj[0])
return Math.min.apply(Math, obj);
if (!iterator && _.isEmpty(obj))
return Infinity;
var result2 = { computed: Infinity };
each(obj, function(value, index, list) {
var computed = iterator ? iterator.call(context, value, index, list) : value;
computed < result2.computed && (result2 = { value, computed });
});
return result2.value;
};
_.shuffle = function(obj) {
var shuffled = [], rand;
each(obj, function(value, index, list) {
rand = Math.floor(Math.random() * (index + 1));
shuffled[index] = shuffled[rand];
shuffled[rand] = value;
});
return shuffled;
};
_.sortBy = function(obj, val, context) {
var iterator = _.isFunction(val) ? val : function(obj2) {
return obj2[val];
};
return _.pluck(_.map(obj, function(value, index, list) {
return {
value,
criteria: iterator.call(context, value, index, list)
};
}).sort(function(left, right) {
var a = left.criteria, b = right.criteria;
if (a === void 0)
return 1;
if (b === void 0)
return -1;
return a < b ? -1 : a > b ? 1 : 0;
}), "value");
};
_.groupBy = function(obj, val) {
var result2 = {};
var iterator = _.isFunction(val) ? val : function(obj2) {
return obj2[val];
};
each(obj, function(value, index) {
var key = iterator(value, index);
(result2[key] || (result2[key] = [])).push(value);
});
return result2;
};
_.sortedIndex = function(array, obj, iterator) {
iterator || (iterator = _.identity);
var low = 0, high = array.length;
while (low < high) {
var mid = low + high >> 1;
iterator(array[mid]) < iterator(obj) ? low = mid + 1 : high = mid;
}
return low;
};
_.toArray = function(obj) {
if (!obj)
return [];
if (_.isArray(obj))
return slice.call(obj);
if (_.isArguments(obj))
return slice.call(obj);
if (obj.toArray && _.isFunction(obj.toArray))
return obj.toArray();
return _.values(obj);
};
_.size = function(obj) {
return _.isArray(obj) ? obj.length : _.keys(obj).length;
};
_.first = _.head = _.take = function(array, n, guard) {
return n != null && !guard ? slice.call(array, 0, n) : array[0];
};
_.initial = function(array, n, guard) {
return slice.call(array, 0, array.length - (n == null || guard ? 1 : n));
};
_.last = function(array, n, guard) {
if (n != null && !guard) {
return slice.call(array, Math.max(array.length - n, 0));
} else {
return array[array.length - 1];
}
};
_.rest = _.tail = function(array, index, guard) {
return slice.call(array, index == null || guard ? 1 : index);
};
_.compact = function(array) {
return _.filter(array, function(value) {
return !!value;
});
};
_.flatten = function(array, shallow) {
return _.reduce(array, function(memo, value) {
if (_.isArray(value))
return memo.concat(shallow ? value : _.flatten(value));
memo[memo.length] = value;
return memo;
}, []);
};
_.without = function(array) {
return _.difference(array, slice.call(arguments, 1));
};
_.uniq = _.unique = function(array, isSorted, iterator) {
var initial = iterator ? _.map(array, iterator) : array;
var results = [];
if (array.length < 3)
isSorted = true;
_.reduce(initial, function(memo, value, index) {
if (isSorted ? _.last(memo) !== value || !memo.length : !_.include(memo, value)) {
memo.push(value);
results.push(array[index]);
}
return memo;
}, []);
return results;
};
_.union = function() {
return _.uniq(_.flatten(arguments, true));
};
_.intersection = _.intersect = function(array) {
var rest = slice.call(arguments, 1);
return _.filter(_.uniq(array), function(item) {
return _.every(rest, function(other) {
return _.indexOf(other, item) >= 0;
});
});
};
_.difference = function(array) {
var rest = _.flatten(slice.call(arguments, 1), true);
return _.filter(array, function(value) {
return !_.include(rest, value);
});
};
_.zip = function() {
var args = slice.call(arguments);
var length = _.max(_.pluck(args, "length"));
var results = new Array(length);
for (var i = 0; i < length; i++)
results[i] = _.pluck(args, "" + i);
return results;
};
_.indexOf = function(array, item, isSorted) {
if (array == null)
return -1;
var i, l;
if (isSorted) {
i = _.sortedIndex(array, item);
return array[i] === item ? i : -1;
}
if (nativeIndexOf && array.indexOf === nativeIndexOf)
return array.indexOf(item);
for (i = 0, l = array.length; i < l; i++)
if (i in array && array[i] === item)
return i;
return -1;
};
_.lastIndexOf = function(array, item) {
if (array == null)
return -1;
if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf)
return array.lastIndexOf(item);
var i = array.length;
while (i--)
if (i in array && array[i] === item)
return i;
return -1;
};
_.range = function(start, stop, step) {
if (arguments.length <= 1) {
stop = start || 0;
start = 0;
}
step = arguments[2] || 1;
var len = Math.max(Math.ceil((stop - start) / step), 0);
var idx = 0;
var range = new Array(len);
while (idx < len) {
range[idx++] = start;
start += step;
}
return range;
};
var ctor = function() {
};
_.bind = function bind(func, context) {
var bound, args;
if (func.bind === nativeBind && nativeBind)
return nativeBind.apply(func, slice.call(arguments, 1));
if (!_.isFunction(func))
throw new TypeError();
args = slice.call(arguments, 2);
return bound = function() {
if (!(this instanceof bound))
return func.apply(context, args.concat(slice.call(arguments)));
ctor.prototype = func.prototype;
var self = new ctor();
var result2 = func.apply(self, args.concat(slice.call(arguments)));
if (Object(result2) === result2)
return result2;
return self;
};
};
_.bindAll = function(obj) {
var funcs = slice.call(arguments, 1);
if (funcs.length == 0)
funcs = _.functions(obj);
each(funcs, function(f) {
obj[f] = _.bind(obj[f], obj);
});
return obj;
};
_.memoize = function(func, hasher) {
var memo = {};
hasher || (hasher = _.identity);
return function() {
var key = hasher.apply(this, arguments);
return _.has(memo, key) ? memo[key] : memo[key] = func.apply(this, arguments);
};
};
_.delay = function(func, wait) {
var args = slice.call(arguments, 2);
return setTimeout(function() {
return func.apply(null, args);
}, wait);
};
_.defer = function(func) {
return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1)));
};
_.throttle = function(func, wait) {
var context, args, timeout, throttling, more, result2;
var whenDone = _.debounce(function() {
more = throttling = false;
}, wait);
return function() {
context = this;
args = arguments;
var later = function() {
timeout = null;
if (more)
func.apply(context, args);
whenDone();
};
if (!timeout)
timeout = setTimeout(later, wait);
if (throttling) {
more = true;
} else {
result2 = func.apply(context, args);
}
whenDone();
throttling = true;
return result2;
};
};
_.debounce = function(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate)
func.apply(context, args);
};
if (immediate && !timeout)
func.apply(context, args);
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
};
_.once = function(func) {
var ran = false, memo;
return function() {
if (ran)
return memo;
ran = true;
return memo = func.apply(this, arguments);
};
};
_.wrap = function(func, wrapper2) {
return function() {
var args = [func].concat(slice.call(arguments, 0));
return wrapper2.apply(this, args);
};
};
_.compose = function() {
var funcs = arguments;
return function() {
var args = arguments;
for (var i = funcs.length - 1; i >= 0; i--) {
args = [funcs[i].apply(this, args)];
}
return args[0];
};
};
_.after = function(times, func) {
if (times <= 0)
return func();
return function() {
if (--times < 1) {
return func.apply(this, arguments);
}
};
};
_.keys = nativeKeys || function(obj) {
if (obj !== Object(obj))
throw new TypeError("Invalid object");
var keys = [];
for (var key in obj)
if (_.has(obj, key))
keys[keys.length] = key;
return keys;
};
_.values = function(obj) {
return _.map(obj, _.identity);
};
_.functions = _.methods = function(obj) {
var names = [];
for (var key in obj) {
if (_.isFunction(obj[key]))
names.push(key);
}
return names.sort();
};
_.extend = function(obj) {
each(slice.call(arguments, 1), function(source) {
for (var prop in source) {
obj[prop] = source[prop];
}
});
return obj;
};
_.pick = function(obj) {
var result2 = {};
each(_.flatten(slice.call(arguments, 1)), function(key) {
if (key in obj)
result2[key] = obj[key];
});
return result2;
};
_.defaults = function(obj) {
each(slice.call(arguments, 1), function(source) {
for (var prop in source) {
if (obj[prop] == null)
obj[prop] = source[prop];
}
});
return obj;
};
_.clone = function(obj) {
if (!_.isObject(obj))
return obj;
return _.isArray(obj) ? obj.slice() : _.extend({}, obj);
};
_.tap = function(obj, interceptor) {
interceptor(obj);
return obj;
};
function eq(a, b, stack) {
if (a === b)
return a !== 0 || 1 / a == 1 / b;
if (a == null || b == null)
return a === b;
if (a._chain)
a = a._wrapped;
if (b._chain)
b = b._wrapped;
if (a.isEqual && _.isFunction(a.isEqual))
return a.isEqual(b);
if (b.isEqual && _.isFunction(b.isEqual))
return b.isEqual(a);
var className = toString.call(a);
if (className != toString.call(b))
return false;
switch (className) {
case "[object String]":
return a == String(b);
case "[object Number]":
return a != +a ? b != +b : a == 0 ? 1 / a == 1 / b : a == +b;
case "[object Date]":
case "[object Boolean]":
return +a == +b;
case "[object RegExp]":
return a.source == b.source && a.global == b.global && a.multiline == b.multiline && a.ignoreCase == b.ignoreCase;
}
if (typeof a != "object" || typeof b != "object")
return false;
var length = stack.length;
while (length--) {
if (stack[length] == a)
return true;
}
stack.push(a);
var size = 0, result2 = true;
if (className == "[object Array]") {
size = a.length;
result2 = size == b.length;
if (result2) {
while (size--) {
if (!(result2 = size in a == size in b && eq(a[size], b[size], stack)))
break;
}
}
} else {
if ("constructor" in a != "constructor" in b || a.constructor != b.constructor)
return false;
for (var key in a) {
if (_.has(a, key)) {
size++;
if (!(result2 = _.has(b, key) && eq(a[key], b[key], stack)))
break;
}
}
if (result2) {
for (key in b) {
if (_.has(b, key) && !size--)
break;
}
result2 = !size;
}
}
stack.pop();
return result2;
}
_.isEqual = function(a, b) {
return eq(a, b, []);
};
_.isEmpty = function(obj) {
if (obj == null)
return true;
if (_.isArray(obj) || _.isString(obj))
return obj.length === 0;
for (var key in obj)
if (_.has(obj, key))
return false;
return true;
};
_.isElement = function(obj) {
return !!(obj && obj.nodeType == 1);
};
_.isArray = nativeIsArray || function(obj) {
return toString.call(obj) == "[object Array]";
};
_.isObject = function(obj) {
return obj === Object(obj);
};
_.isArguments = function(obj) {
return toString.call(obj) == "[object Arguments]";
};
if (!_.isArguments(arguments)) {
_.isArguments = function(obj) {
return !!(obj && _.has(obj, "callee"));
};
}
_.isFunction = function(obj) {
return toString.call(obj) == "[object Function]";
};
_.isString = function(obj) {
return toString.call(obj) == "[object String]";
};
_.isNumber = function(obj) {
return toString.call(obj) == "[object Number]";
};
_.isFinite = function(obj) {
return _.isNumber(obj) && isFinite(obj);
};
_.isNaN = function(obj) {
return obj !== obj;
};
_.isBoolean = function(obj) {
return obj === true || obj === false || toString.call(obj) == "[object Boolean]";
};
_.isDate = function(obj) {
return toString.call(obj) == "[object Date]";
};
_.isRegExp = function(obj) {
return toString.call(obj) == "[object RegExp]";
};
_.isNull = function(obj) {
return obj === null;
};
_.isUndefined = function(obj) {
return obj === void 0;
};
_.has = function(obj, key) {
return hasOwnProperty.call(obj, key);
};
_.noConflict = function() {
root._ = previousUnderscore;
return this;
};
_.identity = function(value) {
return value;
};
_.times = function(n, iterator, context) {
for (var i = 0; i < n; i++)
iterator.call(context, i);
};
_.escape = function(string) {
return ("" + string).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;").replace(/\//g, "&#x2F;");
};
_.result = function(object, property) {
if (object == null)
return null;
var value = object[property];
return _.isFunction(value) ? value.call(object) : value;
};
_.mixin = function(obj) {
each(_.functions(obj), function(name) {
addToWrapper(name, _[name] = obj[name]);
});
};
var idCounter = 0;
_.uniqueId = function(prefix) {
var id = idCounter++;
return prefix ? prefix + id : id;
};
_.templateSettings = {
evaluate: /<%([\s\S]+?)%>/g,
interpolate: /<%=([\s\S]+?)%>/g,
escape: /<%-([\s\S]+?)%>/g
};
var noMatch = /.^/;
var escapes = {
"\\": "\\",
"'": "'",
"r": "\r",
"n": "\n",
"t": " ",
"u2028": "\u2028",
"u2029": "\u2029"
};
for (var p in escapes)
escapes[escapes[p]] = p;
var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g;
var unescaper = /\\(\\|'|r|n|t|u2028|u2029)/g;
var unescape = function(code) {
return code.replace(unescaper, function(match, escape) {
return escapes[escape];
});
};
_.template = function(text, data, settings) {
settings = _.defaults(settings || {}, _.templateSettings);
var source = "__p+='" + text.replace(escaper, function(match) {
return "\\" + escapes[match];
}).replace(settings.escape || noMatch, function(match, code) {
return "'+\n_.escape(" + unescape(code) + ")+\n'";
}).replace(settings.interpolate || noMatch, function(match, code) {
return "'+\n(" + unescape(code) + ")+\n'";
}).replace(settings.evaluate || noMatch, function(match, code) {
return "';\n" + unescape(code) + "\n;__p+='";
}) + "';\n";
if (!settings.variable)
source = "with(obj||{}){\n" + source + "}\n";
source = "var __p='';var print=function(){__p+=Array.prototype.join.call(arguments, '')};\n" + source + "return __p;\n";
var render = new Function(settings.variable || "obj", "_", source);
if (data)
return render(data, _);
var template = function(data2) {
return render.call(this, data2, _);
};
template.source = "function(" + (settings.variable || "obj") + "){\n" + source + "}";
return template;
};
_.chain = function(obj) {
return _(obj).chain();
};
var wrapper = function(obj) {
this._wrapped = obj;
};
_.prototype = wrapper.prototype;
var result = function(obj, chain) {
return chain ? _(obj).chain() : obj;
};
var addToWrapper = function(name, func) {
wrapper.prototype[name] = function() {
var args = slice.call(arguments);
unshift.call(args, this._wrapped);
return result(func.apply(_, args), this._chain);
};
};
_.mixin(_);
each(["pop", "push", "reverse", "shift", "sort", "splice", "unshift"], function(name) {
var method = ArrayProto[name];
wrapper.prototype[name] = function() {
var wrapped = this._wrapped;
method.apply(wrapped, arguments);
var length = wrapped.length;
if ((name == "shift" || name == "splice") && length === 0)
delete wrapped[0];
return result(wrapped, this._chain);
};
});
each(["concat", "join", "slice"], function(name) {
var method = ArrayProto[name];
wrapper.prototype[name] = function() {
return result(method.apply(this._wrapped, arguments), this._chain);
};
});
wrapper.prototype.chain = function() {
this._chain = true;
return this;
};
wrapper.prototype.value = function() {
return this._wrapped;
};
}).call(exports);
}
});
// node_modules/etherpad-lite-client/main.js
var require_main = __commonJS({
"node_modules/etherpad-lite-client/main.js"(exports) {
(function() {
var _, http, https, querystring, retriever, url;
http = require("http");
https = require("https");
url = require("url");
querystring = require("querystring");
_ = require_underscore();
retriever = null;
exports.connect = function(options) {
var api, apiFunctions, base, base1, fn, functionName, i, len;
if (options == null) {
options = {};
}
if (!("apikey" in options)) {
throw new Error("You must specify etherpad-lite apikey");
}
api = {};
api.options = _.extend({}, options);
(base = api.options).host || (base.host = "localhost");
(base1 = api.options).port || (base1.port = 9001);
retriever = http;
if (api.options.port === 443 || api.options.ssl) {
retriever = https;
}
api.call = function(functionName2, functionArgs, callback) {
var apiOptions, chunks, httpOptions, req, rootPath;
rootPath = api.options.rootPath || "/api/1.2.12/";
apiOptions = _.extend({
"apikey": this.options.apikey
}, functionArgs);
httpOptions = _.extend(this.options, {
path: rootPath + functionName2 + "?" + querystring.stringify(apiOptions)
});
chunks = [];
req = retriever.get(httpOptions, function(res) {
res.on("data", function(data) {
return chunks.push(data);
});
return res.on("end", function() {
var error, error1, response;
try {
response = JSON.parse(chunks.join(""));
} catch (error12) {
error = error12;
callback({
code: -1,
message: "cannot parse the API response"
}, null);
return;
}
if (response.code === 0 && response.message === "ok") {
if (response.data) {
return callback(null, response.data);
} else {
return callback(null, response);
}
} else {
return callback({
code: response.code,
message: response.message
}, null);
}
});
});
return req.on("error", function(error) {
return callback({
code: -1,
message: error.message || error
}, null);
});
};
apiFunctions = ["createGroup", "createGroupIfNotExistsFor", "deleteGroup", "listPads", "listAllPads", "createDiffHTML", "createPad", "createGroupPad", "createAuthor", "createAuthorIfNotExistsFor", "listPadsOfAuthor", "createSession", "deleteSession", "getSessionInfo", "listSessionsOfGroup", "listSessionsOfAuthor", "getText", "setText", "getHTML", "setHTML", "getAttributePool", "getRevisionsCount", "getSavedRevisionsCount", "listSavedRevisions", "saveRevision", "getRevisionChangeset", "getLastEdited", "deletePad", "copyPad", "movePad", "getReadOnlyID", "getPadID", "setPublicStatus", "getPublicStatus", "setPassword", "isPasswordProtected", "listAuthorsOfPad", "padUsersCount", "getAuthorName", "padUsers", "sendClientsMessage", "listAllGroups", "checkToken", "appendChatMessage", "getChatHistory", "getChatHistory", "getChatHead", "restoreRevision"];
fn = function(functionName2) {
return api[functionName2] = function(args, callback) {
if (arguments.length === 1 && _.isFunction(args)) {
callback = args;
args = {};
}
if (callback == null) {
callback = function() {
};
}
api.call(functionName2, args, callback);
return null;
};
};
for (i = 0, len = apiFunctions.length; i < len; i++) {
functionName = apiFunctions[i];
fn(functionName);
}
return api;
};
}).call(exports);
}
});
// node_modules/turndown/lib/turndown.browser.cjs.js
var require_turndown_browser_cjs = __commonJS({
"node_modules/turndown/lib/turndown.browser.cjs.js"(exports, module2) {
"use strict";
function extend(destination) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (source.hasOwnProperty(key))
destination[key] = source[key];
}
}
return destination;
}
function repeat(character, count) {
return Array(count + 1).join(character);
}
function trimLeadingNewlines(string) {
return string.replace(/^\n*/, "");
}
function trimTrailingNewlines(string) {
var indexEnd = string.length;
while (indexEnd > 0 && string[indexEnd - 1] === "\n")
indexEnd--;
return string.substring(0, indexEnd);
}
var blockElements = [
"ADDRESS",
"ARTICLE",
"ASIDE",
"AUDIO",
"BLOCKQUOTE",
"BODY",
"CANVAS",
"CENTER",
"DD",
"DIR",
"DIV",
"DL",
"DT",
"FIELDSET",
"FIGCAPTION",
"FIGURE",
"FOOTER",
"FORM",
"FRAMESET",
"H1",
"H2",
"H3",
"H4",
"H5",
"H6",
"HEADER",
"HGROUP",
"HR",
"HTML",
"ISINDEX",
"LI",
"MAIN",
"MENU",
"NAV",
"NOFRAMES",
"NOSCRIPT",
"OL",
"OUTPUT",
"P",
"PRE",
"SECTION",
"TABLE",
"TBODY",
"TD",
"TFOOT",
"TH",
"THEAD",
"TR",
"UL"
];
function isBlock(node) {
return is(node, blockElements);
}
var voidElements = [
"AREA",
"BASE",
"BR",
"COL",
"COMMAND",
"EMBED",
"HR",
"IMG",
"INPUT",
"KEYGEN",
"LINK",
"META",
"PARAM",
"SOURCE",
"TRACK",
"WBR"
];
function isVoid(node) {
return is(node, voidElements);
}
function hasVoid(node) {
return has(node, voidElements);
}
var meaningfulWhenBlankElements = [
"A",
"TABLE",
"THEAD",
"TBODY",
"TFOOT",
"TH",
"TD",
"IFRAME",
"SCRIPT",
"AUDIO",
"VIDEO"
];
function isMeaningfulWhenBlank(node) {
return is(node, meaningfulWhenBlankElements);
}
function hasMeaningfulWhenBlank(node) {
return has(node, meaningfulWhenBlankElements);
}
function is(node, tagNames) {
return tagNames.indexOf(node.nodeName) >= 0;
}
function has(node, tagNames) {
return node.getElementsByTagName && tagNames.some(function(tagName) {
return node.getElementsByTagName(tagName).length;
});
}
var rules = {};
rules.paragraph = {
filter: "p",
replacement: function(content) {
return "\n\n" + content + "\n\n";
}
};
rules.lineBreak = {
filter: "br",
replacement: function(content, node, options) {
return options.br + "\n";
}
};
rules.heading = {
filter: ["h1", "h2", "h3", "h4", "h5", "h6"],
replacement: function(content, node, options) {
var hLevel = Number(node.nodeName.charAt(1));
if (options.headingStyle === "setext" && hLevel < 3) {
var underline = repeat(hLevel === 1 ? "=" : "-", content.length);
return "\n\n" + content + "\n" + underline + "\n\n";
} else {
return "\n\n" + repeat("#", hLevel) + " " + content + "\n\n";
}
}
};
rules.blockquote = {
filter: "blockquote",
replacement: function(content) {
content = content.replace(/^\n+|\n+$/g, "");
content = content.replace(/^/gm, "> ");
return "\n\n" + content + "\n\n";
}
};
rules.list = {
filter: ["ul", "ol"],
replacement: function(content, node) {
var parent = node.parentNode;
if (parent.nodeName === "LI" && parent.lastElementChild === node) {
return "\n" + content;
} else {
return "\n\n" + content + "\n\n";
}
}
};
rules.listItem = {
filter: "li",
replacement: function(content, node, options) {
content = content.replace(/^\n+/, "").replace(/\n+$/, "\n").replace(/\n/gm, "\n ");
var prefix = options.bulletListMarker + " ";
var parent = node.parentNode;
if (parent.nodeName === "OL") {
var start = parent.getAttribute("start");
var index = Array.prototype.indexOf.call(parent.children, node);
prefix = (start ? Number(start) + index : index + 1) + ". ";
}
return prefix + content + (node.nextSibling && !/\n$/.test(content) ? "\n" : "");
}
};
rules.indentedCodeBlock = {
filter: function(node, options) {
return options.codeBlockStyle === "indented" && node.nodeName === "PRE" && node.firstChild && node.firstChild.nodeName === "CODE";
},
replacement: function(content, node, options) {
return "\n\n " + node.firstChild.textContent.replace(/\n/g, "\n ") + "\n\n";
}
};
rules.fencedCodeBlock = {
filter: function(node, options) {
return options.codeBlockStyle === "fenced" && node.nodeName === "PRE" && node.firstChild && node.firstChild.nodeName === "CODE";
},
replacement: function(content, node, options) {
var className = node.firstChild.getAttribute("class") || "";
var language = (className.match(/language-(\S+)/) || [null, ""])[1];
var code = node.firstChild.textContent;
var fenceChar = options.fence.charAt(0);
var fenceSize = 3;
var fenceInCodeRegex = new RegExp("^" + fenceChar + "{3,}", "gm");
var match;
while (match = fenceInCodeRegex.exec(code)) {
if (match[0].length >= fenceSize) {
fenceSize = match[0].length + 1;
}
}
var fence = repeat(fenceChar, fenceSize);
return "\n\n" + fence + language + "\n" + code.replace(/\n$/, "") + "\n" + fence + "\n\n";
}
};
rules.horizontalRule = {
filter: "hr",
replacement: function(content, node, options) {
return "\n\n" + options.hr + "\n\n";
}
};
rules.inlineLink = {
filter: function(node, options) {
return options.linkStyle === "inlined" && node.nodeName === "A" && node.getAttribute("href");
},
replacement: function(content, node) {
var href = node.getAttribute("href");
var title = cleanAttribute(node.getAttribute("title"));
if (title)
title = ' "' + title + '"';
return "[" + content + "](" + href + title + ")";
}
};
rules.referenceLink = {
filter: function(node, options) {
return options.linkStyle === "referenced" && node.nodeName === "A" && node.getAttribute("href");
},
replacement: function(content, node, options) {
var href = node.getAttribute("href");
var title = cleanAttribute(node.getAttribute("title"));
if (title)
title = ' "' + title + '"';
var replacement;
var reference;
switch (options.linkReferenceStyle) {
case "collapsed":
replacement = "[" + content + "][]";
reference = "[" + content + "]: " + href + title;
break;
case "shortcut":
replacement = "[" + content + "]";
reference = "[" + content + "]: " + href + title;
break;
default:
var id = this.references.length + 1;
replacement = "[" + content + "][" + id + "]";
reference = "[" + id + "]: " + href + title;
}
this.references.push(reference);
return replacement;
},
references: [],
append: function(options) {
var references = "";
if (this.references.length) {
references = "\n\n" + this.references.join("\n") + "\n\n";
this.references = [];
}
return references;
}
};
rules.emphasis = {
filter: ["em", "i"],
replacement: function(content, node, options) {
if (!content.trim())
return "";
return options.emDelimiter + content + options.emDelimiter;
}
};
rules.strong = {
filter: ["strong", "b"],
replacement: function(content, node, options) {
if (!content.trim())
return "";
return options.strongDelimiter + content + options.strongDelimiter;
}
};
rules.code = {
filter: function(node) {
var hasSiblings = node.previousSibling || node.nextSibling;
var isCodeBlock = node.parentNode.nodeName === "PRE" && !hasSiblings;
return node.nodeName === "CODE" && !isCodeBlock;
},
replacement: function(content) {
if (!content)
return "";
content = content.replace(/\r?\n|\r/g, " ");
var extraSpace = /^`|^ .*?[^ ].* $|`$/.test(content) ? " " : "";
var delimiter = "`";
var matches = content.match(/`+/gm) || [];
while (matches.indexOf(delimiter) !== -1)
delimiter = delimiter + "`";
return delimiter + extraSpace + content + extraSpace + delimiter;
}
};
rules.image = {
filter: "img",
replacement: function(content, node) {
var alt = cleanAttribute(node.getAttribute("alt"));
var src = node.getAttribute("src") || "";
var title = cleanAttribute(node.getAttribute("title"));
var titlePart = title ? ' "' + title + '"' : "";
return src ? "![" + alt + "](" + src + titlePart + ")" : "";
}
};
function cleanAttribute(attribute) {
return attribute ? attribute.replace(/(\n+\s*)+/g, "\n") : "";
}
function Rules(options) {
this.options = options;
this._keep = [];
this._remove = [];
this.blankRule = {
replacement: options.blankReplacement
};
this.keepReplacement = options.keepReplacement;
this.defaultRule = {
replacement: options.defaultReplacement
};
this.array = [];
for (var key in options.rules)
this.array.push(options.rules[key]);
}
Rules.prototype = {
add: function(key, rule) {
this.array.unshift(rule);
},
keep: function(filter) {
this._keep.unshift({
filter,
replacement: this.keepReplacement
});
},
remove: function(filter) {
this._remove.unshift({
filter,
replacement: function() {
return "";
}
});
},
forNode: function(node) {
if (node.isBlank)
return this.blankRule;
var rule;
if (rule = findRule(this.array, node, this.options))
return rule;
if (rule = findRule(this._keep, node, this.options))
return rule;
if (rule = findRule(this._remove, node, this.options))
return rule;
return this.defaultRule;
},
forEach: function(fn) {
for (var i = 0; i < this.array.length; i++)
fn(this.array[i], i);
}
};
function findRule(rules2, node, options) {
for (var i = 0; i < rules2.length; i++) {
var rule = rules2[i];
if (filterValue(rule, node, options))
return rule;
}
return void 0;
}
function filterValue(rule, node, options) {
var filter = rule.filter;
if (typeof filter === "string") {
if (filter === node.nodeName.toLowerCase())
return true;
} else if (Array.isArray(filter)) {
if (filter.indexOf(node.nodeName.toLowerCase()) > -1)
return true;
} else if (typeof filter === "function") {
if (filter.call(rule, node, options))
return true;
} else {
throw new TypeError("`filter` needs to be a string, array, or function");
}
}
function collapseWhitespace(options) {
var element = options.element;
var isBlock2 = options.isBlock;
var isVoid2 = options.isVoid;
var isPre = options.isPre || function(node2) {
return node2.nodeName === "PRE";
};
if (!element.firstChild || isPre(element))
return;
var prevText = null;
var keepLeadingWs = false;
var prev = null;
var node = next(prev, element, isPre);
while (node !== element) {
if (node.nodeType === 3 || node.nodeType === 4) {
var text = node.data.replace(/[ \r\n\t]+/g, " ");
if ((!prevText || / $/.test(prevText.data)) && !keepLeadingWs && text[0] === " ") {
text = text.substr(1);
}
if (!text) {
node = remove(node);
continue;
}
node.data = text;
prevText = node;
} else if (node.nodeType === 1) {
if (isBlock2(node) || node.nodeName === "BR") {
if (prevText) {
prevText.data = prevText.data.replace(/ $/, "");
}
prevText = null;
keepLeadingWs = false;
} else if (isVoid2(node) || isPre(node)) {
prevText = null;
keepLeadingWs = true;
} else if (prevText) {
keepLeadingWs = false;
}
} else {
node = remove(node);
continue;
}
var nextNode = next(prev, node, isPre);
prev = node;
node = nextNode;
}
if (prevText) {
prevText.data = prevText.data.replace(/ $/, "");
if (!prevText.data) {
remove(prevText);
}
}
}
function remove(node) {
var next2 = node.nextSibling || node.parentNode;
node.parentNode.removeChild(node);
return next2;
}
function next(prev, current, isPre) {
if (prev && prev.parentNode === current || isPre(current)) {
return current.nextSibling || current.parentNode;
}
return current.firstChild || current.nextSibling || current.parentNode;
}
var root = typeof window !== "undefined" ? window : {};
function canParseHTMLNatively() {
var Parser = root.DOMParser;
var canParse = false;
try {
if (new Parser().parseFromString("", "text/html")) {
canParse = true;
}
} catch (e) {
}
return canParse;
}
function createHTMLParser() {
var Parser = function() {
};
{
if (shouldUseActiveX()) {
Parser.prototype.parseFromString = function(string) {
var doc = new window.ActiveXObject("htmlfile");
doc.designMode = "on";
doc.open();
doc.write(string);
doc.close();
return doc;
};
} else {
Parser.prototype.parseFromString = function(string) {
var doc = document.implementation.createHTMLDocument("");
doc.open();
doc.write(string);
doc.close();
return doc;
};
}
}
return Parser;
}
function shouldUseActiveX() {
var useActiveX = false;
try {
document.implementation.createHTMLDocument("").open();
} catch (e) {
if (window.ActiveXObject)
useActiveX = true;
}
return useActiveX;
}
var HTMLParser = canParseHTMLNatively() ? root.DOMParser : createHTMLParser();
function RootNode(input, options) {
var root2;
if (typeof input === "string") {
var doc = htmlParser().parseFromString('<x-turndown id="turndown-root">' + input + "</x-turndown>", "text/html");
root2 = doc.getElementById("turndown-root");
} else {
root2 = input.cloneNode(true);
}
collapseWhitespace({
element: root2,
isBlock,
isVoid,
isPre: options.preformattedCode ? isPreOrCode : null
});
return root2;
}
var _htmlParser;
function htmlParser() {
_htmlParser = _htmlParser || new HTMLParser();
return _htmlParser;
}
function isPreOrCode(node) {
return node.nodeName === "PRE" || node.nodeName === "CODE";
}
function Node(node, options) {
node.isBlock = isBlock(node);
node.isCode = node.nodeName === "CODE" || node.parentNode.isCode;
node.isBlank = isBlank(node);
node.flankingWhitespace = flankingWhitespace(node, options);
return node;
}
function isBlank(node) {
return !isVoid(node) && !isMeaningfulWhenBlank(node) && /^\s*$/i.test(node.textContent) && !hasVoid(node) && !hasMeaningfulWhenBlank(node);
}
function flankingWhitespace(node, options) {
if (node.isBlock || options.preformattedCode && node.isCode) {
return { leading: "", trailing: "" };
}
var edges = edgeWhitespace(node.textContent);
if (edges.leadingAscii && isFlankedByWhitespace("left", node, options)) {
edges.leading = edges.leadingNonAscii;
}
if (edges.trailingAscii && isFlankedByWhitespace("right", node, options)) {
edges.trailing = edges.trailingNonAscii;
}
return { leading: edges.leading, trailing: edges.trailing };
}
function edgeWhitespace(string) {
var m = string.match(/^(([ \t\r\n]*)(\s*))[\s\S]*?((\s*?)([ \t\r\n]*))$/);
return {
leading: m[1],
leadingAscii: m[2],
leadingNonAscii: m[3],
trailing: m[4],
trailingNonAscii: m[5],
trailingAscii: m[6]
};
}
function isFlankedByWhitespace(side, node, options) {
var sibling;
var regExp;
var isFlanked;
if (side === "left") {
sibling = node.previousSibling;
regExp = / $/;
} else {
sibling = node.nextSibling;
regExp = /^ /;
}
if (sibling) {
if (sibling.nodeType === 3) {
isFlanked = regExp.test(sibling.nodeValue);
} else if (options.preformattedCode && sibling.nodeName === "CODE") {
isFlanked = false;
} else if (sibling.nodeType === 1 && !isBlock(sibling)) {
isFlanked = regExp.test(sibling.textContent);
}
}
return isFlanked;
}
var reduce = Array.prototype.reduce;
var escapes = [
[/\\/g, "\\\\"],
[/\*/g, "\\*"],
[/^-/g, "\\-"],
[/^\+ /g, "\\+ "],
[/^(=+)/g, "\\$1"],
[/^(#{1,6}) /g, "\\$1 "],
[/`/g, "\\`"],
[/^~~~/g, "\\~~~"],
[/\[/g, "\\["],
[/\]/g, "\\]"],
[/^>/g, "\\>"],
[/_/g, "\\_"],
[/^(\d+)\. /g, "$1\\. "]
];
function TurndownService2(options) {
if (!(this instanceof TurndownService2))
return new TurndownService2(options);
var defaults = {
rules,
headingStyle: "setext",
hr: "* * *",
bulletListMarker: "*",
codeBlockStyle: "indented",
fence: "```",
emDelimiter: "_",
strongDelimiter: "**",
linkStyle: "inlined",
linkReferenceStyle: "full",
br: " ",
preformattedCode: false,
blankReplacement: function(content, node) {
return node.isBlock ? "\n\n" : "";
},
keepReplacement: function(content, node) {
return node.isBlock ? "\n\n" + node.outerHTML + "\n\n" : node.outerHTML;
},
defaultReplacement: function(content, node) {
return node.isBlock ? "\n\n" + content + "\n\n" : content;
}
};
this.options = extend({}, defaults, options);
this.rules = new Rules(this.options);
}
TurndownService2.prototype = {
turndown: function(input) {
if (!canConvert(input)) {
throw new TypeError(input + " is not a string, or an element/document/fragment node.");
}
if (input === "")
return "";
var output = process.call(this, new RootNode(input, this.options));
return postProcess.call(this, output);
},
use: function(plugin) {
if (Array.isArray(plugin)) {
for (var i = 0; i < plugin.length; i++)
this.use(plugin[i]);
} else if (typeof plugin === "function") {
plugin(this);
} else {
throw new TypeError("plugin must be a Function or an Array of Functions");
}
return this;
},
addRule: function(key, rule) {
this.rules.add(key, rule);
return this;
},
keep: function(filter) {
this.rules.keep(filter);
return this;
},
remove: function(filter) {
this.rules.remove(filter);
return this;
},
escape: function(string) {
return escapes.reduce(function(accumulator, escape) {
return accumulator.replace(escape[0], escape[1]);
}, string);
}
};
function process(parentNode) {
var self = this;
return reduce.call(parentNode.childNodes, function(output, node) {
node = new Node(node, self.options);
var replacement = "";
if (node.nodeType === 3) {
replacement = node.isCode ? node.nodeValue : self.escape(node.nodeValue);
} else if (node.nodeType === 1) {
replacement = replacementForNode.call(self, node);
}
return join(output, replacement);
}, "");
}
function postProcess(output) {
var self = this;
this.rules.forEach(function(rule) {
if (typeof rule.append === "function") {
output = join(output, rule.append(self.options));
}
});
return output.replace(/^[\t\r\n]+/, "").replace(/[\t\r\n\s]+$/, "");
}
function replacementForNode(node) {
var rule = this.rules.forNode(node);
var content = process.call(this, node);
var whitespace = node.flankingWhitespace;
if (whitespace.leading || whitespace.trailing)
content = content.trim();
return whitespace.leading + rule.replacement(content, node, this.options) + whitespace.trailing;
}
function join(output, replacement) {
var s1 = trimTrailingNewlines(output);
var s2 = trimLeadingNewlines(replacement);
var nls = Math.max(output.length - s1.length, replacement.length - s2.length);
var separator = "\n\n".substring(0, nls);
return s1 + separator + s2;
}
function canConvert(input) {
return input != null && (typeof input === "string" || input.nodeType && (input.nodeType === 1 || input.nodeType === 9 || input.nodeType === 11));
}
module2.exports = TurndownService2;
}
});
// main.ts
__export(exports, {
default: () => Etherpad
});
var import_obsidian = __toModule(require("obsidian"));
var import_obsidian2 = __toModule(require("obsidian"));
var etherpad = require_main();
var TurndownService = require_turndown_browser_cjs();
TurndownService.prototype.escape = (text) => text;
function makeid(length) {
let result = "";
let characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let charactersLength = characters.length;
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
var td = new TurndownService().addRule("strikethrough", {
filter: ["s"],
replacement: function(content) {
return "~~" + content + "~~";
}
}).addRule("underline", {
filter: ["u"],
replacement: function(content) {
return "==" + content + "==";
}
}).addRule("a", {
filter: ["a"],
replacement: function(content, node, options) {
return node.getAttribute("href");
}
});
var DEFAULT_SETTINGS = {
host: "localhost",
port: 9001,
apikey: "",
random_pad_id: true
};
var Etherpad = class extends import_obsidian.Plugin {
get etherpad() {
return etherpad.connect({
apikey: this.settings.apikey,
host: this.settings.host,
port: this.settings.port
});
}
onload() {
return __async(this, null, function* () {
yield this.loadSettings();
this.registerEvent(this.app.workspace.on("file-open", (note) => __async(this, null, function* () {
this.replace_note_from_etherpad(note);
})));
this.addCommand({
id: "etherpad-create-pad",
name: "Convert current document to Etherpad",
editorCallback: (editor, view) => __async(this, null, function* () {
const note = view.file;
if (!note.name)
return;
let note_text = editor.getValue();
let note_text_without_frontmatter = yield this.get_text_without_frontmatter(note_text, note);
let pad_id = this.settings.random_pad_id ? makeid(12) : note.basename;
this.etherpad.createPad({
padID: pad_id,
text: note_text_without_frontmatter
}, (error, data) => {
if (error) {
new import_obsidian.Notice(`Error creating pad ${pad_id}: ${error.message}`);
} else {
this.update_frontmatter(note_text, note, { etherpad_id: pad_id });
}
});
})
});
this.addCommand({
id: "etherpad-get-pad",
name: "Replace note content from Etherpad",
editorCallback: (editor, view) => __async(this, null, function* () {
const note = view.file;
this.replace_note_from_etherpad(note);
})
});
this.addCommand({
id: "etherpad-visit-pad",
name: "Visit note in Etherpad in system browser",
editorCallback: (editor, view) => __async(this, null, function* () {
let note = view.file;
if (!note.name)
return;
let frontmatter = this.get_frontmatter(note);
if (frontmatter == null ? void 0 : frontmatter.etherpad_id) {
let url = this.get_url_for_pad_id(frontmatter.etherpad_id);
window.open(url);
}
})
});
this.addSettingTab(new EtherpadSettingTab(this.app, this));
});
}
onunload() {
}
loadSettings() {
return __async(this, null, function* () {
this.settings = Object.assign({}, DEFAULT_SETTINGS, yield this.loadData());
});
}
saveSettings() {
return __async(this, null, function* () {
yield this.saveData(this.settings);
});
}
get_frontmatter(note) {
var _a;
return __spreadValues({}, (_a = this.app.metadataCache.getFileCache(note)) == null ? void 0 : _a.frontmatter);
}
get_text_without_frontmatter(note_text, note) {
return __async(this, null, function* () {
var _a;
let fmc = (_a = app.metadataCache.getFileCache(note)) == null ? void 0 : _a.frontmatter;
if (!fmc) {
return note_text;
}
let end = fmc.position.end.line + 1;
return note_text.split("\n").slice(end).join("\n");
});
}
update_frontmatter(note_text, note, d) {
return __async(this, null, function* () {
let frontmatter = this.get_frontmatter(note);
let updated_frontmatter;
if (!frontmatter) {
updated_frontmatter = d;
} else {
updated_frontmatter = __spreadValues(__spreadValues({}, frontmatter), d);
}
delete updated_frontmatter.position;
let frontmatter_text = `---
${(0, import_obsidian2.stringifyYaml)(updated_frontmatter)}---
`;
this.app.vault.modify(note, frontmatter_text + note_text);
});
}
get_url_for_pad_id(pad_id) {
pad_id = pad_id.replace(" ", "_");
return `http://${this.settings.host}:${this.settings.port}/p/${pad_id}`;
}
replace_note_from_etherpad(note) {
return __async(this, null, function* () {
if (note == null)
return;
let frontmatter = this.get_frontmatter(note);
if (!frontmatter)
return;
if (!frontmatter.etherpad_id)
return;
this.etherpad.getHTML({ padID: frontmatter.etherpad_id }, (err, data) => {
if (err) {
console.log("err", err);
new import_obsidian.Notice("error: " + err);
} else {
delete frontmatter.position;
let now = new Date();
frontmatter.etherpad_get_at = now.toLocaleString();
let frontmatter_text = `---
${(0, import_obsidian2.stringifyYaml)(frontmatter)}---
`;
let note_html = data.html;
let note_text = td.turndown(note_html);
this.app.vault.modify(note, frontmatter_text + note_text);
let url = this.get_url_for_pad_id(frontmatter.etherpad_id);
new import_obsidian.Notice(`Note was reloaded from ${url}.
Local edits will be discarded!`);
}
});
});
}
};
var EtherpadSettingTab = class extends import_obsidian.PluginSettingTab {
constructor(app2, plugin) {
super(app2, plugin);
this.plugin = plugin;
}
display() {
const { containerEl } = this;
containerEl.empty();
containerEl.createEl("h2", { text: "Etherpad Settings" });
new import_obsidian.Setting(containerEl).setName("Server host").setDesc("Server host").addText((text) => text.setPlaceholder("localhost").setValue(this.plugin.settings.host).onChange((value) => __async(this, null, function* () {
this.plugin.settings.host = value;
yield this.plugin.saveSettings();
})));
new import_obsidian.Setting(containerEl).setName("Server port").setDesc("Server port").addText((text) => text.setPlaceholder("9001").setValue(this.plugin.settings.port.toString()).onChange((value) => __async(this, null, function* () {
this.plugin.settings.port = parseInt(value);
yield this.plugin.saveSettings();
})));
new import_obsidian.Setting(containerEl).setName("API key").setDesc("API key").addText((text) => text.setPlaceholder("").setValue(this.plugin.settings.apikey).onChange((value) => __async(this, null, function* () {
this.plugin.settings.apikey = value;
yield this.plugin.saveSettings();
})));
new import_obsidian.Setting(containerEl).setName("Random pad ID").setDesc("Use a random pad id, or current file name").addToggle((b) => b.setValue(this.plugin.settings.random_pad_id).onChange((value) => __async(this, null, function* () {
this.plugin.settings.random_pad_id = value;
yield this.plugin.saveSettings();
})));
}
};
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsibm9kZV9tb2R1bGVzL3VuZGVyc2NvcmUvdW5kZXJzY29yZS5qcyI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