f9db43a2e9
* Add key * Add: a second index uuid, push changes to sync controller * Add: sync.js * Add: tokenManager * Change: log entire body for http error * Add: token flow * Fix: minor * Fix: move cleanup to stop function * Add: syncNow * Update dependencies * Fix: handle 401 error * Add: handle 401 error * Fix: then -> catch * Add: sync options to options page * Update db-to-cloud * Change: make prefs.set return a promise * Add: disble selector if connected * Add: update selector state * Fix: return promise in prefs.set * Fix: manage complex state * Fix: handle prefs change * Change: manage sync status in background * Add: show current status in the UI * Add: schedule a faster sync when db changed * Update dependencies * Add: include progress in sync status * Add: more detail status * Show status text only * Bump dependencies * Change: show loaded and total * Fix: syncTarget is undefined * Add: google and onedrive * Fix: token is not reused * Bump dependencies * Don't use minified version since it is hard to debug * Fix: expire time is incorrect * Change: switch google to code flow * Bump dependencies * Change: only modify pref if the initialization success? * Don't stop the sync if the first sync is not triggered by the user * Add: implement refresh token * Change: switch microsoft to code flow * Add: subtract expire with a latency * Add: microsoft client secret * Add: display error message * Fix: fromPref is not used * Change: try to revoke the token when log out * Add: revoke dropbox token * Fix: Google only generates one refresh token for one user by default * Bump dependencies, fix onedrive list issue * Fix: arguments sent to sync.put is wrong * Fix: don't schedule a sync on db changed if not connected * Bump dependencies. Fix issue of switching drives * Bump db-to-cloud, fix switching drive issue * Fix: only auth user on 401 error, don't display login window without user interaction * Fix: don't call revoke() if token is undefined * Add: login button to generate the access token interactively * Fix: make addMissingProperties a local * Fix: store missing props in an object * Fix: sync.getStatus should be sync * LATENCY -> NETWORK_LATENCY * Fix: cache the token forever if there is no expire time e.g. dropbox * Add some comments * Fix: i18n * Fix: i18n sync status * fixup! Fix: i18n sync status * Fix: 'sync to cloud' is displayed twice
152 lines
4.6 KiB
JavaScript
152 lines
4.6 KiB
JavaScript
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: https://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"), require("./foldcode"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror", "./foldcode"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineOption("foldGutter", false, function(cm, val, old) {
|
|
if (old && old != CodeMirror.Init) {
|
|
cm.clearGutter(cm.state.foldGutter.options.gutter);
|
|
cm.state.foldGutter = null;
|
|
cm.off("gutterClick", onGutterClick);
|
|
cm.off("change", onChange);
|
|
cm.off("viewportChange", onViewportChange);
|
|
cm.off("fold", onFold);
|
|
cm.off("unfold", onFold);
|
|
cm.off("swapDoc", onChange);
|
|
}
|
|
if (val) {
|
|
cm.state.foldGutter = new State(parseOptions(val));
|
|
updateInViewport(cm);
|
|
cm.on("gutterClick", onGutterClick);
|
|
cm.on("change", onChange);
|
|
cm.on("viewportChange", onViewportChange);
|
|
cm.on("fold", onFold);
|
|
cm.on("unfold", onFold);
|
|
cm.on("swapDoc", onChange);
|
|
}
|
|
});
|
|
|
|
var Pos = CodeMirror.Pos;
|
|
|
|
function State(options) {
|
|
this.options = options;
|
|
this.from = this.to = 0;
|
|
}
|
|
|
|
function parseOptions(opts) {
|
|
if (opts === true) opts = {};
|
|
if (opts.gutter == null) opts.gutter = "CodeMirror-foldgutter";
|
|
if (opts.indicatorOpen == null) opts.indicatorOpen = "CodeMirror-foldgutter-open";
|
|
if (opts.indicatorFolded == null) opts.indicatorFolded = "CodeMirror-foldgutter-folded";
|
|
return opts;
|
|
}
|
|
|
|
function isFolded(cm, line) {
|
|
var marks = cm.findMarks(Pos(line, 0), Pos(line + 1, 0));
|
|
for (var i = 0; i < marks.length; ++i) {
|
|
if (marks[i].__isFold) {
|
|
var fromPos = marks[i].find(-1);
|
|
if (fromPos && fromPos.line === line)
|
|
return marks[i];
|
|
}
|
|
}
|
|
}
|
|
|
|
function marker(spec) {
|
|
if (typeof spec == "string") {
|
|
var elt = document.createElement("div");
|
|
elt.className = spec + " CodeMirror-guttermarker-subtle";
|
|
return elt;
|
|
} else {
|
|
return spec.cloneNode(true);
|
|
}
|
|
}
|
|
|
|
function updateFoldInfo(cm, from, to) {
|
|
var opts = cm.state.foldGutter.options, cur = from;
|
|
var minSize = cm.foldOption(opts, "minFoldSize");
|
|
var func = cm.foldOption(opts, "rangeFinder");
|
|
cm.eachLine(from, to, function(line) {
|
|
var mark = null;
|
|
if (isFolded(cm, cur)) {
|
|
mark = marker(opts.indicatorFolded);
|
|
} else {
|
|
var pos = Pos(cur, 0);
|
|
var range = func && func(cm, pos);
|
|
if (range && range.to.line - range.from.line >= minSize)
|
|
mark = marker(opts.indicatorOpen);
|
|
}
|
|
cm.setGutterMarker(line, opts.gutter, mark);
|
|
++cur;
|
|
});
|
|
}
|
|
|
|
function updateInViewport(cm) {
|
|
var vp = cm.getViewport(), state = cm.state.foldGutter;
|
|
if (!state) return;
|
|
cm.operation(function() {
|
|
updateFoldInfo(cm, vp.from, vp.to);
|
|
});
|
|
state.from = vp.from; state.to = vp.to;
|
|
}
|
|
|
|
function onGutterClick(cm, line, gutter) {
|
|
var state = cm.state.foldGutter;
|
|
if (!state) return;
|
|
var opts = state.options;
|
|
if (gutter != opts.gutter) return;
|
|
var folded = isFolded(cm, line);
|
|
if (folded) folded.clear();
|
|
else cm.foldCode(Pos(line, 0), opts);
|
|
}
|
|
|
|
function onChange(cm) {
|
|
var state = cm.state.foldGutter;
|
|
if (!state) return;
|
|
var opts = state.options;
|
|
state.from = state.to = 0;
|
|
clearTimeout(state.changeUpdate);
|
|
state.changeUpdate = setTimeout(function() { updateInViewport(cm); }, opts.foldOnChangeTimeSpan || 600);
|
|
}
|
|
|
|
function onViewportChange(cm) {
|
|
var state = cm.state.foldGutter;
|
|
if (!state) return;
|
|
var opts = state.options;
|
|
clearTimeout(state.changeUpdate);
|
|
state.changeUpdate = setTimeout(function() {
|
|
var vp = cm.getViewport();
|
|
if (state.from == state.to || vp.from - state.to > 20 || state.from - vp.to > 20) {
|
|
updateInViewport(cm);
|
|
} else {
|
|
cm.operation(function() {
|
|
if (vp.from < state.from) {
|
|
updateFoldInfo(cm, vp.from, state.from);
|
|
state.from = vp.from;
|
|
}
|
|
if (vp.to > state.to) {
|
|
updateFoldInfo(cm, state.to, vp.to);
|
|
state.to = vp.to;
|
|
}
|
|
});
|
|
}
|
|
}, opts.updateViewportTimeSpan || 400);
|
|
}
|
|
|
|
function onFold(cm, from) {
|
|
var state = cm.state.foldGutter;
|
|
if (!state) return;
|
|
var line = from.line;
|
|
if (line >= state.from && line < state.to)
|
|
updateFoldInfo(cm, line, line + 1);
|
|
}
|
|
});
|